blob: f5a77bc51c1ef8b230ac24725f7c75952b83f41f [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Dustin Browndb2a8be2017-12-20 11:49:56 -08002 * Copyright (c) 2012-2018 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
7 * copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080019/**
20 * DOC: 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"
Dustin Brown21a1d462018-07-31 15:13:06 -070029#include "wlan_dsc.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080030#include <wlan_hdd_includes.h>
31#include <cds_api.h>
32#include <cds_sched.h>
Arun Khandavallifae92942016-08-01 13:31:08 +053033#include <linux/cpu.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080034#include <linux/etherdevice.h>
35#include <linux/firmware.h>
36#include <wlan_hdd_tx_rx.h>
37#include <wni_api.h>
38#include <wlan_hdd_cfg.h>
39#include <wlan_ptt_sock_svc.h>
40#include <dbglog_host.h>
41#include <wlan_logging_sock_svc.h>
Qiwei Caiad9b01c2018-07-09 17:21:31 +080042#include <wlan_roam_debug.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 Brownd4241942018-02-26 12:51:37 -080057#include "qdf_str.h"
58#include "qdf_trace.h"
59#include "qdf_types.h"
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070060#include <cdp_txrx_peer_ops.h>
Dhanashri Atrea8f82f22017-01-23 12:58:24 -080061#include <cdp_txrx_misc.h>
Mohit Khannaca4173b2017-09-12 21:52:19 -070062#include <cdp_txrx_stats.h>
bings0e03a982018-05-09 08:40:59 +080063#include "cdp_txrx_flow_ctrl_legacy.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080064
65#include <net/addrconf.h>
66#include <linux/wireless.h>
67#include <net/cfg80211.h>
68#include <linux/inetdevice.h>
69#include <net/addrconf.h>
70#include "wlan_hdd_cfg80211.h"
71#include "wlan_hdd_ext_scan.h"
72#include "wlan_hdd_p2p.h"
73#include <linux/rtnetlink.h>
74#include "sap_api.h"
75#include <linux/semaphore.h>
76#include <linux/ctype.h>
77#include <linux/compat.h>
Arunk Khandavalli830c9692018-03-22 12:17:40 +053078#include <linux/reboot.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080079#ifdef MSM_PLATFORM
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080080#include <soc/qcom/subsystem_restart.h>
81#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080082#include <wlan_hdd_hostapd.h>
83#include <wlan_hdd_softap_tx_rx.h>
Jeff Johnson8bb61112018-03-31 13:33:54 -070084#include <wlan_hdd_green_ap.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080085#include "cfg_api.h"
86#include "qwlan_version.h"
87#include "wma_types.h"
88#include "wlan_hdd_tdls.h"
89#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053090#include "cds_regdomain.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080091#endif /* FEATURE_WLAN_CH_AVOID */
Dustin Brownce46d1d2017-08-15 13:34:24 -070092#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070093#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -080094#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080095#include "wlan_hdd_nan.h"
96#include "wlan_hdd_debugfs.h"
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053097#include "wlan_hdd_debugfs_csr.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080098#include "wlan_hdd_driver_ops.h"
99#include "epping_main.h"
Poddar, Siddarth34872782017-08-10 14:08:51 +0530100#include "wlan_hdd_data_stall_detection.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800101
102#include <wlan_hdd_ipa.h>
103#include "hif.h"
104#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800105#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700106#include "wlan_hdd_tsf.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530107#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700108#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700109#include "wlan_hdd_lpass.h"
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530110#include "nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700111#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530112#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800113#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800114#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530115#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800116#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800117#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530118#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530119#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800120#include "os_if_wifi_pos.h"
121#include "wifi_pos_api.h"
122#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800123#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700124#include "os_if_nan.h"
125#include "nan_public_structs.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700126#include "wlan_reg_ucfg_api.h"
bings81fe50a2017-11-27 14:33:26 +0800127#include "wlan_dfs_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700128#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530129#include "sme_power_save_api.h"
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +0530130#include "enet.h"
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700131#include <cdp_txrx_cmn_struct.h>
Mohit Khanna70322002018-05-15 19:21:32 -0700132#include <dp_txrx.h>
Amar Singhal0928b192017-12-01 10:50:54 -0800133#include "wlan_hdd_sysfs.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530134#include "wlan_disa_ucfg_api.h"
Wu Gao52084c12018-05-17 20:47:11 +0800135#include "wlan_disa_obj_mgmt_api.h"
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +0530136#include "wlan_action_oui_ucfg_api.h"
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +0530137#include "wlan_ipa_ucfg_api.h"
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530138#include <target_if.h>
Alok Kumarb64650c2018-03-23 17:05:11 +0530139#include "wlan_hdd_nud_tracking.h"
Nachiket Kukaded0dd62e2018-05-21 18:39:22 +0530140#include "wlan_hdd_apf.h"
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -0700141#include "wlan_hdd_twt.h"
Rachit Kankane0dc3e852018-05-07 17:33:42 +0530142#include "qc_sap_ioctl.h"
Sandeep Puligillac5609d52018-05-17 19:23:41 -0700143#include "wlan_mlme_main.h"
Wu Gaoe5689792018-07-05 19:20:13 +0800144#include "wlan_p2p_cfg_api.h"
Wu Gaobdb7f272018-07-05 19:33:26 +0800145#include "wlan_tdls_cfg_api.h"
Qiwei Caie689a262018-07-26 15:50:22 +0800146#include <wlan_hdd_rssi_monitor.h>
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +0530147#include "wlan_mlme_ucfg_api.h"
Sourav Mohapatra113685f2018-08-29 14:21:55 +0530148#include "wlan_fwol_ucfg_api.h"
Krunal Sonie71838d2018-09-27 10:45:05 -0700149#include "wlan_policy_mgr_ucfg.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530150#ifdef CNSS_GENL
151#include <net/cnss_nl.h>
152#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800153#include "wlan_reg_ucfg_api.h"
Zhang Qian47e22ce2018-01-04 15:38:38 +0800154#include "wlan_ocb_ucfg_api.h"
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -0800155#include <wlan_hdd_spectralscan.h>
gaurank kathpalia4a205fc2018-09-15 00:59:15 +0530156#include "wlan_green_ap_ucfg_api.h"
Liangwei Dong3abfe8f2018-09-20 02:25:44 -0400157#include <wlan_p2p_ucfg_api.h>
158
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800159#ifdef MODULE
160#define WLAN_MODULE_NAME module_name(THIS_MODULE)
161#else
162#define WLAN_MODULE_NAME "wlan"
163#endif
164
165#ifdef TIMER_MANAGER
166#define TIMER_MANAGER_STR " +TIMER_MANAGER"
167#else
168#define TIMER_MANAGER_STR ""
169#endif
170
171#ifdef MEMORY_DEBUG
172#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
173#else
174#define MEMORY_DEBUG_STR ""
175#endif
176
Dustin Brownc1034df2018-02-07 14:51:32 -0800177#ifdef PANIC_ON_BUG
178#define PANIC_ON_BUG_STR " +PANIC_ON_BUG"
179#else
180#define PANIC_ON_BUG_STR ""
181#endif
182
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530183bool g_is_system_reboot_triggered;
Sachin Ahujadddd2632017-03-07 19:07:24 +0530184int wlan_start_ret_val;
185static DECLARE_COMPLETION(wlan_start_comp);
186static unsigned int dev_num = 1;
187static struct cdev wlan_hdd_state_cdev;
188static struct class *class;
189static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530190#ifndef MODULE
191static struct gwlan_loader *wlan_loader;
192static ssize_t wlan_boot_cb(struct kobject *kobj,
193 struct kobj_attribute *attr,
194 const char *buf, size_t count);
195struct gwlan_loader {
196 bool loaded_state;
197 struct kobject *boot_wlan_obj;
198 struct attribute_group *attr_group;
199};
200
201static struct kobj_attribute wlan_boot_attribute =
202 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
203
204static struct attribute *attrs[] = {
205 &wlan_boot_attribute.attr,
206 NULL,
207};
208
209#define MODULE_INITIALIZED 1
Qun Zhang4a83a462018-09-11 16:28:51 +0800210
211#ifdef MULTI_IF_NAME
212#define WLAN_LOADER_NAME "boot_" MULTI_IF_NAME
213#else
214#define WLAN_LOADER_NAME "boot_wlan"
215#endif
Arun Khandavallifae92942016-08-01 13:31:08 +0530216#endif
217
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530218#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
219#define MAX_OPS_NAME_STRING_SIZE 20
Rajeev Kumar6d0b2ea2017-12-26 17:55:33 -0800220#define RATE_LIMIT_ERROR_LOG (256)
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530221
222static qdf_timer_t hdd_drv_ops_inactivity_timer;
Dustin Brown45ed4bb2017-12-18 12:00:13 -0800223static struct task_struct *hdd_drv_ops_task;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530224static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
225
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800226/* the Android framework expects this param even though we don't use it */
227#define BUF_LEN 20
228static char fwpath_buffer[BUF_LEN];
229static struct kparam_string fwpath = {
230 .string = fwpath_buffer,
231 .maxlen = BUF_LEN,
232};
233
234static char *country_code;
235static int enable_11d = -1;
236static int enable_dfs_chan_scan = -1;
237
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800238/*
239 * spinlock for synchronizing asynchronous request/response
240 * (full description of use in wlan_hdd_main.h)
241 */
242DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530243DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800244
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800245#define WLAN_NLINK_CESIUM 30
246
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530247static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800248
249#define WOW_MAX_FILTER_LISTS 1
250#define WOW_MAX_FILTERS_PER_LIST 4
251#define WOW_MIN_PATTERN_SIZE 6
252#define WOW_MAX_PATTERN_SIZE 64
253
Bala Venkatesh110b03e2018-07-10 16:02:08 +0530254/* max peer can be tdls peers + self peer + bss peer */
255#define HDD_MAX_VDEV_PEER_COUNT (HDD_MAX_NUM_TDLS_STA + 2)
Sourav Mohapatra808e3d42018-07-04 09:34:23 +0530256#define IS_IDLE_STOP (!cds_is_driver_unloading() && \
257 !cds_is_driver_recovering() && !cds_is_driver_loading())
Bala Venkatesh110b03e2018-07-10 16:02:08 +0530258
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800259#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
260static const struct wiphy_wowlan_support wowlan_support_reg_init = {
261 .flags = WIPHY_WOWLAN_ANY |
262 WIPHY_WOWLAN_MAGIC_PKT |
263 WIPHY_WOWLAN_DISCONNECT |
264 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
265 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
266 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
267 WIPHY_WOWLAN_4WAY_HANDSHAKE |
268 WIPHY_WOWLAN_RFKILL_RELEASE,
269 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
270 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
271 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
272};
273#endif
274
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700275static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
276 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
277 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
278 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
279 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
280 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
281 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
282 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
283 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
284 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
285 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
286 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
287 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
288 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
289 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
290 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
291 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
292 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
293 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
294 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
295 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
296 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
297 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
298 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
299 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
300 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
301 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
302 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
303 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
304 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
305 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
306 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
307 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
308 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
309 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700310 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700311 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700312 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530313 [QDF_MODULE_ID_GREEN_AP] = {QDF_TRACE_LEVEL_ALL},
Zhang Qian47e22ce2018-01-04 15:38:38 +0800314 [QDF_MODULE_ID_OCB] = {QDF_TRACE_LEVEL_ALL},
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530315 [QDF_MODULE_ID_IPA] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +0530316 [QDF_MODULE_ID_ACTION_OUI] = {QDF_TRACE_LEVEL_ALL},
Dustin Brown84f46ea2018-02-15 11:57:36 -0800317 [QDF_MODULE_ID_CONFIG] = {QDF_TRACE_LEVEL_ALL},
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +0530318 [QDF_MODULE_ID_MLME] = {QDF_TRACE_LEVEL_ALL},
Ashish Kumar Dhanotiya8d039c82018-07-11 20:41:14 +0530319 [QDF_MODULE_ID_TARGET] = {QDF_TRACE_LEVEL_ALL},
Sourav Mohapatra113685f2018-08-29 14:21:55 +0530320 [QDF_MODULE_ID_FWOL] = {QDF_TRACE_LEVEL_ALL},
Abhishek Singh0b0105f2018-09-25 10:44:16 +0530321 [QDF_MODULE_ID_SM_ENGINE] = {QDF_TRACE_LEVEL_ALL},
322 [QDF_MODULE_ID_CMN_MLME] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700323};
324
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530325struct notifier_block hdd_netdev_notifier;
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530326struct notifier_block system_reboot_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800327
328struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800329#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700330static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800331#endif
332
Sachin Ahujadddd2632017-03-07 19:07:24 +0530333void hdd_start_complete(int ret)
334{
335 wlan_start_ret_val = ret;
336
337 complete(&wlan_start_comp);
338}
339
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800340/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530341 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700342 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530343 *
344 * Return: none
345 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700346static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530347{
Jeff Johnson9d295242017-08-29 14:39:48 -0700348 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530349
Dustin Brown920397d2017-12-13 16:27:50 -0800350 hdd_for_each_adapter(hdd_ctx, adapter)
351 hdd_send_rps_ind(adapter);
Nirav Shahbd36b062016-07-18 11:12:59 +0530352}
353
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530354#ifdef QCA_HL_NETDEV_FLOW_CONTROL
355void wlan_hdd_mod_fc_timer(struct hdd_adapter *adapter,
356 enum netif_action_type action)
357{
358 if (!adapter->tx_flow_timer_initialized)
359 return;
360
361 if (action == WLAN_WAKE_NON_PRIORITY_QUEUE) {
362 qdf_mc_timer_stop(&adapter->tx_flow_control_timer);
363 } else if (action == WLAN_STOP_NON_PRIORITY_QUEUE) {
364 QDF_STATUS status =
365 qdf_mc_timer_start(&adapter->tx_flow_control_timer,
366 WLAN_HDD_TX_FLOW_CONTROL_OS_Q_BLOCK_TIME);
367
368 if (!QDF_IS_STATUS_SUCCESS(status))
369 hdd_err("Failed to start tx_flow_control_timer");
370 else
371 adapter->
372 hdd_stats.tx_rx_stats.txflow_timer_cnt++;
373
374 adapter->hdd_stats.tx_rx_stats.txflow_pause_cnt++;
375 adapter->hdd_stats.tx_rx_stats.is_txflow_paused = true;
376 }
377}
378#endif /* QCA_HL_NETDEV_FLOW_CONTROL */
379
Alok Kumar2fad6442018-11-08 19:19:28 +0530380#ifdef MSM_PLATFORM
381void wlan_hdd_update_tcp_rx_param(struct hdd_context *hdd_ctx, void *data)
382{
383 if (!hdd_ctx) {
384 hdd_err("HDD context is null");
385 return;
386 }
387
388 if (!data) {
389 hdd_err("Data is null");
390 return;
391 }
392 if (hdd_ctx->config->enable_tcp_param_update)
393 wlan_hdd_send_tcp_param_update_event(hdd_ctx, data, 1);
394 else
395 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
396 WLAN_SVC_WLAN_TP_IND,
397 data,
398 sizeof(struct wlan_rx_tp_data));
399}
400
401void wlan_hdd_update_tcp_tx_param(struct hdd_context *hdd_ctx, void *data)
402{
403 enum wlan_tp_level next_tx_level;
404 struct wlan_tx_tp_data *tx_tp_data;
405
406 if (!hdd_ctx) {
407 hdd_err("HDD context is null");
408 return;
409 }
410
411 if (!data) {
412 hdd_err("Data is null");
413 return;
414 }
415
416 tx_tp_data = (struct wlan_tx_tp_data *)data;
417 next_tx_level = tx_tp_data->level;
418
419 if (hdd_ctx->config->enable_tcp_param_update)
420 wlan_hdd_send_tcp_param_update_event(hdd_ctx, data, 0);
421 else
422 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
423 WLAN_SVC_WLAN_TP_TX_IND,
424 &next_tx_level,
425 sizeof(next_tx_level));
426}
427
428/**
429 * wlan_hdd_send_tcp_param_update_event() - Send vendor event to update
430 * TCP parameter through Wi-Fi HAL
431 * @hdd_ctx: Pointer to HDD context
432 * @data: Parameters to update
433 * @dir: Direction(tx/rx) to update
434 *
435 * Return: None
436 */
437void wlan_hdd_send_tcp_param_update_event(struct hdd_context *hdd_ctx,
438 void *data,
439 uint8_t dir)
440{
441 struct sk_buff *vendor_event;
442 uint32_t event_len;
443 bool tcp_limit_output = false;
444 bool tcp_del_ack_ind_enabled = false;
445 bool tcp_adv_win_scl_enabled = false;
446 enum wlan_tp_level next_tp_level = WLAN_SVC_TP_NONE;
447
448 event_len = sizeof(uint8_t) + sizeof(uint8_t) + NLMSG_HDRLEN;
449
450 if (dir == 0) /*TX Flow */ {
451 struct wlan_tx_tp_data *tx_tp_data =
452 (struct wlan_tx_tp_data *)data;
453
454 next_tp_level = tx_tp_data->level;
455
456 if (tx_tp_data->tcp_limit_output) {
457 /* TCP_LIMIT_OUTPUT_BYTES */
458 event_len += sizeof(uint32_t);
459 tcp_limit_output = true;
460 }
461 } else if (dir == 1) /* RX Flow */ {
462 struct wlan_rx_tp_data *rx_tp_data =
463 (struct wlan_rx_tp_data *)data;
464
465 next_tp_level = rx_tp_data->level;
466
467 if (rx_tp_data->rx_tp_flags & TCP_DEL_ACK_IND_MASK) {
468 event_len += sizeof(uint32_t); /* TCP_DELACK_SEG */
469 tcp_del_ack_ind_enabled = true;
470 }
471 if (rx_tp_data->rx_tp_flags & TCP_ADV_WIN_SCL_MASK) {
472 event_len += sizeof(uint32_t); /* TCP_ADV_WIN_SCALE */
473 tcp_adv_win_scl_enabled = true;
474 }
475 } else {
476 hdd_err("Invalid Direction [%d]", dir);
477 return;
478 }
479
480 vendor_event =
481 cfg80211_vendor_event_alloc(
482 hdd_ctx->wiphy,
483 NULL, event_len,
484 QCA_NL80211_VENDOR_SUBCMD_THROUGHPUT_CHANGE_EVENT_INDEX,
485 GFP_KERNEL);
486
487 if (!vendor_event) {
488 hdd_err("cfg80211_vendor_event_alloc failed");
489 return;
490 }
491
492 if (nla_put_u8(
493 vendor_event,
494 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_DIRECTION,
495 dir))
496 goto tcp_param_change_nla_failed;
497
498 if (nla_put_u8(
499 vendor_event,
500 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_THROUGHPUT_LEVEL,
501 (next_tp_level == WLAN_SVC_TP_LOW ?
502 QCA_WLAN_THROUGHPUT_LEVEL_LOW :
503 QCA_WLAN_THROUGHPUT_LEVEL_HIGH)))
504 goto tcp_param_change_nla_failed;
505
506 if (tcp_limit_output &&
507 nla_put_u32(
508 vendor_event,
509 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_TCP_LIMIT_OUTPUT_BYTES,
510 (next_tp_level == WLAN_SVC_TP_LOW ?
511 TCP_LIMIT_OUTPUT_BYTES_LOW :
512 TCP_LIMIT_OUTPUT_BYTES_HI)))
513 goto tcp_param_change_nla_failed;
514
515 if (tcp_del_ack_ind_enabled &&
516 (nla_put_u32(
517 vendor_event,
518 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_TCP_DELACK_SEG,
519 (next_tp_level == WLAN_SVC_TP_LOW ?
520 TCP_DEL_ACK_LOW : TCP_DEL_ACK_HI))))
521 goto tcp_param_change_nla_failed;
522
523 if (tcp_adv_win_scl_enabled &&
524 (nla_put_u32(
525 vendor_event,
526 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_TCP_ADV_WIN_SCALE,
527 (next_tp_level == WLAN_SVC_TP_LOW ?
528 WIN_SCALE_LOW : WIN_SCALE_HI))))
529 goto tcp_param_change_nla_failed;
530
531 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
532 return;
533
534tcp_param_change_nla_failed:
535 hdd_err("nla_put api failed");
536 kfree_skb(vendor_event);
537}
538#endif /* MSM_PLATFORM */
539
Nirav Shahbd36b062016-07-18 11:12:59 +0530540/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800541 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
542 * @vdev_id: vdev_id
543 * @action: action type
544 * @reason: reason type
545 *
546 * Return: none
547 */
548void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
549 enum netif_action_type action, enum netif_reason_type reason)
550{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700551 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700552 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800553
554 if (!hdd_ctx) {
555 hdd_err("hdd ctx is NULL");
556 return;
557 }
558 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530559 wlan_hdd_mod_fc_timer(adapter, action);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800560 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800561}
562
563/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700564 * Store WLAN driver version and timestamp info in global variables such that
565 * crash debugger can extract them from driver debug symbol and crashdump for
566 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800567 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800568#ifdef BUILD_TAG
Rajeev Kumare555e2d2018-09-17 11:52:37 -0700569uint8_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 -0800570#else
Rajeev Kumare555e2d2018-09-17 11:52:37 -0700571uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR;
Naveen Rawat93836252017-06-20 16:30:59 -0700572#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800573
574/**
Liangwei Dong17bf2662018-01-05 02:02:05 -0500575 * hdd_get_valid_chan() - return current chan list from regulatory.
576 * @hdd_ctx: HDD context
577 * @chan_list: buf hold returned chan list
578 * @chan_num: input buf size and output returned chan num
579 *
580 * This function helps get current available chan list from regulatory
581 * module. It excludes the "disabled" and "invalid" channels.
582 *
583 * Return: 0 for success.
584 */
585static int hdd_get_valid_chan(struct hdd_context *hdd_ctx,
586 uint8_t *chan_list,
587 uint32_t *chan_num)
588{
589 int i = 0, j = 0;
590 struct regulatory_channel *cur_chan_list;
591 struct wlan_objmgr_pdev *pdev;
592
Dustin Brown07901ec2018-09-07 11:02:41 -0700593 if (!hdd_ctx || !hdd_ctx->pdev || !chan_list || !chan_num)
Liangwei Dong17bf2662018-01-05 02:02:05 -0500594 return -EINVAL;
595
Dustin Brown07901ec2018-09-07 11:02:41 -0700596 pdev = hdd_ctx->pdev;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500597 cur_chan_list = qdf_mem_malloc(NUM_CHANNELS *
598 sizeof(struct regulatory_channel));
599 if (!cur_chan_list)
600 return -ENOMEM;
601
602 if (wlan_reg_get_current_chan_list(pdev, cur_chan_list) !=
603 QDF_STATUS_SUCCESS) {
604 qdf_mem_free(cur_chan_list);
605 return -EINVAL;
606 }
607
608 for (i = 0; i < NUM_CHANNELS; i++) {
609 uint32_t ch = cur_chan_list[i].chan_num;
610 enum channel_state state = wlan_reg_get_channel_state(pdev,
611 ch);
612
613 if (state != CHANNEL_STATE_DISABLE &&
614 state != CHANNEL_STATE_INVALID &&
615 j < *chan_num) {
616 chan_list[j] = (uint8_t)ch;
617 j++;
618 }
619 }
620 *chan_num = j;
621 qdf_mem_free(cur_chan_list);
622 return 0;
623}
624
625/**
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530626 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
627 * @adapter: HDD adapter
628 * @chan_number: Channel number
629 * @chan_bw: Bandwidth
630 *
631 * Checks if the given bandwidth is valid for the given channel number.
632 *
633 * Return: 0 for success, non-zero for failure
634 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700635int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530636 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800637 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530638{
Liangwei Dong17bf2662018-01-05 02:02:05 -0500639 uint8_t chan[NUM_CHANNELS];
640 uint32_t len = NUM_CHANNELS, i;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530641 bool found = false;
Jeff Johnson16528362018-06-14 12:34:16 -0700642 mac_handle_t mac_handle;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500643 int ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530644
Jeff Johnson16528362018-06-14 12:34:16 -0700645 mac_handle = hdd_adapter_get_mac_handle(adapter);
646 if (!mac_handle) {
647 hdd_err("Invalid MAC handle");
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530648 return -EINVAL;
649 }
650
Liangwei Dong17bf2662018-01-05 02:02:05 -0500651 ret = hdd_get_valid_chan(adapter->hdd_ctx, chan,
652 &len);
653 if (ret) {
654 hdd_err("error %d in getting valid channel list", ret);
655 return ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530656 }
657
658 for (i = 0; i < len; i++) {
659 if (chan[i] == chan_number) {
660 found = true;
661 break;
662 }
663 }
664
665 if (found == false) {
666 hdd_err("Channel not in driver's valid channel list");
667 return -EOPNOTSUPP;
668 }
669
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700670 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
671 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530672 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
673 return -EINVAL;
674 }
675
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700676 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530677 if (chan_bw == CH_WIDTH_80MHZ) {
678 hdd_err("BW80 not possible in 2.4GHz band");
679 return -EINVAL;
680 }
681 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
682 (chan_bw != CH_WIDTH_MAX)) {
683 hdd_err("Only BW20 possible on channel 14");
684 return -EINVAL;
685 }
686 }
687
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700688 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530689 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
690 (chan_bw != CH_WIDTH_MAX)) {
691 hdd_err("Only BW20 possible on channel 165");
692 return -EINVAL;
693 }
694 }
695
696 return 0;
697}
698
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530699/**
700 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
701 *
702 * Block the unloading of the driver (or) interface up until the
703 * cds recovery is completed
704 *
705 * Return: true for recovery completion else false
706 */
707static bool hdd_wait_for_recovery_completion(void)
708{
709 int retry = 0;
710
711 /* Wait for recovery to complete */
712 while (cds_is_driver_recovering()) {
713 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
714 hdd_err("Recovery in progress; wait here!!!");
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530715
716 if (g_is_system_reboot_triggered) {
717 hdd_info("System Reboot happening ignore unload!!");
718 return false;
719 }
720
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530721 msleep(1000);
722 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
723 hdd_err("SSR never completed, error");
724 /*
725 * Trigger the bug_on in the internal builds, in the
726 * customer builds self-recovery will be enabled
727 * in those cases just return error.
728 */
729 if (cds_is_self_recovery_enabled())
730 return false;
731 QDF_BUG(0);
732 }
733 }
734
735 hdd_info("Recovery completed successfully!");
736 return true;
737}
738
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530739
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800740static int __hdd_netdev_notifier_call(struct notifier_block *nb,
741 unsigned long state, void *data)
742{
743#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
744 struct netdev_notifier_info *dev_notif_info = data;
745 struct net_device *dev = dev_notif_info->dev;
746#else
747 struct net_device *dev = data;
748#endif
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530749 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700750 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800751
Dustin Brownfdf17c12018-03-14 12:55:34 -0700752 hdd_enter_dev(dev);
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800753
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800754 if (!dev->ieee80211_ptr) {
Dustin Brownaeb55642018-07-30 17:20:32 -0700755 hdd_debug("ieee80211_ptr is null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800756 return NOTIFY_DONE;
757 }
758
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530759 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
760 if (!hdd_ctx) {
761 hdd_err("HDD Context is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800762 return NOTIFY_DONE;
763 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800764
765 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -0700766 hdd_debug("%s: Driver module is closed", __func__);
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800767 return NOTIFY_DONE;
768 }
769
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530770 /* Make sure that this callback corresponds to our device. */
771 adapter = hdd_get_adapter_by_iface_name(hdd_ctx, dev->name);
772 if (!adapter) {
Dustin Brownaeb55642018-07-30 17:20:32 -0700773 hdd_debug("failed to look up adapter for '%s'", dev->name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800774 return NOTIFY_DONE;
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530775 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800776
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530777 if (adapter != WLAN_HDD_GET_PRIV_PTR(dev)) {
778 hdd_err("HDD adapter mismatch!");
779 return NOTIFY_DONE;
780 }
781
Dustin Brownaeb55642018-07-30 17:20:32 -0700782 if (cds_is_driver_recovering()) {
783 hdd_debug("Driver is recovering");
784 return NOTIFY_DONE;
785 }
786
787 if (cds_is_driver_in_bad_state()) {
788 hdd_debug("Driver is in failed recovery state");
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530789 return NOTIFY_DONE;
790 }
791
792 hdd_debug("%s New Net Device State = %lu", dev->name, state);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800793
794 switch (state) {
795 case NETDEV_REGISTER:
796 break;
797
798 case NETDEV_UNREGISTER:
799 break;
800
801 case NETDEV_UP:
Jeff Johnson16528362018-06-14 12:34:16 -0700802 sme_ch_avoid_update_req(hdd_ctx->mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800803 break;
804
805 case NETDEV_DOWN:
806 break;
807
808 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700809 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800810 complete(&adapter->linkup_event_var);
811 break;
812
813 case NETDEV_GOING_DOWN:
Dustin Brown89fa06e2018-09-07 10:47:27 -0700814 if (ucfg_scan_get_vdev_status(adapter->vdev) !=
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700815 SCAN_NOT_IN_PROGRESS) {
Dustin Brown07901ec2018-09-07 11:02:41 -0700816 wlan_abort_scan(hdd_ctx->pdev, INVAL_PDEV_ID,
817 adapter->session_id, INVALID_SCAN_ID,
818 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800819 }
Min Liu9be5d4a2018-05-17 11:51:53 +0800820 cds_flush_work(&adapter->scan_block_work);
821 /* Need to clean up blocked scan request */
822 wlan_hdd_cfg80211_scan_block_cb(&adapter->scan_block_work);
Min Liu9be5d4a2018-05-17 11:51:53 +0800823 hdd_debug("Scan is not Pending from user");
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530824 /*
825 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
826 * of return status of hdd_stop call, kernel resets the IFF_UP
827 * flag after which driver does not send the cfg80211_scan_done.
828 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
829 */
Dustin Brown07901ec2018-09-07 11:02:41 -0700830 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800831 break;
832
833 default:
834 break;
835 }
836
837 return NOTIFY_DONE;
838}
839
840/**
841 * hdd_netdev_notifier_call() - netdev notifier callback function
842 * @nb: pointer to notifier block
843 * @state: state
844 * @ndev: ndev pointer
845 *
846 * Return: 0 on success, error number otherwise.
847 */
848static int hdd_netdev_notifier_call(struct notifier_block *nb,
849 unsigned long state,
850 void *ndev)
851{
852 int ret;
853
854 cds_ssr_protect(__func__);
855 ret = __hdd_netdev_notifier_call(nb, state, ndev);
856 cds_ssr_unprotect(__func__);
857
858 return ret;
859}
860
861struct notifier_block hdd_netdev_notifier = {
862 .notifier_call = hdd_netdev_notifier_call,
863};
864
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530865static int system_reboot_notifier_call(struct notifier_block *nb,
866 unsigned long msg_type, void *_unused)
867{
868 switch (msg_type) {
869 case SYS_DOWN:
870 case SYS_HALT:
871 case SYS_POWER_OFF:
872 g_is_system_reboot_triggered = true;
873 hdd_info("reboot, reason: %ld", msg_type);
874 break;
875 default:
876 break;
877 }
878
879 return NOTIFY_OK;
880}
881
882struct notifier_block system_reboot_notifier = {
883 .notifier_call = system_reboot_notifier_call,
884};
885
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800886/* variable to hold the insmod parameters */
887static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800888
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530889static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700890int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530891
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800892/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800893static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800894
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530895/**
896 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
897 * @ch_width: NL channel width
898 *
899 * Converts the NL channel width to the driver's internal representation
900 *
901 * Return: Converted channel width. In case of non matching NL channel width,
902 * CH_WIDTH_MAX will be returned.
903 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800904enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530905{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800906 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700907
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800908 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530909 switch (ch_width) {
910 case NL80211_CHAN_WIDTH_20_NOHT:
911 case NL80211_CHAN_WIDTH_20:
912 return CH_WIDTH_20MHZ;
913 case NL80211_CHAN_WIDTH_40:
914 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530915 case NL80211_CHAN_WIDTH_80:
916 return CH_WIDTH_80MHZ;
917 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800918 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
919 return CH_WIDTH_80P80MHZ;
920 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
921 return CH_WIDTH_160MHZ;
922 else
923 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530924 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800925 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
926 return CH_WIDTH_160MHZ;
927 else
928 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530929 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800930 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530931 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800932 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530933 default:
934 hdd_err("Invalid channel width %d, setting to default",
935 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800936 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530937 }
938}
939
Dustin Brown56377e12018-10-10 17:04:04 -0700940QDF_STATUS hdd_nl_to_qdf_iface_type(enum nl80211_iftype nl_type,
941 enum QDF_OPMODE *out_qdf_type)
942{
943 switch (nl_type) {
944 case NL80211_IFTYPE_ADHOC:
945 *out_qdf_type = QDF_IBSS_MODE;
946 break;
947 case NL80211_IFTYPE_AP:
948 *out_qdf_type = QDF_SAP_MODE;
949 break;
950 case NL80211_IFTYPE_MONITOR:
951 *out_qdf_type = QDF_MONITOR_MODE;
952 break;
953 case NL80211_IFTYPE_OCB:
954 *out_qdf_type = QDF_OCB_MODE;
955 break;
956 case NL80211_IFTYPE_P2P_CLIENT:
957 *out_qdf_type = QDF_P2P_CLIENT_MODE;
958 break;
959 case NL80211_IFTYPE_P2P_DEVICE:
960 *out_qdf_type = QDF_P2P_DEVICE_MODE;
961 break;
962 case NL80211_IFTYPE_P2P_GO:
963 *out_qdf_type = QDF_P2P_GO_MODE;
964 break;
965 case NL80211_IFTYPE_STATION:
966 *out_qdf_type = QDF_STA_MODE;
967 break;
968 case NL80211_IFTYPE_WDS:
969 *out_qdf_type = QDF_WDS_MODE;
970 break;
971 default:
972 hdd_err("Invalid nl80211 interface type %d", nl_type);
973 return QDF_STATUS_E_INVAL;
974 }
975
976 return QDF_STATUS_SUCCESS;
977}
978
Jeff Johnson16528362018-06-14 12:34:16 -0700979uint8_t wlan_hdd_find_opclass(mac_handle_t mac_handle, uint8_t channel,
980 uint8_t bw_offset)
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530981{
982 uint8_t opclass = 0;
983
Jeff Johnson16528362018-06-14 12:34:16 -0700984 sme_get_opclass(mac_handle, channel, bw_offset, &opclass);
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530985 return opclass;
986}
987
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800988/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530989 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530990 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800991 * @bitmask: Bitmask of log levels to be enabled
992 *
993 * Called immediately after the cfg.ini is read in order to configure
994 * the desired trace levels.
995 *
996 * Return: None
997 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530998int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800999{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301000 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05301001 int qdf_print_idx = -1;
1002 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001003 /*
1004 * if the bitmask is the default value, then a bitmask was not
1005 * specified in cfg.ini, so leave the logging level alone (it
1006 * will remain at the "compiled in" default value)
1007 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001008 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301009 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001010
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05301011 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001012
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05301013 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301014 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05301015 QDF_TRACE_LEVEL_NONE, 0);
1016
1017 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301018 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001019 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +05301020 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001021 while (0 != bitmask) {
1022 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05301023 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301024 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05301025 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301026 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001027 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001028
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001029 level++;
1030 bitmask >>= 1;
1031 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301032 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001033}
1034
Dustin Brownda351e32018-07-23 15:48:22 -07001035int __wlan_hdd_validate_context(struct hdd_context *hdd_ctx, const char *func)
Chris Guo1751acf2017-07-03 14:09:01 +08001036{
Dustin Brownda351e32018-07-23 15:48:22 -07001037 if (!hdd_ctx) {
1038 hdd_err("HDD context is null (via %s)", func);
1039 return -ENODEV;
1040 }
1041
1042 if (!hdd_ctx->config) {
1043 hdd_err("HDD config is null (via %s)", func);
Chris Guo1751acf2017-07-03 14:09:01 +08001044 return -ENODEV;
1045 }
1046
1047 if (cds_is_driver_recovering()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001048 hdd_debug("Recovery in progress (via %s); state:0x%x",
1049 func, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001050 return -EAGAIN;
1051 }
1052
Yue Ma9f275d92017-09-14 16:58:41 -07001053 if (cds_is_load_or_unload_in_progress()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001054 hdd_debug("Load/unload in progress (via %s); state:0x%x",
1055 func, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001056 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -07001057 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05301058
Dustin Brownda351e32018-07-23 15:48:22 -07001059 if (hdd_ctx->start_modules_in_progress) {
1060 hdd_debug("Start modules in progress (via %s)", func);
1061 return -EAGAIN;
1062 }
1063
1064 if (hdd_ctx->stop_modules_in_progress) {
1065 hdd_debug("Stop modules in progress (via %s)", func);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05301066 return -EAGAIN;
1067 }
1068
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301069 if (cds_is_driver_in_bad_state()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001070 hdd_debug("Driver in bad state (via %s); state:0x%x",
1071 func, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +05301072 return -EAGAIN;
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301073 }
1074
Arunk Khandavalli2859fa12018-02-14 10:46:26 +05301075 if (cds_is_fw_down()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001076 hdd_debug("FW is down (via %s); state:0x%x",
1077 func, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +05301078 return -EAGAIN;
Arunk Khandavalli2859fa12018-02-14 10:46:26 +05301079 }
1080
Liangwei Dong858feb12018-05-21 01:52:46 -04001081 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
Dustin Brownda351e32018-07-23 15:48:22 -07001082 hdd_debug("Driver mode change in progress (via %s)", func);
Liangwei Dong858feb12018-05-21 01:52:46 -04001083 return -EAGAIN;
1084 }
1085
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001086 return 0;
1087}
1088
Dustin Browna8700cc2018-08-07 12:04:47 -07001089int __hdd_validate_adapter(struct hdd_adapter *adapter, const char *func)
Dustin Brownf13b8c32017-05-19 17:23:08 -07001090{
1091 if (!adapter) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001092 hdd_err("adapter is null (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001093 return -EINVAL;
1094 }
1095
1096 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001097 hdd_err("bad adapter magic (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001098 return -EINVAL;
1099 }
1100
1101 if (!adapter->dev) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001102 hdd_err("adapter net_device is null (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001103 return -EINVAL;
1104 }
1105
1106 if (!(adapter->dev->flags & IFF_UP)) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001107 hdd_debug_rl("adapter '%s' is not up (via %s)",
1108 adapter->dev->name, func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001109 return -EAGAIN;
1110 }
1111
Dustin Browna8700cc2018-08-07 12:04:47 -07001112 return __wlan_hdd_validate_session_id(adapter->session_id, func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001113}
1114
Dustin Brown63500612018-08-07 11:36:09 -07001115int __wlan_hdd_validate_session_id(uint8_t session_id, const char *func)
1116{
1117 if (session_id == CSR_SESSION_ID_INVALID) {
1118 hdd_debug_rl("adapter is not up (via %s)", func);
1119 return -EINVAL;
1120 }
1121
1122 if (session_id >= CSR_ROAM_SESSION_MAX) {
1123 hdd_err("bad session Id:%u (via %s)", session_id, func);
1124 return -EINVAL;
1125 }
1126
1127 return 0;
1128}
1129
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05301130QDF_STATUS __wlan_hdd_validate_mac_address(struct qdf_mac_addr *mac_addr,
1131 const char *func)
1132{
1133 if (!mac_addr) {
1134 hdd_err("Received NULL mac address (via %s)", func);
1135 return QDF_STATUS_E_INVAL;
1136 }
1137
1138 if (qdf_is_macaddr_zero(mac_addr)) {
1139 hdd_err("MAC is all zero (via %s)", func);
1140 return QDF_STATUS_E_INVAL;
1141 }
1142
1143 if (qdf_is_macaddr_broadcast(mac_addr)) {
1144 hdd_err("MAC is Broadcast (via %s)", func);
1145 return QDF_STATUS_E_INVAL;
1146 }
1147
1148 if (QDF_NET_IS_MAC_MULTICAST(mac_addr->bytes)) {
1149 hdd_err("MAC is Multicast (via %s)", func);
1150 return QDF_STATUS_E_INVAL;
1151 }
1152
1153 return QDF_STATUS_SUCCESS;
1154}
1155
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001156/**
Arun Khandavallica892f62017-05-26 14:25:50 +05301157 * wlan_hdd_validate_modules_state() - Check modules status
1158 * @hdd_ctx: HDD context pointer
1159 *
1160 * Check's the driver module's state and returns true if the
1161 * modules are enabled returns false if modules are closed.
1162 *
1163 * Return: True if modules are enabled or false.
1164 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001165bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +05301166{
1167 mutex_lock(&hdd_ctx->iface_change_lock);
1168 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
1169 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown5e89ef82018-03-14 11:50:23 -07001170 hdd_info("Modules not enabled, Present status: %d",
1171 hdd_ctx->driver_status);
Arun Khandavallica892f62017-05-26 14:25:50 +05301172 return false;
1173 }
1174 mutex_unlock(&hdd_ctx->iface_change_lock);
1175 return true;
1176}
1177
1178/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001179 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -07001180 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001181 *
1182 * This function sets the IBSS power save config parameters to WMA
1183 * which will send it to firmware if FW supports IBSS power save
1184 * before vdev start.
1185 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301186 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001187 * on failure.
1188 */
Jeff Johnson9d295242017-08-29 14:39:48 -07001189QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001190{
1191 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001192 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001193
1194 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001195 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301196 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001197 }
1198
Jeff Johnson1b780e42017-10-31 14:11:45 -07001199 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001200 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
1201 hdd_ctx->config->ibssATIMWinSize,
1202 VDEV_CMD);
1203 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001204 hdd_err("atim window set failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301205 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001206 }
1207
Jeff Johnson1b780e42017-10-31 14:11:45 -07001208 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001209 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
1210 hdd_ctx->config->isIbssPowerSaveAllowed,
1211 VDEV_CMD);
1212 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001213 hdd_err("power save allow failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001214 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301215 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001216 }
1217
Jeff Johnson1b780e42017-10-31 14:11:45 -07001218 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001219 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
1220 hdd_ctx->config->
1221 isIbssPowerCollapseAllowed, VDEV_CMD);
1222 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001223 hdd_err("power collapse allow failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001224 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301225 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001226 }
1227
Jeff Johnson1b780e42017-10-31 14:11:45 -07001228 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001229 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
1230 hdd_ctx->config->isIbssAwakeOnTxRx,
1231 VDEV_CMD);
1232 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001233 hdd_err("set awake on tx/rx failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301234 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001235 }
1236
Jeff Johnson1b780e42017-10-31 14:11:45 -07001237 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001238 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
1239 hdd_ctx->config->ibssInactivityCount,
1240 VDEV_CMD);
1241 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001242 hdd_err("set inactivity time failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301243 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001244 }
1245
Jeff Johnson1b780e42017-10-31 14:11:45 -07001246 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001247 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
1248 hdd_ctx->config->ibssTxSpEndInactivityTime,
1249 VDEV_CMD);
1250 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001251 hdd_err("set txsp end failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001252 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301253 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001254 }
1255
Jeff Johnson1b780e42017-10-31 14:11:45 -07001256 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001257 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
1258 hdd_ctx->config->ibssPsWarmupTime,
1259 VDEV_CMD);
1260 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001261 hdd_err("set ps warmup failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001262 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301263 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001264 }
1265
Jeff Johnson1b780e42017-10-31 14:11:45 -07001266 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001267 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
1268 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
1269 VDEV_CMD);
1270 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001271 hdd_err("set 1rx chain atim failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001272 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301273 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001274 }
1275
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301276 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001277}
1278
Yue Macd359b72017-10-03 15:21:00 -07001279#ifdef FEATURE_RUNTIME_PM
1280/**
1281 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
1282 * @hdd_ctx: HDD context
1283 *
1284 * Return: None
1285 */
1286static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
1287{
1288 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1289
Yue Macd359b72017-10-03 15:21:00 -07001290 qdf_runtime_lock_init(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001291 qdf_runtime_lock_init(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001292
Dustin Brown07901ec2018-09-07 11:02:41 -07001293 wlan_scan_runtime_pm_init(hdd_ctx->pdev);
Yue Macd359b72017-10-03 15:21:00 -07001294}
1295
1296/**
1297 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1298 * @hdd_ctx: HDD Context
1299 *
1300 * Return: None
1301 */
1302static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1303{
1304 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1305
Yue Macd359b72017-10-03 15:21:00 -07001306 qdf_runtime_lock_deinit(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001307 qdf_runtime_lock_deinit(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001308
Dustin Brown07901ec2018-09-07 11:02:41 -07001309 wlan_scan_runtime_pm_deinit(hdd_ctx->pdev);
Yue Macd359b72017-10-03 15:21:00 -07001310}
1311
Yue Macd359b72017-10-03 15:21:00 -07001312#else /* FEATURE_RUNTIME_PM */
1313static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1314static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Yue Macd359b72017-10-03 15:21:00 -07001315#endif /* FEATURE_RUNTIME_PM */
1316
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001317#define INTF_MACADDR_MASK 0x7
1318
1319/**
1320 * hdd_update_macaddr() - update mac address
1321 * @config: hdd configuration
1322 * @hw_macaddr: mac address
1323 *
1324 * Mac address for multiple virtual interface is found as following
1325 * i) The mac address of the first interface is just the actual hw mac address.
1326 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
1327 * define the mac address for the remaining interfaces and locally
1328 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1329 * supported virtual interfaces, right now this is 0x07 (meaning 8
1330 * interface).
1331 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1332 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1333 *
1334 * Return: None
1335 */
1336void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301337 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001338{
1339 int8_t i;
1340 uint8_t macaddr_b3, tmp_br3;
1341
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301342 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301343 QDF_MAC_ADDR_SIZE);
1344 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301345 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301346 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001347 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1348 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1349 INTF_MACADDR_MASK;
1350 macaddr_b3 += tmp_br3;
1351
1352 /* XOR-ing bit-24 of the mac address. This will give enough
1353 * mac address range before collision
1354 */
1355 macaddr_b3 ^= (1 << 7);
1356
1357 /* Set locally administered bit */
1358 config->intfMacAddr[i].bytes[0] |= 0x02;
1359 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001360 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001361 MAC_ADDRESS_STR, i,
1362 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1363 }
1364}
1365
Kabilan Kannan44a58372017-12-06 18:16:11 -08001366static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1367{
Dustin Brown1dbefe62018-09-11 16:32:03 -07001368 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001369 struct tdls_start_params tdls_cfg;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001370 struct hdd_config *cfg = hdd_ctx->config;
1371 QDF_STATUS status;
1372
Dustin Brown1dbefe62018-09-11 16:32:03 -07001373 cfg_tdls_set_vdev_nss_2g(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001374 CFG_TDLS_NSS(cfg->vdev_type_nss_2g));
Dustin Brown1dbefe62018-09-11 16:32:03 -07001375 cfg_tdls_set_vdev_nss_5g(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001376 CFG_TDLS_NSS(cfg->vdev_type_nss_5g));
Kabilan Kannan44a58372017-12-06 18:16:11 -08001377 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
1378 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
1379 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
1380 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
1381 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1382 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1383 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1384 tdls_cfg.tdls_evt_cb_data = psoc;
Jeff Johnson1d40f5b2018-03-02 08:35:53 -08001385 tdls_cfg.tdls_peer_context = hdd_ctx;
1386 tdls_cfg.tdls_reg_peer = hdd_tdls_register_peer;
1387 tdls_cfg.tdls_dereg_peer = hdd_tdls_deregister_peer;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001388 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1389 tdls_cfg.tdls_wmm_cb_data = psoc;
1390 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1391 tdls_cfg.tdls_rx_cb_data = psoc;
1392 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1393
1394 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1395 if (status != QDF_STATUS_SUCCESS) {
1396 hdd_err("failed pmo psoc configuration");
1397 return -EINVAL;
1398 }
1399
1400 hdd_ctx->tdls_umac_comp_active = true;
1401 /* enable napier specific tdls data path */
1402 hdd_ctx->tdls_nap_active = true;
1403
1404 return 0;
1405}
1406
Wu Gaoca416ff2018-09-17 11:05:07 +08001407#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1408static void hdd_update_roam_offload(struct hdd_context *hdd_ctx,
1409 struct wma_tgt_services *cfg)
1410{
1411 bool roam_offload_enable;
1412
Dustin Brown1dbefe62018-09-11 16:32:03 -07001413 ucfg_mlme_get_roaming_offload(hdd_ctx->psoc, &roam_offload_enable);
1414 ucfg_mlme_set_roaming_offload(hdd_ctx->psoc,
Wu Gaoca416ff2018-09-17 11:05:07 +08001415 roam_offload_enable &
1416 cfg->en_roam_offload);
1417}
1418#else
1419static inline void hdd_update_roam_offload(struct hdd_context *hdd_ctx,
1420 struct wma_tgt_services *cfg)
1421{
1422}
1423#endif
1424
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001425static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001426 struct wma_tgt_services *cfg)
1427{
1428 struct hdd_config *config = hdd_ctx->config;
Wu Gao66454f12018-09-26 19:55:41 +08001429 bool arp_offload_enable;
Wu Gaobdb7f272018-07-05 19:33:26 +08001430#ifdef FEATURE_WLAN_TDLS
1431 bool tdls_support;
1432 bool tdls_off_channel;
1433 bool tdls_buffer_sta;
1434 uint32_t tdls_uapsd_mask;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05301435 bool value;
Wu Gaobdb7f272018-07-05 19:33:26 +08001436#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001437 /* Set up UAPSD */
1438 config->apUapsdEnabled &= cfg->uapsd;
1439
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001440 /* 11AX mode support */
1441 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1442 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1443 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1444
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001445 /* 11AC mode support */
1446 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1447 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1448 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001449
1450 /* ARP offload: override user setting if invalid */
Wu Gao66454f12018-09-26 19:55:41 +08001451 arp_offload_enable =
1452 ucfg_pmo_is_arp_offload_enabled(hdd_ctx->psoc);
1453 ucfg_pmo_set_arp_offload_enabled(hdd_ctx->psoc,
1454 arp_offload_enable & cfg->arp_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001455#ifdef FEATURE_WLAN_SCAN_PNO
1456 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001457 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001458 if (cfg->pno_offload)
1459 config->PnoOffload = true;
1460#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001461#ifdef FEATURE_WLAN_TDLS
Dustin Brown1dbefe62018-09-11 16:32:03 -07001462 cfg_tdls_get_support_enable(hdd_ctx->psoc, &tdls_support);
1463 cfg_tdls_set_support_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001464 tdls_support & cfg->en_tdls);
1465
Dustin Brown1dbefe62018-09-11 16:32:03 -07001466 cfg_tdls_get_off_channel_enable(hdd_ctx->psoc, &tdls_off_channel);
1467 cfg_tdls_set_off_channel_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001468 tdls_off_channel &&
1469 cfg->en_tdls_offchan);
1470
Dustin Brown1dbefe62018-09-11 16:32:03 -07001471 cfg_tdls_get_buffer_sta_enable(hdd_ctx->psoc, &tdls_buffer_sta);
1472 cfg_tdls_set_buffer_sta_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001473 tdls_buffer_sta &&
1474 cfg->en_tdls_uapsd_buf_sta);
1475
Dustin Brown1dbefe62018-09-11 16:32:03 -07001476 cfg_tdls_get_uapsd_mask(hdd_ctx->psoc, &tdls_uapsd_mask);
Wu Gaobdb7f272018-07-05 19:33:26 +08001477 if (tdls_uapsd_mask && cfg->en_tdls_uapsd_sleep_sta)
Dustin Brown1dbefe62018-09-11 16:32:03 -07001478 cfg_tdls_set_sleep_sta_enable(hdd_ctx->psoc, true);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001479 else
Dustin Brown1dbefe62018-09-11 16:32:03 -07001480 cfg_tdls_set_sleep_sta_enable(hdd_ctx->psoc, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001481#endif
Wu Gaoca416ff2018-09-17 11:05:07 +08001482 hdd_update_roam_offload(hdd_ctx, cfg);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05301483
Dustin Brown05d81302018-09-11 16:49:22 -07001484 if (ucfg_mlme_get_sap_get_peer_info(hdd_ctx->psoc, &value) ==
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05301485 QDF_STATUS_SUCCESS)
1486 value &= cfg->get_peer_info_enabled;
1487
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001488 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001489 hdd_update_tdls_config(hdd_ctx);
Jeff Johnson16528362018-06-14 12:34:16 -07001490 sme_update_tgt_services(hdd_ctx->mac_handle, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001491}
1492
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001493/**
1494 * hdd_update_vdev_nss() - sets the vdev nss
1495 * @hdd_ctx: HDD context
1496 *
1497 * Sets the Nss per vdev type based on INI
1498 *
1499 * Return: None
1500 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001501static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001502{
1503 struct hdd_config *cfg_ini = hdd_ctx->config;
1504 uint8_t max_supp_nss = 1;
Jeff Johnson16528362018-06-14 12:34:16 -07001505 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301506 QDF_STATUS status;
1507 bool bval;
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001508
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301509 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
1510 if (!QDF_IS_STATUS_SUCCESS(status))
1511 hdd_err("unable to get vht_enable2x2");
1512
1513 if (bval && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001514 max_supp_nss = 2;
Liangwei Dong22810e82018-03-15 03:42:12 -04001515 hdd_debug("max nss %d vdev_type_nss_2g %x vdev_type_nss_5g %x",
1516 max_supp_nss, cfg_ini->vdev_type_nss_2g,
1517 cfg_ini->vdev_type_nss_5g);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001518
Jeff Johnson16528362018-06-14 12:34:16 -07001519 mac_handle = hdd_ctx->mac_handle;
1520 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
1521 cfg_ini->vdev_type_nss_2g, BAND_2G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001522
Jeff Johnson16528362018-06-14 12:34:16 -07001523 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
1524 cfg_ini->vdev_type_nss_5g, BAND_5G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001525}
1526
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301527/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301528 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1529 * @hdd_ctx: HDD context
1530 *
1531 * Updates wiphy vhtcap fields
1532 *
1533 * Return: None
1534 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001535static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301536{
1537 struct ieee80211_supported_band *band_5g =
1538 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301539 QDF_STATUS status;
1540 uint8_t value = 0, value1 = 0;
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301541
1542 if (!band_5g) {
1543 hdd_debug("5GHz band disabled, skipping capability population");
1544 return;
1545 }
1546
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301547 status = ucfg_mlme_cfg_get_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
1548 &value);
1549 if (!QDF_IS_STATUS_SUCCESS(status))
1550 hdd_err("unable to get tx_bfee_ant_supp");
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301551
Abhinav Kumare057b412018-10-09 17:28:16 +05301552 band_5g->vht_cap.cap |=
1553 (value << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301554
1555 value1 = NUM_OF_SOUNDING_DIMENSIONS;
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301556 band_5g->vht_cap.cap |=
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301557 (value1 << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301558
Dustin Brown7e761c72018-07-31 13:50:17 -07001559 hdd_debug("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301560 band_5g->vht_cap.cap, value, value1);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301561}
1562
1563/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301564 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1565 * @hdd_ctx: HDD context
1566 *
1567 * Sets the DBS capability as per INI and firmware capability
1568 *
1569 * Return: None
1570 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001571static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301572{
1573 struct hdd_config *cfg_ini = hdd_ctx->config;
1574 uint8_t hw_dbs_capable = 0;
1575
Dustin Brown1dbefe62018-09-11 16:32:03 -07001576 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->psoc) &&
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001577 ((cfg_ini->dual_mac_feature_disable ==
1578 ENABLE_DBS_CXN_AND_SCAN) ||
1579 (cfg_ini->dual_mac_feature_disable ==
Tushnim Bhattacharyyaaececb22018-08-06 14:27:46 -07001580 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF) ||
1581 (cfg_ini->dual_mac_feature_disable ==
1582 ENABLE_DBS_CXN_AND_DISABLE_SIMULTANEOUS_SCAN)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301583 hw_dbs_capable = 1;
1584
Jeff Johnson16528362018-06-14 12:34:16 -07001585 sme_update_hw_dbs_capable(hdd_ctx->mac_handle, hw_dbs_capable);
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301586}
1587
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001588static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001589 struct wma_tgt_ht_cap *cfg)
1590{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301591 QDF_STATUS status;
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301592 qdf_size_t value_len;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301593 uint32_t value;
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05301594 uint8_t mpdu_density;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301595 struct mlme_ht_capabilities_info ht_cap_info;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001596 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301597 bool b_enable1x1;
Jeff Johnson16528362018-06-14 12:34:16 -07001598
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001599 /* get the MPDU density */
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05301600 status = ucfg_mlme_get_ht_mpdu_density(hdd_ctx->psoc, &mpdu_density);
1601 if (QDF_IS_STATUS_ERROR(status)) {
1602 hdd_err("could not get HT MPDU Density");
1603 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001604 }
1605
1606 /*
1607 * MPDU density:
1608 * override user's setting if value is larger
1609 * than the one supported by target
1610 */
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05301611 if (mpdu_density > cfg->mpdu_density) {
1612 status = ucfg_mlme_set_ht_mpdu_density(hdd_ctx->psoc,
1613 cfg->mpdu_density);
1614 if (QDF_IS_STATUS_ERROR(status))
1615 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001616 }
1617
1618 /* get the HT capability info */
Dustin Brown1dbefe62018-09-11 16:32:03 -07001619 status = ucfg_mlme_get_ht_cap_info(hdd_ctx->psoc, &ht_cap_info);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301620 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001621 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001622 return;
1623 }
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301624
1625 /* check and update RX STBC */
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301626 if (ht_cap_info.rx_stbc && !cfg->ht_rx_stbc)
1627 ht_cap_info.rx_stbc = cfg->ht_rx_stbc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001628
1629 /* Set the LDPC capability */
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301630 ht_cap_info.adv_coding_cap = cfg->ht_rx_ldpc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001631
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301632 if (ht_cap_info.short_gi_20_mhz && !cfg->ht_sgi_20)
1633 ht_cap_info.short_gi_20_mhz = cfg->ht_sgi_20;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001634
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301635 if (ht_cap_info.short_gi_40_mhz && !cfg->ht_sgi_40)
1636 ht_cap_info.short_gi_40_mhz = cfg->ht_sgi_40;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001637
1638 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1639 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1640
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301641 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &b_enable1x1);
1642 if (!QDF_IS_STATUS_SUCCESS(status))
1643 hdd_err("unable to get vht_enable2x2");
1644
1645 b_enable1x1 = b_enable1x1 && (cfg->num_rf_chains == 2);
1646
1647 status = ucfg_mlme_set_vht_enable2x2(hdd_ctx->psoc, b_enable1x1);
1648 if (!QDF_IS_STATUS_SUCCESS(status))
1649 hdd_err("unable to set vht_enable2x2");
1650
Abhinav Kumare057b412018-10-09 17:28:16 +05301651 if (!b_enable1x1) {
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301652 ht_cap_info.tx_stbc = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001653
1654 /* 1x1 */
1655 /* Update Rx Highest Long GI data Rate */
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301656 status = ucfg_mlme_cfg_set_vht_rx_supp_data_rate(
1657 hdd_ctx->psoc,
1658 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1);
1659 if (!QDF_IS_STATUS_SUCCESS(status))
1660 hdd_err("Failed to set rx_supp_data_rate");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001661 /* Update Tx Highest Long GI data Rate */
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301662 status = ucfg_mlme_cfg_set_vht_tx_supp_data_rate(
1663 hdd_ctx->psoc,
1664 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1);
1665 if (!QDF_IS_STATUS_SUCCESS(status))
1666 hdd_err("Failed to set tx_supp_data_rate");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001667 }
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301668 if (!(cfg->ht_tx_stbc && b_enable1x1))
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301669 ht_cap_info.tx_stbc = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001670
Dustin Brown1dbefe62018-09-11 16:32:03 -07001671 status = ucfg_mlme_set_ht_cap_info(hdd_ctx->psoc, ht_cap_info);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301672 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001673 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001674#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301675 value_len = SIZE_OF_SUPPORTED_MCS_SET;
1676 if (ucfg_mlme_get_supported_mcs_set(
1677 hdd_ctx->psoc, mcs_set,
1678 &value_len) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001679 hdd_debug("Read MCS rate set");
gaurank kathpalia18b49362018-04-15 23:12:03 +05301680 if (cfg->num_rf_chains > SIZE_OF_SUPPORTED_MCS_SET)
1681 cfg->num_rf_chains = SIZE_OF_SUPPORTED_MCS_SET;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301682
1683 if (b_enable1x1) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001684 for (value = 0; value < cfg->num_rf_chains; value++)
1685 mcs_set[value] =
1686 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1687
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301688 status = ucfg_mlme_set_supported_mcs_set(
1689 hdd_ctx->psoc,
1690 mcs_set,
1691 (qdf_size_t)SIZE_OF_SUPPORTED_MCS_SET);
1692 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001693 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001694 }
1695 }
1696#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1697}
1698
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001699static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001700 struct wma_tgt_vht_cap *cfg)
1701{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301702 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001703 struct wiphy *wiphy = hdd_ctx->wiphy;
1704 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001705 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001706 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001707 struct wma_caps_per_phy caps_per_phy;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301708 uint8_t val = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001709
Dustin Brown5e06bd32016-10-04 12:49:10 -07001710 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001711 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001712 return;
1713 }
1714
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301715 status = ucfg_mlme_update_vht_cap(hdd_ctx->psoc, cfg);
1716 if (QDF_IS_STATUS_ERROR(status))
1717 hdd_err("could not update vht capabilities");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001718
1719 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1720 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1721 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1722 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1723 else
1724 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1725
1726
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001727 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
Abhinav Kumare057b412018-10-09 17:28:16 +05301728 status = ucfg_mlme_set_vht_ch_width(hdd_ctx->psoc,
1729 VHT_CAP_160_AND_80P80_SUPP);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301730 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001731 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001732 band_5g->vht_cap.cap |=
1733 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001734 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1735 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
Abhinav Kumare057b412018-10-09 17:28:16 +05301736 status = ucfg_mlme_set_vht_ch_width(hdd_ctx->psoc,
1737 VHT_CAP_160_SUPP);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301738 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001739 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001740 band_5g->vht_cap.cap |=
1741 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001742 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1743 }
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001744
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301745 status =
1746 ucfg_mlme_cfg_get_vht_chan_width(hdd_ctx->psoc, &val);
1747 if (QDF_IS_STATUS_ERROR(status))
1748 hdd_err("could not get channel_width");
1749
1750 val = QDF_MIN(val, ch_width);
Abhinav Kumare057b412018-10-09 17:28:16 +05301751 status = ucfg_mlme_set_vht_ch_width(hdd_ctx->psoc, val);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301752 if (QDF_IS_STATUS_ERROR(status))
1753 hdd_err("could not set the channel width");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001754
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001755 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001756 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001757 hdd_debug("VHT RxLDPC capability is set");
1758 } else {
1759 /*
1760 * Get the RX LDPC capability for the NON DBS
1761 * hardware mode for 5G band
1762 */
1763 status = wma_get_caps_for_phyidx_hwmode(&caps_per_phy,
1764 HW_MODE_DBS_NONE, CDS_BAND_5GHZ);
1765 if ((QDF_IS_STATUS_SUCCESS(status)) &&
1766 (caps_per_phy.vht_5g & WMI_VHT_CAP_RX_LDPC)) {
1767 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1768 hdd_debug("VHT RX LDPC capability is set");
1769 }
1770 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001771
1772 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1773 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1774 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1775 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1776
1777 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1778 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1779
1780 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1781 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1782 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1783 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1784 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1785 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1786
1787 band_5g->vht_cap.cap |=
1788 (cfg->vht_max_ampdu_len_exp <<
1789 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1790
1791 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1792 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1793 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1794 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1795 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1796 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1797 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1798 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1799
1800 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1801 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1802
1803}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001804
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001805/**
1806 * hdd_generate_macaddr_auto() - Auto-generate mac address
1807 * @hdd_ctx: Pointer to the HDD context
1808 *
1809 * Auto-generate mac address using device serial number.
1810 * Keep the first 3 bytes of OUI as before and replace
1811 * the last 3 bytes with the lower 3 bytes of serial number.
1812 *
1813 * Return: 0 for success
1814 * Non zero failure code for errors
1815 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001816static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001817{
1818 unsigned int serialno = 0;
1819 struct qdf_mac_addr mac_addr = {
1820 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1821 };
1822
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001823 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001824 if (serialno == 0)
1825 return -EINVAL;
1826
1827 serialno &= 0x00ffffff;
1828
1829 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1830 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1831 mac_addr.bytes[5] = serialno & 0xff;
1832
1833 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1834 return 0;
1835}
1836
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301837/**
1838 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1839 * configuration to cfg_ini in HDD
1840 * @hdd_ctx: Pointer to hdd_ctx
1841 * @cfg: target configuration
1842 *
1843 * Return: None
1844 */
1845#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001846static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301847 struct wma_tgt_cfg *cfg)
1848{
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05301849 ucfg_fwol_set_is_rate_limit_enabled(hdd_ctx->psoc,
1850 cfg->is_ra_rate_limit_enabled);
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301851}
1852#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001853static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301854 struct wma_tgt_cfg *cfg)
1855{
1856}
1857#endif
1858
Jeff Johnsonf9176382018-07-17 19:15:58 -07001859static void hdd_sar_target_config(struct hdd_context *hdd_ctx,
1860 struct wma_tgt_cfg *cfg)
1861{
1862 hdd_ctx->sar_version = cfg->sar_version;
1863}
1864
Jeff Johnson8abc5932018-06-02 22:51:37 -07001865void hdd_update_tgt_cfg(hdd_handle_t hdd_handle, struct wma_tgt_cfg *cfg)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001866{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001867 int ret;
Jeff Johnsonea70b942018-07-02 09:42:31 -07001868 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301869 uint8_t temp_band_cap, band_capability;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001870 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301871 uint8_t antenna_mode;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301872 uint8_t sub_20_chan_width;
Arif Hussainee10f902017-12-27 16:30:17 -08001873 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -07001874 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301875 bool bval = false;
1876 uint8_t value = 0;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301877
gaurank kathpalia843f7c32018-07-02 18:04:14 +05301878 if (!hdd_ctx) {
1879 hdd_err("HDD context is NULL");
1880 return;
1881 }
Dustin Brownbd68fe12017-11-21 15:28:52 -08001882 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1883 if (ret) {
Dustin Brown64204d22018-08-15 16:35:19 -07001884 QDF_DEBUG_PANIC("Failed to create pdev; errno:%d", ret);
1885 return;
1886 }
1887
1888 hdd_debug("New pdev has been created with pdev_id = %u",
Dustin Brown07901ec2018-09-07 11:02:41 -07001889 hdd_ctx->pdev->pdev_objmgr.wlan_pdev_id);
Dustin Brown64204d22018-08-15 16:35:19 -07001890
Dustin Brown07901ec2018-09-07 11:02:41 -07001891 status = dispatcher_pdev_open(hdd_ctx->pdev);
Dustin Brown64204d22018-08-15 16:35:19 -07001892 if (QDF_IS_STATUS_ERROR(status)) {
1893 QDF_DEBUG_PANIC("dispatcher pdev open failed; status:%d",
1894 status);
1895 return;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301896 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001897
Sandeep Puligillab7beb472018-08-13 22:54:20 -07001898 status = hdd_component_pdev_open(hdd_ctx->pdev);
1899 if (QDF_IS_STATUS_ERROR(status)) {
1900 QDF_DEBUG_PANIC("hdd component pdev open failed; status:%d",
1901 status);
1902 return;
1903 }
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301904 cdp_pdev_set_ctrl_pdev(cds_get_context(QDF_MODULE_ID_SOC),
1905 cds_get_context(QDF_MODULE_ID_TXRX),
Dustin Brown07901ec2018-09-07 11:02:41 -07001906 (struct cdp_ctrl_objmgr_pdev *)hdd_ctx->pdev);
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301907
Dustin Brown07901ec2018-09-07 11:02:41 -07001908 wlan_pdev_set_dp_handle(hdd_ctx->pdev,
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301909 cds_get_context(QDF_MODULE_ID_TXRX));
1910
Will Huang07244172018-05-14 14:23:30 +08001911 hdd_objmgr_update_tgt_max_vdev_psoc(hdd_ctx, cfg->max_intf_count);
1912
Dustin Brown1dbefe62018-09-11 16:32:03 -07001913 ucfg_ipa_set_dp_handle(hdd_ctx->psoc,
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301914 cds_get_context(QDF_MODULE_ID_SOC));
Dustin Brown1dbefe62018-09-11 16:32:03 -07001915 ucfg_ipa_set_txrx_handle(hdd_ctx->psoc,
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301916 cds_get_context(QDF_MODULE_ID_TXRX));
Dustin Brown07901ec2018-09-07 11:02:41 -07001917 ucfg_ipa_reg_sap_xmit_cb(hdd_ctx->pdev,
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301918 hdd_softap_hard_start_xmit);
Dustin Brown07901ec2018-09-07 11:02:41 -07001919 ucfg_ipa_reg_send_to_nw_cb(hdd_ctx->pdev,
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301920 hdd_ipa_send_skb_to_network);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301921
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301922 status = ucfg_mlme_get_sub_20_chan_width(hdd_ctx->psoc,
1923 &sub_20_chan_width);
1924 if (QDF_IS_STATUS_ERROR(status)) {
1925 hdd_err("Failed to get sub_20_chan_width config");
1926 return;
1927 }
1928
Naveen Rawat64e477e2016-05-20 10:34:56 -07001929 if (cds_cfg) {
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301930 if (sub_20_chan_width !=
1931 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
Naveen Rawat64e477e2016-05-20 10:34:56 -07001932 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1933 cds_cfg->sub_20_channel_width =
1934 WLAN_SUB_20_CH_WIDTH_NONE;
1935 } else {
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301936 cds_cfg->sub_20_channel_width = sub_20_chan_width;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001937 }
1938 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001939
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301940 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
1941 if (QDF_IS_STATUS_ERROR(status)) {
1942 hdd_err("Failed to get MLME band capability");
1943 return;
1944 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001945
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301946 /* first store the INI band capability */
1947 temp_band_cap = band_capability;
1948
1949 band_capability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301950 hdd_ctx->is_fils_roaming_supported =
1951 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001952
Vignesh Viswanathan694e28e2018-01-18 20:53:57 +05301953 hdd_ctx->config->is_11k_offload_supported =
1954 cfg->services.is_11k_offload_supported;
1955
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001956 /*
1957 * now overwrite the target band capability with INI
1958 * setting if INI setting is a subset
1959 */
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301960 if ((band_capability == BAND_ALL) &&
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001961 (temp_band_cap != BAND_ALL))
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301962 band_capability = temp_band_cap;
1963 else if ((band_capability != BAND_ALL) &&
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001964 (temp_band_cap != BAND_ALL) &&
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301965 (band_capability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001966 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001967 }
1968
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301969 status = ucfg_mlme_set_band_capability(hdd_ctx->psoc, band_capability);
1970 if (QDF_IS_STATUS_ERROR(status)) {
1971 hdd_err("Failed to set MLME Band Capability");
1972 return;
1973 }
1974
1975 hdd_ctx->curr_band = band_capability;
Amar Singhal58b45ef2017-08-01 13:43:54 -07001976
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301977 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001978 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1979 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1980 }
1981
1982 /* This can be extended to other configurations like ht, vht cap... */
1983
Anurag Chouhanc5548422016-02-24 18:33:27 +05301984 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001985 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001986 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001987 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001988 static struct qdf_mac_addr default_mac_addr = {
1989 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1990 };
1991 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1992 &default_mac_addr)) {
1993 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1994 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1995 MAC_ADDRESS_STR,
1996 MAC_ADDR_ARRAY(hdd_ctx->config->
1997 intfMacAddr[0].bytes));
1998 } else {
1999 hdd_err("Invalid MAC passed from target, using MAC from ini file "
2000 MAC_ADDRESS_STR,
2001 MAC_ADDR_ARRAY(hdd_ctx->config->
2002 intfMacAddr[0].bytes));
2003 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07002004 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002005 }
2006
2007 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07002008 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002009
Ryan Hsuc6918552018-05-16 13:29:59 -07002010 hdd_ctx->hw_bd_id = cfg->hw_bd_id;
2011 qdf_mem_copy(&hdd_ctx->hw_bd_info, &cfg->hw_bd_info,
2012 sizeof(cfg->hw_bd_info));
2013
Dustin Brownbee82832018-07-23 10:10:51 -07002014 if (cfg->max_intf_count > CSR_ROAM_SESSION_MAX) {
2015 hdd_err("fw max vdevs (%u) > host max vdevs (%u); using %u",
2016 cfg->max_intf_count, CSR_ROAM_SESSION_MAX,
2017 CSR_ROAM_SESSION_MAX);
2018 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
2019 } else {
2020 hdd_ctx->max_intf_count = cfg->max_intf_count;
2021 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002022
Jeff Johnsonf9176382018-07-17 19:15:58 -07002023 hdd_sar_target_config(hdd_ctx, cfg);
Jeff Johnsonc875e242016-09-23 18:12:34 -07002024 hdd_lpass_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08002025
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002026 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
2027 hdd_update_tgt_services(hdd_ctx, &cfg->services);
2028
2029 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
2030
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002031 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07002032 if (cfg->services.en_11ax) {
2033 hdd_info("11AX: 11ax is enabled - update HDD config");
2034 hdd_update_tgt_he_cap(hdd_ctx, cfg);
2035 }
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -07002036 hdd_update_tgt_twt_cap(hdd_ctx, cfg);
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07002037
2038 hdd_update_vdev_nss(hdd_ctx);
2039
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05302040 hdd_update_hw_dbs_capable(hdd_ctx);
2041
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08002042 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07002043 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002044 hdd_debug("fine_time_meas_cap: 0x%x",
Arif Hussainee10f902017-12-27 16:30:17 -08002045 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08002046
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05302047 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
2048 if (!QDF_IS_STATUS_SUCCESS(status))
2049 hdd_err("unable to get vht_enable2x2");
2050
2051 antenna_mode = (bval == 0x01) ?
Nitesh Shahe50711f2017-04-26 16:30:45 +05302052 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
2053 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002054 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08002055 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08002056
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05302057 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05302058 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05302059
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05302060 status = ucfg_mlme_cfg_get_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
Abhinav Kumare057b412018-10-09 17:28:16 +05302061 &value);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05302062 if (QDF_IS_STATUS_ERROR(status)) {
2063 status = false;
2064 hdd_err("set tx_bfee_ant_supp failed");
2065 }
2066
2067 if ((value >
Arif Hussainee10f902017-12-27 16:30:17 -08002068 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05302069 !cfg->tx_bfee_8ss_enabled) {
2070 status =
2071 ucfg_mlme_cfg_set_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
2072 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF);
2073 if (QDF_IS_STATUS_ERROR(status)) {
2074 status = false;
2075 hdd_err("set tx_bfee_ant_supp failed");
2076 }
2077 }
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302078
Jeff Johnson16528362018-06-14 12:34:16 -07002079 mac_handle = hdd_ctx->mac_handle;
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302080
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05302081 hdd_debug("txBFCsnValue %d", value);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05302082
2083 /*
2084 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
2085 */
2086 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05302087
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05302088 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
2089
Yue Macd359b72017-10-03 15:21:00 -07002090 /*
2091 * This needs to be done after HDD pdev is created and stored since
2092 * it will access the HDD pdev object lock.
2093 */
2094 hdd_runtime_suspend_context_init(hdd_ctx);
2095
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07002096 /* Configure NAN datapath features */
2097 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07002098 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08002099 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Liangwei Dong0da14262018-07-03 03:30:23 -04002100 hdd_ctx->obss_scan_offload = cfg->services.obss_scan_offload;
Jeff Johnson16528362018-06-14 12:34:16 -07002101 status = sme_cfg_set_int(mac_handle, WNI_CFG_OBSS_DETECTION_OFFLOAD,
Arif Hussainee10f902017-12-27 16:30:17 -08002102 cfg->obss_detection_offloaded);
2103 if (QDF_IS_STATUS_ERROR(status))
2104 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Arif Hussain05fb4872018-01-03 16:02:55 -08002105
Jeff Johnson16528362018-06-14 12:34:16 -07002106 status = sme_cfg_set_int(mac_handle,
Arif Hussain05fb4872018-01-03 16:02:55 -08002107 WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD,
2108 cfg->obss_color_collision_offloaded);
2109 if (QDF_IS_STATUS_ERROR(status))
2110 hdd_err("Failed to set WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002111}
2112
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002113bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002114{
Jeff Johnson9d295242017-08-29 14:39:48 -07002115 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002116 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002117
Jiachao Wuf610d912018-01-23 17:47:32 +08002118 if (!hdd_ctx) {
2119 hdd_info("Couldn't get hdd_ctx");
2120 return true;
2121 }
2122
2123 if (hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002124 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08002125 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302126 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002127 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002128
Dustin Brown920397d2017-12-13 16:27:50 -08002129 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002130 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2131
2132 if ((QDF_SAP_MODE == adapter->device_mode ||
2133 QDF_P2P_GO_MODE == adapter->device_mode) &&
Dustin Brown07901ec2018-09-07 11:02:41 -07002134 (wlan_reg_is_passive_or_disable_ch(hdd_ctx->pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002135 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002136 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2137 true;
2138 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07002139 adapter->session_id);
bings6fb9bf62018-07-05 14:01:53 +08002140 if (adapter->txrx_vdev)
2141 cdp_fc_vdev_flush(
2142 cds_get_context(QDF_MODULE_ID_SOC),
bings0e03a982018-05-09 08:40:59 +08002143 adapter->txrx_vdev);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302144 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002145 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302146
2147 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002148}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002149
Jeff Johnson030cd902018-11-11 10:19:40 -08002150bool hdd_is_valid_mac_address(const uint8_t *mac_addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002151{
2152 int xdigit = 0;
2153 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002154
Jeff Johnson030cd902018-11-11 10:19:40 -08002155 while (*mac_addr) {
2156 if (isxdigit(*mac_addr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002157 xdigit++;
Jeff Johnson030cd902018-11-11 10:19:40 -08002158 } else if (':' == *mac_addr) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002159 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2160 break;
2161
2162 ++separator;
2163 } else {
2164 /* Invalid MAC found */
Jeff Johnson030cd902018-11-11 10:19:40 -08002165 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002166 }
Jeff Johnson030cd902018-11-11 10:19:40 -08002167 ++mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002168 }
2169 return xdigit == 12 && (separator == 5 || separator == 0);
2170}
2171
2172/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302173 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2174 * @dev: Handle to struct net_device to be updated.
2175 *
2176 * Return: None
2177 */
2178static void hdd_mon_mode_ether_setup(struct net_device *dev)
2179{
2180 dev->header_ops = NULL;
2181 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2182 dev->hard_header_len = ETH_HLEN;
2183 dev->mtu = ETH_DATA_LEN;
2184 dev->addr_len = ETH_ALEN;
2185 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2186 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2187 dev->priv_flags |= IFF_TX_SKB_SHARING;
2188
2189 memset(dev->broadcast, 0xFF, ETH_ALEN);
2190}
2191
Nirav Shah73713f72018-05-17 14:50:41 +05302192#ifdef FEATURE_MONITOR_MODE_SUPPORT
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302193/**
chenguo71303962018-10-24 19:44:34 +08002194 * hdd_mon_turn_off_ps_and_wow() - Update monitor mode struct net_device.
2195 * @hdd_ctx: Pointer to HDD context.
2196 *
2197 * Return: None
2198 */
2199static void hdd_mon_turn_off_ps_and_wow(struct hdd_context *hdd_ctx)
2200{
2201 ucfg_pmo_set_power_save_mode(hdd_ctx->psoc, PS_NOT_SUPPORTED);
2202 ucfg_pmo_set_wow_enable(hdd_ctx->psoc, PMO_WOW_DISABLE_BOTH);
2203}
2204
2205/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002206 * __hdd__mon_open() - HDD Open function
2207 * @dev: Pointer to net_device structure
2208 *
2209 * This is called in response to ifconfig up
2210 *
2211 * Return: 0 for success; non-zero for failure
2212 */
2213static int __hdd_mon_open(struct net_device *dev)
2214{
2215 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002216 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2217 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002218
Dustin Brownfdf17c12018-03-14 12:55:34 -07002219 hdd_enter_dev(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002220
2221 ret = wlan_hdd_validate_context(hdd_ctx);
2222 if (ret)
2223 return ret;
2224
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302225 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002226
2227 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Brown3ecc8782018-09-19 16:37:13 -07002228 ret = hdd_psoc_idle_restart(hdd_ctx);
Ravi Joshia307f632017-07-17 23:41:41 -07002229 if (ret) {
2230 hdd_err("Failed to start WLAN modules return");
2231 return ret;
2232 }
2233 hdd_err("hdd_wlan_start_modules() successful !");
2234
2235 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2236 ret = hdd_start_adapter(adapter);
2237 if (ret) {
2238 hdd_err("Failed to start adapter :%d",
2239 adapter->device_mode);
2240 return ret;
2241 }
2242 hdd_err("hdd_start_adapters() successful !");
2243 }
chenguo71303962018-10-24 19:44:34 +08002244 hdd_mon_turn_off_ps_and_wow(hdd_ctx);
Ravi Joshia307f632017-07-17 23:41:41 -07002245 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2246 }
2247
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002248 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002249
2250 if (!ret)
2251 ret = hdd_enable_monitor_mode(dev);
2252
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002253 return ret;
2254}
2255
2256/**
2257 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2258 * @dev: Pointer to net_device structure
2259 *
2260 * This is called in response to ifconfig up
2261 *
2262 * Return: 0 for success; non-zero for failure
2263 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002264static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002265{
2266 int ret;
2267
2268 cds_ssr_protect(__func__);
2269 ret = __hdd_mon_open(dev);
2270 cds_ssr_unprotect(__func__);
2271
2272 return ret;
2273}
Nirav Shah73713f72018-05-17 14:50:41 +05302274#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002275
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002276static QDF_STATUS
2277wlan_hdd_update_dbs_scan_and_fw_mode_config(void)
2278{
2279 struct policy_mgr_dual_mac_config cfg = {0};
2280 QDF_STATUS status;
Krunal Soni13b50f82018-09-27 12:37:03 -07002281 uint32_t channel_select_logic_conc = 0;
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002282 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2283
2284 if (!hdd_ctx) {
2285 hdd_err("HDD context is NULL");
2286 return QDF_STATUS_E_FAILURE;
2287 }
2288
2289
Dustin Brown1dbefe62018-09-11 16:32:03 -07002290 if (!policy_mgr_is_hw_dbs_capable(hdd_ctx->psoc))
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002291 return QDF_STATUS_SUCCESS;
2292
2293 cfg.scan_config = 0;
2294 cfg.fw_mode_config = 0;
2295 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Krunal Soni13b50f82018-09-27 12:37:03 -07002296 ucfg_policy_mgr_get_chnl_select_plcy(hdd_ctx->psoc,
2297 &channel_select_logic_conc);
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002298
2299 if (hdd_ctx->config->dual_mac_feature_disable !=
2300 DISABLE_DBS_CXN_AND_SCAN) {
2301 status = policy_mgr_get_updated_scan_and_fw_mode_config(
Dustin Brown1dbefe62018-09-11 16:32:03 -07002302 hdd_ctx->psoc, &cfg.scan_config,
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002303 &cfg.fw_mode_config,
2304 hdd_ctx->config->dual_mac_feature_disable,
2305 channel_select_logic_conc);
2306
2307 if (status != QDF_STATUS_SUCCESS) {
2308 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
2309 status);
2310 return status;
2311 }
2312 }
2313
2314 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
2315 cfg.scan_config, cfg.fw_mode_config);
2316
2317 status = sme_soc_set_dual_mac_config(cfg);
2318 if (status != QDF_STATUS_SUCCESS) {
2319 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
2320 return status;
2321 }
2322
2323 return QDF_STATUS_SUCCESS;
2324}
2325
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002326/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302327 * hdd_start_adapter() - Wrapper function for device specific adapter
2328 * @adapter: pointer to HDD adapter
2329 *
2330 * This function is called to start the device specific adapter for
2331 * the mode passed in the adapter's device_mode.
2332 *
2333 * Return: 0 for success; non-zero for failure
2334 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002335int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302336{
2337
2338 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002339 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302340
Dustin Brownfdf17c12018-03-14 12:55:34 -07002341 hdd_enter_dev(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002342 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302343
2344 switch (device_mode) {
2345 case QDF_P2P_CLIENT_MODE:
2346 case QDF_P2P_DEVICE_MODE:
2347 case QDF_OCB_MODE:
2348 case QDF_STA_MODE:
2349 case QDF_MONITOR_MODE:
2350 ret = hdd_start_station_adapter(adapter);
2351 if (ret)
2352 goto err_start_adapter;
Alok Kumar81e1d732018-09-04 11:10:36 +05302353
2354 hdd_nud_ignore_tracking(adapter, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05302355 break;
2356 case QDF_P2P_GO_MODE:
2357 case QDF_SAP_MODE:
2358 ret = hdd_start_ap_adapter(adapter);
2359 if (ret)
2360 goto err_start_adapter;
2361 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302362 case QDF_IBSS_MODE:
2363 /*
2364 * For IBSS interface is initialized as part of
2365 * hdd_init_station_mode()
2366 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002367 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302368 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002369 /* vdevs are dynamically managed by firmware in FTM */
2370 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302371 default:
2372 hdd_err("Invalid session type %d", device_mode);
2373 QDF_ASSERT(0);
2374 goto err_start_adapter;
2375 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002376
Arun Khandavallifae92942016-08-01 13:31:08 +05302377 if (hdd_set_fw_params(adapter))
2378 hdd_err("Failed to set the FW params for the adapter!");
2379
Dustin Browne7e71d32018-05-11 16:00:08 -07002380 if (adapter->session_id != HDD_SESSION_ID_INVALID) {
2381 ret = wlan_hdd_cfg80211_register_frames(adapter);
2382 if (ret < 0) {
2383 hdd_err("Failed to register frames - ret %d", ret);
2384 goto err_start_adapter;
2385 }
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302386 }
Dustin Browne7e71d32018-05-11 16:00:08 -07002387
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002388 wlan_hdd_update_dbs_scan_and_fw_mode_config();
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302389
Dustin Browndb2a8be2017-12-20 11:49:56 -08002390exit_with_success:
Dustin Browne74003f2018-03-14 12:51:58 -07002391 hdd_exit();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002392
Arun Khandavallifae92942016-08-01 13:31:08 +05302393 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002394
Arun Khandavallifae92942016-08-01 13:31:08 +05302395err_start_adapter:
2396 return -EINVAL;
2397}
2398
2399/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302400 * hdd_enable_power_management() - API to Enable Power Management
2401 *
2402 * API invokes Bus Interface Layer power management functionality
2403 *
2404 * Return: None
2405 */
2406static void hdd_enable_power_management(void)
2407{
2408 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2409
2410 if (!hif_ctx) {
2411 hdd_err("Bus Interface Context is Invalid");
2412 return;
2413 }
2414
2415 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2416}
2417
2418/**
2419 * hdd_disable_power_management() - API to disable Power Management
2420 *
2421 * API disable Bus Interface Layer Power management functionality
2422 *
2423 * Return: None
2424 */
2425static void hdd_disable_power_management(void)
2426{
2427 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2428
2429 if (!hif_ctx) {
2430 hdd_err("Bus Interface Context is Invalid");
2431 return;
2432 }
2433
2434 hif_disable_power_management(hif_ctx);
2435}
2436
Ryan Hsuaadba072018-04-20 13:01:53 -07002437void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302438{
2439 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002440 size_t target_hw_name_len;
2441 const char *target_hw_name;
Ryan Hsuaadba072018-04-20 13:01:53 -07002442 uint8_t *buf;
2443 uint32_t buf_len;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302444
2445 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2446 if (!hif_sc) {
2447 hdd_err("HIF context is NULL");
2448 return;
2449 }
2450
Ryan Hsuaadba072018-04-20 13:01:53 -07002451 hif_get_hw_info(hif_sc, &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302452 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002453 &target_hw_name);
2454
2455 if (hdd_ctx->target_hw_name)
2456 qdf_mem_free(hdd_ctx->target_hw_name);
2457
2458 target_hw_name_len = strlen(target_hw_name) + 1;
2459 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2460 if (hdd_ctx->target_hw_name)
2461 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2462 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302463
Ryan Hsuaadba072018-04-20 13:01:53 -07002464 buf = qdf_mem_malloc(WE_MAX_STR_LEN);
2465 if (buf) {
2466 buf_len = hdd_wlan_get_version(hdd_ctx, WE_MAX_STR_LEN, buf);
2467 hdd_info("%s", buf);
2468 qdf_mem_free(buf);
2469 }
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302470}
2471
2472/**
gbian62edd7e2017-03-07 13:12:13 +08002473 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2474 * @hdd_ctx: Pointer to hdd context
2475 *
2476 * Return: none
2477 */
2478static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002479hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002480{
2481 uint8_t num_entries = 0;
2482 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2483 uint8_t *tx_sched_wrr_ac;
2484 int i;
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002485 struct cds_context *cds_ctx;
gbian62edd7e2017-03-07 13:12:13 +08002486
2487 if (NULL == hdd_ctx)
2488 return;
2489
2490 if (NULL == hdd_ctx->config) {
2491 /* Do nothing if hdd_ctx is invalid */
2492 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2493 return;
2494 }
2495
2496 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2497
2498 if (!cds_ctx) {
2499 hdd_err("Invalid CDS Context");
2500 return;
2501 }
2502
2503 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2504 switch (i) {
2505 case OL_TX_WMM_AC_BE:
2506 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2507 break;
2508 case OL_TX_WMM_AC_BK:
2509 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2510 break;
2511 case OL_TX_WMM_AC_VI:
2512 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2513 break;
2514 case OL_TX_WMM_AC_VO:
2515 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2516 break;
2517 default:
2518 tx_sched_wrr_ac = NULL;
2519 break;
2520 }
2521
2522 hdd_string_to_u8_array(tx_sched_wrr_ac,
2523 tx_sched_wrr_param,
2524 &num_entries,
2525 sizeof(tx_sched_wrr_param));
2526
2527 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2528 cds_ctx->ac_specs[i].wrr_skip_weight =
2529 tx_sched_wrr_param[0];
2530 cds_ctx->ac_specs[i].credit_threshold =
2531 tx_sched_wrr_param[1];
2532 cds_ctx->ac_specs[i].send_limit =
2533 tx_sched_wrr_param[2];
2534 cds_ctx->ac_specs[i].credit_reserve =
2535 tx_sched_wrr_param[3];
2536 cds_ctx->ac_specs[i].discard_weight =
2537 tx_sched_wrr_param[4];
2538 }
2539
2540 num_entries = 0;
2541 }
2542}
2543
Ryan Hsuaadba072018-04-20 13:01:53 -07002544uint32_t hdd_wlan_get_version(struct hdd_context *hdd_ctx,
2545 const size_t version_len, uint8_t *version)
2546{
2547 uint32_t size;
2548 uint32_t msp_id = 0, mspid = 0, siid = 0, crmid = 0, sub_id = 0;
2549
2550 if (!hdd_ctx) {
2551 hdd_err("Invalid context, HDD context is null");
2552 return 0;
2553 }
2554
Ashish Kumar Dhanotiya7353f882018-05-15 12:50:19 +05302555 if (!version || version_len == 0) {
Ryan Hsuaadba072018-04-20 13:01:53 -07002556 hdd_err("Invalid buffer pointr or buffer len\n");
2557 return 0;
2558 }
2559
2560 msp_id = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
2561 mspid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
2562 siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
2563 crmid = hdd_ctx->target_fw_version & 0x7fff;
2564 sub_id = (hdd_ctx->target_fw_vers_ext & 0xf0000000) >> 28;
2565
2566 size = scnprintf(version, version_len,
Ryan Hsuc6918552018-05-16 13:29:59 -07002567 "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 -07002568 QWLAN_VERSIONSTR,
2569 msp_id, mspid, siid, crmid, sub_id,
Ryan Hsuc6918552018-05-16 13:29:59 -07002570 hdd_ctx->target_hw_name,
2571 hdd_ctx->hw_bd_info.bdf_version,
2572 hdd_ctx->hw_bd_info.ref_design_id,
2573 hdd_ctx->hw_bd_info.customer_id,
2574 hdd_ctx->hw_bd_info.project_id,
2575 hdd_ctx->hw_bd_info.board_data_rev);
Ryan Hsuaadba072018-04-20 13:01:53 -07002576
2577 return size;
2578}
2579
Rachit Kankane0dc3e852018-05-07 17:33:42 +05302580int hdd_set_11ax_rate(struct hdd_adapter *adapter, int set_value,
2581 struct sap_config *sap_config)
2582{
2583 uint8_t preamble = 0, nss = 0, rix = 0;
2584 int ret;
2585 mac_handle_t mac_handle = adapter->hdd_ctx->mac_handle;
2586
2587 if (!sap_config) {
2588 if (!sme_is_feature_supported_by_fw(DOT11AX)) {
2589 hdd_err("Target does not support 11ax");
2590 return -EIO;
2591 }
2592 } else if (sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax &&
2593 sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax_ONLY) {
2594 hdd_err("Invalid hw mode, SAP hw_mode= 0x%x, ch = %d",
2595 sap_config->SapHw_mode, sap_config->channel);
2596 return -EIO;
2597 }
2598
2599 if (set_value != 0xff) {
2600 rix = RC_2_RATE_IDX_11AX(set_value);
2601 preamble = WMI_RATE_PREAMBLE_HE;
2602 nss = HT_RC_2_STREAMS_11AX(set_value);
2603
2604 set_value = hdd_assemble_rate_code(preamble, nss, rix);
2605 } else {
2606 ret = sme_set_auto_rate_he_ltf(mac_handle, adapter->session_id,
2607 QCA_WLAN_HE_LTF_AUTO);
2608 }
2609
2610 hdd_info("SET_11AX_RATE val %d rix %d preamble %x nss %d",
2611 set_value, rix, preamble, nss);
2612
2613 ret = wma_cli_set_command(adapter->session_id,
2614 WMI_VDEV_PARAM_FIXED_RATE,
2615 set_value, VDEV_CMD);
2616
2617 return ret;
2618}
2619
2620int hdd_assemble_rate_code(uint8_t preamble, uint8_t nss, uint8_t rate)
2621{
2622 int set_value;
2623
2624 if (sme_is_feature_supported_by_fw(DOT11AX))
2625 set_value = WMI_ASSEMBLE_RATECODE_V1(rate, nss, preamble);
2626 else
2627 set_value = (preamble << 6) | (nss << 4) | rate;
2628
2629 return set_value;
2630}
2631
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002632#ifdef FEATURE_WLAN_WAPI
2633/**
2634 * hdd_wapi_security_sta_exist() - return wapi security sta exist or not
2635 *
2636 * This API returns the wapi security station exist or not
2637 *
2638 * Return: true - wapi security station exist
2639 */
2640static bool hdd_wapi_security_sta_exist(void)
2641{
2642 struct hdd_adapter *adapter = NULL;
2643 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2644
2645 hdd_for_each_adapter(hdd_ctx, adapter) {
2646 if ((adapter->device_mode == QDF_STA_MODE) &&
2647 adapter->wapi_info.wapi_mode &&
2648 (adapter->wapi_info.wapi_auth_mode != WAPI_AUTH_MODE_OPEN))
2649 return true;
2650 }
2651 return false;
2652}
2653#else
2654static bool hdd_wapi_security_sta_exist(void)
2655{
2656 return false;
2657}
2658#endif
2659
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002660#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002661static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2662 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2663{
Jeff Johnson9d295242017-08-29 14:39:48 -07002664 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002665 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002666
2667 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2668 if (!adapter) {
2669 hdd_err("Adapter is NULL");
2670 return PM_MAX_NUM_OF_MODE;
2671 }
2672
2673 return policy_mgr_convert_device_mode_to_qdf_type(
2674 adapter->device_mode);
2675}
2676
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002677static void hdd_register_policy_manager_callback(
2678 struct wlan_objmgr_psoc *psoc)
2679{
2680 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002681
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002682 qdf_mem_zero(&hdd_cbacks, sizeof(hdd_cbacks));
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002683 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002684 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002685 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2686 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002687 hdd_cbacks.get_mode_for_non_connected_vdev =
2688 wlan_hdd_get_mode_for_non_connected_vdev;
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05302689 hdd_cbacks.hdd_get_device_mode = hdd_get_device_mode;
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002690 hdd_cbacks.hdd_wapi_security_sta_exist =
2691 hdd_wapi_security_sta_exist;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002692 if (QDF_STATUS_SUCCESS !=
2693 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2694 hdd_err("HDD callback registration with policy manager failed");
2695 }
2696}
2697#else
2698static void hdd_register_policy_manager_callback(
2699 struct wlan_objmgr_psoc *psoc)
2700{
2701}
2702#endif
2703
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002704static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002705{
2706 struct nan_callbacks cb_obj = {0};
2707
2708 cb_obj.ndi_open = hdd_ndi_open;
2709 cb_obj.ndi_close = hdd_ndi_close;
2710 cb_obj.ndi_start = hdd_ndi_start;
2711 cb_obj.ndi_delete = hdd_ndi_delete;
2712 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2713 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2714
Naveen Rawat37f62c82017-03-26 22:24:43 -07002715 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2716 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002717 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002718
Dustin Brown1dbefe62018-09-11 16:32:03 -07002719 os_if_nan_register_hdd_callbacks(hdd_ctx->psoc, &cb_obj);
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002720}
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002721
Dustin Brown26b3d042017-12-21 11:13:27 -08002722#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002723/**
2724 * hdd_check_for_leaks() - Perform runtime memory leak checks
Dustin Browna6246dd2018-05-24 14:35:58 -07002725 * @hdd_ctx: the global HDD context
Dustin Brown29533f22018-07-24 13:11:56 -07002726 * @is_ssr: true if SSR is in progress
Dustin Brown4c5b9902017-12-19 11:17:19 -08002727 *
2728 * This API triggers runtime memory leak detection. This feature enforces the
2729 * policy that any memory allocated at runtime must also be released at runtime.
2730 *
2731 * Allocating memory at runtime and releasing it at unload is effectively a
2732 * memory leak for configurations which never unload (e.g. LONU, statically
2733 * compiled driver). Such memory leaks are NOT false positives, and must be
2734 * fixed.
2735 *
2736 * Return: None
2737 */
Dustin Brown29533f22018-07-24 13:11:56 -07002738static void hdd_check_for_leaks(struct hdd_context *hdd_ctx, bool is_ssr)
Dustin Brown4bc0a622017-12-06 15:56:50 -08002739{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002740 /* DO NOT REMOVE these checks; for false positives, read above first */
2741
Dustin Brown1dbefe62018-09-11 16:32:03 -07002742 wlan_objmgr_psoc_check_for_peer_leaks(hdd_ctx->psoc);
2743 wlan_objmgr_psoc_check_for_vdev_leaks(hdd_ctx->psoc);
2744 wlan_objmgr_psoc_check_for_pdev_leaks(hdd_ctx->psoc);
Dustin Brown29533f22018-07-24 13:11:56 -07002745
2746 /* many adapter resources are not freed by design during SSR */
2747 if (is_ssr)
2748 return;
2749
Dustin Brown677e0862017-10-10 16:30:09 -07002750 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002751 qdf_nbuf_map_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002752 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002753}
2754
Dustin Brown26b3d042017-12-21 11:13:27 -08002755#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2756#else
Dustin Brown29533f22018-07-24 13:11:56 -07002757static inline void hdd_check_for_leaks(struct hdd_context *hdd_ctx, bool is_ssr)
2758{ }
Dustin Brown26b3d042017-12-21 11:13:27 -08002759
2760#define hdd_debug_domain_set(domain)
2761#endif /* CONFIG_LEAK_DETECTION */
2762
gbian62edd7e2017-03-07 13:12:13 +08002763/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002764 * hdd_update_country_code - Update country code
2765 * @hdd_ctx: HDD context
2766 *
2767 * Update country code based on module parameter country_code
2768 *
2769 * Return: 0 on success and errno on failure
2770 */
2771static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2772{
2773 if (!country_code)
2774 return 0;
2775
2776 return hdd_reg_set_country(hdd_ctx, country_code);
2777}
2778
Dustin Browne7e71d32018-05-11 16:00:08 -07002779int hdd_wlan_start_modules(struct hdd_context *hdd_ctx, bool reinit)
Arun Khandavallifae92942016-08-01 13:31:08 +05302780{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002781 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302782 qdf_device_t qdf_dev;
2783 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302784 bool unint = false;
2785 void *hif_ctx;
Jingxiang Ge95912f82018-04-19 12:01:26 +08002786 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +05302787
Arun Khandavallifae92942016-08-01 13:31:08 +05302788 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2789 if (!qdf_dev) {
2790 hdd_err("QDF Device Context is Invalid return");
2791 return -EINVAL;
2792 }
2793
Dustin Brown4c663222018-10-23 14:19:36 -07002794 hdd_psoc_idle_timer_stop(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302795
Dustin Brown1fe30a82017-10-03 16:13:36 -07002796 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302797 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2798 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002799 hdd_debug("Driver modules already Enabled");
Dustin Browne74003f2018-03-14 12:51:58 -07002800 hdd_exit();
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302801 return 0;
2802 }
2803
Dustin Brown1fe30a82017-10-03 16:13:36 -07002804 hdd_ctx->start_modules_in_progress = true;
2805
Arun Khandavallifae92942016-08-01 13:31:08 +05302806 switch (hdd_ctx->driver_status) {
2807 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002808 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302809 unint = true;
2810 /* Fall through dont add break here */
2811 case DRIVER_MODULES_CLOSED:
Dustin Brown1a20b082018-08-03 17:27:15 -07002812 hdd_info("Wlan transitioning (CLOSED -> ENABLED)");
Dustin Brown550f6d22017-12-14 15:44:01 -08002813
Dustin Brown26b3d042017-12-21 11:13:27 -08002814 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002815
Arun Khandavallifae92942016-08-01 13:31:08 +05302816 if (!reinit && !unint) {
2817 ret = pld_power_on(qdf_dev->dev);
2818 if (ret) {
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002819 hdd_err("Failed to power up device; errno:%d",
Dustin Browndca39692017-11-09 15:30:25 -08002820 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302821 goto release_lock;
2822 }
2823 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002824
2825 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2826 hdd_ctx->config->enable_fw_log);
Arun Khandavallifae92942016-08-01 13:31:08 +05302827 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2828 qdf_dev->bus_type,
2829 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2830 HIF_ENABLE_TYPE_PROBE);
2831 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002832 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302833 goto power_down;
2834 }
2835
2836 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302837 if (!hif_ctx) {
2838 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002839 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302840 goto power_down;
2841 }
2842
Arun Khandavallifae92942016-08-01 13:31:08 +05302843 status = ol_cds_init(qdf_dev, hif_ctx);
2844 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002845 hdd_err("No Memory to Create BMI Context; status: %d",
2846 status);
2847 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302848 goto hif_close;
2849 }
2850
jitiphil4c256a32018-09-07 08:51:52 +05302851 ucfg_ipa_component_config_update(hdd_ctx->psoc);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302852
gbian62edd7e2017-03-07 13:12:13 +08002853 hdd_update_cds_ac_specs_params(hdd_ctx);
2854
Dustin Brown1dbefe62018-09-11 16:32:03 -07002855 status = hdd_component_psoc_open(hdd_ctx->psoc);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05302856 if (QDF_IS_STATUS_ERROR(status)) {
2857 hdd_err("Failed to Open legacy components; status: %d",
2858 status);
2859 ret = qdf_status_to_os_return(status);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05302860 goto cds_free;
2861 }
2862
2863 ret = hdd_update_config(hdd_ctx);
2864 if (ret) {
2865 hdd_err("Failed to update configuration; errno: %d",
2866 ret);
2867 goto cds_free;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05302868 }
2869
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +05302870 status = wbuff_module_init();
2871 if (QDF_IS_STATUS_ERROR(status))
2872 hdd_err("WBUFF init unsuccessful; status: %d", status);
2873
Dustin Brown1dbefe62018-09-11 16:32:03 -07002874 status = cds_open(hdd_ctx->psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002875 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002876 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002877 ret = qdf_status_to_os_return(status);
Krunal Sonie71838d2018-09-27 10:45:05 -07002878 goto psoc_close;
Arun Khandavallifae92942016-08-01 13:31:08 +05302879 }
2880
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +05302881 hdd_ctx->mac_handle = cds_get_context(QDF_MODULE_ID_SME);
2882
Manjunathappa Prakashb6b4ff12018-06-04 12:32:33 -07002883 if (hdd_ctx->config->rx_thread_affinity_mask)
2884 cds_set_rx_thread_cpu_mask(
2885 hdd_ctx->config->rx_thread_affinity_mask);
2886
2887 /* initialize components configurations after psoc open */
Mukul Sharma9d797a02017-01-05 20:26:03 +05302888 ret = hdd_update_components_config(hdd_ctx);
2889 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002890 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302891 ret);
2892 goto close;
2893 }
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302894
Dustin Brown1dbefe62018-09-11 16:32:03 -07002895 status = cds_dp_open(hdd_ctx->psoc);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002896 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002897 hdd_err("Failed to Open cds post open; status: %d",
2898 status);
2899 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002900 goto close;
2901 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302902
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302903 ret = hdd_register_cb(hdd_ctx);
2904 if (ret) {
2905 hdd_err("Failed to register HDD callbacks!");
2906 goto cds_txrx_free;
2907 }
2908
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002909 /*
2910 * NAN compoenet requires certian operations like, open adapter,
2911 * close adapter, etc. to be initiated by HDD, for those
2912 * register HDD callbacks with UMAC's NAN componenet.
2913 */
2914 hdd_nan_register_callbacks(hdd_ctx);
2915
Jeff Johnson3a280122017-09-13 07:42:00 -07002916 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302917 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002918 hdd_err("Failed to pre-enable CDS; status: %d", status);
2919 ret = qdf_status_to_os_return(status);
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302920 goto deregister_cb;
Arun Khandavallifae92942016-08-01 13:31:08 +05302921 }
2922
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002923 hdd_register_policy_manager_callback(
Dustin Brown1dbefe62018-09-11 16:32:03 -07002924 hdd_ctx->psoc);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002925
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302926 hdd_sysfs_create_driver_root_obj();
Dustin Brown1dbefe62018-09-11 16:32:03 -07002927 hdd_sysfs_create_version_interface(hdd_ctx->psoc);
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302928 hdd_sysfs_create_powerstats_interface();
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302929 hdd_update_hw_sw_info(hdd_ctx);
Dustin Brown550f6d22017-12-14 15:44:01 -08002930
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302931 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2932 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002933 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302934 break;
2935 }
Dustin Browndca39692017-11-09 15:30:25 -08002936
Dustin Browne7e71d32018-05-11 16:00:08 -07002937 ret = hdd_configure_cds(hdd_ctx);
Dustin Browndca39692017-11-09 15:30:25 -08002938 if (ret) {
2939 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302940 goto destroy_driver_sysfs;
Arun Khandavallifae92942016-08-01 13:31:08 +05302941 }
Dustin Browndca39692017-11-09 15:30:25 -08002942
Komal Seelamf2136bb2016-09-28 18:30:44 +05302943 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002944
Arun Khandavallifae92942016-08-01 13:31:08 +05302945 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002946
Arun Khandavallifae92942016-08-01 13:31:08 +05302947 default:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002948 QDF_DEBUG_PANIC("Unknown driver state:%d",
Arun Khandavallifae92942016-08-01 13:31:08 +05302949 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002950 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302951 goto release_lock;
2952 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002953
Dustin Brown1a20b082018-08-03 17:27:15 -07002954 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2955 hdd_info("Wlan transitioned (now ENABLED)");
2956
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302957 hdd_ctx->start_modules_in_progress = false;
Dustin Brownad698ae2018-09-05 17:19:30 -07002958
Arun Khandavallifae92942016-08-01 13:31:08 +05302959 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002960
Dustin Browne74003f2018-03-14 12:51:58 -07002961 hdd_exit();
Dustin Brown550f6d22017-12-14 15:44:01 -08002962
Arun Khandavallifae92942016-08-01 13:31:08 +05302963 return 0;
2964
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302965destroy_driver_sysfs:
2966 hdd_sysfs_destroy_powerstats_interface();
2967 hdd_sysfs_destroy_version_interface();
2968 hdd_sysfs_destroy_driver_root_obj();
Rajeev Kumarbe021242017-02-16 16:12:23 -08002969 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002970
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302971deregister_cb:
2972 hdd_deregister_cb(hdd_ctx);
2973
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002974cds_txrx_free:
Dustin Brown1dbefe62018-09-11 16:32:03 -07002975 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->psoc);
Jingxiang Ge95912f82018-04-19 12:01:26 +08002976
2977 if (tgt_hdl && target_psoc_get_wmi_ready(tgt_hdl)) {
2978 hdd_runtime_suspend_context_deinit(hdd_ctx);
Dustin Brown07901ec2018-09-07 11:02:41 -07002979 dispatcher_pdev_close(hdd_ctx->pdev);
Jingxiang Ge95912f82018-04-19 12:01:26 +08002980 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
2981 }
2982
Dustin Brown1dbefe62018-09-11 16:32:03 -07002983 cds_dp_close(hdd_ctx->psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08002984
Arun Khandavallifae92942016-08-01 13:31:08 +05302985close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002986 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002987 hdd_info("Wlan transition aborted (now CLOSED)");
2988
Dustin Brown1dbefe62018-09-11 16:32:03 -07002989 cds_close(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302990
Krunal Sonie71838d2018-09-27 10:45:05 -07002991psoc_close:
Dustin Brown1dbefe62018-09-11 16:32:03 -07002992 hdd_component_psoc_close(hdd_ctx->psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002993 cds_deinit_ini_config();
2994
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002995cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302996 ol_cds_free();
2997
2998hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002999 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
3000 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05303001power_down:
3002 if (!reinit && !unint)
3003 pld_power_off(qdf_dev->dev);
3004release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05303005 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05303006 mutex_unlock(&hdd_ctx->iface_change_lock);
Abhinav Kumar7ae9b7b2017-12-19 15:11:54 +05303007 if (hdd_ctx->target_hw_name) {
3008 qdf_mem_free(hdd_ctx->target_hw_name);
3009 hdd_ctx->target_hw_name = NULL;
3010 }
Dustin Brown29533f22018-07-24 13:11:56 -07003011
3012 hdd_check_for_leaks(hdd_ctx, reinit);
Dustin Brown26b3d042017-12-21 11:13:27 -08003013 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08003014
Dustin Browne74003f2018-03-14 12:51:58 -07003015 hdd_exit();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08003016
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07003017 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05303018}
3019
Naveen Rawat910726a2017-03-06 11:42:51 -08003020#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003021static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003022{
3023 int ret = os_if_wifi_pos_register_nl();
3024
3025 if (ret)
3026 hdd_err("os_if_wifi_pos_register_nl failed");
3027
3028 return ret;
3029}
3030
3031static int hdd_deactivate_wifi_pos(void)
3032{
3033 int ret = os_if_wifi_pos_deregister_nl();
3034
3035 if (ret)
3036 hdd_err("os_if_wifi_pos_deregister_nl failed");
3037
3038 return ret;
3039}
3040
3041/**
3042 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
3043 * @hdd_ctx: hdd context
3044 *
3045 * Return: status of operation
3046 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003047static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003048{
Dustin Brown1dbefe62018-09-11 16:32:03 -07003049 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Naveen Rawat910726a2017-03-06 11:42:51 -08003050 struct hdd_config *cfg = hdd_ctx->config;
3051
3052 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
3053 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
3054 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
3055 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
3056 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
3057 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
3058 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
3059 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
3060}
3061#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003062static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003063{
3064 return oem_activate_service(hdd_ctx);
3065}
3066
3067static int hdd_deactivate_wifi_pos(void)
3068{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05303069 return oem_deactivate_service();
Naveen Rawat910726a2017-03-06 11:42:51 -08003070}
3071
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003072static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003073{
3074}
3075#endif
3076
Arun Khandavallifae92942016-08-01 13:31:08 +05303077/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003078 * __hdd_open() - HDD Open function
3079 * @dev: Pointer to net_device structure
3080 *
3081 * This is called in response to ifconfig up
3082 *
3083 * Return: 0 for success; non-zero for failure
3084 */
3085static int __hdd_open(struct net_device *dev)
3086{
Jeff Johnson9d295242017-08-29 14:39:48 -07003087 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003088 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003089 int ret;
3090
Dustin Brownfdf17c12018-03-14 12:55:34 -07003091 hdd_enter_dev(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303092 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003093 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003094
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05303095 /* Nothing to be done if device is unloading */
3096 if (cds_is_driver_unloading()) {
3097 hdd_err("Driver is unloading can not open the hdd");
3098 return -EBUSY;
3099 }
3100
Dustin Brown01847752017-10-25 13:56:27 -07003101 if (cds_is_driver_recovering()) {
3102 hdd_err("WLAN is currently recovering; Please try again.");
3103 return -EBUSY;
3104 }
3105
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05303106 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
3107 hdd_err("con_mode_handler is in progress; Please try again.");
3108 return -EBUSY;
3109 }
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303110
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05303111 mutex_lock(&hdd_init_deinit_lock);
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05303112 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
3113
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303114 /*
3115 * This scenario can be hit in cases where in the wlan driver after
3116 * registering the netdevices and there is a failure in driver
3117 * initialization. So return error gracefully because the netdevices
3118 * will be de-registered as part of the load failure.
3119 */
3120
3121 if (!cds_is_driver_loaded()) {
3122 hdd_err("Failed to start the wlan driver!!");
3123 ret = -EIO;
3124 goto err_hdd_hdd_init_deinit_lock;
3125 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303126
Dustin Brown3ecc8782018-09-19 16:37:13 -07003127 ret = hdd_psoc_idle_restart(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05303128 if (ret) {
3129 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303130 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05303131 }
3132
Arun Khandavallifae92942016-08-01 13:31:08 +05303133 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3134 ret = hdd_start_adapter(adapter);
3135 if (ret) {
3136 hdd_err("Failed to start adapter :%d",
3137 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303138 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05303139 }
3140 }
3141
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003142 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3143 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003144 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003145 /* Enable TX queues only when we are connected */
3146 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05303147 WLAN_START_ALL_NETIF_QUEUE,
3148 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003149 }
3150
Naveen Rawat286def52016-09-23 15:38:02 -07003151 /* Enable carrier and transmit queues for NDI */
3152 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003153 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07003154 wlan_hdd_netif_queue_control(adapter,
3155 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
3156 WLAN_CONTROL_PATH);
3157 }
3158
Naveen Rawat910726a2017-03-06 11:42:51 -08003159 hdd_populate_wifi_pos_cfg(hdd_ctx);
Arunk Khandavalli40943af2017-05-15 19:25:34 +05303160 hdd_lpass_notify_start(hdd_ctx, adapter);
Naveen Rawat910726a2017-03-06 11:42:51 -08003161
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303162err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05303163 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303164 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003165 return ret;
3166}
3167
Arun Khandavallifae92942016-08-01 13:31:08 +05303168
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003169/**
3170 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
3171 * @dev: Pointer to net_device structure
3172 *
3173 * This is called in response to ifconfig up
3174 *
3175 * Return: 0 for success; non-zero for failure
3176 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003177static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003178{
3179 int ret;
3180
3181 cds_ssr_protect(__func__);
3182 ret = __hdd_open(dev);
3183 cds_ssr_unprotect(__func__);
3184
3185 return ret;
3186}
3187
3188/**
3189 * __hdd_stop() - HDD stop function
3190 * @dev: Pointer to net_device structure
3191 *
3192 * This is called in response to ifconfig down
3193 *
3194 * Return: 0 for success; non-zero for failure
3195 */
3196static int __hdd_stop(struct net_device *dev)
3197{
Jeff Johnson9d295242017-08-29 14:39:48 -07003198 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003199 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003200 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -07003201 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003202
Dustin Brownfdf17c12018-03-14 12:55:34 -07003203 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003204
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303205 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003206 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003207
3208 ret = wlan_hdd_validate_context(hdd_ctx);
Arunk Khandavalli987c8d52018-06-21 17:40:31 +05303209 if (ret) {
3210 set_bit(DOWN_DURING_SSR, &adapter->event_flags);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003211 return ret;
Arunk Khandavalli987c8d52018-06-21 17:40:31 +05303212 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003213
3214 /* Nothing to be done if the interface is not opened */
3215 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003216 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003217 return -ENODEV;
3218 }
3219
3220 /* Make sure the interface is marked as closed */
3221 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303222
Jeff Johnson16528362018-06-14 12:34:16 -07003223 mac_handle = hdd_ctx->mac_handle;
3224
Mukul Sharmad16c2022017-07-25 18:56:12 +05303225 hdd_debug("Disabling Auto Power save timer");
3226 sme_ps_disable_auto_ps_timer(
Jeff Johnson16528362018-06-14 12:34:16 -07003227 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003228 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303229
3230 /*
3231 * Disable TX on the interface, after this hard_start_xmit() will not
3232 * be called on that interface
3233 */
Dustin Browna7bb6ae2018-08-16 16:51:50 -07003234 hdd_debug("Disabling queues, adapter device mode: %s(%d)",
Dustin Brown458027c2018-10-19 12:26:27 -07003235 qdf_opmode_str(adapter->device_mode), adapter->device_mode);
Kabilan Kannan8dac3502017-10-30 12:40:27 -07003236
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303237 wlan_hdd_netif_queue_control(adapter,
3238 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3239 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003240
Arunk Khandavalli40943af2017-05-15 19:25:34 +05303241 if (adapter->device_mode == QDF_STA_MODE)
3242 hdd_lpass_notify_stop(hdd_ctx);
3243
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003244 /*
Naveen Rawat286def52016-09-23 15:38:02 -07003245 * NAN data interface is different in some sense. The traffic on NDI is
3246 * bursty in nature and depends on the need to transfer. The service
3247 * layer may down the interface after the usage and up again when
3248 * required. In some sense, the NDI is expected to be available
3249 * (like SAP) iface until NDI delete request is issued by the service
3250 * layer. Skip BSS termination and adapter deletion for NAN Data
3251 * interface (NDI).
3252 */
3253 if (WLAN_HDD_IS_NDI(adapter))
3254 return 0;
3255
3256 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003257 * The interface is marked as down for outside world (aka kernel)
3258 * But the driver is pretty much alive inside. The driver needs to
3259 * tear down the existing connection on the netdev (session)
3260 * cleanup the data pipes and wait until the control plane is stabilized
3261 * for this interface. The call also needs to wait until the above
3262 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003263 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003264 * That is intentional to be able to scan if it is a STA/P2P interface
3265 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08003266 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003267
3268 /* DeInit the adapter. This ensures datapath cleanup as well */
3269 hdd_deinit_adapter(hdd_ctx, adapter, true);
3270
Arun Khandavallifae92942016-08-01 13:31:08 +05303271 /*
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +05303272 * Upon wifi turn off, DUT has to flush the scan results so if
3273 * this is the last cli iface, flush the scan database.
3274 */
3275 if (!hdd_is_cli_iface_up(hdd_ctx))
Jeff Johnson16528362018-06-14 12:34:16 -07003276 sme_scan_flush_result(mac_handle);
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +05303277
Dustin Brown4c663222018-10-23 14:19:36 -07003278 if (!hdd_is_any_interface_open(hdd_ctx))
3279 hdd_psoc_idle_timer_start(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05303280
Dustin Browne74003f2018-03-14 12:51:58 -07003281 hdd_exit();
Dustin Brown4c663222018-10-23 14:19:36 -07003282
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003283 return 0;
3284}
3285
3286/**
3287 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3288 * @dev: pointer to net_device structure
3289 *
3290 * This is called in response to ifconfig down
3291 *
3292 * Return: 0 for success and error number for failure
3293 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003294static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003295{
3296 int ret;
3297
3298 cds_ssr_protect(__func__);
3299 ret = __hdd_stop(dev);
3300 cds_ssr_unprotect(__func__);
3301
3302 return ret;
3303}
3304
3305/**
3306 * __hdd_uninit() - HDD uninit function
3307 * @dev: Pointer to net_device structure
3308 *
3309 * This is called during the netdev unregister to uninitialize all data
3310 * associated with the device
3311 *
3312 * Return: None
3313 */
3314static void __hdd_uninit(struct net_device *dev)
3315{
Jeff Johnson9d295242017-08-29 14:39:48 -07003316 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003317 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003318
Dustin Brownfdf17c12018-03-14 12:55:34 -07003319 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003320
3321 do {
3322 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003323 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003324 break;
3325 }
3326
Jeff Johnson399c6272017-08-30 10:51:00 -07003327 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3328 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003329 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003330 break;
3331 }
3332
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003333 if (dev != adapter->dev)
3334 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003335
Jeff Johnson399c6272017-08-30 10:51:00 -07003336 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003337
3338 /* after uninit our adapter structure will no longer be valid */
3339 adapter->dev = NULL;
3340 adapter->magic = 0;
3341 } while (0);
3342
Dustin Browne74003f2018-03-14 12:51:58 -07003343 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003344}
3345
3346/**
3347 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
3348 * @dev: pointer to net_device structure
3349 *
3350 * This is called during the netdev unregister to uninitialize all data
3351 * associated with the device
3352 *
3353 * Return: none
3354 */
3355static void hdd_uninit(struct net_device *dev)
3356{
3357 cds_ssr_protect(__func__);
3358 __hdd_uninit(dev);
3359 cds_ssr_unprotect(__func__);
3360}
3361
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003362static int hdd_open_cesium_nl_sock(void)
3363{
3364#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3365 struct netlink_kernel_cfg cfg = {
3366 .groups = WLAN_NLINK_MCAST_GRP_ID,
3367 .input = NULL
3368 };
3369#endif
3370 int ret = 0;
3371
3372#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3373 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3374#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3375 THIS_MODULE,
3376#endif
3377 &cfg);
3378#else
3379 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3380 WLAN_NLINK_MCAST_GRP_ID,
3381 NULL, NULL, THIS_MODULE);
3382#endif
3383
3384 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003385 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003386 ret = -ECONNREFUSED;
3387 }
3388
3389 return ret;
3390}
3391
3392static void hdd_close_cesium_nl_sock(void)
3393{
3394 if (NULL != cesium_nl_srv_sock) {
3395 netlink_kernel_release(cesium_nl_srv_sock);
3396 cesium_nl_srv_sock = NULL;
3397 }
3398}
3399
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303400void hdd_update_dynamic_mac(struct hdd_context *hdd_ctx,
3401 struct qdf_mac_addr *curr_mac_addr,
3402 struct qdf_mac_addr *new_mac_addr)
3403{
3404 uint8_t i;
3405
3406 hdd_enter();
3407
3408 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
3409 if (!qdf_mem_cmp(curr_mac_addr->bytes,
3410 &hdd_ctx->dynamic_mac_list[i].bytes[0],
3411 sizeof(struct qdf_mac_addr))) {
3412 qdf_mem_copy(&hdd_ctx->dynamic_mac_list[i],
3413 new_mac_addr->bytes,
3414 sizeof(struct qdf_mac_addr));
3415 break;
3416 }
3417 }
3418
3419 hdd_exit();
3420}
3421
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003422/**
3423 * __hdd_set_mac_address() - set the user specified mac address
3424 * @dev: Pointer to the net device.
3425 * @addr: Pointer to the sockaddr.
3426 *
3427 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003428 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003429 *
3430 * Return: 0 for success, non zero for failure
3431 */
3432static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3433{
Jeff Johnson9d295242017-08-29 14:39:48 -07003434 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303435 struct hdd_adapter *adapter_temp;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003436 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003437 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303438 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003439 int ret;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303440 struct qdf_mac_addr mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003441
Dustin Brownfdf17c12018-03-14 12:55:34 -07003442 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003443
Hanumanth Reddy Pothula5c7a7812018-03-09 12:55:32 +05303444 if (netif_running(dev)) {
3445 hdd_err("On iface up, set mac address change isn't supported");
3446 return -EBUSY;
3447 }
3448
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003449 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3450 ret = wlan_hdd_validate_context(hdd_ctx);
3451 if (0 != ret)
3452 return ret;
3453
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303454 qdf_mem_copy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303455 adapter_temp = hdd_get_adapter_by_macaddr(hdd_ctx, mac_addr.bytes);
3456 if (adapter_temp) {
3457 if (!qdf_str_cmp(adapter_temp->dev->name, dev->name))
3458 return 0;
3459 hdd_err("%s adapter exist with same address " MAC_ADDRESS_STR,
3460 adapter_temp->dev->name,
Ashish Kumar Dhanotiyaf974f332018-04-19 16:03:15 +05303461 MAC_ADDR_ARRAY(mac_addr.bytes));
3462 return -EINVAL;
3463 }
3464
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05303465 qdf_ret_status = wlan_hdd_validate_mac_address(&mac_addr);
3466 if (QDF_IS_STATUS_ERROR(qdf_ret_status))
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303467 return -EINVAL;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303468
Ashish Kumar Dhanotiya8bfef122018-04-18 16:48:27 +05303469 hdd_info("Changing MAC to " MAC_ADDRESS_STR " of the interface %s ",
3470 MAC_ADDR_ARRAY(mac_addr.bytes), dev->name);
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303471
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303472 hdd_update_dynamic_mac(hdd_ctx, &adapter->mac_addr, &mac_addr);
Jeff Johnson1e851a12017-10-28 14:36:12 -07003473 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003474 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3475
Dustin Browne74003f2018-03-14 12:51:58 -07003476 hdd_exit();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303477 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003478}
3479
3480/**
3481 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3482 * function from SSR
3483 * @dev: pointer to net_device structure
3484 * @addr: Pointer to the sockaddr
3485 *
3486 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003487 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003488 *
3489 * Return: 0 for success.
3490 */
3491static int hdd_set_mac_address(struct net_device *dev, void *addr)
3492{
3493 int ret;
3494
3495 cds_ssr_protect(__func__);
3496 ret = __hdd_set_mac_address(dev, addr);
3497 cds_ssr_unprotect(__func__);
3498
3499 return ret;
3500}
3501
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003502uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003503{
3504 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003505
Dustin Brown61cc3932018-10-18 16:12:13 -07003506 i = qdf_ffz(hdd_ctx->config->intfAddrMask);
3507 if (i < 0 || i >= QDF_MAX_CONCURRENCY_PERSONA)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003508 return NULL;
3509
3510 hdd_ctx->config->intfAddrMask |= (1 << i);
Dustin Brown61cc3932018-10-18 16:12:13 -07003511
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303512 qdf_mem_copy(&hdd_ctx->dynamic_mac_list[i].bytes,
3513 &hdd_ctx->config->intfMacAddr[i].bytes,
3514 sizeof(struct qdf_mac_addr));
Dustin Brown61cc3932018-10-18 16:12:13 -07003515 return hdd_ctx->config->intfMacAddr[i].bytes;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003516}
3517
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003518void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3519 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003520{
3521 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003522
Anurag Chouhan6d760662016-02-20 16:05:43 +05303523 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003524 if (!memcmp(releaseAddr,
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303525 hdd_ctx->dynamic_mac_list[i].bytes,
Dustin Brown61cc3932018-10-18 16:12:13 -07003526 QDF_MAC_ADDR_SIZE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003527 hdd_ctx->config->intfAddrMask &= ~(1 << i);
3528 break;
3529 }
3530 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003531}
3532
3533#ifdef WLAN_FEATURE_PACKET_FILTERING
3534/**
3535 * __hdd_set_multicast_list() - set the multicast address list
3536 * @dev: Pointer to the WLAN device.
3537 * @skb: Pointer to OS packet (sk_buff).
3538 *
3539 * This funciton sets the multicast address list.
3540 *
3541 * Return: None
3542 */
3543static void __hdd_set_multicast_list(struct net_device *dev)
3544{
Jeff Johnson9d295242017-08-29 14:39:48 -07003545 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Dustin Brown0f874482018-06-13 14:39:22 -07003546 int i = 0, errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003547 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003548 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303549 struct pmo_mc_addr_list_params *mc_list_request = NULL;
Dustin Brown1dbefe62018-09-11 16:32:03 -07003550 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303551 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003552
Dustin Brownfdf17c12018-03-14 12:55:34 -07003553 hdd_enter_dev(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303554 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303555 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303556
Dustin Brown0f874482018-06-13 14:39:22 -07003557 errno = wlan_hdd_validate_context(hdd_ctx);
3558 if (errno)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303559 goto out;
3560
Dustin Brown0f874482018-06-13 14:39:22 -07003561 errno = hdd_validate_adapter(adapter);
3562 if (errno)
Dustin Brownc788acb2017-08-01 17:43:51 -07003563 goto out;
3564
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303565 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3566 hdd_err("%s: Driver module is closed", __func__);
Dustin Brown0f874482018-06-13 14:39:22 -07003567 goto out;
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303568 }
3569
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303570 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
Min Liu74a1a502018-10-10 19:59:07 +08003571 if (!mc_list_request)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303572 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003573
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303574 /* Delete already configured multicast address list */
3575 if (adapter->mc_addr_list.mc_cnt > 0) {
Dustin Brown0f874482018-06-13 14:39:22 -07003576 hdd_debug("clear previously configured MC address list");
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303577 hdd_disable_and_flush_mc_addr_list(adapter,
3578 pmo_mc_list_change_notify);
3579 }
3580
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003581 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003582 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303583 hdd_disable_and_flush_mc_addr_list(adapter,
3584 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003585 } else {
3586 mc_count = netdev_mc_count(dev);
Wu Gaod7dd6e42018-10-16 17:22:56 +08003587 if (mc_count > ucfg_pmo_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003588 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Wu Gaod7dd6e42018-10-16 17:22:56 +08003589 ucfg_pmo_max_mc_addr_supported(psoc));
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303590 hdd_disable_and_flush_mc_addr_list(adapter,
3591 pmo_mc_list_change_notify);
Dustin Brown0f874482018-06-13 14:39:22 -07003592 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003593 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003594 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003595 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303596 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003597 if (i == mc_count)
3598 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303599 memset(&(mc_list_request->mc_addr[i].bytes),
3600 0, ETH_ALEN);
3601 memcpy(&(mc_list_request->mc_addr[i].bytes),
3602 ha->addr, ETH_ALEN);
Dustin Brown0f874482018-06-13 14:39:22 -07003603 hdd_debug("mlist[%d] = %pM", i,
3604 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003605 i++;
3606 }
3607 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303608
3609 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003610 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303611 mc_list_request->count = mc_count;
Dustin Brown0f874482018-06-13 14:39:22 -07003612
3613 errno = hdd_cache_mc_addr_list(mc_list_request);
3614 if (errno) {
3615 hdd_err("Failed to cache MC address list for vdev %u; errno:%d",
3616 adapter->session_id, errno);
3617 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003618 }
Dustin Brown0f874482018-06-13 14:39:22 -07003619
3620 hdd_enable_mc_addr_filtering(adapter, pmo_mc_list_change_notify);
3621
3622free_req:
3623 qdf_mem_free(mc_list_request);
3624
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303625out:
Dustin Browne74003f2018-03-14 12:51:58 -07003626 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003627}
3628
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303629
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003630/**
3631 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3632 * @dev: pointer to net_device
3633 *
3634 * Return: none
3635 */
3636static void hdd_set_multicast_list(struct net_device *dev)
3637{
3638 cds_ssr_protect(__func__);
3639 __hdd_set_multicast_list(dev);
3640 cds_ssr_unprotect(__func__);
3641}
3642#endif
3643
3644/**
3645 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3646 * @dev: Pointer to the WLAN device.
3647 * @skb: Pointer to OS packet (sk_buff).
3648 *
3649 * This function is registered with the Linux OS for network
3650 * core to decide which queue to use first.
3651 *
3652 * Return: ac, Queue Index/access category corresponding to UP in IP header
3653 */
3654static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3655#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3656 , void *accel_priv
3657#endif
3658#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3659 , select_queue_fallback_t fallback
3660#endif
3661)
3662{
3663 return hdd_wmm_select_queue(dev, skb);
3664}
3665
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003666static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003667 .ndo_open = hdd_open,
3668 .ndo_stop = hdd_stop,
3669 .ndo_uninit = hdd_uninit,
3670 .ndo_start_xmit = hdd_hard_start_xmit,
3671 .ndo_tx_timeout = hdd_tx_timeout,
3672 .ndo_get_stats = hdd_get_stats,
3673 .ndo_do_ioctl = hdd_ioctl,
3674 .ndo_set_mac_address = hdd_set_mac_address,
3675 .ndo_select_queue = hdd_select_queue,
3676#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003677 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003678#endif
3679};
3680
Nirav Shah73713f72018-05-17 14:50:41 +05303681#ifdef FEATURE_MONITOR_MODE_SUPPORT
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003682/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003683static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003684 .ndo_open = hdd_mon_open,
3685 .ndo_stop = hdd_stop,
3686 .ndo_get_stats = hdd_get_stats,
3687};
3688
3689/**
3690 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003691 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003692 * Return: None
3693 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003694void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003695{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003696 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003697 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003698 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003699 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003700}
Nirav Shah73713f72018-05-17 14:50:41 +05303701#else
3702void hdd_set_station_ops(struct net_device *dev)
3703{
3704 dev->netdev_ops = &wlan_drv_ops;
3705}
3706#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003707
3708/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003709 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3710 * @hdd_ctx: global hdd context
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003711 * @mac_addr: mac address to assign to the interface
Ryan Hsu07495ea2016-01-21 15:25:39 -08003712 * @name: User-visible name of the interface
3713 *
3714 * hdd adapter pointer would point to the netdev->priv space, this function
Jeff Johnson62018292018-05-06 16:18:35 -07003715 * would retrieve the pointer, and setup the hdd adapter configuration.
Ryan Hsu07495ea2016-01-21 15:25:39 -08003716 *
3717 * Return: the pointer to hdd adapter, otherwise NULL
3718 */
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003719static struct hdd_adapter *
3720hdd_alloc_station_adapter(struct hdd_context *hdd_ctx, tSirMacAddr mac_addr,
3721 unsigned char name_assign_type, const char *name)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003722{
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003723 struct net_device *dev;
3724 struct hdd_adapter *adapter;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003725 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303726 QDF_STATUS qdf_status;
jitiphil377bcc12018-10-05 19:46:08 +05303727 void *soc;
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003728
jitiphil377bcc12018-10-05 19:46:08 +05303729 soc = cds_get_context(QDF_MODULE_ID_SOC);
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003730 /* cfg80211 initialization and registration */
3731 dev = alloc_netdev_mq(sizeof(*adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003732#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003733 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003734#endif
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003735 (cds_get_conparam() == QDF_GLOBAL_MONITOR_MODE ?
3736 hdd_mon_mode_ether_setup : ether_setup),
3737 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003738
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003739 if (!dev) {
3740 hdd_err("Failed to allocate new net_device '%s'", name);
3741 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003742 }
3743
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003744 adapter = netdev_priv(dev);
3745
3746 qdf_mem_zero(adapter, sizeof(*adapter));
3747 sta_ctx = &adapter->session.station;
3748 qdf_mem_set(sta_ctx->conn_info.staId, sizeof(sta_ctx->conn_info.staId),
3749 HDD_WLAN_INVALID_STA_ID);
3750 adapter->dev = dev;
3751 adapter->hdd_ctx = hdd_ctx;
3752 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
3753 adapter->session_id = HDD_SESSION_ID_INVALID;
3754
3755 qdf_status = qdf_event_create(&adapter->qdf_session_open_event);
3756 if (QDF_IS_STATUS_ERROR(qdf_status))
3757 goto free_net_dev;
3758
3759 qdf_status = qdf_event_create(&adapter->qdf_session_close_event);
3760 if (QDF_IS_STATUS_ERROR(qdf_status))
3761 goto free_net_dev;
3762
3763 adapter->offloads_configured = false;
3764 adapter->is_link_up_service_needed = false;
3765 adapter->disconnection_in_progress = false;
3766 adapter->send_mode_change = true;
3767
3768 /* Init the net_device structure */
3769 strlcpy(dev->name, name, IFNAMSIZ);
3770
3771 qdf_mem_copy(dev->dev_addr, mac_addr, sizeof(tSirMacAddr));
3772 qdf_mem_copy(adapter->mac_addr.bytes, mac_addr, sizeof(tSirMacAddr));
3773 dev->watchdog_timeo = HDD_TX_TIMEOUT;
3774
jitiphil377bcc12018-10-05 19:46:08 +05303775 if (cdp_cfg_get(soc,
3776 cfg_dp_enable_ip_tcp_udp_checksum_offload))
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003777 dev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
3778 dev->features |= NETIF_F_RXCSUM;
3779
3780 hdd_set_tso_flags(hdd_ctx, dev);
3781 hdd_set_station_ops(adapter->dev);
3782
3783 hdd_dev_setup_destructor(dev);
3784 dev->ieee80211_ptr = &adapter->wdev;
3785 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
3786 adapter->wdev.wiphy = hdd_ctx->wiphy;
3787 adapter->wdev.netdev = dev;
3788
3789 /* set dev's parent to underlying device */
3790 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
3791 hdd_wmm_init(adapter);
3792 spin_lock_init(&adapter->pause_map_lock);
3793 adapter->start_time = qdf_system_ticks();
3794 adapter->last_time = adapter->start_time;
3795
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003796 return adapter;
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003797
3798free_net_dev:
3799 free_netdev(adapter->dev);
3800
3801 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003802}
3803
Jeff Johnson9d295242017-08-29 14:39:48 -07003804static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003805{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003806 struct net_device *dev = adapter->dev;
3807 int ret;
3808
Dustin Brown491d54b2018-03-14 12:39:11 -07003809 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003810
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003811 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003812 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3813
3814 ret = dev_alloc_name(dev, dev->name);
3815 if (ret < 0) {
3816 hdd_err(
3817 "unable to get dev name: %s, err = 0x%x",
3818 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303819 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003820 }
3821 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003822
3823 ret = register_netdevice(dev);
3824 if (ret) {
3825 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3826 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303827 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003828 }
3829 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003830 ret = register_netdev(dev);
3831 if (ret) {
3832 hdd_err("register_netdev(%s) failed, err = 0x%x",
3833 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303834 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003835 }
3836 }
3837 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3838
Dustin Browne74003f2018-03-14 12:51:58 -07003839 hdd_exit();
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003840
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303841 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003842}
3843
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05303844QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id,
3845 QDF_STATUS qdf_status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003846{
Krunal Sonib51eec72017-11-20 21:53:01 -08003847 struct hdd_adapter *adapter;
3848 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003849
Krunal Sonib51eec72017-11-20 21:53:01 -08003850 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3851 if (!hdd_ctx) {
3852 hdd_err("Invalid HDD_CTX");
3853 return QDF_STATUS_E_FAILURE;
3854 }
3855
3856 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3857 if (NULL == adapter) {
Naveen Rawat23a3b912018-05-30 17:45:52 -07003858 hdd_err("NULL adapter for %d", session_id);
Krunal Sonib51eec72017-11-20 21:53:01 -08003859 return QDF_STATUS_E_INVAL;
3860 }
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05303861
3862 if (qdf_status == QDF_STATUS_SUCCESS)
3863 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3864
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303865 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003866 hdd_debug("session %d opened", adapter->session_id);
3867
3868 return QDF_STATUS_SUCCESS;
3869}
3870
3871QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3872{
3873 struct hdd_adapter *adapter;
3874 struct hdd_context *hdd_ctx;
3875
3876 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3877 if (!hdd_ctx) {
3878 hdd_err("Invalid HDD_CTX");
3879 return QDF_STATUS_E_FAILURE;
3880 }
3881
3882 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003883 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003884 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303885 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003886 }
3887
3888 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003889 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303890 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003891 }
3892
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003893 /*
3894 * For NAN Data interface, the close session results in the final
3895 * indication to the userspace
3896 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003897 if (adapter->device_mode == QDF_NDI_MODE)
3898 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003899
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003900 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3901
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003902 /*
3903 * We can be blocked while waiting for scheduled work to be
3904 * flushed, and the adapter structure can potentially be freed, in
3905 * which case the magic will have been reset. So make sure the
3906 * magic is still good, and hence the adapter structure is still
3907 * valid, before signaling completion
3908 */
3909 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303910 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003911
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303912 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003913}
3914
Jeff Johnson9d295242017-08-29 14:39:48 -07003915int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003916{
Dustin Brownd28772b2017-03-17 14:16:07 -07003917 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003918
Dustin Brown89fa06e2018-09-07 10:47:27 -07003919 status = pmo_vdev_ready(adapter->vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003920 if (QDF_IS_STATUS_ERROR(status))
3921 return qdf_status_to_os_return(status);
3922
Dustin Brown89fa06e2018-09-07 10:47:27 -07003923 status = ucfg_reg_11d_vdev_created_update(adapter->vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003924 if (QDF_IS_STATUS_ERROR(status))
3925 return qdf_status_to_os_return(status);
3926
3927 if (wma_capability_enhanced_mcast_filter())
Wu Gaod7dd6e42018-10-16 17:22:56 +08003928 status = ucfg_pmo_enhanced_mc_filter_enable(adapter->vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003929 else
Wu Gaod7dd6e42018-10-16 17:22:56 +08003930 status = ucfg_pmo_enhanced_mc_filter_disable(adapter->vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003931
3932 return qdf_status_to_os_return(status);
3933}
3934
Jeff Johnson9d295242017-08-29 14:39:48 -07003935int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003936{
3937 QDF_STATUS status;
Dustin Brown2da29eb2018-07-13 14:23:12 -07003938 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003939 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003940 uint8_t vdev_id;
Dustin Brownd28772b2017-03-17 14:16:07 -07003941
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003942 vdev_id = adapter->session_id;
3943 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003944
3945 /* vdev created sanity check */
3946 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Dustin Brown2da29eb2018-07-13 14:23:12 -07003947 hdd_err("vdev %u does not exist", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003948 return -EINVAL;
3949 }
Dustin Brown2da29eb2018-07-13 14:23:12 -07003950
Dustin Brown89fa06e2018-09-07 10:47:27 -07003951 status = ucfg_reg_11d_vdev_delete_update(adapter->vdev);
3952 ucfg_scan_set_vdev_del_in_progress(adapter->vdev);
Yue Maf9782842017-05-08 12:49:49 -07003953
Dustin Brownd28772b2017-03-17 14:16:07 -07003954 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303955 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07003956 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -07003957 status = sme_close_session(hdd_ctx->mac_handle, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003958 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Brown2da29eb2018-07-13 14:23:12 -07003959 hdd_err("failed to close sme session; status:%d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003960 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07003961 }
3962
3963 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303964 status = qdf_wait_for_event_completion(
3965 &adapter->qdf_session_close_event,
Abhishek Singh13bf0ce2018-10-24 14:26:14 +05303966 SME_CMD_VDEV_CREATE_DELETE_TIMEOUT);
Dustin Brown2da29eb2018-07-13 14:23:12 -07003967
3968 if (QDF_IS_STATUS_ERROR(status)) {
3969 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3970
Dustin Brownd28772b2017-03-17 14:16:07 -07003971 if (adapter->device_mode == QDF_NDI_MODE)
3972 hdd_ndp_session_end_handler(adapter);
Dustin Brown2da29eb2018-07-13 14:23:12 -07003973
3974 if (status == QDF_STATUS_E_TIMEOUT)
3975 hdd_err("timed out waiting for sme close session");
3976 else if (adapter->qdf_session_close_event.force_set)
3977 hdd_info("SSR occurred during sme close session");
3978 else
3979 hdd_err("failed to wait for sme close session; status:%u",
3980 status);
Dustin Brownd28772b2017-03-17 14:16:07 -07003981 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08003982
Yue Maf9782842017-05-08 12:49:49 -07003983release_vdev:
Jiachao Wu2c42c222018-01-15 18:13:19 +08003984
Sandeep Puligillaef415362017-08-30 16:37:13 -07003985 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08003986 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003987 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08003988 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003989 return errno;
3990 }
3991
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003992 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003993
3994 return 0;
3995}
3996
Krunal Sonib51eec72017-11-20 21:53:01 -08003997static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
3998 struct sme_session_params *session_param,
Jeff Johnson6a18c962018-07-01 09:09:37 -07003999 csr_roam_complete_cb callback,
Krunal Sonib51eec72017-11-20 21:53:01 -08004000 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07004001{
Dustin Brownd28772b2017-03-17 14:16:07 -07004002 uint32_t type;
4003 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08004004 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07004005
4006 /* determine vdev (sub)type */
4007 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304008 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07004009 hdd_err("failed to get vdev type: %d", status);
4010 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004011 }
Krunal Sonib51eec72017-11-20 21:53:01 -08004012 session_param->sme_session_id = adapter->session_id;
4013 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
4014 session_param->type_of_persona = type;
4015 session_param->subtype_of_persona = sub_type;
4016 session_param->session_open_cb = hdd_sme_open_session_callback;
4017 session_param->session_close_cb = hdd_sme_close_session_callback;
4018 session_param->callback = callback;
4019 session_param->callback_ctx = callback_ctx;
4020
4021 return 0;
4022}
4023
4024int hdd_vdev_create(struct hdd_adapter *adapter,
Jeff Johnson6a18c962018-07-01 09:09:37 -07004025 csr_roam_complete_cb callback, void *ctx)
Krunal Sonib51eec72017-11-20 21:53:01 -08004026{
4027 QDF_STATUS status;
4028 int errno;
4029 struct hdd_context *hdd_ctx;
4030 struct sme_session_params sme_session_params = {0};
Krunal Sonib51eec72017-11-20 21:53:01 -08004031
4032 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07004033
4034 /* do vdev create via objmgr */
4035 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown07901ec2018-09-07 11:02:41 -07004036 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07004037 if (errno) {
4038 hdd_err("failed to create objmgr vdev: %d", errno);
4039 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004040 }
Dustin Brownd28772b2017-03-17 14:16:07 -07004041
4042 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304043 status = qdf_event_reset(&adapter->qdf_session_open_event);
4044 if (QDF_STATUS_SUCCESS != status) {
4045 hdd_err("failed to reinit session open event");
4046 return -EINVAL;
4047 }
Krunal Sonib51eec72017-11-20 21:53:01 -08004048 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
4049 callback, ctx);
4050 if (errno) {
4051 hdd_err("failed to populating SME params");
4052 goto objmgr_vdev_destroy_procedure;
4053 }
4054
Jeff Johnson16528362018-06-14 12:34:16 -07004055 status = sme_open_session(hdd_ctx->mac_handle, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07004056 if (QDF_IS_STATUS_ERROR(status)) {
4057 hdd_err("failed to open sme session: %d", status);
4058 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07004059 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004060 }
4061
4062 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304063 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
Abhishek Singh13bf0ce2018-10-24 14:26:14 +05304064 SME_CMD_VDEV_CREATE_DELETE_TIMEOUT);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304065 if (QDF_STATUS_SUCCESS != status) {
4066 if (adapter->qdf_session_open_event.force_set) {
4067 /*
4068 * SSR/PDR has caused shutdown, which has forcefully
4069 * set the event. Return without the closing session.
4070 */
4071 adapter->session_id = HDD_SESSION_ID_INVALID;
4072 hdd_err("Session open event forcefully set");
4073 return -EINVAL;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304074 }
Jeff Johnsonc66d3102018-02-28 11:58:26 -08004075
4076 if (QDF_STATUS_E_TIMEOUT == status)
4077 hdd_err("Session failed to open within timeout period");
4078 else
4079 hdd_err("Failed to wait for session open event(status-%d)",
4080 status);
4081 errno = -ETIMEDOUT;
4082 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
4083 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004084 }
4085
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05304086 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
4087 hdd_err("Session failed to open due to vdev create failure");
4088 errno = -EINVAL;
4089 goto objmgr_vdev_destroy_procedure;
4090 }
4091
Dustin Brownd28772b2017-03-17 14:16:07 -07004092 /* firmware ready for component communication, raise vdev_ready event */
4093 errno = hdd_vdev_ready(adapter);
4094 if (errno) {
4095 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07004096 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004097 }
4098
Naveen Rawat2b430892018-03-13 13:58:18 -07004099 if (adapter->device_mode == QDF_STA_MODE) {
4100 hdd_debug("setting RTT mac randomization param: %d",
4101 hdd_ctx->config->enable_rtt_mac_randomization);
4102 errno = sme_cli_set_command(adapter->session_id,
4103 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_INITIATOR_RANDOM_MAC,
4104 hdd_ctx->config->enable_rtt_mac_randomization,
4105 VDEV_CMD);
4106 if (0 != errno)
4107 hdd_err("RTT mac randomization param set failed %d",
4108 errno);
4109 }
4110
Bala Venkatesh110b03e2018-07-10 16:02:08 +05304111 if (adapter->device_mode == QDF_STA_MODE ||
4112 adapter->device_mode == QDF_P2P_CLIENT_MODE)
Dustin Brown89fa06e2018-09-07 10:47:27 -07004113 wlan_vdev_set_max_peer_count(adapter->vdev,
Bala Venkatesh110b03e2018-07-10 16:02:08 +05304114 HDD_MAX_VDEV_PEER_COUNT);
4115
Jeff Johnson1b780e42017-10-31 14:11:45 -07004116 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004117
4118 return 0;
4119
4120 /*
4121 * Due to legacy constraints, we need to destroy in the same order as
4122 * create. So, split error handling into 2 cases to accommodate.
4123 */
4124
Krunal Soni4a020c72017-10-30 20:58:40 -07004125objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07004126 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07004127
4128 return errno;
4129
Krunal Soni4a020c72017-10-30 20:58:40 -07004130hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07004131 QDF_BUG(!hdd_vdev_destroy(adapter));
4132
4133 return errno;
4134}
4135
Jeff Johnson9d295242017-08-29 14:39:48 -07004136QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07004137{
Jeff Johnsonb9424862017-10-30 08:49:35 -07004138 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004139 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07004140 QDF_STATUS status;
4141 int ret_val;
Jeff Johnson16528362018-06-14 12:34:16 -07004142 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304143 bool bval = false;
Dustin Brownd28772b2017-03-17 14:16:07 -07004144
Dustin Brownd28772b2017-03-17 14:16:07 -07004145 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -07004146 mac_handle = hdd_ctx->mac_handle;
4147 sme_set_curr_device_mode(mac_handle, adapter->device_mode);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304148 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
4149 if (!QDF_IS_STATUS_SUCCESS(status))
4150 hdd_err("unable to get vht_enable2x2");
4151 sme_set_pdev_ht_vht_ies(mac_handle, bval);
4152
Jeff Johnson16528362018-06-14 12:34:16 -07004153 sme_set_vdev_ies_per_band(mac_handle, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004154
Jeff Johnson7f2c5912018-03-23 11:42:28 -07004155 hdd_roam_profile_init(adapter);
4156 hdd_register_wext(adapter->dev);
4157
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07004158 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004159
Jeff Johnsond377dce2017-10-04 10:32:42 -07004160 qdf_mem_set(sta_ctx->conn_info.staId,
4161 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05304162
Deepak Dhamdherea2785822016-11-17 01:17:45 -08004163 /* set fast roaming capability in sme session */
Jeff Johnson16528362018-06-14 12:34:16 -07004164 status = sme_config_fast_roaming(mac_handle, adapter->session_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05304165 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004166 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004167 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004168 hdd_ctx->config->OperatingChannel;
4169
4170 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004171 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004172
4173 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304174 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004175 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004176 status, status);
4177 goto error_init_txrx;
4178 }
4179
4180 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4181
4182 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304183 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004184 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004185 status, status);
4186 goto error_wmm_init;
4187 }
4188
4189 set_bit(WMM_INIT_DONE, &adapter->event_flags);
4190
Jeff Johnson1b780e42017-10-31 14:11:45 -07004191 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004192 WMI_PDEV_PARAM_BURST_ENABLE,
Dundi Raviteja3aa01be2018-05-21 18:58:59 +05304193 HDD_ENABLE_SIFS_BURST_DEFAULT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004194 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07004195 if (ret_val)
4196 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004197
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05304198 /*
4199 * In case of USB tethering, LRO is disabled. If SSR happened
4200 * during that time, then as part of SSR init, do not enable
4201 * the LRO again. Keep the LRO state same as before SSR.
4202 */
jitiphil377bcc12018-10-05 19:46:08 +05304203 if (cdp_cfg_get(cds_get_context(QDF_MODULE_ID_SOC),
4204 cfg_dp_lro_enable) &&
4205 !(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07004206 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05304207
4208 /* rcpi info initialization */
4209 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
4210
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304211 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004212
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004213error_wmm_init:
4214 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4215 hdd_deinit_tx_rx(adapter);
4216error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07004217 hdd_unregister_wext(adapter->dev);
Dustin Brownd28772b2017-03-17 14:16:07 -07004218 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004219
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004220 return status;
4221}
4222
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304223/**
Krunal Soni4a020c72017-10-30 20:58:40 -07004224 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304225 * @hdd_ctx: global hdd context
4226 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07004227 * @rtnl_held: Used to indicate whether or not the caller is holding
4228 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304229 *
4230 * This function De-initializes the STA/P2P/OCB adapter.
4231 *
4232 * Return: None.
4233 */
Krunal Soni4a020c72017-10-30 20:58:40 -07004234static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004235 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004236 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304237{
Dustin Brownfdf17c12018-03-14 12:55:34 -07004238 hdd_enter_dev(adapter->dev);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304239
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05304240 if (adapter->dev) {
4241 if (rtnl_held)
4242 adapter->dev->wireless_handlers = NULL;
4243 else {
4244 rtnl_lock();
4245 adapter->dev->wireless_handlers = NULL;
4246 rtnl_unlock();
4247 }
4248 }
4249
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304250 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
4251 hdd_deinit_tx_rx(adapter);
4252 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4253 }
4254
4255 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4256 hdd_wmm_adapter_close(adapter);
4257 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4258 }
4259
Krunal Sonib51eec72017-11-20 21:53:01 -08004260
Dustin Browne74003f2018-03-14 12:51:58 -07004261 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304262}
4263
Krunal Sonib51eec72017-11-20 21:53:01 -08004264void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
4265 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004266 bool rtnl_held)
4267{
Dustin Brown491d54b2018-03-14 12:39:11 -07004268 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304269
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004270 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004271 case QDF_STA_MODE:
4272 case QDF_P2P_CLIENT_MODE:
4273 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08004274 case QDF_IBSS_MODE:
4275 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004276 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004277 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004278 break;
4279 }
4280
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004281 case QDF_SAP_MODE:
4282 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004283 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004284 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004285 break;
4286 }
4287
4288 default:
4289 break;
4290 }
4291
Dustin Browne74003f2018-03-14 12:51:58 -07004292 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004293}
4294
Jeff Johnson9d295242017-08-29 14:39:48 -07004295static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004296 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004297{
Jeff Johnson5505db82017-11-02 21:19:23 -07004298 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004299
4300 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07004301 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004302 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004303 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004304 return;
4305 }
4306
Alok Kumarb64650c2018-03-23 17:05:11 +05304307 hdd_nud_deinit_tracking(adapter);
4308 qdf_mutex_destroy(&adapter->disconnection_status_lock);
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05304309 hdd_apf_context_destroy(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05304310
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05304311 wlan_hdd_debugfs_csr_deinit(adapter);
4312
Rajeev Kumardca5f812016-02-04 17:28:06 -08004313 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05304314
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004315 /*
4316 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
4317 * the driver is almost closed and cannot handle either control
4318 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004319 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
4320 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004321 * is not right. Setting this flag helps hdd_stop() to recognize that
4322 * the interface is closed and restricts any operations on that
4323 */
4324 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
4325
4326 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004327 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07004328 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004329 else
Jeff Johnson5505db82017-11-02 21:19:23 -07004330 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004331 /*
4332 * Note that the adapter is no longer valid at this point
4333 * since the memory has been reclaimed
4334 */
4335 }
4336}
4337
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004338static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07004339 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004340{
Jeff Johnson9d295242017-08-29 14:39:48 -07004341 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004342
Dustin Brown920397d2017-12-13 16:27:50 -08004343 hdd_for_each_adapter(hdd_ctx, adapter) {
4344 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
4345 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304346 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004347 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004348 }
Dustin Brown920397d2017-12-13 16:27:50 -08004349
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304350 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004351}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004352
Arun Khandavalli2358d522016-05-16 18:05:37 +05304353#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4354/**
4355 * hdd_set_fw_log_params() - Set log parameters to FW
4356 * @hdd_ctx: HDD Context
4357 * @adapter: HDD Adapter
4358 *
4359 * This function set the FW Debug log level based on the INI.
4360 *
4361 * Return: None
4362 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004363static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004364 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304365{
4366 uint8_t count = 0, numentries = 0,
4367 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
4368 uint32_t value = 0;
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304369 QDF_STATUS status;
4370 uint16_t enable_fw_log_level, enable_fw_log_type;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304371 int ret;
4372
Arun Khandavallifae92942016-08-01 13:31:08 +05304373 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4374 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004375 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304376 return;
4377 }
4378
Arun Khandavallifae92942016-08-01 13:31:08 +05304379 /* Enable FW logs based on INI configuration */
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304380 status = ucfg_fwol_get_enable_fw_log_type(hdd_ctx->psoc,
4381 &enable_fw_log_type);
4382 if (QDF_IS_STATUS_ERROR(status))
4383 return;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004384 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304385 WMI_DBGLOG_TYPE,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304386 enable_fw_log_type,
Arun Khandavallifae92942016-08-01 13:31:08 +05304387 DBG_CMD);
4388 if (ret != 0)
4389 hdd_err("Failed to enable FW log type ret %d",
4390 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304391
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304392 status = ucfg_fwol_get_enable_fw_log_level(hdd_ctx->psoc,
4393 &enable_fw_log_level);
4394 if (QDF_IS_STATUS_ERROR(status))
4395 return;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004396 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304397 WMI_DBGLOG_LOG_LEVEL,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304398 enable_fw_log_level,
Arun Khandavallifae92942016-08-01 13:31:08 +05304399 DBG_CMD);
4400 if (ret != 0)
4401 hdd_err("Failed to enable FW log level ret %d",
4402 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304403
4404 hdd_string_to_u8_array(
4405 hdd_ctx->config->enableFwModuleLogLevel,
4406 moduleloglevel,
4407 &numentries,
4408 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
4409
4410 while (count < numentries) {
4411 /*
4412 * FW module log level input string looks like
4413 * below:
4414 * gFwDebugModuleLoglevel=<FW Module ID>,
4415 * <Log Level>,...
4416 * For example:
4417 * gFwDebugModuleLoglevel=
4418 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
4419 * Above input string means :
4420 * For FW module ID 1 enable log level 0
4421 * For FW module ID 2 enable log level 1
4422 * For FW module ID 3 enable log level 2
4423 * For FW module ID 4 enable log level 3
4424 * For FW module ID 5 enable log level 4
4425 * For FW module ID 6 enable log level 5
4426 * For FW module ID 7 enable log level 6
4427 */
4428
Nishank Aggarwale239d962017-03-03 12:26:02 +05304429 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
4430 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
4431 hdd_err("Module id %d and dbglog level %d input length is more than max",
4432 moduleloglevel[count],
4433 moduleloglevel[count + 1]);
4434 return;
4435 }
4436
4437 value = moduleloglevel[count] << 16;
4438 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07004439 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304440 WMI_DBGLOG_MOD_LOG_LEVEL,
4441 value, DBG_CMD);
4442 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304443 hdd_err("Failed to enable FW module log level %d ret %d",
4444 value, ret);
4445
4446 count += 2;
4447 }
Arun Khandavallifae92942016-08-01 13:31:08 +05304448
Arun Khandavalli2358d522016-05-16 18:05:37 +05304449}
4450#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004451static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004452 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304453{
4454}
4455
4456#endif
4457
4458/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004459 * hdd_configure_chain_mask() - programs chain mask to firmware
4460 * @adapter: HDD adapter
4461 *
4462 * Return: 0 on success or errno on failure
4463 */
4464static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4465{
Naveen Rawat98322472018-03-06 10:29:42 -08004466 QDF_STATUS status;
4467 struct wma_caps_per_phy non_dbs_phy_cap;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004468 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304469 bool bval = false;
4470
4471 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
4472 if (!QDF_IS_STATUS_SUCCESS(status))
4473 hdd_err("unable to get vht_enable2x2");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004474
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304475 hdd_debug("enable2x2: %d, lte_coex: %d, disable_DBS: %d",
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304476 bval, hdd_ctx->lte_coex_ant_share,
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304477 hdd_ctx->config->dual_mac_feature_disable);
Liangwei Dong22810e82018-03-15 03:42:12 -04004478 hdd_debug("enable_bt_chain_separation %d",
4479 hdd_ctx->config->enable_bt_chain_separation);
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004480
Naveen Rawat98322472018-03-06 10:29:42 -08004481 status = wma_get_caps_for_phyidx_hwmode(&non_dbs_phy_cap,
4482 HW_MODE_DBS_NONE,
4483 CDS_BAND_ALL);
4484 if (QDF_IS_STATUS_ERROR(status)) {
4485 hdd_err("couldn't get phy caps. skip chain mask programming");
4486 return qdf_status_to_os_return(status);
4487 }
4488
4489 if (non_dbs_phy_cap.tx_chain_mask_2G < 3 ||
4490 non_dbs_phy_cap.rx_chain_mask_2G < 3 ||
4491 non_dbs_phy_cap.tx_chain_mask_5G < 3 ||
4492 non_dbs_phy_cap.rx_chain_mask_5G < 3) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004493 hdd_debug("firmware not capable. skip chain mask programming");
Naveen Rawat98322472018-03-06 10:29:42 -08004494 return 0;
4495 }
4496
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304497 if (bval && !hdd_ctx->config->enable_bt_chain_separation) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004498 hdd_debug("2x2 enabled. skip chain mask programming");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004499 return 0;
4500 }
4501
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004502 if (hdd_ctx->config->dual_mac_feature_disable !=
4503 DISABLE_DBS_CXN_AND_SCAN) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004504 hdd_debug("DBS enabled(%d). skip chain mask programming",
4505 hdd_ctx->config->dual_mac_feature_disable);
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004506 return 0;
4507 }
4508
Naveen Rawatdacb5032018-02-08 15:23:24 -08004509 if (hdd_ctx->lte_coex_ant_share) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004510 hdd_debug("lte ant sharing enabled. skip chainmask programming");
Naveen Rawatdacb5032018-02-08 15:23:24 -08004511 return 0;
4512 }
4513
Dustin Brown1dbefe62018-09-11 16:32:03 -07004514 status = ucfg_mlme_configure_chain_mask(hdd_ctx->psoc,
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304515 adapter->session_id);
4516 if (status != QDF_STATUS_SUCCESS)
4517 goto error;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004518
4519 return 0;
4520
4521error:
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304522 hdd_err("WMI PDEV set param failed");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004523 return -EINVAL;
4524}
4525
4526/**
Dundi Raviteja3b637092018-09-12 13:42:50 +05304527 * hdd_send_coex_config_params() - Send coex config params to FW
4528 * @hdd_ctx: HDD context
4529 * @adapter: Primary adapter context
4530 *
4531 * This function is used to send all coex config related params to FW
4532 *
4533 * Return: 0 on success and -EINVAL on failure
4534 */
4535static int hdd_send_coex_config_params(struct hdd_context *hdd_ctx,
4536 struct hdd_adapter *adapter)
4537{
4538 struct coex_config_params coex_cfg_params = {0};
4539 struct wlan_fwol_coex_config config = {0};
Dustin Brown05d81302018-09-11 16:49:22 -07004540 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Dundi Raviteja3b637092018-09-12 13:42:50 +05304541 QDF_STATUS status;
4542
4543 if (!hdd_ctx) {
4544 hdd_err("hdd_ctx is invalid");
4545 goto err;
4546 }
4547
4548 if (!adapter) {
4549 hdd_err("adapter is invalid");
4550 goto err;
4551 }
4552
4553 if (!psoc) {
4554 hdd_err("HDD psoc is invalid");
4555 goto err;
4556 }
4557
4558 status = ucfg_fwol_get_coex_config_params(psoc, &config);
4559 if (QDF_IS_STATUS_ERROR(status)) {
4560 hdd_err("Unable to get coex config params");
4561 goto err;
4562 }
4563
4564 coex_cfg_params.vdev_id = adapter->session_id;
4565 coex_cfg_params.config_type = WMI_COEX_CONFIG_TX_POWER;
4566 coex_cfg_params.config_arg1 = config.max_tx_power_for_btc;
4567
4568 status = sme_send_coex_config_cmd(&coex_cfg_params);
4569 if (QDF_IS_STATUS_ERROR(status)) {
4570 hdd_err("Failed to send coex Tx power");
4571 goto err;
4572 }
4573
4574 coex_cfg_params.config_type = WMI_COEX_CONFIG_HANDOVER_RSSI;
4575 coex_cfg_params.config_arg1 = config.wlan_low_rssi_threshold;
4576
4577 status = sme_send_coex_config_cmd(&coex_cfg_params);
4578 if (QDF_IS_STATUS_ERROR(status)) {
4579 hdd_err("Failed to send coex handover RSSI");
4580 goto err;
4581 }
4582
4583 coex_cfg_params.config_type = WMI_COEX_CONFIG_BTC_MODE;
4584 coex_cfg_params.config_arg1 = config.btc_mode;
4585
4586 status = sme_send_coex_config_cmd(&coex_cfg_params);
4587 if (QDF_IS_STATUS_ERROR(status)) {
4588 hdd_err("Failed to send coex BTC mode");
4589 goto err;
4590 }
4591
4592 coex_cfg_params.config_type = WMI_COEX_CONFIG_ANTENNA_ISOLATION;
4593 coex_cfg_params.config_arg1 = config.antenna_isolation;
4594
4595 status = sme_send_coex_config_cmd(&coex_cfg_params);
4596 if (QDF_IS_STATUS_ERROR(status)) {
4597 hdd_err("Failed to send coex antenna isolation");
4598 goto err;
4599 }
4600
4601 coex_cfg_params.config_type = WMI_COEX_CONFIG_BT_LOW_RSSI_THRESHOLD;
4602 coex_cfg_params.config_arg1 = config.bt_low_rssi_threshold;
4603
4604 status = sme_send_coex_config_cmd(&coex_cfg_params);
4605 if (QDF_IS_STATUS_ERROR(status)) {
4606 hdd_err("Failed to send coex BT low RSSI threshold");
4607 goto err;
4608 }
4609
4610 coex_cfg_params.config_type = WMI_COEX_CONFIG_BT_INTERFERENCE_LEVEL;
4611 coex_cfg_params.config_arg1 = config.bt_interference_low_ll;
4612 coex_cfg_params.config_arg2 = config.bt_interference_low_ul;
4613 coex_cfg_params.config_arg3 = config.bt_interference_medium_ll;
4614 coex_cfg_params.config_arg4 = config.bt_interference_medium_ul;
4615 coex_cfg_params.config_arg5 = config.bt_interference_high_ll;
4616 coex_cfg_params.config_arg6 = config.bt_interference_high_ul;
4617
4618 status = sme_send_coex_config_cmd(&coex_cfg_params);
4619 if (QDF_IS_STATUS_ERROR(status)) {
4620 hdd_err("Failed to send coex BT interference level");
4621 goto err;
4622 }
4623 return 0;
4624err:
4625 return -EINVAL;
4626}
4627
4628/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304629 * hdd_set_fw_params() - Set parameters to firmware
4630 * @adapter: HDD adapter
4631 *
4632 * This function Sets various parameters to fw once the
4633 * adapter is started.
4634 *
4635 * Return: 0 on success or errno on failure
4636 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004637int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304638{
4639 int ret;
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304640 uint16_t upper_brssi_thresh, lower_brssi_thresh, rts_profile;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304641 bool enable_dtim_1chrx;
4642 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004643 struct hdd_context *hdd_ctx;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304644 bool bval = false;
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05304645 uint8_t max_amsdu_len;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304646
Dustin Brownfdf17c12018-03-14 12:55:34 -07004647 hdd_enter_dev(adapter->dev);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304648
4649 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4650 if (!hdd_ctx)
4651 return -EINVAL;
4652
Dustin Brown732ab9c2017-06-15 13:24:09 -07004653 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4654 hdd_debug("FTM Mode is active; nothing to do");
4655 return 0;
4656 }
4657
Jeff Johnson1b780e42017-10-31 14:11:45 -07004658 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304659 WMI_PDEV_PARAM_DTIM_SYNTH,
4660 hdd_ctx->config->enable_lprx, PDEV_CMD);
4661 if (ret) {
4662 hdd_err("Failed to set LPRx");
4663 goto error;
4664 }
4665
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304666
4667 ret = sme_cli_set_command(
4668 adapter->session_id,
4669 WMI_PDEV_PARAM_1CH_DTIM_OPTIMIZED_CHAIN_SELECTION,
4670 hdd_ctx->config->enable_dtim_selection_diversity,
4671 PDEV_CMD);
4672 if (ret) {
4673 hdd_err("Failed to set DTIM_OPTIMIZED_CHAIN_SELECTION");
4674 goto error;
4675 }
4676
Ashish Kumar Dhanotiya48dac7d2018-03-28 14:59:50 +05304677 ret = sme_cli_set_command(
4678 adapter->session_id,
4679 WMI_PDEV_PARAM_TX_SCH_DELAY,
4680 hdd_ctx->config->enable_tx_sch_delay,
4681 PDEV_CMD);
4682 if (ret) {
4683 hdd_err("Failed to set WMI_PDEV_PARAM_TX_SCH_DELAY");
4684 goto error;
4685 }
4686
Ashish Kumar Dhanotiya959b38c2018-04-06 21:07:57 +05304687 ret = sme_cli_set_command(
4688 adapter->session_id,
4689 WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE,
4690 hdd_ctx->config->enable_secondary_rate,
4691 PDEV_CMD);
4692 if (ret) {
4693 hdd_err("Failed to set WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE");
4694 goto error;
4695 }
4696
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304697 if (adapter->device_mode == QDF_STA_MODE) {
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304698 status = ucfg_get_upper_brssi_thresh(hdd_ctx->psoc,
4699 &upper_brssi_thresh);
4700 if (QDF_IS_STATUS_ERROR(status))
4701 return -EINVAL;
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304702
Jeff Johnson1b780e42017-10-31 14:11:45 -07004703 sme_set_smps_cfg(adapter->session_id,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304704 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4705 upper_brssi_thresh);
4706
4707 status = ucfg_get_lower_brssi_thresh(hdd_ctx->psoc,
4708 &lower_brssi_thresh);
4709 if (QDF_IS_STATUS_ERROR(status))
4710 return -EINVAL;
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304711
Jeff Johnson1b780e42017-10-31 14:11:45 -07004712 sme_set_smps_cfg(adapter->session_id,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304713 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4714 lower_brssi_thresh);
4715
4716 status = ucfg_get_enable_dtim_1chrx(hdd_ctx->psoc,
4717 &enable_dtim_1chrx);
4718 if (QDF_IS_STATUS_ERROR(status))
4719 return -EINVAL;
4720
4721 sme_set_smps_cfg(adapter->session_id,
4722 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4723 enable_dtim_1chrx);
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304724 }
4725
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304726 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
4727 if (!QDF_IS_STATUS_SUCCESS(status))
4728 hdd_err("unable to get vht_enable2x2");
4729
4730 if (bval) {
Dustin Brown732ab9c2017-06-15 13:24:09 -07004731 hdd_debug("configuring 2x2 mode fw params");
4732
Vignesh Viswanathana851d752018-10-03 19:44:38 +05304733 ret = sme_set_cck_tx_fir_override(hdd_ctx->mac_handle,
4734 adapter->session_id);
Dustin Brown732ab9c2017-06-15 13:24:09 -07004735 if (ret) {
4736 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4737 ret);
4738 goto error;
4739 }
Liangwei Dong22810e82018-03-15 03:42:12 -04004740
4741 if (hdd_configure_chain_mask(adapter))
4742 goto error;
Dustin Brown732ab9c2017-06-15 13:24:09 -07004743 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304744#define HDD_DTIM_1CHAIN_RX_ID 0x5
4745#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004746 hdd_debug("configuring 1x1 mode fw params");
4747
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004748 /*
4749 * Disable DTIM 1 chain Rx when in 1x1,
4750 * we are passing two value
4751 * as param_id << 29 | param_value.
4752 * Below param_value = 0(disable)
4753 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004754 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004755 WMI_STA_SMPS_PARAM_CMDID,
4756 HDD_DTIM_1CHAIN_RX_ID <<
4757 HDD_SMPS_PARAM_VALUE_S,
4758 VDEV_CMD);
4759 if (ret) {
4760 hdd_err("DTIM 1 chain set failed %d", ret);
4761 goto error;
4762 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304763
Arun Khandavalli2358d522016-05-16 18:05:37 +05304764#undef HDD_DTIM_1CHAIN_RX_ID
4765#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004766
4767 if (hdd_configure_chain_mask(adapter))
4768 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004769 }
4770
Vignesh Viswanathana851d752018-10-03 19:44:38 +05304771 ret = sme_set_enable_mem_deep_sleep(hdd_ctx->mac_handle,
4772 adapter->session_id);
Dustin Brown732ab9c2017-06-15 13:24:09 -07004773 if (ret) {
4774 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4775 goto error;
4776 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304777
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304778 status = ucfg_fwol_get_rts_profile(hdd_ctx->psoc, &rts_profile);
4779 if (QDF_IS_STATUS_ERROR(status))
4780 return -EINVAL;
4781
Jeff Johnson1b780e42017-10-31 14:11:45 -07004782 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004783 WMI_VDEV_PARAM_ENABLE_RTSCTS,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304784 rts_profile,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004785 VDEV_CMD);
4786 if (ret) {
4787 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4788 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304789 }
4790
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05304791 status = ucfg_mlme_get_max_amsdu_num(hdd_ctx->psoc, &max_amsdu_len);
4792 if (QDF_IS_STATUS_ERROR(status)) {
4793 hdd_err("Failed to get Max AMSDU Num");
4794 goto error;
4795 }
4796
4797 hdd_debug("SET AMSDU num %d", max_amsdu_len);
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004798
Jeff Johnson1b780e42017-10-31 14:11:45 -07004799 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004800 GEN_VDEV_PARAM_AMSDU,
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05304801 max_amsdu_len,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004802 GEN_CMD);
4803 if (ret != 0) {
4804 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4805 goto error;
4806 }
4807
Arun Khandavalli2358d522016-05-16 18:05:37 +05304808 hdd_set_fw_log_params(hdd_ctx, adapter);
Dundi Raviteja3b637092018-09-12 13:42:50 +05304809
4810 ret = hdd_send_coex_config_params(hdd_ctx, adapter);
4811 if (ret) {
4812 hdd_warn("Error initializing coex config params");
4813 goto error;
4814 }
4815
Dustin Browne74003f2018-03-14 12:51:58 -07004816 hdd_exit();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004817
Arun Khandavalli2358d522016-05-16 18:05:37 +05304818 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304819
Arun Khandavalli2358d522016-05-16 18:05:37 +05304820error:
4821 return -EINVAL;
4822}
4823
Ryan Hsu07495ea2016-01-21 15:25:39 -08004824/**
Abhinav Kumarcc959f12018-08-09 13:58:30 +05304825 * hdd_init_completion() - Initialize Completion Variables
4826 * @adapter: HDD adapter
4827 *
4828 * This function Initialize the completion variables for
4829 * a particular adapter
4830 *
4831 * Return: None
4832 */
4833static void hdd_init_completion(struct hdd_adapter *adapter)
4834{
4835 init_completion(&adapter->disconnect_comp_var);
4836 init_completion(&adapter->roaming_comp_var);
4837 init_completion(&adapter->linkup_event_var);
4838 init_completion(&adapter->cancel_rem_on_chan_var);
4839 init_completion(&adapter->rem_on_chan_ready_event);
4840 init_completion(&adapter->sta_authorized_event);
4841 init_completion(&adapter->offchannel_tx_event);
4842 init_completion(&adapter->tx_action_cnf_event);
4843 init_completion(&adapter->ibss_peer_info_comp);
4844 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
4845}
4846
4847/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08004848 * hdd_open_adapter() - open and setup the hdd adatper
4849 * @hdd_ctx: global hdd context
4850 * @session_type: type of the interface to be created
4851 * @iface_name: User-visible name of the interface
4852 * @macAddr: MAC address to assign to the interface
4853 * @name_assign_type: the name of assign type of the netdev
4854 * @rtnl_held: the rtnl lock hold flag
4855 *
4856 * This function open and setup the hdd adpater according to the device
4857 * type request, assign the name, the mac address assigned, and then prepared
4858 * the hdd related parameters, queue, lock and ready to start.
4859 *
4860 * Return: the pointer of hdd adapter, otherwise NULL.
4861 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004862struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004863 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08004864 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004865 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004866{
Jeff Johnson9d295242017-08-29 14:39:48 -07004867 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304868 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05304869 uint8_t i;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004870
4871 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4872 /*
4873 * Max limit reached on the number of vdevs configured by the
4874 * host. Return error
4875 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304876 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4877 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004878 return NULL;
4879 }
4880
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05304881 status = wlan_hdd_validate_mac_address((struct qdf_mac_addr *)macAddr);
4882 if (QDF_IS_STATUS_ERROR(status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004883 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304884 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004885 return NULL;
4886 }
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05304887
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004888 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304889 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304890 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4891 " already exists",
4892 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004893 return NULL;
4894 }
4895
4896 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004897 case QDF_STA_MODE:
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05304898 /*
4899 * Reset locally administered bit for dynamic_mac_list
4900 * also as while releasing the MAC address for any interface
4901 * mac will be compared with dynamic mac list
4902 */
4903 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
4904 if (!qdf_mem_cmp(
4905 macAddr,
4906 &hdd_ctx->dynamic_mac_list[i].bytes[0],
4907 sizeof(struct qdf_mac_addr))) {
4908 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(
4909 hdd_ctx->dynamic_mac_list[i].bytes);
4910 break;
4911 }
4912 }
4913
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004914 /* Reset locally administered bit if the device mode is STA */
4915 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Dustin Brown7e761c72018-07-31 13:50:17 -07004916 hdd_debug("locally administered bit reset in sta mode: "
4917 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004918 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004919 case QDF_P2P_CLIENT_MODE:
4920 case QDF_P2P_DEVICE_MODE:
4921 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07004922 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304923 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004924 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4925 name_assign_type,
4926 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004927
4928 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304929 hdd_err("failed to allocate adapter for session %d",
4930 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004931 return NULL;
4932 }
4933
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004934 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004935 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004936 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004937 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304938 else if (QDF_MONITOR_MODE == session_type)
4939 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004940 else
4941 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4942
4943 adapter->device_mode = session_type;
4944
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004945
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004946 /*
4947 * Workqueue which gets scheduled in IPv4 notification
4948 * callback
4949 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004950 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004951 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004952
4953#ifdef WLAN_NS_OFFLOAD
4954 /*
4955 * Workqueue which gets scheduled in IPv6
4956 * notification callback.
4957 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004958 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004959 hdd_ipv6_notifier_work_queue);
4960#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004961 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004962 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004963 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004964
4965 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004966 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004967 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304968 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4969 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304970
Alok Kumarb64650c2018-03-23 17:05:11 +05304971 hdd_nud_init_tracking(adapter);
4972
4973 qdf_mutex_create(&adapter->disconnection_status_lock);
4974
Ravi Joshi1a292562017-05-18 16:28:54 -07004975 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004976
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004977 case QDF_P2P_GO_MODE:
4978 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004979 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4980 name_assign_type,
4981 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004982 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004983 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304984 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004985 return NULL;
4986 }
4987
4988 adapter->wdev.iftype =
4989 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004990 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004991 NL80211_IFTYPE_P2P_GO;
4992 adapter->device_mode = session_type;
4993
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004994 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004995 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004996 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004997
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004998 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004999 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305000 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5001 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305002
5003 /*
5004 * Workqueue which gets scheduled in IPv4 notification
5005 * callback
5006 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005007 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305008 hdd_ipv4_notifier_work_queue);
5009
5010#ifdef WLAN_NS_OFFLOAD
5011 /*
5012 * Workqueue which gets scheduled in IPv6
5013 * notification callback.
5014 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005015 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305016 hdd_ipv6_notifier_work_queue);
5017#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005018 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305019 case QDF_FTM_MODE:
5020 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
5021 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08005022 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305023 if (NULL == adapter) {
5024 hdd_err("Failed to allocate adapter for FTM mode");
5025 return NULL;
5026 }
5027 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
5028 adapter->device_mode = session_type;
5029 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08005030 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08005031 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08005032
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305033 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005034 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305035 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305036 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5037 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305038 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005039 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005040 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305041 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005042 return NULL;
5043 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005044
Abhinav Kumarcc959f12018-08-09 13:58:30 +05305045 hdd_init_completion(adapter);
hqueaa33ee2017-05-04 17:56:35 +08005046 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
Min Liu9be5d4a2018-05-17 11:51:53 +08005047 qdf_list_create(&adapter->blocked_scan_request_q, WLAN_MAX_SCAN_COUNT);
5048 qdf_mutex_create(&adapter->blocked_scan_request_q_lock);
hqueaa33ee2017-05-04 17:56:35 +08005049
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305050 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005051 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08005052 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005053 }
5054
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305055 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005056 if (NULL != adapter) {
5057 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
5058 adapter = NULL;
5059 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005060
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005061 return NULL;
5062 }
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05305063 hdd_apf_context_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005064
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305065 if (QDF_STATUS_SUCCESS == status) {
Dustin Brown1dbefe62018-09-11 16:32:03 -07005066 policy_mgr_set_concurrency_mode(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005067 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005068
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005069 /* Adapter successfully added. Increment the vdev count */
5070 hdd_ctx->current_intf_count++;
5071
Jeff Johnson5880d792016-08-15 13:32:30 -07005072 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005073 hdd_ctx->current_intf_count);
5074
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08005075 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005076 }
5077
Rajeev Kumardca5f812016-02-04 17:28:06 -08005078 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07005079 hdd_err("Interface %s wow debug_fs init failed",
5080 netdev_name(adapter->dev));
5081
Ajit Pal Singh106c1412018-04-18 18:08:49 +05305082 hdd_register_hl_netdev_fc_timer(adapter,
5083 hdd_tx_resume_timer_expired_handler);
5084
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07005085 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
5086 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005087
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05305088 if (adapter->device_mode == QDF_STA_MODE)
5089 wlan_hdd_debugfs_csr_init(adapter);
5090
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005091 return adapter;
5092
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005093err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07005094 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05305095 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005096
5097 return NULL;
5098}
5099
Dustin Brown728d65a2018-10-02 16:27:52 -07005100static void __hdd_close_adapter(struct hdd_context *hdd_ctx,
5101 struct hdd_adapter *adapter,
5102 bool rtnl_held)
5103{
5104 qdf_list_destroy(&adapter->blocked_scan_request_q);
5105 qdf_mutex_destroy(&adapter->blocked_scan_request_q_lock);
5106 policy_mgr_clear_concurrency_mode(hdd_ctx->psoc, adapter->device_mode);
5107
5108 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
5109
5110 if (hdd_ctx->current_intf_count != 0)
5111 hdd_ctx->current_intf_count--;
5112}
5113
5114void hdd_close_adapter(struct hdd_context *hdd_ctx,
5115 struct hdd_adapter *adapter,
5116 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005117{
Dustin Brown920397d2017-12-13 16:27:50 -08005118 /*
Dustin Brown728d65a2018-10-02 16:27:52 -07005119 * Stop the global bus bandwidth timer while touching the adapter list
5120 * to avoid bad memory access by the timer handler.
Dustin Brown920397d2017-12-13 16:27:50 -08005121 */
Dustin Brown920397d2017-12-13 16:27:50 -08005122 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005123
Dustin Brown920397d2017-12-13 16:27:50 -08005124 hdd_remove_adapter(hdd_ctx, adapter);
Dustin Brown728d65a2018-10-02 16:27:52 -07005125 __hdd_close_adapter(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005126
Dustin Brown920397d2017-12-13 16:27:50 -08005127 /* conditionally restart the bw timer */
5128 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005129}
5130
Dustin Brown728d65a2018-10-02 16:27:52 -07005131void hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005132{
Dustin Brown920397d2017-12-13 16:27:50 -08005133 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005134
Dustin Brown491d54b2018-03-14 12:39:11 -07005135 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005136
Dustin Brown728d65a2018-10-02 16:27:52 -07005137 while (QDF_IS_STATUS_SUCCESS(hdd_remove_front_adapter(hdd_ctx,
5138 &adapter))) {
5139 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
5140 __hdd_close_adapter(hdd_ctx, adapter, rtnl_held);
5141 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005142
Dustin Browne74003f2018-03-14 12:51:58 -07005143 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005144}
5145
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005146void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005147{
Anurag Chouhan6d760662016-02-20 16:05:43 +05305148 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005149 tSirUpdateIE updateIE;
Jeff Johnson16528362018-06-14 12:34:16 -07005150 mac_handle_t mac_handle;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005151
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005152 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005153 case QDF_STA_MODE:
5154 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005155 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005156 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005157 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07005158 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005159 break;
5160 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005161 case QDF_SAP_MODE:
5162 case QDF_P2P_GO_MODE:
5163 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005164 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07005165 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005166 break;
5167 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005168 case QDF_FTM_MODE:
5169 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005170 default:
5171 /*
5172 * wlan_hdd_reset_prob_rspies should not have been called
5173 * for these kind of devices
5174 */
Jeff Johnson5880d792016-08-15 13:32:30 -07005175 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005176 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005177 return;
5178 }
5179
Anurag Chouhanc5548422016-02-24 18:33:27 +05305180 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005181 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005182 updateIE.ieBufferlength = 0;
5183 updateIE.pAdditionIEBuffer = NULL;
5184 updateIE.append = true;
5185 updateIE.notify = false;
Jeff Johnson16528362018-06-14 12:34:16 -07005186 mac_handle = hdd_adapter_get_mac_handle(adapter);
5187 if (sme_update_add_ie(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005188 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305189 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005190 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005191 }
5192}
5193
Dustin Browndb2a8be2017-12-20 11:49:56 -08005194QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
5195 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005196{
Liangwei Dongad89c762018-06-01 01:56:23 -04005197 return hdd_stop_adapter_ext(hdd_ctx, adapter, 0);
5198}
5199
5200QDF_STATUS hdd_stop_adapter_ext(struct hdd_context *hdd_ctx,
5201 struct hdd_adapter *adapter,
5202 enum hdd_adapter_stop_flag_t flag)
5203{
Dustin Brownd747ecd2018-10-26 16:32:22 -07005204 QDF_STATUS status = QDF_STATUS_SUCCESS;
5205 struct hdd_station_ctx *sta_ctx;
Jeff Johnson025618c2018-03-18 14:41:00 -07005206 struct csr_roam_profile *roam_profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005207 union iwreq_data wrqu;
5208 tSirUpdateIE updateIE;
5209 unsigned long rc;
Jeff Johnsone4c11db2018-05-05 23:22:32 -07005210 tsap_config_t *sap_config;
Jeff Johnson16528362018-06-14 12:34:16 -07005211 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005212
Dustin Brown491d54b2018-03-14 12:39:11 -07005213 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005214
Dustin Browne7e71d32018-05-11 16:00:08 -07005215 if (adapter->session_id != HDD_SESSION_ID_INVALID)
5216 wlan_hdd_cfg80211_deregister_frames(adapter);
5217
Alok Kumarb64650c2018-03-23 17:05:11 +05305218 hdd_nud_ignore_tracking(adapter, true);
5219 hdd_nud_reset_tracking(adapter);
Alok Kumar016a1ac2018-09-16 09:55:50 +05305220 hdd_nud_flush_work(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05305221
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005222 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305223 wlan_hdd_netif_queue_control(adapter,
5224 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5225 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08005226 /*
5227 * if this is the last active connection check & stop the
5228 * opportunistic timer first
5229 */
Dustin Brownd747ecd2018-10-26 16:32:22 -07005230 if ((policy_mgr_get_connection_count(hdd_ctx->psoc) == 1 &&
5231 policy_mgr_mode_specific_connection_count(hdd_ctx->psoc,
5232 policy_mgr_convert_device_mode_to_qdf_type(
5233 adapter->device_mode), NULL) == 1) ||
5234 !policy_mgr_get_connection_count(hdd_ctx->psoc))
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08005235 policy_mgr_check_and_stop_opportunistic_timer(
Dustin Brown1dbefe62018-09-11 16:32:03 -07005236 hdd_ctx->psoc, adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -07005237
5238 mac_handle = hdd_ctx->mac_handle;
5239
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005240 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005241 case QDF_STA_MODE:
5242 case QDF_P2P_CLIENT_MODE:
5243 case QDF_IBSS_MODE:
5244 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005245 case QDF_NDI_MODE:
Dustin Brownd747ecd2018-10-26 16:32:22 -07005246 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
5247
5248 if (adapter->device_mode == QDF_NDI_MODE ||
5249 hdd_conn_is_connected(sta_ctx) ||
5250 hdd_is_connecting(sta_ctx)) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005251 INIT_COMPLETION(adapter->disconnect_comp_var);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005252
Jeff Johnson025618c2018-03-18 14:41:00 -07005253 roam_profile = hdd_roam_profile(adapter);
5254 /* For NDI do not use roam_profile */
Dustin Brownd747ecd2018-10-26 16:32:22 -07005255 if (adapter->device_mode == QDF_NDI_MODE)
5256 status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005257 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005258 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005259 eCSR_DISCONNECT_REASON_NDI_DELETE);
Jeff Johnson025618c2018-03-18 14:41:00 -07005260 else if (roam_profile->BSSType ==
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005261 eCSR_BSS_TYPE_START_IBSS)
Dustin Brownd747ecd2018-10-26 16:32:22 -07005262 status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005263 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005264 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005265 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Abhinav Kumar19a7a402018-07-12 17:36:57 +05305266 else if (adapter->device_mode == QDF_STA_MODE)
5267 wlan_hdd_disconnect(adapter,
5268 eCSR_DISCONNECT_REASON_DEAUTH);
5269 else
Dustin Brownd747ecd2018-10-26 16:32:22 -07005270 status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005271 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005272 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005273 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005274 /* success implies disconnect is queued */
5275 if (QDF_IS_STATUS_SUCCESS(status) &&
5276 adapter->device_mode != QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005277 rc = wait_for_completion_timeout(
5278 &adapter->disconnect_comp_var,
5279 msecs_to_jiffies
5280 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005281 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005282 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005283 }
Dustin Brownd747ecd2018-10-26 16:32:22 -07005284 if (QDF_IS_STATUS_ERROR(status))
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005285 hdd_warn("failed to post disconnect");
Dustin Brownd747ecd2018-10-26 16:32:22 -07005286
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005287 memset(&wrqu, '\0', sizeof(wrqu));
5288 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5289 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5290 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
5291 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05305292 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005293
Dustin Brownd747ecd2018-10-26 16:32:22 -07005294 wlan_hdd_scan_abort(adapter);
Wu Gao4a1ec8c2018-07-23 19:18:40 +08005295 wlan_hdd_cleanup_actionframe(adapter);
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05305296 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05305297 hdd_clear_fils_connection_info(adapter);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005298 hdd_deregister_tx_flow_control(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005299
5300#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005301 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005302#ifdef WLAN_NS_OFFLOAD
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005303 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005304#endif
5305#endif
5306
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05305307 if (adapter->device_mode == QDF_STA_MODE)
Dustin Brown07901ec2018-09-07 11:02:41 -07005308 wlan_cfg80211_sched_scan_stop(hdd_ctx->pdev,
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05305309 adapter->dev);
Dustin Browndb2a8be2017-12-20 11:49:56 -08005310
5311 if (wlan_hdd_try_disconnect(adapter)) {
Dustin Brownd747ecd2018-10-26 16:32:22 -07005312 hdd_err("Can't disconnect adapter");
Dustin Browndb2a8be2017-12-20 11:49:56 -08005313 return QDF_STATUS_E_FAILURE;
Krunal Soni985b8132017-02-10 18:49:08 -08005314 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08005315
Himanshu Agarwalb229a142017-12-21 10:16:45 +05305316 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005317 break;
5318
Rajeev Kumar3b906202018-02-01 10:55:14 -08005319 case QDF_MONITOR_MODE:
5320 wlan_hdd_scan_abort(adapter);
5321 hdd_deregister_tx_flow_control(adapter);
5322 hdd_vdev_destroy(adapter);
5323 break;
5324
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005325 case QDF_SAP_MODE:
Will Huang7049bae2018-08-13 17:25:02 +08005326 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
5327 cds_flush_delayed_work(&adapter->acs_pending_work);
5328 clear_bit(ACS_PENDING, &adapter->event_flags);
5329 }
Dustin Brownd747ecd2018-10-26 16:32:22 -07005330
wadesongf9b15ed2017-12-14 14:12:32 +08005331 wlan_hdd_scan_abort(adapter);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005332
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05305333 sap_config = &adapter->session.ap.sap_config;
Dustin Brownd747ecd2018-10-26 16:32:22 -07005334 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
5335
Dustin Brown07901ec2018-09-07 11:02:41 -07005336 ucfg_ipa_flush(hdd_ctx->pdev);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005337
Liangwei Dongad89c762018-06-01 01:56:23 -04005338 if (!(flag & HDD_IN_CAC_WORK_TH_CONTEXT))
5339 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Jeff Johnson46807cd2018-04-29 21:32:22 -07005340 /* fallthrough */
Dustin Browna5cf8e02017-10-19 16:04:19 -07005341
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005342 case QDF_P2P_GO_MODE:
Krunal Soni22208392017-09-29 18:10:34 -07005343 cds_flush_work(&adapter->sap_stop_bss_work);
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305344 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005345 wlan_hdd_undo_acs(adapter);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005346
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005347 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005348 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5349
5350 hdd_deregister_tx_flow_control(adapter);
Kapil Guptac1224bf2017-06-22 21:22:40 +05305351 hdd_destroy_acs_timer(adapter);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005352
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005353 mutex_lock(&hdd_ctx->sap_lock);
5354 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005355 status = wlansap_stop_bss(
5356 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005357
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305358 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07005359 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005360 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305361 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305362 qdf_stop_bss_event);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005363 status = qdf_wait_for_event_completion(
Nachiket Kukade0396b732017-11-14 16:35:16 +05305364 &hostapd_state->qdf_stop_bss_event,
Vignesh Viswanathan865daaa2018-10-11 19:30:44 +05305365 SME_CMD_START_STOP_BSS_TIMEOUT);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005366 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson5880d792016-08-15 13:32:30 -07005367 hdd_err("failure waiting for wlansap_stop_bss %d",
Dustin Brownd747ecd2018-10-26 16:32:22 -07005368 status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005369 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07005370 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005371 }
Dustin Brownd747ecd2018-10-26 16:32:22 -07005372
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005373 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -07005374 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005375 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005376 adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005377 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305378 adapter->device_mode,
5379 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005380
Anurag Chouhanc5548422016-02-24 18:33:27 +05305381 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07005382 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005383 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005384 updateIE.ieBufferlength = 0;
5385 updateIE.pAdditionIEBuffer = NULL;
5386 updateIE.append = false;
5387 updateIE.notify = false;
Dustin Brownd747ecd2018-10-26 16:32:22 -07005388
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005389 /* Probe bcn reset */
Dustin Brownd747ecd2018-10-26 16:32:22 -07005390 status = sme_update_add_ie(mac_handle, &updateIE,
5391 eUPDATE_IE_PROBE_BCN);
5392 if (status == QDF_STATUS_E_FAILURE)
5393 hdd_err("Could not pass PROBE_RSP_BCN to PE");
5394
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005395 /* Assoc resp reset */
Dustin Brownd747ecd2018-10-26 16:32:22 -07005396 status = sme_update_add_ie(mac_handle, &updateIE,
5397 eUPDATE_IE_ASSOC_RESP);
5398 if (status == QDF_STATUS_E_FAILURE)
5399 hdd_err("Could not pass ASSOC_RSP to PE");
5400
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005401 /* Reset WNI_CFG_PROBE_RSP Flags */
5402 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005403 }
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005404 clear_bit(SOFTAP_INIT_DONE, &adapter->event_flags);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005405 qdf_mem_free(adapter->session.ap.beacon);
5406 adapter->session.ap.beacon = NULL;
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005407
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305408 /*
5409 * If Do_Not_Break_Stream was enabled clear avoid channel list.
5410 */
Dustin Brown89fa06e2018-09-07 10:47:27 -07005411 if (policy_mgr_is_dnsc_set(adapter->vdev))
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305412 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
5413
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305414#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005415 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305416#ifdef WLAN_NS_OFFLOAD
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005417 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305418#endif
5419#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08005420
5421 hdd_vdev_destroy(adapter);
5422
Krunal Sonib51eec72017-11-20 21:53:01 -08005423 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005424 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005425 case QDF_OCB_MODE:
Dustin Brownd747ecd2018-10-26 16:32:22 -07005426 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08005427 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Dustin Brownd747ecd2018-10-26 16:32:22 -07005428 cds_get_context(QDF_MODULE_ID_TXRX),
5429 sta_ctx->conn_info.staId[0]);
Zhang Qian79d0d132018-02-05 13:40:16 +08005430 hdd_deregister_tx_flow_control(adapter);
5431 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005432 break;
5433 default:
5434 break;
5435 }
5436
Ajit Pal Singh106c1412018-04-18 18:08:49 +05305437 hdd_deregister_hl_netdev_fc_timer(adapter);
5438
Dustin Brown04348372017-12-14 16:13:39 -08005439 if (adapter->scan_info.default_scan_ies) {
5440 qdf_mem_free(adapter->scan_info.default_scan_ies);
5441 adapter->scan_info.default_scan_ies = NULL;
5442 }
5443
Dustin Browne74003f2018-03-14 12:51:58 -07005444 hdd_exit();
Dustin Brownd747ecd2018-10-26 16:32:22 -07005445
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305446 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005447}
5448
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305449/**
5450 * hdd_deinit_all_adapters - deinit all adapters
5451 * @hdd_ctx: HDD context
5452 * @rtnl_held: True if RTNL lock held
5453 *
5454 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005455void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305456{
Jeff Johnson9d295242017-08-29 14:39:48 -07005457 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305458
Dustin Brown491d54b2018-03-14 12:39:11 -07005459 hdd_enter();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305460
Dustin Brown920397d2017-12-13 16:27:50 -08005461 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305462 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305463
Dustin Browne74003f2018-03-14 12:51:58 -07005464 hdd_exit();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305465}
5466
Dustin Browndb2a8be2017-12-20 11:49:56 -08005467QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005468{
Jeff Johnson9d295242017-08-29 14:39:48 -07005469 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005470
Dustin Brown491d54b2018-03-14 12:39:11 -07005471 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005472
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305473 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5474
Dustin Brown920397d2017-12-13 16:27:50 -08005475 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08005476 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005477
Dustin Browne74003f2018-03-14 12:51:58 -07005478 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005479
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305480 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005481}
5482
Paul Zhang84fa9382017-11-10 21:18:21 +08005483static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
5484 struct hdd_adapter *adapter)
5485{
5486 switch (adapter->device_mode) {
5487 case QDF_STA_MODE:
5488 case QDF_P2P_CLIENT_MODE:
5489 case QDF_IBSS_MODE:
5490 case QDF_P2P_DEVICE_MODE:
5491 case QDF_NDI_MODE:
5492 wlan_hdd_scan_abort(adapter);
5493 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5494 if (adapter->device_mode == QDF_STA_MODE)
Dustin Brown07901ec2018-09-07 11:02:41 -07005495 wlan_cfg80211_sched_scan_stop(hdd_ctx->pdev,
5496 adapter->dev);
Paul Zhang84fa9382017-11-10 21:18:21 +08005497 break;
5498 case QDF_P2P_GO_MODE:
5499 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5500 break;
5501 case QDF_SAP_MODE:
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305502 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Paul Zhang84fa9382017-11-10 21:18:21 +08005503 wlan_hdd_undo_acs(adapter);
5504 break;
5505 default:
5506 break;
5507 }
5508}
5509
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005510QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005511{
Jeff Johnson9d295242017-08-29 14:39:48 -07005512 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07005513 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07005514 struct qdf_mac_addr peerMacAddr;
Yue Ma42654682018-01-11 16:55:24 -08005515 int sta_id;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05305516 bool value;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005517
Dustin Brown491d54b2018-03-14 12:39:11 -07005518 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005519
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305520 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5521
Dustin Brown920397d2017-12-13 16:27:50 -08005522 hdd_for_each_adapter(hdd_ctx, adapter) {
Dustin Brown5e89ef82018-03-14 11:50:23 -07005523 hdd_info("[SSR] reset adapter with device mode %s(%d)",
Dustin Brown458027c2018-10-19 12:26:27 -07005524 qdf_opmode_str(adapter->device_mode),
Dustin Brown5e89ef82018-03-14 11:50:23 -07005525 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305526
5527 if ((adapter->device_mode == QDF_STA_MODE) ||
Paul Zhang679025e2018-03-08 22:39:44 +08005528 (adapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305529 /* Stop tdls timers */
Dustin Brown89fa06e2018-09-07 10:47:27 -07005530 hdd_notify_tdls_reset_adapter(adapter->vdev);
Paul Zhang679025e2018-03-08 22:39:44 +08005531 adapter->session.station.hdd_reassoc_scenario = false;
5532 }
Dustin Brown05d81302018-09-11 16:49:22 -07005533 ucfg_mlme_get_sap_internal_restart(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05305534 if (value &&
Arun Khandavallicc544b32017-01-30 19:52:16 +05305535 adapter->device_mode == QDF_SAP_MODE) {
5536 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305537 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05305538 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005539 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08005540 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005541 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005542 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
5543 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305544 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305545 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005546 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005547 }
Nijun Gong104ccc72018-08-07 10:43:56 +08005548 /*
5549 * Clear fc flag if it was set before SSR to avoid TX queues
5550 * permanently stopped after SSR.
5551 * Here WLAN_START_ALL_NETIF_QUEUE will actually not start any
5552 * queue since it's blocked by reason WLAN_CONTROL_PATH.
5553 */
5554 if (adapter->pause_map & (1 << WLAN_DATA_FLOW_CONTROL))
5555 wlan_hdd_netif_queue_control(adapter,
5556 WLAN_START_ALL_NETIF_QUEUE,
5557 WLAN_DATA_FLOW_CONTROL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005558
Paul Zhang84fa9382017-11-10 21:18:21 +08005559 hdd_reset_scan_operation(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005560
5561 hdd_deinit_tx_rx(adapter);
Dustin Brown1dbefe62018-09-11 16:32:03 -07005562 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005563 adapter->device_mode, adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005564 hdd_green_ap_start_state_mc(hdd_ctx, adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305565 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005566 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5567 hdd_wmm_adapter_close(adapter);
5568 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5569 }
5570
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305571 if (adapter->device_mode == QDF_STA_MODE)
5572 hdd_clear_fils_connection_info(adapter);
5573
Wu Gao3545e642017-07-14 19:24:41 +08005574 if (adapter->device_mode == QDF_SAP_MODE) {
Jingxiang Geec113592018-08-09 15:40:39 +08005575 wlansap_cleanup_cac_timer(
5576 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Wu Gao3545e642017-07-14 19:24:41 +08005577 /*
5578 * If adapter is SAP, set session ID to invalid
5579 * since SAP session will be cleanup during SSR.
5580 */
Wu Gao36717432016-11-21 15:09:48 +08005581 wlansap_set_invalid_session(
5582 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Wu Gao3545e642017-07-14 19:24:41 +08005583 }
5584
Yue Ma42654682018-01-11 16:55:24 -08005585 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005586 if (adapter->device_mode == QDF_STA_MODE ||
5587 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005588 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005589 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07005590 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005591
Yue Ma42654682018-01-11 16:55:24 -08005592 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
Wu Gao6b81fc52018-05-24 19:27:27 +08005593 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Yue Ma42654682018-01-11 16:55:24 -08005594 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5595 if (adapter->sta_info[sta_id].in_use) {
5596 hdd_debug("[SSR] deregister STA with ID %d",
5597 sta_id);
5598 hdd_softap_deregister_sta(adapter,
5599 sta_id);
5600 adapter->sta_info[sta_id].in_use = 0;
5601 }
5602 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005603 }
5604
Alok Kumarb64650c2018-03-23 17:05:11 +05305605 hdd_nud_ignore_tracking(adapter, true);
Alok Kumar016a1ac2018-09-16 09:55:50 +05305606 hdd_nud_reset_tracking(adapter);
5607 hdd_nud_flush_work(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05305608 hdd_set_disconnect_status(adapter, false);
5609
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005610 hdd_softap_deinit_tx_rx(adapter);
Tiger Yu8c387702018-07-06 16:56:42 +08005611 hdd_deregister_tx_flow_control(adapter);
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005612
Yue Maf9782842017-05-08 12:49:49 -07005613 /* Destroy vdev which will be recreated during reinit. */
5614 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005615 }
5616
Dustin Browne74003f2018-03-14 12:51:58 -07005617 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005618
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305619 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005620}
5621
Dustin Brown4c663222018-10-23 14:19:36 -07005622bool hdd_is_any_interface_open(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305623{
Dustin Brown920397d2017-12-13 16:27:50 -08005624 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305625
Dustin Brown4c663222018-10-23 14:19:36 -07005626 if (hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) {
Arun Khandavalliba479c42017-07-26 21:29:40 +05305627 hdd_info("FTM mode, don't close the module");
Dustin Brown4c663222018-10-23 14:19:36 -07005628 return true;
Arun Khandavalliba479c42017-07-26 21:29:40 +05305629 }
5630
Dustin Brown920397d2017-12-13 16:27:50 -08005631 hdd_for_each_adapter(hdd_ctx, adapter) {
5632 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
Dustin Brown4c663222018-10-23 14:19:36 -07005633 test_bit(SME_SESSION_OPENED, &adapter->event_flags))
5634 return true;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305635 }
5636
Dustin Brown4c663222018-10-23 14:19:36 -07005637 return false;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305638}
5639
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305640bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305641{
5642 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5643 return true;
5644 else
5645 return false;
5646}
5647
Anurag Chouhanc4092922016-09-08 15:56:11 +05305648#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08005649 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305650struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5651 struct ieee80211_channel *channel,
5652 const u8 *bssid, const u8 *ssid,
5653 size_t ssid_len)
5654{
5655 return cfg80211_get_bss(wiphy, channel, bssid,
5656 ssid, ssid_len,
5657 WLAN_CAPABILITY_ESS,
5658 WLAN_CAPABILITY_ESS);
5659}
5660#else
5661struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5662 struct ieee80211_channel *channel,
5663 const u8 *bssid, const u8 *ssid,
5664 size_t ssid_len)
5665{
5666 return cfg80211_get_bss(wiphy, channel, bssid,
5667 ssid, ssid_len,
5668 IEEE80211_BSS_TYPE_ESS,
5669 IEEE80211_PRIVACY_ANY);
5670}
5671#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305672
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305673#if defined CFG80211_CONNECT_BSS || \
5674 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305675#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305676 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305677/**
5678 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5679 * @timeout_reason: reason for connect timeout
5680 *
5681 * This function is used to convert host timeout
5682 * reason enum to kernel specific enum.
5683 *
5684 * Return: nl timeout enum
5685 */
5686static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5687 tSirResultCodes timeout_reason)
5688{
5689 switch (timeout_reason) {
5690 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5691 return NL80211_TIMEOUT_SCAN;
5692 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5693 return NL80211_TIMEOUT_AUTH;
5694 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5695 return NL80211_TIMEOUT_ASSOC;
5696 default:
5697 return NL80211_TIMEOUT_UNSPECIFIED;
5698 }
5699}
5700
5701/**
5702 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5703 * @dev: network device
5704 * @bssid: bssid to which we want to associate
5705 * @timeout_reason: reason for connect timeout
5706 *
5707 * This API is used to send connection timeout reason to supplicant
5708 *
5709 * Return: void
5710 */
5711static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5712 const u8 *bssid,
5713 tSirResultCodes timeout_reason)
5714{
5715 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005716
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305717 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5718
5719 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5720 nl_timeout_reason);
5721}
5722
5723/**
5724 * __hdd_connect_bss() - API to send connection status to supplicant
5725 * @dev: network device
5726 * @bssid: bssid to which we want to associate
5727 * @req_ie: Request Information Element
5728 * @req_ie_len: len of the req IE
5729 * @resp_ie: Response IE
5730 * @resp_ie_len: len of ht response IE
5731 * @status: status
5732 * @gfp: Kernel Flag
5733 * @timeout_reason: reason for connect timeout
5734 *
5735 * Return: void
5736 */
5737static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5738 struct cfg80211_bss *bss, const u8 *req_ie,
5739 size_t req_ie_len, const u8 *resp_ie,
5740 size_t resp_ie_len, int status, gfp_t gfp,
5741 tSirResultCodes timeout_reason)
5742{
5743 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005744
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305745 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5746
5747 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5748 resp_ie, resp_ie_len, status, gfp,
5749 nl_timeout_reason);
5750}
5751#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305752#if defined CFG80211_CONNECT_TIMEOUT || \
5753 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305754static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5755 const u8 *bssid,
5756 tSirResultCodes timeout_reason)
5757{
5758 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5759}
5760#endif
5761
5762static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5763 struct cfg80211_bss *bss, const u8 *req_ie,
5764 size_t req_ie_len, const u8 *resp_ie,
5765 size_t resp_ie_len, int status, gfp_t gfp,
5766 tSirResultCodes timeout_reason)
5767{
5768 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5769 resp_ie, resp_ie_len, status, gfp);
5770}
5771#endif
5772
Abhishek Singha84d3952016-09-13 13:45:05 +05305773/**
5774 * hdd_connect_bss() - API to send connection status to supplicant
5775 * @dev: network device
5776 * @bssid: bssid to which we want to associate
5777 * @req_ie: Request Information Element
5778 * @req_ie_len: len of the req IE
5779 * @resp_ie: Response IE
5780 * @resp_ie_len: len of ht response IE
5781 * @status: status
5782 * @gfp: Kernel Flag
5783 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305784 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05305785 *
5786 * The API is a wrapper to send connection status to supplicant
5787 *
5788 * Return: Void
5789 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305790#if defined CFG80211_CONNECT_TIMEOUT || \
5791 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05305792static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5793 struct cfg80211_bss *bss, const u8 *req_ie,
5794 size_t req_ie_len, const u8 *resp_ie,
5795 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305796 bool connect_timeout,
5797 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305798{
5799 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305800 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305801 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305802 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5803 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305804}
5805#else
5806static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5807 struct cfg80211_bss *bss, const u8 *req_ie,
5808 size_t req_ie_len, const u8 *resp_ie,
5809 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305810 bool connect_timeout,
5811 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305812{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305813 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5814 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305815}
5816#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305817
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305818#if defined(WLAN_FEATURE_FILS_SK)
5819#if defined(CFG80211_CONNECT_DONE) || \
5820 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
5821#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
5822 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305823/**
5824 * hdd_populate_fils_params() - Populate FILS keys to connect response
5825 * @fils_params: connect response to supplicant
5826 * @fils_kek: FILS kek
5827 * @fils_kek_len: FILS kek length
5828 * @pmk: FILS PMK
5829 * @pmk_len: FILS PMK length
5830 * @pmkid: PMKID
5831 * @fils_seq_num: FILS Seq number
5832 *
5833 * Return: None
5834 */
5835static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5836 *fils_params, const uint8_t *fils_kek,
5837 size_t fils_kek_len, const uint8_t *pmk,
5838 size_t pmk_len, const uint8_t *pmkid,
5839 uint16_t fils_seq_num)
5840{
5841 /* Increament seq number to be used for next FILS */
5842 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
5843 fils_params->update_erp_next_seq_num = true;
5844 fils_params->fils_kek = fils_kek;
5845 fils_params->fils_kek_len = fils_kek_len;
5846 fils_params->pmk = pmk;
5847 fils_params->pmk_len = pmk_len;
5848 fils_params->pmkid = pmkid;
5849}
5850#else
5851static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5852 *fils_params, const uint8_t
5853 *fils_kek, size_t fils_kek_len,
5854 const uint8_t *pmk, size_t pmk_len,
5855 const uint8_t *pmkid,
5856 uint16_t fils_seq_num)
5857{ }
5858#endif
5859
Jeff Johnson172237b2017-11-07 15:32:59 -08005860void hdd_update_hlp_info(struct net_device *dev,
5861 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305862{
5863 struct sk_buff *skb;
5864 uint16_t skb_len;
5865 struct llc_snap_hdr_t *llc_hdr;
5866 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305867 uint8_t *hlp_data;
5868 uint16_t hlp_data_len;
5869 struct fils_join_rsp_params *roam_fils_params
5870 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305871 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
5872
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305873 if (!roam_fils_params) {
5874 hdd_err("FILS Roam Param NULL");
5875 return;
5876 }
5877
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08005878 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305879 hdd_err("FILS HLP Data NULL, len %d",
5880 roam_fils_params->hlp_data_len);
5881 return;
5882 }
5883
5884 hlp_data = roam_fils_params->hlp_data;
5885 hlp_data_len = roam_fils_params->hlp_data_len;
5886
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305887 /* Calculate skb length */
5888 skb_len = (2 * ETH_ALEN) + hlp_data_len;
5889 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
5890 if (skb == NULL) {
5891 hdd_err("HLP packet nbuf alloc fails");
5892 return;
5893 }
5894
5895 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
5896 QDF_MAC_ADDR_SIZE);
5897 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
5898 QDF_MAC_ADDR_SIZE);
5899
5900 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
5901 if (IS_SNAP(llc_hdr)) {
5902 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5903 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5904 }
5905
5906 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
5907
5908 /*
5909 * This HLP packet is formed from HLP info encapsulated
5910 * in assoc response frame which is AEAD encrypted.
5911 * Hence, this checksum validation can be set unnecessary.
5912 * i.e. network layer need not worry about checksum.
5913 */
5914 skb->ip_summed = CHECKSUM_UNNECESSARY;
5915
5916 status = hdd_rx_packet_cbk(padapter, skb);
5917 if (QDF_IS_STATUS_ERROR(status)) {
5918 hdd_err("Sending HLP packet fails");
5919 return;
5920 }
5921 hdd_debug("send HLP packet to netif successfully");
5922}
5923
5924/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305925 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
5926 * @dev: network device
5927 * @bssid: bssid to which we want to associate
5928 * @bss: cfg80211 bss info
5929 * @roam_info: information about connected bss
5930 * @req_ie: Request Information Element
5931 * @req_ie_len: len of the req IE
5932 * @resp_ie: Response IE
5933 * @resp_ie_len: len of ht response IE
5934 * @status: status
5935 * @gfp: allocation flags
5936 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5937 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305938 *
5939 * This API is used as wrapper to send FILS key/sequence number
5940 * params etc. to supplicant in case of FILS connection
5941 *
5942 * Return: None
5943 */
5944static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005945 struct cfg80211_bss *bss,
5946 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305947 const u8 *req_ie, size_t req_ie_len,
5948 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005949 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305950 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305951{
5952 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305953 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5954 struct fils_join_rsp_params *roam_fils_params =
5955 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005956
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305957 qdf_mem_zero(&fils_params, sizeof(fils_params));
5958
5959 if (!roam_fils_params) {
5960 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5961 } else {
5962 fils_params.status = status;
5963 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08005964 fils_params.timeout_reason =
5965 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305966 fils_params.req_ie = req_ie;
5967 fils_params.req_ie_len = req_ie_len;
5968 fils_params.resp_ie = resp_ie;
5969 fils_params.resp_ie_len = resp_ie_len;
5970 fils_params.bss = bss;
5971 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5972 roam_fils_params->kek_len,
5973 roam_fils_params->fils_pmk,
5974 roam_fils_params->fils_pmk_len,
5975 roam_fils_params->fils_pmkid,
5976 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305977 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305978 }
5979 hdd_debug("FILS indicate connect status %d seq no %d",
5980 fils_params.status,
5981 fils_params.fils_erp_next_seq_num);
5982
5983 cfg80211_connect_done(dev, &fils_params, gfp);
5984
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305985 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305986 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305987
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305988 /* Clear all the FILS key info */
5989 if (roam_fils_params && roam_fils_params->fils_pmk)
5990 qdf_mem_free(roam_fils_params->fils_pmk);
5991 if (roam_fils_params)
5992 qdf_mem_free(roam_fils_params);
5993 roam_info->fils_join_rsp = NULL;
5994}
5995#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005996static inline void
5997hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005998 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005999 const u8 *req_ie, size_t req_ie_len,
6000 const u8 *resp_ie, size_t resp_ie_len, u16 status,
6001 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306002 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306003{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306004#endif
6005#endif
6006
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306007#if defined(WLAN_FEATURE_FILS_SK) && \
6008 (defined(CFG80211_CONNECT_DONE) || \
6009 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306010/**
6011 * hdd_fils_update_connect_results() - API to send fils connection status to
6012 * supplicant.
6013 * @dev: network device
6014 * @bssid: bssid to which we want to associate
6015 * @bss: cfg80211 bss info
6016 * @roam_info: information about connected bss
6017 * @req_ie: Request Information Element
6018 * @req_ie_len: len of the req IE
6019 * @resp_ie: Response IE
6020 * @resp_ie_len: len of ht response IE
6021 * @status: status
6022 * @gfp: allocation flags
6023 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
6024 * @timeout_reason: reason for connect timeout
6025 *
6026 * The API is a wrapper to send connection status to supplicant
6027 *
6028 * Return: 0 if success else failure
6029 */
6030static int hdd_fils_update_connect_results(struct net_device *dev,
6031 const u8 *bssid,
6032 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08006033 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306034 size_t req_ie_len, const u8 *resp_ie,
6035 size_t resp_ie_len, u16 status, gfp_t gfp,
6036 bool connect_timeout,
6037 tSirResultCodes timeout_reason)
6038{
Dustin Brown491d54b2018-03-14 12:39:11 -07006039 hdd_enter();
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306040 if (!roam_info || !roam_info->is_fils_connection)
6041 return -EINVAL;
6042
6043 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
6044 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306045 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306046 return 0;
6047}
6048#else
6049static inline int hdd_fils_update_connect_results(struct net_device *dev,
6050 const u8 *bssid,
6051 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08006052 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306053 size_t req_ie_len, const u8 *resp_ie,
6054 size_t resp_ie_len, u16 status, gfp_t gfp,
6055 bool connect_timeout,
6056 tSirResultCodes timeout_reason)
6057{
6058 return -EINVAL;
6059}
6060#endif
6061
Anurag Chouhanc4092922016-09-08 15:56:11 +05306062/**
6063 * hdd_connect_result() - API to send connection status to supplicant
6064 * @dev: network device
6065 * @bssid: bssid to which we want to associate
6066 * @roam_info: information about connected bss
6067 * @req_ie: Request Information Element
6068 * @req_ie_len: len of the req IE
6069 * @resp_ie: Response IE
6070 * @resp_ie_len: len of ht response IE
6071 * @status: status
6072 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05306073 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306074 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05306075 *
6076 * The API is a wrapper to send connection status to supplicant
6077 * and allow runtime suspend
6078 *
6079 * Return: Void
6080 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306081void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006082 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05306083 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05306084 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306085 bool connect_timeout,
6086 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05306087{
Jeff Johnson9d295242017-08-29 14:39:48 -07006088 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306089 struct cfg80211_bss *bss = NULL;
Jingxiang Ge929c7932018-01-24 14:01:12 +08006090 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306091
6092 if (WLAN_STATUS_SUCCESS == status) {
6093 struct ieee80211_channel *chan;
6094 int freq;
6095 int chan_no = roam_info->pBssDesc->channelId;
6096
6097 if (chan_no <= 14)
6098 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07006099 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306100 else
6101 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07006102 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306103
6104 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
6105 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
6106 roam_info->u.pConnectedProfile->SSID.ssId,
6107 roam_info->u.pConnectedProfile->SSID.length);
6108 }
Komal Seelama89be8d2016-09-29 11:09:26 +05306109
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306110 if (hdd_fils_update_connect_results(dev, bssid, bss,
6111 roam_info, req_ie, req_ie_len, resp_ie,
6112 resp_ie_len, status, gfp, connect_timeout,
6113 timeout_reason) != 0) {
6114 hdd_connect_bss(dev, bssid, bss, req_ie,
6115 req_ie_len, resp_ie, resp_ie_len,
6116 status, gfp, connect_timeout, timeout_reason);
6117 }
Komal Seelama89be8d2016-09-29 11:09:26 +05306118
Jingxiang Geb49aa302018-01-17 20:54:15 +08006119 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07006120 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306121}
6122#else
6123void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006124 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05306125 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05306126 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306127 bool connect_timeout,
6128 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05306129{
Jeff Johnson9d295242017-08-29 14:39:48 -07006130 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Jingxiang Ge929c7932018-01-24 14:01:12 +08006131 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05306132
Anurag Chouhanc4092922016-09-08 15:56:11 +05306133 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
6134 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08006135
Jingxiang Geb49aa302018-01-17 20:54:15 +08006136 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07006137 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306138}
6139#endif
6140
Nirav Shah73713f72018-05-17 14:50:41 +05306141#ifdef FEATURE_MONITOR_MODE_SUPPORT
Jeff Johnsond9952752018-04-18 12:15:35 -07006142int wlan_hdd_set_mon_chan(struct hdd_adapter *adapter, uint32_t chan,
6143 uint32_t bandwidth)
6144{
6145 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6146 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
6147 struct hdd_mon_set_ch_info *ch_info = &sta_ctx->ch_info;
6148 QDF_STATUS status;
Jeff Johnson43837af2018-10-17 12:44:05 -07006149 mac_handle_t mac_handle = hdd_ctx->mac_handle;
Jeff Johnsond9952752018-04-18 12:15:35 -07006150 struct qdf_mac_addr bssid;
6151 struct csr_roam_profile roam_profile;
6152 struct ch_params ch_params;
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006153 eConnectionState connstate;
Jeff Johnsond9952752018-04-18 12:15:35 -07006154
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006155 if (hdd_get_conparam() != QDF_GLOBAL_MONITOR_MODE &&
6156 adapter->device_mode != QDF_STA_MODE) {
6157 hdd_err("Not supported, device is not in monitor mode or sta mission mode");
Jeff Johnsond9952752018-04-18 12:15:35 -07006158 return -EINVAL;
6159 }
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006160 if (adapter->device_mode == QDF_STA_MODE &&
6161 hdd_ctx->config->enable_change_channel_bandwidth) {
6162 connstate = sta_ctx->conn_info.connState;
6163 if (eConnectionState_Associated == connstate ||
6164 eConnectionState_Connecting == connstate) {
6165 return -EINVAL;
6166 }
6167 }
Jeff Johnsond9952752018-04-18 12:15:35 -07006168
Visweswara Tanuku006313a2018-04-12 12:26:34 +05306169 /* Validate Channel */
6170 if (!WLAN_REG_IS_24GHZ_CH(chan) && !WLAN_REG_IS_5GHZ_CH(chan)) {
6171 hdd_err("Channel %d Not supported", chan);
6172 return -EINVAL;
6173 }
6174
6175 if (WLAN_REG_IS_24GHZ_CH(chan)) {
6176 if (bandwidth == CH_WIDTH_80MHZ) {
6177 hdd_err("BW80 not possible in 2.4GHz band");
6178 return -EINVAL;
6179 }
6180 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 14) &&
6181 (bandwidth != CH_WIDTH_MAX)) {
6182 hdd_err("Only BW20 possible on channel 14");
6183 return -EINVAL;
6184 }
6185 }
6186
6187 if (WLAN_REG_IS_5GHZ_CH(chan)) {
6188 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 165) &&
6189 (bandwidth != CH_WIDTH_MAX)) {
6190 hdd_err("Only BW20 possible on channel 165");
6191 return -EINVAL;
6192 }
6193 }
6194
Jeff Johnsond9952752018-04-18 12:15:35 -07006195 hdd_debug("Set monitor mode Channel %d", chan);
6196 qdf_mem_zero(&roam_profile, sizeof(roam_profile));
6197 roam_profile.ChannelInfo.ChannelList = &ch_info->channel;
6198 roam_profile.ChannelInfo.numOfChannels = 1;
6199 roam_profile.phyMode = ch_info->phy_mode;
6200 roam_profile.ch_params.ch_width = bandwidth;
6201 hdd_select_cbmode(adapter, chan, &roam_profile.ch_params);
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006202 if (hdd_ctx->config->enable_change_channel_bandwidth &&
Jeff Johnson43837af2018-10-17 12:44:05 -07006203 (!sme_find_session_by_bssid(mac_handle, adapter->mac_addr.bytes))) {
6204 status = sme_create_mon_session(mac_handle,
Rajeev Kumar Sirasanagandlae3b59912018-08-24 15:53:31 +05306205 adapter->mac_addr.bytes,
6206 adapter->session_id);
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006207 if (status != QDF_STATUS_SUCCESS) {
6208 hdd_err("Status: %d Failed to create session.",
6209 status);
6210 return qdf_status_to_os_return(status);
6211 }
6212 }
Jeff Johnsond9952752018-04-18 12:15:35 -07006213 qdf_mem_copy(bssid.bytes, adapter->mac_addr.bytes,
6214 QDF_MAC_ADDR_SIZE);
6215
6216 ch_params.ch_width = bandwidth;
Dustin Brown07901ec2018-09-07 11:02:41 -07006217 wlan_reg_set_channel_params(hdd_ctx->pdev, chan, 0, &ch_params);
Jeff Johnsond9952752018-04-18 12:15:35 -07006218 if (ch_params.ch_width == CH_WIDTH_INVALID) {
6219 hdd_err("Invalid capture channel or bandwidth for a country");
6220 return -EINVAL;
6221 }
6222 if (wlan_hdd_change_hw_mode_for_given_chnl(adapter, chan,
6223 POLICY_MGR_UPDATE_REASON_SET_OPER_CHAN)) {
6224 hdd_err("Failed to change hw mode");
6225 return -EINVAL;
6226 }
6227
Jeff Johnson16528362018-06-14 12:34:16 -07006228 status = sme_roam_channel_change_req(hdd_ctx->mac_handle,
6229 bssid, &ch_params,
Jeff Johnsond9952752018-04-18 12:15:35 -07006230 &roam_profile);
6231 if (status) {
6232 hdd_err("Status: %d Failed to set sme_roam Channel for monitor mode",
6233 status);
6234 }
6235
6236 adapter->mon_chan = chan;
6237 adapter->mon_bandwidth = bandwidth;
6238 return qdf_status_to_os_return(status);
6239}
Nirav Shah73713f72018-05-17 14:50:41 +05306240#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05306241
Wu Gaodf929f12018-05-25 18:12:25 +08006242#ifdef MSM_PLATFORM
6243/**
6244 * hdd_stop_p2p_go() - call cfg80211 API to stop P2P GO
6245 * @adapter: pointer to adapter
6246 *
6247 * This function calls cfg80211 API to stop P2P GO
6248 *
6249 * Return: None
6250 */
6251static void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6252{
6253 hdd_debug("[SSR] send stop ap to supplicant");
6254 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
6255}
6256
6257static inline void hdd_delete_sta(struct hdd_adapter *adapter)
6258{
6259}
6260#else
6261static inline void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6262{
6263}
6264
6265/**
6266 * hdd_delete_sta() - call cfg80211 API to delete STA
6267 * @adapter: pointer to adapter
6268 *
6269 * This function calls cfg80211 API to delete STA
6270 *
6271 * Return: None
6272 */
6273static void hdd_delete_sta(struct hdd_adapter *adapter)
6274{
6275 struct qdf_mac_addr bcast_mac = QDF_MAC_ADDR_BCAST_INIT;
6276
6277 hdd_debug("[SSR] send restart supplicant");
6278 /* event supplicant to restart */
6279 cfg80211_del_sta(adapter->dev,
6280 (const u8 *)&bcast_mac.bytes[0],
6281 GFP_KERNEL);
6282}
6283#endif
6284
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006285QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006286{
Jeff Johnson9d295242017-08-29 14:39:48 -07006287 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006288 eConnectionState connState;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05306289 bool value;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006290
Dustin Brown491d54b2018-03-14 12:39:11 -07006291 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006292
Dustin Brown920397d2017-12-13 16:27:50 -08006293 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05306294 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08006295 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05306296
Yue Ma42654682018-01-11 16:55:24 -08006297 hdd_debug("[SSR] start adapter with device mode %s(%d)",
Dustin Brown458027c2018-10-19 12:26:27 -07006298 qdf_opmode_str(adapter->device_mode),
Yue Ma42654682018-01-11 16:55:24 -08006299 adapter->device_mode);
6300
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006301 hdd_wmm_init(adapter);
6302
6303 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006304 case QDF_STA_MODE:
6305 case QDF_P2P_CLIENT_MODE:
6306 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006307
6308 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
6309 ->conn_info.connState;
6310
Krunal Sonib51eec72017-11-20 21:53:01 -08006311 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006312 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07006313 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006314
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006315 /* Indicate disconnect event to supplicant
6316 * if associated previously
6317 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006318 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07006319 eConnectionState_IbssConnected == connState ||
6320 eConnectionState_NotConnected == connState ||
6321 eConnectionState_IbssDisconnected == connState ||
6322 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006323 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006324
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006325 memset(&wrqu, '\0', sizeof(wrqu));
6326 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
6327 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
6328 wireless_send_event(adapter->dev, SIOCGIWAP,
6329 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07006330 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07006331 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006332
6333 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05306334 wlan_hdd_cfg80211_indicate_disconnect(
6335 adapter->dev, false,
6336 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006337 } else if (eConnectionState_Connecting == connState) {
6338 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006339 * Indicate connect failure to supplicant if we
6340 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006341 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306342 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306343 NULL, 0, NULL, 0,
6344 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006345 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006346 }
6347
6348 hdd_register_tx_flow_control(adapter,
6349 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08006350 hdd_tx_resume_cb,
6351 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006352
Arunk Khandavalli40943af2017-05-15 19:25:34 +05306353 hdd_lpass_notify_start(hdd_ctx, adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05306354 hdd_nud_ignore_tracking(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006355 break;
6356
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006357 case QDF_SAP_MODE:
Dustin Brown05d81302018-09-11 16:49:22 -07006358 ucfg_mlme_get_sap_internal_restart(hdd_ctx->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05306359 &value);
6360 if (value)
Krunal Sonib51eec72017-11-20 21:53:01 -08006361 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05306362
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006363 break;
6364
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006365 case QDF_P2P_GO_MODE:
Wu Gaodf929f12018-05-25 18:12:25 +08006366 hdd_delete_sta(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006367 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306368 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08006369 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306370 hdd_set_mon_rx_cb(adapter->dev);
6371 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
6372 adapter->mon_bandwidth);
6373 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006374 default:
6375 break;
6376 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07006377 /*
6378 * Action frame registered in one adapter which will
6379 * applicable to all interfaces
6380 */
6381 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006382 }
6383
Wu Gaodf929f12018-05-25 18:12:25 +08006384 hdd_for_each_adapter(hdd_ctx, adapter) {
6385 if (!hdd_is_interface_up(adapter))
6386 continue;
6387
6388 if (adapter->device_mode == QDF_P2P_GO_MODE)
6389 hdd_stop_p2p_go(adapter);
6390 }
6391
Dustin Browne74003f2018-03-14 12:51:58 -07006392 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006393
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306394 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006395}
6396
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006397QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006398 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006399{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306400 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006401 qdf_list_node_t *node;
6402
6403 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006404
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006405 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006406 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006407 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006408
6409 if (QDF_IS_STATUS_ERROR(status))
6410 return status;
6411
6412 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6413
6414 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006415}
6416
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006417QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006418 struct hdd_adapter *current_adapter,
6419 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006420{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306421 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006422 qdf_list_node_t *node;
6423
6424 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006425
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006426 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006427 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08006428 &current_adapter->node,
6429 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006430 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006431
6432 if (QDF_IS_STATUS_ERROR(status))
6433 return status;
6434
6435 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6436
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006437 return status;
6438}
6439
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006440QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006441 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006442{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306443 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006444
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006445 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006446 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006447 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006448
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006449 return status;
6450}
6451
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006452QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006453 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006454{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306455 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006456 qdf_list_node_t *node;
6457
6458 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006459
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006460 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006461 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006462 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006463
6464 if (QDF_IS_STATUS_ERROR(status))
6465 return status;
6466
6467 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6468
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006469 return status;
6470}
6471
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006472QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006473 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006474{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306475 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006476
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006477 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006478 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006479 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006480
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006481 return status;
6482}
6483
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006484QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006485 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006486{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306487 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006488
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006489 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006490 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006491 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006492
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006493 return status;
6494}
6495
Liangwei Dong3abfe8f2018-09-20 02:25:44 -04006496struct hdd_adapter *hdd_get_adapter_by_rand_macaddr(
6497 struct hdd_context *hdd_ctx, tSirMacAddr mac_addr)
6498{
6499 struct hdd_adapter *adapter;
6500
6501 hdd_for_each_adapter(hdd_ctx, adapter) {
6502 if ((adapter->device_mode == QDF_STA_MODE ||
6503 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6504 adapter->device_mode == QDF_P2P_DEVICE_MODE) &&
6505 ucfg_p2p_check_random_mac(hdd_ctx->psoc,
6506 adapter->session_id, mac_addr))
6507 return adapter;
6508 }
6509
6510 return NULL;
6511}
6512
Jeff Johnson9d295242017-08-29 14:39:48 -07006513struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006514 tSirMacAddr macAddr)
6515{
Jeff Johnson9d295242017-08-29 14:39:48 -07006516 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006517
Dustin Brown920397d2017-12-13 16:27:50 -08006518 hdd_for_each_adapter(hdd_ctx, adapter) {
6519 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
6520 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006521 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006522 }
6523
6524 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006525}
6526
Jeff Johnson9d295242017-08-29 14:39:48 -07006527struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006528 uint32_t vdev_id)
6529{
Jeff Johnson9d295242017-08-29 14:39:48 -07006530 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006531
Dustin Brown920397d2017-12-13 16:27:50 -08006532 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07006533 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006534 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006535 }
6536
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006537 return NULL;
6538}
6539
Abhishek Singh7996eb72015-12-30 17:24:02 +05306540/**
6541 * hdd_get_adapter_by_sme_session_id() - Return adapter with
6542 * the sessionid
6543 * @hdd_ctx: hdd context.
6544 * @sme_session_id: sme session is for the adapter to get.
6545 *
6546 * This function is used to get the adapter with provided session id
6547 *
6548 * Return: adapter pointer if found
6549 *
6550 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07006551struct hdd_adapter *
6552hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
6553 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306554{
Jeff Johnson9d295242017-08-29 14:39:48 -07006555 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306556
Dustin Brown920397d2017-12-13 16:27:50 -08006557 hdd_for_each_adapter(hdd_ctx, adapter) {
6558 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306559 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306560 }
Dustin Brown920397d2017-12-13 16:27:50 -08006561
Abhishek Singh7996eb72015-12-30 17:24:02 +05306562 return NULL;
6563}
6564
Jeff Johnson9d295242017-08-29 14:39:48 -07006565struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07006566 const char *iface_name)
6567{
Jeff Johnson9d295242017-08-29 14:39:48 -07006568 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006569
Dustin Brown920397d2017-12-13 16:27:50 -08006570 hdd_for_each_adapter(hdd_ctx, adapter) {
6571 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07006572 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006573 }
Dustin Brown920397d2017-12-13 16:27:50 -08006574
Naveen Rawat4edb6822017-04-12 10:09:17 -07006575 return NULL;
6576}
6577
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006578/**
6579 * hdd_get_adapter() - to get adapter matching the mode
6580 * @hdd_ctx: hdd context
6581 * @mode: adapter mode
6582 *
6583 * This routine will return the pointer to adapter matching
6584 * with the passed mode.
6585 *
6586 * Return: pointer to adapter or null
6587 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006588struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006589 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006590{
Jeff Johnson9d295242017-08-29 14:39:48 -07006591 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006592
Dustin Brown920397d2017-12-13 16:27:50 -08006593 hdd_for_each_adapter(hdd_ctx, adapter) {
6594 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006595 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006596 }
6597
6598 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006599}
6600
Jeff Johnson36a0abf2018-05-20 11:24:25 -07006601enum QDF_OPMODE hdd_get_device_mode(uint32_t session_id)
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306602{
6603 struct hdd_context *hdd_ctx;
6604 struct hdd_adapter *adapter;
6605
6606 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
6607 if (!hdd_ctx) {
6608 hdd_err("Invalid HDD context");
6609 return QDF_MAX_NO_OF_MODE;
6610 }
6611
6612 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
6613 if (!adapter) {
6614 hdd_err("Invalid HDD adapter");
6615 return QDF_MAX_NO_OF_MODE;
6616 }
6617
6618 return adapter->device_mode;
6619}
6620
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006621/**
6622 * hdd_get_operating_channel() - return operating channel of the device mode
6623 * @hdd_ctx: Pointer to the HDD context.
6624 * @mode: Device mode for which operating channel is required.
Jeff Johnson77f89bb2018-05-06 16:21:36 -07006625 * Supported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006626 * QDF_STA_MODE,
6627 * QDF_P2P_CLIENT_MODE,
6628 * QDF_SAP_MODE,
6629 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006630 *
6631 * This API returns the operating channel of the requested device mode
6632 *
6633 * Return: channel number. "0" id the requested device is not found OR it is
6634 * not connected.
6635 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006636uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006637 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006638{
Jeff Johnson9d295242017-08-29 14:39:48 -07006639 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006640 uint8_t operatingChannel = 0;
6641
Dustin Brown920397d2017-12-13 16:27:50 -08006642 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006643 if (mode == adapter->device_mode) {
6644 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006645 case QDF_STA_MODE:
6646 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006647 if (hdd_conn_is_connected
6648 (WLAN_HDD_GET_STATION_CTX_PTR
6649 (adapter))) {
6650 operatingChannel =
6651 (WLAN_HDD_GET_STATION_CTX_PTR
6652 (adapter))->conn_info.
6653 operationChannel;
6654 }
6655 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006656 case QDF_SAP_MODE:
6657 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006658 /* softap connection info */
6659 if (test_bit
6660 (SOFTAP_BSS_STARTED,
6661 &adapter->event_flags))
6662 operatingChannel =
6663 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07006664 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006665 break;
6666 default:
6667 break;
6668 }
6669
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006670 /* Found the device of interest. break the loop */
6671 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006672 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006673 }
Dustin Brown920397d2017-12-13 16:27:50 -08006674
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006675 return operatingChannel;
6676}
6677
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006678static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006679 hdd_ctx)
6680{
Jeff Johnson9d295242017-08-29 14:39:48 -07006681 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006682
Dustin Brown491d54b2018-03-14 12:39:11 -07006683 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006684
Dustin Brown920397d2017-12-13 16:27:50 -08006685 hdd_for_each_adapter(hdd_ctx, adapter) {
6686 if (adapter->device_mode == QDF_STA_MODE ||
6687 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6688 adapter->device_mode == QDF_IBSS_MODE ||
6689 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6690 adapter->device_mode == QDF_SAP_MODE ||
6691 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006692 hdd_unregister_wext(adapter->dev);
6693 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006694 }
6695
Dustin Browne74003f2018-03-14 12:51:58 -07006696 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006697
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306698 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006699}
6700
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006701QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006702{
Jeff Johnson9d295242017-08-29 14:39:48 -07006703 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006704
Dustin Brown491d54b2018-03-14 12:39:11 -07006705 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006706
Dustin Brown920397d2017-12-13 16:27:50 -08006707 hdd_for_each_adapter(hdd_ctx, adapter) {
6708 if (adapter->device_mode == QDF_STA_MODE ||
6709 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6710 adapter->device_mode == QDF_IBSS_MODE ||
6711 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6712 adapter->device_mode == QDF_SAP_MODE ||
6713 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brown07901ec2018-09-07 11:02:41 -07006714 wlan_abort_scan(hdd_ctx->pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006715 adapter->session_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05306716 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006717 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006718 }
6719
Dustin Browne74003f2018-03-14 12:51:58 -07006720 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006721
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306722 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006723}
6724
Dustin Brownf27bce82016-11-03 12:52:27 -07006725/**
6726 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
6727 * adapters
6728 * @hdd_ctx: The HDD context containing the adapters to operate on
6729 *
6730 * return: QDF_STATUS_SUCCESS
6731 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006732static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07006733{
Jeff Johnson9d295242017-08-29 14:39:48 -07006734 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07006735 int err;
6736
Dustin Brown491d54b2018-03-14 12:39:11 -07006737 hdd_enter();
Dustin Brownf27bce82016-11-03 12:52:27 -07006738
Dustin Brown920397d2017-12-13 16:27:50 -08006739 hdd_for_each_adapter(hdd_ctx, adapter) {
6740 if (adapter->device_mode == QDF_STA_MODE ||
6741 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6742 adapter->device_mode == QDF_IBSS_MODE ||
6743 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6744 adapter->device_mode == QDF_SAP_MODE ||
6745 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07006746 err = wlan_hdd_sched_scan_stop(adapter->dev);
6747 if (err)
6748 hdd_err("Unable to stop scheduled scan");
6749 }
Dustin Brownf27bce82016-11-03 12:52:27 -07006750 }
6751
Dustin Browne74003f2018-03-14 12:51:58 -07006752 hdd_exit();
Dustin Brownf27bce82016-11-03 12:52:27 -07006753
6754 return QDF_STATUS_SUCCESS;
6755}
6756
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006757#ifdef WLAN_NS_OFFLOAD
6758/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006759 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006760 * @hdd_ctx: Pointer to hdd context
6761 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006762 * Unregister for IPv6 address change notifications.
6763 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006764 * Return: None
6765 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006766static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006767{
6768 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006769}
6770
6771/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006772 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006773 * @hdd_ctx: Pointer to hdd context
6774 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006775 * Register for IPv6 address change notifications.
6776 *
6777 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006778 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006779static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006780{
6781 int ret;
6782
6783 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
6784 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006785 if (ret) {
6786 hdd_err("Failed to register IPv6 notifier: %d", ret);
6787 goto out;
6788 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006789
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006790 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006791out:
6792 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006793}
6794#else
6795/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006796 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006797 * @hdd_ctx: Pointer to hdd context
6798 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006799 * Unregister for IPv6 address change notifications.
6800 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006801 * Return: None
6802 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006803static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006804{
6805}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006806
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006807/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006808 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006809 * @hdd_ctx: Pointer to hdd context
6810 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006811 * Register for IPv6 address change notifications.
6812 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006813 * Return: None
6814 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006815static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006816{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006817 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006818}
6819#endif
6820
Alok Kumarb64650c2018-03-23 17:05:11 +05306821void hdd_set_disconnect_status(struct hdd_adapter *adapter, bool status)
6822{
6823 qdf_mutex_acquire(&adapter->disconnection_status_lock);
6824 adapter->disconnection_in_progress = status;
6825 qdf_mutex_release(&adapter->disconnection_status_lock);
6826 hdd_debug("setting disconnection status: %d", status);
6827}
6828
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006829/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006830 * hdd_register_notifiers - Register netdev notifiers.
6831 * @hdd_ctx: HDD context
6832 *
6833 * Register netdev notifiers like IPv4 and IPv6.
6834 *
6835 * Return: 0 on success and errno on failure
6836 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006837static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006838{
6839 int ret;
6840
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006841 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
6842 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306843 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006844
6845 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
6846 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
6847 if (ret) {
6848 hdd_err("Failed to register IPv4 notifier: %d", ret);
6849 goto unregister_ip6_notifier;
6850 }
6851
Alok Kumarb64650c2018-03-23 17:05:11 +05306852 ret = hdd_nud_register_netevent_notifier(hdd_ctx);
6853 if (ret) {
6854 hdd_err("Failed to register netevent notifier: %d",
6855 ret);
6856 goto unregister_inetaddr_notifier;
6857 }
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006858 return 0;
6859
Alok Kumarb64650c2018-03-23 17:05:11 +05306860unregister_inetaddr_notifier:
6861 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006862unregister_ip6_notifier:
6863 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006864out:
6865 return ret;
6866
6867}
6868
6869/**
6870 * hdd_unregister_notifiers - Unregister netdev notifiers.
6871 * @hdd_ctx: HDD context
6872 *
6873 * Unregister netdev notifiers like IPv4 and IPv6.
6874 *
6875 * Return: None.
6876 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006877void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006878{
Alok Kumarb64650c2018-03-23 17:05:11 +05306879 hdd_nud_unregister_netevent_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006880 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
6881
6882 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006883}
6884
6885/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006886 * hdd_exit_netlink_services - Exit netlink services
6887 * @hdd_ctx: HDD context
6888 *
6889 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
6890 * nl service.
6891 *
6892 * Return: None.
6893 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006894static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006895{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306896 spectral_scan_deactivate_service();
6897 cnss_diag_deactivate_service();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006898 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006899 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306900 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006901
6902 nl_srv_exit();
6903}
6904
6905/**
6906 * hdd_init_netlink_services- Init netlink services
6907 * @hdd_ctx: HDD context
6908 *
6909 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
6910 * nl service.
6911 *
6912 * Return: 0 on success and errno on failure.
6913 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006914static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006915{
6916 int ret;
6917
Ryan Hsuceddceb2016-04-28 10:20:14 -07006918 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006919 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006920 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006921 goto out;
6922 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07006923 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006924
Naveen Rawat910726a2017-03-06 11:42:51 -08006925 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006926 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006927 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006928 goto err_nl_srv;
6929 }
6930
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306931 ptt_sock_activate_svc();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006932
6933 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07006934 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006935 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006936
6937 ret = cnss_diag_activate_service();
6938 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006939 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006940 goto err_close_cesium;
6941 }
6942
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306943 spectral_scan_activate_service();
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08006944
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006945 return 0;
6946
6947err_close_cesium:
6948 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006949 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306950 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006951err_nl_srv:
6952 nl_srv_exit();
6953out:
6954 return ret;
6955}
6956
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006957/**
6958 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
6959 * @hdd_ctx: HDD context.
6960 *
6961 * Destroy RX wakelock.
6962 *
6963 * Return: None.
6964 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006965static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006966{
6967 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
6968}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006969
6970/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006971 * hdd_rx_wake_lock_create() - Create RX wakelock
6972 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006973 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006974 * Create RX wakelock.
6975 *
6976 * Return: None.
6977 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006978static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006979{
6980 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
6981}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006982
6983/**
Houston Hoffman160db392016-10-10 17:37:51 -07006984 * hdd_context_deinit() - Deinitialize HDD context
6985 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006986 *
Houston Hoffman160db392016-10-10 17:37:51 -07006987 * Deinitialize HDD context along with all the feature specific contexts but
6988 * do not free hdd context itself. Caller of this API is supposed to free
6989 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006990 *
Houston Hoffman160db392016-10-10 17:37:51 -07006991 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006992 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006993static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006994{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306995 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
6996
Houston Hoffman160db392016-10-10 17:37:51 -07006997 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006998
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006999 hdd_sap_context_destroy(hdd_ctx);
7000
7001 hdd_rx_wake_lock_destroy(hdd_ctx);
7002
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007003 hdd_scan_context_destroy(hdd_ctx);
7004
Jeff Johnson19fc8e42017-10-30 19:53:49 -07007005 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007006
Houston Hoffman160db392016-10-10 17:37:51 -07007007 return 0;
7008}
7009
Dustin Brown623e7e32018-09-05 14:27:50 -07007010void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07007011{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07007012 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05307013
Dustin Brown623e7e32018-09-05 14:27:50 -07007014 hdd_exit_netlink_services(hdd_ctx);
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05307015 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7016
Houston Hoffman160db392016-10-10 17:37:51 -07007017 hdd_context_deinit(hdd_ctx);
7018
Dustin Browndb2df2e2018-10-31 15:29:24 -07007019 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
7020
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307021 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007022 hdd_ctx->config = NULL;
Dustin Brown84f46ea2018-02-15 11:57:36 -08007023 cfg_release();
7024
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007025 wiphy_free(hdd_ctx->wiphy);
7026}
7027
7028/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05307029 * wlan_destroy_bug_report_lock() - Destroy bug report lock
7030 *
7031 * This function is used to destroy bug report lock
7032 *
7033 * Return: None
7034 */
7035static void wlan_destroy_bug_report_lock(void)
7036{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07007037 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05307038
7039 p_cds_context = cds_get_global_context();
7040 if (!p_cds_context) {
7041 hdd_err("cds context is NULL");
7042 return;
7043 }
7044
7045 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
7046}
7047
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05307048#ifdef DISABLE_CHANNEL_LIST
7049static void wlan_hdd_cache_chann_mutex_destroy(struct hdd_context *hdd_ctx)
7050{
7051 qdf_mutex_destroy(&hdd_ctx->cache_channel_lock);
7052}
7053#else
7054static void wlan_hdd_cache_chann_mutex_destroy(struct hdd_context *hdd_ctx)
7055{
7056}
7057#endif
7058
Dustin Brown92bd8382018-10-31 15:49:46 -07007059void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007060{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007061 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05307062 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007063
Dustin Brown491d54b2018-03-14 12:39:11 -07007064 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007065
Dustin Brown4c663222018-10-23 14:19:36 -07007066 hdd_psoc_idle_timer_stop(hdd_ctx);
Dustin Brown6470aba2018-09-05 09:49:58 -07007067
Arun Khandavallifae92942016-08-01 13:31:08 +05307068 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007069
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007070#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05307071 if (QDF_TIMER_STATE_RUNNING ==
7072 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
7073 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007074 }
7075
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307076 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05307077 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07007078 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007079 }
Liangwei Dongaef84342016-10-21 05:28:00 -04007080 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
7081 qdf_mem_free(hdd_ctx->last_acs_channel_list);
7082 hdd_ctx->last_acs_channel_list = NULL;
7083 hdd_ctx->num_of_channels = 0;
7084 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007085#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007086
Arun Khandavallifae92942016-08-01 13:31:08 +05307087 mutex_lock(&hdd_ctx->iface_change_lock);
7088 driver_status = hdd_ctx->driver_status;
7089 mutex_unlock(&hdd_ctx->iface_change_lock);
7090
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007091 /*
7092 * Powersave Offload Case
7093 * Disable Idle Power Save Mode
7094 */
7095 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07007096 /* clear the scan queue in all the scenarios */
Dustin Brown07901ec2018-09-07 11:02:41 -07007097 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007098
Arun Khandavallifae92942016-08-01 13:31:08 +05307099 if (driver_status != DRIVER_MODULES_CLOSED) {
7100 hdd_unregister_wext_all_adapters(hdd_ctx);
7101 /*
7102 * Cancel any outstanding scan requests. We are about to close
7103 * all of our adapters, but an adapter structure is what SME
7104 * passes back to our callback function. Hence if there
7105 * are any outstanding scan requests then there is a
7106 * race condition between when the adapter is closed and
7107 * when the callback is invoked. We try to resolve that
7108 * race condition here by canceling any outstanding scans
7109 * before we close the adapters.
7110 * Note that the scans may be cancelled in an asynchronous
7111 * manner, so ideally there needs to be some kind of
7112 * synchronization. Rather than introduce a new
7113 * synchronization here, we will utilize the fact that we are
7114 * about to Request Full Power, and since that is synchronized,
7115 * the expectation is that by the time Request Full Power has
7116 * completed, all scans will be cancelled
7117 */
7118 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07007119 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08007120 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08007121 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007122 }
7123
Arunk Khandavalli830c9692018-03-22 12:17:40 +05307124 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavalli08479ba2017-08-07 19:56:23 +05307125 unregister_netdevice_notifier(&hdd_netdev_notifier);
7126
Rachit Kankane30807332018-06-27 18:39:36 +05307127 qdf_dp_trace_deinit();
7128
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07007129 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05307130
Dustin Brown86d196b2018-08-02 11:51:49 -07007131 hdd_bus_bandwidth_deinit(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -08007132 hdd_driver_memdump_deinit();
7133
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05307134 qdf_nbuf_deinit_replenish_timer();
7135
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05307136 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
7137 hdd_info("Release wakelock for monitor mode!");
7138 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
7139 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
7140 }
7141
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307142 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
7143 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
7144 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05307145 wlan_hdd_cache_chann_mutex_destroy(hdd_ctx);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307146
Naveen Rawate02f8f52018-04-05 11:58:04 -07007147 osif_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007148
Dustin Brownd005ad82018-01-19 10:32:13 -08007149 hdd_close_all_adapters(hdd_ctx, false);
7150
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05307151 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307152 /*
7153 * If there is re_init failure wiphy would have already de-registered
7154 * check the wiphy status before un-registering again
7155 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05307156 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307157 wiphy_unregister(wiphy);
7158 wlan_hdd_cfg80211_deinit(wiphy);
7159 hdd_lpass_notify_stop(hdd_ctx);
7160 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07007161
Arun Khandavallifae92942016-08-01 13:31:08 +05307162 hdd_exit_netlink_services(hdd_ctx);
7163 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307164#ifdef FEATURE_WLAN_CH_AVOID
7165 mutex_destroy(&hdd_ctx->avoid_freq_lock);
7166#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007167}
7168
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007169#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04007170/**
7171 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007172 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04007173 *
7174 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
7175 * Then new ACS request will do a fresh scan without reusing the cached
7176 * scan information.
7177 *
7178 * Return: void
7179 */
Tang Yingying523322d2017-01-17 23:28:43 +08007180static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007181{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007182 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Jeff Johnson16528362018-06-14 12:34:16 -07007183 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007184
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007185 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007186 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04007187 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
7188 qdf_mem_free(hdd_ctx->last_acs_channel_list);
7189 hdd_ctx->last_acs_channel_list = NULL;
7190 hdd_ctx->num_of_channels = 0;
7191 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007192
Jeff Johnson16528362018-06-14 12:34:16 -07007193 mac_handle = hdd_ctx->mac_handle;
7194 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007195 return;
Jeff Johnson16528362018-06-14 12:34:16 -07007196 sme_scan_flush_result(mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007197}
7198#endif
7199
7200#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07007201int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
7202 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007203{
7204 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307205 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07007206 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07007207 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007208
7209 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7210
7211 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307212 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007213 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307214
Jeff Johnson16528362018-06-14 12:34:16 -07007215 mac_handle = hdd_ctx->mac_handle;
7216 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007217 return -EINVAL;
7218
Jeff Johnson16528362018-06-14 12:34:16 -07007219 qdf_status = sme_notify_ht2040_mode(mac_handle, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007220 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307221 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007222 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007223 return -EINVAL;
7224 }
7225
7226 return 0;
7227}
7228#endif
7229
7230/**
7231 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
7232 * @state: state
7233 *
7234 * This function notifies FW with modem power status
7235 *
7236 * Return: 0 if successful, error number otherwise
7237 */
7238int hdd_wlan_notify_modem_power_state(int state)
7239{
7240 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307241 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007242 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07007243 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007244
Anurag Chouhan6d760662016-02-20 16:05:43 +05307245 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007246 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307247 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007248 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307249
Jeff Johnson16528362018-06-14 12:34:16 -07007250 mac_handle = hdd_ctx->mac_handle;
7251 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007252 return -EINVAL;
7253
Jeff Johnson16528362018-06-14 12:34:16 -07007254 qdf_status = sme_notify_modem_power_state(mac_handle, state);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307255 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007256 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007257 state);
7258 return -EINVAL;
7259 }
7260 return 0;
7261}
7262
7263/**
7264 *
7265 * hdd_post_cds_enable_config() - HDD post cds start config helper
7266 * @adapter - Pointer to the HDD
7267 *
7268 * Return: None
7269 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007270QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007271{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307272 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007273
7274 /*
7275 * Send ready indication to the HDD. This will kick off the MAC
7276 * into a 'running' state and should kick off an initial scan.
7277 */
Jeff Johnson16528362018-06-14 12:34:16 -07007278 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->mac_handle);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307279 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007280 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
7281 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307282 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007283 }
7284
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307285 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007286}
7287
Sourav Mohapatra92ea8d62018-02-05 10:03:10 +05307288struct hdd_adapter *hdd_get_first_valid_adapter(struct hdd_context *hdd_ctx)
7289{
7290 struct hdd_adapter *adapter;
7291
7292 hdd_for_each_adapter(hdd_ctx, adapter) {
7293 if (adapter && adapter->magic == WLAN_HDD_ADAPTER_MAGIC)
7294 return adapter;
7295 }
7296
7297 return NULL;
7298}
7299
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007300/* wake lock APIs for HDD */
7301void hdd_prevent_suspend(uint32_t reason)
7302{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307303 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007304}
7305
7306void hdd_allow_suspend(uint32_t reason)
7307{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307308 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007309}
7310
7311void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
7312{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05307313 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
7314 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007315}
7316
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007317/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007318QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007319{
Jeff Johnson16528362018-06-14 12:34:16 -07007320 return sme_init_chan_list(hdd_ctx->mac_handle,
Amar Singhal6f8592b2017-04-26 14:31:58 -07007321 hdd_ctx->reg.alpha2,
7322 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007323}
7324
7325/**
7326 * hdd_is_5g_supported() - check if hardware supports 5GHz
7327 * @hdd_ctx: Pointer to the hdd context
7328 *
7329 * HDD function to know if hardware supports 5GHz
7330 *
7331 * Return: true if hardware supports 5GHz
7332 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007333bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007334{
Amar Singhal58b45ef2017-08-01 13:43:54 -07007335 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08007336 return true;
7337
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08007338 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08007339 return true;
7340 else
7341 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007342}
7343
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007344static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007345{
7346 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07007347 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007348
7349 wiphy = hdd_ctx->wiphy;
7350
7351 /*
7352 * The channel information in
7353 * wiphy needs to be initialized before wiphy registration
7354 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007355 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
7356 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007357 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07007358 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007359 }
7360
7361#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
7362 wiphy->wowlan = &wowlan_support_reg_init;
7363#else
7364 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
7365 WIPHY_WOWLAN_MAGIC_PKT |
7366 WIPHY_WOWLAN_DISCONNECT |
7367 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
7368 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
7369 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
7370 WIPHY_WOWLAN_4WAY_HANDSHAKE |
7371 WIPHY_WOWLAN_RFKILL_RELEASE;
7372
7373 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
7374 WOW_MAX_FILTERS_PER_LIST);
7375 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
7376 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
7377#endif
Liangwei Dong0da14262018-07-03 03:30:23 -04007378 if (hdd_ctx->obss_scan_offload) {
7379 hdd_debug("wmi_service_obss_scan supported");
7380 } else if (hdd_ctx->config->nChannelBondingMode24GHz) {
7381 hdd_debug("enable wpa_supp obss_scan");
7382 wiphy->features |= NL80211_FEATURE_NEED_OBSS_SCAN;
7383 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007384
7385 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007386 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307387 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07007388 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307389 return ret_val;
7390 }
Amar Singhalac26de22018-06-22 12:53:06 -07007391
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007392 /* Check the kernel version for upstream commit aced43ce780dc5 that
7393 * has support for processing user cell_base hints when wiphy is
7394 * self managed or check the backport flag for the same.
7395 */
Amar Singhalac26de22018-06-22 12:53:06 -07007396#if defined CFG80211_USER_HINT_CELL_BASE_SELF_MANAGED || \
7397 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0))
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007398 hdd_send_wiphy_regd_sync_event(hdd_ctx);
7399#endif
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307400
Amar Singhal2d812012018-02-03 15:06:47 +08007401 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007402
Amar Singhale4f28ee2015-10-21 14:36:56 -07007403 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007404}
7405
Mohit Khannaca4173b2017-09-12 21:52:19 -07007406#ifdef MSM_PLATFORM
7407/**
7408 * hdd_display_periodic_stats() - Function to display periodic stats
7409 * @hdd_ctx - handle to hdd context
7410 * @bool data_in_interval - true, if data detected in bw time interval
7411 *
7412 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
7413 * Stats show up in wlan driver logs.
7414 *
7415 * Returns: None
7416 */
Mohit Khanna70322002018-05-15 19:21:32 -07007417static void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
7418 bool data_in_interval)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007419{
Mohit Khanna70322002018-05-15 19:21:32 -07007420 static uint32_t counter;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007421 static bool data_in_time_period;
7422 ol_txrx_pdev_handle pdev;
7423
7424 if (hdd_ctx->config->periodic_stats_disp_time == 0)
7425 return;
7426
7427 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
7428 if (!pdev) {
7429 hdd_err("pdev is NULL");
7430 return;
7431 }
7432
7433 counter++;
7434 if (data_in_interval)
7435 data_in_time_period = data_in_interval;
7436
jitiphil869b9f72018-09-25 17:14:01 +05307437 if (counter * hdd_ctx->config->bus_bw_compute_interval >=
Mohit Khannaca4173b2017-09-12 21:52:19 -07007438 hdd_ctx->config->periodic_stats_disp_time * 1000) {
7439 if (data_in_time_period) {
Mohit Khanna70322002018-05-15 19:21:32 -07007440 wlan_hdd_display_txrx_stats(hdd_ctx);
7441 dp_txrx_dump_stats(cds_get_context(QDF_MODULE_ID_SOC));
7442 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
7443 CDP_RX_RING_STATS,
7444 QDF_STATS_VERBOSITY_LEVEL_LOW);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007445 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
7446 CDP_TXRX_PATH_STATS,
7447 QDF_STATS_VERBOSITY_LEVEL_LOW);
7448 wlan_hdd_display_netif_queue_history
7449 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
7450 qdf_dp_trace_dump_stats();
7451 }
7452 counter = 0;
7453 data_in_time_period = false;
7454 }
7455}
7456
Ravi Joshie2331e82015-07-01 18:18:54 -07007457/**
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007458 * hdd_clear_rps_cpu_mask - clear RPS CPU mask for interfaces
7459 * @hdd_ctx: pointer to struct hdd_context
7460 *
7461 * Return: none
7462 */
7463static void hdd_clear_rps_cpu_mask(struct hdd_context *hdd_ctx)
7464{
7465 struct hdd_adapter *adapter;
7466
7467 hdd_for_each_adapter(hdd_ctx, adapter)
7468 hdd_send_rps_disable_ind(adapter);
7469}
7470
7471/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07007472 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07007473 * @hdd_ctx - handle to hdd context
7474 * @tx_packets - transmit packet count
7475 * @rx_packets - receive packet count
7476 *
7477 * The function controls the bus bandwidth and dynamic control of
7478 * tcp delayed ack configuration
7479 *
7480 * Returns: None
7481 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007482
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007483static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07007484 const uint64_t tx_packets,
7485 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007486{
Mohit Khannaca4173b2017-09-12 21:52:19 -07007487 u64 total_pkts = tx_packets + rx_packets;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007488 uint64_t temp_tx = 0, avg_rx = 0;
7489 uint64_t no_rx_offload_pkts = 0, avg_no_rx_offload_pkts = 0;
7490 uint64_t rx_offload_pkts = 0, avg_rx_offload_pkts = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007491 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08007492 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08007493 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007494 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007495 uint16_t index = 0;
7496 bool vote_level_change = false;
7497 bool rx_level_change = false;
7498 bool tx_level_change = false;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007499 bool rxthread_high_tput_req = false;
Mohit Khannaf7562c32018-07-05 17:42:36 -07007500 bool dptrace_high_tput_req;
Srinivas Girigowda50335342018-09-07 15:21:01 -07007501
jitiphil869b9f72018-09-25 17:14:01 +05307502 if (total_pkts > hdd_ctx->config->bus_bw_high_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007503 next_vote_level = PLD_BUS_WIDTH_HIGH;
jitiphil869b9f72018-09-25 17:14:01 +05307504 else if (total_pkts > hdd_ctx->config->bus_bw_medium_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007505 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
jitiphil869b9f72018-09-25 17:14:01 +05307506 else if (total_pkts > hdd_ctx->config->bus_bw_low_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007507 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07007508 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07007509 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007510
Mohit Khannaf7562c32018-07-05 17:42:36 -07007511 dptrace_high_tput_req =
7512 next_vote_level > PLD_BUS_WIDTH_NONE ? true : false;
7513
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007514 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07007515 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
7516 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007517 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007518 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007519 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007520 if ((next_vote_level == PLD_BUS_WIDTH_LOW) ||
7521 (next_vote_level == PLD_BUS_WIDTH_NONE)) {
Nirav Shahffc6a092016-06-09 16:09:08 +05307522 if (hdd_ctx->hbw_requested) {
7523 pld_remove_pm_qos(hdd_ctx->parent_dev);
7524 hdd_ctx->hbw_requested = false;
7525 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007526 if (hdd_ctx->dynamic_rps)
7527 hdd_clear_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007528 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05307529 if (!hdd_ctx->hbw_requested) {
7530 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
7531 hdd_ctx->hbw_requested = true;
7532 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007533 if (hdd_ctx->dynamic_rps)
7534 hdd_set_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007535 }
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007536
Manjunathappa Prakashcb6df762018-05-29 18:54:58 -07007537 if (hdd_ctx->config->napi_cpu_affinity_mask)
7538 hdd_napi_apply_throughput_policy(hdd_ctx,
7539 tx_packets,
7540 rx_packets);
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007541
jitiphil869b9f72018-09-25 17:14:01 +05307542 if (rx_packets < hdd_ctx->config->bus_bw_low_threshold)
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007543 hdd_disable_rx_ol_for_low_tput(hdd_ctx, true);
7544 else
7545 hdd_disable_rx_ol_for_low_tput(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007546 }
Mohit Khannae71e2262015-11-10 09:37:24 -08007547
Mohit Khannaf7562c32018-07-05 17:42:36 -07007548 qdf_dp_trace_apply_tput_policy(dptrace_high_tput_req);
7549
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007550 /*
7551 * Includes tcp+udp, if perf core is required for tcp, then
7552 * perf core is also required for udp.
7553 */
7554 no_rx_offload_pkts = hdd_ctx->no_rx_offload_pkt_cnt;
7555 hdd_ctx->no_rx_offload_pkt_cnt = 0;
7556 rx_offload_pkts = rx_packets - no_rx_offload_pkts;
Mohit Khannae71e2262015-11-10 09:37:24 -08007557
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007558 avg_no_rx_offload_pkts = (no_rx_offload_pkts +
7559 hdd_ctx->prev_no_rx_offload_pkts) / 2;
7560 hdd_ctx->prev_no_rx_offload_pkts = no_rx_offload_pkts;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08007561
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007562 avg_rx_offload_pkts = (rx_offload_pkts +
7563 hdd_ctx->prev_rx_offload_pkts) / 2;
7564 hdd_ctx->prev_rx_offload_pkts = rx_offload_pkts;
7565
7566 avg_rx = avg_no_rx_offload_pkts + avg_rx_offload_pkts;
7567 /*
7568 * Takes care to set Rx_thread affinity for below case
7569 * 1)LRO/GRO not supported ROME case
7570 * 2)when rx_ol is disabled in cases like concurrency etc
7571 * 3)For UDP cases
7572 */
7573 if (avg_no_rx_offload_pkts >
jitiphil869b9f72018-09-25 17:14:01 +05307574 hdd_ctx->config->bus_bw_high_threshold)
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007575 rxthread_high_tput_req = true;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307576 else
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007577 rxthread_high_tput_req = false;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307578
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007579 if (cds_sched_handle_throughput_req(rxthread_high_tput_req))
7580 hdd_warn("Rx thread high_tput(%d) affinity request failed",
7581 rxthread_high_tput_req);
7582
7583 /* fine-tuning parameters for RX Flows */
jitiphil869b9f72018-09-25 17:14:01 +05307584 if (avg_rx > hdd_ctx->config->tcp_delack_thres_high) {
Ravi Joshifed83572016-10-07 16:20:37 -07007585 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
7586 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
7587 next_rx_level = WLAN_SVC_TP_HIGH;
7588 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07007589 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07007590 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08007591 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007592 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007593
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007594 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007595 struct wlan_rx_tp_data rx_tp_data = {0};
7596
Ravi Joshie2331e82015-07-01 18:18:54 -07007597 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Jeff Johnsonb9feee42018-07-08 10:34:48 -07007598 next_rx_level, avg_rx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007599 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007600 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07007601 /* Send throughput indication only if it is enabled.
7602 * Disabling tcp_del_ack will revert the tcp stack behavior
7603 * to default delayed ack. Note that this will disable the
7604 * dynamic delayed ack mechanism across the system
7605 */
Manjunathappa Prakashbfd12762018-04-29 22:44:52 -07007606 if (hdd_ctx->en_tcp_delack_no_lro)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007607 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
7608
Mohit Khanna6272fb682017-04-13 09:34:36 -07007609 if (hdd_ctx->config->enable_tcp_adv_win_scale)
7610 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
7611
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007612 rx_tp_data.level = next_rx_level;
Alok Kumar2fad6442018-11-08 19:19:28 +05307613 wlan_hdd_update_tcp_rx_param(hdd_ctx, &rx_tp_data);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007614 }
7615
Mohit Khannae71e2262015-11-10 09:37:24 -08007616 /* fine-tuning parameters for TX Flows */
7617 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
7618 hdd_ctx->prev_tx = tx_packets;
7619 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
7620 next_tx_level = WLAN_SVC_TP_HIGH;
7621 else
7622 next_tx_level = WLAN_SVC_TP_LOW;
7623
Prakash Manjunathappae73e3b52018-02-27 18:56:22 -08007624 if ((hdd_ctx->config->enable_tcp_limit_output) &&
7625 (hdd_ctx->cur_tx_level != next_tx_level)) {
Alok Kumar2fad6442018-11-08 19:19:28 +05307626 struct wlan_tx_tp_data tx_tp_data = {0};
7627
Mohit Khannae71e2262015-11-10 09:37:24 -08007628 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
7629 next_tx_level, temp_tx);
7630 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007631 tx_level_change = true;
Alok Kumar2fad6442018-11-08 19:19:28 +05307632 tx_tp_data.level = next_tx_level;
7633 tx_tp_data.tcp_limit_output = true;
7634 wlan_hdd_update_tcp_tx_param(hdd_ctx, &tx_tp_data);
Mohit Khannae71e2262015-11-10 09:37:24 -08007635 }
7636
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007637 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007638 if (vote_level_change || tx_level_change || rx_level_change) {
7639 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
7640 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
7641 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
7642 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
7643 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
7644 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
7645 hdd_ctx->hdd_txrx_hist_idx++;
7646 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
7647 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07007648
7649 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007650}
7651
7652#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Rajeev Kumarb2b5e692018-08-31 15:12:40 -07007653static void __hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007654{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007655 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307656 bus_bw_work);
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307657 struct hdd_adapter *adapter = NULL, *con_sap_adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307658 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05307659 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
7660 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007661 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307662 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007663 bool connected = false;
7664 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
7665
Prashanth Bhattaab004382016-10-11 16:08:11 -07007666 if (wlan_hdd_validate_context(hdd_ctx))
7667 return;
7668
Jeff Johnson214671b2017-10-30 19:45:23 -07007669 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08007670 goto restart_timer;
7671
Dustin Brown920397d2017-12-13 16:27:50 -08007672 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05307673 /*
7674 * Validate magic so we don't end up accessing
7675 * an invalid adapter.
7676 */
7677 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
7678 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007679
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007680 if ((adapter->device_mode == QDF_STA_MODE ||
7681 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007682 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
7683 != eConnectionState_Associated) {
7684
7685 continue;
7686 }
7687
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007688 if ((adapter->device_mode == QDF_SAP_MODE ||
7689 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07007690 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007691
7692 continue;
7693 }
7694
7695 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
7696 adapter->prev_tx_packets);
7697 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
7698 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307699
7700 if (adapter->device_mode == QDF_SAP_MODE ||
7701 adapter->device_mode == QDF_P2P_GO_MODE ||
7702 adapter->device_mode == QDF_IBSS_MODE) {
7703
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08007704 ret = cdp_get_intra_bss_fwd_pkts_count(
7705 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007706 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307707 &fwd_tx_packets, &fwd_rx_packets);
7708 if (ret == A_OK) {
7709 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
7710 fwd_tx_packets,
7711 adapter->prev_fwd_tx_packets);
7712 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
7713 fwd_tx_packets,
7714 adapter->prev_fwd_rx_packets);
7715 }
7716 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007717
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307718 if (adapter->device_mode == QDF_SAP_MODE)
7719 con_sap_adapter = adapter;
7720
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007721 total_rx += adapter->stats.rx_packets;
7722 total_tx += adapter->stats.tx_packets;
7723
7724 spin_lock_bh(&hdd_ctx->bus_bw_lock);
7725 adapter->prev_tx_packets = adapter->stats.tx_packets;
7726 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307727 adapter->prev_fwd_tx_packets = fwd_tx_packets;
7728 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007729 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
7730 connected = true;
7731 }
7732
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007733 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007734 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007735 return;
7736 }
7737
Yun Parka29974a2018-04-09 12:05:49 -07007738 /* add intra bss forwarded tx and rx packets */
7739 tx_packets += fwd_tx_packets_diff;
7740 rx_packets += fwd_rx_packets_diff;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007741
Dustin Brown07901ec2018-09-07 11:02:41 -07007742 if (ucfg_ipa_is_fw_wdi_activated(hdd_ctx->pdev)) {
7743 ucfg_ipa_uc_stat_query(hdd_ctx->pdev, &ipa_tx_packets,
7744 &ipa_rx_packets);
Yun Parka29974a2018-04-09 12:05:49 -07007745 tx_packets += (uint64_t)ipa_tx_packets;
7746 rx_packets += (uint64_t)ipa_rx_packets;
7747
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307748 if (con_sap_adapter) {
7749 con_sap_adapter->stats.tx_packets += ipa_tx_packets;
7750 con_sap_adapter->stats.rx_packets += ipa_rx_packets;
7751 }
7752
Dustin Brown07901ec2018-09-07 11:02:41 -07007753 ucfg_ipa_set_perf_level(hdd_ctx->pdev, tx_packets, rx_packets);
7754 ucfg_ipa_uc_stat_request(hdd_ctx->pdev, 2);
Yun Parka29974a2018-04-09 12:05:49 -07007755 }
7756
7757 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007758
Jingxiang Gec64e1932017-08-22 14:38:59 +08007759restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08007760 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08007761 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08007762 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05307763 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
jitiphil869b9f72018-09-25 17:14:01 +05307764 hdd_ctx->config->bus_bw_compute_interval);
Dustin Brownfce08d12017-01-17 16:29:38 -08007765 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007766}
Prashanth Bhattaab004382016-10-11 16:08:11 -07007767
Rajeev Kumarb2b5e692018-08-31 15:12:40 -07007768static void hdd_bus_bw_work_handler(struct work_struct *work)
7769{
7770 cds_ssr_protect(__func__);
7771 __hdd_bus_bw_work_handler(work);
7772 cds_ssr_unprotect(__func__);
7773}
7774
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307775/**
7776 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
7777 * @arg: Argument of timer function
7778 *
7779 * Schedule a workqueue in this function where all the processing is done.
7780 *
7781 * Return: None.
7782 */
7783static void __hdd_bus_bw_cbk(void *arg)
7784{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007785 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307786
7787 if (wlan_hdd_validate_context(hdd_ctx))
7788 return;
7789
7790 schedule_work(&hdd_ctx->bus_bw_work);
7791}
7792
7793/**
7794 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
7795 * @arg: Argument of timer function
7796 *
7797 * Return: None.
7798 */
7799static void hdd_bus_bw_cbk(void *arg)
7800{
7801 cds_ssr_protect(__func__);
7802 __hdd_bus_bw_cbk(arg);
7803 cds_ssr_unprotect(__func__);
7804}
7805
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007806int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007807{
Dustin Brown35008ba2018-08-23 14:34:21 -07007808 hdd_enter();
7809
Prashanth Bhattaab004382016-10-11 16:08:11 -07007810 spin_lock_init(&hdd_ctx->bus_bw_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07007811 INIT_WORK(&hdd_ctx->bus_bw_work, hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08007812 hdd_ctx->bus_bw_timer_running = false;
7813 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07007814 qdf_timer_init(NULL, &hdd_ctx->bus_bw_timer, hdd_bus_bw_cbk,
7815 (void *)hdd_ctx, QDF_TIMER_TYPE_SW);
7816
7817 hdd_exit();
Prashanth Bhattaab004382016-10-11 16:08:11 -07007818
7819 return 0;
7820}
7821
Dustin Brown86d196b2018-08-02 11:51:49 -07007822void hdd_bus_bandwidth_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007823{
Dustin Brown35008ba2018-08-23 14:34:21 -07007824 hdd_enter();
Prashanth Bhattaab004382016-10-11 16:08:11 -07007825
Rajeev Kumarc27efb62018-08-31 14:21:22 -07007826 QDF_BUG(!hdd_ctx->bus_bw_timer_running);
Dustin Brown35008ba2018-08-23 14:34:21 -07007827
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307828 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08007829 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07007830
7831 hdd_exit();
Prashanth Bhattaab004382016-10-11 16:08:11 -07007832}
Lin Baic5c06882017-09-21 13:58:43 +08007833
Dustin Brown35008ba2018-08-23 14:34:21 -07007834#endif /* MSM_PLATFORM */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007835
7836/**
Nirav Shahed34b212016-04-25 10:59:16 +05307837 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
7838 * @hdd_ctx: hdd context
7839 *
7840 * Return: 0 for success or error code
7841 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007842static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307843{
7844 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
7845 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Min Liu74a1a502018-10-10 19:59:07 +08007846 if (!hdd_ctx->hdd_txrx_hist)
Nirav Shahed34b212016-04-25 10:59:16 +05307847 return -ENOMEM;
Nirav Shahed34b212016-04-25 10:59:16 +05307848 return 0;
7849}
7850
7851/**
7852 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
7853 * @hdd_ctx: hdd context
7854 *
7855 * Return: none
7856 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007857void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307858{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307859 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
7860 return;
7861
7862 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
7863 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05307864}
7865
Nirav Shahda008342016-05-17 18:50:40 +05307866static uint8_t *convert_level_to_string(uint32_t level)
7867{
7868 switch (level) {
7869 /* initialize the wlan sub system */
7870 case WLAN_SVC_TP_NONE:
7871 return "NONE";
7872 case WLAN_SVC_TP_LOW:
7873 return "LOW";
7874 case WLAN_SVC_TP_MEDIUM:
7875 return "MED";
7876 case WLAN_SVC_TP_HIGH:
7877 return "HIGH";
7878 default:
7879 return "INVAL";
7880 }
7881}
7882
Nirav Shahed34b212016-04-25 10:59:16 +05307883
7884/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007885 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
7886 * @hdd_ctx: hdd context
7887 *
7888 * Return: none
7889 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007890void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007891{
7892 int i;
7893
7894#ifdef MSM_PLATFORM
Nirav Shahe6194ac2018-07-13 11:04:41 +05307895 hdd_nofl_info("BW compute Interval: %dms",
jitiphil869b9f72018-09-25 17:14:01 +05307896 hdd_ctx->config->bus_bw_compute_interval);
Nirav Shahe6194ac2018-07-13 11:04:41 +05307897 hdd_nofl_info("BW High TH: %d BW Med TH: %d BW Low TH: %d",
jitiphil869b9f72018-09-25 17:14:01 +05307898 hdd_ctx->config->bus_bw_high_threshold,
7899 hdd_ctx->config->bus_bw_medium_threshold,
7900 hdd_ctx->config->bus_bw_low_threshold);
Nirav Shahe6194ac2018-07-13 11:04:41 +05307901 hdd_nofl_info("Enable TCP DEL ACK: %d",
7902 hdd_ctx->en_tcp_delack_no_lro);
7903 hdd_nofl_info("TCP DEL High TH: %d TCP DEL Low TH: %d",
jitiphil869b9f72018-09-25 17:14:01 +05307904 hdd_ctx->config->tcp_delack_thres_high,
7905 hdd_ctx->config->tcp_delack_thres_low);
Nirav Shahe6194ac2018-07-13 11:04:41 +05307906 hdd_nofl_info("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
7907 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007908#endif
7909
Nirav Shahe6194ac2018-07-13 11:04:41 +05307910 hdd_nofl_info("Total entries: %d Current index: %d",
7911 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
Nirav Shahda008342016-05-17 18:50:40 +05307912
Nirav Shahe6194ac2018-07-13 11:04:41 +05307913 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 -08007914
7915 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007916 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007917 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Nirav Shahe6194ac2018-07-13 11:04:41 +05307918 hdd_nofl_info("[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
7919 i, hdd_ctx->hdd_txrx_hist[i].qtime,
7920 hdd_ctx->hdd_txrx_hist[i].interval_rx,
7921 hdd_ctx->hdd_txrx_hist[i].interval_tx,
7922 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007923 hdd_ctx->hdd_txrx_hist[i].
7924 next_vote_level),
Nirav Shahe6194ac2018-07-13 11:04:41 +05307925 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007926 hdd_ctx->hdd_txrx_hist[i].
7927 next_rx_level),
Nirav Shahe6194ac2018-07-13 11:04:41 +05307928 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007929 hdd_ctx->hdd_txrx_hist[i].
7930 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007931 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007932}
7933
7934/**
7935 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
7936 * @hdd_ctx: hdd context
7937 *
7938 * Return: none
7939 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007940void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007941{
7942 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05307943 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
7944 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007945}
7946
Mohit Khannaca4173b2017-09-12 21:52:19 -07007947/* length of the netif queue log needed per adapter */
7948#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
7949
7950/**
7951 *
7952 * hdd_display_netif_queue_history_compact() - display compact netifq history
7953 * @hdd_ctx: hdd context
7954 *
7955 * Return: none
7956 */
7957static void
7958hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
7959{
7960 int adapter_num = 0;
7961 int i;
7962 int bytes_written;
7963 u32 tbytes;
7964 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007965 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08007966 char *comb_log_str;
7967 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007968 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007969
Dustin Brownbee82832018-07-23 10:10:51 -07007970 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * CSR_ROAM_SESSION_MAX) + 1;
jiadbdefb252018-01-03 14:27:06 +08007971 comb_log_str = qdf_mem_malloc(comb_log_str_size);
Min Liu74a1a502018-10-10 19:59:07 +08007972 if (!comb_log_str)
jiadbdefb252018-01-03 14:27:06 +08007973 return;
jiadbdefb252018-01-03 14:27:06 +08007974
Mohit Khannaca4173b2017-09-12 21:52:19 -07007975 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007976
Dustin Brown920397d2017-12-13 16:27:50 -08007977 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007978 curr_time = qdf_system_ticks();
7979 total = curr_time - adapter->start_time;
7980 delta = curr_time - adapter->last_time;
7981
7982 if (adapter->pause_map) {
7983 pause = adapter->total_pause_time + delta;
7984 unpause = adapter->total_unpause_time;
7985 } else {
7986 unpause = adapter->total_unpause_time + delta;
7987 pause = adapter->total_pause_time;
7988 }
7989
7990 tbytes = 0;
7991 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7992 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7993 if (adapter->queue_oper_stats[i].pause_count == 0)
7994 continue;
7995 tbytes +=
7996 snprintf(
7997 &temp_str[tbytes],
7998 (tbytes >= sizeof(temp_str) ?
7999 0 : sizeof(temp_str) - tbytes),
8000 "%d(%d,%d) ",
8001 i,
8002 adapter->queue_oper_stats[i].
8003 pause_count,
8004 adapter->queue_oper_stats[i].
8005 unpause_count);
8006 }
8007 if (tbytes >= sizeof(temp_str))
8008 hdd_warn("log truncated");
8009
8010 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08008011 bytes_written >= comb_log_str_size ? 0 :
8012 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07008013 "[%d %d] (%d) %u/%ums %s|",
8014 adapter->session_id, adapter->device_mode,
8015 adapter->pause_map,
8016 qdf_system_ticks_to_msecs(pause),
8017 qdf_system_ticks_to_msecs(total),
8018 temp_str);
8019
Mohit Khannaca4173b2017-09-12 21:52:19 -07008020 adapter_num++;
8021 }
8022
8023 /* using QDF_TRACE to avoid printing function name */
8024 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
8025 "STATS |%s", comb_log_str);
8026
jiadbdefb252018-01-03 14:27:06 +08008027 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07008028 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08008029
8030 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07008031}
8032
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008033/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008034 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07008035 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008036 *
8037 * Return: none
8038 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07008039void
8040wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
8041 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008042{
8043
Jeff Johnson9d295242017-08-29 14:39:48 -07008044 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008045 int i;
Nirav Shahda008342016-05-17 18:50:40 +05308046 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008047
Mohit Khannaca4173b2017-09-12 21:52:19 -07008048 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
8049 hdd_display_netif_queue_history_compact(hdd_ctx);
8050 return;
8051 }
8052
Dustin Brown920397d2017-12-13 16:27:50 -08008053 hdd_for_each_adapter(hdd_ctx, adapter) {
Nirav Shahe6194ac2018-07-13 11:04:41 +05308054 hdd_nofl_info("Netif queue operation statistics:");
8055 hdd_nofl_info("Session_id %d device mode %d",
8056 adapter->session_id, adapter->device_mode);
8057 hdd_nofl_info("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05308058 curr_time = qdf_system_ticks();
8059 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05308060 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05308061 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05308062 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05308063 unpause = adapter->total_unpause_time;
8064 } else {
Nirav Shahda008342016-05-17 18:50:40 +05308065 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05308066 pause = adapter->total_pause_time;
8067 }
Nirav Shahe6194ac2018-07-13 11:04:41 +05308068 hdd_nofl_info("Total: %ums Pause: %ums Unpause: %ums",
8069 qdf_system_ticks_to_msecs(total),
8070 qdf_system_ticks_to_msecs(pause),
8071 qdf_system_ticks_to_msecs(unpause));
8072 hdd_nofl_info("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008073
Nirav Shahda008342016-05-17 18:50:40 +05308074 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
8075 qdf_time_t pause_delta = 0;
8076
8077 if (adapter->pause_map & (1 << i))
8078 pause_delta = delta;
8079
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008080 /* using hdd_log to avoid printing function name */
Nirav Shahe6194ac2018-07-13 11:04:41 +05308081 hdd_nofl_info("%s: %d: %d: %ums",
8082 hdd_reason_type_to_string(i),
8083 adapter->queue_oper_stats[i].pause_count,
8084 adapter->queue_oper_stats[i].
8085 unpause_count,
8086 qdf_system_ticks_to_msecs(
8087 adapter->queue_oper_stats[i].
8088 total_pause_time + pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008089 }
8090
Nirav Shahe6194ac2018-07-13 11:04:41 +05308091 hdd_nofl_info("Netif queue operation history:");
8092 hdd_nofl_info("Total entries: %d current index %d",
8093 WLAN_HDD_MAX_HISTORY_ENTRY,
8094 adapter->history_index);
Nirav Shahda008342016-05-17 18:50:40 +05308095
Nirav Shahe6194ac2018-07-13 11:04:41 +05308096 hdd_nofl_info("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008097
8098 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008099 /* using hdd_log to avoid printing function name */
8100 if (adapter->queue_oper_history[i].time == 0)
8101 continue;
Nirav Shahe6194ac2018-07-13 11:04:41 +05308102 hdd_nofl_info("%d: %u: %s: %s: %x",
8103 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008104 adapter->queue_oper_history[i].time),
Nirav Shahe6194ac2018-07-13 11:04:41 +05308105 hdd_action_type_to_string(
8106 adapter->queue_oper_history[i].
8107 netif_action),
8108 hdd_reason_type_to_string(
8109 adapter->queue_oper_history[i].
8110 netif_reason),
8111 adapter->queue_oper_history[i].pause_map);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008112 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008113 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008114}
8115
8116/**
8117 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
8118 * @hdd_ctx: hdd context
8119 *
8120 * Return: none
8121 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008122void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008123{
Jeff Johnson9d295242017-08-29 14:39:48 -07008124 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008125
Dustin Brown920397d2017-12-13 16:27:50 -08008126 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308127 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008128 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308129 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008130 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05308131 adapter->history_index = 0;
8132 adapter->start_time = adapter->last_time = qdf_system_ticks();
8133 adapter->total_pause_time = 0;
8134 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008135 }
8136}
8137
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008138#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
8139/**
8140 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
8141 * @hdd_ctx: hdd global context
8142 *
8143 * Return: none
8144 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008145static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008146{
8147 uint8_t i;
8148
8149 mutex_init(&hdd_ctx->op_ctx.op_lock);
8150 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
8151 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
8152 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
8153 }
8154}
8155#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008156static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008157{
8158}
8159#endif
8160
Yingying Tang95409972016-10-20 15:16:15 +08008161#ifdef WLAN_FEATURE_WOW_PULSE
8162/**
8163 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008164 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08008165 * @enable: enable or disable this behaviour
8166 *
8167 * Return: int
8168 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008169static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008170{
Yingying Tang95409972016-10-20 15:16:15 +08008171 struct wow_pulse_mode wow_pulse_set_info;
8172 QDF_STATUS status;
8173
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008174 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08008175
Wu Gao66454f12018-09-26 19:55:41 +08008176 if (!ucfg_pmo_is_wow_pulse_enabled(phddctx->psoc))
Yingying Tang95409972016-10-20 15:16:15 +08008177 return 0;
8178
8179 /* prepare the request to send to SME */
8180 if (enable == true) {
8181 wow_pulse_set_info.wow_pulse_enable = true;
8182 wow_pulse_set_info.wow_pulse_pin =
Wu Gao66454f12018-09-26 19:55:41 +08008183 ucfg_pmo_get_wow_pulse_pin(phddctx->psoc);
8184
Yingying Tang95409972016-10-20 15:16:15 +08008185 wow_pulse_set_info.wow_pulse_interval_high =
Wu Gao66454f12018-09-26 19:55:41 +08008186 ucfg_pmo_get_wow_pulse_interval_high(phddctx->psoc);
8187
8188 wow_pulse_set_info.wow_pulse_interval_low =
8189 ucfg_pmo_get_wow_pulse_interval_low(phddctx->psoc);
Yingying Tang95409972016-10-20 15:16:15 +08008190 } else {
8191 wow_pulse_set_info.wow_pulse_enable = false;
8192 wow_pulse_set_info.wow_pulse_pin = 0;
8193 wow_pulse_set_info.wow_pulse_interval_low = 0;
8194 wow_pulse_set_info.wow_pulse_interval_high = 0;
8195 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008196 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08008197 wow_pulse_set_info.wow_pulse_enable,
8198 wow_pulse_set_info.wow_pulse_pin,
8199 wow_pulse_set_info.wow_pulse_interval_low,
8200 wow_pulse_set_info.wow_pulse_interval_high);
8201
8202 status = sme_set_wow_pulse(&wow_pulse_set_info);
8203 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008204 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08008205 return -EIO;
8206 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008207 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08008208 return 0;
8209}
8210#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008211static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008212{
8213 return 0;
8214}
8215#endif
8216
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008217#ifdef WLAN_FEATURE_FASTPATH
jitiphil377bcc12018-10-05 19:46:08 +05308218
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008219/**
8220 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
8221 * @hdd_cfg: hdd config
8222 * @context: lower layer context
8223 *
8224 * Return: none
8225 */
jitiphil377bcc12018-10-05 19:46:08 +05308226void hdd_enable_fastpath(struct hdd_context *hdd_ctx,
8227 void *context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008228{
jitiphil377bcc12018-10-05 19:46:08 +05308229 if (cfg_get(hdd_ctx->psoc, CFG_DP_ENABLE_FASTPATH))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008230 hif_enable_fastpath(context);
8231}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008232#endif
8233
Yuanyuan Liu13738502016-04-06 17:41:37 -07008234#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008235/**
8236 * hdd_set_thermal_level_cb() - set thermal level callback function
Jeff Johnson0e963082018-07-04 19:39:20 -07008237 * @hdd_handle: opaque handle for the hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008238 * @level: thermal level
8239 *
8240 * Change IPA data path to SW path when the thermal throttle level greater
8241 * than 0, and restore the original data path when throttle level is 0
8242 *
8243 * Return: none
8244 */
Jeff Johnson0e963082018-07-04 19:39:20 -07008245static void hdd_set_thermal_level_cb(hdd_handle_t hdd_handle, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008246{
Jeff Johnson0e963082018-07-04 19:39:20 -07008247 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008248
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008249 /* Change IPA to SW path when throttle level greater than 0 */
8250 if (level > THROTTLE_LEVEL_0)
Dustin Brown07901ec2018-09-07 11:02:41 -07008251 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->pdev, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008252 else
8253 /* restore original concurrency mode */
Dustin Brown07901ec2018-09-07 11:02:41 -07008254 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->pdev, hdd_ctx->mcc_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008255}
8256
8257/**
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308258 * hdd_get_safe_channel() - Get safe channel from current regulatory
8259 * @hdd_ctx: pointer to hdd context
8260 * @adapter: pointer to softap adapter
8261 *
8262 * This function is used to get safe channel from current regulatory valid
8263 * channels to restart SAP if failed to get safe channel from PCL.
8264 *
8265 * Return: Channel number to restart SAP in case of success. In case of any
8266 * failure, the channel number returned is zero.
8267 */
8268static uint8_t
8269hdd_get_safe_channel(struct hdd_context *hdd_ctx,
8270 struct hdd_adapter *adapter)
8271{
8272 struct sir_pcl_list pcl = {0};
8273 uint32_t i, j;
8274 bool found = false;
8275 int ret;
8276
8277 /* Try for safe channel from all valid channel */
8278 pcl.pcl_len = MAX_NUM_CHAN;
8279 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
8280 &pcl.pcl_len);
8281 if (ret) {
8282 hdd_err("error %d in getting valid channel list", ret);
8283 return INVALID_CHANNEL_ID;
8284 }
8285
8286 for (i = 0; i < pcl.pcl_len; i++) {
8287 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
8288 found = false;
8289 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
8290 if (pcl.pcl_list[i] ==
8291 hdd_ctx->unsafe_channel_list[j]) {
8292 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
8293 found = true;
8294 break;
8295 }
8296 }
8297
8298 if (found)
8299 continue;
8300
8301 if ((pcl.pcl_list[i] >=
8302 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
8303 (pcl.pcl_list[i] <=
8304 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
8305 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
8306 return pcl.pcl_list[i];
8307 }
8308 }
8309
8310 return INVALID_CHANNEL_ID;
8311}
8312
8313#else
8314/**
8315 * hdd_set_thermal_level_cb() - set thermal level callback function
8316 * @hdd_handle: opaque handle for the hdd context
8317 * @level: thermal level
8318 *
8319 * Change IPA data path to SW path when the thermal throttle level greater
8320 * than 0, and restore the original data path when throttle level is 0
8321 *
8322 * Return: none
8323 */
8324static void hdd_set_thermal_level_cb(hdd_handle_t hdd_handle, u_int8_t level)
8325{
8326}
8327
8328/**
8329 * hdd_get_safe_channel() - Get safe channel from current regulatory
8330 * @hdd_ctx: pointer to hdd context
8331 * @adapter: pointer to softap adapter
8332 *
8333 * This function is used to get safe channel from current regulatory valid
8334 * channels to restart SAP if failed to get safe channel from PCL.
8335 *
8336 * Return: Channel number to restart SAP in case of success. In case of any
8337 * failure, the channel number returned is zero.
8338 */
8339static uint8_t
8340hdd_get_safe_channel(struct hdd_context *hdd_ctx,
8341 struct hdd_adapter *adapter)
8342{
8343 return 0;
8344}
8345#endif
8346
8347/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308348 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
8349 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05308350 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008351 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308352 * Get a safe channel to restart SAP. PCL already takes into account the
8353 * unsafe channels. So, the PCL is validated with the ACS range to provide
8354 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008355 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308356 * Return: Channel number to restart SAP in case of success. In case of any
8357 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008358 */
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308359static uint8_t
8360hdd_get_safe_channel_from_pcl_and_acs_range(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008361{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308362 struct sir_pcl_list pcl;
8363 QDF_STATUS status;
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308364 uint32_t i;
Jeff Johnson16528362018-06-14 12:34:16 -07008365 mac_handle_t mac_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008366 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008367
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308368 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8369 if (!hdd_ctx) {
8370 hdd_err("invalid HDD context");
8371 return INVALID_CHANNEL_ID;
8372 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008373
Jeff Johnson16528362018-06-14 12:34:16 -07008374 mac_handle = hdd_ctx->mac_handle;
8375 if (!mac_handle) {
8376 hdd_err("invalid MAC handle");
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05308377 return INVALID_CHANNEL_ID;
8378 }
8379
Dustin Brown1dbefe62018-09-11 16:32:03 -07008380 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008381 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08008382 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
8383 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308384 if (QDF_IS_STATUS_ERROR(status)) {
8385 hdd_err("Get PCL failed");
8386 return INVALID_CHANNEL_ID;
8387 }
8388
Frank Liudc2cefb2017-06-21 15:38:18 +08008389 /*
8390 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
8391 * channel is unsafe channel, the pcl may be empty, instead of return,
8392 * try to choose a safe channel from acs range.
8393 */
8394 if (!pcl.pcl_len)
8395 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308396
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008397 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07008398 adapter->session.ap.sap_config.acs_cfg.start_ch,
8399 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308400
8401 /* PCL already takes unsafe channel into account */
8402 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008403 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308404 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008405 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308406 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008407 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008408 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308409 return pcl.pcl_list[i];
8410 }
8411 }
8412
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008413 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308414
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308415 return hdd_get_safe_channel(hdd_ctx, adapter);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308416}
8417
8418/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008419 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308420 * @adapter: AP adapter
8421 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08008422 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308423 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008424 * Moves the SAP interface by invoking the function which
8425 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308426 *
8427 * Return: None
8428 */
Min Liu2fef5792018-01-19 17:59:42 +08008429void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
8430 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308431{
Jeff Johnson87251032017-08-29 13:31:11 -07008432 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008433 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07008434 mac_handle_t mac_handle;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308435
8436 if (!adapter) {
8437 hdd_err("invalid adapter");
8438 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008439 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308440
8441 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
8442
Jeff Johnson16528362018-06-14 12:34:16 -07008443 mac_handle = hdd_adapter_get_mac_handle(adapter);
8444 if (!mac_handle) {
8445 hdd_err("invalid MAC handle");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308446 return;
8447 }
8448
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008449 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8450
Jeff Johnson91df29d2017-10-27 19:29:50 -07008451 hdd_ap_ctx->sap_config.channel = channel;
Himanshu Agarwalf5c5b102018-05-22 20:13:57 +05308452 hdd_ap_ctx->sap_config.ch_params.ch_width = CH_WIDTH_MAX;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308453
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008454 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07008455 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308456
Dustin Brown07901ec2018-09-07 11:02:41 -07008457 wlan_reg_set_channel_params(hdd_ctx->pdev,
8458 hdd_ap_ctx->sap_config.channel,
8459 hdd_ap_ctx->sap_config.sec_ch,
8460 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308461
Dustin Brown1dbefe62018-09-11 16:32:03 -07008462 policy_mgr_change_sap_channel_with_csa(hdd_ctx->psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07008463 adapter->session_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08008464 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008465}
Kapil Gupta8878ad92017-02-13 11:56:04 +05308466
Jeff Johnson9d295242017-08-29 14:39:48 -07008467int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05308468{
8469 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308470 int status;
8471 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308472
8473 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8474
8475 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07008476 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05308477 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07008478 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308479 }
8480 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07008481 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308482 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308483 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07008484 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308485 WLAN_VENDOR_ACS_WAIT_TIME);
8486 if (qdf_status != QDF_STATUS_SUCCESS) {
8487 hdd_err("failed to start external acs timer");
8488 return -ENOSPC;
8489 }
8490 /* Update config to application */
8491 status = hdd_cfg80211_update_acs_config(adapter, reason);
Dustin Brown5e89ef82018-03-14 11:50:23 -07008492 hdd_info("Updated ACS config to nl with reason %d", reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308493
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308494 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308495}
8496
Nirav Shaheb017be2018-02-15 11:20:58 +05308497#if defined(FEATURE_WLAN_CH_AVOID)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308498/**
8499 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
8500 * @hdd_ctx: hdd context pointer
8501 *
8502 * hdd_unsafe_channel_restart_sap check all unsafe channel list
8503 * and if ACS is enabled, driver will ask userspace to restart the
8504 * sap. User space on LTE coex indication restart driver.
8505 *
8506 * Return - none
8507 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008508void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308509{
Dustin Brown920397d2017-12-13 16:27:50 -08008510 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308511 uint32_t i;
8512 bool found = false;
8513 uint8_t restart_chan;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05308514 bool value;
Harprit Chhabada1eeeb8d2018-09-14 15:16:56 -07008515 QDF_STATUS status;
8516 bool is_acs_support_for_dfs_ltecoex = cfg_default(CFG_USER_ACS_DFS_LTE);
8517 bool is_vendor_acs_support =
8518 cfg_default(CFG_USER_AUTO_CHANNEL_SELECTION);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008519
Dustin Brown920397d2017-12-13 16:27:50 -08008520 hdd_for_each_adapter(hdd_ctxt, adapter) {
8521 if (!(adapter->device_mode == QDF_SAP_MODE &&
8522 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008523 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08008524 adapter->device_mode,
8525 adapter->session.ap.sap_config.
8526 acs_cfg.acs_mode);
8527 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308528 }
8529
8530 found = false;
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008531 /*
8532 * If STA+SAP is doing SCC & g_sta_sap_scc_on_lte_coex_chan
8533 * is set, no need to move SAP.
8534 */
Dustin Brown1dbefe62018-09-11 16:32:03 -07008535 if (policy_mgr_is_sta_sap_scc(hdd_ctxt->psoc,
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008536 adapter->session.ap.operating_channel) &&
8537 hdd_ctxt->config->sta_sap_scc_on_lte_coex_chan)
8538 hdd_debug("SAP is allowed on SCC channel, no need to move SAP");
8539 else {
8540 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
8541 if (adapter->session.ap.operating_channel ==
8542 hdd_ctxt->unsafe_channel_list[i]) {
8543 found = true;
8544 hdd_debug("operating ch:%d is unsafe",
8545 adapter->session.ap.operating_channel);
8546 break;
8547 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308548 }
8549 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308550 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008551 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08008552 adapter->session.ap.operating_channel);
8553 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308554 }
8555
Harprit Chhabada1eeeb8d2018-09-14 15:16:56 -07008556 status = ucfg_mlme_get_acs_support_for_dfs_ltecoex(
8557 hdd_ctxt->psoc,
8558 &is_acs_support_for_dfs_ltecoex);
8559 if (!QDF_IS_STATUS_SUCCESS(status))
8560 hdd_err("get_acs_support_for_dfs_ltecoex failed,set def");
8561
8562 status = ucfg_mlme_get_vendor_acs_support(
8563 hdd_ctxt->psoc,
8564 &is_vendor_acs_support);
8565 if (!QDF_IS_STATUS_SUCCESS(status))
8566 hdd_err("get_vendor_acs_support failed, set default");
8567
8568 if (is_vendor_acs_support && is_acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08008569 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05308570 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08008571 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308572 } else
8573 restart_chan =
8574 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08008575 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308576 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008577 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308578 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008579 /*
8580 * SAP restart due to unsafe channel. While
8581 * restarting the SAP, make sure to clear
8582 * acs_channel, channel to reset to
8583 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308584 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008585 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308586 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008587 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308588 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
8589 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Dustin Brown05d81302018-09-11 16:49:22 -07008590 ucfg_mlme_get_sap_internal_restart(hdd_ctxt->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05308591 &value);
8592 hdd_debug("driver to start sap: %d", value);
8593 if (value)
Min Liu2fef5792018-01-19 17:59:42 +08008594 hdd_switch_sap_channel(adapter, restart_chan,
8595 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04008596 else
8597 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308598 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308599 }
8600}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05308601
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008602/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008603 * hdd_init_channel_avoidance() - Initialize channel avoidance
8604 * @hdd_ctx: HDD global context
8605 *
8606 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07008607 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008608 * down to the lower layers. Then subscribe to subsequent channel
8609 * avoidance events.
8610 *
8611 * Return: None
8612 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008613static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008614{
8615 uint16_t unsafe_channel_count;
8616 int index;
8617
Yuanyuan Liu13738502016-04-06 17:41:37 -07008618 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
8619 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008620 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08008621 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008622
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008623 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008624 hdd_ctx->unsafe_channel_count);
8625
Anurag Chouhan6d760662016-02-20 16:05:43 +05308626 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08008627 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008628
8629 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008630 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008631 hdd_ctx->unsafe_channel_list[index]);
8632
8633 }
8634
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008635}
Dustin Brown676a2322017-08-15 13:16:13 -07008636
Jeff Johnson9d295242017-08-29 14:39:48 -07008637static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008638 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008639{
8640 uint8_t restart_chan;
8641
8642 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
8643 if (!restart_chan) {
8644 hdd_alert("fail to restart SAP");
8645 return;
8646 }
8647
8648 /* SAP restart due to unsafe channel. While restarting
8649 * the SAP, make sure to clear acs_channel, channel to
8650 * reset to 0. Otherwise these settings will override
8651 * the ACS while restart.
8652 */
8653 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07008654
8655 hdd_debug("sending coex indication");
8656
8657 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
8658 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08008659 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07008660}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008661
8662int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
8663 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
8664{
8665 uint32_t size;
8666 uint16_t *unsafe_list;
8667 uint16_t chan_count;
8668
8669 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
8670 return -EINVAL;
8671
8672 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
8673 NUM_CHANNELS);
8674 if (chan_count) {
8675 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
8676 unsafe_list = qdf_mem_malloc(size);
Min Liu74a1a502018-10-10 19:59:07 +08008677 if (!unsafe_list)
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008678 return -ENOMEM;
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008679 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
8680 } else {
8681 unsafe_list = NULL;
8682 }
8683
8684 *local_unsafe_list = unsafe_list;
8685 *local_unsafe_list_count = chan_count;
8686
8687 return 0;
8688}
8689
8690bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
8691 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
8692{
8693 int i, j;
8694
8695 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
8696 return true;
8697 if (local_unsafe_list_count == 0)
8698 return false;
8699 for (i = 0; i < local_unsafe_list_count; i++) {
8700 for (j = 0; j < local_unsafe_list_count; j++)
8701 if (local_unsafe_list[i] ==
8702 hdd_ctx->unsafe_channel_list[j])
8703 break;
8704 if (j >= local_unsafe_list_count)
8705 break;
8706 }
8707 if (i >= local_unsafe_list_count) {
8708 hdd_info("unsafe chan list same");
8709 return false;
8710 }
8711
8712 return true;
8713}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008714#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008715static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008716{
8717}
Dustin Brown676a2322017-08-15 13:16:13 -07008718
Jeff Johnson9d295242017-08-29 14:39:48 -07008719static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008720 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008721{
8722 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
8723}
Yuanyuan Liu13738502016-04-06 17:41:37 -07008724#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008725
8726/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08008727 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
8728 * user space
8729 * @frame_ind: Management frame data to be informed.
8730 *
8731 * This function is used to indicate management frame to
8732 * user space
8733 *
8734 * Return: None
8735 *
8736 */
8737void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
8738{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008739 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07008740 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008741 int i;
Pragaspathi Thilagaraj28ffc042018-07-18 15:19:36 +05308742 struct ieee80211_mgmt *mgmt =
8743 (struct ieee80211_mgmt *)frame_ind->frameBuf;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008744
Dustin Browne7e71d32018-05-11 16:00:08 -07008745 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
8746 if (wlan_hdd_validate_context(hdd_ctx))
Rajeev Kumard004abc2016-02-17 12:09:56 -08008747 return;
8748
Pragaspathi Thilagaraj28ffc042018-07-18 15:19:36 +05308749 if (frame_ind->frame_len < ieee80211_hdrlen(mgmt->frame_control)) {
8750 hdd_err(" Invalid frame length");
8751 return;
8752 }
8753
Rajeev Kumard004abc2016-02-17 12:09:56 -08008754 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
8755 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
8756 adapter =
8757 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
8758 if (adapter)
8759 break;
8760 }
Wu Gaoa0230a62018-01-04 20:56:57 +08008761 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
8762 hdd_for_each_adapter(hdd_ctx, adapter) {
8763 if ((NULL != adapter) &&
8764 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
8765 __hdd_indicate_mgmt_frame(adapter,
8766 frame_ind->frame_len,
8767 frame_ind->frameBuf,
8768 frame_ind->frameType,
8769 frame_ind->rxChan,
8770 frame_ind->rxRssi);
8771 }
8772 }
8773 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008774 } else {
8775 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
8776 frame_ind->sessionId);
8777 }
8778
8779 if ((NULL != adapter) &&
8780 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
8781 __hdd_indicate_mgmt_frame(adapter,
8782 frame_ind->frame_len,
8783 frame_ind->frameBuf,
8784 frame_ind->frameType,
8785 frame_ind->rxChan,
8786 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008787}
8788
Kapil Gupta8878ad92017-02-13 11:56:04 +05308789void hdd_acs_response_timeout_handler(void *context)
8790{
8791 struct hdd_external_acs_timer_context *timer_context =
8792 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07008793 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008794 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308795 uint8_t reason;
8796
Dustin Brown491d54b2018-03-14 12:39:11 -07008797 hdd_enter();
Kapil Gupta8878ad92017-02-13 11:56:04 +05308798 if (!timer_context) {
8799 hdd_err("invlaid timer context");
8800 return;
8801 }
8802 adapter = timer_context->adapter;
8803 reason = timer_context->reason;
8804
8805
8806 if ((!adapter) ||
8807 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
8808 hdd_err("invalid adapter or adapter has invalid magic");
8809 return;
8810 }
8811 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8812 if (wlan_hdd_validate_context(hdd_ctx))
8813 return;
8814
8815 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
8816 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8817 else
8818 return;
8819
8820 hdd_err("ACS timeout happened for %s reason %d",
8821 adapter->dev->name, reason);
Jeff Johnson16528362018-06-14 12:34:16 -07008822
Kapil Gupta8878ad92017-02-13 11:56:04 +05308823 switch (reason) {
8824 /* SAP init case */
8825 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
8826 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
8827 false);
8828 wlan_hdd_cfg80211_start_acs(adapter);
8829 break;
8830 /* DFS detected on current channel */
8831 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
8832 wlan_sap_update_next_channel(
8833 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
Jeff Johnson16528362018-06-14 12:34:16 -07008834 sme_update_new_channel_event(hdd_ctx->mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07008835 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308836 break;
8837 /* LTE coex event on current channel */
8838 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
8839 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
8840 break;
8841 default:
8842 hdd_info("invalid reason for timer invoke");
8843
8844 }
8845}
8846
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008847/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008848 * hdd_override_ini_config - Override INI config
8849 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008850 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008851 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008852 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008853 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008854 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008855static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008856{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008857
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008858 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
8859 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008860 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008861 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008862 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008863 if (0 == enable_11d || 1 == enable_11d) {
8864 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008865 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008866 }
Leo Chang11545d62016-10-17 14:53:50 -07008867
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +05308868 if (hdd_ctx->config->action_oui_enable && !ucfg_action_oui_enabled()) {
8869 hdd_ctx->config->action_oui_enable = 0;
8870 hdd_err("Ignore ini: %s, since no action_oui component",
8871 CFG_ENABLE_ACTION_OUI);
8872 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008873}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008874
Ashish Kumar Dhanotiya12f68212018-09-04 22:00:14 +05308875#ifdef ENABLE_MTRACE_LOG
8876static void hdd_set_mtrace_for_each(struct hdd_context *hdd_ctx)
8877{
8878 uint8_t module_id = 0;
8879 int qdf_print_idx = -1;
8880
8881 qdf_print_idx = qdf_get_pidx();
8882 for (module_id = 0; module_id < QDF_MODULE_ID_MAX; module_id++)
8883 qdf_print_set_category_verbose(
8884 qdf_print_idx,
8885 module_id, QDF_TRACE_LEVEL_TRACE,
8886 hdd_ctx->config->enable_mtrace);
8887}
8888#else
8889static void hdd_set_mtrace_for_each(struct hdd_context *hdd_ctx)
8890{
8891}
8892
8893#endif
8894
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008895/**
8896 * hdd_set_trace_level_for_each - Set trace level for each INI config
8897 * @hdd_ctx - HDD context
8898 *
8899 * Set trace level for each module based on INI config.
8900 *
8901 * Return: None
8902 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008903static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008904{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308905 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
8906 hdd_ctx->config->qdf_trace_enable_wdi);
8907 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
8908 hdd_ctx->config->qdf_trace_enable_hdd);
8909 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
8910 hdd_ctx->config->qdf_trace_enable_sme);
8911 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
8912 hdd_ctx->config->qdf_trace_enable_pe);
8913 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
8914 hdd_ctx->config->qdf_trace_enable_wma);
8915 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
8916 hdd_ctx->config->qdf_trace_enable_sys);
8917 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
8918 hdd_ctx->config->qdf_trace_enable_qdf);
8919 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
8920 hdd_ctx->config->qdf_trace_enable_sap);
8921 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
8922 hdd_ctx->config->qdf_trace_enable_hdd_sap);
8923 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
8924 hdd_ctx->config->qdf_trace_enable_bmi);
8925 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
8926 hdd_ctx->config->qdf_trace_enable_cfg);
8927 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
8928 hdd_ctx->config->qdf_trace_enable_epping);
8929 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
8930 hdd_ctx->config->qdf_trace_enable_qdf_devices);
8931 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07008932 hdd_ctx->config->qdf_trace_enable_txrx);
8933 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
8934 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308935 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
8936 hdd_ctx->config->qdf_trace_enable_htc);
8937 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
8938 hdd_ctx->config->qdf_trace_enable_hif);
8939 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
8940 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
8941 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
8942 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08008943 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
8944 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07008945 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
8946 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008947 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
8948 hdd_ctx->config->qdf_trace_enable_regulatory);
Naveen Rawat3cb779e2018-02-16 16:36:10 -08008949 hdd_qdf_trace_enable(QDF_MODULE_ID_CP_STATS,
8950 hdd_ctx->config->qdf_trace_enable_cp_stats);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05308951 hdd_qdf_trace_enable(QDF_MODULE_ID_MLME, 0xffff);
Sourav Mohapatra113685f2018-08-29 14:21:55 +05308952 hdd_qdf_trace_enable(QDF_MODULE_ID_FWOL, 0xffff);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008953
Ashish Kumar Dhanotiya12f68212018-09-04 22:00:14 +05308954 hdd_set_mtrace_for_each(hdd_ctx);
8955
Nirav Shah5c083da2018-08-03 13:46:02 +05308956 hdd_cfg_print_global_config(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008957}
8958
8959/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008960 * hdd_context_init() - Initialize HDD context
8961 * @hdd_ctx: HDD context.
8962 *
8963 * Initialize HDD context along with all the feature specific contexts.
8964 *
8965 * return: 0 on success and errno on failure.
8966 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008967static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008968{
8969 int ret;
8970
8971 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
8972 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
8973
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008974 init_completion(&hdd_ctx->mc_sus_event_var);
8975 init_completion(&hdd_ctx->ready_to_suspend);
8976
8977 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308978 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008979 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308980
Dustin Brownbee82832018-07-23 10:10:51 -07008981 qdf_list_create(&hdd_ctx->hdd_adapters, 0);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008982
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008983 ret = hdd_scan_context_init(hdd_ctx);
8984 if (ret)
8985 goto list_destroy;
8986
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008987 hdd_rx_wake_lock_create(hdd_ctx);
8988
8989 ret = hdd_sap_context_init(hdd_ctx);
8990 if (ret)
8991 goto scan_destroy;
8992
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008993 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8994
8995 hdd_init_offloaded_packets_ctx(hdd_ctx);
8996
8997 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8998 hdd_ctx->config);
8999 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08009000 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009001
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05309002 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
9003 "monitor_mode_wakelock");
9004
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009005 return 0;
9006
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009007sap_destroy:
9008 hdd_sap_context_destroy(hdd_ctx);
9009
9010scan_destroy:
9011 hdd_scan_context_destroy(hdd_ctx);
9012 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009013list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07009014 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08009015
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009016 return ret;
9017}
9018
Dustin Brown4c663222018-10-23 14:19:36 -07009019void hdd_psoc_idle_timer_start(struct hdd_context *hdd_ctx)
9020{
9021 uint32_t timeout_ms = hdd_ctx->config->iface_change_wait_time;
9022 enum wake_lock_reason reason =
9023 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER;
9024
9025 hdd_debug("Starting psoc idle timer");
9026 qdf_sched_delayed_work(&hdd_ctx->psoc_idle_timeout_work, timeout_ms);
9027 hdd_prevent_suspend_timeout(timeout_ms, reason);
9028}
9029
9030void hdd_psoc_idle_timer_stop(struct hdd_context *hdd_ctx)
9031{
9032 qdf_cancel_delayed_work(&hdd_ctx->psoc_idle_timeout_work);
9033 hdd_debug("Stopped psoc idle timer");
9034}
9035
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009036/**
Dustin Brown3ecc8782018-09-19 16:37:13 -07009037 * hdd_psoc_idle_shutdown() - perform an idle shutdown on the given psoc
9038 * @hdd_ctx: the hdd context which should be shutdown
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309039 *
Dustin Brown3ecc8782018-09-19 16:37:13 -07009040 * When no interfaces are "up" on a psoc, an idle shutdown timer is started.
9041 * If no interfaces are brought up before the timer expires, we do an
9042 * "idle shutdown," cutting power to the physical SoC to save power. This is
9043 * done completely transparently from the perspective of userspace.
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309044 *
Dustin Brown3ecc8782018-09-19 16:37:13 -07009045 * Return: None
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309046 */
Dustin Brown3ecc8782018-09-19 16:37:13 -07009047static void hdd_psoc_idle_shutdown(struct hdd_context *hdd_ctx)
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309048{
Dustin Brown3ecc8782018-09-19 16:37:13 -07009049 struct hdd_psoc *hdd_psoc = hdd_ctx->hdd_psoc;
9050 QDF_STATUS status;
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309051
Dustin Brown491d54b2018-03-14 12:39:11 -07009052 hdd_enter();
Dustin Brown3ecc8782018-09-19 16:37:13 -07009053
9054 status = dsc_psoc_trans_start(hdd_psoc->dsc_psoc, "idle shutdown");
9055 if (QDF_IS_STATUS_ERROR(status)) {
9056 hdd_info("psoc busy, abort idle shutdown; status:%u", status);
9057 return;
9058 }
9059
9060 QDF_BUG(!hdd_wlan_stop_modules(hdd_ctx, false));
9061
9062 hdd_psoc->state = psoc_state_idle;
9063 dsc_psoc_trans_stop(hdd_psoc->dsc_psoc);
9064
Dustin Browne74003f2018-03-14 12:51:58 -07009065 hdd_exit();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309066}
9067
Dustin Brown3ecc8782018-09-19 16:37:13 -07009068int hdd_psoc_idle_restart(struct hdd_context *hdd_ctx)
9069{
9070 struct hdd_psoc *hdd_psoc = hdd_ctx->hdd_psoc;
9071 QDF_STATUS status;
9072 int errno;
9073
9074 status = dsc_psoc_trans_start_wait(hdd_psoc->dsc_psoc, "idle restart");
9075 if (QDF_IS_STATUS_ERROR(status)) {
9076 hdd_info("unable to start 'idle restart'; status:%u", status);
9077 return qdf_status_to_os_return(status);
9078 }
9079
9080 errno = hdd_wlan_start_modules(hdd_ctx, false);
9081 if (!errno)
9082 hdd_psoc->state = psoc_state_active;
9083
9084 dsc_psoc_trans_stop(hdd_psoc->dsc_psoc);
9085
9086 return errno;
9087}
9088
9089/**
9090 * hdd_psoc_idle_timeout_callback() - Handler for psoc idle timeout
9091 * @priv: pointer to hdd context
9092 *
9093 * Return: None
9094 */
9095static void hdd_psoc_idle_timeout_callback(void *priv)
9096{
9097 struct hdd_context *hdd_ctx = priv;
9098
9099 if (wlan_hdd_validate_context(hdd_ctx))
9100 return;
9101
9102 hdd_debug("Psoc idle timeout elapsed; starting psoc shutdown");
9103 hdd_psoc_idle_shutdown(hdd_ctx);
9104}
9105
Nirav Shaheb017be2018-02-15 11:20:58 +05309106#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9107static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
9108{
9109 wlan_logging_set_log_to_console(hdd_ctx->config->
9110 wlan_logging_to_console);
9111 wlan_logging_set_active(hdd_ctx->config->wlan_logging_enable);
9112}
9113#else
9114static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
9115{ }
9116#endif
9117
Dundi Raviteja8e338282018-09-25 17:16:04 +05309118#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9119static void hdd_init_wlan_logging_params(struct hdd_config *config,
9120 struct wlan_objmgr_psoc *psoc)
9121{
9122 config->wlan_logging_enable = cfg_get(psoc, CFG_WLAN_LOGGING_SUPPORT);
9123
9124 config->wlan_logging_to_console =
9125 cfg_get(psoc, CFG_WLAN_LOGGING_CONSOLE_SUPPORT);
9126}
9127#else
9128static void hdd_init_wlan_logging_params(struct hdd_config *config,
9129 struct wlan_objmgr_psoc *psoc)
9130{
9131}
9132#endif
9133
9134#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9135static void hdd_init_wlan_auto_shutdown(struct hdd_config *config,
9136 struct wlan_objmgr_psoc *psoc)
9137{
9138 config->wlan_auto_shutdown = cfg_get(psoc, CFG_WLAN_AUTO_SHUTDOWN);
9139}
9140#else
9141static void hdd_init_wlan_auto_shutdown(struct hdd_config *config,
9142 struct wlan_objmgr_psoc *psoc)
9143{
9144}
9145#endif
9146
9147#ifndef REMOVE_PKT_LOG
9148static void hdd_init_packet_log(struct hdd_config *config,
9149 struct wlan_objmgr_psoc *psoc)
9150{
9151 config->enable_packet_log = cfg_get(psoc, CFG_ENABLE_PACKET_LOG);
9152}
9153#else
9154static void hdd_init_packet_log(struct hdd_config *config,
9155 struct wlan_objmgr_psoc *psoc)
9156{
9157}
9158#endif
9159
9160/**
9161 * hdd_cfg_params_init() - Initialize hdd params in hdd_config strucuture
9162 * @hdd_ctx - Pointer to HDD context
9163 *
9164 * Return: None
9165 */
9166static void hdd_cfg_params_init(struct hdd_context *hdd_ctx)
9167{
9168 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
9169 struct hdd_config *config = hdd_ctx->config;
9170
9171 if (!psoc) {
9172 hdd_err("Invalid psoc");
9173 return;
9174 }
9175
9176 if (!config) {
9177 hdd_err("Invalid hdd config");
9178 return;
9179 }
9180
9181 config->bug_on_reinit_failure = cfg_get(psoc,
9182 CFG_BUG_ON_REINIT_FAILURE);
9183
9184 config->is_ramdump_enabled = cfg_get(psoc,
9185 CFG_ENABLE_RAMDUMP_COLLECTION);
9186
9187 config->iface_change_wait_time = cfg_get(psoc,
9188 CFG_INTERFACE_CHANGE_WAIT);
9189
9190 config->multicast_host_fw_msgs = cfg_get(psoc,
9191 CFG_MULTICAST_HOST_FW_MSGS);
9192
9193 config->private_wext_control = cfg_get(psoc, CFG_PRIVATE_WEXT_CONTROL);
9194 config->timer_multiplier = cfg_get(psoc, CFG_TIMER_MULTIPLIER);
9195 config->enablefwprint = cfg_get(psoc, CFG_ENABLE_FW_UART_PRINT);
9196 config->enable_fw_log = cfg_get(psoc, CFG_ENABLE_FW_LOG);
9197
9198 hdd_init_wlan_auto_shutdown(config, psoc);
9199 hdd_init_wlan_logging_params(config, psoc);
9200 hdd_init_packet_log(config, psoc);
jitiphil869b9f72018-09-25 17:14:01 +05309201 hdd_dp_cfg_update(psoc, hdd_ctx);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309202}
9203
Dustin Brown623e7e32018-09-05 14:27:50 -07009204struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009205{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309206 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009207 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009208 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009209
Dustin Brown491d54b2018-03-14 12:39:11 -07009210 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009211
Dustin Brown92bd8382018-10-31 15:49:46 -07009212 hdd_ctx = hdd_cfg80211_wiphy_alloc();
9213 if (!hdd_ctx) {
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009214 ret = -ENOMEM;
9215 goto err_out;
9216 }
9217
Dustin Brown4c663222018-10-23 14:19:36 -07009218 qdf_create_delayed_work(&hdd_ctx->psoc_idle_timeout_work,
Dustin Brown3ecc8782018-09-19 16:37:13 -07009219 hdd_psoc_idle_timeout_callback,
Dustin Brown4c663222018-10-23 14:19:36 -07009220 hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309221
9222 mutex_init(&hdd_ctx->iface_change_lock);
9223
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009224 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05309225 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009226
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309227 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Min Liu74a1a502018-10-10 19:59:07 +08009228 if (!hdd_ctx->config) {
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009229 ret = -ENOMEM;
9230 goto err_free_hdd_context;
9231 }
9232
9233 /* Read and parse the qcom_cfg.ini file */
9234 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309235 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309236 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009237 WLAN_INI_FILE);
9238 ret = -EINVAL;
9239 goto err_free_config;
9240 }
9241
Dustin Brown84f46ea2018-02-15 11:57:36 -08009242 status = cfg_parse(WLAN_INI_FILE);
9243 if (QDF_IS_STATUS_ERROR(status))
9244 hdd_err("Failed to parse cfg %s; status:%d\n",
9245 WLAN_INI_FILE, status);
9246
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309247 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx, DEFAULT_PSOC_ID);
9248 if (ret) {
Dundi Raviteja8e338282018-09-25 17:16:04 +05309249 QDF_DEBUG_PANIC("Psoc creation fails!");
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309250 goto err_free_config;
9251 }
9252
Dundi Raviteja8e338282018-09-25 17:16:04 +05309253 hdd_cfg_params_init(hdd_ctx);
9254
Dustin Brown7f939932017-05-18 15:02:17 -07009255 hdd_debug("setting timer multiplier: %u",
9256 hdd_ctx->config->timer_multiplier);
9257 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
9258
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309259 cds_set_fatal_event(cfg_get(hdd_ctx->psoc,
9260 CFG_ENABLE_FATAL_EVENT_TRIGGER));
Abhishek Singh5ea86532016-04-27 14:10:53 +05309261
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009262 hdd_override_ini_config(hdd_ctx);
9263
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009264 ret = hdd_context_init(hdd_ctx);
9265
9266 if (ret)
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309267 goto err_hdd_objmgr_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009268
Anurag Chouhan6d760662016-02-20 16:05:43 +05309269 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009270 goto skip_multicast_logging;
9271
9272 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
9273
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07009274 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
9275 if (ret)
9276 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05309277
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009278 ret = hdd_init_netlink_services(hdd_ctx);
9279 if (ret)
9280 goto err_deinit_txrx_histogram;
9281
Nirav Shaheb017be2018-02-15 11:20:58 +05309282 hdd_set_wlan_logging(hdd_ctx);
Nirav Shahed34b212016-04-25 10:59:16 +05309283
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009284skip_multicast_logging:
9285 hdd_set_trace_level_for_each(hdd_ctx);
9286
Rajeev Kumar493a31b2017-09-29 14:01:24 -07009287 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
9288
Dustin Browne74003f2018-03-14 12:51:58 -07009289 hdd_exit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07009290
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009291 return hdd_ctx;
9292
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009293err_deinit_txrx_histogram:
9294 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
9295
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07009296err_deinit_hdd_context:
9297 hdd_context_deinit(hdd_ctx);
9298
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309299err_hdd_objmgr_destroy:
9300 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9301
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009302err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309303 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009304
9305err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309306 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08009307 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009308
9309err_out:
9310 return ERR_PTR(ret);
9311}
9312
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009313#ifdef WLAN_OPEN_P2P_INTERFACE
9314/**
9315 * hdd_open_p2p_interface - Open P2P interface
Dustin Brown61cc3932018-10-18 16:12:13 -07009316 * @hdd_ctx: HDD context
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009317 *
Dustin Brown61cc3932018-10-18 16:12:13 -07009318 * Return: QDF_STATUS
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009319 */
Dustin Brown61cc3932018-10-18 16:12:13 -07009320static QDF_STATUS hdd_open_p2p_interface(struct hdd_context *hdd_ctx)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009321{
Jeff Johnson9d295242017-08-29 14:39:48 -07009322 struct hdd_adapter *adapter;
Dustin Brown61cc3932018-10-18 16:12:13 -07009323 bool p2p_dev_addr_admin;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009324
Dustin Brown1dbefe62018-09-11 16:32:03 -07009325 cfg_p2p_get_device_addr_admin(hdd_ctx->psoc, &p2p_dev_addr_admin);
Dustin Brown61cc3932018-10-18 16:12:13 -07009326
Wu Gaoe5689792018-07-05 19:20:13 +08009327 if (p2p_dev_addr_admin &&
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009328 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Dustin Brown61cc3932018-10-18 16:12:13 -07009329 hdd_ctx->p2p_device_address = hdd_ctx->config->intfMacAddr[0];
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009330
9331 /*
Dustin Brown61cc3932018-10-18 16:12:13 -07009332 * Generate the P2P Device Address. This consists of
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009333 * the device's primary MAC address with the locally
9334 * administered bit set.
9335 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009336 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009337 } else {
Dustin Brown61cc3932018-10-18 16:12:13 -07009338 uint8_t *p2p_dev_addr;
9339
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009340 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
Dustin Brown61cc3932018-10-18 16:12:13 -07009341 if (!p2p_dev_addr) {
9342 hdd_err("Failed to get MAC address for new p2p device");
9343 return QDF_STATUS_E_INVAL;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009344 }
9345
Dustin Brown61cc3932018-10-18 16:12:13 -07009346 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009347 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009348 }
9349
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009350 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Dustin Brown61cc3932018-10-18 16:12:13 -07009351 hdd_ctx->p2p_device_address.bytes,
9352 NET_NAME_UNKNOWN, true);
9353 if (!adapter) {
9354 hdd_err("Failed to open p2p interface");
9355 return QDF_STATUS_E_INVAL;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009356 }
9357
Dustin Brown61cc3932018-10-18 16:12:13 -07009358 return QDF_STATUS_SUCCESS;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009359}
9360#else
Dustin Brown61cc3932018-10-18 16:12:13 -07009361static inline QDF_STATUS hdd_open_p2p_interface(struct hdd_context *hdd_ctx)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009362{
Dustin Brown61cc3932018-10-18 16:12:13 -07009363 return QDF_STATUS_SUCCESS;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009364}
9365#endif
9366
Dustin Brown61cc3932018-10-18 16:12:13 -07009367static QDF_STATUS hdd_open_ocb_interface(struct hdd_context *hdd_ctx)
Jeff Johnson957bc272017-02-02 08:54:48 -08009368{
Jeff Johnson9d295242017-08-29 14:39:48 -07009369 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08009370
9371 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
9372 wlan_hdd_get_intf_addr(hdd_ctx),
Dustin Brown61cc3932018-10-18 16:12:13 -07009373 NET_NAME_UNKNOWN, true);
9374 if (!adapter) {
Jeff Johnson957bc272017-02-02 08:54:48 -08009375 hdd_err("Failed to open 802.11p interface");
Dustin Brown61cc3932018-10-18 16:12:13 -07009376 return QDF_STATUS_E_INVAL;
Jeff Johnson957bc272017-02-02 08:54:48 -08009377 }
9378
Dustin Brown61cc3932018-10-18 16:12:13 -07009379 return QDF_STATUS_SUCCESS;
9380}
9381
9382static QDF_STATUS hdd_open_concurrent_interface(struct hdd_context *hdd_ctx)
9383{
9384 struct hdd_adapter *adapter;
9385
9386 if (qdf_str_eq(hdd_ctx->config->enableConcurrentSTA, ""))
9387 return QDF_STATUS_SUCCESS;
9388
9389 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
9390 hdd_ctx->config->enableConcurrentSTA,
9391 wlan_hdd_get_intf_addr(hdd_ctx),
9392 NET_NAME_UNKNOWN, true);
9393 if (!adapter) {
9394 hdd_err("Failed to open concurrent station interface");
9395 return QDF_STATUS_E_INVAL;
9396 }
9397
9398 return QDF_STATUS_SUCCESS;
Jeff Johnson957bc272017-02-02 08:54:48 -08009399}
9400
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009401/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309402 * hdd_start_station_adapter()- Start the Station Adapter
9403 * @adapter: HDD adapter
9404 *
9405 * This function initializes the adapter for the station mode.
9406 *
9407 * Return: 0 on success or errno on failure.
9408 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009409int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309410{
9411 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08009412 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309413
Dustin Brownfdf17c12018-03-14 12:55:34 -07009414 hdd_enter_dev(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08009415 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9416 hdd_err("session is already opened, %d",
9417 adapter->session_id);
9418 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9419 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309420
Krunal Sonib51eec72017-11-20 21:53:01 -08009421 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
9422 if (ret) {
9423 hdd_err("failed to create vdev: %d", ret);
9424 return ret;
9425 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309426 status = hdd_init_station_mode(adapter);
9427
9428 if (QDF_STATUS_SUCCESS != status) {
9429 hdd_err("Error Initializing station mode: %d", status);
9430 return qdf_status_to_os_return(status);
9431 }
9432
Arun Khandavallifae92942016-08-01 13:31:08 +05309433 hdd_register_tx_flow_control(adapter,
9434 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009435 hdd_tx_resume_cb,
9436 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309437
Dustin Browne74003f2018-03-14 12:51:58 -07009438 hdd_exit();
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05309439
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309440 return 0;
9441}
9442
9443/**
9444 * hdd_start_ap_adapter()- Start AP Adapter
9445 * @adapter: HDD adapter
9446 *
9447 * This function initializes the adapter for the AP mode.
9448 *
9449 * Return: 0 on success errno on failure.
9450 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009451int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309452{
9453 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009454 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08009455 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08009456 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309457
Dustin Brown491d54b2018-03-14 12:39:11 -07009458 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309459
Krunal Sonib51eec72017-11-20 21:53:01 -08009460 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9461 hdd_err("session is already opened, %d",
9462 adapter->session_id);
9463 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9464 }
9465 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009466 * In SSR case no need to create new sap context.
9467 * Otherwise create sap context first and then create
9468 * vdev as while creating the vdev, driver needs to
9469 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08009470 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009471 if (adapter->session.ap.sap_context) {
9472 is_ssr = true;
9473 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08009474 hdd_err("sap creation failed");
9475 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
9476 }
9477
9478 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
9479 adapter->session.ap.sap_context);
9480 if (ret) {
9481 hdd_err("failed to create vdev, status:%d", ret);
9482 hdd_sap_destroy_ctx(adapter);
9483 return ret;
9484 }
Naveen Rawat1af09392018-01-03 17:28:21 -08009485
9486 if (adapter->device_mode == QDF_SAP_MODE)
9487 sme_cli_set_command(adapter->session_id,
9488 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
9489 (bool)(hdd_ctx->config->fine_time_meas_cap &
9490 WMI_FW_AP_RTT_RESPR),
9491 VDEV_CMD);
9492
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009493 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309494
9495 if (QDF_STATUS_SUCCESS != status) {
9496 hdd_err("Error Initializing the AP mode: %d", status);
9497 return qdf_status_to_os_return(status);
9498 }
9499
Arun Khandavallifae92942016-08-01 13:31:08 +05309500 hdd_register_tx_flow_control(adapter,
9501 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009502 hdd_softap_tx_resume_cb,
9503 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309504
Dustin Browne74003f2018-03-14 12:51:58 -07009505 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309506 return 0;
9507}
9508
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309509#ifdef QCA_LL_TX_FLOW_CONTROL_V2
9510/**
9511 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
9512 * @cds_cfg: CDS Configuration
9513 * @hdd_ctx: Pointer to hdd context
9514 *
9515 * Return: none
9516 */
9517static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9518 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009519 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309520{
9521 cds_cfg->tx_flow_stop_queue_th =
9522 hdd_ctx->config->TxFlowStopQueueThreshold;
9523 cds_cfg->tx_flow_start_queue_offset =
9524 hdd_ctx->config->TxFlowStartQueueOffset;
Mohit Khanna70322002018-05-15 19:21:32 -07009525 /* configuration for DP RX Threads */
9526 cds_cfg->enable_dp_rx_threads = hdd_ctx->enable_dp_rx_threads;
9527 cds_cfg->num_dp_rx_threads = hdd_ctx->config->num_dp_rx_threads;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309528}
9529#else
9530static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9531 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009532 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309533{
9534}
9535#endif
9536
9537#ifdef FEATURE_WLAN_RA_FILTERING
9538/**
9539 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
9540 * @cds_cfg: CDS Configuration
9541 * @hdd_ctx: Pointer to hdd context
9542 *
9543 * Return: none
9544 */
Anand Kumar3b92a912016-12-05 12:01:26 +05309545static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009546 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309547{
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05309548 bool is_rate_limit_enabled;
9549 QDF_STATUS status;
9550
9551 status = ucfg_fwol_get_is_rate_limit_enabled(hdd_ctx->psoc,
9552 &is_rate_limit_enabled);
9553 if (QDF_IS_STATUS_ERROR(status))
9554 return;
9555
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309556 cds_cfg->ra_ratelimit_interval =
9557 hdd_ctx->config->RArateLimitInterval;
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05309558 cds_cfg->is_ra_ratelimit_enabled = is_rate_limit_enabled;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309559}
9560#else
Anand Kumar3b92a912016-12-05 12:01:26 +05309561static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009562 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309563{
9564}
9565#endif
9566
9567/**
9568 * hdd_update_cds_config() - API to update cds configuration parameters
9569 * @hdd_ctx: HDD Context
9570 *
9571 * Return: 0 for Success, errno on failure
9572 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009573static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309574{
9575 struct cds_config_info *cds_cfg;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309576 int value;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309577 uint8_t band_capability;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309578 uint8_t ito_repeat_count;
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309579 bool crash_inject;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309580 bool self_recovery;
9581 bool fw_timeout_crash;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309582 QDF_STATUS status;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309583
Min Liu74a1a502018-10-10 19:59:07 +08009584 cds_cfg = qdf_mem_malloc(sizeof(*cds_cfg));
9585 if (!cds_cfg)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309586 return -ENOMEM;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309587
Srinivas Girigowda35b00312017-06-27 21:52:03 -07009588 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309589 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309590
9591 /*
9592 * Copy the DFS Phyerr Filtering Offload status.
9593 * This parameter reflects the value of the
9594 * dfs_phyerr_filter_offload flag as set in the ini.
9595 */
9596 cds_cfg->dfs_phyerr_filter_offload =
9597 hdd_ctx->config->fDfsPhyerrFilterOffload;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309598
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309599 status = ucfg_mlme_get_crash_inject(hdd_ctx->psoc, &crash_inject);
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309600 if (QDF_IS_STATUS_ERROR(status)) {
9601 hdd_err("Failed to get crash inject ini config");
9602 goto exit;
9603 }
9604
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309605 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
9606 if (QDF_IS_STATUS_ERROR(status)) {
9607 hdd_err("Failed to get self recovery ini config");
9608 goto exit;
9609 }
9610
9611 status = ucfg_mlme_get_fw_timeout_crash(hdd_ctx->psoc,
9612 &fw_timeout_crash);
9613 if (QDF_IS_STATUS_ERROR(status)) {
9614 hdd_err("Failed to get fw timeout crash ini config");
9615 goto exit;
9616 }
9617
9618 status = ucfg_mlme_get_ito_repeat_count(hdd_ctx->psoc,
9619 &ito_repeat_count);
9620 if (QDF_IS_STATUS_ERROR(status)) {
9621 hdd_err("Failed to get ITO repeat count ini config");
9622 goto exit;
9623 }
9624
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309625 cds_cfg->force_target_assert_enabled = crash_inject;
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05309626
Dustin Brown05d81302018-09-11 16:49:22 -07009627 ucfg_mlme_get_sap_max_offload_peers(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309628 cds_cfg->ap_maxoffload_peers = value;
Dustin Brown05d81302018-09-11 16:49:22 -07009629 ucfg_mlme_get_sap_max_offload_reorder_buffs(hdd_ctx->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309630 &value);
9631 cds_cfg->ap_maxoffload_reorderbuffs = value;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309632
9633 cds_cfg->ap_disable_intrabss_fwd =
9634 hdd_ctx->config->apDisableIntraBssFwd;
9635
9636 cds_cfg->dfs_pri_multiplier =
9637 hdd_ctx->config->dfsRadarPriMultiplier;
9638 cds_cfg->reorder_offload =
9639 hdd_ctx->config->reorderOffloadSupport;
9640
9641 /* IPA micro controller data path offload resource config item */
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05309642 cds_cfg->uc_offload_enabled = ucfg_ipa_uc_is_enabled();
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309643 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
9644
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07009645 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309646 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
Dustin Brown05d81302018-09-11 16:49:22 -07009647 ucfg_mlme_get_sap_max_peers(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309648 cds_cfg->max_station = value;
Naveen Rawat64e477e2016-05-20 10:34:56 -07009649 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07009650 cds_cfg->max_msdus_per_rxinorderind =
9651 hdd_ctx->config->max_msdus_per_rxinorderind;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309652 cds_cfg->self_recovery_enabled = self_recovery;
9653 cds_cfg->fw_timeout_crash = fw_timeout_crash;
Nachiket Kukadee547a482018-05-22 16:43:30 +05309654 cds_cfg->active_uc_apf_mode = hdd_ctx->config->active_uc_apf_mode;
9655 cds_cfg->active_mc_bc_apf_mode = hdd_ctx->config->active_mc_bc_apf_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309656
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309657 cds_cfg->ito_repeat_count = ito_repeat_count;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309658
9659 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
9660 if (QDF_IS_STATUS_ERROR(status))
9661 goto exit;
9662
9663 cds_cfg->bandcapability = band_capability;
Zhu Jianmina2f8e8d2018-02-11 16:37:10 +08009664 cds_cfg->delay_before_vdev_stop =
9665 hdd_ctx->config->delay_before_vdev_stop;
Rachit Kankane0106e382018-05-16 18:59:28 +05309666 cds_cfg->num_vdevs = hdd_ctx->config->num_vdevs;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309667
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309668 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
9669 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07009670 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309671 cds_init_ini_config(cds_cfg);
9672 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309673
9674exit:
9675 qdf_mem_free(cds_cfg);
9676 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309677}
9678
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009679/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009680 * hdd_update_user_config() - API to update user configuration
9681 * parameters to obj mgr which are used by multiple components
9682 * @hdd_ctx: HDD Context
9683 *
9684 * Return: 0 for Success, errno on failure
9685 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009686static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009687{
9688 struct wlan_objmgr_psoc_user_config *user_config;
Wu Gaoe5689792018-07-05 19:20:13 +08009689 bool skip_dfs_in_p2p_search = false;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309690 uint8_t band_capability;
9691 QDF_STATUS status;
9692
9693 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
9694 if (QDF_IS_STATUS_ERROR(status))
9695 return -EIO;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009696
9697 user_config = qdf_mem_malloc(sizeof(*user_config));
Min Liu74a1a502018-10-10 19:59:07 +08009698 if (!user_config)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009699 return -ENOMEM;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009700
9701 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
9702 user_config->dual_mac_feature_disable =
9703 hdd_ctx->config->dual_mac_feature_disable;
9704 user_config->indoor_channel_support =
9705 hdd_ctx->config->indoor_channel_support;
9706 user_config->is_11d_support_enabled =
9707 hdd_ctx->config->Is11dSupportEnabled;
9708 user_config->is_11h_support_enabled =
9709 hdd_ctx->config->Is11hSupportEnabled;
Dustin Brown1dbefe62018-09-11 16:32:03 -07009710 cfg_p2p_get_skip_dfs_channel_p2p_search(hdd_ctx->psoc,
Wu Gaoe5689792018-07-05 19:20:13 +08009711 &skip_dfs_in_p2p_search);
9712 user_config->skip_dfs_chnl_in_p2p_search = skip_dfs_in_p2p_search;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309713 user_config->band_capability = band_capability;
Dustin Brown1dbefe62018-09-11 16:32:03 -07009714 wlan_objmgr_psoc_set_user_config(hdd_ctx->psoc, user_config);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009715
9716 qdf_mem_free(user_config);
9717 return 0;
9718}
9719
9720/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009721 * hdd_init_thermal_info - Initialize thermal level
9722 * @hdd_ctx: HDD context
9723 *
9724 * Initialize thermal level at SME layer and set the thermal level callback
9725 * which would be called when a configured thermal threshold is hit.
9726 *
9727 * Return: 0 on success and errno on failure
9728 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009729static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009730{
9731 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309732 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -07009733 mac_handle_t mac_handle;
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309734 struct wlan_fwol_thermal_temp thermal_temp = {0};
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009735
9736 thermal_param.smeThermalMgmtEnabled =
9737 hdd_ctx->config->thermalMitigationEnable;
9738 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
9739
Poddar, Siddarth83905022016-04-16 17:56:08 -07009740 thermal_param.sme_throttle_duty_cycle_tbl[0] =
9741 hdd_ctx->config->throttle_dutycycle_level0;
9742 thermal_param.sme_throttle_duty_cycle_tbl[1] =
9743 hdd_ctx->config->throttle_dutycycle_level1;
9744 thermal_param.sme_throttle_duty_cycle_tbl[2] =
9745 hdd_ctx->config->throttle_dutycycle_level2;
9746 thermal_param.sme_throttle_duty_cycle_tbl[3] =
9747 hdd_ctx->config->throttle_dutycycle_level3;
9748
Dustin Brown05d81302018-09-11 16:49:22 -07009749 status = ucfg_fwol_get_thermal_temp(hdd_ctx->psoc, &thermal_temp);
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309750 if (QDF_IS_STATUS_ERROR(status))
9751 return qdf_status_to_os_return(status);
9752
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009753 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309754 thermal_temp.thermal_temp_min_level0;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009755 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309756 thermal_temp.thermal_temp_max_level0;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009757 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309758 thermal_temp.thermal_temp_min_level1;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009759 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309760 thermal_temp.thermal_temp_max_level1;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009761 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309762 thermal_temp.thermal_temp_min_level2;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009763 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309764 thermal_temp.thermal_temp_max_level2;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009765 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309766 thermal_temp.thermal_temp_min_level3;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009767 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309768 thermal_temp.thermal_temp_max_level3;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009769
Jeff Johnson16528362018-06-14 12:34:16 -07009770 mac_handle = hdd_ctx->mac_handle;
9771 status = sme_init_thermal_info(mac_handle, thermal_param);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009772
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309773 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05309774 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009775
Jeff Johnson16528362018-06-14 12:34:16 -07009776 sme_add_set_thermal_level_callback(mac_handle,
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009777 hdd_set_thermal_level_cb);
9778
9779 return 0;
9780
9781}
9782
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009783#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
9784/**
9785 * hdd_hold_rtnl_lock - Hold RTNL lock
9786 *
9787 * Hold RTNL lock
9788 *
9789 * Return: True if held and false otherwise
9790 */
9791static inline bool hdd_hold_rtnl_lock(void)
9792{
9793 rtnl_lock();
9794 return true;
9795}
9796
9797/**
9798 * hdd_release_rtnl_lock - Release RTNL lock
9799 *
9800 * Release RTNL lock
9801 *
9802 * Return: None
9803 */
9804static inline void hdd_release_rtnl_lock(void)
9805{
9806 rtnl_unlock();
9807}
9808#else
9809static inline bool hdd_hold_rtnl_lock(void) { return false; }
9810static inline void hdd_release_rtnl_lock(void) { }
9811#endif
9812
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009813#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009814
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309815/* MAX iwpriv command support */
9816#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309817#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309818#define MAX_PKTLOG_SIZE 16
9819
9820/**
9821 * hdd_pktlog_set_buff_size() - set pktlog buffer size
9822 * @hdd_ctx: hdd context
9823 * @set_value2: pktlog buffer size value
9824 *
9825 *
9826 * Return: 0 for success or error.
9827 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009828static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309829{
9830 struct sir_wifi_start_log start_log = { 0 };
9831 QDF_STATUS status;
9832
9833 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9834 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9835 start_log.ini_triggered = cds_is_packet_log_enabled();
9836 start_log.user_triggered = 1;
9837 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309838 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309839
Jeff Johnson16528362018-06-14 12:34:16 -07009840 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309841 if (!QDF_IS_STATUS_SUCCESS(status)) {
9842 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009843 hdd_exit();
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309844 return -EINVAL;
9845 }
9846
9847 return 0;
9848}
9849
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009850/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309851 * hdd_pktlog_clear_buff() - clear pktlog buffer
9852 * @hdd_ctx: hdd context
9853 *
9854 * Return: 0 for success or error.
9855 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009856static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309857{
9858 struct sir_wifi_start_log start_log;
9859 QDF_STATUS status;
9860
9861 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9862 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9863 start_log.ini_triggered = cds_is_packet_log_enabled();
9864 start_log.user_triggered = 1;
9865 start_log.size = 0;
9866 start_log.is_pktlog_buff_clear = true;
9867
Jeff Johnson16528362018-06-14 12:34:16 -07009868 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309869 if (!QDF_IS_STATUS_SUCCESS(status)) {
9870 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009871 hdd_exit();
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309872 return -EINVAL;
9873 }
9874
9875 return 0;
9876}
9877
9878
9879/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009880 * hdd_process_pktlog_command() - process pktlog command
9881 * @hdd_ctx: hdd context
9882 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309883 * @set_value2: pktlog buffer size value
9884 *
9885 * This function process pktlog command.
9886 * set_value2 only matters when set_value is 3 (set buff size)
9887 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009888 *
9889 * Return: 0 for success or error.
9890 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009891int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309892 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009893{
9894 int ret;
9895 bool enable;
9896 uint8_t user_triggered = 0;
9897
9898 ret = wlan_hdd_validate_context(hdd_ctx);
9899 if (0 != ret)
9900 return ret;
9901
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009902 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009903
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309904 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009905 hdd_err("invalid pktlog value %d", set_value);
9906 return -EINVAL;
9907 }
9908
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309909 if (set_value == PKTLOG_SET_BUFF_SIZE) {
9910 if (set_value2 <= 0) {
9911 hdd_err("invalid pktlog size %d", set_value2);
9912 return -EINVAL;
9913 } else if (set_value2 > MAX_PKTLOG_SIZE) {
9914 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
9915 return -EINVAL;
9916 }
9917 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309918 } else if (set_value == PKTLOG_CLEAR_BUFF) {
9919 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309920 }
9921
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009922 /*
9923 * set_value = 0 then disable packetlog
9924 * set_value = 1 enable packetlog forcefully
9925 * set_vlaue = 2 then disable packetlog if disabled through ini or
9926 * enable packetlog with AUTO type.
9927 */
9928 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
9929 true : false;
9930
9931 if (1 == set_value) {
9932 enable = true;
9933 user_triggered = 1;
9934 }
9935
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309936 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009937}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07009938
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009939/**
9940 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
9941 * @hdd_ctx: HDD context
9942 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309943 * @user_triggered: triggered through iwpriv
9944 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009945 *
9946 * Return: 0 on success; error number otherwise
9947 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009948int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309949 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009950{
9951 struct sir_wifi_start_log start_log;
9952 QDF_STATUS status;
9953
9954 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9955 start_log.verbose_level =
9956 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009957 start_log.ini_triggered = cds_is_packet_log_enabled();
9958 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309959 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309960 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05309961 /*
9962 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
9963 * commands. Host uses this flag to decide whether to send pktlog
9964 * disable command to fw without sending pktlog enable command
9965 * previously. For eg, If vendor sends pktlog disable command without
9966 * sending pktlog enable command, then host discards the packet
9967 * but for iwpriv command, host will send it to fw.
9968 */
9969 start_log.is_iwpriv_command = 1;
Jeff Johnson16528362018-06-14 12:34:16 -07009970 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009971 if (!QDF_IS_STATUS_SUCCESS(status)) {
9972 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009973 hdd_exit();
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009974 return -EINVAL;
9975 }
9976
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309977 if (enable == true)
9978 hdd_ctx->is_pktlog_enabled = 1;
9979 else
9980 hdd_ctx->is_pktlog_enabled = 0;
9981
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009982 return 0;
9983}
9984#endif /* REMOVE_PKT_LOG */
9985
Komal Seelam92fff912016-03-24 11:51:41 +05309986/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009987 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
9988 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05309989 * @dev: Device Pointer
9990 * @num: Number of Valid Mac address
9991 *
9992 * Return: Pointer to MAC address buffer
9993 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009994static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9995 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309996{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009997 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309998}
Komal Seelam92fff912016-03-24 11:51:41 +05309999
10000/**
10001 * hdd_populate_random_mac_addr() - API to populate random mac addresses
10002 * @hdd_ctx: HDD Context
10003 * @num: Number of random mac addresses needed
10004 *
10005 * Generate random addresses using bit manipulation on the base mac address
10006 *
10007 * Return: None
10008 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010009void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +053010010{
10011 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
10012 uint32_t iter;
10013 struct hdd_config *ini = hdd_ctx->config;
10014 uint8_t *buf = NULL;
10015 uint8_t macaddr_b3, tmp_br3;
10016 uint8_t *src = ini->intfMacAddr[0].bytes;
10017
10018 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
10019 buf = ini->intfMacAddr[iter].bytes;
10020 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
10021 macaddr_b3 = buf[3];
10022 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
10023 INTF_MACADDR_MASK;
10024 macaddr_b3 += tmp_br3;
10025 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
10026 buf[0] |= 0x02;
10027 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010028 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +053010029 }
10030}
10031
10032/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010033 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +053010034 * @hdd_ctx: HDD Context
10035 *
10036 * API to get mac addresses from platform driver and update the driver
10037 * structures and configure FW with the base mac address.
10038 * Return: int
10039 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010040static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +053010041{
10042 uint32_t no_of_mac_addr, iter;
10043 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
10044 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
10045 uint8_t *addr, *buf;
10046 struct device *dev = hdd_ctx->parent_dev;
10047 struct hdd_config *ini = hdd_ctx->config;
10048 tSirMacAddr mac_addr;
10049 QDF_STATUS status;
10050
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010051 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +053010052
Dustin Brown7e761c72018-07-31 13:50:17 -070010053 if (no_of_mac_addr == 0 || !addr)
Komal Seelam92fff912016-03-24 11:51:41 +053010054 return -EINVAL;
Komal Seelam92fff912016-03-24 11:51:41 +053010055
10056 if (no_of_mac_addr > max_mac_addr)
10057 no_of_mac_addr = max_mac_addr;
10058
10059 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
10060
10061 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
10062 buf = ini->intfMacAddr[iter].bytes;
10063 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010064 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +053010065 }
10066
10067 status = sme_set_custom_mac_addr(mac_addr);
10068
10069 if (!QDF_IS_STATUS_SUCCESS(status))
10070 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010071
Komal Seelam92fff912016-03-24 11:51:41 +053010072 if (no_of_mac_addr < max_mac_addr)
10073 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
10074 no_of_mac_addr);
10075 return 0;
10076}
10077
10078/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010079 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
10080 * @hdd_ctx: HDD Context
10081 *
10082 * Update MAC address to FW. If MAC address passed by FW is invalid, host
10083 * will generate its own MAC and update it to FW.
10084 *
10085 * Return: 0 for success
10086 * Non-zero error code for failure
10087 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010088static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010089{
10090 tSirMacAddr customMacAddr;
10091 QDF_STATUS status;
10092
10093 qdf_mem_copy(&customMacAddr,
10094 &hdd_ctx->config->intfMacAddr[0].bytes[0],
10095 sizeof(tSirMacAddr));
10096 status = sme_set_custom_mac_addr(customMacAddr);
10097 if (!QDF_IS_STATUS_SUCCESS(status))
10098 return -EAGAIN;
10099 return 0;
10100}
10101
10102/**
Komal Seelam92fff912016-03-24 11:51:41 +053010103 * hdd_initialize_mac_address() - API to get wlan mac addresses
10104 * @hdd_ctx: HDD Context
10105 *
10106 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
10107 * is provisioned with mac addresses, driver uses it, else it will use
10108 * wlan_mac.bin to update HW MAC addresses.
10109 *
10110 * Return: None
10111 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010112static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +053010113{
10114 QDF_STATUS status;
10115 int ret;
10116
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010117 ret = hdd_platform_wlan_mac(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010118 if (!ret) {
10119 hdd_info("using MAC address from platform driver");
Komal Seelam92fff912016-03-24 11:51:41 +053010120 return;
Dustin Brown7e761c72018-07-31 13:50:17 -070010121 }
Komal Seelam92fff912016-03-24 11:51:41 +053010122
10123 status = hdd_update_mac_config(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010124 if (QDF_IS_STATUS_SUCCESS(status)) {
10125 hdd_info("using MAC address from wlan_mac.bin");
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010126 return;
Dustin Brown7e761c72018-07-31 13:50:17 -070010127 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010128
Dustin Brown7e761c72018-07-31 13:50:17 -070010129 hdd_info("using default MAC address");
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010130
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -080010131 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010132 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010133 if (ret)
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -080010134 hdd_err("MAC address out-of-sync, ret:%d", ret);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010135 }
Komal Seelam92fff912016-03-24 11:51:41 +053010136}
10137
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010138static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010139{
10140 int vdev_id = 0;
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053010141 QDF_STATUS status;
10142 bool smart_chainmask_enabled;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010143 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010144 int vpdev = PDEV_CMD;
10145 int ret;
10146
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053010147 status = ucfg_get_smart_chainmask_enabled(hdd_ctx->psoc,
10148 &smart_chainmask_enabled);
10149 if (QDF_IS_STATUS_ERROR(status))
10150 return -EINVAL;
10151
10152 ret = sme_cli_set_command(vdev_id, param_id,
10153 (int)smart_chainmask_enabled, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010154 if (ret)
10155 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
10156
10157 return ret;
10158}
10159
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010160static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010161{
10162 int vdev_id = 0;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010163 QDF_STATUS status;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010164 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010165 bool alternative_chainmask_enabled;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010166 int vpdev = PDEV_CMD;
10167 int ret;
10168
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010169 status = ucfg_get_alternative_chainmask_enabled(
10170 hdd_ctx->psoc,
10171 &alternative_chainmask_enabled);
10172 if (QDF_IS_STATUS_ERROR(status))
10173 return -EINVAL;
10174
10175 ret = sme_cli_set_command(vdev_id, param_id,
10176 (int)alternative_chainmask_enabled, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010177 if (ret)
10178 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
10179 ret);
10180
10181 return ret;
10182}
10183
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010184static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -070010185{
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010186 QDF_STATUS status;
Jeff Johnson12a744b2017-04-04 08:19:37 -070010187 int vdev_id = 0;
10188 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010189 bool value;
Jeff Johnson12a744b2017-04-04 08:19:37 -070010190 int vpdev = PDEV_CMD;
10191 int ret;
10192
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010193 status = ucfg_fwol_get_ani_enabled(hdd_ctx->psoc, &value);
10194 if (QDF_IS_STATUS_ERROR(status))
10195 return -EINVAL;
10196
10197 ret = sme_cli_set_command(vdev_id, param_id, (int)value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -070010198 if (ret)
10199 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
10200
10201 return ret;
10202}
10203
Jeff Johnson89c66ff2016-04-22 15:21:37 -070010204/**
Prashanth Bhatta07998752016-04-28 12:35:33 -070010205 * hdd_pre_enable_configure() - Configurations prior to cds_enable
10206 * @hdd_ctx: HDD context
10207 *
10208 * Pre configurations to be done at lower layer before calling cds enable.
10209 *
10210 * Return: 0 on success and errno on failure.
10211 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010212static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -070010213{
10214 int ret;
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010215 uint8_t val = 0;
Prashanth Bhatta07998752016-04-28 12:35:33 -070010216 QDF_STATUS status;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010217 uint32_t arp_ac_category;
Leo Changfdb45c32016-10-28 11:09:23 -070010218 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010219
Leo Changfdb45c32016-10-28 11:09:23 -070010220 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Ajit Pal Singh5d269612018-04-19 16:29:12 +053010221 /* Register HL netdev flow control callback */
10222 cdp_hl_fc_register(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010223
10224 /*
10225 * Note that the cds_pre_enable() sequence triggers the cfg download.
10226 * The cfg download must occur before we update the SME config
10227 * since the SME config operation must access the cfg database
10228 */
10229 status = hdd_set_sme_config(hdd_ctx);
10230
10231 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010232 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010233 ret = qdf_status_to_os_return(status);
10234 goto out;
10235 }
10236
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -070010237 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
10238 if (QDF_STATUS_SUCCESS != status) {
10239 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
10240 ret = qdf_status_to_os_return(status);
10241 goto out;
10242 }
10243
Dustin Brown1dbefe62018-09-11 16:32:03 -070010244 status = ucfg_mlme_get_tx_chainmask_1ss(hdd_ctx->psoc, &val);
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010245 if (QDF_STATUS_SUCCESS != status) {
10246 hdd_err("Get tx_chainmask_1ss from mlme failed");
10247 ret = qdf_status_to_os_return(status);
10248 goto out;
10249 }
10250 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS, val,
Prashanth Bhatta07998752016-04-28 12:35:33 -070010251 PDEV_CMD);
10252 if (0 != ret) {
10253 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
10254 goto out;
10255 }
10256
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010257 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
10258 if (ret)
10259 goto out;
10260
10261 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
10262 if (ret)
10263 goto out;
10264
Jeff Johnson12a744b2017-04-04 08:19:37 -070010265 ret = hdd_set_ani_enabled(hdd_ctx);
10266 if (ret)
10267 goto out;
10268
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010269 status = ucfg_get_arp_ac_category(hdd_ctx->psoc, &arp_ac_category);
10270
10271 if (QDF_IS_STATUS_ERROR(status))
10272 return -EINVAL;
10273
Naveen Rawat247a8682017-06-05 15:00:31 -070010274 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010275 arp_ac_category,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -080010276 PDEV_CMD);
10277 if (0 != ret) {
10278 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010279 arp_ac_category, ret);
Srinivas Girigowda70e169a2017-03-07 23:55:57 -080010280 goto out;
10281 }
10282
Prashanth Bhatta07998752016-04-28 12:35:33 -070010283 status = hdd_set_sme_chan_list(hdd_ctx);
10284 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010285 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010286 ret = qdf_status_to_os_return(status);
10287 goto out;
10288 }
10289
10290 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -070010291 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010292 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -070010293 ret = -EINVAL;
10294 goto out;
10295 }
10296
Prashanth Bhatta07998752016-04-28 12:35:33 -070010297 /*
10298 * Set the MAC Address Currently this is used by HAL to add self sta.
10299 * Remove this once self sta is added as part of session open.
10300 */
Jeff Johnson16528362018-06-14 12:34:16 -070010301 status = sme_cfg_set_str(hdd_ctx->mac_handle, WNI_CFG_STA_ID,
Jeff Johnsonbae59f92018-06-01 17:05:43 -070010302 hdd_ctx->config->intfMacAddr[0].bytes,
10303 sizeof(hdd_ctx->config->intfMacAddr[0]));
Prashanth Bhatta07998752016-04-28 12:35:33 -070010304
Jeff Johnsonbae59f92018-06-01 17:05:43 -070010305 if (QDF_IS_STATUS_ERROR(status)) {
10306 hdd_err("Failed to set MAC Address, status %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010307 ret = -EINVAL;
10308 goto out;
10309 }
10310
10311 hdd_init_channel_avoidance(hdd_ctx);
10312
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +053010313 /* update enable sap mandatory chan list */
Dustin Brown1dbefe62018-09-11 16:32:03 -070010314 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->psoc,
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +053010315 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010316out:
10317 return ret;
10318}
10319
Rachit Kankane026e77a2018-07-31 16:21:09 +053010320#ifdef FEATURE_P2P_LISTEN_OFFLOAD
Prashanth Bhatta07998752016-04-28 12:35:33 -070010321/**
Peng Xu8fdaa492016-06-22 10:20:47 -070010322 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010323 * @context: context registered with sme_register_p2p_lo_event(). HDD
10324 * always registers a hdd context pointer
10325 * @evt:event structure pointer
Peng Xu8fdaa492016-06-22 10:20:47 -070010326 *
10327 * This is the p2p listen offload stop event handler, it sends vendor
10328 * event back to supplicant to notify the stop reason.
10329 *
10330 * Return: None
10331 */
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010332static void wlan_hdd_p2p_lo_event_callback(void *context,
10333 struct sir_p2p_lo_event *evt)
Peng Xu8fdaa492016-06-22 10:20:47 -070010334{
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010335 struct hdd_context *hdd_ctx = context;
Peng Xu8fdaa492016-06-22 10:20:47 -070010336 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -070010337 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -070010338
Dustin Brown491d54b2018-03-14 12:39:11 -070010339 hdd_enter();
Peng Xu8fdaa492016-06-22 10:20:47 -070010340
10341 if (hdd_ctx == NULL) {
10342 hdd_err("Invalid HDD context pointer");
10343 return;
10344 }
10345
Peng Xu5c682812017-08-06 07:39:13 -070010346 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
10347 if (!adapter) {
10348 hdd_err("Cannot find adapter by vdev_id = %d",
10349 evt->vdev_id);
10350 return;
10351 }
10352
Peng Xu8fdaa492016-06-22 10:20:47 -070010353 vendor_event =
10354 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -070010355 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -070010356 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
10357 GFP_KERNEL);
10358
10359 if (!vendor_event) {
10360 hdd_err("cfg80211_vendor_event_alloc failed");
10361 return;
10362 }
10363
10364 if (nla_put_u32(vendor_event,
10365 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
10366 evt->reason_code)) {
10367 hdd_err("nla put failed");
10368 kfree_skb(vendor_event);
10369 return;
10370 }
10371
10372 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -070010373 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
10374 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -070010375}
Rachit Kankane026e77a2018-07-31 16:21:09 +053010376#else
10377static void wlan_hdd_p2p_lo_event_callback(void *context,
10378 struct sir_p2p_lo_event *evt)
10379{
10380}
10381#endif
Peng Xu8fdaa492016-06-22 10:20:47 -070010382
Rachit Kankanef6834c42018-08-02 18:47:50 +053010383#ifdef FEATURE_WLAN_DYNAMIC_CVM
10384static inline int hdd_set_vc_mode_config(struct hdd_context *hdd_ctx)
10385{
10386 return sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap);
10387}
10388#else
10389static inline int hdd_set_vc_mode_config(struct hdd_context *hdd_ctx)
10390{
10391 return QDF_STATUS_SUCCESS;
10392}
10393#endif
10394
Peng Xu8fdaa492016-06-22 10:20:47 -070010395/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010396 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
10397 * @hdd_ctx: HDD context
10398 *
10399 * This function sends the adaptive dwell time config configuration to the
10400 * firmware via WMA
10401 *
10402 * Return: 0 - success, < 0 - failure
10403 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010404static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010405{
10406 QDF_STATUS status;
10407 struct adaptive_dwelltime_params dwelltime_params;
10408
10409 dwelltime_params.is_enabled =
10410 hdd_ctx->config->adaptive_dwell_mode_enabled;
10411 dwelltime_params.dwelltime_mode =
10412 hdd_ctx->config->global_adapt_dwelltime_mode;
10413 dwelltime_params.lpf_weight =
10414 hdd_ctx->config->adapt_dwell_lpf_weight;
10415 dwelltime_params.passive_mon_intval =
10416 hdd_ctx->config->adapt_dwell_passive_mon_intval;
10417 dwelltime_params.wifi_act_threshold =
10418 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
10419
Jeff Johnson16528362018-06-14 12:34:16 -070010420 status = sme_set_adaptive_dwelltime_config(hdd_ctx->mac_handle,
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010421 &dwelltime_params);
10422
10423 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
10424 if (!QDF_IS_STATUS_SUCCESS(status)) {
10425 hdd_err("Failed to send Adaptive Dwelltime configuration!");
10426 return -EAGAIN;
10427 }
10428 return 0;
10429}
10430
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010431int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010432{
10433 QDF_STATUS status;
10434 struct wmi_dbs_scan_sel_params dbs_scan_params;
10435 uint32_t i = 0;
10436 uint8_t count = 0, numentries = 0;
10437 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
10438 * CDS_DBS_SCAN_CLIENTS_MAX];
10439
10440 /* check if DBS is enabled or supported */
Bala Venkateshc8236ca2018-03-09 12:38:29 +053010441 if ((hdd_ctx->config->dual_mac_feature_disable ==
10442 DISABLE_DBS_CXN_AND_SCAN) ||
10443 (hdd_ctx->config->dual_mac_feature_disable ==
10444 ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN))
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010445 return -EINVAL;
10446
10447 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
10448 dbs_scan_config, &numentries,
10449 (CDS_DBS_SCAN_PARAM_PER_CLIENT
10450 * CDS_DBS_SCAN_CLIENTS_MAX));
10451
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010452 if (!numentries) {
Dustin Brown6a8d39b2018-08-14 15:27:26 -070010453 hdd_debug("Do not send scan_selection_config");
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010454 return 0;
10455 }
10456
10457 /* hdd_set_fw_log_params */
10458 dbs_scan_params.num_clients = 0;
10459 while (count < (numentries - 2)) {
10460 dbs_scan_params.module_id[i] = dbs_scan_config[count];
10461 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
10462 dbs_scan_params.num_non_dbs_scans[i] =
10463 dbs_scan_config[count + 2];
10464 dbs_scan_params.num_clients++;
10465 hdd_debug("module:%d NDS:%d NNDS:%d",
10466 dbs_scan_params.module_id[i],
10467 dbs_scan_params.num_dbs_scans[i],
10468 dbs_scan_params.num_non_dbs_scans[i]);
10469 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
10470 i++;
10471 }
10472
10473 dbs_scan_params.pdev_id = 0;
10474
10475 hdd_debug("clients:%d pdev:%d",
10476 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
10477
Jeff Johnson16528362018-06-14 12:34:16 -070010478 status = sme_set_dbs_scan_selection_config(hdd_ctx->mac_handle,
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010479 &dbs_scan_params);
10480 hdd_debug("Sending DBS Scan Selection Configuration to fw");
10481 if (!QDF_IS_STATUS_SUCCESS(status)) {
10482 hdd_err("Failed to send DBS Scan selection configuration!");
10483 return -EAGAIN;
10484 }
10485 return 0;
10486}
10487
Arun Khandavallid4349a92016-07-25 11:10:43 +053010488#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10489/**
10490 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
10491 * @hdd_ctx: HDD context
10492 *
10493 * Set auto shutdown callback to get indications from firmware to indicate
10494 * userspace to shutdown WLAN after a configured amount of inactivity.
10495 *
10496 * Return: 0 on success and errno on failure.
10497 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010498static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010499{
10500 QDF_STATUS status;
10501
Dundi Raviteja8e338282018-09-25 17:16:04 +053010502 if (!hdd_ctx->config->wlan_auto_shutdown)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010503 return 0;
10504
Jeff Johnson16528362018-06-14 12:34:16 -070010505 status = sme_set_auto_shutdown_cb(hdd_ctx->mac_handle,
Arun Khandavallid4349a92016-07-25 11:10:43 +053010506 wlan_hdd_auto_shutdown_cb);
10507 if (status != QDF_STATUS_SUCCESS)
10508 hdd_err("Auto shutdown feature could not be enabled: %d",
10509 status);
10510
10511 return qdf_status_to_os_return(status);
10512}
10513#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010514static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010515{
10516 return 0;
10517}
10518#endif
10519
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010520#ifdef MWS_COEX
10521/**
10522 * hdd_set_mws_coex() - Set MWS coex configurations
10523 * @hdd_ctx: HDD context
10524 *
10525 * This function sends MWS-COEX 4G quick FTDM and
10526 * MWS-COEX 5G-NR power limit to FW
10527 *
10528 * Return: 0 on success and errno on failure.
10529 */
10530static int hdd_init_mws_coex(struct hdd_context *hdd_ctx)
10531{
10532 int ret = 0;
10533
10534 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_MWSCOEX_4G_ALLOW_QUICK_FTDM,
10535 hdd_ctx->config->mws_coex_4g_quick_tdm,
10536 PDEV_CMD);
10537 if (ret) {
10538 hdd_warn("Unable to send MWS-COEX 4G quick FTDM policy");
10539 return ret;
10540 }
10541
10542 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_MWSCOEX_SET_5GNR_PWR_LIMIT,
10543 hdd_ctx->config->mws_coex_5g_nr_pwr_limit,
10544 PDEV_CMD);
10545 if (ret) {
10546 hdd_warn("Unable to send MWS-COEX 4G quick FTDM policy");
10547 return ret;
10548 }
10549 return ret;
10550}
10551#else
10552static int hdd_init_mws_coex(struct hdd_context *hdd_ctx)
10553{
10554 return 0;
10555}
10556#endif
10557
Arun Khandavallid4349a92016-07-25 11:10:43 +053010558/**
10559 * hdd_features_init() - Init features
10560 * @hdd_ctx: HDD context
Arun Khandavallid4349a92016-07-25 11:10:43 +053010561 *
10562 * Initialize features and their feature context after WLAN firmware is up.
10563 *
10564 * Return: 0 on success and errno on failure.
10565 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010566static int hdd_features_init(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010567{
10568 tSirTxPowerLimit hddtxlimit;
10569 QDF_STATUS status;
10570 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070010571 mac_handle_t mac_handle;
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010572 struct hdd_config *cfg;
Wu Gao93816212018-08-31 16:49:54 +080010573 bool b_cts2self;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010574
Dustin Brown491d54b2018-03-14 12:39:11 -070010575 hdd_enter();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010576
Dustin Brownad698ae2018-09-05 17:19:30 -070010577 ret = hdd_update_country_code(hdd_ctx);
10578 if (ret) {
10579 hdd_err("Failed to update country code; errno:%d", ret);
10580 return -EINVAL;
10581 }
10582
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010583 ret = hdd_init_mws_coex(hdd_ctx);
10584 if (ret)
10585 hdd_warn("Error initializing mws-coex");
10586
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010587 cfg = hdd_ctx->config;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010588 /* FW capabilities received, Set the Dot11 mode */
Jeff Johnson16528362018-06-14 12:34:16 -070010589 mac_handle = hdd_ctx->mac_handle;
10590 sme_setdef_dot11mode(mac_handle);
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010591 sme_set_etsi13_srd_ch_in_master_mode(mac_handle,
10592 cfg->
10593 etsi13_srd_chan_in_master_mode);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010594
10595 if (hdd_ctx->config->fIsImpsEnabled)
10596 hdd_set_idle_ps_config(hdd_ctx, true);
10597 else
10598 hdd_set_idle_ps_config(hdd_ctx, false);
10599
Poddar, Siddarth37033032017-10-11 15:47:40 +053010600 /* Send Enable/Disable data stall detection cmd to FW */
10601 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
jitiphil377bcc12018-10-05 19:46:08 +053010602 cdp_cfg_get(cds_get_context(QDF_MODULE_ID_SOC),
10603 cfg_dp_enable_data_stall), PDEV_CMD);
Poddar, Siddarth37033032017-10-11 15:47:40 +053010604
Dustin Brown1dbefe62018-09-11 16:32:03 -070010605 ucfg_mlme_get_go_cts2self_for_sta(hdd_ctx->psoc, &b_cts2self);
Wu Gao93816212018-08-31 16:49:54 +080010606 if (b_cts2self)
Jeff Johnson16528362018-06-14 12:34:16 -070010607 sme_set_cts2self_for_p2p_go(mac_handle);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010608
Rachit Kankanef6834c42018-08-02 18:47:50 +053010609 if (hdd_set_vc_mode_config(hdd_ctx))
Nachiket Kukade8983cf62017-10-12 18:14:48 +053010610 hdd_warn("Error in setting Voltage Corner mode config to FW");
10611
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010612 if (hdd_rx_ol_init(hdd_ctx))
10613 hdd_err("Unable to initialize Rx LRO/GRO in fw");
Arun Khandavallid4349a92016-07-25 11:10:43 +053010614
10615 if (hdd_adaptive_dwelltime_init(hdd_ctx))
10616 hdd_err("Unable to send adaptive dwelltime setting to FW");
10617
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010618 if (hdd_dbs_scan_selection_init(hdd_ctx))
10619 hdd_err("Unable to send DBS scan selection setting to FW");
10620
Arun Khandavallid4349a92016-07-25 11:10:43 +053010621 ret = hdd_init_thermal_info(hdd_ctx);
10622 if (ret) {
10623 hdd_err("Error while initializing thermal information");
Dustin Browne7e71d32018-05-11 16:00:08 -070010624 return ret;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010625 }
10626
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010627 /**
10628 * In case of SSR/PDR, if pktlog was enabled manually before
10629 * SSR/PDR, Then enabled it again automatically after Wlan
10630 * device up.
10631 */
10632 if (cds_is_driver_recovering()) {
10633 if (hdd_ctx->is_pktlog_enabled)
10634 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Alok Kumar5a75b9d2018-08-31 10:55:43 +053010635 } else if (cds_is_packet_log_enabled())
10636 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Poddar, Siddarth66a46592017-02-22 11:44:44 +053010637
Arun Khandavallid4349a92016-07-25 11:10:43 +053010638 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
10639 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
Jeff Johnson16528362018-06-14 12:34:16 -070010640 status = sme_txpower_limit(mac_handle, &hddtxlimit);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010641 if (!QDF_IS_STATUS_SUCCESS(status))
10642 hdd_err("Error setting txlimit in sme: %d", status);
10643
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010644 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010645
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053010646 status = sme_enable_disable_chanavoidind_event(mac_handle, 0);
10647 if (QDF_IS_STATUS_ERROR(status) && (status != QDF_STATUS_E_NOSUPPORT)) {
10648 hdd_err("Failed to disable Chan Avoidance Indication");
Sourav Mohapatra674925f2018-04-16 11:16:58 +053010649 return -EINVAL;
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +053010650 }
Arun Khandavallid4349a92016-07-25 11:10:43 +053010651
10652 /* register P2P Listen Offload event callback */
10653 if (wma_is_p2p_lo_capable())
Jeff Johnson16528362018-06-14 12:34:16 -070010654 sme_register_p2p_lo_event(mac_handle, hdd_ctx,
10655 wlan_hdd_p2p_lo_event_callback);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010656
10657 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
10658
10659 if (ret)
Sourav Mohapatra674925f2018-04-16 11:16:58 +053010660 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010661
Dustin Brown11638b72018-01-25 17:37:25 +053010662 wlan_hdd_init_chan_info(hdd_ctx);
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010663 wlan_hdd_twt_init(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010664
Dustin Browne74003f2018-03-14 12:51:58 -070010665 hdd_exit();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010666 return 0;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010667}
10668
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010669/**
10670 * hdd_features_deinit() - Deinit features
10671 * @hdd_ctx: HDD context
10672 *
10673 * De-Initialize features and their feature context.
10674 *
10675 * Return: none.
10676 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010677static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010678{
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010679 wlan_hdd_twt_deinit(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010680 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010681 wlan_hdd_tsf_deinit(hdd_ctx);
10682}
10683
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010684/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010685 * hdd_register_bcn_cb() - register scan beacon callback
10686 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010687 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010688 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010689 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010690static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010691{
10692 QDF_STATUS status;
10693
Dustin Brown1dbefe62018-09-11 16:32:03 -070010694 status = ucfg_scan_register_bcn_cb(hdd_ctx->psoc,
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010695 wlan_cfg80211_inform_bss_frame,
10696 SCAN_CB_TYPE_INFORM_BCN);
10697 if (!QDF_IS_STATUS_SUCCESS(status)) {
10698 hdd_err("failed with status code %08d [x%08x]",
10699 status, status);
10700 return status;
10701 }
10702
10703 return QDF_STATUS_SUCCESS;
10704}
Arun Khandavallid4349a92016-07-25 11:10:43 +053010705
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010706/**
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070010707 * hdd_v2_flow_pool_map() - Flow pool create callback when vdev is active
10708 * @vdev_id: vdev_id, corresponds to flow_pool
10709 *
10710 * Return: none.
10711 */
10712static void hdd_v2_flow_pool_map(int vdev_id)
10713{
10714 QDF_STATUS status;
10715
10716 status = cdp_flow_pool_map(cds_get_context(QDF_MODULE_ID_SOC),
10717 cds_get_context(QDF_MODULE_ID_TXRX),
10718 vdev_id);
10719 /*
10720 * For Adrastea flow control v2 is based on FW MAP events,
10721 * so this above callback is not implemented.
10722 * Hence this is not actual failure. Dont return failure
10723 */
10724 if ((status != QDF_STATUS_SUCCESS) &&
10725 (status != QDF_STATUS_E_INVAL)) {
10726 hdd_err("vdev_id: %d, failed to create flow pool status %d",
10727 vdev_id, status);
10728 }
10729}
10730
10731/**
10732 * hdd_v2_flow_pool_unmap() - Flow pool create callback when vdev is not active
10733 * @vdev_id: vdev_id, corresponds to flow_pool
10734 *
10735 * Return: none.
10736 */
10737static void hdd_v2_flow_pool_unmap(int vdev_id)
10738{
10739 cdp_flow_pool_unmap(cds_get_context(QDF_MODULE_ID_SOC),
10740 cds_get_context(QDF_MODULE_ID_TXRX), vdev_id);
10741}
10742
10743/**
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010744 * hdd_action_oui_config() - Configure action_oui strings
10745 * @hdd_ctx: pointer to hdd context
10746 *
10747 * This is a HDD wrapper function which invokes ucfg api
10748 * of action_oui component to parse action oui strings.
10749 *
10750 * Return: None
10751 */
10752static void hdd_action_oui_config(struct hdd_context *hdd_ctx)
10753{
10754 QDF_STATUS status;
10755 uint32_t id;
10756 uint8_t *str;
10757
10758 if (!hdd_ctx->config->action_oui_enable)
10759 return;
10760
10761 for (id = 0; id < ACTION_OUI_MAXIMUM_ID; id++) {
10762 str = hdd_ctx->config->action_oui_str[id];
10763 if (!qdf_str_len(str))
10764 continue;
10765
Dustin Brown1dbefe62018-09-11 16:32:03 -070010766 status = ucfg_action_oui_parse(hdd_ctx->psoc, str, id);
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010767 if (!QDF_IS_STATUS_SUCCESS(status))
10768 hdd_err("Failed to parse action_oui str: %u", id);
10769 }
10770}
10771
10772/**
10773 * hdd_action_oui_send() - Send action_oui extensions to firmware
10774 * @hdd_ctx: pointer to hdd context
10775 *
10776 * This is a HDD wrapper function which invokes ucfg api
10777 * of action_oui component to send action oui extensions to firmware.
10778 *
10779 * Return: None
10780 */
10781static void hdd_action_oui_send(struct hdd_context *hdd_ctx)
10782{
10783 QDF_STATUS status;
10784
10785 if (!hdd_ctx->config->action_oui_enable)
10786 return;
10787
Dustin Brown1dbefe62018-09-11 16:32:03 -070010788 status = ucfg_action_oui_send(hdd_ctx->psoc);
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010789 if (!QDF_IS_STATUS_SUCCESS(status))
10790 hdd_err("Failed to send one or all action_ouis");
10791}
10792
10793/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010794 * hdd_configure_cds() - Configure cds modules
10795 * @hdd_ctx: HDD context
10796 * @adapter: Primary adapter context
10797 *
10798 * Enable Cds modules after WLAN firmware is up.
10799 *
10800 * Return: 0 on success and errno on failure.
10801 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010802int hdd_configure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010803{
10804 int ret;
10805 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010806 int set_value;
Jeff Johnson16528362018-06-14 12:34:16 -070010807 mac_handle_t mac_handle;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010808 bool enable_rts_sifsbursting;
10809 uint8_t enable_phy_reg_retention;
10810 uint8_t max_mpdus_inampdu;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010811 uint32_t num_abg_tx_chains = 0;
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010812 uint16_t num_11b_tx_chains = 0;
10813 uint16_t num_11ag_tx_chains = 0;
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010814 struct policy_mgr_dp_cbacks dp_cbs = {0};
Bala Venkatesh2fde2c62018-09-11 20:33:24 +053010815 bool value;
Wu Gao66454f12018-09-26 19:55:41 +080010816 enum pmo_auto_pwr_detect_failure_mode auto_power_fail_mode;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053010817 bool bval = false;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010818
Jeff Johnson16528362018-06-14 12:34:16 -070010819 mac_handle = hdd_ctx->mac_handle;
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010820
10821 hdd_action_oui_send(hdd_ctx);
10822
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010823 if (hdd_ctx->config->is_force_1x1)
10824 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
10825 1, PDEV_CMD);
10826 /* set chip power save failure detected callback */
Jeff Johnson16528362018-06-14 12:34:16 -070010827 sme_set_chip_pwr_save_fail_cb(mac_handle,
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010828 hdd_chip_pwr_save_fail_detected_cb);
10829
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010830 status = ucfg_get_max_mpdus_inampdu(hdd_ctx->psoc,
10831 &max_mpdus_inampdu);
10832 if (status)
10833 return status;
10834
10835 if (max_mpdus_inampdu) {
10836 set_value = max_mpdus_inampdu;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010837 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
10838 set_value, PDEV_CMD);
10839 }
10840
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010841 status = ucfg_get_enable_rts_sifsbursting(hdd_ctx->psoc,
10842 &enable_rts_sifsbursting);
10843 if (status)
10844 return status;
10845
10846 if (enable_rts_sifsbursting) {
10847 set_value = enable_rts_sifsbursting;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010848 sme_cli_set_command(0,
10849 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
10850 set_value, PDEV_CMD);
10851 }
10852
Dustin Brown05d81302018-09-11 16:49:22 -070010853 ucfg_mlme_get_sap_get_peer_info(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +053010854 if (value) {
10855 set_value = value;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010856 sme_cli_set_command(0,
10857 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
10858 set_value, PDEV_CMD);
10859 }
10860
Dustin Brown1dbefe62018-09-11 16:32:03 -070010861 status = ucfg_mlme_get_num_11b_tx_chains(hdd_ctx->psoc,
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010862 &num_11b_tx_chains);
10863 if (status != QDF_STATUS_SUCCESS) {
10864 hdd_err("Failed to get num_11b_tx_chains");
10865 goto out;
10866 }
10867
Dustin Brown1dbefe62018-09-11 16:32:03 -070010868 status = ucfg_mlme_get_num_11ag_tx_chains(hdd_ctx->psoc,
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010869 &num_11ag_tx_chains);
10870 if (status != QDF_STATUS_SUCCESS) {
10871 hdd_err("Failed to get num_11ag_tx_chains");
10872 goto out;
10873 }
10874
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053010875 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
10876 if (!QDF_IS_STATUS_SUCCESS(status))
10877 hdd_err("unable to get vht_enable2x2");
10878
10879 if (!bval) {
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010880 if (num_11b_tx_chains > 1)
10881 num_11b_tx_chains = 1;
10882 if (num_11ag_tx_chains > 1)
10883 num_11ag_tx_chains = 1;
10884 }
10885 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
10886 num_11b_tx_chains);
10887 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
10888 num_11ag_tx_chains);
10889 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
10890 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +053010891
Paul Zhang02526cd2018-09-20 17:47:46 +080010892 if (!ucfg_reg_is_regdb_offloaded(hdd_ctx->psoc))
10893 ucfg_reg_program_default_cc(hdd_ctx->pdev,
10894 hdd_ctx->reg.reg_domain);
10895
Arun Khandavallifae92942016-08-01 13:31:08 +053010896 ret = hdd_pre_enable_configure(hdd_ctx);
10897 if (ret) {
10898 hdd_err("Failed to pre-configure cds");
10899 goto out;
10900 }
10901
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010902 /* Always get latest IPA resources allocated from cds_open and configure
10903 * IPA module before configuring them to FW. Sequence required as crash
10904 * observed otherwise.
10905 */
Dustin Brown07901ec2018-09-07 11:02:41 -070010906 if (ucfg_ipa_uc_ol_init(hdd_ctx->pdev,
10907 cds_get_context(QDF_MODULE_ID_QDF_DEVICE))) {
Manikandan Mohan2e803a02017-02-14 14:57:53 -080010908 hdd_err("Failed to setup pipes");
10909 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010910 }
10911
Arun Khandavallifae92942016-08-01 13:31:08 +053010912 /*
10913 * Start CDS which starts up the SME/MAC/HAL modules and everything
10914 * else
10915 */
Dustin Brown1dbefe62018-09-11 16:32:03 -070010916 status = cds_enable(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010917
10918 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010919 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053010920 goto out;
10921 }
10922
10923 status = hdd_post_cds_enable_config(hdd_ctx);
10924 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010925 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010926 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010927 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010928 status = hdd_register_bcn_cb(hdd_ctx);
10929 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +080010930 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010931 goto cds_disable;
10932 }
Arun Khandavallifae92942016-08-01 13:31:08 +053010933
Dustin Browne7e71d32018-05-11 16:00:08 -070010934 ret = hdd_features_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010935 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010936 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010937
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010938 if (hdd_ctx->ol_enable)
10939 dp_cbs.hdd_disable_rx_ol_in_concurrency =
10940 hdd_disable_rx_ol_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -070010941 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
jiadbb47e132018-03-30 16:28:30 +080010942 dp_cbs.hdd_ipa_set_mcc_mode_cb = hdd_ipa_set_mcc_mode;
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070010943 dp_cbs.hdd_v2_flow_pool_map = hdd_v2_flow_pool_map;
10944 dp_cbs.hdd_v2_flow_pool_unmap = hdd_v2_flow_pool_unmap;
Dustin Brown1dbefe62018-09-11 16:32:03 -070010945 status = policy_mgr_register_dp_cb(hdd_ctx->psoc, &dp_cbs);
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010946 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -070010947 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010948 goto cds_disable;
10949 }
Dustin Brown1dbefe62018-09-11 16:32:03 -070010950 status = policy_mgr_register_mode_change_cb(hdd_ctx->psoc,
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010951 wlan_hdd_send_mode_change_event);
10952 if (!QDF_IS_STATUS_SUCCESS(status)) {
10953 hdd_debug("Failed to register mode change cb with Policy Manager");
10954 goto cds_disable;
10955 }
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010956
Jeff Johnson8bb61112018-03-31 13:33:54 -070010957 if (hdd_green_ap_enable_egap(hdd_ctx))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +053010958 hdd_debug("enhance green ap is not enabled");
10959
Nachiket Kukadedd302662017-07-13 17:31:44 +053010960 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
10961 hdd_debug("Failed to set wow pulse");
10962
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053010963 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
10964 hdd_ctx->config->gcmp_enabled, PDEV_CMD);
Wu Gao66454f12018-09-26 19:55:41 +080010965
10966 auto_power_fail_mode =
10967 ucfg_pmo_get_auto_power_fail_mode(hdd_ctx->psoc);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053010968 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
Wu Gao66454f12018-09-26 19:55:41 +080010969 auto_power_fail_mode, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053010970
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010971 status = ucfg_get_enable_phy_reg_retention(hdd_ctx->psoc,
10972 &enable_phy_reg_retention);
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053010973
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010974 if (QDF_IS_STATUS_ERROR(status))
10975 return -EINVAL;
10976
10977 if (enable_phy_reg_retention)
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053010978 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010979 enable_phy_reg_retention, PDEV_CMD);
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053010980
Arun Khandavallifae92942016-08-01 13:31:08 +053010981 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010982
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010983cds_disable:
Dustin Brown1dbefe62018-09-11 16:32:03 -070010984 cds_disable(hdd_ctx->psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010985
Arun Khandavallifae92942016-08-01 13:31:08 +053010986out:
10987 return -EINVAL;
10988}
10989
10990/**
10991 * hdd_deconfigure_cds() -De-Configure cds
10992 * @hdd_ctx: HDD context
10993 *
10994 * Deconfigure Cds modules before WLAN firmware is down.
10995 *
10996 * Return: 0 on success and errno on failure.
10997 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010998static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010999{
11000 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070011001 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011002
Dustin Brown491d54b2018-03-14 12:39:11 -070011003 hdd_enter();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080011004
11005 /* De-init features */
11006 hdd_features_deinit(hdd_ctx);
11007
Dustin Brown1dbefe62018-09-11 16:32:03 -070011008 qdf_status = policy_mgr_deregister_mode_change_cb(hdd_ctx->psoc);
Srinivas Girigowdad2412882018-09-07 15:42:04 -070011009 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053011010 hdd_debug("Failed to deregister mode change cb with Policy Manager");
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053011011
Dustin Brown1dbefe62018-09-11 16:32:03 -070011012 qdf_status = cds_disable(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053011013 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11014 hdd_err("Failed to Disable the CDS Modules! :%d",
11015 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070011016 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011017 }
11018
Dustin Brown07901ec2018-09-07 11:02:41 -070011019 if (ucfg_ipa_uc_ol_deinit(hdd_ctx->pdev) != QDF_STATUS_SUCCESS) {
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053011020 hdd_err("Failed to disconnect pipes");
11021 ret = -EINVAL;
11022 }
11023
Dustin Browne74003f2018-03-14 12:51:58 -070011024 hdd_exit();
Houston Hoffman6640cf32016-10-10 16:44:29 -070011025 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053011026}
11027
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070011028#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
11029static void hdd_deregister_policy_manager_callback(
11030 struct wlan_objmgr_psoc *psoc)
11031{
11032 if (QDF_STATUS_SUCCESS !=
11033 policy_mgr_deregister_hdd_cb(psoc)) {
11034 hdd_err("HDD callback deregister with policy manager failed");
11035 }
11036}
11037#else
11038static void hdd_deregister_policy_manager_callback(
11039 struct wlan_objmgr_psoc *psoc)
11040{
11041}
11042#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053011043
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011044int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053011045{
11046 void *hif_ctx;
11047 qdf_device_t qdf_ctx;
11048 QDF_STATUS qdf_status;
Dustin Brown4bc0a622017-12-06 15:56:50 -080011049 bool is_recovery_stop = cds_is_driver_recovering();
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053011050 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -070011051 int active_threads;
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053011052 int debugfs_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053011053 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053011054
Dustin Brown491d54b2018-03-14 12:39:11 -070011055 hdd_enter();
Arun Khandavallifae92942016-08-01 13:31:08 +053011056
Dustin Brown1dbefe62018-09-11 16:32:03 -070011057 hdd_deregister_policy_manager_callback(hdd_ctx->psoc);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070011058
Arun Khandavallifae92942016-08-01 13:31:08 +053011059 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11060 if (!qdf_ctx) {
11061 hdd_err("QDF device context NULL");
11062 return -EINVAL;
11063 }
11064
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011065 mutex_lock(&hdd_ctx->iface_change_lock);
11066 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011067 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011068
Dustin Brown70111822017-03-30 15:31:40 -070011069 active_threads = cds_return_external_threads_count();
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053011070 debugfs_threads = hdd_return_debugfs_threads_count();
Dustin Brown70111822017-03-30 15:31:40 -070011071
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053011072 if (active_threads > 0 || debugfs_threads > 0 ||
11073 hdd_ctx->is_wiphy_suspended) {
11074 hdd_warn("External threads %d, Debugfs threads %d, wiphy suspend %d",
11075 active_threads, debugfs_threads,
11076 hdd_ctx->is_wiphy_suspended);
11077
11078 if (active_threads)
11079 cds_print_external_threads();
Dustin Brown70111822017-03-30 15:31:40 -070011080
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053011081 if (IS_IDLE_STOP && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070011082 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4c663222018-10-23 14:19:36 -070011083 hdd_psoc_idle_timer_start(hdd_ctx);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011084 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011085 cds_set_module_stop_in_progress(false);
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011086
Dustin Brown70111822017-03-30 15:31:40 -070011087 return 0;
11088 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070011089 }
11090
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080011091 /* free user wowl patterns */
11092 hdd_free_user_wowl_ptrns();
11093
Arun Khandavallifae92942016-08-01 13:31:08 +053011094 switch (hdd_ctx->driver_status) {
11095 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011096 hdd_debug("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011097 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011098 case DRIVER_MODULES_CLOSED:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011099 hdd_debug("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011100 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011101 case DRIVER_MODULES_ENABLED:
Dustin Brown1a20b082018-08-03 17:27:15 -070011102 hdd_info("Wlan transitioning (CLOSED <- ENABLED)");
11103
11104 if (hdd_get_conparam() == QDF_GLOBAL_FTM_MODE)
11105 break;
Dustin Brown550f6d22017-12-14 15:44:01 -080011106
Komal Seelamf2136bb2016-09-28 18:30:44 +053011107 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053011108 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011109 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053011110 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011111 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011112 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011113 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080011114
Arun Khandavallifae92942016-08-01 13:31:08 +053011115 break;
11116 default:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011117 QDF_DEBUG_PANIC("Unknown driver state:%d",
Arun Khandavallifae92942016-08-01 13:31:08 +053011118 hdd_ctx->driver_status);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011119 ret = -EINVAL;
11120 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011121 }
11122
Arunk Khandavalli890f6d92018-10-30 20:18:28 +053011123 hdd_sysfs_destroy_powerstats_interface();
Amar Singhal18081642018-01-26 16:04:13 -080011124 hdd_sysfs_destroy_version_interface();
Arunk Khandavalli890f6d92018-10-30 20:18:28 +053011125 hdd_sysfs_destroy_driver_root_obj();
Dustin Brown550f6d22017-12-14 15:44:01 -080011126 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080011127
Rajeev Kumarbe021242017-02-16 16:12:23 -080011128 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053011129 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11130 hdd_err("Failed to process post CDS disable Modules! :%d",
11131 qdf_status);
11132 ret = -EINVAL;
11133 QDF_ASSERT(0);
11134 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011135
Sourav Mohapatra674925f2018-04-16 11:16:58 +053011136 /* De-register the SME callbacks */
11137 hdd_deregister_cb(hdd_ctx);
11138
psimhadeea0a12017-12-18 14:50:02 -080011139 hdd_runtime_suspend_context_deinit(hdd_ctx);
11140
Dustin Brown1dbefe62018-09-11 16:32:03 -070011141 qdf_status = cds_dp_close(hdd_ctx->psoc);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011142 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11143 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
11144 ret = -EINVAL;
11145 QDF_ASSERT(0);
11146 }
11147
Dustin Brown1dbefe62018-09-11 16:32:03 -070011148 qdf_status = cds_close(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053011149 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011150 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053011151 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011152 QDF_ASSERT(0);
11153 }
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053011154
11155 qdf_status = wbuff_module_deinit();
11156 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
11157 hdd_err("WBUFF de-init unsuccessful; status: %d", qdf_status);
11158
Sandeep Puligillab7beb472018-08-13 22:54:20 -070011159 hdd_component_pdev_close(hdd_ctx->pdev);
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053011160
Dustin Brown1dbefe62018-09-11 16:32:03 -070011161 hdd_component_psoc_close(hdd_ctx->psoc);
Dustin Brown07901ec2018-09-07 11:02:41 -070011162 dispatcher_pdev_close(hdd_ctx->pdev);
Liangwei Dong50a64a72018-01-11 01:17:00 -050011163 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
11164 if (ret) {
11165 hdd_err("Failed to destroy pdev; errno:%d", ret);
11166 QDF_ASSERT(0);
11167 }
11168
11169 /*
11170 * Reset total mac phy during module stop such that during
11171 * next module start same psoc is used to populate new service
11172 * ready data
11173 */
Dustin Brown1dbefe62018-09-11 16:32:03 -070011174 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->psoc);
Arunk Khandavallia6305a32018-01-25 11:19:18 +053011175 if (tgt_hdl)
11176 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
11177
Liangwei Dong50a64a72018-01-11 01:17:00 -050011178
Arun Khandavallifae92942016-08-01 13:31:08 +053011179 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
11180 if (!hif_ctx) {
11181 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011182 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011183 }
11184
Arunk Khandavalli4b404332017-09-26 12:46:00 +053011185 if (hdd_ctx->target_hw_name) {
11186 qdf_mem_free(hdd_ctx->target_hw_name);
11187 hdd_ctx->target_hw_name = NULL;
11188 }
11189
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053011190 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053011191
11192 ol_cds_free();
11193
Dustin Brownc2a156e2018-10-25 16:56:27 -070011194 if (IS_IDLE_STOP) {
Arun Khandavallifae92942016-08-01 13:31:08 +053011195 ret = pld_power_off(qdf_ctx->dev);
11196 if (ret)
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011197 hdd_err("Failed to power down device; errno:%d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053011198 }
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011199
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011200 /* Free the cache channels of the command SET_DISABLE_CHANNEL_LIST */
11201 wlan_hdd_free_cache_channels(hdd_ctx);
Arunk Khandavalli847969d2017-09-25 15:15:36 +053011202
Dustin Brown29533f22018-07-24 13:11:56 -070011203 hdd_check_for_leaks(hdd_ctx, is_recovery_stop);
Dustin Brown26b3d042017-12-21 11:13:27 -080011204 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080011205
Arunk Khandavalli847969d2017-09-25 15:15:36 +053011206 /* Once the firmware sequence is completed reset this flag */
11207 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053011208 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080011209 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053011210
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011211done:
11212 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011213 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011214 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4bc0a622017-12-06 15:56:50 -080011215
Dustin Browne74003f2018-03-14 12:51:58 -070011216 hdd_exit();
Arun Khandavallifae92942016-08-01 13:31:08 +053011217
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011218 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053011219}
11220
Arun Khandavallifae92942016-08-01 13:31:08 +053011221
Wen Gong3f003382018-05-14 14:26:37 +080011222#ifdef WLAN_FEATURE_MEMDUMP_ENABLE
Arun Khandavallifae92942016-08-01 13:31:08 +053011223/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011224 * hdd_state_info_dump() - prints state information of hdd layer
11225 * @buf: buffer pointer
11226 * @size: size of buffer to be filled
11227 *
11228 * This function is used to dump state information of hdd layer
11229 *
11230 * Return: None
11231 */
11232static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
11233{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011234 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070011235 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070011236 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011237 uint16_t len = 0;
11238 char *buf = *buf_ptr;
11239
11240 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11241 if (!hdd_ctx) {
11242 hdd_err("Failed to get hdd context ");
11243 return;
11244 }
11245
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011246 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011247
11248 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070011249 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011250 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080011251 "\n is_scheduler_suspended %d",
11252 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011253
Dustin Brown920397d2017-12-13 16:27:50 -080011254 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011255 if (adapter->dev)
11256 len += scnprintf(buf + len, *size - len,
11257 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080011258 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011259 "\n device_mode: %d", adapter->device_mode);
11260 switch (adapter->device_mode) {
11261 case QDF_STA_MODE:
11262 case QDF_P2P_CLIENT_MODE:
11263 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11264 len += scnprintf(buf + len, *size - len,
11265 "\n connState: %d",
11266 hdd_sta_ctx->conn_info.connState);
11267 break;
11268
11269 default:
11270 break;
11271 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011272 }
11273
11274 *size -= len;
11275 *buf_ptr += len;
11276}
11277
11278/**
11279 * hdd_register_debug_callback() - registration function for hdd layer
11280 * to print hdd state information
11281 *
11282 * Return: None
11283 */
11284static void hdd_register_debug_callback(void)
11285{
11286 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
11287}
Wen Gong3f003382018-05-14 14:26:37 +080011288#else /* WLAN_FEATURE_MEMDUMP_ENABLE */
Wen Gongaa6d55d2018-04-26 16:33:21 +080011289static void hdd_register_debug_callback(void)
11290{
11291}
Wen Gong3f003382018-05-14 14:26:37 +080011292#endif /* WLAN_FEATURE_MEMDUMP_ENABLE */
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011293
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053011294/*
11295 * wlan_init_bug_report_lock() - Initialize bug report lock
11296 *
11297 * This function is used to create bug report lock
11298 *
11299 * Return: None
11300 */
11301static void wlan_init_bug_report_lock(void)
11302{
Jeff Johnson2b6982c2018-05-29 14:56:11 -070011303 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053011304
11305 p_cds_context = cds_get_global_context();
11306 if (!p_cds_context) {
11307 hdd_err("cds context is NULL");
11308 return;
11309 }
11310
11311 qdf_spinlock_create(&p_cds_context->bug_report_lock);
11312}
11313
Nirav Shahd21a2e32018-04-20 16:34:43 +053011314#ifdef CONFIG_DP_TRACE
Mohit Khannaf8f96822017-05-17 17:11:59 -070011315void hdd_dp_trace_init(struct hdd_config *config)
11316{
Mohit Khannaf8f96822017-05-17 17:11:59 -070011317 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
11318 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
11319 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
11320 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
11321 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
11322 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
11323 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080011324 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070011325
Nirav Shahd21a2e32018-04-20 16:34:43 +053011326 if (!config->enable_dp_trace) {
11327 hdd_err("dp trace is disabled from ini");
11328 return;
11329 }
11330
Mohit Khannaf8f96822017-05-17 17:11:59 -070011331 hdd_string_to_u8_array(config->dp_trace_config, config_params,
11332 &num_entries, sizeof(config_params));
11333
11334 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080011335 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080011336 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080011337 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080011338 else if (bw_compute_interval > 1000) {
11339 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
11340 thresh_time_limit = 1;
11341 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070011342 hdd_err("busBandwidthComputeInterval is 0, using defaults");
11343
11344 switch (num_entries) {
11345 case 4:
11346 proto_bitmap = config_params[3];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011347 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011348 case 3:
11349 verbosity = config_params[2];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011350 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011351 case 2:
11352 thresh = config_params[1];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011353 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011354 case 1:
11355 live_mode = config_params[0];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011356 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011357 default:
Dustin Browna7bb6ae2018-08-16 16:51:50 -070011358 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
11359 live_mode, thresh, thresh_time_limit,
11360 verbosity, proto_bitmap);
Mohit Khannaf8f96822017-05-17 17:11:59 -070011361 };
11362
11363 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
11364 verbosity, proto_bitmap);
11365
11366}
Nirav Shahd21a2e32018-04-20 16:34:43 +053011367#endif
11368
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011369#ifdef DISABLE_CHANNEL_LIST
Dustin Brown623e7e32018-09-05 14:27:50 -070011370static QDF_STATUS wlan_hdd_cache_chann_mutex_create(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011371{
11372 return qdf_mutex_create(&hdd_ctx->cache_channel_lock);
11373}
11374#else
Dustin Brown623e7e32018-09-05 14:27:50 -070011375static QDF_STATUS wlan_hdd_cache_chann_mutex_create(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011376{
Dustin Brown623e7e32018-09-05 14:27:50 -070011377 return QDF_STATUS_SUCCESS;
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011378}
11379#endif
11380
Dustin Brown61cc3932018-10-18 16:12:13 -070011381static QDF_STATUS
11382hdd_open_adapters_for_mission_mode(struct hdd_context *hdd_ctx)
Dustin Browna2deeb72018-10-18 14:19:27 -070011383{
11384 struct hdd_adapter *adapter;
11385 enum dot11p_mode dot11p_mode;
Dustin Brown61cc3932018-10-18 16:12:13 -070011386 QDF_STATUS status;
Dustin Browna2deeb72018-10-18 14:19:27 -070011387
11388 ucfg_mlme_get_dot11p_mode(hdd_ctx->psoc, &dot11p_mode);
11389
11390 /* Create only 802.11p interface? */
11391 if (dot11p_mode == CFG_11P_STANDALONE)
Dustin Brown61cc3932018-10-18 16:12:13 -070011392 return hdd_open_ocb_interface(hdd_ctx);
Dustin Browna2deeb72018-10-18 14:19:27 -070011393
11394 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
11395 wlan_hdd_get_intf_addr(hdd_ctx),
11396 NET_NAME_UNKNOWN, true);
11397 if (!adapter)
Dustin Brown61cc3932018-10-18 16:12:13 -070011398 return QDF_STATUS_E_INVAL;
Dustin Browna2deeb72018-10-18 14:19:27 -070011399
Dustin Brown61cc3932018-10-18 16:12:13 -070011400 /* opening concurrent STA is best effort, continue on error */
11401 hdd_open_concurrent_interface(hdd_ctx);
Dustin Browna2deeb72018-10-18 14:19:27 -070011402
Dustin Brown61cc3932018-10-18 16:12:13 -070011403 status = hdd_open_p2p_interface(hdd_ctx);
11404 if (status)
Dustin Browna2deeb72018-10-18 14:19:27 -070011405 goto err_close_adapters;
11406
11407 /* Open 802.11p Interface */
11408 if (dot11p_mode == CFG_11P_CONCURRENT) {
Dustin Brown61cc3932018-10-18 16:12:13 -070011409 status = hdd_open_ocb_interface(hdd_ctx);
11410 if (QDF_IS_STATUS_ERROR(status))
Dustin Browna2deeb72018-10-18 14:19:27 -070011411 goto err_close_adapters;
11412 }
11413
Dustin Brown61cc3932018-10-18 16:12:13 -070011414 return QDF_STATUS_SUCCESS;
Dustin Browna2deeb72018-10-18 14:19:27 -070011415
11416err_close_adapters:
11417 hdd_close_all_adapters(hdd_ctx, true);
11418
Dustin Brown61cc3932018-10-18 16:12:13 -070011419 return status;
Dustin Browna2deeb72018-10-18 14:19:27 -070011420}
11421
Dustin Brown61cc3932018-10-18 16:12:13 -070011422static QDF_STATUS hdd_open_adapters_for_ftm_mode(struct hdd_context *hdd_ctx)
Dustin Browna2deeb72018-10-18 14:19:27 -070011423{
11424 struct hdd_adapter *adapter;
Dustin Brown61cc3932018-10-18 16:12:13 -070011425
11426 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
11427 wlan_hdd_get_intf_addr(hdd_ctx),
11428 NET_NAME_UNKNOWN, true);
11429
11430 return adapter ? QDF_STATUS_SUCCESS : QDF_STATUS_E_INVAL;
11431}
11432
11433static QDF_STATUS
11434hdd_open_adapters_for_monitor_mode(struct hdd_context *hdd_ctx)
11435{
11436 struct hdd_adapter *adapter;
11437
11438 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
11439 wlan_hdd_get_intf_addr(hdd_ctx),
11440 NET_NAME_UNKNOWN, true);
11441
11442 return adapter ? QDF_STATUS_SUCCESS : QDF_STATUS_E_INVAL;
11443}
11444
11445static QDF_STATUS hdd_open_adapters_for_epping_mode(struct hdd_context *hdd_ctx)
11446{
Dustin Browna2deeb72018-10-18 14:19:27 -070011447 QDF_STATUS status;
Dustin Brown61cc3932018-10-18 16:12:13 -070011448 qdf_device_t qdf_dev;
Dustin Browna2deeb72018-10-18 14:19:27 -070011449
11450 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11451 QDF_BUG(qdf_dev);
11452 if (!qdf_dev)
Dustin Brown61cc3932018-10-18 16:12:13 -070011453 return QDF_STATUS_E_INVAL;
11454
11455 status = epping_open();
11456 if (QDF_IS_STATUS_ERROR(status))
11457 return status;
11458
11459 if (epping_enable(qdf_dev->dev)) {
11460 status = QDF_STATUS_E_INVAL;
11461 goto epping_close;
11462 }
11463
11464 return QDF_STATUS_SUCCESS;
11465
11466epping_close:
11467 epping_close();
11468
11469 return status;
11470}
11471
11472typedef QDF_STATUS (*hdd_open_mode_handler)(struct hdd_context *hdd_ctx);
11473
11474static const hdd_open_mode_handler
11475hdd_open_mode_handlers[QDF_GLOBAL_MAX_MODE] = {
11476 [QDF_GLOBAL_MISSION_MODE] = hdd_open_adapters_for_mission_mode,
11477 [QDF_GLOBAL_FTM_MODE] = hdd_open_adapters_for_ftm_mode,
11478 [QDF_GLOBAL_MONITOR_MODE] = hdd_open_adapters_for_monitor_mode,
11479 [QDF_GLOBAL_EPPING_MODE] = hdd_open_adapters_for_epping_mode,
11480};
11481
Dustin Brown92bd8382018-10-31 15:49:46 -070011482static QDF_STATUS hdd_open_adapters_for_mode(struct hdd_context *hdd_ctx,
11483 enum QDF_GLOBAL_MODE driver_mode)
Dustin Brown61cc3932018-10-18 16:12:13 -070011484{
11485 QDF_STATUS status;
11486
11487 if (driver_mode < 0 ||
11488 driver_mode >= QDF_GLOBAL_MAX_MODE ||
11489 !hdd_open_mode_handlers[driver_mode]) {
11490 hdd_err("Driver mode %d not supported", driver_mode);
11491 return -ENOTSUPP;
11492 }
Dustin Browna2deeb72018-10-18 14:19:27 -070011493
11494 hdd_hold_rtnl_lock();
Dustin Brown61cc3932018-10-18 16:12:13 -070011495 status = hdd_open_mode_handlers[driver_mode](hdd_ctx);
Dustin Browna2deeb72018-10-18 14:19:27 -070011496 hdd_release_rtnl_lock();
11497
Dustin Brown92bd8382018-10-31 15:49:46 -070011498 return status;
Dustin Browna2deeb72018-10-18 14:19:27 -070011499}
11500
Dustin Brown623e7e32018-09-05 14:27:50 -070011501int hdd_wlan_startup(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011502{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011503 QDF_STATUS status;
Dustin Brown623e7e32018-09-05 14:27:50 -070011504 int errno;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011505
Dustin Brown491d54b2018-03-14 12:39:11 -070011506 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011507
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011508 hdd_action_oui_config(hdd_ctx);
11509
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053011510 qdf_nbuf_init_replenish_timer();
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011511
Dustin Brown623e7e32018-09-05 14:27:50 -070011512 status = wlan_hdd_cache_chann_mutex_create(hdd_ctx);
11513 if (QDF_IS_STATUS_ERROR(status))
11514 return qdf_status_to_os_return(status);
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011515
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053011516#ifdef FEATURE_WLAN_CH_AVOID
11517 mutex_init(&hdd_ctx->avoid_freq_lock);
11518#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053011519
Naveen Rawate02f8f52018-04-05 11:58:04 -070011520 osif_request_manager_init();
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053011521 qdf_atomic_init(&hdd_ctx->con_mode_flag);
Dustin Brown021cecd2017-12-11 13:56:43 -080011522 hdd_driver_memdump_init();
Dustin Brown86d196b2018-08-02 11:51:49 -070011523 hdd_bus_bandwidth_init(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -080011524
Dustin Brown623e7e32018-09-05 14:27:50 -070011525 errno = hdd_wlan_start_modules(hdd_ctx, false);
11526 if (errno) {
11527 hdd_err("Failed to start modules; errno:%d", errno);
11528 goto memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011529 }
11530
Yingying Tang80e15f32016-09-27 18:23:01 +080011531 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011532
Dustin Brown623e7e32018-09-05 14:27:50 -070011533 hdd_ctx->mac_handle = cds_get_context(QDF_MODULE_ID_SME);
11534 if (!hdd_ctx->mac_handle) {
Jeff Johnson16528362018-06-14 12:34:16 -070011535 hdd_err("Mac Handle is null");
Dustin Brown623e7e32018-09-05 14:27:50 -070011536 goto stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011537 }
11538
Dustin Brown623e7e32018-09-05 14:27:50 -070011539 errno = hdd_wiphy_init(hdd_ctx);
11540 if (errno) {
11541 hdd_err("Failed to initialize wiphy; errno:%d", errno);
11542 goto stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011543 }
11544
Nirav Shahd21a2e32018-04-20 16:34:43 +053011545 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053011546
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070011547 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080011548
Dustin Brown623e7e32018-09-05 14:27:50 -070011549 errno = register_netdevice_notifier(&hdd_netdev_notifier);
11550 if (errno) {
11551 hdd_err("register_netdevice_notifier failed; errno:%d", errno);
11552 goto unregister_wiphy;
Paul Zhangfb02f452017-12-22 11:58:43 +080011553 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053011554
Dustin Brown623e7e32018-09-05 14:27:50 -070011555 errno = register_reboot_notifier(&system_reboot_notifier);
11556 if (errno) {
11557 hdd_err("Failed to register reboot notifier; errno:%d", errno);
11558 goto unregister_netdev;
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011559 }
11560
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080011561 wlan_hdd_update_11n_mode(hdd_ctx->config);
11562
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011563#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053011564 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053011565 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011566 hdd_skip_acs_scan_timer_handler,
Dustin Browna2deeb72018-10-18 14:19:27 -070011567 hdd_ctx);
Dustin Brown92bd8382018-10-31 15:49:46 -070011568 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070011569 hdd_err("Failed to init ACS Skip timer");
Dustin Brown92bd8382018-10-31 15:49:46 -070011570
Liangwei Dongaef84342016-10-21 05:28:00 -040011571 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011572#endif
11573
Arunk Khandavalli40943af2017-05-15 19:25:34 +053011574 hdd_lpass_notify_wlan_version(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011575
Dustin Brown623e7e32018-09-05 14:27:50 -070011576 errno = hdd_register_notifiers(hdd_ctx);
11577 if (errno)
11578 goto unregister_reboot;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070011579
Paul Zhangfb02f452017-12-22 11:58:43 +080011580 status = wlansap_global_init();
Dustin Brown92bd8382018-10-31 15:49:46 -070011581 if (QDF_IS_STATUS_ERROR(status))
11582 goto unregister_notifiers;
Paul Zhangfb02f452017-12-22 11:58:43 +080011583
Dustin Brown92bd8382018-10-31 15:49:46 -070011584 hdd_set_idle_ps_config(hdd_ctx, hdd_ctx->config->fIsImpsEnabled);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011585
Dustin Brown92bd8382018-10-31 15:49:46 -070011586 hdd_exit();
11587
11588 return 0;
11589
11590unregister_notifiers:
11591 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011592
Dustin Brown623e7e32018-09-05 14:27:50 -070011593unregister_reboot:
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011594 unregister_reboot_notifier(&system_reboot_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011595
Dustin Brown623e7e32018-09-05 14:27:50 -070011596unregister_netdev:
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011597 unregister_netdevice_notifier(&hdd_netdev_notifier);
11598
Dustin Brown623e7e32018-09-05 14:27:50 -070011599unregister_wiphy:
Rachit Kankane30807332018-06-27 18:39:36 +053011600 qdf_dp_trace_deinit();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011601 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011602
Dustin Brown623e7e32018-09-05 14:27:50 -070011603stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011604 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053011605
Dustin Brown623e7e32018-09-05 14:27:50 -070011606memdump_deinit:
Dustin Brown86d196b2018-08-02 11:51:49 -070011607 hdd_bus_bandwidth_deinit(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -080011608 hdd_driver_memdump_deinit();
Naveen Rawate02f8f52018-04-05 11:58:04 -070011609 osif_request_manager_deinit();
Dustin Brown623e7e32018-09-05 14:27:50 -070011610 qdf_nbuf_deinit_replenish_timer();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070011611
Nachiket Kukade8003d252017-03-30 15:55:58 +053011612 if (cds_is_fw_down())
11613 hdd_err("Not setting the complete event as fw is down");
11614 else
Dustin Brown623e7e32018-09-05 14:27:50 -070011615 hdd_start_complete(errno);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011616
Dustin Browne74003f2018-03-14 12:51:58 -070011617 hdd_exit();
Dustin Brown92bd8382018-10-31 15:49:46 -070011618
Dustin Brown623e7e32018-09-05 14:27:50 -070011619 return errno;
Dustin Brown92bd8382018-10-31 15:49:46 -070011620}
11621
11622QDF_STATUS hdd_psoc_create_vdevs(struct hdd_context *hdd_ctx)
11623{
11624 enum QDF_GLOBAL_MODE driver_mode = hdd_get_conparam();
11625 QDF_STATUS status;
11626
11627 status = hdd_open_adapters_for_mode(hdd_ctx, driver_mode);
11628 if (QDF_IS_STATUS_ERROR(status)) {
11629 hdd_err("Failed to create vdevs; status:%d", status);
11630 return status;
11631 }
11632
11633 if (hdd_ctx->rps)
11634 hdd_set_rps_cpu_mask(hdd_ctx);
11635
11636 if (driver_mode != QDF_GLOBAL_FTM_MODE)
11637 hdd_psoc_idle_timer_start(hdd_ctx);
11638
11639 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011640}
11641
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011642/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011643 * hdd_wlan_update_target_info() - update target type info
11644 * @hdd_ctx: HDD context
11645 * @context: hif context
11646 *
11647 * Update target info received from firmware in hdd context
11648 * Return:None
11649 */
11650
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011651void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053011652{
11653 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
11654
11655 if (!tgt_info) {
11656 hdd_err("Target info is Null");
11657 return;
11658 }
11659
11660 hdd_ctx->target_type = tgt_info->target_type;
11661}
11662
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011663void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp, void *context)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011664{
11665 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011666 int status;
11667 struct hdd_adapter *adapter = NULL;
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011668 struct osif_request *request = NULL;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011669
Dustin Brown491d54b2018-03-14 12:39:11 -070011670 hdd_enter();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011671
11672 if (!rsp) {
11673 hdd_err("data is null");
11674 return;
11675 }
11676
11677 status = wlan_hdd_validate_context(hdd_ctx);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011678 if (status != 0)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011679 return;
11680
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011681 request = osif_request_get(context);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011682 if (!request) {
11683 hdd_err("obselete request");
11684 return;
11685 }
11686
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011687 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
11688 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
11689 hdd_err("Invalid adapter or adapter has invalid magic");
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011690 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011691 return;
11692 }
11693
Alok Kumarce2c29a2018-10-12 15:44:02 +053011694 hdd_debug("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
11695 hdd_debug("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
11696 hdd_debug("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
11697 hdd_debug("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
11698 hdd_debug("rsp->out_of_order_arp_rsp_drop_cnt :%x",
11699 rsp->out_of_order_arp_rsp_drop_cnt);
11700 hdd_debug("rsp->dad_detected :%x", rsp->dad_detected);
11701 hdd_debug("rsp->connect_status :%x", rsp->connect_status);
11702 hdd_debug("rsp->ba_session_establishment_status :%x",
11703 rsp->ba_session_establishment_status);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011704
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011705 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011706 adapter->dad |= rsp->dad_detected;
11707 adapter->con_status = rsp->connect_status;
11708
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053011709 /* Flag true indicates connectivity check stats present. */
11710 if (rsp->connect_stats_present) {
Alok Kumarce2c29a2018-10-12 15:44:02 +053011711 hdd_debug("rsp->tcp_ack_recvd :%x", rsp->tcp_ack_recvd);
11712 hdd_debug("rsp->icmpv4_rsp_recvd :%x", rsp->icmpv4_rsp_recvd);
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053011713 adapter->hdd_stats.hdd_tcp_stats.rx_fw_cnt = rsp->tcp_ack_recvd;
11714 adapter->hdd_stats.hdd_icmpv4_stats.rx_fw_cnt =
11715 rsp->icmpv4_rsp_recvd;
11716 }
11717
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011718 osif_request_complete(request);
11719 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011720
Dustin Browne74003f2018-03-14 12:51:58 -070011721 hdd_exit();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011722}
11723
11724/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011725 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011726 * @hdd_ctx: HDD context
11727 *
11728 * Register the HDD callbacks to CDS/SME.
11729 *
11730 * Return: 0 for success or Error code for failure
11731 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011732int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011733{
11734 QDF_STATUS status;
11735 int ret = 0;
Jeff Johnson16528362018-06-14 12:34:16 -070011736 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011737
Dustin Brown491d54b2018-03-14 12:39:11 -070011738 hdd_enter();
Sourav Mohapatra674925f2018-04-16 11:16:58 +053011739 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
11740 hdd_err("in ftm mode, no need to register callbacks");
11741 return ret;
11742 }
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011743
Jeff Johnson16528362018-06-14 12:34:16 -070011744 mac_handle = hdd_ctx->mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011745
Jeff Johnson16528362018-06-14 12:34:16 -070011746 sme_register_oem_data_rsp_callback(mac_handle,
11747 hdd_send_oem_data_rsp_msg);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011748
Jeff Johnson16528362018-06-14 12:34:16 -070011749 sme_register_mgmt_frame_ind_callback(mac_handle,
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053011750 hdd_indicate_mgmt_frame);
Jeff Johnson16528362018-06-14 12:34:16 -070011751 sme_set_tsfcb(mac_handle, hdd_get_tsf_cb, hdd_ctx);
11752 sme_nan_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011753 wlan_hdd_cfg80211_nan_callback);
Jeff Johnson16528362018-06-14 12:34:16 -070011754 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011755 wlan_hdd_cfg80211_stats_ext_callback);
11756
Jeff Johnson16528362018-06-14 12:34:16 -070011757 sme_ext_scan_register_callback(mac_handle,
11758 wlan_hdd_cfg80211_extscan_callback);
11759 sme_stats_ext2_register_callback(mac_handle,
lifeng66831662017-05-19 16:01:35 +080011760 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011761
Jeff Johnson16528362018-06-14 12:34:16 -070011762 sme_set_rssi_threshold_breached_cb(mac_handle,
11763 hdd_rssi_threshold_breached);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011764
Jeff Johnson16528362018-06-14 12:34:16 -070011765 sme_set_link_layer_stats_ind_cb(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011766 wlan_hdd_cfg80211_link_layer_stats_callback);
11767
Jeff Johnson16528362018-06-14 12:34:16 -070011768 sme_rso_cmd_status_cb(mac_handle, wlan_hdd_rso_cmd_status_cb);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053011769
Jeff Johnson16528362018-06-14 12:34:16 -070011770 sme_set_link_layer_ext_cb(mac_handle,
Zhang Qianca38fb12016-12-23 11:10:48 +080011771 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
11772
Jeff Johnson16528362018-06-14 12:34:16 -070011773 status = sme_set_lost_link_info_cb(mac_handle,
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053011774 hdd_lost_link_info_cb);
11775 /* print error and not block the startup process */
11776 if (!QDF_IS_STATUS_SUCCESS(status))
11777 hdd_err("set lost link info callback failed");
11778
Poddar, Siddarth34872782017-08-10 14:08:51 +053011779 ret = hdd_register_data_stall_detect_cb();
11780 if (ret) {
11781 hdd_err("Register data stall detect detect callback failed.");
11782 return ret;
11783 }
11784
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011785 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
11786
Jeff Johnson16528362018-06-14 12:34:16 -070011787 sme_register_set_connection_info_cb(mac_handle,
11788 hdd_set_connection_in_progress,
11789 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053011790
Jeff Johnson16528362018-06-14 12:34:16 -070011791 status = sme_congestion_register_callback(mac_handle,
11792 hdd_update_cca_info_cb);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053011793 if (!QDF_IS_STATUS_SUCCESS(status))
11794 hdd_err("set congestion callback failed");
11795
Jeff Johnson16528362018-06-14 12:34:16 -070011796 status = sme_set_bt_activity_info_cb(mac_handle,
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053011797 hdd_bt_activity_cb);
11798 if (!QDF_IS_STATUS_SUCCESS(status))
11799 hdd_err("set bt activity info callback failed");
11800
Jeff Johnson16528362018-06-14 12:34:16 -070011801 status = sme_register_tx_queue_cb(mac_handle,
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080011802 hdd_tx_queue_cb);
11803 if (!QDF_IS_STATUS_SUCCESS(status))
11804 hdd_err("Register tx queue callback failed");
11805
Dustin Browne74003f2018-03-14 12:51:58 -070011806 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011807
11808 return ret;
11809}
11810
11811/**
11812 * hdd_deregister_cb() - De-Register HDD callbacks.
11813 * @hdd_ctx: HDD context
11814 *
11815 * De-Register the HDD callbacks to CDS/SME.
11816 *
11817 * Return: void
11818 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011819void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011820{
11821 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053011822 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070011823 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011824
Dustin Brown491d54b2018-03-14 12:39:11 -070011825 hdd_enter();
Sourav Mohapatra674925f2018-04-16 11:16:58 +053011826 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
11827 hdd_err("in ftm mode, no need to deregister callbacks");
11828 return;
11829 }
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011830
Jeff Johnson16528362018-06-14 12:34:16 -070011831 mac_handle = hdd_ctx->mac_handle;
11832 sme_deregister_tx_queue_cb(mac_handle);
11833 status = sme_deregister_for_dcc_stats_event(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011834 if (!QDF_IS_STATUS_SUCCESS(status))
11835 hdd_err("De-register of dcc stats callback failed: %d",
11836 status);
11837
Jeff Johnson16528362018-06-14 12:34:16 -070011838 sme_reset_link_layer_stats_ind_cb(mac_handle);
11839 sme_reset_rssi_threshold_breached_cb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011840
Jeff Johnson16528362018-06-14 12:34:16 -070011841 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011842 wlan_hdd_cfg80211_stats_ext_callback);
11843
Jeff Johnson16528362018-06-14 12:34:16 -070011844 sme_nan_deregister_callback(mac_handle);
11845 status = sme_reset_tsfcb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011846 if (!QDF_IS_STATUS_SUCCESS(status))
11847 hdd_err("Failed to de-register tsfcb the callback:%d",
11848 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011849
Poddar, Siddarth34872782017-08-10 14:08:51 +053011850 ret = hdd_deregister_data_stall_detect_cb();
11851 if (ret)
11852 hdd_err("Failed to de-register data stall detect event callback");
11853
Jeff Johnson16528362018-06-14 12:34:16 -070011854 sme_deregister_oem_data_rsp_callback(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011855
Dustin Browne74003f2018-03-14 12:51:58 -070011856 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011857}
11858
11859/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011860 * hdd_softap_sta_deauth() - handle deauth req from HDD
11861 * @adapter: Pointer to the HDD
11862 * @enable: bool value
11863 *
11864 * This to take counter measure to handle deauth req from HDD
11865 *
11866 * Return: None
11867 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011868QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011869 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011870{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011871 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011872
Dustin Brown491d54b2018-03-14 12:39:11 -070011873 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011874
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011875 /* Ignore request to deauth bcmc station */
11876 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011877 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011878
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011879 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011880 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
11881 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011882
Dustin Browne74003f2018-03-14 12:51:58 -070011883 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011884 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011885}
11886
11887/**
11888 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
11889 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011890 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011891 *
11892 * This to take counter measure to handle deauth req from HDD
11893 *
11894 * Return: None
11895 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011896void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011897 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011898{
Dustin Brown491d54b2018-03-14 12:39:11 -070011899 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011900
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011901 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011902 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011903 return;
11904
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011905 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011906 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011907}
11908
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011909/**
11910 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
11911 * @hdd_ctx: HDD Context
11912 *
11913 * API to find if there is any STA or P2P-Client is connected
11914 *
11915 * Return: true if connected; false otherwise
11916 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011917QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011918{
Jeff Johnson16528362018-06-14 12:34:16 -070011919 return sme_is_sta_p2p_client_connected(hdd_ctx->mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011920}
11921
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011922void wlan_hdd_disable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011923{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011924 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
11925 struct hdd_adapter *adapter = NULL;
11926 struct csr_roam_profile *roam_profile;
11927 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011928
Dustin Brown1dbefe62018-09-11 16:32:03 -070011929 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->psoc)) {
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011930 hdd_debug("No active sta session");
11931 return;
11932 }
11933
11934 hdd_for_each_adapter(hdd_ctx, adapter) {
11935 roam_profile = hdd_roam_profile(adapter);
11936 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11937
11938 if (cur_adapter->session_id != adapter->session_id &&
11939 adapter->device_mode == QDF_STA_MODE &&
11940 hdd_conn_is_connected(sta_ctx)) {
11941 hdd_debug("%d Disable roaming", adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -070011942 sme_stop_roaming(hdd_ctx->mac_handle,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011943 adapter->session_id,
11944 ecsr_driver_disabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011945 }
11946 }
11947}
11948
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011949void wlan_hdd_enable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011950{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011951 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
11952 struct hdd_adapter *adapter = NULL;
11953 struct csr_roam_profile *roam_profile;
11954 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011955
Dustin Brown1dbefe62018-09-11 16:32:03 -070011956 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->psoc)) {
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011957 hdd_debug("No active sta session");
11958 return;
11959 }
11960
11961 hdd_for_each_adapter(hdd_ctx, adapter) {
11962 roam_profile = hdd_roam_profile(adapter);
11963 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11964
11965 if (cur_adapter->session_id != adapter->session_id &&
11966 adapter->device_mode == QDF_STA_MODE &&
11967 hdd_conn_is_connected(sta_ctx)) {
11968 hdd_debug("%d Enable roaming", adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -070011969 sme_start_roaming(hdd_ctx->mac_handle,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011970 adapter->session_id,
11971 REASON_DRIVER_ENABLED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011972 }
11973 }
11974}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011975
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011976/**
11977 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
11978 * @skb: sk buffer pointer
11979 *
11980 * Sends the bcast message to SVC multicast group with generic nl socket
11981 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
11982 *
11983 * Return: None
11984 */
11985static void nl_srv_bcast_svc(struct sk_buff *skb)
11986{
11987#ifdef CNSS_GENL
11988 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
11989#else
11990 nl_srv_bcast(skb);
11991#endif
11992}
11993
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011994void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011995{
11996 struct sk_buff *skb;
11997 struct nlmsghdr *nlh;
11998 tAniMsgHdr *ani_hdr;
11999 void *nl_data = NULL;
12000 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012001 struct radio_index_tlv *radio_info;
12002 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012003
12004 if (in_interrupt() || irqs_disabled() || in_atomic())
12005 flags = GFP_ATOMIC;
12006
12007 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
12008
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012009 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012010 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012011
12012 nlh = (struct nlmsghdr *)skb->data;
12013 nlh->nlmsg_pid = 0; /* from kernel */
12014 nlh->nlmsg_flags = 0;
12015 nlh->nlmsg_seq = 0;
12016 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
12017
12018 ani_hdr = NLMSG_DATA(nlh);
12019 ani_hdr->type = type;
12020
12021 switch (type) {
12022 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053012023 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012024 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012025 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070012026 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012027 ani_hdr->length = 0;
12028 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012029 break;
12030 case WLAN_SVC_WLAN_STATUS_IND:
12031 case WLAN_SVC_WLAN_VERSION_IND:
12032 case WLAN_SVC_DFS_CAC_START_IND:
12033 case WLAN_SVC_DFS_CAC_END_IND:
12034 case WLAN_SVC_DFS_RADAR_DETECT_IND:
12035 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
12036 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080012037 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053012038 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080012039 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012040 ani_hdr->length = len;
12041 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
12042 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
12043 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012044 break;
12045
12046 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070012047 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012048 type);
12049 kfree_skb(skb);
12050 return;
12051 }
12052
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012053 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080012054 * Add radio index at the end of the svc event in TLV format
12055 * to maintain the backward compatibility with userspace
12056 * applications.
12057 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012058
12059 tlv_len = 0;
12060
12061 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
12062 < WLAN_NL_MAX_PAYLOAD) {
12063 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
12064 sizeof(*ani_hdr) + len);
12065 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
12066 radio_info->length = (unsigned short) sizeof(radio_info->radio);
12067 radio_info->radio = radio;
12068 tlv_len = sizeof(*radio_info);
Dustin Browna2868622018-03-20 11:38:14 -070012069 hdd_debug("Added radio index tlv - radio index %d",
12070 radio_info->radio);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012071 }
12072
12073 nlh->nlmsg_len += tlv_len;
12074 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
12075
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053012076 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012077}
12078
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012079#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
12080void wlan_hdd_auto_shutdown_cb(void)
12081{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012082 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012083
12084 if (!hdd_ctx)
12085 return;
12086
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012087 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012088 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
12089 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012090}
12091
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012092void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012093{
Jeff Johnson9d295242017-08-29 14:39:48 -070012094 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012095 bool ap_connected = false, sta_connected = false;
Jeff Johnson16528362018-06-14 12:34:16 -070012096 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012097
Jeff Johnson16528362018-06-14 12:34:16 -070012098 mac_handle = hdd_ctx->mac_handle;
12099 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012100 return;
12101
Dundi Raviteja8e338282018-09-25 17:16:04 +053012102 if (hdd_ctx->config->wlan_auto_shutdown == 0)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012103 return;
12104
12105 if (enable == false) {
Jeff Johnson16528362018-06-14 12:34:16 -070012106 if (sme_set_auto_shutdown_timer(mac_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012107 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012108 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012109 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012110 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070012111 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012112 return;
12113 }
12114
12115 /* To enable shutdown timer check conncurrency */
Dustin Brown1dbefe62018-09-11 16:32:03 -070012116 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->psoc)) {
Dustin Brown920397d2017-12-13 16:27:50 -080012117 hdd_for_each_adapter(hdd_ctx, adapter) {
12118 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012119 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
12120 conn_info.connState ==
12121 eConnectionState_Associated) {
12122 sta_connected = true;
12123 break;
12124 }
12125 }
Dustin Brown920397d2017-12-13 16:27:50 -080012126
12127 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012128 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070012129 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012130 ap_connected = true;
12131 break;
12132 }
12133 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012134 }
12135 }
12136
12137 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012138 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012139 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012140 }
Jeff Johnson68755312017-02-10 11:46:55 -080012141
Jeff Johnson16528362018-06-14 12:34:16 -070012142 if (sme_set_auto_shutdown_timer(mac_handle,
Dundi Raviteja8e338282018-09-25 17:16:04 +053012143 hdd_ctx->config->wlan_auto_shutdown)
Jeff Johnson68755312017-02-10 11:46:55 -080012144 != QDF_STATUS_SUCCESS)
12145 hdd_err("Failed to start wlan auto shutdown timer");
12146 else
Dustin Brown5e89ef82018-03-14 11:50:23 -070012147 hdd_info("Auto Shutdown timer for %d seconds enabled",
Dundi Raviteja8e338282018-09-25 17:16:04 +053012148 hdd_ctx->config->wlan_auto_shutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012149}
12150#endif
12151
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070012152struct hdd_adapter *
12153hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
12154 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012155{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012156 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070012157 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012158
12159 con_sap_adapter = NULL;
12160
Dustin Brown920397d2017-12-13 16:27:50 -080012161 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012162 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
12163 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012164 adapter != this_sap_adapter) {
12165 if (check_start_bss) {
12166 if (test_bit(SOFTAP_BSS_STARTED,
12167 &adapter->event_flags)) {
12168 con_sap_adapter = adapter;
12169 break;
12170 }
12171 } else {
12172 con_sap_adapter = adapter;
12173 break;
12174 }
12175 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012176 }
12177
12178 return con_sap_adapter;
12179}
12180
12181#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070012182static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012183{
Dustin Brown5ec6b552017-03-31 12:11:40 -070012184 return adapter->device_mode == QDF_STA_MODE ||
12185 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012186}
12187
Jeff Johnson9d295242017-08-29 14:39:48 -070012188static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012189{
Dustin Brown5ec6b552017-03-31 12:11:40 -070012190 return adapter->device_mode == QDF_SAP_MODE ||
12191 adapter->device_mode == QDF_P2P_GO_MODE;
12192}
12193
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012194static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012195{
Dustin Brown920397d2017-12-13 16:27:50 -080012196 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070012197
Dustin Brown920397d2017-12-13 16:27:50 -080012198 hdd_for_each_adapter(hdd_ctx, adapter) {
12199 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070012200 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
12201 conn_info.connState == eConnectionState_Associated) {
12202 return true;
12203 }
12204
Dustin Brown920397d2017-12-13 16:27:50 -080012205 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070012206 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070012207 return true;
12208 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070012209 }
12210
12211 return false;
12212}
12213
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012214static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012215{
12216 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012217
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053012218 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012219 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053012220 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012221
Dustin Brown5ec6b552017-03-31 12:11:40 -070012222 return is_running;
12223}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012224
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012225static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012226{
12227 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
12228 hdd_ctx->bus_bw_timer_running = true;
12229 qdf_timer_start(&hdd_ctx->bus_bw_timer,
jitiphil869b9f72018-09-25 17:14:01 +053012230 hdd_ctx->config->bus_bw_compute_interval);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012231 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
12232}
12233
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012234void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012235{
Dustin Brown491d54b2018-03-14 12:39:11 -070012236 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012237
12238 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12239 hdd_debug("Bandwidth compute timer already started");
12240 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012241 }
12242
Dustin Brown5ec6b552017-03-31 12:11:40 -070012243 __hdd_bus_bw_compute_timer_start(hdd_ctx);
12244
Dustin Browne74003f2018-03-14 12:51:58 -070012245 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012246}
12247
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012248void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012249{
Dustin Brown491d54b2018-03-14 12:39:11 -070012250 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012251
12252 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12253 hdd_debug("Bandwidth compute timer already started");
12254 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070012255 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070012256
12257 if (hdd_any_adapter_is_assoc(hdd_ctx))
12258 __hdd_bus_bw_compute_timer_start(hdd_ctx);
12259
Dustin Browne74003f2018-03-14 12:51:58 -070012260 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012261}
12262
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012263static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012264{
Dustin Brown07901ec2018-09-07 11:02:41 -070012265 ucfg_ipa_set_perf_level(hdd_ctx->pdev, 0, 0);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012266
12267 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012268 hdd_ctx->bus_bw_timer_running = false;
Dustin Brown35008ba2018-08-23 14:34:21 -070012269 qdf_timer_sync_cancel(&hdd_ctx->bus_bw_timer);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012270 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
12271
Dustin Brown35008ba2018-08-23 14:34:21 -070012272 /* work callback is long running; flush outside of lock */
12273 cancel_work_sync(&hdd_ctx->bus_bw_work);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012274 hdd_reset_tcp_delack(hdd_ctx);
12275}
12276
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012277void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012278{
Dustin Brown491d54b2018-03-14 12:39:11 -070012279 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012280
12281 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12282 hdd_debug("Bandwidth compute timer already stopped");
12283 return;
12284 }
12285
12286 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
12287
Dustin Browne74003f2018-03-14 12:51:58 -070012288 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012289}
12290
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012291void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012292{
Dustin Brown491d54b2018-03-14 12:39:11 -070012293 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012294
12295 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12296 hdd_debug("Bandwidth compute timer already stopped");
12297 return;
12298 }
12299
12300 if (!hdd_any_adapter_is_assoc(hdd_ctx))
12301 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
12302
Dustin Browne74003f2018-03-14 12:51:58 -070012303 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012304}
12305#endif
12306
12307/**
12308 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
12309 * and sta's operating channel.
12310 * @sta_adapter: Describe the first argument to foobar.
12311 * @ap_adapter: Describe the second argument to foobar.
12312 * @roam_profile: Roam profile of AP to which STA wants to connect.
12313 * @concurrent_chnl_same: If both SAP and STA channels are same then
12314 * set this flag to true else false.
12315 *
12316 * This function checks the sap's operating channel and sta's operating channel.
12317 * if both are same then it will return false else it will restart the sap in
12318 * sta's channel and return true.
12319 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012320 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012321 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070012322QDF_STATUS
12323wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
12324 struct hdd_adapter *ap_adapter,
Jeff Johnson61b5e982018-03-15 11:33:31 -070012325 struct csr_roam_profile *roam_profile,
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070012326 tScanResultHandle *scan_cache,
12327 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012328{
Jeff Johnson87251032017-08-29 13:31:11 -070012329 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012330 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012331 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012332 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012333 *concurrent_chnl_same = true;
12334
12335 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12336 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070012337 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012338 scan_cache,
12339 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012340 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012341 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012342 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070012343 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012344 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012345 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012346 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012347 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012348 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070012349 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012350 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012351 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012352 }
12353 }
12354 } else {
12355 /*
12356 * Lets handle worst case scenario here, Scan cache lookup is
12357 * failed so we have to stop the SAP to avoid any channel
12358 * discrepancy between SAP's channel and STA's channel.
12359 * Return the status as failure so caller function could know
12360 * that scan look up is failed.
12361 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070012362 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012363 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012364 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012365 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012366}
12367
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012368/**
12369 * wlan_hdd_stop_sap() - This function stops bss of SAP.
12370 * @ap_adapter: SAP adapter
12371 *
12372 * This function will process the stopping of sap adapter.
12373 *
12374 * Return: None
12375 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012376void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012377{
Jeff Johnson87251032017-08-29 13:31:11 -070012378 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012379 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053012380 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012381 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012382
12383 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012384 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012385 return;
12386 }
12387
12388 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12389 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012390 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012391 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012392
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012393 mutex_lock(&hdd_ctx->sap_lock);
12394 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080012395 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012396 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012397 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053012398 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012399 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012400 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053012401 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080012402 qdf_stop_bss_event,
Vignesh Viswanathan865daaa2018-10-11 19:30:44 +053012403 SME_CMD_START_STOP_BSS_TIMEOUT);
Anurag Chouhance0dc992016-02-16 18:18:03 +053012404 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012405 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070012406 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012407 return;
12408 }
12409 }
12410 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -070012411 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012412 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012413 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012414 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012415 false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012416 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012417 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012418 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012419 }
12420 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012421}
12422
12423/**
12424 * wlan_hdd_start_sap() - this function starts bss of SAP.
12425 * @ap_adapter: SAP adapter
12426 *
12427 * This function will process the starting of sap adapter.
12428 *
12429 * Return: None
12430 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012431void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012432{
Jeff Johnson87251032017-08-29 13:31:11 -070012433 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012434 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053012435 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012436 struct hdd_context *hdd_ctx;
Jeff Johnsone4c11db2018-05-05 23:22:32 -070012437 tsap_config_t *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012438
12439 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012440 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012441 return;
12442 }
12443
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012444 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070012445 hdd_err("SoftAp role has not been enabled");
12446 return;
12447 }
12448
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012449 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
12450 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12451 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070012452 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012453
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012454 mutex_lock(&hdd_ctx->sap_lock);
12455 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
12456 goto end;
12457
12458 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012459 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012460 goto end;
12461 }
Dustin Brown07901ec2018-09-07 11:02:41 -070012462 wlan_reg_set_channel_params(hdd_ctx->pdev,
Abhinav Kumar6f694482018-09-04 16:07:39 +053012463 hdd_ap_ctx->sap_config.channel, 0,
12464 &hdd_ap_ctx->sap_config.ch_params);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012465
Wei Song2f76f642016-11-18 16:32:53 +080012466 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012467 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070012468 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012469 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012470 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012471 goto end;
12472
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012473 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053012474 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Vignesh Viswanathan865daaa2018-10-11 19:30:44 +053012475 SME_CMD_START_STOP_BSS_TIMEOUT);
Anurag Chouhance0dc992016-02-16 18:18:03 +053012476 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012477 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012478 goto end;
12479 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070012480 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012481 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012482 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012483 if (hostapd_state->bss_state == BSS_START) {
Dustin Brown1dbefe62018-09-11 16:32:03 -070012484 policy_mgr_incr_active_session(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012485 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012486 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012487 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012488 true);
12489 }
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053012490 mutex_unlock(&hdd_ctx->sap_lock);
12491
12492 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012493end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012494 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012495 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070012496 /* SAP context and beacon cleanup will happen during driver unload
12497 * in hdd_stop_adapter
12498 */
12499 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
12500
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012501}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012502
12503/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012504 * hdd_get_fw_version() - Get FW version
12505 * @hdd_ctx: pointer to HDD context.
12506 * @major_spid: FW version - major spid.
12507 * @minor_spid: FW version - minor spid
12508 * @ssid: FW version - ssid
12509 * @crmid: FW version - crmid
12510 *
12511 * This function is called to get the firmware build version stored
12512 * as part of the HDD context
12513 *
12514 * Return: None
12515 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012516void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012517 uint32_t *major_spid, uint32_t *minor_spid,
12518 uint32_t *siid, uint32_t *crmid)
12519{
12520 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
12521 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
12522 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
12523 *crmid = hdd_ctx->target_fw_version & 0x7fff;
12524}
12525
12526#ifdef QCA_CONFIG_SMP
12527/**
12528 * wlan_hdd_get_cpu() - get cpu_index
12529 *
12530 * Return: cpu_index
12531 */
12532int wlan_hdd_get_cpu(void)
12533{
12534 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012535
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012536 put_cpu();
12537 return cpu_index;
12538}
12539#endif
12540
12541/**
12542 * hdd_get_fwpath() - get framework path
12543 *
12544 * This function is used to get the string written by
12545 * userspace to start the wlan driver
12546 *
12547 * Return: string
12548 */
12549const char *hdd_get_fwpath(void)
12550{
12551 return fwpath.string;
12552}
12553
Dustin Brown94ce20f2018-09-04 13:11:38 -070012554static inline int hdd_state_query_cb(void)
12555{
12556 return !!wlan_hdd_validate_context(cds_get_context(QDF_MODULE_ID_HDD));
12557}
12558
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012559/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012560 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012561 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012562 * This function initilizes CDS global context with the help of cds_init. This
12563 * has to be the first function called after probe to get a valid global
12564 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012565 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012566 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012567 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012568int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012569{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012570 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012571 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012572
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012573 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080012574 if (QDF_IS_STATUS_ERROR(status)) {
12575 hdd_err("Failed to allocate CDS context");
12576 ret = -ENOMEM;
12577 goto err_out;
12578 }
Dustin Brown94ce20f2018-09-04 13:11:38 -070012579 qdf_register_module_state_query_callback(hdd_state_query_cb);
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053012580
12581 wlan_init_bug_report_lock();
12582
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012583#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12584 wlan_logging_sock_init_svc();
12585#endif
12586
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012587 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
12588 (void *)hdd_drv_ops_inactivity_handler, NULL,
12589 QDF_TIMER_TYPE_SW);
12590
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012591 hdd_trace_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053012592 hdd_register_debug_callback();
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012593 wlan_roam_debug_init();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012594
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012595err_out:
12596 return ret;
12597}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012598
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012599/**
12600 * hdd_deinit() - Deinitialize Driver
12601 *
12602 * This function frees CDS global context with the help of cds_deinit. This
12603 * has to be the last function call in remove callback to free the global
12604 * context.
12605 */
12606void hdd_deinit(void)
12607{
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012608 wlan_roam_debug_deinit();
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012609 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012610
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012611#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12612 wlan_logging_sock_deinit_svc();
12613#endif
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012614
12615 wlan_destroy_bug_report_lock();
12616 cds_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012617}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012618
Yue Ma6e7b1a02017-04-03 14:17:46 -070012619#ifdef QCA_WIFI_NAPIER_EMULATION
12620#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
12621#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012622#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070012623#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012624
Sachin Ahujadddd2632017-03-07 19:07:24 +053012625static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
12626 struct file *file)
12627{
12628 return 0;
12629}
12630
12631static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
12632 const char __user *user_buf,
12633 size_t count,
12634 loff_t *f_pos)
12635{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012636 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053012637 static const char wlan_off_str[] = "OFF";
12638 static const char wlan_on_str[] = "ON";
12639 int ret;
12640 unsigned long rc;
12641
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012642 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012643 pr_err("Failed to read buffer\n");
12644 return -EINVAL;
12645 }
12646
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012647 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012648 pr_debug("Wifi turning off from UI\n");
12649 goto exit;
12650 }
12651
Srinivas Girigowdad2412882018-09-07 15:42:04 -070012652 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) == 0)
Sachin Ahuja16904db2017-12-13 19:56:57 +053012653 pr_info("Wifi Turning On from UI\n");
Sachin Ahuja16904db2017-12-13 19:56:57 +053012654
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012655 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012656 pr_err("Invalid value received from framework");
12657 goto exit;
12658 }
12659
12660 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053012661 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053012662 rc = wait_for_completion_timeout(&wlan_start_comp,
12663 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
12664 if (!rc) {
Srinivas Girigowda09625b02018-09-10 15:28:09 -070012665 hdd_alert("Timed-out!!");
Sachin Ahujadddd2632017-03-07 19:07:24 +053012666 ret = -EINVAL;
Sachin Ahujadddd2632017-03-07 19:07:24 +053012667 return ret;
12668 }
12669
12670 hdd_start_complete(0);
12671 }
12672
12673exit:
12674 return count;
12675}
12676
12677
12678const struct file_operations wlan_hdd_state_fops = {
12679 .owner = THIS_MODULE,
12680 .open = wlan_hdd_state_ctrl_param_open,
12681 .write = wlan_hdd_state_ctrl_param_write,
12682};
12683
12684static int wlan_hdd_state_ctrl_param_create(void)
12685{
12686 unsigned int wlan_hdd_state_major = 0;
12687 int ret;
12688 struct device *dev;
12689
12690 device = MKDEV(wlan_hdd_state_major, 0);
12691
12692 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
12693 if (ret) {
12694 pr_err("Failed to register qcwlanstate");
12695 goto dev_alloc_err;
12696 }
12697 wlan_hdd_state_major = MAJOR(device);
12698
12699 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
12700 if (IS_ERR(class)) {
12701 pr_err("wlan_hdd_state class_create error");
12702 goto class_err;
12703 }
12704
12705 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
12706 if (IS_ERR(dev)) {
12707 pr_err("wlan_hdd_statedevice_create error");
12708 goto err_class_destroy;
12709 }
12710
12711 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
12712 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
12713 if (ret) {
12714 pr_err("Failed to add cdev error");
12715 goto cdev_add_err;
12716 }
12717
12718 pr_info("wlan_hdd_state %s major(%d) initialized",
12719 WLAN_MODULE_NAME, wlan_hdd_state_major);
12720
12721 return 0;
12722
12723cdev_add_err:
12724 device_destroy(class, device);
12725err_class_destroy:
12726 class_destroy(class);
12727class_err:
12728 unregister_chrdev_region(device, dev_num);
12729dev_alloc_err:
12730 return -ENODEV;
12731}
12732
12733static void wlan_hdd_state_ctrl_param_destroy(void)
12734{
12735 cdev_del(&wlan_hdd_state_cdev);
12736 device_destroy(class, device);
12737 class_destroy(class);
12738 unregister_chrdev_region(device, dev_num);
12739
12740 pr_info("Device node unregistered");
12741}
12742
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012743/**
Dustin Brownd585cb32018-09-12 17:12:23 -070012744 * hdd_component_init() - Initialize all components
Mukul Sharmad75a6672017-06-22 15:40:53 +053012745 *
Dustin Brownd585cb32018-09-12 17:12:23 -070012746 * Return: QDF_STATUS
Mukul Sharmad75a6672017-06-22 15:40:53 +053012747 */
Dustin Brownd585cb32018-09-12 17:12:23 -070012748static QDF_STATUS hdd_component_init(void)
Mukul Sharmad75a6672017-06-22 15:40:53 +053012749{
Dustin Brownd585cb32018-09-12 17:12:23 -070012750 QDF_STATUS status;
12751
12752 /* initialize converged components */
12753 status = dispatcher_init();
12754 if (QDF_IS_STATUS_ERROR(status))
12755 return status;
12756
12757 /* initialize non-converged components */
12758 status = ucfg_mlme_init();
12759 if (QDF_IS_STATUS_ERROR(status))
12760 goto dispatcher_deinit;
12761
12762 status = ucfg_fwol_init();
12763 if (QDF_IS_STATUS_ERROR(status))
12764 goto mlme_deinit;
12765
12766 status = disa_init();
12767 if (QDF_IS_STATUS_ERROR(status))
12768 goto fwol_deinit;
12769
12770 status = pmo_init();
12771 if (QDF_IS_STATUS_ERROR(status))
12772 goto disa_deinit;
12773
12774 status = ucfg_ocb_init();
12775 if (QDF_IS_STATUS_ERROR(status))
12776 goto pmo_deinit;
12777
12778 status = ipa_init();
12779 if (QDF_IS_STATUS_ERROR(status))
12780 goto ocb_deinit;
12781
12782 status = ucfg_action_oui_init();
12783 if (QDF_IS_STATUS_ERROR(status))
12784 goto ipa_deinit;
12785
12786 return QDF_STATUS_SUCCESS;
12787
12788ipa_deinit:
12789 ipa_deinit();
12790ocb_deinit:
12791 ucfg_ocb_deinit();
12792pmo_deinit:
12793 pmo_deinit();
12794disa_deinit:
12795 disa_deinit();
12796fwol_deinit:
12797 ucfg_fwol_deinit();
12798mlme_deinit:
12799 ucfg_mlme_deinit();
12800dispatcher_deinit:
12801 dispatcher_deinit();
12802
12803 return status;
Mukul Sharmad75a6672017-06-22 15:40:53 +053012804}
12805
12806/**
Dustin Brownd585cb32018-09-12 17:12:23 -070012807 * hdd_component_deinit() - Deinitialize all components
Mukul Sharmad75a6672017-06-22 15:40:53 +053012808 *
12809 * Return: None
12810 */
Dustin Brownd585cb32018-09-12 17:12:23 -070012811static void hdd_component_deinit(void)
Mukul Sharmad75a6672017-06-22 15:40:53 +053012812{
Dustin Brownd585cb32018-09-12 17:12:23 -070012813 /* deinitialize non-converged components */
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053012814 ucfg_action_oui_deinit();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053012815 ipa_deinit();
Zhang Qian47e22ce2018-01-04 15:38:38 +080012816 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053012817 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012818 disa_deinit();
Sourav Mohapatra113685f2018-08-29 14:21:55 +053012819 ucfg_fwol_deinit();
Vignesh Viswanathana0921c42018-09-04 19:03:35 +053012820 ucfg_mlme_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070012821
12822 /* deinitialize converged components */
12823 dispatcher_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012824}
12825
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053012826QDF_STATUS hdd_component_psoc_open(struct wlan_objmgr_psoc *psoc)
12827{
Sourav Mohapatra113685f2018-08-29 14:21:55 +053012828 QDF_STATUS status;
12829
12830 status = ucfg_mlme_psoc_open(psoc);
12831 if (QDF_IS_STATUS_ERROR(status))
12832 return status;
12833
12834 status = ucfg_fwol_psoc_open(psoc);
12835 if (QDF_IS_STATUS_ERROR(status))
Wu Gao66454f12018-09-26 19:55:41 +080012836 goto err_fwol;
12837
12838 status = ucfg_pmo_psoc_open(psoc);
12839 if (QDF_IS_STATUS_ERROR(status))
12840 goto err_pmo;
Sourav Mohapatra113685f2018-08-29 14:21:55 +053012841
Krunal Sonie9c12f52018-10-04 11:45:42 -070012842 status = ucfg_policy_mgr_psoc_open(psoc);
12843 if (QDF_IS_STATUS_ERROR(status))
12844 goto err_plcy_mgr;
12845
Sourav Mohapatra113685f2018-08-29 14:21:55 +053012846 return status;
12847
Krunal Sonie9c12f52018-10-04 11:45:42 -070012848err_plcy_mgr:
12849 ucfg_pmo_psoc_close(psoc);
Wu Gao66454f12018-09-26 19:55:41 +080012850err_pmo:
12851 ucfg_fwol_psoc_close(psoc);
12852err_fwol:
Sourav Mohapatra113685f2018-08-29 14:21:55 +053012853 ucfg_mlme_psoc_close(psoc);
Krunal Sonie9c12f52018-10-04 11:45:42 -070012854
Sourav Mohapatra113685f2018-08-29 14:21:55 +053012855 return status;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053012856}
12857
12858void hdd_component_psoc_close(struct wlan_objmgr_psoc *psoc)
12859{
Krunal Sonie9c12f52018-10-04 11:45:42 -070012860 ucfg_policy_mgr_psoc_close(psoc);
Wu Gao66454f12018-09-26 19:55:41 +080012861 ucfg_pmo_psoc_close(psoc);
Sourav Mohapatra113685f2018-08-29 14:21:55 +053012862 ucfg_fwol_psoc_close(psoc);
Vignesh Viswanathana0921c42018-09-04 19:03:35 +053012863 ucfg_mlme_psoc_close(psoc);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053012864}
12865
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012866void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
12867{
Zhang Qian47e22ce2018-01-04 15:38:38 +080012868 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012869 disa_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012870}
12871
12872void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
12873{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012874 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080012875 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053012876}
12877
Sandeep Puligillab7beb472018-08-13 22:54:20 -070012878QDF_STATUS hdd_component_pdev_open(struct wlan_objmgr_pdev *pdev)
12879{
12880 return ucfg_mlme_pdev_open(pdev);
12881}
12882
12883void hdd_component_pdev_close(struct wlan_objmgr_pdev *pdev)
12884{
12885 ucfg_mlme_pdev_close(pdev);
12886}
12887
Dustin Brown21a1d462018-07-31 15:13:06 -070012888static struct hdd_driver __hdd_driver;
12889
12890static QDF_STATUS hdd_driver_ctx_init(struct hdd_driver *hdd_driver)
12891{
12892 QDF_BUG(hdd_driver);
12893 if (!hdd_driver)
12894 return QDF_STATUS_E_INVAL;
12895
12896 hdd_driver->state = driver_state_uninit;
12897
12898 return dsc_driver_create(&hdd_driver->dsc_driver);
12899}
12900
12901static void hdd_driver_ctx_deinit(struct hdd_driver *hdd_driver)
12902{
12903 QDF_BUG(hdd_driver);
12904 if (!hdd_driver)
12905 return;
12906
12907 dsc_driver_destroy(&hdd_driver->dsc_driver);
12908 qdf_mem_zero(hdd_driver, sizeof(*hdd_driver));
12909}
12910
12911struct hdd_driver *hdd_driver_get(void)
12912{
12913 return &__hdd_driver;
12914}
12915
Dustin Browna2a39dc2018-09-17 15:29:59 -070012916static QDF_STATUS hdd_qdf_print_init(void)
12917{
12918 QDF_STATUS status;
12919 int qdf_print_idx;
12920
12921 status = qdf_print_setup();
12922 if (QDF_IS_STATUS_ERROR(status)) {
12923 pr_err("Failed qdf_print_setup; status:%u\n", status);
12924 return status;
12925 }
12926
12927 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
12928 if (qdf_print_idx < 0) {
12929 pr_err("Failed to register for qdf_print_ctrl\n");
12930 return QDF_STATUS_E_FAILURE;
12931 }
12932
12933 qdf_set_pidx(qdf_print_idx);
12934
12935 return QDF_STATUS_SUCCESS;
12936}
12937
12938static void hdd_qdf_print_deinit(void)
12939{
12940 int qdf_pidx = qdf_get_pidx();
12941
12942 qdf_set_pidx(-1);
12943 qdf_print_ctrl_cleanup(qdf_pidx);
12944
12945 /* currently, no qdf print 'un-setup'*/
12946}
12947
12948static QDF_STATUS hdd_qdf_init(void)
12949{
12950 QDF_STATUS status;
12951
12952 status = hdd_qdf_print_init();
12953 if (QDF_IS_STATUS_ERROR(status))
12954 goto exit;
12955
12956 status = qdf_debugfs_init();
12957 if (QDF_IS_STATUS_ERROR(status)) {
12958 hdd_err("Failed to init debugfs; status:%u", status);
12959 goto print_deinit;
12960 }
12961
12962 qdf_lock_stats_init();
12963 qdf_mem_init();
12964 qdf_mc_timer_manager_init();
12965 qdf_event_list_init();
12966
12967 status = qdf_cpuhp_init();
12968 if (QDF_IS_STATUS_ERROR(status)) {
12969 hdd_err("Failed to init cpuhp; status:%u", status);
12970 goto event_deinit;
12971 }
12972
12973 status = qdf_trace_spin_lock_init();
12974 if (QDF_IS_STATUS_ERROR(status)) {
12975 hdd_err("Failed to init spinlock; status:%u", status);
12976 goto cpuhp_deinit;
12977 }
12978
12979 qdf_trace_init();
12980 qdf_register_debugcb_init();
12981
12982 return QDF_STATUS_SUCCESS;
12983
12984cpuhp_deinit:
12985 qdf_cpuhp_deinit();
12986event_deinit:
12987 qdf_event_list_destroy();
12988 qdf_mc_timer_manager_exit();
12989 qdf_mem_exit();
12990 qdf_lock_stats_deinit();
12991 qdf_debugfs_exit();
12992print_deinit:
12993 hdd_qdf_print_deinit();
12994
12995exit:
12996 return status;
12997}
12998
12999static void hdd_qdf_deinit(void)
13000{
13001 /* currently, no debugcb deinit */
13002
13003 qdf_trace_deinit();
13004
13005 /* currently, no trace spinlock deinit */
13006
13007 qdf_cpuhp_deinit();
13008 qdf_event_list_destroy();
13009 qdf_mc_timer_manager_exit();
13010 qdf_mem_exit();
13011 qdf_lock_stats_deinit();
13012 qdf_debugfs_exit();
13013 hdd_qdf_print_deinit();
13014}
Dustin Brownf0f70562018-09-14 10:29:38 -070013015
13016/**
13017 * hdd_driver_load() - Perform the driver-level load operation
13018 *
13019 * Note: this is used in both static and DLKM driver builds
13020 *
13021 * Return: Errno
13022 */
13023static int hdd_driver_load(void)
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013024{
Dustin Brown21a1d462018-07-31 15:13:06 -070013025 struct hdd_driver *hdd_driver = hdd_driver_get();
Dustin Brownd585cb32018-09-12 17:12:23 -070013026 QDF_STATUS status;
Dustin Brownf0f70562018-09-14 10:29:38 -070013027 int errno;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013028
Rajeev Kumare555e2d2018-09-17 11:52:37 -070013029 pr_err("%s: Loading driver v%s\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070013030 WLAN_MODULE_NAME,
Rajeev Kumare555e2d2018-09-17 11:52:37 -070013031 g_wlan_driver_version);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013032
Dustin Browna2a39dc2018-09-17 15:29:59 -070013033 status = hdd_qdf_init();
13034 if (QDF_IS_STATUS_ERROR(status)) {
13035 errno = qdf_status_to_os_return(status);
13036 goto exit;
13037 }
13038
Dustin Brown21a1d462018-07-31 15:13:06 -070013039 status = hdd_driver_ctx_init(hdd_driver);
13040 if (QDF_IS_STATUS_ERROR(status)) {
13041 hdd_err("Failed to init driver context; status:%u", status);
13042 errno = qdf_status_to_os_return(status);
13043 goto qdf_deinit;
13044 }
13045
13046 status = dsc_driver_trans_start(hdd_driver->dsc_driver, "load");
13047 QDF_BUG(QDF_IS_STATUS_SUCCESS(status));
13048 if (QDF_IS_STATUS_ERROR(status)) {
13049 errno = qdf_status_to_os_return(status);
13050 goto hdd_driver_deinit;
13051 }
13052
Dustin Brownf0f70562018-09-14 10:29:38 -070013053 errno = hdd_init();
13054 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013055 hdd_err("Failed to init HDD; errno:%d", errno);
Dustin Brown21a1d462018-07-31 15:13:06 -070013056 goto trans_stop;
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013057 }
13058
Dustin Brownd585cb32018-09-12 17:12:23 -070013059 status = hdd_component_init();
13060 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013061 hdd_err("Failed to init components; status:%u", status);
Dustin Brownf0f70562018-09-14 10:29:38 -070013062 errno = qdf_status_to_os_return(status);
Dustin Brownd585cb32018-09-12 17:12:23 -070013063 goto hdd_deinit;
13064 }
Mukul Sharmad75a6672017-06-22 15:40:53 +053013065
Dustin Brownf0f70562018-09-14 10:29:38 -070013066 status = qdf_wake_lock_create(&wlan_wake_lock, "wlan");
13067 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013068 hdd_err("Failed to create wake lock; status:%u", status);
Dustin Brownf0f70562018-09-14 10:29:38 -070013069 errno = qdf_status_to_os_return(status);
13070 goto comp_deinit;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013071 }
13072
Dustin Brownf0f70562018-09-14 10:29:38 -070013073 hdd_set_conparam(con_mode);
13074
Dustin Brownf0f70562018-09-14 10:29:38 -070013075 errno = wlan_hdd_state_ctrl_param_create();
13076 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013077 hdd_err("Failed to create ctrl param; errno:%d", errno);
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013078 goto wakelock_destroy;
13079 }
13080
Dustin Brown25843ad2018-09-17 14:54:33 -070013081 errno = pld_init();
13082 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013083 hdd_err("Failed to init PLD; errno:%d", errno);
Dustin Brown25843ad2018-09-17 14:54:33 -070013084 goto param_destroy;
13085 }
13086
Dustin Brown21a1d462018-07-31 15:13:06 -070013087 hdd_driver->state = driver_state_loaded;
13088 dsc_driver_trans_stop(hdd_driver->dsc_driver);
13089
13090 /* psoc probe can happen in registration; do after 'load' transition */
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013091 errno = wlan_hdd_register_driver();
13092 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013093 hdd_err("Failed to register driver; errno:%d", errno);
Dustin Brown25843ad2018-09-17 14:54:33 -070013094 goto pld_deinit;
Sachin Ahuja16904db2017-12-13 19:56:57 +053013095 }
13096
Dustin Browna2a39dc2018-09-17 15:29:59 -070013097 hdd_debug("%s: driver loaded", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013098
13099 return 0;
Dustin Brownd585cb32018-09-12 17:12:23 -070013100
Dustin Brown25843ad2018-09-17 14:54:33 -070013101pld_deinit:
Dustin Brown21a1d462018-07-31 15:13:06 -070013102 status = dsc_driver_trans_start(hdd_driver->dsc_driver, "unload");
13103 QDF_BUG(QDF_IS_STATUS_SUCCESS(status));
13104
Dustin Brown25843ad2018-09-17 14:54:33 -070013105 pld_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013106
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013107param_destroy:
13108 wlan_hdd_state_ctrl_param_destroy();
Dustin Brownf0f70562018-09-14 10:29:38 -070013109wakelock_destroy:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053013110 qdf_wake_lock_destroy(&wlan_wake_lock);
Dustin Brownf0f70562018-09-14 10:29:38 -070013111comp_deinit:
Dustin Brownd585cb32018-09-12 17:12:23 -070013112 hdd_component_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013113hdd_deinit:
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013114 hdd_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013115trans_stop:
13116 hdd_driver->state = driver_state_deinit;
13117 dsc_driver_trans_stop(hdd_driver->dsc_driver);
13118hdd_driver_deinit:
13119 hdd_driver_ctx_deinit(hdd_driver);
Dustin Browna2a39dc2018-09-17 15:29:59 -070013120qdf_deinit:
13121 hdd_qdf_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013122
Dustin Brown25843ad2018-09-17 14:54:33 -070013123exit:
Dustin Brownf0f70562018-09-14 10:29:38 -070013124 return errno;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013125}
13126
13127/**
Dustin Brownf0f70562018-09-14 10:29:38 -070013128 * hdd_driver_unload() - Performs the driver-level unload operation
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013129 *
Dustin Brownf0f70562018-09-14 10:29:38 -070013130 * Note: this is used in both static and DLKM driver builds
13131 *
13132 * Return: None
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013133 */
Dustin Brownf0f70562018-09-14 10:29:38 -070013134static void hdd_driver_unload(void)
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013135{
Dustin Brown21a1d462018-07-31 15:13:06 -070013136 struct hdd_driver *hdd_driver = hdd_driver_get();
Will Huang36049722018-04-13 11:48:51 +080013137 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Dustin Brown21a1d462018-07-31 15:13:06 -070013138 QDF_STATUS status;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053013139
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013140 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
13141 QWLAN_VERSIONSTR);
13142
Dustin Brown21a1d462018-07-31 15:13:06 -070013143 status = dsc_driver_trans_start_wait(hdd_driver->dsc_driver, "unload");
13144 QDF_BUG(QDF_IS_STATUS_SUCCESS(status));
13145 if (QDF_IS_STATUS_ERROR(status)) {
13146 hdd_err("Unable to unload wlan; status:%u", status);
Arunk Khandavalli830c9692018-03-22 12:17:40 +053013147 return;
Dustin Brown21a1d462018-07-31 15:13:06 -070013148 }
13149
13150 dsc_driver_wait_for_ops(hdd_driver->dsc_driver);
13151
13152 if (!hdd_wait_for_recovery_completion()) {
13153 dsc_driver_trans_stop(hdd_driver->dsc_driver);
13154 return;
13155 }
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053013156
Will Huangba035ec2018-07-05 11:13:30 +080013157 cds_set_driver_loaded(false);
13158 cds_set_unload_in_progress(true);
13159
13160 if (!cds_wait_for_external_threads_completion(__func__))
13161 hdd_warn("External threads are still active attempting "
13162 "driver unload anyway");
13163
Rajeev Kumar3505ae52018-05-10 18:44:45 -070013164 if (hdd_ctx)
Dustin Brown4c663222018-10-23 14:19:36 -070013165 hdd_psoc_idle_timer_stop(hdd_ctx);
Will Huang36049722018-04-13 11:48:51 +080013166
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013167 wlan_hdd_unregister_driver();
Dustin Brown25843ad2018-09-17 14:54:33 -070013168 pld_deinit();
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013169 wlan_hdd_state_ctrl_param_destroy();
Dustin Brownf0f70562018-09-14 10:29:38 -070013170 hdd_set_conparam(0);
Anurag Chouhana37b5b72016-02-21 14:53:42 +053013171 qdf_wake_lock_destroy(&wlan_wake_lock);
Dustin Brownd585cb32018-09-12 17:12:23 -070013172 hdd_component_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013173 hdd_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013174
13175 hdd_driver->state = driver_state_deinit;
13176 dsc_driver_trans_stop(hdd_driver->dsc_driver);
Dustin Brown623e7e32018-09-05 14:27:50 -070013177
Dustin Brown21a1d462018-07-31 15:13:06 -070013178 hdd_driver_ctx_deinit(hdd_driver);
13179
Dustin Browna2a39dc2018-09-17 15:29:59 -070013180 hdd_qdf_deinit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013181}
13182
Arun Khandavallifae92942016-08-01 13:31:08 +053013183#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013184/**
Arun Khandavallifae92942016-08-01 13:31:08 +053013185 * wlan_boot_cb() - Wlan boot callback
13186 * @kobj: object whose directory we're creating the link in.
13187 * @attr: attribute the user is interacting with
13188 * @buff: the buffer containing the user data
13189 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013190 *
Arun Khandavallifae92942016-08-01 13:31:08 +053013191 * This callback is invoked when the fs is ready to start the
13192 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013193 *
Arun Khandavallifae92942016-08-01 13:31:08 +053013194 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013195 */
Arun Khandavallifae92942016-08-01 13:31:08 +053013196static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013197 struct kobj_attribute *attr,
13198 const char *buf,
13199 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013200{
Arun Khandavallifae92942016-08-01 13:31:08 +053013201
Arun Khandavallifae92942016-08-01 13:31:08 +053013202 if (wlan_loader->loaded_state) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013203 hdd_err("wlan driver already initialized");
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013204 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053013205 }
13206
Dustin Brownf0f70562018-09-14 10:29:38 -070013207 if (hdd_driver_load())
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013208 return -EIO;
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013209
13210 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053013211
13212 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013213}
Arun Khandavallifae92942016-08-01 13:31:08 +053013214
13215/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013216 * hdd_sysfs_cleanup() - cleanup sysfs
13217 *
13218 * Return: None
13219 *
13220 */
13221static void hdd_sysfs_cleanup(void)
13222{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013223 /* remove from group */
13224 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
13225 sysfs_remove_group(wlan_loader->boot_wlan_obj,
13226 wlan_loader->attr_group);
13227
13228 /* unlink the object from parent */
13229 kobject_del(wlan_loader->boot_wlan_obj);
13230
13231 /* free the object */
13232 kobject_put(wlan_loader->boot_wlan_obj);
13233
13234 kfree(wlan_loader->attr_group);
13235 kfree(wlan_loader);
13236
13237 wlan_loader = NULL;
13238}
13239
13240/**
Arun Khandavallifae92942016-08-01 13:31:08 +053013241 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
13242 * ready
13243 *
13244 * This is creates the syfs entry boot_wlan. Which shall be invoked
13245 * when the filesystem is ready.
13246 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013247 * QDF API cannot be used here since this function is called even before
13248 * initializing WLAN driver.
13249 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070013250 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053013251 */
13252static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013253{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013254 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053013255
13256 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013257 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013258 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053013259
13260 wlan_loader->boot_wlan_obj = NULL;
13261 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
13262 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013263 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053013264 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053013265
13266 wlan_loader->loaded_state = 0;
13267 wlan_loader->attr_group->attrs = attrs;
13268
Qun Zhang4a83a462018-09-11 16:28:51 +080013269 wlan_loader->boot_wlan_obj = kobject_create_and_add(WLAN_LOADER_NAME,
Arun Khandavallifae92942016-08-01 13:31:08 +053013270 kernel_kobj);
13271 if (!wlan_loader->boot_wlan_obj) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013272 hdd_err("sysfs create and add failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053013273 goto error_return;
13274 }
13275
13276 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
13277 wlan_loader->attr_group);
13278 if (ret) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013279 hdd_err("sysfs create group failed; errno:%d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053013280 goto error_return;
13281 }
13282
13283 return 0;
13284
13285error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013286 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053013287
13288 return ret;
13289}
13290
13291/**
13292 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
13293 *
13294 * Return: 0 on success or errno on failure
13295 */
13296static int wlan_deinit_sysfs(void)
13297{
Arun Khandavallifae92942016-08-01 13:31:08 +053013298 if (!wlan_loader) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013299 hdd_err("wlan_loader is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053013300 return -EINVAL;
13301 }
13302
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013303 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013304 return 0;
13305}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013306
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013307#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053013308
13309#ifdef MODULE
13310/**
Dustin Brownf0f70562018-09-14 10:29:38 -070013311 * hdd_module_init() - Module init helper
Arun Khandavallifae92942016-08-01 13:31:08 +053013312 *
13313 * Module init helper function used by both module and static driver.
13314 *
13315 * Return: 0 for success, errno on failure
13316 */
13317static int hdd_module_init(void)
13318{
Dustin Brownf0f70562018-09-14 10:29:38 -070013319 if (hdd_driver_load())
Dustin Brownab482ac2017-06-09 17:00:44 -070013320 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053013321
Dustin Brownab482ac2017-06-09 17:00:44 -070013322 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053013323}
13324#else
13325static int __init hdd_module_init(void)
13326{
13327 int ret = -EINVAL;
13328
13329 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070013330 if (ret)
Dustin Browna2a39dc2018-09-17 15:29:59 -070013331 hdd_err("Failed to create sysfs entry");
Arun Khandavallifae92942016-08-01 13:31:08 +053013332
13333 return ret;
13334}
13335#endif
13336
13337
13338#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013339/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013340 * hdd_module_exit() - Exit function
13341 *
13342 * This is the driver exit point (invoked when module is unloaded using rmmod)
13343 *
13344 * Return: None
13345 */
13346static void __exit hdd_module_exit(void)
13347{
Dustin Brownf0f70562018-09-14 10:29:38 -070013348 hdd_driver_unload();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013349}
Arun Khandavallifae92942016-08-01 13:31:08 +053013350#else
13351static void __exit hdd_module_exit(void)
13352{
Dustin Brownf0f70562018-09-14 10:29:38 -070013353 hdd_driver_unload();
Arun Khandavallifae92942016-08-01 13:31:08 +053013354 wlan_deinit_sysfs();
13355}
13356#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013357
Srinivas Girigowda841da292018-02-21 16:33:00 -080013358static int fwpath_changed_handler(const char *kmessage,
13359 const struct kernel_param *kp)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013360{
13361 return param_set_copystring(kmessage, kp);
13362}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013363
Nirav Shah73713f72018-05-17 14:50:41 +053013364#ifdef FEATURE_MONITOR_MODE_SUPPORT
13365static bool is_monitor_mode_supported(void)
13366{
13367 return true;
13368}
13369#else
13370static bool is_monitor_mode_supported(void)
13371{
13372 pr_err("Monitor mode not supported!");
13373 return false;
13374}
13375#endif
13376
13377#ifdef WLAN_FEATURE_EPPING
13378static bool is_epping_mode_supported(void)
13379{
13380 return true;
13381}
13382#else
13383static bool is_epping_mode_supported(void)
13384{
13385 pr_err("Epping mode not supported!");
13386 return false;
13387}
13388#endif
13389
Ryan Hsu6e9db0b2018-06-01 10:45:51 -070013390#ifdef QCA_WIFI_FTM
13391static bool is_ftm_mode_supported(void)
13392{
13393 return true;
13394}
13395#else
13396static bool is_ftm_mode_supported(void)
13397{
13398 pr_err("FTM mode not supported!");
13399 return false;
13400}
13401#endif
13402
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013403/**
13404 * is_con_mode_valid() check con mode is valid or not
13405 * @mode: global con mode
13406 *
13407 * Return: TRUE on success FALSE on failure
13408 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080013409static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013410{
13411 switch (mode) {
13412 case QDF_GLOBAL_MONITOR_MODE:
Nirav Shah73713f72018-05-17 14:50:41 +053013413 return is_monitor_mode_supported();
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013414 case QDF_GLOBAL_EPPING_MODE:
Nirav Shah73713f72018-05-17 14:50:41 +053013415 return is_epping_mode_supported();
13416 case QDF_GLOBAL_FTM_MODE:
Ryan Hsu6e9db0b2018-06-01 10:45:51 -070013417 return is_ftm_mode_supported();
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013418 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013419 return true;
13420 default:
13421 return false;
13422 }
13423}
13424
Dustin Brown27cd9942017-09-27 16:11:44 -070013425static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080013426 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070013427{
13428 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
13429 return;
13430
13431 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070013432 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053013433 hdd_info("Release wakelock for monitor mode!");
13434 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
13435 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
Dundi Raviteja0a2a65b2018-04-30 12:34:11 +053013436 /* fallthrough */
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053013437 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070013438 case QDF_GLOBAL_FTM_MODE:
13439 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brown07901ec2018-09-07 11:02:41 -070013440 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, NULL);
Dustin Browndb2a8be2017-12-20 11:49:56 -080013441 hdd_stop_all_adapters(hdd_ctx);
Ashish Kumar Dhanotiya6ff329e2018-10-05 20:38:10 +053013442 hdd_deinit_all_adapters(hdd_ctx, false);
Dustin Brown27cd9942017-09-27 16:11:44 -070013443
Dustin Brown27cd9942017-09-27 16:11:44 -070013444 break;
13445 default:
13446 break;
13447 }
13448}
13449
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013450static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080013451 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013452{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053013453 int driver_status;
13454
13455 driver_status = hdd_ctx->driver_status;
13456
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013457 switch (curr_mode) {
13458 case QDF_GLOBAL_MISSION_MODE:
13459 case QDF_GLOBAL_MONITOR_MODE:
13460 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013461 hdd_close_all_adapters(hdd_ctx, false);
13462 break;
13463 case QDF_GLOBAL_EPPING_MODE:
13464 epping_disable();
13465 epping_close();
13466 break;
13467 default:
13468 return;
13469 }
13470}
13471
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013472static int
13473hdd_parse_driver_mode(const char *mode_str, enum QDF_GLOBAL_MODE *out_mode)
13474{
13475 int mode;
13476 int errno;
13477
Dustin Brown62743f42018-10-24 14:53:18 -070013478 *out_mode = QDF_GLOBAL_MAX_MODE;
13479
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013480 errno = kstrtoint(mode_str, 0, &mode);
13481 if (!errno)
13482 *out_mode = (enum QDF_GLOBAL_MODE)mode;
13483
13484 return errno;
13485}
13486
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013487/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013488 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013489 * @kmessage: con mode name on which driver to be bring up
13490 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013491 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013492 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013493 * This function is invoked when user updates con mode using sys entry,
13494 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013495 *
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013496 * Return: Errno
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013497 */
Srinivas Girigowda841da292018-02-21 16:33:00 -080013498static int __con_mode_handler(const char *kmessage,
13499 const struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013500 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013501{
Jeff Johnson876c1a62017-12-12 10:43:07 -080013502 enum QDF_GLOBAL_MODE curr_mode;
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013503 enum QDF_GLOBAL_MODE next_mode;
13504 int errno;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013505
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013506 hdd_info("Driver mode changing to %s", kmessage);
Dustin Brownab6029b2017-05-24 13:04:19 -070013507
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013508 errno = wlan_hdd_validate_context(hdd_ctx);
13509 if (errno)
13510 return errno;
13511
13512 errno = hdd_parse_driver_mode(kmessage, &next_mode);
13513 if (errno) {
13514 hdd_err_rl("Failed to parse driver mode '%s'", kmessage);
13515 return errno;
13516 }
13517
13518 if (!is_con_mode_valid(next_mode)) {
13519 hdd_err_rl("Requested driver mode is invalid");
13520 return -EINVAL;
13521 }
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013522
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013523 qdf_atomic_set(&hdd_ctx->con_mode_flag, 1);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013524 mutex_lock(&hdd_init_deinit_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +053013525
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013526 curr_mode = hdd_get_conparam();
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013527 if (curr_mode == next_mode) {
13528 hdd_err_rl("Driver is already in the requested mode");
13529 errno = 0;
13530 goto unlock;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013531 }
13532
Dustin Brown27cd9942017-09-27 16:11:44 -070013533 /* ensure adapters are stopped */
13534 hdd_stop_present_mode(hdd_ctx, curr_mode);
13535
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013536 errno = hdd_wlan_stop_modules(hdd_ctx, true);
13537 if (errno) {
Arun Khandavallifae92942016-08-01 13:31:08 +053013538 hdd_err("Stop wlan modules failed");
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013539 goto unlock;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013540 }
13541
Dustin Browndd4e50f2018-05-24 15:43:42 -070013542 /* Cleanup present mode before switching to new mode */
13543 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053013544
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013545 hdd_set_conparam(next_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013546
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013547 errno = hdd_wlan_start_modules(hdd_ctx, false);
13548 if (errno) {
13549 hdd_err("Start wlan modules failed: %d", errno);
13550 goto unlock;
Arun Khandavallifae92942016-08-01 13:31:08 +053013551 }
13552
jitiphil7af5cf22018-10-26 16:06:27 +053013553 errno = hdd_open_adapters_for_mode(hdd_ctx, next_mode);
13554 if (errno) {
13555 hdd_err("Failed to open adapters");
13556 goto unlock;
13557 }
13558
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013559 if (next_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Browne7e71d32018-05-11 16:00:08 -070013560 struct hdd_adapter *adapter =
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013561 hdd_get_adapter(hdd_ctx, QDF_MONITOR_MODE);
Dustin Browne7e71d32018-05-11 16:00:08 -070013562
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013563 QDF_BUG(adapter);
Dustin Browne7e71d32018-05-11 16:00:08 -070013564 if (!adapter) {
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013565 hdd_err("Failed to get monitor adapter");
13566 goto unlock;
Dustin Browne7e71d32018-05-11 16:00:08 -070013567 }
13568
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013569 errno = hdd_start_adapter(adapter);
13570 if (errno) {
13571 hdd_err("Failed to start monitor adapter");
13572 goto unlock;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013573 }
Arun Khandavallifae92942016-08-01 13:31:08 +053013574
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013575 hdd_info("Acquire wakelock for monitor mode");
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053013576 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
13577 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
13578 }
13579
Dustin Brown20024e32018-01-03 12:34:58 -080013580 /* con_mode is a global module parameter */
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013581 con_mode = next_mode;
13582 hdd_info("Driver mode successfully changed to %s", kmessage);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013583
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013584 errno = 0;
13585
13586unlock:
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013587 mutex_unlock(&hdd_init_deinit_lock);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013588 qdf_atomic_set(&hdd_ctx->con_mode_flag, 0);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013589
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013590 return errno;
13591}
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013592
Srinivas Girigowda841da292018-02-21 16:33:00 -080013593static int con_mode_handler(const char *kmessage, const struct kernel_param *kp)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013594{
Dustin Brown67d30412018-09-20 12:10:22 -070013595 struct hdd_driver *hdd_driver = hdd_driver_get();
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013596 struct hdd_context *hdd_ctx;
Dustin Brown67d30412018-09-20 12:10:22 -070013597 QDF_STATUS status;
13598 int errno;
13599
13600 hdd_enter();
13601
Dustin Brown13fa9872018-11-13 10:57:45 -080013602 /* This handler will be invoked before module init when the wlan driver
13603 * is loaded using 'insmod wlan.ko con_mode=5' for example. Return
13604 * success in this case, as module init will bring up the correct
13605 * con_mode when it runs.
13606 */
13607 if (hdd_driver->state == driver_state_uninit)
13608 return 0;
13609
Dustin Brown67d30412018-09-20 12:10:22 -070013610 status = dsc_driver_trans_start_wait(hdd_driver->dsc_driver,
13611 "mode change");
13612 if (QDF_IS_STATUS_ERROR(status)) {
13613 hdd_err("Failed to start 'mode change'; status:%u", status);
13614 errno = qdf_status_to_os_return(status);
13615 goto exit;
13616 }
13617
13618 dsc_driver_wait_for_ops(hdd_driver->dsc_driver);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013619
13620 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Dustin Brown67d30412018-09-20 12:10:22 -070013621 errno = wlan_hdd_validate_context(hdd_ctx);
13622 if (errno)
13623 goto trans_stop;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013624
Ashish Kumar Dhanotiya759b3272018-05-18 17:49:46 +053013625 if (!cds_wait_for_external_threads_completion(__func__)) {
13626 hdd_warn("External threads are still active, can not change mode");
Dustin Brown67d30412018-09-20 12:10:22 -070013627 errno = -EAGAIN;
13628 goto trans_stop;
Ashish Kumar Dhanotiya759b3272018-05-18 17:49:46 +053013629 }
13630
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013631 cds_ssr_protect(__func__);
Dustin Brown67d30412018-09-20 12:10:22 -070013632 errno = __con_mode_handler(kmessage, kp, hdd_ctx);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013633 cds_ssr_unprotect(__func__);
13634
Dustin Brown67d30412018-09-20 12:10:22 -070013635trans_stop:
13636 dsc_driver_trans_stop(hdd_driver->dsc_driver);
13637
13638exit:
13639 hdd_exit();
13640
13641 return errno;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013642}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013643
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013644static int con_mode_handler_ftm(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080013645 const struct kernel_param *kp)
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013646{
13647 int ret;
13648
13649 ret = param_set_int(kmessage, kp);
13650
13651 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
13652 pr_err("Only FTM mode supported!");
13653 return -ENOTSUPP;
13654 }
13655
13656 hdd_set_conparam(con_mode_ftm);
13657 con_mode = con_mode_ftm;
13658
13659 return ret;
13660}
13661
Nirav Shah73713f72018-05-17 14:50:41 +053013662#ifdef FEATURE_MONITOR_MODE_SUPPORT
Ravi Joshia307f632017-07-17 23:41:41 -070013663static int con_mode_handler_monitor(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080013664 const struct kernel_param *kp)
Ravi Joshia307f632017-07-17 23:41:41 -070013665{
13666 int ret;
13667
13668 ret = param_set_int(kmessage, kp);
13669
13670 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
13671 pr_err("Only Monitor mode supported!");
13672 return -ENOTSUPP;
13673 }
13674
13675 hdd_set_conparam(con_mode_monitor);
13676 con_mode = con_mode_monitor;
13677
13678 return ret;
13679}
Nirav Shah73713f72018-05-17 14:50:41 +053013680#endif
Ravi Joshia307f632017-07-17 23:41:41 -070013681
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013682/**
13683 * hdd_get_conparam() - driver exit point
13684 *
13685 * This is the driver exit point (invoked when module is unloaded using rmmod)
13686 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080013687 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013688 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080013689enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013690{
Jeff Johnson876c1a62017-12-12 10:43:07 -080013691 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013692}
13693
Dustin Brownf0f70562018-09-14 10:29:38 -070013694void hdd_set_conparam(int32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013695{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080013696 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013697}
13698
Komal Seelamc11bb222016-01-27 18:57:10 +053013699/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013700 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
13701 * @hdd_ctx: HDD context
13702 *
13703 * Cleans up the pre cac interface, if it exists
13704 *
13705 * Return: None
13706 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013707void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013708{
13709 uint8_t session_id;
13710 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070013711 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013712
Jeff Johnson16528362018-06-14 12:34:16 -070013713 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->mac_handle, &session_id);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013714 if (QDF_IS_STATUS_ERROR(status)) {
13715 hdd_err("failed to get pre cac vdev id");
13716 return;
13717 }
13718
13719 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
13720 if (!precac_adapter) {
Jeff Johnsondd2f1fc2018-05-06 11:22:52 -070013721 hdd_err("invalid pre cac adapter");
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013722 return;
13723 }
13724
13725 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
13726 wlan_hdd_sap_pre_cac_failure,
13727 (void *)precac_adapter);
13728 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
13729
13730}
13731
13732/**
Komal Seelamec702b02016-02-24 18:42:16 +053013733 * hdd_update_ol_config - API to update ol configuration parameters
13734 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053013735 *
Komal Seelamc11bb222016-01-27 18:57:10 +053013736 * Return: void
13737 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013738static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053013739{
Komal Seelamec702b02016-02-24 18:42:16 +053013740 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053013741 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053013742 bool self_recovery = false;
13743 QDF_STATUS status;
Komal Seelamc11bb222016-01-27 18:57:10 +053013744
Komal Seelamec702b02016-02-24 18:42:16 +053013745 if (!ol_ctx)
13746 return;
13747
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053013748 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
13749 if (QDF_IS_STATUS_ERROR(status))
13750 hdd_err("Failed to get self recovery ini config");
13751
13752 cfg.enable_self_recovery = self_recovery;
Komal Seelamec702b02016-02-24 18:42:16 +053013753 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
13754 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
13755 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070013756 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053013757
13758 ol_init_ini_config(ol_ctx, &cfg);
13759}
13760
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013761#ifdef FEATURE_RUNTIME_PM
13762/**
13763 * hdd_populate_runtime_cfg() - populate runtime configuration
13764 * @hdd_ctx: hdd context
13765 * @cfg: pointer to the configuration memory being populated
13766 *
13767 * Return: void
13768 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013769static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013770 struct hif_config_info *cfg)
13771{
13772 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
Wu Gao66454f12018-09-26 19:55:41 +080013773 cfg->runtime_pm_delay =
13774 ucfg_pmo_get_runtime_pm_delay(hdd_ctx->psoc);
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013775}
13776#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013777static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013778 struct hif_config_info *cfg)
13779{
13780}
13781#endif
13782
Komal Seelamec702b02016-02-24 18:42:16 +053013783/**
13784 * hdd_update_hif_config - API to update HIF configuration parameters
13785 * @hdd_ctx: HDD Context
13786 *
13787 * Return: void
13788 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013789static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053013790{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053013791 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053013792 struct hif_config_info cfg;
Vignesh Viswanathana851d752018-10-03 19:44:38 +053013793 bool prevent_link_down = false;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053013794 bool self_recovery = false;
Vignesh Viswanathana851d752018-10-03 19:44:38 +053013795 QDF_STATUS status;
Komal Seelamec702b02016-02-24 18:42:16 +053013796
13797 if (!scn)
13798 return;
13799
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053013800 status = ucfg_mlme_get_prevent_link_down(hdd_ctx->psoc,
13801 &prevent_link_down);
Vignesh Viswanathana851d752018-10-03 19:44:38 +053013802 if (QDF_IS_STATUS_ERROR(status))
13803 hdd_err("Failed to get prevent_link_down config");
13804
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053013805 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
13806 if (QDF_IS_STATUS_ERROR(status))
13807 hdd_err("Failed to get self recovery ini config");
13808
13809 cfg.enable_self_recovery = self_recovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013810 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053013811 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070013812
Vignesh Viswanathana851d752018-10-03 19:44:38 +053013813 if (prevent_link_down)
Dustin Brownee3e0592017-09-07 13:50:11 -070013814 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053013815}
13816
13817/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013818 * hdd_update_dp_config() - Propagate config parameters to Lithium
13819 * datapath
13820 * @hdd_ctx: HDD Context
13821 *
13822 * Return: 0 for success/errno for failure
13823 */
13824static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
13825{
13826 struct cdp_config_params params;
13827 QDF_STATUS status;
jitiphil377bcc12018-10-05 19:46:08 +053013828 void *soc;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013829
jitiphil377bcc12018-10-05 19:46:08 +053013830 soc = cds_get_context(QDF_MODULE_ID_SOC);
13831 params.tso_enable = cfg_get(hdd_ctx->psoc, CFG_DP_TSO);
13832 params.lro_enable = cfg_get(hdd_ctx->psoc, CFG_DP_LRO);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013833#ifdef QCA_LL_TX_FLOW_CONTROL_V2
13834 params.tx_flow_stop_queue_threshold =
13835 hdd_ctx->config->TxFlowStopQueueThreshold;
13836 params.tx_flow_start_queue_offset =
13837 hdd_ctx->config->TxFlowStartQueueOffset;
13838#endif
jitiphil377bcc12018-10-05 19:46:08 +053013839 params.flow_steering_enable =
13840 cfg_get(hdd_ctx->psoc, CFG_DP_FLOW_STEERING_ENABLED);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013841 params.napi_enable = hdd_ctx->napi_enable;
13842 params.tcp_udp_checksumoffload =
jitiphil377bcc12018-10-05 19:46:08 +053013843 cfg_get(hdd_ctx->psoc,
13844 CFG_DP_TCP_UDP_CKSUM_OFFLOAD);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013845
jitiphil377bcc12018-10-05 19:46:08 +053013846 status = cdp_update_config_parameters(soc, &params);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013847 if (status) {
Dustin Browna2868622018-03-20 11:38:14 -070013848 hdd_err("Failed to attach config parameters");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013849 return status;
13850 }
13851
13852 return 0;
13853}
13854
13855/**
Komal Seelamec702b02016-02-24 18:42:16 +053013856 * hdd_update_config() - Initialize driver per module ini parameters
13857 * @hdd_ctx: HDD Context
13858 *
13859 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013860 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053013861 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013862int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053013863{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013864 int ret;
13865
Wu Gao66454f12018-09-26 19:55:41 +080013866 if (ucfg_pmo_is_ns_offloaded(hdd_ctx->psoc))
13867 hdd_ctx->ns_offload_enable = true;
13868
Komal Seelamec702b02016-02-24 18:42:16 +053013869 hdd_update_ol_config(hdd_ctx);
13870 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013871 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
13872 ret = hdd_update_cds_config_ftm(hdd_ctx);
13873 else
13874 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080013875 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013876
13877 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053013878}
13879
Mukul Sharma9d797a02017-01-05 20:26:03 +053013880#ifdef FEATURE_WLAN_RA_FILTERING
13881/**
13882 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
13883 * @psoc_cfg: pmo psoc Configuration
13884 * @hdd_ctx: Pointer to hdd context
13885 *
13886 * Return: none
13887 */
13888static inline void hdd_ra_populate_pmo_config(
13889 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013890 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013891{
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053013892 bool is_rate_limit_enabled;
13893 QDF_STATUS status;
13894
13895 status = ucfg_fwol_get_is_rate_limit_enabled(hdd_ctx->psoc,
13896 &is_rate_limit_enabled);
13897 if (QDF_IS_STATUS_ERROR(status))
13898 return;
13899
Mukul Sharma9d797a02017-01-05 20:26:03 +053013900 psoc_cfg->ra_ratelimit_interval =
13901 hdd_ctx->config->RArateLimitInterval;
13902 psoc_cfg->ra_ratelimit_enable =
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053013903 is_rate_limit_enabled;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013904}
13905#else
13906static inline void hdd_ra_populate_pmo_config(
13907 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013908 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013909{
13910}
13911#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080013912
Mukul Sharma9d797a02017-01-05 20:26:03 +053013913/**
13914 * hdd_update_pmo_config - API to update pmo configuration parameters
13915 * @hdd_ctx: HDD context
13916 *
13917 * Return: void
13918 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013919static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013920{
Mukul Sharma9d797a02017-01-05 20:26:03 +053013921 struct pmo_psoc_cfg psoc_cfg;
13922 QDF_STATUS status;
Wu Gao66454f12018-09-26 19:55:41 +080013923 enum pmo_wow_enable_type wow_enable;
13924
13925 ucfg_pmo_get_psoc_config(hdd_ctx->psoc, &psoc_cfg);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013926
13927 /*
13928 * Value of hdd_ctx->wowEnable can be,
13929 * 0 - Disable both magic pattern match and pattern byte match.
13930 * 1 - Enable magic pattern match on all interfaces.
13931 * 2 - Enable pattern byte match on all interfaces.
13932 * 3 - Enable both magic patter and pattern byte match on
13933 * all interfaces.
13934 */
Wu Gao66454f12018-09-26 19:55:41 +080013935 wow_enable = ucfg_pmo_get_wow_enable(hdd_ctx->psoc);
13936 psoc_cfg.magic_ptrn_enable = (wow_enable & 0x01) ? true : false;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013937 psoc_cfg.ptrn_match_enable_all_vdev =
Wu Gao66454f12018-09-26 19:55:41 +080013938 (wow_enable & 0x02) ? true : false;
Dustin Brownb9987af2018-03-01 17:15:11 -080013939 psoc_cfg.packet_filter_enabled = !hdd_ctx->config->disablePacketFilter;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013940 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080013941 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9223f232017-03-08 18:42:27 +053013942 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013943
13944 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053013945 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013946
Dustin Brown1dbefe62018-09-11 16:32:03 -070013947 status = ucfg_pmo_update_psoc_config(hdd_ctx->psoc, &psoc_cfg);
Dustin Brownb9987af2018-03-01 17:15:11 -080013948 if (QDF_IS_STATUS_ERROR(status))
13949 hdd_err("failed pmo psoc configuration; status:%d", status);
13950
13951 return qdf_status_to_os_return(status);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013952}
13953
Abhishek Singhb20db962017-03-03 21:28:46 +053013954#ifdef FEATURE_WLAN_SCAN_PNO
13955static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
13956 struct hdd_config *cfg)
13957{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070013958 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
13959
Abhishek Singhb20db962017-03-03 21:28:46 +053013960 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
13961 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
13962 pno_cfg->stationary_thresh = cfg->stationary_thresh;
13963 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
13964 pno_cfg->channel_prediction_full_scan =
13965 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070013966 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
13967 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
13968 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
13969 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053013970}
13971#else
13972static inline void
13973hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070013974 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053013975{
Abhishek Singhb20db962017-03-03 21:28:46 +053013976}
13977#endif
13978
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013979void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
Dundi Raviteja85a240a2018-09-10 15:03:07 +053013980 struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013981{
Dundi Raviteja85a240a2018-09-10 15:03:07 +053013982 struct wlan_fwol_ie_whitelist whitelist = {0};
13983 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Dundi Raviteja85a240a2018-09-10 15:03:07 +053013984 QDF_STATUS status;
13985 bool is_ie_whitelist_enable = false;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013986 uint8_t i = 0;
13987
Dundi Raviteja85a240a2018-09-10 15:03:07 +053013988 status = ucfg_fwol_get_ie_whitelist(psoc, &is_ie_whitelist_enable);
13989 if (QDF_IS_STATUS_ERROR(status)) {
13990 hdd_err("Unable to get IE whitelist param");
13991 return;
13992 }
13993
13994 ie_whitelist->white_list = is_ie_whitelist_enable;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013995 if (!ie_whitelist->white_list)
13996 return;
13997
Dundi Raviteja85a240a2018-09-10 15:03:07 +053013998 status = ucfg_fwol_get_all_whitelist_params(psoc, &whitelist);
13999 if (QDF_IS_STATUS_ERROR(status)) {
14000 hdd_err("Unable to get all whitelist params");
14001 return;
14002 }
14003
14004 ie_whitelist->ie_bitmap[0] = whitelist.ie_bitmap_0;
14005 ie_whitelist->ie_bitmap[1] = whitelist.ie_bitmap_1;
14006 ie_whitelist->ie_bitmap[2] = whitelist.ie_bitmap_2;
14007 ie_whitelist->ie_bitmap[3] = whitelist.ie_bitmap_3;
14008 ie_whitelist->ie_bitmap[4] = whitelist.ie_bitmap_4;
14009 ie_whitelist->ie_bitmap[5] = whitelist.ie_bitmap_5;
14010 ie_whitelist->ie_bitmap[6] = whitelist.ie_bitmap_6;
14011 ie_whitelist->ie_bitmap[7] = whitelist.ie_bitmap_7;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014012
Dundi Raviteja9ab4e7b2018-09-28 14:18:28 +053014013 ie_whitelist->num_vendor_oui = whitelist.no_of_probe_req_ouis;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014014 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
Dundi Raviteja9ab4e7b2018-09-28 14:18:28 +053014015 ie_whitelist->voui[i] = whitelist.probe_req_voui[i];
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014016}
14017
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014018uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
14019{
14020 uint8_t i, score;
14021
14022 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
14023 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
14024 if (score > MAX_INDEX_SCORE)
14025 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
14026 MAX_INDEX_SCORE, i);
14027 }
14028
14029 return per_index_score;
14030}
14031
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014032QDF_STATUS hdd_update_score_config(
14033 struct scoring_config *score_config, struct hdd_context *hdd_ctx)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014034{
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014035 struct hdd_config *cfg = hdd_ctx->config;
gaurank kathpaliaae52c982018-10-04 01:35:18 +053014036 QDF_STATUS status;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014037 bool bval = false;
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014038
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014039 sme_update_score_config(hdd_ctx->mac_handle, score_config);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014040
14041 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
14042 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
gaurank kathpaliaae52c982018-10-04 01:35:18 +053014043
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014044 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
gaurank kathpaliaae52c982018-10-04 01:35:18 +053014045 if (!QDF_IS_STATUS_SUCCESS(status))
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014046 hdd_err("unable to get vht_enable2x2");
gaurank kathpaliaae52c982018-10-04 01:35:18 +053014047 score_config->vdev_nss_24g =
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014048 bval ? CFG_STA_NSS(cfg->vdev_type_nss_2g) : 1;
gaurank kathpaliaae52c982018-10-04 01:35:18 +053014049 score_config->vdev_nss_5g =
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014050 bval ? CFG_STA_NSS(cfg->vdev_type_nss_5g) : 1;
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014051
14052 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
14053 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
14054 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
14055 score_config->he_cap = 1;
14056
14057 if (score_config->he_cap ||
14058 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
14059 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
14060 score_config->vht_cap = 1;
14061
14062 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
14063 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
14064 score_config->ht_cap = 1;
14065
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014066 status = ucfg_mlme_get_vht_for_24ghz(hdd_ctx->psoc, &bval);
14067 if (!QDF_IS_STATUS_SUCCESS(status))
14068 hdd_err("Failed to get vht_for_24ghz");
14069 if (score_config->vht_cap && bval)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014070 score_config->vht_24G_cap = 1;
14071
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014072 status = ucfg_mlme_get_vht_enable_tx_bf(hdd_ctx->psoc,
14073 &bval);
14074 if (!QDF_IS_STATUS_SUCCESS(status))
14075 hdd_err("unable to get vht_enable_tx_bf");
14076
14077 if (bval)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014078 score_config->beamformee_cap = 1;
14079
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014080 return QDF_STATUS_SUCCESS;
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014081}
14082
Abhishek Singh257a9482017-03-06 16:52:39 +053014083/**
bings81fe50a2017-11-27 14:33:26 +080014084 * hdd_update_dfs_config() - API to update dfs configuration parameters.
14085 * @hdd_ctx: HDD context
14086 *
14087 * Return: 0 if success else err
14088 */
14089static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
14090{
Dustin Brown1dbefe62018-09-11 16:32:03 -070014091 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
bings81fe50a2017-11-27 14:33:26 +080014092 struct hdd_config *cfg = hdd_ctx->config;
14093 struct dfs_user_config dfs_cfg;
14094 QDF_STATUS status;
14095
14096 dfs_cfg.dfs_is_phyerr_filter_offload = !!cfg->fDfsPhyerrFilterOffload;
14097 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
14098 if (QDF_IS_STATUS_ERROR(status)) {
14099 hdd_err("failed dfs psoc configuration");
14100 return -EINVAL;
14101 }
14102
14103 return 0;
14104}
14105
14106/**
Abhishek Singh257a9482017-03-06 16:52:39 +053014107 * hdd_update_scan_config - API to update scan configuration parameters
14108 * @hdd_ctx: HDD context
14109 *
14110 * Return: 0 if success else err
14111 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014112static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053014113{
Dustin Brown1dbefe62018-09-11 16:32:03 -070014114 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Abhishek Singh257a9482017-03-06 16:52:39 +053014115 struct scan_user_cfg scan_cfg;
14116 struct hdd_config *cfg = hdd_ctx->config;
14117 QDF_STATUS status;
Wu Gaoca416ff2018-09-17 11:05:07 +080014118 uint8_t scan_bucket_thre;
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014119 uint8_t select_5ghz_margin;
14120
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014121 status = ucfg_mlme_get_select_5ghz_margin(hdd_ctx->psoc,
14122 &select_5ghz_margin);
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014123 if (QDF_IS_STATUS_ERROR(status)) {
14124 hdd_err("Failed to get select_5ghz_margin");
14125 return -EIO;
14126 }
Abhishek Singh257a9482017-03-06 16:52:39 +053014127
14128 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
14129 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
14130 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
14131 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
14132 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
14133 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
14134 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053014135 /* convert to ms */
14136 scan_cfg.scan_cache_aging_time =
14137 cfg->scanAgingTimeout * 1000;
14138 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014139 scan_cfg.select_5ghz_margin = select_5ghz_margin;
Dustin Brown1dbefe62018-09-11 16:32:03 -070014140 ucfg_mlme_get_first_scan_bucket_threshold(hdd_ctx->psoc,
Wu Gaoca416ff2018-09-17 11:05:07 +080014141 &scan_bucket_thre);
14142 scan_cfg.scan_bucket_threshold = (int32_t)scan_bucket_thre;
Abhishek Singh158fe252017-03-23 11:09:34 +053014143 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053014144 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053014145 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080014146 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
14147 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053014148 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070014149 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singhc87bb042018-01-30 17:10:42 +053014150 scan_cfg.sta_miracast_mcc_rest_time =
14151 cfg->sta_miracast_mcc_rest_time_val;
Abhishek Singhb20db962017-03-03 21:28:46 +053014152 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014153 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, hdd_ctx);
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014154
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014155 status = hdd_update_score_config(&scan_cfg.score_config, hdd_ctx);
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014156 if (QDF_IS_STATUS_ERROR(status)) {
14157 hdd_err("Failed to update scoring config");
14158 return -EINVAL;
14159 }
Abhishek Singhb20db962017-03-03 21:28:46 +053014160
Abhishek Singh257a9482017-03-06 16:52:39 +053014161 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
14162 if (status != QDF_STATUS_SUCCESS) {
14163 hdd_err("failed pmo psoc configuration");
14164 return -EINVAL;
14165 }
Liangwei Dongac3ddde2018-09-10 23:25:12 -040014166 ucfg_scan_set_global_config(
14167 psoc, SCAN_CFG_DROP_BCN_ON_CHANNEL_MISMATCH,
14168 cfg_get(psoc, CFG_DROP_BCN_ON_CHANNEL_MISMATCH));
Abhishek Singh257a9482017-03-06 16:52:39 +053014169
14170 return 0;
14171}
Abhishek Singh257a9482017-03-06 16:52:39 +053014172
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014173int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053014174{
14175 int ret;
14176
14177 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053014178 if (ret)
14179 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014180
Abhishek Singh257a9482017-03-06 16:52:39 +053014181 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080014182 if (ret)
14183 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014184
Frank Liud4b2fa02017-03-29 11:46:48 +080014185 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014186 if (ret)
14187 return ret;
14188
14189 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080014190 if (ret)
14191 return ret;
14192
14193 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014194
14195 return ret;
14196}
14197
Agrawal Ashish65634612016-08-18 13:24:32 +053014198/**
14199 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
14200 * @mode : cfg80211 DFS mode
14201 *
14202 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
14203 */
14204enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
14205{
14206 switch (mode) {
14207 case DFS_MODE_ENABLE:
14208 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014209 case DFS_MODE_DISABLE:
14210 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014211 case DFS_MODE_DEPRIORITIZE:
14212 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014213 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080014214 hdd_debug("ACS dfs mode is NONE");
14215 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014216 }
14217}
14218
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014219/**
14220 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
14221 * @hddctx: pointer to hdd context
14222 * @set_value: enable/disable
14223 *
14224 * When Host sends vendor command enable, FW will send *ONE* CA ind to
14225 * Host(even though it is duplicate). When Host send vendor command
14226 * disable,FW doesn't perform any action. Whenever any change in
14227 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
14228 *
14229 * return - 0 on success, appropriate error values on failure.
14230 */
Jeff Johnson16528362018-06-14 12:34:16 -070014231int hdd_enable_disable_ca_event(struct hdd_context *hdd_ctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014232{
14233 QDF_STATUS status;
14234
Jeff Johnson16528362018-06-14 12:34:16 -070014235 if (0 != wlan_hdd_validate_context(hdd_ctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014236 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014237
Jeff Johnson16528362018-06-14 12:34:16 -070014238 status = sme_enable_disable_chanavoidind_event(hdd_ctx->mac_handle,
14239 set_value);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014240 if (!QDF_IS_STATUS_SUCCESS(status)) {
14241 hdd_err("Failed to send chan avoid command to SME");
14242 return -EINVAL;
14243 }
14244 return 0;
14245}
Agrawal Ashish65634612016-08-18 13:24:32 +053014246
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014247/**
14248 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
14249 * @value: value to set
14250 *
14251 * This function will set the passed value to roaming in progress flag.
14252 *
14253 * Return: None
14254 */
14255void hdd_set_roaming_in_progress(bool value)
14256{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014257 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014258
14259 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14260 if (!hdd_ctx) {
14261 hdd_err("HDD context is NULL");
14262 return;
14263 }
14264
14265 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080014266 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014267}
14268
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014269bool hdd_is_roaming_in_progress(struct hdd_context *hdd_ctx)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014270{
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014271 if (!hdd_ctx) {
14272 hdd_err("HDD context is NULL");
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014273 return false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014274 }
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080014275
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014276 hdd_debug("roaming_in_progress = %d", hdd_ctx->roaming_in_progress);
14277
14278 return hdd_ctx->roaming_in_progress;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014279}
14280
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014281/**
14282 * hdd_is_connection_in_progress() - check if connection is in
14283 * progress
14284 * @session_id: session id
14285 * @reason: scan reject reason
14286 *
14287 * Go through each adapter and check if Connection is in progress
14288 *
14289 * Return: true if connection is in progress else false
14290 */
14291bool hdd_is_connection_in_progress(uint8_t *session_id,
14292 enum scan_reject_states *reason)
14293{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070014294 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070014295 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014296 uint8_t sta_id = 0;
14297 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014298 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -070014299 mac_handle_t mac_handle;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014300
14301 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14302 if (!hdd_ctx) {
14303 hdd_err("HDD context is NULL");
14304 return false;
14305 }
14306
Jeff Johnson16528362018-06-14 12:34:16 -070014307 mac_handle = hdd_ctx->mac_handle;
14308
Dustin Brown920397d2017-12-13 16:27:50 -080014309 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya929afa42018-06-01 15:04:44 -070014310 hdd_debug("Adapter with device mode %s(%d) exists",
Dustin Brown458027c2018-10-19 12:26:27 -070014311 qdf_opmode_str(adapter->device_mode),
14312 adapter->device_mode);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014313 if (((QDF_STA_MODE == adapter->device_mode)
14314 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
14315 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
14316 && (eConnectionState_Connecting ==
14317 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
14318 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014319 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014320 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070014321 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014322 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070014323 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014324 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014325 }
14326 return true;
14327 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070014328 /*
14329 * sme_neighbor_middle_of_roaming is for LFR2
14330 * hdd_is_roaming_in_progress is for LFR3
14331 */
14332 if (((QDF_STA_MODE == adapter->device_mode) &&
14333 sme_neighbor_middle_of_roaming(
Jeff Johnson16528362018-06-14 12:34:16 -070014334 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -070014335 adapter->session_id)) ||
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014336 hdd_is_roaming_in_progress(hdd_ctx)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014337 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014338 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070014339 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014340 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070014341 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014342 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014343 }
14344 return true;
14345 }
14346 if ((QDF_STA_MODE == adapter->device_mode) ||
14347 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
14348 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
14349 hdd_sta_ctx =
14350 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
14351 if ((eConnectionState_Associated ==
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053014352 hdd_sta_ctx->conn_info.connState)
14353 && sme_is_sta_key_exchange_in_progress(
Jeff Johnson16528362018-06-14 12:34:16 -070014354 mac_handle, adapter->session_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014355 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070014356 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014357 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014358 " is in middle of WPS/EAPOL exchange.",
14359 MAC_ADDR_ARRAY(sta_mac));
14360 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070014361 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014362 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014363 }
14364 return true;
14365 }
14366 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
14367 (QDF_P2P_GO_MODE == adapter->device_mode)) {
14368 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
14369 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014370 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014371 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014372 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014373 continue;
14374
14375 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014376 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070014377 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014378 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014379 " of SAP/GO is in middle of WPS/EAPOL exchange",
14380 MAC_ADDR_ARRAY(sta_mac));
14381 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070014382 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014383 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014384 }
14385 return true;
14386 }
14387 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014388 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014389 return true;
14390 }
14391 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014392 }
Dustin Brown920397d2017-12-13 16:27:50 -080014393
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014394 return false;
14395}
14396
14397/**
14398 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070014399 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014400 *
14401 * Return: None
14402 */
Jeff Johnson9d295242017-08-29 14:39:48 -070014403void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014404{
Jeff Johnson87251032017-08-29 13:31:11 -070014405 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070014406 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014407 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014408 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Jeff Johnsone4c11db2018-05-05 23:22:32 -070014409 tsap_config_t *sap_config;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014410 void *sap_ctx;
14411
14412 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070014413 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070014414 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014415
14416 mutex_lock(&hdd_ctx->sap_lock);
14417 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
14418 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014419 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
14420 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
14421 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
14422 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053014423 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014424 qdf_stop_bss_event,
Vignesh Viswanathan865daaa2018-10-11 19:30:44 +053014425 SME_CMD_START_STOP_BSS_TIMEOUT);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014426
14427 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014428 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014429 goto end;
14430 }
14431 }
14432 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -070014433 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070014434 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070014435 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014436 false);
Jeff Johnson6867ec32017-09-29 20:30:20 -070014437 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014438
14439 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014440 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014441 wlansap_reset_sap_config_add_ie(sap_config,
14442 eUPDATE_IE_ALL);
14443 goto end;
14444 }
14445
14446 qdf_event_reset(&hostapd_state->qdf_event);
14447 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
14448 sap_config,
14449 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014450 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014451 wlansap_reset_sap_config_add_ie(sap_config,
14452 eUPDATE_IE_ALL);
14453 goto end;
14454 }
14455
Jeff Johnson6867ec32017-09-29 20:30:20 -070014456 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014457 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053014458 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Vignesh Viswanathan865daaa2018-10-11 19:30:44 +053014459 SME_CMD_START_STOP_BSS_TIMEOUT);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014460 wlansap_reset_sap_config_add_ie(sap_config,
14461 eUPDATE_IE_ALL);
14462 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014463 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014464 goto end;
14465 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070014466 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014467 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014468 if (hostapd_state->bss_state == BSS_START) {
Dustin Brown1dbefe62018-09-11 16:32:03 -070014469 policy_mgr_incr_active_session(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014470 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070014471 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070014472 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014473 ap_adapter->device_mode,
14474 true);
14475 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014476 }
14477end:
14478 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014479}
14480
14481/**
14482 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
14483 * with non dfs acs
14484 *
14485 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
14486 *
14487 * Return: None
14488 */
14489void hdd_check_and_restart_sap_with_non_dfs_acs(void)
14490{
Jeff Johnson9d295242017-08-29 14:39:48 -070014491 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014492 struct hdd_context *hdd_ctx;
Jeff Johnson2b6982c2018-05-29 14:56:11 -070014493 struct cds_context *cds_ctx;
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014494 uint8_t restart_chan;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014495
14496 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14497 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014498 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014499 return;
14500 }
14501
14502 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
14503 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014504 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014505 return;
14506 }
14507
Dustin Brown1dbefe62018-09-11 16:32:03 -070014508 if (policy_mgr_get_concurrency_mode(hdd_ctx->psoc)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014509 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Dustin Brown7e761c72018-07-31 13:50:17 -070014510 hdd_debug("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014511 return;
14512 }
14513
14514 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Dustin Brown07901ec2018-09-07 11:02:41 -070014515 if (ap_adapter &&
14516 test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags) &&
14517 wlan_reg_is_dfs_ch(hdd_ctx->pdev,
14518 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014519
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014520 hdd_warn("STA-AP Mode DFS not supported, Switch SAP channel to Non DFS");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014521
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014522 restart_chan =
14523 hdd_get_safe_channel_from_pcl_and_acs_range(ap_adapter);
14524 if (!restart_chan ||
Dustin Brown07901ec2018-09-07 11:02:41 -070014525 wlan_reg_is_dfs_ch(hdd_ctx->pdev, restart_chan))
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014526 restart_chan = SAP_DEFAULT_5GHZ_CHANNEL;
14527
14528 hdd_switch_sap_channel(ap_adapter, restart_chan, true);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014529 }
14530}
14531
14532/**
14533 * hdd_set_connection_in_progress() - to set the connection in
14534 * progress flag
14535 * @value: value to set
14536 *
14537 * This function will set the passed value to connection in progress flag.
14538 * If value is previously being set to true then no need to set it again.
14539 *
14540 * Return: true if value is being set correctly and false otherwise.
14541 */
14542bool hdd_set_connection_in_progress(bool value)
14543{
14544 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014545 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014546
14547 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14548 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014549 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014550 return false;
14551 }
14552
14553 qdf_spin_lock(&hdd_ctx->connection_status_lock);
14554 /*
14555 * if the value is set to true previously and if someone is
14556 * trying to make it true again then it could be some race
14557 * condition being triggered. Avoid this situation by returning
14558 * false
14559 */
14560 if (hdd_ctx->connection_in_progress && value)
14561 status = false;
14562 else
14563 hdd_ctx->connection_in_progress = value;
14564 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
14565 return status;
14566}
14567
Jeff Johnson9d295242017-08-29 14:39:48 -070014568int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014569{
14570 if (!adapter) {
14571 hdd_err("Invalid adapter");
14572 return -EINVAL;
14573 }
14574 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070014575 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014576 WMA_VDEV_MCC_SET_TIME_QUOTA,
14577 set_value, VDEV_CMD);
14578 return 0;
14579
14580}
14581
Jeff Johnson9d295242017-08-29 14:39:48 -070014582int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014583{
14584 if (!adapter) {
14585 hdd_err("Invalid adapter");
14586 return -EINVAL;
14587 }
14588
14589 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070014590 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014591 WMA_VDEV_MCC_SET_TIME_LATENCY,
14592 set_value, VDEV_CMD);
14593 return 0;
14594}
14595
Jeff Johnson9d295242017-08-29 14:39:48 -070014596struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070014597 *psoc, uint8_t vdev_id)
14598{
Jeff Johnson9d295242017-08-29 14:39:48 -070014599 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014600 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070014601
14602 /*
14603 * Currently PSOC is not being used. But this logic will
14604 * change once we have the converged implementation of
14605 * HDD context per PSOC in place. This would break if
14606 * multiple vdev objects reuse the vdev id.
14607 */
14608 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
14609 if (!adapter)
14610 hdd_err("Get adapter by vdev id failed");
14611
14612 return adapter;
14613}
14614
Jeff Johnson9d295242017-08-29 14:39:48 -070014615int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014616 int8_t *rssi, int8_t *snr)
14617{
14618 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -070014619 mac_handle_t mac_handle;
Jeff Johnson025618c2018-03-18 14:41:00 -070014620 struct csr_roam_profile *roam_profile;
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014621
Jeff Johnson025618c2018-03-18 14:41:00 -070014622 roam_profile = hdd_roam_profile(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -070014623 mac_handle = hdd_adapter_get_mac_handle(adapter);
14624 status = sme_get_rssi_snr_by_bssid(mac_handle,
Jeff Johnson025618c2018-03-18 14:41:00 -070014625 roam_profile, bssid, rssi, snr);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014626 if (QDF_STATUS_SUCCESS != status) {
14627 hdd_warn("sme_get_rssi_snr_by_bssid failed");
14628 return -EINVAL;
14629 }
14630
14631 return 0;
14632}
14633
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014634/**
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014635 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
14636 * @adapter - HDD adapter
14637 *
14638 * Return: 0 on success and non zero value on failure
14639 */
14640int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
14641{
14642 struct hdd_context *hdd_ctx;
14643 int ret;
14644 QDF_STATUS status;
Krunal Sonie71838d2018-09-27 10:45:05 -070014645 uint8_t sys_pref = 0;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014646
14647 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
14648 ret = wlan_hdd_validate_context(hdd_ctx);
14649 if (ret < 0)
14650 return ret;
14651
Krunal Sonie71838d2018-09-27 10:45:05 -070014652 ucfg_policy_mgr_get_sys_pref(hdd_ctx->psoc,
14653 &sys_pref);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014654 /* set the system preferece to default */
Krunal Sonie71838d2018-09-27 10:45:05 -070014655 policy_mgr_set_cur_conc_system_pref(hdd_ctx->psoc, sys_pref);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014656
14657 /* clear the bitmap */
14658 adapter->active_ac = 0;
14659
14660 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson16528362018-06-14 12:34:16 -070014661 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014662
Jeff Johnson16528362018-06-14 12:34:16 -070014663 status = sme_send_limit_off_channel_params(hdd_ctx->mac_handle,
14664 adapter->session_id,
14665 false, 0, 0, false);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014666 if (!QDF_IS_STATUS_SUCCESS(status)) {
14667 hdd_err("failed to reset limit off chan params");
14668 ret = -EINVAL;
14669 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014670
14671 return ret;
14672}
14673
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014674/**
14675 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
14676 * @drv_op: Enum indicating driver op
14677 *
14678 * Return: none
14679 */
14680void hdd_start_driver_ops_timer(int drv_op)
14681{
14682 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
14683 switch (drv_op) {
14684 case eHDD_DRV_OP_PROBE:
14685 memcpy(drv_ops_string, "probe", sizeof("probe"));
14686 break;
14687 case eHDD_DRV_OP_REMOVE:
14688 memcpy(drv_ops_string, "remove", sizeof("remove"));
14689 break;
14690 case eHDD_DRV_OP_SHUTDOWN:
14691 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
14692 break;
14693 case eHDD_DRV_OP_REINIT:
14694 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
14695 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053014696 case eHDD_DRV_OP_IFF_UP:
14697 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
14698 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014699 }
14700
Dustin Brown45ed4bb2017-12-18 12:00:13 -080014701 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014702 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
Dustin Browncfc54fe2018-06-18 16:17:41 -070014703 HDD_OPS_INACTIVITY_TIMEOUT * qdf_timer_get_multiplier());
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014704}
14705
14706/**
14707 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
14708 *
14709 * Return: none
14710 */
14711void hdd_stop_driver_ops_timer(void)
14712{
14713 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
14714}
14715
14716/**
14717 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
14718 * inactivity timer
14719 *
14720 * Return: None
14721 */
14722void hdd_drv_ops_inactivity_handler(void)
14723{
Rajeev Kumar4471f1b2018-06-08 14:18:28 -070014724 hdd_err("WLAN_BUG_RCA %s: %d Sec timer expired while in .%s",
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014725 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
14726
Dustin Brown45ed4bb2017-12-18 12:00:13 -080014727 if (hdd_drv_ops_task) {
14728 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
14729 qdf_print_thread_trace(hdd_drv_ops_task);
14730 } else {
14731 hdd_err("hdd_drv_ops_task is null");
14732 }
14733
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014734 /* Driver shutdown is stuck, no recovery possible at this point */
14735 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
14736 sizeof("shutdown")))
14737 QDF_BUG(0);
14738
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080014739 if (cds_is_fw_down()) {
14740 hdd_err("FW is down");
14741 return;
14742 }
14743
Dustin Brown83044c22018-08-13 15:00:44 -070014744 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014745}
14746
Yun Parkff6a16a2017-09-26 16:38:18 -070014747/**
14748 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
14749 * @struct hdd_context *hdd_ctx
14750 * @struct hdd_adapter *padapter
14751 * @bool enble
14752 *
14753 * Return: none
14754 */
14755void hdd_set_rx_mode_rps(bool enable)
14756{
14757 struct cds_config_info *cds_cfg = cds_get_ini_config();
Ryan Hsu0e878fa2018-05-04 15:22:09 -070014758 struct hdd_context *hdd_ctx;
14759 struct hdd_adapter *adapter;
Yun Parkff6a16a2017-09-26 16:38:18 -070014760
Ryan Hsu0e878fa2018-05-04 15:22:09 -070014761 if (!cds_cfg)
14762 return;
14763
14764 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14765 if (!hdd_ctx)
14766 return;
14767
14768 adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
14769 if (!adapter)
14770 return;
14771
14772 if (!hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
Yun Parkff6a16a2017-09-26 16:38:18 -070014773 if (enable && !cds_cfg->rps_enabled)
14774 hdd_send_rps_ind(adapter);
14775 else if (!enable && cds_cfg->rps_enabled)
14776 hdd_send_rps_disable_ind(adapter);
14777 }
14778}
14779
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +053014780bool hdd_is_cli_iface_up(struct hdd_context *hdd_ctx)
14781{
14782 struct hdd_adapter *adapter = NULL;
14783
14784 hdd_for_each_adapter(hdd_ctx, adapter) {
14785 if ((adapter->device_mode == QDF_STA_MODE ||
14786 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
14787 qdf_atomic_test_bit(DEVICE_IFACE_OPENED,
14788 &adapter->event_flags)){
14789 return true;
14790 }
14791 }
14792
14793 return false;
14794}
14795
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014796/* Register the module init/exit functions */
14797module_init(hdd_module_init);
14798module_exit(hdd_module_exit);
14799
14800MODULE_LICENSE("Dual BSD/GPL");
14801MODULE_AUTHOR("Qualcomm Atheros, Inc.");
14802MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
14803
Srinivas Girigowda841da292018-02-21 16:33:00 -080014804static const struct kernel_param_ops con_mode_ops = {
14805 .set = con_mode_handler,
14806 .get = param_get_int,
14807};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014808
Srinivas Girigowda841da292018-02-21 16:33:00 -080014809static const struct kernel_param_ops con_mode_ftm_ops = {
14810 .set = con_mode_handler_ftm,
14811 .get = param_get_int,
14812};
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053014813
Nirav Shah73713f72018-05-17 14:50:41 +053014814#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080014815static const struct kernel_param_ops con_mode_monitor_ops = {
14816 .set = con_mode_handler_monitor,
14817 .get = param_get_int,
14818};
Nirav Shah73713f72018-05-17 14:50:41 +053014819#endif
Ravi Joshia307f632017-07-17 23:41:41 -070014820
Srinivas Girigowda841da292018-02-21 16:33:00 -080014821static const struct kernel_param_ops fwpath_ops = {
14822 .set = fwpath_changed_handler,
14823 .get = param_get_string,
14824};
14825
14826module_param_cb(con_mode, &con_mode_ops, &con_mode,
14827 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
14828
14829module_param_cb(con_mode_ftm, &con_mode_ftm_ops, &con_mode_ftm,
14830 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
14831
Nirav Shah73713f72018-05-17 14:50:41 +053014832#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080014833module_param_cb(con_mode_monitor, &con_mode_monitor_ops, &con_mode_monitor,
14834 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Nirav Shah73713f72018-05-17 14:50:41 +053014835#endif
Srinivas Girigowda841da292018-02-21 16:33:00 -080014836
14837module_param_cb(fwpath, &fwpath_ops, &fwpath,
14838 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014839
14840module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
14841
14842module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
14843
14844module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);