blob: 4116721bf31fceb53b271b837d22a0a1abf49416 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Jeff Johnson30e9bb62018-12-27 20:57:09 -08002 * Copyright (c) 2012-2019 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
7 * copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080019/**
20 * DOC: wlan_hdd_main.c
21 *
22 * WLAN Host Device Driver implementation
23 *
24 */
25
26/* Include Files */
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053027#include <wbuff.h>
Dustin Brown84f46ea2018-02-15 11:57:36 -080028#include "cfg_ucfg_api.h"
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>
Dustin Brownfe50cef2018-12-10 10:42:37 -080043#include "wlan_hdd_dsc.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080044#include <wlan_hdd_wowl.h>
45#include <wlan_hdd_misc.h>
46#include <wlan_hdd_wext.h>
47#include "wlan_hdd_trace.h"
48#include "wlan_hdd_ioctl.h"
49#include "wlan_hdd_ftm.h"
50#include "wlan_hdd_power.h"
51#include "wlan_hdd_stats.h"
Prashanth Bhatta527fd752016-04-28 12:35:23 -070052#include "wlan_hdd_scan.h"
Krunal Sonie9c12f52018-10-04 11:45:42 -070053#include "wlan_policy_mgr_ucfg.h"
Naveen Rawate02f8f52018-04-05 11:58:04 -070054#include <wlan_osif_request_manager.h>
Dustin Brown26b3d042017-12-21 11:13:27 -080055#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4bc0a622017-12-06 15:56:50 -080056#include "qdf_debug_domain.h"
Dustin Brown26b3d042017-12-21 11:13:27 -080057#endif
Dustin Brownd4241942018-02-26 12:51:37 -080058#include "qdf_str.h"
Dustin Brownd315c452018-11-27 11:28:48 -080059#include "qdf_talloc.h"
Dustin Brownd4241942018-02-26 12:51:37 -080060#include "qdf_trace.h"
61#include "qdf_types.h"
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070062#include <cdp_txrx_peer_ops.h>
Dhanashri Atrea8f82f22017-01-23 12:58:24 -080063#include <cdp_txrx_misc.h>
Mohit Khannaca4173b2017-09-12 21:52:19 -070064#include <cdp_txrx_stats.h>
bings0e03a982018-05-09 08:40:59 +080065#include "cdp_txrx_flow_ctrl_legacy.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080066
67#include <net/addrconf.h>
68#include <linux/wireless.h>
69#include <net/cfg80211.h>
70#include <linux/inetdevice.h>
71#include <net/addrconf.h>
72#include "wlan_hdd_cfg80211.h"
73#include "wlan_hdd_ext_scan.h"
74#include "wlan_hdd_p2p.h"
75#include <linux/rtnetlink.h>
76#include "sap_api.h"
77#include <linux/semaphore.h>
78#include <linux/ctype.h>
79#include <linux/compat.h>
Arunk Khandavalli830c9692018-03-22 12:17:40 +053080#include <linux/reboot.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080081#ifdef MSM_PLATFORM
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080082#include <soc/qcom/subsystem_restart.h>
83#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080084#include <wlan_hdd_hostapd.h>
85#include <wlan_hdd_softap_tx_rx.h>
Jeff Johnson8bb61112018-03-31 13:33:54 -070086#include <wlan_hdd_green_ap.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080087#include "cfg_api.h"
88#include "qwlan_version.h"
89#include "wma_types.h"
90#include "wlan_hdd_tdls.h"
91#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053092#include "cds_regdomain.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080093#endif /* FEATURE_WLAN_CH_AVOID */
Dustin Brownce46d1d2017-08-15 13:34:24 -070094#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070095#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -080096#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080097#include "wlan_hdd_nan.h"
98#include "wlan_hdd_debugfs.h"
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053099#include "wlan_hdd_debugfs_csr.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800100#include "wlan_hdd_driver_ops.h"
101#include "epping_main.h"
Poddar, Siddarth34872782017-08-10 14:08:51 +0530102#include "wlan_hdd_data_stall_detection.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800103
104#include <wlan_hdd_ipa.h>
105#include "hif.h"
106#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800107#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700108#include "wlan_hdd_tsf.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530109#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700110#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700111#include "wlan_hdd_lpass.h"
Nachiket Kukade63bb63d2018-11-21 14:42:14 +0530112#include "wlan_nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700113#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530114#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800115#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800116#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530117#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800118#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800119#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530120#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530121#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800122#include "os_if_wifi_pos.h"
123#include "wifi_pos_api.h"
124#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800125#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700126#include "os_if_nan.h"
127#include "nan_public_structs.h"
Nachiket Kukade85aa3782018-11-02 20:12:34 +0530128#include "nan_ucfg_api.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700129#include "wlan_reg_ucfg_api.h"
bings81fe50a2017-11-27 14:33:26 +0800130#include "wlan_dfs_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700131#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530132#include "sme_power_save_api.h"
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +0530133#include "enet.h"
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700134#include <cdp_txrx_cmn_struct.h>
Mohit Khanna70322002018-05-15 19:21:32 -0700135#include <dp_txrx.h>
Amar Singhal0928b192017-12-01 10:50:54 -0800136#include "wlan_hdd_sysfs.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530137#include "wlan_disa_ucfg_api.h"
Wu Gao52084c12018-05-17 20:47:11 +0800138#include "wlan_disa_obj_mgmt_api.h"
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +0530139#include "wlan_action_oui_ucfg_api.h"
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +0530140#include "wlan_ipa_ucfg_api.h"
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530141#include <target_if.h>
Alok Kumarb64650c2018-03-23 17:05:11 +0530142#include "wlan_hdd_nud_tracking.h"
Nachiket Kukaded0dd62e2018-05-21 18:39:22 +0530143#include "wlan_hdd_apf.h"
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -0700144#include "wlan_hdd_twt.h"
Rachit Kankane0dc3e852018-05-07 17:33:42 +0530145#include "qc_sap_ioctl.h"
Sandeep Puligillac5609d52018-05-17 19:23:41 -0700146#include "wlan_mlme_main.h"
Wu Gaoe5689792018-07-05 19:20:13 +0800147#include "wlan_p2p_cfg_api.h"
Wu Gao637d58a2018-12-08 10:37:34 +0800148#include "wlan_cfg80211_p2p.h"
Wu Gaobdb7f272018-07-05 19:33:26 +0800149#include "wlan_tdls_cfg_api.h"
Qiwei Caie689a262018-07-26 15:50:22 +0800150#include <wlan_hdd_rssi_monitor.h>
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +0530151#include "wlan_mlme_ucfg_api.h"
Sourav Mohapatra113685f2018-08-29 14:21:55 +0530152#include "wlan_fwol_ucfg_api.h"
Krunal Sonie71838d2018-09-27 10:45:05 -0700153#include "wlan_policy_mgr_ucfg.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530154#ifdef CNSS_GENL
155#include <net/cnss_nl.h>
156#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800157#include "wlan_reg_ucfg_api.h"
Zhang Qian47e22ce2018-01-04 15:38:38 +0800158#include "wlan_ocb_ucfg_api.h"
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -0800159#include <wlan_hdd_spectralscan.h>
gaurank kathpalia4a205fc2018-09-15 00:59:15 +0530160#include "wlan_green_ap_ucfg_api.h"
Liangwei Dong3abfe8f2018-09-20 02:25:44 -0400161#include <wlan_p2p_ucfg_api.h>
Mohit Khanna81418772018-10-30 14:14:46 -0700162#include <target_type.h>
Liangwei Dong3abfe8f2018-09-20 02:25:44 -0400163
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800164#ifdef MODULE
165#define WLAN_MODULE_NAME module_name(THIS_MODULE)
166#else
167#define WLAN_MODULE_NAME "wlan"
168#endif
169
170#ifdef TIMER_MANAGER
171#define TIMER_MANAGER_STR " +TIMER_MANAGER"
172#else
173#define TIMER_MANAGER_STR ""
174#endif
175
176#ifdef MEMORY_DEBUG
177#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
178#else
179#define MEMORY_DEBUG_STR ""
180#endif
181
Dustin Brownc1034df2018-02-07 14:51:32 -0800182#ifdef PANIC_ON_BUG
183#define PANIC_ON_BUG_STR " +PANIC_ON_BUG"
184#else
185#define PANIC_ON_BUG_STR ""
186#endif
187
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530188bool g_is_system_reboot_triggered;
Sachin Ahujadddd2632017-03-07 19:07:24 +0530189int wlan_start_ret_val;
190static DECLARE_COMPLETION(wlan_start_comp);
191static unsigned int dev_num = 1;
192static struct cdev wlan_hdd_state_cdev;
193static struct class *class;
194static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530195#ifndef MODULE
196static struct gwlan_loader *wlan_loader;
197static ssize_t wlan_boot_cb(struct kobject *kobj,
198 struct kobj_attribute *attr,
199 const char *buf, size_t count);
200struct gwlan_loader {
201 bool loaded_state;
202 struct kobject *boot_wlan_obj;
203 struct attribute_group *attr_group;
204};
205
206static struct kobj_attribute wlan_boot_attribute =
207 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
208
209static struct attribute *attrs[] = {
210 &wlan_boot_attribute.attr,
211 NULL,
212};
213
214#define MODULE_INITIALIZED 1
Qun Zhang4a83a462018-09-11 16:28:51 +0800215
216#ifdef MULTI_IF_NAME
217#define WLAN_LOADER_NAME "boot_" MULTI_IF_NAME
218#else
219#define WLAN_LOADER_NAME "boot_wlan"
220#endif
Arun Khandavallifae92942016-08-01 13:31:08 +0530221#endif
222
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530223#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
224#define MAX_OPS_NAME_STRING_SIZE 20
225
226static qdf_timer_t hdd_drv_ops_inactivity_timer;
Dustin Brown45ed4bb2017-12-18 12:00:13 -0800227static struct task_struct *hdd_drv_ops_task;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530228static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
229
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800230/* the Android framework expects this param even though we don't use it */
231#define BUF_LEN 20
232static char fwpath_buffer[BUF_LEN];
233static struct kparam_string fwpath = {
234 .string = fwpath_buffer,
235 .maxlen = BUF_LEN,
236};
237
238static char *country_code;
239static int enable_11d = -1;
240static int enable_dfs_chan_scan = -1;
241
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800242/*
243 * spinlock for synchronizing asynchronous request/response
244 * (full description of use in wlan_hdd_main.h)
245 */
246DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530247DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800248
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800249#define WLAN_NLINK_CESIUM 30
250
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530251static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800252
253#define WOW_MAX_FILTER_LISTS 1
254#define WOW_MAX_FILTERS_PER_LIST 4
255#define WOW_MIN_PATTERN_SIZE 6
256#define WOW_MAX_PATTERN_SIZE 64
257
Bala Venkatesh110b03e2018-07-10 16:02:08 +0530258/* max peer can be tdls peers + self peer + bss peer */
259#define HDD_MAX_VDEV_PEER_COUNT (HDD_MAX_NUM_TDLS_STA + 2)
Sourav Mohapatra808e3d42018-07-04 09:34:23 +0530260#define IS_IDLE_STOP (!cds_is_driver_unloading() && \
261 !cds_is_driver_recovering() && !cds_is_driver_loading())
Bala Venkatesh110b03e2018-07-10 16:02:08 +0530262
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800263#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
264static const struct wiphy_wowlan_support wowlan_support_reg_init = {
265 .flags = WIPHY_WOWLAN_ANY |
266 WIPHY_WOWLAN_MAGIC_PKT |
267 WIPHY_WOWLAN_DISCONNECT |
268 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
269 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
270 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
271 WIPHY_WOWLAN_4WAY_HANDSHAKE |
272 WIPHY_WOWLAN_RFKILL_RELEASE,
273 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
274 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
275 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
276};
277#endif
278
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700279static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
280 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
281 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
282 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
283 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
284 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
285 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
286 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
287 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
288 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
289 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
290 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
291 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
292 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
293 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
294 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
295 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
296 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
297 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
298 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
299 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
300 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
301 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
302 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
303 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
304 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
305 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
306 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
307 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
308 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
309 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
310 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
311 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
312 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
313 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700314 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700315 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700316 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530317 [QDF_MODULE_ID_GREEN_AP] = {QDF_TRACE_LEVEL_ALL},
Zhang Qian47e22ce2018-01-04 15:38:38 +0800318 [QDF_MODULE_ID_OCB] = {QDF_TRACE_LEVEL_ALL},
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530319 [QDF_MODULE_ID_IPA] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +0530320 [QDF_MODULE_ID_ACTION_OUI] = {QDF_TRACE_LEVEL_ALL},
Dustin Brown84f46ea2018-02-15 11:57:36 -0800321 [QDF_MODULE_ID_CONFIG] = {QDF_TRACE_LEVEL_ALL},
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +0530322 [QDF_MODULE_ID_MLME] = {QDF_TRACE_LEVEL_ALL},
Ashish Kumar Dhanotiya8d039c82018-07-11 20:41:14 +0530323 [QDF_MODULE_ID_TARGET] = {QDF_TRACE_LEVEL_ALL},
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -0700324 [QDF_MODULE_ID_CRYPTO] = {QDF_TRACE_LEVEL_ALL},
Sourav Mohapatra113685f2018-08-29 14:21:55 +0530325 [QDF_MODULE_ID_FWOL] = {QDF_TRACE_LEVEL_ALL},
Abhishek Singh0b0105f2018-09-25 10:44:16 +0530326 [QDF_MODULE_ID_SM_ENGINE] = {QDF_TRACE_LEVEL_ALL},
327 [QDF_MODULE_ID_CMN_MLME] = {QDF_TRACE_LEVEL_ALL},
Nachiket Kukade089b9832018-12-12 16:38:17 +0530328 [QDF_MODULE_ID_NAN] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700329};
330
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530331struct notifier_block hdd_netdev_notifier;
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530332struct notifier_block system_reboot_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800333
334struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800335#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700336static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800337#endif
338
Sachin Ahujadddd2632017-03-07 19:07:24 +0530339void hdd_start_complete(int ret)
340{
341 wlan_start_ret_val = ret;
342
343 complete(&wlan_start_comp);
344}
345
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800346/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530347 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700348 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530349 *
350 * Return: none
351 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700352static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530353{
Jeff Johnson9d295242017-08-29 14:39:48 -0700354 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530355
Dustin Brown920397d2017-12-13 16:27:50 -0800356 hdd_for_each_adapter(hdd_ctx, adapter)
357 hdd_send_rps_ind(adapter);
Nirav Shahbd36b062016-07-18 11:12:59 +0530358}
359
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530360#ifdef QCA_HL_NETDEV_FLOW_CONTROL
361void wlan_hdd_mod_fc_timer(struct hdd_adapter *adapter,
362 enum netif_action_type action)
363{
364 if (!adapter->tx_flow_timer_initialized)
365 return;
366
367 if (action == WLAN_WAKE_NON_PRIORITY_QUEUE) {
368 qdf_mc_timer_stop(&adapter->tx_flow_control_timer);
369 } else if (action == WLAN_STOP_NON_PRIORITY_QUEUE) {
370 QDF_STATUS status =
371 qdf_mc_timer_start(&adapter->tx_flow_control_timer,
372 WLAN_HDD_TX_FLOW_CONTROL_OS_Q_BLOCK_TIME);
373
374 if (!QDF_IS_STATUS_SUCCESS(status))
375 hdd_err("Failed to start tx_flow_control_timer");
376 else
377 adapter->
378 hdd_stats.tx_rx_stats.txflow_timer_cnt++;
379
380 adapter->hdd_stats.tx_rx_stats.txflow_pause_cnt++;
381 adapter->hdd_stats.tx_rx_stats.is_txflow_paused = true;
382 }
383}
384#endif /* QCA_HL_NETDEV_FLOW_CONTROL */
385
Alok Kumar2fad6442018-11-08 19:19:28 +0530386#ifdef MSM_PLATFORM
387void wlan_hdd_update_tcp_rx_param(struct hdd_context *hdd_ctx, void *data)
388{
389 if (!hdd_ctx) {
390 hdd_err("HDD context is null");
391 return;
392 }
393
394 if (!data) {
395 hdd_err("Data is null");
396 return;
397 }
398 if (hdd_ctx->config->enable_tcp_param_update)
399 wlan_hdd_send_tcp_param_update_event(hdd_ctx, data, 1);
400 else
401 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
402 WLAN_SVC_WLAN_TP_IND,
403 data,
404 sizeof(struct wlan_rx_tp_data));
405}
406
407void wlan_hdd_update_tcp_tx_param(struct hdd_context *hdd_ctx, void *data)
408{
409 enum wlan_tp_level next_tx_level;
410 struct wlan_tx_tp_data *tx_tp_data;
411
412 if (!hdd_ctx) {
413 hdd_err("HDD context is null");
414 return;
415 }
416
417 if (!data) {
418 hdd_err("Data is null");
419 return;
420 }
421
422 tx_tp_data = (struct wlan_tx_tp_data *)data;
423 next_tx_level = tx_tp_data->level;
424
425 if (hdd_ctx->config->enable_tcp_param_update)
426 wlan_hdd_send_tcp_param_update_event(hdd_ctx, data, 0);
427 else
428 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
429 WLAN_SVC_WLAN_TP_TX_IND,
430 &next_tx_level,
431 sizeof(next_tx_level));
432}
433
434/**
435 * wlan_hdd_send_tcp_param_update_event() - Send vendor event to update
436 * TCP parameter through Wi-Fi HAL
437 * @hdd_ctx: Pointer to HDD context
438 * @data: Parameters to update
439 * @dir: Direction(tx/rx) to update
440 *
441 * Return: None
442 */
443void wlan_hdd_send_tcp_param_update_event(struct hdd_context *hdd_ctx,
444 void *data,
445 uint8_t dir)
446{
447 struct sk_buff *vendor_event;
448 uint32_t event_len;
449 bool tcp_limit_output = false;
450 bool tcp_del_ack_ind_enabled = false;
451 bool tcp_adv_win_scl_enabled = false;
452 enum wlan_tp_level next_tp_level = WLAN_SVC_TP_NONE;
453
454 event_len = sizeof(uint8_t) + sizeof(uint8_t) + NLMSG_HDRLEN;
455
456 if (dir == 0) /*TX Flow */ {
457 struct wlan_tx_tp_data *tx_tp_data =
458 (struct wlan_tx_tp_data *)data;
459
460 next_tp_level = tx_tp_data->level;
461
462 if (tx_tp_data->tcp_limit_output) {
463 /* TCP_LIMIT_OUTPUT_BYTES */
464 event_len += sizeof(uint32_t);
465 tcp_limit_output = true;
466 }
467 } else if (dir == 1) /* RX Flow */ {
468 struct wlan_rx_tp_data *rx_tp_data =
469 (struct wlan_rx_tp_data *)data;
470
471 next_tp_level = rx_tp_data->level;
472
473 if (rx_tp_data->rx_tp_flags & TCP_DEL_ACK_IND_MASK) {
474 event_len += sizeof(uint32_t); /* TCP_DELACK_SEG */
475 tcp_del_ack_ind_enabled = true;
476 }
477 if (rx_tp_data->rx_tp_flags & TCP_ADV_WIN_SCL_MASK) {
478 event_len += sizeof(uint32_t); /* TCP_ADV_WIN_SCALE */
479 tcp_adv_win_scl_enabled = true;
480 }
481 } else {
482 hdd_err("Invalid Direction [%d]", dir);
483 return;
484 }
485
486 vendor_event =
487 cfg80211_vendor_event_alloc(
488 hdd_ctx->wiphy,
489 NULL, event_len,
490 QCA_NL80211_VENDOR_SUBCMD_THROUGHPUT_CHANGE_EVENT_INDEX,
491 GFP_KERNEL);
492
493 if (!vendor_event) {
494 hdd_err("cfg80211_vendor_event_alloc failed");
495 return;
496 }
497
498 if (nla_put_u8(
499 vendor_event,
500 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_DIRECTION,
501 dir))
502 goto tcp_param_change_nla_failed;
503
504 if (nla_put_u8(
505 vendor_event,
506 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_THROUGHPUT_LEVEL,
507 (next_tp_level == WLAN_SVC_TP_LOW ?
508 QCA_WLAN_THROUGHPUT_LEVEL_LOW :
509 QCA_WLAN_THROUGHPUT_LEVEL_HIGH)))
510 goto tcp_param_change_nla_failed;
511
512 if (tcp_limit_output &&
513 nla_put_u32(
514 vendor_event,
515 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_TCP_LIMIT_OUTPUT_BYTES,
516 (next_tp_level == WLAN_SVC_TP_LOW ?
517 TCP_LIMIT_OUTPUT_BYTES_LOW :
518 TCP_LIMIT_OUTPUT_BYTES_HI)))
519 goto tcp_param_change_nla_failed;
520
521 if (tcp_del_ack_ind_enabled &&
522 (nla_put_u32(
523 vendor_event,
524 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_TCP_DELACK_SEG,
525 (next_tp_level == WLAN_SVC_TP_LOW ?
526 TCP_DEL_ACK_LOW : TCP_DEL_ACK_HI))))
527 goto tcp_param_change_nla_failed;
528
529 if (tcp_adv_win_scl_enabled &&
530 (nla_put_u32(
531 vendor_event,
532 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_TCP_ADV_WIN_SCALE,
533 (next_tp_level == WLAN_SVC_TP_LOW ?
534 WIN_SCALE_LOW : WIN_SCALE_HI))))
535 goto tcp_param_change_nla_failed;
536
537 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
538 return;
539
540tcp_param_change_nla_failed:
541 hdd_err("nla_put api failed");
542 kfree_skb(vendor_event);
543}
544#endif /* MSM_PLATFORM */
545
Nirav Shahbd36b062016-07-18 11:12:59 +0530546/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800547 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
548 * @vdev_id: vdev_id
549 * @action: action type
550 * @reason: reason type
551 *
552 * Return: none
553 */
554void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
555 enum netif_action_type action, enum netif_reason_type reason)
556{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700557 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700558 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800559
560 if (!hdd_ctx) {
561 hdd_err("hdd ctx is NULL");
562 return;
563 }
564 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530565 wlan_hdd_mod_fc_timer(adapter, action);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800566 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800567}
568
569/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700570 * Store WLAN driver version and timestamp info in global variables such that
571 * crash debugger can extract them from driver debug symbol and crashdump for
572 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800573 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800574#ifdef BUILD_TAG
Rajeev Kumare555e2d2018-09-17 11:52:37 -0700575uint8_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 -0800576#else
Rajeev Kumare555e2d2018-09-17 11:52:37 -0700577uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR;
Naveen Rawat93836252017-06-20 16:30:59 -0700578#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800579
580/**
Liangwei Dong17bf2662018-01-05 02:02:05 -0500581 * hdd_get_valid_chan() - return current chan list from regulatory.
582 * @hdd_ctx: HDD context
583 * @chan_list: buf hold returned chan list
584 * @chan_num: input buf size and output returned chan num
585 *
586 * This function helps get current available chan list from regulatory
587 * module. It excludes the "disabled" and "invalid" channels.
588 *
589 * Return: 0 for success.
590 */
591static int hdd_get_valid_chan(struct hdd_context *hdd_ctx,
592 uint8_t *chan_list,
593 uint32_t *chan_num)
594{
595 int i = 0, j = 0;
596 struct regulatory_channel *cur_chan_list;
597 struct wlan_objmgr_pdev *pdev;
598
Dustin Brown07901ec2018-09-07 11:02:41 -0700599 if (!hdd_ctx || !hdd_ctx->pdev || !chan_list || !chan_num)
Liangwei Dong17bf2662018-01-05 02:02:05 -0500600 return -EINVAL;
601
Dustin Brown07901ec2018-09-07 11:02:41 -0700602 pdev = hdd_ctx->pdev;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500603 cur_chan_list = qdf_mem_malloc(NUM_CHANNELS *
604 sizeof(struct regulatory_channel));
605 if (!cur_chan_list)
606 return -ENOMEM;
607
608 if (wlan_reg_get_current_chan_list(pdev, cur_chan_list) !=
609 QDF_STATUS_SUCCESS) {
610 qdf_mem_free(cur_chan_list);
611 return -EINVAL;
612 }
613
614 for (i = 0; i < NUM_CHANNELS; i++) {
615 uint32_t ch = cur_chan_list[i].chan_num;
616 enum channel_state state = wlan_reg_get_channel_state(pdev,
617 ch);
618
619 if (state != CHANNEL_STATE_DISABLE &&
620 state != CHANNEL_STATE_INVALID &&
621 j < *chan_num) {
622 chan_list[j] = (uint8_t)ch;
623 j++;
624 }
625 }
626 *chan_num = j;
627 qdf_mem_free(cur_chan_list);
628 return 0;
629}
630
631/**
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530632 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
633 * @adapter: HDD adapter
634 * @chan_number: Channel number
635 * @chan_bw: Bandwidth
636 *
637 * Checks if the given bandwidth is valid for the given channel number.
638 *
639 * Return: 0 for success, non-zero for failure
640 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700641int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530642 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800643 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530644{
Liangwei Dong17bf2662018-01-05 02:02:05 -0500645 uint8_t chan[NUM_CHANNELS];
646 uint32_t len = NUM_CHANNELS, i;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530647 bool found = false;
Jeff Johnson16528362018-06-14 12:34:16 -0700648 mac_handle_t mac_handle;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500649 int ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530650
Jeff Johnson16528362018-06-14 12:34:16 -0700651 mac_handle = hdd_adapter_get_mac_handle(adapter);
652 if (!mac_handle) {
653 hdd_err("Invalid MAC handle");
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530654 return -EINVAL;
655 }
656
Liangwei Dong17bf2662018-01-05 02:02:05 -0500657 ret = hdd_get_valid_chan(adapter->hdd_ctx, chan,
658 &len);
659 if (ret) {
660 hdd_err("error %d in getting valid channel list", ret);
661 return ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530662 }
663
664 for (i = 0; i < len; i++) {
665 if (chan[i] == chan_number) {
666 found = true;
667 break;
668 }
669 }
670
671 if (found == false) {
672 hdd_err("Channel not in driver's valid channel list");
673 return -EOPNOTSUPP;
674 }
675
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700676 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
677 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530678 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
679 return -EINVAL;
680 }
681
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700682 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530683 if (chan_bw == CH_WIDTH_80MHZ) {
684 hdd_err("BW80 not possible in 2.4GHz band");
685 return -EINVAL;
686 }
687 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
688 (chan_bw != CH_WIDTH_MAX)) {
689 hdd_err("Only BW20 possible on channel 14");
690 return -EINVAL;
691 }
692 }
693
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700694 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530695 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
696 (chan_bw != CH_WIDTH_MAX)) {
697 hdd_err("Only BW20 possible on channel 165");
698 return -EINVAL;
699 }
700 }
701
702 return 0;
703}
704
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530705/**
706 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
707 *
708 * Block the unloading of the driver (or) interface up until the
709 * cds recovery is completed
710 *
711 * Return: true for recovery completion else false
712 */
713static bool hdd_wait_for_recovery_completion(void)
714{
715 int retry = 0;
716
717 /* Wait for recovery to complete */
718 while (cds_is_driver_recovering()) {
719 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
720 hdd_err("Recovery in progress; wait here!!!");
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530721
722 if (g_is_system_reboot_triggered) {
723 hdd_info("System Reboot happening ignore unload!!");
724 return false;
725 }
726
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530727 msleep(1000);
728 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
729 hdd_err("SSR never completed, error");
730 /*
731 * Trigger the bug_on in the internal builds, in the
732 * customer builds self-recovery will be enabled
733 * in those cases just return error.
734 */
735 if (cds_is_self_recovery_enabled())
736 return false;
737 QDF_BUG(0);
738 }
739 }
740
741 hdd_info("Recovery completed successfully!");
742 return true;
743}
744
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530745
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800746static int __hdd_netdev_notifier_call(struct notifier_block *nb,
747 unsigned long state, void *data)
748{
749#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
750 struct netdev_notifier_info *dev_notif_info = data;
751 struct net_device *dev = dev_notif_info->dev;
752#else
753 struct net_device *dev = data;
754#endif
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530755 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700756 struct hdd_context *hdd_ctx;
Min Liu8c5d99e2018-09-10 17:18:44 +0800757 struct wlan_objmgr_vdev *vdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800758
Dustin Brownfdf17c12018-03-14 12:55:34 -0700759 hdd_enter_dev(dev);
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800760
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800761 if (!dev->ieee80211_ptr) {
Dustin Brownaeb55642018-07-30 17:20:32 -0700762 hdd_debug("ieee80211_ptr is null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800763 return NOTIFY_DONE;
764 }
765
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530766 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
767 if (!hdd_ctx) {
768 hdd_err("HDD Context is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800769 return NOTIFY_DONE;
770 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800771
772 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -0700773 hdd_debug("%s: Driver module is closed", __func__);
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800774 return NOTIFY_DONE;
775 }
776
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530777 /* Make sure that this callback corresponds to our device. */
778 adapter = hdd_get_adapter_by_iface_name(hdd_ctx, dev->name);
779 if (!adapter) {
Dustin Brownaeb55642018-07-30 17:20:32 -0700780 hdd_debug("failed to look up adapter for '%s'", dev->name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800781 return NOTIFY_DONE;
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530782 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800783
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530784 if (adapter != WLAN_HDD_GET_PRIV_PTR(dev)) {
785 hdd_err("HDD adapter mismatch!");
786 return NOTIFY_DONE;
787 }
788
Dustin Brownaeb55642018-07-30 17:20:32 -0700789 if (cds_is_driver_recovering()) {
790 hdd_debug("Driver is recovering");
791 return NOTIFY_DONE;
792 }
793
794 if (cds_is_driver_in_bad_state()) {
795 hdd_debug("Driver is in failed recovery state");
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530796 return NOTIFY_DONE;
797 }
798
799 hdd_debug("%s New Net Device State = %lu", dev->name, state);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800800
801 switch (state) {
802 case NETDEV_REGISTER:
803 break;
804
805 case NETDEV_UNREGISTER:
806 break;
807
808 case NETDEV_UP:
Jeff Johnson16528362018-06-14 12:34:16 -0700809 sme_ch_avoid_update_req(hdd_ctx->mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800810 break;
811
812 case NETDEV_DOWN:
813 break;
814
815 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700816 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800817 complete(&adapter->linkup_event_var);
818 break;
819
820 case NETDEV_GOING_DOWN:
Min Liu8c5d99e2018-09-10 17:18:44 +0800821 vdev = hdd_objmgr_get_vdev(adapter);
822 if (!vdev)
823 break;
824 if (ucfg_scan_get_vdev_status(vdev) !=
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700825 SCAN_NOT_IN_PROGRESS) {
Dustin Brown07901ec2018-09-07 11:02:41 -0700826 wlan_abort_scan(hdd_ctx->pdev, INVAL_PDEV_ID,
827 adapter->session_id, INVALID_SCAN_ID,
828 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800829 }
Min Liu8c5d99e2018-09-10 17:18:44 +0800830 hdd_objmgr_put_vdev(adapter);
Min Liu9be5d4a2018-05-17 11:51:53 +0800831 cds_flush_work(&adapter->scan_block_work);
832 /* Need to clean up blocked scan request */
833 wlan_hdd_cfg80211_scan_block_cb(&adapter->scan_block_work);
Min Liu9be5d4a2018-05-17 11:51:53 +0800834 hdd_debug("Scan is not Pending from user");
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530835 /*
836 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
837 * of return status of hdd_stop call, kernel resets the IFF_UP
838 * flag after which driver does not send the cfg80211_scan_done.
839 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
840 */
Dustin Brown07901ec2018-09-07 11:02:41 -0700841 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800842 break;
843
844 default:
845 break;
846 }
847
848 return NOTIFY_DONE;
849}
850
851/**
852 * hdd_netdev_notifier_call() - netdev notifier callback function
853 * @nb: pointer to notifier block
854 * @state: state
855 * @ndev: ndev pointer
856 *
857 * Return: 0 on success, error number otherwise.
858 */
859static int hdd_netdev_notifier_call(struct notifier_block *nb,
860 unsigned long state,
861 void *ndev)
862{
863 int ret;
864
865 cds_ssr_protect(__func__);
866 ret = __hdd_netdev_notifier_call(nb, state, ndev);
867 cds_ssr_unprotect(__func__);
868
869 return ret;
870}
871
872struct notifier_block hdd_netdev_notifier = {
873 .notifier_call = hdd_netdev_notifier_call,
874};
875
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530876static int system_reboot_notifier_call(struct notifier_block *nb,
877 unsigned long msg_type, void *_unused)
878{
879 switch (msg_type) {
880 case SYS_DOWN:
881 case SYS_HALT:
882 case SYS_POWER_OFF:
883 g_is_system_reboot_triggered = true;
884 hdd_info("reboot, reason: %ld", msg_type);
885 break;
886 default:
887 break;
888 }
889
890 return NOTIFY_OK;
891}
892
893struct notifier_block system_reboot_notifier = {
894 .notifier_call = system_reboot_notifier_call,
895};
896
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800897/* variable to hold the insmod parameters */
898static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800899
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530900static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700901int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530902
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800903/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800904static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800905
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530906/**
907 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
908 * @ch_width: NL channel width
909 *
910 * Converts the NL channel width to the driver's internal representation
911 *
912 * Return: Converted channel width. In case of non matching NL channel width,
913 * CH_WIDTH_MAX will be returned.
914 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800915enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530916{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800917 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700918
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800919 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530920 switch (ch_width) {
921 case NL80211_CHAN_WIDTH_20_NOHT:
922 case NL80211_CHAN_WIDTH_20:
923 return CH_WIDTH_20MHZ;
924 case NL80211_CHAN_WIDTH_40:
925 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530926 case NL80211_CHAN_WIDTH_80:
927 return CH_WIDTH_80MHZ;
928 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800929 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
930 return CH_WIDTH_80P80MHZ;
931 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
932 return CH_WIDTH_160MHZ;
933 else
934 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530935 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800936 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
937 return CH_WIDTH_160MHZ;
938 else
939 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530940 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800941 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530942 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800943 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530944 default:
945 hdd_err("Invalid channel width %d, setting to default",
946 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800947 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530948 }
949}
950
Dustin Brown56377e12018-10-10 17:04:04 -0700951QDF_STATUS hdd_nl_to_qdf_iface_type(enum nl80211_iftype nl_type,
952 enum QDF_OPMODE *out_qdf_type)
953{
954 switch (nl_type) {
955 case NL80211_IFTYPE_ADHOC:
956 *out_qdf_type = QDF_IBSS_MODE;
957 break;
958 case NL80211_IFTYPE_AP:
959 *out_qdf_type = QDF_SAP_MODE;
960 break;
961 case NL80211_IFTYPE_MONITOR:
962 *out_qdf_type = QDF_MONITOR_MODE;
963 break;
964 case NL80211_IFTYPE_OCB:
965 *out_qdf_type = QDF_OCB_MODE;
966 break;
967 case NL80211_IFTYPE_P2P_CLIENT:
968 *out_qdf_type = QDF_P2P_CLIENT_MODE;
969 break;
970 case NL80211_IFTYPE_P2P_DEVICE:
971 *out_qdf_type = QDF_P2P_DEVICE_MODE;
972 break;
973 case NL80211_IFTYPE_P2P_GO:
974 *out_qdf_type = QDF_P2P_GO_MODE;
975 break;
976 case NL80211_IFTYPE_STATION:
977 *out_qdf_type = QDF_STA_MODE;
978 break;
979 case NL80211_IFTYPE_WDS:
980 *out_qdf_type = QDF_WDS_MODE;
981 break;
982 default:
983 hdd_err("Invalid nl80211 interface type %d", nl_type);
984 return QDF_STATUS_E_INVAL;
985 }
986
987 return QDF_STATUS_SUCCESS;
988}
989
Jeff Johnson16528362018-06-14 12:34:16 -0700990uint8_t wlan_hdd_find_opclass(mac_handle_t mac_handle, uint8_t channel,
991 uint8_t bw_offset)
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530992{
993 uint8_t opclass = 0;
994
Jeff Johnson16528362018-06-14 12:34:16 -0700995 sme_get_opclass(mac_handle, channel, bw_offset, &opclass);
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530996 return opclass;
997}
998
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800999/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05301000 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301001 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001002 * @bitmask: Bitmask of log levels to be enabled
1003 *
1004 * Called immediately after the cfg.ini is read in order to configure
1005 * the desired trace levels.
1006 *
1007 * Return: None
1008 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301009int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001010{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301011 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05301012 int qdf_print_idx = -1;
1013 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001014 /*
1015 * if the bitmask is the default value, then a bitmask was not
1016 * specified in cfg.ini, so leave the logging level alone (it
1017 * will remain at the "compiled in" default value)
1018 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001019 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301020 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001021
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05301022 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001023
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05301024 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301025 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05301026 QDF_TRACE_LEVEL_NONE, 0);
1027
1028 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301029 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001030 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +05301031 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001032 while (0 != bitmask) {
1033 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05301034 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301035 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05301036 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301037 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001038 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001039
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001040 level++;
1041 bitmask >>= 1;
1042 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301043 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001044}
1045
Dustin Brownda351e32018-07-23 15:48:22 -07001046int __wlan_hdd_validate_context(struct hdd_context *hdd_ctx, const char *func)
Chris Guo1751acf2017-07-03 14:09:01 +08001047{
Dustin Brownda351e32018-07-23 15:48:22 -07001048 if (!hdd_ctx) {
1049 hdd_err("HDD context is null (via %s)", func);
1050 return -ENODEV;
1051 }
1052
1053 if (!hdd_ctx->config) {
1054 hdd_err("HDD config is null (via %s)", func);
Chris Guo1751acf2017-07-03 14:09:01 +08001055 return -ENODEV;
1056 }
1057
1058 if (cds_is_driver_recovering()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001059 hdd_debug("Recovery in progress (via %s); state:0x%x",
1060 func, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001061 return -EAGAIN;
1062 }
1063
Yue Ma9f275d92017-09-14 16:58:41 -07001064 if (cds_is_load_or_unload_in_progress()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001065 hdd_debug("Load/unload in progress (via %s); state:0x%x",
1066 func, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001067 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -07001068 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05301069
Dustin Brownda351e32018-07-23 15:48:22 -07001070 if (hdd_ctx->start_modules_in_progress) {
1071 hdd_debug("Start modules in progress (via %s)", func);
1072 return -EAGAIN;
1073 }
1074
1075 if (hdd_ctx->stop_modules_in_progress) {
1076 hdd_debug("Stop modules in progress (via %s)", func);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05301077 return -EAGAIN;
1078 }
1079
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301080 if (cds_is_driver_in_bad_state()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001081 hdd_debug("Driver in bad state (via %s); state:0x%x",
1082 func, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +05301083 return -EAGAIN;
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301084 }
1085
Arunk Khandavalli2859fa12018-02-14 10:46:26 +05301086 if (cds_is_fw_down()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001087 hdd_debug("FW is down (via %s); state:0x%x",
1088 func, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +05301089 return -EAGAIN;
Arunk Khandavalli2859fa12018-02-14 10:46:26 +05301090 }
1091
Liangwei Dong858feb12018-05-21 01:52:46 -04001092 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
Dustin Brownda351e32018-07-23 15:48:22 -07001093 hdd_debug("Driver mode change in progress (via %s)", func);
Liangwei Dong858feb12018-05-21 01:52:46 -04001094 return -EAGAIN;
1095 }
1096
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001097 return 0;
1098}
1099
Dustin Browna8700cc2018-08-07 12:04:47 -07001100int __hdd_validate_adapter(struct hdd_adapter *adapter, const char *func)
Dustin Brownf13b8c32017-05-19 17:23:08 -07001101{
1102 if (!adapter) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001103 hdd_err("adapter is null (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001104 return -EINVAL;
1105 }
1106
1107 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001108 hdd_err("bad adapter magic (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001109 return -EINVAL;
1110 }
1111
1112 if (!adapter->dev) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001113 hdd_err("adapter net_device is null (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001114 return -EINVAL;
1115 }
1116
1117 if (!(adapter->dev->flags & IFF_UP)) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001118 hdd_debug_rl("adapter '%s' is not up (via %s)",
1119 adapter->dev->name, func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001120 return -EAGAIN;
1121 }
1122
Dustin Browna8700cc2018-08-07 12:04:47 -07001123 return __wlan_hdd_validate_session_id(adapter->session_id, func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001124}
1125
Dustin Brown63500612018-08-07 11:36:09 -07001126int __wlan_hdd_validate_session_id(uint8_t session_id, const char *func)
1127{
1128 if (session_id == CSR_SESSION_ID_INVALID) {
1129 hdd_debug_rl("adapter is not up (via %s)", func);
1130 return -EINVAL;
1131 }
1132
1133 if (session_id >= CSR_ROAM_SESSION_MAX) {
1134 hdd_err("bad session Id:%u (via %s)", session_id, func);
1135 return -EINVAL;
1136 }
1137
1138 return 0;
1139}
1140
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05301141QDF_STATUS __wlan_hdd_validate_mac_address(struct qdf_mac_addr *mac_addr,
1142 const char *func)
1143{
1144 if (!mac_addr) {
1145 hdd_err("Received NULL mac address (via %s)", func);
1146 return QDF_STATUS_E_INVAL;
1147 }
1148
1149 if (qdf_is_macaddr_zero(mac_addr)) {
1150 hdd_err("MAC is all zero (via %s)", func);
1151 return QDF_STATUS_E_INVAL;
1152 }
1153
1154 if (qdf_is_macaddr_broadcast(mac_addr)) {
1155 hdd_err("MAC is Broadcast (via %s)", func);
1156 return QDF_STATUS_E_INVAL;
1157 }
1158
1159 if (QDF_NET_IS_MAC_MULTICAST(mac_addr->bytes)) {
1160 hdd_err("MAC is Multicast (via %s)", func);
1161 return QDF_STATUS_E_INVAL;
1162 }
1163
1164 return QDF_STATUS_SUCCESS;
1165}
1166
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001167/**
Arun Khandavallica892f62017-05-26 14:25:50 +05301168 * wlan_hdd_validate_modules_state() - Check modules status
1169 * @hdd_ctx: HDD context pointer
1170 *
1171 * Check's the driver module's state and returns true if the
1172 * modules are enabled returns false if modules are closed.
1173 *
1174 * Return: True if modules are enabled or false.
1175 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001176bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +05301177{
1178 mutex_lock(&hdd_ctx->iface_change_lock);
1179 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
1180 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown5e89ef82018-03-14 11:50:23 -07001181 hdd_info("Modules not enabled, Present status: %d",
1182 hdd_ctx->driver_status);
Arun Khandavallica892f62017-05-26 14:25:50 +05301183 return false;
1184 }
1185 mutex_unlock(&hdd_ctx->iface_change_lock);
1186 return true;
1187}
1188
1189/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001190 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -07001191 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001192 *
1193 * This function sets the IBSS power save config parameters to WMA
1194 * which will send it to firmware if FW supports IBSS power save
1195 * before vdev start.
1196 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301197 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001198 * on failure.
1199 */
Jeff Johnson9d295242017-08-29 14:39:48 -07001200QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001201{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001202 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001203
1204 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001205 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301206 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001207 }
1208
Manikandan Mohan2bd09772018-11-28 18:27:32 -08001209 return ucfg_mlme_ibss_power_save_setup(hdd_ctx->psoc,
1210 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001211}
1212
Yue Macd359b72017-10-03 15:21:00 -07001213#ifdef FEATURE_RUNTIME_PM
1214/**
1215 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
1216 * @hdd_ctx: HDD context
1217 *
1218 * Return: None
1219 */
1220static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
1221{
1222 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1223
Yue Macd359b72017-10-03 15:21:00 -07001224 qdf_runtime_lock_init(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001225 qdf_runtime_lock_init(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001226
Dustin Brown07901ec2018-09-07 11:02:41 -07001227 wlan_scan_runtime_pm_init(hdd_ctx->pdev);
Yue Macd359b72017-10-03 15:21:00 -07001228}
1229
1230/**
1231 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1232 * @hdd_ctx: HDD Context
1233 *
1234 * Return: None
1235 */
1236static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1237{
1238 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1239
Yue Macd359b72017-10-03 15:21:00 -07001240 qdf_runtime_lock_deinit(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001241 qdf_runtime_lock_deinit(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001242
Dustin Brown07901ec2018-09-07 11:02:41 -07001243 wlan_scan_runtime_pm_deinit(hdd_ctx->pdev);
Yue Macd359b72017-10-03 15:21:00 -07001244}
1245
Yue Macd359b72017-10-03 15:21:00 -07001246#else /* FEATURE_RUNTIME_PM */
1247static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1248static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Yue Macd359b72017-10-03 15:21:00 -07001249#endif /* FEATURE_RUNTIME_PM */
1250
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001251#define INTF_MACADDR_MASK 0x7
1252
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301253void hdd_update_macaddr(struct hdd_context *hdd_ctx,
1254 struct qdf_mac_addr hw_macaddr, bool generate_mac_auto)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001255{
1256 int8_t i;
1257 uint8_t macaddr_b3, tmp_br3;
1258
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301259 /*
1260 * If "generate_mac_auto" is true, it indicates that all the
1261 * addresses are derived addresses, else the first addresses
1262 * is not derived address (It is provided by fw).
1263 */
1264 if (!generate_mac_auto) {
1265 qdf_mem_copy(hdd_ctx->provisioned_mac_addr[0].bytes,
1266 hw_macaddr.bytes, QDF_MAC_ADDR_SIZE);
1267 hdd_ctx->num_provisioned_addr++;
1268 hdd_info("hdd_ctx->provisioned_mac_addr[0]: "
1269 MAC_ADDRESS_STR,
1270 MAC_ADDR_ARRAY(hdd_ctx->
1271 provisioned_mac_addr[0].bytes));
1272 } else {
1273 qdf_mem_copy(hdd_ctx->derived_mac_addr[0].bytes,
1274 hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301275 QDF_MAC_ADDR_SIZE);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301276 hdd_ctx->num_derived_addr++;
1277 hdd_info("hdd_ctx->derived_mac_addr[0]: "
1278 MAC_ADDRESS_STR,
1279 MAC_ADDR_ARRAY(hdd_ctx->derived_mac_addr[0].bytes));
1280 }
1281 for (i = hdd_ctx->num_derived_addr; i < (QDF_MAX_CONCURRENCY_PERSONA -
1282 hdd_ctx->num_provisioned_addr);
1283 i++) {
1284 qdf_mem_copy(hdd_ctx->derived_mac_addr[i].bytes,
1285 hw_macaddr.bytes,
1286 QDF_MAC_ADDR_SIZE);
1287 macaddr_b3 = hdd_ctx->derived_mac_addr[i].bytes[3];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001288 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1289 INTF_MACADDR_MASK;
1290 macaddr_b3 += tmp_br3;
1291
1292 /* XOR-ing bit-24 of the mac address. This will give enough
1293 * mac address range before collision
1294 */
1295 macaddr_b3 ^= (1 << 7);
1296
1297 /* Set locally administered bit */
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301298 hdd_ctx->derived_mac_addr[i].bytes[0] |= 0x02;
1299 hdd_ctx->derived_mac_addr[i].bytes[3] = macaddr_b3;
1300 hdd_info("hdd_ctx->derived_mac_addr[%d]: "
1301 MAC_ADDRESS_STR, i,
1302 MAC_ADDR_ARRAY(hdd_ctx->derived_mac_addr[i].bytes));
1303 hdd_ctx->num_derived_addr++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001304 }
1305}
1306
Kabilan Kannan44a58372017-12-06 18:16:11 -08001307static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1308{
Dustin Brown1dbefe62018-09-11 16:32:03 -07001309 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001310 struct tdls_start_params tdls_cfg;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001311 QDF_STATUS status;
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301312 struct wlan_mlme_nss_chains vdev_ini_cfg;
1313
1314 /* Populate the nss chain params from ini for this vdev type */
1315 sme_populate_nss_chain_params(hdd_ctx->mac_handle, &vdev_ini_cfg,
1316 QDF_TDLS_MODE,
1317 hdd_ctx->num_rf_chains);
Kabilan Kannan44a58372017-12-06 18:16:11 -08001318
Dustin Brown1dbefe62018-09-11 16:32:03 -07001319 cfg_tdls_set_vdev_nss_2g(hdd_ctx->psoc,
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301320 vdev_ini_cfg.rx_nss[NSS_CHAINS_BAND_2GHZ]);
Dustin Brown1dbefe62018-09-11 16:32:03 -07001321 cfg_tdls_set_vdev_nss_5g(hdd_ctx->psoc,
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301322 vdev_ini_cfg.rx_nss[NSS_CHAINS_BAND_5GHZ]);
jiad7b8a5e02018-11-26 16:37:57 +08001323 hdd_init_tdls_config(&tdls_cfg);
Kabilan Kannan44a58372017-12-06 18:16:11 -08001324 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1325 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1326 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1327 tdls_cfg.tdls_evt_cb_data = psoc;
Jeff Johnson1d40f5b2018-03-02 08:35:53 -08001328 tdls_cfg.tdls_peer_context = hdd_ctx;
1329 tdls_cfg.tdls_reg_peer = hdd_tdls_register_peer;
1330 tdls_cfg.tdls_dereg_peer = hdd_tdls_deregister_peer;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001331 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1332 tdls_cfg.tdls_wmm_cb_data = psoc;
1333 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1334 tdls_cfg.tdls_rx_cb_data = psoc;
1335 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1336
1337 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1338 if (status != QDF_STATUS_SUCCESS) {
1339 hdd_err("failed pmo psoc configuration");
1340 return -EINVAL;
1341 }
1342
1343 hdd_ctx->tdls_umac_comp_active = true;
1344 /* enable napier specific tdls data path */
1345 hdd_ctx->tdls_nap_active = true;
1346
1347 return 0;
1348}
1349
Wu Gaoca416ff2018-09-17 11:05:07 +08001350#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1351static void hdd_update_roam_offload(struct hdd_context *hdd_ctx,
1352 struct wma_tgt_services *cfg)
1353{
1354 bool roam_offload_enable;
1355
Dustin Brown1dbefe62018-09-11 16:32:03 -07001356 ucfg_mlme_get_roaming_offload(hdd_ctx->psoc, &roam_offload_enable);
1357 ucfg_mlme_set_roaming_offload(hdd_ctx->psoc,
Wu Gaoca416ff2018-09-17 11:05:07 +08001358 roam_offload_enable &
1359 cfg->en_roam_offload);
1360}
1361#else
1362static inline void hdd_update_roam_offload(struct hdd_context *hdd_ctx,
1363 struct wma_tgt_services *cfg)
1364{
1365}
1366#endif
1367
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001368static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001369 struct wma_tgt_services *cfg)
1370{
1371 struct hdd_config *config = hdd_ctx->config;
Wu Gao66454f12018-09-26 19:55:41 +08001372 bool arp_offload_enable;
Wu Gao1ab05582018-11-08 16:22:49 +08001373 bool mawc_enabled;
Wu Gaobdb7f272018-07-05 19:33:26 +08001374#ifdef FEATURE_WLAN_TDLS
1375 bool tdls_support;
1376 bool tdls_off_channel;
1377 bool tdls_buffer_sta;
1378 uint32_t tdls_uapsd_mask;
1379#endif
jiad7b8a5e02018-11-26 16:37:57 +08001380 bool value;
1381
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001382 /* Set up UAPSD */
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05301383 ucfg_mlme_set_sap_uapsd_flag(hdd_ctx->psoc, cfg->uapsd);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001384
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001385 /* 11AX mode support */
1386 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1387 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1388 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1389
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001390 /* 11AC mode support */
1391 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1392 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1393 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001394
1395 /* ARP offload: override user setting if invalid */
Wu Gao66454f12018-09-26 19:55:41 +08001396 arp_offload_enable =
1397 ucfg_pmo_is_arp_offload_enabled(hdd_ctx->psoc);
1398 ucfg_pmo_set_arp_offload_enabled(hdd_ctx->psoc,
1399 arp_offload_enable & cfg->arp_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001400#ifdef FEATURE_WLAN_SCAN_PNO
1401 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001402 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001403 if (cfg->pno_offload)
1404 config->PnoOffload = true;
1405#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001406#ifdef FEATURE_WLAN_TDLS
Dustin Brown1dbefe62018-09-11 16:32:03 -07001407 cfg_tdls_get_support_enable(hdd_ctx->psoc, &tdls_support);
1408 cfg_tdls_set_support_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001409 tdls_support & cfg->en_tdls);
1410
Dustin Brown1dbefe62018-09-11 16:32:03 -07001411 cfg_tdls_get_off_channel_enable(hdd_ctx->psoc, &tdls_off_channel);
1412 cfg_tdls_set_off_channel_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001413 tdls_off_channel &&
1414 cfg->en_tdls_offchan);
1415
Dustin Brown1dbefe62018-09-11 16:32:03 -07001416 cfg_tdls_get_buffer_sta_enable(hdd_ctx->psoc, &tdls_buffer_sta);
1417 cfg_tdls_set_buffer_sta_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001418 tdls_buffer_sta &&
1419 cfg->en_tdls_uapsd_buf_sta);
1420
Dustin Brown1dbefe62018-09-11 16:32:03 -07001421 cfg_tdls_get_uapsd_mask(hdd_ctx->psoc, &tdls_uapsd_mask);
Wu Gaobdb7f272018-07-05 19:33:26 +08001422 if (tdls_uapsd_mask && cfg->en_tdls_uapsd_sleep_sta)
Dustin Brown1dbefe62018-09-11 16:32:03 -07001423 cfg_tdls_set_sleep_sta_enable(hdd_ctx->psoc, true);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001424 else
Dustin Brown1dbefe62018-09-11 16:32:03 -07001425 cfg_tdls_set_sleep_sta_enable(hdd_ctx->psoc, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001426#endif
Wu Gaoca416ff2018-09-17 11:05:07 +08001427 hdd_update_roam_offload(hdd_ctx, cfg);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05301428
Dustin Brown05d81302018-09-11 16:49:22 -07001429 if (ucfg_mlme_get_sap_get_peer_info(hdd_ctx->psoc, &value) ==
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05301430 QDF_STATUS_SUCCESS)
1431 value &= cfg->get_peer_info_enabled;
1432
Wu Gao1ab05582018-11-08 16:22:49 +08001433 ucfg_mlme_is_mawc_enabled(hdd_ctx->psoc, &mawc_enabled);
1434 ucfg_mlme_set_mawc_enabled(hdd_ctx->psoc,
1435 mawc_enabled & cfg->is_fw_mawc_capable);
Kabilan Kannan44a58372017-12-06 18:16:11 -08001436 hdd_update_tdls_config(hdd_ctx);
Jeff Johnson16528362018-06-14 12:34:16 -07001437 sme_update_tgt_services(hdd_ctx->mac_handle, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001438}
1439
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001440/**
1441 * hdd_update_vdev_nss() - sets the vdev nss
1442 * @hdd_ctx: HDD context
1443 *
1444 * Sets the Nss per vdev type based on INI
1445 *
1446 * Return: None
1447 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001448static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001449{
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001450 uint8_t max_supp_nss = 1;
Jeff Johnson16528362018-06-14 12:34:16 -07001451 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301452 QDF_STATUS status;
1453 bool bval;
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001454
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301455 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
1456 if (!QDF_IS_STATUS_SUCCESS(status))
1457 hdd_err("unable to get vht_enable2x2");
1458
1459 if (bval && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001460 max_supp_nss = 2;
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301461
1462 hdd_debug("max nss %d", max_supp_nss);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001463
Jeff Johnson16528362018-06-14 12:34:16 -07001464 mac_handle = hdd_ctx->mac_handle;
1465 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301466 NSS_CHAINS_BAND_2GHZ);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001467
Jeff Johnson16528362018-06-14 12:34:16 -07001468 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301469 NSS_CHAINS_BAND_5GHZ);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001470}
1471
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301472/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301473 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1474 * @hdd_ctx: HDD context
1475 *
1476 * Updates wiphy vhtcap fields
1477 *
1478 * Return: None
1479 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001480static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301481{
1482 struct ieee80211_supported_band *band_5g =
1483 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301484 QDF_STATUS status;
1485 uint8_t value = 0, value1 = 0;
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301486
1487 if (!band_5g) {
1488 hdd_debug("5GHz band disabled, skipping capability population");
1489 return;
1490 }
1491
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301492 status = ucfg_mlme_cfg_get_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
1493 &value);
1494 if (!QDF_IS_STATUS_SUCCESS(status))
1495 hdd_err("unable to get tx_bfee_ant_supp");
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301496
Abhinav Kumare057b412018-10-09 17:28:16 +05301497 band_5g->vht_cap.cap |=
1498 (value << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301499
1500 value1 = NUM_OF_SOUNDING_DIMENSIONS;
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301501 band_5g->vht_cap.cap |=
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301502 (value1 << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301503
Dustin Brown7e761c72018-07-31 13:50:17 -07001504 hdd_debug("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301505 band_5g->vht_cap.cap, value, value1);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301506}
1507
1508/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301509 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1510 * @hdd_ctx: HDD context
1511 *
1512 * Sets the DBS capability as per INI and firmware capability
1513 *
1514 * Return: None
1515 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001516static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301517{
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301518 uint8_t hw_dbs_capable = 0;
Krunal Sonidf29bc42018-11-15 13:26:29 -08001519 uint8_t dual_mac_feature = DISABLE_DBS_CXN_AND_SCAN;
1520 QDF_STATUS status;
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301521
Krunal Sonidf29bc42018-11-15 13:26:29 -08001522 status = ucfg_policy_mgr_get_dual_mac_feature(hdd_ctx->psoc,
1523 &dual_mac_feature);
1524 if (status != QDF_STATUS_SUCCESS)
1525 hdd_err("can't get dual_mac_feature value");
1526 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->psoc)) {
1527 switch (dual_mac_feature) {
1528 case ENABLE_DBS_CXN_AND_SCAN:
1529 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
1530 case ENABLE_DBS_CXN_AND_DISABLE_SIMULTANEOUS_SCAN:
1531 hw_dbs_capable = 1;
1532 break;
1533 default:
1534 hw_dbs_capable = 0;
1535 break;
1536 }
1537 }
Jeff Johnson16528362018-06-14 12:34:16 -07001538 sme_update_hw_dbs_capable(hdd_ctx->mac_handle, hw_dbs_capable);
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301539}
1540
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001541static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001542 struct wma_tgt_ht_cap *cfg)
1543{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301544 QDF_STATUS status;
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301545 qdf_size_t value_len;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301546 uint32_t value;
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05301547 uint8_t mpdu_density;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301548 struct mlme_ht_capabilities_info ht_cap_info;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001549 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301550 bool b_enable1x1;
Jeff Johnson16528362018-06-14 12:34:16 -07001551
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001552 /* get the MPDU density */
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05301553 status = ucfg_mlme_get_ht_mpdu_density(hdd_ctx->psoc, &mpdu_density);
1554 if (QDF_IS_STATUS_ERROR(status)) {
1555 hdd_err("could not get HT MPDU Density");
1556 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001557 }
1558
1559 /*
1560 * MPDU density:
1561 * override user's setting if value is larger
1562 * than the one supported by target
1563 */
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05301564 if (mpdu_density > cfg->mpdu_density) {
1565 status = ucfg_mlme_set_ht_mpdu_density(hdd_ctx->psoc,
1566 cfg->mpdu_density);
1567 if (QDF_IS_STATUS_ERROR(status))
1568 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001569 }
1570
1571 /* get the HT capability info */
Dustin Brown1dbefe62018-09-11 16:32:03 -07001572 status = ucfg_mlme_get_ht_cap_info(hdd_ctx->psoc, &ht_cap_info);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301573 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001574 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001575 return;
1576 }
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301577
1578 /* check and update RX STBC */
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301579 if (ht_cap_info.rx_stbc && !cfg->ht_rx_stbc)
1580 ht_cap_info.rx_stbc = cfg->ht_rx_stbc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001581
1582 /* Set the LDPC capability */
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301583 ht_cap_info.adv_coding_cap = cfg->ht_rx_ldpc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001584
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301585 if (ht_cap_info.short_gi_20_mhz && !cfg->ht_sgi_20)
1586 ht_cap_info.short_gi_20_mhz = cfg->ht_sgi_20;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001587
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301588 if (ht_cap_info.short_gi_40_mhz && !cfg->ht_sgi_40)
1589 ht_cap_info.short_gi_40_mhz = cfg->ht_sgi_40;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001590
1591 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1592 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1593
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301594 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &b_enable1x1);
1595 if (!QDF_IS_STATUS_SUCCESS(status))
1596 hdd_err("unable to get vht_enable2x2");
1597
1598 b_enable1x1 = b_enable1x1 && (cfg->num_rf_chains == 2);
1599
1600 status = ucfg_mlme_set_vht_enable2x2(hdd_ctx->psoc, b_enable1x1);
1601 if (!QDF_IS_STATUS_SUCCESS(status))
1602 hdd_err("unable to set vht_enable2x2");
1603
Abhinav Kumare057b412018-10-09 17:28:16 +05301604 if (!b_enable1x1) {
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301605 ht_cap_info.tx_stbc = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001606
1607 /* 1x1 */
1608 /* Update Rx Highest Long GI data Rate */
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301609 status = ucfg_mlme_cfg_set_vht_rx_supp_data_rate(
1610 hdd_ctx->psoc,
1611 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1);
1612 if (!QDF_IS_STATUS_SUCCESS(status))
1613 hdd_err("Failed to set rx_supp_data_rate");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001614 /* Update Tx Highest Long GI data Rate */
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301615 status = ucfg_mlme_cfg_set_vht_tx_supp_data_rate(
1616 hdd_ctx->psoc,
1617 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1);
1618 if (!QDF_IS_STATUS_SUCCESS(status))
1619 hdd_err("Failed to set tx_supp_data_rate");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001620 }
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301621 if (!(cfg->ht_tx_stbc && b_enable1x1))
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301622 ht_cap_info.tx_stbc = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001623
Dustin Brown1dbefe62018-09-11 16:32:03 -07001624 status = ucfg_mlme_set_ht_cap_info(hdd_ctx->psoc, ht_cap_info);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301625 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001626 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001627#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301628 value_len = SIZE_OF_SUPPORTED_MCS_SET;
1629 if (ucfg_mlme_get_supported_mcs_set(
1630 hdd_ctx->psoc, mcs_set,
1631 &value_len) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001632 hdd_debug("Read MCS rate set");
gaurank kathpalia18b49362018-04-15 23:12:03 +05301633 if (cfg->num_rf_chains > SIZE_OF_SUPPORTED_MCS_SET)
1634 cfg->num_rf_chains = SIZE_OF_SUPPORTED_MCS_SET;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301635
1636 if (b_enable1x1) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001637 for (value = 0; value < cfg->num_rf_chains; value++)
1638 mcs_set[value] =
1639 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1640
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301641 status = ucfg_mlme_set_supported_mcs_set(
1642 hdd_ctx->psoc,
1643 mcs_set,
1644 (qdf_size_t)SIZE_OF_SUPPORTED_MCS_SET);
1645 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001646 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001647 }
1648 }
1649#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1650}
1651
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001652static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001653 struct wma_tgt_vht_cap *cfg)
1654{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301655 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001656 struct wiphy *wiphy = hdd_ctx->wiphy;
1657 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001658 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001659 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001660 struct wma_caps_per_phy caps_per_phy;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301661 uint8_t val = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001662
Dustin Brown5e06bd32016-10-04 12:49:10 -07001663 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001664 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001665 return;
1666 }
1667
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301668 status = ucfg_mlme_update_vht_cap(hdd_ctx->psoc, cfg);
1669 if (QDF_IS_STATUS_ERROR(status))
1670 hdd_err("could not update vht capabilities");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001671
1672 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1673 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1674 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1675 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1676 else
1677 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1678
1679
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001680 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
Abhinav Kumare057b412018-10-09 17:28:16 +05301681 status = ucfg_mlme_set_vht_ch_width(hdd_ctx->psoc,
1682 VHT_CAP_160_AND_80P80_SUPP);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301683 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001684 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001685 band_5g->vht_cap.cap |=
1686 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001687 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1688 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
Abhinav Kumare057b412018-10-09 17:28:16 +05301689 status = ucfg_mlme_set_vht_ch_width(hdd_ctx->psoc,
1690 VHT_CAP_160_SUPP);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301691 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001692 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001693 band_5g->vht_cap.cap |=
1694 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001695 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1696 }
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001697
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301698 status =
1699 ucfg_mlme_cfg_get_vht_chan_width(hdd_ctx->psoc, &val);
1700 if (QDF_IS_STATUS_ERROR(status))
1701 hdd_err("could not get channel_width");
1702
1703 val = QDF_MIN(val, ch_width);
Abhinav Kumare057b412018-10-09 17:28:16 +05301704 status = ucfg_mlme_set_vht_ch_width(hdd_ctx->psoc, val);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301705 if (QDF_IS_STATUS_ERROR(status))
1706 hdd_err("could not set the channel width");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001707
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001708 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001709 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001710 hdd_debug("VHT RxLDPC capability is set");
1711 } else {
1712 /*
1713 * Get the RX LDPC capability for the NON DBS
1714 * hardware mode for 5G band
1715 */
1716 status = wma_get_caps_for_phyidx_hwmode(&caps_per_phy,
1717 HW_MODE_DBS_NONE, CDS_BAND_5GHZ);
1718 if ((QDF_IS_STATUS_SUCCESS(status)) &&
1719 (caps_per_phy.vht_5g & WMI_VHT_CAP_RX_LDPC)) {
1720 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1721 hdd_debug("VHT RX LDPC capability is set");
1722 }
1723 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001724
1725 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1726 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1727 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1728 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1729
1730 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1731 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1732
1733 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1734 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1735 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1736 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1737 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1738 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1739
1740 band_5g->vht_cap.cap |=
1741 (cfg->vht_max_ampdu_len_exp <<
1742 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1743
1744 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1745 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1746 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1747 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1748 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1749 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1750 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1751 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1752
1753 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1754 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1755
1756}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001757
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001758/**
1759 * hdd_generate_macaddr_auto() - Auto-generate mac address
1760 * @hdd_ctx: Pointer to the HDD context
1761 *
1762 * Auto-generate mac address using device serial number.
1763 * Keep the first 3 bytes of OUI as before and replace
1764 * the last 3 bytes with the lower 3 bytes of serial number.
1765 *
1766 * Return: 0 for success
1767 * Non zero failure code for errors
1768 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001769static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001770{
1771 unsigned int serialno = 0;
1772 struct qdf_mac_addr mac_addr = {
1773 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1774 };
1775
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001776 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001777 if (serialno == 0)
1778 return -EINVAL;
1779
1780 serialno &= 0x00ffffff;
1781
1782 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1783 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1784 mac_addr.bytes[5] = serialno & 0xff;
1785
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301786 hdd_update_macaddr(hdd_ctx, mac_addr, true);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001787 return 0;
1788}
1789
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301790/**
1791 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1792 * configuration to cfg_ini in HDD
1793 * @hdd_ctx: Pointer to hdd_ctx
1794 * @cfg: target configuration
1795 *
1796 * Return: None
1797 */
1798#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001799static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301800 struct wma_tgt_cfg *cfg)
1801{
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05301802 ucfg_fwol_set_is_rate_limit_enabled(hdd_ctx->psoc,
1803 cfg->is_ra_rate_limit_enabled);
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301804}
1805#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001806static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301807 struct wma_tgt_cfg *cfg)
1808{
1809}
1810#endif
1811
Jeff Johnsonf9176382018-07-17 19:15:58 -07001812static void hdd_sar_target_config(struct hdd_context *hdd_ctx,
1813 struct wma_tgt_cfg *cfg)
1814{
1815 hdd_ctx->sar_version = cfg->sar_version;
1816}
1817
Jeff Johnson8abc5932018-06-02 22:51:37 -07001818void hdd_update_tgt_cfg(hdd_handle_t hdd_handle, struct wma_tgt_cfg *cfg)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001819{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001820 int ret;
Jeff Johnsonea70b942018-07-02 09:42:31 -07001821 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301822 uint8_t temp_band_cap, band_capability;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001823 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301824 uint8_t antenna_mode;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301825 uint8_t sub_20_chan_width;
Arif Hussainee10f902017-12-27 16:30:17 -08001826 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -07001827 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301828 bool bval = false;
1829 uint8_t value = 0;
Arif Hussainbd5194c2018-11-27 19:01:15 -08001830 uint32_t fine_time_meas_cap = 0;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301831
gaurank kathpalia843f7c32018-07-02 18:04:14 +05301832 if (!hdd_ctx) {
1833 hdd_err("HDD context is NULL");
1834 return;
1835 }
Dustin Brownbd68fe12017-11-21 15:28:52 -08001836 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1837 if (ret) {
Dustin Brown64204d22018-08-15 16:35:19 -07001838 QDF_DEBUG_PANIC("Failed to create pdev; errno:%d", ret);
1839 return;
1840 }
1841
1842 hdd_debug("New pdev has been created with pdev_id = %u",
Dustin Brown07901ec2018-09-07 11:02:41 -07001843 hdd_ctx->pdev->pdev_objmgr.wlan_pdev_id);
Dustin Brown64204d22018-08-15 16:35:19 -07001844
Dustin Brown07901ec2018-09-07 11:02:41 -07001845 status = dispatcher_pdev_open(hdd_ctx->pdev);
Dustin Brown64204d22018-08-15 16:35:19 -07001846 if (QDF_IS_STATUS_ERROR(status)) {
1847 QDF_DEBUG_PANIC("dispatcher pdev open failed; status:%d",
1848 status);
1849 return;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301850 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001851
Sandeep Puligillab7beb472018-08-13 22:54:20 -07001852 status = hdd_component_pdev_open(hdd_ctx->pdev);
1853 if (QDF_IS_STATUS_ERROR(status)) {
1854 QDF_DEBUG_PANIC("hdd component pdev open failed; status:%d",
1855 status);
1856 return;
1857 }
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301858 cdp_pdev_set_ctrl_pdev(cds_get_context(QDF_MODULE_ID_SOC),
1859 cds_get_context(QDF_MODULE_ID_TXRX),
Dustin Brown07901ec2018-09-07 11:02:41 -07001860 (struct cdp_ctrl_objmgr_pdev *)hdd_ctx->pdev);
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301861
Dustin Brown07901ec2018-09-07 11:02:41 -07001862 wlan_pdev_set_dp_handle(hdd_ctx->pdev,
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301863 cds_get_context(QDF_MODULE_ID_TXRX));
1864
Will Huang07244172018-05-14 14:23:30 +08001865 hdd_objmgr_update_tgt_max_vdev_psoc(hdd_ctx, cfg->max_intf_count);
1866
Dustin Brown1dbefe62018-09-11 16:32:03 -07001867 ucfg_ipa_set_dp_handle(hdd_ctx->psoc,
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301868 cds_get_context(QDF_MODULE_ID_SOC));
Dustin Brown1dbefe62018-09-11 16:32:03 -07001869 ucfg_ipa_set_txrx_handle(hdd_ctx->psoc,
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301870 cds_get_context(QDF_MODULE_ID_TXRX));
Dustin Brown07901ec2018-09-07 11:02:41 -07001871 ucfg_ipa_reg_sap_xmit_cb(hdd_ctx->pdev,
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301872 hdd_softap_hard_start_xmit);
Dustin Brown07901ec2018-09-07 11:02:41 -07001873 ucfg_ipa_reg_send_to_nw_cb(hdd_ctx->pdev,
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301874 hdd_ipa_send_skb_to_network);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301875
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301876 status = ucfg_mlme_get_sub_20_chan_width(hdd_ctx->psoc,
1877 &sub_20_chan_width);
1878 if (QDF_IS_STATUS_ERROR(status)) {
1879 hdd_err("Failed to get sub_20_chan_width config");
1880 return;
1881 }
1882
Naveen Rawat64e477e2016-05-20 10:34:56 -07001883 if (cds_cfg) {
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301884 if (sub_20_chan_width !=
1885 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
Naveen Rawat64e477e2016-05-20 10:34:56 -07001886 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1887 cds_cfg->sub_20_channel_width =
1888 WLAN_SUB_20_CH_WIDTH_NONE;
1889 } else {
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301890 cds_cfg->sub_20_channel_width = sub_20_chan_width;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001891 }
1892 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001893
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301894 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
1895 if (QDF_IS_STATUS_ERROR(status)) {
1896 hdd_err("Failed to get MLME band capability");
1897 return;
1898 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001899
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301900 /* first store the INI band capability */
1901 temp_band_cap = band_capability;
1902
1903 band_capability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301904 hdd_ctx->is_fils_roaming_supported =
1905 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001906
Vignesh Viswanathan694e28e2018-01-18 20:53:57 +05301907 hdd_ctx->config->is_11k_offload_supported =
1908 cfg->services.is_11k_offload_supported;
1909
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001910 /*
1911 * now overwrite the target band capability with INI
1912 * setting if INI setting is a subset
1913 */
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301914 if ((band_capability == BAND_ALL) &&
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001915 (temp_band_cap != BAND_ALL))
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301916 band_capability = temp_band_cap;
1917 else if ((band_capability != BAND_ALL) &&
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001918 (temp_band_cap != BAND_ALL) &&
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301919 (band_capability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001920 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001921 }
1922
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301923 status = ucfg_mlme_set_band_capability(hdd_ctx->psoc, band_capability);
1924 if (QDF_IS_STATUS_ERROR(status)) {
1925 hdd_err("Failed to set MLME Band Capability");
1926 return;
1927 }
1928
1929 hdd_ctx->curr_band = band_capability;
Amar Singhal58b45ef2017-08-01 13:43:54 -07001930
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301931 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001932 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1933 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1934 }
1935
1936 /* This can be extended to other configurations like ht, vht cap... */
1937
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301938 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr))
1939 qdf_mem_copy(&hdd_ctx->hw_macaddr, &cfg->hw_macaddr,
1940 QDF_MAC_ADDR_SIZE);
1941 else
1942 hdd_info("hw_mac is zero");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001943
1944 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001945 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001946
Ryan Hsuc6918552018-05-16 13:29:59 -07001947 hdd_ctx->hw_bd_id = cfg->hw_bd_id;
1948 qdf_mem_copy(&hdd_ctx->hw_bd_info, &cfg->hw_bd_info,
1949 sizeof(cfg->hw_bd_info));
1950
Dustin Brownbee82832018-07-23 10:10:51 -07001951 if (cfg->max_intf_count > CSR_ROAM_SESSION_MAX) {
1952 hdd_err("fw max vdevs (%u) > host max vdevs (%u); using %u",
1953 cfg->max_intf_count, CSR_ROAM_SESSION_MAX,
1954 CSR_ROAM_SESSION_MAX);
1955 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
1956 } else {
1957 hdd_ctx->max_intf_count = cfg->max_intf_count;
1958 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001959
Jeff Johnsonf9176382018-07-17 19:15:58 -07001960 hdd_sar_target_config(hdd_ctx, cfg);
Jeff Johnsonc875e242016-09-23 18:12:34 -07001961 hdd_lpass_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001962
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001963 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1964 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1965
1966 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1967
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001968 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001969 if (cfg->services.en_11ax) {
1970 hdd_info("11AX: 11ax is enabled - update HDD config");
1971 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1972 }
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -07001973 hdd_update_tgt_twt_cap(hdd_ctx, cfg);
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001974
1975 hdd_update_vdev_nss(hdd_ctx);
1976
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301977 hdd_update_hw_dbs_capable(hdd_ctx);
gaurank kathpalia5fcefa92018-10-24 15:03:15 +05301978 hdd_ctx->dynamic_nss_chains_support =
1979 cfg->dynamic_nss_chains_support;
Arif Hussainbd5194c2018-11-27 19:01:15 -08001980 ucfg_mlme_get_fine_time_meas_cap(hdd_ctx->psoc, &fine_time_meas_cap);
1981 fine_time_meas_cap &= cfg->fine_time_measurement_cap;
1982 status = ucfg_mlme_set_fine_time_meas_cap(hdd_ctx->psoc,
1983 fine_time_meas_cap);
1984 if (QDF_IS_STATUS_ERROR(status)) {
1985 hdd_err("failed to set fine_time_meas_cap, 0x%x, ox%x",
1986 fine_time_meas_cap, cfg->fine_time_measurement_cap);
1987 ucfg_mlme_get_fine_time_meas_cap(hdd_ctx->psoc,
1988 &fine_time_meas_cap);
1989 }
1990
Krunal Sonie3531942016-04-12 17:43:53 -07001991 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Arif Hussainbd5194c2018-11-27 19:01:15 -08001992 hdd_debug("fine_time_meas_cap: 0x%x", fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001993
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301994 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
1995 if (!QDF_IS_STATUS_SUCCESS(status))
1996 hdd_err("unable to get vht_enable2x2");
1997
1998 antenna_mode = (bval == 0x01) ?
Nitesh Shahe50711f2017-04-26 16:30:45 +05301999 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
2000 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002001 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08002002 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08002003
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05302004 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05302005 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05302006
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05302007 status = ucfg_mlme_cfg_get_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
Abhinav Kumare057b412018-10-09 17:28:16 +05302008 &value);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05302009 if (QDF_IS_STATUS_ERROR(status)) {
2010 status = false;
2011 hdd_err("set tx_bfee_ant_supp failed");
2012 }
2013
2014 if ((value >
Arif Hussainee10f902017-12-27 16:30:17 -08002015 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05302016 !cfg->tx_bfee_8ss_enabled) {
2017 status =
2018 ucfg_mlme_cfg_set_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
2019 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF);
2020 if (QDF_IS_STATUS_ERROR(status)) {
2021 status = false;
2022 hdd_err("set tx_bfee_ant_supp failed");
2023 }
2024 }
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302025
Jeff Johnson16528362018-06-14 12:34:16 -07002026 mac_handle = hdd_ctx->mac_handle;
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302027
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05302028 hdd_debug("txBFCsnValue %d", value);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05302029
2030 /*
2031 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
2032 */
2033 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05302034
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05302035 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
2036
Yue Macd359b72017-10-03 15:21:00 -07002037 /*
2038 * This needs to be done after HDD pdev is created and stored since
2039 * it will access the HDD pdev object lock.
2040 */
2041 hdd_runtime_suspend_context_init(hdd_ctx);
2042
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07002043 /* Configure NAN datapath features */
2044 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Nachiket Kukade85aa3782018-11-02 20:12:34 +05302045 ucfg_nan_set_tgt_caps(hdd_ctx->psoc, &cfg->nan_caps);
Arif Hussain759a0232017-03-20 13:17:18 -07002046 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08002047 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Liangwei Dong0da14262018-07-03 03:30:23 -04002048 hdd_ctx->obss_scan_offload = cfg->services.obss_scan_offload;
Jeff Johnson16528362018-06-14 12:34:16 -07002049 status = sme_cfg_set_int(mac_handle, WNI_CFG_OBSS_DETECTION_OFFLOAD,
Arif Hussainee10f902017-12-27 16:30:17 -08002050 cfg->obss_detection_offloaded);
2051 if (QDF_IS_STATUS_ERROR(status))
2052 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Arif Hussain05fb4872018-01-03 16:02:55 -08002053
Jeff Johnson16528362018-06-14 12:34:16 -07002054 status = sme_cfg_set_int(mac_handle,
Arif Hussain05fb4872018-01-03 16:02:55 -08002055 WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD,
2056 cfg->obss_color_collision_offloaded);
2057 if (QDF_IS_STATUS_ERROR(status))
2058 hdd_err("Failed to set WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002059}
2060
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002061bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002062{
Jeff Johnson9d295242017-08-29 14:39:48 -07002063 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002064 struct hdd_ap_ctx *ap_ctx;
Arif Hussain224d3812018-11-16 17:58:38 -08002065 bool dfs_disable_channel_switch = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002066
Jiachao Wuf610d912018-01-23 17:47:32 +08002067 if (!hdd_ctx) {
2068 hdd_info("Couldn't get hdd_ctx");
2069 return true;
2070 }
2071
Arif Hussain224d3812018-11-16 17:58:38 -08002072 ucfg_mlme_get_dfs_disable_channel_switch(hdd_ctx->psoc,
2073 &dfs_disable_channel_switch);
2074 if (dfs_disable_channel_switch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002075 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussain224d3812018-11-16 17:58:38 -08002076 hdd_ctx, dfs_disable_channel_switch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302077 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002078 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002079
Dustin Brown920397d2017-12-13 16:27:50 -08002080 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002081 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2082
2083 if ((QDF_SAP_MODE == adapter->device_mode ||
2084 QDF_P2P_GO_MODE == adapter->device_mode) &&
Dustin Brown07901ec2018-09-07 11:02:41 -07002085 (wlan_reg_is_passive_or_disable_ch(hdd_ctx->pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002086 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002087 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2088 true;
2089 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07002090 adapter->session_id);
bings6fb9bf62018-07-05 14:01:53 +08002091 if (adapter->txrx_vdev)
2092 cdp_fc_vdev_flush(
2093 cds_get_context(QDF_MODULE_ID_SOC),
bings0e03a982018-05-09 08:40:59 +08002094 adapter->txrx_vdev);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302095 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002096 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302097
2098 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002099}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002100
Jeff Johnson030cd902018-11-11 10:19:40 -08002101bool hdd_is_valid_mac_address(const uint8_t *mac_addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002102{
2103 int xdigit = 0;
2104 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002105
Jeff Johnson030cd902018-11-11 10:19:40 -08002106 while (*mac_addr) {
2107 if (isxdigit(*mac_addr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002108 xdigit++;
Jeff Johnson030cd902018-11-11 10:19:40 -08002109 } else if (':' == *mac_addr) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002110 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2111 break;
2112
2113 ++separator;
2114 } else {
2115 /* Invalid MAC found */
Jeff Johnson030cd902018-11-11 10:19:40 -08002116 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002117 }
Jeff Johnson030cd902018-11-11 10:19:40 -08002118 ++mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002119 }
2120 return xdigit == 12 && (separator == 5 || separator == 0);
2121}
2122
2123/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302124 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2125 * @dev: Handle to struct net_device to be updated.
2126 *
2127 * Return: None
2128 */
2129static void hdd_mon_mode_ether_setup(struct net_device *dev)
2130{
2131 dev->header_ops = NULL;
2132 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2133 dev->hard_header_len = ETH_HLEN;
2134 dev->mtu = ETH_DATA_LEN;
2135 dev->addr_len = ETH_ALEN;
2136 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2137 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2138 dev->priv_flags |= IFF_TX_SKB_SHARING;
2139
2140 memset(dev->broadcast, 0xFF, ETH_ALEN);
2141}
2142
Nirav Shah73713f72018-05-17 14:50:41 +05302143#ifdef FEATURE_MONITOR_MODE_SUPPORT
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302144/**
chenguo71303962018-10-24 19:44:34 +08002145 * hdd_mon_turn_off_ps_and_wow() - Update monitor mode struct net_device.
2146 * @hdd_ctx: Pointer to HDD context.
2147 *
2148 * Return: None
2149 */
2150static void hdd_mon_turn_off_ps_and_wow(struct hdd_context *hdd_ctx)
2151{
2152 ucfg_pmo_set_power_save_mode(hdd_ctx->psoc, PS_NOT_SUPPORTED);
2153 ucfg_pmo_set_wow_enable(hdd_ctx->psoc, PMO_WOW_DISABLE_BOTH);
2154}
2155
2156/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002157 * __hdd__mon_open() - HDD Open function
2158 * @dev: Pointer to net_device structure
2159 *
2160 * This is called in response to ifconfig up
2161 *
2162 * Return: 0 for success; non-zero for failure
2163 */
2164static int __hdd_mon_open(struct net_device *dev)
2165{
2166 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002167 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2168 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002169
Dustin Brownfdf17c12018-03-14 12:55:34 -07002170 hdd_enter_dev(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002171
2172 ret = wlan_hdd_validate_context(hdd_ctx);
2173 if (ret)
2174 return ret;
2175
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302176 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002177
2178 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Brown3ecc8782018-09-19 16:37:13 -07002179 ret = hdd_psoc_idle_restart(hdd_ctx);
Ravi Joshia307f632017-07-17 23:41:41 -07002180 if (ret) {
2181 hdd_err("Failed to start WLAN modules return");
2182 return ret;
2183 }
2184 hdd_err("hdd_wlan_start_modules() successful !");
2185
2186 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2187 ret = hdd_start_adapter(adapter);
2188 if (ret) {
2189 hdd_err("Failed to start adapter :%d",
2190 adapter->device_mode);
2191 return ret;
2192 }
2193 hdd_err("hdd_start_adapters() successful !");
2194 }
chenguo71303962018-10-24 19:44:34 +08002195 hdd_mon_turn_off_ps_and_wow(hdd_ctx);
Ravi Joshia307f632017-07-17 23:41:41 -07002196 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2197 }
2198
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002199 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002200
2201 if (!ret)
2202 ret = hdd_enable_monitor_mode(dev);
2203
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002204 return ret;
2205}
2206
2207/**
2208 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2209 * @dev: Pointer to net_device structure
2210 *
2211 * This is called in response to ifconfig up
2212 *
2213 * Return: 0 for success; non-zero for failure
2214 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002215static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002216{
2217 int ret;
2218
2219 cds_ssr_protect(__func__);
2220 ret = __hdd_mon_open(dev);
2221 cds_ssr_unprotect(__func__);
2222
2223 return ret;
2224}
Nirav Shah73713f72018-05-17 14:50:41 +05302225#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002226
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002227static QDF_STATUS
2228wlan_hdd_update_dbs_scan_and_fw_mode_config(void)
2229{
2230 struct policy_mgr_dual_mac_config cfg = {0};
2231 QDF_STATUS status;
Krunal Sonie64b17e2018-12-13 16:00:02 -08002232 uint32_t chnl_sel_logic_conc = 0;
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002233 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Krunal Sonidf29bc42018-11-15 13:26:29 -08002234 uint8_t dual_mac_feature = DISABLE_DBS_CXN_AND_SCAN;
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002235
2236 if (!hdd_ctx) {
2237 hdd_err("HDD context is NULL");
2238 return QDF_STATUS_E_FAILURE;
2239 }
2240
Krunal Sonie64b17e2018-12-13 16:00:02 -08002241 /*
2242 * ROME platform doesn't support any DBS related commands in FW,
2243 * so if driver sends wmi command with dual_mac_config with all set to
2244 * 0 then FW wouldn't respond back and driver would timeout on waiting
2245 * for response. Check if FW supports DBS to eliminate ROME vs
2246 * NON-ROME platform.
2247 */
2248 if (!policy_mgr_find_if_fw_supports_dbs(hdd_ctx->psoc))
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002249 return QDF_STATUS_SUCCESS;
2250
2251 cfg.scan_config = 0;
2252 cfg.fw_mode_config = 0;
2253 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Krunal Sonie64b17e2018-12-13 16:00:02 -08002254 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->psoc)) {
2255 status =
2256 ucfg_policy_mgr_get_chnl_select_plcy(hdd_ctx->psoc,
2257 &chnl_sel_logic_conc);
2258 if (status != QDF_STATUS_SUCCESS) {
2259 hdd_err("can't get chnl sel policy, use def");
2260 return status;
2261 }
Krunal Sonidf29bc42018-11-15 13:26:29 -08002262 }
2263 status =
2264 ucfg_policy_mgr_get_dual_mac_feature(hdd_ctx->psoc,
2265 &dual_mac_feature);
2266 if (status != QDF_STATUS_SUCCESS) {
2267 hdd_err("ucfg_policy_mgr_get_dual_mac_feature failed, use def");
2268 return status;
2269 }
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002270
Krunal Sonidf29bc42018-11-15 13:26:29 -08002271 if (dual_mac_feature != DISABLE_DBS_CXN_AND_SCAN) {
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002272 status = policy_mgr_get_updated_scan_and_fw_mode_config(
Dustin Brown1dbefe62018-09-11 16:32:03 -07002273 hdd_ctx->psoc, &cfg.scan_config,
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002274 &cfg.fw_mode_config,
Krunal Sonidf29bc42018-11-15 13:26:29 -08002275 dual_mac_feature,
Krunal Sonie64b17e2018-12-13 16:00:02 -08002276 chnl_sel_logic_conc);
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002277
2278 if (status != QDF_STATUS_SUCCESS) {
2279 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
2280 status);
2281 return status;
2282 }
2283 }
2284
2285 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
2286 cfg.scan_config, cfg.fw_mode_config);
2287
2288 status = sme_soc_set_dual_mac_config(cfg);
2289 if (status != QDF_STATUS_SUCCESS) {
2290 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
2291 return status;
2292 }
2293
2294 return QDF_STATUS_SUCCESS;
2295}
2296
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002297/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302298 * hdd_start_adapter() - Wrapper function for device specific adapter
2299 * @adapter: pointer to HDD adapter
2300 *
2301 * This function is called to start the device specific adapter for
2302 * the mode passed in the adapter's device_mode.
2303 *
2304 * Return: 0 for success; non-zero for failure
2305 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002306int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302307{
2308
2309 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002310 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302311
Dustin Brownfdf17c12018-03-14 12:55:34 -07002312 hdd_enter_dev(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002313 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302314
2315 switch (device_mode) {
2316 case QDF_P2P_CLIENT_MODE:
2317 case QDF_P2P_DEVICE_MODE:
2318 case QDF_OCB_MODE:
2319 case QDF_STA_MODE:
2320 case QDF_MONITOR_MODE:
2321 ret = hdd_start_station_adapter(adapter);
2322 if (ret)
2323 goto err_start_adapter;
Alok Kumar81e1d732018-09-04 11:10:36 +05302324
2325 hdd_nud_ignore_tracking(adapter, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05302326 break;
2327 case QDF_P2P_GO_MODE:
2328 case QDF_SAP_MODE:
2329 ret = hdd_start_ap_adapter(adapter);
2330 if (ret)
2331 goto err_start_adapter;
2332 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302333 case QDF_IBSS_MODE:
2334 /*
2335 * For IBSS interface is initialized as part of
2336 * hdd_init_station_mode()
2337 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002338 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302339 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002340 /* vdevs are dynamically managed by firmware in FTM */
2341 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302342 default:
2343 hdd_err("Invalid session type %d", device_mode);
2344 QDF_ASSERT(0);
2345 goto err_start_adapter;
2346 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002347
Arun Khandavallifae92942016-08-01 13:31:08 +05302348 if (hdd_set_fw_params(adapter))
2349 hdd_err("Failed to set the FW params for the adapter!");
2350
Dustin Browne7e71d32018-05-11 16:00:08 -07002351 if (adapter->session_id != HDD_SESSION_ID_INVALID) {
2352 ret = wlan_hdd_cfg80211_register_frames(adapter);
2353 if (ret < 0) {
2354 hdd_err("Failed to register frames - ret %d", ret);
2355 goto err_start_adapter;
2356 }
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302357 }
Dustin Browne7e71d32018-05-11 16:00:08 -07002358
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002359 wlan_hdd_update_dbs_scan_and_fw_mode_config();
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302360
Dustin Browndb2a8be2017-12-20 11:49:56 -08002361exit_with_success:
Dustin Browne74003f2018-03-14 12:51:58 -07002362 hdd_exit();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002363
Arun Khandavallifae92942016-08-01 13:31:08 +05302364 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002365
Arun Khandavallifae92942016-08-01 13:31:08 +05302366err_start_adapter:
2367 return -EINVAL;
2368}
2369
2370/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302371 * hdd_enable_power_management() - API to Enable Power Management
2372 *
2373 * API invokes Bus Interface Layer power management functionality
2374 *
2375 * Return: None
2376 */
2377static void hdd_enable_power_management(void)
2378{
2379 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2380
2381 if (!hif_ctx) {
2382 hdd_err("Bus Interface Context is Invalid");
2383 return;
2384 }
2385
2386 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2387}
2388
2389/**
2390 * hdd_disable_power_management() - API to disable Power Management
2391 *
2392 * API disable Bus Interface Layer Power management functionality
2393 *
2394 * Return: None
2395 */
2396static void hdd_disable_power_management(void)
2397{
2398 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2399
2400 if (!hif_ctx) {
2401 hdd_err("Bus Interface Context is Invalid");
2402 return;
2403 }
2404
2405 hif_disable_power_management(hif_ctx);
2406}
2407
Ryan Hsuaadba072018-04-20 13:01:53 -07002408void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302409{
2410 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002411 size_t target_hw_name_len;
2412 const char *target_hw_name;
Ryan Hsuaadba072018-04-20 13:01:53 -07002413 uint8_t *buf;
2414 uint32_t buf_len;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302415
2416 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2417 if (!hif_sc) {
2418 hdd_err("HIF context is NULL");
2419 return;
2420 }
2421
Ryan Hsuaadba072018-04-20 13:01:53 -07002422 hif_get_hw_info(hif_sc, &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302423 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002424 &target_hw_name);
2425
2426 if (hdd_ctx->target_hw_name)
2427 qdf_mem_free(hdd_ctx->target_hw_name);
2428
2429 target_hw_name_len = strlen(target_hw_name) + 1;
2430 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2431 if (hdd_ctx->target_hw_name)
2432 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2433 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302434
Ryan Hsuaadba072018-04-20 13:01:53 -07002435 buf = qdf_mem_malloc(WE_MAX_STR_LEN);
2436 if (buf) {
2437 buf_len = hdd_wlan_get_version(hdd_ctx, WE_MAX_STR_LEN, buf);
2438 hdd_info("%s", buf);
2439 qdf_mem_free(buf);
2440 }
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302441}
2442
2443/**
gbian62edd7e2017-03-07 13:12:13 +08002444 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2445 * @hdd_ctx: Pointer to hdd context
2446 *
2447 * Return: none
2448 */
2449static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002450hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002451{
jitiphil8e15ea62018-11-16 18:05:34 +05302452 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM] = {0};
2453 qdf_size_t out_size = 0;
gbian62edd7e2017-03-07 13:12:13 +08002454 int i;
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002455 struct cds_context *cds_ctx;
gbian62edd7e2017-03-07 13:12:13 +08002456
2457 if (NULL == hdd_ctx)
2458 return;
2459
2460 if (NULL == hdd_ctx->config) {
2461 /* Do nothing if hdd_ctx is invalid */
2462 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2463 return;
2464 }
2465
2466 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2467
2468 if (!cds_ctx) {
2469 hdd_err("Invalid CDS Context");
2470 return;
2471 }
2472
2473 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2474 switch (i) {
2475 case OL_TX_WMM_AC_BE:
jitiphil8e15ea62018-11-16 18:05:34 +05302476 qdf_uint8_array_parse(
2477 cfg_get(hdd_ctx->psoc,
2478 CFG_DP_ENABLE_TX_SCHED_WRR_BE),
2479 tx_sched_wrr_param,
2480 sizeof(tx_sched_wrr_param),
2481 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002482 break;
2483 case OL_TX_WMM_AC_BK:
jitiphil8e15ea62018-11-16 18:05:34 +05302484 qdf_uint8_array_parse(
2485 cfg_get(hdd_ctx->psoc,
2486 CFG_DP_ENABLE_TX_SCHED_WRR_BK),
2487 tx_sched_wrr_param,
2488 sizeof(tx_sched_wrr_param),
2489 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002490 break;
2491 case OL_TX_WMM_AC_VI:
jitiphil8e15ea62018-11-16 18:05:34 +05302492 qdf_uint8_array_parse(
2493 cfg_get(hdd_ctx->psoc,
2494 CFG_DP_ENABLE_TX_SCHED_WRR_VI),
2495 tx_sched_wrr_param,
2496 sizeof(tx_sched_wrr_param),
2497 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002498 break;
2499 case OL_TX_WMM_AC_VO:
jitiphil8e15ea62018-11-16 18:05:34 +05302500 qdf_uint8_array_parse(
2501 cfg_get(hdd_ctx->psoc,
2502 CFG_DP_ENABLE_TX_SCHED_WRR_VO),
2503 tx_sched_wrr_param,
2504 sizeof(tx_sched_wrr_param),
2505 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002506 break;
2507 default:
gbian62edd7e2017-03-07 13:12:13 +08002508 break;
2509 }
2510
jitiphil8e15ea62018-11-16 18:05:34 +05302511 if (out_size == TX_SCHED_WRR_PARAMS_NUM) {
gbian62edd7e2017-03-07 13:12:13 +08002512 cds_ctx->ac_specs[i].wrr_skip_weight =
2513 tx_sched_wrr_param[0];
2514 cds_ctx->ac_specs[i].credit_threshold =
2515 tx_sched_wrr_param[1];
2516 cds_ctx->ac_specs[i].send_limit =
2517 tx_sched_wrr_param[2];
2518 cds_ctx->ac_specs[i].credit_reserve =
2519 tx_sched_wrr_param[3];
2520 cds_ctx->ac_specs[i].discard_weight =
2521 tx_sched_wrr_param[4];
2522 }
2523
jitiphil8e15ea62018-11-16 18:05:34 +05302524 out_size = 0;
gbian62edd7e2017-03-07 13:12:13 +08002525 }
2526}
2527
Ryan Hsuaadba072018-04-20 13:01:53 -07002528uint32_t hdd_wlan_get_version(struct hdd_context *hdd_ctx,
2529 const size_t version_len, uint8_t *version)
2530{
2531 uint32_t size;
2532 uint32_t msp_id = 0, mspid = 0, siid = 0, crmid = 0, sub_id = 0;
2533
2534 if (!hdd_ctx) {
2535 hdd_err("Invalid context, HDD context is null");
2536 return 0;
2537 }
2538
Ashish Kumar Dhanotiya7353f882018-05-15 12:50:19 +05302539 if (!version || version_len == 0) {
Ryan Hsuaadba072018-04-20 13:01:53 -07002540 hdd_err("Invalid buffer pointr or buffer len\n");
2541 return 0;
2542 }
2543
2544 msp_id = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
2545 mspid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
2546 siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
2547 crmid = hdd_ctx->target_fw_version & 0x7fff;
2548 sub_id = (hdd_ctx->target_fw_vers_ext & 0xf0000000) >> 28;
2549
2550 size = scnprintf(version, version_len,
Ryan Hsuc6918552018-05-16 13:29:59 -07002551 "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 -07002552 QWLAN_VERSIONSTR,
2553 msp_id, mspid, siid, crmid, sub_id,
Ryan Hsuc6918552018-05-16 13:29:59 -07002554 hdd_ctx->target_hw_name,
2555 hdd_ctx->hw_bd_info.bdf_version,
2556 hdd_ctx->hw_bd_info.ref_design_id,
2557 hdd_ctx->hw_bd_info.customer_id,
2558 hdd_ctx->hw_bd_info.project_id,
2559 hdd_ctx->hw_bd_info.board_data_rev);
Ryan Hsuaadba072018-04-20 13:01:53 -07002560
2561 return size;
2562}
2563
Rachit Kankane0dc3e852018-05-07 17:33:42 +05302564int hdd_set_11ax_rate(struct hdd_adapter *adapter, int set_value,
2565 struct sap_config *sap_config)
2566{
2567 uint8_t preamble = 0, nss = 0, rix = 0;
2568 int ret;
2569 mac_handle_t mac_handle = adapter->hdd_ctx->mac_handle;
2570
2571 if (!sap_config) {
2572 if (!sme_is_feature_supported_by_fw(DOT11AX)) {
2573 hdd_err("Target does not support 11ax");
2574 return -EIO;
2575 }
2576 } else if (sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax &&
2577 sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax_ONLY) {
2578 hdd_err("Invalid hw mode, SAP hw_mode= 0x%x, ch = %d",
2579 sap_config->SapHw_mode, sap_config->channel);
2580 return -EIO;
2581 }
2582
2583 if (set_value != 0xff) {
2584 rix = RC_2_RATE_IDX_11AX(set_value);
2585 preamble = WMI_RATE_PREAMBLE_HE;
2586 nss = HT_RC_2_STREAMS_11AX(set_value);
2587
2588 set_value = hdd_assemble_rate_code(preamble, nss, rix);
2589 } else {
2590 ret = sme_set_auto_rate_he_ltf(mac_handle, adapter->session_id,
2591 QCA_WLAN_HE_LTF_AUTO);
2592 }
2593
2594 hdd_info("SET_11AX_RATE val %d rix %d preamble %x nss %d",
2595 set_value, rix, preamble, nss);
2596
2597 ret = wma_cli_set_command(adapter->session_id,
2598 WMI_VDEV_PARAM_FIXED_RATE,
2599 set_value, VDEV_CMD);
2600
2601 return ret;
2602}
2603
2604int hdd_assemble_rate_code(uint8_t preamble, uint8_t nss, uint8_t rate)
2605{
2606 int set_value;
2607
2608 if (sme_is_feature_supported_by_fw(DOT11AX))
2609 set_value = WMI_ASSEMBLE_RATECODE_V1(rate, nss, preamble);
2610 else
2611 set_value = (preamble << 6) | (nss << 4) | rate;
2612
2613 return set_value;
2614}
2615
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002616#ifdef FEATURE_WLAN_WAPI
2617/**
2618 * hdd_wapi_security_sta_exist() - return wapi security sta exist or not
2619 *
2620 * This API returns the wapi security station exist or not
2621 *
2622 * Return: true - wapi security station exist
2623 */
2624static bool hdd_wapi_security_sta_exist(void)
2625{
2626 struct hdd_adapter *adapter = NULL;
2627 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2628
2629 hdd_for_each_adapter(hdd_ctx, adapter) {
2630 if ((adapter->device_mode == QDF_STA_MODE) &&
2631 adapter->wapi_info.wapi_mode &&
2632 (adapter->wapi_info.wapi_auth_mode != WAPI_AUTH_MODE_OPEN))
2633 return true;
2634 }
2635 return false;
2636}
2637#else
2638static bool hdd_wapi_security_sta_exist(void)
2639{
2640 return false;
2641}
2642#endif
2643
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002644#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002645static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2646 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2647{
Jeff Johnson9d295242017-08-29 14:39:48 -07002648 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002649 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002650
2651 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2652 if (!adapter) {
2653 hdd_err("Adapter is NULL");
2654 return PM_MAX_NUM_OF_MODE;
2655 }
2656
2657 return policy_mgr_convert_device_mode_to_qdf_type(
2658 adapter->device_mode);
2659}
2660
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002661static void hdd_register_policy_manager_callback(
2662 struct wlan_objmgr_psoc *psoc)
2663{
2664 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002665
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002666 qdf_mem_zero(&hdd_cbacks, sizeof(hdd_cbacks));
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002667 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002668 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002669 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2670 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002671 hdd_cbacks.get_mode_for_non_connected_vdev =
2672 wlan_hdd_get_mode_for_non_connected_vdev;
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05302673 hdd_cbacks.hdd_get_device_mode = hdd_get_device_mode;
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002674 hdd_cbacks.hdd_wapi_security_sta_exist =
2675 hdd_wapi_security_sta_exist;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002676 if (QDF_STATUS_SUCCESS !=
2677 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2678 hdd_err("HDD callback registration with policy manager failed");
2679 }
2680}
2681#else
2682static void hdd_register_policy_manager_callback(
2683 struct wlan_objmgr_psoc *psoc)
2684{
2685}
2686#endif
2687
jiadff1ac132018-11-26 16:27:48 +08002688#ifdef WLAN_FEATURE_NAN_DATAPATH
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002689static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002690{
2691 struct nan_callbacks cb_obj = {0};
2692
2693 cb_obj.ndi_open = hdd_ndi_open;
2694 cb_obj.ndi_close = hdd_ndi_close;
2695 cb_obj.ndi_start = hdd_ndi_start;
2696 cb_obj.ndi_delete = hdd_ndi_delete;
2697 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2698 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2699
Naveen Rawat37f62c82017-03-26 22:24:43 -07002700 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2701 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002702 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002703
Dustin Brown1dbefe62018-09-11 16:32:03 -07002704 os_if_nan_register_hdd_callbacks(hdd_ctx->psoc, &cb_obj);
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002705}
jiadff1ac132018-11-26 16:27:48 +08002706#else
2707static inline void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
2708{
2709}
2710#endif
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002711
Dustin Brown26b3d042017-12-21 11:13:27 -08002712#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002713/**
2714 * hdd_check_for_leaks() - Perform runtime memory leak checks
Dustin Browna6246dd2018-05-24 14:35:58 -07002715 * @hdd_ctx: the global HDD context
Dustin Brown29533f22018-07-24 13:11:56 -07002716 * @is_ssr: true if SSR is in progress
Dustin Brown4c5b9902017-12-19 11:17:19 -08002717 *
2718 * This API triggers runtime memory leak detection. This feature enforces the
2719 * policy that any memory allocated at runtime must also be released at runtime.
2720 *
2721 * Allocating memory at runtime and releasing it at unload is effectively a
2722 * memory leak for configurations which never unload (e.g. LONU, statically
2723 * compiled driver). Such memory leaks are NOT false positives, and must be
2724 * fixed.
2725 *
2726 * Return: None
2727 */
Dustin Brown29533f22018-07-24 13:11:56 -07002728static void hdd_check_for_leaks(struct hdd_context *hdd_ctx, bool is_ssr)
Dustin Brown4bc0a622017-12-06 15:56:50 -08002729{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002730 /* DO NOT REMOVE these checks; for false positives, read above first */
2731
Dustin Brown1dbefe62018-09-11 16:32:03 -07002732 wlan_objmgr_psoc_check_for_peer_leaks(hdd_ctx->psoc);
2733 wlan_objmgr_psoc_check_for_vdev_leaks(hdd_ctx->psoc);
2734 wlan_objmgr_psoc_check_for_pdev_leaks(hdd_ctx->psoc);
Dustin Brown29533f22018-07-24 13:11:56 -07002735
2736 /* many adapter resources are not freed by design during SSR */
2737 if (is_ssr)
2738 return;
2739
Dustin Brown677e0862017-10-10 16:30:09 -07002740 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002741 qdf_nbuf_map_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002742 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002743}
2744
Dustin Brown26b3d042017-12-21 11:13:27 -08002745#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2746#else
Dustin Brown29533f22018-07-24 13:11:56 -07002747static inline void hdd_check_for_leaks(struct hdd_context *hdd_ctx, bool is_ssr)
2748{ }
Dustin Brown26b3d042017-12-21 11:13:27 -08002749
2750#define hdd_debug_domain_set(domain)
2751#endif /* CONFIG_LEAK_DETECTION */
2752
gbian62edd7e2017-03-07 13:12:13 +08002753/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002754 * hdd_update_country_code - Update country code
2755 * @hdd_ctx: HDD context
2756 *
2757 * Update country code based on module parameter country_code
2758 *
2759 * Return: 0 on success and errno on failure
2760 */
2761static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2762{
2763 if (!country_code)
2764 return 0;
2765
2766 return hdd_reg_set_country(hdd_ctx, country_code);
2767}
2768
Dustin Browne7e71d32018-05-11 16:00:08 -07002769int hdd_wlan_start_modules(struct hdd_context *hdd_ctx, bool reinit)
Arun Khandavallifae92942016-08-01 13:31:08 +05302770{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002771 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302772 qdf_device_t qdf_dev;
2773 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302774 bool unint = false;
2775 void *hif_ctx;
Jingxiang Ge95912f82018-04-19 12:01:26 +08002776 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +05302777
Arun Khandavallifae92942016-08-01 13:31:08 +05302778 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2779 if (!qdf_dev) {
2780 hdd_err("QDF Device Context is Invalid return");
2781 return -EINVAL;
2782 }
2783
Dustin Brown4c663222018-10-23 14:19:36 -07002784 hdd_psoc_idle_timer_stop(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302785
Dustin Brown1fe30a82017-10-03 16:13:36 -07002786 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302787 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2788 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002789 hdd_debug("Driver modules already Enabled");
Dustin Browne74003f2018-03-14 12:51:58 -07002790 hdd_exit();
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302791 return 0;
2792 }
2793
Dustin Brown1fe30a82017-10-03 16:13:36 -07002794 hdd_ctx->start_modules_in_progress = true;
2795
Arun Khandavallifae92942016-08-01 13:31:08 +05302796 switch (hdd_ctx->driver_status) {
2797 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002798 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302799 unint = true;
2800 /* Fall through dont add break here */
2801 case DRIVER_MODULES_CLOSED:
Dustin Brown1a20b082018-08-03 17:27:15 -07002802 hdd_info("Wlan transitioning (CLOSED -> ENABLED)");
Dustin Brown550f6d22017-12-14 15:44:01 -08002803
Dustin Brown26b3d042017-12-21 11:13:27 -08002804 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002805
Arun Khandavallifae92942016-08-01 13:31:08 +05302806 if (!reinit && !unint) {
2807 ret = pld_power_on(qdf_dev->dev);
2808 if (ret) {
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002809 hdd_err("Failed to power up device; errno:%d",
Dustin Browndca39692017-11-09 15:30:25 -08002810 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302811 goto release_lock;
2812 }
2813 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002814
2815 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2816 hdd_ctx->config->enable_fw_log);
Arun Khandavallifae92942016-08-01 13:31:08 +05302817 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2818 qdf_dev->bus_type,
2819 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2820 HIF_ENABLE_TYPE_PROBE);
2821 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002822 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302823 goto power_down;
2824 }
2825
2826 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302827 if (!hif_ctx) {
2828 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002829 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302830 goto power_down;
2831 }
2832
Arun Khandavallifae92942016-08-01 13:31:08 +05302833 status = ol_cds_init(qdf_dev, hif_ctx);
2834 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002835 hdd_err("No Memory to Create BMI Context; status: %d",
2836 status);
2837 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302838 goto hif_close;
2839 }
2840
jitiphil4c256a32018-09-07 08:51:52 +05302841 ucfg_ipa_component_config_update(hdd_ctx->psoc);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302842
gbian62edd7e2017-03-07 13:12:13 +08002843 hdd_update_cds_ac_specs_params(hdd_ctx);
2844
Dustin Brown1dbefe62018-09-11 16:32:03 -07002845 status = hdd_component_psoc_open(hdd_ctx->psoc);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05302846 if (QDF_IS_STATUS_ERROR(status)) {
2847 hdd_err("Failed to Open legacy components; status: %d",
2848 status);
2849 ret = qdf_status_to_os_return(status);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05302850 goto cds_free;
2851 }
2852
2853 ret = hdd_update_config(hdd_ctx);
2854 if (ret) {
2855 hdd_err("Failed to update configuration; errno: %d",
2856 ret);
2857 goto cds_free;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05302858 }
2859
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +05302860 status = wbuff_module_init();
2861 if (QDF_IS_STATUS_ERROR(status))
2862 hdd_err("WBUFF init unsuccessful; status: %d", status);
2863
Dustin Brown1dbefe62018-09-11 16:32:03 -07002864 status = cds_open(hdd_ctx->psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002865 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002866 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002867 ret = qdf_status_to_os_return(status);
Krunal Sonie71838d2018-09-27 10:45:05 -07002868 goto psoc_close;
Arun Khandavallifae92942016-08-01 13:31:08 +05302869 }
2870
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +05302871 hdd_ctx->mac_handle = cds_get_context(QDF_MODULE_ID_SME);
2872
Manjunathappa Prakashb6b4ff12018-06-04 12:32:33 -07002873 if (hdd_ctx->config->rx_thread_affinity_mask)
2874 cds_set_rx_thread_cpu_mask(
2875 hdd_ctx->config->rx_thread_affinity_mask);
2876
2877 /* initialize components configurations after psoc open */
Mukul Sharma9d797a02017-01-05 20:26:03 +05302878 ret = hdd_update_components_config(hdd_ctx);
2879 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002880 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302881 ret);
2882 goto close;
2883 }
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302884
Dustin Brown1dbefe62018-09-11 16:32:03 -07002885 status = cds_dp_open(hdd_ctx->psoc);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002886 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002887 hdd_err("Failed to Open cds post open; status: %d",
2888 status);
2889 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002890 goto close;
2891 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302892
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302893 ret = hdd_register_cb(hdd_ctx);
2894 if (ret) {
2895 hdd_err("Failed to register HDD callbacks!");
2896 goto cds_txrx_free;
2897 }
2898
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002899 /*
2900 * NAN compoenet requires certian operations like, open adapter,
2901 * close adapter, etc. to be initiated by HDD, for those
2902 * register HDD callbacks with UMAC's NAN componenet.
2903 */
2904 hdd_nan_register_callbacks(hdd_ctx);
2905
Jeff Johnson3a280122017-09-13 07:42:00 -07002906 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302907 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002908 hdd_err("Failed to pre-enable CDS; status: %d", status);
2909 ret = qdf_status_to_os_return(status);
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302910 goto deregister_cb;
Arun Khandavallifae92942016-08-01 13:31:08 +05302911 }
2912
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002913 hdd_register_policy_manager_callback(
Dustin Brown1dbefe62018-09-11 16:32:03 -07002914 hdd_ctx->psoc);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002915
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302916 hdd_sysfs_create_driver_root_obj();
Dustin Brown1dbefe62018-09-11 16:32:03 -07002917 hdd_sysfs_create_version_interface(hdd_ctx->psoc);
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302918 hdd_sysfs_create_powerstats_interface();
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302919 hdd_update_hw_sw_info(hdd_ctx);
Dustin Brown550f6d22017-12-14 15:44:01 -08002920
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302921 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2922 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002923 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302924 break;
2925 }
Dustin Browndca39692017-11-09 15:30:25 -08002926
Dustin Browne7e71d32018-05-11 16:00:08 -07002927 ret = hdd_configure_cds(hdd_ctx);
Dustin Browndca39692017-11-09 15:30:25 -08002928 if (ret) {
2929 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302930 goto destroy_driver_sysfs;
Arun Khandavallifae92942016-08-01 13:31:08 +05302931 }
Dustin Browndca39692017-11-09 15:30:25 -08002932
Komal Seelamf2136bb2016-09-28 18:30:44 +05302933 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002934
Arun Khandavallifae92942016-08-01 13:31:08 +05302935 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002936
Arun Khandavallifae92942016-08-01 13:31:08 +05302937 default:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002938 QDF_DEBUG_PANIC("Unknown driver state:%d",
Arun Khandavallifae92942016-08-01 13:31:08 +05302939 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002940 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302941 goto release_lock;
2942 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002943
Dustin Brown1a20b082018-08-03 17:27:15 -07002944 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2945 hdd_info("Wlan transitioned (now ENABLED)");
2946
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302947 hdd_ctx->start_modules_in_progress = false;
Dustin Brownad698ae2018-09-05 17:19:30 -07002948
Arun Khandavallifae92942016-08-01 13:31:08 +05302949 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002950
Dustin Browne74003f2018-03-14 12:51:58 -07002951 hdd_exit();
Dustin Brown550f6d22017-12-14 15:44:01 -08002952
Arun Khandavallifae92942016-08-01 13:31:08 +05302953 return 0;
2954
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302955destroy_driver_sysfs:
2956 hdd_sysfs_destroy_powerstats_interface();
2957 hdd_sysfs_destroy_version_interface();
2958 hdd_sysfs_destroy_driver_root_obj();
Rajeev Kumarbe021242017-02-16 16:12:23 -08002959 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002960
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302961deregister_cb:
2962 hdd_deregister_cb(hdd_ctx);
2963
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002964cds_txrx_free:
Dustin Brown1dbefe62018-09-11 16:32:03 -07002965 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->psoc);
Jingxiang Ge95912f82018-04-19 12:01:26 +08002966
2967 if (tgt_hdl && target_psoc_get_wmi_ready(tgt_hdl)) {
2968 hdd_runtime_suspend_context_deinit(hdd_ctx);
Dustin Brown07901ec2018-09-07 11:02:41 -07002969 dispatcher_pdev_close(hdd_ctx->pdev);
Jingxiang Ge95912f82018-04-19 12:01:26 +08002970 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
2971 }
2972
Dustin Brown1dbefe62018-09-11 16:32:03 -07002973 cds_dp_close(hdd_ctx->psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08002974
Arun Khandavallifae92942016-08-01 13:31:08 +05302975close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002976 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002977 hdd_info("Wlan transition aborted (now CLOSED)");
2978
Dustin Brown1dbefe62018-09-11 16:32:03 -07002979 cds_close(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302980
Krunal Sonie71838d2018-09-27 10:45:05 -07002981psoc_close:
Dustin Brown1dbefe62018-09-11 16:32:03 -07002982 hdd_component_psoc_close(hdd_ctx->psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002983 cds_deinit_ini_config();
2984
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002985cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302986 ol_cds_free();
2987
2988hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002989 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2990 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302991power_down:
2992 if (!reinit && !unint)
2993 pld_power_off(qdf_dev->dev);
2994release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302995 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302996 mutex_unlock(&hdd_ctx->iface_change_lock);
Abhinav Kumar7ae9b7b2017-12-19 15:11:54 +05302997 if (hdd_ctx->target_hw_name) {
2998 qdf_mem_free(hdd_ctx->target_hw_name);
2999 hdd_ctx->target_hw_name = NULL;
3000 }
Dustin Brown29533f22018-07-24 13:11:56 -07003001
3002 hdd_check_for_leaks(hdd_ctx, reinit);
Dustin Brown26b3d042017-12-21 11:13:27 -08003003 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08003004
Dustin Browne74003f2018-03-14 12:51:58 -07003005 hdd_exit();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08003006
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07003007 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05303008}
3009
Naveen Rawat910726a2017-03-06 11:42:51 -08003010#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003011static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003012{
3013 int ret = os_if_wifi_pos_register_nl();
3014
3015 if (ret)
3016 hdd_err("os_if_wifi_pos_register_nl failed");
3017
3018 return ret;
3019}
3020
3021static int hdd_deactivate_wifi_pos(void)
3022{
3023 int ret = os_if_wifi_pos_deregister_nl();
3024
3025 if (ret)
3026 hdd_err("os_if_wifi_pos_deregister_nl failed");
3027
3028 return ret;
3029}
3030
3031/**
3032 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
3033 * @hdd_ctx: hdd context
3034 *
3035 * Return: status of operation
3036 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003037static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003038{
Dustin Brown1dbefe62018-09-11 16:32:03 -07003039 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Wu Gao1ab05582018-11-08 16:22:49 +08003040 uint16_t neighbor_scan_max_chan_time;
3041 uint16_t neighbor_scan_min_chan_time;
Naveen Rawat910726a2017-03-06 11:42:51 -08003042
3043 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
3044 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
3045 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
3046 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
3047 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
3048 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
Wu Gao1ab05582018-11-08 16:22:49 +08003049 ucfg_mlme_get_neighbor_scan_max_chan_time(psoc,
3050 &neighbor_scan_max_chan_time);
3051 ucfg_mlme_get_neighbor_scan_min_chan_time(psoc,
3052 &neighbor_scan_min_chan_time);
3053 wifi_pos_set_dwell_time_min(psoc, neighbor_scan_min_chan_time);
3054 wifi_pos_set_dwell_time_max(psoc, neighbor_scan_max_chan_time);
Naveen Rawat910726a2017-03-06 11:42:51 -08003055}
3056#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003057static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003058{
3059 return oem_activate_service(hdd_ctx);
3060}
3061
3062static int hdd_deactivate_wifi_pos(void)
3063{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05303064 return oem_deactivate_service();
Naveen Rawat910726a2017-03-06 11:42:51 -08003065}
3066
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003067static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003068{
3069}
3070#endif
3071
Arun Khandavallifae92942016-08-01 13:31:08 +05303072/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003073 * __hdd_open() - HDD Open function
3074 * @dev: Pointer to net_device structure
3075 *
3076 * This is called in response to ifconfig up
3077 *
3078 * Return: 0 for success; non-zero for failure
3079 */
3080static int __hdd_open(struct net_device *dev)
3081{
Jeff Johnson9d295242017-08-29 14:39:48 -07003082 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003083 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003084 int ret;
3085
Dustin Brownfdf17c12018-03-14 12:55:34 -07003086 hdd_enter_dev(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303087 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003088 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003089
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05303090 /* Nothing to be done if device is unloading */
3091 if (cds_is_driver_unloading()) {
3092 hdd_err("Driver is unloading can not open the hdd");
3093 return -EBUSY;
3094 }
3095
Dustin Brown01847752017-10-25 13:56:27 -07003096 if (cds_is_driver_recovering()) {
3097 hdd_err("WLAN is currently recovering; Please try again.");
3098 return -EBUSY;
3099 }
3100
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05303101 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
3102 hdd_err("con_mode_handler is in progress; Please try again.");
3103 return -EBUSY;
3104 }
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303105
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05303106 mutex_lock(&hdd_init_deinit_lock);
Jeff Johnson5794d4f2018-12-04 11:57:09 -08003107 hdd_start_driver_ops_timer(HDD_DRV_OP_IFF_UP);
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05303108
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303109 /*
3110 * This scenario can be hit in cases where in the wlan driver after
3111 * registering the netdevices and there is a failure in driver
3112 * initialization. So return error gracefully because the netdevices
3113 * will be de-registered as part of the load failure.
3114 */
3115
3116 if (!cds_is_driver_loaded()) {
3117 hdd_err("Failed to start the wlan driver!!");
3118 ret = -EIO;
3119 goto err_hdd_hdd_init_deinit_lock;
3120 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303121
Dustin Brown3ecc8782018-09-19 16:37:13 -07003122 ret = hdd_psoc_idle_restart(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05303123 if (ret) {
3124 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303125 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05303126 }
3127
Arun Khandavallifae92942016-08-01 13:31:08 +05303128 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3129 ret = hdd_start_adapter(adapter);
3130 if (ret) {
3131 hdd_err("Failed to start adapter :%d",
3132 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303133 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05303134 }
3135 }
3136
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003137 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3138 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003139 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003140 /* Enable TX queues only when we are connected */
3141 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05303142 WLAN_START_ALL_NETIF_QUEUE,
3143 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003144 }
3145
Naveen Rawat286def52016-09-23 15:38:02 -07003146 /* Enable carrier and transmit queues for NDI */
3147 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003148 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07003149 wlan_hdd_netif_queue_control(adapter,
3150 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
3151 WLAN_CONTROL_PATH);
3152 }
3153
Naveen Rawat910726a2017-03-06 11:42:51 -08003154 hdd_populate_wifi_pos_cfg(hdd_ctx);
Arunk Khandavalli40943af2017-05-15 19:25:34 +05303155 hdd_lpass_notify_start(hdd_ctx, adapter);
Naveen Rawat910726a2017-03-06 11:42:51 -08003156
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303157err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05303158 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303159 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003160 return ret;
3161}
3162
Arun Khandavallifae92942016-08-01 13:31:08 +05303163
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003164/**
3165 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
3166 * @dev: Pointer to net_device structure
3167 *
3168 * This is called in response to ifconfig up
3169 *
3170 * Return: 0 for success; non-zero for failure
3171 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003172static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003173{
3174 int ret;
3175
3176 cds_ssr_protect(__func__);
3177 ret = __hdd_open(dev);
3178 cds_ssr_unprotect(__func__);
3179
3180 return ret;
3181}
3182
3183/**
3184 * __hdd_stop() - HDD stop function
3185 * @dev: Pointer to net_device structure
3186 *
3187 * This is called in response to ifconfig down
3188 *
3189 * Return: 0 for success; non-zero for failure
3190 */
3191static int __hdd_stop(struct net_device *dev)
3192{
Jeff Johnson9d295242017-08-29 14:39:48 -07003193 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003194 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003195 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -07003196 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003197
Dustin Brownfdf17c12018-03-14 12:55:34 -07003198 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003199
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303200 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003201 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003202
3203 ret = wlan_hdd_validate_context(hdd_ctx);
Arunk Khandavalli987c8d52018-06-21 17:40:31 +05303204 if (ret) {
3205 set_bit(DOWN_DURING_SSR, &adapter->event_flags);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003206 return ret;
Arunk Khandavalli987c8d52018-06-21 17:40:31 +05303207 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003208
3209 /* Nothing to be done if the interface is not opened */
3210 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003211 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003212 return -ENODEV;
3213 }
3214
3215 /* Make sure the interface is marked as closed */
3216 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303217
Jeff Johnson16528362018-06-14 12:34:16 -07003218 mac_handle = hdd_ctx->mac_handle;
3219
Mukul Sharmad16c2022017-07-25 18:56:12 +05303220 hdd_debug("Disabling Auto Power save timer");
3221 sme_ps_disable_auto_ps_timer(
Jeff Johnson16528362018-06-14 12:34:16 -07003222 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003223 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303224
3225 /*
3226 * Disable TX on the interface, after this hard_start_xmit() will not
3227 * be called on that interface
3228 */
Dustin Browna7bb6ae2018-08-16 16:51:50 -07003229 hdd_debug("Disabling queues, adapter device mode: %s(%d)",
Dustin Brown458027c2018-10-19 12:26:27 -07003230 qdf_opmode_str(adapter->device_mode), adapter->device_mode);
Kabilan Kannan8dac3502017-10-30 12:40:27 -07003231
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303232 wlan_hdd_netif_queue_control(adapter,
3233 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3234 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003235
Arunk Khandavalli40943af2017-05-15 19:25:34 +05303236 if (adapter->device_mode == QDF_STA_MODE)
3237 hdd_lpass_notify_stop(hdd_ctx);
3238
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003239 /*
Naveen Rawat286def52016-09-23 15:38:02 -07003240 * NAN data interface is different in some sense. The traffic on NDI is
3241 * bursty in nature and depends on the need to transfer. The service
3242 * layer may down the interface after the usage and up again when
3243 * required. In some sense, the NDI is expected to be available
3244 * (like SAP) iface until NDI delete request is issued by the service
3245 * layer. Skip BSS termination and adapter deletion for NAN Data
3246 * interface (NDI).
3247 */
3248 if (WLAN_HDD_IS_NDI(adapter))
3249 return 0;
3250
3251 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003252 * The interface is marked as down for outside world (aka kernel)
3253 * But the driver is pretty much alive inside. The driver needs to
3254 * tear down the existing connection on the netdev (session)
3255 * cleanup the data pipes and wait until the control plane is stabilized
3256 * for this interface. The call also needs to wait until the above
3257 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003258 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003259 * That is intentional to be able to scan if it is a STA/P2P interface
3260 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08003261 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003262
3263 /* DeInit the adapter. This ensures datapath cleanup as well */
3264 hdd_deinit_adapter(hdd_ctx, adapter, true);
3265
Dustin Brown4c663222018-10-23 14:19:36 -07003266 if (!hdd_is_any_interface_open(hdd_ctx))
3267 hdd_psoc_idle_timer_start(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05303268
Dustin Browne74003f2018-03-14 12:51:58 -07003269 hdd_exit();
Dustin Brown4c663222018-10-23 14:19:36 -07003270
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003271 return 0;
3272}
3273
3274/**
3275 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3276 * @dev: pointer to net_device structure
3277 *
3278 * This is called in response to ifconfig down
3279 *
3280 * Return: 0 for success and error number for failure
3281 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003282static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003283{
3284 int ret;
3285
3286 cds_ssr_protect(__func__);
3287 ret = __hdd_stop(dev);
3288 cds_ssr_unprotect(__func__);
3289
3290 return ret;
3291}
3292
3293/**
3294 * __hdd_uninit() - HDD uninit function
3295 * @dev: Pointer to net_device structure
3296 *
3297 * This is called during the netdev unregister to uninitialize all data
3298 * associated with the device
3299 *
3300 * Return: None
3301 */
3302static void __hdd_uninit(struct net_device *dev)
3303{
Jeff Johnson9d295242017-08-29 14:39:48 -07003304 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003305 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003306
Dustin Brownfdf17c12018-03-14 12:55:34 -07003307 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003308
3309 do {
3310 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003311 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003312 break;
3313 }
3314
Jeff Johnson399c6272017-08-30 10:51:00 -07003315 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3316 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003317 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003318 break;
3319 }
3320
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003321 if (dev != adapter->dev)
3322 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003323
Jeff Johnson399c6272017-08-30 10:51:00 -07003324 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003325
3326 /* after uninit our adapter structure will no longer be valid */
3327 adapter->dev = NULL;
3328 adapter->magic = 0;
3329 } while (0);
3330
Dustin Browne74003f2018-03-14 12:51:58 -07003331 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003332}
3333
3334/**
3335 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
3336 * @dev: pointer to net_device structure
3337 *
3338 * This is called during the netdev unregister to uninitialize all data
3339 * associated with the device
3340 *
3341 * Return: none
3342 */
3343static void hdd_uninit(struct net_device *dev)
3344{
3345 cds_ssr_protect(__func__);
3346 __hdd_uninit(dev);
3347 cds_ssr_unprotect(__func__);
3348}
3349
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003350static int hdd_open_cesium_nl_sock(void)
3351{
3352#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3353 struct netlink_kernel_cfg cfg = {
3354 .groups = WLAN_NLINK_MCAST_GRP_ID,
3355 .input = NULL
3356 };
3357#endif
3358 int ret = 0;
3359
3360#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3361 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3362#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3363 THIS_MODULE,
3364#endif
3365 &cfg);
3366#else
3367 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3368 WLAN_NLINK_MCAST_GRP_ID,
3369 NULL, NULL, THIS_MODULE);
3370#endif
3371
3372 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003373 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003374 ret = -ECONNREFUSED;
3375 }
3376
3377 return ret;
3378}
3379
3380static void hdd_close_cesium_nl_sock(void)
3381{
3382 if (NULL != cesium_nl_srv_sock) {
3383 netlink_kernel_release(cesium_nl_srv_sock);
3384 cesium_nl_srv_sock = NULL;
3385 }
3386}
3387
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303388void hdd_update_dynamic_mac(struct hdd_context *hdd_ctx,
3389 struct qdf_mac_addr *curr_mac_addr,
3390 struct qdf_mac_addr *new_mac_addr)
3391{
3392 uint8_t i;
3393
3394 hdd_enter();
3395
3396 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303397 if (!qdf_mem_cmp(
3398 curr_mac_addr->bytes,
3399 &hdd_ctx->dynamic_mac_list[i].dynamic_mac.bytes[0],
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303400 sizeof(struct qdf_mac_addr))) {
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303401 qdf_mem_copy(&hdd_ctx->dynamic_mac_list[i].dynamic_mac,
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303402 new_mac_addr->bytes,
3403 sizeof(struct qdf_mac_addr));
3404 break;
3405 }
3406 }
3407
3408 hdd_exit();
3409}
3410
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003411/**
3412 * __hdd_set_mac_address() - set the user specified mac address
3413 * @dev: Pointer to the net device.
3414 * @addr: Pointer to the sockaddr.
3415 *
3416 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003417 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003418 *
3419 * Return: 0 for success, non zero for failure
3420 */
3421static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3422{
Jeff Johnson9d295242017-08-29 14:39:48 -07003423 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303424 struct hdd_adapter *adapter_temp;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003425 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003426 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303427 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003428 int ret;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303429 struct qdf_mac_addr mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003430
Dustin Brownfdf17c12018-03-14 12:55:34 -07003431 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003432
Hanumanth Reddy Pothula5c7a7812018-03-09 12:55:32 +05303433 if (netif_running(dev)) {
3434 hdd_err("On iface up, set mac address change isn't supported");
3435 return -EBUSY;
3436 }
3437
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003438 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3439 ret = wlan_hdd_validate_context(hdd_ctx);
3440 if (0 != ret)
3441 return ret;
3442
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303443 qdf_mem_copy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303444 adapter_temp = hdd_get_adapter_by_macaddr(hdd_ctx, mac_addr.bytes);
3445 if (adapter_temp) {
3446 if (!qdf_str_cmp(adapter_temp->dev->name, dev->name))
3447 return 0;
3448 hdd_err("%s adapter exist with same address " MAC_ADDRESS_STR,
3449 adapter_temp->dev->name,
Ashish Kumar Dhanotiyaf974f332018-04-19 16:03:15 +05303450 MAC_ADDR_ARRAY(mac_addr.bytes));
3451 return -EINVAL;
3452 }
3453
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05303454 qdf_ret_status = wlan_hdd_validate_mac_address(&mac_addr);
3455 if (QDF_IS_STATUS_ERROR(qdf_ret_status))
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303456 return -EINVAL;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303457
Ashish Kumar Dhanotiya8bfef122018-04-18 16:48:27 +05303458 hdd_info("Changing MAC to " MAC_ADDRESS_STR " of the interface %s ",
3459 MAC_ADDR_ARRAY(mac_addr.bytes), dev->name);
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303460
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303461 hdd_update_dynamic_mac(hdd_ctx, &adapter->mac_addr, &mac_addr);
Jeff Johnson1e851a12017-10-28 14:36:12 -07003462 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003463 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3464
Dustin Browne74003f2018-03-14 12:51:58 -07003465 hdd_exit();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303466 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003467}
3468
3469/**
3470 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3471 * function from SSR
3472 * @dev: pointer to net_device structure
3473 * @addr: Pointer to the sockaddr
3474 *
3475 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003476 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003477 *
3478 * Return: 0 for success.
3479 */
3480static int hdd_set_mac_address(struct net_device *dev, void *addr)
3481{
3482 int ret;
3483
3484 cds_ssr_protect(__func__);
3485 ret = __hdd_set_mac_address(dev, addr);
3486 cds_ssr_unprotect(__func__);
3487
3488 return ret;
3489}
3490
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303491static uint8_t *wlan_hdd_get_derived_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003492{
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303493 int i, j;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003494
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303495 i = qdf_ffz(hdd_ctx->derived_intf_addr_mask);
3496 if (i < 0 || i >= hdd_ctx->num_derived_addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003497 return NULL;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303498 qdf_atomic_set_bit(i, &hdd_ctx->derived_intf_addr_mask);
3499 hdd_info("Assigning MAC from derived list" MAC_ADDRESS_STR,
3500 MAC_ADDR_ARRAY(hdd_ctx->derived_mac_addr[i].bytes));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003501
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303502 /* Copy the mac in dynamic mac list at first free position */
3503 for (j = 0; j < QDF_MAX_CONCURRENCY_PERSONA; j++) {
3504 if (qdf_is_macaddr_zero(&hdd_ctx->
3505 dynamic_mac_list[j].dynamic_mac))
3506 break;
3507 }
3508 if (j == QDF_MAX_CONCURRENCY_PERSONA) {
3509 hdd_err("Max interfaces are up");
3510 return NULL;
3511 }
Dustin Brown61cc3932018-10-18 16:12:13 -07003512
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303513 qdf_mem_copy(&hdd_ctx->dynamic_mac_list[j].dynamic_mac.bytes,
3514 &hdd_ctx->derived_mac_addr[i].bytes,
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303515 sizeof(struct qdf_mac_addr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303516 hdd_ctx->dynamic_mac_list[j].is_provisioned_mac = false;
3517 hdd_ctx->dynamic_mac_list[j].bit_position = i;
3518
3519 return hdd_ctx->derived_mac_addr[i].bytes;
3520}
3521
3522static uint8_t *wlan_hdd_get_provisioned_intf_addr(struct hdd_context *hdd_ctx)
3523{
3524 int i, j;
3525
3526 i = qdf_ffz(hdd_ctx->provisioned_intf_addr_mask);
3527 if (i < 0 || i >= hdd_ctx->num_provisioned_addr)
3528 return NULL;
3529 qdf_atomic_set_bit(i, &hdd_ctx->provisioned_intf_addr_mask);
3530 hdd_info("Assigning MAC from provisioned list" MAC_ADDRESS_STR,
3531 MAC_ADDR_ARRAY(hdd_ctx->provisioned_mac_addr[i].bytes));
3532
3533 /* Copy the mac in dynamic mac list at first free position */
3534 for (j = 0; j < QDF_MAX_CONCURRENCY_PERSONA; j++) {
3535 if (qdf_is_macaddr_zero(&hdd_ctx->
3536 dynamic_mac_list[j].dynamic_mac))
3537 break;
3538 }
3539 if (j == QDF_MAX_CONCURRENCY_PERSONA) {
3540 hdd_err("Max interfaces are up");
3541 return NULL;
3542 }
3543
3544 qdf_mem_copy(&hdd_ctx->dynamic_mac_list[j].dynamic_mac.bytes,
3545 &hdd_ctx->provisioned_mac_addr[i].bytes,
3546 sizeof(struct qdf_mac_addr));
3547 hdd_ctx->dynamic_mac_list[j].is_provisioned_mac = true;
3548 hdd_ctx->dynamic_mac_list[j].bit_position = i;
3549 return hdd_ctx->provisioned_mac_addr[i].bytes;
3550}
3551
3552uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx,
3553 enum QDF_OPMODE interface_type)
3554{
3555 uint8_t *mac_addr = NULL;
3556
3557 if (qdf_atomic_test_bit(interface_type,
3558 (unsigned long *)
3559 (&hdd_ctx->config->provisioned_intf_pool)))
3560 mac_addr = wlan_hdd_get_provisioned_intf_addr(hdd_ctx);
3561
3562 if ((!mac_addr) &&
3563 (qdf_atomic_test_bit(interface_type,
3564 (unsigned long *)
3565 (&hdd_ctx->config->derived_intf_pool))))
3566 mac_addr = wlan_hdd_get_derived_intf_addr(hdd_ctx);
3567
3568 if (!mac_addr)
3569 hdd_err("MAC is not available in both the lists");
3570 return mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003571}
3572
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003573void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3574 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003575{
3576 int i;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303577 int mac_pos_in_mask;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003578
Anurag Chouhan6d760662016-02-20 16:05:43 +05303579 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003580 if (!memcmp(releaseAddr,
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303581 hdd_ctx->dynamic_mac_list[i].dynamic_mac.bytes,
3582 QDF_MAC_ADDR_SIZE)) {
3583 mac_pos_in_mask =
3584 hdd_ctx->dynamic_mac_list[i].bit_position;
3585 if (hdd_ctx->dynamic_mac_list[i].is_provisioned_mac) {
3586 qdf_atomic_clear_bit(
3587 mac_pos_in_mask,
3588 &hdd_ctx->
3589 provisioned_intf_addr_mask);
3590 hdd_info("Releasing MAC from provisioned list");
3591 hdd_info(
3592 MAC_ADDRESS_STR,
3593 MAC_ADDR_ARRAY(releaseAddr));
3594 } else {
3595 qdf_atomic_clear_bit(
3596 mac_pos_in_mask, &hdd_ctx->
3597 derived_intf_addr_mask);
3598 hdd_info("Releasing MAC from derived list");
3599 hdd_info(MAC_ADDRESS_STR,
3600 MAC_ADDR_ARRAY(releaseAddr));
3601 }
3602 qdf_zero_macaddr(&hdd_ctx->
3603 dynamic_mac_list[i].dynamic_mac);
3604 hdd_ctx->dynamic_mac_list[i].is_provisioned_mac =
3605 false;
3606 hdd_ctx->dynamic_mac_list[i].bit_position = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003607 break;
3608 }
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303609
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003610 }
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303611 if (i == QDF_MAX_CONCURRENCY_PERSONA)
3612 hdd_err("Releasing non existing MAC" MAC_ADDRESS_STR,
3613 MAC_ADDR_ARRAY(releaseAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003614}
3615
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003616/**
3617 * __hdd_set_multicast_list() - set the multicast address list
3618 * @dev: Pointer to the WLAN device.
3619 * @skb: Pointer to OS packet (sk_buff).
3620 *
3621 * This funciton sets the multicast address list.
3622 *
3623 * Return: None
3624 */
3625static void __hdd_set_multicast_list(struct net_device *dev)
3626{
Jeff Johnson9d295242017-08-29 14:39:48 -07003627 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Dustin Brown0f874482018-06-13 14:39:22 -07003628 int i = 0, errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003629 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003630 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303631 struct pmo_mc_addr_list_params *mc_list_request = NULL;
Dustin Brown1dbefe62018-09-11 16:32:03 -07003632 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303633 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003634
Dustin Brownfdf17c12018-03-14 12:55:34 -07003635 hdd_enter_dev(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303636 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303637 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303638
Dustin Brown0f874482018-06-13 14:39:22 -07003639 errno = wlan_hdd_validate_context(hdd_ctx);
3640 if (errno)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303641 goto out;
3642
Dustin Brown0f874482018-06-13 14:39:22 -07003643 errno = hdd_validate_adapter(adapter);
3644 if (errno)
Dustin Brownc788acb2017-08-01 17:43:51 -07003645 goto out;
3646
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303647 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3648 hdd_err("%s: Driver module is closed", __func__);
Dustin Brown0f874482018-06-13 14:39:22 -07003649 goto out;
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303650 }
3651
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303652 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
Min Liu74a1a502018-10-10 19:59:07 +08003653 if (!mc_list_request)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303654 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003655
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303656 /* Delete already configured multicast address list */
3657 if (adapter->mc_addr_list.mc_cnt > 0) {
Dustin Brown0f874482018-06-13 14:39:22 -07003658 hdd_debug("clear previously configured MC address list");
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303659 hdd_disable_and_flush_mc_addr_list(adapter,
3660 pmo_mc_list_change_notify);
3661 }
3662
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003663 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003664 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303665 hdd_disable_and_flush_mc_addr_list(adapter,
3666 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003667 } else {
3668 mc_count = netdev_mc_count(dev);
Wu Gaod7dd6e42018-10-16 17:22:56 +08003669 if (mc_count > ucfg_pmo_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003670 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Wu Gaod7dd6e42018-10-16 17:22:56 +08003671 ucfg_pmo_max_mc_addr_supported(psoc));
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303672 hdd_disable_and_flush_mc_addr_list(adapter,
3673 pmo_mc_list_change_notify);
stonezdf2bdfd2018-11-20 14:45:06 +08003674 adapter->mc_addr_list.mc_cnt = 0;
Dustin Brown0f874482018-06-13 14:39:22 -07003675 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003676 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003677 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003678 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303679 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003680 if (i == mc_count)
3681 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303682 memset(&(mc_list_request->mc_addr[i].bytes),
3683 0, ETH_ALEN);
3684 memcpy(&(mc_list_request->mc_addr[i].bytes),
3685 ha->addr, ETH_ALEN);
Dustin Brown0f874482018-06-13 14:39:22 -07003686 hdd_debug("mlist[%d] = %pM", i,
3687 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003688 i++;
3689 }
3690 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303691
stonezdf2bdfd2018-11-20 14:45:06 +08003692 adapter->mc_addr_list.mc_cnt = mc_count;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303693 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003694 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303695 mc_list_request->count = mc_count;
Dustin Brown0f874482018-06-13 14:39:22 -07003696
3697 errno = hdd_cache_mc_addr_list(mc_list_request);
3698 if (errno) {
3699 hdd_err("Failed to cache MC address list for vdev %u; errno:%d",
3700 adapter->session_id, errno);
3701 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003702 }
Dustin Brown0f874482018-06-13 14:39:22 -07003703
3704 hdd_enable_mc_addr_filtering(adapter, pmo_mc_list_change_notify);
3705
3706free_req:
3707 qdf_mem_free(mc_list_request);
3708
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303709out:
Dustin Browne74003f2018-03-14 12:51:58 -07003710 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003711}
3712
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303713
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003714/**
3715 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3716 * @dev: pointer to net_device
3717 *
3718 * Return: none
3719 */
3720static void hdd_set_multicast_list(struct net_device *dev)
3721{
3722 cds_ssr_protect(__func__);
3723 __hdd_set_multicast_list(dev);
3724 cds_ssr_unprotect(__func__);
3725}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003726
3727/**
3728 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3729 * @dev: Pointer to the WLAN device.
3730 * @skb: Pointer to OS packet (sk_buff).
3731 *
3732 * This function is registered with the Linux OS for network
3733 * core to decide which queue to use first.
3734 *
3735 * Return: ac, Queue Index/access category corresponding to UP in IP header
3736 */
3737static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3738#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3739 , void *accel_priv
3740#endif
3741#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3742 , select_queue_fallback_t fallback
3743#endif
3744)
3745{
3746 return hdd_wmm_select_queue(dev, skb);
3747}
3748
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003749static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003750 .ndo_open = hdd_open,
3751 .ndo_stop = hdd_stop,
3752 .ndo_uninit = hdd_uninit,
3753 .ndo_start_xmit = hdd_hard_start_xmit,
3754 .ndo_tx_timeout = hdd_tx_timeout,
3755 .ndo_get_stats = hdd_get_stats,
3756 .ndo_do_ioctl = hdd_ioctl,
3757 .ndo_set_mac_address = hdd_set_mac_address,
3758 .ndo_select_queue = hdd_select_queue,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003759 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003760};
3761
Nirav Shah73713f72018-05-17 14:50:41 +05303762#ifdef FEATURE_MONITOR_MODE_SUPPORT
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003763/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003764static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003765 .ndo_open = hdd_mon_open,
3766 .ndo_stop = hdd_stop,
3767 .ndo_get_stats = hdd_get_stats,
3768};
3769
3770/**
3771 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003772 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003773 * Return: None
3774 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003775void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003776{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003777 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003778 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003779 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003780 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003781}
Nirav Shah73713f72018-05-17 14:50:41 +05303782#else
3783void hdd_set_station_ops(struct net_device *dev)
3784{
3785 dev->netdev_ops = &wlan_drv_ops;
3786}
3787#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003788
3789/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003790 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3791 * @hdd_ctx: global hdd context
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003792 * @mac_addr: mac address to assign to the interface
Ryan Hsu07495ea2016-01-21 15:25:39 -08003793 * @name: User-visible name of the interface
3794 *
3795 * hdd adapter pointer would point to the netdev->priv space, this function
Jeff Johnson62018292018-05-06 16:18:35 -07003796 * would retrieve the pointer, and setup the hdd adapter configuration.
Ryan Hsu07495ea2016-01-21 15:25:39 -08003797 *
3798 * Return: the pointer to hdd adapter, otherwise NULL
3799 */
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003800static struct hdd_adapter *
3801hdd_alloc_station_adapter(struct hdd_context *hdd_ctx, tSirMacAddr mac_addr,
3802 unsigned char name_assign_type, const char *name)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003803{
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003804 struct net_device *dev;
3805 struct hdd_adapter *adapter;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003806 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303807 QDF_STATUS qdf_status;
jitiphil377bcc12018-10-05 19:46:08 +05303808 void *soc;
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003809
jitiphil377bcc12018-10-05 19:46:08 +05303810 soc = cds_get_context(QDF_MODULE_ID_SOC);
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003811 /* cfg80211 initialization and registration */
3812 dev = alloc_netdev_mq(sizeof(*adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003813#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003814 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003815#endif
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003816 (cds_get_conparam() == QDF_GLOBAL_MONITOR_MODE ?
3817 hdd_mon_mode_ether_setup : ether_setup),
3818 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003819
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003820 if (!dev) {
3821 hdd_err("Failed to allocate new net_device '%s'", name);
3822 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003823 }
3824
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003825 adapter = netdev_priv(dev);
3826
3827 qdf_mem_zero(adapter, sizeof(*adapter));
3828 sta_ctx = &adapter->session.station;
3829 qdf_mem_set(sta_ctx->conn_info.staId, sizeof(sta_ctx->conn_info.staId),
3830 HDD_WLAN_INVALID_STA_ID);
3831 adapter->dev = dev;
3832 adapter->hdd_ctx = hdd_ctx;
3833 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
3834 adapter->session_id = HDD_SESSION_ID_INVALID;
3835
3836 qdf_status = qdf_event_create(&adapter->qdf_session_open_event);
3837 if (QDF_IS_STATUS_ERROR(qdf_status))
3838 goto free_net_dev;
3839
3840 qdf_status = qdf_event_create(&adapter->qdf_session_close_event);
3841 if (QDF_IS_STATUS_ERROR(qdf_status))
3842 goto free_net_dev;
3843
3844 adapter->offloads_configured = false;
3845 adapter->is_link_up_service_needed = false;
3846 adapter->disconnection_in_progress = false;
3847 adapter->send_mode_change = true;
3848
3849 /* Init the net_device structure */
3850 strlcpy(dev->name, name, IFNAMSIZ);
3851
3852 qdf_mem_copy(dev->dev_addr, mac_addr, sizeof(tSirMacAddr));
3853 qdf_mem_copy(adapter->mac_addr.bytes, mac_addr, sizeof(tSirMacAddr));
3854 dev->watchdog_timeo = HDD_TX_TIMEOUT;
3855
jitiphil377bcc12018-10-05 19:46:08 +05303856 if (cdp_cfg_get(soc,
3857 cfg_dp_enable_ip_tcp_udp_checksum_offload))
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003858 dev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
3859 dev->features |= NETIF_F_RXCSUM;
3860
3861 hdd_set_tso_flags(hdd_ctx, dev);
3862 hdd_set_station_ops(adapter->dev);
3863
3864 hdd_dev_setup_destructor(dev);
3865 dev->ieee80211_ptr = &adapter->wdev;
3866 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
3867 adapter->wdev.wiphy = hdd_ctx->wiphy;
3868 adapter->wdev.netdev = dev;
3869
3870 /* set dev's parent to underlying device */
3871 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
3872 hdd_wmm_init(adapter);
3873 spin_lock_init(&adapter->pause_map_lock);
3874 adapter->start_time = qdf_system_ticks();
3875 adapter->last_time = adapter->start_time;
3876
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003877 return adapter;
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003878
3879free_net_dev:
3880 free_netdev(adapter->dev);
3881
3882 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003883}
3884
Jeff Johnson9d295242017-08-29 14:39:48 -07003885static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003886{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003887 struct net_device *dev = adapter->dev;
3888 int ret;
3889
Dustin Brown491d54b2018-03-14 12:39:11 -07003890 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003891
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003892 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003893 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3894
3895 ret = dev_alloc_name(dev, dev->name);
3896 if (ret < 0) {
3897 hdd_err(
3898 "unable to get dev name: %s, err = 0x%x",
3899 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303900 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003901 }
3902 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003903
3904 ret = register_netdevice(dev);
3905 if (ret) {
3906 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3907 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303908 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003909 }
3910 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003911 ret = register_netdev(dev);
3912 if (ret) {
3913 hdd_err("register_netdev(%s) failed, err = 0x%x",
3914 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303915 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003916 }
3917 }
3918 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3919
Dustin Browne74003f2018-03-14 12:51:58 -07003920 hdd_exit();
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003921
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303922 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003923}
3924
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05303925QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id,
3926 QDF_STATUS qdf_status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003927{
Krunal Sonib51eec72017-11-20 21:53:01 -08003928 struct hdd_adapter *adapter;
3929 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003930
Krunal Sonib51eec72017-11-20 21:53:01 -08003931 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3932 if (!hdd_ctx) {
3933 hdd_err("Invalid HDD_CTX");
3934 return QDF_STATUS_E_FAILURE;
3935 }
3936
3937 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3938 if (NULL == adapter) {
Naveen Rawat23a3b912018-05-30 17:45:52 -07003939 hdd_err("NULL adapter for %d", session_id);
Krunal Sonib51eec72017-11-20 21:53:01 -08003940 return QDF_STATUS_E_INVAL;
3941 }
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05303942
3943 if (qdf_status == QDF_STATUS_SUCCESS)
3944 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3945
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303946 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003947 hdd_debug("session %d opened", adapter->session_id);
3948
3949 return QDF_STATUS_SUCCESS;
3950}
3951
3952QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3953{
3954 struct hdd_adapter *adapter;
3955 struct hdd_context *hdd_ctx;
3956
3957 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3958 if (!hdd_ctx) {
3959 hdd_err("Invalid HDD_CTX");
3960 return QDF_STATUS_E_FAILURE;
3961 }
3962
3963 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003964 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003965 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303966 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003967 }
3968
3969 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003970 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303971 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003972 }
3973
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003974 /*
3975 * For NAN Data interface, the close session results in the final
3976 * indication to the userspace
3977 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003978 if (adapter->device_mode == QDF_NDI_MODE)
3979 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003980
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003981 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3982
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003983 /*
3984 * We can be blocked while waiting for scheduled work to be
3985 * flushed, and the adapter structure can potentially be freed, in
3986 * which case the magic will have been reset. So make sure the
3987 * magic is still good, and hence the adapter structure is still
3988 * valid, before signaling completion
3989 */
3990 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303991 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003992
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303993 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003994}
3995
Jeff Johnson9d295242017-08-29 14:39:48 -07003996int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003997{
Min Liu8c5d99e2018-09-10 17:18:44 +08003998 struct wlan_objmgr_vdev *vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07003999 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004000
Min Liu8c5d99e2018-09-10 17:18:44 +08004001 vdev = hdd_objmgr_get_vdev(adapter);
4002 if (!vdev)
4003 return -EINVAL;
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07004004
Min Liu8c5d99e2018-09-10 17:18:44 +08004005 status = pmo_vdev_ready(vdev);
4006 if (QDF_IS_STATUS_ERROR(status)) {
4007 hdd_objmgr_put_vdev(adapter);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07004008 return qdf_status_to_os_return(status);
Min Liu8c5d99e2018-09-10 17:18:44 +08004009 }
4010
4011 status = ucfg_reg_11d_vdev_created_update(vdev);
4012 if (QDF_IS_STATUS_ERROR(status)) {
4013 hdd_objmgr_put_vdev(adapter);
4014 return qdf_status_to_os_return(status);
4015 }
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07004016
4017 if (wma_capability_enhanced_mcast_filter())
Min Liu8c5d99e2018-09-10 17:18:44 +08004018 status = ucfg_pmo_enhanced_mc_filter_enable(vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07004019 else
Min Liu8c5d99e2018-09-10 17:18:44 +08004020 status = ucfg_pmo_enhanced_mc_filter_disable(vdev);
4021
4022 hdd_objmgr_put_vdev(adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07004023
4024 return qdf_status_to_os_return(status);
4025}
4026
Jeff Johnson9d295242017-08-29 14:39:48 -07004027int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07004028{
4029 QDF_STATUS status;
Dustin Brown2da29eb2018-07-13 14:23:12 -07004030 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004031 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004032 uint8_t vdev_id;
Min Liu8c5d99e2018-09-10 17:18:44 +08004033 struct wlan_objmgr_vdev *vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07004034
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004035 vdev_id = adapter->session_id;
4036 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004037
4038 /* vdev created sanity check */
4039 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Dustin Brown2da29eb2018-07-13 14:23:12 -07004040 hdd_err("vdev %u does not exist", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004041 return -EINVAL;
4042 }
Dustin Brown2da29eb2018-07-13 14:23:12 -07004043
Min Liu8c5d99e2018-09-10 17:18:44 +08004044 vdev = hdd_objmgr_get_vdev(adapter);
4045 if (!vdev)
4046 return -EINVAL;
Ashish Kumar Dhanotiya68ee2e42018-11-19 21:15:14 +05304047
4048 ucfg_pmo_del_wow_pattern(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08004049 status = ucfg_reg_11d_vdev_delete_update(vdev);
Abhishek Singh935e4772018-11-21 14:14:10 +05304050 ucfg_scan_vdev_set_disable(vdev, REASON_VDEV_DOWN);
Min Liu8c5d99e2018-09-10 17:18:44 +08004051 hdd_objmgr_put_vdev(adapter);
Yue Maf9782842017-05-08 12:49:49 -07004052
Dustin Brownd28772b2017-03-17 14:16:07 -07004053 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304054 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07004055 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -07004056 status = sme_close_session(hdd_ctx->mac_handle, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004057 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Brown2da29eb2018-07-13 14:23:12 -07004058 hdd_err("failed to close sme session; status:%d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08004059 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07004060 }
4061
4062 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304063 status = qdf_wait_for_event_completion(
4064 &adapter->qdf_session_close_event,
Abhishek Singh13bf0ce2018-10-24 14:26:14 +05304065 SME_CMD_VDEV_CREATE_DELETE_TIMEOUT);
Dustin Brown2da29eb2018-07-13 14:23:12 -07004066
4067 if (QDF_IS_STATUS_ERROR(status)) {
4068 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
4069
Dustin Brownd28772b2017-03-17 14:16:07 -07004070 if (adapter->device_mode == QDF_NDI_MODE)
4071 hdd_ndp_session_end_handler(adapter);
Dustin Brown2da29eb2018-07-13 14:23:12 -07004072
4073 if (status == QDF_STATUS_E_TIMEOUT)
4074 hdd_err("timed out waiting for sme close session");
4075 else if (adapter->qdf_session_close_event.force_set)
4076 hdd_info("SSR occurred during sme close session");
4077 else
4078 hdd_err("failed to wait for sme close session; status:%u",
4079 status);
Dustin Brownd28772b2017-03-17 14:16:07 -07004080 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08004081
Yue Maf9782842017-05-08 12:49:49 -07004082release_vdev:
Jiachao Wu2c42c222018-01-15 18:13:19 +08004083
Sandeep Puligillaef415362017-08-30 16:37:13 -07004084 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08004085 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07004086 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08004087 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07004088 return errno;
4089 }
4090
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004091 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004092
4093 return 0;
4094}
4095
Krunal Sonib51eec72017-11-20 21:53:01 -08004096static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
4097 struct sme_session_params *session_param,
Jeff Johnson6a18c962018-07-01 09:09:37 -07004098 csr_roam_complete_cb callback,
Krunal Sonib51eec72017-11-20 21:53:01 -08004099 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07004100{
Dustin Brownd28772b2017-03-17 14:16:07 -07004101 uint32_t type;
4102 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08004103 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07004104
4105 /* determine vdev (sub)type */
4106 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304107 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07004108 hdd_err("failed to get vdev type: %d", status);
4109 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004110 }
Krunal Sonib51eec72017-11-20 21:53:01 -08004111 session_param->sme_session_id = adapter->session_id;
4112 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
4113 session_param->type_of_persona = type;
4114 session_param->subtype_of_persona = sub_type;
4115 session_param->session_open_cb = hdd_sme_open_session_callback;
4116 session_param->session_close_cb = hdd_sme_close_session_callback;
4117 session_param->callback = callback;
4118 session_param->callback_ctx = callback_ctx;
4119
4120 return 0;
4121}
4122
gaurank kathpalia78af1932018-10-27 20:33:10 +05304123static void
4124hdd_store_nss_chains_cfg_in_vdev(struct hdd_adapter *adapter)
4125{
4126 struct wlan_mlme_nss_chains vdev_ini_cfg;
4127 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4128
gaurank kathpaliab414bce2018-11-09 18:44:46 +05304129 /* Populate the nss chain params from ini for this vdev type */
gaurank kathpalia78af1932018-10-27 20:33:10 +05304130 sme_populate_nss_chain_params(hdd_ctx->mac_handle, &vdev_ini_cfg,
4131 adapter->device_mode,
4132 hdd_ctx->num_rf_chains);
gaurank kathpaliab414bce2018-11-09 18:44:46 +05304133
4134 /* Store the nss chain config into the vdev */
4135 sme_store_nss_chains_cfg_in_vdev(adapter->vdev, &vdev_ini_cfg);
gaurank kathpalia78af1932018-10-27 20:33:10 +05304136}
gaurank kathpalia6982d472018-10-31 21:54:15 +05304137
4138bool hdd_is_vdev_in_conn_state(struct hdd_adapter *adapter)
4139{
4140 switch (adapter->device_mode) {
4141 case QDF_STA_MODE:
4142 case QDF_P2P_CLIENT_MODE:
4143 case QDF_P2P_DEVICE_MODE:
4144 return hdd_conn_is_connected(
4145 WLAN_HDD_GET_STATION_CTX_PTR(adapter));
4146 case QDF_SAP_MODE:
4147 case QDF_P2P_GO_MODE:
4148 return (test_bit(SOFTAP_BSS_STARTED,
4149 &adapter->event_flags));
4150 default:
4151 hdd_err("Device mode %d invalid", adapter->device_mode);
4152 return 0;
4153 }
4154
4155 return 0;
4156}
4157
Krunal Sonib51eec72017-11-20 21:53:01 -08004158int hdd_vdev_create(struct hdd_adapter *adapter,
Jeff Johnson6a18c962018-07-01 09:09:37 -07004159 csr_roam_complete_cb callback, void *ctx)
Krunal Sonib51eec72017-11-20 21:53:01 -08004160{
4161 QDF_STATUS status;
4162 int errno;
Karthik Kantamneni9180c752018-11-14 12:14:17 +05304163 bool bval;
Krunal Sonib51eec72017-11-20 21:53:01 -08004164 struct hdd_context *hdd_ctx;
4165 struct sme_session_params sme_session_params = {0};
Min Liu8c5d99e2018-09-10 17:18:44 +08004166 struct wlan_objmgr_vdev *vdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004167
4168 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07004169
4170 /* do vdev create via objmgr */
4171 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown07901ec2018-09-07 11:02:41 -07004172 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07004173 if (errno) {
4174 hdd_err("failed to create objmgr vdev: %d", errno);
4175 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004176 }
Dustin Brownd28772b2017-03-17 14:16:07 -07004177
4178 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304179 status = qdf_event_reset(&adapter->qdf_session_open_event);
4180 if (QDF_STATUS_SUCCESS != status) {
4181 hdd_err("failed to reinit session open event");
4182 return -EINVAL;
4183 }
Krunal Sonib51eec72017-11-20 21:53:01 -08004184 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
4185 callback, ctx);
4186 if (errno) {
4187 hdd_err("failed to populating SME params");
4188 goto objmgr_vdev_destroy_procedure;
4189 }
Jeff Johnson16528362018-06-14 12:34:16 -07004190 status = sme_open_session(hdd_ctx->mac_handle, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07004191 if (QDF_IS_STATUS_ERROR(status)) {
4192 hdd_err("failed to open sme session: %d", status);
4193 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07004194 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004195 }
4196
4197 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304198 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
Abhishek Singh13bf0ce2018-10-24 14:26:14 +05304199 SME_CMD_VDEV_CREATE_DELETE_TIMEOUT);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304200 if (QDF_STATUS_SUCCESS != status) {
4201 if (adapter->qdf_session_open_event.force_set) {
4202 /*
4203 * SSR/PDR has caused shutdown, which has forcefully
4204 * set the event. Return without the closing session.
4205 */
4206 adapter->session_id = HDD_SESSION_ID_INVALID;
4207 hdd_err("Session open event forcefully set");
4208 return -EINVAL;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304209 }
Jeff Johnsonc66d3102018-02-28 11:58:26 -08004210
4211 if (QDF_STATUS_E_TIMEOUT == status)
4212 hdd_err("Session failed to open within timeout period");
4213 else
4214 hdd_err("Failed to wait for session open event(status-%d)",
4215 status);
4216 errno = -ETIMEDOUT;
4217 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
4218 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004219 }
4220
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05304221 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
4222 hdd_err("Session failed to open due to vdev create failure");
4223 errno = -EINVAL;
4224 goto objmgr_vdev_destroy_procedure;
4225 }
4226
Dustin Brownd28772b2017-03-17 14:16:07 -07004227 /* firmware ready for component communication, raise vdev_ready event */
4228 errno = hdd_vdev_ready(adapter);
4229 if (errno) {
4230 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07004231 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004232 }
4233
Naveen Rawat2b430892018-03-13 13:58:18 -07004234 if (adapter->device_mode == QDF_STA_MODE) {
Karthik Kantamneni9180c752018-11-14 12:14:17 +05304235 bval = false;
4236 status = ucfg_mlme_get_rtt_mac_randomization(hdd_ctx->psoc,
4237 &bval);
4238 if (QDF_IS_STATUS_ERROR(status))
4239 hdd_err("unable to get RTT MAC randomization value");
4240
4241 hdd_debug("setting RTT mac randomization param: %d", bval);
Naveen Rawat2b430892018-03-13 13:58:18 -07004242 errno = sme_cli_set_command(adapter->session_id,
4243 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_INITIATOR_RANDOM_MAC,
Karthik Kantamneni9180c752018-11-14 12:14:17 +05304244 bval,
Naveen Rawat2b430892018-03-13 13:58:18 -07004245 VDEV_CMD);
4246 if (0 != errno)
4247 hdd_err("RTT mac randomization param set failed %d",
4248 errno);
4249 }
4250
Bala Venkatesh110b03e2018-07-10 16:02:08 +05304251 if (adapter->device_mode == QDF_STA_MODE ||
Min Liu8c5d99e2018-09-10 17:18:44 +08004252 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
4253 vdev = hdd_objmgr_get_vdev(adapter);
4254 if (!vdev)
4255 goto hdd_vdev_destroy_procedure;
4256 wlan_vdev_set_max_peer_count(vdev, HDD_MAX_VDEV_PEER_COUNT);
4257 hdd_objmgr_put_vdev(adapter);
4258 }
Bala Venkatesh110b03e2018-07-10 16:02:08 +05304259
gaurank kathpalia78af1932018-10-27 20:33:10 +05304260 hdd_store_nss_chains_cfg_in_vdev(adapter);
4261
Jeff Johnson1b780e42017-10-31 14:11:45 -07004262 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004263
4264 return 0;
4265
4266 /*
4267 * Due to legacy constraints, we need to destroy in the same order as
4268 * create. So, split error handling into 2 cases to accommodate.
4269 */
4270
Krunal Soni4a020c72017-10-30 20:58:40 -07004271objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07004272 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07004273
4274 return errno;
4275
Krunal Soni4a020c72017-10-30 20:58:40 -07004276hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07004277 QDF_BUG(!hdd_vdev_destroy(adapter));
4278
4279 return errno;
4280}
4281
Jeff Johnson9d295242017-08-29 14:39:48 -07004282QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07004283{
Jeff Johnsonb9424862017-10-30 08:49:35 -07004284 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004285 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07004286 QDF_STATUS status;
4287 int ret_val;
Jeff Johnson16528362018-06-14 12:34:16 -07004288 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304289 bool bval = false;
Dustin Brownd28772b2017-03-17 14:16:07 -07004290
Dustin Brownd28772b2017-03-17 14:16:07 -07004291 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -07004292 mac_handle = hdd_ctx->mac_handle;
4293 sme_set_curr_device_mode(mac_handle, adapter->device_mode);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304294 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
4295 if (!QDF_IS_STATUS_SUCCESS(status))
4296 hdd_err("unable to get vht_enable2x2");
4297 sme_set_pdev_ht_vht_ies(mac_handle, bval);
4298
Jeff Johnson16528362018-06-14 12:34:16 -07004299 sme_set_vdev_ies_per_band(mac_handle, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004300
Jeff Johnson7f2c5912018-03-23 11:42:28 -07004301 hdd_roam_profile_init(adapter);
4302 hdd_register_wext(adapter->dev);
4303
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07004304 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004305
Jeff Johnsond377dce2017-10-04 10:32:42 -07004306 qdf_mem_set(sta_ctx->conn_info.staId,
4307 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05304308
Deepak Dhamdherea2785822016-11-17 01:17:45 -08004309 /* set fast roaming capability in sme session */
Jeff Johnson16528362018-06-14 12:34:16 -07004310 status = sme_config_fast_roaming(mac_handle, adapter->session_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05304311 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004312 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004313 sta_ctx->conn_info.operationChannel =
Vignesh Viswanathana0358ff2018-11-27 09:53:07 +05304314 hdd_ctx->config->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004315
4316 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004317 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004318
4319 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304320 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004321 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004322 status, status);
4323 goto error_init_txrx;
4324 }
4325
4326 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4327
4328 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304329 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004330 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004331 status, status);
4332 goto error_wmm_init;
4333 }
4334
4335 set_bit(WMM_INIT_DONE, &adapter->event_flags);
4336
Jeff Johnson1b780e42017-10-31 14:11:45 -07004337 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004338 WMI_PDEV_PARAM_BURST_ENABLE,
Dundi Raviteja3aa01be2018-05-21 18:58:59 +05304339 HDD_ENABLE_SIFS_BURST_DEFAULT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004340 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07004341 if (ret_val)
4342 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004343
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05304344 /*
4345 * In case of USB tethering, LRO is disabled. If SSR happened
4346 * during that time, then as part of SSR init, do not enable
4347 * the LRO again. Keep the LRO state same as before SSR.
4348 */
jitiphil377bcc12018-10-05 19:46:08 +05304349 if (cdp_cfg_get(cds_get_context(QDF_MODULE_ID_SOC),
4350 cfg_dp_lro_enable) &&
4351 !(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07004352 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05304353
4354 /* rcpi info initialization */
4355 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
4356
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304357 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004358
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004359error_wmm_init:
4360 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4361 hdd_deinit_tx_rx(adapter);
4362error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07004363 hdd_unregister_wext(adapter->dev);
Dustin Brownd28772b2017-03-17 14:16:07 -07004364 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004365
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004366 return status;
4367}
4368
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304369/**
Krunal Soni4a020c72017-10-30 20:58:40 -07004370 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304371 * @hdd_ctx: global hdd context
4372 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07004373 * @rtnl_held: Used to indicate whether or not the caller is holding
4374 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304375 *
4376 * This function De-initializes the STA/P2P/OCB adapter.
4377 *
4378 * Return: None.
4379 */
Krunal Soni4a020c72017-10-30 20:58:40 -07004380static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004381 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004382 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304383{
Dustin Brownfdf17c12018-03-14 12:55:34 -07004384 hdd_enter_dev(adapter->dev);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304385
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05304386 if (adapter->dev) {
4387 if (rtnl_held)
4388 adapter->dev->wireless_handlers = NULL;
4389 else {
4390 rtnl_lock();
4391 adapter->dev->wireless_handlers = NULL;
4392 rtnl_unlock();
4393 }
4394 }
4395
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304396 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
4397 hdd_deinit_tx_rx(adapter);
4398 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4399 }
4400
4401 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4402 hdd_wmm_adapter_close(adapter);
4403 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4404 }
4405
Krunal Sonib51eec72017-11-20 21:53:01 -08004406
Dustin Browne74003f2018-03-14 12:51:58 -07004407 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304408}
4409
Krunal Sonib51eec72017-11-20 21:53:01 -08004410void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
4411 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004412 bool rtnl_held)
4413{
Dustin Brown491d54b2018-03-14 12:39:11 -07004414 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304415
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004416 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004417 case QDF_STA_MODE:
4418 case QDF_P2P_CLIENT_MODE:
4419 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08004420 case QDF_IBSS_MODE:
4421 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004422 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004423 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004424 break;
4425 }
4426
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004427 case QDF_SAP_MODE:
4428 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004429 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004430 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004431 break;
4432 }
4433
4434 default:
4435 break;
4436 }
4437
Dustin Browne74003f2018-03-14 12:51:58 -07004438 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004439}
4440
Min Liu8c5d99e2018-09-10 17:18:44 +08004441static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx,
4442 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004443 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004444{
Jeff Johnson5505db82017-11-02 21:19:23 -07004445 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004446
4447 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07004448 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004449 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004450 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004451 return;
4452 }
4453
Alok Kumarb64650c2018-03-23 17:05:11 +05304454 hdd_nud_deinit_tracking(adapter);
4455 qdf_mutex_destroy(&adapter->disconnection_status_lock);
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05304456 hdd_apf_context_destroy(adapter);
Min Liu8c5d99e2018-09-10 17:18:44 +08004457 qdf_spinlock_destroy(&adapter->vdev_lock);
Alok Kumarb64650c2018-03-23 17:05:11 +05304458
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05304459 wlan_hdd_debugfs_csr_deinit(adapter);
Arunk Khandavallica56d4b2018-11-29 15:46:00 +05304460 if (adapter->device_mode == QDF_STA_MODE)
4461 hdd_sysfs_destroy_adapter_root_obj(adapter);
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05304462
Rajeev Kumardca5f812016-02-04 17:28:06 -08004463 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05304464
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004465 /*
4466 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
4467 * the driver is almost closed and cannot handle either control
4468 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004469 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
4470 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004471 * is not right. Setting this flag helps hdd_stop() to recognize that
4472 * the interface is closed and restricts any operations on that
4473 */
4474 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
4475
4476 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004477 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07004478 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004479 else
Jeff Johnson5505db82017-11-02 21:19:23 -07004480 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004481 /*
4482 * Note that the adapter is no longer valid at this point
4483 * since the memory has been reclaimed
4484 */
4485 }
4486}
4487
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004488static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07004489 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004490{
Jeff Johnson9d295242017-08-29 14:39:48 -07004491 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004492
Dustin Brown920397d2017-12-13 16:27:50 -08004493 hdd_for_each_adapter(hdd_ctx, adapter) {
4494 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
4495 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304496 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004497 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004498 }
Dustin Brown920397d2017-12-13 16:27:50 -08004499
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304500 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004501}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004502
Arun Khandavalli2358d522016-05-16 18:05:37 +05304503#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4504/**
4505 * hdd_set_fw_log_params() - Set log parameters to FW
4506 * @hdd_ctx: HDD Context
4507 * @adapter: HDD Adapter
4508 *
4509 * This function set the FW Debug log level based on the INI.
4510 *
4511 * Return: None
4512 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004513static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004514 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304515{
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304516 QDF_STATUS status;
4517 uint16_t enable_fw_log_level, enable_fw_log_type;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304518 int ret;
4519
Arun Khandavallifae92942016-08-01 13:31:08 +05304520 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4521 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004522 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304523 return;
4524 }
4525
Arun Khandavallifae92942016-08-01 13:31:08 +05304526 /* Enable FW logs based on INI configuration */
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304527 status = ucfg_fwol_get_enable_fw_log_type(hdd_ctx->psoc,
4528 &enable_fw_log_type);
4529 if (QDF_IS_STATUS_ERROR(status))
4530 return;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004531 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304532 WMI_DBGLOG_TYPE,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304533 enable_fw_log_type,
Arun Khandavallifae92942016-08-01 13:31:08 +05304534 DBG_CMD);
4535 if (ret != 0)
4536 hdd_err("Failed to enable FW log type ret %d",
4537 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304538
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304539 status = ucfg_fwol_get_enable_fw_log_level(hdd_ctx->psoc,
4540 &enable_fw_log_level);
4541 if (QDF_IS_STATUS_ERROR(status))
4542 return;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004543 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304544 WMI_DBGLOG_LOG_LEVEL,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304545 enable_fw_log_level,
Arun Khandavallifae92942016-08-01 13:31:08 +05304546 DBG_CMD);
4547 if (ret != 0)
4548 hdd_err("Failed to enable FW log level ret %d",
4549 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304550
lifengfaa83cb2018-11-24 01:53:56 +08004551 sme_enable_fw_module_log_level(hdd_ctx->mac_handle,
4552 adapter->session_id);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304553}
4554#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004555static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004556 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304557{
4558}
4559
4560#endif
4561
4562/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004563 * hdd_configure_chain_mask() - programs chain mask to firmware
4564 * @adapter: HDD adapter
4565 *
4566 * Return: 0 on success or errno on failure
4567 */
4568static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4569{
Naveen Rawat98322472018-03-06 10:29:42 -08004570 QDF_STATUS status;
4571 struct wma_caps_per_phy non_dbs_phy_cap;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004572 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304573 bool enable2x2 = false, enable_bt_chain_sep = false;
Krunal Sonidf29bc42018-11-15 13:26:29 -08004574 uint8_t dual_mac_feature = DISABLE_DBS_CXN_AND_SCAN;
4575
4576 status = ucfg_policy_mgr_get_dual_mac_feature(hdd_ctx->psoc,
4577 &dual_mac_feature);
4578 if (!QDF_IS_STATUS_SUCCESS(status))
4579 hdd_err("unable to get dual mac feature");
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304580
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304581 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &enable2x2);
4582 if (QDF_IS_STATUS_ERROR(status))
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304583 hdd_err("unable to get vht_enable2x2");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004584
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304585 status = ucfg_mlme_get_bt_chain_separation_flag(hdd_ctx->psoc,
4586 &enable_bt_chain_sep);
4587 if (QDF_IS_STATUS_ERROR(status))
4588 hdd_debug("unable to get BT chain separation. using default");
4589
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304590 hdd_debug("enable2x2: %d, lte_coex: %d, disable_DBS: %d",
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304591 enable2x2, hdd_ctx->lte_coex_ant_share,
Krunal Sonidf29bc42018-11-15 13:26:29 -08004592 dual_mac_feature);
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304593 hdd_debug("enable_bt_chain_separation %d", enable_bt_chain_sep);
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004594
Naveen Rawat98322472018-03-06 10:29:42 -08004595 status = wma_get_caps_for_phyidx_hwmode(&non_dbs_phy_cap,
4596 HW_MODE_DBS_NONE,
4597 CDS_BAND_ALL);
4598 if (QDF_IS_STATUS_ERROR(status)) {
4599 hdd_err("couldn't get phy caps. skip chain mask programming");
4600 return qdf_status_to_os_return(status);
4601 }
4602
4603 if (non_dbs_phy_cap.tx_chain_mask_2G < 3 ||
4604 non_dbs_phy_cap.rx_chain_mask_2G < 3 ||
4605 non_dbs_phy_cap.tx_chain_mask_5G < 3 ||
4606 non_dbs_phy_cap.rx_chain_mask_5G < 3) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004607 hdd_debug("firmware not capable. skip chain mask programming");
Naveen Rawat98322472018-03-06 10:29:42 -08004608 return 0;
4609 }
4610
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304611 if (enable2x2 && !enable_bt_chain_sep) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004612 hdd_debug("2x2 enabled. skip chain mask programming");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004613 return 0;
4614 }
4615
Krunal Sonidf29bc42018-11-15 13:26:29 -08004616 if (dual_mac_feature != DISABLE_DBS_CXN_AND_SCAN) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004617 hdd_debug("DBS enabled(%d). skip chain mask programming",
Krunal Sonidf29bc42018-11-15 13:26:29 -08004618 dual_mac_feature);
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004619 return 0;
4620 }
4621
Naveen Rawatdacb5032018-02-08 15:23:24 -08004622 if (hdd_ctx->lte_coex_ant_share) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004623 hdd_debug("lte ant sharing enabled. skip chainmask programming");
Naveen Rawatdacb5032018-02-08 15:23:24 -08004624 return 0;
4625 }
4626
Dustin Brown1dbefe62018-09-11 16:32:03 -07004627 status = ucfg_mlme_configure_chain_mask(hdd_ctx->psoc,
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304628 adapter->session_id);
4629 if (status != QDF_STATUS_SUCCESS)
4630 goto error;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004631
4632 return 0;
4633
4634error:
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304635 hdd_err("WMI PDEV set param failed");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004636 return -EINVAL;
4637}
4638
4639/**
Dundi Raviteja3b637092018-09-12 13:42:50 +05304640 * hdd_send_coex_config_params() - Send coex config params to FW
4641 * @hdd_ctx: HDD context
4642 * @adapter: Primary adapter context
4643 *
4644 * This function is used to send all coex config related params to FW
4645 *
4646 * Return: 0 on success and -EINVAL on failure
4647 */
4648static int hdd_send_coex_config_params(struct hdd_context *hdd_ctx,
4649 struct hdd_adapter *adapter)
4650{
4651 struct coex_config_params coex_cfg_params = {0};
4652 struct wlan_fwol_coex_config config = {0};
Dustin Brown05d81302018-09-11 16:49:22 -07004653 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Dundi Raviteja3b637092018-09-12 13:42:50 +05304654 QDF_STATUS status;
4655
4656 if (!hdd_ctx) {
4657 hdd_err("hdd_ctx is invalid");
4658 goto err;
4659 }
4660
4661 if (!adapter) {
4662 hdd_err("adapter is invalid");
4663 goto err;
4664 }
4665
4666 if (!psoc) {
4667 hdd_err("HDD psoc is invalid");
4668 goto err;
4669 }
4670
4671 status = ucfg_fwol_get_coex_config_params(psoc, &config);
4672 if (QDF_IS_STATUS_ERROR(status)) {
4673 hdd_err("Unable to get coex config params");
4674 goto err;
4675 }
4676
4677 coex_cfg_params.vdev_id = adapter->session_id;
4678 coex_cfg_params.config_type = WMI_COEX_CONFIG_TX_POWER;
4679 coex_cfg_params.config_arg1 = config.max_tx_power_for_btc;
4680
4681 status = sme_send_coex_config_cmd(&coex_cfg_params);
4682 if (QDF_IS_STATUS_ERROR(status)) {
4683 hdd_err("Failed to send coex Tx power");
4684 goto err;
4685 }
4686
4687 coex_cfg_params.config_type = WMI_COEX_CONFIG_HANDOVER_RSSI;
4688 coex_cfg_params.config_arg1 = config.wlan_low_rssi_threshold;
4689
4690 status = sme_send_coex_config_cmd(&coex_cfg_params);
4691 if (QDF_IS_STATUS_ERROR(status)) {
4692 hdd_err("Failed to send coex handover RSSI");
4693 goto err;
4694 }
4695
4696 coex_cfg_params.config_type = WMI_COEX_CONFIG_BTC_MODE;
4697 coex_cfg_params.config_arg1 = config.btc_mode;
4698
4699 status = sme_send_coex_config_cmd(&coex_cfg_params);
4700 if (QDF_IS_STATUS_ERROR(status)) {
4701 hdd_err("Failed to send coex BTC mode");
4702 goto err;
4703 }
4704
4705 coex_cfg_params.config_type = WMI_COEX_CONFIG_ANTENNA_ISOLATION;
4706 coex_cfg_params.config_arg1 = config.antenna_isolation;
4707
4708 status = sme_send_coex_config_cmd(&coex_cfg_params);
4709 if (QDF_IS_STATUS_ERROR(status)) {
4710 hdd_err("Failed to send coex antenna isolation");
4711 goto err;
4712 }
4713
4714 coex_cfg_params.config_type = WMI_COEX_CONFIG_BT_LOW_RSSI_THRESHOLD;
4715 coex_cfg_params.config_arg1 = config.bt_low_rssi_threshold;
4716
4717 status = sme_send_coex_config_cmd(&coex_cfg_params);
4718 if (QDF_IS_STATUS_ERROR(status)) {
4719 hdd_err("Failed to send coex BT low RSSI threshold");
4720 goto err;
4721 }
4722
4723 coex_cfg_params.config_type = WMI_COEX_CONFIG_BT_INTERFERENCE_LEVEL;
4724 coex_cfg_params.config_arg1 = config.bt_interference_low_ll;
4725 coex_cfg_params.config_arg2 = config.bt_interference_low_ul;
4726 coex_cfg_params.config_arg3 = config.bt_interference_medium_ll;
4727 coex_cfg_params.config_arg4 = config.bt_interference_medium_ul;
4728 coex_cfg_params.config_arg5 = config.bt_interference_high_ll;
4729 coex_cfg_params.config_arg6 = config.bt_interference_high_ul;
4730
4731 status = sme_send_coex_config_cmd(&coex_cfg_params);
4732 if (QDF_IS_STATUS_ERROR(status)) {
4733 hdd_err("Failed to send coex BT interference level");
4734 goto err;
4735 }
4736 return 0;
4737err:
4738 return -EINVAL;
4739}
4740
4741/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304742 * hdd_set_fw_params() - Set parameters to firmware
4743 * @adapter: HDD adapter
4744 *
4745 * This function Sets various parameters to fw once the
4746 * adapter is started.
4747 *
4748 * Return: 0 on success or errno on failure
4749 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004750int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304751{
4752 int ret;
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304753 uint16_t upper_brssi_thresh, lower_brssi_thresh, rts_profile;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304754 bool enable_dtim_1chrx;
4755 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004756 struct hdd_context *hdd_ctx;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304757 bool bval = false;
Manikandan Mohand350c192018-11-29 14:01:12 -08004758 uint8_t max_amsdu_len, enable_tx_sch_delay;
4759 uint32_t dtim_sel_diversity, enable_secondary_rate;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304760
Dustin Brownfdf17c12018-03-14 12:55:34 -07004761 hdd_enter_dev(adapter->dev);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304762
4763 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4764 if (!hdd_ctx)
4765 return -EINVAL;
4766
Dustin Brown732ab9c2017-06-15 13:24:09 -07004767 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4768 hdd_debug("FTM Mode is active; nothing to do");
4769 return 0;
4770 }
4771
Manikandan Mohand350c192018-11-29 14:01:12 -08004772 ret = -1;
4773 if (QDF_IS_STATUS_SUCCESS(ucfg_fwol_get_lprx_enable(hdd_ctx->psoc,
4774 &bval))) {
4775 ret = sme_cli_set_command(adapter->session_id,
4776 WMI_PDEV_PARAM_DTIM_SYNTH,
4777 bval, PDEV_CMD);
4778 }
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304779 if (ret) {
4780 hdd_err("Failed to set LPRx");
4781 goto error;
4782 }
4783
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +05304784 ucfg_mlme_get_dtim_selection_diversity(hdd_ctx->psoc,
4785 &dtim_sel_diversity);
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304786
4787 ret = sme_cli_set_command(
4788 adapter->session_id,
4789 WMI_PDEV_PARAM_1CH_DTIM_OPTIMIZED_CHAIN_SELECTION,
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +05304790 dtim_sel_diversity, PDEV_CMD);
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304791 if (ret) {
4792 hdd_err("Failed to set DTIM_OPTIMIZED_CHAIN_SELECTION");
4793 goto error;
4794 }
4795
Manikandan Mohand350c192018-11-29 14:01:12 -08004796 ret = -1;
4797 if (QDF_IS_STATUS_SUCCESS(ucfg_fwol_get_enable_tx_sch_delay(
4798 hdd_ctx->psoc, &enable_tx_sch_delay))) {
4799 ret = sme_cli_set_command(adapter->session_id,
4800 WMI_PDEV_PARAM_TX_SCH_DELAY,
4801 enable_tx_sch_delay, PDEV_CMD);
4802 }
Ashish Kumar Dhanotiya48dac7d2018-03-28 14:59:50 +05304803 if (ret) {
4804 hdd_err("Failed to set WMI_PDEV_PARAM_TX_SCH_DELAY");
4805 goto error;
4806 }
4807
Manikandan Mohand350c192018-11-29 14:01:12 -08004808 ret = -1;
4809 if (QDF_IS_STATUS_SUCCESS(ucfg_fwol_get_enable_secondary_rate(
4810 hdd_ctx->psoc, &enable_secondary_rate))) {
4811 ret = sme_cli_set_command(adapter->session_id,
4812 WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE,
4813 enable_secondary_rate, PDEV_CMD);
4814 }
Ashish Kumar Dhanotiya959b38c2018-04-06 21:07:57 +05304815 if (ret) {
4816 hdd_err("Failed to set WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE");
4817 goto error;
4818 }
4819
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304820 if (adapter->device_mode == QDF_STA_MODE) {
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304821 status = ucfg_get_upper_brssi_thresh(hdd_ctx->psoc,
4822 &upper_brssi_thresh);
4823 if (QDF_IS_STATUS_ERROR(status))
4824 return -EINVAL;
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304825
Jeff Johnson1b780e42017-10-31 14:11:45 -07004826 sme_set_smps_cfg(adapter->session_id,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304827 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4828 upper_brssi_thresh);
4829
4830 status = ucfg_get_lower_brssi_thresh(hdd_ctx->psoc,
4831 &lower_brssi_thresh);
4832 if (QDF_IS_STATUS_ERROR(status))
4833 return -EINVAL;
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304834
Jeff Johnson1b780e42017-10-31 14:11:45 -07004835 sme_set_smps_cfg(adapter->session_id,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304836 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4837 lower_brssi_thresh);
4838
4839 status = ucfg_get_enable_dtim_1chrx(hdd_ctx->psoc,
4840 &enable_dtim_1chrx);
4841 if (QDF_IS_STATUS_ERROR(status))
4842 return -EINVAL;
4843
4844 sme_set_smps_cfg(adapter->session_id,
4845 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4846 enable_dtim_1chrx);
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304847 }
4848
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304849 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
4850 if (!QDF_IS_STATUS_SUCCESS(status))
4851 hdd_err("unable to get vht_enable2x2");
4852
4853 if (bval) {
Dustin Brown732ab9c2017-06-15 13:24:09 -07004854 hdd_debug("configuring 2x2 mode fw params");
4855
Vignesh Viswanathana851d752018-10-03 19:44:38 +05304856 ret = sme_set_cck_tx_fir_override(hdd_ctx->mac_handle,
4857 adapter->session_id);
Dustin Brown732ab9c2017-06-15 13:24:09 -07004858 if (ret) {
4859 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4860 ret);
4861 goto error;
4862 }
Liangwei Dong22810e82018-03-15 03:42:12 -04004863
4864 if (hdd_configure_chain_mask(adapter))
4865 goto error;
Dustin Brown732ab9c2017-06-15 13:24:09 -07004866 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304867#define HDD_DTIM_1CHAIN_RX_ID 0x5
4868#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004869 hdd_debug("configuring 1x1 mode fw params");
4870
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004871 /*
4872 * Disable DTIM 1 chain Rx when in 1x1,
4873 * we are passing two value
4874 * as param_id << 29 | param_value.
4875 * Below param_value = 0(disable)
4876 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004877 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004878 WMI_STA_SMPS_PARAM_CMDID,
4879 HDD_DTIM_1CHAIN_RX_ID <<
4880 HDD_SMPS_PARAM_VALUE_S,
4881 VDEV_CMD);
4882 if (ret) {
4883 hdd_err("DTIM 1 chain set failed %d", ret);
4884 goto error;
4885 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304886
Arun Khandavalli2358d522016-05-16 18:05:37 +05304887#undef HDD_DTIM_1CHAIN_RX_ID
4888#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004889
4890 if (hdd_configure_chain_mask(adapter))
4891 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004892 }
4893
Vignesh Viswanathana851d752018-10-03 19:44:38 +05304894 ret = sme_set_enable_mem_deep_sleep(hdd_ctx->mac_handle,
4895 adapter->session_id);
Dustin Brown732ab9c2017-06-15 13:24:09 -07004896 if (ret) {
4897 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4898 goto error;
4899 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304900
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304901 status = ucfg_fwol_get_rts_profile(hdd_ctx->psoc, &rts_profile);
4902 if (QDF_IS_STATUS_ERROR(status))
4903 return -EINVAL;
4904
Jeff Johnson1b780e42017-10-31 14:11:45 -07004905 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004906 WMI_VDEV_PARAM_ENABLE_RTSCTS,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304907 rts_profile,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004908 VDEV_CMD);
4909 if (ret) {
4910 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4911 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304912 }
4913
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05304914 status = ucfg_mlme_get_max_amsdu_num(hdd_ctx->psoc, &max_amsdu_len);
4915 if (QDF_IS_STATUS_ERROR(status)) {
4916 hdd_err("Failed to get Max AMSDU Num");
4917 goto error;
4918 }
4919
4920 hdd_debug("SET AMSDU num %d", max_amsdu_len);
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004921
Jeff Johnson1b780e42017-10-31 14:11:45 -07004922 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004923 GEN_VDEV_PARAM_AMSDU,
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05304924 max_amsdu_len,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004925 GEN_CMD);
4926 if (ret != 0) {
4927 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4928 goto error;
4929 }
4930
Arun Khandavalli2358d522016-05-16 18:05:37 +05304931 hdd_set_fw_log_params(hdd_ctx, adapter);
Dundi Raviteja3b637092018-09-12 13:42:50 +05304932
4933 ret = hdd_send_coex_config_params(hdd_ctx, adapter);
4934 if (ret) {
4935 hdd_warn("Error initializing coex config params");
4936 goto error;
4937 }
4938
Dustin Browne74003f2018-03-14 12:51:58 -07004939 hdd_exit();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004940
Arun Khandavalli2358d522016-05-16 18:05:37 +05304941 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304942
Arun Khandavalli2358d522016-05-16 18:05:37 +05304943error:
4944 return -EINVAL;
4945}
4946
Ryan Hsu07495ea2016-01-21 15:25:39 -08004947/**
Abhinav Kumarcc959f12018-08-09 13:58:30 +05304948 * hdd_init_completion() - Initialize Completion Variables
4949 * @adapter: HDD adapter
4950 *
4951 * This function Initialize the completion variables for
4952 * a particular adapter
4953 *
4954 * Return: None
4955 */
4956static void hdd_init_completion(struct hdd_adapter *adapter)
4957{
4958 init_completion(&adapter->disconnect_comp_var);
4959 init_completion(&adapter->roaming_comp_var);
4960 init_completion(&adapter->linkup_event_var);
Abhinav Kumarcc959f12018-08-09 13:58:30 +05304961 init_completion(&adapter->sta_authorized_event);
4962 init_completion(&adapter->offchannel_tx_event);
4963 init_completion(&adapter->tx_action_cnf_event);
4964 init_completion(&adapter->ibss_peer_info_comp);
4965 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
4966}
4967
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05304968static void hdd_reset_locally_admin_bit(struct hdd_context *hdd_ctx,
4969 tSirMacAddr macAddr)
4970{
4971 int i;
4972 /*
4973 * Reset locally administered bit for dynamic_mac_list
4974 * also as while releasing the MAC address for any
4975 * interface mac will be compared with dynamic mac list
4976 */
4977 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
4978 if (!qdf_mem_cmp(
4979 macAddr,
4980 &hdd_ctx->
4981 dynamic_mac_list[i].dynamic_mac.bytes[0],
4982 sizeof(struct qdf_mac_addr))) {
4983 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(
4984 hdd_ctx->
4985 dynamic_mac_list[i].dynamic_mac.bytes);
4986 break;
4987 }
4988 }
4989 /*
4990 * Reset locally administered bit if the device mode is
4991 * STA
4992 */
4993 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
4994 hdd_debug("locally administered bit reset in sta mode: "
4995 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
4996}
4997
Abhinav Kumarcc959f12018-08-09 13:58:30 +05304998/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08004999 * hdd_open_adapter() - open and setup the hdd adatper
5000 * @hdd_ctx: global hdd context
5001 * @session_type: type of the interface to be created
5002 * @iface_name: User-visible name of the interface
5003 * @macAddr: MAC address to assign to the interface
5004 * @name_assign_type: the name of assign type of the netdev
5005 * @rtnl_held: the rtnl lock hold flag
5006 *
5007 * This function open and setup the hdd adpater according to the device
5008 * type request, assign the name, the mac address assigned, and then prepared
5009 * the hdd related parameters, queue, lock and ready to start.
5010 *
5011 * Return: the pointer of hdd adapter, otherwise NULL.
5012 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005013struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005014 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08005015 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08005016 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005017{
Jeff Johnson9d295242017-08-29 14:39:48 -07005018 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305019 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005020
5021 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
5022 /*
5023 * Max limit reached on the number of vdevs configured by the
5024 * host. Return error
5025 */
Arun Khandavallifae92942016-08-01 13:31:08 +05305026 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
5027 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005028 return NULL;
5029 }
5030
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05305031 status = wlan_hdd_validate_mac_address((struct qdf_mac_addr *)macAddr);
5032 if (QDF_IS_STATUS_ERROR(status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005033 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05305034 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005035 return NULL;
5036 }
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05305037
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005038 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305039 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305040 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
5041 " already exists",
5042 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005043 return NULL;
5044 }
5045
5046 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005047 case QDF_STA_MODE:
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05305048 if (!hdd_ctx->config->mac_provision)
5049 hdd_reset_locally_admin_bit(hdd_ctx, macAddr);
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05305050
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005051 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005052 case QDF_P2P_CLIENT_MODE:
5053 case QDF_P2P_DEVICE_MODE:
5054 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07005055 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305056 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08005057 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
5058 name_assign_type,
5059 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005060
5061 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305062 hdd_err("failed to allocate adapter for session %d",
5063 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005064 return NULL;
5065 }
5066
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005067 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005068 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005069 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005070 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305071 else if (QDF_MONITOR_MODE == session_type)
5072 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005073 else
5074 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
5075
5076 adapter->device_mode = session_type;
5077
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005078
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005079 /*
5080 * Workqueue which gets scheduled in IPv4 notification
5081 * callback
5082 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005083 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005084 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005085
5086#ifdef WLAN_NS_OFFLOAD
5087 /*
5088 * Workqueue which gets scheduled in IPv6
5089 * notification callback.
5090 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005091 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005092 hdd_ipv6_notifier_work_queue);
5093#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005094 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08005095 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08005096 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005097
5098 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005099 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005100 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305101 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5102 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05305103
Alok Kumarb64650c2018-03-23 17:05:11 +05305104 hdd_nud_init_tracking(adapter);
Arunk Khandavallica56d4b2018-11-29 15:46:00 +05305105 if (adapter->device_mode == QDF_STA_MODE ||
5106 adapter->device_mode == QDF_P2P_DEVICE_MODE)
5107 hdd_sysfs_create_adapter_root_obj(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05305108 qdf_mutex_create(&adapter->disconnection_status_lock);
5109
Ravi Joshi1a292562017-05-18 16:28:54 -07005110 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005111
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005112 case QDF_P2P_GO_MODE:
5113 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08005114 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
5115 name_assign_type,
5116 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005117 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005118 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05305119 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005120 return NULL;
5121 }
5122
5123 adapter->wdev.iftype =
5124 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005125 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005126 NL80211_IFTYPE_P2P_GO;
5127 adapter->device_mode = session_type;
5128
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07005129 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08005130 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005131 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08005132
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005133 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005134 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305135 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5136 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305137
5138 /*
5139 * Workqueue which gets scheduled in IPv4 notification
5140 * callback
5141 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005142 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305143 hdd_ipv4_notifier_work_queue);
5144
5145#ifdef WLAN_NS_OFFLOAD
5146 /*
5147 * Workqueue which gets scheduled in IPv6
5148 * notification callback.
5149 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005150 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305151 hdd_ipv6_notifier_work_queue);
5152#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005153 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305154 case QDF_FTM_MODE:
5155 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
5156 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08005157 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305158 if (NULL == adapter) {
5159 hdd_err("Failed to allocate adapter for FTM mode");
5160 return NULL;
5161 }
5162 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
5163 adapter->device_mode = session_type;
5164 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08005165 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08005166 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08005167
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305168 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005169 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305170 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305171 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5172 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305173 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005174 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005175 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305176 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005177 return NULL;
5178 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005179
Min Liu8c5d99e2018-09-10 17:18:44 +08005180 qdf_spinlock_create(&adapter->vdev_lock);
5181
Abhinav Kumarcc959f12018-08-09 13:58:30 +05305182 hdd_init_completion(adapter);
hqueaa33ee2017-05-04 17:56:35 +08005183 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
Min Liu9be5d4a2018-05-17 11:51:53 +08005184 qdf_list_create(&adapter->blocked_scan_request_q, WLAN_MAX_SCAN_COUNT);
5185 qdf_mutex_create(&adapter->blocked_scan_request_q_lock);
hqueaa33ee2017-05-04 17:56:35 +08005186
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305187 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005188 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08005189 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005190 }
5191
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305192 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005193 if (NULL != adapter) {
5194 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
5195 adapter = NULL;
5196 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005197
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005198 return NULL;
5199 }
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05305200 hdd_apf_context_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005201
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305202 if (QDF_STATUS_SUCCESS == status) {
Dustin Brown1dbefe62018-09-11 16:32:03 -07005203 policy_mgr_set_concurrency_mode(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005204 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005205
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005206 /* Adapter successfully added. Increment the vdev count */
5207 hdd_ctx->current_intf_count++;
5208
Jeff Johnson5880d792016-08-15 13:32:30 -07005209 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005210 hdd_ctx->current_intf_count);
5211
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08005212 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005213 }
5214
Rajeev Kumardca5f812016-02-04 17:28:06 -08005215 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07005216 hdd_err("Interface %s wow debug_fs init failed",
5217 netdev_name(adapter->dev));
5218
Ajit Pal Singh106c1412018-04-18 18:08:49 +05305219 hdd_register_hl_netdev_fc_timer(adapter,
5220 hdd_tx_resume_timer_expired_handler);
5221
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07005222 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
5223 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005224
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05305225 if (adapter->device_mode == QDF_STA_MODE)
5226 wlan_hdd_debugfs_csr_init(adapter);
5227
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005228 return adapter;
5229
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005230err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07005231 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05305232 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005233
5234 return NULL;
5235}
5236
Dustin Brown728d65a2018-10-02 16:27:52 -07005237static void __hdd_close_adapter(struct hdd_context *hdd_ctx,
5238 struct hdd_adapter *adapter,
5239 bool rtnl_held)
5240{
5241 qdf_list_destroy(&adapter->blocked_scan_request_q);
5242 qdf_mutex_destroy(&adapter->blocked_scan_request_q_lock);
5243 policy_mgr_clear_concurrency_mode(hdd_ctx->psoc, adapter->device_mode);
5244
5245 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
5246
5247 if (hdd_ctx->current_intf_count != 0)
5248 hdd_ctx->current_intf_count--;
5249}
5250
5251void hdd_close_adapter(struct hdd_context *hdd_ctx,
5252 struct hdd_adapter *adapter,
5253 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005254{
Dustin Brown920397d2017-12-13 16:27:50 -08005255 /*
Dustin Brown728d65a2018-10-02 16:27:52 -07005256 * Stop the global bus bandwidth timer while touching the adapter list
5257 * to avoid bad memory access by the timer handler.
Dustin Brown920397d2017-12-13 16:27:50 -08005258 */
Dustin Brown920397d2017-12-13 16:27:50 -08005259 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005260
Dustin Brown920397d2017-12-13 16:27:50 -08005261 hdd_remove_adapter(hdd_ctx, adapter);
Dustin Brown728d65a2018-10-02 16:27:52 -07005262 __hdd_close_adapter(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005263
Dustin Brown920397d2017-12-13 16:27:50 -08005264 /* conditionally restart the bw timer */
5265 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005266}
5267
Dustin Brown728d65a2018-10-02 16:27:52 -07005268void hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005269{
Dustin Brown920397d2017-12-13 16:27:50 -08005270 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005271
Dustin Brown491d54b2018-03-14 12:39:11 -07005272 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005273
Dustin Brown728d65a2018-10-02 16:27:52 -07005274 while (QDF_IS_STATUS_SUCCESS(hdd_remove_front_adapter(hdd_ctx,
5275 &adapter))) {
5276 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
5277 __hdd_close_adapter(hdd_ctx, adapter, rtnl_held);
5278 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005279
Dustin Browne74003f2018-03-14 12:51:58 -07005280 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005281}
5282
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005283void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005284{
Anurag Chouhan6d760662016-02-20 16:05:43 +05305285 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005286 tSirUpdateIE updateIE;
Jeff Johnson16528362018-06-14 12:34:16 -07005287 mac_handle_t mac_handle;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005288
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005289 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005290 case QDF_STA_MODE:
5291 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005292 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005293 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005294 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07005295 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005296 break;
5297 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005298 case QDF_SAP_MODE:
5299 case QDF_P2P_GO_MODE:
5300 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005301 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07005302 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005303 break;
5304 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005305 case QDF_FTM_MODE:
5306 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005307 default:
5308 /*
5309 * wlan_hdd_reset_prob_rspies should not have been called
5310 * for these kind of devices
5311 */
Jeff Johnson5880d792016-08-15 13:32:30 -07005312 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005313 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005314 return;
5315 }
5316
Anurag Chouhanc5548422016-02-24 18:33:27 +05305317 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005318 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005319 updateIE.ieBufferlength = 0;
5320 updateIE.pAdditionIEBuffer = NULL;
5321 updateIE.append = true;
5322 updateIE.notify = false;
Jeff Johnson16528362018-06-14 12:34:16 -07005323 mac_handle = hdd_adapter_get_mac_handle(adapter);
5324 if (sme_update_add_ie(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005325 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305326 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005327 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005328 }
5329}
5330
Dustin Browndb2a8be2017-12-20 11:49:56 -08005331QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
5332 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005333{
Liangwei Dongad89c762018-06-01 01:56:23 -04005334 return hdd_stop_adapter_ext(hdd_ctx, adapter, 0);
5335}
5336
5337QDF_STATUS hdd_stop_adapter_ext(struct hdd_context *hdd_ctx,
5338 struct hdd_adapter *adapter,
5339 enum hdd_adapter_stop_flag_t flag)
5340{
Dustin Brownd747ecd2018-10-26 16:32:22 -07005341 QDF_STATUS status = QDF_STATUS_SUCCESS;
5342 struct hdd_station_ctx *sta_ctx;
Jeff Johnson025618c2018-03-18 14:41:00 -07005343 struct csr_roam_profile *roam_profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005344 union iwreq_data wrqu;
5345 tSirUpdateIE updateIE;
5346 unsigned long rc;
Jeff Johnsone4c11db2018-05-05 23:22:32 -07005347 tsap_config_t *sap_config;
Jeff Johnson16528362018-06-14 12:34:16 -07005348 mac_handle_t mac_handle;
Min Liu8c5d99e2018-09-10 17:18:44 +08005349 struct wlan_objmgr_vdev *vdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005350
Dustin Brown491d54b2018-03-14 12:39:11 -07005351 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005352
Dustin Browne7e71d32018-05-11 16:00:08 -07005353 if (adapter->session_id != HDD_SESSION_ID_INVALID)
5354 wlan_hdd_cfg80211_deregister_frames(adapter);
5355
Alok Kumarb64650c2018-03-23 17:05:11 +05305356 hdd_nud_ignore_tracking(adapter, true);
5357 hdd_nud_reset_tracking(adapter);
Alok Kumar016a1ac2018-09-16 09:55:50 +05305358 hdd_nud_flush_work(adapter);
hangtian9c47aaf2018-11-26 17:59:39 +08005359 hdd_stop_tsf_sync(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05305360
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005361 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305362 wlan_hdd_netif_queue_control(adapter,
5363 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5364 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08005365 /*
5366 * if this is the last active connection check & stop the
5367 * opportunistic timer first
5368 */
Dustin Brownd747ecd2018-10-26 16:32:22 -07005369 if ((policy_mgr_get_connection_count(hdd_ctx->psoc) == 1 &&
5370 policy_mgr_mode_specific_connection_count(hdd_ctx->psoc,
5371 policy_mgr_convert_device_mode_to_qdf_type(
5372 adapter->device_mode), NULL) == 1) ||
5373 !policy_mgr_get_connection_count(hdd_ctx->psoc))
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08005374 policy_mgr_check_and_stop_opportunistic_timer(
Dustin Brown1dbefe62018-09-11 16:32:03 -07005375 hdd_ctx->psoc, adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -07005376
5377 mac_handle = hdd_ctx->mac_handle;
5378
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005379 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005380 case QDF_STA_MODE:
5381 case QDF_P2P_CLIENT_MODE:
5382 case QDF_IBSS_MODE:
5383 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005384 case QDF_NDI_MODE:
Dustin Brownd747ecd2018-10-26 16:32:22 -07005385 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
5386
5387 if (adapter->device_mode == QDF_NDI_MODE ||
5388 hdd_conn_is_connected(sta_ctx) ||
5389 hdd_is_connecting(sta_ctx)) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005390 INIT_COMPLETION(adapter->disconnect_comp_var);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005391
Jeff Johnson025618c2018-03-18 14:41:00 -07005392 roam_profile = hdd_roam_profile(adapter);
5393 /* For NDI do not use roam_profile */
Dustin Brownd747ecd2018-10-26 16:32:22 -07005394 if (adapter->device_mode == QDF_NDI_MODE)
5395 status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005396 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005397 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005398 eCSR_DISCONNECT_REASON_NDI_DELETE);
Jeff Johnson025618c2018-03-18 14:41:00 -07005399 else if (roam_profile->BSSType ==
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005400 eCSR_BSS_TYPE_START_IBSS)
Dustin Brownd747ecd2018-10-26 16:32:22 -07005401 status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005402 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005403 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005404 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Abhinav Kumar19a7a402018-07-12 17:36:57 +05305405 else if (adapter->device_mode == QDF_STA_MODE)
5406 wlan_hdd_disconnect(adapter,
5407 eCSR_DISCONNECT_REASON_DEAUTH);
5408 else
Dustin Brownd747ecd2018-10-26 16:32:22 -07005409 status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005410 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005411 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005412 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005413 /* success implies disconnect is queued */
5414 if (QDF_IS_STATUS_SUCCESS(status) &&
5415 adapter->device_mode != QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005416 rc = wait_for_completion_timeout(
5417 &adapter->disconnect_comp_var,
5418 msecs_to_jiffies
5419 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005420 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005421 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005422 }
Dustin Brownd747ecd2018-10-26 16:32:22 -07005423 if (QDF_IS_STATUS_ERROR(status))
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005424 hdd_warn("failed to post disconnect");
Dustin Brownd747ecd2018-10-26 16:32:22 -07005425
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005426 memset(&wrqu, '\0', sizeof(wrqu));
5427 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5428 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5429 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
5430 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05305431 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005432
Dustin Brownd747ecd2018-10-26 16:32:22 -07005433 wlan_hdd_scan_abort(adapter);
Wu Gao4a1ec8c2018-07-23 19:18:40 +08005434 wlan_hdd_cleanup_actionframe(adapter);
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05305435 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05305436 hdd_clear_fils_connection_info(adapter);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005437 hdd_deregister_tx_flow_control(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005438
5439#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005440 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005441#ifdef WLAN_NS_OFFLOAD
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005442 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005443#endif
5444#endif
5445
Min Liu8c5d99e2018-09-10 17:18:44 +08005446 if (adapter->device_mode == QDF_STA_MODE) {
5447 struct wlan_objmgr_vdev *vdev;
5448
5449 vdev = hdd_objmgr_get_vdev(adapter);
5450 if (vdev) {
5451 wlan_cfg80211_sched_scan_stop(vdev);
5452 hdd_objmgr_put_vdev(adapter);
5453 }
5454 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08005455
Pragaspathi Thilagaraje6f37e02019-01-04 12:24:33 +05305456 /*
5457 * During vdev destroy, if any STA is in connecting state the
5458 * roam command will be in active queue and thus vdev destroy is
5459 * queued in pending queue. In case STA tries to connect to
5460 * multiple BSSID and fails to connect, due to auth/assoc
5461 * timeouts it may take more than vdev destroy time to get
5462 * completed. On vdev destroy timeout vdev is moved to logically
5463 * deleted state. Once connection is completed, vdev destroy is
5464 * activated and to release the self-peer ref count it try to
5465 * get the ref of the vdev, which fails as vdev is logically
5466 * deleted and this leads to peer ref leak. So before vdev
5467 * destroy is queued abort any STA ongoing connection to avoid
5468 * vdev destroy timeout.
5469 */
5470 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags))
5471 hdd_abort_ongoing_sta_connection(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08005472
Himanshu Agarwalb229a142017-12-21 10:16:45 +05305473 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005474 break;
5475
Rajeev Kumar3b906202018-02-01 10:55:14 -08005476 case QDF_MONITOR_MODE:
5477 wlan_hdd_scan_abort(adapter);
5478 hdd_deregister_tx_flow_control(adapter);
5479 hdd_vdev_destroy(adapter);
5480 break;
5481
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005482 case QDF_SAP_MODE:
Will Huang7049bae2018-08-13 17:25:02 +08005483 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
5484 cds_flush_delayed_work(&adapter->acs_pending_work);
5485 clear_bit(ACS_PENDING, &adapter->event_flags);
5486 }
Dustin Brownd747ecd2018-10-26 16:32:22 -07005487
wadesongf9b15ed2017-12-14 14:12:32 +08005488 wlan_hdd_scan_abort(adapter);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005489
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05305490 sap_config = &adapter->session.ap.sap_config;
Dustin Brownd747ecd2018-10-26 16:32:22 -07005491 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
5492
Dustin Brown07901ec2018-09-07 11:02:41 -07005493 ucfg_ipa_flush(hdd_ctx->pdev);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005494
Liangwei Dongad89c762018-06-01 01:56:23 -04005495 if (!(flag & HDD_IN_CAC_WORK_TH_CONTEXT))
5496 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Jeff Johnson46807cd2018-04-29 21:32:22 -07005497 /* fallthrough */
Dustin Browna5cf8e02017-10-19 16:04:19 -07005498
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005499 case QDF_P2P_GO_MODE:
Krunal Soni22208392017-09-29 18:10:34 -07005500 cds_flush_work(&adapter->sap_stop_bss_work);
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305501 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005502 wlan_hdd_undo_acs(adapter);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005503
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005504 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005505 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5506
5507 hdd_deregister_tx_flow_control(adapter);
Kapil Guptac1224bf2017-06-22 21:22:40 +05305508 hdd_destroy_acs_timer(adapter);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005509
Pragaspathi Thilagaraje6f37e02019-01-04 12:24:33 +05305510 /**
5511 * During vdev destroy, If any STA is in connecting state the
5512 * roam command will be in active queue and thus vdev destroy is
5513 * queued in pending queue. In case STA is tries to connected to
5514 * multiple BSSID and fails to connect, due to auth/assoc
5515 * timeouts it may take more than vdev destroy time to get
5516 * completes. If vdev destroy timeout vdev is moved to logically
5517 * deleted state. Once connection is completed, vdev destroy is
5518 * activated and to release the self-peer ref count it try to
5519 * get the ref of the vdev, which fails as vdev is logically
5520 * deleted and this leads to peer ref leak. So before vdev
5521 * destroy is queued abort any STA ongoing connection to avoid
5522 * vdev destroy timeout.
5523 */
5524 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags))
5525 hdd_abort_ongoing_sta_connection(hdd_ctx);
5526
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005527 mutex_lock(&hdd_ctx->sap_lock);
5528 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005529 status = wlansap_stop_bss(
5530 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005531
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305532 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07005533 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005534 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305535 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305536 qdf_stop_bss_event);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005537 status = qdf_wait_for_event_completion(
Nachiket Kukade0396b732017-11-14 16:35:16 +05305538 &hostapd_state->qdf_stop_bss_event,
Vignesh Viswanathan865daaa2018-10-11 19:30:44 +05305539 SME_CMD_START_STOP_BSS_TIMEOUT);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005540 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson5880d792016-08-15 13:32:30 -07005541 hdd_err("failure waiting for wlansap_stop_bss %d",
Dustin Brownd747ecd2018-10-26 16:32:22 -07005542 status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005543 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07005544 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005545 }
Dustin Brownd747ecd2018-10-26 16:32:22 -07005546
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005547 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -07005548 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005549 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005550 adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005551 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305552 adapter->device_mode,
5553 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005554
Anurag Chouhanc5548422016-02-24 18:33:27 +05305555 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07005556 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005557 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005558 updateIE.ieBufferlength = 0;
5559 updateIE.pAdditionIEBuffer = NULL;
5560 updateIE.append = false;
5561 updateIE.notify = false;
Dustin Brownd747ecd2018-10-26 16:32:22 -07005562
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005563 /* Probe bcn reset */
Dustin Brownd747ecd2018-10-26 16:32:22 -07005564 status = sme_update_add_ie(mac_handle, &updateIE,
5565 eUPDATE_IE_PROBE_BCN);
5566 if (status == QDF_STATUS_E_FAILURE)
5567 hdd_err("Could not pass PROBE_RSP_BCN to PE");
5568
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005569 /* Assoc resp reset */
Dustin Brownd747ecd2018-10-26 16:32:22 -07005570 status = sme_update_add_ie(mac_handle, &updateIE,
5571 eUPDATE_IE_ASSOC_RESP);
5572 if (status == QDF_STATUS_E_FAILURE)
5573 hdd_err("Could not pass ASSOC_RSP to PE");
5574
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005575 /* Reset WNI_CFG_PROBE_RSP Flags */
5576 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005577 }
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005578 clear_bit(SOFTAP_INIT_DONE, &adapter->event_flags);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005579 qdf_mem_free(adapter->session.ap.beacon);
5580 adapter->session.ap.beacon = NULL;
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005581
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305582 /*
5583 * If Do_Not_Break_Stream was enabled clear avoid channel list.
5584 */
Min Liu8c5d99e2018-09-10 17:18:44 +08005585 vdev = hdd_objmgr_get_vdev(adapter);
5586 if (vdev) {
5587 if (policy_mgr_is_dnsc_set(vdev))
5588 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
5589 hdd_objmgr_put_vdev(adapter);
5590 }
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305591
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305592#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005593 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305594#ifdef WLAN_NS_OFFLOAD
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005595 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305596#endif
5597#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08005598
5599 hdd_vdev_destroy(adapter);
5600
Krunal Sonib51eec72017-11-20 21:53:01 -08005601 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005602 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005603 case QDF_OCB_MODE:
Dustin Brownd747ecd2018-10-26 16:32:22 -07005604 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08005605 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Dustin Brownd747ecd2018-10-26 16:32:22 -07005606 cds_get_context(QDF_MODULE_ID_TXRX),
5607 sta_ctx->conn_info.staId[0]);
Zhang Qian79d0d132018-02-05 13:40:16 +08005608 hdd_deregister_tx_flow_control(adapter);
5609 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005610 break;
5611 default:
5612 break;
5613 }
5614
Ajit Pal Singh106c1412018-04-18 18:08:49 +05305615 hdd_deregister_hl_netdev_fc_timer(adapter);
5616
Dustin Brown04348372017-12-14 16:13:39 -08005617 if (adapter->scan_info.default_scan_ies) {
5618 qdf_mem_free(adapter->scan_info.default_scan_ies);
5619 adapter->scan_info.default_scan_ies = NULL;
5620 }
5621
Dustin Browne74003f2018-03-14 12:51:58 -07005622 hdd_exit();
Dustin Brownd747ecd2018-10-26 16:32:22 -07005623
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305624 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005625}
5626
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305627/**
5628 * hdd_deinit_all_adapters - deinit all adapters
5629 * @hdd_ctx: HDD context
5630 * @rtnl_held: True if RTNL lock held
5631 *
5632 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005633void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305634{
Jeff Johnson9d295242017-08-29 14:39:48 -07005635 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305636
Dustin Brown491d54b2018-03-14 12:39:11 -07005637 hdd_enter();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305638
Dustin Brown920397d2017-12-13 16:27:50 -08005639 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305640 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305641
Dustin Browne74003f2018-03-14 12:51:58 -07005642 hdd_exit();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305643}
5644
Dustin Browndb2a8be2017-12-20 11:49:56 -08005645QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005646{
Jeff Johnson9d295242017-08-29 14:39:48 -07005647 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005648
Dustin Brown491d54b2018-03-14 12:39:11 -07005649 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005650
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305651 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5652
Dustin Brown920397d2017-12-13 16:27:50 -08005653 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08005654 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005655
Dustin Browne74003f2018-03-14 12:51:58 -07005656 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005657
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305658 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005659}
5660
Paul Zhang84fa9382017-11-10 21:18:21 +08005661static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
5662 struct hdd_adapter *adapter)
5663{
5664 switch (adapter->device_mode) {
5665 case QDF_STA_MODE:
5666 case QDF_P2P_CLIENT_MODE:
5667 case QDF_IBSS_MODE:
5668 case QDF_P2P_DEVICE_MODE:
5669 case QDF_NDI_MODE:
5670 wlan_hdd_scan_abort(adapter);
5671 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Min Liu8c5d99e2018-09-10 17:18:44 +08005672 if (adapter->device_mode == QDF_STA_MODE) {
5673 struct wlan_objmgr_vdev *vdev;
5674
5675 vdev = hdd_objmgr_get_vdev(adapter);
5676 if (vdev) {
5677 wlan_cfg80211_sched_scan_stop(vdev);
5678 hdd_objmgr_put_vdev(adapter);
5679 }
5680 }
Paul Zhang84fa9382017-11-10 21:18:21 +08005681 break;
5682 case QDF_P2P_GO_MODE:
5683 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5684 break;
5685 case QDF_SAP_MODE:
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305686 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Paul Zhang84fa9382017-11-10 21:18:21 +08005687 wlan_hdd_undo_acs(adapter);
5688 break;
5689 default:
5690 break;
5691 }
5692}
5693
Ke Huangc067b8d2018-05-21 15:50:13 +08005694#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
5695/**
5696 * hdd_adapter_abort_tx_flow() - Abort the tx flow control
5697 * @pAdapter: pointer to hdd_adapter_t
5698 *
5699 * Resume tx and stop the tx flow control timer if the tx is paused
5700 * and the flow control timer is running. This function is called by
5701 * SSR to avoid the inconsistency of tx status before and after SSR.
5702 *
5703 * Return: void
5704 */
5705static void hdd_adapter_abort_tx_flow(struct hdd_adapter *adapter)
5706{
5707 if (adapter->hdd_stats.tx_rx_stats.is_txflow_paused &&
5708 QDF_TIMER_STATE_RUNNING ==
5709 qdf_mc_timer_get_current_state(
5710 &adapter->tx_flow_control_timer)) {
5711 hdd_tx_resume_timer_expired_handler(adapter);
5712 qdf_mc_timer_stop(&adapter->tx_flow_control_timer);
5713 }
5714}
5715#endif
5716
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005717QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005718{
Jeff Johnson9d295242017-08-29 14:39:48 -07005719 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07005720 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07005721 struct qdf_mac_addr peerMacAddr;
Yue Ma42654682018-01-11 16:55:24 -08005722 int sta_id;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05305723 bool value;
Min Liu8c5d99e2018-09-10 17:18:44 +08005724 struct wlan_objmgr_vdev *vdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005725
Dustin Brown491d54b2018-03-14 12:39:11 -07005726 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005727
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305728 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5729
Dustin Brown920397d2017-12-13 16:27:50 -08005730 hdd_for_each_adapter(hdd_ctx, adapter) {
Dustin Brown5e89ef82018-03-14 11:50:23 -07005731 hdd_info("[SSR] reset adapter with device mode %s(%d)",
Dustin Brown458027c2018-10-19 12:26:27 -07005732 qdf_opmode_str(adapter->device_mode),
Dustin Brown5e89ef82018-03-14 11:50:23 -07005733 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305734
Ke Huangc067b8d2018-05-21 15:50:13 +08005735#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
5736 hdd_adapter_abort_tx_flow(adapter);
5737#endif
5738
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305739 if ((adapter->device_mode == QDF_STA_MODE) ||
Paul Zhang679025e2018-03-08 22:39:44 +08005740 (adapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305741 /* Stop tdls timers */
Min Liu8c5d99e2018-09-10 17:18:44 +08005742 vdev = hdd_objmgr_get_vdev(adapter);
5743 if (vdev) {
5744 hdd_notify_tdls_reset_adapter(vdev);
5745 hdd_objmgr_put_vdev(adapter);
5746 }
Paul Zhang679025e2018-03-08 22:39:44 +08005747 adapter->session.station.hdd_reassoc_scenario = false;
5748 }
Dustin Brown05d81302018-09-11 16:49:22 -07005749 ucfg_mlme_get_sap_internal_restart(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05305750 if (value &&
Arun Khandavallicc544b32017-01-30 19:52:16 +05305751 adapter->device_mode == QDF_SAP_MODE) {
5752 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305753 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05305754 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005755 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08005756 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005757 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005758 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
5759 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305760 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305761 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005762 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005763 }
Nijun Gong104ccc72018-08-07 10:43:56 +08005764 /*
5765 * Clear fc flag if it was set before SSR to avoid TX queues
5766 * permanently stopped after SSR.
5767 * Here WLAN_START_ALL_NETIF_QUEUE will actually not start any
5768 * queue since it's blocked by reason WLAN_CONTROL_PATH.
5769 */
5770 if (adapter->pause_map & (1 << WLAN_DATA_FLOW_CONTROL))
5771 wlan_hdd_netif_queue_control(adapter,
5772 WLAN_START_ALL_NETIF_QUEUE,
5773 WLAN_DATA_FLOW_CONTROL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005774
Paul Zhang84fa9382017-11-10 21:18:21 +08005775 hdd_reset_scan_operation(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005776
5777 hdd_deinit_tx_rx(adapter);
Dustin Brown1dbefe62018-09-11 16:32:03 -07005778 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005779 adapter->device_mode, adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005780 hdd_green_ap_start_state_mc(hdd_ctx, adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305781 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005782 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5783 hdd_wmm_adapter_close(adapter);
5784 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5785 }
5786
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305787 if (adapter->device_mode == QDF_STA_MODE)
5788 hdd_clear_fils_connection_info(adapter);
5789
Wu Gao3545e642017-07-14 19:24:41 +08005790 if (adapter->device_mode == QDF_SAP_MODE) {
Jingxiang Geec113592018-08-09 15:40:39 +08005791 wlansap_cleanup_cac_timer(
5792 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Wu Gao3545e642017-07-14 19:24:41 +08005793 /*
5794 * If adapter is SAP, set session ID to invalid
5795 * since SAP session will be cleanup during SSR.
5796 */
Wu Gao36717432016-11-21 15:09:48 +08005797 wlansap_set_invalid_session(
5798 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Wu Gao3545e642017-07-14 19:24:41 +08005799 }
5800
Yue Ma42654682018-01-11 16:55:24 -08005801 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005802 if (adapter->device_mode == QDF_STA_MODE ||
5803 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005804 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005805 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07005806 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005807
Yue Ma42654682018-01-11 16:55:24 -08005808 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
Wu Gao6b81fc52018-05-24 19:27:27 +08005809 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Yue Ma42654682018-01-11 16:55:24 -08005810 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5811 if (adapter->sta_info[sta_id].in_use) {
5812 hdd_debug("[SSR] deregister STA with ID %d",
5813 sta_id);
5814 hdd_softap_deregister_sta(adapter,
5815 sta_id);
5816 adapter->sta_info[sta_id].in_use = 0;
5817 }
5818 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005819 }
5820
Alok Kumarb64650c2018-03-23 17:05:11 +05305821 hdd_nud_ignore_tracking(adapter, true);
Alok Kumar016a1ac2018-09-16 09:55:50 +05305822 hdd_nud_reset_tracking(adapter);
5823 hdd_nud_flush_work(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05305824 hdd_set_disconnect_status(adapter, false);
hangtian9c47aaf2018-11-26 17:59:39 +08005825 hdd_stop_tsf_sync(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05305826
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005827 hdd_softap_deinit_tx_rx(adapter);
Tiger Yu8c387702018-07-06 16:56:42 +08005828 hdd_deregister_tx_flow_control(adapter);
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005829
Yue Maf9782842017-05-08 12:49:49 -07005830 /* Destroy vdev which will be recreated during reinit. */
5831 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005832 }
5833
Dustin Browne74003f2018-03-14 12:51:58 -07005834 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005835
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305836 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005837}
5838
Dustin Brown4c663222018-10-23 14:19:36 -07005839bool hdd_is_any_interface_open(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305840{
Dustin Brown920397d2017-12-13 16:27:50 -08005841 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305842
Dustin Brown4c663222018-10-23 14:19:36 -07005843 if (hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) {
Arun Khandavalliba479c42017-07-26 21:29:40 +05305844 hdd_info("FTM mode, don't close the module");
Dustin Brown4c663222018-10-23 14:19:36 -07005845 return true;
Arun Khandavalliba479c42017-07-26 21:29:40 +05305846 }
5847
Dustin Brown920397d2017-12-13 16:27:50 -08005848 hdd_for_each_adapter(hdd_ctx, adapter) {
5849 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
Dustin Brown4c663222018-10-23 14:19:36 -07005850 test_bit(SME_SESSION_OPENED, &adapter->event_flags))
5851 return true;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305852 }
5853
Dustin Brown4c663222018-10-23 14:19:36 -07005854 return false;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305855}
5856
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305857bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305858{
5859 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5860 return true;
5861 else
5862 return false;
5863}
5864
Anurag Chouhanc4092922016-09-08 15:56:11 +05305865#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08005866 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305867struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5868 struct ieee80211_channel *channel,
5869 const u8 *bssid, const u8 *ssid,
5870 size_t ssid_len)
5871{
5872 return cfg80211_get_bss(wiphy, channel, bssid,
5873 ssid, ssid_len,
5874 WLAN_CAPABILITY_ESS,
5875 WLAN_CAPABILITY_ESS);
5876}
5877#else
5878struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5879 struct ieee80211_channel *channel,
5880 const u8 *bssid, const u8 *ssid,
5881 size_t ssid_len)
5882{
5883 return cfg80211_get_bss(wiphy, channel, bssid,
5884 ssid, ssid_len,
5885 IEEE80211_BSS_TYPE_ESS,
5886 IEEE80211_PRIVACY_ANY);
5887}
5888#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305889
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305890#if defined CFG80211_CONNECT_BSS || \
5891 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305892#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305893 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305894/**
5895 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5896 * @timeout_reason: reason for connect timeout
5897 *
5898 * This function is used to convert host timeout
5899 * reason enum to kernel specific enum.
5900 *
5901 * Return: nl timeout enum
5902 */
5903static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5904 tSirResultCodes timeout_reason)
5905{
5906 switch (timeout_reason) {
5907 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5908 return NL80211_TIMEOUT_SCAN;
5909 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5910 return NL80211_TIMEOUT_AUTH;
5911 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5912 return NL80211_TIMEOUT_ASSOC;
5913 default:
5914 return NL80211_TIMEOUT_UNSPECIFIED;
5915 }
5916}
5917
5918/**
5919 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5920 * @dev: network device
5921 * @bssid: bssid to which we want to associate
5922 * @timeout_reason: reason for connect timeout
5923 *
5924 * This API is used to send connection timeout reason to supplicant
5925 *
5926 * Return: void
5927 */
5928static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5929 const u8 *bssid,
5930 tSirResultCodes timeout_reason)
5931{
5932 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005933
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305934 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5935
5936 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5937 nl_timeout_reason);
5938}
5939
5940/**
5941 * __hdd_connect_bss() - API to send connection status to supplicant
5942 * @dev: network device
5943 * @bssid: bssid to which we want to associate
5944 * @req_ie: Request Information Element
5945 * @req_ie_len: len of the req IE
5946 * @resp_ie: Response IE
5947 * @resp_ie_len: len of ht response IE
5948 * @status: status
5949 * @gfp: Kernel Flag
5950 * @timeout_reason: reason for connect timeout
5951 *
5952 * Return: void
5953 */
5954static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5955 struct cfg80211_bss *bss, const u8 *req_ie,
5956 size_t req_ie_len, const u8 *resp_ie,
5957 size_t resp_ie_len, int status, gfp_t gfp,
5958 tSirResultCodes timeout_reason)
5959{
5960 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005961
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305962 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5963
5964 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5965 resp_ie, resp_ie_len, status, gfp,
5966 nl_timeout_reason);
5967}
5968#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305969#if defined CFG80211_CONNECT_TIMEOUT || \
5970 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305971static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5972 const u8 *bssid,
5973 tSirResultCodes timeout_reason)
5974{
5975 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5976}
5977#endif
5978
5979static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5980 struct cfg80211_bss *bss, const u8 *req_ie,
5981 size_t req_ie_len, const u8 *resp_ie,
5982 size_t resp_ie_len, int status, gfp_t gfp,
5983 tSirResultCodes timeout_reason)
5984{
5985 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5986 resp_ie, resp_ie_len, status, gfp);
5987}
5988#endif
5989
Abhishek Singha84d3952016-09-13 13:45:05 +05305990/**
5991 * hdd_connect_bss() - API to send connection status to supplicant
5992 * @dev: network device
5993 * @bssid: bssid to which we want to associate
5994 * @req_ie: Request Information Element
5995 * @req_ie_len: len of the req IE
5996 * @resp_ie: Response IE
5997 * @resp_ie_len: len of ht response IE
5998 * @status: status
5999 * @gfp: Kernel Flag
6000 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306001 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05306002 *
6003 * The API is a wrapper to send connection status to supplicant
6004 *
6005 * Return: Void
6006 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306007#if defined CFG80211_CONNECT_TIMEOUT || \
6008 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05306009static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
6010 struct cfg80211_bss *bss, const u8 *req_ie,
6011 size_t req_ie_len, const u8 *resp_ie,
6012 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306013 bool connect_timeout,
6014 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05306015{
6016 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306017 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05306018 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306019 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
6020 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05306021}
6022#else
6023static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
6024 struct cfg80211_bss *bss, const u8 *req_ie,
6025 size_t req_ie_len, const u8 *resp_ie,
6026 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306027 bool connect_timeout,
6028 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05306029{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306030 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
6031 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05306032}
6033#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05306034
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306035#if defined(WLAN_FEATURE_FILS_SK)
6036#if defined(CFG80211_CONNECT_DONE) || \
6037 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
6038#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
6039 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306040/**
6041 * hdd_populate_fils_params() - Populate FILS keys to connect response
6042 * @fils_params: connect response to supplicant
6043 * @fils_kek: FILS kek
6044 * @fils_kek_len: FILS kek length
6045 * @pmk: FILS PMK
6046 * @pmk_len: FILS PMK length
6047 * @pmkid: PMKID
6048 * @fils_seq_num: FILS Seq number
6049 *
6050 * Return: None
6051 */
6052static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
6053 *fils_params, const uint8_t *fils_kek,
6054 size_t fils_kek_len, const uint8_t *pmk,
6055 size_t pmk_len, const uint8_t *pmkid,
6056 uint16_t fils_seq_num)
6057{
6058 /* Increament seq number to be used for next FILS */
6059 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
6060 fils_params->update_erp_next_seq_num = true;
6061 fils_params->fils_kek = fils_kek;
6062 fils_params->fils_kek_len = fils_kek_len;
6063 fils_params->pmk = pmk;
6064 fils_params->pmk_len = pmk_len;
6065 fils_params->pmkid = pmkid;
6066}
6067#else
6068static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
6069 *fils_params, const uint8_t
6070 *fils_kek, size_t fils_kek_len,
6071 const uint8_t *pmk, size_t pmk_len,
6072 const uint8_t *pmkid,
6073 uint16_t fils_seq_num)
6074{ }
6075#endif
6076
Jeff Johnson172237b2017-11-07 15:32:59 -08006077void hdd_update_hlp_info(struct net_device *dev,
6078 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306079{
6080 struct sk_buff *skb;
6081 uint16_t skb_len;
6082 struct llc_snap_hdr_t *llc_hdr;
6083 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306084 uint8_t *hlp_data;
6085 uint16_t hlp_data_len;
6086 struct fils_join_rsp_params *roam_fils_params
6087 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306088 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
6089
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306090 if (!roam_fils_params) {
6091 hdd_err("FILS Roam Param NULL");
6092 return;
6093 }
6094
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08006095 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306096 hdd_err("FILS HLP Data NULL, len %d",
6097 roam_fils_params->hlp_data_len);
6098 return;
6099 }
6100
6101 hlp_data = roam_fils_params->hlp_data;
6102 hlp_data_len = roam_fils_params->hlp_data_len;
6103
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306104 /* Calculate skb length */
6105 skb_len = (2 * ETH_ALEN) + hlp_data_len;
6106 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
6107 if (skb == NULL) {
6108 hdd_err("HLP packet nbuf alloc fails");
6109 return;
6110 }
6111
6112 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
6113 QDF_MAC_ADDR_SIZE);
6114 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
6115 QDF_MAC_ADDR_SIZE);
6116
6117 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
6118 if (IS_SNAP(llc_hdr)) {
6119 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
6120 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
6121 }
6122
6123 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
6124
6125 /*
6126 * This HLP packet is formed from HLP info encapsulated
6127 * in assoc response frame which is AEAD encrypted.
6128 * Hence, this checksum validation can be set unnecessary.
6129 * i.e. network layer need not worry about checksum.
6130 */
6131 skb->ip_summed = CHECKSUM_UNNECESSARY;
6132
6133 status = hdd_rx_packet_cbk(padapter, skb);
6134 if (QDF_IS_STATUS_ERROR(status)) {
6135 hdd_err("Sending HLP packet fails");
6136 return;
6137 }
6138 hdd_debug("send HLP packet to netif successfully");
6139}
6140
6141/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306142 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
6143 * @dev: network device
6144 * @bssid: bssid to which we want to associate
6145 * @bss: cfg80211 bss info
6146 * @roam_info: information about connected bss
6147 * @req_ie: Request Information Element
6148 * @req_ie_len: len of the req IE
6149 * @resp_ie: Response IE
6150 * @resp_ie_len: len of ht response IE
6151 * @status: status
6152 * @gfp: allocation flags
6153 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
6154 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306155 *
6156 * This API is used as wrapper to send FILS key/sequence number
6157 * params etc. to supplicant in case of FILS connection
6158 *
6159 * Return: None
6160 */
6161static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006162 struct cfg80211_bss *bss,
6163 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306164 const u8 *req_ie, size_t req_ie_len,
6165 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006166 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306167 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306168{
6169 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306170 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
6171 struct fils_join_rsp_params *roam_fils_params =
6172 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006173
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306174 qdf_mem_zero(&fils_params, sizeof(fils_params));
6175
6176 if (!roam_fils_params) {
6177 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
6178 } else {
6179 fils_params.status = status;
6180 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08006181 fils_params.timeout_reason =
6182 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306183 fils_params.req_ie = req_ie;
6184 fils_params.req_ie_len = req_ie_len;
6185 fils_params.resp_ie = resp_ie;
6186 fils_params.resp_ie_len = resp_ie_len;
6187 fils_params.bss = bss;
6188 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
6189 roam_fils_params->kek_len,
6190 roam_fils_params->fils_pmk,
6191 roam_fils_params->fils_pmk_len,
6192 roam_fils_params->fils_pmkid,
6193 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05306194 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306195 }
6196 hdd_debug("FILS indicate connect status %d seq no %d",
6197 fils_params.status,
6198 fils_params.fils_erp_next_seq_num);
6199
6200 cfg80211_connect_done(dev, &fils_params, gfp);
6201
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306202 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306203 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306204
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306205 /* Clear all the FILS key info */
6206 if (roam_fils_params && roam_fils_params->fils_pmk)
6207 qdf_mem_free(roam_fils_params->fils_pmk);
6208 if (roam_fils_params)
6209 qdf_mem_free(roam_fils_params);
6210 roam_info->fils_join_rsp = NULL;
6211}
6212#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006213static inline void
6214hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006215 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006216 const u8 *req_ie, size_t req_ie_len,
6217 const u8 *resp_ie, size_t resp_ie_len, u16 status,
6218 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306219 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306220{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306221#endif
6222#endif
6223
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306224#if defined(WLAN_FEATURE_FILS_SK) && \
6225 (defined(CFG80211_CONNECT_DONE) || \
6226 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306227/**
6228 * hdd_fils_update_connect_results() - API to send fils connection status to
6229 * supplicant.
6230 * @dev: network device
6231 * @bssid: bssid to which we want to associate
6232 * @bss: cfg80211 bss info
6233 * @roam_info: information about connected bss
6234 * @req_ie: Request Information Element
6235 * @req_ie_len: len of the req IE
6236 * @resp_ie: Response IE
6237 * @resp_ie_len: len of ht response IE
6238 * @status: status
6239 * @gfp: allocation flags
6240 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
6241 * @timeout_reason: reason for connect timeout
6242 *
6243 * The API is a wrapper to send connection status to supplicant
6244 *
6245 * Return: 0 if success else failure
6246 */
6247static int hdd_fils_update_connect_results(struct net_device *dev,
6248 const u8 *bssid,
6249 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08006250 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306251 size_t req_ie_len, const u8 *resp_ie,
6252 size_t resp_ie_len, u16 status, gfp_t gfp,
6253 bool connect_timeout,
6254 tSirResultCodes timeout_reason)
6255{
Dustin Brown491d54b2018-03-14 12:39:11 -07006256 hdd_enter();
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306257 if (!roam_info || !roam_info->is_fils_connection)
6258 return -EINVAL;
6259
6260 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
6261 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306262 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306263 return 0;
6264}
6265#else
6266static inline int hdd_fils_update_connect_results(struct net_device *dev,
6267 const u8 *bssid,
6268 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08006269 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306270 size_t req_ie_len, const u8 *resp_ie,
6271 size_t resp_ie_len, u16 status, gfp_t gfp,
6272 bool connect_timeout,
6273 tSirResultCodes timeout_reason)
6274{
6275 return -EINVAL;
6276}
6277#endif
6278
Anurag Chouhanc4092922016-09-08 15:56:11 +05306279/**
6280 * hdd_connect_result() - API to send connection status to supplicant
6281 * @dev: network device
6282 * @bssid: bssid to which we want to associate
6283 * @roam_info: information about connected bss
6284 * @req_ie: Request Information Element
6285 * @req_ie_len: len of the req IE
6286 * @resp_ie: Response IE
6287 * @resp_ie_len: len of ht response IE
6288 * @status: status
6289 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05306290 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306291 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05306292 *
6293 * The API is a wrapper to send connection status to supplicant
6294 * and allow runtime suspend
6295 *
6296 * Return: Void
6297 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306298void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006299 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05306300 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05306301 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306302 bool connect_timeout,
6303 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05306304{
Jeff Johnson9d295242017-08-29 14:39:48 -07006305 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306306 struct cfg80211_bss *bss = NULL;
Jingxiang Ge929c7932018-01-24 14:01:12 +08006307 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306308
6309 if (WLAN_STATUS_SUCCESS == status) {
6310 struct ieee80211_channel *chan;
6311 int freq;
6312 int chan_no = roam_info->pBssDesc->channelId;
6313
6314 if (chan_no <= 14)
6315 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07006316 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306317 else
6318 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07006319 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306320
6321 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
6322 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
6323 roam_info->u.pConnectedProfile->SSID.ssId,
6324 roam_info->u.pConnectedProfile->SSID.length);
6325 }
Komal Seelama89be8d2016-09-29 11:09:26 +05306326
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306327 if (hdd_fils_update_connect_results(dev, bssid, bss,
6328 roam_info, req_ie, req_ie_len, resp_ie,
6329 resp_ie_len, status, gfp, connect_timeout,
6330 timeout_reason) != 0) {
6331 hdd_connect_bss(dev, bssid, bss, req_ie,
6332 req_ie_len, resp_ie, resp_ie_len,
6333 status, gfp, connect_timeout, timeout_reason);
6334 }
Komal Seelama89be8d2016-09-29 11:09:26 +05306335
Jingxiang Geb49aa302018-01-17 20:54:15 +08006336 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07006337 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306338}
6339#else
6340void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006341 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05306342 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05306343 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306344 bool connect_timeout,
6345 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05306346{
Jeff Johnson9d295242017-08-29 14:39:48 -07006347 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Jingxiang Ge929c7932018-01-24 14:01:12 +08006348 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05306349
Anurag Chouhanc4092922016-09-08 15:56:11 +05306350 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
6351 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08006352
Jingxiang Geb49aa302018-01-17 20:54:15 +08006353 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07006354 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306355}
6356#endif
6357
Nirav Shah73713f72018-05-17 14:50:41 +05306358#ifdef FEATURE_MONITOR_MODE_SUPPORT
Jeff Johnsond9952752018-04-18 12:15:35 -07006359int wlan_hdd_set_mon_chan(struct hdd_adapter *adapter, uint32_t chan,
6360 uint32_t bandwidth)
6361{
6362 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6363 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
6364 struct hdd_mon_set_ch_info *ch_info = &sta_ctx->ch_info;
6365 QDF_STATUS status;
Jeff Johnson43837af2018-10-17 12:44:05 -07006366 mac_handle_t mac_handle = hdd_ctx->mac_handle;
Jeff Johnsond9952752018-04-18 12:15:35 -07006367 struct qdf_mac_addr bssid;
6368 struct csr_roam_profile roam_profile;
6369 struct ch_params ch_params;
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006370 eConnectionState connstate;
Jeff Johnsond9952752018-04-18 12:15:35 -07006371
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006372 if (hdd_get_conparam() != QDF_GLOBAL_MONITOR_MODE &&
6373 adapter->device_mode != QDF_STA_MODE) {
6374 hdd_err("Not supported, device is not in monitor mode or sta mission mode");
Jeff Johnsond9952752018-04-18 12:15:35 -07006375 return -EINVAL;
6376 }
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006377 if (adapter->device_mode == QDF_STA_MODE &&
6378 hdd_ctx->config->enable_change_channel_bandwidth) {
6379 connstate = sta_ctx->conn_info.connState;
6380 if (eConnectionState_Associated == connstate ||
6381 eConnectionState_Connecting == connstate) {
6382 return -EINVAL;
6383 }
6384 }
Jeff Johnsond9952752018-04-18 12:15:35 -07006385
Visweswara Tanuku006313a2018-04-12 12:26:34 +05306386 /* Validate Channel */
6387 if (!WLAN_REG_IS_24GHZ_CH(chan) && !WLAN_REG_IS_5GHZ_CH(chan)) {
6388 hdd_err("Channel %d Not supported", chan);
6389 return -EINVAL;
6390 }
6391
6392 if (WLAN_REG_IS_24GHZ_CH(chan)) {
6393 if (bandwidth == CH_WIDTH_80MHZ) {
6394 hdd_err("BW80 not possible in 2.4GHz band");
6395 return -EINVAL;
6396 }
6397 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 14) &&
6398 (bandwidth != CH_WIDTH_MAX)) {
6399 hdd_err("Only BW20 possible on channel 14");
6400 return -EINVAL;
6401 }
6402 }
6403
6404 if (WLAN_REG_IS_5GHZ_CH(chan)) {
6405 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 165) &&
6406 (bandwidth != CH_WIDTH_MAX)) {
6407 hdd_err("Only BW20 possible on channel 165");
6408 return -EINVAL;
6409 }
6410 }
6411
Jeff Johnsond9952752018-04-18 12:15:35 -07006412 hdd_debug("Set monitor mode Channel %d", chan);
6413 qdf_mem_zero(&roam_profile, sizeof(roam_profile));
6414 roam_profile.ChannelInfo.ChannelList = &ch_info->channel;
6415 roam_profile.ChannelInfo.numOfChannels = 1;
6416 roam_profile.phyMode = ch_info->phy_mode;
6417 roam_profile.ch_params.ch_width = bandwidth;
6418 hdd_select_cbmode(adapter, chan, &roam_profile.ch_params);
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006419 if (hdd_ctx->config->enable_change_channel_bandwidth &&
Jeff Johnson43837af2018-10-17 12:44:05 -07006420 (!sme_find_session_by_bssid(mac_handle, adapter->mac_addr.bytes))) {
6421 status = sme_create_mon_session(mac_handle,
Rajeev Kumar Sirasanagandlae3b59912018-08-24 15:53:31 +05306422 adapter->mac_addr.bytes,
6423 adapter->session_id);
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006424 if (status != QDF_STATUS_SUCCESS) {
6425 hdd_err("Status: %d Failed to create session.",
6426 status);
6427 return qdf_status_to_os_return(status);
6428 }
6429 }
Jeff Johnsond9952752018-04-18 12:15:35 -07006430 qdf_mem_copy(bssid.bytes, adapter->mac_addr.bytes,
6431 QDF_MAC_ADDR_SIZE);
6432
6433 ch_params.ch_width = bandwidth;
Dustin Brown07901ec2018-09-07 11:02:41 -07006434 wlan_reg_set_channel_params(hdd_ctx->pdev, chan, 0, &ch_params);
Jeff Johnsond9952752018-04-18 12:15:35 -07006435 if (ch_params.ch_width == CH_WIDTH_INVALID) {
6436 hdd_err("Invalid capture channel or bandwidth for a country");
6437 return -EINVAL;
6438 }
6439 if (wlan_hdd_change_hw_mode_for_given_chnl(adapter, chan,
6440 POLICY_MGR_UPDATE_REASON_SET_OPER_CHAN)) {
6441 hdd_err("Failed to change hw mode");
6442 return -EINVAL;
6443 }
6444
Jeff Johnson16528362018-06-14 12:34:16 -07006445 status = sme_roam_channel_change_req(hdd_ctx->mac_handle,
6446 bssid, &ch_params,
Jeff Johnsond9952752018-04-18 12:15:35 -07006447 &roam_profile);
6448 if (status) {
6449 hdd_err("Status: %d Failed to set sme_roam Channel for monitor mode",
6450 status);
6451 }
6452
6453 adapter->mon_chan = chan;
6454 adapter->mon_bandwidth = bandwidth;
6455 return qdf_status_to_os_return(status);
6456}
Nirav Shah73713f72018-05-17 14:50:41 +05306457#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05306458
Wu Gaodf929f12018-05-25 18:12:25 +08006459#ifdef MSM_PLATFORM
6460/**
6461 * hdd_stop_p2p_go() - call cfg80211 API to stop P2P GO
6462 * @adapter: pointer to adapter
6463 *
6464 * This function calls cfg80211 API to stop P2P GO
6465 *
6466 * Return: None
6467 */
6468static void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6469{
6470 hdd_debug("[SSR] send stop ap to supplicant");
6471 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
6472}
6473
6474static inline void hdd_delete_sta(struct hdd_adapter *adapter)
6475{
6476}
6477#else
6478static inline void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6479{
6480}
6481
6482/**
6483 * hdd_delete_sta() - call cfg80211 API to delete STA
6484 * @adapter: pointer to adapter
6485 *
6486 * This function calls cfg80211 API to delete STA
6487 *
6488 * Return: None
6489 */
6490static void hdd_delete_sta(struct hdd_adapter *adapter)
6491{
6492 struct qdf_mac_addr bcast_mac = QDF_MAC_ADDR_BCAST_INIT;
6493
6494 hdd_debug("[SSR] send restart supplicant");
6495 /* event supplicant to restart */
6496 cfg80211_del_sta(adapter->dev,
6497 (const u8 *)&bcast_mac.bytes[0],
6498 GFP_KERNEL);
6499}
6500#endif
6501
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006502QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006503{
Jeff Johnson9d295242017-08-29 14:39:48 -07006504 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006505 eConnectionState connState;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05306506 bool value;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006507
Dustin Brown491d54b2018-03-14 12:39:11 -07006508 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006509
Dustin Brown920397d2017-12-13 16:27:50 -08006510 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05306511 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08006512 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05306513
Yue Ma42654682018-01-11 16:55:24 -08006514 hdd_debug("[SSR] start adapter with device mode %s(%d)",
Dustin Brown458027c2018-10-19 12:26:27 -07006515 qdf_opmode_str(adapter->device_mode),
Yue Ma42654682018-01-11 16:55:24 -08006516 adapter->device_mode);
6517
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006518 hdd_wmm_init(adapter);
6519
6520 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006521 case QDF_STA_MODE:
6522 case QDF_P2P_CLIENT_MODE:
6523 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006524
6525 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
6526 ->conn_info.connState;
6527
Krunal Sonib51eec72017-11-20 21:53:01 -08006528 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006529 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07006530 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006531
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006532 /* Indicate disconnect event to supplicant
6533 * if associated previously
6534 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006535 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07006536 eConnectionState_IbssConnected == connState ||
6537 eConnectionState_NotConnected == connState ||
6538 eConnectionState_IbssDisconnected == connState ||
6539 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006540 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006541
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006542 memset(&wrqu, '\0', sizeof(wrqu));
6543 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
6544 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
6545 wireless_send_event(adapter->dev, SIOCGIWAP,
6546 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07006547 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07006548 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006549
6550 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05306551 wlan_hdd_cfg80211_indicate_disconnect(
6552 adapter->dev, false,
6553 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006554 } else if (eConnectionState_Connecting == connState) {
6555 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006556 * Indicate connect failure to supplicant if we
6557 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006558 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306559 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306560 NULL, 0, NULL, 0,
6561 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006562 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006563 }
6564
6565 hdd_register_tx_flow_control(adapter,
6566 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08006567 hdd_tx_resume_cb,
6568 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006569
Arunk Khandavalli40943af2017-05-15 19:25:34 +05306570 hdd_lpass_notify_start(hdd_ctx, adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05306571 hdd_nud_ignore_tracking(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006572 break;
6573
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006574 case QDF_SAP_MODE:
Dustin Brown05d81302018-09-11 16:49:22 -07006575 ucfg_mlme_get_sap_internal_restart(hdd_ctx->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05306576 &value);
6577 if (value)
Krunal Sonib51eec72017-11-20 21:53:01 -08006578 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05306579
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006580 break;
6581
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006582 case QDF_P2P_GO_MODE:
Wu Gaodf929f12018-05-25 18:12:25 +08006583 hdd_delete_sta(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006584 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306585 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08006586 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306587 hdd_set_mon_rx_cb(adapter->dev);
6588 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
6589 adapter->mon_bandwidth);
6590 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006591 default:
6592 break;
6593 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07006594 /*
6595 * Action frame registered in one adapter which will
6596 * applicable to all interfaces
6597 */
6598 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006599 }
6600
Wu Gaodf929f12018-05-25 18:12:25 +08006601 hdd_for_each_adapter(hdd_ctx, adapter) {
6602 if (!hdd_is_interface_up(adapter))
6603 continue;
6604
6605 if (adapter->device_mode == QDF_P2P_GO_MODE)
6606 hdd_stop_p2p_go(adapter);
6607 }
6608
Dustin Browne74003f2018-03-14 12:51:58 -07006609 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006610
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306611 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006612}
6613
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006614QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006615 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006616{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306617 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006618 qdf_list_node_t *node;
6619
6620 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006621
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006622 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006623 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006624 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006625
6626 if (QDF_IS_STATUS_ERROR(status))
6627 return status;
6628
6629 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6630
6631 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006632}
6633
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006634QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006635 struct hdd_adapter *current_adapter,
6636 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006637{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306638 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006639 qdf_list_node_t *node;
6640
6641 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006642
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006643 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006644 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08006645 &current_adapter->node,
6646 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006647 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006648
6649 if (QDF_IS_STATUS_ERROR(status))
6650 return status;
6651
6652 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6653
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006654 return status;
6655}
6656
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006657QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006658 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006659{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306660 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006661
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006662 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006663 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006664 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006665
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006666 return status;
6667}
6668
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006669QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006670 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006671{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306672 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006673 qdf_list_node_t *node;
6674
6675 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006676
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006677 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006678 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006679 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006680
6681 if (QDF_IS_STATUS_ERROR(status))
6682 return status;
6683
6684 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6685
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006686 return status;
6687}
6688
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006689QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006690 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006691{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306692 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006693
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006694 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006695 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006696 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006697
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006698 return status;
6699}
6700
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006701QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006702 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006703{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306704 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006705
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006706 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006707 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006708 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006709
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006710 return status;
6711}
6712
Liangwei Dong3abfe8f2018-09-20 02:25:44 -04006713struct hdd_adapter *hdd_get_adapter_by_rand_macaddr(
6714 struct hdd_context *hdd_ctx, tSirMacAddr mac_addr)
6715{
6716 struct hdd_adapter *adapter;
6717
6718 hdd_for_each_adapter(hdd_ctx, adapter) {
6719 if ((adapter->device_mode == QDF_STA_MODE ||
6720 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6721 adapter->device_mode == QDF_P2P_DEVICE_MODE) &&
6722 ucfg_p2p_check_random_mac(hdd_ctx->psoc,
6723 adapter->session_id, mac_addr))
6724 return adapter;
6725 }
6726
6727 return NULL;
6728}
6729
Jeff Johnson9d295242017-08-29 14:39:48 -07006730struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006731 tSirMacAddr macAddr)
6732{
Jeff Johnson9d295242017-08-29 14:39:48 -07006733 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006734
Dustin Brown920397d2017-12-13 16:27:50 -08006735 hdd_for_each_adapter(hdd_ctx, adapter) {
6736 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
6737 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006738 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006739 }
6740
6741 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006742}
6743
Jeff Johnson9d295242017-08-29 14:39:48 -07006744struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006745 uint32_t vdev_id)
6746{
Jeff Johnson9d295242017-08-29 14:39:48 -07006747 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006748
Dustin Brown920397d2017-12-13 16:27:50 -08006749 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07006750 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006751 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006752 }
6753
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006754 return NULL;
6755}
6756
Abhishek Singh7996eb72015-12-30 17:24:02 +05306757/**
6758 * hdd_get_adapter_by_sme_session_id() - Return adapter with
6759 * the sessionid
6760 * @hdd_ctx: hdd context.
6761 * @sme_session_id: sme session is for the adapter to get.
6762 *
6763 * This function is used to get the adapter with provided session id
6764 *
6765 * Return: adapter pointer if found
6766 *
6767 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07006768struct hdd_adapter *
6769hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
6770 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306771{
Jeff Johnson9d295242017-08-29 14:39:48 -07006772 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306773
Dustin Brown920397d2017-12-13 16:27:50 -08006774 hdd_for_each_adapter(hdd_ctx, adapter) {
6775 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306776 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306777 }
Dustin Brown920397d2017-12-13 16:27:50 -08006778
Abhishek Singh7996eb72015-12-30 17:24:02 +05306779 return NULL;
6780}
6781
Jeff Johnson9d295242017-08-29 14:39:48 -07006782struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07006783 const char *iface_name)
6784{
Jeff Johnson9d295242017-08-29 14:39:48 -07006785 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006786
Dustin Brown920397d2017-12-13 16:27:50 -08006787 hdd_for_each_adapter(hdd_ctx, adapter) {
6788 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07006789 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006790 }
Dustin Brown920397d2017-12-13 16:27:50 -08006791
Naveen Rawat4edb6822017-04-12 10:09:17 -07006792 return NULL;
6793}
6794
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006795/**
6796 * hdd_get_adapter() - to get adapter matching the mode
6797 * @hdd_ctx: hdd context
6798 * @mode: adapter mode
6799 *
6800 * This routine will return the pointer to adapter matching
6801 * with the passed mode.
6802 *
6803 * Return: pointer to adapter or null
6804 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006805struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006806 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006807{
Jeff Johnson9d295242017-08-29 14:39:48 -07006808 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006809
Dustin Brown920397d2017-12-13 16:27:50 -08006810 hdd_for_each_adapter(hdd_ctx, adapter) {
6811 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006812 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006813 }
6814
6815 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006816}
6817
Jeff Johnson36a0abf2018-05-20 11:24:25 -07006818enum QDF_OPMODE hdd_get_device_mode(uint32_t session_id)
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306819{
6820 struct hdd_context *hdd_ctx;
6821 struct hdd_adapter *adapter;
6822
6823 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
6824 if (!hdd_ctx) {
6825 hdd_err("Invalid HDD context");
6826 return QDF_MAX_NO_OF_MODE;
6827 }
6828
6829 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
6830 if (!adapter) {
6831 hdd_err("Invalid HDD adapter");
6832 return QDF_MAX_NO_OF_MODE;
6833 }
6834
6835 return adapter->device_mode;
6836}
6837
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006838/**
6839 * hdd_get_operating_channel() - return operating channel of the device mode
6840 * @hdd_ctx: Pointer to the HDD context.
6841 * @mode: Device mode for which operating channel is required.
Jeff Johnson77f89bb2018-05-06 16:21:36 -07006842 * Supported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006843 * QDF_STA_MODE,
6844 * QDF_P2P_CLIENT_MODE,
6845 * QDF_SAP_MODE,
6846 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006847 *
6848 * This API returns the operating channel of the requested device mode
6849 *
6850 * Return: channel number. "0" id the requested device is not found OR it is
6851 * not connected.
6852 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006853uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006854 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006855{
Jeff Johnson9d295242017-08-29 14:39:48 -07006856 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006857 uint8_t operatingChannel = 0;
6858
Dustin Brown920397d2017-12-13 16:27:50 -08006859 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006860 if (mode == adapter->device_mode) {
6861 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006862 case QDF_STA_MODE:
6863 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006864 if (hdd_conn_is_connected
6865 (WLAN_HDD_GET_STATION_CTX_PTR
6866 (adapter))) {
6867 operatingChannel =
6868 (WLAN_HDD_GET_STATION_CTX_PTR
6869 (adapter))->conn_info.
6870 operationChannel;
6871 }
6872 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006873 case QDF_SAP_MODE:
6874 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006875 /* softap connection info */
6876 if (test_bit
6877 (SOFTAP_BSS_STARTED,
6878 &adapter->event_flags))
6879 operatingChannel =
6880 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07006881 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006882 break;
6883 default:
6884 break;
6885 }
6886
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006887 /* Found the device of interest. break the loop */
6888 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006889 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006890 }
Dustin Brown920397d2017-12-13 16:27:50 -08006891
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006892 return operatingChannel;
6893}
6894
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006895static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006896 hdd_ctx)
6897{
Jeff Johnson9d295242017-08-29 14:39:48 -07006898 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006899
Dustin Brown491d54b2018-03-14 12:39:11 -07006900 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006901
Dustin Brown920397d2017-12-13 16:27:50 -08006902 hdd_for_each_adapter(hdd_ctx, adapter) {
6903 if (adapter->device_mode == QDF_STA_MODE ||
6904 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6905 adapter->device_mode == QDF_IBSS_MODE ||
6906 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6907 adapter->device_mode == QDF_SAP_MODE ||
6908 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006909 hdd_unregister_wext(adapter->dev);
6910 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006911 }
6912
Dustin Browne74003f2018-03-14 12:51:58 -07006913 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006914
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306915 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006916}
6917
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006918QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006919{
Jeff Johnson9d295242017-08-29 14:39:48 -07006920 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006921
Dustin Brown491d54b2018-03-14 12:39:11 -07006922 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006923
Dustin Brown920397d2017-12-13 16:27:50 -08006924 hdd_for_each_adapter(hdd_ctx, adapter) {
6925 if (adapter->device_mode == QDF_STA_MODE ||
6926 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6927 adapter->device_mode == QDF_IBSS_MODE ||
6928 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6929 adapter->device_mode == QDF_SAP_MODE ||
6930 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brown07901ec2018-09-07 11:02:41 -07006931 wlan_abort_scan(hdd_ctx->pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006932 adapter->session_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05306933 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006934 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006935 }
6936
Dustin Browne74003f2018-03-14 12:51:58 -07006937 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006938
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306939 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006940}
6941
Dustin Brownf27bce82016-11-03 12:52:27 -07006942/**
6943 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
6944 * adapters
6945 * @hdd_ctx: The HDD context containing the adapters to operate on
6946 *
6947 * return: QDF_STATUS_SUCCESS
6948 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006949static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07006950{
Jeff Johnson9d295242017-08-29 14:39:48 -07006951 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07006952 int err;
6953
Dustin Brown491d54b2018-03-14 12:39:11 -07006954 hdd_enter();
Dustin Brownf27bce82016-11-03 12:52:27 -07006955
Dustin Brown920397d2017-12-13 16:27:50 -08006956 hdd_for_each_adapter(hdd_ctx, adapter) {
6957 if (adapter->device_mode == QDF_STA_MODE ||
6958 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6959 adapter->device_mode == QDF_IBSS_MODE ||
6960 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6961 adapter->device_mode == QDF_SAP_MODE ||
6962 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07006963 err = wlan_hdd_sched_scan_stop(adapter->dev);
6964 if (err)
6965 hdd_err("Unable to stop scheduled scan");
6966 }
Dustin Brownf27bce82016-11-03 12:52:27 -07006967 }
6968
Dustin Browne74003f2018-03-14 12:51:58 -07006969 hdd_exit();
Dustin Brownf27bce82016-11-03 12:52:27 -07006970
6971 return QDF_STATUS_SUCCESS;
6972}
6973
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006974#ifdef WLAN_NS_OFFLOAD
6975/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006976 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006977 * @hdd_ctx: Pointer to hdd context
6978 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006979 * Unregister for IPv6 address change notifications.
6980 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006981 * Return: None
6982 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006983static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006984{
6985 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006986}
6987
6988/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006989 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006990 * @hdd_ctx: Pointer to hdd context
6991 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006992 * Register for IPv6 address change notifications.
6993 *
6994 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006995 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006996static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006997{
6998 int ret;
6999
7000 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
7001 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007002 if (ret) {
7003 hdd_err("Failed to register IPv6 notifier: %d", ret);
7004 goto out;
7005 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007006
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007007 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007008out:
7009 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007010}
7011#else
7012/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007013 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007014 * @hdd_ctx: Pointer to hdd context
7015 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007016 * Unregister for IPv6 address change notifications.
7017 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007018 * Return: None
7019 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007020static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007021{
7022}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007023
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007024/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007025 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007026 * @hdd_ctx: Pointer to hdd context
7027 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007028 * Register for IPv6 address change notifications.
7029 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007030 * Return: None
7031 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007032static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007033{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007034 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007035}
7036#endif
7037
Alok Kumarb64650c2018-03-23 17:05:11 +05307038void hdd_set_disconnect_status(struct hdd_adapter *adapter, bool status)
7039{
7040 qdf_mutex_acquire(&adapter->disconnection_status_lock);
7041 adapter->disconnection_in_progress = status;
7042 qdf_mutex_release(&adapter->disconnection_status_lock);
7043 hdd_debug("setting disconnection status: %d", status);
7044}
7045
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007046/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007047 * hdd_register_notifiers - Register netdev notifiers.
7048 * @hdd_ctx: HDD context
7049 *
7050 * Register netdev notifiers like IPv4 and IPv6.
7051 *
7052 * Return: 0 on success and errno on failure
7053 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007054static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007055{
7056 int ret;
7057
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007058 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
7059 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05307060 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007061
7062 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
7063 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
7064 if (ret) {
7065 hdd_err("Failed to register IPv4 notifier: %d", ret);
7066 goto unregister_ip6_notifier;
7067 }
7068
Alok Kumarb64650c2018-03-23 17:05:11 +05307069 ret = hdd_nud_register_netevent_notifier(hdd_ctx);
7070 if (ret) {
7071 hdd_err("Failed to register netevent notifier: %d",
7072 ret);
7073 goto unregister_inetaddr_notifier;
7074 }
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007075 return 0;
7076
Alok Kumarb64650c2018-03-23 17:05:11 +05307077unregister_inetaddr_notifier:
7078 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007079unregister_ip6_notifier:
7080 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007081out:
7082 return ret;
7083
7084}
7085
7086/**
7087 * hdd_unregister_notifiers - Unregister netdev notifiers.
7088 * @hdd_ctx: HDD context
7089 *
7090 * Unregister netdev notifiers like IPv4 and IPv6.
7091 *
7092 * Return: None.
7093 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007094void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007095{
Alok Kumarb64650c2018-03-23 17:05:11 +05307096 hdd_nud_unregister_netevent_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007097 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
7098
7099 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007100}
7101
7102/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007103 * hdd_exit_netlink_services - Exit netlink services
7104 * @hdd_ctx: HDD context
7105 *
7106 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
7107 * nl service.
7108 *
7109 * Return: None.
7110 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007111static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007112{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307113 spectral_scan_deactivate_service();
7114 cnss_diag_deactivate_service();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007115 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007116 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307117 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007118
7119 nl_srv_exit();
7120}
7121
7122/**
7123 * hdd_init_netlink_services- Init netlink services
7124 * @hdd_ctx: HDD context
7125 *
7126 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
7127 * nl service.
7128 *
7129 * Return: 0 on success and errno on failure.
7130 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007131static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007132{
7133 int ret;
7134
Ryan Hsuceddceb2016-04-28 10:20:14 -07007135 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007136 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007137 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007138 goto out;
7139 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07007140 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007141
Naveen Rawat910726a2017-03-06 11:42:51 -08007142 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007143 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007144 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007145 goto err_nl_srv;
7146 }
7147
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307148 ptt_sock_activate_svc();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007149
7150 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07007151 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007152 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007153
7154 ret = cnss_diag_activate_service();
7155 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007156 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007157 goto err_close_cesium;
7158 }
7159
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307160 spectral_scan_activate_service();
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08007161
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007162 return 0;
7163
7164err_close_cesium:
7165 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007166 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307167 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007168err_nl_srv:
7169 nl_srv_exit();
7170out:
7171 return ret;
7172}
7173
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007174/**
7175 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
7176 * @hdd_ctx: HDD context.
7177 *
7178 * Destroy RX wakelock.
7179 *
7180 * Return: None.
7181 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007182static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007183{
7184 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
7185}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007186
7187/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007188 * hdd_rx_wake_lock_create() - Create RX wakelock
7189 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007190 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007191 * Create RX wakelock.
7192 *
7193 * Return: None.
7194 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007195static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007196{
7197 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
7198}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007199
7200/**
Houston Hoffman160db392016-10-10 17:37:51 -07007201 * hdd_context_deinit() - Deinitialize HDD context
7202 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007203 *
Houston Hoffman160db392016-10-10 17:37:51 -07007204 * Deinitialize HDD context along with all the feature specific contexts but
7205 * do not free hdd context itself. Caller of this API is supposed to free
7206 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007207 *
Houston Hoffman160db392016-10-10 17:37:51 -07007208 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007209 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007210static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007211{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05307212 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
7213
Houston Hoffman160db392016-10-10 17:37:51 -07007214 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007215
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007216 hdd_sap_context_destroy(hdd_ctx);
7217
7218 hdd_rx_wake_lock_destroy(hdd_ctx);
7219
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007220 hdd_scan_context_destroy(hdd_ctx);
7221
Jeff Johnson19fc8e42017-10-30 19:53:49 -07007222 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007223
Houston Hoffman160db392016-10-10 17:37:51 -07007224 return 0;
7225}
7226
Dustin Brown623e7e32018-09-05 14:27:50 -07007227void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07007228{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07007229 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05307230
Dustin Brown623e7e32018-09-05 14:27:50 -07007231 hdd_exit_netlink_services(hdd_ctx);
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05307232 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7233
Houston Hoffman160db392016-10-10 17:37:51 -07007234 hdd_context_deinit(hdd_ctx);
7235
Dustin Browndb2df2e2018-10-31 15:29:24 -07007236 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
7237
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307238 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007239 hdd_ctx->config = NULL;
Dustin Brown84f46ea2018-02-15 11:57:36 -08007240 cfg_release();
7241
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007242 wiphy_free(hdd_ctx->wiphy);
7243}
7244
7245/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05307246 * wlan_destroy_bug_report_lock() - Destroy bug report lock
7247 *
7248 * This function is used to destroy bug report lock
7249 *
7250 * Return: None
7251 */
7252static void wlan_destroy_bug_report_lock(void)
7253{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07007254 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05307255
7256 p_cds_context = cds_get_global_context();
7257 if (!p_cds_context) {
7258 hdd_err("cds context is NULL");
7259 return;
7260 }
7261
7262 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
7263}
7264
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05307265#ifdef DISABLE_CHANNEL_LIST
7266static void wlan_hdd_cache_chann_mutex_destroy(struct hdd_context *hdd_ctx)
7267{
7268 qdf_mutex_destroy(&hdd_ctx->cache_channel_lock);
7269}
7270#else
7271static void wlan_hdd_cache_chann_mutex_destroy(struct hdd_context *hdd_ctx)
7272{
7273}
7274#endif
7275
Dustin Brown92bd8382018-10-31 15:49:46 -07007276void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007277{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007278 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05307279 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007280
Dustin Brown491d54b2018-03-14 12:39:11 -07007281 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007282
Dustin Brown4c663222018-10-23 14:19:36 -07007283 hdd_psoc_idle_timer_stop(hdd_ctx);
Dustin Brown6470aba2018-09-05 09:49:58 -07007284
Arun Khandavallifae92942016-08-01 13:31:08 +05307285 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007286
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007287#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05307288 if (QDF_TIMER_STATE_RUNNING ==
7289 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
7290 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007291 }
7292
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307293 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05307294 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07007295 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007296 }
Liangwei Dongaef84342016-10-21 05:28:00 -04007297 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
7298 qdf_mem_free(hdd_ctx->last_acs_channel_list);
7299 hdd_ctx->last_acs_channel_list = NULL;
7300 hdd_ctx->num_of_channels = 0;
7301 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007302#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007303
Arun Khandavallifae92942016-08-01 13:31:08 +05307304 mutex_lock(&hdd_ctx->iface_change_lock);
7305 driver_status = hdd_ctx->driver_status;
7306 mutex_unlock(&hdd_ctx->iface_change_lock);
7307
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007308 /*
7309 * Powersave Offload Case
7310 * Disable Idle Power Save Mode
7311 */
7312 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07007313 /* clear the scan queue in all the scenarios */
Dustin Brown07901ec2018-09-07 11:02:41 -07007314 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007315
Arun Khandavallifae92942016-08-01 13:31:08 +05307316 if (driver_status != DRIVER_MODULES_CLOSED) {
7317 hdd_unregister_wext_all_adapters(hdd_ctx);
7318 /*
7319 * Cancel any outstanding scan requests. We are about to close
7320 * all of our adapters, but an adapter structure is what SME
7321 * passes back to our callback function. Hence if there
7322 * are any outstanding scan requests then there is a
7323 * race condition between when the adapter is closed and
7324 * when the callback is invoked. We try to resolve that
7325 * race condition here by canceling any outstanding scans
7326 * before we close the adapters.
7327 * Note that the scans may be cancelled in an asynchronous
7328 * manner, so ideally there needs to be some kind of
7329 * synchronization. Rather than introduce a new
7330 * synchronization here, we will utilize the fact that we are
7331 * about to Request Full Power, and since that is synchronized,
7332 * the expectation is that by the time Request Full Power has
7333 * completed, all scans will be cancelled
7334 */
7335 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07007336 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08007337 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08007338 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007339 }
7340
Arunk Khandavalli830c9692018-03-22 12:17:40 +05307341 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavalli08479ba2017-08-07 19:56:23 +05307342 unregister_netdevice_notifier(&hdd_netdev_notifier);
7343
Rachit Kankane30807332018-06-27 18:39:36 +05307344 qdf_dp_trace_deinit();
7345
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07007346 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05307347
Visweswara Tanukuc029a202018-11-27 10:42:10 +05307348 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Dustin Brown86d196b2018-08-02 11:51:49 -07007349 hdd_bus_bandwidth_deinit(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -08007350 hdd_driver_memdump_deinit();
7351
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05307352 qdf_nbuf_deinit_replenish_timer();
7353
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05307354 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
7355 hdd_info("Release wakelock for monitor mode!");
7356 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
7357 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
7358 }
7359
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307360 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307361 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05307362 wlan_hdd_cache_chann_mutex_destroy(hdd_ctx);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307363
Naveen Rawate02f8f52018-04-05 11:58:04 -07007364 osif_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007365
Dustin Brownd005ad82018-01-19 10:32:13 -08007366 hdd_close_all_adapters(hdd_ctx, false);
7367
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05307368 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307369 /*
7370 * If there is re_init failure wiphy would have already de-registered
7371 * check the wiphy status before un-registering again
7372 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05307373 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307374 wiphy_unregister(wiphy);
7375 wlan_hdd_cfg80211_deinit(wiphy);
7376 hdd_lpass_notify_stop(hdd_ctx);
7377 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07007378
Arun Khandavallifae92942016-08-01 13:31:08 +05307379 hdd_exit_netlink_services(hdd_ctx);
7380 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307381#ifdef FEATURE_WLAN_CH_AVOID
7382 mutex_destroy(&hdd_ctx->avoid_freq_lock);
7383#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007384}
7385
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007386#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04007387/**
7388 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007389 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04007390 *
7391 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
7392 * Then new ACS request will do a fresh scan without reusing the cached
7393 * scan information.
7394 *
7395 * Return: void
7396 */
Tang Yingying523322d2017-01-17 23:28:43 +08007397static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007398{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007399 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Jeff Johnson16528362018-06-14 12:34:16 -07007400 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007401
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007402 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007403 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04007404 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
7405 qdf_mem_free(hdd_ctx->last_acs_channel_list);
7406 hdd_ctx->last_acs_channel_list = NULL;
7407 hdd_ctx->num_of_channels = 0;
7408 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007409
Jeff Johnson16528362018-06-14 12:34:16 -07007410 mac_handle = hdd_ctx->mac_handle;
7411 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007412 return;
Jeff Johnson16528362018-06-14 12:34:16 -07007413 sme_scan_flush_result(mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007414}
7415#endif
7416
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007417/**
7418 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
7419 * @state: state
7420 *
7421 * This function notifies FW with modem power status
7422 *
7423 * Return: 0 if successful, error number otherwise
7424 */
7425int hdd_wlan_notify_modem_power_state(int state)
7426{
7427 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307428 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007429 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07007430 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007431
Anurag Chouhan6d760662016-02-20 16:05:43 +05307432 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007433 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307434 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007435 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307436
Jeff Johnson16528362018-06-14 12:34:16 -07007437 mac_handle = hdd_ctx->mac_handle;
7438 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007439 return -EINVAL;
7440
Jeff Johnson16528362018-06-14 12:34:16 -07007441 qdf_status = sme_notify_modem_power_state(mac_handle, state);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307442 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007443 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007444 state);
7445 return -EINVAL;
7446 }
7447 return 0;
7448}
7449
7450/**
7451 *
7452 * hdd_post_cds_enable_config() - HDD post cds start config helper
7453 * @adapter - Pointer to the HDD
7454 *
7455 * Return: None
7456 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007457QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007458{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307459 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007460
7461 /*
7462 * Send ready indication to the HDD. This will kick off the MAC
7463 * into a 'running' state and should kick off an initial scan.
7464 */
Jeff Johnson16528362018-06-14 12:34:16 -07007465 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->mac_handle);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307466 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007467 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
7468 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307469 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007470 }
7471
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307472 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007473}
7474
Sourav Mohapatra92ea8d62018-02-05 10:03:10 +05307475struct hdd_adapter *hdd_get_first_valid_adapter(struct hdd_context *hdd_ctx)
7476{
7477 struct hdd_adapter *adapter;
7478
7479 hdd_for_each_adapter(hdd_ctx, adapter) {
7480 if (adapter && adapter->magic == WLAN_HDD_ADAPTER_MAGIC)
7481 return adapter;
7482 }
7483
7484 return NULL;
7485}
7486
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007487/* wake lock APIs for HDD */
7488void hdd_prevent_suspend(uint32_t reason)
7489{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307490 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007491}
7492
7493void hdd_allow_suspend(uint32_t reason)
7494{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307495 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007496}
7497
7498void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
7499{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05307500 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
7501 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007502}
7503
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007504/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007505QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007506{
Jeff Johnson16528362018-06-14 12:34:16 -07007507 return sme_init_chan_list(hdd_ctx->mac_handle,
Amar Singhal6f8592b2017-04-26 14:31:58 -07007508 hdd_ctx->reg.alpha2,
7509 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007510}
7511
7512/**
7513 * hdd_is_5g_supported() - check if hardware supports 5GHz
7514 * @hdd_ctx: Pointer to the hdd context
7515 *
7516 * HDD function to know if hardware supports 5GHz
7517 *
7518 * Return: true if hardware supports 5GHz
7519 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007520bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007521{
Amar Singhal58b45ef2017-08-01 13:43:54 -07007522 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08007523 return true;
7524
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08007525 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08007526 return true;
7527 else
7528 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007529}
7530
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007531static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007532{
7533 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07007534 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007535
7536 wiphy = hdd_ctx->wiphy;
7537
7538 /*
7539 * The channel information in
7540 * wiphy needs to be initialized before wiphy registration
7541 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007542 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
7543 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007544 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07007545 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007546 }
7547
7548#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
7549 wiphy->wowlan = &wowlan_support_reg_init;
7550#else
7551 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
7552 WIPHY_WOWLAN_MAGIC_PKT |
7553 WIPHY_WOWLAN_DISCONNECT |
7554 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
7555 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
7556 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
7557 WIPHY_WOWLAN_4WAY_HANDSHAKE |
7558 WIPHY_WOWLAN_RFKILL_RELEASE;
7559
7560 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
7561 WOW_MAX_FILTERS_PER_LIST);
7562 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
7563 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
7564#endif
Liangwei Dong0da14262018-07-03 03:30:23 -04007565 if (hdd_ctx->obss_scan_offload) {
7566 hdd_debug("wmi_service_obss_scan supported");
7567 } else if (hdd_ctx->config->nChannelBondingMode24GHz) {
7568 hdd_debug("enable wpa_supp obss_scan");
7569 wiphy->features |= NL80211_FEATURE_NEED_OBSS_SCAN;
7570 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007571
7572 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007573 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307574 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07007575 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307576 return ret_val;
7577 }
Amar Singhalac26de22018-06-22 12:53:06 -07007578
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007579 /* Check the kernel version for upstream commit aced43ce780dc5 that
7580 * has support for processing user cell_base hints when wiphy is
7581 * self managed or check the backport flag for the same.
7582 */
Amar Singhalac26de22018-06-22 12:53:06 -07007583#if defined CFG80211_USER_HINT_CELL_BASE_SELF_MANAGED || \
7584 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0))
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007585 hdd_send_wiphy_regd_sync_event(hdd_ctx);
7586#endif
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307587
Amar Singhal2d812012018-02-03 15:06:47 +08007588 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007589
Amar Singhale4f28ee2015-10-21 14:36:56 -07007590 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007591}
7592
Mohit Khannaca4173b2017-09-12 21:52:19 -07007593#ifdef MSM_PLATFORM
7594/**
7595 * hdd_display_periodic_stats() - Function to display periodic stats
7596 * @hdd_ctx - handle to hdd context
7597 * @bool data_in_interval - true, if data detected in bw time interval
7598 *
7599 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
7600 * Stats show up in wlan driver logs.
7601 *
7602 * Returns: None
7603 */
Mohit Khanna70322002018-05-15 19:21:32 -07007604static void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
7605 bool data_in_interval)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007606{
Mohit Khanna70322002018-05-15 19:21:32 -07007607 static uint32_t counter;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007608 static bool data_in_time_period;
7609 ol_txrx_pdev_handle pdev;
Mohit Khanna81418772018-10-30 14:14:46 -07007610 ol_txrx_soc_handle soc;
Arif Hussaincca60432018-12-03 19:45:12 -08007611 uint32_t periodic_stats_disp_time = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007612
Arif Hussaincca60432018-12-03 19:45:12 -08007613 ucfg_mlme_stats_get_periodic_display_time(hdd_ctx->psoc,
7614 &periodic_stats_disp_time);
7615 if (!periodic_stats_disp_time)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007616 return;
7617
Mohit Khanna81418772018-10-30 14:14:46 -07007618 soc = cds_get_context(QDF_MODULE_ID_SOC);
7619 if (!soc) {
7620 hdd_err("soc is NULL");
7621 return;
7622 }
7623
Mohit Khannaca4173b2017-09-12 21:52:19 -07007624 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
7625 if (!pdev) {
7626 hdd_err("pdev is NULL");
7627 return;
7628 }
7629
7630 counter++;
7631 if (data_in_interval)
7632 data_in_time_period = data_in_interval;
7633
jitiphil869b9f72018-09-25 17:14:01 +05307634 if (counter * hdd_ctx->config->bus_bw_compute_interval >=
Arif Hussaincca60432018-12-03 19:45:12 -08007635 periodic_stats_disp_time * 1000) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007636 if (data_in_time_period) {
Mohit Khanna70322002018-05-15 19:21:32 -07007637 wlan_hdd_display_txrx_stats(hdd_ctx);
Mohit Khannac9649652018-11-28 18:10:28 -08007638 dp_txrx_ext_dump_stats(soc, CDP_DP_RX_THREAD_STATS);
Mohit Khanna81418772018-10-30 14:14:46 -07007639 cdp_display_stats(soc,
Mohit Khanna70322002018-05-15 19:21:32 -07007640 CDP_RX_RING_STATS,
7641 QDF_STATS_VERBOSITY_LEVEL_LOW);
Mohit Khanna81418772018-10-30 14:14:46 -07007642 cdp_display_stats(soc,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007643 CDP_TXRX_PATH_STATS,
7644 QDF_STATS_VERBOSITY_LEVEL_LOW);
7645 wlan_hdd_display_netif_queue_history
7646 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
7647 qdf_dp_trace_dump_stats();
7648 }
7649 counter = 0;
7650 data_in_time_period = false;
7651 }
7652}
7653
Ravi Joshie2331e82015-07-01 18:18:54 -07007654/**
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007655 * hdd_clear_rps_cpu_mask - clear RPS CPU mask for interfaces
7656 * @hdd_ctx: pointer to struct hdd_context
7657 *
7658 * Return: none
7659 */
7660static void hdd_clear_rps_cpu_mask(struct hdd_context *hdd_ctx)
7661{
7662 struct hdd_adapter *adapter;
7663
7664 hdd_for_each_adapter(hdd_ctx, adapter)
7665 hdd_send_rps_disable_ind(adapter);
7666}
7667
7668/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07007669 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07007670 * @hdd_ctx - handle to hdd context
7671 * @tx_packets - transmit packet count
7672 * @rx_packets - receive packet count
7673 *
7674 * The function controls the bus bandwidth and dynamic control of
7675 * tcp delayed ack configuration
7676 *
7677 * Returns: None
7678 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007679
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007680static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07007681 const uint64_t tx_packets,
7682 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007683{
Mohit Khannaca4173b2017-09-12 21:52:19 -07007684 u64 total_pkts = tx_packets + rx_packets;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007685 uint64_t temp_tx = 0, avg_rx = 0;
7686 uint64_t no_rx_offload_pkts = 0, avg_no_rx_offload_pkts = 0;
7687 uint64_t rx_offload_pkts = 0, avg_rx_offload_pkts = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007688 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08007689 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08007690 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007691 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007692 uint16_t index = 0;
7693 bool vote_level_change = false;
7694 bool rx_level_change = false;
7695 bool tx_level_change = false;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007696 bool rxthread_high_tput_req = false;
Mohit Khannaf7562c32018-07-05 17:42:36 -07007697 bool dptrace_high_tput_req;
Srinivas Girigowda50335342018-09-07 15:21:01 -07007698
jitiphil869b9f72018-09-25 17:14:01 +05307699 if (total_pkts > hdd_ctx->config->bus_bw_high_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007700 next_vote_level = PLD_BUS_WIDTH_HIGH;
jitiphil869b9f72018-09-25 17:14:01 +05307701 else if (total_pkts > hdd_ctx->config->bus_bw_medium_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007702 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
jitiphil869b9f72018-09-25 17:14:01 +05307703 else if (total_pkts > hdd_ctx->config->bus_bw_low_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007704 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07007705 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07007706 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007707
Mohit Khannaf7562c32018-07-05 17:42:36 -07007708 dptrace_high_tput_req =
7709 next_vote_level > PLD_BUS_WIDTH_NONE ? true : false;
7710
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007711 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07007712 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
7713 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007714 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007715 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007716 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007717 if ((next_vote_level == PLD_BUS_WIDTH_LOW) ||
7718 (next_vote_level == PLD_BUS_WIDTH_NONE)) {
Nirav Shahffc6a092016-06-09 16:09:08 +05307719 if (hdd_ctx->hbw_requested) {
7720 pld_remove_pm_qos(hdd_ctx->parent_dev);
7721 hdd_ctx->hbw_requested = false;
7722 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007723 if (hdd_ctx->dynamic_rps)
7724 hdd_clear_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007725 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05307726 if (!hdd_ctx->hbw_requested) {
7727 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
7728 hdd_ctx->hbw_requested = true;
7729 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007730 if (hdd_ctx->dynamic_rps)
7731 hdd_set_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007732 }
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007733
Manjunathappa Prakashcb6df762018-05-29 18:54:58 -07007734 if (hdd_ctx->config->napi_cpu_affinity_mask)
7735 hdd_napi_apply_throughput_policy(hdd_ctx,
7736 tx_packets,
7737 rx_packets);
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007738
jitiphil869b9f72018-09-25 17:14:01 +05307739 if (rx_packets < hdd_ctx->config->bus_bw_low_threshold)
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007740 hdd_disable_rx_ol_for_low_tput(hdd_ctx, true);
7741 else
7742 hdd_disable_rx_ol_for_low_tput(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007743 }
Mohit Khannae71e2262015-11-10 09:37:24 -08007744
Mohit Khannaf7562c32018-07-05 17:42:36 -07007745 qdf_dp_trace_apply_tput_policy(dptrace_high_tput_req);
7746
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007747 /*
7748 * Includes tcp+udp, if perf core is required for tcp, then
7749 * perf core is also required for udp.
7750 */
7751 no_rx_offload_pkts = hdd_ctx->no_rx_offload_pkt_cnt;
7752 hdd_ctx->no_rx_offload_pkt_cnt = 0;
7753 rx_offload_pkts = rx_packets - no_rx_offload_pkts;
Mohit Khannae71e2262015-11-10 09:37:24 -08007754
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007755 avg_no_rx_offload_pkts = (no_rx_offload_pkts +
7756 hdd_ctx->prev_no_rx_offload_pkts) / 2;
7757 hdd_ctx->prev_no_rx_offload_pkts = no_rx_offload_pkts;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08007758
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007759 avg_rx_offload_pkts = (rx_offload_pkts +
7760 hdd_ctx->prev_rx_offload_pkts) / 2;
7761 hdd_ctx->prev_rx_offload_pkts = rx_offload_pkts;
7762
7763 avg_rx = avg_no_rx_offload_pkts + avg_rx_offload_pkts;
7764 /*
7765 * Takes care to set Rx_thread affinity for below case
7766 * 1)LRO/GRO not supported ROME case
7767 * 2)when rx_ol is disabled in cases like concurrency etc
7768 * 3)For UDP cases
7769 */
7770 if (avg_no_rx_offload_pkts >
jitiphil869b9f72018-09-25 17:14:01 +05307771 hdd_ctx->config->bus_bw_high_threshold)
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007772 rxthread_high_tput_req = true;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307773 else
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007774 rxthread_high_tput_req = false;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307775
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007776 if (cds_sched_handle_throughput_req(rxthread_high_tput_req))
7777 hdd_warn("Rx thread high_tput(%d) affinity request failed",
7778 rxthread_high_tput_req);
7779
7780 /* fine-tuning parameters for RX Flows */
jitiphil869b9f72018-09-25 17:14:01 +05307781 if (avg_rx > hdd_ctx->config->tcp_delack_thres_high) {
Ravi Joshifed83572016-10-07 16:20:37 -07007782 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
7783 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
7784 next_rx_level = WLAN_SVC_TP_HIGH;
7785 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07007786 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07007787 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08007788 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007789 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007790
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007791 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007792 struct wlan_rx_tp_data rx_tp_data = {0};
7793
Ravi Joshie2331e82015-07-01 18:18:54 -07007794 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Jeff Johnsonb9feee42018-07-08 10:34:48 -07007795 next_rx_level, avg_rx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007796 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007797 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07007798 /* Send throughput indication only if it is enabled.
7799 * Disabling tcp_del_ack will revert the tcp stack behavior
7800 * to default delayed ack. Note that this will disable the
7801 * dynamic delayed ack mechanism across the system
7802 */
Manjunathappa Prakashbfd12762018-04-29 22:44:52 -07007803 if (hdd_ctx->en_tcp_delack_no_lro)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007804 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
7805
Mohit Khanna6272fb682017-04-13 09:34:36 -07007806 if (hdd_ctx->config->enable_tcp_adv_win_scale)
7807 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
7808
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007809 rx_tp_data.level = next_rx_level;
Alok Kumar2fad6442018-11-08 19:19:28 +05307810 wlan_hdd_update_tcp_rx_param(hdd_ctx, &rx_tp_data);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007811 }
7812
Mohit Khannae71e2262015-11-10 09:37:24 -08007813 /* fine-tuning parameters for TX Flows */
7814 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
7815 hdd_ctx->prev_tx = tx_packets;
7816 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
7817 next_tx_level = WLAN_SVC_TP_HIGH;
7818 else
7819 next_tx_level = WLAN_SVC_TP_LOW;
7820
Prakash Manjunathappae73e3b52018-02-27 18:56:22 -08007821 if ((hdd_ctx->config->enable_tcp_limit_output) &&
7822 (hdd_ctx->cur_tx_level != next_tx_level)) {
Alok Kumar2fad6442018-11-08 19:19:28 +05307823 struct wlan_tx_tp_data tx_tp_data = {0};
7824
Mohit Khannae71e2262015-11-10 09:37:24 -08007825 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
7826 next_tx_level, temp_tx);
7827 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007828 tx_level_change = true;
Alok Kumar2fad6442018-11-08 19:19:28 +05307829 tx_tp_data.level = next_tx_level;
7830 tx_tp_data.tcp_limit_output = true;
7831 wlan_hdd_update_tcp_tx_param(hdd_ctx, &tx_tp_data);
Mohit Khannae71e2262015-11-10 09:37:24 -08007832 }
7833
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007834 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007835 if (vote_level_change || tx_level_change || rx_level_change) {
7836 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
7837 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
7838 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
7839 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
7840 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
7841 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
7842 hdd_ctx->hdd_txrx_hist_idx++;
7843 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
7844 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07007845
7846 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007847}
7848
7849#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Rajeev Kumarb2b5e692018-08-31 15:12:40 -07007850static void __hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007851{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007852 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307853 bus_bw_work);
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307854 struct hdd_adapter *adapter = NULL, *con_sap_adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307855 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05307856 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
7857 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007858 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307859 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007860 bool connected = false;
7861 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
7862
Prashanth Bhattaab004382016-10-11 16:08:11 -07007863 if (wlan_hdd_validate_context(hdd_ctx))
7864 return;
7865
Jeff Johnson214671b2017-10-30 19:45:23 -07007866 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08007867 goto restart_timer;
7868
Dustin Brown920397d2017-12-13 16:27:50 -08007869 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05307870 /*
7871 * Validate magic so we don't end up accessing
7872 * an invalid adapter.
7873 */
7874 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
7875 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007876
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007877 if ((adapter->device_mode == QDF_STA_MODE ||
7878 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007879 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
7880 != eConnectionState_Associated) {
7881
7882 continue;
7883 }
7884
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007885 if ((adapter->device_mode == QDF_SAP_MODE ||
7886 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07007887 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007888
7889 continue;
7890 }
7891
7892 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
7893 adapter->prev_tx_packets);
7894 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
7895 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307896
7897 if (adapter->device_mode == QDF_SAP_MODE ||
7898 adapter->device_mode == QDF_P2P_GO_MODE ||
7899 adapter->device_mode == QDF_IBSS_MODE) {
7900
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08007901 ret = cdp_get_intra_bss_fwd_pkts_count(
7902 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007903 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307904 &fwd_tx_packets, &fwd_rx_packets);
7905 if (ret == A_OK) {
7906 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
7907 fwd_tx_packets,
7908 adapter->prev_fwd_tx_packets);
7909 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
7910 fwd_tx_packets,
7911 adapter->prev_fwd_rx_packets);
7912 }
7913 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007914
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307915 if (adapter->device_mode == QDF_SAP_MODE)
7916 con_sap_adapter = adapter;
7917
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007918 total_rx += adapter->stats.rx_packets;
7919 total_tx += adapter->stats.tx_packets;
7920
7921 spin_lock_bh(&hdd_ctx->bus_bw_lock);
7922 adapter->prev_tx_packets = adapter->stats.tx_packets;
7923 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307924 adapter->prev_fwd_tx_packets = fwd_tx_packets;
7925 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007926 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
7927 connected = true;
7928 }
7929
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007930 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007931 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007932 return;
7933 }
7934
Yun Parka29974a2018-04-09 12:05:49 -07007935 /* add intra bss forwarded tx and rx packets */
7936 tx_packets += fwd_tx_packets_diff;
7937 rx_packets += fwd_rx_packets_diff;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007938
Dustin Brown07901ec2018-09-07 11:02:41 -07007939 if (ucfg_ipa_is_fw_wdi_activated(hdd_ctx->pdev)) {
7940 ucfg_ipa_uc_stat_query(hdd_ctx->pdev, &ipa_tx_packets,
7941 &ipa_rx_packets);
Yun Parka29974a2018-04-09 12:05:49 -07007942 tx_packets += (uint64_t)ipa_tx_packets;
7943 rx_packets += (uint64_t)ipa_rx_packets;
7944
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307945 if (con_sap_adapter) {
7946 con_sap_adapter->stats.tx_packets += ipa_tx_packets;
7947 con_sap_adapter->stats.rx_packets += ipa_rx_packets;
7948 }
7949
Dustin Brown07901ec2018-09-07 11:02:41 -07007950 ucfg_ipa_set_perf_level(hdd_ctx->pdev, tx_packets, rx_packets);
7951 ucfg_ipa_uc_stat_request(hdd_ctx->pdev, 2);
Yun Parka29974a2018-04-09 12:05:49 -07007952 }
7953
7954 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007955
Jingxiang Gec64e1932017-08-22 14:38:59 +08007956restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08007957 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08007958 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08007959 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05307960 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
jitiphil869b9f72018-09-25 17:14:01 +05307961 hdd_ctx->config->bus_bw_compute_interval);
Dustin Brownfce08d12017-01-17 16:29:38 -08007962 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007963}
Prashanth Bhattaab004382016-10-11 16:08:11 -07007964
Rajeev Kumarb2b5e692018-08-31 15:12:40 -07007965static void hdd_bus_bw_work_handler(struct work_struct *work)
7966{
7967 cds_ssr_protect(__func__);
7968 __hdd_bus_bw_work_handler(work);
7969 cds_ssr_unprotect(__func__);
7970}
7971
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307972/**
7973 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
7974 * @arg: Argument of timer function
7975 *
7976 * Schedule a workqueue in this function where all the processing is done.
7977 *
7978 * Return: None.
7979 */
7980static void __hdd_bus_bw_cbk(void *arg)
7981{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007982 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307983
7984 if (wlan_hdd_validate_context(hdd_ctx))
7985 return;
7986
7987 schedule_work(&hdd_ctx->bus_bw_work);
7988}
7989
7990/**
7991 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
7992 * @arg: Argument of timer function
7993 *
7994 * Return: None.
7995 */
7996static void hdd_bus_bw_cbk(void *arg)
7997{
7998 cds_ssr_protect(__func__);
7999 __hdd_bus_bw_cbk(arg);
8000 cds_ssr_unprotect(__func__);
8001}
8002
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008003int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07008004{
Dustin Brown35008ba2018-08-23 14:34:21 -07008005 hdd_enter();
8006
Prashanth Bhattaab004382016-10-11 16:08:11 -07008007 spin_lock_init(&hdd_ctx->bus_bw_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07008008 INIT_WORK(&hdd_ctx->bus_bw_work, hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08008009 hdd_ctx->bus_bw_timer_running = false;
8010 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07008011 qdf_timer_init(NULL, &hdd_ctx->bus_bw_timer, hdd_bus_bw_cbk,
8012 (void *)hdd_ctx, QDF_TIMER_TYPE_SW);
8013
8014 hdd_exit();
Prashanth Bhattaab004382016-10-11 16:08:11 -07008015
8016 return 0;
8017}
8018
Dustin Brown86d196b2018-08-02 11:51:49 -07008019void hdd_bus_bandwidth_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07008020{
Dustin Brown35008ba2018-08-23 14:34:21 -07008021 hdd_enter();
Prashanth Bhattaab004382016-10-11 16:08:11 -07008022
Rajeev Kumarc27efb62018-08-31 14:21:22 -07008023 QDF_BUG(!hdd_ctx->bus_bw_timer_running);
Dustin Brown35008ba2018-08-23 14:34:21 -07008024
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05308025 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08008026 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07008027
8028 hdd_exit();
Prashanth Bhattaab004382016-10-11 16:08:11 -07008029}
Lin Baic5c06882017-09-21 13:58:43 +08008030
Dustin Brown35008ba2018-08-23 14:34:21 -07008031#endif /* MSM_PLATFORM */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008032
8033/**
Nirav Shahed34b212016-04-25 10:59:16 +05308034 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
8035 * @hdd_ctx: hdd context
8036 *
8037 * Return: 0 for success or error code
8038 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008039static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05308040{
8041 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
8042 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Min Liu74a1a502018-10-10 19:59:07 +08008043 if (!hdd_ctx->hdd_txrx_hist)
Nirav Shahed34b212016-04-25 10:59:16 +05308044 return -ENOMEM;
Nirav Shahed34b212016-04-25 10:59:16 +05308045 return 0;
8046}
8047
8048/**
8049 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
8050 * @hdd_ctx: hdd context
8051 *
8052 * Return: none
8053 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008054void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05308055{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05308056 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
8057 return;
8058
8059 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
8060 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05308061}
8062
Nirav Shahda008342016-05-17 18:50:40 +05308063static uint8_t *convert_level_to_string(uint32_t level)
8064{
8065 switch (level) {
8066 /* initialize the wlan sub system */
8067 case WLAN_SVC_TP_NONE:
8068 return "NONE";
8069 case WLAN_SVC_TP_LOW:
8070 return "LOW";
8071 case WLAN_SVC_TP_MEDIUM:
8072 return "MED";
8073 case WLAN_SVC_TP_HIGH:
8074 return "HIGH";
8075 default:
8076 return "INVAL";
8077 }
8078}
8079
Nirav Shahed34b212016-04-25 10:59:16 +05308080
8081/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008082 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
8083 * @hdd_ctx: hdd context
8084 *
8085 * Return: none
8086 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008087void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008088{
8089 int i;
8090
8091#ifdef MSM_PLATFORM
Nirav Shahe6194ac2018-07-13 11:04:41 +05308092 hdd_nofl_info("BW compute Interval: %dms",
jitiphil869b9f72018-09-25 17:14:01 +05308093 hdd_ctx->config->bus_bw_compute_interval);
Nirav Shahe6194ac2018-07-13 11:04:41 +05308094 hdd_nofl_info("BW High TH: %d BW Med TH: %d BW Low TH: %d",
jitiphil869b9f72018-09-25 17:14:01 +05308095 hdd_ctx->config->bus_bw_high_threshold,
8096 hdd_ctx->config->bus_bw_medium_threshold,
8097 hdd_ctx->config->bus_bw_low_threshold);
Nirav Shahe6194ac2018-07-13 11:04:41 +05308098 hdd_nofl_info("Enable TCP DEL ACK: %d",
8099 hdd_ctx->en_tcp_delack_no_lro);
8100 hdd_nofl_info("TCP DEL High TH: %d TCP DEL Low TH: %d",
jitiphil869b9f72018-09-25 17:14:01 +05308101 hdd_ctx->config->tcp_delack_thres_high,
8102 hdd_ctx->config->tcp_delack_thres_low);
Nirav Shahe6194ac2018-07-13 11:04:41 +05308103 hdd_nofl_info("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
8104 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008105#endif
8106
Nirav Shahe6194ac2018-07-13 11:04:41 +05308107 hdd_nofl_info("Total entries: %d Current index: %d",
8108 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
Nirav Shahda008342016-05-17 18:50:40 +05308109
Nirav Shahe6194ac2018-07-13 11:04:41 +05308110 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 -08008111
8112 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008113 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08008114 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Nirav Shahe6194ac2018-07-13 11:04:41 +05308115 hdd_nofl_info("[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
8116 i, hdd_ctx->hdd_txrx_hist[i].qtime,
8117 hdd_ctx->hdd_txrx_hist[i].interval_rx,
8118 hdd_ctx->hdd_txrx_hist[i].interval_tx,
8119 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008120 hdd_ctx->hdd_txrx_hist[i].
8121 next_vote_level),
Nirav Shahe6194ac2018-07-13 11:04:41 +05308122 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008123 hdd_ctx->hdd_txrx_hist[i].
8124 next_rx_level),
Nirav Shahe6194ac2018-07-13 11:04:41 +05308125 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008126 hdd_ctx->hdd_txrx_hist[i].
8127 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008128 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008129}
8130
8131/**
8132 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
8133 * @hdd_ctx: hdd context
8134 *
8135 * Return: none
8136 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008137void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008138{
8139 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05308140 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
8141 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008142}
8143
Mohit Khannaca4173b2017-09-12 21:52:19 -07008144/* length of the netif queue log needed per adapter */
8145#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
8146
8147/**
8148 *
8149 * hdd_display_netif_queue_history_compact() - display compact netifq history
8150 * @hdd_ctx: hdd context
8151 *
8152 * Return: none
8153 */
8154static void
8155hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
8156{
8157 int adapter_num = 0;
8158 int i;
8159 int bytes_written;
8160 u32 tbytes;
8161 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008162 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08008163 char *comb_log_str;
8164 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008165 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008166
Dustin Brownbee82832018-07-23 10:10:51 -07008167 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * CSR_ROAM_SESSION_MAX) + 1;
jiadbdefb252018-01-03 14:27:06 +08008168 comb_log_str = qdf_mem_malloc(comb_log_str_size);
Min Liu74a1a502018-10-10 19:59:07 +08008169 if (!comb_log_str)
jiadbdefb252018-01-03 14:27:06 +08008170 return;
jiadbdefb252018-01-03 14:27:06 +08008171
Mohit Khannaca4173b2017-09-12 21:52:19 -07008172 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008173
Dustin Brown920397d2017-12-13 16:27:50 -08008174 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07008175 curr_time = qdf_system_ticks();
8176 total = curr_time - adapter->start_time;
8177 delta = curr_time - adapter->last_time;
8178
8179 if (adapter->pause_map) {
8180 pause = adapter->total_pause_time + delta;
8181 unpause = adapter->total_unpause_time;
8182 } else {
8183 unpause = adapter->total_unpause_time + delta;
8184 pause = adapter->total_pause_time;
8185 }
8186
8187 tbytes = 0;
8188 qdf_mem_set(temp_str, 0, sizeof(temp_str));
8189 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
8190 if (adapter->queue_oper_stats[i].pause_count == 0)
8191 continue;
8192 tbytes +=
8193 snprintf(
8194 &temp_str[tbytes],
8195 (tbytes >= sizeof(temp_str) ?
8196 0 : sizeof(temp_str) - tbytes),
8197 "%d(%d,%d) ",
8198 i,
8199 adapter->queue_oper_stats[i].
8200 pause_count,
8201 adapter->queue_oper_stats[i].
8202 unpause_count);
8203 }
8204 if (tbytes >= sizeof(temp_str))
8205 hdd_warn("log truncated");
8206
8207 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08008208 bytes_written >= comb_log_str_size ? 0 :
8209 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07008210 "[%d %d] (%d) %u/%ums %s|",
8211 adapter->session_id, adapter->device_mode,
8212 adapter->pause_map,
8213 qdf_system_ticks_to_msecs(pause),
8214 qdf_system_ticks_to_msecs(total),
8215 temp_str);
8216
Mohit Khannaca4173b2017-09-12 21:52:19 -07008217 adapter_num++;
8218 }
8219
8220 /* using QDF_TRACE to avoid printing function name */
8221 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
8222 "STATS |%s", comb_log_str);
8223
jiadbdefb252018-01-03 14:27:06 +08008224 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07008225 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08008226
8227 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07008228}
8229
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008230/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008231 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07008232 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008233 *
8234 * Return: none
8235 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07008236void
8237wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
8238 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008239{
8240
Jeff Johnson9d295242017-08-29 14:39:48 -07008241 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008242 int i;
Nirav Shahda008342016-05-17 18:50:40 +05308243 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008244
Mohit Khannaca4173b2017-09-12 21:52:19 -07008245 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
8246 hdd_display_netif_queue_history_compact(hdd_ctx);
8247 return;
8248 }
8249
Dustin Brown920397d2017-12-13 16:27:50 -08008250 hdd_for_each_adapter(hdd_ctx, adapter) {
Nirav Shahe6194ac2018-07-13 11:04:41 +05308251 hdd_nofl_info("Netif queue operation statistics:");
8252 hdd_nofl_info("Session_id %d device mode %d",
8253 adapter->session_id, adapter->device_mode);
8254 hdd_nofl_info("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05308255 curr_time = qdf_system_ticks();
8256 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05308257 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05308258 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05308259 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05308260 unpause = adapter->total_unpause_time;
8261 } else {
Nirav Shahda008342016-05-17 18:50:40 +05308262 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05308263 pause = adapter->total_pause_time;
8264 }
Nirav Shahe6194ac2018-07-13 11:04:41 +05308265 hdd_nofl_info("Total: %ums Pause: %ums Unpause: %ums",
8266 qdf_system_ticks_to_msecs(total),
8267 qdf_system_ticks_to_msecs(pause),
8268 qdf_system_ticks_to_msecs(unpause));
8269 hdd_nofl_info("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008270
Nirav Shahda008342016-05-17 18:50:40 +05308271 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
8272 qdf_time_t pause_delta = 0;
8273
8274 if (adapter->pause_map & (1 << i))
8275 pause_delta = delta;
8276
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008277 /* using hdd_log to avoid printing function name */
Nirav Shahe6194ac2018-07-13 11:04:41 +05308278 hdd_nofl_info("%s: %d: %d: %ums",
8279 hdd_reason_type_to_string(i),
8280 adapter->queue_oper_stats[i].pause_count,
8281 adapter->queue_oper_stats[i].
8282 unpause_count,
8283 qdf_system_ticks_to_msecs(
8284 adapter->queue_oper_stats[i].
8285 total_pause_time + pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008286 }
8287
Nirav Shahe6194ac2018-07-13 11:04:41 +05308288 hdd_nofl_info("Netif queue operation history:");
8289 hdd_nofl_info("Total entries: %d current index %d",
8290 WLAN_HDD_MAX_HISTORY_ENTRY,
8291 adapter->history_index);
Nirav Shahda008342016-05-17 18:50:40 +05308292
Nirav Shahe6194ac2018-07-13 11:04:41 +05308293 hdd_nofl_info("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008294
8295 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008296 /* using hdd_log to avoid printing function name */
8297 if (adapter->queue_oper_history[i].time == 0)
8298 continue;
Nirav Shahe6194ac2018-07-13 11:04:41 +05308299 hdd_nofl_info("%d: %u: %s: %s: %x",
8300 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008301 adapter->queue_oper_history[i].time),
Nirav Shahe6194ac2018-07-13 11:04:41 +05308302 hdd_action_type_to_string(
8303 adapter->queue_oper_history[i].
8304 netif_action),
8305 hdd_reason_type_to_string(
8306 adapter->queue_oper_history[i].
8307 netif_reason),
8308 adapter->queue_oper_history[i].pause_map);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008309 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008310 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008311}
8312
8313/**
8314 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
8315 * @hdd_ctx: hdd context
8316 *
8317 * Return: none
8318 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008319void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008320{
Jeff Johnson9d295242017-08-29 14:39:48 -07008321 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008322
Dustin Brown920397d2017-12-13 16:27:50 -08008323 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308324 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008325 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308326 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008327 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05308328 adapter->history_index = 0;
8329 adapter->start_time = adapter->last_time = qdf_system_ticks();
8330 adapter->total_pause_time = 0;
8331 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008332 }
8333}
8334
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008335#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
8336/**
8337 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
8338 * @hdd_ctx: hdd global context
8339 *
8340 * Return: none
8341 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008342static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008343{
8344 uint8_t i;
8345
8346 mutex_init(&hdd_ctx->op_ctx.op_lock);
8347 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
8348 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
8349 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
8350 }
8351}
8352#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008353static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008354{
8355}
8356#endif
8357
Yingying Tang95409972016-10-20 15:16:15 +08008358#ifdef WLAN_FEATURE_WOW_PULSE
8359/**
8360 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008361 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08008362 * @enable: enable or disable this behaviour
8363 *
8364 * Return: int
8365 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008366static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008367{
Yingying Tang95409972016-10-20 15:16:15 +08008368 struct wow_pulse_mode wow_pulse_set_info;
8369 QDF_STATUS status;
8370
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008371 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08008372
Wu Gao66454f12018-09-26 19:55:41 +08008373 if (!ucfg_pmo_is_wow_pulse_enabled(phddctx->psoc))
Yingying Tang95409972016-10-20 15:16:15 +08008374 return 0;
8375
8376 /* prepare the request to send to SME */
8377 if (enable == true) {
8378 wow_pulse_set_info.wow_pulse_enable = true;
8379 wow_pulse_set_info.wow_pulse_pin =
Wu Gao66454f12018-09-26 19:55:41 +08008380 ucfg_pmo_get_wow_pulse_pin(phddctx->psoc);
8381
Yingying Tang95409972016-10-20 15:16:15 +08008382 wow_pulse_set_info.wow_pulse_interval_high =
Wu Gao66454f12018-09-26 19:55:41 +08008383 ucfg_pmo_get_wow_pulse_interval_high(phddctx->psoc);
8384
8385 wow_pulse_set_info.wow_pulse_interval_low =
8386 ucfg_pmo_get_wow_pulse_interval_low(phddctx->psoc);
Yingying Tang95409972016-10-20 15:16:15 +08008387 } else {
8388 wow_pulse_set_info.wow_pulse_enable = false;
8389 wow_pulse_set_info.wow_pulse_pin = 0;
8390 wow_pulse_set_info.wow_pulse_interval_low = 0;
8391 wow_pulse_set_info.wow_pulse_interval_high = 0;
8392 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008393 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08008394 wow_pulse_set_info.wow_pulse_enable,
8395 wow_pulse_set_info.wow_pulse_pin,
8396 wow_pulse_set_info.wow_pulse_interval_low,
8397 wow_pulse_set_info.wow_pulse_interval_high);
8398
8399 status = sme_set_wow_pulse(&wow_pulse_set_info);
8400 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008401 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08008402 return -EIO;
8403 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008404 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08008405 return 0;
8406}
8407#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008408static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008409{
8410 return 0;
8411}
8412#endif
8413
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008414#ifdef WLAN_FEATURE_FASTPATH
jitiphil377bcc12018-10-05 19:46:08 +05308415
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008416/**
8417 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
8418 * @hdd_cfg: hdd config
8419 * @context: lower layer context
8420 *
8421 * Return: none
8422 */
jitiphil377bcc12018-10-05 19:46:08 +05308423void hdd_enable_fastpath(struct hdd_context *hdd_ctx,
8424 void *context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008425{
jitiphil377bcc12018-10-05 19:46:08 +05308426 if (cfg_get(hdd_ctx->psoc, CFG_DP_ENABLE_FASTPATH))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008427 hif_enable_fastpath(context);
8428}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008429#endif
8430
Yuanyuan Liu13738502016-04-06 17:41:37 -07008431#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008432/**
8433 * hdd_set_thermal_level_cb() - set thermal level callback function
Jeff Johnson0e963082018-07-04 19:39:20 -07008434 * @hdd_handle: opaque handle for the hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008435 * @level: thermal level
8436 *
8437 * Change IPA data path to SW path when the thermal throttle level greater
8438 * than 0, and restore the original data path when throttle level is 0
8439 *
8440 * Return: none
8441 */
Jeff Johnson0e963082018-07-04 19:39:20 -07008442static void hdd_set_thermal_level_cb(hdd_handle_t hdd_handle, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008443{
Jeff Johnson0e963082018-07-04 19:39:20 -07008444 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008445
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008446 /* Change IPA to SW path when throttle level greater than 0 */
8447 if (level > THROTTLE_LEVEL_0)
Dustin Brown07901ec2018-09-07 11:02:41 -07008448 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->pdev, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008449 else
8450 /* restore original concurrency mode */
Dustin Brown07901ec2018-09-07 11:02:41 -07008451 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->pdev, hdd_ctx->mcc_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008452}
8453
8454/**
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308455 * hdd_get_safe_channel() - Get safe channel from current regulatory
8456 * @hdd_ctx: pointer to hdd context
8457 * @adapter: pointer to softap adapter
8458 *
8459 * This function is used to get safe channel from current regulatory valid
8460 * channels to restart SAP if failed to get safe channel from PCL.
8461 *
8462 * Return: Channel number to restart SAP in case of success. In case of any
8463 * failure, the channel number returned is zero.
8464 */
8465static uint8_t
8466hdd_get_safe_channel(struct hdd_context *hdd_ctx,
8467 struct hdd_adapter *adapter)
8468{
8469 struct sir_pcl_list pcl = {0};
8470 uint32_t i, j;
8471 bool found = false;
8472 int ret;
8473
8474 /* Try for safe channel from all valid channel */
8475 pcl.pcl_len = MAX_NUM_CHAN;
8476 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
8477 &pcl.pcl_len);
8478 if (ret) {
8479 hdd_err("error %d in getting valid channel list", ret);
8480 return INVALID_CHANNEL_ID;
8481 }
8482
8483 for (i = 0; i < pcl.pcl_len; i++) {
8484 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
8485 found = false;
8486 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
8487 if (pcl.pcl_list[i] ==
8488 hdd_ctx->unsafe_channel_list[j]) {
8489 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
8490 found = true;
8491 break;
8492 }
8493 }
8494
8495 if (found)
8496 continue;
8497
8498 if ((pcl.pcl_list[i] >=
8499 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
8500 (pcl.pcl_list[i] <=
8501 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
8502 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
8503 return pcl.pcl_list[i];
8504 }
8505 }
8506
8507 return INVALID_CHANNEL_ID;
8508}
8509
8510#else
8511/**
8512 * hdd_set_thermal_level_cb() - set thermal level callback function
8513 * @hdd_handle: opaque handle for the hdd context
8514 * @level: thermal level
8515 *
8516 * Change IPA data path to SW path when the thermal throttle level greater
8517 * than 0, and restore the original data path when throttle level is 0
8518 *
8519 * Return: none
8520 */
8521static void hdd_set_thermal_level_cb(hdd_handle_t hdd_handle, u_int8_t level)
8522{
8523}
8524
8525/**
8526 * hdd_get_safe_channel() - Get safe channel from current regulatory
8527 * @hdd_ctx: pointer to hdd context
8528 * @adapter: pointer to softap adapter
8529 *
8530 * This function is used to get safe channel from current regulatory valid
8531 * channels to restart SAP if failed to get safe channel from PCL.
8532 *
8533 * Return: Channel number to restart SAP in case of success. In case of any
8534 * failure, the channel number returned is zero.
8535 */
8536static uint8_t
8537hdd_get_safe_channel(struct hdd_context *hdd_ctx,
8538 struct hdd_adapter *adapter)
8539{
8540 return 0;
8541}
8542#endif
8543
8544/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308545 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
8546 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05308547 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008548 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308549 * Get a safe channel to restart SAP. PCL already takes into account the
8550 * unsafe channels. So, the PCL is validated with the ACS range to provide
8551 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008552 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308553 * Return: Channel number to restart SAP in case of success. In case of any
8554 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008555 */
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308556static uint8_t
8557hdd_get_safe_channel_from_pcl_and_acs_range(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008558{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308559 struct sir_pcl_list pcl;
8560 QDF_STATUS status;
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308561 uint32_t i;
Jeff Johnson16528362018-06-14 12:34:16 -07008562 mac_handle_t mac_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008563 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008564
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308565 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8566 if (!hdd_ctx) {
8567 hdd_err("invalid HDD context");
8568 return INVALID_CHANNEL_ID;
8569 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008570
Jeff Johnson16528362018-06-14 12:34:16 -07008571 mac_handle = hdd_ctx->mac_handle;
8572 if (!mac_handle) {
8573 hdd_err("invalid MAC handle");
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05308574 return INVALID_CHANNEL_ID;
8575 }
8576
Dustin Brown1dbefe62018-09-11 16:32:03 -07008577 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008578 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08008579 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
8580 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308581 if (QDF_IS_STATUS_ERROR(status)) {
8582 hdd_err("Get PCL failed");
8583 return INVALID_CHANNEL_ID;
8584 }
8585
Frank Liudc2cefb2017-06-21 15:38:18 +08008586 /*
8587 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
8588 * channel is unsafe channel, the pcl may be empty, instead of return,
8589 * try to choose a safe channel from acs range.
8590 */
8591 if (!pcl.pcl_len)
8592 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308593
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008594 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07008595 adapter->session.ap.sap_config.acs_cfg.start_ch,
8596 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308597
8598 /* PCL already takes unsafe channel into account */
8599 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008600 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308601 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008602 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308603 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008604 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008605 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308606 return pcl.pcl_list[i];
8607 }
8608 }
8609
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008610 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308611
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308612 return hdd_get_safe_channel(hdd_ctx, adapter);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308613}
8614
8615/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008616 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308617 * @adapter: AP adapter
8618 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08008619 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308620 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008621 * Moves the SAP interface by invoking the function which
8622 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308623 *
8624 * Return: None
8625 */
Min Liu2fef5792018-01-19 17:59:42 +08008626void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
8627 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308628{
Jeff Johnson87251032017-08-29 13:31:11 -07008629 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008630 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07008631 mac_handle_t mac_handle;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308632
8633 if (!adapter) {
8634 hdd_err("invalid adapter");
8635 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008636 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308637
8638 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
8639
Jeff Johnson16528362018-06-14 12:34:16 -07008640 mac_handle = hdd_adapter_get_mac_handle(adapter);
8641 if (!mac_handle) {
8642 hdd_err("invalid MAC handle");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308643 return;
8644 }
8645
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008646 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8647
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008648 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07008649 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308650
Dustin Brown1dbefe62018-09-11 16:32:03 -07008651 policy_mgr_change_sap_channel_with_csa(hdd_ctx->psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07008652 adapter->session_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08008653 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008654}
Kapil Gupta8878ad92017-02-13 11:56:04 +05308655
Jeff Johnson9d295242017-08-29 14:39:48 -07008656int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05308657{
8658 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308659 int status;
8660 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308661
8662 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8663
8664 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07008665 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05308666 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07008667 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308668 }
8669 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07008670 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308671 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308672 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07008673 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308674 WLAN_VENDOR_ACS_WAIT_TIME);
8675 if (qdf_status != QDF_STATUS_SUCCESS) {
8676 hdd_err("failed to start external acs timer");
8677 return -ENOSPC;
8678 }
8679 /* Update config to application */
8680 status = hdd_cfg80211_update_acs_config(adapter, reason);
Dustin Brown5e89ef82018-03-14 11:50:23 -07008681 hdd_info("Updated ACS config to nl with reason %d", reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308682
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308683 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308684}
8685
Nirav Shaheb017be2018-02-15 11:20:58 +05308686#if defined(FEATURE_WLAN_CH_AVOID)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308687/**
8688 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
8689 * @hdd_ctx: hdd context pointer
8690 *
8691 * hdd_unsafe_channel_restart_sap check all unsafe channel list
8692 * and if ACS is enabled, driver will ask userspace to restart the
8693 * sap. User space on LTE coex indication restart driver.
8694 *
8695 * Return - none
8696 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008697void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308698{
Dustin Brown920397d2017-12-13 16:27:50 -08008699 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308700 uint32_t i;
8701 bool found = false;
8702 uint8_t restart_chan;
Krunal Sonidf29bc42018-11-15 13:26:29 -08008703 uint8_t scc_on_lte_coex = 0;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05308704 bool value;
Harprit Chhabada1eeeb8d2018-09-14 15:16:56 -07008705 QDF_STATUS status;
8706 bool is_acs_support_for_dfs_ltecoex = cfg_default(CFG_USER_ACS_DFS_LTE);
8707 bool is_vendor_acs_support =
8708 cfg_default(CFG_USER_AUTO_CHANNEL_SELECTION);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008709
Dustin Brown920397d2017-12-13 16:27:50 -08008710 hdd_for_each_adapter(hdd_ctxt, adapter) {
8711 if (!(adapter->device_mode == QDF_SAP_MODE &&
8712 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008713 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08008714 adapter->device_mode,
8715 adapter->session.ap.sap_config.
8716 acs_cfg.acs_mode);
8717 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308718 }
8719
8720 found = false;
Krunal Sonidf29bc42018-11-15 13:26:29 -08008721 status =
8722 ucfg_policy_mgr_get_sta_sap_scc_lte_coex_chnl(hdd_ctxt->psoc,
8723 &scc_on_lte_coex);
8724 if (!QDF_IS_STATUS_SUCCESS(status))
8725 hdd_err("can't get scc on lte coex chnl, use def");
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008726 /*
8727 * If STA+SAP is doing SCC & g_sta_sap_scc_on_lte_coex_chan
8728 * is set, no need to move SAP.
8729 */
Dustin Brown1dbefe62018-09-11 16:32:03 -07008730 if (policy_mgr_is_sta_sap_scc(hdd_ctxt->psoc,
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008731 adapter->session.ap.operating_channel) &&
Krunal Sonidf29bc42018-11-15 13:26:29 -08008732 scc_on_lte_coex)
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008733 hdd_debug("SAP is allowed on SCC channel, no need to move SAP");
8734 else {
8735 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
8736 if (adapter->session.ap.operating_channel ==
8737 hdd_ctxt->unsafe_channel_list[i]) {
8738 found = true;
8739 hdd_debug("operating ch:%d is unsafe",
8740 adapter->session.ap.operating_channel);
8741 break;
8742 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308743 }
8744 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308745 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008746 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08008747 adapter->session.ap.operating_channel);
8748 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308749 }
8750
Harprit Chhabada1eeeb8d2018-09-14 15:16:56 -07008751 status = ucfg_mlme_get_acs_support_for_dfs_ltecoex(
8752 hdd_ctxt->psoc,
8753 &is_acs_support_for_dfs_ltecoex);
8754 if (!QDF_IS_STATUS_SUCCESS(status))
8755 hdd_err("get_acs_support_for_dfs_ltecoex failed,set def");
8756
8757 status = ucfg_mlme_get_vendor_acs_support(
8758 hdd_ctxt->psoc,
8759 &is_vendor_acs_support);
8760 if (!QDF_IS_STATUS_SUCCESS(status))
8761 hdd_err("get_vendor_acs_support failed, set default");
8762
8763 if (is_vendor_acs_support && is_acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08008764 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05308765 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08008766 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308767 } else
8768 restart_chan =
8769 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08008770 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308771 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008772 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308773 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008774 /*
8775 * SAP restart due to unsafe channel. While
8776 * restarting the SAP, make sure to clear
8777 * acs_channel, channel to reset to
8778 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308779 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008780 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308781 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008782 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308783 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
8784 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Dustin Brown05d81302018-09-11 16:49:22 -07008785 ucfg_mlme_get_sap_internal_restart(hdd_ctxt->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05308786 &value);
8787 hdd_debug("driver to start sap: %d", value);
8788 if (value)
Min Liu2fef5792018-01-19 17:59:42 +08008789 hdd_switch_sap_channel(adapter, restart_chan,
8790 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04008791 else
8792 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308793 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308794 }
8795}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05308796
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008797/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008798 * hdd_init_channel_avoidance() - Initialize channel avoidance
8799 * @hdd_ctx: HDD global context
8800 *
8801 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07008802 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008803 * down to the lower layers. Then subscribe to subsequent channel
8804 * avoidance events.
8805 *
8806 * Return: None
8807 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008808static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008809{
8810 uint16_t unsafe_channel_count;
8811 int index;
8812
Yuanyuan Liu13738502016-04-06 17:41:37 -07008813 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
8814 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008815 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08008816 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008817
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008818 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008819 hdd_ctx->unsafe_channel_count);
8820
Anurag Chouhan6d760662016-02-20 16:05:43 +05308821 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08008822 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008823
8824 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008825 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008826 hdd_ctx->unsafe_channel_list[index]);
8827
8828 }
8829
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008830}
Dustin Brown676a2322017-08-15 13:16:13 -07008831
Jeff Johnson9d295242017-08-29 14:39:48 -07008832static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008833 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008834{
8835 uint8_t restart_chan;
8836
8837 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
8838 if (!restart_chan) {
8839 hdd_alert("fail to restart SAP");
8840 return;
8841 }
8842
8843 /* SAP restart due to unsafe channel. While restarting
8844 * the SAP, make sure to clear acs_channel, channel to
8845 * reset to 0. Otherwise these settings will override
8846 * the ACS while restart.
8847 */
8848 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07008849
8850 hdd_debug("sending coex indication");
8851
8852 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
8853 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08008854 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07008855}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008856
8857int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
8858 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
8859{
8860 uint32_t size;
8861 uint16_t *unsafe_list;
8862 uint16_t chan_count;
8863
8864 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
8865 return -EINVAL;
8866
8867 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
8868 NUM_CHANNELS);
8869 if (chan_count) {
8870 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
8871 unsafe_list = qdf_mem_malloc(size);
Min Liu74a1a502018-10-10 19:59:07 +08008872 if (!unsafe_list)
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008873 return -ENOMEM;
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008874 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
8875 } else {
8876 unsafe_list = NULL;
8877 }
8878
8879 *local_unsafe_list = unsafe_list;
8880 *local_unsafe_list_count = chan_count;
8881
8882 return 0;
8883}
8884
8885bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
8886 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
8887{
8888 int i, j;
8889
8890 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
8891 return true;
8892 if (local_unsafe_list_count == 0)
8893 return false;
8894 for (i = 0; i < local_unsafe_list_count; i++) {
8895 for (j = 0; j < local_unsafe_list_count; j++)
8896 if (local_unsafe_list[i] ==
8897 hdd_ctx->unsafe_channel_list[j])
8898 break;
8899 if (j >= local_unsafe_list_count)
8900 break;
8901 }
8902 if (i >= local_unsafe_list_count) {
8903 hdd_info("unsafe chan list same");
8904 return false;
8905 }
8906
8907 return true;
8908}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008909#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008910static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008911{
8912}
Dustin Brown676a2322017-08-15 13:16:13 -07008913
Jeff Johnson9d295242017-08-29 14:39:48 -07008914static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008915 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008916{
8917 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
8918}
Yuanyuan Liu13738502016-04-06 17:41:37 -07008919#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008920
8921/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08008922 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
8923 * user space
8924 * @frame_ind: Management frame data to be informed.
8925 *
8926 * This function is used to indicate management frame to
8927 * user space
8928 *
8929 * Return: None
8930 *
8931 */
8932void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
8933{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008934 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07008935 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008936 int i;
Pragaspathi Thilagaraj28ffc042018-07-18 15:19:36 +05308937 struct ieee80211_mgmt *mgmt =
8938 (struct ieee80211_mgmt *)frame_ind->frameBuf;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008939
Dustin Browne7e71d32018-05-11 16:00:08 -07008940 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
8941 if (wlan_hdd_validate_context(hdd_ctx))
Rajeev Kumard004abc2016-02-17 12:09:56 -08008942 return;
8943
Pragaspathi Thilagaraj28ffc042018-07-18 15:19:36 +05308944 if (frame_ind->frame_len < ieee80211_hdrlen(mgmt->frame_control)) {
8945 hdd_err(" Invalid frame length");
8946 return;
8947 }
8948
Rajeev Kumard004abc2016-02-17 12:09:56 -08008949 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
8950 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
8951 adapter =
8952 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
8953 if (adapter)
8954 break;
8955 }
Wu Gaoa0230a62018-01-04 20:56:57 +08008956 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
8957 hdd_for_each_adapter(hdd_ctx, adapter) {
8958 if ((NULL != adapter) &&
8959 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
8960 __hdd_indicate_mgmt_frame(adapter,
8961 frame_ind->frame_len,
8962 frame_ind->frameBuf,
8963 frame_ind->frameType,
8964 frame_ind->rxChan,
8965 frame_ind->rxRssi);
8966 }
8967 }
8968 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008969 } else {
8970 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
8971 frame_ind->sessionId);
8972 }
8973
8974 if ((NULL != adapter) &&
8975 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
8976 __hdd_indicate_mgmt_frame(adapter,
8977 frame_ind->frame_len,
8978 frame_ind->frameBuf,
8979 frame_ind->frameType,
8980 frame_ind->rxChan,
8981 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008982}
8983
Kapil Gupta8878ad92017-02-13 11:56:04 +05308984void hdd_acs_response_timeout_handler(void *context)
8985{
8986 struct hdd_external_acs_timer_context *timer_context =
8987 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07008988 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008989 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308990 uint8_t reason;
8991
Dustin Brown491d54b2018-03-14 12:39:11 -07008992 hdd_enter();
Kapil Gupta8878ad92017-02-13 11:56:04 +05308993 if (!timer_context) {
8994 hdd_err("invlaid timer context");
8995 return;
8996 }
8997 adapter = timer_context->adapter;
8998 reason = timer_context->reason;
8999
9000
9001 if ((!adapter) ||
9002 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
9003 hdd_err("invalid adapter or adapter has invalid magic");
9004 return;
9005 }
9006 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
9007 if (wlan_hdd_validate_context(hdd_ctx))
9008 return;
9009
9010 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
9011 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
9012 else
9013 return;
9014
9015 hdd_err("ACS timeout happened for %s reason %d",
9016 adapter->dev->name, reason);
Jeff Johnson16528362018-06-14 12:34:16 -07009017
Kapil Gupta8878ad92017-02-13 11:56:04 +05309018 switch (reason) {
9019 /* SAP init case */
9020 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
9021 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
9022 false);
9023 wlan_hdd_cfg80211_start_acs(adapter);
9024 break;
9025 /* DFS detected on current channel */
9026 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
9027 wlan_sap_update_next_channel(
9028 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
Jeff Johnson16528362018-06-14 12:34:16 -07009029 sme_update_new_channel_event(hdd_ctx->mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07009030 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05309031 break;
9032 /* LTE coex event on current channel */
9033 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
9034 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
9035 break;
9036 default:
9037 hdd_info("invalid reason for timer invoke");
9038
9039 }
9040}
9041
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009042/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009043 * hdd_override_ini_config - Override INI config
9044 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009045 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009046 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009047 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009048 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009049 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009050static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009051{
Abhinav Kumard4d6eb72018-12-04 20:30:37 +05309052 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009053
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009054 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
9055 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009056 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009057 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009058 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009059 if (0 == enable_11d || 1 == enable_11d) {
Abhinav Kumard4d6eb72018-12-04 20:30:37 +05309060 status = ucfg_mlme_set_11d_enabled(hdd_ctx->psoc, enable_11d);
9061 if (!QDF_IS_STATUS_SUCCESS(status))
9062 hdd_err("Failed to set 11d_enable flag");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009063 }
Leo Chang11545d62016-10-17 14:53:50 -07009064
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +05309065 if (hdd_ctx->config->action_oui_enable && !ucfg_action_oui_enabled()) {
9066 hdd_ctx->config->action_oui_enable = 0;
Sourav Mohapatra58841062018-11-19 16:33:27 +05309067 hdd_err("Ignore action oui ini, since no action_oui component");
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +05309068 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009069}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009070
Ashish Kumar Dhanotiya12f68212018-09-04 22:00:14 +05309071#ifdef ENABLE_MTRACE_LOG
9072static void hdd_set_mtrace_for_each(struct hdd_context *hdd_ctx)
9073{
9074 uint8_t module_id = 0;
9075 int qdf_print_idx = -1;
9076
9077 qdf_print_idx = qdf_get_pidx();
9078 for (module_id = 0; module_id < QDF_MODULE_ID_MAX; module_id++)
9079 qdf_print_set_category_verbose(
9080 qdf_print_idx,
9081 module_id, QDF_TRACE_LEVEL_TRACE,
9082 hdd_ctx->config->enable_mtrace);
9083}
9084#else
9085static void hdd_set_mtrace_for_each(struct hdd_context *hdd_ctx)
9086{
9087}
9088
9089#endif
9090
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009091/**
9092 * hdd_set_trace_level_for_each - Set trace level for each INI config
9093 * @hdd_ctx - HDD context
9094 *
9095 * Set trace level for each module based on INI config.
9096 *
9097 * Return: None
9098 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009099static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009100{
Wu Gaobc6eaa12018-11-30 14:17:45 +08009101 hdd_qdf_trace_enable(QDF_MODULE_ID_DP, 0x7f);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05309102 hdd_qdf_trace_enable(QDF_MODULE_ID_MLME, 0xffff);
Sourav Mohapatra113685f2018-08-29 14:21:55 +05309103 hdd_qdf_trace_enable(QDF_MODULE_ID_FWOL, 0xffff);
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07009104 hdd_qdf_trace_enable(QDF_MODULE_ID_CRYPTO, 0xffff);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07009105
Ashish Kumar Dhanotiya12f68212018-09-04 22:00:14 +05309106 hdd_set_mtrace_for_each(hdd_ctx);
9107
Nirav Shah5c083da2018-08-03 13:46:02 +05309108 hdd_cfg_print_global_config(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009109}
9110
9111/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009112 * hdd_context_init() - Initialize HDD context
9113 * @hdd_ctx: HDD context.
9114 *
9115 * Initialize HDD context along with all the feature specific contexts.
9116 *
9117 * return: 0 on success and errno on failure.
9118 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009119static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009120{
9121 int ret;
9122
9123 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
9124 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
9125
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009126 init_completion(&hdd_ctx->mc_sus_event_var);
9127 init_completion(&hdd_ctx->ready_to_suspend);
9128
9129 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009130 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05309131
Dustin Brownbee82832018-07-23 10:10:51 -07009132 qdf_list_create(&hdd_ctx->hdd_adapters, 0);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009133
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009134 ret = hdd_scan_context_init(hdd_ctx);
9135 if (ret)
9136 goto list_destroy;
9137
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009138 hdd_rx_wake_lock_create(hdd_ctx);
9139
9140 ret = hdd_sap_context_init(hdd_ctx);
9141 if (ret)
9142 goto scan_destroy;
9143
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009144 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
9145
9146 hdd_init_offloaded_packets_ctx(hdd_ctx);
9147
9148 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
9149 hdd_ctx->config);
9150 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08009151 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009152
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05309153 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
9154 "monitor_mode_wakelock");
9155
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009156 return 0;
9157
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009158sap_destroy:
9159 hdd_sap_context_destroy(hdd_ctx);
9160
9161scan_destroy:
9162 hdd_scan_context_destroy(hdd_ctx);
9163 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009164list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07009165 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08009166
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009167 return ret;
9168}
9169
Dustin Brown4c663222018-10-23 14:19:36 -07009170void hdd_psoc_idle_timer_start(struct hdd_context *hdd_ctx)
9171{
9172 uint32_t timeout_ms = hdd_ctx->config->iface_change_wait_time;
9173 enum wake_lock_reason reason =
9174 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER;
9175
Rajeev Kumar7b7bb3f2018-12-20 12:09:54 -08009176 if (!timeout_ms) {
9177 hdd_info("psoc idle timer is disabled");
9178 return;
9179 }
9180
Dustin Brown4c663222018-10-23 14:19:36 -07009181 hdd_debug("Starting psoc idle timer");
9182 qdf_sched_delayed_work(&hdd_ctx->psoc_idle_timeout_work, timeout_ms);
9183 hdd_prevent_suspend_timeout(timeout_ms, reason);
9184}
9185
9186void hdd_psoc_idle_timer_stop(struct hdd_context *hdd_ctx)
9187{
9188 qdf_cancel_delayed_work(&hdd_ctx->psoc_idle_timeout_work);
9189 hdd_debug("Stopped psoc idle timer");
9190}
9191
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009192/**
Dustin Brown3ecc8782018-09-19 16:37:13 -07009193 * hdd_psoc_idle_shutdown() - perform an idle shutdown on the given psoc
9194 * @hdd_ctx: the hdd context which should be shutdown
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309195 *
Dustin Brown3ecc8782018-09-19 16:37:13 -07009196 * When no interfaces are "up" on a psoc, an idle shutdown timer is started.
9197 * If no interfaces are brought up before the timer expires, we do an
9198 * "idle shutdown," cutting power to the physical SoC to save power. This is
9199 * done completely transparently from the perspective of userspace.
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309200 *
Dustin Brown3ecc8782018-09-19 16:37:13 -07009201 * Return: None
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309202 */
Dustin Brown3ecc8782018-09-19 16:37:13 -07009203static void hdd_psoc_idle_shutdown(struct hdd_context *hdd_ctx)
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309204{
Dustin Brown3ecc8782018-09-19 16:37:13 -07009205 struct hdd_psoc *hdd_psoc = hdd_ctx->hdd_psoc;
9206 QDF_STATUS status;
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309207
Dustin Brown491d54b2018-03-14 12:39:11 -07009208 hdd_enter();
Dustin Brown3ecc8782018-09-19 16:37:13 -07009209
9210 status = dsc_psoc_trans_start(hdd_psoc->dsc_psoc, "idle shutdown");
9211 if (QDF_IS_STATUS_ERROR(status)) {
9212 hdd_info("psoc busy, abort idle shutdown; status:%u", status);
9213 return;
9214 }
9215
9216 QDF_BUG(!hdd_wlan_stop_modules(hdd_ctx, false));
9217
9218 hdd_psoc->state = psoc_state_idle;
9219 dsc_psoc_trans_stop(hdd_psoc->dsc_psoc);
9220
Dustin Browne74003f2018-03-14 12:51:58 -07009221 hdd_exit();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309222}
9223
Dustin Brown3ecc8782018-09-19 16:37:13 -07009224int hdd_psoc_idle_restart(struct hdd_context *hdd_ctx)
9225{
9226 struct hdd_psoc *hdd_psoc = hdd_ctx->hdd_psoc;
9227 QDF_STATUS status;
9228 int errno;
9229
9230 status = dsc_psoc_trans_start_wait(hdd_psoc->dsc_psoc, "idle restart");
9231 if (QDF_IS_STATUS_ERROR(status)) {
9232 hdd_info("unable to start 'idle restart'; status:%u", status);
9233 return qdf_status_to_os_return(status);
9234 }
9235
9236 errno = hdd_wlan_start_modules(hdd_ctx, false);
9237 if (!errno)
9238 hdd_psoc->state = psoc_state_active;
9239
9240 dsc_psoc_trans_stop(hdd_psoc->dsc_psoc);
9241
9242 return errno;
9243}
9244
9245/**
9246 * hdd_psoc_idle_timeout_callback() - Handler for psoc idle timeout
9247 * @priv: pointer to hdd context
9248 *
9249 * Return: None
9250 */
9251static void hdd_psoc_idle_timeout_callback(void *priv)
9252{
9253 struct hdd_context *hdd_ctx = priv;
9254
9255 if (wlan_hdd_validate_context(hdd_ctx))
9256 return;
9257
9258 hdd_debug("Psoc idle timeout elapsed; starting psoc shutdown");
9259 hdd_psoc_idle_shutdown(hdd_ctx);
9260}
9261
Nirav Shaheb017be2018-02-15 11:20:58 +05309262#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9263static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
9264{
9265 wlan_logging_set_log_to_console(hdd_ctx->config->
9266 wlan_logging_to_console);
9267 wlan_logging_set_active(hdd_ctx->config->wlan_logging_enable);
9268}
9269#else
9270static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
9271{ }
9272#endif
9273
Dundi Raviteja8e338282018-09-25 17:16:04 +05309274#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9275static void hdd_init_wlan_logging_params(struct hdd_config *config,
9276 struct wlan_objmgr_psoc *psoc)
9277{
9278 config->wlan_logging_enable = cfg_get(psoc, CFG_WLAN_LOGGING_SUPPORT);
9279
9280 config->wlan_logging_to_console =
9281 cfg_get(psoc, CFG_WLAN_LOGGING_CONSOLE_SUPPORT);
9282}
9283#else
9284static void hdd_init_wlan_logging_params(struct hdd_config *config,
9285 struct wlan_objmgr_psoc *psoc)
9286{
9287}
9288#endif
9289
9290#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9291static void hdd_init_wlan_auto_shutdown(struct hdd_config *config,
9292 struct wlan_objmgr_psoc *psoc)
9293{
9294 config->wlan_auto_shutdown = cfg_get(psoc, CFG_WLAN_AUTO_SHUTDOWN);
9295}
9296#else
9297static void hdd_init_wlan_auto_shutdown(struct hdd_config *config,
9298 struct wlan_objmgr_psoc *psoc)
9299{
9300}
9301#endif
9302
9303#ifndef REMOVE_PKT_LOG
9304static void hdd_init_packet_log(struct hdd_config *config,
9305 struct wlan_objmgr_psoc *psoc)
9306{
9307 config->enable_packet_log = cfg_get(psoc, CFG_ENABLE_PACKET_LOG);
9308}
9309#else
9310static void hdd_init_packet_log(struct hdd_config *config,
9311 struct wlan_objmgr_psoc *psoc)
9312{
9313}
9314#endif
9315
Sandeep Puligilla43b6d1a2018-12-03 09:16:13 -08009316#ifdef ENABLE_MTRACE_LOG
9317static void hdd_init_mtrace_log(struct hdd_config *config,
9318 struct wlan_objmgr_psoc *psoc)
9319{
9320 config->enable_mtrace = cfg_get(psoc, CFG_ENABLE_MTRACE);
9321}
9322#else
9323static void hdd_init_mtrace_log(struct hdd_config *config,
9324 struct wlan_objmgr_psoc *psoc)
9325{
9326}
9327#endif
9328
Sourav Mohapatra0dfe5552018-11-16 11:29:54 +05309329#ifdef FEATURE_RUNTIME_PM
9330static void hdd_init_runtime_pm(struct hdd_config *config,
9331 struct wlan_objmgr_psoc *psoc)
9332{
9333 config->runtime_pm = cfg_get(psoc, CFG_ENABLE_RUNTIME_PM);
9334}
9335#else
9336static void hdd_init_runtime_pm(struct hdd_config *config,
9337 struct wlan_objmgr_psoc *psoc)
9338
9339{
9340}
9341#endif
9342
9343#ifdef FEATURE_WLAN_DYNAMIC_CVM
9344static void hdd_init_vc_mode_cfg_bitmap(struct hdd_config *config,
9345 struct wlan_objmgr_psoc *psoc)
9346{
9347 config->vc_mode_cfg_bitmap = cfg_get(psoc, CFG_VC_MODE_BITMAP);
9348}
9349#else
9350static void hdd_init_vc_mode_cfg_bitmap(struct hdd_config *config,
9351 struct wlan_objmgr_psoc *psoc)
9352{
9353}
9354#endif
9355
Dundi Raviteja8e338282018-09-25 17:16:04 +05309356/**
9357 * hdd_cfg_params_init() - Initialize hdd params in hdd_config strucuture
9358 * @hdd_ctx - Pointer to HDD context
9359 *
9360 * Return: None
9361 */
9362static void hdd_cfg_params_init(struct hdd_context *hdd_ctx)
9363{
9364 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
9365 struct hdd_config *config = hdd_ctx->config;
9366
9367 if (!psoc) {
9368 hdd_err("Invalid psoc");
9369 return;
9370 }
9371
9372 if (!config) {
9373 hdd_err("Invalid hdd config");
9374 return;
9375 }
9376
9377 config->bug_on_reinit_failure = cfg_get(psoc,
9378 CFG_BUG_ON_REINIT_FAILURE);
9379
9380 config->is_ramdump_enabled = cfg_get(psoc,
9381 CFG_ENABLE_RAMDUMP_COLLECTION);
9382
9383 config->iface_change_wait_time = cfg_get(psoc,
9384 CFG_INTERFACE_CHANGE_WAIT);
9385
9386 config->multicast_host_fw_msgs = cfg_get(psoc,
9387 CFG_MULTICAST_HOST_FW_MSGS);
9388
9389 config->private_wext_control = cfg_get(psoc, CFG_PRIVATE_WEXT_CONTROL);
9390 config->timer_multiplier = cfg_get(psoc, CFG_TIMER_MULTIPLIER);
9391 config->enablefwprint = cfg_get(psoc, CFG_ENABLE_FW_UART_PRINT);
9392 config->enable_fw_log = cfg_get(psoc, CFG_ENABLE_FW_LOG);
Vignesh Viswanathana0358ff2018-11-27 09:53:07 +05309393 config->operating_channel = cfg_get(psoc, CFG_OPERATING_CHANNEL);
9394 config->num_vdevs = cfg_get(psoc, CFG_NUM_VDEV_ENABLE);
Vignesh Viswanathana0358ff2018-11-27 09:53:07 +05309395 qdf_str_lcopy(config->enable_concurrent_sta,
9396 cfg_get(psoc, CFG_ENABLE_CONCURRENT_STA),
9397 CFG_CONCURRENT_IFACE_MAX_LEN);
9398 qdf_str_lcopy(config->dbs_scan_selection,
9399 cfg_get(psoc, CFG_DBS_SCAN_SELECTION),
9400 CFG_DBS_SCAN_PARAM_LENGTH);
Sourav Mohapatra0dfe5552018-11-16 11:29:54 +05309401 config->inform_bss_rssi_raw = cfg_get(psoc, CFG_INFORM_BSS_RSSI_RAW);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05309402 config->mac_provision = cfg_get(psoc, CFG_ENABLE_MAC_PROVISION);
9403 config->provisioned_intf_pool =
9404 cfg_get(psoc, CFG_PROVISION_INTERFACE_POOL);
9405 config->derived_intf_pool = cfg_get(psoc, CFG_DERIVED_INTERFACE_POOL);
Sourav Mohapatra58841062018-11-19 16:33:27 +05309406 config->action_oui_enable = cfg_get(psoc, CFG_ENABLE_ACTION_OUI);
Sourav Mohapatra58841062018-11-19 16:33:27 +05309407 qdf_str_lcopy(config->action_oui_str[0],
9408 cfg_get(psoc, CFG_ACTION_OUI_CONNECT_1X1),
9409 ACTION_OUI_MAX_STR_LEN);
9410 qdf_str_lcopy(config->action_oui_str[1],
9411 cfg_get(psoc, CFG_ACTION_OUI_ITO_EXTENSION),
9412 ACTION_OUI_MAX_STR_LEN);
9413 qdf_str_lcopy(config->action_oui_str[2],
9414 cfg_get(psoc, CFG_ACTION_OUI_CCKM_1X1),
9415 ACTION_OUI_MAX_STR_LEN);
9416 qdf_str_lcopy(config->action_oui_str[3],
9417 cfg_get(psoc, CFG_ACTION_OUI_ITO_ALTERNATE),
9418 ACTION_OUI_MAX_STR_LEN);
9419 qdf_str_lcopy(config->action_oui_str[4],
9420 cfg_get(psoc, CFG_ACTION_OUI_SWITCH_TO_11N_MODE),
9421 ACTION_OUI_MAX_STR_LEN);
9422 qdf_str_lcopy(config->action_oui_str[5],
9423 cfg_get(psoc,
9424 CFG_ACTION_OUI_CONNECT_1X1_WITH_1_CHAIN),
9425 ACTION_OUI_MAX_STR_LEN);
Rajeev Kumar Sirasanagandlad7987f12018-12-08 23:24:04 +05309426 qdf_str_lcopy(config->action_oui_str[6],
9427 cfg_get(psoc,
9428 CFG_ACTION_OUI_DISABLE_AGGRESSIVE_TX),
9429 ACTION_OUI_MAX_STR_LEN);
Sourav Mohapatra9e014cf2018-12-11 09:39:33 +05309430 config->enable_rtt_support = cfg_get(psoc, CFG_ENABLE_RTT_SUPPORT);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309431
Sourav Mohapatra0dfe5552018-11-16 11:29:54 +05309432 hdd_init_vc_mode_cfg_bitmap(config, psoc);
9433 hdd_init_runtime_pm(config, psoc);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309434 hdd_init_wlan_auto_shutdown(config, psoc);
9435 hdd_init_wlan_logging_params(config, psoc);
9436 hdd_init_packet_log(config, psoc);
Sandeep Puligilla43b6d1a2018-12-03 09:16:13 -08009437 hdd_init_mtrace_log(config, psoc);
jitiphil869b9f72018-09-25 17:14:01 +05309438 hdd_dp_cfg_update(psoc, hdd_ctx);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309439}
9440
Dustin Brown623e7e32018-09-05 14:27:50 -07009441struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009442{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309443 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009444 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009445 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009446
Dustin Brown491d54b2018-03-14 12:39:11 -07009447 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009448
Dustin Brown92bd8382018-10-31 15:49:46 -07009449 hdd_ctx = hdd_cfg80211_wiphy_alloc();
9450 if (!hdd_ctx) {
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009451 ret = -ENOMEM;
9452 goto err_out;
9453 }
9454
Dustin Brown4c663222018-10-23 14:19:36 -07009455 qdf_create_delayed_work(&hdd_ctx->psoc_idle_timeout_work,
Dustin Brown3ecc8782018-09-19 16:37:13 -07009456 hdd_psoc_idle_timeout_callback,
Dustin Brown4c663222018-10-23 14:19:36 -07009457 hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309458
9459 mutex_init(&hdd_ctx->iface_change_lock);
9460
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009461 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05309462 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009463
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309464 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Min Liu74a1a502018-10-10 19:59:07 +08009465 if (!hdd_ctx->config) {
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009466 ret = -ENOMEM;
9467 goto err_free_hdd_context;
9468 }
9469
9470 /* Read and parse the qcom_cfg.ini file */
9471 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309472 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309473 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009474 WLAN_INI_FILE);
9475 ret = -EINVAL;
9476 goto err_free_config;
9477 }
9478
Dustin Brown84f46ea2018-02-15 11:57:36 -08009479 status = cfg_parse(WLAN_INI_FILE);
9480 if (QDF_IS_STATUS_ERROR(status))
9481 hdd_err("Failed to parse cfg %s; status:%d\n",
9482 WLAN_INI_FILE, status);
9483
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309484 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx, DEFAULT_PSOC_ID);
9485 if (ret) {
Dundi Raviteja8e338282018-09-25 17:16:04 +05309486 QDF_DEBUG_PANIC("Psoc creation fails!");
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309487 goto err_free_config;
9488 }
9489
Dundi Raviteja8e338282018-09-25 17:16:04 +05309490 hdd_cfg_params_init(hdd_ctx);
9491
Dustin Brown7f939932017-05-18 15:02:17 -07009492 hdd_debug("setting timer multiplier: %u",
9493 hdd_ctx->config->timer_multiplier);
9494 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
9495
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309496 cds_set_fatal_event(cfg_get(hdd_ctx->psoc,
9497 CFG_ENABLE_FATAL_EVENT_TRIGGER));
Abhishek Singh5ea86532016-04-27 14:10:53 +05309498
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009499 hdd_override_ini_config(hdd_ctx);
9500
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009501 ret = hdd_context_init(hdd_ctx);
9502
9503 if (ret)
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309504 goto err_hdd_objmgr_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009505
Anurag Chouhan6d760662016-02-20 16:05:43 +05309506 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009507 goto skip_multicast_logging;
9508
9509 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
9510
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07009511 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
9512 if (ret)
9513 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05309514
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009515 ret = hdd_init_netlink_services(hdd_ctx);
9516 if (ret)
9517 goto err_deinit_txrx_histogram;
9518
Nirav Shaheb017be2018-02-15 11:20:58 +05309519 hdd_set_wlan_logging(hdd_ctx);
Nirav Shahed34b212016-04-25 10:59:16 +05309520
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009521skip_multicast_logging:
9522 hdd_set_trace_level_for_each(hdd_ctx);
9523
Rajeev Kumar493a31b2017-09-29 14:01:24 -07009524 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
9525
Dustin Browne74003f2018-03-14 12:51:58 -07009526 hdd_exit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07009527
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009528 return hdd_ctx;
9529
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009530err_deinit_txrx_histogram:
9531 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
9532
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07009533err_deinit_hdd_context:
9534 hdd_context_deinit(hdd_ctx);
9535
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309536err_hdd_objmgr_destroy:
9537 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9538
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009539err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309540 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009541
9542err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309543 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08009544 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009545
9546err_out:
9547 return ERR_PTR(ret);
9548}
9549
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009550#ifdef WLAN_OPEN_P2P_INTERFACE
9551/**
9552 * hdd_open_p2p_interface - Open P2P interface
Dustin Brown61cc3932018-10-18 16:12:13 -07009553 * @hdd_ctx: HDD context
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009554 *
Dustin Brown61cc3932018-10-18 16:12:13 -07009555 * Return: QDF_STATUS
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009556 */
Dustin Brown61cc3932018-10-18 16:12:13 -07009557static QDF_STATUS hdd_open_p2p_interface(struct hdd_context *hdd_ctx)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009558{
Jeff Johnson9d295242017-08-29 14:39:48 -07009559 struct hdd_adapter *adapter;
Dustin Brown61cc3932018-10-18 16:12:13 -07009560 bool p2p_dev_addr_admin;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05309561 bool is_p2p_locally_administered = false;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009562
Dustin Brown1dbefe62018-09-11 16:32:03 -07009563 cfg_p2p_get_device_addr_admin(hdd_ctx->psoc, &p2p_dev_addr_admin);
Dustin Brown61cc3932018-10-18 16:12:13 -07009564
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05309565 if (p2p_dev_addr_admin) {
9566 if (hdd_ctx->num_provisioned_addr &&
9567 !(hdd_ctx->provisioned_mac_addr[0].bytes[0] & 0x02)) {
9568 hdd_ctx->p2p_device_address =
9569 hdd_ctx->provisioned_mac_addr[0];
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009570
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05309571 /*
9572 * Generate the P2P Device Address. This consists of
9573 * the device's primary MAC address with the locally
9574 * administered bit set.
9575 */
9576
9577 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
9578 is_p2p_locally_administered = true;
9579 } else if (!(hdd_ctx->derived_mac_addr[0].bytes[0] & 0x02)) {
9580 hdd_ctx->p2p_device_address =
9581 hdd_ctx->derived_mac_addr[0];
9582 /*
9583 * Generate the P2P Device Address. This consists of
9584 * the device's primary MAC address with the locally
9585 * administered bit set.
9586 */
9587 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
9588 is_p2p_locally_administered = true;
9589 }
9590 }
9591 if (!is_p2p_locally_administered) {
Dustin Brown61cc3932018-10-18 16:12:13 -07009592 uint8_t *p2p_dev_addr;
9593
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05309594 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx,
9595 QDF_P2P_DEVICE_MODE);
Dustin Brown61cc3932018-10-18 16:12:13 -07009596 if (!p2p_dev_addr) {
9597 hdd_err("Failed to get MAC address for new p2p device");
9598 return QDF_STATUS_E_INVAL;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009599 }
9600
Dustin Brown61cc3932018-10-18 16:12:13 -07009601 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009602 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009603 }
9604
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009605 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Dustin Brown61cc3932018-10-18 16:12:13 -07009606 hdd_ctx->p2p_device_address.bytes,
9607 NET_NAME_UNKNOWN, true);
9608 if (!adapter) {
9609 hdd_err("Failed to open p2p interface");
9610 return QDF_STATUS_E_INVAL;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009611 }
9612
Dustin Brown61cc3932018-10-18 16:12:13 -07009613 return QDF_STATUS_SUCCESS;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009614}
9615#else
Dustin Brown61cc3932018-10-18 16:12:13 -07009616static inline QDF_STATUS hdd_open_p2p_interface(struct hdd_context *hdd_ctx)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009617{
Dustin Brown61cc3932018-10-18 16:12:13 -07009618 return QDF_STATUS_SUCCESS;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009619}
9620#endif
9621
Dustin Brown61cc3932018-10-18 16:12:13 -07009622static QDF_STATUS hdd_open_ocb_interface(struct hdd_context *hdd_ctx)
Jeff Johnson957bc272017-02-02 08:54:48 -08009623{
Jeff Johnson9d295242017-08-29 14:39:48 -07009624 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08009625
9626 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05309627 wlan_hdd_get_intf_addr(hdd_ctx,
9628 QDF_OCB_MODE),
Dustin Brown61cc3932018-10-18 16:12:13 -07009629 NET_NAME_UNKNOWN, true);
9630 if (!adapter) {
Jeff Johnson957bc272017-02-02 08:54:48 -08009631 hdd_err("Failed to open 802.11p interface");
Dustin Brown61cc3932018-10-18 16:12:13 -07009632 return QDF_STATUS_E_INVAL;
Jeff Johnson957bc272017-02-02 08:54:48 -08009633 }
9634
Dustin Brown61cc3932018-10-18 16:12:13 -07009635 return QDF_STATUS_SUCCESS;
9636}
9637
9638static QDF_STATUS hdd_open_concurrent_interface(struct hdd_context *hdd_ctx)
9639{
9640 struct hdd_adapter *adapter;
9641
Vignesh Viswanathana0358ff2018-11-27 09:53:07 +05309642 if (qdf_str_eq(hdd_ctx->config->enable_concurrent_sta, ""))
Dustin Brown61cc3932018-10-18 16:12:13 -07009643 return QDF_STATUS_SUCCESS;
9644
9645 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
Vignesh Viswanathana0358ff2018-11-27 09:53:07 +05309646 hdd_ctx->config->enable_concurrent_sta,
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05309647 wlan_hdd_get_intf_addr(hdd_ctx,
9648 QDF_STA_MODE),
Dustin Brown61cc3932018-10-18 16:12:13 -07009649 NET_NAME_UNKNOWN, true);
9650 if (!adapter) {
9651 hdd_err("Failed to open concurrent station interface");
9652 return QDF_STATUS_E_INVAL;
9653 }
9654
9655 return QDF_STATUS_SUCCESS;
Jeff Johnson957bc272017-02-02 08:54:48 -08009656}
9657
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009658/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309659 * hdd_start_station_adapter()- Start the Station Adapter
9660 * @adapter: HDD adapter
9661 *
9662 * This function initializes the adapter for the station mode.
9663 *
9664 * Return: 0 on success or errno on failure.
9665 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009666int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309667{
9668 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08009669 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309670
Dustin Brownfdf17c12018-03-14 12:55:34 -07009671 hdd_enter_dev(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08009672 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9673 hdd_err("session is already opened, %d",
9674 adapter->session_id);
9675 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9676 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309677
Krunal Sonib51eec72017-11-20 21:53:01 -08009678 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
9679 if (ret) {
9680 hdd_err("failed to create vdev: %d", ret);
9681 return ret;
9682 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309683 status = hdd_init_station_mode(adapter);
9684
9685 if (QDF_STATUS_SUCCESS != status) {
9686 hdd_err("Error Initializing station mode: %d", status);
9687 return qdf_status_to_os_return(status);
9688 }
9689
Arun Khandavallifae92942016-08-01 13:31:08 +05309690 hdd_register_tx_flow_control(adapter,
9691 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009692 hdd_tx_resume_cb,
9693 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309694
Dustin Browne74003f2018-03-14 12:51:58 -07009695 hdd_exit();
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05309696
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309697 return 0;
9698}
9699
9700/**
9701 * hdd_start_ap_adapter()- Start AP Adapter
9702 * @adapter: HDD adapter
9703 *
9704 * This function initializes the adapter for the AP mode.
9705 *
9706 * Return: 0 on success errno on failure.
9707 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009708int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309709{
9710 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009711 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08009712 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08009713 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arif Hussainbd5194c2018-11-27 19:01:15 -08009714 uint32_t fine_time_meas_cap = 0;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309715
Dustin Brown491d54b2018-03-14 12:39:11 -07009716 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309717
Krunal Sonib51eec72017-11-20 21:53:01 -08009718 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9719 hdd_err("session is already opened, %d",
9720 adapter->session_id);
9721 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9722 }
9723 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009724 * In SSR case no need to create new sap context.
9725 * Otherwise create sap context first and then create
9726 * vdev as while creating the vdev, driver needs to
9727 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08009728 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009729 if (adapter->session.ap.sap_context) {
9730 is_ssr = true;
9731 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08009732 hdd_err("sap creation failed");
9733 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
9734 }
9735
9736 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
9737 adapter->session.ap.sap_context);
9738 if (ret) {
9739 hdd_err("failed to create vdev, status:%d", ret);
9740 hdd_sap_destroy_ctx(adapter);
9741 return ret;
9742 }
Naveen Rawat1af09392018-01-03 17:28:21 -08009743
Arif Hussainbd5194c2018-11-27 19:01:15 -08009744 if (adapter->device_mode == QDF_SAP_MODE) {
9745 ucfg_mlme_get_fine_time_meas_cap(hdd_ctx->psoc,
9746 &fine_time_meas_cap);
Naveen Rawat1af09392018-01-03 17:28:21 -08009747 sme_cli_set_command(adapter->session_id,
9748 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
Arif Hussainbd5194c2018-11-27 19:01:15 -08009749 (bool)(fine_time_meas_cap & WMI_FW_AP_RTT_RESPR),
Naveen Rawat1af09392018-01-03 17:28:21 -08009750 VDEV_CMD);
Arif Hussainbd5194c2018-11-27 19:01:15 -08009751 }
Naveen Rawat1af09392018-01-03 17:28:21 -08009752
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009753 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309754
9755 if (QDF_STATUS_SUCCESS != status) {
9756 hdd_err("Error Initializing the AP mode: %d", status);
9757 return qdf_status_to_os_return(status);
9758 }
9759
Arun Khandavallifae92942016-08-01 13:31:08 +05309760 hdd_register_tx_flow_control(adapter,
9761 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009762 hdd_softap_tx_resume_cb,
9763 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309764
Dustin Browne74003f2018-03-14 12:51:58 -07009765 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309766 return 0;
9767}
9768
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309769#ifdef QCA_LL_TX_FLOW_CONTROL_V2
9770/**
9771 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
9772 * @cds_cfg: CDS Configuration
9773 * @hdd_ctx: Pointer to hdd context
9774 *
9775 * Return: none
9776 */
9777static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9778 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009779 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309780{
9781 cds_cfg->tx_flow_stop_queue_th =
jitiphil47c3d9a2018-11-08 18:30:55 +05309782 cfg_get(hdd_ctx->psoc, CFG_DP_TX_FLOW_STOP_QUEUE_TH);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309783 cds_cfg->tx_flow_start_queue_offset =
jitiphil47c3d9a2018-11-08 18:30:55 +05309784 cfg_get(hdd_ctx->psoc, CFG_DP_TX_FLOW_START_QUEUE_OFFSET);
Mohit Khanna70322002018-05-15 19:21:32 -07009785 /* configuration for DP RX Threads */
9786 cds_cfg->enable_dp_rx_threads = hdd_ctx->enable_dp_rx_threads;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309787}
9788#else
9789static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9790 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009791 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309792{
9793}
9794#endif
9795
9796#ifdef FEATURE_WLAN_RA_FILTERING
9797/**
9798 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
9799 * @cds_cfg: CDS Configuration
9800 * @hdd_ctx: Pointer to hdd context
9801 *
9802 * Return: none
9803 */
Anand Kumar3b92a912016-12-05 12:01:26 +05309804static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009805 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309806{
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05309807 bool is_rate_limit_enabled;
9808 QDF_STATUS status;
9809
9810 status = ucfg_fwol_get_is_rate_limit_enabled(hdd_ctx->psoc,
9811 &is_rate_limit_enabled);
9812 if (QDF_IS_STATUS_ERROR(status))
9813 return;
9814
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309815 cds_cfg->ra_ratelimit_interval =
9816 hdd_ctx->config->RArateLimitInterval;
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05309817 cds_cfg->is_ra_ratelimit_enabled = is_rate_limit_enabled;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309818}
9819#else
Anand Kumar3b92a912016-12-05 12:01:26 +05309820static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009821 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309822{
9823}
9824#endif
9825
9826/**
9827 * hdd_update_cds_config() - API to update cds configuration parameters
9828 * @hdd_ctx: HDD Context
9829 *
9830 * Return: 0 for Success, errno on failure
9831 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009832static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309833{
9834 struct cds_config_info *cds_cfg;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309835 int value;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309836 uint8_t band_capability;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309837 uint8_t ito_repeat_count;
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309838 bool crash_inject;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309839 bool self_recovery;
9840 bool fw_timeout_crash;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309841 QDF_STATUS status;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309842
Min Liu74a1a502018-10-10 19:59:07 +08009843 cds_cfg = qdf_mem_malloc(sizeof(*cds_cfg));
9844 if (!cds_cfg)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309845 return -ENOMEM;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309846
Srinivas Girigowda35b00312017-06-27 21:52:03 -07009847 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Bala Venkatesh46e29032018-11-14 18:24:55 +05309848 ucfg_mlme_get_sap_max_modulated_dtim(hdd_ctx->psoc,
9849 &cds_cfg->sta_maxlimod_dtim);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309850
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309851 status = ucfg_mlme_get_crash_inject(hdd_ctx->psoc, &crash_inject);
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309852 if (QDF_IS_STATUS_ERROR(status)) {
9853 hdd_err("Failed to get crash inject ini config");
9854 goto exit;
9855 }
9856
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309857 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
9858 if (QDF_IS_STATUS_ERROR(status)) {
9859 hdd_err("Failed to get self recovery ini config");
9860 goto exit;
9861 }
9862
9863 status = ucfg_mlme_get_fw_timeout_crash(hdd_ctx->psoc,
9864 &fw_timeout_crash);
9865 if (QDF_IS_STATUS_ERROR(status)) {
9866 hdd_err("Failed to get fw timeout crash ini config");
9867 goto exit;
9868 }
9869
9870 status = ucfg_mlme_get_ito_repeat_count(hdd_ctx->psoc,
9871 &ito_repeat_count);
9872 if (QDF_IS_STATUS_ERROR(status)) {
9873 hdd_err("Failed to get ITO repeat count ini config");
9874 goto exit;
9875 }
9876
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309877 cds_cfg->force_target_assert_enabled = crash_inject;
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05309878
Dustin Brown05d81302018-09-11 16:49:22 -07009879 ucfg_mlme_get_sap_max_offload_peers(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309880 cds_cfg->ap_maxoffload_peers = value;
Dustin Brown05d81302018-09-11 16:49:22 -07009881 ucfg_mlme_get_sap_max_offload_reorder_buffs(hdd_ctx->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309882 &value);
9883 cds_cfg->ap_maxoffload_reorderbuffs = value;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309884
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309885 cds_cfg->reorder_offload =
jitiphil47c3d9a2018-11-08 18:30:55 +05309886 cfg_get(hdd_ctx->psoc, CFG_DP_REORDER_OFFLOAD_SUPPORT);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309887
9888 /* IPA micro controller data path offload resource config item */
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05309889 cds_cfg->uc_offload_enabled = ucfg_ipa_uc_is_enabled();
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309890 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
9891
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07009892 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Dustin Brown05d81302018-09-11 16:49:22 -07009893 ucfg_mlme_get_sap_max_peers(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309894 cds_cfg->max_station = value;
Naveen Rawat64e477e2016-05-20 10:34:56 -07009895 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07009896 cds_cfg->max_msdus_per_rxinorderind =
jitiphil8e15ea62018-11-16 18:05:34 +05309897 cfg_get(hdd_ctx->psoc, CFG_DP_MAX_MSDUS_PER_RXIND);
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309898 cds_cfg->self_recovery_enabled = self_recovery;
9899 cds_cfg->fw_timeout_crash = fw_timeout_crash;
Nachiket Kukadee547a482018-05-22 16:43:30 +05309900 cds_cfg->active_uc_apf_mode = hdd_ctx->config->active_uc_apf_mode;
9901 cds_cfg->active_mc_bc_apf_mode = hdd_ctx->config->active_mc_bc_apf_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309902
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309903 cds_cfg->ito_repeat_count = ito_repeat_count;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309904
9905 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
9906 if (QDF_IS_STATUS_ERROR(status))
9907 goto exit;
9908
9909 cds_cfg->bandcapability = band_capability;
Rachit Kankane0106e382018-05-16 18:59:28 +05309910 cds_cfg->num_vdevs = hdd_ctx->config->num_vdevs;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309911
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309912 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
9913 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07009914 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309915 cds_init_ini_config(cds_cfg);
9916 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309917
9918exit:
9919 qdf_mem_free(cds_cfg);
9920 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309921}
9922
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009923/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009924 * hdd_update_user_config() - API to update user configuration
9925 * parameters to obj mgr which are used by multiple components
9926 * @hdd_ctx: HDD Context
9927 *
9928 * Return: 0 for Success, errno on failure
9929 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009930static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009931{
9932 struct wlan_objmgr_psoc_user_config *user_config;
Wu Gaoe5689792018-07-05 19:20:13 +08009933 bool skip_dfs_in_p2p_search = false;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309934 uint8_t band_capability;
Krunal Sonidf29bc42018-11-15 13:26:29 -08009935 uint8_t dual_mac_feature = DISABLE_DBS_CXN_AND_SCAN;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309936 QDF_STATUS status;
Abhinav Kumard4d6eb72018-12-04 20:30:37 +05309937 bool value = false;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309938
9939 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
9940 if (QDF_IS_STATUS_ERROR(status))
9941 return -EIO;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009942
Krunal Sonidf29bc42018-11-15 13:26:29 -08009943 status = ucfg_policy_mgr_get_dual_mac_feature(hdd_ctx->psoc,
9944 &dual_mac_feature);
9945 if (QDF_IS_STATUS_ERROR(status))
9946 return -EIO;
9947
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009948 user_config = qdf_mem_malloc(sizeof(*user_config));
Min Liu74a1a502018-10-10 19:59:07 +08009949 if (!user_config)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009950 return -ENOMEM;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009951
9952 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
Abhinav Kumard4d6eb72018-12-04 20:30:37 +05309953 status = ucfg_mlme_is_11d_enabled(hdd_ctx->psoc, &value);
9954 if (!QDF_IS_STATUS_SUCCESS(status))
9955 hdd_err("Invalid 11d_enable flag");
9956 user_config->is_11d_support_enabled = value;
9957
9958 value = false;
9959 status = ucfg_mlme_is_11h_enabled(hdd_ctx->psoc, &value);
9960 if (!QDF_IS_STATUS_SUCCESS(status))
9961 hdd_err("Invalid 11h_enable flag");
9962 user_config->is_11h_support_enabled = value;
Dustin Brown1dbefe62018-09-11 16:32:03 -07009963 cfg_p2p_get_skip_dfs_channel_p2p_search(hdd_ctx->psoc,
Wu Gaoe5689792018-07-05 19:20:13 +08009964 &skip_dfs_in_p2p_search);
9965 user_config->skip_dfs_chnl_in_p2p_search = skip_dfs_in_p2p_search;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309966 user_config->band_capability = band_capability;
Dustin Brown1dbefe62018-09-11 16:32:03 -07009967 wlan_objmgr_psoc_set_user_config(hdd_ctx->psoc, user_config);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009968
9969 qdf_mem_free(user_config);
9970 return 0;
9971}
9972
9973/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009974 * hdd_init_thermal_info - Initialize thermal level
9975 * @hdd_ctx: HDD context
9976 *
9977 * Initialize thermal level at SME layer and set the thermal level callback
9978 * which would be called when a configured thermal threshold is hit.
9979 *
9980 * Return: 0 on success and errno on failure
9981 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009982static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009983{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309984 QDF_STATUS status;
Manikandan Mohan9045e2e2018-11-26 16:44:19 -08009985 mac_handle_t mac_handle = hdd_ctx->mac_handle;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009986
Manikandan Mohan9045e2e2018-11-26 16:44:19 -08009987 status = sme_init_thermal_info(mac_handle);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009988
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309989 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05309990 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009991
Jeff Johnson16528362018-06-14 12:34:16 -07009992 sme_add_set_thermal_level_callback(mac_handle,
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009993 hdd_set_thermal_level_cb);
9994
9995 return 0;
9996
9997}
9998
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009999#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
10000/**
10001 * hdd_hold_rtnl_lock - Hold RTNL lock
10002 *
10003 * Hold RTNL lock
10004 *
10005 * Return: True if held and false otherwise
10006 */
10007static inline bool hdd_hold_rtnl_lock(void)
10008{
10009 rtnl_lock();
10010 return true;
10011}
10012
10013/**
10014 * hdd_release_rtnl_lock - Release RTNL lock
10015 *
10016 * Release RTNL lock
10017 *
10018 * Return: None
10019 */
10020static inline void hdd_release_rtnl_lock(void)
10021{
10022 rtnl_unlock();
10023}
10024#else
10025static inline bool hdd_hold_rtnl_lock(void) { return false; }
10026static inline void hdd_release_rtnl_lock(void) { }
10027#endif
10028
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010029#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010030
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010031/* MAX iwpriv command support */
10032#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010033#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010034#define MAX_PKTLOG_SIZE 16
10035
10036/**
10037 * hdd_pktlog_set_buff_size() - set pktlog buffer size
10038 * @hdd_ctx: hdd context
10039 * @set_value2: pktlog buffer size value
10040 *
10041 *
10042 * Return: 0 for success or error.
10043 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010044static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010045{
10046 struct sir_wifi_start_log start_log = { 0 };
10047 QDF_STATUS status;
10048
10049 start_log.ring_id = RING_ID_PER_PACKET_STATS;
10050 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
10051 start_log.ini_triggered = cds_is_packet_log_enabled();
10052 start_log.user_triggered = 1;
10053 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010054 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010055
Jeff Johnson16528362018-06-14 12:34:16 -070010056 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010057 if (!QDF_IS_STATUS_SUCCESS(status)) {
10058 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -070010059 hdd_exit();
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010060 return -EINVAL;
10061 }
10062
10063 return 0;
10064}
10065
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010066/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010067 * hdd_pktlog_clear_buff() - clear pktlog buffer
10068 * @hdd_ctx: hdd context
10069 *
10070 * Return: 0 for success or error.
10071 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010072static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010073{
10074 struct sir_wifi_start_log start_log;
10075 QDF_STATUS status;
10076
10077 start_log.ring_id = RING_ID_PER_PACKET_STATS;
10078 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
10079 start_log.ini_triggered = cds_is_packet_log_enabled();
10080 start_log.user_triggered = 1;
10081 start_log.size = 0;
10082 start_log.is_pktlog_buff_clear = true;
10083
Jeff Johnson16528362018-06-14 12:34:16 -070010084 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010085 if (!QDF_IS_STATUS_SUCCESS(status)) {
10086 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -070010087 hdd_exit();
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010088 return -EINVAL;
10089 }
10090
10091 return 0;
10092}
10093
10094
10095/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010096 * hdd_process_pktlog_command() - process pktlog command
10097 * @hdd_ctx: hdd context
10098 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010099 * @set_value2: pktlog buffer size value
10100 *
10101 * This function process pktlog command.
10102 * set_value2 only matters when set_value is 3 (set buff size)
10103 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010104 *
10105 * Return: 0 for success or error.
10106 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010107int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010108 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010109{
10110 int ret;
10111 bool enable;
10112 uint8_t user_triggered = 0;
10113
10114 ret = wlan_hdd_validate_context(hdd_ctx);
10115 if (0 != ret)
10116 return ret;
10117
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010118 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010119
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010120 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010121 hdd_err("invalid pktlog value %d", set_value);
10122 return -EINVAL;
10123 }
10124
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010125 if (set_value == PKTLOG_SET_BUFF_SIZE) {
10126 if (set_value2 <= 0) {
10127 hdd_err("invalid pktlog size %d", set_value2);
10128 return -EINVAL;
10129 } else if (set_value2 > MAX_PKTLOG_SIZE) {
10130 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
10131 return -EINVAL;
10132 }
10133 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010134 } else if (set_value == PKTLOG_CLEAR_BUFF) {
10135 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010136 }
10137
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010138 /*
10139 * set_value = 0 then disable packetlog
10140 * set_value = 1 enable packetlog forcefully
10141 * set_vlaue = 2 then disable packetlog if disabled through ini or
10142 * enable packetlog with AUTO type.
10143 */
10144 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
10145 true : false;
10146
10147 if (1 == set_value) {
10148 enable = true;
10149 user_triggered = 1;
10150 }
10151
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010152 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010153}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010154
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010155/**
10156 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
10157 * @hdd_ctx: HDD context
10158 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010159 * @user_triggered: triggered through iwpriv
10160 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010161 *
10162 * Return: 0 on success; error number otherwise
10163 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010164int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010165 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010166{
10167 struct sir_wifi_start_log start_log;
10168 QDF_STATUS status;
10169
10170 start_log.ring_id = RING_ID_PER_PACKET_STATS;
10171 start_log.verbose_level =
10172 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010173 start_log.ini_triggered = cds_is_packet_log_enabled();
10174 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010175 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010176 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +053010177 /*
10178 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
10179 * commands. Host uses this flag to decide whether to send pktlog
10180 * disable command to fw without sending pktlog enable command
10181 * previously. For eg, If vendor sends pktlog disable command without
10182 * sending pktlog enable command, then host discards the packet
10183 * but for iwpriv command, host will send it to fw.
10184 */
10185 start_log.is_iwpriv_command = 1;
Jeff Johnson16528362018-06-14 12:34:16 -070010186 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010187 if (!QDF_IS_STATUS_SUCCESS(status)) {
10188 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -070010189 hdd_exit();
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010190 return -EINVAL;
10191 }
10192
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010193 if (enable == true)
10194 hdd_ctx->is_pktlog_enabled = 1;
10195 else
10196 hdd_ctx->is_pktlog_enabled = 0;
10197
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010198 return 0;
10199}
10200#endif /* REMOVE_PKT_LOG */
10201
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010202void hdd_free_mac_address_lists(struct hdd_context *hdd_ctx)
10203{
10204 hdd_debug("Resetting MAC address lists");
10205 qdf_mem_set(hdd_ctx->provisioned_mac_addr,
10206 sizeof(hdd_ctx->provisioned_mac_addr), 0);
10207 qdf_mem_set(hdd_ctx->derived_mac_addr,
10208 sizeof(hdd_ctx->derived_mac_addr), 0);
10209 hdd_ctx->num_provisioned_addr = 0;
10210 hdd_ctx->num_derived_addr = 0;
10211 hdd_ctx->provisioned_intf_addr_mask = 0;
10212 hdd_ctx->derived_intf_addr_mask = 0;
10213}
10214
Komal Seelam92fff912016-03-24 11:51:41 +053010215/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010216 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
10217 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +053010218 * @dev: Device Pointer
10219 * @num: Number of Valid Mac address
10220 *
10221 * Return: Pointer to MAC address buffer
10222 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010223static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
10224 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +053010225{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010226 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +053010227}
Komal Seelam92fff912016-03-24 11:51:41 +053010228
10229/**
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010230 * hdd_get_platform_wlan_derived_mac_buff() - API to query platform driver
10231 * for derived MAC address
10232 * @dev: Device Pointer
10233 * @num: Number of Valid Mac address
10234 *
10235 * Return: Pointer to MAC address buffer
10236 */
10237static uint8_t *hdd_get_platform_wlan_derived_mac_buff(struct device *dev,
10238 uint32_t *num)
10239{
10240 return pld_get_wlan_derived_mac_address(dev, num);
10241}
10242
10243/**
Komal Seelam92fff912016-03-24 11:51:41 +053010244 * hdd_populate_random_mac_addr() - API to populate random mac addresses
10245 * @hdd_ctx: HDD Context
10246 * @num: Number of random mac addresses needed
10247 *
10248 * Generate random addresses using bit manipulation on the base mac address
10249 *
10250 * Return: None
10251 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010252void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +053010253{
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010254 uint32_t idx = hdd_ctx->num_derived_addr;
Komal Seelam92fff912016-03-24 11:51:41 +053010255 uint32_t iter;
Komal Seelam92fff912016-03-24 11:51:41 +053010256 uint8_t *buf = NULL;
10257 uint8_t macaddr_b3, tmp_br3;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010258 /*
10259 * Consider first provisioned mac address as source address to derive
10260 * remaining addresses
10261 */
Komal Seelam92fff912016-03-24 11:51:41 +053010262
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010263 uint8_t *src = hdd_ctx->provisioned_mac_addr[0].bytes;
10264
10265 for (iter = 0; iter < num; ++iter, ++idx) {
10266 buf = hdd_ctx->derived_mac_addr[idx].bytes;
Komal Seelam92fff912016-03-24 11:51:41 +053010267 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
10268 macaddr_b3 = buf[3];
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010269 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + idx) &
Komal Seelam92fff912016-03-24 11:51:41 +053010270 INTF_MACADDR_MASK;
10271 macaddr_b3 += tmp_br3;
10272 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
10273 buf[0] |= 0x02;
10274 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010275 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010276 hdd_ctx->num_derived_addr++;
Komal Seelam92fff912016-03-24 11:51:41 +053010277 }
10278}
10279
10280/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010281 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +053010282 * @hdd_ctx: HDD Context
10283 *
10284 * API to get mac addresses from platform driver and update the driver
10285 * structures and configure FW with the base mac address.
10286 * Return: int
10287 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010288static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +053010289{
10290 uint32_t no_of_mac_addr, iter;
10291 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
10292 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
10293 uint8_t *addr, *buf;
10294 struct device *dev = hdd_ctx->parent_dev;
Komal Seelam92fff912016-03-24 11:51:41 +053010295 tSirMacAddr mac_addr;
10296 QDF_STATUS status;
10297
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010298 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +053010299
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010300 if (no_of_mac_addr == 0 || !addr) {
10301 hdd_debug("No mac configured from platform driver");
Komal Seelam92fff912016-03-24 11:51:41 +053010302 return -EINVAL;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010303 }
10304
10305 hdd_free_mac_address_lists(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +053010306
10307 if (no_of_mac_addr > max_mac_addr)
10308 no_of_mac_addr = max_mac_addr;
10309
10310 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
10311
10312 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010313 buf = hdd_ctx->provisioned_mac_addr[iter].bytes;
Komal Seelam92fff912016-03-24 11:51:41 +053010314 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010315 hdd_info("provisioned MAC Addr [%d]" MAC_ADDRESS_STR, iter,
10316 MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +053010317 }
10318
Komal Seelam92fff912016-03-24 11:51:41 +053010319
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010320 hdd_ctx->num_provisioned_addr = no_of_mac_addr;
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010321
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010322 if (hdd_ctx->config->mac_provision) {
10323 addr = hdd_get_platform_wlan_derived_mac_buff(dev,
10324 &no_of_mac_addr);
10325
10326 if (no_of_mac_addr == 0 || !addr)
10327 hdd_warn("No derived address from platform driver");
10328 else if (no_of_mac_addr >
10329 (max_mac_addr - hdd_ctx->num_provisioned_addr))
10330 no_of_mac_addr = (max_mac_addr -
10331 hdd_ctx->num_provisioned_addr);
10332
10333 for (iter = 0; iter < no_of_mac_addr; ++iter,
10334 addr += mac_addr_size) {
10335 buf = hdd_ctx->derived_mac_addr[iter].bytes;
10336 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
10337 hdd_debug("derived MAC Addr [%d]" MAC_ADDRESS_STR, iter,
10338 MAC_ADDR_ARRAY(buf));
10339 }
10340 hdd_ctx->num_derived_addr = no_of_mac_addr;
10341 }
10342
10343 no_of_mac_addr = hdd_ctx->num_provisioned_addr +
10344 hdd_ctx->num_derived_addr;
Komal Seelam92fff912016-03-24 11:51:41 +053010345 if (no_of_mac_addr < max_mac_addr)
10346 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
10347 no_of_mac_addr);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010348
10349 status = sme_set_custom_mac_addr(mac_addr);
10350 if (!QDF_IS_STATUS_SUCCESS(status))
10351 return -EAGAIN;
10352
Komal Seelam92fff912016-03-24 11:51:41 +053010353 return 0;
10354}
10355
10356/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010357 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
10358 * @hdd_ctx: HDD Context
10359 *
10360 * Update MAC address to FW. If MAC address passed by FW is invalid, host
10361 * will generate its own MAC and update it to FW.
10362 *
10363 * Return: 0 for success
10364 * Non-zero error code for failure
10365 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010366static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010367{
10368 tSirMacAddr customMacAddr;
10369 QDF_STATUS status;
10370
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010371 if (hdd_ctx->num_provisioned_addr)
10372 qdf_mem_copy(&customMacAddr,
10373 &hdd_ctx->provisioned_mac_addr[0].bytes[0],
10374 sizeof(tSirMacAddr));
10375 else
10376 qdf_mem_copy(&customMacAddr,
10377 &hdd_ctx->derived_mac_addr[0].bytes[0],
10378 sizeof(tSirMacAddr));
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010379 status = sme_set_custom_mac_addr(customMacAddr);
10380 if (!QDF_IS_STATUS_SUCCESS(status))
10381 return -EAGAIN;
10382 return 0;
10383}
10384
10385/**
Komal Seelam92fff912016-03-24 11:51:41 +053010386 * hdd_initialize_mac_address() - API to get wlan mac addresses
10387 * @hdd_ctx: HDD Context
10388 *
10389 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
10390 * is provisioned with mac addresses, driver uses it, else it will use
10391 * wlan_mac.bin to update HW MAC addresses.
10392 *
10393 * Return: None
10394 */
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010395static int hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +053010396{
10397 QDF_STATUS status;
10398 int ret;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010399 bool update_mac_addr_to_fw = true;
Komal Seelam92fff912016-03-24 11:51:41 +053010400
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010401 ret = hdd_platform_wlan_mac(hdd_ctx);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010402 if (hdd_ctx->config->mac_provision || !ret) {
Dustin Brown7e761c72018-07-31 13:50:17 -070010403 hdd_info("using MAC address from platform driver");
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010404 return ret;
Dustin Brown7e761c72018-07-31 13:50:17 -070010405 }
Komal Seelam92fff912016-03-24 11:51:41 +053010406
10407 status = hdd_update_mac_config(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010408 if (QDF_IS_STATUS_SUCCESS(status)) {
10409 hdd_info("using MAC address from wlan_mac.bin");
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010410 return 0;
Dustin Brown7e761c72018-07-31 13:50:17 -070010411 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010412
Dustin Brown7e761c72018-07-31 13:50:17 -070010413 hdd_info("using default MAC address");
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010414
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010415 /* Use fw provided MAC */
10416 if (!qdf_is_macaddr_zero(&hdd_ctx->hw_macaddr)) {
10417 hdd_update_macaddr(hdd_ctx, hdd_ctx->hw_macaddr, false);
10418 update_mac_addr_to_fw = false;
10419 return 0;
10420 } else if (hdd_generate_macaddr_auto(hdd_ctx) != 0) {
10421 struct qdf_mac_addr mac_addr;
10422
10423 hdd_err("MAC failure from device serial no.");
Jeff Johnson51a80522018-12-11 20:19:44 -080010424 qdf_get_random_bytes(&mac_addr, sizeof(mac_addr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010425 /*
10426 * Reset multicast bit (bit-0) and set
10427 * locally-administered bit
10428 */
10429 mac_addr.bytes[0] = 0x2;
10430 hdd_update_macaddr(hdd_ctx, mac_addr, true);
10431 }
10432
10433 if (update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010434 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010435 if (ret)
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -080010436 hdd_err("MAC address out-of-sync, ret:%d", ret);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010437 }
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010438 return ret;
Komal Seelam92fff912016-03-24 11:51:41 +053010439}
10440
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010441static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010442{
10443 int vdev_id = 0;
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053010444 QDF_STATUS status;
10445 bool smart_chainmask_enabled;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010446 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010447 int vpdev = PDEV_CMD;
10448 int ret;
10449
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053010450 status = ucfg_get_smart_chainmask_enabled(hdd_ctx->psoc,
10451 &smart_chainmask_enabled);
10452 if (QDF_IS_STATUS_ERROR(status))
10453 return -EINVAL;
10454
10455 ret = sme_cli_set_command(vdev_id, param_id,
10456 (int)smart_chainmask_enabled, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010457 if (ret)
10458 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
10459
10460 return ret;
10461}
10462
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010463static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010464{
10465 int vdev_id = 0;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010466 QDF_STATUS status;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010467 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010468 bool alternative_chainmask_enabled;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010469 int vpdev = PDEV_CMD;
10470 int ret;
10471
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010472 status = ucfg_get_alternative_chainmask_enabled(
10473 hdd_ctx->psoc,
10474 &alternative_chainmask_enabled);
10475 if (QDF_IS_STATUS_ERROR(status))
10476 return -EINVAL;
10477
10478 ret = sme_cli_set_command(vdev_id, param_id,
10479 (int)alternative_chainmask_enabled, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010480 if (ret)
10481 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
10482 ret);
10483
10484 return ret;
10485}
10486
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010487static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -070010488{
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010489 QDF_STATUS status;
Jeff Johnson12a744b2017-04-04 08:19:37 -070010490 int vdev_id = 0;
10491 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010492 bool value;
Jeff Johnson12a744b2017-04-04 08:19:37 -070010493 int vpdev = PDEV_CMD;
10494 int ret;
10495
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010496 status = ucfg_fwol_get_ani_enabled(hdd_ctx->psoc, &value);
10497 if (QDF_IS_STATUS_ERROR(status))
10498 return -EINVAL;
10499
10500 ret = sme_cli_set_command(vdev_id, param_id, (int)value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -070010501 if (ret)
10502 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
10503
10504 return ret;
10505}
10506
Jeff Johnson89c66ff2016-04-22 15:21:37 -070010507/**
Prashanth Bhatta07998752016-04-28 12:35:33 -070010508 * hdd_pre_enable_configure() - Configurations prior to cds_enable
10509 * @hdd_ctx: HDD context
10510 *
10511 * Pre configurations to be done at lower layer before calling cds enable.
10512 *
10513 * Return: 0 on success and errno on failure.
10514 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010515static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -070010516{
10517 int ret;
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010518 uint8_t val = 0;
Prashanth Bhatta07998752016-04-28 12:35:33 -070010519 QDF_STATUS status;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010520 uint32_t arp_ac_category;
Leo Changfdb45c32016-10-28 11:09:23 -070010521 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010522
Leo Changfdb45c32016-10-28 11:09:23 -070010523 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Ajit Pal Singh5d269612018-04-19 16:29:12 +053010524 /* Register HL netdev flow control callback */
10525 cdp_hl_fc_register(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010526
10527 /*
10528 * Note that the cds_pre_enable() sequence triggers the cfg download.
10529 * The cfg download must occur before we update the SME config
10530 * since the SME config operation must access the cfg database
10531 */
10532 status = hdd_set_sme_config(hdd_ctx);
10533
10534 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010535 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010536 ret = qdf_status_to_os_return(status);
10537 goto out;
10538 }
10539
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -070010540 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
10541 if (QDF_STATUS_SUCCESS != status) {
10542 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
10543 ret = qdf_status_to_os_return(status);
10544 goto out;
10545 }
10546
Dustin Brown1dbefe62018-09-11 16:32:03 -070010547 status = ucfg_mlme_get_tx_chainmask_1ss(hdd_ctx->psoc, &val);
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010548 if (QDF_STATUS_SUCCESS != status) {
10549 hdd_err("Get tx_chainmask_1ss from mlme failed");
10550 ret = qdf_status_to_os_return(status);
10551 goto out;
10552 }
10553 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS, val,
Prashanth Bhatta07998752016-04-28 12:35:33 -070010554 PDEV_CMD);
10555 if (0 != ret) {
10556 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
10557 goto out;
10558 }
10559
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010560 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
10561 if (ret)
10562 goto out;
10563
10564 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
10565 if (ret)
10566 goto out;
10567
Jeff Johnson12a744b2017-04-04 08:19:37 -070010568 ret = hdd_set_ani_enabled(hdd_ctx);
10569 if (ret)
10570 goto out;
10571
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010572 status = ucfg_get_arp_ac_category(hdd_ctx->psoc, &arp_ac_category);
10573
10574 if (QDF_IS_STATUS_ERROR(status))
10575 return -EINVAL;
10576
Naveen Rawat247a8682017-06-05 15:00:31 -070010577 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010578 arp_ac_category,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -080010579 PDEV_CMD);
10580 if (0 != ret) {
10581 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010582 arp_ac_category, ret);
Srinivas Girigowda70e169a2017-03-07 23:55:57 -080010583 goto out;
10584 }
10585
Prashanth Bhatta07998752016-04-28 12:35:33 -070010586 status = hdd_set_sme_chan_list(hdd_ctx);
10587 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010588 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010589 ret = qdf_status_to_os_return(status);
10590 goto out;
10591 }
10592
10593 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -070010594 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010595 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -070010596 ret = -EINVAL;
10597 goto out;
10598 }
10599
Prashanth Bhatta07998752016-04-28 12:35:33 -070010600
10601 hdd_init_channel_avoidance(hdd_ctx);
10602
10603out:
10604 return ret;
10605}
10606
Rachit Kankane026e77a2018-07-31 16:21:09 +053010607#ifdef FEATURE_P2P_LISTEN_OFFLOAD
Prashanth Bhatta07998752016-04-28 12:35:33 -070010608/**
Peng Xu8fdaa492016-06-22 10:20:47 -070010609 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010610 * @context: context registered with sme_register_p2p_lo_event(). HDD
10611 * always registers a hdd context pointer
10612 * @evt:event structure pointer
Peng Xu8fdaa492016-06-22 10:20:47 -070010613 *
10614 * This is the p2p listen offload stop event handler, it sends vendor
10615 * event back to supplicant to notify the stop reason.
10616 *
10617 * Return: None
10618 */
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010619static void wlan_hdd_p2p_lo_event_callback(void *context,
10620 struct sir_p2p_lo_event *evt)
Peng Xu8fdaa492016-06-22 10:20:47 -070010621{
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010622 struct hdd_context *hdd_ctx = context;
Peng Xu8fdaa492016-06-22 10:20:47 -070010623 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -070010624 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -070010625
Dustin Brown491d54b2018-03-14 12:39:11 -070010626 hdd_enter();
Peng Xu8fdaa492016-06-22 10:20:47 -070010627
10628 if (hdd_ctx == NULL) {
10629 hdd_err("Invalid HDD context pointer");
10630 return;
10631 }
10632
Peng Xu5c682812017-08-06 07:39:13 -070010633 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
10634 if (!adapter) {
10635 hdd_err("Cannot find adapter by vdev_id = %d",
10636 evt->vdev_id);
10637 return;
10638 }
10639
Peng Xu8fdaa492016-06-22 10:20:47 -070010640 vendor_event =
10641 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -070010642 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -070010643 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
10644 GFP_KERNEL);
10645
10646 if (!vendor_event) {
10647 hdd_err("cfg80211_vendor_event_alloc failed");
10648 return;
10649 }
10650
10651 if (nla_put_u32(vendor_event,
10652 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
10653 evt->reason_code)) {
10654 hdd_err("nla put failed");
10655 kfree_skb(vendor_event);
10656 return;
10657 }
10658
10659 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -070010660 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
10661 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -070010662}
Rachit Kankane026e77a2018-07-31 16:21:09 +053010663#else
10664static void wlan_hdd_p2p_lo_event_callback(void *context,
10665 struct sir_p2p_lo_event *evt)
10666{
10667}
10668#endif
Peng Xu8fdaa492016-06-22 10:20:47 -070010669
Rachit Kankanef6834c42018-08-02 18:47:50 +053010670#ifdef FEATURE_WLAN_DYNAMIC_CVM
10671static inline int hdd_set_vc_mode_config(struct hdd_context *hdd_ctx)
10672{
10673 return sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap);
10674}
10675#else
10676static inline int hdd_set_vc_mode_config(struct hdd_context *hdd_ctx)
10677{
10678 return QDF_STATUS_SUCCESS;
10679}
10680#endif
10681
Peng Xu8fdaa492016-06-22 10:20:47 -070010682/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010683 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
10684 * @hdd_ctx: HDD context
10685 *
10686 * This function sends the adaptive dwell time config configuration to the
10687 * firmware via WMA
10688 *
10689 * Return: 0 - success, < 0 - failure
10690 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010691static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010692{
10693 QDF_STATUS status;
10694 struct adaptive_dwelltime_params dwelltime_params;
10695
10696 dwelltime_params.is_enabled =
10697 hdd_ctx->config->adaptive_dwell_mode_enabled;
10698 dwelltime_params.dwelltime_mode =
10699 hdd_ctx->config->global_adapt_dwelltime_mode;
10700 dwelltime_params.lpf_weight =
10701 hdd_ctx->config->adapt_dwell_lpf_weight;
10702 dwelltime_params.passive_mon_intval =
10703 hdd_ctx->config->adapt_dwell_passive_mon_intval;
10704 dwelltime_params.wifi_act_threshold =
10705 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
10706
Jeff Johnson16528362018-06-14 12:34:16 -070010707 status = sme_set_adaptive_dwelltime_config(hdd_ctx->mac_handle,
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010708 &dwelltime_params);
10709
10710 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
10711 if (!QDF_IS_STATUS_SUCCESS(status)) {
10712 hdd_err("Failed to send Adaptive Dwelltime configuration!");
10713 return -EAGAIN;
10714 }
10715 return 0;
10716}
10717
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010718int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010719{
10720 QDF_STATUS status;
10721 struct wmi_dbs_scan_sel_params dbs_scan_params;
10722 uint32_t i = 0;
10723 uint8_t count = 0, numentries = 0;
Krunal Sonidf29bc42018-11-15 13:26:29 -080010724 uint8_t dual_mac_feature;
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010725 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
10726 * CDS_DBS_SCAN_CLIENTS_MAX];
10727
Krunal Sonidf29bc42018-11-15 13:26:29 -080010728 status = ucfg_policy_mgr_get_dual_mac_feature(hdd_ctx->psoc,
10729 &dual_mac_feature);
10730
10731 if (status != QDF_STATUS_SUCCESS) {
10732 hdd_err("can't get dual mac feature flag");
10733 return -EINVAL;
10734 }
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010735 /* check if DBS is enabled or supported */
Krunal Sonidf29bc42018-11-15 13:26:29 -080010736 if ((dual_mac_feature == DISABLE_DBS_CXN_AND_SCAN) ||
10737 (dual_mac_feature == ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN))
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010738 return -EINVAL;
10739
10740 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
10741 dbs_scan_config, &numentries,
10742 (CDS_DBS_SCAN_PARAM_PER_CLIENT
10743 * CDS_DBS_SCAN_CLIENTS_MAX));
10744
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010745 if (!numentries) {
Dustin Brown6a8d39b2018-08-14 15:27:26 -070010746 hdd_debug("Do not send scan_selection_config");
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010747 return 0;
10748 }
10749
10750 /* hdd_set_fw_log_params */
10751 dbs_scan_params.num_clients = 0;
10752 while (count < (numentries - 2)) {
10753 dbs_scan_params.module_id[i] = dbs_scan_config[count];
10754 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
10755 dbs_scan_params.num_non_dbs_scans[i] =
10756 dbs_scan_config[count + 2];
10757 dbs_scan_params.num_clients++;
10758 hdd_debug("module:%d NDS:%d NNDS:%d",
10759 dbs_scan_params.module_id[i],
10760 dbs_scan_params.num_dbs_scans[i],
10761 dbs_scan_params.num_non_dbs_scans[i]);
10762 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
10763 i++;
10764 }
10765
10766 dbs_scan_params.pdev_id = 0;
10767
10768 hdd_debug("clients:%d pdev:%d",
10769 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
10770
Jeff Johnson16528362018-06-14 12:34:16 -070010771 status = sme_set_dbs_scan_selection_config(hdd_ctx->mac_handle,
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010772 &dbs_scan_params);
10773 hdd_debug("Sending DBS Scan Selection Configuration to fw");
10774 if (!QDF_IS_STATUS_SUCCESS(status)) {
10775 hdd_err("Failed to send DBS Scan selection configuration!");
10776 return -EAGAIN;
10777 }
10778 return 0;
10779}
10780
Arun Khandavallid4349a92016-07-25 11:10:43 +053010781#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10782/**
10783 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
10784 * @hdd_ctx: HDD context
10785 *
10786 * Set auto shutdown callback to get indications from firmware to indicate
10787 * userspace to shutdown WLAN after a configured amount of inactivity.
10788 *
10789 * Return: 0 on success and errno on failure.
10790 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010791static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010792{
10793 QDF_STATUS status;
10794
Dundi Raviteja8e338282018-09-25 17:16:04 +053010795 if (!hdd_ctx->config->wlan_auto_shutdown)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010796 return 0;
10797
Jeff Johnson16528362018-06-14 12:34:16 -070010798 status = sme_set_auto_shutdown_cb(hdd_ctx->mac_handle,
Arun Khandavallid4349a92016-07-25 11:10:43 +053010799 wlan_hdd_auto_shutdown_cb);
10800 if (status != QDF_STATUS_SUCCESS)
10801 hdd_err("Auto shutdown feature could not be enabled: %d",
10802 status);
10803
10804 return qdf_status_to_os_return(status);
10805}
10806#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010807static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010808{
10809 return 0;
10810}
10811#endif
10812
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010813#ifdef MWS_COEX
10814/**
10815 * hdd_set_mws_coex() - Set MWS coex configurations
10816 * @hdd_ctx: HDD context
10817 *
10818 * This function sends MWS-COEX 4G quick FTDM and
10819 * MWS-COEX 5G-NR power limit to FW
10820 *
10821 * Return: 0 on success and errno on failure.
10822 */
10823static int hdd_init_mws_coex(struct hdd_context *hdd_ctx)
10824{
10825 int ret = 0;
lifengdb340e72018-11-20 00:50:20 +080010826 uint32_t mws_coex_4g_quick_tdm = 0, mws_coex_5g_nr_pwr_limit = 0;
10827
10828 ucfg_mlme_get_mws_coex_4g_quick_tdm(hdd_ctx->psoc,
10829 &mws_coex_4g_quick_tdm);
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010830
10831 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_MWSCOEX_4G_ALLOW_QUICK_FTDM,
lifengdb340e72018-11-20 00:50:20 +080010832 mws_coex_4g_quick_tdm,
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010833 PDEV_CMD);
10834 if (ret) {
10835 hdd_warn("Unable to send MWS-COEX 4G quick FTDM policy");
10836 return ret;
10837 }
10838
lifengdb340e72018-11-20 00:50:20 +080010839 ucfg_mlme_get_mws_coex_5g_nr_pwr_limit(hdd_ctx->psoc,
10840 &mws_coex_5g_nr_pwr_limit);
10841
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010842 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_MWSCOEX_SET_5GNR_PWR_LIMIT,
lifengdb340e72018-11-20 00:50:20 +080010843 mws_coex_5g_nr_pwr_limit,
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010844 PDEV_CMD);
10845 if (ret) {
10846 hdd_warn("Unable to send MWS-COEX 4G quick FTDM policy");
10847 return ret;
10848 }
lifengdb340e72018-11-20 00:50:20 +080010849
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010850 return ret;
10851}
10852#else
10853static int hdd_init_mws_coex(struct hdd_context *hdd_ctx)
10854{
10855 return 0;
10856}
10857#endif
10858
Arun Khandavallid4349a92016-07-25 11:10:43 +053010859/**
10860 * hdd_features_init() - Init features
10861 * @hdd_ctx: HDD context
Arun Khandavallid4349a92016-07-25 11:10:43 +053010862 *
10863 * Initialize features and their feature context after WLAN firmware is up.
10864 *
10865 * Return: 0 on success and errno on failure.
10866 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010867static int hdd_features_init(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010868{
10869 tSirTxPowerLimit hddtxlimit;
10870 QDF_STATUS status;
10871 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070010872 mac_handle_t mac_handle;
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010873 struct hdd_config *cfg;
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +053010874 bool b_cts2self, is_imps_enabled;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010875
Dustin Brown491d54b2018-03-14 12:39:11 -070010876 hdd_enter();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010877
Dustin Brownad698ae2018-09-05 17:19:30 -070010878 ret = hdd_update_country_code(hdd_ctx);
10879 if (ret) {
10880 hdd_err("Failed to update country code; errno:%d", ret);
10881 return -EINVAL;
10882 }
10883
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010884 ret = hdd_init_mws_coex(hdd_ctx);
10885 if (ret)
10886 hdd_warn("Error initializing mws-coex");
10887
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010888 cfg = hdd_ctx->config;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010889 /* FW capabilities received, Set the Dot11 mode */
Jeff Johnson16528362018-06-14 12:34:16 -070010890 mac_handle = hdd_ctx->mac_handle;
10891 sme_setdef_dot11mode(mac_handle);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010892
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +053010893 ucfg_mlme_is_imps_enabled(hdd_ctx->psoc, &is_imps_enabled);
10894 hdd_set_idle_ps_config(hdd_ctx, is_imps_enabled);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010895
Poddar, Siddarth37033032017-10-11 15:47:40 +053010896 /* Send Enable/Disable data stall detection cmd to FW */
10897 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
jitiphil377bcc12018-10-05 19:46:08 +053010898 cdp_cfg_get(cds_get_context(QDF_MODULE_ID_SOC),
10899 cfg_dp_enable_data_stall), PDEV_CMD);
Poddar, Siddarth37033032017-10-11 15:47:40 +053010900
Dustin Brown1dbefe62018-09-11 16:32:03 -070010901 ucfg_mlme_get_go_cts2self_for_sta(hdd_ctx->psoc, &b_cts2self);
Wu Gao93816212018-08-31 16:49:54 +080010902 if (b_cts2self)
Jeff Johnson16528362018-06-14 12:34:16 -070010903 sme_set_cts2self_for_p2p_go(mac_handle);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010904
Rachit Kankanef6834c42018-08-02 18:47:50 +053010905 if (hdd_set_vc_mode_config(hdd_ctx))
Nachiket Kukade8983cf62017-10-12 18:14:48 +053010906 hdd_warn("Error in setting Voltage Corner mode config to FW");
10907
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010908 if (hdd_rx_ol_init(hdd_ctx))
10909 hdd_err("Unable to initialize Rx LRO/GRO in fw");
Arun Khandavallid4349a92016-07-25 11:10:43 +053010910
10911 if (hdd_adaptive_dwelltime_init(hdd_ctx))
10912 hdd_err("Unable to send adaptive dwelltime setting to FW");
10913
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010914 if (hdd_dbs_scan_selection_init(hdd_ctx))
10915 hdd_err("Unable to send DBS scan selection setting to FW");
10916
Arun Khandavallid4349a92016-07-25 11:10:43 +053010917 ret = hdd_init_thermal_info(hdd_ctx);
10918 if (ret) {
10919 hdd_err("Error while initializing thermal information");
Dustin Browne7e71d32018-05-11 16:00:08 -070010920 return ret;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010921 }
10922
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010923 /**
10924 * In case of SSR/PDR, if pktlog was enabled manually before
10925 * SSR/PDR, Then enabled it again automatically after Wlan
10926 * device up.
10927 */
10928 if (cds_is_driver_recovering()) {
10929 if (hdd_ctx->is_pktlog_enabled)
10930 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Alok Kumar5a75b9d2018-08-31 10:55:43 +053010931 } else if (cds_is_packet_log_enabled())
10932 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Poddar, Siddarth66a46592017-02-22 11:44:44 +053010933
gaurank kathpalia3d2e3852018-10-03 22:03:23 +053010934 hddtxlimit.txPower2g = ucfg_get_tx_power(hdd_ctx->psoc, BAND_2G);
10935 hddtxlimit.txPower5g = ucfg_get_tx_power(hdd_ctx->psoc, BAND_5G);
Jeff Johnson16528362018-06-14 12:34:16 -070010936 status = sme_txpower_limit(mac_handle, &hddtxlimit);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010937 if (!QDF_IS_STATUS_SUCCESS(status))
10938 hdd_err("Error setting txlimit in sme: %d", status);
10939
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010940 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010941
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053010942 status = sme_enable_disable_chanavoidind_event(mac_handle, 0);
10943 if (QDF_IS_STATUS_ERROR(status) && (status != QDF_STATUS_E_NOSUPPORT)) {
10944 hdd_err("Failed to disable Chan Avoidance Indication");
Sourav Mohapatra674925f2018-04-16 11:16:58 +053010945 return -EINVAL;
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +053010946 }
Arun Khandavallid4349a92016-07-25 11:10:43 +053010947
10948 /* register P2P Listen Offload event callback */
10949 if (wma_is_p2p_lo_capable())
Jeff Johnson16528362018-06-14 12:34:16 -070010950 sme_register_p2p_lo_event(mac_handle, hdd_ctx,
10951 wlan_hdd_p2p_lo_event_callback);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010952
10953 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
10954
10955 if (ret)
Sourav Mohapatra674925f2018-04-16 11:16:58 +053010956 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010957
Dustin Brown11638b72018-01-25 17:37:25 +053010958 wlan_hdd_init_chan_info(hdd_ctx);
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010959 wlan_hdd_twt_init(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010960
Dustin Browne74003f2018-03-14 12:51:58 -070010961 hdd_exit();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010962 return 0;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010963}
10964
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010965/**
10966 * hdd_features_deinit() - Deinit features
10967 * @hdd_ctx: HDD context
10968 *
10969 * De-Initialize features and their feature context.
10970 *
10971 * Return: none.
10972 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010973static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010974{
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010975 wlan_hdd_twt_deinit(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010976 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010977 wlan_hdd_tsf_deinit(hdd_ctx);
jitiphil4e3bef42018-11-14 14:31:13 +053010978 if (cds_is_packet_log_enabled())
10979 hdd_pktlog_enable_disable(hdd_ctx, false, 0, 0);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010980}
10981
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010982/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010983 * hdd_register_bcn_cb() - register scan beacon callback
10984 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010985 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010986 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010987 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010988static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010989{
10990 QDF_STATUS status;
10991
Dustin Brown1dbefe62018-09-11 16:32:03 -070010992 status = ucfg_scan_register_bcn_cb(hdd_ctx->psoc,
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010993 wlan_cfg80211_inform_bss_frame,
10994 SCAN_CB_TYPE_INFORM_BCN);
10995 if (!QDF_IS_STATUS_SUCCESS(status)) {
10996 hdd_err("failed with status code %08d [x%08x]",
10997 status, status);
10998 return status;
10999 }
11000
11001 return QDF_STATUS_SUCCESS;
11002}
Arun Khandavallid4349a92016-07-25 11:10:43 +053011003
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053011004/**
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070011005 * hdd_v2_flow_pool_map() - Flow pool create callback when vdev is active
11006 * @vdev_id: vdev_id, corresponds to flow_pool
11007 *
11008 * Return: none.
11009 */
11010static void hdd_v2_flow_pool_map(int vdev_id)
11011{
11012 QDF_STATUS status;
11013
11014 status = cdp_flow_pool_map(cds_get_context(QDF_MODULE_ID_SOC),
11015 cds_get_context(QDF_MODULE_ID_TXRX),
11016 vdev_id);
11017 /*
11018 * For Adrastea flow control v2 is based on FW MAP events,
11019 * so this above callback is not implemented.
11020 * Hence this is not actual failure. Dont return failure
11021 */
11022 if ((status != QDF_STATUS_SUCCESS) &&
11023 (status != QDF_STATUS_E_INVAL)) {
11024 hdd_err("vdev_id: %d, failed to create flow pool status %d",
11025 vdev_id, status);
11026 }
11027}
11028
11029/**
11030 * hdd_v2_flow_pool_unmap() - Flow pool create callback when vdev is not active
11031 * @vdev_id: vdev_id, corresponds to flow_pool
11032 *
11033 * Return: none.
11034 */
11035static void hdd_v2_flow_pool_unmap(int vdev_id)
11036{
11037 cdp_flow_pool_unmap(cds_get_context(QDF_MODULE_ID_SOC),
11038 cds_get_context(QDF_MODULE_ID_TXRX), vdev_id);
11039}
11040
11041/**
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011042 * hdd_action_oui_config() - Configure action_oui strings
11043 * @hdd_ctx: pointer to hdd context
11044 *
11045 * This is a HDD wrapper function which invokes ucfg api
11046 * of action_oui component to parse action oui strings.
11047 *
11048 * Return: None
11049 */
11050static void hdd_action_oui_config(struct hdd_context *hdd_ctx)
11051{
11052 QDF_STATUS status;
11053 uint32_t id;
11054 uint8_t *str;
11055
11056 if (!hdd_ctx->config->action_oui_enable)
11057 return;
11058
11059 for (id = 0; id < ACTION_OUI_MAXIMUM_ID; id++) {
11060 str = hdd_ctx->config->action_oui_str[id];
11061 if (!qdf_str_len(str))
11062 continue;
11063
Dustin Brown1dbefe62018-09-11 16:32:03 -070011064 status = ucfg_action_oui_parse(hdd_ctx->psoc, str, id);
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011065 if (!QDF_IS_STATUS_SUCCESS(status))
11066 hdd_err("Failed to parse action_oui str: %u", id);
11067 }
11068}
11069
11070/**
11071 * hdd_action_oui_send() - Send action_oui extensions to firmware
11072 * @hdd_ctx: pointer to hdd context
11073 *
11074 * This is a HDD wrapper function which invokes ucfg api
11075 * of action_oui component to send action oui extensions to firmware.
11076 *
11077 * Return: None
11078 */
11079static void hdd_action_oui_send(struct hdd_context *hdd_ctx)
11080{
11081 QDF_STATUS status;
11082
11083 if (!hdd_ctx->config->action_oui_enable)
11084 return;
11085
Dustin Brown1dbefe62018-09-11 16:32:03 -070011086 status = ucfg_action_oui_send(hdd_ctx->psoc);
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011087 if (!QDF_IS_STATUS_SUCCESS(status))
11088 hdd_err("Failed to send one or all action_ouis");
11089}
11090
11091/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011092 * hdd_configure_cds() - Configure cds modules
11093 * @hdd_ctx: HDD context
11094 * @adapter: Primary adapter context
11095 *
11096 * Enable Cds modules after WLAN firmware is up.
11097 *
11098 * Return: 0 on success and errno on failure.
11099 */
Dustin Browne7e71d32018-05-11 16:00:08 -070011100int hdd_configure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053011101{
11102 int ret;
11103 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011104 int set_value;
Jeff Johnson16528362018-06-14 12:34:16 -070011105 mac_handle_t mac_handle;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011106 bool enable_rts_sifsbursting;
11107 uint8_t enable_phy_reg_retention;
Krunal Sonidf29bc42018-11-15 13:26:29 -080011108 uint8_t max_mpdus_inampdu, is_force_1x1 = 0;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011109 uint32_t num_abg_tx_chains = 0;
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053011110 uint16_t num_11b_tx_chains = 0;
11111 uint16_t num_11ag_tx_chains = 0;
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070011112 struct policy_mgr_dp_cbacks dp_cbs = {0};
Bala Venkatesh2fde2c62018-09-11 20:33:24 +053011113 bool value;
Wu Gao66454f12018-09-26 19:55:41 +080011114 enum pmo_auto_pwr_detect_failure_mode auto_power_fail_mode;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053011115 bool bval = false;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011116
Jeff Johnson16528362018-06-14 12:34:16 -070011117 mac_handle = hdd_ctx->mac_handle;
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011118
11119 hdd_action_oui_send(hdd_ctx);
Krunal Sonidf29bc42018-11-15 13:26:29 -080011120 status = ucfg_policy_mgr_get_force_1x1(hdd_ctx->psoc, &is_force_1x1);
11121 if (status != QDF_STATUS_SUCCESS) {
11122 hdd_err("Failed to get force 1x1 value");
11123 goto out;
11124 }
11125 if (is_force_1x1)
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011126 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
11127 1, PDEV_CMD);
11128 /* set chip power save failure detected callback */
Jeff Johnson16528362018-06-14 12:34:16 -070011129 sme_set_chip_pwr_save_fail_cb(mac_handle,
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011130 hdd_chip_pwr_save_fail_detected_cb);
11131
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011132 status = ucfg_get_max_mpdus_inampdu(hdd_ctx->psoc,
11133 &max_mpdus_inampdu);
Krunal Sonidf29bc42018-11-15 13:26:29 -080011134 if (status) {
11135 hdd_err("Failed to get max mpdus in ampdu value");
11136 goto out;
11137 }
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011138
11139 if (max_mpdus_inampdu) {
11140 set_value = max_mpdus_inampdu;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011141 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
11142 set_value, PDEV_CMD);
11143 }
11144
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011145 status = ucfg_get_enable_rts_sifsbursting(hdd_ctx->psoc,
11146 &enable_rts_sifsbursting);
Krunal Sonidf29bc42018-11-15 13:26:29 -080011147 if (status) {
11148 hdd_err("Failed to get rts sifs bursting value");
11149 goto out;
11150 }
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011151
11152 if (enable_rts_sifsbursting) {
11153 set_value = enable_rts_sifsbursting;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011154 sme_cli_set_command(0,
11155 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
11156 set_value, PDEV_CMD);
11157 }
11158
Dustin Brown05d81302018-09-11 16:49:22 -070011159 ucfg_mlme_get_sap_get_peer_info(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +053011160 if (value) {
11161 set_value = value;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011162 sme_cli_set_command(0,
11163 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
11164 set_value, PDEV_CMD);
11165 }
11166
Dustin Brown1dbefe62018-09-11 16:32:03 -070011167 status = ucfg_mlme_get_num_11b_tx_chains(hdd_ctx->psoc,
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053011168 &num_11b_tx_chains);
11169 if (status != QDF_STATUS_SUCCESS) {
11170 hdd_err("Failed to get num_11b_tx_chains");
11171 goto out;
11172 }
11173
Dustin Brown1dbefe62018-09-11 16:32:03 -070011174 status = ucfg_mlme_get_num_11ag_tx_chains(hdd_ctx->psoc,
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053011175 &num_11ag_tx_chains);
11176 if (status != QDF_STATUS_SUCCESS) {
11177 hdd_err("Failed to get num_11ag_tx_chains");
11178 goto out;
11179 }
11180
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053011181 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
11182 if (!QDF_IS_STATUS_SUCCESS(status))
11183 hdd_err("unable to get vht_enable2x2");
11184
11185 if (!bval) {
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011186 if (num_11b_tx_chains > 1)
11187 num_11b_tx_chains = 1;
11188 if (num_11ag_tx_chains > 1)
11189 num_11ag_tx_chains = 1;
11190 }
11191 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
11192 num_11b_tx_chains);
11193 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
11194 num_11ag_tx_chains);
11195 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
11196 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +053011197
Paul Zhang02526cd2018-09-20 17:47:46 +080011198 if (!ucfg_reg_is_regdb_offloaded(hdd_ctx->psoc))
11199 ucfg_reg_program_default_cc(hdd_ctx->pdev,
11200 hdd_ctx->reg.reg_domain);
11201
Arun Khandavallifae92942016-08-01 13:31:08 +053011202 ret = hdd_pre_enable_configure(hdd_ctx);
11203 if (ret) {
11204 hdd_err("Failed to pre-configure cds");
11205 goto out;
11206 }
11207
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080011208 /* Always get latest IPA resources allocated from cds_open and configure
11209 * IPA module before configuring them to FW. Sequence required as crash
11210 * observed otherwise.
11211 */
Dustin Brown07901ec2018-09-07 11:02:41 -070011212 if (ucfg_ipa_uc_ol_init(hdd_ctx->pdev,
11213 cds_get_context(QDF_MODULE_ID_QDF_DEVICE))) {
Manikandan Mohan2e803a02017-02-14 14:57:53 -080011214 hdd_err("Failed to setup pipes");
11215 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080011216 }
11217
Arun Khandavallifae92942016-08-01 13:31:08 +053011218 /*
11219 * Start CDS which starts up the SME/MAC/HAL modules and everything
11220 * else
11221 */
Dustin Brown1dbefe62018-09-11 16:32:03 -070011222 status = cds_enable(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053011223
11224 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011225 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053011226 goto out;
11227 }
11228
11229 status = hdd_post_cds_enable_config(hdd_ctx);
11230 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011231 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011232 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053011233 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +053011234 status = hdd_register_bcn_cb(hdd_ctx);
11235 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +080011236 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +053011237 goto cds_disable;
11238 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011239
Dustin Browne7e71d32018-05-11 16:00:08 -070011240 ret = hdd_features_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053011241 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011242 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053011243
Mohit Khanna81418772018-10-30 14:14:46 -070011244 /* Donot disable rx offload on concurrency for lithium based targets */
11245 if (!(hdd_ctx->target_type == TARGET_TYPE_QCA6290 ||
11246 hdd_ctx->target_type == TARGET_TYPE_QCA6390))
11247 if (hdd_ctx->ol_enable)
11248 dp_cbs.hdd_disable_rx_ol_in_concurrency =
11249 hdd_disable_rx_ol_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -070011250 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
jiadbb47e132018-03-30 16:28:30 +080011251 dp_cbs.hdd_ipa_set_mcc_mode_cb = hdd_ipa_set_mcc_mode;
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070011252 dp_cbs.hdd_v2_flow_pool_map = hdd_v2_flow_pool_map;
11253 dp_cbs.hdd_v2_flow_pool_unmap = hdd_v2_flow_pool_unmap;
Dustin Brown1dbefe62018-09-11 16:32:03 -070011254 status = policy_mgr_register_dp_cb(hdd_ctx->psoc, &dp_cbs);
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070011255 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -070011256 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070011257 goto cds_disable;
11258 }
Dustin Brown1dbefe62018-09-11 16:32:03 -070011259 status = policy_mgr_register_mode_change_cb(hdd_ctx->psoc,
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053011260 wlan_hdd_send_mode_change_event);
11261 if (!QDF_IS_STATUS_SUCCESS(status)) {
11262 hdd_debug("Failed to register mode change cb with Policy Manager");
11263 goto cds_disable;
11264 }
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070011265
Jeff Johnson8bb61112018-03-31 13:33:54 -070011266 if (hdd_green_ap_enable_egap(hdd_ctx))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +053011267 hdd_debug("enhance green ap is not enabled");
11268
Nachiket Kukadedd302662017-07-13 17:31:44 +053011269 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
11270 hdd_debug("Failed to set wow pulse");
11271
Manikandan Mohand350c192018-11-29 14:01:12 -080011272 bval = false;
11273 if (QDF_IS_STATUS_ERROR(ucfg_fwol_get_gcmp_enable(hdd_ctx->psoc,
11274 &bval)))
11275 hdd_err("Unable to get GCMP enable config param");
11276
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053011277 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
Manikandan Mohand350c192018-11-29 14:01:12 -080011278 bval, PDEV_CMD);
Wu Gao66454f12018-09-26 19:55:41 +080011279
11280 auto_power_fail_mode =
11281 ucfg_pmo_get_auto_power_fail_mode(hdd_ctx->psoc);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053011282 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
Wu Gao66454f12018-09-26 19:55:41 +080011283 auto_power_fail_mode, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053011284
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011285 status = ucfg_get_enable_phy_reg_retention(hdd_ctx->psoc,
11286 &enable_phy_reg_retention);
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053011287
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011288 if (QDF_IS_STATUS_ERROR(status))
11289 return -EINVAL;
11290
11291 if (enable_phy_reg_retention)
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053011292 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011293 enable_phy_reg_retention, PDEV_CMD);
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053011294
Arun Khandavallifae92942016-08-01 13:31:08 +053011295 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011296
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011297cds_disable:
Dustin Brown1dbefe62018-09-11 16:32:03 -070011298 cds_disable(hdd_ctx->psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011299
Arun Khandavallifae92942016-08-01 13:31:08 +053011300out:
11301 return -EINVAL;
11302}
11303
11304/**
11305 * hdd_deconfigure_cds() -De-Configure cds
11306 * @hdd_ctx: HDD context
11307 *
11308 * Deconfigure Cds modules before WLAN firmware is down.
11309 *
11310 * Return: 0 on success and errno on failure.
11311 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011312static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053011313{
11314 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070011315 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011316
Dustin Brown491d54b2018-03-14 12:39:11 -070011317 hdd_enter();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080011318
11319 /* De-init features */
11320 hdd_features_deinit(hdd_ctx);
11321
Dustin Brown1dbefe62018-09-11 16:32:03 -070011322 qdf_status = policy_mgr_deregister_mode_change_cb(hdd_ctx->psoc);
Srinivas Girigowdad2412882018-09-07 15:42:04 -070011323 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053011324 hdd_debug("Failed to deregister mode change cb with Policy Manager");
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053011325
Dustin Brown1dbefe62018-09-11 16:32:03 -070011326 qdf_status = cds_disable(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053011327 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11328 hdd_err("Failed to Disable the CDS Modules! :%d",
11329 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070011330 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011331 }
11332
Dustin Brown07901ec2018-09-07 11:02:41 -070011333 if (ucfg_ipa_uc_ol_deinit(hdd_ctx->pdev) != QDF_STATUS_SUCCESS) {
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053011334 hdd_err("Failed to disconnect pipes");
11335 ret = -EINVAL;
11336 }
11337
Dustin Browne74003f2018-03-14 12:51:58 -070011338 hdd_exit();
Houston Hoffman6640cf32016-10-10 16:44:29 -070011339 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053011340}
11341
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070011342#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
11343static void hdd_deregister_policy_manager_callback(
11344 struct wlan_objmgr_psoc *psoc)
11345{
11346 if (QDF_STATUS_SUCCESS !=
11347 policy_mgr_deregister_hdd_cb(psoc)) {
11348 hdd_err("HDD callback deregister with policy manager failed");
11349 }
11350}
11351#else
11352static void hdd_deregister_policy_manager_callback(
11353 struct wlan_objmgr_psoc *psoc)
11354{
11355}
11356#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053011357
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011358int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053011359{
11360 void *hif_ctx;
11361 qdf_device_t qdf_ctx;
11362 QDF_STATUS qdf_status;
Dustin Brown4bc0a622017-12-06 15:56:50 -080011363 bool is_recovery_stop = cds_is_driver_recovering();
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053011364 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -070011365 int active_threads;
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053011366 int debugfs_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053011367 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053011368
Dustin Brown491d54b2018-03-14 12:39:11 -070011369 hdd_enter();
Arun Khandavallifae92942016-08-01 13:31:08 +053011370
Dustin Brown1dbefe62018-09-11 16:32:03 -070011371 hdd_deregister_policy_manager_callback(hdd_ctx->psoc);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070011372
Arun Khandavallifae92942016-08-01 13:31:08 +053011373 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11374 if (!qdf_ctx) {
11375 hdd_err("QDF device context NULL");
11376 return -EINVAL;
11377 }
11378
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011379 mutex_lock(&hdd_ctx->iface_change_lock);
11380 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011381 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011382
Dustin Brown70111822017-03-30 15:31:40 -070011383 active_threads = cds_return_external_threads_count();
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053011384 debugfs_threads = hdd_return_debugfs_threads_count();
Dustin Brown70111822017-03-30 15:31:40 -070011385
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053011386 if (active_threads > 0 || debugfs_threads > 0 ||
11387 hdd_ctx->is_wiphy_suspended) {
11388 hdd_warn("External threads %d, Debugfs threads %d, wiphy suspend %d",
11389 active_threads, debugfs_threads,
11390 hdd_ctx->is_wiphy_suspended);
11391
11392 if (active_threads)
11393 cds_print_external_threads();
Dustin Brown70111822017-03-30 15:31:40 -070011394
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053011395 if (IS_IDLE_STOP && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070011396 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4c663222018-10-23 14:19:36 -070011397 hdd_psoc_idle_timer_start(hdd_ctx);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011398 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011399 cds_set_module_stop_in_progress(false);
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011400
Dustin Brown70111822017-03-30 15:31:40 -070011401 return 0;
11402 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070011403 }
11404
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080011405 /* free user wowl patterns */
11406 hdd_free_user_wowl_ptrns();
11407
Arun Khandavallifae92942016-08-01 13:31:08 +053011408 switch (hdd_ctx->driver_status) {
11409 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011410 hdd_debug("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011411 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011412 case DRIVER_MODULES_CLOSED:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011413 hdd_debug("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011414 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011415 case DRIVER_MODULES_ENABLED:
Dustin Brown1a20b082018-08-03 17:27:15 -070011416 hdd_info("Wlan transitioning (CLOSED <- ENABLED)");
11417
11418 if (hdd_get_conparam() == QDF_GLOBAL_FTM_MODE)
11419 break;
Dustin Brown550f6d22017-12-14 15:44:01 -080011420
Komal Seelamf2136bb2016-09-28 18:30:44 +053011421 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053011422 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011423 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053011424 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011425 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011426 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011427 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080011428
Arun Khandavallifae92942016-08-01 13:31:08 +053011429 break;
11430 default:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011431 QDF_DEBUG_PANIC("Unknown driver state:%d",
Arun Khandavallifae92942016-08-01 13:31:08 +053011432 hdd_ctx->driver_status);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011433 ret = -EINVAL;
11434 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011435 }
11436
Arunk Khandavalli890f6d92018-10-30 20:18:28 +053011437 hdd_sysfs_destroy_powerstats_interface();
Amar Singhal18081642018-01-26 16:04:13 -080011438 hdd_sysfs_destroy_version_interface();
Arunk Khandavalli890f6d92018-10-30 20:18:28 +053011439 hdd_sysfs_destroy_driver_root_obj();
Dustin Brown550f6d22017-12-14 15:44:01 -080011440 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080011441
Rajeev Kumarbe021242017-02-16 16:12:23 -080011442 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053011443 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11444 hdd_err("Failed to process post CDS disable Modules! :%d",
11445 qdf_status);
11446 ret = -EINVAL;
11447 QDF_ASSERT(0);
11448 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011449
Sourav Mohapatra674925f2018-04-16 11:16:58 +053011450 /* De-register the SME callbacks */
11451 hdd_deregister_cb(hdd_ctx);
11452
psimhadeea0a12017-12-18 14:50:02 -080011453 hdd_runtime_suspend_context_deinit(hdd_ctx);
11454
Dustin Brown1dbefe62018-09-11 16:32:03 -070011455 qdf_status = cds_dp_close(hdd_ctx->psoc);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011456 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11457 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
11458 ret = -EINVAL;
11459 QDF_ASSERT(0);
11460 }
11461
Dustin Brown1dbefe62018-09-11 16:32:03 -070011462 qdf_status = cds_close(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053011463 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011464 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053011465 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011466 QDF_ASSERT(0);
11467 }
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053011468
11469 qdf_status = wbuff_module_deinit();
11470 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
11471 hdd_err("WBUFF de-init unsuccessful; status: %d", qdf_status);
11472
Sandeep Puligillab7beb472018-08-13 22:54:20 -070011473 hdd_component_pdev_close(hdd_ctx->pdev);
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053011474
Dustin Brown1dbefe62018-09-11 16:32:03 -070011475 hdd_component_psoc_close(hdd_ctx->psoc);
Dustin Brown07901ec2018-09-07 11:02:41 -070011476 dispatcher_pdev_close(hdd_ctx->pdev);
Liangwei Dong50a64a72018-01-11 01:17:00 -050011477 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
11478 if (ret) {
11479 hdd_err("Failed to destroy pdev; errno:%d", ret);
11480 QDF_ASSERT(0);
11481 }
11482
11483 /*
11484 * Reset total mac phy during module stop such that during
11485 * next module start same psoc is used to populate new service
11486 * ready data
11487 */
Dustin Brown1dbefe62018-09-11 16:32:03 -070011488 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->psoc);
Arunk Khandavallia6305a32018-01-25 11:19:18 +053011489 if (tgt_hdl)
11490 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
11491
Liangwei Dong50a64a72018-01-11 01:17:00 -050011492
Arun Khandavallifae92942016-08-01 13:31:08 +053011493 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
11494 if (!hif_ctx) {
11495 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011496 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011497 }
11498
Arunk Khandavalli4b404332017-09-26 12:46:00 +053011499 if (hdd_ctx->target_hw_name) {
11500 qdf_mem_free(hdd_ctx->target_hw_name);
11501 hdd_ctx->target_hw_name = NULL;
11502 }
11503
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053011504 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053011505
11506 ol_cds_free();
11507
Dustin Brownc2a156e2018-10-25 16:56:27 -070011508 if (IS_IDLE_STOP) {
Arun Khandavallifae92942016-08-01 13:31:08 +053011509 ret = pld_power_off(qdf_ctx->dev);
11510 if (ret)
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011511 hdd_err("Failed to power down device; errno:%d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053011512 }
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011513
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011514 /* Free the cache channels of the command SET_DISABLE_CHANNEL_LIST */
11515 wlan_hdd_free_cache_channels(hdd_ctx);
Arunk Khandavalli847969d2017-09-25 15:15:36 +053011516
Dustin Brown29533f22018-07-24 13:11:56 -070011517 hdd_check_for_leaks(hdd_ctx, is_recovery_stop);
Dustin Brown26b3d042017-12-21 11:13:27 -080011518 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080011519
Arunk Khandavalli847969d2017-09-25 15:15:36 +053011520 /* Once the firmware sequence is completed reset this flag */
11521 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053011522 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080011523 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053011524
Kai Liueabb1df2018-11-08 14:58:54 +080011525 pld_request_bus_bandwidth(hdd_ctx->parent_dev, PLD_BUS_WIDTH_NONE);
11526
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011527done:
11528 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011529 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011530 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4bc0a622017-12-06 15:56:50 -080011531
Dustin Browne74003f2018-03-14 12:51:58 -070011532 hdd_exit();
Arun Khandavallifae92942016-08-01 13:31:08 +053011533
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011534 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053011535}
11536
Arun Khandavallifae92942016-08-01 13:31:08 +053011537
Wen Gong3f003382018-05-14 14:26:37 +080011538#ifdef WLAN_FEATURE_MEMDUMP_ENABLE
Arun Khandavallifae92942016-08-01 13:31:08 +053011539/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011540 * hdd_state_info_dump() - prints state information of hdd layer
11541 * @buf: buffer pointer
11542 * @size: size of buffer to be filled
11543 *
11544 * This function is used to dump state information of hdd layer
11545 *
11546 * Return: None
11547 */
11548static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
11549{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011550 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070011551 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070011552 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011553 uint16_t len = 0;
11554 char *buf = *buf_ptr;
11555
11556 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11557 if (!hdd_ctx) {
11558 hdd_err("Failed to get hdd context ");
11559 return;
11560 }
11561
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011562 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011563
11564 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070011565 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011566 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080011567 "\n is_scheduler_suspended %d",
11568 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011569
Dustin Brown920397d2017-12-13 16:27:50 -080011570 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011571 if (adapter->dev)
11572 len += scnprintf(buf + len, *size - len,
11573 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080011574 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011575 "\n device_mode: %d", adapter->device_mode);
11576 switch (adapter->device_mode) {
11577 case QDF_STA_MODE:
11578 case QDF_P2P_CLIENT_MODE:
11579 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11580 len += scnprintf(buf + len, *size - len,
11581 "\n connState: %d",
11582 hdd_sta_ctx->conn_info.connState);
11583 break;
11584
11585 default:
11586 break;
11587 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011588 }
11589
11590 *size -= len;
11591 *buf_ptr += len;
11592}
11593
11594/**
11595 * hdd_register_debug_callback() - registration function for hdd layer
11596 * to print hdd state information
11597 *
11598 * Return: None
11599 */
11600static void hdd_register_debug_callback(void)
11601{
11602 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
11603}
Wen Gong3f003382018-05-14 14:26:37 +080011604#else /* WLAN_FEATURE_MEMDUMP_ENABLE */
Wen Gongaa6d55d2018-04-26 16:33:21 +080011605static void hdd_register_debug_callback(void)
11606{
11607}
Wen Gong3f003382018-05-14 14:26:37 +080011608#endif /* WLAN_FEATURE_MEMDUMP_ENABLE */
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011609
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053011610/*
11611 * wlan_init_bug_report_lock() - Initialize bug report lock
11612 *
11613 * This function is used to create bug report lock
11614 *
11615 * Return: None
11616 */
11617static void wlan_init_bug_report_lock(void)
11618{
Jeff Johnson2b6982c2018-05-29 14:56:11 -070011619 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053011620
11621 p_cds_context = cds_get_global_context();
11622 if (!p_cds_context) {
11623 hdd_err("cds context is NULL");
11624 return;
11625 }
11626
11627 qdf_spinlock_create(&p_cds_context->bug_report_lock);
11628}
11629
Nirav Shahd21a2e32018-04-20 16:34:43 +053011630#ifdef CONFIG_DP_TRACE
Mohit Khannaf8f96822017-05-17 17:11:59 -070011631void hdd_dp_trace_init(struct hdd_config *config)
11632{
Mohit Khannaf8f96822017-05-17 17:11:59 -070011633 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
11634 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
11635 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
11636 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
11637 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
11638 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
11639 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080011640 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070011641
Nirav Shahd21a2e32018-04-20 16:34:43 +053011642 if (!config->enable_dp_trace) {
11643 hdd_err("dp trace is disabled from ini");
11644 return;
11645 }
11646
Mohit Khannaf8f96822017-05-17 17:11:59 -070011647 hdd_string_to_u8_array(config->dp_trace_config, config_params,
11648 &num_entries, sizeof(config_params));
11649
11650 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080011651 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080011652 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080011653 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080011654 else if (bw_compute_interval > 1000) {
11655 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
11656 thresh_time_limit = 1;
11657 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070011658 hdd_err("busBandwidthComputeInterval is 0, using defaults");
11659
11660 switch (num_entries) {
11661 case 4:
11662 proto_bitmap = config_params[3];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011663 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011664 case 3:
11665 verbosity = config_params[2];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011666 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011667 case 2:
11668 thresh = config_params[1];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011669 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011670 case 1:
11671 live_mode = config_params[0];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011672 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011673 default:
Dustin Browna7bb6ae2018-08-16 16:51:50 -070011674 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
11675 live_mode, thresh, thresh_time_limit,
11676 verbosity, proto_bitmap);
Mohit Khannaf8f96822017-05-17 17:11:59 -070011677 };
11678
11679 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
11680 verbosity, proto_bitmap);
11681
11682}
Nirav Shahd21a2e32018-04-20 16:34:43 +053011683#endif
11684
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011685#ifdef DISABLE_CHANNEL_LIST
Dustin Brown623e7e32018-09-05 14:27:50 -070011686static QDF_STATUS wlan_hdd_cache_chann_mutex_create(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011687{
11688 return qdf_mutex_create(&hdd_ctx->cache_channel_lock);
11689}
11690#else
Dustin Brown623e7e32018-09-05 14:27:50 -070011691static QDF_STATUS wlan_hdd_cache_chann_mutex_create(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011692{
Dustin Brown623e7e32018-09-05 14:27:50 -070011693 return QDF_STATUS_SUCCESS;
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011694}
11695#endif
11696
Dustin Brown61cc3932018-10-18 16:12:13 -070011697static QDF_STATUS
11698hdd_open_adapters_for_mission_mode(struct hdd_context *hdd_ctx)
Dustin Browna2deeb72018-10-18 14:19:27 -070011699{
11700 struct hdd_adapter *adapter;
11701 enum dot11p_mode dot11p_mode;
Dustin Brown61cc3932018-10-18 16:12:13 -070011702 QDF_STATUS status;
Dustin Browna2deeb72018-10-18 14:19:27 -070011703
11704 ucfg_mlme_get_dot11p_mode(hdd_ctx->psoc, &dot11p_mode);
11705
11706 /* Create only 802.11p interface? */
11707 if (dot11p_mode == CFG_11P_STANDALONE)
Dustin Brown61cc3932018-10-18 16:12:13 -070011708 return hdd_open_ocb_interface(hdd_ctx);
Dustin Browna2deeb72018-10-18 14:19:27 -070011709
11710 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053011711 wlan_hdd_get_intf_addr(hdd_ctx,
11712 QDF_STA_MODE),
Dustin Browna2deeb72018-10-18 14:19:27 -070011713 NET_NAME_UNKNOWN, true);
11714 if (!adapter)
Dustin Brown61cc3932018-10-18 16:12:13 -070011715 return QDF_STATUS_E_INVAL;
Dustin Browna2deeb72018-10-18 14:19:27 -070011716
Dustin Brown61cc3932018-10-18 16:12:13 -070011717 /* opening concurrent STA is best effort, continue on error */
11718 hdd_open_concurrent_interface(hdd_ctx);
Dustin Browna2deeb72018-10-18 14:19:27 -070011719
Dustin Brown61cc3932018-10-18 16:12:13 -070011720 status = hdd_open_p2p_interface(hdd_ctx);
11721 if (status)
Dustin Browna2deeb72018-10-18 14:19:27 -070011722 goto err_close_adapters;
11723
11724 /* Open 802.11p Interface */
11725 if (dot11p_mode == CFG_11P_CONCURRENT) {
Dustin Brown61cc3932018-10-18 16:12:13 -070011726 status = hdd_open_ocb_interface(hdd_ctx);
11727 if (QDF_IS_STATUS_ERROR(status))
Dustin Browna2deeb72018-10-18 14:19:27 -070011728 goto err_close_adapters;
11729 }
11730
Dustin Brown61cc3932018-10-18 16:12:13 -070011731 return QDF_STATUS_SUCCESS;
Dustin Browna2deeb72018-10-18 14:19:27 -070011732
11733err_close_adapters:
11734 hdd_close_all_adapters(hdd_ctx, true);
11735
Dustin Brown61cc3932018-10-18 16:12:13 -070011736 return status;
Dustin Browna2deeb72018-10-18 14:19:27 -070011737}
11738
Dustin Brown61cc3932018-10-18 16:12:13 -070011739static QDF_STATUS hdd_open_adapters_for_ftm_mode(struct hdd_context *hdd_ctx)
Dustin Browna2deeb72018-10-18 14:19:27 -070011740{
11741 struct hdd_adapter *adapter;
Dustin Brown61cc3932018-10-18 16:12:13 -070011742
11743 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053011744 wlan_hdd_get_intf_addr(hdd_ctx,
11745 QDF_FTM_MODE),
Dustin Brown61cc3932018-10-18 16:12:13 -070011746 NET_NAME_UNKNOWN, true);
11747
11748 return adapter ? QDF_STATUS_SUCCESS : QDF_STATUS_E_INVAL;
11749}
11750
11751static QDF_STATUS
11752hdd_open_adapters_for_monitor_mode(struct hdd_context *hdd_ctx)
11753{
11754 struct hdd_adapter *adapter;
11755
11756 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053011757 wlan_hdd_get_intf_addr(hdd_ctx,
11758 QDF_MONITOR_MODE),
Dustin Brown61cc3932018-10-18 16:12:13 -070011759 NET_NAME_UNKNOWN, true);
11760
11761 return adapter ? QDF_STATUS_SUCCESS : QDF_STATUS_E_INVAL;
11762}
11763
11764static QDF_STATUS hdd_open_adapters_for_epping_mode(struct hdd_context *hdd_ctx)
11765{
Dustin Browna2deeb72018-10-18 14:19:27 -070011766 QDF_STATUS status;
Dustin Brown61cc3932018-10-18 16:12:13 -070011767 qdf_device_t qdf_dev;
Dustin Browna2deeb72018-10-18 14:19:27 -070011768
11769 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11770 QDF_BUG(qdf_dev);
11771 if (!qdf_dev)
Dustin Brown61cc3932018-10-18 16:12:13 -070011772 return QDF_STATUS_E_INVAL;
11773
11774 status = epping_open();
11775 if (QDF_IS_STATUS_ERROR(status))
11776 return status;
11777
11778 if (epping_enable(qdf_dev->dev)) {
11779 status = QDF_STATUS_E_INVAL;
11780 goto epping_close;
11781 }
11782
11783 return QDF_STATUS_SUCCESS;
11784
11785epping_close:
11786 epping_close();
11787
11788 return status;
11789}
11790
11791typedef QDF_STATUS (*hdd_open_mode_handler)(struct hdd_context *hdd_ctx);
11792
11793static const hdd_open_mode_handler
11794hdd_open_mode_handlers[QDF_GLOBAL_MAX_MODE] = {
11795 [QDF_GLOBAL_MISSION_MODE] = hdd_open_adapters_for_mission_mode,
11796 [QDF_GLOBAL_FTM_MODE] = hdd_open_adapters_for_ftm_mode,
11797 [QDF_GLOBAL_MONITOR_MODE] = hdd_open_adapters_for_monitor_mode,
11798 [QDF_GLOBAL_EPPING_MODE] = hdd_open_adapters_for_epping_mode,
11799};
11800
Dustin Brown92bd8382018-10-31 15:49:46 -070011801static QDF_STATUS hdd_open_adapters_for_mode(struct hdd_context *hdd_ctx,
11802 enum QDF_GLOBAL_MODE driver_mode)
Dustin Brown61cc3932018-10-18 16:12:13 -070011803{
11804 QDF_STATUS status;
11805
11806 if (driver_mode < 0 ||
11807 driver_mode >= QDF_GLOBAL_MAX_MODE ||
11808 !hdd_open_mode_handlers[driver_mode]) {
11809 hdd_err("Driver mode %d not supported", driver_mode);
11810 return -ENOTSUPP;
11811 }
Dustin Browna2deeb72018-10-18 14:19:27 -070011812
11813 hdd_hold_rtnl_lock();
Dustin Brown61cc3932018-10-18 16:12:13 -070011814 status = hdd_open_mode_handlers[driver_mode](hdd_ctx);
Dustin Browna2deeb72018-10-18 14:19:27 -070011815 hdd_release_rtnl_lock();
11816
Dustin Brown92bd8382018-10-31 15:49:46 -070011817 return status;
Dustin Browna2deeb72018-10-18 14:19:27 -070011818}
11819
Dustin Brown623e7e32018-09-05 14:27:50 -070011820int hdd_wlan_startup(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011821{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011822 QDF_STATUS status;
Dustin Brown623e7e32018-09-05 14:27:50 -070011823 int errno;
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +053011824 bool is_imps_enabled;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011825
Dustin Brown491d54b2018-03-14 12:39:11 -070011826 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011827
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011828 hdd_action_oui_config(hdd_ctx);
11829
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053011830 qdf_nbuf_init_replenish_timer();
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011831
Dustin Brown623e7e32018-09-05 14:27:50 -070011832 status = wlan_hdd_cache_chann_mutex_create(hdd_ctx);
11833 if (QDF_IS_STATUS_ERROR(status))
11834 return qdf_status_to_os_return(status);
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011835
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053011836#ifdef FEATURE_WLAN_CH_AVOID
11837 mutex_init(&hdd_ctx->avoid_freq_lock);
11838#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053011839
Naveen Rawate02f8f52018-04-05 11:58:04 -070011840 osif_request_manager_init();
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053011841 qdf_atomic_init(&hdd_ctx->con_mode_flag);
Dustin Brown021cecd2017-12-11 13:56:43 -080011842 hdd_driver_memdump_init();
Dustin Brown86d196b2018-08-02 11:51:49 -070011843 hdd_bus_bandwidth_init(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -080011844
Dustin Brown623e7e32018-09-05 14:27:50 -070011845 errno = hdd_wlan_start_modules(hdd_ctx, false);
11846 if (errno) {
11847 hdd_err("Failed to start modules; errno:%d", errno);
11848 goto memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011849 }
11850
Yingying Tang80e15f32016-09-27 18:23:01 +080011851 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011852
Dustin Brown623e7e32018-09-05 14:27:50 -070011853 hdd_ctx->mac_handle = cds_get_context(QDF_MODULE_ID_SME);
11854 if (!hdd_ctx->mac_handle) {
Jeff Johnson16528362018-06-14 12:34:16 -070011855 hdd_err("Mac Handle is null");
Dustin Brown623e7e32018-09-05 14:27:50 -070011856 goto stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011857 }
11858
Dustin Brown623e7e32018-09-05 14:27:50 -070011859 errno = hdd_wiphy_init(hdd_ctx);
11860 if (errno) {
11861 hdd_err("Failed to initialize wiphy; errno:%d", errno);
11862 goto stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011863 }
11864
Nirav Shahd21a2e32018-04-20 16:34:43 +053011865 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053011866
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053011867 errno = hdd_initialize_mac_address(hdd_ctx);
11868 if (errno) {
11869 hdd_err("MAC initializtion failed: %d", errno);
11870 goto unregister_wiphy;
11871 }
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080011872
Dustin Brown623e7e32018-09-05 14:27:50 -070011873 errno = register_netdevice_notifier(&hdd_netdev_notifier);
11874 if (errno) {
11875 hdd_err("register_netdevice_notifier failed; errno:%d", errno);
11876 goto unregister_wiphy;
Paul Zhangfb02f452017-12-22 11:58:43 +080011877 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053011878
Dustin Brown623e7e32018-09-05 14:27:50 -070011879 errno = register_reboot_notifier(&system_reboot_notifier);
11880 if (errno) {
11881 hdd_err("Failed to register reboot notifier; errno:%d", errno);
11882 goto unregister_netdev;
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011883 }
11884
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080011885 wlan_hdd_update_11n_mode(hdd_ctx->config);
11886
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011887#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053011888 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053011889 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011890 hdd_skip_acs_scan_timer_handler,
Dustin Browna2deeb72018-10-18 14:19:27 -070011891 hdd_ctx);
Dustin Brown92bd8382018-10-31 15:49:46 -070011892 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070011893 hdd_err("Failed to init ACS Skip timer");
Dustin Brown92bd8382018-10-31 15:49:46 -070011894
Liangwei Dongaef84342016-10-21 05:28:00 -040011895 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011896#endif
11897
Arunk Khandavalli40943af2017-05-15 19:25:34 +053011898 hdd_lpass_notify_wlan_version(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011899
Dustin Brown623e7e32018-09-05 14:27:50 -070011900 errno = hdd_register_notifiers(hdd_ctx);
11901 if (errno)
11902 goto unregister_reboot;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070011903
Paul Zhangfb02f452017-12-22 11:58:43 +080011904 status = wlansap_global_init();
Dustin Brown92bd8382018-10-31 15:49:46 -070011905 if (QDF_IS_STATUS_ERROR(status))
11906 goto unregister_notifiers;
Paul Zhangfb02f452017-12-22 11:58:43 +080011907
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +053011908 ucfg_mlme_is_imps_enabled(hdd_ctx->psoc, &is_imps_enabled);
11909 hdd_set_idle_ps_config(hdd_ctx, is_imps_enabled);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011910
Dustin Brown92bd8382018-10-31 15:49:46 -070011911 hdd_exit();
11912
11913 return 0;
11914
11915unregister_notifiers:
11916 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011917
Dustin Brown623e7e32018-09-05 14:27:50 -070011918unregister_reboot:
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011919 unregister_reboot_notifier(&system_reboot_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011920
Dustin Brown623e7e32018-09-05 14:27:50 -070011921unregister_netdev:
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011922 unregister_netdevice_notifier(&hdd_netdev_notifier);
11923
Dustin Brown623e7e32018-09-05 14:27:50 -070011924unregister_wiphy:
Rachit Kankane30807332018-06-27 18:39:36 +053011925 qdf_dp_trace_deinit();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011926 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011927
Dustin Brown623e7e32018-09-05 14:27:50 -070011928stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011929 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053011930
Dustin Brown623e7e32018-09-05 14:27:50 -070011931memdump_deinit:
Dustin Brown86d196b2018-08-02 11:51:49 -070011932 hdd_bus_bandwidth_deinit(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -080011933 hdd_driver_memdump_deinit();
Naveen Rawate02f8f52018-04-05 11:58:04 -070011934 osif_request_manager_deinit();
Dustin Brown623e7e32018-09-05 14:27:50 -070011935 qdf_nbuf_deinit_replenish_timer();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070011936
Nachiket Kukade8003d252017-03-30 15:55:58 +053011937 if (cds_is_fw_down())
11938 hdd_err("Not setting the complete event as fw is down");
11939 else
Dustin Brown623e7e32018-09-05 14:27:50 -070011940 hdd_start_complete(errno);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011941
Dustin Browne74003f2018-03-14 12:51:58 -070011942 hdd_exit();
Dustin Brown92bd8382018-10-31 15:49:46 -070011943
Dustin Brown623e7e32018-09-05 14:27:50 -070011944 return errno;
Dustin Brown92bd8382018-10-31 15:49:46 -070011945}
11946
11947QDF_STATUS hdd_psoc_create_vdevs(struct hdd_context *hdd_ctx)
11948{
11949 enum QDF_GLOBAL_MODE driver_mode = hdd_get_conparam();
11950 QDF_STATUS status;
11951
11952 status = hdd_open_adapters_for_mode(hdd_ctx, driver_mode);
11953 if (QDF_IS_STATUS_ERROR(status)) {
11954 hdd_err("Failed to create vdevs; status:%d", status);
11955 return status;
11956 }
11957
11958 if (hdd_ctx->rps)
11959 hdd_set_rps_cpu_mask(hdd_ctx);
11960
11961 if (driver_mode != QDF_GLOBAL_FTM_MODE)
11962 hdd_psoc_idle_timer_start(hdd_ctx);
11963
11964 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011965}
11966
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011967/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011968 * hdd_wlan_update_target_info() - update target type info
11969 * @hdd_ctx: HDD context
11970 * @context: hif context
11971 *
11972 * Update target info received from firmware in hdd context
11973 * Return:None
11974 */
11975
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011976void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053011977{
11978 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
11979
11980 if (!tgt_info) {
11981 hdd_err("Target info is Null");
11982 return;
11983 }
11984
11985 hdd_ctx->target_type = tgt_info->target_type;
11986}
11987
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011988void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp, void *context)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011989{
11990 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011991 int status;
11992 struct hdd_adapter *adapter = NULL;
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011993 struct osif_request *request = NULL;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011994
Dustin Brown491d54b2018-03-14 12:39:11 -070011995 hdd_enter();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011996
11997 if (!rsp) {
11998 hdd_err("data is null");
11999 return;
12000 }
12001
12002 status = wlan_hdd_validate_context(hdd_ctx);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053012003 if (status != 0)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012004 return;
12005
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070012006 request = osif_request_get(context);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053012007 if (!request) {
12008 hdd_err("obselete request");
12009 return;
12010 }
12011
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012012 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
12013 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
12014 hdd_err("Invalid adapter or adapter has invalid magic");
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070012015 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012016 return;
12017 }
12018
Alok Kumarce2c29a2018-10-12 15:44:02 +053012019 hdd_debug("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
12020 hdd_debug("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
12021 hdd_debug("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
12022 hdd_debug("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
12023 hdd_debug("rsp->out_of_order_arp_rsp_drop_cnt :%x",
12024 rsp->out_of_order_arp_rsp_drop_cnt);
12025 hdd_debug("rsp->dad_detected :%x", rsp->dad_detected);
12026 hdd_debug("rsp->connect_status :%x", rsp->connect_status);
12027 hdd_debug("rsp->ba_session_establishment_status :%x",
12028 rsp->ba_session_establishment_status);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012029
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012030 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012031 adapter->dad |= rsp->dad_detected;
12032 adapter->con_status = rsp->connect_status;
12033
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053012034 /* Flag true indicates connectivity check stats present. */
12035 if (rsp->connect_stats_present) {
Alok Kumarce2c29a2018-10-12 15:44:02 +053012036 hdd_debug("rsp->tcp_ack_recvd :%x", rsp->tcp_ack_recvd);
12037 hdd_debug("rsp->icmpv4_rsp_recvd :%x", rsp->icmpv4_rsp_recvd);
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053012038 adapter->hdd_stats.hdd_tcp_stats.rx_fw_cnt = rsp->tcp_ack_recvd;
12039 adapter->hdd_stats.hdd_icmpv4_stats.rx_fw_cnt =
12040 rsp->icmpv4_rsp_recvd;
12041 }
12042
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070012043 osif_request_complete(request);
12044 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012045
Dustin Browne74003f2018-03-14 12:51:58 -070012046 hdd_exit();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012047}
12048
12049/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012050 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012051 * @hdd_ctx: HDD context
12052 *
12053 * Register the HDD callbacks to CDS/SME.
12054 *
12055 * Return: 0 for success or Error code for failure
12056 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012057int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012058{
12059 QDF_STATUS status;
12060 int ret = 0;
Jeff Johnson16528362018-06-14 12:34:16 -070012061 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012062
Dustin Brown491d54b2018-03-14 12:39:11 -070012063 hdd_enter();
Sourav Mohapatra674925f2018-04-16 11:16:58 +053012064 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
12065 hdd_err("in ftm mode, no need to register callbacks");
12066 return ret;
12067 }
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012068
Jeff Johnson16528362018-06-14 12:34:16 -070012069 mac_handle = hdd_ctx->mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012070
Jeff Johnson16528362018-06-14 12:34:16 -070012071 sme_register_oem_data_rsp_callback(mac_handle,
12072 hdd_send_oem_data_rsp_msg);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012073
Jeff Johnson16528362018-06-14 12:34:16 -070012074 sme_register_mgmt_frame_ind_callback(mac_handle,
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053012075 hdd_indicate_mgmt_frame);
Jeff Johnson16528362018-06-14 12:34:16 -070012076 sme_set_tsfcb(mac_handle, hdd_get_tsf_cb, hdd_ctx);
Jeff Johnson16528362018-06-14 12:34:16 -070012077 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012078 wlan_hdd_cfg80211_stats_ext_callback);
12079
Jeff Johnson16528362018-06-14 12:34:16 -070012080 sme_ext_scan_register_callback(mac_handle,
12081 wlan_hdd_cfg80211_extscan_callback);
12082 sme_stats_ext2_register_callback(mac_handle,
lifeng66831662017-05-19 16:01:35 +080012083 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012084
Jeff Johnson16528362018-06-14 12:34:16 -070012085 sme_set_rssi_threshold_breached_cb(mac_handle,
12086 hdd_rssi_threshold_breached);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012087
Jeff Johnson16528362018-06-14 12:34:16 -070012088 sme_set_link_layer_stats_ind_cb(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012089 wlan_hdd_cfg80211_link_layer_stats_callback);
12090
Jeff Johnson16528362018-06-14 12:34:16 -070012091 sme_rso_cmd_status_cb(mac_handle, wlan_hdd_rso_cmd_status_cb);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053012092
Jeff Johnson16528362018-06-14 12:34:16 -070012093 sme_set_link_layer_ext_cb(mac_handle,
Zhang Qianca38fb12016-12-23 11:10:48 +080012094 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
12095
Jeff Johnson16528362018-06-14 12:34:16 -070012096 status = sme_set_lost_link_info_cb(mac_handle,
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053012097 hdd_lost_link_info_cb);
12098 /* print error and not block the startup process */
12099 if (!QDF_IS_STATUS_SUCCESS(status))
12100 hdd_err("set lost link info callback failed");
12101
Poddar, Siddarth34872782017-08-10 14:08:51 +053012102 ret = hdd_register_data_stall_detect_cb();
12103 if (ret) {
12104 hdd_err("Register data stall detect detect callback failed.");
12105 return ret;
12106 }
12107
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012108 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
12109
Jeff Johnson16528362018-06-14 12:34:16 -070012110 sme_register_set_connection_info_cb(mac_handle,
12111 hdd_set_connection_in_progress,
12112 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053012113
Jeff Johnson16528362018-06-14 12:34:16 -070012114 status = sme_congestion_register_callback(mac_handle,
12115 hdd_update_cca_info_cb);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053012116 if (!QDF_IS_STATUS_SUCCESS(status))
12117 hdd_err("set congestion callback failed");
12118
Jeff Johnson16528362018-06-14 12:34:16 -070012119 status = sme_set_bt_activity_info_cb(mac_handle,
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053012120 hdd_bt_activity_cb);
12121 if (!QDF_IS_STATUS_SUCCESS(status))
12122 hdd_err("set bt activity info callback failed");
12123
Jeff Johnson16528362018-06-14 12:34:16 -070012124 status = sme_register_tx_queue_cb(mac_handle,
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080012125 hdd_tx_queue_cb);
12126 if (!QDF_IS_STATUS_SUCCESS(status))
12127 hdd_err("Register tx queue callback failed");
12128
Dustin Browne74003f2018-03-14 12:51:58 -070012129 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012130
12131 return ret;
12132}
12133
12134/**
12135 * hdd_deregister_cb() - De-Register HDD callbacks.
12136 * @hdd_ctx: HDD context
12137 *
12138 * De-Register the HDD callbacks to CDS/SME.
12139 *
12140 * Return: void
12141 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012142void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012143{
12144 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053012145 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070012146 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012147
Dustin Brown491d54b2018-03-14 12:39:11 -070012148 hdd_enter();
Sourav Mohapatra674925f2018-04-16 11:16:58 +053012149 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
12150 hdd_err("in ftm mode, no need to deregister callbacks");
12151 return;
12152 }
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012153
Jeff Johnson16528362018-06-14 12:34:16 -070012154 mac_handle = hdd_ctx->mac_handle;
12155 sme_deregister_tx_queue_cb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012156
Jeff Johnson16528362018-06-14 12:34:16 -070012157 sme_reset_link_layer_stats_ind_cb(mac_handle);
12158 sme_reset_rssi_threshold_breached_cb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012159
Jeff Johnson16528362018-06-14 12:34:16 -070012160 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012161 wlan_hdd_cfg80211_stats_ext_callback);
12162
Jeff Johnson16528362018-06-14 12:34:16 -070012163 status = sme_reset_tsfcb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012164 if (!QDF_IS_STATUS_SUCCESS(status))
12165 hdd_err("Failed to de-register tsfcb the callback:%d",
12166 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012167
Poddar, Siddarth34872782017-08-10 14:08:51 +053012168 ret = hdd_deregister_data_stall_detect_cb();
12169 if (ret)
12170 hdd_err("Failed to de-register data stall detect event callback");
12171
Jeff Johnson16528362018-06-14 12:34:16 -070012172 sme_deregister_oem_data_rsp_callback(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012173
Dustin Browne74003f2018-03-14 12:51:58 -070012174 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012175}
12176
12177/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012178 * hdd_softap_sta_deauth() - handle deauth req from HDD
12179 * @adapter: Pointer to the HDD
12180 * @enable: bool value
12181 *
12182 * This to take counter measure to handle deauth req from HDD
12183 *
12184 * Return: None
12185 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012186QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080012187 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012188{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012189 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012190
Dustin Brown491d54b2018-03-14 12:39:11 -070012191 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012192
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012193 /* Ignore request to deauth bcmc station */
12194 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012195 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012196
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012197 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012198 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
12199 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012200
Dustin Browne74003f2018-03-14 12:51:58 -070012201 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012202 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012203}
12204
12205/**
12206 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
12207 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053012208 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012209 *
12210 * This to take counter measure to handle deauth req from HDD
12211 *
12212 * Return: None
12213 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012214void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080012215 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012216{
Dustin Brown491d54b2018-03-14 12:39:11 -070012217 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012218
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012219 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053012220 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012221 return;
12222
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012223 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053012224 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012225}
12226
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012227void wlan_hdd_disable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012228{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012229 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
12230 struct hdd_adapter *adapter = NULL;
12231 struct csr_roam_profile *roam_profile;
12232 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012233
Dustin Brown1dbefe62018-09-11 16:32:03 -070012234 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->psoc)) {
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012235 hdd_debug("No active sta session");
12236 return;
12237 }
12238
12239 hdd_for_each_adapter(hdd_ctx, adapter) {
12240 roam_profile = hdd_roam_profile(adapter);
12241 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12242
12243 if (cur_adapter->session_id != adapter->session_id &&
12244 adapter->device_mode == QDF_STA_MODE &&
12245 hdd_conn_is_connected(sta_ctx)) {
12246 hdd_debug("%d Disable roaming", adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -070012247 sme_stop_roaming(hdd_ctx->mac_handle,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012248 adapter->session_id,
12249 ecsr_driver_disabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012250 }
12251 }
12252}
12253
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012254void wlan_hdd_enable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012255{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012256 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
12257 struct hdd_adapter *adapter = NULL;
12258 struct csr_roam_profile *roam_profile;
12259 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012260
Dustin Brown1dbefe62018-09-11 16:32:03 -070012261 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->psoc)) {
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012262 hdd_debug("No active sta session");
12263 return;
12264 }
12265
12266 hdd_for_each_adapter(hdd_ctx, adapter) {
12267 roam_profile = hdd_roam_profile(adapter);
12268 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12269
12270 if (cur_adapter->session_id != adapter->session_id &&
12271 adapter->device_mode == QDF_STA_MODE &&
12272 hdd_conn_is_connected(sta_ctx)) {
12273 hdd_debug("%d Enable roaming", adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -070012274 sme_start_roaming(hdd_ctx->mac_handle,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012275 adapter->session_id,
12276 REASON_DRIVER_ENABLED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012277 }
12278 }
12279}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012280
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053012281/**
12282 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
12283 * @skb: sk buffer pointer
12284 *
12285 * Sends the bcast message to SVC multicast group with generic nl socket
12286 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
12287 *
12288 * Return: None
12289 */
12290static void nl_srv_bcast_svc(struct sk_buff *skb)
12291{
12292#ifdef CNSS_GENL
12293 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
12294#else
12295 nl_srv_bcast(skb);
12296#endif
12297}
12298
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012299void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012300{
12301 struct sk_buff *skb;
12302 struct nlmsghdr *nlh;
12303 tAniMsgHdr *ani_hdr;
12304 void *nl_data = NULL;
12305 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012306 struct radio_index_tlv *radio_info;
12307 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012308
12309 if (in_interrupt() || irqs_disabled() || in_atomic())
12310 flags = GFP_ATOMIC;
12311
12312 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
12313
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012314 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012315 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012316
12317 nlh = (struct nlmsghdr *)skb->data;
12318 nlh->nlmsg_pid = 0; /* from kernel */
12319 nlh->nlmsg_flags = 0;
12320 nlh->nlmsg_seq = 0;
12321 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
12322
12323 ani_hdr = NLMSG_DATA(nlh);
12324 ani_hdr->type = type;
12325
12326 switch (type) {
12327 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053012328 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012329 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012330 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070012331 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012332 ani_hdr->length = 0;
12333 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012334 break;
12335 case WLAN_SVC_WLAN_STATUS_IND:
12336 case WLAN_SVC_WLAN_VERSION_IND:
12337 case WLAN_SVC_DFS_CAC_START_IND:
12338 case WLAN_SVC_DFS_CAC_END_IND:
12339 case WLAN_SVC_DFS_RADAR_DETECT_IND:
12340 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
12341 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080012342 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053012343 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080012344 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012345 ani_hdr->length = len;
12346 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
12347 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
12348 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012349 break;
12350
12351 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070012352 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012353 type);
12354 kfree_skb(skb);
12355 return;
12356 }
12357
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012358 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080012359 * Add radio index at the end of the svc event in TLV format
12360 * to maintain the backward compatibility with userspace
12361 * applications.
12362 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012363
12364 tlv_len = 0;
12365
12366 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
12367 < WLAN_NL_MAX_PAYLOAD) {
12368 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
12369 sizeof(*ani_hdr) + len);
12370 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
12371 radio_info->length = (unsigned short) sizeof(radio_info->radio);
12372 radio_info->radio = radio;
12373 tlv_len = sizeof(*radio_info);
Dustin Browna2868622018-03-20 11:38:14 -070012374 hdd_debug("Added radio index tlv - radio index %d",
12375 radio_info->radio);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012376 }
12377
12378 nlh->nlmsg_len += tlv_len;
12379 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
12380
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053012381 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012382}
12383
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012384#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
12385void wlan_hdd_auto_shutdown_cb(void)
12386{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012387 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012388
12389 if (!hdd_ctx)
12390 return;
12391
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012392 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012393 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
12394 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012395}
12396
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012397void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012398{
Jeff Johnson9d295242017-08-29 14:39:48 -070012399 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012400 bool ap_connected = false, sta_connected = false;
Jeff Johnson16528362018-06-14 12:34:16 -070012401 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012402
Jeff Johnson16528362018-06-14 12:34:16 -070012403 mac_handle = hdd_ctx->mac_handle;
12404 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012405 return;
12406
Dundi Raviteja8e338282018-09-25 17:16:04 +053012407 if (hdd_ctx->config->wlan_auto_shutdown == 0)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012408 return;
12409
12410 if (enable == false) {
Jeff Johnson16528362018-06-14 12:34:16 -070012411 if (sme_set_auto_shutdown_timer(mac_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012412 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012413 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012414 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012415 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070012416 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012417 return;
12418 }
12419
12420 /* To enable shutdown timer check conncurrency */
Dustin Brown1dbefe62018-09-11 16:32:03 -070012421 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->psoc)) {
Dustin Brown920397d2017-12-13 16:27:50 -080012422 hdd_for_each_adapter(hdd_ctx, adapter) {
12423 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012424 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
12425 conn_info.connState ==
12426 eConnectionState_Associated) {
12427 sta_connected = true;
12428 break;
12429 }
12430 }
Dustin Brown920397d2017-12-13 16:27:50 -080012431
12432 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012433 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070012434 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012435 ap_connected = true;
12436 break;
12437 }
12438 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012439 }
12440 }
12441
12442 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012443 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012444 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012445 }
Jeff Johnson68755312017-02-10 11:46:55 -080012446
Jeff Johnson16528362018-06-14 12:34:16 -070012447 if (sme_set_auto_shutdown_timer(mac_handle,
Dundi Raviteja8e338282018-09-25 17:16:04 +053012448 hdd_ctx->config->wlan_auto_shutdown)
Jeff Johnson68755312017-02-10 11:46:55 -080012449 != QDF_STATUS_SUCCESS)
12450 hdd_err("Failed to start wlan auto shutdown timer");
12451 else
Dustin Brown5e89ef82018-03-14 11:50:23 -070012452 hdd_info("Auto Shutdown timer for %d seconds enabled",
Dundi Raviteja8e338282018-09-25 17:16:04 +053012453 hdd_ctx->config->wlan_auto_shutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012454}
12455#endif
12456
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070012457struct hdd_adapter *
12458hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
12459 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012460{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012461 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070012462 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012463
12464 con_sap_adapter = NULL;
12465
Dustin Brown920397d2017-12-13 16:27:50 -080012466 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012467 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
12468 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012469 adapter != this_sap_adapter) {
12470 if (check_start_bss) {
12471 if (test_bit(SOFTAP_BSS_STARTED,
12472 &adapter->event_flags)) {
12473 con_sap_adapter = adapter;
12474 break;
12475 }
12476 } else {
12477 con_sap_adapter = adapter;
12478 break;
12479 }
12480 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012481 }
12482
12483 return con_sap_adapter;
12484}
12485
12486#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070012487static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012488{
Dustin Brown5ec6b552017-03-31 12:11:40 -070012489 return adapter->device_mode == QDF_STA_MODE ||
12490 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012491}
12492
Jeff Johnson9d295242017-08-29 14:39:48 -070012493static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012494{
Dustin Brown5ec6b552017-03-31 12:11:40 -070012495 return adapter->device_mode == QDF_SAP_MODE ||
12496 adapter->device_mode == QDF_P2P_GO_MODE;
12497}
12498
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012499static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012500{
Dustin Brown920397d2017-12-13 16:27:50 -080012501 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070012502
Dustin Brown920397d2017-12-13 16:27:50 -080012503 hdd_for_each_adapter(hdd_ctx, adapter) {
12504 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070012505 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
12506 conn_info.connState == eConnectionState_Associated) {
12507 return true;
12508 }
12509
Dustin Brown920397d2017-12-13 16:27:50 -080012510 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070012511 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070012512 return true;
12513 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070012514 }
12515
12516 return false;
12517}
12518
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012519static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012520{
12521 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012522
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053012523 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012524 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053012525 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012526
Dustin Brown5ec6b552017-03-31 12:11:40 -070012527 return is_running;
12528}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012529
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012530static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012531{
12532 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
12533 hdd_ctx->bus_bw_timer_running = true;
12534 qdf_timer_start(&hdd_ctx->bus_bw_timer,
jitiphil869b9f72018-09-25 17:14:01 +053012535 hdd_ctx->config->bus_bw_compute_interval);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012536 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
12537}
12538
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012539void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012540{
Dustin Brown491d54b2018-03-14 12:39:11 -070012541 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012542
12543 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12544 hdd_debug("Bandwidth compute timer already started");
12545 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012546 }
12547
Dustin Brown5ec6b552017-03-31 12:11:40 -070012548 __hdd_bus_bw_compute_timer_start(hdd_ctx);
12549
Dustin Browne74003f2018-03-14 12:51:58 -070012550 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012551}
12552
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012553void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012554{
Dustin Brown491d54b2018-03-14 12:39:11 -070012555 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012556
12557 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12558 hdd_debug("Bandwidth compute timer already started");
12559 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070012560 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070012561
12562 if (hdd_any_adapter_is_assoc(hdd_ctx))
12563 __hdd_bus_bw_compute_timer_start(hdd_ctx);
12564
Dustin Browne74003f2018-03-14 12:51:58 -070012565 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012566}
12567
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012568static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012569{
Dustin Brown07901ec2018-09-07 11:02:41 -070012570 ucfg_ipa_set_perf_level(hdd_ctx->pdev, 0, 0);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012571
12572 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012573 hdd_ctx->bus_bw_timer_running = false;
Dustin Brown35008ba2018-08-23 14:34:21 -070012574 qdf_timer_sync_cancel(&hdd_ctx->bus_bw_timer);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012575 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
12576
Dustin Brown35008ba2018-08-23 14:34:21 -070012577 /* work callback is long running; flush outside of lock */
12578 cancel_work_sync(&hdd_ctx->bus_bw_work);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012579 hdd_reset_tcp_delack(hdd_ctx);
12580}
12581
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012582void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012583{
Dustin Brown491d54b2018-03-14 12:39:11 -070012584 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012585
12586 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12587 hdd_debug("Bandwidth compute timer already stopped");
12588 return;
12589 }
12590
12591 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
12592
Dustin Browne74003f2018-03-14 12:51:58 -070012593 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012594}
12595
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012596void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012597{
Dustin Brown491d54b2018-03-14 12:39:11 -070012598 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012599
12600 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12601 hdd_debug("Bandwidth compute timer already stopped");
12602 return;
12603 }
12604
12605 if (!hdd_any_adapter_is_assoc(hdd_ctx))
12606 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
12607
Dustin Browne74003f2018-03-14 12:51:58 -070012608 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012609}
12610#endif
12611
12612/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012613 * wlan_hdd_stop_sap() - This function stops bss of SAP.
12614 * @ap_adapter: SAP adapter
12615 *
12616 * This function will process the stopping of sap adapter.
12617 *
12618 * Return: None
12619 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012620void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012621{
Jeff Johnson87251032017-08-29 13:31:11 -070012622 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012623 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053012624 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012625 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012626
12627 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012628 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012629 return;
12630 }
12631
12632 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12633 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012634 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012635 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012636
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012637 mutex_lock(&hdd_ctx->sap_lock);
12638 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080012639 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012640 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012641 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053012642 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012643 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012644 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053012645 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080012646 qdf_stop_bss_event,
Vignesh Viswanathan865daaa2018-10-11 19:30:44 +053012647 SME_CMD_START_STOP_BSS_TIMEOUT);
Anurag Chouhance0dc992016-02-16 18:18:03 +053012648 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012649 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070012650 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012651 return;
12652 }
12653 }
12654 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -070012655 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012656 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012657 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012658 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012659 false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012660 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012661 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012662 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012663 }
12664 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012665}
12666
12667/**
12668 * wlan_hdd_start_sap() - this function starts bss of SAP.
12669 * @ap_adapter: SAP adapter
12670 *
12671 * This function will process the starting of sap adapter.
12672 *
12673 * Return: None
12674 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012675void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012676{
Jeff Johnson87251032017-08-29 13:31:11 -070012677 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012678 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053012679 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012680 struct hdd_context *hdd_ctx;
Jeff Johnsone4c11db2018-05-05 23:22:32 -070012681 tsap_config_t *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012682
12683 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012684 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012685 return;
12686 }
12687
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012688 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070012689 hdd_err("SoftAp role has not been enabled");
12690 return;
12691 }
12692
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012693 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
12694 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12695 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070012696 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012697
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012698 mutex_lock(&hdd_ctx->sap_lock);
12699 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
12700 goto end;
12701
12702 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012703 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012704 goto end;
12705 }
Dustin Brown07901ec2018-09-07 11:02:41 -070012706 wlan_reg_set_channel_params(hdd_ctx->pdev,
Abhinav Kumar6f694482018-09-04 16:07:39 +053012707 hdd_ap_ctx->sap_config.channel, 0,
12708 &hdd_ap_ctx->sap_config.ch_params);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012709
Wei Song2f76f642016-11-18 16:32:53 +080012710 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012711 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070012712 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012713 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012714 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012715 goto end;
12716
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012717 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053012718 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Vignesh Viswanathan865daaa2018-10-11 19:30:44 +053012719 SME_CMD_START_STOP_BSS_TIMEOUT);
Anurag Chouhance0dc992016-02-16 18:18:03 +053012720 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012721 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012722 goto end;
12723 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070012724 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012725 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012726 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012727 if (hostapd_state->bss_state == BSS_START) {
Dustin Brown1dbefe62018-09-11 16:32:03 -070012728 policy_mgr_incr_active_session(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012729 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012730 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012731 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012732 true);
12733 }
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053012734 mutex_unlock(&hdd_ctx->sap_lock);
12735
12736 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012737end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012738 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012739 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070012740 /* SAP context and beacon cleanup will happen during driver unload
12741 * in hdd_stop_adapter
12742 */
12743 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
12744
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012745}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012746
12747/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012748 * hdd_get_fw_version() - Get FW version
12749 * @hdd_ctx: pointer to HDD context.
12750 * @major_spid: FW version - major spid.
12751 * @minor_spid: FW version - minor spid
12752 * @ssid: FW version - ssid
12753 * @crmid: FW version - crmid
12754 *
12755 * This function is called to get the firmware build version stored
12756 * as part of the HDD context
12757 *
12758 * Return: None
12759 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012760void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012761 uint32_t *major_spid, uint32_t *minor_spid,
12762 uint32_t *siid, uint32_t *crmid)
12763{
12764 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
12765 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
12766 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
12767 *crmid = hdd_ctx->target_fw_version & 0x7fff;
12768}
12769
12770#ifdef QCA_CONFIG_SMP
12771/**
12772 * wlan_hdd_get_cpu() - get cpu_index
12773 *
12774 * Return: cpu_index
12775 */
12776int wlan_hdd_get_cpu(void)
12777{
12778 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012779
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012780 put_cpu();
12781 return cpu_index;
12782}
12783#endif
12784
12785/**
12786 * hdd_get_fwpath() - get framework path
12787 *
12788 * This function is used to get the string written by
12789 * userspace to start the wlan driver
12790 *
12791 * Return: string
12792 */
12793const char *hdd_get_fwpath(void)
12794{
12795 return fwpath.string;
12796}
12797
Dustin Brown94ce20f2018-09-04 13:11:38 -070012798static inline int hdd_state_query_cb(void)
12799{
12800 return !!wlan_hdd_validate_context(cds_get_context(QDF_MODULE_ID_HDD));
12801}
12802
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012803/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012804 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012805 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012806 * This function initilizes CDS global context with the help of cds_init. This
12807 * has to be the first function called after probe to get a valid global
12808 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012809 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012810 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012811 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012812int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012813{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012814 QDF_STATUS status;
Dustin Brownfe50cef2018-12-10 10:42:37 -080012815 int ret;
12816
12817 hdd_dsc_init();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012818
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012819 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080012820 if (QDF_IS_STATUS_ERROR(status)) {
12821 hdd_err("Failed to allocate CDS context");
12822 ret = -ENOMEM;
Dustin Brownfe50cef2018-12-10 10:42:37 -080012823 goto deinit_dsc;
wadesongae4ffd12017-10-24 16:45:54 +080012824 }
Dustin Brown94ce20f2018-09-04 13:11:38 -070012825 qdf_register_module_state_query_callback(hdd_state_query_cb);
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053012826
12827 wlan_init_bug_report_lock();
12828
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012829#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12830 wlan_logging_sock_init_svc();
12831#endif
12832
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012833 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
12834 (void *)hdd_drv_ops_inactivity_handler, NULL,
12835 QDF_TIMER_TYPE_SW);
12836
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012837 hdd_trace_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053012838 hdd_register_debug_callback();
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012839 wlan_roam_debug_init();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012840
Dustin Brownfe50cef2018-12-10 10:42:37 -080012841 return 0;
12842
12843deinit_dsc:
12844 hdd_dsc_deinit();
12845
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012846 return ret;
12847}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012848
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012849/**
12850 * hdd_deinit() - Deinitialize Driver
12851 *
12852 * This function frees CDS global context with the help of cds_deinit. This
12853 * has to be the last function call in remove callback to free the global
12854 * context.
12855 */
12856void hdd_deinit(void)
12857{
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012858 wlan_roam_debug_deinit();
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012859 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012860
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012861#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12862 wlan_logging_sock_deinit_svc();
12863#endif
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012864
12865 wlan_destroy_bug_report_lock();
12866 cds_deinit();
Dustin Brownfe50cef2018-12-10 10:42:37 -080012867
12868 hdd_dsc_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012869}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012870
Yue Ma6e7b1a02017-04-03 14:17:46 -070012871#ifdef QCA_WIFI_NAPIER_EMULATION
12872#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
12873#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012874#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070012875#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012876
Sachin Ahujadddd2632017-03-07 19:07:24 +053012877static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
12878 struct file *file)
12879{
12880 return 0;
12881}
12882
12883static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
12884 const char __user *user_buf,
12885 size_t count,
12886 loff_t *f_pos)
12887{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012888 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053012889 static const char wlan_off_str[] = "OFF";
12890 static const char wlan_on_str[] = "ON";
12891 int ret;
12892 unsigned long rc;
12893
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012894 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012895 pr_err("Failed to read buffer\n");
12896 return -EINVAL;
12897 }
12898
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012899 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012900 pr_debug("Wifi turning off from UI\n");
12901 goto exit;
12902 }
12903
Srinivas Girigowdad2412882018-09-07 15:42:04 -070012904 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) == 0)
Sachin Ahuja16904db2017-12-13 19:56:57 +053012905 pr_info("Wifi Turning On from UI\n");
Sachin Ahuja16904db2017-12-13 19:56:57 +053012906
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012907 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012908 pr_err("Invalid value received from framework");
12909 goto exit;
12910 }
12911
12912 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053012913 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053012914 rc = wait_for_completion_timeout(&wlan_start_comp,
12915 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
12916 if (!rc) {
Srinivas Girigowda09625b02018-09-10 15:28:09 -070012917 hdd_alert("Timed-out!!");
Sachin Ahujadddd2632017-03-07 19:07:24 +053012918 ret = -EINVAL;
Sachin Ahujadddd2632017-03-07 19:07:24 +053012919 return ret;
12920 }
12921
12922 hdd_start_complete(0);
12923 }
12924
12925exit:
12926 return count;
12927}
12928
12929
12930const struct file_operations wlan_hdd_state_fops = {
12931 .owner = THIS_MODULE,
12932 .open = wlan_hdd_state_ctrl_param_open,
12933 .write = wlan_hdd_state_ctrl_param_write,
12934};
12935
12936static int wlan_hdd_state_ctrl_param_create(void)
12937{
12938 unsigned int wlan_hdd_state_major = 0;
12939 int ret;
12940 struct device *dev;
12941
12942 device = MKDEV(wlan_hdd_state_major, 0);
12943
12944 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
12945 if (ret) {
12946 pr_err("Failed to register qcwlanstate");
12947 goto dev_alloc_err;
12948 }
12949 wlan_hdd_state_major = MAJOR(device);
12950
12951 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
12952 if (IS_ERR(class)) {
12953 pr_err("wlan_hdd_state class_create error");
12954 goto class_err;
12955 }
12956
12957 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
12958 if (IS_ERR(dev)) {
12959 pr_err("wlan_hdd_statedevice_create error");
12960 goto err_class_destroy;
12961 }
12962
12963 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
12964 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
12965 if (ret) {
12966 pr_err("Failed to add cdev error");
12967 goto cdev_add_err;
12968 }
12969
12970 pr_info("wlan_hdd_state %s major(%d) initialized",
12971 WLAN_MODULE_NAME, wlan_hdd_state_major);
12972
12973 return 0;
12974
12975cdev_add_err:
12976 device_destroy(class, device);
12977err_class_destroy:
12978 class_destroy(class);
12979class_err:
12980 unregister_chrdev_region(device, dev_num);
12981dev_alloc_err:
12982 return -ENODEV;
12983}
12984
12985static void wlan_hdd_state_ctrl_param_destroy(void)
12986{
12987 cdev_del(&wlan_hdd_state_cdev);
12988 device_destroy(class, device);
12989 class_destroy(class);
12990 unregister_chrdev_region(device, dev_num);
12991
12992 pr_info("Device node unregistered");
12993}
12994
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012995/**
Dustin Brownd585cb32018-09-12 17:12:23 -070012996 * hdd_component_init() - Initialize all components
Mukul Sharmad75a6672017-06-22 15:40:53 +053012997 *
Dustin Brownd585cb32018-09-12 17:12:23 -070012998 * Return: QDF_STATUS
Mukul Sharmad75a6672017-06-22 15:40:53 +053012999 */
Dustin Brownd585cb32018-09-12 17:12:23 -070013000static QDF_STATUS hdd_component_init(void)
Mukul Sharmad75a6672017-06-22 15:40:53 +053013001{
Dustin Brownd585cb32018-09-12 17:12:23 -070013002 QDF_STATUS status;
13003
13004 /* initialize converged components */
Arif Hussain49698112018-07-31 00:32:50 -070013005 status = target_if_init(wma_get_psoc_from_scn_handle);
Dustin Brownd585cb32018-09-12 17:12:23 -070013006 if (QDF_IS_STATUS_ERROR(status))
13007 return status;
13008
Arif Hussain49698112018-07-31 00:32:50 -070013009 status = dispatcher_init();
13010 if (QDF_IS_STATUS_ERROR(status))
13011 goto target_if_deinit;
13012
Dustin Brownd585cb32018-09-12 17:12:23 -070013013 /* initialize non-converged components */
13014 status = ucfg_mlme_init();
13015 if (QDF_IS_STATUS_ERROR(status))
13016 goto dispatcher_deinit;
13017
13018 status = ucfg_fwol_init();
13019 if (QDF_IS_STATUS_ERROR(status))
13020 goto mlme_deinit;
13021
13022 status = disa_init();
13023 if (QDF_IS_STATUS_ERROR(status))
13024 goto fwol_deinit;
13025
13026 status = pmo_init();
13027 if (QDF_IS_STATUS_ERROR(status))
13028 goto disa_deinit;
13029
13030 status = ucfg_ocb_init();
13031 if (QDF_IS_STATUS_ERROR(status))
13032 goto pmo_deinit;
13033
13034 status = ipa_init();
13035 if (QDF_IS_STATUS_ERROR(status))
13036 goto ocb_deinit;
13037
13038 status = ucfg_action_oui_init();
13039 if (QDF_IS_STATUS_ERROR(status))
13040 goto ipa_deinit;
13041
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013042 status = nan_init();
13043 if (QDF_IS_STATUS_ERROR(status))
13044 goto action_oui_deinit;
13045
Wu Gao637d58a2018-12-08 10:37:34 +080013046 status = ucfg_p2p_init();
13047 if (QDF_IS_STATUS_ERROR(status))
13048 goto nan_deinit;
13049
Wu Gaod6b5e402018-12-03 22:09:24 +080013050 status = policy_mgr_init();
13051 if (QDF_IS_STATUS_ERROR(status))
13052 goto p2p_deinit;
13053
Wu Gao5f793402018-12-08 11:04:00 +080013054 status = ucfg_tdls_init();
13055 if (QDF_IS_STATUS_ERROR(status))
13056 goto policy_deinit;
13057
Dustin Brownd585cb32018-09-12 17:12:23 -070013058 return QDF_STATUS_SUCCESS;
13059
Wu Gao5f793402018-12-08 11:04:00 +080013060policy_deinit:
13061 policy_mgr_deinit();
Wu Gaod6b5e402018-12-03 22:09:24 +080013062p2p_deinit:
13063 ucfg_p2p_deinit();
Wu Gao637d58a2018-12-08 10:37:34 +080013064nan_deinit:
13065 nan_deinit();
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013066action_oui_deinit:
13067 ucfg_action_oui_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013068ipa_deinit:
13069 ipa_deinit();
13070ocb_deinit:
13071 ucfg_ocb_deinit();
13072pmo_deinit:
13073 pmo_deinit();
13074disa_deinit:
13075 disa_deinit();
13076fwol_deinit:
13077 ucfg_fwol_deinit();
13078mlme_deinit:
13079 ucfg_mlme_deinit();
13080dispatcher_deinit:
13081 dispatcher_deinit();
Arif Hussain49698112018-07-31 00:32:50 -070013082target_if_deinit:
13083 target_if_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013084
13085 return status;
Mukul Sharmad75a6672017-06-22 15:40:53 +053013086}
13087
13088/**
Dustin Brownd585cb32018-09-12 17:12:23 -070013089 * hdd_component_deinit() - Deinitialize all components
Mukul Sharmad75a6672017-06-22 15:40:53 +053013090 *
13091 * Return: None
13092 */
Dustin Brownd585cb32018-09-12 17:12:23 -070013093static void hdd_component_deinit(void)
Mukul Sharmad75a6672017-06-22 15:40:53 +053013094{
Dustin Brownd585cb32018-09-12 17:12:23 -070013095 /* deinitialize non-converged components */
Wu Gao5f793402018-12-08 11:04:00 +080013096 ucfg_tdls_deinit();
Wu Gaod6b5e402018-12-03 22:09:24 +080013097 policy_mgr_deinit();
Wu Gao637d58a2018-12-08 10:37:34 +080013098 ucfg_p2p_deinit();
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013099 nan_deinit();
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053013100 ucfg_action_oui_deinit();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053013101 ipa_deinit();
Zhang Qian47e22ce2018-01-04 15:38:38 +080013102 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053013103 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013104 disa_deinit();
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013105 ucfg_fwol_deinit();
Vignesh Viswanathana0921c42018-09-04 19:03:35 +053013106 ucfg_mlme_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013107
13108 /* deinitialize converged components */
13109 dispatcher_deinit();
Arif Hussain49698112018-07-31 00:32:50 -070013110 target_if_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013111}
13112
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053013113QDF_STATUS hdd_component_psoc_open(struct wlan_objmgr_psoc *psoc)
13114{
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013115 QDF_STATUS status;
13116
13117 status = ucfg_mlme_psoc_open(psoc);
13118 if (QDF_IS_STATUS_ERROR(status))
13119 return status;
13120
13121 status = ucfg_fwol_psoc_open(psoc);
13122 if (QDF_IS_STATUS_ERROR(status))
Wu Gao66454f12018-09-26 19:55:41 +080013123 goto err_fwol;
13124
13125 status = ucfg_pmo_psoc_open(psoc);
13126 if (QDF_IS_STATUS_ERROR(status))
13127 goto err_pmo;
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013128
Krunal Sonie9c12f52018-10-04 11:45:42 -070013129 status = ucfg_policy_mgr_psoc_open(psoc);
13130 if (QDF_IS_STATUS_ERROR(status))
13131 goto err_plcy_mgr;
13132
Wu Gao637d58a2018-12-08 10:37:34 +080013133 status = ucfg_p2p_psoc_open(psoc);
13134 if (QDF_IS_STATUS_ERROR(status))
13135 goto err_p2p;
Wu Gao5f793402018-12-08 11:04:00 +080013136
13137 status = ucfg_tdls_psoc_open(psoc);
13138 if (QDF_IS_STATUS_ERROR(status))
13139 goto err_tdls;
13140
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013141 return status;
13142
Wu Gao5f793402018-12-08 11:04:00 +080013143err_tdls:
13144 ucfg_tdls_psoc_close(psoc);
Wu Gao637d58a2018-12-08 10:37:34 +080013145err_p2p:
13146 ucfg_p2p_psoc_close(psoc);
Krunal Sonie9c12f52018-10-04 11:45:42 -070013147err_plcy_mgr:
13148 ucfg_pmo_psoc_close(psoc);
Wu Gao66454f12018-09-26 19:55:41 +080013149err_pmo:
13150 ucfg_fwol_psoc_close(psoc);
13151err_fwol:
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013152 ucfg_mlme_psoc_close(psoc);
Krunal Sonie9c12f52018-10-04 11:45:42 -070013153
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013154 return status;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053013155}
13156
13157void hdd_component_psoc_close(struct wlan_objmgr_psoc *psoc)
13158{
Wu Gao5f793402018-12-08 11:04:00 +080013159 ucfg_tdls_psoc_close(psoc);
Wu Gao637d58a2018-12-08 10:37:34 +080013160 ucfg_p2p_psoc_close(psoc);
Krunal Sonie9c12f52018-10-04 11:45:42 -070013161 ucfg_policy_mgr_psoc_close(psoc);
Wu Gao66454f12018-09-26 19:55:41 +080013162 ucfg_pmo_psoc_close(psoc);
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013163 ucfg_fwol_psoc_close(psoc);
Vignesh Viswanathana0921c42018-09-04 19:03:35 +053013164 ucfg_mlme_psoc_close(psoc);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053013165}
13166
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013167void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
13168{
Zhang Qian47e22ce2018-01-04 15:38:38 +080013169 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013170 disa_psoc_enable(psoc);
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013171 nan_psoc_enable(psoc);
Wu Gao637d58a2018-12-08 10:37:34 +080013172 p2p_psoc_enable(psoc);
Wu Gaod6b5e402018-12-03 22:09:24 +080013173 policy_mgr_psoc_enable(psoc);
Wu Gaoa67c3802018-12-27 12:07:52 +080013174 ucfg_tdls_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013175}
13176
13177void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
13178{
Wu Gaoa67c3802018-12-27 12:07:52 +080013179 ucfg_tdls_psoc_disable(psoc);
Wu Gaod6b5e402018-12-03 22:09:24 +080013180 policy_mgr_psoc_disable(psoc);
Wu Gao637d58a2018-12-08 10:37:34 +080013181 p2p_psoc_disable(psoc);
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013182 nan_psoc_disable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013183 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080013184 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053013185}
13186
Sandeep Puligillab7beb472018-08-13 22:54:20 -070013187QDF_STATUS hdd_component_pdev_open(struct wlan_objmgr_pdev *pdev)
13188{
13189 return ucfg_mlme_pdev_open(pdev);
13190}
13191
13192void hdd_component_pdev_close(struct wlan_objmgr_pdev *pdev)
13193{
13194 ucfg_mlme_pdev_close(pdev);
13195}
13196
Dustin Brown21a1d462018-07-31 15:13:06 -070013197static struct hdd_driver __hdd_driver;
13198
13199static QDF_STATUS hdd_driver_ctx_init(struct hdd_driver *hdd_driver)
13200{
13201 QDF_BUG(hdd_driver);
13202 if (!hdd_driver)
13203 return QDF_STATUS_E_INVAL;
13204
13205 hdd_driver->state = driver_state_uninit;
13206
13207 return dsc_driver_create(&hdd_driver->dsc_driver);
13208}
13209
13210static void hdd_driver_ctx_deinit(struct hdd_driver *hdd_driver)
13211{
13212 QDF_BUG(hdd_driver);
13213 if (!hdd_driver)
13214 return;
13215
13216 dsc_driver_destroy(&hdd_driver->dsc_driver);
13217 qdf_mem_zero(hdd_driver, sizeof(*hdd_driver));
13218}
13219
13220struct hdd_driver *hdd_driver_get(void)
13221{
13222 return &__hdd_driver;
13223}
13224
Dustin Browna2a39dc2018-09-17 15:29:59 -070013225static QDF_STATUS hdd_qdf_print_init(void)
13226{
13227 QDF_STATUS status;
13228 int qdf_print_idx;
13229
13230 status = qdf_print_setup();
13231 if (QDF_IS_STATUS_ERROR(status)) {
13232 pr_err("Failed qdf_print_setup; status:%u\n", status);
13233 return status;
13234 }
13235
13236 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
13237 if (qdf_print_idx < 0) {
13238 pr_err("Failed to register for qdf_print_ctrl\n");
13239 return QDF_STATUS_E_FAILURE;
13240 }
13241
13242 qdf_set_pidx(qdf_print_idx);
13243
13244 return QDF_STATUS_SUCCESS;
13245}
13246
13247static void hdd_qdf_print_deinit(void)
13248{
13249 int qdf_pidx = qdf_get_pidx();
13250
13251 qdf_set_pidx(-1);
13252 qdf_print_ctrl_cleanup(qdf_pidx);
13253
13254 /* currently, no qdf print 'un-setup'*/
13255}
13256
13257static QDF_STATUS hdd_qdf_init(void)
13258{
13259 QDF_STATUS status;
13260
13261 status = hdd_qdf_print_init();
13262 if (QDF_IS_STATUS_ERROR(status))
13263 goto exit;
13264
13265 status = qdf_debugfs_init();
13266 if (QDF_IS_STATUS_ERROR(status)) {
13267 hdd_err("Failed to init debugfs; status:%u", status);
13268 goto print_deinit;
13269 }
13270
13271 qdf_lock_stats_init();
13272 qdf_mem_init();
13273 qdf_mc_timer_manager_init();
13274 qdf_event_list_init();
13275
Dustin Brownd315c452018-11-27 11:28:48 -080013276 status = qdf_talloc_feature_init();
13277 if (QDF_IS_STATUS_ERROR(status)) {
13278 hdd_err("Failed to init talloc; status:%u", status);
13279 goto event_deinit;
13280 }
13281
Dustin Browna2a39dc2018-09-17 15:29:59 -070013282 status = qdf_cpuhp_init();
13283 if (QDF_IS_STATUS_ERROR(status)) {
13284 hdd_err("Failed to init cpuhp; status:%u", status);
Dustin Brownd315c452018-11-27 11:28:48 -080013285 goto talloc_deinit;
Dustin Browna2a39dc2018-09-17 15:29:59 -070013286 }
13287
13288 status = qdf_trace_spin_lock_init();
13289 if (QDF_IS_STATUS_ERROR(status)) {
13290 hdd_err("Failed to init spinlock; status:%u", status);
13291 goto cpuhp_deinit;
13292 }
13293
13294 qdf_trace_init();
13295 qdf_register_debugcb_init();
13296
13297 return QDF_STATUS_SUCCESS;
13298
13299cpuhp_deinit:
13300 qdf_cpuhp_deinit();
Dustin Brownd315c452018-11-27 11:28:48 -080013301talloc_deinit:
13302 qdf_talloc_feature_deinit();
Dustin Browna2a39dc2018-09-17 15:29:59 -070013303event_deinit:
13304 qdf_event_list_destroy();
13305 qdf_mc_timer_manager_exit();
13306 qdf_mem_exit();
13307 qdf_lock_stats_deinit();
13308 qdf_debugfs_exit();
13309print_deinit:
13310 hdd_qdf_print_deinit();
13311
13312exit:
13313 return status;
13314}
13315
13316static void hdd_qdf_deinit(void)
13317{
13318 /* currently, no debugcb deinit */
13319
13320 qdf_trace_deinit();
13321
13322 /* currently, no trace spinlock deinit */
13323
13324 qdf_cpuhp_deinit();
Dustin Brownd315c452018-11-27 11:28:48 -080013325 qdf_talloc_feature_deinit();
Dustin Browna2a39dc2018-09-17 15:29:59 -070013326 qdf_event_list_destroy();
13327 qdf_mc_timer_manager_exit();
13328 qdf_mem_exit();
13329 qdf_lock_stats_deinit();
13330 qdf_debugfs_exit();
13331 hdd_qdf_print_deinit();
13332}
Dustin Brownf0f70562018-09-14 10:29:38 -070013333
13334/**
13335 * hdd_driver_load() - Perform the driver-level load operation
13336 *
13337 * Note: this is used in both static and DLKM driver builds
13338 *
13339 * Return: Errno
13340 */
13341static int hdd_driver_load(void)
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013342{
Dustin Brown21a1d462018-07-31 15:13:06 -070013343 struct hdd_driver *hdd_driver = hdd_driver_get();
Dustin Brownd585cb32018-09-12 17:12:23 -070013344 QDF_STATUS status;
Dustin Brownf0f70562018-09-14 10:29:38 -070013345 int errno;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013346
Rajeev Kumare555e2d2018-09-17 11:52:37 -070013347 pr_err("%s: Loading driver v%s\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070013348 WLAN_MODULE_NAME,
Rajeev Kumare555e2d2018-09-17 11:52:37 -070013349 g_wlan_driver_version);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013350
Dustin Browna2a39dc2018-09-17 15:29:59 -070013351 status = hdd_qdf_init();
13352 if (QDF_IS_STATUS_ERROR(status)) {
13353 errno = qdf_status_to_os_return(status);
13354 goto exit;
13355 }
13356
Dustin Brown21a1d462018-07-31 15:13:06 -070013357 status = hdd_driver_ctx_init(hdd_driver);
13358 if (QDF_IS_STATUS_ERROR(status)) {
13359 hdd_err("Failed to init driver context; status:%u", status);
13360 errno = qdf_status_to_os_return(status);
13361 goto qdf_deinit;
13362 }
13363
13364 status = dsc_driver_trans_start(hdd_driver->dsc_driver, "load");
13365 QDF_BUG(QDF_IS_STATUS_SUCCESS(status));
13366 if (QDF_IS_STATUS_ERROR(status)) {
13367 errno = qdf_status_to_os_return(status);
13368 goto hdd_driver_deinit;
13369 }
13370
Dustin Brownf0f70562018-09-14 10:29:38 -070013371 errno = hdd_init();
13372 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013373 hdd_err("Failed to init HDD; errno:%d", errno);
Dustin Brown21a1d462018-07-31 15:13:06 -070013374 goto trans_stop;
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013375 }
13376
Dustin Brownd585cb32018-09-12 17:12:23 -070013377 status = hdd_component_init();
13378 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013379 hdd_err("Failed to init components; status:%u", status);
Dustin Brownf0f70562018-09-14 10:29:38 -070013380 errno = qdf_status_to_os_return(status);
Dustin Brownd585cb32018-09-12 17:12:23 -070013381 goto hdd_deinit;
13382 }
Mukul Sharmad75a6672017-06-22 15:40:53 +053013383
Dustin Brownf0f70562018-09-14 10:29:38 -070013384 status = qdf_wake_lock_create(&wlan_wake_lock, "wlan");
13385 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013386 hdd_err("Failed to create wake lock; status:%u", status);
Dustin Brownf0f70562018-09-14 10:29:38 -070013387 errno = qdf_status_to_os_return(status);
13388 goto comp_deinit;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013389 }
13390
Dustin Brownf0f70562018-09-14 10:29:38 -070013391 hdd_set_conparam(con_mode);
13392
Dustin Brownf0f70562018-09-14 10:29:38 -070013393 errno = wlan_hdd_state_ctrl_param_create();
13394 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013395 hdd_err("Failed to create ctrl param; errno:%d", errno);
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013396 goto wakelock_destroy;
13397 }
13398
Dustin Brown25843ad2018-09-17 14:54:33 -070013399 errno = pld_init();
13400 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013401 hdd_err("Failed to init PLD; errno:%d", errno);
Dustin Brown25843ad2018-09-17 14:54:33 -070013402 goto param_destroy;
13403 }
13404
Dustin Brown21a1d462018-07-31 15:13:06 -070013405 hdd_driver->state = driver_state_loaded;
13406 dsc_driver_trans_stop(hdd_driver->dsc_driver);
13407
13408 /* psoc probe can happen in registration; do after 'load' transition */
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013409 errno = wlan_hdd_register_driver();
13410 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013411 hdd_err("Failed to register driver; errno:%d", errno);
Dustin Brown25843ad2018-09-17 14:54:33 -070013412 goto pld_deinit;
Sachin Ahuja16904db2017-12-13 19:56:57 +053013413 }
13414
Dustin Browna2a39dc2018-09-17 15:29:59 -070013415 hdd_debug("%s: driver loaded", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013416
13417 return 0;
Dustin Brownd585cb32018-09-12 17:12:23 -070013418
Dustin Brown25843ad2018-09-17 14:54:33 -070013419pld_deinit:
Dustin Brown21a1d462018-07-31 15:13:06 -070013420 status = dsc_driver_trans_start(hdd_driver->dsc_driver, "unload");
13421 QDF_BUG(QDF_IS_STATUS_SUCCESS(status));
13422
Dustin Brown25843ad2018-09-17 14:54:33 -070013423 pld_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013424
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013425param_destroy:
13426 wlan_hdd_state_ctrl_param_destroy();
Dustin Brownf0f70562018-09-14 10:29:38 -070013427wakelock_destroy:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053013428 qdf_wake_lock_destroy(&wlan_wake_lock);
Dustin Brownf0f70562018-09-14 10:29:38 -070013429comp_deinit:
Dustin Brownd585cb32018-09-12 17:12:23 -070013430 hdd_component_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013431hdd_deinit:
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013432 hdd_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013433trans_stop:
13434 hdd_driver->state = driver_state_deinit;
13435 dsc_driver_trans_stop(hdd_driver->dsc_driver);
13436hdd_driver_deinit:
13437 hdd_driver_ctx_deinit(hdd_driver);
Dustin Browna2a39dc2018-09-17 15:29:59 -070013438qdf_deinit:
13439 hdd_qdf_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013440
Dustin Brown25843ad2018-09-17 14:54:33 -070013441exit:
Dustin Brownf0f70562018-09-14 10:29:38 -070013442 return errno;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013443}
13444
13445/**
Dustin Brownf0f70562018-09-14 10:29:38 -070013446 * hdd_driver_unload() - Performs the driver-level unload operation
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013447 *
Dustin Brownf0f70562018-09-14 10:29:38 -070013448 * Note: this is used in both static and DLKM driver builds
13449 *
13450 * Return: None
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013451 */
Dustin Brownf0f70562018-09-14 10:29:38 -070013452static void hdd_driver_unload(void)
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013453{
Dustin Brown21a1d462018-07-31 15:13:06 -070013454 struct hdd_driver *hdd_driver = hdd_driver_get();
Will Huang36049722018-04-13 11:48:51 +080013455 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Dustin Brown21a1d462018-07-31 15:13:06 -070013456 QDF_STATUS status;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053013457
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013458 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
13459 QWLAN_VERSIONSTR);
13460
Dustin Brown21a1d462018-07-31 15:13:06 -070013461 status = dsc_driver_trans_start_wait(hdd_driver->dsc_driver, "unload");
13462 QDF_BUG(QDF_IS_STATUS_SUCCESS(status));
13463 if (QDF_IS_STATUS_ERROR(status)) {
13464 hdd_err("Unable to unload wlan; status:%u", status);
Arunk Khandavalli830c9692018-03-22 12:17:40 +053013465 return;
Dustin Brown21a1d462018-07-31 15:13:06 -070013466 }
13467
13468 dsc_driver_wait_for_ops(hdd_driver->dsc_driver);
13469
13470 if (!hdd_wait_for_recovery_completion()) {
13471 dsc_driver_trans_stop(hdd_driver->dsc_driver);
13472 return;
13473 }
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053013474
Will Huangba035ec2018-07-05 11:13:30 +080013475 cds_set_driver_loaded(false);
13476 cds_set_unload_in_progress(true);
13477
13478 if (!cds_wait_for_external_threads_completion(__func__))
13479 hdd_warn("External threads are still active attempting "
13480 "driver unload anyway");
13481
Rajeev Kumar3505ae52018-05-10 18:44:45 -070013482 if (hdd_ctx)
Dustin Brown4c663222018-10-23 14:19:36 -070013483 hdd_psoc_idle_timer_stop(hdd_ctx);
Will Huang36049722018-04-13 11:48:51 +080013484
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013485 wlan_hdd_unregister_driver();
Dustin Brown25843ad2018-09-17 14:54:33 -070013486 pld_deinit();
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013487 wlan_hdd_state_ctrl_param_destroy();
Dustin Brownf0f70562018-09-14 10:29:38 -070013488 hdd_set_conparam(0);
Anurag Chouhana37b5b72016-02-21 14:53:42 +053013489 qdf_wake_lock_destroy(&wlan_wake_lock);
Dustin Brownd585cb32018-09-12 17:12:23 -070013490 hdd_component_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013491 hdd_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013492
13493 hdd_driver->state = driver_state_deinit;
13494 dsc_driver_trans_stop(hdd_driver->dsc_driver);
Dustin Brown623e7e32018-09-05 14:27:50 -070013495
Dustin Brown21a1d462018-07-31 15:13:06 -070013496 hdd_driver_ctx_deinit(hdd_driver);
13497
Dustin Browna2a39dc2018-09-17 15:29:59 -070013498 hdd_qdf_deinit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013499}
13500
Arun Khandavallifae92942016-08-01 13:31:08 +053013501#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013502/**
Arun Khandavallifae92942016-08-01 13:31:08 +053013503 * wlan_boot_cb() - Wlan boot callback
13504 * @kobj: object whose directory we're creating the link in.
13505 * @attr: attribute the user is interacting with
13506 * @buff: the buffer containing the user data
13507 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013508 *
Arun Khandavallifae92942016-08-01 13:31:08 +053013509 * This callback is invoked when the fs is ready to start the
13510 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013511 *
Arun Khandavallifae92942016-08-01 13:31:08 +053013512 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013513 */
Arun Khandavallifae92942016-08-01 13:31:08 +053013514static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013515 struct kobj_attribute *attr,
13516 const char *buf,
13517 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013518{
Arun Khandavallifae92942016-08-01 13:31:08 +053013519
Arun Khandavallifae92942016-08-01 13:31:08 +053013520 if (wlan_loader->loaded_state) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013521 hdd_err("wlan driver already initialized");
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013522 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053013523 }
13524
Dustin Brownf0f70562018-09-14 10:29:38 -070013525 if (hdd_driver_load())
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013526 return -EIO;
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013527
13528 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053013529
13530 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013531}
Arun Khandavallifae92942016-08-01 13:31:08 +053013532
13533/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013534 * hdd_sysfs_cleanup() - cleanup sysfs
13535 *
13536 * Return: None
13537 *
13538 */
13539static void hdd_sysfs_cleanup(void)
13540{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013541 /* remove from group */
13542 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
13543 sysfs_remove_group(wlan_loader->boot_wlan_obj,
13544 wlan_loader->attr_group);
13545
13546 /* unlink the object from parent */
13547 kobject_del(wlan_loader->boot_wlan_obj);
13548
13549 /* free the object */
13550 kobject_put(wlan_loader->boot_wlan_obj);
13551
13552 kfree(wlan_loader->attr_group);
13553 kfree(wlan_loader);
13554
13555 wlan_loader = NULL;
13556}
13557
13558/**
Arun Khandavallifae92942016-08-01 13:31:08 +053013559 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
13560 * ready
13561 *
13562 * This is creates the syfs entry boot_wlan. Which shall be invoked
13563 * when the filesystem is ready.
13564 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013565 * QDF API cannot be used here since this function is called even before
13566 * initializing WLAN driver.
13567 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070013568 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053013569 */
13570static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013571{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013572 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053013573
13574 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013575 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013576 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053013577
13578 wlan_loader->boot_wlan_obj = NULL;
13579 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
13580 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013581 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053013582 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053013583
13584 wlan_loader->loaded_state = 0;
13585 wlan_loader->attr_group->attrs = attrs;
13586
Qun Zhang4a83a462018-09-11 16:28:51 +080013587 wlan_loader->boot_wlan_obj = kobject_create_and_add(WLAN_LOADER_NAME,
Arun Khandavallifae92942016-08-01 13:31:08 +053013588 kernel_kobj);
13589 if (!wlan_loader->boot_wlan_obj) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013590 hdd_err("sysfs create and add failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053013591 goto error_return;
13592 }
13593
13594 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
13595 wlan_loader->attr_group);
13596 if (ret) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013597 hdd_err("sysfs create group failed; errno:%d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053013598 goto error_return;
13599 }
13600
13601 return 0;
13602
13603error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013604 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053013605
13606 return ret;
13607}
13608
13609/**
13610 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
13611 *
13612 * Return: 0 on success or errno on failure
13613 */
13614static int wlan_deinit_sysfs(void)
13615{
Arun Khandavallifae92942016-08-01 13:31:08 +053013616 if (!wlan_loader) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013617 hdd_err("wlan_loader is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053013618 return -EINVAL;
13619 }
13620
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013621 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013622 return 0;
13623}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013624
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013625#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053013626
13627#ifdef MODULE
13628/**
Dustin Brownf0f70562018-09-14 10:29:38 -070013629 * hdd_module_init() - Module init helper
Arun Khandavallifae92942016-08-01 13:31:08 +053013630 *
13631 * Module init helper function used by both module and static driver.
13632 *
13633 * Return: 0 for success, errno on failure
13634 */
13635static int hdd_module_init(void)
13636{
Dustin Brownf0f70562018-09-14 10:29:38 -070013637 if (hdd_driver_load())
Dustin Brownab482ac2017-06-09 17:00:44 -070013638 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053013639
Dustin Brownab482ac2017-06-09 17:00:44 -070013640 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053013641}
13642#else
13643static int __init hdd_module_init(void)
13644{
13645 int ret = -EINVAL;
13646
13647 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070013648 if (ret)
Dustin Browna2a39dc2018-09-17 15:29:59 -070013649 hdd_err("Failed to create sysfs entry");
Arun Khandavallifae92942016-08-01 13:31:08 +053013650
13651 return ret;
13652}
13653#endif
13654
13655
13656#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013657/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013658 * hdd_module_exit() - Exit function
13659 *
13660 * This is the driver exit point (invoked when module is unloaded using rmmod)
13661 *
13662 * Return: None
13663 */
13664static void __exit hdd_module_exit(void)
13665{
Dustin Brownf0f70562018-09-14 10:29:38 -070013666 hdd_driver_unload();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013667}
Arun Khandavallifae92942016-08-01 13:31:08 +053013668#else
13669static void __exit hdd_module_exit(void)
13670{
Dustin Brownf0f70562018-09-14 10:29:38 -070013671 hdd_driver_unload();
Arun Khandavallifae92942016-08-01 13:31:08 +053013672 wlan_deinit_sysfs();
13673}
13674#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013675
Srinivas Girigowda841da292018-02-21 16:33:00 -080013676static int fwpath_changed_handler(const char *kmessage,
13677 const struct kernel_param *kp)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013678{
13679 return param_set_copystring(kmessage, kp);
13680}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013681
Nirav Shah73713f72018-05-17 14:50:41 +053013682#ifdef FEATURE_MONITOR_MODE_SUPPORT
13683static bool is_monitor_mode_supported(void)
13684{
13685 return true;
13686}
13687#else
13688static bool is_monitor_mode_supported(void)
13689{
13690 pr_err("Monitor mode not supported!");
13691 return false;
13692}
13693#endif
13694
13695#ifdef WLAN_FEATURE_EPPING
13696static bool is_epping_mode_supported(void)
13697{
13698 return true;
13699}
13700#else
13701static bool is_epping_mode_supported(void)
13702{
13703 pr_err("Epping mode not supported!");
13704 return false;
13705}
13706#endif
13707
Ryan Hsu6e9db0b2018-06-01 10:45:51 -070013708#ifdef QCA_WIFI_FTM
13709static bool is_ftm_mode_supported(void)
13710{
13711 return true;
13712}
13713#else
13714static bool is_ftm_mode_supported(void)
13715{
13716 pr_err("FTM mode not supported!");
13717 return false;
13718}
13719#endif
13720
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013721/**
13722 * is_con_mode_valid() check con mode is valid or not
13723 * @mode: global con mode
13724 *
13725 * Return: TRUE on success FALSE on failure
13726 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080013727static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013728{
13729 switch (mode) {
13730 case QDF_GLOBAL_MONITOR_MODE:
Nirav Shah73713f72018-05-17 14:50:41 +053013731 return is_monitor_mode_supported();
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013732 case QDF_GLOBAL_EPPING_MODE:
Nirav Shah73713f72018-05-17 14:50:41 +053013733 return is_epping_mode_supported();
13734 case QDF_GLOBAL_FTM_MODE:
Ryan Hsu6e9db0b2018-06-01 10:45:51 -070013735 return is_ftm_mode_supported();
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013736 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013737 return true;
13738 default:
13739 return false;
13740 }
13741}
13742
Dustin Brown27cd9942017-09-27 16:11:44 -070013743static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080013744 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070013745{
13746 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
13747 return;
13748
13749 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070013750 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053013751 hdd_info("Release wakelock for monitor mode!");
13752 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
13753 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
Dundi Raviteja0a2a65b2018-04-30 12:34:11 +053013754 /* fallthrough */
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053013755 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070013756 case QDF_GLOBAL_FTM_MODE:
13757 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brown07901ec2018-09-07 11:02:41 -070013758 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, NULL);
Dustin Browndb2a8be2017-12-20 11:49:56 -080013759 hdd_stop_all_adapters(hdd_ctx);
Ashish Kumar Dhanotiya6ff329e2018-10-05 20:38:10 +053013760 hdd_deinit_all_adapters(hdd_ctx, false);
Dustin Brown27cd9942017-09-27 16:11:44 -070013761
Dustin Brown27cd9942017-09-27 16:11:44 -070013762 break;
13763 default:
13764 break;
13765 }
13766}
13767
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013768static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080013769 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013770{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053013771 int driver_status;
13772
13773 driver_status = hdd_ctx->driver_status;
13774
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013775 switch (curr_mode) {
13776 case QDF_GLOBAL_MISSION_MODE:
13777 case QDF_GLOBAL_MONITOR_MODE:
13778 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013779 hdd_close_all_adapters(hdd_ctx, false);
13780 break;
13781 case QDF_GLOBAL_EPPING_MODE:
13782 epping_disable();
13783 epping_close();
13784 break;
13785 default:
13786 return;
13787 }
13788}
13789
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013790static int
13791hdd_parse_driver_mode(const char *mode_str, enum QDF_GLOBAL_MODE *out_mode)
13792{
13793 int mode;
13794 int errno;
13795
Dustin Brown62743f42018-10-24 14:53:18 -070013796 *out_mode = QDF_GLOBAL_MAX_MODE;
13797
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013798 errno = kstrtoint(mode_str, 0, &mode);
13799 if (!errno)
13800 *out_mode = (enum QDF_GLOBAL_MODE)mode;
13801
13802 return errno;
13803}
13804
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013805/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013806 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013807 * @kmessage: con mode name on which driver to be bring up
13808 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013809 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013810 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013811 * This function is invoked when user updates con mode using sys entry,
13812 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013813 *
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013814 * Return: Errno
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013815 */
Srinivas Girigowda841da292018-02-21 16:33:00 -080013816static int __con_mode_handler(const char *kmessage,
13817 const struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013818 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013819{
Jeff Johnson876c1a62017-12-12 10:43:07 -080013820 enum QDF_GLOBAL_MODE curr_mode;
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013821 enum QDF_GLOBAL_MODE next_mode;
13822 int errno;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013823
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013824 hdd_info("Driver mode changing to %s", kmessage);
Dustin Brownab6029b2017-05-24 13:04:19 -070013825
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013826 errno = wlan_hdd_validate_context(hdd_ctx);
13827 if (errno)
13828 return errno;
13829
13830 errno = hdd_parse_driver_mode(kmessage, &next_mode);
13831 if (errno) {
13832 hdd_err_rl("Failed to parse driver mode '%s'", kmessage);
13833 return errno;
13834 }
13835
13836 if (!is_con_mode_valid(next_mode)) {
13837 hdd_err_rl("Requested driver mode is invalid");
13838 return -EINVAL;
13839 }
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013840
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013841 qdf_atomic_set(&hdd_ctx->con_mode_flag, 1);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013842 mutex_lock(&hdd_init_deinit_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +053013843
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013844 curr_mode = hdd_get_conparam();
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013845 if (curr_mode == next_mode) {
13846 hdd_err_rl("Driver is already in the requested mode");
13847 errno = 0;
13848 goto unlock;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013849 }
13850
Dustin Brown27cd9942017-09-27 16:11:44 -070013851 /* ensure adapters are stopped */
13852 hdd_stop_present_mode(hdd_ctx, curr_mode);
13853
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013854 errno = hdd_wlan_stop_modules(hdd_ctx, true);
13855 if (errno) {
Arun Khandavallifae92942016-08-01 13:31:08 +053013856 hdd_err("Stop wlan modules failed");
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013857 goto unlock;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013858 }
13859
Dustin Browndd4e50f2018-05-24 15:43:42 -070013860 /* Cleanup present mode before switching to new mode */
13861 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053013862
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013863 hdd_set_conparam(next_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013864
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013865 errno = hdd_wlan_start_modules(hdd_ctx, false);
13866 if (errno) {
13867 hdd_err("Start wlan modules failed: %d", errno);
13868 goto unlock;
Arun Khandavallifae92942016-08-01 13:31:08 +053013869 }
13870
jitiphil7af5cf22018-10-26 16:06:27 +053013871 errno = hdd_open_adapters_for_mode(hdd_ctx, next_mode);
13872 if (errno) {
13873 hdd_err("Failed to open adapters");
13874 goto unlock;
13875 }
13876
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013877 if (next_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Browne7e71d32018-05-11 16:00:08 -070013878 struct hdd_adapter *adapter =
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013879 hdd_get_adapter(hdd_ctx, QDF_MONITOR_MODE);
Dustin Browne7e71d32018-05-11 16:00:08 -070013880
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013881 QDF_BUG(adapter);
Dustin Browne7e71d32018-05-11 16:00:08 -070013882 if (!adapter) {
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013883 hdd_err("Failed to get monitor adapter");
13884 goto unlock;
Dustin Browne7e71d32018-05-11 16:00:08 -070013885 }
13886
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013887 errno = hdd_start_adapter(adapter);
13888 if (errno) {
13889 hdd_err("Failed to start monitor adapter");
13890 goto unlock;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013891 }
Arun Khandavallifae92942016-08-01 13:31:08 +053013892
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013893 hdd_info("Acquire wakelock for monitor mode");
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053013894 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
13895 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
13896 }
13897
Dustin Brown20024e32018-01-03 12:34:58 -080013898 /* con_mode is a global module parameter */
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013899 con_mode = next_mode;
13900 hdd_info("Driver mode successfully changed to %s", kmessage);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013901
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013902 errno = 0;
13903
13904unlock:
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013905 mutex_unlock(&hdd_init_deinit_lock);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013906 qdf_atomic_set(&hdd_ctx->con_mode_flag, 0);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013907
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013908 return errno;
13909}
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013910
Srinivas Girigowda841da292018-02-21 16:33:00 -080013911static int con_mode_handler(const char *kmessage, const struct kernel_param *kp)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013912{
Dustin Brown67d30412018-09-20 12:10:22 -070013913 struct hdd_driver *hdd_driver = hdd_driver_get();
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013914 struct hdd_context *hdd_ctx;
Dustin Brown67d30412018-09-20 12:10:22 -070013915 QDF_STATUS status;
13916 int errno;
13917
13918 hdd_enter();
13919
Dustin Brown13fa9872018-11-13 10:57:45 -080013920 /* This handler will be invoked before module init when the wlan driver
13921 * is loaded using 'insmod wlan.ko con_mode=5' for example. Return
13922 * success in this case, as module init will bring up the correct
13923 * con_mode when it runs.
13924 */
13925 if (hdd_driver->state == driver_state_uninit)
13926 return 0;
13927
Rajeev Kumaracb73d02018-12-18 14:07:40 -080013928 if (hdd_driver->state == driver_state_deinit) {
13929 hdd_err_rl("driver is unloaded so load again");
13930 return -EAGAIN;
13931 }
13932
Dustin Brown67d30412018-09-20 12:10:22 -070013933 status = dsc_driver_trans_start_wait(hdd_driver->dsc_driver,
13934 "mode change");
13935 if (QDF_IS_STATUS_ERROR(status)) {
13936 hdd_err("Failed to start 'mode change'; status:%u", status);
13937 errno = qdf_status_to_os_return(status);
13938 goto exit;
13939 }
13940
13941 dsc_driver_wait_for_ops(hdd_driver->dsc_driver);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013942
13943 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Dustin Brown67d30412018-09-20 12:10:22 -070013944 errno = wlan_hdd_validate_context(hdd_ctx);
13945 if (errno)
13946 goto trans_stop;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013947
Ashish Kumar Dhanotiya759b3272018-05-18 17:49:46 +053013948 if (!cds_wait_for_external_threads_completion(__func__)) {
13949 hdd_warn("External threads are still active, can not change mode");
Dustin Brown67d30412018-09-20 12:10:22 -070013950 errno = -EAGAIN;
13951 goto trans_stop;
Ashish Kumar Dhanotiya759b3272018-05-18 17:49:46 +053013952 }
13953
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013954 cds_ssr_protect(__func__);
Dustin Brown67d30412018-09-20 12:10:22 -070013955 errno = __con_mode_handler(kmessage, kp, hdd_ctx);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013956 cds_ssr_unprotect(__func__);
13957
Dustin Brown67d30412018-09-20 12:10:22 -070013958trans_stop:
13959 dsc_driver_trans_stop(hdd_driver->dsc_driver);
13960
13961exit:
13962 hdd_exit();
13963
13964 return errno;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013965}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013966
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013967static int con_mode_handler_ftm(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080013968 const struct kernel_param *kp)
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013969{
13970 int ret;
13971
13972 ret = param_set_int(kmessage, kp);
13973
13974 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
13975 pr_err("Only FTM mode supported!");
13976 return -ENOTSUPP;
13977 }
13978
13979 hdd_set_conparam(con_mode_ftm);
13980 con_mode = con_mode_ftm;
13981
13982 return ret;
13983}
13984
Nirav Shah73713f72018-05-17 14:50:41 +053013985#ifdef FEATURE_MONITOR_MODE_SUPPORT
Ravi Joshia307f632017-07-17 23:41:41 -070013986static int con_mode_handler_monitor(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080013987 const struct kernel_param *kp)
Ravi Joshia307f632017-07-17 23:41:41 -070013988{
13989 int ret;
13990
13991 ret = param_set_int(kmessage, kp);
13992
13993 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
13994 pr_err("Only Monitor mode supported!");
13995 return -ENOTSUPP;
13996 }
13997
13998 hdd_set_conparam(con_mode_monitor);
13999 con_mode = con_mode_monitor;
14000
14001 return ret;
14002}
Nirav Shah73713f72018-05-17 14:50:41 +053014003#endif
Ravi Joshia307f632017-07-17 23:41:41 -070014004
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014005/**
14006 * hdd_get_conparam() - driver exit point
14007 *
14008 * This is the driver exit point (invoked when module is unloaded using rmmod)
14009 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080014010 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014011 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080014012enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014013{
Jeff Johnson876c1a62017-12-12 10:43:07 -080014014 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014015}
14016
Dustin Brownf0f70562018-09-14 10:29:38 -070014017void hdd_set_conparam(int32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014018{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080014019 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014020}
14021
Komal Seelamc11bb222016-01-27 18:57:10 +053014022/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014023 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
14024 * @hdd_ctx: HDD context
14025 *
14026 * Cleans up the pre cac interface, if it exists
14027 *
14028 * Return: None
14029 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014030void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014031{
14032 uint8_t session_id;
14033 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070014034 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014035
Jeff Johnson16528362018-06-14 12:34:16 -070014036 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->mac_handle, &session_id);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014037 if (QDF_IS_STATUS_ERROR(status)) {
14038 hdd_err("failed to get pre cac vdev id");
14039 return;
14040 }
14041
14042 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
14043 if (!precac_adapter) {
Jeff Johnsondd2f1fc2018-05-06 11:22:52 -070014044 hdd_err("invalid pre cac adapter");
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014045 return;
14046 }
14047
14048 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
14049 wlan_hdd_sap_pre_cac_failure,
14050 (void *)precac_adapter);
14051 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
14052
14053}
14054
14055/**
Komal Seelamec702b02016-02-24 18:42:16 +053014056 * hdd_update_ol_config - API to update ol configuration parameters
14057 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053014058 *
Komal Seelamc11bb222016-01-27 18:57:10 +053014059 * Return: void
14060 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014061static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053014062{
Abhishek Singh98278ce2018-12-27 11:41:03 +053014063 struct ol_config_info cfg = {0};
Anurag Chouhandf2b2682016-02-29 14:15:27 +053014064 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014065 bool self_recovery = false;
14066 QDF_STATUS status;
Komal Seelamc11bb222016-01-27 18:57:10 +053014067
Komal Seelamec702b02016-02-24 18:42:16 +053014068 if (!ol_ctx)
14069 return;
14070
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014071 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
14072 if (QDF_IS_STATUS_ERROR(status))
14073 hdd_err("Failed to get self recovery ini config");
14074
14075 cfg.enable_self_recovery = self_recovery;
Komal Seelamec702b02016-02-24 18:42:16 +053014076 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
14077 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
14078 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070014079 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053014080
14081 ol_init_ini_config(ol_ctx, &cfg);
14082}
14083
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014084#ifdef FEATURE_RUNTIME_PM
14085/**
14086 * hdd_populate_runtime_cfg() - populate runtime configuration
14087 * @hdd_ctx: hdd context
14088 * @cfg: pointer to the configuration memory being populated
14089 *
14090 * Return: void
14091 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014092static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014093 struct hif_config_info *cfg)
14094{
14095 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
Wu Gao66454f12018-09-26 19:55:41 +080014096 cfg->runtime_pm_delay =
14097 ucfg_pmo_get_runtime_pm_delay(hdd_ctx->psoc);
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014098}
14099#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014100static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014101 struct hif_config_info *cfg)
14102{
14103}
14104#endif
14105
Komal Seelamec702b02016-02-24 18:42:16 +053014106/**
14107 * hdd_update_hif_config - API to update HIF configuration parameters
14108 * @hdd_ctx: HDD Context
14109 *
14110 * Return: void
14111 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014112static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053014113{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053014114 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Abhishek Singh98278ce2018-12-27 11:41:03 +053014115 struct hif_config_info cfg = {0};
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014116 bool prevent_link_down = false;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014117 bool self_recovery = false;
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014118 QDF_STATUS status;
Komal Seelamec702b02016-02-24 18:42:16 +053014119
14120 if (!scn)
14121 return;
14122
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014123 status = ucfg_mlme_get_prevent_link_down(hdd_ctx->psoc,
14124 &prevent_link_down);
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014125 if (QDF_IS_STATUS_ERROR(status))
14126 hdd_err("Failed to get prevent_link_down config");
14127
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014128 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
14129 if (QDF_IS_STATUS_ERROR(status))
14130 hdd_err("Failed to get self recovery ini config");
14131
14132 cfg.enable_self_recovery = self_recovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014133 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053014134 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070014135
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014136 if (prevent_link_down)
Dustin Brownee3e0592017-09-07 13:50:11 -070014137 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053014138}
14139
14140/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014141 * hdd_update_dp_config() - Propagate config parameters to Lithium
14142 * datapath
14143 * @hdd_ctx: HDD Context
14144 *
14145 * Return: 0 for success/errno for failure
14146 */
14147static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
14148{
Abhishek Singh98278ce2018-12-27 11:41:03 +053014149 struct cdp_config_params params = {0};
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014150 QDF_STATUS status;
jitiphil377bcc12018-10-05 19:46:08 +053014151 void *soc;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014152
jitiphil377bcc12018-10-05 19:46:08 +053014153 soc = cds_get_context(QDF_MODULE_ID_SOC);
14154 params.tso_enable = cfg_get(hdd_ctx->psoc, CFG_DP_TSO);
14155 params.lro_enable = cfg_get(hdd_ctx->psoc, CFG_DP_LRO);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014156#ifdef QCA_LL_TX_FLOW_CONTROL_V2
14157 params.tx_flow_stop_queue_threshold =
jitiphil47c3d9a2018-11-08 18:30:55 +053014158 cfg_get(hdd_ctx->psoc, CFG_DP_TX_FLOW_STOP_QUEUE_TH);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014159 params.tx_flow_start_queue_offset =
jitiphil47c3d9a2018-11-08 18:30:55 +053014160 cfg_get(hdd_ctx->psoc,
14161 CFG_DP_TX_FLOW_START_QUEUE_OFFSET);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014162#endif
jitiphil377bcc12018-10-05 19:46:08 +053014163 params.flow_steering_enable =
14164 cfg_get(hdd_ctx->psoc, CFG_DP_FLOW_STEERING_ENABLED);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014165 params.napi_enable = hdd_ctx->napi_enable;
14166 params.tcp_udp_checksumoffload =
jitiphil377bcc12018-10-05 19:46:08 +053014167 cfg_get(hdd_ctx->psoc,
14168 CFG_DP_TCP_UDP_CKSUM_OFFLOAD);
Sravan Kumar Kairam0af1ee52018-12-12 20:37:51 +053014169 params.ipa_enable = ucfg_ipa_is_enabled();
Mohit Khanna81418772018-10-30 14:14:46 -070014170 params.gro_enable = cfg_get(hdd_ctx->psoc, CFG_DP_GRO);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014171
jitiphil377bcc12018-10-05 19:46:08 +053014172 status = cdp_update_config_parameters(soc, &params);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014173 if (status) {
Dustin Browna2868622018-03-20 11:38:14 -070014174 hdd_err("Failed to attach config parameters");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014175 return status;
14176 }
14177
14178 return 0;
14179}
14180
14181/**
Komal Seelamec702b02016-02-24 18:42:16 +053014182 * hdd_update_config() - Initialize driver per module ini parameters
14183 * @hdd_ctx: HDD Context
14184 *
14185 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053014186 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053014187 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014188int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053014189{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053014190 int ret;
14191
Wu Gao66454f12018-09-26 19:55:41 +080014192 if (ucfg_pmo_is_ns_offloaded(hdd_ctx->psoc))
14193 hdd_ctx->ns_offload_enable = true;
14194
Komal Seelamec702b02016-02-24 18:42:16 +053014195 hdd_update_ol_config(hdd_ctx);
14196 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053014197 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
14198 ret = hdd_update_cds_config_ftm(hdd_ctx);
14199 else
14200 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080014201 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053014202
14203 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053014204}
14205
Mukul Sharma9d797a02017-01-05 20:26:03 +053014206#ifdef FEATURE_WLAN_RA_FILTERING
14207/**
14208 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
14209 * @psoc_cfg: pmo psoc Configuration
14210 * @hdd_ctx: Pointer to hdd context
14211 *
14212 * Return: none
14213 */
14214static inline void hdd_ra_populate_pmo_config(
14215 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014216 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053014217{
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053014218 bool is_rate_limit_enabled;
14219 QDF_STATUS status;
14220
14221 status = ucfg_fwol_get_is_rate_limit_enabled(hdd_ctx->psoc,
14222 &is_rate_limit_enabled);
14223 if (QDF_IS_STATUS_ERROR(status))
14224 return;
14225
Mukul Sharma9d797a02017-01-05 20:26:03 +053014226 psoc_cfg->ra_ratelimit_interval =
14227 hdd_ctx->config->RArateLimitInterval;
14228 psoc_cfg->ra_ratelimit_enable =
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053014229 is_rate_limit_enabled;
Mukul Sharma9d797a02017-01-05 20:26:03 +053014230}
14231#else
14232static inline void hdd_ra_populate_pmo_config(
14233 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014234 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053014235{
14236}
14237#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080014238
Mukul Sharma9d797a02017-01-05 20:26:03 +053014239/**
14240 * hdd_update_pmo_config - API to update pmo configuration parameters
14241 * @hdd_ctx: HDD context
14242 *
14243 * Return: void
14244 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014245static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053014246{
Abhishek Singh98278ce2018-12-27 11:41:03 +053014247 struct pmo_psoc_cfg psoc_cfg = {0};
Mukul Sharma9d797a02017-01-05 20:26:03 +053014248 QDF_STATUS status;
Wu Gao66454f12018-09-26 19:55:41 +080014249 enum pmo_wow_enable_type wow_enable;
14250
14251 ucfg_pmo_get_psoc_config(hdd_ctx->psoc, &psoc_cfg);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014252
14253 /*
14254 * Value of hdd_ctx->wowEnable can be,
14255 * 0 - Disable both magic pattern match and pattern byte match.
14256 * 1 - Enable magic pattern match on all interfaces.
14257 * 2 - Enable pattern byte match on all interfaces.
14258 * 3 - Enable both magic patter and pattern byte match on
14259 * all interfaces.
14260 */
Wu Gao66454f12018-09-26 19:55:41 +080014261 wow_enable = ucfg_pmo_get_wow_enable(hdd_ctx->psoc);
14262 psoc_cfg.magic_ptrn_enable = (wow_enable & 0x01) ? true : false;
Mukul Sharma9d797a02017-01-05 20:26:03 +053014263 psoc_cfg.ptrn_match_enable_all_vdev =
Wu Gao66454f12018-09-26 19:55:41 +080014264 (wow_enable & 0x02) ? true : false;
Dustin Brownb9987af2018-03-01 17:15:11 -080014265 psoc_cfg.packet_filter_enabled = !hdd_ctx->config->disablePacketFilter;
Mukul Sharma9d797a02017-01-05 20:26:03 +053014266 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080014267 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Bala Venkatesh46e29032018-11-14 18:24:55 +053014268 ucfg_mlme_get_sap_max_modulated_dtim(hdd_ctx->psoc,
14269 &psoc_cfg.sta_max_li_mod_dtim);
14270
Mukul Sharma9d797a02017-01-05 20:26:03 +053014271
14272 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053014273 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014274
Dustin Brown1dbefe62018-09-11 16:32:03 -070014275 status = ucfg_pmo_update_psoc_config(hdd_ctx->psoc, &psoc_cfg);
Dustin Brownb9987af2018-03-01 17:15:11 -080014276 if (QDF_IS_STATUS_ERROR(status))
14277 hdd_err("failed pmo psoc configuration; status:%d", status);
14278
14279 return qdf_status_to_os_return(status);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014280}
14281
Abhishek Singhb20db962017-03-03 21:28:46 +053014282#ifdef FEATURE_WLAN_SCAN_PNO
14283static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Wu Gao1ab05582018-11-08 16:22:49 +080014284 struct hdd_context *hdd_ctx)
Abhishek Singhb20db962017-03-03 21:28:46 +053014285{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070014286 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
Wu Gao1ab05582018-11-08 16:22:49 +080014287 struct hdd_config *cfg = hdd_ctx->config;
14288 bool mawc_enabled;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070014289
Abhishek Singhb20db962017-03-03 21:28:46 +053014290 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
14291 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
14292 pno_cfg->stationary_thresh = cfg->stationary_thresh;
Abhishek Singhcfc4e232018-12-20 11:04:57 +053014293 pno_cfg->adaptive_dwell_mode = cfg->pnoscan_adaptive_dwell_mode;
Abhishek Singhb20db962017-03-03 21:28:46 +053014294 pno_cfg->channel_prediction_full_scan =
14295 cfg->channel_prediction_full_scan;
Wu Gao1ab05582018-11-08 16:22:49 +080014296
14297 ucfg_mlme_is_mawc_enabled(hdd_ctx->psoc, &mawc_enabled);
14298 mawc_cfg->enable = mawc_enabled && cfg->mawc_nlo_enabled;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070014299 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
14300 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
14301 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053014302}
14303#else
14304static inline void
14305hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Wu Gao1ab05582018-11-08 16:22:49 +080014306 struct hdd_context *hdd_ctx)
Abhishek Singhb20db962017-03-03 21:28:46 +053014307{
Abhishek Singhb20db962017-03-03 21:28:46 +053014308}
14309#endif
14310
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014311void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014312 struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014313{
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014314 struct wlan_fwol_ie_whitelist whitelist = {0};
14315 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014316 QDF_STATUS status;
14317 bool is_ie_whitelist_enable = false;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014318 uint8_t i = 0;
14319
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014320 status = ucfg_fwol_get_ie_whitelist(psoc, &is_ie_whitelist_enable);
14321 if (QDF_IS_STATUS_ERROR(status)) {
14322 hdd_err("Unable to get IE whitelist param");
14323 return;
14324 }
14325
14326 ie_whitelist->white_list = is_ie_whitelist_enable;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014327 if (!ie_whitelist->white_list)
14328 return;
14329
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014330 status = ucfg_fwol_get_all_whitelist_params(psoc, &whitelist);
14331 if (QDF_IS_STATUS_ERROR(status)) {
14332 hdd_err("Unable to get all whitelist params");
14333 return;
14334 }
14335
14336 ie_whitelist->ie_bitmap[0] = whitelist.ie_bitmap_0;
14337 ie_whitelist->ie_bitmap[1] = whitelist.ie_bitmap_1;
14338 ie_whitelist->ie_bitmap[2] = whitelist.ie_bitmap_2;
14339 ie_whitelist->ie_bitmap[3] = whitelist.ie_bitmap_3;
14340 ie_whitelist->ie_bitmap[4] = whitelist.ie_bitmap_4;
14341 ie_whitelist->ie_bitmap[5] = whitelist.ie_bitmap_5;
14342 ie_whitelist->ie_bitmap[6] = whitelist.ie_bitmap_6;
14343 ie_whitelist->ie_bitmap[7] = whitelist.ie_bitmap_7;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014344
Dundi Raviteja9ab4e7b2018-09-28 14:18:28 +053014345 ie_whitelist->num_vendor_oui = whitelist.no_of_probe_req_ouis;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014346 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
Dundi Raviteja9ab4e7b2018-09-28 14:18:28 +053014347 ie_whitelist->voui[i] = whitelist.probe_req_voui[i];
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014348}
14349
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014350uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
14351{
14352 uint8_t i, score;
14353
14354 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
14355 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
14356 if (score > MAX_INDEX_SCORE)
14357 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
14358 MAX_INDEX_SCORE, i);
14359 }
14360
14361 return per_index_score;
14362}
14363
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014364QDF_STATUS hdd_update_score_config(
14365 struct scoring_config *score_config, struct hdd_context *hdd_ctx)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014366{
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014367 struct hdd_config *cfg = hdd_ctx->config;
gaurank kathpaliaae52c982018-10-04 01:35:18 +053014368 QDF_STATUS status;
gaurank kathpalia651abcd2018-11-12 22:41:23 +053014369 struct wlan_mlme_nss_chains vdev_ini_cfg;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014370 bool bval = false;
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014371
Abhishek Singh98278ce2018-12-27 11:41:03 +053014372 qdf_mem_zero(&vdev_ini_cfg, sizeof(struct wlan_mlme_nss_chains));
gaurank kathpalia651abcd2018-11-12 22:41:23 +053014373 /* Populate the nss chain params from ini for this vdev type */
14374 sme_populate_nss_chain_params(hdd_ctx->mac_handle, &vdev_ini_cfg,
14375 QDF_STA_MODE,
14376 hdd_ctx->num_rf_chains);
14377
14378 score_config->vdev_nss_24g = vdev_ini_cfg.rx_nss[NSS_CHAINS_BAND_2GHZ];
14379 score_config->vdev_nss_24g = vdev_ini_cfg.rx_nss[NSS_CHAINS_BAND_5GHZ];
14380
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014381 sme_update_score_config(hdd_ctx->mac_handle, score_config);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014382
14383 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
14384 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
gaurank kathpaliaae52c982018-10-04 01:35:18 +053014385
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014386 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
14387 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
14388 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
14389 score_config->he_cap = 1;
14390
14391 if (score_config->he_cap ||
14392 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
14393 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
14394 score_config->vht_cap = 1;
14395
14396 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
14397 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
14398 score_config->ht_cap = 1;
14399
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014400 status = ucfg_mlme_get_vht_for_24ghz(hdd_ctx->psoc, &bval);
14401 if (!QDF_IS_STATUS_SUCCESS(status))
14402 hdd_err("Failed to get vht_for_24ghz");
14403 if (score_config->vht_cap && bval)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014404 score_config->vht_24G_cap = 1;
14405
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014406 status = ucfg_mlme_get_vht_enable_tx_bf(hdd_ctx->psoc,
14407 &bval);
14408 if (!QDF_IS_STATUS_SUCCESS(status))
14409 hdd_err("unable to get vht_enable_tx_bf");
14410
14411 if (bval)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014412 score_config->beamformee_cap = 1;
14413
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014414 return QDF_STATUS_SUCCESS;
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014415}
14416
Abhishek Singh257a9482017-03-06 16:52:39 +053014417/**
bings81fe50a2017-11-27 14:33:26 +080014418 * hdd_update_dfs_config() - API to update dfs configuration parameters.
14419 * @hdd_ctx: HDD context
14420 *
14421 * Return: 0 if success else err
14422 */
14423static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
14424{
Dustin Brown1dbefe62018-09-11 16:32:03 -070014425 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Abhishek Singh98278ce2018-12-27 11:41:03 +053014426 struct dfs_user_config dfs_cfg = {0};
bings81fe50a2017-11-27 14:33:26 +080014427 QDF_STATUS status;
14428
Arif Hussain224d3812018-11-16 17:58:38 -080014429 ucfg_mlme_get_dfs_filter_offload(hdd_ctx->psoc,
14430 &dfs_cfg.dfs_is_phyerr_filter_offload);
bings81fe50a2017-11-27 14:33:26 +080014431 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
14432 if (QDF_IS_STATUS_ERROR(status)) {
14433 hdd_err("failed dfs psoc configuration");
14434 return -EINVAL;
14435 }
14436
14437 return 0;
14438}
14439
14440/**
Abhishek Singh257a9482017-03-06 16:52:39 +053014441 * hdd_update_scan_config - API to update scan configuration parameters
14442 * @hdd_ctx: HDD context
14443 *
14444 * Return: 0 if success else err
14445 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014446static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053014447{
Dustin Brown1dbefe62018-09-11 16:32:03 -070014448 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Abhishek Singh98278ce2018-12-27 11:41:03 +053014449 struct scan_user_cfg scan_cfg = {0};
Abhishek Singh257a9482017-03-06 16:52:39 +053014450 struct hdd_config *cfg = hdd_ctx->config;
14451 QDF_STATUS status;
Krunal Sonid2c33e12018-12-06 15:02:37 -080014452 uint32_t mcast_mcc_rest_time = 0;
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014453
Abhishek Singh158fe252017-03-23 11:09:34 +053014454 /* convert to ms */
14455 scan_cfg.scan_cache_aging_time =
14456 cfg->scanAgingTimeout * 1000;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053014457 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070014458 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Krunal Sonid2c33e12018-12-06 15:02:37 -080014459 status = ucfg_mlme_get_sta_miracast_mcc_rest_time(hdd_ctx->psoc,
14460 &mcast_mcc_rest_time);
14461 if (!QDF_IS_STATUS_SUCCESS(status)) {
14462 hdd_err("ucfg_mlme_get_sta_miracast_mcc_rest_time, use def");
14463 return -EIO;
14464 }
14465 scan_cfg.sta_miracast_mcc_rest_time = mcast_mcc_rest_time;
Wu Gao1ab05582018-11-08 16:22:49 +080014466 hdd_update_pno_config(&scan_cfg.pno_cfg, hdd_ctx);
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014467 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, hdd_ctx);
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014468
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014469 status = hdd_update_score_config(&scan_cfg.score_config, hdd_ctx);
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014470 if (QDF_IS_STATUS_ERROR(status)) {
14471 hdd_err("Failed to update scoring config");
14472 return -EINVAL;
14473 }
Abhishek Singhb20db962017-03-03 21:28:46 +053014474
Abhishek Singh257a9482017-03-06 16:52:39 +053014475 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
14476 if (status != QDF_STATUS_SUCCESS) {
14477 hdd_err("failed pmo psoc configuration");
14478 return -EINVAL;
14479 }
14480
14481 return 0;
14482}
Abhishek Singh257a9482017-03-06 16:52:39 +053014483
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014484int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053014485{
14486 int ret;
14487
14488 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053014489 if (ret)
14490 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014491
Abhishek Singh257a9482017-03-06 16:52:39 +053014492 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080014493 if (ret)
14494 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014495
Frank Liud4b2fa02017-03-29 11:46:48 +080014496 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014497 if (ret)
14498 return ret;
14499
14500 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080014501 if (ret)
14502 return ret;
14503
14504 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014505
14506 return ret;
14507}
14508
Agrawal Ashish65634612016-08-18 13:24:32 +053014509/**
14510 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
14511 * @mode : cfg80211 DFS mode
14512 *
14513 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
14514 */
14515enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
14516{
14517 switch (mode) {
14518 case DFS_MODE_ENABLE:
14519 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014520 case DFS_MODE_DISABLE:
14521 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014522 case DFS_MODE_DEPRIORITIZE:
14523 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014524 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080014525 hdd_debug("ACS dfs mode is NONE");
14526 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014527 }
14528}
14529
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014530/**
14531 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
14532 * @hddctx: pointer to hdd context
14533 * @set_value: enable/disable
14534 *
14535 * When Host sends vendor command enable, FW will send *ONE* CA ind to
14536 * Host(even though it is duplicate). When Host send vendor command
14537 * disable,FW doesn't perform any action. Whenever any change in
14538 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
14539 *
14540 * return - 0 on success, appropriate error values on failure.
14541 */
Jeff Johnson16528362018-06-14 12:34:16 -070014542int hdd_enable_disable_ca_event(struct hdd_context *hdd_ctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014543{
14544 QDF_STATUS status;
14545
Jeff Johnson16528362018-06-14 12:34:16 -070014546 if (0 != wlan_hdd_validate_context(hdd_ctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014547 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014548
Jeff Johnson16528362018-06-14 12:34:16 -070014549 status = sme_enable_disable_chanavoidind_event(hdd_ctx->mac_handle,
14550 set_value);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014551 if (!QDF_IS_STATUS_SUCCESS(status)) {
14552 hdd_err("Failed to send chan avoid command to SME");
14553 return -EINVAL;
14554 }
14555 return 0;
14556}
Agrawal Ashish65634612016-08-18 13:24:32 +053014557
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014558/**
14559 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
14560 * @value: value to set
14561 *
14562 * This function will set the passed value to roaming in progress flag.
14563 *
14564 * Return: None
14565 */
14566void hdd_set_roaming_in_progress(bool value)
14567{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014568 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014569
14570 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14571 if (!hdd_ctx) {
14572 hdd_err("HDD context is NULL");
14573 return;
14574 }
14575
14576 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080014577 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014578}
14579
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014580bool hdd_is_roaming_in_progress(struct hdd_context *hdd_ctx)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014581{
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014582 if (!hdd_ctx) {
14583 hdd_err("HDD context is NULL");
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014584 return false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014585 }
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080014586
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014587 hdd_debug("roaming_in_progress = %d", hdd_ctx->roaming_in_progress);
14588
14589 return hdd_ctx->roaming_in_progress;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014590}
14591
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014592/**
14593 * hdd_is_connection_in_progress() - check if connection is in
14594 * progress
14595 * @session_id: session id
14596 * @reason: scan reject reason
14597 *
14598 * Go through each adapter and check if Connection is in progress
14599 *
14600 * Return: true if connection is in progress else false
14601 */
14602bool hdd_is_connection_in_progress(uint8_t *session_id,
14603 enum scan_reject_states *reason)
14604{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070014605 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070014606 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014607 uint8_t sta_id = 0;
14608 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014609 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -070014610 mac_handle_t mac_handle;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014611
14612 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14613 if (!hdd_ctx) {
14614 hdd_err("HDD context is NULL");
14615 return false;
14616 }
14617
Jeff Johnson16528362018-06-14 12:34:16 -070014618 mac_handle = hdd_ctx->mac_handle;
14619
Dustin Brown920397d2017-12-13 16:27:50 -080014620 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya929afa42018-06-01 15:04:44 -070014621 hdd_debug("Adapter with device mode %s(%d) exists",
Dustin Brown458027c2018-10-19 12:26:27 -070014622 qdf_opmode_str(adapter->device_mode),
14623 adapter->device_mode);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014624 if (((QDF_STA_MODE == adapter->device_mode)
14625 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
14626 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
14627 && (eConnectionState_Connecting ==
14628 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
14629 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014630 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014631 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070014632 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014633 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070014634 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014635 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014636 }
14637 return true;
14638 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070014639 /*
14640 * sme_neighbor_middle_of_roaming is for LFR2
14641 * hdd_is_roaming_in_progress is for LFR3
14642 */
14643 if (((QDF_STA_MODE == adapter->device_mode) &&
14644 sme_neighbor_middle_of_roaming(
Jeff Johnson16528362018-06-14 12:34:16 -070014645 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -070014646 adapter->session_id)) ||
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014647 hdd_is_roaming_in_progress(hdd_ctx)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014648 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014649 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070014650 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014651 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070014652 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014653 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014654 }
14655 return true;
14656 }
14657 if ((QDF_STA_MODE == adapter->device_mode) ||
14658 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
14659 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
14660 hdd_sta_ctx =
14661 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
14662 if ((eConnectionState_Associated ==
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053014663 hdd_sta_ctx->conn_info.connState)
14664 && sme_is_sta_key_exchange_in_progress(
Jeff Johnson16528362018-06-14 12:34:16 -070014665 mac_handle, adapter->session_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014666 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070014667 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014668 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014669 " is in middle of WPS/EAPOL exchange.",
14670 MAC_ADDR_ARRAY(sta_mac));
14671 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070014672 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014673 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014674 }
14675 return true;
14676 }
14677 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
14678 (QDF_P2P_GO_MODE == adapter->device_mode)) {
14679 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
14680 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014681 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014682 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014683 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014684 continue;
14685
14686 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014687 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070014688 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014689 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014690 " of SAP/GO is in middle of WPS/EAPOL exchange",
14691 MAC_ADDR_ARRAY(sta_mac));
14692 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070014693 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014694 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014695 }
14696 return true;
14697 }
14698 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014699 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014700 return true;
14701 }
14702 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014703 }
Dustin Brown920397d2017-12-13 16:27:50 -080014704
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014705 return false;
14706}
14707
14708/**
14709 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070014710 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014711 *
14712 * Return: None
14713 */
Jeff Johnson9d295242017-08-29 14:39:48 -070014714void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014715{
Jeff Johnson87251032017-08-29 13:31:11 -070014716 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070014717 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014718 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014719 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Jeff Johnsone4c11db2018-05-05 23:22:32 -070014720 tsap_config_t *sap_config;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014721 void *sap_ctx;
14722
14723 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070014724 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070014725 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014726
14727 mutex_lock(&hdd_ctx->sap_lock);
14728 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
14729 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014730 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
14731 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
14732 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
14733 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053014734 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014735 qdf_stop_bss_event,
Vignesh Viswanathan865daaa2018-10-11 19:30:44 +053014736 SME_CMD_START_STOP_BSS_TIMEOUT);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014737
14738 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014739 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014740 goto end;
14741 }
14742 }
14743 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -070014744 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070014745 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070014746 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014747 false);
Jeff Johnson6867ec32017-09-29 20:30:20 -070014748 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014749
14750 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014751 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014752 wlansap_reset_sap_config_add_ie(sap_config,
14753 eUPDATE_IE_ALL);
14754 goto end;
14755 }
14756
14757 qdf_event_reset(&hostapd_state->qdf_event);
14758 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
14759 sap_config,
14760 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014761 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014762 wlansap_reset_sap_config_add_ie(sap_config,
14763 eUPDATE_IE_ALL);
14764 goto end;
14765 }
14766
Jeff Johnson6867ec32017-09-29 20:30:20 -070014767 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014768 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053014769 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Vignesh Viswanathan865daaa2018-10-11 19:30:44 +053014770 SME_CMD_START_STOP_BSS_TIMEOUT);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014771 wlansap_reset_sap_config_add_ie(sap_config,
14772 eUPDATE_IE_ALL);
14773 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014774 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014775 goto end;
14776 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070014777 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014778 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014779 if (hostapd_state->bss_state == BSS_START) {
Dustin Brown1dbefe62018-09-11 16:32:03 -070014780 policy_mgr_incr_active_session(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014781 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070014782 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070014783 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014784 ap_adapter->device_mode,
14785 true);
14786 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014787 }
14788end:
14789 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014790}
14791
14792/**
14793 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
14794 * with non dfs acs
14795 *
14796 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
14797 *
14798 * Return: None
14799 */
14800void hdd_check_and_restart_sap_with_non_dfs_acs(void)
14801{
Jeff Johnson9d295242017-08-29 14:39:48 -070014802 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014803 struct hdd_context *hdd_ctx;
Jeff Johnson2b6982c2018-05-29 14:56:11 -070014804 struct cds_context *cds_ctx;
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014805 uint8_t restart_chan;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014806
14807 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14808 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014809 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014810 return;
14811 }
14812
14813 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
14814 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014815 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014816 return;
14817 }
14818
Dustin Brown1dbefe62018-09-11 16:32:03 -070014819 if (policy_mgr_get_concurrency_mode(hdd_ctx->psoc)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014820 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Dustin Brown7e761c72018-07-31 13:50:17 -070014821 hdd_debug("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014822 return;
14823 }
14824
14825 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Dustin Brown07901ec2018-09-07 11:02:41 -070014826 if (ap_adapter &&
14827 test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags) &&
14828 wlan_reg_is_dfs_ch(hdd_ctx->pdev,
14829 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014830
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014831 hdd_warn("STA-AP Mode DFS not supported, Switch SAP channel to Non DFS");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014832
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014833 restart_chan =
14834 hdd_get_safe_channel_from_pcl_and_acs_range(ap_adapter);
14835 if (!restart_chan ||
Dustin Brown07901ec2018-09-07 11:02:41 -070014836 wlan_reg_is_dfs_ch(hdd_ctx->pdev, restart_chan))
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014837 restart_chan = SAP_DEFAULT_5GHZ_CHANNEL;
14838
14839 hdd_switch_sap_channel(ap_adapter, restart_chan, true);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014840 }
14841}
14842
14843/**
14844 * hdd_set_connection_in_progress() - to set the connection in
14845 * progress flag
14846 * @value: value to set
14847 *
14848 * This function will set the passed value to connection in progress flag.
14849 * If value is previously being set to true then no need to set it again.
14850 *
14851 * Return: true if value is being set correctly and false otherwise.
14852 */
14853bool hdd_set_connection_in_progress(bool value)
14854{
14855 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014856 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014857
14858 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14859 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014860 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014861 return false;
14862 }
14863
14864 qdf_spin_lock(&hdd_ctx->connection_status_lock);
14865 /*
14866 * if the value is set to true previously and if someone is
14867 * trying to make it true again then it could be some race
14868 * condition being triggered. Avoid this situation by returning
14869 * false
14870 */
14871 if (hdd_ctx->connection_in_progress && value)
14872 status = false;
14873 else
14874 hdd_ctx->connection_in_progress = value;
14875 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
14876 return status;
14877}
14878
Jeff Johnson9d295242017-08-29 14:39:48 -070014879int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014880{
14881 if (!adapter) {
14882 hdd_err("Invalid adapter");
14883 return -EINVAL;
14884 }
14885 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070014886 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014887 WMA_VDEV_MCC_SET_TIME_QUOTA,
14888 set_value, VDEV_CMD);
14889 return 0;
14890
14891}
14892
Jeff Johnson9d295242017-08-29 14:39:48 -070014893int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014894{
14895 if (!adapter) {
14896 hdd_err("Invalid adapter");
14897 return -EINVAL;
14898 }
14899
14900 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070014901 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014902 WMA_VDEV_MCC_SET_TIME_LATENCY,
14903 set_value, VDEV_CMD);
14904 return 0;
14905}
14906
Jeff Johnson9d295242017-08-29 14:39:48 -070014907struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070014908 *psoc, uint8_t vdev_id)
14909{
Jeff Johnson9d295242017-08-29 14:39:48 -070014910 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014911 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070014912
14913 /*
14914 * Currently PSOC is not being used. But this logic will
14915 * change once we have the converged implementation of
14916 * HDD context per PSOC in place. This would break if
14917 * multiple vdev objects reuse the vdev id.
14918 */
14919 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
14920 if (!adapter)
14921 hdd_err("Get adapter by vdev id failed");
14922
14923 return adapter;
14924}
14925
Jeff Johnson9d295242017-08-29 14:39:48 -070014926int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014927 int8_t *rssi, int8_t *snr)
14928{
14929 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -070014930 mac_handle_t mac_handle;
Jeff Johnson025618c2018-03-18 14:41:00 -070014931 struct csr_roam_profile *roam_profile;
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014932
Jeff Johnson025618c2018-03-18 14:41:00 -070014933 roam_profile = hdd_roam_profile(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -070014934 mac_handle = hdd_adapter_get_mac_handle(adapter);
14935 status = sme_get_rssi_snr_by_bssid(mac_handle,
Jeff Johnson025618c2018-03-18 14:41:00 -070014936 roam_profile, bssid, rssi, snr);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014937 if (QDF_STATUS_SUCCESS != status) {
14938 hdd_warn("sme_get_rssi_snr_by_bssid failed");
14939 return -EINVAL;
14940 }
14941
14942 return 0;
14943}
14944
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014945/**
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014946 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
14947 * @adapter - HDD adapter
14948 *
14949 * Return: 0 on success and non zero value on failure
14950 */
14951int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
14952{
14953 struct hdd_context *hdd_ctx;
14954 int ret;
14955 QDF_STATUS status;
Krunal Sonie71838d2018-09-27 10:45:05 -070014956 uint8_t sys_pref = 0;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014957
14958 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
14959 ret = wlan_hdd_validate_context(hdd_ctx);
14960 if (ret < 0)
14961 return ret;
14962
Krunal Sonie71838d2018-09-27 10:45:05 -070014963 ucfg_policy_mgr_get_sys_pref(hdd_ctx->psoc,
14964 &sys_pref);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014965 /* set the system preferece to default */
Krunal Sonie71838d2018-09-27 10:45:05 -070014966 policy_mgr_set_cur_conc_system_pref(hdd_ctx->psoc, sys_pref);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014967
14968 /* clear the bitmap */
14969 adapter->active_ac = 0;
14970
14971 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson16528362018-06-14 12:34:16 -070014972 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014973
Jeff Johnson16528362018-06-14 12:34:16 -070014974 status = sme_send_limit_off_channel_params(hdd_ctx->mac_handle,
14975 adapter->session_id,
14976 false, 0, 0, false);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014977 if (!QDF_IS_STATUS_SUCCESS(status)) {
14978 hdd_err("failed to reset limit off chan params");
14979 ret = -EINVAL;
14980 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014981
14982 return ret;
14983}
14984
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014985/**
14986 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
14987 * @drv_op: Enum indicating driver op
14988 *
14989 * Return: none
14990 */
14991void hdd_start_driver_ops_timer(int drv_op)
14992{
14993 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
14994 switch (drv_op) {
Jeff Johnson5794d4f2018-12-04 11:57:09 -080014995 case HDD_DRV_OP_PROBE:
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014996 memcpy(drv_ops_string, "probe", sizeof("probe"));
14997 break;
Jeff Johnson5794d4f2018-12-04 11:57:09 -080014998 case HDD_DRV_OP_REMOVE:
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014999 memcpy(drv_ops_string, "remove", sizeof("remove"));
15000 break;
Jeff Johnson5794d4f2018-12-04 11:57:09 -080015001 case HDD_DRV_OP_SHUTDOWN:
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053015002 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
15003 break;
Jeff Johnson5794d4f2018-12-04 11:57:09 -080015004 case HDD_DRV_OP_REINIT:
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053015005 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
15006 break;
Jeff Johnson5794d4f2018-12-04 11:57:09 -080015007 case HDD_DRV_OP_IFF_UP:
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053015008 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
15009 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053015010 }
15011
Dustin Brown45ed4bb2017-12-18 12:00:13 -080015012 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053015013 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
Dustin Browncfc54fe2018-06-18 16:17:41 -070015014 HDD_OPS_INACTIVITY_TIMEOUT * qdf_timer_get_multiplier());
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053015015}
15016
15017/**
15018 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
15019 *
15020 * Return: none
15021 */
15022void hdd_stop_driver_ops_timer(void)
15023{
15024 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
15025}
15026
15027/**
15028 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
15029 * inactivity timer
15030 *
15031 * Return: None
15032 */
15033void hdd_drv_ops_inactivity_handler(void)
15034{
Rajeev Kumar4471f1b2018-06-08 14:18:28 -070015035 hdd_err("WLAN_BUG_RCA %s: %d Sec timer expired while in .%s",
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053015036 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
15037
Dustin Brown45ed4bb2017-12-18 12:00:13 -080015038 if (hdd_drv_ops_task) {
15039 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
15040 qdf_print_thread_trace(hdd_drv_ops_task);
15041 } else {
15042 hdd_err("hdd_drv_ops_task is null");
15043 }
15044
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053015045 /* Driver shutdown is stuck, no recovery possible at this point */
15046 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
15047 sizeof("shutdown")))
15048 QDF_BUG(0);
15049
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080015050 if (cds_is_fw_down()) {
15051 hdd_err("FW is down");
15052 return;
15053 }
15054
Dustin Brown83044c22018-08-13 15:00:44 -070015055 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053015056}
15057
Yun Parkff6a16a2017-09-26 16:38:18 -070015058/**
15059 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
15060 * @struct hdd_context *hdd_ctx
15061 * @struct hdd_adapter *padapter
15062 * @bool enble
15063 *
15064 * Return: none
15065 */
15066void hdd_set_rx_mode_rps(bool enable)
15067{
15068 struct cds_config_info *cds_cfg = cds_get_ini_config();
Ryan Hsu0e878fa2018-05-04 15:22:09 -070015069 struct hdd_context *hdd_ctx;
15070 struct hdd_adapter *adapter;
Yun Parkff6a16a2017-09-26 16:38:18 -070015071
Ryan Hsu0e878fa2018-05-04 15:22:09 -070015072 if (!cds_cfg)
15073 return;
15074
15075 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
15076 if (!hdd_ctx)
15077 return;
15078
15079 adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
15080 if (!adapter)
15081 return;
15082
15083 if (!hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
Yun Parkff6a16a2017-09-26 16:38:18 -070015084 if (enable && !cds_cfg->rps_enabled)
15085 hdd_send_rps_ind(adapter);
15086 else if (!enable && cds_cfg->rps_enabled)
15087 hdd_send_rps_disable_ind(adapter);
15088 }
15089}
15090
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015091/* Register the module init/exit functions */
15092module_init(hdd_module_init);
15093module_exit(hdd_module_exit);
15094
15095MODULE_LICENSE("Dual BSD/GPL");
15096MODULE_AUTHOR("Qualcomm Atheros, Inc.");
15097MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
15098
Srinivas Girigowda841da292018-02-21 16:33:00 -080015099static const struct kernel_param_ops con_mode_ops = {
15100 .set = con_mode_handler,
15101 .get = param_get_int,
15102};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015103
Srinivas Girigowda841da292018-02-21 16:33:00 -080015104static const struct kernel_param_ops con_mode_ftm_ops = {
15105 .set = con_mode_handler_ftm,
15106 .get = param_get_int,
15107};
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053015108
Nirav Shah73713f72018-05-17 14:50:41 +053015109#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080015110static const struct kernel_param_ops con_mode_monitor_ops = {
15111 .set = con_mode_handler_monitor,
15112 .get = param_get_int,
15113};
Nirav Shah73713f72018-05-17 14:50:41 +053015114#endif
Ravi Joshia307f632017-07-17 23:41:41 -070015115
Srinivas Girigowda841da292018-02-21 16:33:00 -080015116static const struct kernel_param_ops fwpath_ops = {
15117 .set = fwpath_changed_handler,
15118 .get = param_get_string,
15119};
15120
15121module_param_cb(con_mode, &con_mode_ops, &con_mode,
15122 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
15123
15124module_param_cb(con_mode_ftm, &con_mode_ftm_ops, &con_mode_ftm,
15125 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
15126
Nirav Shah73713f72018-05-17 14:50:41 +053015127#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080015128module_param_cb(con_mode_monitor, &con_mode_monitor_ops, &con_mode_monitor,
15129 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Nirav Shah73713f72018-05-17 14:50:41 +053015130#endif
Srinivas Girigowda841da292018-02-21 16:33:00 -080015131
15132module_param_cb(fwpath, &fwpath_ops, &fwpath,
15133 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015134
15135module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
15136
15137module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
15138
15139module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);