blob: 6d4edf863204e0c9118148e88e984f223054355f [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Dustin Browndb2a8be2017-12-20 11:49:56 -08002 * Copyright (c) 2012-2018 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
7 * copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080019/**
20 * DOC: wlan_hdd_main.c
21 *
22 * WLAN Host Device Driver implementation
23 *
24 */
25
26/* Include Files */
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053027#include <wbuff.h>
Dustin Brown84f46ea2018-02-15 11:57:36 -080028#include "cfg_ucfg_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080029#include <wlan_hdd_includes.h>
30#include <cds_api.h>
31#include <cds_sched.h>
Arun Khandavallifae92942016-08-01 13:31:08 +053032#include <linux/cpu.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080033#include <linux/etherdevice.h>
34#include <linux/firmware.h>
35#include <wlan_hdd_tx_rx.h>
36#include <wni_api.h>
37#include <wlan_hdd_cfg.h>
38#include <wlan_ptt_sock_svc.h>
39#include <dbglog_host.h>
40#include <wlan_logging_sock_svc.h>
Qiwei Caiad9b01c2018-07-09 17:21:31 +080041#include <wlan_roam_debug.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080042#include <wlan_hdd_wowl.h>
43#include <wlan_hdd_misc.h>
44#include <wlan_hdd_wext.h>
45#include "wlan_hdd_trace.h"
46#include "wlan_hdd_ioctl.h"
47#include "wlan_hdd_ftm.h"
48#include "wlan_hdd_power.h"
49#include "wlan_hdd_stats.h"
Prashanth Bhatta527fd752016-04-28 12:35:23 -070050#include "wlan_hdd_scan.h"
Krunal Sonie9c12f52018-10-04 11:45:42 -070051#include "wlan_policy_mgr_ucfg.h"
Naveen Rawate02f8f52018-04-05 11:58:04 -070052#include <wlan_osif_request_manager.h>
Dustin Brown26b3d042017-12-21 11:13:27 -080053#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4bc0a622017-12-06 15:56:50 -080054#include "qdf_debug_domain.h"
Dustin Brown26b3d042017-12-21 11:13:27 -080055#endif
Dustin Brownd4241942018-02-26 12:51:37 -080056#include "qdf_str.h"
57#include "qdf_trace.h"
58#include "qdf_types.h"
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070059#include <cdp_txrx_peer_ops.h>
Dhanashri Atrea8f82f22017-01-23 12:58:24 -080060#include <cdp_txrx_misc.h>
Mohit Khannaca4173b2017-09-12 21:52:19 -070061#include <cdp_txrx_stats.h>
bings0e03a982018-05-09 08:40:59 +080062#include "cdp_txrx_flow_ctrl_legacy.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080063
64#include <net/addrconf.h>
65#include <linux/wireless.h>
66#include <net/cfg80211.h>
67#include <linux/inetdevice.h>
68#include <net/addrconf.h>
69#include "wlan_hdd_cfg80211.h"
70#include "wlan_hdd_ext_scan.h"
71#include "wlan_hdd_p2p.h"
72#include <linux/rtnetlink.h>
73#include "sap_api.h"
74#include <linux/semaphore.h>
75#include <linux/ctype.h>
76#include <linux/compat.h>
Arunk Khandavalli830c9692018-03-22 12:17:40 +053077#include <linux/reboot.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080078#ifdef MSM_PLATFORM
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080079#include <soc/qcom/subsystem_restart.h>
80#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080081#include <wlan_hdd_hostapd.h>
82#include <wlan_hdd_softap_tx_rx.h>
Jeff Johnson8bb61112018-03-31 13:33:54 -070083#include <wlan_hdd_green_ap.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080084#include "cfg_api.h"
85#include "qwlan_version.h"
86#include "wma_types.h"
87#include "wlan_hdd_tdls.h"
88#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053089#include "cds_regdomain.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080090#endif /* FEATURE_WLAN_CH_AVOID */
Dustin Brownce46d1d2017-08-15 13:34:24 -070091#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070092#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -080093#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080094#include "wlan_hdd_nan.h"
95#include "wlan_hdd_debugfs.h"
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053096#include "wlan_hdd_debugfs_csr.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080097#include "wlan_hdd_driver_ops.h"
98#include "epping_main.h"
Poddar, Siddarth34872782017-08-10 14:08:51 +053099#include "wlan_hdd_data_stall_detection.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800100
101#include <wlan_hdd_ipa.h>
102#include "hif.h"
103#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800104#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700105#include "wlan_hdd_tsf.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530106#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700107#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700108#include "wlan_hdd_lpass.h"
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530109#include "nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700110#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530111#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800112#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800113#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530114#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800115#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800116#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530117#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530118#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800119#include "os_if_wifi_pos.h"
120#include "wifi_pos_api.h"
121#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800122#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700123#include "os_if_nan.h"
124#include "nan_public_structs.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700125#include "wlan_reg_ucfg_api.h"
bings81fe50a2017-11-27 14:33:26 +0800126#include "wlan_dfs_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700127#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530128#include "sme_power_save_api.h"
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +0530129#include "enet.h"
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700130#include <cdp_txrx_cmn_struct.h>
Mohit Khanna70322002018-05-15 19:21:32 -0700131#include <dp_txrx.h>
Amar Singhal0928b192017-12-01 10:50:54 -0800132#include "wlan_hdd_sysfs.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530133#include "wlan_disa_ucfg_api.h"
Wu Gao52084c12018-05-17 20:47:11 +0800134#include "wlan_disa_obj_mgmt_api.h"
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +0530135#include "wlan_action_oui_ucfg_api.h"
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +0530136#include "wlan_ipa_ucfg_api.h"
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530137#include <target_if.h>
Alok Kumarb64650c2018-03-23 17:05:11 +0530138#include "wlan_hdd_nud_tracking.h"
Nachiket Kukaded0dd62e2018-05-21 18:39:22 +0530139#include "wlan_hdd_apf.h"
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -0700140#include "wlan_hdd_twt.h"
Rachit Kankane0dc3e852018-05-07 17:33:42 +0530141#include "qc_sap_ioctl.h"
Sandeep Puligillac5609d52018-05-17 19:23:41 -0700142#include "wlan_mlme_main.h"
Wu Gaoe5689792018-07-05 19:20:13 +0800143#include "wlan_p2p_cfg_api.h"
Wu Gaobdb7f272018-07-05 19:33:26 +0800144#include "wlan_tdls_cfg_api.h"
Qiwei Caie689a262018-07-26 15:50:22 +0800145#include <wlan_hdd_rssi_monitor.h>
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +0530146#include "wlan_mlme_ucfg_api.h"
Harprit Chhabada1eeeb8d2018-09-14 15:16:56 -0700147#include "cfg_mlme_acs.h"
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +0530148#include "wlan_mlme_public_struct.h"
Sourav Mohapatra113685f2018-08-29 14:21:55 +0530149#include "wlan_fwol_ucfg_api.h"
Krunal Sonie71838d2018-09-27 10:45:05 -0700150#include "wlan_policy_mgr_ucfg.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530151#ifdef CNSS_GENL
152#include <net/cnss_nl.h>
153#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800154#include "wlan_reg_ucfg_api.h"
Zhang Qian47e22ce2018-01-04 15:38:38 +0800155#include "wlan_ocb_ucfg_api.h"
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -0800156#include <wlan_hdd_spectralscan.h>
gaurank kathpalia4a205fc2018-09-15 00:59:15 +0530157#include "wlan_green_ap_ucfg_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800158#ifdef MODULE
159#define WLAN_MODULE_NAME module_name(THIS_MODULE)
160#else
161#define WLAN_MODULE_NAME "wlan"
162#endif
163
164#ifdef TIMER_MANAGER
165#define TIMER_MANAGER_STR " +TIMER_MANAGER"
166#else
167#define TIMER_MANAGER_STR ""
168#endif
169
170#ifdef MEMORY_DEBUG
171#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
172#else
173#define MEMORY_DEBUG_STR ""
174#endif
175
Dustin Brownc1034df2018-02-07 14:51:32 -0800176#ifdef PANIC_ON_BUG
177#define PANIC_ON_BUG_STR " +PANIC_ON_BUG"
178#else
179#define PANIC_ON_BUG_STR ""
180#endif
181
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530182bool g_is_system_reboot_triggered;
Sachin Ahujadddd2632017-03-07 19:07:24 +0530183int wlan_start_ret_val;
184static DECLARE_COMPLETION(wlan_start_comp);
185static unsigned int dev_num = 1;
186static struct cdev wlan_hdd_state_cdev;
187static struct class *class;
188static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530189#ifndef MODULE
190static struct gwlan_loader *wlan_loader;
191static ssize_t wlan_boot_cb(struct kobject *kobj,
192 struct kobj_attribute *attr,
193 const char *buf, size_t count);
194struct gwlan_loader {
195 bool loaded_state;
196 struct kobject *boot_wlan_obj;
197 struct attribute_group *attr_group;
198};
199
200static struct kobj_attribute wlan_boot_attribute =
201 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
202
203static struct attribute *attrs[] = {
204 &wlan_boot_attribute.attr,
205 NULL,
206};
207
208#define MODULE_INITIALIZED 1
Qun Zhang4a83a462018-09-11 16:28:51 +0800209
210#ifdef MULTI_IF_NAME
211#define WLAN_LOADER_NAME "boot_" MULTI_IF_NAME
212#else
213#define WLAN_LOADER_NAME "boot_wlan"
214#endif
Arun Khandavallifae92942016-08-01 13:31:08 +0530215#endif
216
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530217#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
218#define MAX_OPS_NAME_STRING_SIZE 20
Rajeev Kumar6d0b2ea2017-12-26 17:55:33 -0800219#define RATE_LIMIT_ERROR_LOG (256)
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530220
221static qdf_timer_t hdd_drv_ops_inactivity_timer;
Dustin Brown45ed4bb2017-12-18 12:00:13 -0800222static struct task_struct *hdd_drv_ops_task;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530223static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
224
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800225/* the Android framework expects this param even though we don't use it */
226#define BUF_LEN 20
227static char fwpath_buffer[BUF_LEN];
228static struct kparam_string fwpath = {
229 .string = fwpath_buffer,
230 .maxlen = BUF_LEN,
231};
232
233static char *country_code;
234static int enable_11d = -1;
235static int enable_dfs_chan_scan = -1;
236
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800237/*
238 * spinlock for synchronizing asynchronous request/response
239 * (full description of use in wlan_hdd_main.h)
240 */
241DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530242DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800243
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800244#define WLAN_NLINK_CESIUM 30
245
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530246static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800247
248#define WOW_MAX_FILTER_LISTS 1
249#define WOW_MAX_FILTERS_PER_LIST 4
250#define WOW_MIN_PATTERN_SIZE 6
251#define WOW_MAX_PATTERN_SIZE 64
252
Bala Venkatesh110b03e2018-07-10 16:02:08 +0530253/* max peer can be tdls peers + self peer + bss peer */
254#define HDD_MAX_VDEV_PEER_COUNT (HDD_MAX_NUM_TDLS_STA + 2)
Sourav Mohapatra808e3d42018-07-04 09:34:23 +0530255#define IS_IDLE_STOP (!cds_is_driver_unloading() && \
256 !cds_is_driver_recovering() && !cds_is_driver_loading())
Bala Venkatesh110b03e2018-07-10 16:02:08 +0530257
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800258#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
259static const struct wiphy_wowlan_support wowlan_support_reg_init = {
260 .flags = WIPHY_WOWLAN_ANY |
261 WIPHY_WOWLAN_MAGIC_PKT |
262 WIPHY_WOWLAN_DISCONNECT |
263 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
264 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
265 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
266 WIPHY_WOWLAN_4WAY_HANDSHAKE |
267 WIPHY_WOWLAN_RFKILL_RELEASE,
268 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
269 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
270 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
271};
272#endif
273
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700274static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
275 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
276 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
277 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
278 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
279 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
280 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
281 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
282 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
283 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
284 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
285 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
286 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
287 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
288 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
289 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
290 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
291 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
292 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
293 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
294 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
295 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
296 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
297 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
298 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
299 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
300 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
301 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
302 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
303 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
304 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
305 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
306 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
307 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
308 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700309 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700310 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700311 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530312 [QDF_MODULE_ID_GREEN_AP] = {QDF_TRACE_LEVEL_ALL},
Zhang Qian47e22ce2018-01-04 15:38:38 +0800313 [QDF_MODULE_ID_OCB] = {QDF_TRACE_LEVEL_ALL},
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530314 [QDF_MODULE_ID_IPA] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +0530315 [QDF_MODULE_ID_ACTION_OUI] = {QDF_TRACE_LEVEL_ALL},
Dustin Brown84f46ea2018-02-15 11:57:36 -0800316 [QDF_MODULE_ID_CONFIG] = {QDF_TRACE_LEVEL_ALL},
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +0530317 [QDF_MODULE_ID_MLME] = {QDF_TRACE_LEVEL_ALL},
Ashish Kumar Dhanotiya8d039c82018-07-11 20:41:14 +0530318 [QDF_MODULE_ID_TARGET] = {QDF_TRACE_LEVEL_ALL},
Sourav Mohapatra113685f2018-08-29 14:21:55 +0530319 [QDF_MODULE_ID_FWOL] = {QDF_TRACE_LEVEL_ALL},
Abhishek Singh0b0105f2018-09-25 10:44:16 +0530320 [QDF_MODULE_ID_SM_ENGINE] = {QDF_TRACE_LEVEL_ALL},
321 [QDF_MODULE_ID_CMN_MLME] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700322};
323
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530324struct notifier_block hdd_netdev_notifier;
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530325struct notifier_block system_reboot_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800326
327struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800328#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700329static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800330#endif
331
Sachin Ahujadddd2632017-03-07 19:07:24 +0530332void hdd_start_complete(int ret)
333{
334 wlan_start_ret_val = ret;
335
336 complete(&wlan_start_comp);
337}
338
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800339/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530340 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700341 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530342 *
343 * Return: none
344 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700345static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530346{
Jeff Johnson9d295242017-08-29 14:39:48 -0700347 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530348
Dustin Brown920397d2017-12-13 16:27:50 -0800349 hdd_for_each_adapter(hdd_ctx, adapter)
350 hdd_send_rps_ind(adapter);
Nirav Shahbd36b062016-07-18 11:12:59 +0530351}
352
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530353#ifdef QCA_HL_NETDEV_FLOW_CONTROL
354void wlan_hdd_mod_fc_timer(struct hdd_adapter *adapter,
355 enum netif_action_type action)
356{
357 if (!adapter->tx_flow_timer_initialized)
358 return;
359
360 if (action == WLAN_WAKE_NON_PRIORITY_QUEUE) {
361 qdf_mc_timer_stop(&adapter->tx_flow_control_timer);
362 } else if (action == WLAN_STOP_NON_PRIORITY_QUEUE) {
363 QDF_STATUS status =
364 qdf_mc_timer_start(&adapter->tx_flow_control_timer,
365 WLAN_HDD_TX_FLOW_CONTROL_OS_Q_BLOCK_TIME);
366
367 if (!QDF_IS_STATUS_SUCCESS(status))
368 hdd_err("Failed to start tx_flow_control_timer");
369 else
370 adapter->
371 hdd_stats.tx_rx_stats.txflow_timer_cnt++;
372
373 adapter->hdd_stats.tx_rx_stats.txflow_pause_cnt++;
374 adapter->hdd_stats.tx_rx_stats.is_txflow_paused = true;
375 }
376}
377#endif /* QCA_HL_NETDEV_FLOW_CONTROL */
378
Nirav Shahbd36b062016-07-18 11:12:59 +0530379/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800380 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
381 * @vdev_id: vdev_id
382 * @action: action type
383 * @reason: reason type
384 *
385 * Return: none
386 */
387void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
388 enum netif_action_type action, enum netif_reason_type reason)
389{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700390 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700391 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800392
393 if (!hdd_ctx) {
394 hdd_err("hdd ctx is NULL");
395 return;
396 }
397 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530398 wlan_hdd_mod_fc_timer(adapter, action);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800399 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800400}
401
402/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700403 * Store WLAN driver version and timestamp info in global variables such that
404 * crash debugger can extract them from driver debug symbol and crashdump for
405 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800406 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800407#ifdef BUILD_TAG
Rajeev Kumare555e2d2018-09-17 11:52:37 -0700408uint8_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 -0800409#else
Rajeev Kumare555e2d2018-09-17 11:52:37 -0700410uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR;
Naveen Rawat93836252017-06-20 16:30:59 -0700411#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800412
413/**
414 * hdd_device_mode_to_string() - return string conversion of device mode
415 * @device_mode: device mode
416 *
417 * This utility function helps log string conversion of device mode.
418 *
419 * Return: string conversion of device mode, if match found;
420 * "Unknown" otherwise.
421 */
422const char *hdd_device_mode_to_string(uint8_t device_mode)
423{
424 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800425 CASE_RETURN_STRING(QDF_STA_MODE);
426 CASE_RETURN_STRING(QDF_SAP_MODE);
427 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
428 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
429 CASE_RETURN_STRING(QDF_FTM_MODE);
430 CASE_RETURN_STRING(QDF_IBSS_MODE);
431 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
432 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700433 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800434 default:
435 return "Unknown";
436 }
437}
438
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530439/**
Liangwei Dong17bf2662018-01-05 02:02:05 -0500440 * hdd_get_valid_chan() - return current chan list from regulatory.
441 * @hdd_ctx: HDD context
442 * @chan_list: buf hold returned chan list
443 * @chan_num: input buf size and output returned chan num
444 *
445 * This function helps get current available chan list from regulatory
446 * module. It excludes the "disabled" and "invalid" channels.
447 *
448 * Return: 0 for success.
449 */
450static int hdd_get_valid_chan(struct hdd_context *hdd_ctx,
451 uint8_t *chan_list,
452 uint32_t *chan_num)
453{
454 int i = 0, j = 0;
455 struct regulatory_channel *cur_chan_list;
456 struct wlan_objmgr_pdev *pdev;
457
Dustin Brown07901ec2018-09-07 11:02:41 -0700458 if (!hdd_ctx || !hdd_ctx->pdev || !chan_list || !chan_num)
Liangwei Dong17bf2662018-01-05 02:02:05 -0500459 return -EINVAL;
460
Dustin Brown07901ec2018-09-07 11:02:41 -0700461 pdev = hdd_ctx->pdev;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500462 cur_chan_list = qdf_mem_malloc(NUM_CHANNELS *
463 sizeof(struct regulatory_channel));
464 if (!cur_chan_list)
465 return -ENOMEM;
466
467 if (wlan_reg_get_current_chan_list(pdev, cur_chan_list) !=
468 QDF_STATUS_SUCCESS) {
469 qdf_mem_free(cur_chan_list);
470 return -EINVAL;
471 }
472
473 for (i = 0; i < NUM_CHANNELS; i++) {
474 uint32_t ch = cur_chan_list[i].chan_num;
475 enum channel_state state = wlan_reg_get_channel_state(pdev,
476 ch);
477
478 if (state != CHANNEL_STATE_DISABLE &&
479 state != CHANNEL_STATE_INVALID &&
480 j < *chan_num) {
481 chan_list[j] = (uint8_t)ch;
482 j++;
483 }
484 }
485 *chan_num = j;
486 qdf_mem_free(cur_chan_list);
487 return 0;
488}
489
490/**
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530491 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
492 * @adapter: HDD adapter
493 * @chan_number: Channel number
494 * @chan_bw: Bandwidth
495 *
496 * Checks if the given bandwidth is valid for the given channel number.
497 *
498 * Return: 0 for success, non-zero for failure
499 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700500int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530501 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800502 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530503{
Liangwei Dong17bf2662018-01-05 02:02:05 -0500504 uint8_t chan[NUM_CHANNELS];
505 uint32_t len = NUM_CHANNELS, i;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530506 bool found = false;
Jeff Johnson16528362018-06-14 12:34:16 -0700507 mac_handle_t mac_handle;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500508 int ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530509
Jeff Johnson16528362018-06-14 12:34:16 -0700510 mac_handle = hdd_adapter_get_mac_handle(adapter);
511 if (!mac_handle) {
512 hdd_err("Invalid MAC handle");
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530513 return -EINVAL;
514 }
515
Liangwei Dong17bf2662018-01-05 02:02:05 -0500516 ret = hdd_get_valid_chan(adapter->hdd_ctx, chan,
517 &len);
518 if (ret) {
519 hdd_err("error %d in getting valid channel list", ret);
520 return ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530521 }
522
523 for (i = 0; i < len; i++) {
524 if (chan[i] == chan_number) {
525 found = true;
526 break;
527 }
528 }
529
530 if (found == false) {
531 hdd_err("Channel not in driver's valid channel list");
532 return -EOPNOTSUPP;
533 }
534
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700535 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
536 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530537 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
538 return -EINVAL;
539 }
540
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700541 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530542 if (chan_bw == CH_WIDTH_80MHZ) {
543 hdd_err("BW80 not possible in 2.4GHz band");
544 return -EINVAL;
545 }
546 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
547 (chan_bw != CH_WIDTH_MAX)) {
548 hdd_err("Only BW20 possible on channel 14");
549 return -EINVAL;
550 }
551 }
552
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700553 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530554 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
555 (chan_bw != CH_WIDTH_MAX)) {
556 hdd_err("Only BW20 possible on channel 165");
557 return -EINVAL;
558 }
559 }
560
561 return 0;
562}
563
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530564/**
565 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
566 *
567 * Block the unloading of the driver (or) interface up until the
568 * cds recovery is completed
569 *
570 * Return: true for recovery completion else false
571 */
572static bool hdd_wait_for_recovery_completion(void)
573{
574 int retry = 0;
575
576 /* Wait for recovery to complete */
577 while (cds_is_driver_recovering()) {
578 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
579 hdd_err("Recovery in progress; wait here!!!");
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530580
581 if (g_is_system_reboot_triggered) {
582 hdd_info("System Reboot happening ignore unload!!");
583 return false;
584 }
585
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530586 msleep(1000);
587 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
588 hdd_err("SSR never completed, error");
589 /*
590 * Trigger the bug_on in the internal builds, in the
591 * customer builds self-recovery will be enabled
592 * in those cases just return error.
593 */
594 if (cds_is_self_recovery_enabled())
595 return false;
596 QDF_BUG(0);
597 }
598 }
599
600 hdd_info("Recovery completed successfully!");
601 return true;
602}
603
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530604
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800605static int __hdd_netdev_notifier_call(struct notifier_block *nb,
606 unsigned long state, void *data)
607{
608#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
609 struct netdev_notifier_info *dev_notif_info = data;
610 struct net_device *dev = dev_notif_info->dev;
611#else
612 struct net_device *dev = data;
613#endif
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530614 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700615 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800616
Dustin Brownfdf17c12018-03-14 12:55:34 -0700617 hdd_enter_dev(dev);
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800618
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800619 if (!dev->ieee80211_ptr) {
Dustin Brownaeb55642018-07-30 17:20:32 -0700620 hdd_debug("ieee80211_ptr is null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800621 return NOTIFY_DONE;
622 }
623
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530624 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
625 if (!hdd_ctx) {
626 hdd_err("HDD Context is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800627 return NOTIFY_DONE;
628 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800629
630 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -0700631 hdd_debug("%s: Driver module is closed", __func__);
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800632 return NOTIFY_DONE;
633 }
634
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530635 /* Make sure that this callback corresponds to our device. */
636 adapter = hdd_get_adapter_by_iface_name(hdd_ctx, dev->name);
637 if (!adapter) {
Dustin Brownaeb55642018-07-30 17:20:32 -0700638 hdd_debug("failed to look up adapter for '%s'", dev->name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800639 return NOTIFY_DONE;
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530640 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800641
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530642 if (adapter != WLAN_HDD_GET_PRIV_PTR(dev)) {
643 hdd_err("HDD adapter mismatch!");
644 return NOTIFY_DONE;
645 }
646
Dustin Brownaeb55642018-07-30 17:20:32 -0700647 if (cds_is_driver_recovering()) {
648 hdd_debug("Driver is recovering");
649 return NOTIFY_DONE;
650 }
651
652 if (cds_is_driver_in_bad_state()) {
653 hdd_debug("Driver is in failed recovery state");
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530654 return NOTIFY_DONE;
655 }
656
657 hdd_debug("%s New Net Device State = %lu", dev->name, state);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800658
659 switch (state) {
660 case NETDEV_REGISTER:
661 break;
662
663 case NETDEV_UNREGISTER:
664 break;
665
666 case NETDEV_UP:
Jeff Johnson16528362018-06-14 12:34:16 -0700667 sme_ch_avoid_update_req(hdd_ctx->mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800668 break;
669
670 case NETDEV_DOWN:
671 break;
672
673 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700674 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800675 complete(&adapter->linkup_event_var);
676 break;
677
678 case NETDEV_GOING_DOWN:
Dustin Brown89fa06e2018-09-07 10:47:27 -0700679 if (ucfg_scan_get_vdev_status(adapter->vdev) !=
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700680 SCAN_NOT_IN_PROGRESS) {
Dustin Brown07901ec2018-09-07 11:02:41 -0700681 wlan_abort_scan(hdd_ctx->pdev, INVAL_PDEV_ID,
682 adapter->session_id, INVALID_SCAN_ID,
683 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800684 }
Min Liu9be5d4a2018-05-17 11:51:53 +0800685 cds_flush_work(&adapter->scan_block_work);
686 /* Need to clean up blocked scan request */
687 wlan_hdd_cfg80211_scan_block_cb(&adapter->scan_block_work);
Min Liu9be5d4a2018-05-17 11:51:53 +0800688 hdd_debug("Scan is not Pending from user");
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530689 /*
690 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
691 * of return status of hdd_stop call, kernel resets the IFF_UP
692 * flag after which driver does not send the cfg80211_scan_done.
693 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
694 */
Dustin Brown07901ec2018-09-07 11:02:41 -0700695 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800696 break;
697
698 default:
699 break;
700 }
701
702 return NOTIFY_DONE;
703}
704
705/**
706 * hdd_netdev_notifier_call() - netdev notifier callback function
707 * @nb: pointer to notifier block
708 * @state: state
709 * @ndev: ndev pointer
710 *
711 * Return: 0 on success, error number otherwise.
712 */
713static int hdd_netdev_notifier_call(struct notifier_block *nb,
714 unsigned long state,
715 void *ndev)
716{
717 int ret;
718
719 cds_ssr_protect(__func__);
720 ret = __hdd_netdev_notifier_call(nb, state, ndev);
721 cds_ssr_unprotect(__func__);
722
723 return ret;
724}
725
726struct notifier_block hdd_netdev_notifier = {
727 .notifier_call = hdd_netdev_notifier_call,
728};
729
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530730static int system_reboot_notifier_call(struct notifier_block *nb,
731 unsigned long msg_type, void *_unused)
732{
733 switch (msg_type) {
734 case SYS_DOWN:
735 case SYS_HALT:
736 case SYS_POWER_OFF:
737 g_is_system_reboot_triggered = true;
738 hdd_info("reboot, reason: %ld", msg_type);
739 break;
740 default:
741 break;
742 }
743
744 return NOTIFY_OK;
745}
746
747struct notifier_block system_reboot_notifier = {
748 .notifier_call = system_reboot_notifier_call,
749};
750
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800751/* variable to hold the insmod parameters */
752static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800753
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530754static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700755int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530756
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800757/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800758static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800759
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530760/**
761 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
762 * @ch_width: NL channel width
763 *
764 * Converts the NL channel width to the driver's internal representation
765 *
766 * Return: Converted channel width. In case of non matching NL channel width,
767 * CH_WIDTH_MAX will be returned.
768 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800769enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530770{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800771 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700772
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800773 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530774 switch (ch_width) {
775 case NL80211_CHAN_WIDTH_20_NOHT:
776 case NL80211_CHAN_WIDTH_20:
777 return CH_WIDTH_20MHZ;
778 case NL80211_CHAN_WIDTH_40:
779 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530780 case NL80211_CHAN_WIDTH_80:
781 return CH_WIDTH_80MHZ;
782 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800783 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
784 return CH_WIDTH_80P80MHZ;
785 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
786 return CH_WIDTH_160MHZ;
787 else
788 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530789 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800790 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
791 return CH_WIDTH_160MHZ;
792 else
793 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530794 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800795 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530796 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800797 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530798 default:
799 hdd_err("Invalid channel width %d, setting to default",
800 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800801 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530802 }
803}
804
Dustin Brown56377e12018-10-10 17:04:04 -0700805QDF_STATUS hdd_nl_to_qdf_iface_type(enum nl80211_iftype nl_type,
806 enum QDF_OPMODE *out_qdf_type)
807{
808 switch (nl_type) {
809 case NL80211_IFTYPE_ADHOC:
810 *out_qdf_type = QDF_IBSS_MODE;
811 break;
812 case NL80211_IFTYPE_AP:
813 *out_qdf_type = QDF_SAP_MODE;
814 break;
815 case NL80211_IFTYPE_MONITOR:
816 *out_qdf_type = QDF_MONITOR_MODE;
817 break;
818 case NL80211_IFTYPE_OCB:
819 *out_qdf_type = QDF_OCB_MODE;
820 break;
821 case NL80211_IFTYPE_P2P_CLIENT:
822 *out_qdf_type = QDF_P2P_CLIENT_MODE;
823 break;
824 case NL80211_IFTYPE_P2P_DEVICE:
825 *out_qdf_type = QDF_P2P_DEVICE_MODE;
826 break;
827 case NL80211_IFTYPE_P2P_GO:
828 *out_qdf_type = QDF_P2P_GO_MODE;
829 break;
830 case NL80211_IFTYPE_STATION:
831 *out_qdf_type = QDF_STA_MODE;
832 break;
833 case NL80211_IFTYPE_WDS:
834 *out_qdf_type = QDF_WDS_MODE;
835 break;
836 default:
837 hdd_err("Invalid nl80211 interface type %d", nl_type);
838 return QDF_STATUS_E_INVAL;
839 }
840
841 return QDF_STATUS_SUCCESS;
842}
843
Jeff Johnson16528362018-06-14 12:34:16 -0700844uint8_t wlan_hdd_find_opclass(mac_handle_t mac_handle, uint8_t channel,
845 uint8_t bw_offset)
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530846{
847 uint8_t opclass = 0;
848
Jeff Johnson16528362018-06-14 12:34:16 -0700849 sme_get_opclass(mac_handle, channel, bw_offset, &opclass);
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530850 return opclass;
851}
852
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800853/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530854 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530855 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800856 * @bitmask: Bitmask of log levels to be enabled
857 *
858 * Called immediately after the cfg.ini is read in order to configure
859 * the desired trace levels.
860 *
861 * Return: None
862 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530863int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800864{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530865 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530866 int qdf_print_idx = -1;
867 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800868 /*
869 * if the bitmask is the default value, then a bitmask was not
870 * specified in cfg.ini, so leave the logging level alone (it
871 * will remain at the "compiled in" default value)
872 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700873 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530874 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800875
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530876 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800877
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530878 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530879 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530880 QDF_TRACE_LEVEL_NONE, 0);
881
882 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530883 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800884 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530885 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800886 while (0 != bitmask) {
887 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530888 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530889 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530890 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530891 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800892 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700893
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800894 level++;
895 bitmask >>= 1;
896 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530897 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800898}
899
Dustin Brownda351e32018-07-23 15:48:22 -0700900int __wlan_hdd_validate_context(struct hdd_context *hdd_ctx, const char *func)
Chris Guo1751acf2017-07-03 14:09:01 +0800901{
Dustin Brownda351e32018-07-23 15:48:22 -0700902 if (!hdd_ctx) {
903 hdd_err("HDD context is null (via %s)", func);
904 return -ENODEV;
905 }
906
907 if (!hdd_ctx->config) {
908 hdd_err("HDD config is null (via %s)", func);
Chris Guo1751acf2017-07-03 14:09:01 +0800909 return -ENODEV;
910 }
911
912 if (cds_is_driver_recovering()) {
Dustin Brownda351e32018-07-23 15:48:22 -0700913 hdd_debug("Recovery in progress (via %s); state:0x%x",
914 func, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800915 return -EAGAIN;
916 }
917
Yue Ma9f275d92017-09-14 16:58:41 -0700918 if (cds_is_load_or_unload_in_progress()) {
Dustin Brownda351e32018-07-23 15:48:22 -0700919 hdd_debug("Load/unload in progress (via %s); state:0x%x",
920 func, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800921 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -0700922 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530923
Dustin Brownda351e32018-07-23 15:48:22 -0700924 if (hdd_ctx->start_modules_in_progress) {
925 hdd_debug("Start modules in progress (via %s)", func);
926 return -EAGAIN;
927 }
928
929 if (hdd_ctx->stop_modules_in_progress) {
930 hdd_debug("Stop modules in progress (via %s)", func);
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530931 return -EAGAIN;
932 }
933
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530934 if (cds_is_driver_in_bad_state()) {
Dustin Brownda351e32018-07-23 15:48:22 -0700935 hdd_debug("Driver in bad state (via %s); state:0x%x",
936 func, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +0530937 return -EAGAIN;
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530938 }
939
Arunk Khandavalli2859fa12018-02-14 10:46:26 +0530940 if (cds_is_fw_down()) {
Dustin Brownda351e32018-07-23 15:48:22 -0700941 hdd_debug("FW is down (via %s); state:0x%x",
942 func, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +0530943 return -EAGAIN;
Arunk Khandavalli2859fa12018-02-14 10:46:26 +0530944 }
945
Liangwei Dong858feb12018-05-21 01:52:46 -0400946 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
Dustin Brownda351e32018-07-23 15:48:22 -0700947 hdd_debug("Driver mode change in progress (via %s)", func);
Liangwei Dong858feb12018-05-21 01:52:46 -0400948 return -EAGAIN;
949 }
950
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800951 return 0;
952}
953
Dustin Browna8700cc2018-08-07 12:04:47 -0700954int __hdd_validate_adapter(struct hdd_adapter *adapter, const char *func)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700955{
956 if (!adapter) {
Dustin Browna8700cc2018-08-07 12:04:47 -0700957 hdd_err("adapter is null (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700958 return -EINVAL;
959 }
960
961 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Dustin Browna8700cc2018-08-07 12:04:47 -0700962 hdd_err("bad adapter magic (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700963 return -EINVAL;
964 }
965
966 if (!adapter->dev) {
Dustin Browna8700cc2018-08-07 12:04:47 -0700967 hdd_err("adapter net_device is null (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700968 return -EINVAL;
969 }
970
971 if (!(adapter->dev->flags & IFF_UP)) {
Dustin Browna8700cc2018-08-07 12:04:47 -0700972 hdd_debug_rl("adapter '%s' is not up (via %s)",
973 adapter->dev->name, func);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700974 return -EAGAIN;
975 }
976
Dustin Browna8700cc2018-08-07 12:04:47 -0700977 return __wlan_hdd_validate_session_id(adapter->session_id, func);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700978}
979
Dustin Brown63500612018-08-07 11:36:09 -0700980int __wlan_hdd_validate_session_id(uint8_t session_id, const char *func)
981{
982 if (session_id == CSR_SESSION_ID_INVALID) {
983 hdd_debug_rl("adapter is not up (via %s)", func);
984 return -EINVAL;
985 }
986
987 if (session_id >= CSR_ROAM_SESSION_MAX) {
988 hdd_err("bad session Id:%u (via %s)", session_id, func);
989 return -EINVAL;
990 }
991
992 return 0;
993}
994
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +0530995QDF_STATUS __wlan_hdd_validate_mac_address(struct qdf_mac_addr *mac_addr,
996 const char *func)
997{
998 if (!mac_addr) {
999 hdd_err("Received NULL mac address (via %s)", func);
1000 return QDF_STATUS_E_INVAL;
1001 }
1002
1003 if (qdf_is_macaddr_zero(mac_addr)) {
1004 hdd_err("MAC is all zero (via %s)", func);
1005 return QDF_STATUS_E_INVAL;
1006 }
1007
1008 if (qdf_is_macaddr_broadcast(mac_addr)) {
1009 hdd_err("MAC is Broadcast (via %s)", func);
1010 return QDF_STATUS_E_INVAL;
1011 }
1012
1013 if (QDF_NET_IS_MAC_MULTICAST(mac_addr->bytes)) {
1014 hdd_err("MAC is Multicast (via %s)", func);
1015 return QDF_STATUS_E_INVAL;
1016 }
1017
1018 return QDF_STATUS_SUCCESS;
1019}
1020
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001021/**
Arun Khandavallica892f62017-05-26 14:25:50 +05301022 * wlan_hdd_validate_modules_state() - Check modules status
1023 * @hdd_ctx: HDD context pointer
1024 *
1025 * Check's the driver module's state and returns true if the
1026 * modules are enabled returns false if modules are closed.
1027 *
1028 * Return: True if modules are enabled or false.
1029 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001030bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +05301031{
1032 mutex_lock(&hdd_ctx->iface_change_lock);
1033 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
1034 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown5e89ef82018-03-14 11:50:23 -07001035 hdd_info("Modules not enabled, Present status: %d",
1036 hdd_ctx->driver_status);
Arun Khandavallica892f62017-05-26 14:25:50 +05301037 return false;
1038 }
1039 mutex_unlock(&hdd_ctx->iface_change_lock);
1040 return true;
1041}
1042
1043/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001044 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -07001045 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001046 *
1047 * This function sets the IBSS power save config parameters to WMA
1048 * which will send it to firmware if FW supports IBSS power save
1049 * before vdev start.
1050 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301051 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001052 * on failure.
1053 */
Jeff Johnson9d295242017-08-29 14:39:48 -07001054QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001055{
1056 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001057 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001058
1059 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001060 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301061 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001062 }
1063
Jeff Johnson1b780e42017-10-31 14:11:45 -07001064 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001065 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
1066 hdd_ctx->config->ibssATIMWinSize,
1067 VDEV_CMD);
1068 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001069 hdd_err("atim window set failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301070 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001071 }
1072
Jeff Johnson1b780e42017-10-31 14:11:45 -07001073 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001074 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
1075 hdd_ctx->config->isIbssPowerSaveAllowed,
1076 VDEV_CMD);
1077 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001078 hdd_err("power save allow failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001079 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301080 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001081 }
1082
Jeff Johnson1b780e42017-10-31 14:11:45 -07001083 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001084 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
1085 hdd_ctx->config->
1086 isIbssPowerCollapseAllowed, VDEV_CMD);
1087 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001088 hdd_err("power collapse allow failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001089 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301090 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001091 }
1092
Jeff Johnson1b780e42017-10-31 14:11:45 -07001093 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001094 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
1095 hdd_ctx->config->isIbssAwakeOnTxRx,
1096 VDEV_CMD);
1097 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001098 hdd_err("set awake on tx/rx failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301099 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001100 }
1101
Jeff Johnson1b780e42017-10-31 14:11:45 -07001102 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001103 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
1104 hdd_ctx->config->ibssInactivityCount,
1105 VDEV_CMD);
1106 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001107 hdd_err("set inactivity time failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301108 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001109 }
1110
Jeff Johnson1b780e42017-10-31 14:11:45 -07001111 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001112 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
1113 hdd_ctx->config->ibssTxSpEndInactivityTime,
1114 VDEV_CMD);
1115 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001116 hdd_err("set txsp end failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001117 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301118 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001119 }
1120
Jeff Johnson1b780e42017-10-31 14:11:45 -07001121 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001122 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
1123 hdd_ctx->config->ibssPsWarmupTime,
1124 VDEV_CMD);
1125 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001126 hdd_err("set ps warmup failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001127 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301128 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001129 }
1130
Jeff Johnson1b780e42017-10-31 14:11:45 -07001131 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001132 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
1133 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
1134 VDEV_CMD);
1135 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001136 hdd_err("set 1rx chain atim failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001137 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301138 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001139 }
1140
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301141 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001142}
1143
Yue Macd359b72017-10-03 15:21:00 -07001144#ifdef FEATURE_RUNTIME_PM
1145/**
1146 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
1147 * @hdd_ctx: HDD context
1148 *
1149 * Return: None
1150 */
1151static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
1152{
1153 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1154
Yue Macd359b72017-10-03 15:21:00 -07001155 qdf_runtime_lock_init(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001156 qdf_runtime_lock_init(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001157
Dustin Brown07901ec2018-09-07 11:02:41 -07001158 wlan_scan_runtime_pm_init(hdd_ctx->pdev);
Yue Macd359b72017-10-03 15:21:00 -07001159}
1160
1161/**
1162 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1163 * @hdd_ctx: HDD Context
1164 *
1165 * Return: None
1166 */
1167static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1168{
1169 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1170
Yue Macd359b72017-10-03 15:21:00 -07001171 qdf_runtime_lock_deinit(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001172 qdf_runtime_lock_deinit(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001173
Dustin Brown07901ec2018-09-07 11:02:41 -07001174 wlan_scan_runtime_pm_deinit(hdd_ctx->pdev);
Yue Macd359b72017-10-03 15:21:00 -07001175}
1176
Yue Macd359b72017-10-03 15:21:00 -07001177#else /* FEATURE_RUNTIME_PM */
1178static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1179static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Yue Macd359b72017-10-03 15:21:00 -07001180#endif /* FEATURE_RUNTIME_PM */
1181
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001182#define INTF_MACADDR_MASK 0x7
1183
1184/**
1185 * hdd_update_macaddr() - update mac address
1186 * @config: hdd configuration
1187 * @hw_macaddr: mac address
1188 *
1189 * Mac address for multiple virtual interface is found as following
1190 * i) The mac address of the first interface is just the actual hw mac address.
1191 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
1192 * define the mac address for the remaining interfaces and locally
1193 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1194 * supported virtual interfaces, right now this is 0x07 (meaning 8
1195 * interface).
1196 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1197 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1198 *
1199 * Return: None
1200 */
1201void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301202 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001203{
1204 int8_t i;
1205 uint8_t macaddr_b3, tmp_br3;
1206
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301207 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301208 QDF_MAC_ADDR_SIZE);
1209 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301210 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301211 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001212 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1213 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1214 INTF_MACADDR_MASK;
1215 macaddr_b3 += tmp_br3;
1216
1217 /* XOR-ing bit-24 of the mac address. This will give enough
1218 * mac address range before collision
1219 */
1220 macaddr_b3 ^= (1 << 7);
1221
1222 /* Set locally administered bit */
1223 config->intfMacAddr[i].bytes[0] |= 0x02;
1224 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001225 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001226 MAC_ADDRESS_STR, i,
1227 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1228 }
1229}
1230
Kabilan Kannan44a58372017-12-06 18:16:11 -08001231static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1232{
Dustin Brown1dbefe62018-09-11 16:32:03 -07001233 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001234 struct tdls_start_params tdls_cfg;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001235 struct hdd_config *cfg = hdd_ctx->config;
1236 QDF_STATUS status;
1237
Dustin Brown1dbefe62018-09-11 16:32:03 -07001238 cfg_tdls_set_vdev_nss_2g(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001239 CFG_TDLS_NSS(cfg->vdev_type_nss_2g));
Dustin Brown1dbefe62018-09-11 16:32:03 -07001240 cfg_tdls_set_vdev_nss_5g(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001241 CFG_TDLS_NSS(cfg->vdev_type_nss_5g));
Kabilan Kannan44a58372017-12-06 18:16:11 -08001242 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
1243 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
1244 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
1245 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
1246 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1247 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1248 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1249 tdls_cfg.tdls_evt_cb_data = psoc;
Jeff Johnson1d40f5b2018-03-02 08:35:53 -08001250 tdls_cfg.tdls_peer_context = hdd_ctx;
1251 tdls_cfg.tdls_reg_peer = hdd_tdls_register_peer;
1252 tdls_cfg.tdls_dereg_peer = hdd_tdls_deregister_peer;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001253 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1254 tdls_cfg.tdls_wmm_cb_data = psoc;
1255 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1256 tdls_cfg.tdls_rx_cb_data = psoc;
1257 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1258
1259 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1260 if (status != QDF_STATUS_SUCCESS) {
1261 hdd_err("failed pmo psoc configuration");
1262 return -EINVAL;
1263 }
1264
1265 hdd_ctx->tdls_umac_comp_active = true;
1266 /* enable napier specific tdls data path */
1267 hdd_ctx->tdls_nap_active = true;
1268
1269 return 0;
1270}
1271
Wu Gaoca416ff2018-09-17 11:05:07 +08001272#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1273static void hdd_update_roam_offload(struct hdd_context *hdd_ctx,
1274 struct wma_tgt_services *cfg)
1275{
1276 bool roam_offload_enable;
1277
Dustin Brown1dbefe62018-09-11 16:32:03 -07001278 ucfg_mlme_get_roaming_offload(hdd_ctx->psoc, &roam_offload_enable);
1279 ucfg_mlme_set_roaming_offload(hdd_ctx->psoc,
Wu Gaoca416ff2018-09-17 11:05:07 +08001280 roam_offload_enable &
1281 cfg->en_roam_offload);
1282}
1283#else
1284static inline void hdd_update_roam_offload(struct hdd_context *hdd_ctx,
1285 struct wma_tgt_services *cfg)
1286{
1287}
1288#endif
1289
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001290static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001291 struct wma_tgt_services *cfg)
1292{
1293 struct hdd_config *config = hdd_ctx->config;
Wu Gao66454f12018-09-26 19:55:41 +08001294 bool arp_offload_enable;
Wu Gaobdb7f272018-07-05 19:33:26 +08001295#ifdef FEATURE_WLAN_TDLS
1296 bool tdls_support;
1297 bool tdls_off_channel;
1298 bool tdls_buffer_sta;
1299 uint32_t tdls_uapsd_mask;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05301300 bool value;
Wu Gaobdb7f272018-07-05 19:33:26 +08001301#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001302 /* Set up UAPSD */
1303 config->apUapsdEnabled &= cfg->uapsd;
1304
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001305 /* 11AX mode support */
1306 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1307 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1308 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1309
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001310 /* 11AC mode support */
1311 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1312 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1313 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001314
1315 /* ARP offload: override user setting if invalid */
Wu Gao66454f12018-09-26 19:55:41 +08001316 arp_offload_enable =
1317 ucfg_pmo_is_arp_offload_enabled(hdd_ctx->psoc);
1318 ucfg_pmo_set_arp_offload_enabled(hdd_ctx->psoc,
1319 arp_offload_enable & cfg->arp_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001320#ifdef FEATURE_WLAN_SCAN_PNO
1321 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001322 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001323 if (cfg->pno_offload)
1324 config->PnoOffload = true;
1325#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001326#ifdef FEATURE_WLAN_TDLS
Dustin Brown1dbefe62018-09-11 16:32:03 -07001327 cfg_tdls_get_support_enable(hdd_ctx->psoc, &tdls_support);
1328 cfg_tdls_set_support_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001329 tdls_support & cfg->en_tdls);
1330
Dustin Brown1dbefe62018-09-11 16:32:03 -07001331 cfg_tdls_get_off_channel_enable(hdd_ctx->psoc, &tdls_off_channel);
1332 cfg_tdls_set_off_channel_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001333 tdls_off_channel &&
1334 cfg->en_tdls_offchan);
1335
Dustin Brown1dbefe62018-09-11 16:32:03 -07001336 cfg_tdls_get_buffer_sta_enable(hdd_ctx->psoc, &tdls_buffer_sta);
1337 cfg_tdls_set_buffer_sta_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001338 tdls_buffer_sta &&
1339 cfg->en_tdls_uapsd_buf_sta);
1340
Dustin Brown1dbefe62018-09-11 16:32:03 -07001341 cfg_tdls_get_uapsd_mask(hdd_ctx->psoc, &tdls_uapsd_mask);
Wu Gaobdb7f272018-07-05 19:33:26 +08001342 if (tdls_uapsd_mask && cfg->en_tdls_uapsd_sleep_sta)
Dustin Brown1dbefe62018-09-11 16:32:03 -07001343 cfg_tdls_set_sleep_sta_enable(hdd_ctx->psoc, true);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001344 else
Dustin Brown1dbefe62018-09-11 16:32:03 -07001345 cfg_tdls_set_sleep_sta_enable(hdd_ctx->psoc, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001346#endif
Wu Gaoca416ff2018-09-17 11:05:07 +08001347 hdd_update_roam_offload(hdd_ctx, cfg);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05301348
Dustin Brown05d81302018-09-11 16:49:22 -07001349 if (ucfg_mlme_get_sap_get_peer_info(hdd_ctx->psoc, &value) ==
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05301350 QDF_STATUS_SUCCESS)
1351 value &= cfg->get_peer_info_enabled;
1352
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001353 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001354 hdd_update_tdls_config(hdd_ctx);
Jeff Johnson16528362018-06-14 12:34:16 -07001355 sme_update_tgt_services(hdd_ctx->mac_handle, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001356}
1357
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001358/**
1359 * hdd_update_vdev_nss() - sets the vdev nss
1360 * @hdd_ctx: HDD context
1361 *
1362 * Sets the Nss per vdev type based on INI
1363 *
1364 * Return: None
1365 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001366static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001367{
1368 struct hdd_config *cfg_ini = hdd_ctx->config;
1369 uint8_t max_supp_nss = 1;
Jeff Johnson16528362018-06-14 12:34:16 -07001370 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301371 QDF_STATUS status;
1372 bool bval;
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001373
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301374 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
1375 if (!QDF_IS_STATUS_SUCCESS(status))
1376 hdd_err("unable to get vht_enable2x2");
1377
1378 if (bval && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001379 max_supp_nss = 2;
Liangwei Dong22810e82018-03-15 03:42:12 -04001380 hdd_debug("max nss %d vdev_type_nss_2g %x vdev_type_nss_5g %x",
1381 max_supp_nss, cfg_ini->vdev_type_nss_2g,
1382 cfg_ini->vdev_type_nss_5g);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001383
Jeff Johnson16528362018-06-14 12:34:16 -07001384 mac_handle = hdd_ctx->mac_handle;
1385 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
1386 cfg_ini->vdev_type_nss_2g, BAND_2G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001387
Jeff Johnson16528362018-06-14 12:34:16 -07001388 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
1389 cfg_ini->vdev_type_nss_5g, BAND_5G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001390}
1391
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301392/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301393 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1394 * @hdd_ctx: HDD context
1395 *
1396 * Updates wiphy vhtcap fields
1397 *
1398 * Return: None
1399 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001400static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301401{
1402 struct ieee80211_supported_band *band_5g =
1403 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301404 QDF_STATUS status;
1405 uint8_t value = 0, value1 = 0;
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301406
1407 if (!band_5g) {
1408 hdd_debug("5GHz band disabled, skipping capability population");
1409 return;
1410 }
1411
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301412 status = ucfg_mlme_cfg_get_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
1413 &value);
1414 if (!QDF_IS_STATUS_SUCCESS(status))
1415 hdd_err("unable to get tx_bfee_ant_supp");
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301416
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301417 band_5g->vht_cap.cap |= (value << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1418
1419 value1 = NUM_OF_SOUNDING_DIMENSIONS;
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301420 band_5g->vht_cap.cap |=
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301421 (value1 << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301422
Dustin Brown7e761c72018-07-31 13:50:17 -07001423 hdd_debug("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301424 band_5g->vht_cap.cap, value, value1);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301425}
1426
1427/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301428 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1429 * @hdd_ctx: HDD context
1430 *
1431 * Sets the DBS capability as per INI and firmware capability
1432 *
1433 * Return: None
1434 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001435static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301436{
1437 struct hdd_config *cfg_ini = hdd_ctx->config;
1438 uint8_t hw_dbs_capable = 0;
1439
Dustin Brown1dbefe62018-09-11 16:32:03 -07001440 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->psoc) &&
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001441 ((cfg_ini->dual_mac_feature_disable ==
1442 ENABLE_DBS_CXN_AND_SCAN) ||
1443 (cfg_ini->dual_mac_feature_disable ==
Tushnim Bhattacharyyaaececb22018-08-06 14:27:46 -07001444 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF) ||
1445 (cfg_ini->dual_mac_feature_disable ==
1446 ENABLE_DBS_CXN_AND_DISABLE_SIMULTANEOUS_SCAN)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301447 hw_dbs_capable = 1;
1448
Jeff Johnson16528362018-06-14 12:34:16 -07001449 sme_update_hw_dbs_capable(hdd_ctx->mac_handle, hw_dbs_capable);
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301450}
1451
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001452static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001453 struct wma_tgt_ht_cap *cfg)
1454{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301455 QDF_STATUS status;
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301456 qdf_size_t value_len;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301457 uint32_t value;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301458 struct mlme_ht_capabilities_info ht_cap_info;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001459 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301460 mac_handle_t mac_handle = hdd_ctx->mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301461 bool b_enable1x1;
Jeff Johnson16528362018-06-14 12:34:16 -07001462
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001463 /* get the MPDU density */
Jeff Johnson16528362018-06-14 12:34:16 -07001464 status = sme_cfg_get_int(mac_handle, WNI_CFG_MPDU_DENSITY, &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001465
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301466 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001467 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001468 value = 0;
1469 }
1470
1471 /*
1472 * MPDU density:
1473 * override user's setting if value is larger
1474 * than the one supported by target
1475 */
1476 if (value > cfg->mpdu_density) {
Jeff Johnson16528362018-06-14 12:34:16 -07001477 status = sme_cfg_set_int(mac_handle, WNI_CFG_MPDU_DENSITY,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001478 cfg->mpdu_density);
1479
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301480 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001481 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001482 }
1483
1484 /* get the HT capability info */
Dustin Brown1dbefe62018-09-11 16:32:03 -07001485 status = ucfg_mlme_get_ht_cap_info(hdd_ctx->psoc, &ht_cap_info);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301486 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001487 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001488 return;
1489 }
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301490
1491 /* check and update RX STBC */
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301492 if (ht_cap_info.rx_stbc && !cfg->ht_rx_stbc)
1493 ht_cap_info.rx_stbc = cfg->ht_rx_stbc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001494
1495 /* Set the LDPC capability */
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301496 ht_cap_info.adv_coding_cap = cfg->ht_rx_ldpc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001497
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301498 if (ht_cap_info.short_gi_20_mhz && !cfg->ht_sgi_20)
1499 ht_cap_info.short_gi_20_mhz = cfg->ht_sgi_20;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001500
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301501 if (ht_cap_info.short_gi_40_mhz && !cfg->ht_sgi_40)
1502 ht_cap_info.short_gi_40_mhz = cfg->ht_sgi_40;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001503
1504 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1505 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1506
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301507 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &b_enable1x1);
1508 if (!QDF_IS_STATUS_SUCCESS(status))
1509 hdd_err("unable to get vht_enable2x2");
1510
1511 b_enable1x1 = b_enable1x1 && (cfg->num_rf_chains == 2);
1512
1513 status = ucfg_mlme_set_vht_enable2x2(hdd_ctx->psoc, b_enable1x1);
1514 if (!QDF_IS_STATUS_SUCCESS(status))
1515 hdd_err("unable to set vht_enable2x2");
1516
1517 if (b_enable1x1 == false) {
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301518 ht_cap_info.tx_stbc = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001519
1520 /* 1x1 */
1521 /* Update Rx Highest Long GI data Rate */
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301522 status = ucfg_mlme_cfg_set_vht_rx_supp_data_rate(
1523 hdd_ctx->psoc,
1524 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1);
1525 if (!QDF_IS_STATUS_SUCCESS(status))
1526 hdd_err("Failed to set rx_supp_data_rate");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001527 /* Update Tx Highest Long GI data Rate */
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301528 status = ucfg_mlme_cfg_set_vht_tx_supp_data_rate(
1529 hdd_ctx->psoc,
1530 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1);
1531 if (!QDF_IS_STATUS_SUCCESS(status))
1532 hdd_err("Failed to set tx_supp_data_rate");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001533 }
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301534 if (!(cfg->ht_tx_stbc && b_enable1x1))
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301535 ht_cap_info.tx_stbc = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001536
Dustin Brown1dbefe62018-09-11 16:32:03 -07001537 status = ucfg_mlme_set_ht_cap_info(hdd_ctx->psoc, ht_cap_info);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301538 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001539 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001540#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301541 value_len = SIZE_OF_SUPPORTED_MCS_SET;
1542 if (ucfg_mlme_get_supported_mcs_set(
1543 hdd_ctx->psoc, mcs_set,
1544 &value_len) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001545 hdd_debug("Read MCS rate set");
gaurank kathpalia18b49362018-04-15 23:12:03 +05301546 if (cfg->num_rf_chains > SIZE_OF_SUPPORTED_MCS_SET)
1547 cfg->num_rf_chains = SIZE_OF_SUPPORTED_MCS_SET;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301548
1549 if (b_enable1x1) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001550 for (value = 0; value < cfg->num_rf_chains; value++)
1551 mcs_set[value] =
1552 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1553
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301554 status = ucfg_mlme_set_supported_mcs_set(
1555 hdd_ctx->psoc,
1556 mcs_set,
1557 (qdf_size_t)SIZE_OF_SUPPORTED_MCS_SET);
1558 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001559 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001560 }
1561 }
1562#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1563}
1564
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001565static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001566 struct wma_tgt_vht_cap *cfg)
1567{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301568 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001569 struct wiphy *wiphy = hdd_ctx->wiphy;
1570 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001571 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001572 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001573 struct wma_caps_per_phy caps_per_phy;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301574 uint8_t val = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001575
Dustin Brown5e06bd32016-10-04 12:49:10 -07001576 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001577 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001578 return;
1579 }
1580
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301581 status = ucfg_mlme_update_vht_cap(hdd_ctx->psoc, cfg);
1582 if (QDF_IS_STATUS_ERROR(status))
1583 hdd_err("could not update vht capabilities");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001584
1585 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1586 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1587 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1588 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1589 else
1590 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1591
1592
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001593 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301594 status =
1595 ucfg_mlme_cfg_set_vht_chan_width(hdd_ctx->psoc,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001596 VHT_CAP_160_AND_80P80_SUPP);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301597 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001598 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001599 band_5g->vht_cap.cap |=
1600 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001601 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1602 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301603 status =
1604 ucfg_mlme_cfg_set_vht_chan_width(hdd_ctx->psoc,
1605 VHT_CAP_160_SUPP);
1606 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001607 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001608 band_5g->vht_cap.cap |=
1609 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001610 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1611 }
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001612
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301613 status =
1614 ucfg_mlme_cfg_get_vht_chan_width(hdd_ctx->psoc, &val);
1615 if (QDF_IS_STATUS_ERROR(status))
1616 hdd_err("could not get channel_width");
1617
1618 val = QDF_MIN(val, ch_width);
1619 status =
1620 ucfg_mlme_cfg_set_vht_chan_width(hdd_ctx->psoc, val);
1621 if (QDF_IS_STATUS_ERROR(status))
1622 hdd_err("could not set the channel width");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001623
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001624 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001625 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001626 hdd_debug("VHT RxLDPC capability is set");
1627 } else {
1628 /*
1629 * Get the RX LDPC capability for the NON DBS
1630 * hardware mode for 5G band
1631 */
1632 status = wma_get_caps_for_phyidx_hwmode(&caps_per_phy,
1633 HW_MODE_DBS_NONE, CDS_BAND_5GHZ);
1634 if ((QDF_IS_STATUS_SUCCESS(status)) &&
1635 (caps_per_phy.vht_5g & WMI_VHT_CAP_RX_LDPC)) {
1636 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1637 hdd_debug("VHT RX LDPC capability is set");
1638 }
1639 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001640
1641 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1642 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1643 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1644 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1645
1646 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1647 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1648
1649 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1650 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1651 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1652 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1653 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1654 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1655
1656 band_5g->vht_cap.cap |=
1657 (cfg->vht_max_ampdu_len_exp <<
1658 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1659
1660 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1661 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1662 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1663 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1664 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1665 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1666 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1667 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1668
1669 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1670 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1671
1672}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001673
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001674/**
1675 * hdd_generate_macaddr_auto() - Auto-generate mac address
1676 * @hdd_ctx: Pointer to the HDD context
1677 *
1678 * Auto-generate mac address using device serial number.
1679 * Keep the first 3 bytes of OUI as before and replace
1680 * the last 3 bytes with the lower 3 bytes of serial number.
1681 *
1682 * Return: 0 for success
1683 * Non zero failure code for errors
1684 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001685static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001686{
1687 unsigned int serialno = 0;
1688 struct qdf_mac_addr mac_addr = {
1689 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1690 };
1691
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001692 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001693 if (serialno == 0)
1694 return -EINVAL;
1695
1696 serialno &= 0x00ffffff;
1697
1698 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1699 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1700 mac_addr.bytes[5] = serialno & 0xff;
1701
1702 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1703 return 0;
1704}
1705
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301706/**
1707 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1708 * configuration to cfg_ini in HDD
1709 * @hdd_ctx: Pointer to hdd_ctx
1710 * @cfg: target configuration
1711 *
1712 * Return: None
1713 */
1714#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001715static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301716 struct wma_tgt_cfg *cfg)
1717{
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05301718 ucfg_fwol_set_is_rate_limit_enabled(hdd_ctx->psoc,
1719 cfg->is_ra_rate_limit_enabled);
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301720}
1721#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001722static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301723 struct wma_tgt_cfg *cfg)
1724{
1725}
1726#endif
1727
Jeff Johnsonf9176382018-07-17 19:15:58 -07001728static void hdd_sar_target_config(struct hdd_context *hdd_ctx,
1729 struct wma_tgt_cfg *cfg)
1730{
1731 hdd_ctx->sar_version = cfg->sar_version;
1732}
1733
Jeff Johnson8abc5932018-06-02 22:51:37 -07001734void hdd_update_tgt_cfg(hdd_handle_t hdd_handle, struct wma_tgt_cfg *cfg)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001735{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001736 int ret;
Jeff Johnsonea70b942018-07-02 09:42:31 -07001737 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301738 uint8_t temp_band_cap, band_capability;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001739 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301740 uint8_t antenna_mode;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301741 uint8_t sub_20_chan_width;
Arif Hussainee10f902017-12-27 16:30:17 -08001742 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -07001743 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301744 bool bval = false;
1745 uint8_t value = 0;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301746
gaurank kathpalia843f7c32018-07-02 18:04:14 +05301747 if (!hdd_ctx) {
1748 hdd_err("HDD context is NULL");
1749 return;
1750 }
Dustin Brownbd68fe12017-11-21 15:28:52 -08001751 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1752 if (ret) {
Dustin Brown64204d22018-08-15 16:35:19 -07001753 QDF_DEBUG_PANIC("Failed to create pdev; errno:%d", ret);
1754 return;
1755 }
1756
1757 hdd_debug("New pdev has been created with pdev_id = %u",
Dustin Brown07901ec2018-09-07 11:02:41 -07001758 hdd_ctx->pdev->pdev_objmgr.wlan_pdev_id);
Dustin Brown64204d22018-08-15 16:35:19 -07001759
Dustin Brown07901ec2018-09-07 11:02:41 -07001760 status = dispatcher_pdev_open(hdd_ctx->pdev);
Dustin Brown64204d22018-08-15 16:35:19 -07001761 if (QDF_IS_STATUS_ERROR(status)) {
1762 QDF_DEBUG_PANIC("dispatcher pdev open failed; status:%d",
1763 status);
1764 return;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301765 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001766
Sandeep Puligillab7beb472018-08-13 22:54:20 -07001767 status = hdd_component_pdev_open(hdd_ctx->pdev);
1768 if (QDF_IS_STATUS_ERROR(status)) {
1769 QDF_DEBUG_PANIC("hdd component pdev open failed; status:%d",
1770 status);
1771 return;
1772 }
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301773 cdp_pdev_set_ctrl_pdev(cds_get_context(QDF_MODULE_ID_SOC),
1774 cds_get_context(QDF_MODULE_ID_TXRX),
Dustin Brown07901ec2018-09-07 11:02:41 -07001775 (struct cdp_ctrl_objmgr_pdev *)hdd_ctx->pdev);
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301776
Dustin Brown07901ec2018-09-07 11:02:41 -07001777 wlan_pdev_set_dp_handle(hdd_ctx->pdev,
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301778 cds_get_context(QDF_MODULE_ID_TXRX));
1779
Will Huang07244172018-05-14 14:23:30 +08001780 hdd_objmgr_update_tgt_max_vdev_psoc(hdd_ctx, cfg->max_intf_count);
1781
Dustin Brown1dbefe62018-09-11 16:32:03 -07001782 ucfg_ipa_set_dp_handle(hdd_ctx->psoc,
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301783 cds_get_context(QDF_MODULE_ID_SOC));
Dustin Brown1dbefe62018-09-11 16:32:03 -07001784 ucfg_ipa_set_txrx_handle(hdd_ctx->psoc,
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301785 cds_get_context(QDF_MODULE_ID_TXRX));
Dustin Brown07901ec2018-09-07 11:02:41 -07001786 ucfg_ipa_reg_sap_xmit_cb(hdd_ctx->pdev,
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301787 hdd_softap_hard_start_xmit);
Dustin Brown07901ec2018-09-07 11:02:41 -07001788 ucfg_ipa_reg_send_to_nw_cb(hdd_ctx->pdev,
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301789 hdd_ipa_send_skb_to_network);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301790
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301791 status = ucfg_mlme_get_sub_20_chan_width(hdd_ctx->psoc,
1792 &sub_20_chan_width);
1793 if (QDF_IS_STATUS_ERROR(status)) {
1794 hdd_err("Failed to get sub_20_chan_width config");
1795 return;
1796 }
1797
Naveen Rawat64e477e2016-05-20 10:34:56 -07001798 if (cds_cfg) {
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301799 if (sub_20_chan_width !=
1800 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
Naveen Rawat64e477e2016-05-20 10:34:56 -07001801 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1802 cds_cfg->sub_20_channel_width =
1803 WLAN_SUB_20_CH_WIDTH_NONE;
1804 } else {
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301805 cds_cfg->sub_20_channel_width = sub_20_chan_width;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001806 }
1807 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001808
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301809 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
1810 if (QDF_IS_STATUS_ERROR(status)) {
1811 hdd_err("Failed to get MLME band capability");
1812 return;
1813 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001814
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301815 /* first store the INI band capability */
1816 temp_band_cap = band_capability;
1817
1818 band_capability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301819 hdd_ctx->is_fils_roaming_supported =
1820 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001821
Vignesh Viswanathan694e28e2018-01-18 20:53:57 +05301822 hdd_ctx->config->is_11k_offload_supported =
1823 cfg->services.is_11k_offload_supported;
1824
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001825 /*
1826 * now overwrite the target band capability with INI
1827 * setting if INI setting is a subset
1828 */
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301829 if ((band_capability == BAND_ALL) &&
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001830 (temp_band_cap != BAND_ALL))
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301831 band_capability = temp_band_cap;
1832 else if ((band_capability != BAND_ALL) &&
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001833 (temp_band_cap != BAND_ALL) &&
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301834 (band_capability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001835 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001836 }
1837
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301838 status = ucfg_mlme_set_band_capability(hdd_ctx->psoc, band_capability);
1839 if (QDF_IS_STATUS_ERROR(status)) {
1840 hdd_err("Failed to set MLME Band Capability");
1841 return;
1842 }
1843
1844 hdd_ctx->curr_band = band_capability;
Amar Singhal58b45ef2017-08-01 13:43:54 -07001845
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301846 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001847 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1848 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1849 }
1850
1851 /* This can be extended to other configurations like ht, vht cap... */
1852
Anurag Chouhanc5548422016-02-24 18:33:27 +05301853 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001854 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001855 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001856 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001857 static struct qdf_mac_addr default_mac_addr = {
1858 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1859 };
1860 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1861 &default_mac_addr)) {
1862 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1863 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1864 MAC_ADDRESS_STR,
1865 MAC_ADDR_ARRAY(hdd_ctx->config->
1866 intfMacAddr[0].bytes));
1867 } else {
1868 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1869 MAC_ADDRESS_STR,
1870 MAC_ADDR_ARRAY(hdd_ctx->config->
1871 intfMacAddr[0].bytes));
1872 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001873 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001874 }
1875
1876 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001877 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001878
Ryan Hsuc6918552018-05-16 13:29:59 -07001879 hdd_ctx->hw_bd_id = cfg->hw_bd_id;
1880 qdf_mem_copy(&hdd_ctx->hw_bd_info, &cfg->hw_bd_info,
1881 sizeof(cfg->hw_bd_info));
1882
Dustin Brownbee82832018-07-23 10:10:51 -07001883 if (cfg->max_intf_count > CSR_ROAM_SESSION_MAX) {
1884 hdd_err("fw max vdevs (%u) > host max vdevs (%u); using %u",
1885 cfg->max_intf_count, CSR_ROAM_SESSION_MAX,
1886 CSR_ROAM_SESSION_MAX);
1887 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
1888 } else {
1889 hdd_ctx->max_intf_count = cfg->max_intf_count;
1890 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001891
Jeff Johnsonf9176382018-07-17 19:15:58 -07001892 hdd_sar_target_config(hdd_ctx, cfg);
Jeff Johnsonc875e242016-09-23 18:12:34 -07001893 hdd_lpass_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001894
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001895 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1896 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1897
1898 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1899
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001900 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001901 if (cfg->services.en_11ax) {
1902 hdd_info("11AX: 11ax is enabled - update HDD config");
1903 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1904 }
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -07001905 hdd_update_tgt_twt_cap(hdd_ctx, cfg);
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001906
1907 hdd_update_vdev_nss(hdd_ctx);
1908
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301909 hdd_update_hw_dbs_capable(hdd_ctx);
1910
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001911 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001912 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001913 hdd_debug("fine_time_meas_cap: 0x%x",
Arif Hussainee10f902017-12-27 16:30:17 -08001914 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001915
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301916 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
1917 if (!QDF_IS_STATUS_SUCCESS(status))
1918 hdd_err("unable to get vht_enable2x2");
1919
1920 antenna_mode = (bval == 0x01) ?
Nitesh Shahe50711f2017-04-26 16:30:45 +05301921 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1922 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001923 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08001924 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001925
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05301926 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301927 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301928
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301929 status = ucfg_mlme_cfg_get_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
1930 &value);
1931 if (QDF_IS_STATUS_ERROR(status)) {
1932 status = false;
1933 hdd_err("set tx_bfee_ant_supp failed");
1934 }
1935
1936 if ((value >
Arif Hussainee10f902017-12-27 16:30:17 -08001937 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301938 !cfg->tx_bfee_8ss_enabled) {
1939 status =
1940 ucfg_mlme_cfg_set_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
1941 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF);
1942 if (QDF_IS_STATUS_ERROR(status)) {
1943 status = false;
1944 hdd_err("set tx_bfee_ant_supp failed");
1945 }
1946 }
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301947
Jeff Johnson16528362018-06-14 12:34:16 -07001948 mac_handle = hdd_ctx->mac_handle;
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301949
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301950 hdd_debug("txBFCsnValue %d", value);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301951
1952 /*
1953 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
1954 */
1955 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05301956
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05301957 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
1958
Yue Macd359b72017-10-03 15:21:00 -07001959 /*
1960 * This needs to be done after HDD pdev is created and stored since
1961 * it will access the HDD pdev object lock.
1962 */
1963 hdd_runtime_suspend_context_init(hdd_ctx);
1964
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07001965 /* Configure NAN datapath features */
1966 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07001967 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08001968 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Liangwei Dong0da14262018-07-03 03:30:23 -04001969 hdd_ctx->obss_scan_offload = cfg->services.obss_scan_offload;
Jeff Johnson16528362018-06-14 12:34:16 -07001970 status = sme_cfg_set_int(mac_handle, WNI_CFG_OBSS_DETECTION_OFFLOAD,
Arif Hussainee10f902017-12-27 16:30:17 -08001971 cfg->obss_detection_offloaded);
1972 if (QDF_IS_STATUS_ERROR(status))
1973 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Arif Hussain05fb4872018-01-03 16:02:55 -08001974
Jeff Johnson16528362018-06-14 12:34:16 -07001975 status = sme_cfg_set_int(mac_handle,
Arif Hussain05fb4872018-01-03 16:02:55 -08001976 WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD,
1977 cfg->obss_color_collision_offloaded);
1978 if (QDF_IS_STATUS_ERROR(status))
1979 hdd_err("Failed to set WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001980}
1981
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001982bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001983{
Jeff Johnson9d295242017-08-29 14:39:48 -07001984 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07001985 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001986
Jiachao Wuf610d912018-01-23 17:47:32 +08001987 if (!hdd_ctx) {
1988 hdd_info("Couldn't get hdd_ctx");
1989 return true;
1990 }
1991
1992 if (hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07001993 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08001994 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05301995 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08001996 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001997
Dustin Brown920397d2017-12-13 16:27:50 -08001998 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08001999 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2000
2001 if ((QDF_SAP_MODE == adapter->device_mode ||
2002 QDF_P2P_GO_MODE == adapter->device_mode) &&
Dustin Brown07901ec2018-09-07 11:02:41 -07002003 (wlan_reg_is_passive_or_disable_ch(hdd_ctx->pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002004 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002005 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2006 true;
2007 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07002008 adapter->session_id);
bings6fb9bf62018-07-05 14:01:53 +08002009 if (adapter->txrx_vdev)
2010 cdp_fc_vdev_flush(
2011 cds_get_context(QDF_MODULE_ID_SOC),
bings0e03a982018-05-09 08:40:59 +08002012 adapter->txrx_vdev);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302013 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002014 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302015
2016 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002017}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002018
2019/**
2020 * hdd_is_valid_mac_address() - validate MAC address
2021 * @pMacAddr: Pointer to the input MAC address
2022 *
2023 * This function validates whether the given MAC address is valid or not
2024 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
2025 * where X is the hexa decimal digit character and separated by ':'
2026 * This algorithm works even if MAC address is not separated by ':'
2027 *
2028 * This code checks given input string mac contains exactly 12 hexadecimal
2029 * digits and a separator colon : appears in the input string only after
2030 * an even number of hex digits.
2031 *
2032 * Return: 1 for valid and 0 for invalid
2033 */
2034bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
2035{
2036 int xdigit = 0;
2037 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002038
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002039 while (*pMacAddr) {
2040 if (isxdigit(*pMacAddr)) {
2041 xdigit++;
2042 } else if (':' == *pMacAddr) {
2043 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2044 break;
2045
2046 ++separator;
2047 } else {
2048 /* Invalid MAC found */
2049 return 0;
2050 }
2051 ++pMacAddr;
2052 }
2053 return xdigit == 12 && (separator == 5 || separator == 0);
2054}
2055
2056/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302057 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2058 * @dev: Handle to struct net_device to be updated.
2059 *
2060 * Return: None
2061 */
2062static void hdd_mon_mode_ether_setup(struct net_device *dev)
2063{
2064 dev->header_ops = NULL;
2065 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2066 dev->hard_header_len = ETH_HLEN;
2067 dev->mtu = ETH_DATA_LEN;
2068 dev->addr_len = ETH_ALEN;
2069 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2070 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2071 dev->priv_flags |= IFF_TX_SKB_SHARING;
2072
2073 memset(dev->broadcast, 0xFF, ETH_ALEN);
2074}
2075
Nirav Shah73713f72018-05-17 14:50:41 +05302076#ifdef FEATURE_MONITOR_MODE_SUPPORT
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302077/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002078 * __hdd__mon_open() - HDD Open function
2079 * @dev: Pointer to net_device structure
2080 *
2081 * This is called in response to ifconfig up
2082 *
2083 * Return: 0 for success; non-zero for failure
2084 */
2085static int __hdd_mon_open(struct net_device *dev)
2086{
2087 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002088 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2089 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002090
Dustin Brownfdf17c12018-03-14 12:55:34 -07002091 hdd_enter_dev(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002092
2093 ret = wlan_hdd_validate_context(hdd_ctx);
2094 if (ret)
2095 return ret;
2096
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302097 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002098
2099 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Browne7e71d32018-05-11 16:00:08 -07002100 ret = hdd_wlan_start_modules(hdd_ctx, false);
Ravi Joshia307f632017-07-17 23:41:41 -07002101 if (ret) {
2102 hdd_err("Failed to start WLAN modules return");
2103 return ret;
2104 }
2105 hdd_err("hdd_wlan_start_modules() successful !");
2106
2107 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2108 ret = hdd_start_adapter(adapter);
2109 if (ret) {
2110 hdd_err("Failed to start adapter :%d",
2111 adapter->device_mode);
2112 return ret;
2113 }
2114 hdd_err("hdd_start_adapters() successful !");
2115 }
2116 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2117 }
2118
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002119 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002120
2121 if (!ret)
2122 ret = hdd_enable_monitor_mode(dev);
2123
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002124 return ret;
2125}
2126
2127/**
2128 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2129 * @dev: Pointer to net_device structure
2130 *
2131 * This is called in response to ifconfig up
2132 *
2133 * Return: 0 for success; non-zero for failure
2134 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002135static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002136{
2137 int ret;
2138
2139 cds_ssr_protect(__func__);
2140 ret = __hdd_mon_open(dev);
2141 cds_ssr_unprotect(__func__);
2142
2143 return ret;
2144}
Nirav Shah73713f72018-05-17 14:50:41 +05302145#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002146
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002147static QDF_STATUS
2148wlan_hdd_update_dbs_scan_and_fw_mode_config(void)
2149{
2150 struct policy_mgr_dual_mac_config cfg = {0};
2151 QDF_STATUS status;
Krunal Soni13b50f82018-09-27 12:37:03 -07002152 uint32_t channel_select_logic_conc = 0;
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002153 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2154
2155 if (!hdd_ctx) {
2156 hdd_err("HDD context is NULL");
2157 return QDF_STATUS_E_FAILURE;
2158 }
2159
2160
Dustin Brown1dbefe62018-09-11 16:32:03 -07002161 if (!policy_mgr_is_hw_dbs_capable(hdd_ctx->psoc))
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002162 return QDF_STATUS_SUCCESS;
2163
2164 cfg.scan_config = 0;
2165 cfg.fw_mode_config = 0;
2166 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Krunal Soni13b50f82018-09-27 12:37:03 -07002167 ucfg_policy_mgr_get_chnl_select_plcy(hdd_ctx->psoc,
2168 &channel_select_logic_conc);
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002169
2170 if (hdd_ctx->config->dual_mac_feature_disable !=
2171 DISABLE_DBS_CXN_AND_SCAN) {
2172 status = policy_mgr_get_updated_scan_and_fw_mode_config(
Dustin Brown1dbefe62018-09-11 16:32:03 -07002173 hdd_ctx->psoc, &cfg.scan_config,
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002174 &cfg.fw_mode_config,
2175 hdd_ctx->config->dual_mac_feature_disable,
2176 channel_select_logic_conc);
2177
2178 if (status != QDF_STATUS_SUCCESS) {
2179 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
2180 status);
2181 return status;
2182 }
2183 }
2184
2185 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
2186 cfg.scan_config, cfg.fw_mode_config);
2187
2188 status = sme_soc_set_dual_mac_config(cfg);
2189 if (status != QDF_STATUS_SUCCESS) {
2190 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
2191 return status;
2192 }
2193
2194 return QDF_STATUS_SUCCESS;
2195}
2196
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002197/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302198 * hdd_start_adapter() - Wrapper function for device specific adapter
2199 * @adapter: pointer to HDD adapter
2200 *
2201 * This function is called to start the device specific adapter for
2202 * the mode passed in the adapter's device_mode.
2203 *
2204 * Return: 0 for success; non-zero for failure
2205 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002206int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302207{
2208
2209 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002210 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302211
Dustin Brownfdf17c12018-03-14 12:55:34 -07002212 hdd_enter_dev(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002213 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302214
2215 switch (device_mode) {
2216 case QDF_P2P_CLIENT_MODE:
2217 case QDF_P2P_DEVICE_MODE:
2218 case QDF_OCB_MODE:
2219 case QDF_STA_MODE:
2220 case QDF_MONITOR_MODE:
2221 ret = hdd_start_station_adapter(adapter);
2222 if (ret)
2223 goto err_start_adapter;
Alok Kumar81e1d732018-09-04 11:10:36 +05302224
2225 hdd_nud_ignore_tracking(adapter, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05302226 break;
2227 case QDF_P2P_GO_MODE:
2228 case QDF_SAP_MODE:
2229 ret = hdd_start_ap_adapter(adapter);
2230 if (ret)
2231 goto err_start_adapter;
2232 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302233 case QDF_IBSS_MODE:
2234 /*
2235 * For IBSS interface is initialized as part of
2236 * hdd_init_station_mode()
2237 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002238 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302239 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002240 /* vdevs are dynamically managed by firmware in FTM */
2241 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302242 default:
2243 hdd_err("Invalid session type %d", device_mode);
2244 QDF_ASSERT(0);
2245 goto err_start_adapter;
2246 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002247
Arun Khandavallifae92942016-08-01 13:31:08 +05302248 if (hdd_set_fw_params(adapter))
2249 hdd_err("Failed to set the FW params for the adapter!");
2250
Dustin Browne7e71d32018-05-11 16:00:08 -07002251 if (adapter->session_id != HDD_SESSION_ID_INVALID) {
2252 ret = wlan_hdd_cfg80211_register_frames(adapter);
2253 if (ret < 0) {
2254 hdd_err("Failed to register frames - ret %d", ret);
2255 goto err_start_adapter;
2256 }
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302257 }
Dustin Browne7e71d32018-05-11 16:00:08 -07002258
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002259 wlan_hdd_update_dbs_scan_and_fw_mode_config();
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302260
Dustin Browndb2a8be2017-12-20 11:49:56 -08002261exit_with_success:
Dustin Browne74003f2018-03-14 12:51:58 -07002262 hdd_exit();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002263
Arun Khandavallifae92942016-08-01 13:31:08 +05302264 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002265
Arun Khandavallifae92942016-08-01 13:31:08 +05302266err_start_adapter:
2267 return -EINVAL;
2268}
2269
2270/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302271 * hdd_enable_power_management() - API to Enable Power Management
2272 *
2273 * API invokes Bus Interface Layer power management functionality
2274 *
2275 * Return: None
2276 */
2277static void hdd_enable_power_management(void)
2278{
2279 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2280
2281 if (!hif_ctx) {
2282 hdd_err("Bus Interface Context is Invalid");
2283 return;
2284 }
2285
2286 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2287}
2288
2289/**
2290 * hdd_disable_power_management() - API to disable Power Management
2291 *
2292 * API disable Bus Interface Layer Power management functionality
2293 *
2294 * Return: None
2295 */
2296static void hdd_disable_power_management(void)
2297{
2298 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2299
2300 if (!hif_ctx) {
2301 hdd_err("Bus Interface Context is Invalid");
2302 return;
2303 }
2304
2305 hif_disable_power_management(hif_ctx);
2306}
2307
Ryan Hsuaadba072018-04-20 13:01:53 -07002308void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302309{
2310 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002311 size_t target_hw_name_len;
2312 const char *target_hw_name;
Ryan Hsuaadba072018-04-20 13:01:53 -07002313 uint8_t *buf;
2314 uint32_t buf_len;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302315
2316 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2317 if (!hif_sc) {
2318 hdd_err("HIF context is NULL");
2319 return;
2320 }
2321
Ryan Hsuaadba072018-04-20 13:01:53 -07002322 hif_get_hw_info(hif_sc, &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302323 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002324 &target_hw_name);
2325
2326 if (hdd_ctx->target_hw_name)
2327 qdf_mem_free(hdd_ctx->target_hw_name);
2328
2329 target_hw_name_len = strlen(target_hw_name) + 1;
2330 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2331 if (hdd_ctx->target_hw_name)
2332 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2333 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302334
Ryan Hsuaadba072018-04-20 13:01:53 -07002335 buf = qdf_mem_malloc(WE_MAX_STR_LEN);
2336 if (buf) {
2337 buf_len = hdd_wlan_get_version(hdd_ctx, WE_MAX_STR_LEN, buf);
2338 hdd_info("%s", buf);
2339 qdf_mem_free(buf);
2340 }
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302341}
2342
2343/**
gbian62edd7e2017-03-07 13:12:13 +08002344 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2345 * @hdd_ctx: Pointer to hdd context
2346 *
2347 * Return: none
2348 */
2349static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002350hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002351{
2352 uint8_t num_entries = 0;
2353 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2354 uint8_t *tx_sched_wrr_ac;
2355 int i;
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002356 struct cds_context *cds_ctx;
gbian62edd7e2017-03-07 13:12:13 +08002357
2358 if (NULL == hdd_ctx)
2359 return;
2360
2361 if (NULL == hdd_ctx->config) {
2362 /* Do nothing if hdd_ctx is invalid */
2363 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2364 return;
2365 }
2366
2367 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2368
2369 if (!cds_ctx) {
2370 hdd_err("Invalid CDS Context");
2371 return;
2372 }
2373
2374 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2375 switch (i) {
2376 case OL_TX_WMM_AC_BE:
2377 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2378 break;
2379 case OL_TX_WMM_AC_BK:
2380 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2381 break;
2382 case OL_TX_WMM_AC_VI:
2383 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2384 break;
2385 case OL_TX_WMM_AC_VO:
2386 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2387 break;
2388 default:
2389 tx_sched_wrr_ac = NULL;
2390 break;
2391 }
2392
2393 hdd_string_to_u8_array(tx_sched_wrr_ac,
2394 tx_sched_wrr_param,
2395 &num_entries,
2396 sizeof(tx_sched_wrr_param));
2397
2398 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2399 cds_ctx->ac_specs[i].wrr_skip_weight =
2400 tx_sched_wrr_param[0];
2401 cds_ctx->ac_specs[i].credit_threshold =
2402 tx_sched_wrr_param[1];
2403 cds_ctx->ac_specs[i].send_limit =
2404 tx_sched_wrr_param[2];
2405 cds_ctx->ac_specs[i].credit_reserve =
2406 tx_sched_wrr_param[3];
2407 cds_ctx->ac_specs[i].discard_weight =
2408 tx_sched_wrr_param[4];
2409 }
2410
2411 num_entries = 0;
2412 }
2413}
2414
Ryan Hsuaadba072018-04-20 13:01:53 -07002415uint32_t hdd_wlan_get_version(struct hdd_context *hdd_ctx,
2416 const size_t version_len, uint8_t *version)
2417{
2418 uint32_t size;
2419 uint32_t msp_id = 0, mspid = 0, siid = 0, crmid = 0, sub_id = 0;
2420
2421 if (!hdd_ctx) {
2422 hdd_err("Invalid context, HDD context is null");
2423 return 0;
2424 }
2425
Ashish Kumar Dhanotiya7353f882018-05-15 12:50:19 +05302426 if (!version || version_len == 0) {
Ryan Hsuaadba072018-04-20 13:01:53 -07002427 hdd_err("Invalid buffer pointr or buffer len\n");
2428 return 0;
2429 }
2430
2431 msp_id = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
2432 mspid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
2433 siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
2434 crmid = hdd_ctx->target_fw_version & 0x7fff;
2435 sub_id = (hdd_ctx->target_fw_vers_ext & 0xf0000000) >> 28;
2436
2437 size = scnprintf(version, version_len,
Ryan Hsuc6918552018-05-16 13:29:59 -07002438 "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 -07002439 QWLAN_VERSIONSTR,
2440 msp_id, mspid, siid, crmid, sub_id,
Ryan Hsuc6918552018-05-16 13:29:59 -07002441 hdd_ctx->target_hw_name,
2442 hdd_ctx->hw_bd_info.bdf_version,
2443 hdd_ctx->hw_bd_info.ref_design_id,
2444 hdd_ctx->hw_bd_info.customer_id,
2445 hdd_ctx->hw_bd_info.project_id,
2446 hdd_ctx->hw_bd_info.board_data_rev);
Ryan Hsuaadba072018-04-20 13:01:53 -07002447
2448 return size;
2449}
2450
Rachit Kankane0dc3e852018-05-07 17:33:42 +05302451int hdd_set_11ax_rate(struct hdd_adapter *adapter, int set_value,
2452 struct sap_config *sap_config)
2453{
2454 uint8_t preamble = 0, nss = 0, rix = 0;
2455 int ret;
2456 mac_handle_t mac_handle = adapter->hdd_ctx->mac_handle;
2457
2458 if (!sap_config) {
2459 if (!sme_is_feature_supported_by_fw(DOT11AX)) {
2460 hdd_err("Target does not support 11ax");
2461 return -EIO;
2462 }
2463 } else if (sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax &&
2464 sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax_ONLY) {
2465 hdd_err("Invalid hw mode, SAP hw_mode= 0x%x, ch = %d",
2466 sap_config->SapHw_mode, sap_config->channel);
2467 return -EIO;
2468 }
2469
2470 if (set_value != 0xff) {
2471 rix = RC_2_RATE_IDX_11AX(set_value);
2472 preamble = WMI_RATE_PREAMBLE_HE;
2473 nss = HT_RC_2_STREAMS_11AX(set_value);
2474
2475 set_value = hdd_assemble_rate_code(preamble, nss, rix);
2476 } else {
2477 ret = sme_set_auto_rate_he_ltf(mac_handle, adapter->session_id,
2478 QCA_WLAN_HE_LTF_AUTO);
2479 }
2480
2481 hdd_info("SET_11AX_RATE val %d rix %d preamble %x nss %d",
2482 set_value, rix, preamble, nss);
2483
2484 ret = wma_cli_set_command(adapter->session_id,
2485 WMI_VDEV_PARAM_FIXED_RATE,
2486 set_value, VDEV_CMD);
2487
2488 return ret;
2489}
2490
2491int hdd_assemble_rate_code(uint8_t preamble, uint8_t nss, uint8_t rate)
2492{
2493 int set_value;
2494
2495 if (sme_is_feature_supported_by_fw(DOT11AX))
2496 set_value = WMI_ASSEMBLE_RATECODE_V1(rate, nss, preamble);
2497 else
2498 set_value = (preamble << 6) | (nss << 4) | rate;
2499
2500 return set_value;
2501}
2502
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002503#ifdef FEATURE_WLAN_WAPI
2504/**
2505 * hdd_wapi_security_sta_exist() - return wapi security sta exist or not
2506 *
2507 * This API returns the wapi security station exist or not
2508 *
2509 * Return: true - wapi security station exist
2510 */
2511static bool hdd_wapi_security_sta_exist(void)
2512{
2513 struct hdd_adapter *adapter = NULL;
2514 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2515
2516 hdd_for_each_adapter(hdd_ctx, adapter) {
2517 if ((adapter->device_mode == QDF_STA_MODE) &&
2518 adapter->wapi_info.wapi_mode &&
2519 (adapter->wapi_info.wapi_auth_mode != WAPI_AUTH_MODE_OPEN))
2520 return true;
2521 }
2522 return false;
2523}
2524#else
2525static bool hdd_wapi_security_sta_exist(void)
2526{
2527 return false;
2528}
2529#endif
2530
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002531#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002532static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2533 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2534{
Jeff Johnson9d295242017-08-29 14:39:48 -07002535 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002536 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002537
2538 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2539 if (!adapter) {
2540 hdd_err("Adapter is NULL");
2541 return PM_MAX_NUM_OF_MODE;
2542 }
2543
2544 return policy_mgr_convert_device_mode_to_qdf_type(
2545 adapter->device_mode);
2546}
2547
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002548static void hdd_register_policy_manager_callback(
2549 struct wlan_objmgr_psoc *psoc)
2550{
2551 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002552
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002553 qdf_mem_zero(&hdd_cbacks, sizeof(hdd_cbacks));
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002554 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002555 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002556 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2557 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002558 hdd_cbacks.get_mode_for_non_connected_vdev =
2559 wlan_hdd_get_mode_for_non_connected_vdev;
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05302560 hdd_cbacks.hdd_get_device_mode = hdd_get_device_mode;
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002561 hdd_cbacks.hdd_wapi_security_sta_exist =
2562 hdd_wapi_security_sta_exist;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002563 if (QDF_STATUS_SUCCESS !=
2564 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2565 hdd_err("HDD callback registration with policy manager failed");
2566 }
2567}
2568#else
2569static void hdd_register_policy_manager_callback(
2570 struct wlan_objmgr_psoc *psoc)
2571{
2572}
2573#endif
2574
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002575static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002576{
2577 struct nan_callbacks cb_obj = {0};
2578
2579 cb_obj.ndi_open = hdd_ndi_open;
2580 cb_obj.ndi_close = hdd_ndi_close;
2581 cb_obj.ndi_start = hdd_ndi_start;
2582 cb_obj.ndi_delete = hdd_ndi_delete;
2583 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2584 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2585
Naveen Rawat37f62c82017-03-26 22:24:43 -07002586 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2587 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002588 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002589
Dustin Brown1dbefe62018-09-11 16:32:03 -07002590 os_if_nan_register_hdd_callbacks(hdd_ctx->psoc, &cb_obj);
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002591}
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002592
Dustin Brown26b3d042017-12-21 11:13:27 -08002593#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002594/**
2595 * hdd_check_for_leaks() - Perform runtime memory leak checks
Dustin Browna6246dd2018-05-24 14:35:58 -07002596 * @hdd_ctx: the global HDD context
Dustin Brown29533f22018-07-24 13:11:56 -07002597 * @is_ssr: true if SSR is in progress
Dustin Brown4c5b9902017-12-19 11:17:19 -08002598 *
2599 * This API triggers runtime memory leak detection. This feature enforces the
2600 * policy that any memory allocated at runtime must also be released at runtime.
2601 *
2602 * Allocating memory at runtime and releasing it at unload is effectively a
2603 * memory leak for configurations which never unload (e.g. LONU, statically
2604 * compiled driver). Such memory leaks are NOT false positives, and must be
2605 * fixed.
2606 *
2607 * Return: None
2608 */
Dustin Brown29533f22018-07-24 13:11:56 -07002609static void hdd_check_for_leaks(struct hdd_context *hdd_ctx, bool is_ssr)
Dustin Brown4bc0a622017-12-06 15:56:50 -08002610{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002611 /* DO NOT REMOVE these checks; for false positives, read above first */
2612
Dustin Brown1dbefe62018-09-11 16:32:03 -07002613 wlan_objmgr_psoc_check_for_peer_leaks(hdd_ctx->psoc);
2614 wlan_objmgr_psoc_check_for_vdev_leaks(hdd_ctx->psoc);
2615 wlan_objmgr_psoc_check_for_pdev_leaks(hdd_ctx->psoc);
Dustin Brown29533f22018-07-24 13:11:56 -07002616
2617 /* many adapter resources are not freed by design during SSR */
2618 if (is_ssr)
2619 return;
2620
Dustin Brown677e0862017-10-10 16:30:09 -07002621 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002622 qdf_nbuf_map_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002623 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002624}
2625
Dustin Brown26b3d042017-12-21 11:13:27 -08002626#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2627#else
Dustin Brown29533f22018-07-24 13:11:56 -07002628static inline void hdd_check_for_leaks(struct hdd_context *hdd_ctx, bool is_ssr)
2629{ }
Dustin Brown26b3d042017-12-21 11:13:27 -08002630
2631#define hdd_debug_domain_set(domain)
2632#endif /* CONFIG_LEAK_DETECTION */
2633
gbian62edd7e2017-03-07 13:12:13 +08002634/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002635 * hdd_update_country_code - Update country code
2636 * @hdd_ctx: HDD context
2637 *
2638 * Update country code based on module parameter country_code
2639 *
2640 * Return: 0 on success and errno on failure
2641 */
2642static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2643{
2644 if (!country_code)
2645 return 0;
2646
2647 return hdd_reg_set_country(hdd_ctx, country_code);
2648}
2649
2650/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302651 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2652 * @hdd_ctx: HDD context
Arun Khandavallifae92942016-08-01 13:31:08 +05302653 * @reinit: flag to indicate from SSR or normal path
2654 *
2655 * This function maintains the driver state machine it will be invoked from
2656 * startup, reinit and change interface. Depending on the driver state shall
2657 * perform the opening of the modules.
2658 *
2659 * Return: 0 for success; non-zero for failure
2660 */
Dustin Browne7e71d32018-05-11 16:00:08 -07002661int hdd_wlan_start_modules(struct hdd_context *hdd_ctx, bool reinit)
Arun Khandavallifae92942016-08-01 13:31:08 +05302662{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002663 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302664 qdf_device_t qdf_dev;
2665 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302666 bool unint = false;
2667 void *hif_ctx;
Jingxiang Ge95912f82018-04-19 12:01:26 +08002668 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +05302669
Arun Khandavallifae92942016-08-01 13:31:08 +05302670 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2671 if (!qdf_dev) {
2672 hdd_err("QDF Device Context is Invalid return");
2673 return -EINVAL;
2674 }
2675
Dustin Brown6f427922017-09-19 12:19:00 -07002676 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05302677
Dustin Brown1fe30a82017-10-03 16:13:36 -07002678 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302679 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2680 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002681 hdd_debug("Driver modules already Enabled");
Dustin Browne74003f2018-03-14 12:51:58 -07002682 hdd_exit();
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302683 return 0;
2684 }
2685
Dustin Brown1fe30a82017-10-03 16:13:36 -07002686 hdd_ctx->start_modules_in_progress = true;
2687
Arun Khandavallifae92942016-08-01 13:31:08 +05302688 switch (hdd_ctx->driver_status) {
2689 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002690 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302691 unint = true;
2692 /* Fall through dont add break here */
2693 case DRIVER_MODULES_CLOSED:
Dustin Brown1a20b082018-08-03 17:27:15 -07002694 hdd_info("Wlan transitioning (CLOSED -> ENABLED)");
Dustin Brown550f6d22017-12-14 15:44:01 -08002695
Dustin Brown26b3d042017-12-21 11:13:27 -08002696 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002697
Arun Khandavallifae92942016-08-01 13:31:08 +05302698 if (!reinit && !unint) {
2699 ret = pld_power_on(qdf_dev->dev);
2700 if (ret) {
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002701 hdd_err("Failed to power up device; errno:%d",
Dustin Browndca39692017-11-09 15:30:25 -08002702 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302703 goto release_lock;
2704 }
2705 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002706
2707 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2708 hdd_ctx->config->enable_fw_log);
Arun Khandavallifae92942016-08-01 13:31:08 +05302709 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2710 qdf_dev->bus_type,
2711 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2712 HIF_ENABLE_TYPE_PROBE);
2713 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002714 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302715 goto power_down;
2716 }
2717
2718 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302719 if (!hif_ctx) {
2720 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002721 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302722 goto power_down;
2723 }
2724
Arun Khandavallifae92942016-08-01 13:31:08 +05302725 status = ol_cds_init(qdf_dev, hif_ctx);
2726 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002727 hdd_err("No Memory to Create BMI Context; status: %d",
2728 status);
2729 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302730 goto hif_close;
2731 }
2732
jitiphil4c256a32018-09-07 08:51:52 +05302733 ucfg_ipa_component_config_update(hdd_ctx->psoc);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302734
gbian62edd7e2017-03-07 13:12:13 +08002735 hdd_update_cds_ac_specs_params(hdd_ctx);
2736
Dustin Brown1dbefe62018-09-11 16:32:03 -07002737 status = hdd_component_psoc_open(hdd_ctx->psoc);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05302738 if (QDF_IS_STATUS_ERROR(status)) {
2739 hdd_err("Failed to Open legacy components; status: %d",
2740 status);
2741 ret = qdf_status_to_os_return(status);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05302742 goto cds_free;
2743 }
2744
2745 ret = hdd_update_config(hdd_ctx);
2746 if (ret) {
2747 hdd_err("Failed to update configuration; errno: %d",
2748 ret);
2749 goto cds_free;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05302750 }
2751
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +05302752 status = wbuff_module_init();
2753 if (QDF_IS_STATUS_ERROR(status))
2754 hdd_err("WBUFF init unsuccessful; status: %d", status);
2755
Dustin Brown1dbefe62018-09-11 16:32:03 -07002756 status = cds_open(hdd_ctx->psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002757 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002758 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002759 ret = qdf_status_to_os_return(status);
Krunal Sonie71838d2018-09-27 10:45:05 -07002760 goto psoc_close;
Arun Khandavallifae92942016-08-01 13:31:08 +05302761 }
2762
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +05302763 hdd_ctx->mac_handle = cds_get_context(QDF_MODULE_ID_SME);
2764
Manjunathappa Prakashb6b4ff12018-06-04 12:32:33 -07002765 if (hdd_ctx->config->rx_thread_affinity_mask)
2766 cds_set_rx_thread_cpu_mask(
2767 hdd_ctx->config->rx_thread_affinity_mask);
2768
2769 /* initialize components configurations after psoc open */
Mukul Sharma9d797a02017-01-05 20:26:03 +05302770 ret = hdd_update_components_config(hdd_ctx);
2771 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002772 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302773 ret);
2774 goto close;
2775 }
Dustin Brown1dbefe62018-09-11 16:32:03 -07002776 status = cds_dp_open(hdd_ctx->psoc);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002777 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002778 hdd_err("Failed to Open cds post open; status: %d",
2779 status);
2780 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002781 goto close;
2782 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302783
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002784 /*
2785 * NAN compoenet requires certian operations like, open adapter,
2786 * close adapter, etc. to be initiated by HDD, for those
2787 * register HDD callbacks with UMAC's NAN componenet.
2788 */
2789 hdd_nan_register_callbacks(hdd_ctx);
2790
Jeff Johnson3a280122017-09-13 07:42:00 -07002791 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302792 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002793 hdd_err("Failed to pre-enable CDS; status: %d", status);
2794 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002795 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302796 }
2797
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002798 hdd_register_policy_manager_callback(
Dustin Brown1dbefe62018-09-11 16:32:03 -07002799 hdd_ctx->psoc);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002800
Dustin Brown1dbefe62018-09-11 16:32:03 -07002801 hdd_sysfs_create_version_interface(hdd_ctx->psoc);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302802 hdd_update_hw_sw_info(hdd_ctx);
Dustin Brown550f6d22017-12-14 15:44:01 -08002803
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302804 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2805 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002806 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302807 break;
2808 }
Dustin Browndca39692017-11-09 15:30:25 -08002809
Dustin Browne7e71d32018-05-11 16:00:08 -07002810 ret = hdd_configure_cds(hdd_ctx);
Dustin Browndca39692017-11-09 15:30:25 -08002811 if (ret) {
2812 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002813 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302814 }
Dustin Browndca39692017-11-09 15:30:25 -08002815
Komal Seelamf2136bb2016-09-28 18:30:44 +05302816 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002817
Arun Khandavallifae92942016-08-01 13:31:08 +05302818 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002819
Arun Khandavallifae92942016-08-01 13:31:08 +05302820 default:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002821 QDF_DEBUG_PANIC("Unknown driver state:%d",
Arun Khandavallifae92942016-08-01 13:31:08 +05302822 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002823 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302824 goto release_lock;
2825 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002826
Dustin Brown1a20b082018-08-03 17:27:15 -07002827 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2828 hdd_info("Wlan transitioned (now ENABLED)");
2829
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302830 hdd_ctx->start_modules_in_progress = false;
Dustin Brownad698ae2018-09-05 17:19:30 -07002831
Arun Khandavallifae92942016-08-01 13:31:08 +05302832 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002833
Dustin Browne74003f2018-03-14 12:51:58 -07002834 hdd_exit();
Dustin Brown550f6d22017-12-14 15:44:01 -08002835
Arun Khandavallifae92942016-08-01 13:31:08 +05302836 return 0;
2837
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002838post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002839 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002840
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002841cds_txrx_free:
Dustin Brown1dbefe62018-09-11 16:32:03 -07002842 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->psoc);
Jingxiang Ge95912f82018-04-19 12:01:26 +08002843
2844 if (tgt_hdl && target_psoc_get_wmi_ready(tgt_hdl)) {
2845 hdd_runtime_suspend_context_deinit(hdd_ctx);
Dustin Brown07901ec2018-09-07 11:02:41 -07002846 dispatcher_pdev_close(hdd_ctx->pdev);
Jingxiang Ge95912f82018-04-19 12:01:26 +08002847 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
2848 }
2849
Dustin Brown1dbefe62018-09-11 16:32:03 -07002850 cds_dp_close(hdd_ctx->psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08002851
Arun Khandavallifae92942016-08-01 13:31:08 +05302852close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002853 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002854 hdd_info("Wlan transition aborted (now CLOSED)");
2855
Dustin Brown1dbefe62018-09-11 16:32:03 -07002856 cds_close(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302857
Krunal Sonie71838d2018-09-27 10:45:05 -07002858psoc_close:
Dustin Brown1dbefe62018-09-11 16:32:03 -07002859 hdd_component_psoc_close(hdd_ctx->psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002860 cds_deinit_ini_config();
2861
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002862cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302863 ol_cds_free();
2864
2865hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002866 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2867 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302868power_down:
2869 if (!reinit && !unint)
2870 pld_power_off(qdf_dev->dev);
2871release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302872 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302873 mutex_unlock(&hdd_ctx->iface_change_lock);
Abhinav Kumar7ae9b7b2017-12-19 15:11:54 +05302874 if (hdd_ctx->target_hw_name) {
2875 qdf_mem_free(hdd_ctx->target_hw_name);
2876 hdd_ctx->target_hw_name = NULL;
2877 }
Dustin Brown29533f22018-07-24 13:11:56 -07002878
2879 hdd_check_for_leaks(hdd_ctx, reinit);
Dustin Brown26b3d042017-12-21 11:13:27 -08002880 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002881
Dustin Browne74003f2018-03-14 12:51:58 -07002882 hdd_exit();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002883
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002884 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302885}
2886
Naveen Rawat910726a2017-03-06 11:42:51 -08002887#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002888static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002889{
2890 int ret = os_if_wifi_pos_register_nl();
2891
2892 if (ret)
2893 hdd_err("os_if_wifi_pos_register_nl failed");
2894
2895 return ret;
2896}
2897
2898static int hdd_deactivate_wifi_pos(void)
2899{
2900 int ret = os_if_wifi_pos_deregister_nl();
2901
2902 if (ret)
2903 hdd_err("os_if_wifi_pos_deregister_nl failed");
2904
2905 return ret;
2906}
2907
2908/**
2909 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2910 * @hdd_ctx: hdd context
2911 *
2912 * Return: status of operation
2913 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002914static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002915{
Dustin Brown1dbefe62018-09-11 16:32:03 -07002916 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Naveen Rawat910726a2017-03-06 11:42:51 -08002917 struct hdd_config *cfg = hdd_ctx->config;
2918
2919 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2920 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2921 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2922 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2923 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2924 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2925 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2926 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2927}
2928#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002929static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002930{
2931 return oem_activate_service(hdd_ctx);
2932}
2933
2934static int hdd_deactivate_wifi_pos(void)
2935{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05302936 return oem_deactivate_service();
Naveen Rawat910726a2017-03-06 11:42:51 -08002937}
2938
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002939static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002940{
2941}
2942#endif
2943
Arun Khandavallifae92942016-08-01 13:31:08 +05302944/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002945 * __hdd_open() - HDD Open function
2946 * @dev: Pointer to net_device structure
2947 *
2948 * This is called in response to ifconfig up
2949 *
2950 * Return: 0 for success; non-zero for failure
2951 */
2952static int __hdd_open(struct net_device *dev)
2953{
Jeff Johnson9d295242017-08-29 14:39:48 -07002954 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002955 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002956 int ret;
2957
Dustin Brownfdf17c12018-03-14 12:55:34 -07002958 hdd_enter_dev(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302959 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002960 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002961
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302962 /* Nothing to be done if device is unloading */
2963 if (cds_is_driver_unloading()) {
2964 hdd_err("Driver is unloading can not open the hdd");
2965 return -EBUSY;
2966 }
2967
Dustin Brown01847752017-10-25 13:56:27 -07002968 if (cds_is_driver_recovering()) {
2969 hdd_err("WLAN is currently recovering; Please try again.");
2970 return -EBUSY;
2971 }
2972
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302973 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
2974 hdd_err("con_mode_handler is in progress; Please try again.");
2975 return -EBUSY;
2976 }
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302977
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302978 mutex_lock(&hdd_init_deinit_lock);
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302979 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
2980
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302981 /*
2982 * This scenario can be hit in cases where in the wlan driver after
2983 * registering the netdevices and there is a failure in driver
2984 * initialization. So return error gracefully because the netdevices
2985 * will be de-registered as part of the load failure.
2986 */
2987
2988 if (!cds_is_driver_loaded()) {
2989 hdd_err("Failed to start the wlan driver!!");
2990 ret = -EIO;
2991 goto err_hdd_hdd_init_deinit_lock;
2992 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302993
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002994
Dustin Browne7e71d32018-05-11 16:00:08 -07002995 ret = hdd_wlan_start_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05302996 if (ret) {
2997 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302998 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302999 }
3000
3001
3002 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3003 ret = hdd_start_adapter(adapter);
3004 if (ret) {
3005 hdd_err("Failed to start adapter :%d",
3006 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303007 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05303008 }
3009 }
3010
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003011 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3012 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003013 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003014 /* Enable TX queues only when we are connected */
3015 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05303016 WLAN_START_ALL_NETIF_QUEUE,
3017 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003018 }
3019
Naveen Rawat286def52016-09-23 15:38:02 -07003020 /* Enable carrier and transmit queues for NDI */
3021 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003022 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07003023 wlan_hdd_netif_queue_control(adapter,
3024 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
3025 WLAN_CONTROL_PATH);
3026 }
3027
Naveen Rawat910726a2017-03-06 11:42:51 -08003028 hdd_populate_wifi_pos_cfg(hdd_ctx);
Arunk Khandavalli40943af2017-05-15 19:25:34 +05303029 hdd_lpass_notify_start(hdd_ctx, adapter);
Naveen Rawat910726a2017-03-06 11:42:51 -08003030
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303031err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05303032 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303033 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003034 return ret;
3035}
3036
Arun Khandavallifae92942016-08-01 13:31:08 +05303037
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003038/**
3039 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
3040 * @dev: Pointer to net_device structure
3041 *
3042 * This is called in response to ifconfig up
3043 *
3044 * Return: 0 for success; non-zero for failure
3045 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003046static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003047{
3048 int ret;
3049
3050 cds_ssr_protect(__func__);
3051 ret = __hdd_open(dev);
3052 cds_ssr_unprotect(__func__);
3053
3054 return ret;
3055}
3056
3057/**
3058 * __hdd_stop() - HDD stop function
3059 * @dev: Pointer to net_device structure
3060 *
3061 * This is called in response to ifconfig down
3062 *
3063 * Return: 0 for success; non-zero for failure
3064 */
3065static int __hdd_stop(struct net_device *dev)
3066{
Jeff Johnson9d295242017-08-29 14:39:48 -07003067 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003068 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003069 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -07003070 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003071
Dustin Brownfdf17c12018-03-14 12:55:34 -07003072 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003073
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303074 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003075 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003076
3077 ret = wlan_hdd_validate_context(hdd_ctx);
Arunk Khandavalli987c8d52018-06-21 17:40:31 +05303078 if (ret) {
3079 set_bit(DOWN_DURING_SSR, &adapter->event_flags);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003080 return ret;
Arunk Khandavalli987c8d52018-06-21 17:40:31 +05303081 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003082
3083 /* Nothing to be done if the interface is not opened */
3084 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003085 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003086 return -ENODEV;
3087 }
3088
3089 /* Make sure the interface is marked as closed */
3090 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303091
Jeff Johnson16528362018-06-14 12:34:16 -07003092 mac_handle = hdd_ctx->mac_handle;
3093
Mukul Sharmad16c2022017-07-25 18:56:12 +05303094 hdd_debug("Disabling Auto Power save timer");
3095 sme_ps_disable_auto_ps_timer(
Jeff Johnson16528362018-06-14 12:34:16 -07003096 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003097 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303098
3099 /*
3100 * Disable TX on the interface, after this hard_start_xmit() will not
3101 * be called on that interface
3102 */
Dustin Browna7bb6ae2018-08-16 16:51:50 -07003103 hdd_debug("Disabling queues, adapter device mode: %s(%d)",
3104 hdd_device_mode_to_string(adapter->device_mode),
3105 adapter->device_mode);
Kabilan Kannan8dac3502017-10-30 12:40:27 -07003106
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303107 wlan_hdd_netif_queue_control(adapter,
3108 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3109 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003110
Arunk Khandavalli40943af2017-05-15 19:25:34 +05303111 if (adapter->device_mode == QDF_STA_MODE)
3112 hdd_lpass_notify_stop(hdd_ctx);
3113
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003114 /*
Naveen Rawat286def52016-09-23 15:38:02 -07003115 * NAN data interface is different in some sense. The traffic on NDI is
3116 * bursty in nature and depends on the need to transfer. The service
3117 * layer may down the interface after the usage and up again when
3118 * required. In some sense, the NDI is expected to be available
3119 * (like SAP) iface until NDI delete request is issued by the service
3120 * layer. Skip BSS termination and adapter deletion for NAN Data
3121 * interface (NDI).
3122 */
3123 if (WLAN_HDD_IS_NDI(adapter))
3124 return 0;
3125
3126 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003127 * The interface is marked as down for outside world (aka kernel)
3128 * But the driver is pretty much alive inside. The driver needs to
3129 * tear down the existing connection on the netdev (session)
3130 * cleanup the data pipes and wait until the control plane is stabilized
3131 * for this interface. The call also needs to wait until the above
3132 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003133 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003134 * That is intentional to be able to scan if it is a STA/P2P interface
3135 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08003136 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003137
3138 /* DeInit the adapter. This ensures datapath cleanup as well */
3139 hdd_deinit_adapter(hdd_ctx, adapter, true);
3140
Arun Khandavallifae92942016-08-01 13:31:08 +05303141
3142 /*
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +05303143 * Upon wifi turn off, DUT has to flush the scan results so if
3144 * this is the last cli iface, flush the scan database.
3145 */
3146 if (!hdd_is_cli_iface_up(hdd_ctx))
Jeff Johnson16528362018-06-14 12:34:16 -07003147 sme_scan_flush_result(mac_handle);
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +05303148
3149 /*
Arun Khandavallifae92942016-08-01 13:31:08 +05303150 * Find if any iface is up. If any iface is up then can't put device to
3151 * sleep/power save mode
3152 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05303153 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003154 hdd_debug("Closing all modules from the hdd_stop");
Dustin Brown6f427922017-09-19 12:19:00 -07003155 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
3156 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05303157 hdd_prevent_suspend_timeout(
3158 hdd_ctx->config->iface_change_wait_time,
3159 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05303160 }
3161
Dustin Browne74003f2018-03-14 12:51:58 -07003162 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003163 return 0;
3164}
3165
3166/**
3167 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3168 * @dev: pointer to net_device structure
3169 *
3170 * This is called in response to ifconfig down
3171 *
3172 * Return: 0 for success and error number for failure
3173 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003174static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003175{
3176 int ret;
3177
3178 cds_ssr_protect(__func__);
3179 ret = __hdd_stop(dev);
3180 cds_ssr_unprotect(__func__);
3181
3182 return ret;
3183}
3184
3185/**
3186 * __hdd_uninit() - HDD uninit function
3187 * @dev: Pointer to net_device structure
3188 *
3189 * This is called during the netdev unregister to uninitialize all data
3190 * associated with the device
3191 *
3192 * Return: None
3193 */
3194static void __hdd_uninit(struct net_device *dev)
3195{
Jeff Johnson9d295242017-08-29 14:39:48 -07003196 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003197 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003198
Dustin Brownfdf17c12018-03-14 12:55:34 -07003199 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003200
3201 do {
3202 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003203 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003204 break;
3205 }
3206
Jeff Johnson399c6272017-08-30 10:51:00 -07003207 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3208 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003209 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003210 break;
3211 }
3212
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003213 if (dev != adapter->dev)
3214 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003215
Jeff Johnson399c6272017-08-30 10:51:00 -07003216 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003217
3218 /* after uninit our adapter structure will no longer be valid */
3219 adapter->dev = NULL;
3220 adapter->magic = 0;
3221 } while (0);
3222
Dustin Browne74003f2018-03-14 12:51:58 -07003223 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003224}
3225
3226/**
3227 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
3228 * @dev: pointer to net_device structure
3229 *
3230 * This is called during the netdev unregister to uninitialize all data
3231 * associated with the device
3232 *
3233 * Return: none
3234 */
3235static void hdd_uninit(struct net_device *dev)
3236{
3237 cds_ssr_protect(__func__);
3238 __hdd_uninit(dev);
3239 cds_ssr_unprotect(__func__);
3240}
3241
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003242static int hdd_open_cesium_nl_sock(void)
3243{
3244#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3245 struct netlink_kernel_cfg cfg = {
3246 .groups = WLAN_NLINK_MCAST_GRP_ID,
3247 .input = NULL
3248 };
3249#endif
3250 int ret = 0;
3251
3252#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3253 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3254#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3255 THIS_MODULE,
3256#endif
3257 &cfg);
3258#else
3259 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3260 WLAN_NLINK_MCAST_GRP_ID,
3261 NULL, NULL, THIS_MODULE);
3262#endif
3263
3264 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003265 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003266 ret = -ECONNREFUSED;
3267 }
3268
3269 return ret;
3270}
3271
3272static void hdd_close_cesium_nl_sock(void)
3273{
3274 if (NULL != cesium_nl_srv_sock) {
3275 netlink_kernel_release(cesium_nl_srv_sock);
3276 cesium_nl_srv_sock = NULL;
3277 }
3278}
3279
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003280/**
3281 * __hdd_set_mac_address() - set the user specified mac address
3282 * @dev: Pointer to the net device.
3283 * @addr: Pointer to the sockaddr.
3284 *
3285 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003286 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003287 *
3288 * Return: 0 for success, non zero for failure
3289 */
3290static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3291{
Jeff Johnson9d295242017-08-29 14:39:48 -07003292 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303293 struct hdd_adapter *adapter_temp;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003294 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003295 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303296 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003297 int ret;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303298 struct qdf_mac_addr mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003299
Dustin Brownfdf17c12018-03-14 12:55:34 -07003300 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003301
Hanumanth Reddy Pothula5c7a7812018-03-09 12:55:32 +05303302 if (netif_running(dev)) {
3303 hdd_err("On iface up, set mac address change isn't supported");
3304 return -EBUSY;
3305 }
3306
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003307 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3308 ret = wlan_hdd_validate_context(hdd_ctx);
3309 if (0 != ret)
3310 return ret;
3311
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303312 qdf_mem_copy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303313 adapter_temp = hdd_get_adapter_by_macaddr(hdd_ctx, mac_addr.bytes);
3314 if (adapter_temp) {
3315 if (!qdf_str_cmp(adapter_temp->dev->name, dev->name))
3316 return 0;
3317 hdd_err("%s adapter exist with same address " MAC_ADDRESS_STR,
3318 adapter_temp->dev->name,
Ashish Kumar Dhanotiyaf974f332018-04-19 16:03:15 +05303319 MAC_ADDR_ARRAY(mac_addr.bytes));
3320 return -EINVAL;
3321 }
3322
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05303323 qdf_ret_status = wlan_hdd_validate_mac_address(&mac_addr);
3324 if (QDF_IS_STATUS_ERROR(qdf_ret_status))
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303325 return -EINVAL;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303326
Ashish Kumar Dhanotiya8bfef122018-04-18 16:48:27 +05303327 hdd_info("Changing MAC to " MAC_ADDRESS_STR " of the interface %s ",
3328 MAC_ADDR_ARRAY(mac_addr.bytes), dev->name);
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303329
Jeff Johnson1e851a12017-10-28 14:36:12 -07003330 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003331 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3332
Dustin Browne74003f2018-03-14 12:51:58 -07003333 hdd_exit();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303334 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003335}
3336
3337/**
3338 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3339 * function from SSR
3340 * @dev: pointer to net_device structure
3341 * @addr: Pointer to the sockaddr
3342 *
3343 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003344 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003345 *
3346 * Return: 0 for success.
3347 */
3348static int hdd_set_mac_address(struct net_device *dev, void *addr)
3349{
3350 int ret;
3351
3352 cds_ssr_protect(__func__);
3353 ret = __hdd_set_mac_address(dev, addr);
3354 cds_ssr_unprotect(__func__);
3355
3356 return ret;
3357}
3358
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003359uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003360{
3361 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003362
Anurag Chouhan6d760662016-02-20 16:05:43 +05303363 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003364 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
3365 break;
3366 }
3367
Anurag Chouhan6d760662016-02-20 16:05:43 +05303368 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003369 return NULL;
3370
3371 hdd_ctx->config->intfAddrMask |= (1 << i);
3372 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
3373}
3374
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003375void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3376 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003377{
3378 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003379
Anurag Chouhan6d760662016-02-20 16:05:43 +05303380 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003381 if (!memcmp(releaseAddr,
3382 &hdd_ctx->config->intfMacAddr[i].bytes[0],
3383 6)) {
3384 hdd_ctx->config->intfAddrMask &= ~(1 << i);
3385 break;
3386 }
3387 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003388}
3389
3390#ifdef WLAN_FEATURE_PACKET_FILTERING
3391/**
3392 * __hdd_set_multicast_list() - set the multicast address list
3393 * @dev: Pointer to the WLAN device.
3394 * @skb: Pointer to OS packet (sk_buff).
3395 *
3396 * This funciton sets the multicast address list.
3397 *
3398 * Return: None
3399 */
3400static void __hdd_set_multicast_list(struct net_device *dev)
3401{
Jeff Johnson9d295242017-08-29 14:39:48 -07003402 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Dustin Brown0f874482018-06-13 14:39:22 -07003403 int i = 0, errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003404 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003405 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303406 struct pmo_mc_addr_list_params *mc_list_request = NULL;
Dustin Brown1dbefe62018-09-11 16:32:03 -07003407 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303408 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003409
Dustin Brownfdf17c12018-03-14 12:55:34 -07003410 hdd_enter_dev(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303411 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303412 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303413
Dustin Brown0f874482018-06-13 14:39:22 -07003414 errno = wlan_hdd_validate_context(hdd_ctx);
3415 if (errno)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303416 goto out;
3417
Dustin Brown0f874482018-06-13 14:39:22 -07003418 errno = hdd_validate_adapter(adapter);
3419 if (errno)
Dustin Brownc788acb2017-08-01 17:43:51 -07003420 goto out;
3421
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303422 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3423 hdd_err("%s: Driver module is closed", __func__);
Dustin Brown0f874482018-06-13 14:39:22 -07003424 goto out;
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303425 }
3426
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303427 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
3428 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003429 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303430 goto out;
3431 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003432
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303433 /* Delete already configured multicast address list */
3434 if (adapter->mc_addr_list.mc_cnt > 0) {
Dustin Brown0f874482018-06-13 14:39:22 -07003435 hdd_debug("clear previously configured MC address list");
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303436 hdd_disable_and_flush_mc_addr_list(adapter,
3437 pmo_mc_list_change_notify);
3438 }
3439
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003440 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003441 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303442 hdd_disable_and_flush_mc_addr_list(adapter,
3443 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003444 } else {
3445 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303446 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003447 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Dustin Brown0f874482018-06-13 14:39:22 -07003448 pmo_ucfg_max_mc_addr_supported(psoc));
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303449 hdd_disable_and_flush_mc_addr_list(adapter,
3450 pmo_mc_list_change_notify);
Dustin Brown0f874482018-06-13 14:39:22 -07003451 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003452 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003453 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003454 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303455 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003456 if (i == mc_count)
3457 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303458 memset(&(mc_list_request->mc_addr[i].bytes),
3459 0, ETH_ALEN);
3460 memcpy(&(mc_list_request->mc_addr[i].bytes),
3461 ha->addr, ETH_ALEN);
Dustin Brown0f874482018-06-13 14:39:22 -07003462 hdd_debug("mlist[%d] = %pM", i,
3463 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003464 i++;
3465 }
3466 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303467
3468 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003469 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303470 mc_list_request->count = mc_count;
Dustin Brown0f874482018-06-13 14:39:22 -07003471
3472 errno = hdd_cache_mc_addr_list(mc_list_request);
3473 if (errno) {
3474 hdd_err("Failed to cache MC address list for vdev %u; errno:%d",
3475 adapter->session_id, errno);
3476 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003477 }
Dustin Brown0f874482018-06-13 14:39:22 -07003478
3479 hdd_enable_mc_addr_filtering(adapter, pmo_mc_list_change_notify);
3480
3481free_req:
3482 qdf_mem_free(mc_list_request);
3483
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303484out:
Dustin Browne74003f2018-03-14 12:51:58 -07003485 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003486}
3487
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303488
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003489/**
3490 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3491 * @dev: pointer to net_device
3492 *
3493 * Return: none
3494 */
3495static void hdd_set_multicast_list(struct net_device *dev)
3496{
3497 cds_ssr_protect(__func__);
3498 __hdd_set_multicast_list(dev);
3499 cds_ssr_unprotect(__func__);
3500}
3501#endif
3502
3503/**
3504 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3505 * @dev: Pointer to the WLAN device.
3506 * @skb: Pointer to OS packet (sk_buff).
3507 *
3508 * This function is registered with the Linux OS for network
3509 * core to decide which queue to use first.
3510 *
3511 * Return: ac, Queue Index/access category corresponding to UP in IP header
3512 */
3513static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3514#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3515 , void *accel_priv
3516#endif
3517#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3518 , select_queue_fallback_t fallback
3519#endif
3520)
3521{
3522 return hdd_wmm_select_queue(dev, skb);
3523}
3524
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003525static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003526 .ndo_open = hdd_open,
3527 .ndo_stop = hdd_stop,
3528 .ndo_uninit = hdd_uninit,
3529 .ndo_start_xmit = hdd_hard_start_xmit,
3530 .ndo_tx_timeout = hdd_tx_timeout,
3531 .ndo_get_stats = hdd_get_stats,
3532 .ndo_do_ioctl = hdd_ioctl,
3533 .ndo_set_mac_address = hdd_set_mac_address,
3534 .ndo_select_queue = hdd_select_queue,
3535#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003536 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003537#endif
3538};
3539
Nirav Shah73713f72018-05-17 14:50:41 +05303540#ifdef FEATURE_MONITOR_MODE_SUPPORT
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003541/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003542static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003543 .ndo_open = hdd_mon_open,
3544 .ndo_stop = hdd_stop,
3545 .ndo_get_stats = hdd_get_stats,
3546};
3547
3548/**
3549 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003550 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003551 * Return: None
3552 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003553void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003554{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003555 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003556 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003557 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003558 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003559}
Nirav Shah73713f72018-05-17 14:50:41 +05303560#else
3561void hdd_set_station_ops(struct net_device *dev)
3562{
3563 dev->netdev_ops = &wlan_drv_ops;
3564}
3565#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003566
3567/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003568 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3569 * @hdd_ctx: global hdd context
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003570 * @mac_addr: mac address to assign to the interface
Ryan Hsu07495ea2016-01-21 15:25:39 -08003571 * @name: User-visible name of the interface
3572 *
3573 * hdd adapter pointer would point to the netdev->priv space, this function
Jeff Johnson62018292018-05-06 16:18:35 -07003574 * would retrieve the pointer, and setup the hdd adapter configuration.
Ryan Hsu07495ea2016-01-21 15:25:39 -08003575 *
3576 * Return: the pointer to hdd adapter, otherwise NULL
3577 */
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003578static struct hdd_adapter *
3579hdd_alloc_station_adapter(struct hdd_context *hdd_ctx, tSirMacAddr mac_addr,
3580 unsigned char name_assign_type, const char *name)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003581{
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003582 struct net_device *dev;
3583 struct hdd_adapter *adapter;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003584 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303585 QDF_STATUS qdf_status;
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003586
3587 /* cfg80211 initialization and registration */
3588 dev = alloc_netdev_mq(sizeof(*adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003589#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003590 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003591#endif
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003592 (cds_get_conparam() == QDF_GLOBAL_MONITOR_MODE ?
3593 hdd_mon_mode_ether_setup : ether_setup),
3594 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003595
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003596 if (!dev) {
3597 hdd_err("Failed to allocate new net_device '%s'", name);
3598 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003599 }
3600
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003601 adapter = netdev_priv(dev);
3602
3603 qdf_mem_zero(adapter, sizeof(*adapter));
3604 sta_ctx = &adapter->session.station;
3605 qdf_mem_set(sta_ctx->conn_info.staId, sizeof(sta_ctx->conn_info.staId),
3606 HDD_WLAN_INVALID_STA_ID);
3607 adapter->dev = dev;
3608 adapter->hdd_ctx = hdd_ctx;
3609 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
3610 adapter->session_id = HDD_SESSION_ID_INVALID;
3611
3612 qdf_status = qdf_event_create(&adapter->qdf_session_open_event);
3613 if (QDF_IS_STATUS_ERROR(qdf_status))
3614 goto free_net_dev;
3615
3616 qdf_status = qdf_event_create(&adapter->qdf_session_close_event);
3617 if (QDF_IS_STATUS_ERROR(qdf_status))
3618 goto free_net_dev;
3619
3620 adapter->offloads_configured = false;
3621 adapter->is_link_up_service_needed = false;
3622 adapter->disconnection_in_progress = false;
3623 adapter->send_mode_change = true;
3624
3625 /* Init the net_device structure */
3626 strlcpy(dev->name, name, IFNAMSIZ);
3627
3628 qdf_mem_copy(dev->dev_addr, mac_addr, sizeof(tSirMacAddr));
3629 qdf_mem_copy(adapter->mac_addr.bytes, mac_addr, sizeof(tSirMacAddr));
3630 dev->watchdog_timeo = HDD_TX_TIMEOUT;
3631
3632 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
3633 dev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
3634 dev->features |= NETIF_F_RXCSUM;
3635
3636 hdd_set_tso_flags(hdd_ctx, dev);
3637 hdd_set_station_ops(adapter->dev);
3638
3639 hdd_dev_setup_destructor(dev);
3640 dev->ieee80211_ptr = &adapter->wdev;
3641 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
3642 adapter->wdev.wiphy = hdd_ctx->wiphy;
3643 adapter->wdev.netdev = dev;
3644
3645 /* set dev's parent to underlying device */
3646 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
3647 hdd_wmm_init(adapter);
3648 spin_lock_init(&adapter->pause_map_lock);
3649 adapter->start_time = qdf_system_ticks();
3650 adapter->last_time = adapter->start_time;
3651
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003652 return adapter;
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003653
3654free_net_dev:
3655 free_netdev(adapter->dev);
3656
3657 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003658}
3659
Jeff Johnson9d295242017-08-29 14:39:48 -07003660static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003661{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003662 struct net_device *dev = adapter->dev;
3663 int ret;
3664
Dustin Brown491d54b2018-03-14 12:39:11 -07003665 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003666
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003667 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003668 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3669
3670 ret = dev_alloc_name(dev, dev->name);
3671 if (ret < 0) {
3672 hdd_err(
3673 "unable to get dev name: %s, err = 0x%x",
3674 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303675 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003676 }
3677 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003678
3679 ret = register_netdevice(dev);
3680 if (ret) {
3681 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3682 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303683 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003684 }
3685 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003686 ret = register_netdev(dev);
3687 if (ret) {
3688 hdd_err("register_netdev(%s) failed, err = 0x%x",
3689 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303690 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003691 }
3692 }
3693 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3694
Dustin Browne74003f2018-03-14 12:51:58 -07003695 hdd_exit();
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003696
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303697 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003698}
3699
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05303700QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id,
3701 QDF_STATUS qdf_status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003702{
Krunal Sonib51eec72017-11-20 21:53:01 -08003703 struct hdd_adapter *adapter;
3704 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003705
Krunal Sonib51eec72017-11-20 21:53:01 -08003706 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3707 if (!hdd_ctx) {
3708 hdd_err("Invalid HDD_CTX");
3709 return QDF_STATUS_E_FAILURE;
3710 }
3711
3712 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3713 if (NULL == adapter) {
Naveen Rawat23a3b912018-05-30 17:45:52 -07003714 hdd_err("NULL adapter for %d", session_id);
Krunal Sonib51eec72017-11-20 21:53:01 -08003715 return QDF_STATUS_E_INVAL;
3716 }
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05303717
3718 if (qdf_status == QDF_STATUS_SUCCESS)
3719 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3720
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303721 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003722 hdd_debug("session %d opened", adapter->session_id);
3723
3724 return QDF_STATUS_SUCCESS;
3725}
3726
3727QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3728{
3729 struct hdd_adapter *adapter;
3730 struct hdd_context *hdd_ctx;
3731
3732 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3733 if (!hdd_ctx) {
3734 hdd_err("Invalid HDD_CTX");
3735 return QDF_STATUS_E_FAILURE;
3736 }
3737
3738 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003739 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003740 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303741 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003742 }
3743
3744 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003745 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303746 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003747 }
3748
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003749 /*
3750 * For NAN Data interface, the close session results in the final
3751 * indication to the userspace
3752 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003753 if (adapter->device_mode == QDF_NDI_MODE)
3754 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003755
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003756 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3757
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003758 /*
3759 * We can be blocked while waiting for scheduled work to be
3760 * flushed, and the adapter structure can potentially be freed, in
3761 * which case the magic will have been reset. So make sure the
3762 * magic is still good, and hence the adapter structure is still
3763 * valid, before signaling completion
3764 */
3765 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303766 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003767
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303768 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003769}
3770
Jeff Johnson9d295242017-08-29 14:39:48 -07003771int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003772{
Dustin Brownd28772b2017-03-17 14:16:07 -07003773 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003774
Dustin Brown89fa06e2018-09-07 10:47:27 -07003775 status = pmo_vdev_ready(adapter->vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003776 if (QDF_IS_STATUS_ERROR(status))
3777 return qdf_status_to_os_return(status);
3778
Dustin Brown89fa06e2018-09-07 10:47:27 -07003779 status = ucfg_reg_11d_vdev_created_update(adapter->vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003780 if (QDF_IS_STATUS_ERROR(status))
3781 return qdf_status_to_os_return(status);
3782
3783 if (wma_capability_enhanced_mcast_filter())
Dustin Brown89fa06e2018-09-07 10:47:27 -07003784 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003785 else
Dustin Brown89fa06e2018-09-07 10:47:27 -07003786 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003787
3788 return qdf_status_to_os_return(status);
3789}
3790
Jeff Johnson9d295242017-08-29 14:39:48 -07003791int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003792{
3793 QDF_STATUS status;
Dustin Brown2da29eb2018-07-13 14:23:12 -07003794 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003795 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003796 uint8_t vdev_id;
Dustin Brownd28772b2017-03-17 14:16:07 -07003797
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003798 vdev_id = adapter->session_id;
3799 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003800
3801 /* vdev created sanity check */
3802 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Dustin Brown2da29eb2018-07-13 14:23:12 -07003803 hdd_err("vdev %u does not exist", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003804 return -EINVAL;
3805 }
Dustin Brown2da29eb2018-07-13 14:23:12 -07003806
Dustin Brown89fa06e2018-09-07 10:47:27 -07003807 status = ucfg_reg_11d_vdev_delete_update(adapter->vdev);
3808 ucfg_scan_set_vdev_del_in_progress(adapter->vdev);
Yue Maf9782842017-05-08 12:49:49 -07003809
Dustin Brownd28772b2017-03-17 14:16:07 -07003810 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303811 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07003812 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -07003813 status = sme_close_session(hdd_ctx->mac_handle, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003814 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Brown2da29eb2018-07-13 14:23:12 -07003815 hdd_err("failed to close sme session; status:%d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003816 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07003817 }
3818
3819 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303820 status = qdf_wait_for_event_completion(
3821 &adapter->qdf_session_close_event,
3822 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
Dustin Brown2da29eb2018-07-13 14:23:12 -07003823
3824 if (QDF_IS_STATUS_ERROR(status)) {
3825 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3826
Dustin Brownd28772b2017-03-17 14:16:07 -07003827 if (adapter->device_mode == QDF_NDI_MODE)
3828 hdd_ndp_session_end_handler(adapter);
Dustin Brown2da29eb2018-07-13 14:23:12 -07003829
3830 if (status == QDF_STATUS_E_TIMEOUT)
3831 hdd_err("timed out waiting for sme close session");
3832 else if (adapter->qdf_session_close_event.force_set)
3833 hdd_info("SSR occurred during sme close session");
3834 else
3835 hdd_err("failed to wait for sme close session; status:%u",
3836 status);
Dustin Brownd28772b2017-03-17 14:16:07 -07003837 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08003838
Yue Maf9782842017-05-08 12:49:49 -07003839release_vdev:
Dustin Brown89fa06e2018-09-07 10:47:27 -07003840 ucfg_scan_clear_vdev_del_in_progress(adapter->vdev);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003841
Sandeep Puligillaef415362017-08-30 16:37:13 -07003842 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08003843 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003844 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08003845 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003846 return errno;
3847 }
3848
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003849 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003850
3851 return 0;
3852}
3853
Krunal Sonib51eec72017-11-20 21:53:01 -08003854static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
3855 struct sme_session_params *session_param,
Jeff Johnson6a18c962018-07-01 09:09:37 -07003856 csr_roam_complete_cb callback,
Krunal Sonib51eec72017-11-20 21:53:01 -08003857 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07003858{
Dustin Brownd28772b2017-03-17 14:16:07 -07003859 uint32_t type;
3860 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08003861 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07003862
3863 /* determine vdev (sub)type */
3864 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303865 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003866 hdd_err("failed to get vdev type: %d", status);
3867 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003868 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003869 session_param->sme_session_id = adapter->session_id;
3870 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
3871 session_param->type_of_persona = type;
3872 session_param->subtype_of_persona = sub_type;
3873 session_param->session_open_cb = hdd_sme_open_session_callback;
3874 session_param->session_close_cb = hdd_sme_close_session_callback;
3875 session_param->callback = callback;
3876 session_param->callback_ctx = callback_ctx;
3877
3878 return 0;
3879}
3880
3881int hdd_vdev_create(struct hdd_adapter *adapter,
Jeff Johnson6a18c962018-07-01 09:09:37 -07003882 csr_roam_complete_cb callback, void *ctx)
Krunal Sonib51eec72017-11-20 21:53:01 -08003883{
3884 QDF_STATUS status;
3885 int errno;
3886 struct hdd_context *hdd_ctx;
3887 struct sme_session_params sme_session_params = {0};
Krunal Sonib51eec72017-11-20 21:53:01 -08003888
3889 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07003890
3891 /* do vdev create via objmgr */
3892 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown07901ec2018-09-07 11:02:41 -07003893 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003894 if (errno) {
3895 hdd_err("failed to create objmgr vdev: %d", errno);
3896 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003897 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003898
3899 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303900 status = qdf_event_reset(&adapter->qdf_session_open_event);
3901 if (QDF_STATUS_SUCCESS != status) {
3902 hdd_err("failed to reinit session open event");
3903 return -EINVAL;
3904 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003905 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
3906 callback, ctx);
3907 if (errno) {
3908 hdd_err("failed to populating SME params");
3909 goto objmgr_vdev_destroy_procedure;
3910 }
3911
Jeff Johnson16528362018-06-14 12:34:16 -07003912 status = sme_open_session(hdd_ctx->mac_handle, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07003913 if (QDF_IS_STATUS_ERROR(status)) {
3914 hdd_err("failed to open sme session: %d", status);
3915 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07003916 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003917 }
3918
3919 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303920 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
3921 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3922 if (QDF_STATUS_SUCCESS != status) {
3923 if (adapter->qdf_session_open_event.force_set) {
3924 /*
3925 * SSR/PDR has caused shutdown, which has forcefully
3926 * set the event. Return without the closing session.
3927 */
3928 adapter->session_id = HDD_SESSION_ID_INVALID;
3929 hdd_err("Session open event forcefully set");
3930 return -EINVAL;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303931 }
Jeff Johnsonc66d3102018-02-28 11:58:26 -08003932
3933 if (QDF_STATUS_E_TIMEOUT == status)
3934 hdd_err("Session failed to open within timeout period");
3935 else
3936 hdd_err("Failed to wait for session open event(status-%d)",
3937 status);
3938 errno = -ETIMEDOUT;
3939 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3940 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003941 }
3942
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05303943 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3944 hdd_err("Session failed to open due to vdev create failure");
3945 errno = -EINVAL;
3946 goto objmgr_vdev_destroy_procedure;
3947 }
3948
Dustin Brownd28772b2017-03-17 14:16:07 -07003949 /* firmware ready for component communication, raise vdev_ready event */
3950 errno = hdd_vdev_ready(adapter);
3951 if (errno) {
3952 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07003953 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003954 }
3955
Naveen Rawat2b430892018-03-13 13:58:18 -07003956 if (adapter->device_mode == QDF_STA_MODE) {
3957 hdd_debug("setting RTT mac randomization param: %d",
3958 hdd_ctx->config->enable_rtt_mac_randomization);
3959 errno = sme_cli_set_command(adapter->session_id,
3960 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_INITIATOR_RANDOM_MAC,
3961 hdd_ctx->config->enable_rtt_mac_randomization,
3962 VDEV_CMD);
3963 if (0 != errno)
3964 hdd_err("RTT mac randomization param set failed %d",
3965 errno);
3966 }
3967
Bala Venkatesh110b03e2018-07-10 16:02:08 +05303968 if (adapter->device_mode == QDF_STA_MODE ||
3969 adapter->device_mode == QDF_P2P_CLIENT_MODE)
Dustin Brown89fa06e2018-09-07 10:47:27 -07003970 wlan_vdev_set_max_peer_count(adapter->vdev,
Bala Venkatesh110b03e2018-07-10 16:02:08 +05303971 HDD_MAX_VDEV_PEER_COUNT);
3972
Jeff Johnson1b780e42017-10-31 14:11:45 -07003973 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003974
3975 return 0;
3976
3977 /*
3978 * Due to legacy constraints, we need to destroy in the same order as
3979 * create. So, split error handling into 2 cases to accommodate.
3980 */
3981
Krunal Soni4a020c72017-10-30 20:58:40 -07003982objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07003983 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003984
3985 return errno;
3986
Krunal Soni4a020c72017-10-30 20:58:40 -07003987hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07003988 QDF_BUG(!hdd_vdev_destroy(adapter));
3989
3990 return errno;
3991}
3992
Jeff Johnson9d295242017-08-29 14:39:48 -07003993QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003994{
Jeff Johnsonb9424862017-10-30 08:49:35 -07003995 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003996 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003997 QDF_STATUS status;
3998 int ret_val;
Jeff Johnson16528362018-06-14 12:34:16 -07003999 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304000 bool bval = false;
Dustin Brownd28772b2017-03-17 14:16:07 -07004001
Dustin Brownd28772b2017-03-17 14:16:07 -07004002 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -07004003 mac_handle = hdd_ctx->mac_handle;
4004 sme_set_curr_device_mode(mac_handle, adapter->device_mode);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304005 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
4006 if (!QDF_IS_STATUS_SUCCESS(status))
4007 hdd_err("unable to get vht_enable2x2");
4008 sme_set_pdev_ht_vht_ies(mac_handle, bval);
4009
Jeff Johnson16528362018-06-14 12:34:16 -07004010 sme_set_vdev_ies_per_band(mac_handle, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004011
Jeff Johnson7f2c5912018-03-23 11:42:28 -07004012 hdd_roam_profile_init(adapter);
4013 hdd_register_wext(adapter->dev);
4014
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07004015 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004016
Jeff Johnsond377dce2017-10-04 10:32:42 -07004017 qdf_mem_set(sta_ctx->conn_info.staId,
4018 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05304019
Deepak Dhamdherea2785822016-11-17 01:17:45 -08004020 /* set fast roaming capability in sme session */
Jeff Johnson16528362018-06-14 12:34:16 -07004021 status = sme_config_fast_roaming(mac_handle, adapter->session_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05304022 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004023 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004024 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004025 hdd_ctx->config->OperatingChannel;
4026
4027 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004028 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004029
4030 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304031 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004032 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004033 status, status);
4034 goto error_init_txrx;
4035 }
4036
4037 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4038
4039 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304040 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004041 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004042 status, status);
4043 goto error_wmm_init;
4044 }
4045
4046 set_bit(WMM_INIT_DONE, &adapter->event_flags);
4047
Jeff Johnson1b780e42017-10-31 14:11:45 -07004048 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004049 WMI_PDEV_PARAM_BURST_ENABLE,
Dundi Raviteja3aa01be2018-05-21 18:58:59 +05304050 HDD_ENABLE_SIFS_BURST_DEFAULT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004051 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07004052 if (ret_val)
4053 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004054
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05304055 /*
4056 * In case of USB tethering, LRO is disabled. If SSR happened
4057 * during that time, then as part of SSR init, do not enable
4058 * the LRO again. Keep the LRO state same as before SSR.
4059 */
Alok Kumar90a73092018-08-03 13:55:09 +05304060 if (hdd_ctx->config->lro_enable &&
4061 !(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07004062 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05304063
4064 /* rcpi info initialization */
4065 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
4066
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304067 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004068
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004069error_wmm_init:
4070 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4071 hdd_deinit_tx_rx(adapter);
4072error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07004073 hdd_unregister_wext(adapter->dev);
Dustin Brownd28772b2017-03-17 14:16:07 -07004074 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004075
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004076 return status;
4077}
4078
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304079/**
Krunal Soni4a020c72017-10-30 20:58:40 -07004080 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304081 * @hdd_ctx: global hdd context
4082 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07004083 * @rtnl_held: Used to indicate whether or not the caller is holding
4084 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304085 *
4086 * This function De-initializes the STA/P2P/OCB adapter.
4087 *
4088 * Return: None.
4089 */
Krunal Soni4a020c72017-10-30 20:58:40 -07004090static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004091 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004092 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304093{
Dustin Brownfdf17c12018-03-14 12:55:34 -07004094 hdd_enter_dev(adapter->dev);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304095
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05304096 if (adapter->dev) {
4097 if (rtnl_held)
4098 adapter->dev->wireless_handlers = NULL;
4099 else {
4100 rtnl_lock();
4101 adapter->dev->wireless_handlers = NULL;
4102 rtnl_unlock();
4103 }
4104 }
4105
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304106 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
4107 hdd_deinit_tx_rx(adapter);
4108 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4109 }
4110
4111 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4112 hdd_wmm_adapter_close(adapter);
4113 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4114 }
4115
Krunal Sonib51eec72017-11-20 21:53:01 -08004116
Dustin Browne74003f2018-03-14 12:51:58 -07004117 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304118}
4119
Krunal Sonib51eec72017-11-20 21:53:01 -08004120void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
4121 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004122 bool rtnl_held)
4123{
Dustin Brown491d54b2018-03-14 12:39:11 -07004124 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304125
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004126 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004127 case QDF_STA_MODE:
4128 case QDF_P2P_CLIENT_MODE:
4129 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08004130 case QDF_IBSS_MODE:
4131 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004132 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004133 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004134 break;
4135 }
4136
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004137 case QDF_SAP_MODE:
4138 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004139 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004140 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004141 break;
4142 }
4143
4144 default:
4145 break;
4146 }
4147
Dustin Browne74003f2018-03-14 12:51:58 -07004148 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004149}
4150
Jeff Johnson9d295242017-08-29 14:39:48 -07004151static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004152 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004153{
Jeff Johnson5505db82017-11-02 21:19:23 -07004154 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004155
4156 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07004157 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004158 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004159 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004160 return;
4161 }
4162
Alok Kumarb64650c2018-03-23 17:05:11 +05304163 hdd_nud_deinit_tracking(adapter);
4164 qdf_mutex_destroy(&adapter->disconnection_status_lock);
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05304165 hdd_apf_context_destroy(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05304166
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05304167 wlan_hdd_debugfs_csr_deinit(adapter);
4168
Rajeev Kumardca5f812016-02-04 17:28:06 -08004169 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05304170
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004171 /*
4172 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
4173 * the driver is almost closed and cannot handle either control
4174 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004175 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
4176 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004177 * is not right. Setting this flag helps hdd_stop() to recognize that
4178 * the interface is closed and restricts any operations on that
4179 */
4180 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
4181
4182 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004183 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07004184 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004185 else
Jeff Johnson5505db82017-11-02 21:19:23 -07004186 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004187 /*
4188 * Note that the adapter is no longer valid at this point
4189 * since the memory has been reclaimed
4190 */
4191 }
4192}
4193
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004194static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07004195 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004196{
Jeff Johnson9d295242017-08-29 14:39:48 -07004197 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004198
Dustin Brown920397d2017-12-13 16:27:50 -08004199 hdd_for_each_adapter(hdd_ctx, adapter) {
4200 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
4201 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304202 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004203 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004204 }
Dustin Brown920397d2017-12-13 16:27:50 -08004205
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304206 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004207}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004208
Arun Khandavalli2358d522016-05-16 18:05:37 +05304209#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4210/**
4211 * hdd_set_fw_log_params() - Set log parameters to FW
4212 * @hdd_ctx: HDD Context
4213 * @adapter: HDD Adapter
4214 *
4215 * This function set the FW Debug log level based on the INI.
4216 *
4217 * Return: None
4218 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004219static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004220 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304221{
4222 uint8_t count = 0, numentries = 0,
4223 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
4224 uint32_t value = 0;
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304225 QDF_STATUS status;
4226 uint16_t enable_fw_log_level, enable_fw_log_type;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304227 int ret;
4228
Arun Khandavallifae92942016-08-01 13:31:08 +05304229 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4230 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004231 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304232 return;
4233 }
4234
Arun Khandavallifae92942016-08-01 13:31:08 +05304235 /* Enable FW logs based on INI configuration */
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304236 status = ucfg_fwol_get_enable_fw_log_type(hdd_ctx->psoc,
4237 &enable_fw_log_type);
4238 if (QDF_IS_STATUS_ERROR(status))
4239 return;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004240 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304241 WMI_DBGLOG_TYPE,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304242 enable_fw_log_type,
Arun Khandavallifae92942016-08-01 13:31:08 +05304243 DBG_CMD);
4244 if (ret != 0)
4245 hdd_err("Failed to enable FW log type ret %d",
4246 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304247
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304248 status = ucfg_fwol_get_enable_fw_log_level(hdd_ctx->psoc,
4249 &enable_fw_log_level);
4250 if (QDF_IS_STATUS_ERROR(status))
4251 return;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004252 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304253 WMI_DBGLOG_LOG_LEVEL,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304254 enable_fw_log_level,
Arun Khandavallifae92942016-08-01 13:31:08 +05304255 DBG_CMD);
4256 if (ret != 0)
4257 hdd_err("Failed to enable FW log level ret %d",
4258 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304259
4260 hdd_string_to_u8_array(
4261 hdd_ctx->config->enableFwModuleLogLevel,
4262 moduleloglevel,
4263 &numentries,
4264 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
4265
4266 while (count < numentries) {
4267 /*
4268 * FW module log level input string looks like
4269 * below:
4270 * gFwDebugModuleLoglevel=<FW Module ID>,
4271 * <Log Level>,...
4272 * For example:
4273 * gFwDebugModuleLoglevel=
4274 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
4275 * Above input string means :
4276 * For FW module ID 1 enable log level 0
4277 * For FW module ID 2 enable log level 1
4278 * For FW module ID 3 enable log level 2
4279 * For FW module ID 4 enable log level 3
4280 * For FW module ID 5 enable log level 4
4281 * For FW module ID 6 enable log level 5
4282 * For FW module ID 7 enable log level 6
4283 */
4284
Nishank Aggarwale239d962017-03-03 12:26:02 +05304285 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
4286 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
4287 hdd_err("Module id %d and dbglog level %d input length is more than max",
4288 moduleloglevel[count],
4289 moduleloglevel[count + 1]);
4290 return;
4291 }
4292
4293 value = moduleloglevel[count] << 16;
4294 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07004295 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304296 WMI_DBGLOG_MOD_LOG_LEVEL,
4297 value, DBG_CMD);
4298 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304299 hdd_err("Failed to enable FW module log level %d ret %d",
4300 value, ret);
4301
4302 count += 2;
4303 }
Arun Khandavallifae92942016-08-01 13:31:08 +05304304
Arun Khandavalli2358d522016-05-16 18:05:37 +05304305}
4306#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004307static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004308 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304309{
4310}
4311
4312#endif
4313
4314/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004315 * hdd_configure_chain_mask() - programs chain mask to firmware
4316 * @adapter: HDD adapter
4317 *
4318 * Return: 0 on success or errno on failure
4319 */
4320static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4321{
Naveen Rawat98322472018-03-06 10:29:42 -08004322 QDF_STATUS status;
4323 struct wma_caps_per_phy non_dbs_phy_cap;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004324 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304325 bool bval = false;
4326
4327 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
4328 if (!QDF_IS_STATUS_SUCCESS(status))
4329 hdd_err("unable to get vht_enable2x2");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004330
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304331 hdd_debug("enable2x2: %d, lte_coex: %d, disable_DBS: %d",
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304332 bval, hdd_ctx->lte_coex_ant_share,
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304333 hdd_ctx->config->dual_mac_feature_disable);
Liangwei Dong22810e82018-03-15 03:42:12 -04004334 hdd_debug("enable_bt_chain_separation %d",
4335 hdd_ctx->config->enable_bt_chain_separation);
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004336
Naveen Rawat98322472018-03-06 10:29:42 -08004337 status = wma_get_caps_for_phyidx_hwmode(&non_dbs_phy_cap,
4338 HW_MODE_DBS_NONE,
4339 CDS_BAND_ALL);
4340 if (QDF_IS_STATUS_ERROR(status)) {
4341 hdd_err("couldn't get phy caps. skip chain mask programming");
4342 return qdf_status_to_os_return(status);
4343 }
4344
4345 if (non_dbs_phy_cap.tx_chain_mask_2G < 3 ||
4346 non_dbs_phy_cap.rx_chain_mask_2G < 3 ||
4347 non_dbs_phy_cap.tx_chain_mask_5G < 3 ||
4348 non_dbs_phy_cap.rx_chain_mask_5G < 3) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004349 hdd_debug("firmware not capable. skip chain mask programming");
Naveen Rawat98322472018-03-06 10:29:42 -08004350 return 0;
4351 }
4352
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304353 if (bval && !hdd_ctx->config->enable_bt_chain_separation) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004354 hdd_debug("2x2 enabled. skip chain mask programming");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004355 return 0;
4356 }
4357
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004358 if (hdd_ctx->config->dual_mac_feature_disable !=
4359 DISABLE_DBS_CXN_AND_SCAN) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004360 hdd_debug("DBS enabled(%d). skip chain mask programming",
4361 hdd_ctx->config->dual_mac_feature_disable);
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004362 return 0;
4363 }
4364
Naveen Rawatdacb5032018-02-08 15:23:24 -08004365 if (hdd_ctx->lte_coex_ant_share) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004366 hdd_debug("lte ant sharing enabled. skip chainmask programming");
Naveen Rawatdacb5032018-02-08 15:23:24 -08004367 return 0;
4368 }
4369
Dustin Brown1dbefe62018-09-11 16:32:03 -07004370 status = ucfg_mlme_configure_chain_mask(hdd_ctx->psoc,
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304371 adapter->session_id);
4372 if (status != QDF_STATUS_SUCCESS)
4373 goto error;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004374
4375 return 0;
4376
4377error:
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304378 hdd_err("WMI PDEV set param failed");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004379 return -EINVAL;
4380}
4381
4382/**
Dundi Raviteja3b637092018-09-12 13:42:50 +05304383 * hdd_send_coex_config_params() - Send coex config params to FW
4384 * @hdd_ctx: HDD context
4385 * @adapter: Primary adapter context
4386 *
4387 * This function is used to send all coex config related params to FW
4388 *
4389 * Return: 0 on success and -EINVAL on failure
4390 */
4391static int hdd_send_coex_config_params(struct hdd_context *hdd_ctx,
4392 struct hdd_adapter *adapter)
4393{
4394 struct coex_config_params coex_cfg_params = {0};
4395 struct wlan_fwol_coex_config config = {0};
Dustin Brown05d81302018-09-11 16:49:22 -07004396 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Dundi Raviteja3b637092018-09-12 13:42:50 +05304397 QDF_STATUS status;
4398
4399 if (!hdd_ctx) {
4400 hdd_err("hdd_ctx is invalid");
4401 goto err;
4402 }
4403
4404 if (!adapter) {
4405 hdd_err("adapter is invalid");
4406 goto err;
4407 }
4408
4409 if (!psoc) {
4410 hdd_err("HDD psoc is invalid");
4411 goto err;
4412 }
4413
4414 status = ucfg_fwol_get_coex_config_params(psoc, &config);
4415 if (QDF_IS_STATUS_ERROR(status)) {
4416 hdd_err("Unable to get coex config params");
4417 goto err;
4418 }
4419
4420 coex_cfg_params.vdev_id = adapter->session_id;
4421 coex_cfg_params.config_type = WMI_COEX_CONFIG_TX_POWER;
4422 coex_cfg_params.config_arg1 = config.max_tx_power_for_btc;
4423
4424 status = sme_send_coex_config_cmd(&coex_cfg_params);
4425 if (QDF_IS_STATUS_ERROR(status)) {
4426 hdd_err("Failed to send coex Tx power");
4427 goto err;
4428 }
4429
4430 coex_cfg_params.config_type = WMI_COEX_CONFIG_HANDOVER_RSSI;
4431 coex_cfg_params.config_arg1 = config.wlan_low_rssi_threshold;
4432
4433 status = sme_send_coex_config_cmd(&coex_cfg_params);
4434 if (QDF_IS_STATUS_ERROR(status)) {
4435 hdd_err("Failed to send coex handover RSSI");
4436 goto err;
4437 }
4438
4439 coex_cfg_params.config_type = WMI_COEX_CONFIG_BTC_MODE;
4440 coex_cfg_params.config_arg1 = config.btc_mode;
4441
4442 status = sme_send_coex_config_cmd(&coex_cfg_params);
4443 if (QDF_IS_STATUS_ERROR(status)) {
4444 hdd_err("Failed to send coex BTC mode");
4445 goto err;
4446 }
4447
4448 coex_cfg_params.config_type = WMI_COEX_CONFIG_ANTENNA_ISOLATION;
4449 coex_cfg_params.config_arg1 = config.antenna_isolation;
4450
4451 status = sme_send_coex_config_cmd(&coex_cfg_params);
4452 if (QDF_IS_STATUS_ERROR(status)) {
4453 hdd_err("Failed to send coex antenna isolation");
4454 goto err;
4455 }
4456
4457 coex_cfg_params.config_type = WMI_COEX_CONFIG_BT_LOW_RSSI_THRESHOLD;
4458 coex_cfg_params.config_arg1 = config.bt_low_rssi_threshold;
4459
4460 status = sme_send_coex_config_cmd(&coex_cfg_params);
4461 if (QDF_IS_STATUS_ERROR(status)) {
4462 hdd_err("Failed to send coex BT low RSSI threshold");
4463 goto err;
4464 }
4465
4466 coex_cfg_params.config_type = WMI_COEX_CONFIG_BT_INTERFERENCE_LEVEL;
4467 coex_cfg_params.config_arg1 = config.bt_interference_low_ll;
4468 coex_cfg_params.config_arg2 = config.bt_interference_low_ul;
4469 coex_cfg_params.config_arg3 = config.bt_interference_medium_ll;
4470 coex_cfg_params.config_arg4 = config.bt_interference_medium_ul;
4471 coex_cfg_params.config_arg5 = config.bt_interference_high_ll;
4472 coex_cfg_params.config_arg6 = config.bt_interference_high_ul;
4473
4474 status = sme_send_coex_config_cmd(&coex_cfg_params);
4475 if (QDF_IS_STATUS_ERROR(status)) {
4476 hdd_err("Failed to send coex BT interference level");
4477 goto err;
4478 }
4479 return 0;
4480err:
4481 return -EINVAL;
4482}
4483
4484/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304485 * hdd_set_fw_params() - Set parameters to firmware
4486 * @adapter: HDD adapter
4487 *
4488 * This function Sets various parameters to fw once the
4489 * adapter is started.
4490 *
4491 * Return: 0 on success or errno on failure
4492 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004493int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304494{
4495 int ret;
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304496 uint16_t upper_brssi_thresh, lower_brssi_thresh, rts_profile;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304497 bool enable_dtim_1chrx;
4498 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004499 struct hdd_context *hdd_ctx;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304500 bool bval = false;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304501
Dustin Brownfdf17c12018-03-14 12:55:34 -07004502 hdd_enter_dev(adapter->dev);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304503
4504 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4505 if (!hdd_ctx)
4506 return -EINVAL;
4507
Dustin Brown732ab9c2017-06-15 13:24:09 -07004508 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4509 hdd_debug("FTM Mode is active; nothing to do");
4510 return 0;
4511 }
4512
Jeff Johnson1b780e42017-10-31 14:11:45 -07004513 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304514 WMI_PDEV_PARAM_DTIM_SYNTH,
4515 hdd_ctx->config->enable_lprx, PDEV_CMD);
4516 if (ret) {
4517 hdd_err("Failed to set LPRx");
4518 goto error;
4519 }
4520
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304521
4522 ret = sme_cli_set_command(
4523 adapter->session_id,
4524 WMI_PDEV_PARAM_1CH_DTIM_OPTIMIZED_CHAIN_SELECTION,
4525 hdd_ctx->config->enable_dtim_selection_diversity,
4526 PDEV_CMD);
4527 if (ret) {
4528 hdd_err("Failed to set DTIM_OPTIMIZED_CHAIN_SELECTION");
4529 goto error;
4530 }
4531
Ashish Kumar Dhanotiya48dac7d2018-03-28 14:59:50 +05304532 ret = sme_cli_set_command(
4533 adapter->session_id,
4534 WMI_PDEV_PARAM_TX_SCH_DELAY,
4535 hdd_ctx->config->enable_tx_sch_delay,
4536 PDEV_CMD);
4537 if (ret) {
4538 hdd_err("Failed to set WMI_PDEV_PARAM_TX_SCH_DELAY");
4539 goto error;
4540 }
4541
Ashish Kumar Dhanotiya959b38c2018-04-06 21:07:57 +05304542 ret = sme_cli_set_command(
4543 adapter->session_id,
4544 WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE,
4545 hdd_ctx->config->enable_secondary_rate,
4546 PDEV_CMD);
4547 if (ret) {
4548 hdd_err("Failed to set WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE");
4549 goto error;
4550 }
4551
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304552 if (adapter->device_mode == QDF_STA_MODE) {
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304553 status = ucfg_get_upper_brssi_thresh(hdd_ctx->psoc,
4554 &upper_brssi_thresh);
4555 if (QDF_IS_STATUS_ERROR(status))
4556 return -EINVAL;
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304557
Jeff Johnson1b780e42017-10-31 14:11:45 -07004558 sme_set_smps_cfg(adapter->session_id,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304559 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4560 upper_brssi_thresh);
4561
4562 status = ucfg_get_lower_brssi_thresh(hdd_ctx->psoc,
4563 &lower_brssi_thresh);
4564 if (QDF_IS_STATUS_ERROR(status))
4565 return -EINVAL;
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304566
Jeff Johnson1b780e42017-10-31 14:11:45 -07004567 sme_set_smps_cfg(adapter->session_id,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304568 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4569 lower_brssi_thresh);
4570
4571 status = ucfg_get_enable_dtim_1chrx(hdd_ctx->psoc,
4572 &enable_dtim_1chrx);
4573 if (QDF_IS_STATUS_ERROR(status))
4574 return -EINVAL;
4575
4576 sme_set_smps_cfg(adapter->session_id,
4577 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4578 enable_dtim_1chrx);
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304579 }
4580
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304581 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
4582 if (!QDF_IS_STATUS_SUCCESS(status))
4583 hdd_err("unable to get vht_enable2x2");
4584
4585 if (bval) {
Dustin Brown732ab9c2017-06-15 13:24:09 -07004586 hdd_debug("configuring 2x2 mode fw params");
4587
Vignesh Viswanathana851d752018-10-03 19:44:38 +05304588 ret = sme_set_cck_tx_fir_override(hdd_ctx->mac_handle,
4589 adapter->session_id);
Dustin Brown732ab9c2017-06-15 13:24:09 -07004590 if (ret) {
4591 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4592 ret);
4593 goto error;
4594 }
Liangwei Dong22810e82018-03-15 03:42:12 -04004595
4596 if (hdd_configure_chain_mask(adapter))
4597 goto error;
Dustin Brown732ab9c2017-06-15 13:24:09 -07004598 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304599#define HDD_DTIM_1CHAIN_RX_ID 0x5
4600#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004601 hdd_debug("configuring 1x1 mode fw params");
4602
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004603 /*
4604 * Disable DTIM 1 chain Rx when in 1x1,
4605 * we are passing two value
4606 * as param_id << 29 | param_value.
4607 * Below param_value = 0(disable)
4608 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004609 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004610 WMI_STA_SMPS_PARAM_CMDID,
4611 HDD_DTIM_1CHAIN_RX_ID <<
4612 HDD_SMPS_PARAM_VALUE_S,
4613 VDEV_CMD);
4614 if (ret) {
4615 hdd_err("DTIM 1 chain set failed %d", ret);
4616 goto error;
4617 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304618
Arun Khandavalli2358d522016-05-16 18:05:37 +05304619#undef HDD_DTIM_1CHAIN_RX_ID
4620#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004621
4622 if (hdd_configure_chain_mask(adapter))
4623 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004624 }
4625
Vignesh Viswanathana851d752018-10-03 19:44:38 +05304626 ret = sme_set_enable_mem_deep_sleep(hdd_ctx->mac_handle,
4627 adapter->session_id);
Dustin Brown732ab9c2017-06-15 13:24:09 -07004628 if (ret) {
4629 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4630 goto error;
4631 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304632
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304633 status = ucfg_fwol_get_rts_profile(hdd_ctx->psoc, &rts_profile);
4634 if (QDF_IS_STATUS_ERROR(status))
4635 return -EINVAL;
4636
Jeff Johnson1b780e42017-10-31 14:11:45 -07004637 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004638 WMI_VDEV_PARAM_ENABLE_RTSCTS,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304639 rts_profile,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004640 VDEV_CMD);
4641 if (ret) {
4642 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4643 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304644 }
4645
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004646 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
4647
Jeff Johnson1b780e42017-10-31 14:11:45 -07004648 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004649 GEN_VDEV_PARAM_AMSDU,
4650 hdd_ctx->config->max_amsdu_num,
4651 GEN_CMD);
4652 if (ret != 0) {
4653 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4654 goto error;
4655 }
4656
Arun Khandavalli2358d522016-05-16 18:05:37 +05304657 hdd_set_fw_log_params(hdd_ctx, adapter);
Dundi Raviteja3b637092018-09-12 13:42:50 +05304658
4659 ret = hdd_send_coex_config_params(hdd_ctx, adapter);
4660 if (ret) {
4661 hdd_warn("Error initializing coex config params");
4662 goto error;
4663 }
4664
Dustin Browne74003f2018-03-14 12:51:58 -07004665 hdd_exit();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004666
Arun Khandavalli2358d522016-05-16 18:05:37 +05304667 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304668
Arun Khandavalli2358d522016-05-16 18:05:37 +05304669error:
4670 return -EINVAL;
4671}
4672
Ryan Hsu07495ea2016-01-21 15:25:39 -08004673/**
Abhinav Kumarcc959f12018-08-09 13:58:30 +05304674 * hdd_init_completion() - Initialize Completion Variables
4675 * @adapter: HDD adapter
4676 *
4677 * This function Initialize the completion variables for
4678 * a particular adapter
4679 *
4680 * Return: None
4681 */
4682static void hdd_init_completion(struct hdd_adapter *adapter)
4683{
4684 init_completion(&adapter->disconnect_comp_var);
4685 init_completion(&adapter->roaming_comp_var);
4686 init_completion(&adapter->linkup_event_var);
4687 init_completion(&adapter->cancel_rem_on_chan_var);
4688 init_completion(&adapter->rem_on_chan_ready_event);
4689 init_completion(&adapter->sta_authorized_event);
4690 init_completion(&adapter->offchannel_tx_event);
4691 init_completion(&adapter->tx_action_cnf_event);
4692 init_completion(&adapter->ibss_peer_info_comp);
4693 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
4694}
4695
4696/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08004697 * hdd_open_adapter() - open and setup the hdd adatper
4698 * @hdd_ctx: global hdd context
4699 * @session_type: type of the interface to be created
4700 * @iface_name: User-visible name of the interface
4701 * @macAddr: MAC address to assign to the interface
4702 * @name_assign_type: the name of assign type of the netdev
4703 * @rtnl_held: the rtnl lock hold flag
4704 *
4705 * This function open and setup the hdd adpater according to the device
4706 * type request, assign the name, the mac address assigned, and then prepared
4707 * the hdd related parameters, queue, lock and ready to start.
4708 *
4709 * Return: the pointer of hdd adapter, otherwise NULL.
4710 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004711struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004712 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08004713 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004714 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004715{
Jeff Johnson9d295242017-08-29 14:39:48 -07004716 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304717 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004718
4719 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4720 /*
4721 * Max limit reached on the number of vdevs configured by the
4722 * host. Return error
4723 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304724 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4725 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004726 return NULL;
4727 }
4728
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05304729 status = wlan_hdd_validate_mac_address((struct qdf_mac_addr *)macAddr);
4730 if (QDF_IS_STATUS_ERROR(status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004731 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304732 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004733 return NULL;
4734 }
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05304735
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004736 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304737 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304738 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4739 " already exists",
4740 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004741 return NULL;
4742 }
4743
4744 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004745 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004746 /* Reset locally administered bit if the device mode is STA */
4747 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Dustin Brown7e761c72018-07-31 13:50:17 -07004748 hdd_debug("locally administered bit reset in sta mode: "
4749 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004750 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004751 case QDF_P2P_CLIENT_MODE:
4752 case QDF_P2P_DEVICE_MODE:
4753 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07004754 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304755 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004756 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4757 name_assign_type,
4758 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004759
4760 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304761 hdd_err("failed to allocate adapter for session %d",
4762 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004763 return NULL;
4764 }
4765
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004766 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004767 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004768 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004769 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304770 else if (QDF_MONITOR_MODE == session_type)
4771 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004772 else
4773 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4774
4775 adapter->device_mode = session_type;
4776
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004777
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004778 /*
4779 * Workqueue which gets scheduled in IPv4 notification
4780 * callback
4781 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004782 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004783 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004784
4785#ifdef WLAN_NS_OFFLOAD
4786 /*
4787 * Workqueue which gets scheduled in IPv6
4788 * notification callback.
4789 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004790 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004791 hdd_ipv6_notifier_work_queue);
4792#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004793 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004794 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004795 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004796
4797 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004798 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004799 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304800 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4801 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304802
Alok Kumarb64650c2018-03-23 17:05:11 +05304803 hdd_nud_init_tracking(adapter);
4804
4805 qdf_mutex_create(&adapter->disconnection_status_lock);
4806
Ravi Joshi1a292562017-05-18 16:28:54 -07004807 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004808
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004809 case QDF_P2P_GO_MODE:
4810 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004811 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4812 name_assign_type,
4813 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004814 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004815 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304816 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004817 return NULL;
4818 }
4819
4820 adapter->wdev.iftype =
4821 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004822 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004823 NL80211_IFTYPE_P2P_GO;
4824 adapter->device_mode = session_type;
4825
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004826 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004827 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004828 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004829
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004830 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004831 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304832 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4833 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304834
4835 /*
4836 * Workqueue which gets scheduled in IPv4 notification
4837 * callback
4838 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004839 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304840 hdd_ipv4_notifier_work_queue);
4841
4842#ifdef WLAN_NS_OFFLOAD
4843 /*
4844 * Workqueue which gets scheduled in IPv6
4845 * notification callback.
4846 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004847 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304848 hdd_ipv6_notifier_work_queue);
4849#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004850 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304851 case QDF_FTM_MODE:
4852 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4853 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08004854 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304855 if (NULL == adapter) {
4856 hdd_err("Failed to allocate adapter for FTM mode");
4857 return NULL;
4858 }
4859 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4860 adapter->device_mode = session_type;
4861 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004862 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004863 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004864
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304865 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004866 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304867 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304868 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4869 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304870 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004871 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004872 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304873 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004874 return NULL;
4875 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004876
Abhinav Kumarcc959f12018-08-09 13:58:30 +05304877 hdd_init_completion(adapter);
hqueaa33ee2017-05-04 17:56:35 +08004878 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
Min Liu9be5d4a2018-05-17 11:51:53 +08004879 qdf_list_create(&adapter->blocked_scan_request_q, WLAN_MAX_SCAN_COUNT);
4880 qdf_mutex_create(&adapter->blocked_scan_request_q_lock);
hqueaa33ee2017-05-04 17:56:35 +08004881
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304882 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004883 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08004884 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004885 }
4886
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304887 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004888 if (NULL != adapter) {
4889 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4890 adapter = NULL;
4891 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004892
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004893 return NULL;
4894 }
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05304895 hdd_apf_context_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004896
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304897 if (QDF_STATUS_SUCCESS == status) {
Dustin Brown1dbefe62018-09-11 16:32:03 -07004898 policy_mgr_set_concurrency_mode(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004899 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004900
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004901 /* Adapter successfully added. Increment the vdev count */
4902 hdd_ctx->current_intf_count++;
4903
Jeff Johnson5880d792016-08-15 13:32:30 -07004904 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004905 hdd_ctx->current_intf_count);
4906
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004907 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004908 }
4909
Rajeev Kumardca5f812016-02-04 17:28:06 -08004910 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004911 hdd_err("Interface %s wow debug_fs init failed",
4912 netdev_name(adapter->dev));
4913
Ajit Pal Singh106c1412018-04-18 18:08:49 +05304914 hdd_register_hl_netdev_fc_timer(adapter,
4915 hdd_tx_resume_timer_expired_handler);
4916
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004917 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4918 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004919
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05304920 if (adapter->device_mode == QDF_STA_MODE)
4921 wlan_hdd_debugfs_csr_init(adapter);
4922
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004923 return adapter;
4924
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004925err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07004926 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304927 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004928
4929 return NULL;
4930}
4931
Dustin Brown728d65a2018-10-02 16:27:52 -07004932static void __hdd_close_adapter(struct hdd_context *hdd_ctx,
4933 struct hdd_adapter *adapter,
4934 bool rtnl_held)
4935{
4936 qdf_list_destroy(&adapter->blocked_scan_request_q);
4937 qdf_mutex_destroy(&adapter->blocked_scan_request_q_lock);
4938 policy_mgr_clear_concurrency_mode(hdd_ctx->psoc, adapter->device_mode);
4939
4940 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4941
4942 if (hdd_ctx->current_intf_count != 0)
4943 hdd_ctx->current_intf_count--;
4944}
4945
4946void hdd_close_adapter(struct hdd_context *hdd_ctx,
4947 struct hdd_adapter *adapter,
4948 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004949{
Dustin Brown920397d2017-12-13 16:27:50 -08004950 /*
Dustin Brown728d65a2018-10-02 16:27:52 -07004951 * Stop the global bus bandwidth timer while touching the adapter list
4952 * to avoid bad memory access by the timer handler.
Dustin Brown920397d2017-12-13 16:27:50 -08004953 */
Dustin Brown920397d2017-12-13 16:27:50 -08004954 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004955
Dustin Brown920397d2017-12-13 16:27:50 -08004956 hdd_remove_adapter(hdd_ctx, adapter);
Dustin Brown728d65a2018-10-02 16:27:52 -07004957 __hdd_close_adapter(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004958
Dustin Brown920397d2017-12-13 16:27:50 -08004959 /* conditionally restart the bw timer */
4960 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004961}
4962
Dustin Brown728d65a2018-10-02 16:27:52 -07004963void hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004964{
Dustin Brown920397d2017-12-13 16:27:50 -08004965 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004966
Dustin Brown491d54b2018-03-14 12:39:11 -07004967 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004968
Dustin Brown728d65a2018-10-02 16:27:52 -07004969 while (QDF_IS_STATUS_SUCCESS(hdd_remove_front_adapter(hdd_ctx,
4970 &adapter))) {
4971 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
4972 __hdd_close_adapter(hdd_ctx, adapter, rtnl_held);
4973 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004974
Dustin Browne74003f2018-03-14 12:51:58 -07004975 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004976}
4977
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004978void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004979{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304980 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004981 tSirUpdateIE updateIE;
Jeff Johnson16528362018-06-14 12:34:16 -07004982 mac_handle_t mac_handle;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004983
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004984 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004985 case QDF_STA_MODE:
4986 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004987 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004988 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004989 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004990 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004991 break;
4992 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004993 case QDF_SAP_MODE:
4994 case QDF_P2P_GO_MODE:
4995 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004996 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07004997 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004998 break;
4999 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005000 case QDF_FTM_MODE:
5001 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005002 default:
5003 /*
5004 * wlan_hdd_reset_prob_rspies should not have been called
5005 * for these kind of devices
5006 */
Jeff Johnson5880d792016-08-15 13:32:30 -07005007 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005008 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005009 return;
5010 }
5011
Anurag Chouhanc5548422016-02-24 18:33:27 +05305012 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005013 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005014 updateIE.ieBufferlength = 0;
5015 updateIE.pAdditionIEBuffer = NULL;
5016 updateIE.append = true;
5017 updateIE.notify = false;
Jeff Johnson16528362018-06-14 12:34:16 -07005018 mac_handle = hdd_adapter_get_mac_handle(adapter);
5019 if (sme_update_add_ie(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005020 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305021 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005022 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005023 }
5024}
5025
Dustin Browndb2a8be2017-12-20 11:49:56 -08005026QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
5027 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005028{
Liangwei Dongad89c762018-06-01 01:56:23 -04005029 return hdd_stop_adapter_ext(hdd_ctx, adapter, 0);
5030}
5031
5032QDF_STATUS hdd_stop_adapter_ext(struct hdd_context *hdd_ctx,
5033 struct hdd_adapter *adapter,
5034 enum hdd_adapter_stop_flag_t flag)
5035{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305036 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson025618c2018-03-18 14:41:00 -07005037 struct csr_roam_profile *roam_profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005038 union iwreq_data wrqu;
5039 tSirUpdateIE updateIE;
5040 unsigned long rc;
Jeff Johnsone4c11db2018-05-05 23:22:32 -07005041 tsap_config_t *sap_config;
Jeff Johnson16528362018-06-14 12:34:16 -07005042 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005043
Dustin Brown491d54b2018-03-14 12:39:11 -07005044 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005045
Dustin Browne7e71d32018-05-11 16:00:08 -07005046 if (adapter->session_id != HDD_SESSION_ID_INVALID)
5047 wlan_hdd_cfg80211_deregister_frames(adapter);
5048
Alok Kumarb64650c2018-03-23 17:05:11 +05305049 hdd_nud_ignore_tracking(adapter, true);
5050 hdd_nud_reset_tracking(adapter);
Alok Kumar016a1ac2018-09-16 09:55:50 +05305051 hdd_nud_flush_work(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05305052
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005053 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305054 wlan_hdd_netif_queue_control(adapter,
5055 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5056 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08005057 /*
5058 * if this is the last active connection check & stop the
5059 * opportunistic timer first
5060 */
Dustin Brown1dbefe62018-09-11 16:32:03 -07005061 if (((policy_mgr_get_connection_count(hdd_ctx->psoc) == 1) &&
5062 (policy_mgr_mode_specific_connection_count(hdd_ctx->psoc,
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08005063 policy_mgr_convert_device_mode_to_qdf_type(
5064 adapter->device_mode), NULL) == 1)) ||
Dustin Brown1dbefe62018-09-11 16:32:03 -07005065 !policy_mgr_get_connection_count(hdd_ctx->psoc))
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08005066 policy_mgr_check_and_stop_opportunistic_timer(
Dustin Brown1dbefe62018-09-11 16:32:03 -07005067 hdd_ctx->psoc, adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -07005068
5069 mac_handle = hdd_ctx->mac_handle;
5070
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005071 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005072 case QDF_STA_MODE:
5073 case QDF_P2P_CLIENT_MODE:
5074 case QDF_IBSS_MODE:
5075 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005076 case QDF_NDI_MODE:
5077 if ((QDF_NDI_MODE == adapter->device_mode) ||
5078 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005079 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
5080 hdd_is_connecting(
5081 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005082 INIT_COMPLETION(adapter->disconnect_comp_var);
Jeff Johnson025618c2018-03-18 14:41:00 -07005083 roam_profile = hdd_roam_profile(adapter);
5084 /* For NDI do not use roam_profile */
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005085 if (QDF_NDI_MODE == adapter->device_mode)
5086 qdf_ret_status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005087 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005088 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005089 eCSR_DISCONNECT_REASON_NDI_DELETE);
Jeff Johnson025618c2018-03-18 14:41:00 -07005090 else if (roam_profile->BSSType ==
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005091 eCSR_BSS_TYPE_START_IBSS)
5092 qdf_ret_status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005093 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005094 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005095 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Abhinav Kumar19a7a402018-07-12 17:36:57 +05305096 else if (adapter->device_mode == QDF_STA_MODE)
5097 wlan_hdd_disconnect(adapter,
5098 eCSR_DISCONNECT_REASON_DEAUTH);
5099 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005100 qdf_ret_status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005101 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005102 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005103 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005104 /* success implies disconnect command got
5105 * queued up successfully
5106 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005107 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
5108 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005109 rc = wait_for_completion_timeout(
5110 &adapter->disconnect_comp_var,
5111 msecs_to_jiffies
5112 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005113 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005114 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005115 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005116 if (qdf_ret_status != QDF_STATUS_SUCCESS)
5117 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005118 memset(&wrqu, '\0', sizeof(wrqu));
5119 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5120 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5121 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
5122 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05305123 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08005124 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005125
Wu Gao4a1ec8c2018-07-23 19:18:40 +08005126 wlan_hdd_cleanup_actionframe(adapter);
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05305127 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05305128 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005129
5130#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005131 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005132#endif
5133
5134 hdd_deregister_tx_flow_control(adapter);
5135
5136#ifdef WLAN_NS_OFFLOAD
5137#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005138 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005139#endif
5140#endif
5141
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05305142 if (adapter->device_mode == QDF_STA_MODE)
Dustin Brown07901ec2018-09-07 11:02:41 -07005143 wlan_cfg80211_sched_scan_stop(hdd_ctx->pdev,
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05305144 adapter->dev);
Dustin Browndb2a8be2017-12-20 11:49:56 -08005145
5146 if (wlan_hdd_try_disconnect(adapter)) {
5147 hdd_err("Error: Can't disconnect adapter");
5148 return QDF_STATUS_E_FAILURE;
Krunal Soni985b8132017-02-10 18:49:08 -08005149 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08005150
Himanshu Agarwalb229a142017-12-21 10:16:45 +05305151 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005152 break;
5153
Rajeev Kumar3b906202018-02-01 10:55:14 -08005154 case QDF_MONITOR_MODE:
5155 wlan_hdd_scan_abort(adapter);
5156 hdd_deregister_tx_flow_control(adapter);
5157 hdd_vdev_destroy(adapter);
5158 break;
5159
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005160 case QDF_SAP_MODE:
Will Huang7049bae2018-08-13 17:25:02 +08005161 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
5162 cds_flush_delayed_work(&adapter->acs_pending_work);
5163 clear_bit(ACS_PENDING, &adapter->event_flags);
5164 }
wadesongf9b15ed2017-12-14 14:12:32 +08005165 wlan_hdd_scan_abort(adapter);
Govind Singh1dab23b2017-08-12 13:31:00 +05305166 /* Flush IPA exception path packets */
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05305167 sap_config = &adapter->session.ap.sap_config;
5168 if (sap_config)
5169 wlansap_reset_sap_config_add_ie(sap_config,
5170 eUPDATE_IE_ALL);
Dustin Brown07901ec2018-09-07 11:02:41 -07005171 ucfg_ipa_flush(hdd_ctx->pdev);
Liangwei Dongad89c762018-06-01 01:56:23 -04005172 if (!(flag & HDD_IN_CAC_WORK_TH_CONTEXT))
5173 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Jeff Johnson46807cd2018-04-29 21:32:22 -07005174 /* fallthrough */
Dustin Browna5cf8e02017-10-19 16:04:19 -07005175
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005176 case QDF_P2P_GO_MODE:
Krunal Soni22208392017-09-29 18:10:34 -07005177 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005178
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005179 /* Any softap specific cleanup here... */
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305180 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005181 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005182 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005183 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5184
5185 hdd_deregister_tx_flow_control(adapter);
5186
Kapil Guptac1224bf2017-06-22 21:22:40 +05305187 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005188 mutex_lock(&hdd_ctx->sap_lock);
5189 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305190 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05305191 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005192
5193 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005194 status = wlansap_stop_bss(
5195 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005196
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305197 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07005198 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005199 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305200 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305201 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305202 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +05305203 qdf_wait_for_event_completion(
5204 &hostapd_state->qdf_stop_bss_event,
Vignesh Viswanathan865daaa2018-10-11 19:30:44 +05305205 SME_CMD_START_STOP_BSS_TIMEOUT);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005206
Anurag Chouhance0dc992016-02-16 18:18:03 +05305207 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005208 hdd_err("failure waiting for wlansap_stop_bss %d",
5209 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005210 }
5211 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07005212 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005213 }
5214 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -07005215 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005216 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005217 adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005218 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305219 adapter->device_mode,
5220 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005221
Anurag Chouhanc5548422016-02-24 18:33:27 +05305222 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07005223 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005224 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005225 updateIE.ieBufferlength = 0;
5226 updateIE.pAdditionIEBuffer = NULL;
5227 updateIE.append = false;
5228 updateIE.notify = false;
5229 /* Probe bcn reset */
Jeff Johnson16528362018-06-14 12:34:16 -07005230 if (sme_update_add_ie(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005231 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305232 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005233 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005234 }
5235 /* Assoc resp reset */
Jeff Johnson16528362018-06-14 12:34:16 -07005236 if (sme_update_add_ie(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005237 &updateIE,
5238 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305239 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005240 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005241 }
5242 /* Reset WNI_CFG_PROBE_RSP Flags */
5243 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005244 }
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005245 clear_bit(SOFTAP_INIT_DONE, &adapter->event_flags);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005246 qdf_mem_free(adapter->session.ap.beacon);
5247 adapter->session.ap.beacon = NULL;
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005248
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305249 /*
5250 * If Do_Not_Break_Stream was enabled clear avoid channel list.
5251 */
Dustin Brown89fa06e2018-09-07 10:47:27 -07005252 if (policy_mgr_is_dnsc_set(adapter->vdev))
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305253 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
5254
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305255#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005256 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305257#endif
5258
5259#ifdef WLAN_NS_OFFLOAD
5260#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005261 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305262#endif
5263#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08005264
5265 hdd_vdev_destroy(adapter);
5266
Krunal Sonib51eec72017-11-20 21:53:01 -08005267 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005268 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005269 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08005270 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08005271 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07005272 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Zhang Qian79d0d132018-02-05 13:40:16 +08005273 hdd_deregister_tx_flow_control(adapter);
5274 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005275 break;
5276 default:
5277 break;
5278 }
5279
Ajit Pal Singh106c1412018-04-18 18:08:49 +05305280 hdd_deregister_hl_netdev_fc_timer(adapter);
5281
Dustin Brown04348372017-12-14 16:13:39 -08005282 if (adapter->scan_info.default_scan_ies) {
5283 qdf_mem_free(adapter->scan_info.default_scan_ies);
5284 adapter->scan_info.default_scan_ies = NULL;
5285 }
5286
Dustin Browne74003f2018-03-14 12:51:58 -07005287 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305288 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005289}
5290
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305291/**
5292 * hdd_deinit_all_adapters - deinit all adapters
5293 * @hdd_ctx: HDD context
5294 * @rtnl_held: True if RTNL lock held
5295 *
5296 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005297void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305298{
Jeff Johnson9d295242017-08-29 14:39:48 -07005299 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305300
Dustin Brown491d54b2018-03-14 12:39:11 -07005301 hdd_enter();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305302
Dustin Brown920397d2017-12-13 16:27:50 -08005303 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305304 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305305
Dustin Browne74003f2018-03-14 12:51:58 -07005306 hdd_exit();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305307}
5308
Dustin Browndb2a8be2017-12-20 11:49:56 -08005309QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005310{
Jeff Johnson9d295242017-08-29 14:39:48 -07005311 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005312
Dustin Brown491d54b2018-03-14 12:39:11 -07005313 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005314
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305315 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5316
Dustin Brown920397d2017-12-13 16:27:50 -08005317 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08005318 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005319
Dustin Browne74003f2018-03-14 12:51:58 -07005320 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005321
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305322 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005323}
5324
Paul Zhang84fa9382017-11-10 21:18:21 +08005325static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
5326 struct hdd_adapter *adapter)
5327{
5328 switch (adapter->device_mode) {
5329 case QDF_STA_MODE:
5330 case QDF_P2P_CLIENT_MODE:
5331 case QDF_IBSS_MODE:
5332 case QDF_P2P_DEVICE_MODE:
5333 case QDF_NDI_MODE:
5334 wlan_hdd_scan_abort(adapter);
5335 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5336 if (adapter->device_mode == QDF_STA_MODE)
Dustin Brown07901ec2018-09-07 11:02:41 -07005337 wlan_cfg80211_sched_scan_stop(hdd_ctx->pdev,
5338 adapter->dev);
Paul Zhang84fa9382017-11-10 21:18:21 +08005339 break;
5340 case QDF_P2P_GO_MODE:
5341 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5342 break;
5343 case QDF_SAP_MODE:
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305344 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Paul Zhang84fa9382017-11-10 21:18:21 +08005345 wlan_hdd_undo_acs(adapter);
5346 break;
5347 default:
5348 break;
5349 }
5350}
5351
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005352QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005353{
Jeff Johnson9d295242017-08-29 14:39:48 -07005354 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07005355 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07005356 struct qdf_mac_addr peerMacAddr;
Yue Ma42654682018-01-11 16:55:24 -08005357 int sta_id;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05305358 bool value;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005359
Dustin Brown491d54b2018-03-14 12:39:11 -07005360 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005361
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305362 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5363
Dustin Brown920397d2017-12-13 16:27:50 -08005364 hdd_for_each_adapter(hdd_ctx, adapter) {
Dustin Brown5e89ef82018-03-14 11:50:23 -07005365 hdd_info("[SSR] reset adapter with device mode %s(%d)",
5366 hdd_device_mode_to_string(adapter->device_mode),
5367 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305368
5369 if ((adapter->device_mode == QDF_STA_MODE) ||
Paul Zhang679025e2018-03-08 22:39:44 +08005370 (adapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305371 /* Stop tdls timers */
Dustin Brown89fa06e2018-09-07 10:47:27 -07005372 hdd_notify_tdls_reset_adapter(adapter->vdev);
Paul Zhang679025e2018-03-08 22:39:44 +08005373 adapter->session.station.hdd_reassoc_scenario = false;
5374 }
Dustin Brown05d81302018-09-11 16:49:22 -07005375 ucfg_mlme_get_sap_internal_restart(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05305376 if (value &&
Arun Khandavallicc544b32017-01-30 19:52:16 +05305377 adapter->device_mode == QDF_SAP_MODE) {
5378 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305379 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05305380 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005381 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08005382 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005383 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005384 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
5385 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305386 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305387 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005388 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005389 }
Nijun Gong104ccc72018-08-07 10:43:56 +08005390 /*
5391 * Clear fc flag if it was set before SSR to avoid TX queues
5392 * permanently stopped after SSR.
5393 * Here WLAN_START_ALL_NETIF_QUEUE will actually not start any
5394 * queue since it's blocked by reason WLAN_CONTROL_PATH.
5395 */
5396 if (adapter->pause_map & (1 << WLAN_DATA_FLOW_CONTROL))
5397 wlan_hdd_netif_queue_control(adapter,
5398 WLAN_START_ALL_NETIF_QUEUE,
5399 WLAN_DATA_FLOW_CONTROL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005400
Paul Zhang84fa9382017-11-10 21:18:21 +08005401 hdd_reset_scan_operation(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005402
5403 hdd_deinit_tx_rx(adapter);
Dustin Brown1dbefe62018-09-11 16:32:03 -07005404 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005405 adapter->device_mode, adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005406 hdd_green_ap_start_state_mc(hdd_ctx, adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305407 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005408 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5409 hdd_wmm_adapter_close(adapter);
5410 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5411 }
5412
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305413 if (adapter->device_mode == QDF_STA_MODE)
5414 hdd_clear_fils_connection_info(adapter);
5415
Wu Gao3545e642017-07-14 19:24:41 +08005416 if (adapter->device_mode == QDF_SAP_MODE) {
Jingxiang Geec113592018-08-09 15:40:39 +08005417 wlansap_cleanup_cac_timer(
5418 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Wu Gao3545e642017-07-14 19:24:41 +08005419 /*
5420 * If adapter is SAP, set session ID to invalid
5421 * since SAP session will be cleanup during SSR.
5422 */
Wu Gao36717432016-11-21 15:09:48 +08005423 wlansap_set_invalid_session(
5424 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Wu Gao3545e642017-07-14 19:24:41 +08005425 }
5426
Yue Ma42654682018-01-11 16:55:24 -08005427 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005428 if (adapter->device_mode == QDF_STA_MODE ||
5429 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005430 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005431 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07005432 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005433
Yue Ma42654682018-01-11 16:55:24 -08005434 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
Wu Gao6b81fc52018-05-24 19:27:27 +08005435 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Yue Ma42654682018-01-11 16:55:24 -08005436 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5437 if (adapter->sta_info[sta_id].in_use) {
5438 hdd_debug("[SSR] deregister STA with ID %d",
5439 sta_id);
5440 hdd_softap_deregister_sta(adapter,
5441 sta_id);
5442 adapter->sta_info[sta_id].in_use = 0;
5443 }
5444 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005445 }
5446
Alok Kumarb64650c2018-03-23 17:05:11 +05305447 hdd_nud_ignore_tracking(adapter, true);
Alok Kumar016a1ac2018-09-16 09:55:50 +05305448 hdd_nud_reset_tracking(adapter);
5449 hdd_nud_flush_work(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05305450 hdd_set_disconnect_status(adapter, false);
5451
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005452 hdd_softap_deinit_tx_rx(adapter);
Tiger Yu8c387702018-07-06 16:56:42 +08005453 hdd_deregister_tx_flow_control(adapter);
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005454
Yue Maf9782842017-05-08 12:49:49 -07005455 /* Destroy vdev which will be recreated during reinit. */
5456 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005457 }
5458
Dustin Browne74003f2018-03-14 12:51:58 -07005459 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005460
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305461 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005462}
5463
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005464bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305465{
Dustin Brown920397d2017-12-13 16:27:50 -08005466 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305467 bool close_modules = true;
5468
Arun Khandavalliba479c42017-07-26 21:29:40 +05305469 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
5470 hdd_info("FTM mode, don't close the module");
5471 return false;
5472 }
5473
Dustin Brown920397d2017-12-13 16:27:50 -08005474 hdd_for_each_adapter(hdd_ctx, adapter) {
5475 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
5476 test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005477 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305478 close_modules = false;
5479 break;
5480 }
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305481 }
5482
5483 return close_modules;
5484}
5485
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305486bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305487{
5488 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5489 return true;
5490 else
5491 return false;
5492}
5493
Anurag Chouhanc4092922016-09-08 15:56:11 +05305494#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08005495 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305496struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5497 struct ieee80211_channel *channel,
5498 const u8 *bssid, const u8 *ssid,
5499 size_t ssid_len)
5500{
5501 return cfg80211_get_bss(wiphy, channel, bssid,
5502 ssid, ssid_len,
5503 WLAN_CAPABILITY_ESS,
5504 WLAN_CAPABILITY_ESS);
5505}
5506#else
5507struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5508 struct ieee80211_channel *channel,
5509 const u8 *bssid, const u8 *ssid,
5510 size_t ssid_len)
5511{
5512 return cfg80211_get_bss(wiphy, channel, bssid,
5513 ssid, ssid_len,
5514 IEEE80211_BSS_TYPE_ESS,
5515 IEEE80211_PRIVACY_ANY);
5516}
5517#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305518
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305519#if defined CFG80211_CONNECT_BSS || \
5520 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305521#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305522 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305523/**
5524 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5525 * @timeout_reason: reason for connect timeout
5526 *
5527 * This function is used to convert host timeout
5528 * reason enum to kernel specific enum.
5529 *
5530 * Return: nl timeout enum
5531 */
5532static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5533 tSirResultCodes timeout_reason)
5534{
5535 switch (timeout_reason) {
5536 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5537 return NL80211_TIMEOUT_SCAN;
5538 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5539 return NL80211_TIMEOUT_AUTH;
5540 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5541 return NL80211_TIMEOUT_ASSOC;
5542 default:
5543 return NL80211_TIMEOUT_UNSPECIFIED;
5544 }
5545}
5546
5547/**
5548 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5549 * @dev: network device
5550 * @bssid: bssid to which we want to associate
5551 * @timeout_reason: reason for connect timeout
5552 *
5553 * This API is used to send connection timeout reason to supplicant
5554 *
5555 * Return: void
5556 */
5557static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5558 const u8 *bssid,
5559 tSirResultCodes timeout_reason)
5560{
5561 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005562
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305563 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5564
5565 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5566 nl_timeout_reason);
5567}
5568
5569/**
5570 * __hdd_connect_bss() - API to send connection status to supplicant
5571 * @dev: network device
5572 * @bssid: bssid to which we want to associate
5573 * @req_ie: Request Information Element
5574 * @req_ie_len: len of the req IE
5575 * @resp_ie: Response IE
5576 * @resp_ie_len: len of ht response IE
5577 * @status: status
5578 * @gfp: Kernel Flag
5579 * @timeout_reason: reason for connect timeout
5580 *
5581 * Return: void
5582 */
5583static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5584 struct cfg80211_bss *bss, const u8 *req_ie,
5585 size_t req_ie_len, const u8 *resp_ie,
5586 size_t resp_ie_len, int status, gfp_t gfp,
5587 tSirResultCodes timeout_reason)
5588{
5589 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005590
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305591 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5592
5593 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5594 resp_ie, resp_ie_len, status, gfp,
5595 nl_timeout_reason);
5596}
5597#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305598#if defined CFG80211_CONNECT_TIMEOUT || \
5599 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305600static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5601 const u8 *bssid,
5602 tSirResultCodes timeout_reason)
5603{
5604 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5605}
5606#endif
5607
5608static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5609 struct cfg80211_bss *bss, const u8 *req_ie,
5610 size_t req_ie_len, const u8 *resp_ie,
5611 size_t resp_ie_len, int status, gfp_t gfp,
5612 tSirResultCodes timeout_reason)
5613{
5614 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5615 resp_ie, resp_ie_len, status, gfp);
5616}
5617#endif
5618
Abhishek Singha84d3952016-09-13 13:45:05 +05305619/**
5620 * hdd_connect_bss() - API to send connection status to supplicant
5621 * @dev: network device
5622 * @bssid: bssid to which we want to associate
5623 * @req_ie: Request Information Element
5624 * @req_ie_len: len of the req IE
5625 * @resp_ie: Response IE
5626 * @resp_ie_len: len of ht response IE
5627 * @status: status
5628 * @gfp: Kernel Flag
5629 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305630 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05305631 *
5632 * The API is a wrapper to send connection status to supplicant
5633 *
5634 * Return: Void
5635 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305636#if defined CFG80211_CONNECT_TIMEOUT || \
5637 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05305638static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5639 struct cfg80211_bss *bss, const u8 *req_ie,
5640 size_t req_ie_len, const u8 *resp_ie,
5641 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305642 bool connect_timeout,
5643 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305644{
5645 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305646 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305647 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305648 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5649 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305650}
5651#else
5652static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5653 struct cfg80211_bss *bss, const u8 *req_ie,
5654 size_t req_ie_len, const u8 *resp_ie,
5655 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305656 bool connect_timeout,
5657 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305658{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305659 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5660 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305661}
5662#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305663
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305664#if defined(WLAN_FEATURE_FILS_SK)
5665#if defined(CFG80211_CONNECT_DONE) || \
5666 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
5667#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
5668 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305669/**
5670 * hdd_populate_fils_params() - Populate FILS keys to connect response
5671 * @fils_params: connect response to supplicant
5672 * @fils_kek: FILS kek
5673 * @fils_kek_len: FILS kek length
5674 * @pmk: FILS PMK
5675 * @pmk_len: FILS PMK length
5676 * @pmkid: PMKID
5677 * @fils_seq_num: FILS Seq number
5678 *
5679 * Return: None
5680 */
5681static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5682 *fils_params, const uint8_t *fils_kek,
5683 size_t fils_kek_len, const uint8_t *pmk,
5684 size_t pmk_len, const uint8_t *pmkid,
5685 uint16_t fils_seq_num)
5686{
5687 /* Increament seq number to be used for next FILS */
5688 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
5689 fils_params->update_erp_next_seq_num = true;
5690 fils_params->fils_kek = fils_kek;
5691 fils_params->fils_kek_len = fils_kek_len;
5692 fils_params->pmk = pmk;
5693 fils_params->pmk_len = pmk_len;
5694 fils_params->pmkid = pmkid;
5695}
5696#else
5697static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5698 *fils_params, const uint8_t
5699 *fils_kek, size_t fils_kek_len,
5700 const uint8_t *pmk, size_t pmk_len,
5701 const uint8_t *pmkid,
5702 uint16_t fils_seq_num)
5703{ }
5704#endif
5705
Jeff Johnson172237b2017-11-07 15:32:59 -08005706void hdd_update_hlp_info(struct net_device *dev,
5707 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305708{
5709 struct sk_buff *skb;
5710 uint16_t skb_len;
5711 struct llc_snap_hdr_t *llc_hdr;
5712 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305713 uint8_t *hlp_data;
5714 uint16_t hlp_data_len;
5715 struct fils_join_rsp_params *roam_fils_params
5716 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305717 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
5718
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305719 if (!roam_fils_params) {
5720 hdd_err("FILS Roam Param NULL");
5721 return;
5722 }
5723
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08005724 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305725 hdd_err("FILS HLP Data NULL, len %d",
5726 roam_fils_params->hlp_data_len);
5727 return;
5728 }
5729
5730 hlp_data = roam_fils_params->hlp_data;
5731 hlp_data_len = roam_fils_params->hlp_data_len;
5732
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305733 /* Calculate skb length */
5734 skb_len = (2 * ETH_ALEN) + hlp_data_len;
5735 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
5736 if (skb == NULL) {
5737 hdd_err("HLP packet nbuf alloc fails");
5738 return;
5739 }
5740
5741 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
5742 QDF_MAC_ADDR_SIZE);
5743 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
5744 QDF_MAC_ADDR_SIZE);
5745
5746 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
5747 if (IS_SNAP(llc_hdr)) {
5748 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5749 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5750 }
5751
5752 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
5753
5754 /*
5755 * This HLP packet is formed from HLP info encapsulated
5756 * in assoc response frame which is AEAD encrypted.
5757 * Hence, this checksum validation can be set unnecessary.
5758 * i.e. network layer need not worry about checksum.
5759 */
5760 skb->ip_summed = CHECKSUM_UNNECESSARY;
5761
5762 status = hdd_rx_packet_cbk(padapter, skb);
5763 if (QDF_IS_STATUS_ERROR(status)) {
5764 hdd_err("Sending HLP packet fails");
5765 return;
5766 }
5767 hdd_debug("send HLP packet to netif successfully");
5768}
5769
5770/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305771 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
5772 * @dev: network device
5773 * @bssid: bssid to which we want to associate
5774 * @bss: cfg80211 bss info
5775 * @roam_info: information about connected bss
5776 * @req_ie: Request Information Element
5777 * @req_ie_len: len of the req IE
5778 * @resp_ie: Response IE
5779 * @resp_ie_len: len of ht response IE
5780 * @status: status
5781 * @gfp: allocation flags
5782 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5783 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305784 *
5785 * This API is used as wrapper to send FILS key/sequence number
5786 * params etc. to supplicant in case of FILS connection
5787 *
5788 * Return: None
5789 */
5790static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005791 struct cfg80211_bss *bss,
5792 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305793 const u8 *req_ie, size_t req_ie_len,
5794 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005795 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305796 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305797{
5798 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305799 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5800 struct fils_join_rsp_params *roam_fils_params =
5801 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005802
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305803 qdf_mem_zero(&fils_params, sizeof(fils_params));
5804
5805 if (!roam_fils_params) {
5806 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5807 } else {
5808 fils_params.status = status;
5809 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08005810 fils_params.timeout_reason =
5811 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305812 fils_params.req_ie = req_ie;
5813 fils_params.req_ie_len = req_ie_len;
5814 fils_params.resp_ie = resp_ie;
5815 fils_params.resp_ie_len = resp_ie_len;
5816 fils_params.bss = bss;
5817 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5818 roam_fils_params->kek_len,
5819 roam_fils_params->fils_pmk,
5820 roam_fils_params->fils_pmk_len,
5821 roam_fils_params->fils_pmkid,
5822 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305823 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305824 }
5825 hdd_debug("FILS indicate connect status %d seq no %d",
5826 fils_params.status,
5827 fils_params.fils_erp_next_seq_num);
5828
5829 cfg80211_connect_done(dev, &fils_params, gfp);
5830
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305831 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305832 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305833
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305834 /* Clear all the FILS key info */
5835 if (roam_fils_params && roam_fils_params->fils_pmk)
5836 qdf_mem_free(roam_fils_params->fils_pmk);
5837 if (roam_fils_params)
5838 qdf_mem_free(roam_fils_params);
5839 roam_info->fils_join_rsp = NULL;
5840}
5841#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005842static inline void
5843hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005844 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005845 const u8 *req_ie, size_t req_ie_len,
5846 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5847 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305848 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305849{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305850#endif
5851#endif
5852
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305853#if defined(WLAN_FEATURE_FILS_SK) && \
5854 (defined(CFG80211_CONNECT_DONE) || \
5855 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305856/**
5857 * hdd_fils_update_connect_results() - API to send fils connection status to
5858 * supplicant.
5859 * @dev: network device
5860 * @bssid: bssid to which we want to associate
5861 * @bss: cfg80211 bss info
5862 * @roam_info: information about connected bss
5863 * @req_ie: Request Information Element
5864 * @req_ie_len: len of the req IE
5865 * @resp_ie: Response IE
5866 * @resp_ie_len: len of ht response IE
5867 * @status: status
5868 * @gfp: allocation flags
5869 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5870 * @timeout_reason: reason for connect timeout
5871 *
5872 * The API is a wrapper to send connection status to supplicant
5873 *
5874 * Return: 0 if success else failure
5875 */
5876static int hdd_fils_update_connect_results(struct net_device *dev,
5877 const u8 *bssid,
5878 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005879 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305880 size_t req_ie_len, const u8 *resp_ie,
5881 size_t resp_ie_len, u16 status, gfp_t gfp,
5882 bool connect_timeout,
5883 tSirResultCodes timeout_reason)
5884{
Dustin Brown491d54b2018-03-14 12:39:11 -07005885 hdd_enter();
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305886 if (!roam_info || !roam_info->is_fils_connection)
5887 return -EINVAL;
5888
5889 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5890 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305891 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305892 return 0;
5893}
5894#else
5895static inline int hdd_fils_update_connect_results(struct net_device *dev,
5896 const u8 *bssid,
5897 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005898 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305899 size_t req_ie_len, const u8 *resp_ie,
5900 size_t resp_ie_len, u16 status, gfp_t gfp,
5901 bool connect_timeout,
5902 tSirResultCodes timeout_reason)
5903{
5904 return -EINVAL;
5905}
5906#endif
5907
Anurag Chouhanc4092922016-09-08 15:56:11 +05305908/**
5909 * hdd_connect_result() - API to send connection status to supplicant
5910 * @dev: network device
5911 * @bssid: bssid to which we want to associate
5912 * @roam_info: information about connected bss
5913 * @req_ie: Request Information Element
5914 * @req_ie_len: len of the req IE
5915 * @resp_ie: Response IE
5916 * @resp_ie_len: len of ht response IE
5917 * @status: status
5918 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305919 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305920 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305921 *
5922 * The API is a wrapper to send connection status to supplicant
5923 * and allow runtime suspend
5924 *
5925 * Return: Void
5926 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305927void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005928 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305929 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305930 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305931 bool connect_timeout,
5932 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305933{
Jeff Johnson9d295242017-08-29 14:39:48 -07005934 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305935 struct cfg80211_bss *bss = NULL;
Jingxiang Ge929c7932018-01-24 14:01:12 +08005936 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305937
5938 if (WLAN_STATUS_SUCCESS == status) {
5939 struct ieee80211_channel *chan;
5940 int freq;
5941 int chan_no = roam_info->pBssDesc->channelId;
5942
5943 if (chan_no <= 14)
5944 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005945 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305946 else
5947 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005948 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305949
5950 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5951 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5952 roam_info->u.pConnectedProfile->SSID.ssId,
5953 roam_info->u.pConnectedProfile->SSID.length);
5954 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305955
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305956 if (hdd_fils_update_connect_results(dev, bssid, bss,
5957 roam_info, req_ie, req_ie_len, resp_ie,
5958 resp_ie_len, status, gfp, connect_timeout,
5959 timeout_reason) != 0) {
5960 hdd_connect_bss(dev, bssid, bss, req_ie,
5961 req_ie_len, resp_ie, resp_ie_len,
5962 status, gfp, connect_timeout, timeout_reason);
5963 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305964
Jingxiang Geb49aa302018-01-17 20:54:15 +08005965 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005966 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305967}
5968#else
5969void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005970 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305971 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305972 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305973 bool connect_timeout,
5974 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305975{
Jeff Johnson9d295242017-08-29 14:39:48 -07005976 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Jingxiang Ge929c7932018-01-24 14:01:12 +08005977 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05305978
Anurag Chouhanc4092922016-09-08 15:56:11 +05305979 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5980 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005981
Jingxiang Geb49aa302018-01-17 20:54:15 +08005982 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005983 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305984}
5985#endif
5986
Nirav Shah73713f72018-05-17 14:50:41 +05305987#ifdef FEATURE_MONITOR_MODE_SUPPORT
Jeff Johnsond9952752018-04-18 12:15:35 -07005988int wlan_hdd_set_mon_chan(struct hdd_adapter *adapter, uint32_t chan,
5989 uint32_t bandwidth)
5990{
5991 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
5992 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
5993 struct hdd_mon_set_ch_info *ch_info = &sta_ctx->ch_info;
5994 QDF_STATUS status;
Jeff Johnson43837af2018-10-17 12:44:05 -07005995 mac_handle_t mac_handle = hdd_ctx->mac_handle;
Jeff Johnsond9952752018-04-18 12:15:35 -07005996 struct qdf_mac_addr bssid;
5997 struct csr_roam_profile roam_profile;
5998 struct ch_params ch_params;
Chaoli Zhou75b062f2018-06-11 12:36:54 +08005999 eConnectionState connstate;
Jeff Johnsond9952752018-04-18 12:15:35 -07006000
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006001 if (hdd_get_conparam() != QDF_GLOBAL_MONITOR_MODE &&
6002 adapter->device_mode != QDF_STA_MODE) {
6003 hdd_err("Not supported, device is not in monitor mode or sta mission mode");
Jeff Johnsond9952752018-04-18 12:15:35 -07006004 return -EINVAL;
6005 }
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006006 if (adapter->device_mode == QDF_STA_MODE &&
6007 hdd_ctx->config->enable_change_channel_bandwidth) {
6008 connstate = sta_ctx->conn_info.connState;
6009 if (eConnectionState_Associated == connstate ||
6010 eConnectionState_Connecting == connstate) {
6011 return -EINVAL;
6012 }
6013 }
Jeff Johnsond9952752018-04-18 12:15:35 -07006014
Visweswara Tanuku006313a2018-04-12 12:26:34 +05306015 /* Validate Channel */
6016 if (!WLAN_REG_IS_24GHZ_CH(chan) && !WLAN_REG_IS_5GHZ_CH(chan)) {
6017 hdd_err("Channel %d Not supported", chan);
6018 return -EINVAL;
6019 }
6020
6021 if (WLAN_REG_IS_24GHZ_CH(chan)) {
6022 if (bandwidth == CH_WIDTH_80MHZ) {
6023 hdd_err("BW80 not possible in 2.4GHz band");
6024 return -EINVAL;
6025 }
6026 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 14) &&
6027 (bandwidth != CH_WIDTH_MAX)) {
6028 hdd_err("Only BW20 possible on channel 14");
6029 return -EINVAL;
6030 }
6031 }
6032
6033 if (WLAN_REG_IS_5GHZ_CH(chan)) {
6034 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 165) &&
6035 (bandwidth != CH_WIDTH_MAX)) {
6036 hdd_err("Only BW20 possible on channel 165");
6037 return -EINVAL;
6038 }
6039 }
6040
Jeff Johnsond9952752018-04-18 12:15:35 -07006041 hdd_debug("Set monitor mode Channel %d", chan);
6042 qdf_mem_zero(&roam_profile, sizeof(roam_profile));
6043 roam_profile.ChannelInfo.ChannelList = &ch_info->channel;
6044 roam_profile.ChannelInfo.numOfChannels = 1;
6045 roam_profile.phyMode = ch_info->phy_mode;
6046 roam_profile.ch_params.ch_width = bandwidth;
6047 hdd_select_cbmode(adapter, chan, &roam_profile.ch_params);
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006048 if (hdd_ctx->config->enable_change_channel_bandwidth &&
Jeff Johnson43837af2018-10-17 12:44:05 -07006049 (!sme_find_session_by_bssid(mac_handle, adapter->mac_addr.bytes))) {
6050 status = sme_create_mon_session(mac_handle,
Rajeev Kumar Sirasanagandlae3b59912018-08-24 15:53:31 +05306051 adapter->mac_addr.bytes,
6052 adapter->session_id);
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006053 if (status != QDF_STATUS_SUCCESS) {
6054 hdd_err("Status: %d Failed to create session.",
6055 status);
6056 return qdf_status_to_os_return(status);
6057 }
6058 }
Jeff Johnsond9952752018-04-18 12:15:35 -07006059 qdf_mem_copy(bssid.bytes, adapter->mac_addr.bytes,
6060 QDF_MAC_ADDR_SIZE);
6061
6062 ch_params.ch_width = bandwidth;
Dustin Brown07901ec2018-09-07 11:02:41 -07006063 wlan_reg_set_channel_params(hdd_ctx->pdev, chan, 0, &ch_params);
Jeff Johnsond9952752018-04-18 12:15:35 -07006064 if (ch_params.ch_width == CH_WIDTH_INVALID) {
6065 hdd_err("Invalid capture channel or bandwidth for a country");
6066 return -EINVAL;
6067 }
6068 if (wlan_hdd_change_hw_mode_for_given_chnl(adapter, chan,
6069 POLICY_MGR_UPDATE_REASON_SET_OPER_CHAN)) {
6070 hdd_err("Failed to change hw mode");
6071 return -EINVAL;
6072 }
6073
Jeff Johnson16528362018-06-14 12:34:16 -07006074 status = sme_roam_channel_change_req(hdd_ctx->mac_handle,
6075 bssid, &ch_params,
Jeff Johnsond9952752018-04-18 12:15:35 -07006076 &roam_profile);
6077 if (status) {
6078 hdd_err("Status: %d Failed to set sme_roam Channel for monitor mode",
6079 status);
6080 }
6081
6082 adapter->mon_chan = chan;
6083 adapter->mon_bandwidth = bandwidth;
6084 return qdf_status_to_os_return(status);
6085}
Nirav Shah73713f72018-05-17 14:50:41 +05306086#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05306087
Wu Gaodf929f12018-05-25 18:12:25 +08006088#ifdef MSM_PLATFORM
6089/**
6090 * hdd_stop_p2p_go() - call cfg80211 API to stop P2P GO
6091 * @adapter: pointer to adapter
6092 *
6093 * This function calls cfg80211 API to stop P2P GO
6094 *
6095 * Return: None
6096 */
6097static void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6098{
6099 hdd_debug("[SSR] send stop ap to supplicant");
6100 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
6101}
6102
6103static inline void hdd_delete_sta(struct hdd_adapter *adapter)
6104{
6105}
6106#else
6107static inline void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6108{
6109}
6110
6111/**
6112 * hdd_delete_sta() - call cfg80211 API to delete STA
6113 * @adapter: pointer to adapter
6114 *
6115 * This function calls cfg80211 API to delete STA
6116 *
6117 * Return: None
6118 */
6119static void hdd_delete_sta(struct hdd_adapter *adapter)
6120{
6121 struct qdf_mac_addr bcast_mac = QDF_MAC_ADDR_BCAST_INIT;
6122
6123 hdd_debug("[SSR] send restart supplicant");
6124 /* event supplicant to restart */
6125 cfg80211_del_sta(adapter->dev,
6126 (const u8 *)&bcast_mac.bytes[0],
6127 GFP_KERNEL);
6128}
6129#endif
6130
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006131QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006132{
Jeff Johnson9d295242017-08-29 14:39:48 -07006133 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006134 eConnectionState connState;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05306135 bool value;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006136
Dustin Brown491d54b2018-03-14 12:39:11 -07006137 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006138
Dustin Brown920397d2017-12-13 16:27:50 -08006139 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05306140 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08006141 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05306142
Yue Ma42654682018-01-11 16:55:24 -08006143 hdd_debug("[SSR] start adapter with device mode %s(%d)",
6144 hdd_device_mode_to_string(adapter->device_mode),
6145 adapter->device_mode);
6146
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006147 hdd_wmm_init(adapter);
6148
6149 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006150 case QDF_STA_MODE:
6151 case QDF_P2P_CLIENT_MODE:
6152 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006153
6154 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
6155 ->conn_info.connState;
6156
Krunal Sonib51eec72017-11-20 21:53:01 -08006157 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006158 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07006159 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006160
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006161 /* Indicate disconnect event to supplicant
6162 * if associated previously
6163 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006164 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07006165 eConnectionState_IbssConnected == connState ||
6166 eConnectionState_NotConnected == connState ||
6167 eConnectionState_IbssDisconnected == connState ||
6168 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006169 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006170
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006171 memset(&wrqu, '\0', sizeof(wrqu));
6172 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
6173 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
6174 wireless_send_event(adapter->dev, SIOCGIWAP,
6175 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07006176 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07006177 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006178
6179 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05306180 wlan_hdd_cfg80211_indicate_disconnect(
6181 adapter->dev, false,
6182 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006183 } else if (eConnectionState_Connecting == connState) {
6184 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006185 * Indicate connect failure to supplicant if we
6186 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006187 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306188 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306189 NULL, 0, NULL, 0,
6190 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006191 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006192 }
6193
6194 hdd_register_tx_flow_control(adapter,
6195 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08006196 hdd_tx_resume_cb,
6197 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006198
Arunk Khandavalli40943af2017-05-15 19:25:34 +05306199 hdd_lpass_notify_start(hdd_ctx, adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05306200 hdd_nud_ignore_tracking(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006201 break;
6202
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006203 case QDF_SAP_MODE:
Dustin Brown05d81302018-09-11 16:49:22 -07006204 ucfg_mlme_get_sap_internal_restart(hdd_ctx->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05306205 &value);
6206 if (value)
Krunal Sonib51eec72017-11-20 21:53:01 -08006207 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05306208
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006209 break;
6210
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006211 case QDF_P2P_GO_MODE:
Wu Gaodf929f12018-05-25 18:12:25 +08006212 hdd_delete_sta(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006213 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306214 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08006215 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306216 hdd_set_mon_rx_cb(adapter->dev);
6217 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
6218 adapter->mon_bandwidth);
6219 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006220 default:
6221 break;
6222 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07006223 /*
6224 * Action frame registered in one adapter which will
6225 * applicable to all interfaces
6226 */
6227 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006228 }
6229
Wu Gaodf929f12018-05-25 18:12:25 +08006230 hdd_for_each_adapter(hdd_ctx, adapter) {
6231 if (!hdd_is_interface_up(adapter))
6232 continue;
6233
6234 if (adapter->device_mode == QDF_P2P_GO_MODE)
6235 hdd_stop_p2p_go(adapter);
6236 }
6237
Dustin Browne74003f2018-03-14 12:51:58 -07006238 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006239
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306240 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006241}
6242
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006243QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006244 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006245{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306246 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006247 qdf_list_node_t *node;
6248
6249 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006250
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006251 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006252 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006253 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006254
6255 if (QDF_IS_STATUS_ERROR(status))
6256 return status;
6257
6258 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6259
6260 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006261}
6262
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006263QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006264 struct hdd_adapter *current_adapter,
6265 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006266{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306267 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006268 qdf_list_node_t *node;
6269
6270 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006271
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006272 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006273 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08006274 &current_adapter->node,
6275 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006276 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006277
6278 if (QDF_IS_STATUS_ERROR(status))
6279 return status;
6280
6281 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6282
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006283 return status;
6284}
6285
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006286QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006287 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006288{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306289 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006290
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006291 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006292 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006293 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006294
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006295 return status;
6296}
6297
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006298QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006299 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006300{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306301 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006302 qdf_list_node_t *node;
6303
6304 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006305
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006306 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006307 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006308 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006309
6310 if (QDF_IS_STATUS_ERROR(status))
6311 return status;
6312
6313 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6314
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006315 return status;
6316}
6317
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006318QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006319 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006320{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306321 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006322
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006323 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006324 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006325 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006326
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006327 return status;
6328}
6329
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006330QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006331 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006332{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306333 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006334
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006335 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006336 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006337 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006338
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006339 return status;
6340}
6341
Jeff Johnson9d295242017-08-29 14:39:48 -07006342struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006343 tSirMacAddr macAddr)
6344{
Jeff Johnson9d295242017-08-29 14:39:48 -07006345 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006346
Dustin Brown920397d2017-12-13 16:27:50 -08006347 hdd_for_each_adapter(hdd_ctx, adapter) {
6348 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
6349 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006350 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006351 }
6352
6353 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006354}
6355
Jeff Johnson9d295242017-08-29 14:39:48 -07006356struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006357 uint32_t vdev_id)
6358{
Jeff Johnson9d295242017-08-29 14:39:48 -07006359 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006360
Dustin Brown920397d2017-12-13 16:27:50 -08006361 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07006362 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006363 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006364 }
6365
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006366 return NULL;
6367}
6368
Abhishek Singh7996eb72015-12-30 17:24:02 +05306369/**
6370 * hdd_get_adapter_by_sme_session_id() - Return adapter with
6371 * the sessionid
6372 * @hdd_ctx: hdd context.
6373 * @sme_session_id: sme session is for the adapter to get.
6374 *
6375 * This function is used to get the adapter with provided session id
6376 *
6377 * Return: adapter pointer if found
6378 *
6379 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07006380struct hdd_adapter *
6381hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
6382 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306383{
Jeff Johnson9d295242017-08-29 14:39:48 -07006384 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306385
Dustin Brown920397d2017-12-13 16:27:50 -08006386 hdd_for_each_adapter(hdd_ctx, adapter) {
6387 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306388 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306389 }
Dustin Brown920397d2017-12-13 16:27:50 -08006390
Abhishek Singh7996eb72015-12-30 17:24:02 +05306391 return NULL;
6392}
6393
Jeff Johnson9d295242017-08-29 14:39:48 -07006394struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07006395 const char *iface_name)
6396{
Jeff Johnson9d295242017-08-29 14:39:48 -07006397 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006398
Dustin Brown920397d2017-12-13 16:27:50 -08006399 hdd_for_each_adapter(hdd_ctx, adapter) {
6400 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07006401 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006402 }
Dustin Brown920397d2017-12-13 16:27:50 -08006403
Naveen Rawat4edb6822017-04-12 10:09:17 -07006404 return NULL;
6405}
6406
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006407/**
6408 * hdd_get_adapter() - to get adapter matching the mode
6409 * @hdd_ctx: hdd context
6410 * @mode: adapter mode
6411 *
6412 * This routine will return the pointer to adapter matching
6413 * with the passed mode.
6414 *
6415 * Return: pointer to adapter or null
6416 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006417struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006418 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006419{
Jeff Johnson9d295242017-08-29 14:39:48 -07006420 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006421
Dustin Brown920397d2017-12-13 16:27:50 -08006422 hdd_for_each_adapter(hdd_ctx, adapter) {
6423 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006424 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006425 }
6426
6427 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006428}
6429
Jeff Johnson36a0abf2018-05-20 11:24:25 -07006430enum QDF_OPMODE hdd_get_device_mode(uint32_t session_id)
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306431{
6432 struct hdd_context *hdd_ctx;
6433 struct hdd_adapter *adapter;
6434
6435 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
6436 if (!hdd_ctx) {
6437 hdd_err("Invalid HDD context");
6438 return QDF_MAX_NO_OF_MODE;
6439 }
6440
6441 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
6442 if (!adapter) {
6443 hdd_err("Invalid HDD adapter");
6444 return QDF_MAX_NO_OF_MODE;
6445 }
6446
6447 return adapter->device_mode;
6448}
6449
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006450/**
6451 * hdd_get_operating_channel() - return operating channel of the device mode
6452 * @hdd_ctx: Pointer to the HDD context.
6453 * @mode: Device mode for which operating channel is required.
Jeff Johnson77f89bb2018-05-06 16:21:36 -07006454 * Supported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006455 * QDF_STA_MODE,
6456 * QDF_P2P_CLIENT_MODE,
6457 * QDF_SAP_MODE,
6458 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006459 *
6460 * This API returns the operating channel of the requested device mode
6461 *
6462 * Return: channel number. "0" id the requested device is not found OR it is
6463 * not connected.
6464 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006465uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006466 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006467{
Jeff Johnson9d295242017-08-29 14:39:48 -07006468 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006469 uint8_t operatingChannel = 0;
6470
Dustin Brown920397d2017-12-13 16:27:50 -08006471 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006472 if (mode == adapter->device_mode) {
6473 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006474 case QDF_STA_MODE:
6475 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006476 if (hdd_conn_is_connected
6477 (WLAN_HDD_GET_STATION_CTX_PTR
6478 (adapter))) {
6479 operatingChannel =
6480 (WLAN_HDD_GET_STATION_CTX_PTR
6481 (adapter))->conn_info.
6482 operationChannel;
6483 }
6484 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006485 case QDF_SAP_MODE:
6486 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006487 /* softap connection info */
6488 if (test_bit
6489 (SOFTAP_BSS_STARTED,
6490 &adapter->event_flags))
6491 operatingChannel =
6492 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07006493 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006494 break;
6495 default:
6496 break;
6497 }
6498
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006499 /* Found the device of interest. break the loop */
6500 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006501 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006502 }
Dustin Brown920397d2017-12-13 16:27:50 -08006503
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006504 return operatingChannel;
6505}
6506
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006507static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006508 hdd_ctx)
6509{
Jeff Johnson9d295242017-08-29 14:39:48 -07006510 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006511
Dustin Brown491d54b2018-03-14 12:39:11 -07006512 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006513
Dustin Brown920397d2017-12-13 16:27:50 -08006514 hdd_for_each_adapter(hdd_ctx, adapter) {
6515 if (adapter->device_mode == QDF_STA_MODE ||
6516 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6517 adapter->device_mode == QDF_IBSS_MODE ||
6518 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6519 adapter->device_mode == QDF_SAP_MODE ||
6520 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006521 hdd_unregister_wext(adapter->dev);
6522 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006523 }
6524
Dustin Browne74003f2018-03-14 12:51:58 -07006525 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006526
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306527 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006528}
6529
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006530QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006531{
Jeff Johnson9d295242017-08-29 14:39:48 -07006532 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006533
Dustin Brown491d54b2018-03-14 12:39:11 -07006534 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006535
Dustin Brown920397d2017-12-13 16:27:50 -08006536 hdd_for_each_adapter(hdd_ctx, adapter) {
6537 if (adapter->device_mode == QDF_STA_MODE ||
6538 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6539 adapter->device_mode == QDF_IBSS_MODE ||
6540 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6541 adapter->device_mode == QDF_SAP_MODE ||
6542 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brown07901ec2018-09-07 11:02:41 -07006543 wlan_abort_scan(hdd_ctx->pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006544 adapter->session_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05306545 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006546 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006547 }
6548
Dustin Browne74003f2018-03-14 12:51:58 -07006549 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006550
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306551 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006552}
6553
Dustin Brownf27bce82016-11-03 12:52:27 -07006554/**
6555 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
6556 * adapters
6557 * @hdd_ctx: The HDD context containing the adapters to operate on
6558 *
6559 * return: QDF_STATUS_SUCCESS
6560 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006561static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07006562{
Jeff Johnson9d295242017-08-29 14:39:48 -07006563 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07006564 int err;
6565
Dustin Brown491d54b2018-03-14 12:39:11 -07006566 hdd_enter();
Dustin Brownf27bce82016-11-03 12:52:27 -07006567
Dustin Brown920397d2017-12-13 16:27:50 -08006568 hdd_for_each_adapter(hdd_ctx, adapter) {
6569 if (adapter->device_mode == QDF_STA_MODE ||
6570 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6571 adapter->device_mode == QDF_IBSS_MODE ||
6572 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6573 adapter->device_mode == QDF_SAP_MODE ||
6574 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07006575 err = wlan_hdd_sched_scan_stop(adapter->dev);
6576 if (err)
6577 hdd_err("Unable to stop scheduled scan");
6578 }
Dustin Brownf27bce82016-11-03 12:52:27 -07006579 }
6580
Dustin Browne74003f2018-03-14 12:51:58 -07006581 hdd_exit();
Dustin Brownf27bce82016-11-03 12:52:27 -07006582
6583 return QDF_STATUS_SUCCESS;
6584}
6585
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006586#ifdef WLAN_NS_OFFLOAD
6587/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006588 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006589 * @hdd_ctx: Pointer to hdd context
6590 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006591 * Unregister for IPv6 address change notifications.
6592 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006593 * Return: None
6594 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006595static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006596{
6597 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006598}
6599
6600/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006601 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006602 * @hdd_ctx: Pointer to hdd context
6603 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006604 * Register for IPv6 address change notifications.
6605 *
6606 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006607 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006608static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006609{
6610 int ret;
6611
6612 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
6613 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006614 if (ret) {
6615 hdd_err("Failed to register IPv6 notifier: %d", ret);
6616 goto out;
6617 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006618
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006619 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006620out:
6621 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006622}
6623#else
6624/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006625 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006626 * @hdd_ctx: Pointer to hdd context
6627 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006628 * Unregister for IPv6 address change notifications.
6629 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006630 * Return: None
6631 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006632static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006633{
6634}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006635
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006636/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006637 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006638 * @hdd_ctx: Pointer to hdd context
6639 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006640 * Register for IPv6 address change notifications.
6641 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006642 * Return: None
6643 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006644static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006645{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006646 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006647}
6648#endif
6649
Alok Kumarb64650c2018-03-23 17:05:11 +05306650void hdd_set_disconnect_status(struct hdd_adapter *adapter, bool status)
6651{
6652 qdf_mutex_acquire(&adapter->disconnection_status_lock);
6653 adapter->disconnection_in_progress = status;
6654 qdf_mutex_release(&adapter->disconnection_status_lock);
6655 hdd_debug("setting disconnection status: %d", status);
6656}
6657
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006658/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006659 * hdd_register_notifiers - Register netdev notifiers.
6660 * @hdd_ctx: HDD context
6661 *
6662 * Register netdev notifiers like IPv4 and IPv6.
6663 *
6664 * Return: 0 on success and errno on failure
6665 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006666static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006667{
6668 int ret;
6669
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006670 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
6671 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306672 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006673
6674 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
6675 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
6676 if (ret) {
6677 hdd_err("Failed to register IPv4 notifier: %d", ret);
6678 goto unregister_ip6_notifier;
6679 }
6680
Alok Kumarb64650c2018-03-23 17:05:11 +05306681 ret = hdd_nud_register_netevent_notifier(hdd_ctx);
6682 if (ret) {
6683 hdd_err("Failed to register netevent notifier: %d",
6684 ret);
6685 goto unregister_inetaddr_notifier;
6686 }
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006687 return 0;
6688
Alok Kumarb64650c2018-03-23 17:05:11 +05306689unregister_inetaddr_notifier:
6690 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006691unregister_ip6_notifier:
6692 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006693out:
6694 return ret;
6695
6696}
6697
6698/**
6699 * hdd_unregister_notifiers - Unregister netdev notifiers.
6700 * @hdd_ctx: HDD context
6701 *
6702 * Unregister netdev notifiers like IPv4 and IPv6.
6703 *
6704 * Return: None.
6705 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006706void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006707{
Alok Kumarb64650c2018-03-23 17:05:11 +05306708 hdd_nud_unregister_netevent_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006709 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
6710
6711 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006712}
6713
6714/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006715 * hdd_exit_netlink_services - Exit netlink services
6716 * @hdd_ctx: HDD context
6717 *
6718 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
6719 * nl service.
6720 *
6721 * Return: None.
6722 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006723static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006724{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306725 spectral_scan_deactivate_service();
6726 cnss_diag_deactivate_service();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006727 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006728 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306729 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006730
6731 nl_srv_exit();
6732}
6733
6734/**
6735 * hdd_init_netlink_services- Init netlink services
6736 * @hdd_ctx: HDD context
6737 *
6738 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
6739 * nl service.
6740 *
6741 * Return: 0 on success and errno on failure.
6742 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006743static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006744{
6745 int ret;
6746
Ryan Hsuceddceb2016-04-28 10:20:14 -07006747 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006748 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006749 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006750 goto out;
6751 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07006752 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006753
Naveen Rawat910726a2017-03-06 11:42:51 -08006754 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006755 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006756 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006757 goto err_nl_srv;
6758 }
6759
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306760 ptt_sock_activate_svc();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006761
6762 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07006763 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006764 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006765
6766 ret = cnss_diag_activate_service();
6767 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006768 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006769 goto err_close_cesium;
6770 }
6771
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306772 spectral_scan_activate_service();
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08006773
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006774 return 0;
6775
6776err_close_cesium:
6777 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006778 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306779 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006780err_nl_srv:
6781 nl_srv_exit();
6782out:
6783 return ret;
6784}
6785
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006786/**
6787 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
6788 * @hdd_ctx: HDD context.
6789 *
6790 * Destroy RX wakelock.
6791 *
6792 * Return: None.
6793 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006794static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006795{
6796 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
6797}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006798
6799/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006800 * hdd_rx_wake_lock_create() - Create RX wakelock
6801 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006802 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006803 * Create RX wakelock.
6804 *
6805 * Return: None.
6806 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006807static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006808{
6809 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
6810}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006811
6812/**
Houston Hoffman160db392016-10-10 17:37:51 -07006813 * hdd_context_deinit() - Deinitialize HDD context
6814 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006815 *
Houston Hoffman160db392016-10-10 17:37:51 -07006816 * Deinitialize HDD context along with all the feature specific contexts but
6817 * do not free hdd context itself. Caller of this API is supposed to free
6818 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006819 *
Houston Hoffman160db392016-10-10 17:37:51 -07006820 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006821 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006822static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006823{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306824 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
6825
Houston Hoffman160db392016-10-10 17:37:51 -07006826 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006827
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006828 hdd_sap_context_destroy(hdd_ctx);
6829
6830 hdd_rx_wake_lock_destroy(hdd_ctx);
6831
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006832 hdd_scan_context_destroy(hdd_ctx);
6833
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006834 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006835
Houston Hoffman160db392016-10-10 17:37:51 -07006836 return 0;
6837}
6838
6839/**
6840 * hdd_context_destroy() - Destroy HDD context
6841 * @hdd_ctx: HDD context to be destroyed.
6842 *
6843 * Free config and HDD context as well as destroy all the resources.
6844 *
6845 * Return: None
6846 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006847static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07006848{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07006849 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05306850
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05306851 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
6852
Houston Hoffman160db392016-10-10 17:37:51 -07006853 hdd_context_deinit(hdd_ctx);
6854
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306855 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006856 hdd_ctx->config = NULL;
6857
Dustin Brown84f46ea2018-02-15 11:57:36 -08006858 cfg_release();
6859
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006860 wiphy_free(hdd_ctx->wiphy);
6861}
6862
6863/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306864 * wlan_destroy_bug_report_lock() - Destroy bug report lock
6865 *
6866 * This function is used to destroy bug report lock
6867 *
6868 * Return: None
6869 */
6870static void wlan_destroy_bug_report_lock(void)
6871{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07006872 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306873
6874 p_cds_context = cds_get_global_context();
6875 if (!p_cds_context) {
6876 hdd_err("cds context is NULL");
6877 return;
6878 }
6879
6880 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6881}
6882
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05306883#ifdef DISABLE_CHANNEL_LIST
6884static void wlan_hdd_cache_chann_mutex_destroy(struct hdd_context *hdd_ctx)
6885{
6886 qdf_mutex_destroy(&hdd_ctx->cache_channel_lock);
6887}
6888#else
6889static void wlan_hdd_cache_chann_mutex_destroy(struct hdd_context *hdd_ctx)
6890{
6891}
6892#endif
6893
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306894/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006895 * hdd_wlan_exit() - HDD WLAN exit function
6896 * @hdd_ctx: Pointer to the HDD Context
6897 *
6898 * This is the driver exit point (invoked during rmmod)
6899 *
6900 * Return: None
6901 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006902static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006903{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006904 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306905 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006906
Dustin Brown491d54b2018-03-14 12:39:11 -07006907 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006908
Dustin Brown6470aba2018-09-05 09:49:58 -07006909 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
6910
Arun Khandavallifae92942016-08-01 13:31:08 +05306911 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006912
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006913#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306914 if (QDF_TIMER_STATE_RUNNING ==
6915 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6916 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006917 }
6918
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306919 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306920 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006921 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006922 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006923 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6924 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6925 hdd_ctx->last_acs_channel_list = NULL;
6926 hdd_ctx->num_of_channels = 0;
6927 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006928#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006929
Arun Khandavallifae92942016-08-01 13:31:08 +05306930 mutex_lock(&hdd_ctx->iface_change_lock);
6931 driver_status = hdd_ctx->driver_status;
6932 mutex_unlock(&hdd_ctx->iface_change_lock);
6933
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006934 /*
6935 * Powersave Offload Case
6936 * Disable Idle Power Save Mode
6937 */
6938 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07006939 /* clear the scan queue in all the scenarios */
Dustin Brown07901ec2018-09-07 11:02:41 -07006940 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006941
Arun Khandavallifae92942016-08-01 13:31:08 +05306942 if (driver_status != DRIVER_MODULES_CLOSED) {
6943 hdd_unregister_wext_all_adapters(hdd_ctx);
6944 /*
6945 * Cancel any outstanding scan requests. We are about to close
6946 * all of our adapters, but an adapter structure is what SME
6947 * passes back to our callback function. Hence if there
6948 * are any outstanding scan requests then there is a
6949 * race condition between when the adapter is closed and
6950 * when the callback is invoked. We try to resolve that
6951 * race condition here by canceling any outstanding scans
6952 * before we close the adapters.
6953 * Note that the scans may be cancelled in an asynchronous
6954 * manner, so ideally there needs to be some kind of
6955 * synchronization. Rather than introduce a new
6956 * synchronization here, we will utilize the fact that we are
6957 * about to Request Full Power, and since that is synchronized,
6958 * the expectation is that by the time Request Full Power has
6959 * completed, all scans will be cancelled
6960 */
6961 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006962 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08006963 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08006964 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006965 }
6966
Arunk Khandavalli830c9692018-03-22 12:17:40 +05306967 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306968 unregister_netdevice_notifier(&hdd_netdev_notifier);
6969
Rachit Kankane30807332018-06-27 18:39:36 +05306970 qdf_dp_trace_deinit();
6971
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006972 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306973
Dustin Brown86d196b2018-08-02 11:51:49 -07006974 hdd_bus_bandwidth_deinit(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -08006975 hdd_driver_memdump_deinit();
6976
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306977 qdf_nbuf_deinit_replenish_timer();
6978
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306979 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
6980 hdd_info("Release wakelock for monitor mode!");
6981 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
6982 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
6983 }
6984
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306985 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6986 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6987 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05306988 wlan_hdd_cache_chann_mutex_destroy(hdd_ctx);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306989
Naveen Rawate02f8f52018-04-05 11:58:04 -07006990 osif_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006991
Dustin Brownd005ad82018-01-19 10:32:13 -08006992 hdd_close_all_adapters(hdd_ctx, false);
6993
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306994 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306995 /*
6996 * If there is re_init failure wiphy would have already de-registered
6997 * check the wiphy status before un-registering again
6998 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306999 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307000 wiphy_unregister(wiphy);
7001 wlan_hdd_cfg80211_deinit(wiphy);
7002 hdd_lpass_notify_stop(hdd_ctx);
7003 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07007004
Arun Khandavallifae92942016-08-01 13:31:08 +05307005 hdd_exit_netlink_services(hdd_ctx);
7006 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307007#ifdef FEATURE_WLAN_CH_AVOID
7008 mutex_destroy(&hdd_ctx->avoid_freq_lock);
7009#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05307010
Abhishek Singhe9068f12017-03-31 14:14:52 +05307011 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
7012 if (driver_status)
7013 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07007014
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007015 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007016}
7017
7018void __hdd_wlan_exit(void)
7019{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007020 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007021
Dustin Brown491d54b2018-03-14 12:39:11 -07007022 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007023
Anurag Chouhan6d760662016-02-20 16:05:43 +05307024 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007025 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007026 hdd_err("Invalid HDD Context");
Dustin Browne74003f2018-03-14 12:51:58 -07007027 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007028 return;
7029 }
7030
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007031 /* Do all the cleanup before deregistering the driver */
7032 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07007033
Dustin Browne74003f2018-03-14 12:51:58 -07007034 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007035}
7036
7037#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04007038/**
7039 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007040 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04007041 *
7042 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
7043 * Then new ACS request will do a fresh scan without reusing the cached
7044 * scan information.
7045 *
7046 * Return: void
7047 */
Tang Yingying523322d2017-01-17 23:28:43 +08007048static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007049{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007050 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Jeff Johnson16528362018-06-14 12:34:16 -07007051 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007052
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007053 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007054 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04007055 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
7056 qdf_mem_free(hdd_ctx->last_acs_channel_list);
7057 hdd_ctx->last_acs_channel_list = NULL;
7058 hdd_ctx->num_of_channels = 0;
7059 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007060
Jeff Johnson16528362018-06-14 12:34:16 -07007061 mac_handle = hdd_ctx->mac_handle;
7062 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007063 return;
Jeff Johnson16528362018-06-14 12:34:16 -07007064 sme_scan_flush_result(mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007065}
7066#endif
7067
7068#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07007069int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
7070 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007071{
7072 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307073 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07007074 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07007075 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007076
7077 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7078
7079 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307080 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007081 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307082
Jeff Johnson16528362018-06-14 12:34:16 -07007083 mac_handle = hdd_ctx->mac_handle;
7084 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007085 return -EINVAL;
7086
Jeff Johnson16528362018-06-14 12:34:16 -07007087 qdf_status = sme_notify_ht2040_mode(mac_handle, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007088 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307089 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007090 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007091 return -EINVAL;
7092 }
7093
7094 return 0;
7095}
7096#endif
7097
7098/**
7099 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
7100 * @state: state
7101 *
7102 * This function notifies FW with modem power status
7103 *
7104 * Return: 0 if successful, error number otherwise
7105 */
7106int hdd_wlan_notify_modem_power_state(int state)
7107{
7108 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307109 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007110 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07007111 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007112
Anurag Chouhan6d760662016-02-20 16:05:43 +05307113 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007114 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307115 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007116 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307117
Jeff Johnson16528362018-06-14 12:34:16 -07007118 mac_handle = hdd_ctx->mac_handle;
7119 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007120 return -EINVAL;
7121
Jeff Johnson16528362018-06-14 12:34:16 -07007122 qdf_status = sme_notify_modem_power_state(mac_handle, state);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307123 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007124 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007125 state);
7126 return -EINVAL;
7127 }
7128 return 0;
7129}
7130
7131/**
7132 *
7133 * hdd_post_cds_enable_config() - HDD post cds start config helper
7134 * @adapter - Pointer to the HDD
7135 *
7136 * Return: None
7137 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007138QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007139{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307140 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007141
7142 /*
7143 * Send ready indication to the HDD. This will kick off the MAC
7144 * into a 'running' state and should kick off an initial scan.
7145 */
Jeff Johnson16528362018-06-14 12:34:16 -07007146 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->mac_handle);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307147 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007148 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
7149 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307150 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007151 }
7152
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307153 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007154}
7155
Sourav Mohapatra92ea8d62018-02-05 10:03:10 +05307156struct hdd_adapter *hdd_get_first_valid_adapter(struct hdd_context *hdd_ctx)
7157{
7158 struct hdd_adapter *adapter;
7159
7160 hdd_for_each_adapter(hdd_ctx, adapter) {
7161 if (adapter && adapter->magic == WLAN_HDD_ADAPTER_MAGIC)
7162 return adapter;
7163 }
7164
7165 return NULL;
7166}
7167
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007168/* wake lock APIs for HDD */
7169void hdd_prevent_suspend(uint32_t reason)
7170{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307171 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007172}
7173
7174void hdd_allow_suspend(uint32_t reason)
7175{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307176 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007177}
7178
7179void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
7180{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05307181 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
7182 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007183}
7184
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007185/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007186QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007187{
Jeff Johnson16528362018-06-14 12:34:16 -07007188 return sme_init_chan_list(hdd_ctx->mac_handle,
Amar Singhal6f8592b2017-04-26 14:31:58 -07007189 hdd_ctx->reg.alpha2,
7190 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007191}
7192
7193/**
7194 * hdd_is_5g_supported() - check if hardware supports 5GHz
7195 * @hdd_ctx: Pointer to the hdd context
7196 *
7197 * HDD function to know if hardware supports 5GHz
7198 *
7199 * Return: true if hardware supports 5GHz
7200 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007201bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007202{
Amar Singhal58b45ef2017-08-01 13:43:54 -07007203 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08007204 return true;
7205
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08007206 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08007207 return true;
7208 else
7209 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007210}
7211
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007212static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007213{
7214 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07007215 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007216
7217 wiphy = hdd_ctx->wiphy;
7218
7219 /*
7220 * The channel information in
7221 * wiphy needs to be initialized before wiphy registration
7222 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007223 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
7224 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007225 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07007226 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007227 }
7228
7229#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
7230 wiphy->wowlan = &wowlan_support_reg_init;
7231#else
7232 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
7233 WIPHY_WOWLAN_MAGIC_PKT |
7234 WIPHY_WOWLAN_DISCONNECT |
7235 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
7236 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
7237 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
7238 WIPHY_WOWLAN_4WAY_HANDSHAKE |
7239 WIPHY_WOWLAN_RFKILL_RELEASE;
7240
7241 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
7242 WOW_MAX_FILTERS_PER_LIST);
7243 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
7244 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
7245#endif
Liangwei Dong0da14262018-07-03 03:30:23 -04007246 if (hdd_ctx->obss_scan_offload) {
7247 hdd_debug("wmi_service_obss_scan supported");
7248 } else if (hdd_ctx->config->nChannelBondingMode24GHz) {
7249 hdd_debug("enable wpa_supp obss_scan");
7250 wiphy->features |= NL80211_FEATURE_NEED_OBSS_SCAN;
7251 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007252
7253 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007254 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307255 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07007256 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307257 return ret_val;
7258 }
Amar Singhalac26de22018-06-22 12:53:06 -07007259
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007260 /* Check the kernel version for upstream commit aced43ce780dc5 that
7261 * has support for processing user cell_base hints when wiphy is
7262 * self managed or check the backport flag for the same.
7263 */
Amar Singhalac26de22018-06-22 12:53:06 -07007264#if defined CFG80211_USER_HINT_CELL_BASE_SELF_MANAGED || \
7265 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0))
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007266 hdd_send_wiphy_regd_sync_event(hdd_ctx);
7267#endif
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307268
Amar Singhal2d812012018-02-03 15:06:47 +08007269 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007270
Amar Singhale4f28ee2015-10-21 14:36:56 -07007271 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007272}
7273
Mohit Khannaca4173b2017-09-12 21:52:19 -07007274#ifdef MSM_PLATFORM
7275/**
7276 * hdd_display_periodic_stats() - Function to display periodic stats
7277 * @hdd_ctx - handle to hdd context
7278 * @bool data_in_interval - true, if data detected in bw time interval
7279 *
7280 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
7281 * Stats show up in wlan driver logs.
7282 *
7283 * Returns: None
7284 */
Mohit Khanna70322002018-05-15 19:21:32 -07007285static void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
7286 bool data_in_interval)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007287{
Mohit Khanna70322002018-05-15 19:21:32 -07007288 static uint32_t counter;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007289 static bool data_in_time_period;
7290 ol_txrx_pdev_handle pdev;
7291
7292 if (hdd_ctx->config->periodic_stats_disp_time == 0)
7293 return;
7294
7295 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
7296 if (!pdev) {
7297 hdd_err("pdev is NULL");
7298 return;
7299 }
7300
7301 counter++;
7302 if (data_in_interval)
7303 data_in_time_period = data_in_interval;
7304
jitiphil869b9f72018-09-25 17:14:01 +05307305 if (counter * hdd_ctx->config->bus_bw_compute_interval >=
Mohit Khannaca4173b2017-09-12 21:52:19 -07007306 hdd_ctx->config->periodic_stats_disp_time * 1000) {
7307 if (data_in_time_period) {
Mohit Khanna70322002018-05-15 19:21:32 -07007308 wlan_hdd_display_txrx_stats(hdd_ctx);
7309 dp_txrx_dump_stats(cds_get_context(QDF_MODULE_ID_SOC));
7310 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
7311 CDP_RX_RING_STATS,
7312 QDF_STATS_VERBOSITY_LEVEL_LOW);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007313 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
7314 CDP_TXRX_PATH_STATS,
7315 QDF_STATS_VERBOSITY_LEVEL_LOW);
7316 wlan_hdd_display_netif_queue_history
7317 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
7318 qdf_dp_trace_dump_stats();
7319 }
7320 counter = 0;
7321 data_in_time_period = false;
7322 }
7323}
7324
Ravi Joshie2331e82015-07-01 18:18:54 -07007325/**
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007326 * hdd_clear_rps_cpu_mask - clear RPS CPU mask for interfaces
7327 * @hdd_ctx: pointer to struct hdd_context
7328 *
7329 * Return: none
7330 */
7331static void hdd_clear_rps_cpu_mask(struct hdd_context *hdd_ctx)
7332{
7333 struct hdd_adapter *adapter;
7334
7335 hdd_for_each_adapter(hdd_ctx, adapter)
7336 hdd_send_rps_disable_ind(adapter);
7337}
7338
7339/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07007340 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07007341 * @hdd_ctx - handle to hdd context
7342 * @tx_packets - transmit packet count
7343 * @rx_packets - receive packet count
7344 *
7345 * The function controls the bus bandwidth and dynamic control of
7346 * tcp delayed ack configuration
7347 *
7348 * Returns: None
7349 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007350
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007351static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07007352 const uint64_t tx_packets,
7353 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007354{
Mohit Khannaca4173b2017-09-12 21:52:19 -07007355 u64 total_pkts = tx_packets + rx_packets;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007356 uint64_t temp_tx = 0, avg_rx = 0;
7357 uint64_t no_rx_offload_pkts = 0, avg_no_rx_offload_pkts = 0;
7358 uint64_t rx_offload_pkts = 0, avg_rx_offload_pkts = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007359 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08007360 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08007361 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007362 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007363 uint16_t index = 0;
7364 bool vote_level_change = false;
7365 bool rx_level_change = false;
7366 bool tx_level_change = false;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007367 bool rxthread_high_tput_req = false;
Mohit Khannaf7562c32018-07-05 17:42:36 -07007368 bool dptrace_high_tput_req;
Srinivas Girigowda50335342018-09-07 15:21:01 -07007369
jitiphil869b9f72018-09-25 17:14:01 +05307370 if (total_pkts > hdd_ctx->config->bus_bw_high_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007371 next_vote_level = PLD_BUS_WIDTH_HIGH;
jitiphil869b9f72018-09-25 17:14:01 +05307372 else if (total_pkts > hdd_ctx->config->bus_bw_medium_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007373 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
jitiphil869b9f72018-09-25 17:14:01 +05307374 else if (total_pkts > hdd_ctx->config->bus_bw_low_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007375 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07007376 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07007377 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007378
Mohit Khannaf7562c32018-07-05 17:42:36 -07007379 dptrace_high_tput_req =
7380 next_vote_level > PLD_BUS_WIDTH_NONE ? true : false;
7381
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007382 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07007383 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
7384 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007385 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007386 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007387 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007388 if ((next_vote_level == PLD_BUS_WIDTH_LOW) ||
7389 (next_vote_level == PLD_BUS_WIDTH_NONE)) {
Nirav Shahffc6a092016-06-09 16:09:08 +05307390 if (hdd_ctx->hbw_requested) {
7391 pld_remove_pm_qos(hdd_ctx->parent_dev);
7392 hdd_ctx->hbw_requested = false;
7393 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007394 if (hdd_ctx->dynamic_rps)
7395 hdd_clear_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007396 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05307397 if (!hdd_ctx->hbw_requested) {
7398 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
7399 hdd_ctx->hbw_requested = true;
7400 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007401 if (hdd_ctx->dynamic_rps)
7402 hdd_set_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007403 }
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007404
Manjunathappa Prakashcb6df762018-05-29 18:54:58 -07007405 if (hdd_ctx->config->napi_cpu_affinity_mask)
7406 hdd_napi_apply_throughput_policy(hdd_ctx,
7407 tx_packets,
7408 rx_packets);
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007409
jitiphil869b9f72018-09-25 17:14:01 +05307410 if (rx_packets < hdd_ctx->config->bus_bw_low_threshold)
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007411 hdd_disable_rx_ol_for_low_tput(hdd_ctx, true);
7412 else
7413 hdd_disable_rx_ol_for_low_tput(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007414 }
Mohit Khannae71e2262015-11-10 09:37:24 -08007415
Mohit Khannaf7562c32018-07-05 17:42:36 -07007416 qdf_dp_trace_apply_tput_policy(dptrace_high_tput_req);
7417
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007418 /*
7419 * Includes tcp+udp, if perf core is required for tcp, then
7420 * perf core is also required for udp.
7421 */
7422 no_rx_offload_pkts = hdd_ctx->no_rx_offload_pkt_cnt;
7423 hdd_ctx->no_rx_offload_pkt_cnt = 0;
7424 rx_offload_pkts = rx_packets - no_rx_offload_pkts;
Mohit Khannae71e2262015-11-10 09:37:24 -08007425
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007426 avg_no_rx_offload_pkts = (no_rx_offload_pkts +
7427 hdd_ctx->prev_no_rx_offload_pkts) / 2;
7428 hdd_ctx->prev_no_rx_offload_pkts = no_rx_offload_pkts;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08007429
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007430 avg_rx_offload_pkts = (rx_offload_pkts +
7431 hdd_ctx->prev_rx_offload_pkts) / 2;
7432 hdd_ctx->prev_rx_offload_pkts = rx_offload_pkts;
7433
7434 avg_rx = avg_no_rx_offload_pkts + avg_rx_offload_pkts;
7435 /*
7436 * Takes care to set Rx_thread affinity for below case
7437 * 1)LRO/GRO not supported ROME case
7438 * 2)when rx_ol is disabled in cases like concurrency etc
7439 * 3)For UDP cases
7440 */
7441 if (avg_no_rx_offload_pkts >
jitiphil869b9f72018-09-25 17:14:01 +05307442 hdd_ctx->config->bus_bw_high_threshold)
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007443 rxthread_high_tput_req = true;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307444 else
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007445 rxthread_high_tput_req = false;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307446
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007447 if (cds_sched_handle_throughput_req(rxthread_high_tput_req))
7448 hdd_warn("Rx thread high_tput(%d) affinity request failed",
7449 rxthread_high_tput_req);
7450
7451 /* fine-tuning parameters for RX Flows */
jitiphil869b9f72018-09-25 17:14:01 +05307452 if (avg_rx > hdd_ctx->config->tcp_delack_thres_high) {
Ravi Joshifed83572016-10-07 16:20:37 -07007453 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
7454 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
7455 next_rx_level = WLAN_SVC_TP_HIGH;
7456 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07007457 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07007458 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08007459 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007460 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007461
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007462 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007463 struct wlan_rx_tp_data rx_tp_data = {0};
7464
Ravi Joshie2331e82015-07-01 18:18:54 -07007465 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Jeff Johnsonb9feee42018-07-08 10:34:48 -07007466 next_rx_level, avg_rx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007467 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007468 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07007469 /* Send throughput indication only if it is enabled.
7470 * Disabling tcp_del_ack will revert the tcp stack behavior
7471 * to default delayed ack. Note that this will disable the
7472 * dynamic delayed ack mechanism across the system
7473 */
Manjunathappa Prakashbfd12762018-04-29 22:44:52 -07007474 if (hdd_ctx->en_tcp_delack_no_lro)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007475 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
7476
Mohit Khanna6272fb682017-04-13 09:34:36 -07007477 if (hdd_ctx->config->enable_tcp_adv_win_scale)
7478 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
7479
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007480 rx_tp_data.level = next_rx_level;
7481 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7482 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
7483 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007484 }
7485
Mohit Khannae71e2262015-11-10 09:37:24 -08007486 /* fine-tuning parameters for TX Flows */
7487 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
7488 hdd_ctx->prev_tx = tx_packets;
7489 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
7490 next_tx_level = WLAN_SVC_TP_HIGH;
7491 else
7492 next_tx_level = WLAN_SVC_TP_LOW;
7493
Prakash Manjunathappae73e3b52018-02-27 18:56:22 -08007494 if ((hdd_ctx->config->enable_tcp_limit_output) &&
7495 (hdd_ctx->cur_tx_level != next_tx_level)) {
Mohit Khannae71e2262015-11-10 09:37:24 -08007496 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
7497 next_tx_level, temp_tx);
7498 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007499 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05307500 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7501 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08007502 &next_tx_level,
7503 sizeof(next_tx_level));
7504 }
7505
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007506 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007507 if (vote_level_change || tx_level_change || rx_level_change) {
7508 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
7509 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
7510 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
7511 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
7512 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
7513 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
7514 hdd_ctx->hdd_txrx_hist_idx++;
7515 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
7516 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07007517
7518 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007519}
7520
7521#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Rajeev Kumarb2b5e692018-08-31 15:12:40 -07007522static void __hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007523{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007524 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307525 bus_bw_work);
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307526 struct hdd_adapter *adapter = NULL, *con_sap_adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307527 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05307528 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
7529 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007530 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307531 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007532 bool connected = false;
7533 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
7534
Prashanth Bhattaab004382016-10-11 16:08:11 -07007535 if (wlan_hdd_validate_context(hdd_ctx))
7536 return;
7537
Jeff Johnson214671b2017-10-30 19:45:23 -07007538 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08007539 goto restart_timer;
7540
Dustin Brown920397d2017-12-13 16:27:50 -08007541 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05307542 /*
7543 * Validate magic so we don't end up accessing
7544 * an invalid adapter.
7545 */
7546 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
7547 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007548
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007549 if ((adapter->device_mode == QDF_STA_MODE ||
7550 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007551 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
7552 != eConnectionState_Associated) {
7553
7554 continue;
7555 }
7556
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007557 if ((adapter->device_mode == QDF_SAP_MODE ||
7558 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07007559 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007560
7561 continue;
7562 }
7563
7564 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
7565 adapter->prev_tx_packets);
7566 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
7567 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307568
7569 if (adapter->device_mode == QDF_SAP_MODE ||
7570 adapter->device_mode == QDF_P2P_GO_MODE ||
7571 adapter->device_mode == QDF_IBSS_MODE) {
7572
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08007573 ret = cdp_get_intra_bss_fwd_pkts_count(
7574 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007575 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307576 &fwd_tx_packets, &fwd_rx_packets);
7577 if (ret == A_OK) {
7578 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
7579 fwd_tx_packets,
7580 adapter->prev_fwd_tx_packets);
7581 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
7582 fwd_tx_packets,
7583 adapter->prev_fwd_rx_packets);
7584 }
7585 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007586
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307587 if (adapter->device_mode == QDF_SAP_MODE)
7588 con_sap_adapter = adapter;
7589
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007590 total_rx += adapter->stats.rx_packets;
7591 total_tx += adapter->stats.tx_packets;
7592
7593 spin_lock_bh(&hdd_ctx->bus_bw_lock);
7594 adapter->prev_tx_packets = adapter->stats.tx_packets;
7595 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307596 adapter->prev_fwd_tx_packets = fwd_tx_packets;
7597 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007598 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
7599 connected = true;
7600 }
7601
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007602 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007603 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007604 return;
7605 }
7606
Yun Parka29974a2018-04-09 12:05:49 -07007607 /* add intra bss forwarded tx and rx packets */
7608 tx_packets += fwd_tx_packets_diff;
7609 rx_packets += fwd_rx_packets_diff;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007610
Dustin Brown07901ec2018-09-07 11:02:41 -07007611 if (ucfg_ipa_is_fw_wdi_activated(hdd_ctx->pdev)) {
7612 ucfg_ipa_uc_stat_query(hdd_ctx->pdev, &ipa_tx_packets,
7613 &ipa_rx_packets);
Yun Parka29974a2018-04-09 12:05:49 -07007614 tx_packets += (uint64_t)ipa_tx_packets;
7615 rx_packets += (uint64_t)ipa_rx_packets;
7616
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307617 if (con_sap_adapter) {
7618 con_sap_adapter->stats.tx_packets += ipa_tx_packets;
7619 con_sap_adapter->stats.rx_packets += ipa_rx_packets;
7620 }
7621
Dustin Brown07901ec2018-09-07 11:02:41 -07007622 ucfg_ipa_set_perf_level(hdd_ctx->pdev, tx_packets, rx_packets);
7623 ucfg_ipa_uc_stat_request(hdd_ctx->pdev, 2);
Yun Parka29974a2018-04-09 12:05:49 -07007624 }
7625
7626 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007627
Jingxiang Gec64e1932017-08-22 14:38:59 +08007628restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08007629 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08007630 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08007631 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05307632 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
jitiphil869b9f72018-09-25 17:14:01 +05307633 hdd_ctx->config->bus_bw_compute_interval);
Dustin Brownfce08d12017-01-17 16:29:38 -08007634 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007635}
Prashanth Bhattaab004382016-10-11 16:08:11 -07007636
Rajeev Kumarb2b5e692018-08-31 15:12:40 -07007637static void hdd_bus_bw_work_handler(struct work_struct *work)
7638{
7639 cds_ssr_protect(__func__);
7640 __hdd_bus_bw_work_handler(work);
7641 cds_ssr_unprotect(__func__);
7642}
7643
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307644/**
7645 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
7646 * @arg: Argument of timer function
7647 *
7648 * Schedule a workqueue in this function where all the processing is done.
7649 *
7650 * Return: None.
7651 */
7652static void __hdd_bus_bw_cbk(void *arg)
7653{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007654 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307655
7656 if (wlan_hdd_validate_context(hdd_ctx))
7657 return;
7658
7659 schedule_work(&hdd_ctx->bus_bw_work);
7660}
7661
7662/**
7663 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
7664 * @arg: Argument of timer function
7665 *
7666 * Return: None.
7667 */
7668static void hdd_bus_bw_cbk(void *arg)
7669{
7670 cds_ssr_protect(__func__);
7671 __hdd_bus_bw_cbk(arg);
7672 cds_ssr_unprotect(__func__);
7673}
7674
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007675int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007676{
Dustin Brown35008ba2018-08-23 14:34:21 -07007677 hdd_enter();
7678
Prashanth Bhattaab004382016-10-11 16:08:11 -07007679 spin_lock_init(&hdd_ctx->bus_bw_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07007680 INIT_WORK(&hdd_ctx->bus_bw_work, hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08007681 hdd_ctx->bus_bw_timer_running = false;
7682 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07007683 qdf_timer_init(NULL, &hdd_ctx->bus_bw_timer, hdd_bus_bw_cbk,
7684 (void *)hdd_ctx, QDF_TIMER_TYPE_SW);
7685
7686 hdd_exit();
Prashanth Bhattaab004382016-10-11 16:08:11 -07007687
7688 return 0;
7689}
7690
Dustin Brown86d196b2018-08-02 11:51:49 -07007691void hdd_bus_bandwidth_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007692{
Dustin Brown35008ba2018-08-23 14:34:21 -07007693 hdd_enter();
Prashanth Bhattaab004382016-10-11 16:08:11 -07007694
Rajeev Kumarc27efb62018-08-31 14:21:22 -07007695 QDF_BUG(!hdd_ctx->bus_bw_timer_running);
Dustin Brown35008ba2018-08-23 14:34:21 -07007696
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307697 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08007698 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07007699
7700 hdd_exit();
Prashanth Bhattaab004382016-10-11 16:08:11 -07007701}
Lin Baic5c06882017-09-21 13:58:43 +08007702
Dustin Brown35008ba2018-08-23 14:34:21 -07007703#endif /* MSM_PLATFORM */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007704
7705/**
Nirav Shahed34b212016-04-25 10:59:16 +05307706 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
7707 * @hdd_ctx: hdd context
7708 *
7709 * Return: 0 for success or error code
7710 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007711static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307712{
7713 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
7714 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
7715 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007716 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05307717 return -ENOMEM;
7718 }
7719 return 0;
7720}
7721
7722/**
7723 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
7724 * @hdd_ctx: hdd context
7725 *
7726 * Return: none
7727 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007728void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307729{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307730 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
7731 return;
7732
7733 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
7734 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05307735}
7736
Nirav Shahda008342016-05-17 18:50:40 +05307737static uint8_t *convert_level_to_string(uint32_t level)
7738{
7739 switch (level) {
7740 /* initialize the wlan sub system */
7741 case WLAN_SVC_TP_NONE:
7742 return "NONE";
7743 case WLAN_SVC_TP_LOW:
7744 return "LOW";
7745 case WLAN_SVC_TP_MEDIUM:
7746 return "MED";
7747 case WLAN_SVC_TP_HIGH:
7748 return "HIGH";
7749 default:
7750 return "INVAL";
7751 }
7752}
7753
Nirav Shahed34b212016-04-25 10:59:16 +05307754
7755/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007756 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
7757 * @hdd_ctx: hdd context
7758 *
7759 * Return: none
7760 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007761void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007762{
7763 int i;
7764
7765#ifdef MSM_PLATFORM
Nirav Shahe6194ac2018-07-13 11:04:41 +05307766 hdd_nofl_info("BW compute Interval: %dms",
jitiphil869b9f72018-09-25 17:14:01 +05307767 hdd_ctx->config->bus_bw_compute_interval);
Nirav Shahe6194ac2018-07-13 11:04:41 +05307768 hdd_nofl_info("BW High TH: %d BW Med TH: %d BW Low TH: %d",
jitiphil869b9f72018-09-25 17:14:01 +05307769 hdd_ctx->config->bus_bw_high_threshold,
7770 hdd_ctx->config->bus_bw_medium_threshold,
7771 hdd_ctx->config->bus_bw_low_threshold);
Nirav Shahe6194ac2018-07-13 11:04:41 +05307772 hdd_nofl_info("Enable TCP DEL ACK: %d",
7773 hdd_ctx->en_tcp_delack_no_lro);
7774 hdd_nofl_info("TCP DEL High TH: %d TCP DEL Low TH: %d",
jitiphil869b9f72018-09-25 17:14:01 +05307775 hdd_ctx->config->tcp_delack_thres_high,
7776 hdd_ctx->config->tcp_delack_thres_low);
Nirav Shahe6194ac2018-07-13 11:04:41 +05307777 hdd_nofl_info("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
7778 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007779#endif
7780
Nirav Shahe6194ac2018-07-13 11:04:41 +05307781 hdd_nofl_info("Total entries: %d Current index: %d",
7782 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
Nirav Shahda008342016-05-17 18:50:40 +05307783
Nirav Shahe6194ac2018-07-13 11:04:41 +05307784 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 -08007785
7786 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007787 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007788 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Nirav Shahe6194ac2018-07-13 11:04:41 +05307789 hdd_nofl_info("[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
7790 i, hdd_ctx->hdd_txrx_hist[i].qtime,
7791 hdd_ctx->hdd_txrx_hist[i].interval_rx,
7792 hdd_ctx->hdd_txrx_hist[i].interval_tx,
7793 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007794 hdd_ctx->hdd_txrx_hist[i].
7795 next_vote_level),
Nirav Shahe6194ac2018-07-13 11:04:41 +05307796 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007797 hdd_ctx->hdd_txrx_hist[i].
7798 next_rx_level),
Nirav Shahe6194ac2018-07-13 11:04:41 +05307799 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007800 hdd_ctx->hdd_txrx_hist[i].
7801 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007802 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007803}
7804
7805/**
7806 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
7807 * @hdd_ctx: hdd context
7808 *
7809 * Return: none
7810 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007811void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007812{
7813 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05307814 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
7815 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007816}
7817
Mohit Khannaca4173b2017-09-12 21:52:19 -07007818/* length of the netif queue log needed per adapter */
7819#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
7820
7821/**
7822 *
7823 * hdd_display_netif_queue_history_compact() - display compact netifq history
7824 * @hdd_ctx: hdd context
7825 *
7826 * Return: none
7827 */
7828static void
7829hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
7830{
7831 int adapter_num = 0;
7832 int i;
7833 int bytes_written;
7834 u32 tbytes;
7835 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007836 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08007837 char *comb_log_str;
7838 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007839 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007840
Dustin Brownbee82832018-07-23 10:10:51 -07007841 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * CSR_ROAM_SESSION_MAX) + 1;
jiadbdefb252018-01-03 14:27:06 +08007842 comb_log_str = qdf_mem_malloc(comb_log_str_size);
7843 if (!comb_log_str) {
7844 hdd_err("failed to alloc comb_log_str");
7845 return;
7846 }
7847
Mohit Khannaca4173b2017-09-12 21:52:19 -07007848 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007849
Dustin Brown920397d2017-12-13 16:27:50 -08007850 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007851 curr_time = qdf_system_ticks();
7852 total = curr_time - adapter->start_time;
7853 delta = curr_time - adapter->last_time;
7854
7855 if (adapter->pause_map) {
7856 pause = adapter->total_pause_time + delta;
7857 unpause = adapter->total_unpause_time;
7858 } else {
7859 unpause = adapter->total_unpause_time + delta;
7860 pause = adapter->total_pause_time;
7861 }
7862
7863 tbytes = 0;
7864 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7865 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7866 if (adapter->queue_oper_stats[i].pause_count == 0)
7867 continue;
7868 tbytes +=
7869 snprintf(
7870 &temp_str[tbytes],
7871 (tbytes >= sizeof(temp_str) ?
7872 0 : sizeof(temp_str) - tbytes),
7873 "%d(%d,%d) ",
7874 i,
7875 adapter->queue_oper_stats[i].
7876 pause_count,
7877 adapter->queue_oper_stats[i].
7878 unpause_count);
7879 }
7880 if (tbytes >= sizeof(temp_str))
7881 hdd_warn("log truncated");
7882
7883 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08007884 bytes_written >= comb_log_str_size ? 0 :
7885 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007886 "[%d %d] (%d) %u/%ums %s|",
7887 adapter->session_id, adapter->device_mode,
7888 adapter->pause_map,
7889 qdf_system_ticks_to_msecs(pause),
7890 qdf_system_ticks_to_msecs(total),
7891 temp_str);
7892
Mohit Khannaca4173b2017-09-12 21:52:19 -07007893 adapter_num++;
7894 }
7895
7896 /* using QDF_TRACE to avoid printing function name */
7897 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
7898 "STATS |%s", comb_log_str);
7899
jiadbdefb252018-01-03 14:27:06 +08007900 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007901 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08007902
7903 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007904}
7905
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007906/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007907 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07007908 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007909 *
7910 * Return: none
7911 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007912void
7913wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
7914 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007915{
7916
Jeff Johnson9d295242017-08-29 14:39:48 -07007917 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007918 int i;
Nirav Shahda008342016-05-17 18:50:40 +05307919 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007920
Mohit Khannaca4173b2017-09-12 21:52:19 -07007921 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
7922 hdd_display_netif_queue_history_compact(hdd_ctx);
7923 return;
7924 }
7925
Dustin Brown920397d2017-12-13 16:27:50 -08007926 hdd_for_each_adapter(hdd_ctx, adapter) {
Nirav Shahe6194ac2018-07-13 11:04:41 +05307927 hdd_nofl_info("Netif queue operation statistics:");
7928 hdd_nofl_info("Session_id %d device mode %d",
7929 adapter->session_id, adapter->device_mode);
7930 hdd_nofl_info("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05307931 curr_time = qdf_system_ticks();
7932 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05307933 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05307934 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05307935 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307936 unpause = adapter->total_unpause_time;
7937 } else {
Nirav Shahda008342016-05-17 18:50:40 +05307938 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307939 pause = adapter->total_pause_time;
7940 }
Nirav Shahe6194ac2018-07-13 11:04:41 +05307941 hdd_nofl_info("Total: %ums Pause: %ums Unpause: %ums",
7942 qdf_system_ticks_to_msecs(total),
7943 qdf_system_ticks_to_msecs(pause),
7944 qdf_system_ticks_to_msecs(unpause));
7945 hdd_nofl_info("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007946
Nirav Shahda008342016-05-17 18:50:40 +05307947 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7948 qdf_time_t pause_delta = 0;
7949
7950 if (adapter->pause_map & (1 << i))
7951 pause_delta = delta;
7952
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007953 /* using hdd_log to avoid printing function name */
Nirav Shahe6194ac2018-07-13 11:04:41 +05307954 hdd_nofl_info("%s: %d: %d: %ums",
7955 hdd_reason_type_to_string(i),
7956 adapter->queue_oper_stats[i].pause_count,
7957 adapter->queue_oper_stats[i].
7958 unpause_count,
7959 qdf_system_ticks_to_msecs(
7960 adapter->queue_oper_stats[i].
7961 total_pause_time + pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007962 }
7963
Nirav Shahe6194ac2018-07-13 11:04:41 +05307964 hdd_nofl_info("Netif queue operation history:");
7965 hdd_nofl_info("Total entries: %d current index %d",
7966 WLAN_HDD_MAX_HISTORY_ENTRY,
7967 adapter->history_index);
Nirav Shahda008342016-05-17 18:50:40 +05307968
Nirav Shahe6194ac2018-07-13 11:04:41 +05307969 hdd_nofl_info("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007970
7971 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007972 /* using hdd_log to avoid printing function name */
7973 if (adapter->queue_oper_history[i].time == 0)
7974 continue;
Nirav Shahe6194ac2018-07-13 11:04:41 +05307975 hdd_nofl_info("%d: %u: %s: %s: %x",
7976 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007977 adapter->queue_oper_history[i].time),
Nirav Shahe6194ac2018-07-13 11:04:41 +05307978 hdd_action_type_to_string(
7979 adapter->queue_oper_history[i].
7980 netif_action),
7981 hdd_reason_type_to_string(
7982 adapter->queue_oper_history[i].
7983 netif_reason),
7984 adapter->queue_oper_history[i].pause_map);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007985 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007986 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007987}
7988
7989/**
7990 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
7991 * @hdd_ctx: hdd context
7992 *
7993 * Return: none
7994 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007995void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007996{
Jeff Johnson9d295242017-08-29 14:39:48 -07007997 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007998
Dustin Brown920397d2017-12-13 16:27:50 -08007999 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308000 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008001 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308002 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008003 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05308004 adapter->history_index = 0;
8005 adapter->start_time = adapter->last_time = qdf_system_ticks();
8006 adapter->total_pause_time = 0;
8007 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008008 }
8009}
8010
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008011#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
8012/**
8013 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
8014 * @hdd_ctx: hdd global context
8015 *
8016 * Return: none
8017 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008018static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008019{
8020 uint8_t i;
8021
8022 mutex_init(&hdd_ctx->op_ctx.op_lock);
8023 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
8024 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
8025 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
8026 }
8027}
8028#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008029static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008030{
8031}
8032#endif
8033
Yingying Tang95409972016-10-20 15:16:15 +08008034#ifdef WLAN_FEATURE_WOW_PULSE
8035/**
8036 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008037 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08008038 * @enable: enable or disable this behaviour
8039 *
8040 * Return: int
8041 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008042static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008043{
Yingying Tang95409972016-10-20 15:16:15 +08008044 struct wow_pulse_mode wow_pulse_set_info;
8045 QDF_STATUS status;
8046
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008047 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08008048
Wu Gao66454f12018-09-26 19:55:41 +08008049 if (!ucfg_pmo_is_wow_pulse_enabled(phddctx->psoc))
Yingying Tang95409972016-10-20 15:16:15 +08008050 return 0;
8051
8052 /* prepare the request to send to SME */
8053 if (enable == true) {
8054 wow_pulse_set_info.wow_pulse_enable = true;
8055 wow_pulse_set_info.wow_pulse_pin =
Wu Gao66454f12018-09-26 19:55:41 +08008056 ucfg_pmo_get_wow_pulse_pin(phddctx->psoc);
8057
Yingying Tang95409972016-10-20 15:16:15 +08008058 wow_pulse_set_info.wow_pulse_interval_high =
Wu Gao66454f12018-09-26 19:55:41 +08008059 ucfg_pmo_get_wow_pulse_interval_high(phddctx->psoc);
8060
8061 wow_pulse_set_info.wow_pulse_interval_low =
8062 ucfg_pmo_get_wow_pulse_interval_low(phddctx->psoc);
Yingying Tang95409972016-10-20 15:16:15 +08008063 } else {
8064 wow_pulse_set_info.wow_pulse_enable = false;
8065 wow_pulse_set_info.wow_pulse_pin = 0;
8066 wow_pulse_set_info.wow_pulse_interval_low = 0;
8067 wow_pulse_set_info.wow_pulse_interval_high = 0;
8068 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008069 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08008070 wow_pulse_set_info.wow_pulse_enable,
8071 wow_pulse_set_info.wow_pulse_pin,
8072 wow_pulse_set_info.wow_pulse_interval_low,
8073 wow_pulse_set_info.wow_pulse_interval_high);
8074
8075 status = sme_set_wow_pulse(&wow_pulse_set_info);
8076 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008077 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08008078 return -EIO;
8079 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008080 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08008081 return 0;
8082}
8083#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008084static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008085{
8086 return 0;
8087}
8088#endif
8089
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008090#ifdef WLAN_FEATURE_FASTPATH
8091/**
8092 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
8093 * @hdd_cfg: hdd config
8094 * @context: lower layer context
8095 *
8096 * Return: none
8097 */
Arun Khandavallifae92942016-08-01 13:31:08 +05308098void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008099 void *context)
8100{
8101 if (hdd_cfg->fastpath_enable)
8102 hif_enable_fastpath(context);
8103}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008104#endif
8105
Yuanyuan Liu13738502016-04-06 17:41:37 -07008106#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008107/**
8108 * hdd_set_thermal_level_cb() - set thermal level callback function
Jeff Johnson0e963082018-07-04 19:39:20 -07008109 * @hdd_handle: opaque handle for the hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008110 * @level: thermal level
8111 *
8112 * Change IPA data path to SW path when the thermal throttle level greater
8113 * than 0, and restore the original data path when throttle level is 0
8114 *
8115 * Return: none
8116 */
Jeff Johnson0e963082018-07-04 19:39:20 -07008117static void hdd_set_thermal_level_cb(hdd_handle_t hdd_handle, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008118{
Jeff Johnson0e963082018-07-04 19:39:20 -07008119 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008120
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008121 /* Change IPA to SW path when throttle level greater than 0 */
8122 if (level > THROTTLE_LEVEL_0)
Dustin Brown07901ec2018-09-07 11:02:41 -07008123 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->pdev, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008124 else
8125 /* restore original concurrency mode */
Dustin Brown07901ec2018-09-07 11:02:41 -07008126 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->pdev, hdd_ctx->mcc_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008127}
8128
8129/**
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308130 * hdd_get_safe_channel() - Get safe channel from current regulatory
8131 * @hdd_ctx: pointer to hdd context
8132 * @adapter: pointer to softap adapter
8133 *
8134 * This function is used to get safe channel from current regulatory valid
8135 * channels to restart SAP if failed to get safe channel from PCL.
8136 *
8137 * Return: Channel number to restart SAP in case of success. In case of any
8138 * failure, the channel number returned is zero.
8139 */
8140static uint8_t
8141hdd_get_safe_channel(struct hdd_context *hdd_ctx,
8142 struct hdd_adapter *adapter)
8143{
8144 struct sir_pcl_list pcl = {0};
8145 uint32_t i, j;
8146 bool found = false;
8147 int ret;
8148
8149 /* Try for safe channel from all valid channel */
8150 pcl.pcl_len = MAX_NUM_CHAN;
8151 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
8152 &pcl.pcl_len);
8153 if (ret) {
8154 hdd_err("error %d in getting valid channel list", ret);
8155 return INVALID_CHANNEL_ID;
8156 }
8157
8158 for (i = 0; i < pcl.pcl_len; i++) {
8159 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
8160 found = false;
8161 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
8162 if (pcl.pcl_list[i] ==
8163 hdd_ctx->unsafe_channel_list[j]) {
8164 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
8165 found = true;
8166 break;
8167 }
8168 }
8169
8170 if (found)
8171 continue;
8172
8173 if ((pcl.pcl_list[i] >=
8174 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
8175 (pcl.pcl_list[i] <=
8176 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
8177 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
8178 return pcl.pcl_list[i];
8179 }
8180 }
8181
8182 return INVALID_CHANNEL_ID;
8183}
8184
8185#else
8186/**
8187 * hdd_set_thermal_level_cb() - set thermal level callback function
8188 * @hdd_handle: opaque handle for the hdd context
8189 * @level: thermal level
8190 *
8191 * Change IPA data path to SW path when the thermal throttle level greater
8192 * than 0, and restore the original data path when throttle level is 0
8193 *
8194 * Return: none
8195 */
8196static void hdd_set_thermal_level_cb(hdd_handle_t hdd_handle, u_int8_t level)
8197{
8198}
8199
8200/**
8201 * hdd_get_safe_channel() - Get safe channel from current regulatory
8202 * @hdd_ctx: pointer to hdd context
8203 * @adapter: pointer to softap adapter
8204 *
8205 * This function is used to get safe channel from current regulatory valid
8206 * channels to restart SAP if failed to get safe channel from PCL.
8207 *
8208 * Return: Channel number to restart SAP in case of success. In case of any
8209 * failure, the channel number returned is zero.
8210 */
8211static uint8_t
8212hdd_get_safe_channel(struct hdd_context *hdd_ctx,
8213 struct hdd_adapter *adapter)
8214{
8215 return 0;
8216}
8217#endif
8218
8219/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308220 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
8221 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05308222 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008223 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308224 * Get a safe channel to restart SAP. PCL already takes into account the
8225 * unsafe channels. So, the PCL is validated with the ACS range to provide
8226 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008227 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308228 * Return: Channel number to restart SAP in case of success. In case of any
8229 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008230 */
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308231static uint8_t
8232hdd_get_safe_channel_from_pcl_and_acs_range(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008233{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308234 struct sir_pcl_list pcl;
8235 QDF_STATUS status;
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308236 uint32_t i;
Jeff Johnson16528362018-06-14 12:34:16 -07008237 mac_handle_t mac_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008238 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008239
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308240 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8241 if (!hdd_ctx) {
8242 hdd_err("invalid HDD context");
8243 return INVALID_CHANNEL_ID;
8244 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008245
Jeff Johnson16528362018-06-14 12:34:16 -07008246 mac_handle = hdd_ctx->mac_handle;
8247 if (!mac_handle) {
8248 hdd_err("invalid MAC handle");
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05308249 return INVALID_CHANNEL_ID;
8250 }
8251
Dustin Brown1dbefe62018-09-11 16:32:03 -07008252 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008253 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08008254 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
8255 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308256 if (QDF_IS_STATUS_ERROR(status)) {
8257 hdd_err("Get PCL failed");
8258 return INVALID_CHANNEL_ID;
8259 }
8260
Frank Liudc2cefb2017-06-21 15:38:18 +08008261 /*
8262 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
8263 * channel is unsafe channel, the pcl may be empty, instead of return,
8264 * try to choose a safe channel from acs range.
8265 */
8266 if (!pcl.pcl_len)
8267 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308268
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008269 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07008270 adapter->session.ap.sap_config.acs_cfg.start_ch,
8271 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308272
8273 /* PCL already takes unsafe channel into account */
8274 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008275 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308276 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008277 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308278 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008279 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008280 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308281 return pcl.pcl_list[i];
8282 }
8283 }
8284
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008285 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308286
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308287 return hdd_get_safe_channel(hdd_ctx, adapter);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308288}
8289
8290/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008291 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308292 * @adapter: AP adapter
8293 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08008294 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308295 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008296 * Moves the SAP interface by invoking the function which
8297 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308298 *
8299 * Return: None
8300 */
Min Liu2fef5792018-01-19 17:59:42 +08008301void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
8302 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308303{
Jeff Johnson87251032017-08-29 13:31:11 -07008304 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008305 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07008306 mac_handle_t mac_handle;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308307
8308 if (!adapter) {
8309 hdd_err("invalid adapter");
8310 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008311 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308312
8313 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
8314
Jeff Johnson16528362018-06-14 12:34:16 -07008315 mac_handle = hdd_adapter_get_mac_handle(adapter);
8316 if (!mac_handle) {
8317 hdd_err("invalid MAC handle");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308318 return;
8319 }
8320
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008321 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8322
Jeff Johnson91df29d2017-10-27 19:29:50 -07008323 hdd_ap_ctx->sap_config.channel = channel;
Himanshu Agarwalf5c5b102018-05-22 20:13:57 +05308324 hdd_ap_ctx->sap_config.ch_params.ch_width = CH_WIDTH_MAX;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308325
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008326 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07008327 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308328
Dustin Brown07901ec2018-09-07 11:02:41 -07008329 wlan_reg_set_channel_params(hdd_ctx->pdev,
8330 hdd_ap_ctx->sap_config.channel,
8331 hdd_ap_ctx->sap_config.sec_ch,
8332 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308333
Dustin Brown1dbefe62018-09-11 16:32:03 -07008334 policy_mgr_change_sap_channel_with_csa(hdd_ctx->psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07008335 adapter->session_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08008336 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008337}
Kapil Gupta8878ad92017-02-13 11:56:04 +05308338
Jeff Johnson9d295242017-08-29 14:39:48 -07008339int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05308340{
8341 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308342 int status;
8343 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308344
8345 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8346
8347 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07008348 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05308349 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07008350 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308351 }
8352 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07008353 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308354 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308355 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07008356 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308357 WLAN_VENDOR_ACS_WAIT_TIME);
8358 if (qdf_status != QDF_STATUS_SUCCESS) {
8359 hdd_err("failed to start external acs timer");
8360 return -ENOSPC;
8361 }
8362 /* Update config to application */
8363 status = hdd_cfg80211_update_acs_config(adapter, reason);
Dustin Brown5e89ef82018-03-14 11:50:23 -07008364 hdd_info("Updated ACS config to nl with reason %d", reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308365
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308366 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308367}
8368
Nirav Shaheb017be2018-02-15 11:20:58 +05308369#if defined(FEATURE_WLAN_CH_AVOID)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308370/**
8371 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
8372 * @hdd_ctx: hdd context pointer
8373 *
8374 * hdd_unsafe_channel_restart_sap check all unsafe channel list
8375 * and if ACS is enabled, driver will ask userspace to restart the
8376 * sap. User space on LTE coex indication restart driver.
8377 *
8378 * Return - none
8379 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008380void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308381{
Dustin Brown920397d2017-12-13 16:27:50 -08008382 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308383 uint32_t i;
8384 bool found = false;
8385 uint8_t restart_chan;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05308386 bool value;
Harprit Chhabada1eeeb8d2018-09-14 15:16:56 -07008387 QDF_STATUS status;
8388 bool is_acs_support_for_dfs_ltecoex = cfg_default(CFG_USER_ACS_DFS_LTE);
8389 bool is_vendor_acs_support =
8390 cfg_default(CFG_USER_AUTO_CHANNEL_SELECTION);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008391
Dustin Brown920397d2017-12-13 16:27:50 -08008392 hdd_for_each_adapter(hdd_ctxt, adapter) {
8393 if (!(adapter->device_mode == QDF_SAP_MODE &&
8394 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008395 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08008396 adapter->device_mode,
8397 adapter->session.ap.sap_config.
8398 acs_cfg.acs_mode);
8399 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308400 }
8401
8402 found = false;
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008403 /*
8404 * If STA+SAP is doing SCC & g_sta_sap_scc_on_lte_coex_chan
8405 * is set, no need to move SAP.
8406 */
Dustin Brown1dbefe62018-09-11 16:32:03 -07008407 if (policy_mgr_is_sta_sap_scc(hdd_ctxt->psoc,
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008408 adapter->session.ap.operating_channel) &&
8409 hdd_ctxt->config->sta_sap_scc_on_lte_coex_chan)
8410 hdd_debug("SAP is allowed on SCC channel, no need to move SAP");
8411 else {
8412 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
8413 if (adapter->session.ap.operating_channel ==
8414 hdd_ctxt->unsafe_channel_list[i]) {
8415 found = true;
8416 hdd_debug("operating ch:%d is unsafe",
8417 adapter->session.ap.operating_channel);
8418 break;
8419 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308420 }
8421 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308422 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008423 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08008424 adapter->session.ap.operating_channel);
8425 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308426 }
8427
Harprit Chhabada1eeeb8d2018-09-14 15:16:56 -07008428 status = ucfg_mlme_get_acs_support_for_dfs_ltecoex(
8429 hdd_ctxt->psoc,
8430 &is_acs_support_for_dfs_ltecoex);
8431 if (!QDF_IS_STATUS_SUCCESS(status))
8432 hdd_err("get_acs_support_for_dfs_ltecoex failed,set def");
8433
8434 status = ucfg_mlme_get_vendor_acs_support(
8435 hdd_ctxt->psoc,
8436 &is_vendor_acs_support);
8437 if (!QDF_IS_STATUS_SUCCESS(status))
8438 hdd_err("get_vendor_acs_support failed, set default");
8439
8440 if (is_vendor_acs_support && is_acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08008441 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05308442 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08008443 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308444 } else
8445 restart_chan =
8446 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08008447 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308448 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008449 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308450 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008451 /*
8452 * SAP restart due to unsafe channel. While
8453 * restarting the SAP, make sure to clear
8454 * acs_channel, channel to reset to
8455 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308456 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008457 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308458 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008459 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308460 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
8461 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Dustin Brown05d81302018-09-11 16:49:22 -07008462 ucfg_mlme_get_sap_internal_restart(hdd_ctxt->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05308463 &value);
8464 hdd_debug("driver to start sap: %d", value);
8465 if (value)
Min Liu2fef5792018-01-19 17:59:42 +08008466 hdd_switch_sap_channel(adapter, restart_chan,
8467 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04008468 else
8469 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308470 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308471 }
8472}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05308473
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008474/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008475 * hdd_init_channel_avoidance() - Initialize channel avoidance
8476 * @hdd_ctx: HDD global context
8477 *
8478 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07008479 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008480 * down to the lower layers. Then subscribe to subsequent channel
8481 * avoidance events.
8482 *
8483 * Return: None
8484 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008485static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008486{
8487 uint16_t unsafe_channel_count;
8488 int index;
8489
Yuanyuan Liu13738502016-04-06 17:41:37 -07008490 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
8491 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008492 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08008493 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008494
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008495 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008496 hdd_ctx->unsafe_channel_count);
8497
Anurag Chouhan6d760662016-02-20 16:05:43 +05308498 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08008499 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008500
8501 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008502 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008503 hdd_ctx->unsafe_channel_list[index]);
8504
8505 }
8506
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008507}
Dustin Brown676a2322017-08-15 13:16:13 -07008508
Jeff Johnson9d295242017-08-29 14:39:48 -07008509static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008510 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008511{
8512 uint8_t restart_chan;
8513
8514 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
8515 if (!restart_chan) {
8516 hdd_alert("fail to restart SAP");
8517 return;
8518 }
8519
8520 /* SAP restart due to unsafe channel. While restarting
8521 * the SAP, make sure to clear acs_channel, channel to
8522 * reset to 0. Otherwise these settings will override
8523 * the ACS while restart.
8524 */
8525 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07008526
8527 hdd_debug("sending coex indication");
8528
8529 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
8530 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08008531 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07008532}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008533
8534int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
8535 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
8536{
8537 uint32_t size;
8538 uint16_t *unsafe_list;
8539 uint16_t chan_count;
8540
8541 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
8542 return -EINVAL;
8543
8544 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
8545 NUM_CHANNELS);
8546 if (chan_count) {
8547 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
8548 unsafe_list = qdf_mem_malloc(size);
8549 if (!unsafe_list) {
8550 hdd_err("No memory for unsafe chan list size%d",
8551 size);
8552 return -ENOMEM;
8553 }
8554 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
8555 } else {
8556 unsafe_list = NULL;
8557 }
8558
8559 *local_unsafe_list = unsafe_list;
8560 *local_unsafe_list_count = chan_count;
8561
8562 return 0;
8563}
8564
8565bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
8566 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
8567{
8568 int i, j;
8569
8570 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
8571 return true;
8572 if (local_unsafe_list_count == 0)
8573 return false;
8574 for (i = 0; i < local_unsafe_list_count; i++) {
8575 for (j = 0; j < local_unsafe_list_count; j++)
8576 if (local_unsafe_list[i] ==
8577 hdd_ctx->unsafe_channel_list[j])
8578 break;
8579 if (j >= local_unsafe_list_count)
8580 break;
8581 }
8582 if (i >= local_unsafe_list_count) {
8583 hdd_info("unsafe chan list same");
8584 return false;
8585 }
8586
8587 return true;
8588}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008589#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008590static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008591{
8592}
Dustin Brown676a2322017-08-15 13:16:13 -07008593
Jeff Johnson9d295242017-08-29 14:39:48 -07008594static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008595 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008596{
8597 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
8598}
Yuanyuan Liu13738502016-04-06 17:41:37 -07008599#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008600
8601/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08008602 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
8603 * user space
8604 * @frame_ind: Management frame data to be informed.
8605 *
8606 * This function is used to indicate management frame to
8607 * user space
8608 *
8609 * Return: None
8610 *
8611 */
8612void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
8613{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008614 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07008615 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008616 int i;
Pragaspathi Thilagaraj28ffc042018-07-18 15:19:36 +05308617 struct ieee80211_mgmt *mgmt =
8618 (struct ieee80211_mgmt *)frame_ind->frameBuf;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008619
Dustin Browne7e71d32018-05-11 16:00:08 -07008620 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
8621 if (wlan_hdd_validate_context(hdd_ctx))
Rajeev Kumard004abc2016-02-17 12:09:56 -08008622 return;
8623
Pragaspathi Thilagaraj28ffc042018-07-18 15:19:36 +05308624 if (frame_ind->frame_len < ieee80211_hdrlen(mgmt->frame_control)) {
8625 hdd_err(" Invalid frame length");
8626 return;
8627 }
8628
Rajeev Kumard004abc2016-02-17 12:09:56 -08008629 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
8630 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
8631 adapter =
8632 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
8633 if (adapter)
8634 break;
8635 }
Wu Gaoa0230a62018-01-04 20:56:57 +08008636 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
8637 hdd_for_each_adapter(hdd_ctx, adapter) {
8638 if ((NULL != adapter) &&
8639 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
8640 __hdd_indicate_mgmt_frame(adapter,
8641 frame_ind->frame_len,
8642 frame_ind->frameBuf,
8643 frame_ind->frameType,
8644 frame_ind->rxChan,
8645 frame_ind->rxRssi);
8646 }
8647 }
8648 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008649 } else {
8650 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
8651 frame_ind->sessionId);
8652 }
8653
8654 if ((NULL != adapter) &&
8655 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
8656 __hdd_indicate_mgmt_frame(adapter,
8657 frame_ind->frame_len,
8658 frame_ind->frameBuf,
8659 frame_ind->frameType,
8660 frame_ind->rxChan,
8661 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008662}
8663
Kapil Gupta8878ad92017-02-13 11:56:04 +05308664void hdd_acs_response_timeout_handler(void *context)
8665{
8666 struct hdd_external_acs_timer_context *timer_context =
8667 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07008668 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008669 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308670 uint8_t reason;
8671
Dustin Brown491d54b2018-03-14 12:39:11 -07008672 hdd_enter();
Kapil Gupta8878ad92017-02-13 11:56:04 +05308673 if (!timer_context) {
8674 hdd_err("invlaid timer context");
8675 return;
8676 }
8677 adapter = timer_context->adapter;
8678 reason = timer_context->reason;
8679
8680
8681 if ((!adapter) ||
8682 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
8683 hdd_err("invalid adapter or adapter has invalid magic");
8684 return;
8685 }
8686 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8687 if (wlan_hdd_validate_context(hdd_ctx))
8688 return;
8689
8690 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
8691 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8692 else
8693 return;
8694
8695 hdd_err("ACS timeout happened for %s reason %d",
8696 adapter->dev->name, reason);
Jeff Johnson16528362018-06-14 12:34:16 -07008697
Kapil Gupta8878ad92017-02-13 11:56:04 +05308698 switch (reason) {
8699 /* SAP init case */
8700 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
8701 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
8702 false);
8703 wlan_hdd_cfg80211_start_acs(adapter);
8704 break;
8705 /* DFS detected on current channel */
8706 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
8707 wlan_sap_update_next_channel(
8708 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
Jeff Johnson16528362018-06-14 12:34:16 -07008709 sme_update_new_channel_event(hdd_ctx->mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07008710 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308711 break;
8712 /* LTE coex event on current channel */
8713 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
8714 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
8715 break;
8716 default:
8717 hdd_info("invalid reason for timer invoke");
8718
8719 }
8720}
8721
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008722/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008723 * hdd_override_ini_config - Override INI config
8724 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008725 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008726 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008727 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008728 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008729 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008730static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008731{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008732
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008733 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
8734 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008735 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008736 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008737 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008738 if (0 == enable_11d || 1 == enable_11d) {
8739 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008740 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008741 }
Leo Chang11545d62016-10-17 14:53:50 -07008742
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +05308743 if (hdd_ctx->config->action_oui_enable && !ucfg_action_oui_enabled()) {
8744 hdd_ctx->config->action_oui_enable = 0;
8745 hdd_err("Ignore ini: %s, since no action_oui component",
8746 CFG_ENABLE_ACTION_OUI);
8747 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008748}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008749
Ashish Kumar Dhanotiya12f68212018-09-04 22:00:14 +05308750#ifdef ENABLE_MTRACE_LOG
8751static void hdd_set_mtrace_for_each(struct hdd_context *hdd_ctx)
8752{
8753 uint8_t module_id = 0;
8754 int qdf_print_idx = -1;
8755
8756 qdf_print_idx = qdf_get_pidx();
8757 for (module_id = 0; module_id < QDF_MODULE_ID_MAX; module_id++)
8758 qdf_print_set_category_verbose(
8759 qdf_print_idx,
8760 module_id, QDF_TRACE_LEVEL_TRACE,
8761 hdd_ctx->config->enable_mtrace);
8762}
8763#else
8764static void hdd_set_mtrace_for_each(struct hdd_context *hdd_ctx)
8765{
8766}
8767
8768#endif
8769
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008770/**
8771 * hdd_set_trace_level_for_each - Set trace level for each INI config
8772 * @hdd_ctx - HDD context
8773 *
8774 * Set trace level for each module based on INI config.
8775 *
8776 * Return: None
8777 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008778static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008779{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308780 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
8781 hdd_ctx->config->qdf_trace_enable_wdi);
8782 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
8783 hdd_ctx->config->qdf_trace_enable_hdd);
8784 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
8785 hdd_ctx->config->qdf_trace_enable_sme);
8786 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
8787 hdd_ctx->config->qdf_trace_enable_pe);
8788 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
8789 hdd_ctx->config->qdf_trace_enable_wma);
8790 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
8791 hdd_ctx->config->qdf_trace_enable_sys);
8792 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
8793 hdd_ctx->config->qdf_trace_enable_qdf);
8794 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
8795 hdd_ctx->config->qdf_trace_enable_sap);
8796 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
8797 hdd_ctx->config->qdf_trace_enable_hdd_sap);
8798 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
8799 hdd_ctx->config->qdf_trace_enable_bmi);
8800 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
8801 hdd_ctx->config->qdf_trace_enable_cfg);
8802 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
8803 hdd_ctx->config->qdf_trace_enable_epping);
8804 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
8805 hdd_ctx->config->qdf_trace_enable_qdf_devices);
8806 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07008807 hdd_ctx->config->qdf_trace_enable_txrx);
8808 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
8809 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308810 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
8811 hdd_ctx->config->qdf_trace_enable_htc);
8812 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
8813 hdd_ctx->config->qdf_trace_enable_hif);
8814 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
8815 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
8816 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
8817 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08008818 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
8819 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07008820 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
8821 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008822 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
8823 hdd_ctx->config->qdf_trace_enable_regulatory);
Naveen Rawat3cb779e2018-02-16 16:36:10 -08008824 hdd_qdf_trace_enable(QDF_MODULE_ID_CP_STATS,
8825 hdd_ctx->config->qdf_trace_enable_cp_stats);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05308826 hdd_qdf_trace_enable(QDF_MODULE_ID_MLME, 0xffff);
Sourav Mohapatra113685f2018-08-29 14:21:55 +05308827 hdd_qdf_trace_enable(QDF_MODULE_ID_FWOL, 0xffff);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008828
Ashish Kumar Dhanotiya12f68212018-09-04 22:00:14 +05308829 hdd_set_mtrace_for_each(hdd_ctx);
8830
Nirav Shah5c083da2018-08-03 13:46:02 +05308831 hdd_cfg_print_global_config(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008832}
8833
8834/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008835 * hdd_context_init() - Initialize HDD context
8836 * @hdd_ctx: HDD context.
8837 *
8838 * Initialize HDD context along with all the feature specific contexts.
8839 *
8840 * return: 0 on success and errno on failure.
8841 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008842static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008843{
8844 int ret;
8845
8846 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
8847 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
8848
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008849 init_completion(&hdd_ctx->mc_sus_event_var);
8850 init_completion(&hdd_ctx->ready_to_suspend);
8851
8852 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308853 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008854 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308855
Dustin Brownbee82832018-07-23 10:10:51 -07008856 qdf_list_create(&hdd_ctx->hdd_adapters, 0);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008857
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008858 ret = hdd_scan_context_init(hdd_ctx);
8859 if (ret)
8860 goto list_destroy;
8861
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008862 hdd_rx_wake_lock_create(hdd_ctx);
8863
8864 ret = hdd_sap_context_init(hdd_ctx);
8865 if (ret)
8866 goto scan_destroy;
8867
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008868 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8869
8870 hdd_init_offloaded_packets_ctx(hdd_ctx);
8871
8872 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8873 hdd_ctx->config);
8874 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08008875 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008876
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05308877 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
8878 "monitor_mode_wakelock");
8879
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008880 return 0;
8881
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008882sap_destroy:
8883 hdd_sap_context_destroy(hdd_ctx);
8884
8885scan_destroy:
8886 hdd_scan_context_destroy(hdd_ctx);
8887 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008888list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008889 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08008890
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008891 return ret;
8892}
8893
8894/**
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308895 * hdd_iface_change_callback() - Function invoked when stop modules expires
8896 * @priv: pointer to hdd context
8897 *
8898 * This function is invoked when the timer waiting for the interface change
8899 * expires, it shall cut-down the power to wlan and stop all the modules.
8900 *
8901 * Return: void
8902 */
8903static void hdd_iface_change_callback(void *priv)
8904{
8905 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
8906 int ret;
8907 int status = wlan_hdd_validate_context(hdd_ctx);
8908
8909 if (status)
8910 return;
8911
Dustin Brown491d54b2018-03-14 12:39:11 -07008912 hdd_enter();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308913 hdd_debug("Interface change timer expired close the modules!");
8914 ret = hdd_wlan_stop_modules(hdd_ctx, false);
8915 if (ret)
8916 hdd_err("Failed to stop modules");
Dustin Browne74003f2018-03-14 12:51:58 -07008917 hdd_exit();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308918}
8919
Nirav Shaheb017be2018-02-15 11:20:58 +05308920#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
8921static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8922{
8923 wlan_logging_set_log_to_console(hdd_ctx->config->
8924 wlan_logging_to_console);
8925 wlan_logging_set_active(hdd_ctx->config->wlan_logging_enable);
8926}
8927#else
8928static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8929{ }
8930#endif
8931
Dundi Raviteja8e338282018-09-25 17:16:04 +05308932#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
8933static void hdd_init_wlan_logging_params(struct hdd_config *config,
8934 struct wlan_objmgr_psoc *psoc)
8935{
8936 config->wlan_logging_enable = cfg_get(psoc, CFG_WLAN_LOGGING_SUPPORT);
8937
8938 config->wlan_logging_to_console =
8939 cfg_get(psoc, CFG_WLAN_LOGGING_CONSOLE_SUPPORT);
8940}
8941#else
8942static void hdd_init_wlan_logging_params(struct hdd_config *config,
8943 struct wlan_objmgr_psoc *psoc)
8944{
8945}
8946#endif
8947
8948#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
8949static void hdd_init_wlan_auto_shutdown(struct hdd_config *config,
8950 struct wlan_objmgr_psoc *psoc)
8951{
8952 config->wlan_auto_shutdown = cfg_get(psoc, CFG_WLAN_AUTO_SHUTDOWN);
8953}
8954#else
8955static void hdd_init_wlan_auto_shutdown(struct hdd_config *config,
8956 struct wlan_objmgr_psoc *psoc)
8957{
8958}
8959#endif
8960
8961#ifndef REMOVE_PKT_LOG
8962static void hdd_init_packet_log(struct hdd_config *config,
8963 struct wlan_objmgr_psoc *psoc)
8964{
8965 config->enable_packet_log = cfg_get(psoc, CFG_ENABLE_PACKET_LOG);
8966}
8967#else
8968static void hdd_init_packet_log(struct hdd_config *config,
8969 struct wlan_objmgr_psoc *psoc)
8970{
8971}
8972#endif
8973
8974/**
8975 * hdd_cfg_params_init() - Initialize hdd params in hdd_config strucuture
8976 * @hdd_ctx - Pointer to HDD context
8977 *
8978 * Return: None
8979 */
8980static void hdd_cfg_params_init(struct hdd_context *hdd_ctx)
8981{
8982 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
8983 struct hdd_config *config = hdd_ctx->config;
8984
8985 if (!psoc) {
8986 hdd_err("Invalid psoc");
8987 return;
8988 }
8989
8990 if (!config) {
8991 hdd_err("Invalid hdd config");
8992 return;
8993 }
8994
8995 config->bug_on_reinit_failure = cfg_get(psoc,
8996 CFG_BUG_ON_REINIT_FAILURE);
8997
8998 config->is_ramdump_enabled = cfg_get(psoc,
8999 CFG_ENABLE_RAMDUMP_COLLECTION);
9000
9001 config->iface_change_wait_time = cfg_get(psoc,
9002 CFG_INTERFACE_CHANGE_WAIT);
9003
9004 config->multicast_host_fw_msgs = cfg_get(psoc,
9005 CFG_MULTICAST_HOST_FW_MSGS);
9006
9007 config->private_wext_control = cfg_get(psoc, CFG_PRIVATE_WEXT_CONTROL);
9008 config->timer_multiplier = cfg_get(psoc, CFG_TIMER_MULTIPLIER);
9009 config->enablefwprint = cfg_get(psoc, CFG_ENABLE_FW_UART_PRINT);
9010 config->enable_fw_log = cfg_get(psoc, CFG_ENABLE_FW_LOG);
9011
9012 hdd_init_wlan_auto_shutdown(config, psoc);
9013 hdd_init_wlan_logging_params(config, psoc);
9014 hdd_init_packet_log(config, psoc);
jitiphil869b9f72018-09-25 17:14:01 +05309015 hdd_dp_cfg_update(psoc, hdd_ctx);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309016}
9017
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05309018/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009019 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05309020 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009021 *
9022 * Allocate and initialize HDD context. HDD context is allocated as part of
9023 * wiphy allocation and then context is initialized.
9024 *
9025 * Return: HDD context on success and ERR_PTR on failure
9026 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009027static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009028{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309029 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009030 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009031 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009032
Dustin Brown491d54b2018-03-14 12:39:11 -07009033 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009034
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009035 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009036 if (hdd_ctx == NULL) {
9037 ret = -ENOMEM;
9038 goto err_out;
9039 }
9040
Dustin Brown6f427922017-09-19 12:19:00 -07009041 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
9042 hdd_iface_change_callback,
9043 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309044
9045 mutex_init(&hdd_ctx->iface_change_lock);
9046
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009047 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05309048 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009049
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309050 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009051 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009052 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009053 ret = -ENOMEM;
9054 goto err_free_hdd_context;
9055 }
9056
9057 /* Read and parse the qcom_cfg.ini file */
9058 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309059 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309060 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009061 WLAN_INI_FILE);
9062 ret = -EINVAL;
9063 goto err_free_config;
9064 }
9065
Dustin Brown84f46ea2018-02-15 11:57:36 -08009066 status = cfg_parse(WLAN_INI_FILE);
9067 if (QDF_IS_STATUS_ERROR(status))
9068 hdd_err("Failed to parse cfg %s; status:%d\n",
9069 WLAN_INI_FILE, status);
9070
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309071 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx, DEFAULT_PSOC_ID);
9072 if (ret) {
Dundi Raviteja8e338282018-09-25 17:16:04 +05309073 QDF_DEBUG_PANIC("Psoc creation fails!");
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309074 goto err_free_config;
9075 }
9076
Dundi Raviteja8e338282018-09-25 17:16:04 +05309077 hdd_cfg_params_init(hdd_ctx);
9078
Dustin Brown7f939932017-05-18 15:02:17 -07009079 hdd_debug("setting timer multiplier: %u",
9080 hdd_ctx->config->timer_multiplier);
9081 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
9082
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309083 cds_set_fatal_event(cfg_get(hdd_ctx->psoc,
9084 CFG_ENABLE_FATAL_EVENT_TRIGGER));
Abhishek Singh5ea86532016-04-27 14:10:53 +05309085
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009086 hdd_override_ini_config(hdd_ctx);
9087
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009088 ret = hdd_context_init(hdd_ctx);
9089
9090 if (ret)
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309091 goto err_hdd_objmgr_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009092
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009093 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05309094 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009095
Anurag Chouhan6d760662016-02-20 16:05:43 +05309096 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009097 goto skip_multicast_logging;
9098
9099 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
9100
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07009101 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
9102 if (ret)
9103 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05309104
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009105 ret = hdd_init_netlink_services(hdd_ctx);
9106 if (ret)
9107 goto err_deinit_txrx_histogram;
9108
Nirav Shaheb017be2018-02-15 11:20:58 +05309109 hdd_set_wlan_logging(hdd_ctx);
Nirav Shahed34b212016-04-25 10:59:16 +05309110
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009111skip_multicast_logging:
9112 hdd_set_trace_level_for_each(hdd_ctx);
9113
Rajeev Kumar493a31b2017-09-29 14:01:24 -07009114 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
9115
Dustin Browne74003f2018-03-14 12:51:58 -07009116 hdd_exit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07009117
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009118 return hdd_ctx;
9119
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009120err_deinit_txrx_histogram:
9121 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
9122
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07009123err_deinit_hdd_context:
9124 hdd_context_deinit(hdd_ctx);
9125
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309126err_hdd_objmgr_destroy:
9127 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9128
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009129err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309130 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009131
9132err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309133 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08009134 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009135
9136err_out:
9137 return ERR_PTR(ret);
9138}
9139
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009140#ifdef WLAN_OPEN_P2P_INTERFACE
9141/**
9142 * hdd_open_p2p_interface - Open P2P interface
9143 * @hdd_ctx: HDD context
9144 * @rtnl_held: True if RTNL lock held
9145 *
9146 * Open P2P interface during probe. This function called to open the P2P
9147 * interface at probe along with STA interface.
9148 *
9149 * Return: 0 on success and errno on failure
9150 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009151static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009152{
Jeff Johnson9d295242017-08-29 14:39:48 -07009153 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009154 uint8_t *p2p_dev_addr;
Wu Gaoe5689792018-07-05 19:20:13 +08009155 bool p2p_dev_addr_admin = false;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009156
Dustin Brown1dbefe62018-09-11 16:32:03 -07009157 cfg_p2p_get_device_addr_admin(hdd_ctx->psoc, &p2p_dev_addr_admin);
Wu Gaoe5689792018-07-05 19:20:13 +08009158 if (p2p_dev_addr_admin &&
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009159 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009160 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009161 hdd_ctx->config->intfMacAddr[0].bytes,
9162 sizeof(tSirMacAddr));
9163
9164 /*
9165 * Generate the P2P Device Address. This consists of
9166 * the device's primary MAC address with the locally
9167 * administered bit set.
9168 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009169 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009170 } else {
9171 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
9172 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009173 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009174 return -ENOSPC;
9175 }
9176
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009177 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
9178 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009179 }
9180
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009181 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009182 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08009183 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009184
9185 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009186 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009187 return -ENOSPC;
9188 }
9189
9190 return 0;
9191}
9192#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009193static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009194 bool rtnl_held)
9195{
9196 return 0;
9197}
9198#endif
9199
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009200static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08009201{
Jeff Johnson9d295242017-08-29 14:39:48 -07009202 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08009203 int ret = 0;
9204
9205 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
9206 wlan_hdd_get_intf_addr(hdd_ctx),
9207 NET_NAME_UNKNOWN, rtnl_held);
9208 if (adapter == NULL) {
9209 hdd_err("Failed to open 802.11p interface");
9210 ret = -ENOSPC;
9211 }
9212
9213 return ret;
9214}
9215
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009216/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309217 * hdd_start_station_adapter()- Start the Station Adapter
9218 * @adapter: HDD adapter
9219 *
9220 * This function initializes the adapter for the station mode.
9221 *
9222 * Return: 0 on success or errno on failure.
9223 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009224int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309225{
9226 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08009227 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309228
Dustin Brownfdf17c12018-03-14 12:55:34 -07009229 hdd_enter_dev(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08009230 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9231 hdd_err("session is already opened, %d",
9232 adapter->session_id);
9233 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9234 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309235
Krunal Sonib51eec72017-11-20 21:53:01 -08009236 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
9237 if (ret) {
9238 hdd_err("failed to create vdev: %d", ret);
9239 return ret;
9240 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309241 status = hdd_init_station_mode(adapter);
9242
9243 if (QDF_STATUS_SUCCESS != status) {
9244 hdd_err("Error Initializing station mode: %d", status);
9245 return qdf_status_to_os_return(status);
9246 }
9247
Arun Khandavallifae92942016-08-01 13:31:08 +05309248 hdd_register_tx_flow_control(adapter,
9249 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009250 hdd_tx_resume_cb,
9251 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309252
Dustin Browne74003f2018-03-14 12:51:58 -07009253 hdd_exit();
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05309254
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309255 return 0;
9256}
9257
9258/**
9259 * hdd_start_ap_adapter()- Start AP Adapter
9260 * @adapter: HDD adapter
9261 *
9262 * This function initializes the adapter for the AP mode.
9263 *
9264 * Return: 0 on success errno on failure.
9265 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009266int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309267{
9268 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009269 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08009270 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08009271 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309272
Dustin Brown491d54b2018-03-14 12:39:11 -07009273 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309274
Krunal Sonib51eec72017-11-20 21:53:01 -08009275 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9276 hdd_err("session is already opened, %d",
9277 adapter->session_id);
9278 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9279 }
9280 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009281 * In SSR case no need to create new sap context.
9282 * Otherwise create sap context first and then create
9283 * vdev as while creating the vdev, driver needs to
9284 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08009285 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009286 if (adapter->session.ap.sap_context) {
9287 is_ssr = true;
9288 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08009289 hdd_err("sap creation failed");
9290 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
9291 }
9292
9293 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
9294 adapter->session.ap.sap_context);
9295 if (ret) {
9296 hdd_err("failed to create vdev, status:%d", ret);
9297 hdd_sap_destroy_ctx(adapter);
9298 return ret;
9299 }
Naveen Rawat1af09392018-01-03 17:28:21 -08009300
9301 if (adapter->device_mode == QDF_SAP_MODE)
9302 sme_cli_set_command(adapter->session_id,
9303 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
9304 (bool)(hdd_ctx->config->fine_time_meas_cap &
9305 WMI_FW_AP_RTT_RESPR),
9306 VDEV_CMD);
9307
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009308 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309309
9310 if (QDF_STATUS_SUCCESS != status) {
9311 hdd_err("Error Initializing the AP mode: %d", status);
9312 return qdf_status_to_os_return(status);
9313 }
9314
Arun Khandavallifae92942016-08-01 13:31:08 +05309315 hdd_register_tx_flow_control(adapter,
9316 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009317 hdd_softap_tx_resume_cb,
9318 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309319
Dustin Browne74003f2018-03-14 12:51:58 -07009320 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309321 return 0;
9322}
9323
Sourav Mohapatra57006c72017-11-19 16:15:55 +05309324static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
9325 bool rtnl_held)
9326{
9327 struct hdd_adapter *adapter;
9328
9329 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
9330 hdd_ctx->config->enableConcurrentSTA,
9331 wlan_hdd_get_intf_addr(hdd_ctx),
9332 NET_NAME_UNKNOWN, rtnl_held);
9333
9334 if (!adapter)
9335 return -ENOSPC;
9336
9337 return 0;
9338}
9339
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309340/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009341 * hdd_open_interfaces - Open all required interfaces
9342 * hdd_ctx: HDD context
9343 * rtnl_held: True if RTNL lock is held
9344 *
9345 * Open all the interfaces like STA, P2P and OCB based on the configuration.
9346 *
Jeff Johnson957bc272017-02-02 08:54:48 -08009347 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009348 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009349static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009350{
Jeff Johnson9d295242017-08-29 14:39:48 -07009351 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009352 int ret;
Wu Gao93816212018-08-31 16:49:54 +08009353 uint8_t dot11p_mode;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009354
Ravi Joshia307f632017-07-17 23:41:41 -07009355 /* open monitor mode adapter if con_mode is monitor mode */
Lin Bai1c678482017-12-18 18:29:11 +08009356 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
9357 con_mode == QDF_GLOBAL_FTM_MODE) {
9358 uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
9359 QDF_MONITOR_MODE : QDF_FTM_MODE;
9360
9361 adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
9362 wlan_hdd_get_intf_addr(hdd_ctx),
9363 NET_NAME_UNKNOWN, rtnl_held);
Ravi Joshia307f632017-07-17 23:41:41 -07009364 if (!adapter) {
9365 hdd_err("open adapter failed");
9366 return -ENOSPC;
9367 }
Lin Bai1c678482017-12-18 18:29:11 +08009368
Ravi Joshia307f632017-07-17 23:41:41 -07009369 return 0;
9370 }
Dustin Brown1dbefe62018-09-11 16:32:03 -07009371 ucfg_mlme_get_dot11p_mode(hdd_ctx->psoc, &dot11p_mode);
Wu Gao93816212018-08-31 16:49:54 +08009372 if (dot11p_mode == CFG_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05309373 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08009374 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009375
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009376 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009377 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08009378 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009379
9380 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08009381 return -ENOSPC;
9382
Sourav Mohapatra57006c72017-11-19 16:15:55 +05309383 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
9384 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
9385 if (ret)
9386 hdd_err("Cannot create concurrent STA interface");
9387 }
9388
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009389 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
9390 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08009391 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009392
9393 /* Open 802.11p Interface */
Wu Gao93816212018-08-31 16:49:54 +08009394 if (dot11p_mode == CFG_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08009395 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
9396 if (ret)
9397 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009398 }
9399
Jeff Johnson957bc272017-02-02 08:54:48 -08009400 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009401
Jeff Johnson957bc272017-02-02 08:54:48 -08009402err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009403 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08009404 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009405}
9406
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009407
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309408#ifdef QCA_LL_TX_FLOW_CONTROL_V2
9409/**
9410 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
9411 * @cds_cfg: CDS Configuration
9412 * @hdd_ctx: Pointer to hdd context
9413 *
9414 * Return: none
9415 */
9416static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9417 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009418 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309419{
9420 cds_cfg->tx_flow_stop_queue_th =
9421 hdd_ctx->config->TxFlowStopQueueThreshold;
9422 cds_cfg->tx_flow_start_queue_offset =
9423 hdd_ctx->config->TxFlowStartQueueOffset;
Mohit Khanna70322002018-05-15 19:21:32 -07009424 /* configuration for DP RX Threads */
9425 cds_cfg->enable_dp_rx_threads = hdd_ctx->enable_dp_rx_threads;
9426 cds_cfg->num_dp_rx_threads = hdd_ctx->config->num_dp_rx_threads;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309427}
9428#else
9429static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9430 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009431 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309432{
9433}
9434#endif
9435
9436#ifdef FEATURE_WLAN_RA_FILTERING
9437/**
9438 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
9439 * @cds_cfg: CDS Configuration
9440 * @hdd_ctx: Pointer to hdd context
9441 *
9442 * Return: none
9443 */
Anand Kumar3b92a912016-12-05 12:01:26 +05309444static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009445 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309446{
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05309447 bool is_rate_limit_enabled;
9448 QDF_STATUS status;
9449
9450 status = ucfg_fwol_get_is_rate_limit_enabled(hdd_ctx->psoc,
9451 &is_rate_limit_enabled);
9452 if (QDF_IS_STATUS_ERROR(status))
9453 return;
9454
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309455 cds_cfg->ra_ratelimit_interval =
9456 hdd_ctx->config->RArateLimitInterval;
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05309457 cds_cfg->is_ra_ratelimit_enabled = is_rate_limit_enabled;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309458}
9459#else
Anand Kumar3b92a912016-12-05 12:01:26 +05309460static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009461 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309462{
9463}
9464#endif
9465
9466/**
9467 * hdd_update_cds_config() - API to update cds configuration parameters
9468 * @hdd_ctx: HDD Context
9469 *
9470 * Return: 0 for Success, errno on failure
9471 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009472static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309473{
9474 struct cds_config_info *cds_cfg;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309475 int value;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309476 uint8_t band_capability;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309477 uint8_t ito_repeat_count;
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309478 bool crash_inject;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309479 bool self_recovery;
9480 bool fw_timeout_crash;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309481 QDF_STATUS status;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309482
9483 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
9484 if (!cds_cfg) {
9485 hdd_err("failed to allocate cds config");
9486 return -ENOMEM;
9487 }
9488
Srinivas Girigowda35b00312017-06-27 21:52:03 -07009489 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309490 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309491
9492 /*
9493 * Copy the DFS Phyerr Filtering Offload status.
9494 * This parameter reflects the value of the
9495 * dfs_phyerr_filter_offload flag as set in the ini.
9496 */
9497 cds_cfg->dfs_phyerr_filter_offload =
9498 hdd_ctx->config->fDfsPhyerrFilterOffload;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309499
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309500 status = ucfg_mlme_get_crash_inject(hdd_ctx->psoc, &crash_inject);
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309501 if (QDF_IS_STATUS_ERROR(status)) {
9502 hdd_err("Failed to get crash inject ini config");
9503 goto exit;
9504 }
9505
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309506 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
9507 if (QDF_IS_STATUS_ERROR(status)) {
9508 hdd_err("Failed to get self recovery ini config");
9509 goto exit;
9510 }
9511
9512 status = ucfg_mlme_get_fw_timeout_crash(hdd_ctx->psoc,
9513 &fw_timeout_crash);
9514 if (QDF_IS_STATUS_ERROR(status)) {
9515 hdd_err("Failed to get fw timeout crash ini config");
9516 goto exit;
9517 }
9518
9519 status = ucfg_mlme_get_ito_repeat_count(hdd_ctx->psoc,
9520 &ito_repeat_count);
9521 if (QDF_IS_STATUS_ERROR(status)) {
9522 hdd_err("Failed to get ITO repeat count ini config");
9523 goto exit;
9524 }
9525
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309526 cds_cfg->force_target_assert_enabled = crash_inject;
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05309527
Dustin Brown05d81302018-09-11 16:49:22 -07009528 ucfg_mlme_get_sap_max_offload_peers(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309529 cds_cfg->ap_maxoffload_peers = value;
Dustin Brown05d81302018-09-11 16:49:22 -07009530 ucfg_mlme_get_sap_max_offload_reorder_buffs(hdd_ctx->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309531 &value);
9532 cds_cfg->ap_maxoffload_reorderbuffs = value;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309533
9534 cds_cfg->ap_disable_intrabss_fwd =
9535 hdd_ctx->config->apDisableIntraBssFwd;
9536
9537 cds_cfg->dfs_pri_multiplier =
9538 hdd_ctx->config->dfsRadarPriMultiplier;
9539 cds_cfg->reorder_offload =
9540 hdd_ctx->config->reorderOffloadSupport;
9541
9542 /* IPA micro controller data path offload resource config item */
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05309543 cds_cfg->uc_offload_enabled = ucfg_ipa_uc_is_enabled();
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309544 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07009545 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
9546 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009547 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009548 hdd_ctx->config->IpaUcRxIndRingCount);
9549 hdd_ctx->config->IpaUcRxIndRingCount =
9550 rounddown_pow_of_two(
9551 hdd_ctx->config->IpaUcRxIndRingCount);
9552 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
9553 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309554 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07009555 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009556 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009557 hdd_ctx->config->IpaUcRxIndRingCount);
9558 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309559 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07009560 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309561 cds_cfg->uc_tx_partition_base =
9562 hdd_ctx->config->IpaUcTxPartitionBase;
9563 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
9564
9565 cds_cfg->ip_tcp_udp_checksum_offload =
9566 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07009567 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309568 cds_cfg->ce_classify_enabled =
9569 hdd_ctx->config->ce_classify_enabled;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309570 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
Dustin Brown05d81302018-09-11 16:49:22 -07009571 ucfg_mlme_get_sap_max_peers(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309572 cds_cfg->max_station = value;
Naveen Rawat64e477e2016-05-20 10:34:56 -07009573 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07009574 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07009575 cds_cfg->max_msdus_per_rxinorderind =
9576 hdd_ctx->config->max_msdus_per_rxinorderind;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309577 cds_cfg->self_recovery_enabled = self_recovery;
9578 cds_cfg->fw_timeout_crash = fw_timeout_crash;
Nachiket Kukadee547a482018-05-22 16:43:30 +05309579 cds_cfg->active_uc_apf_mode = hdd_ctx->config->active_uc_apf_mode;
9580 cds_cfg->active_mc_bc_apf_mode = hdd_ctx->config->active_mc_bc_apf_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309581
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309582 cds_cfg->ito_repeat_count = ito_repeat_count;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309583
9584 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
9585 if (QDF_IS_STATUS_ERROR(status))
9586 goto exit;
9587
9588 cds_cfg->bandcapability = band_capability;
Zhu Jianmina2f8e8d2018-02-11 16:37:10 +08009589 cds_cfg->delay_before_vdev_stop =
9590 hdd_ctx->config->delay_before_vdev_stop;
Rachit Kankane0106e382018-05-16 18:59:28 +05309591 cds_cfg->num_vdevs = hdd_ctx->config->num_vdevs;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309592
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309593 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
9594 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07009595 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309596 cds_init_ini_config(cds_cfg);
9597 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309598
9599exit:
9600 qdf_mem_free(cds_cfg);
9601 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309602}
9603
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009604/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009605 * hdd_update_user_config() - API to update user configuration
9606 * parameters to obj mgr which are used by multiple components
9607 * @hdd_ctx: HDD Context
9608 *
9609 * Return: 0 for Success, errno on failure
9610 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009611static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009612{
9613 struct wlan_objmgr_psoc_user_config *user_config;
Wu Gaoe5689792018-07-05 19:20:13 +08009614 bool skip_dfs_in_p2p_search = false;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309615 uint8_t band_capability;
9616 QDF_STATUS status;
9617
9618 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
9619 if (QDF_IS_STATUS_ERROR(status))
9620 return -EIO;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009621
9622 user_config = qdf_mem_malloc(sizeof(*user_config));
9623 if (user_config == NULL) {
9624 hdd_alert("Failed to alloc memory for user_config!");
9625 return -ENOMEM;
9626 }
9627
9628 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
9629 user_config->dual_mac_feature_disable =
9630 hdd_ctx->config->dual_mac_feature_disable;
9631 user_config->indoor_channel_support =
9632 hdd_ctx->config->indoor_channel_support;
9633 user_config->is_11d_support_enabled =
9634 hdd_ctx->config->Is11dSupportEnabled;
9635 user_config->is_11h_support_enabled =
9636 hdd_ctx->config->Is11hSupportEnabled;
Dustin Brown1dbefe62018-09-11 16:32:03 -07009637 cfg_p2p_get_skip_dfs_channel_p2p_search(hdd_ctx->psoc,
Wu Gaoe5689792018-07-05 19:20:13 +08009638 &skip_dfs_in_p2p_search);
9639 user_config->skip_dfs_chnl_in_p2p_search = skip_dfs_in_p2p_search;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309640 user_config->band_capability = band_capability;
Dustin Brown1dbefe62018-09-11 16:32:03 -07009641 wlan_objmgr_psoc_set_user_config(hdd_ctx->psoc, user_config);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009642
9643 qdf_mem_free(user_config);
9644 return 0;
9645}
9646
9647/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009648 * hdd_init_thermal_info - Initialize thermal level
9649 * @hdd_ctx: HDD context
9650 *
9651 * Initialize thermal level at SME layer and set the thermal level callback
9652 * which would be called when a configured thermal threshold is hit.
9653 *
9654 * Return: 0 on success and errno on failure
9655 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009656static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009657{
9658 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309659 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -07009660 mac_handle_t mac_handle;
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309661 struct wlan_fwol_thermal_temp thermal_temp = {0};
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009662
9663 thermal_param.smeThermalMgmtEnabled =
9664 hdd_ctx->config->thermalMitigationEnable;
9665 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
9666
Poddar, Siddarth83905022016-04-16 17:56:08 -07009667 thermal_param.sme_throttle_duty_cycle_tbl[0] =
9668 hdd_ctx->config->throttle_dutycycle_level0;
9669 thermal_param.sme_throttle_duty_cycle_tbl[1] =
9670 hdd_ctx->config->throttle_dutycycle_level1;
9671 thermal_param.sme_throttle_duty_cycle_tbl[2] =
9672 hdd_ctx->config->throttle_dutycycle_level2;
9673 thermal_param.sme_throttle_duty_cycle_tbl[3] =
9674 hdd_ctx->config->throttle_dutycycle_level3;
9675
Dustin Brown05d81302018-09-11 16:49:22 -07009676 status = ucfg_fwol_get_thermal_temp(hdd_ctx->psoc, &thermal_temp);
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309677 if (QDF_IS_STATUS_ERROR(status))
9678 return qdf_status_to_os_return(status);
9679
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009680 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309681 thermal_temp.thermal_temp_min_level0;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009682 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309683 thermal_temp.thermal_temp_max_level0;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009684 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309685 thermal_temp.thermal_temp_min_level1;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009686 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309687 thermal_temp.thermal_temp_max_level1;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009688 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309689 thermal_temp.thermal_temp_min_level2;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009690 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309691 thermal_temp.thermal_temp_max_level2;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009692 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309693 thermal_temp.thermal_temp_min_level3;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009694 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309695 thermal_temp.thermal_temp_max_level3;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009696
Jeff Johnson16528362018-06-14 12:34:16 -07009697 mac_handle = hdd_ctx->mac_handle;
9698 status = sme_init_thermal_info(mac_handle, thermal_param);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009699
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309700 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05309701 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009702
Jeff Johnson16528362018-06-14 12:34:16 -07009703 sme_add_set_thermal_level_callback(mac_handle,
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009704 hdd_set_thermal_level_cb);
9705
9706 return 0;
9707
9708}
9709
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009710#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
9711/**
9712 * hdd_hold_rtnl_lock - Hold RTNL lock
9713 *
9714 * Hold RTNL lock
9715 *
9716 * Return: True if held and false otherwise
9717 */
9718static inline bool hdd_hold_rtnl_lock(void)
9719{
9720 rtnl_lock();
9721 return true;
9722}
9723
9724/**
9725 * hdd_release_rtnl_lock - Release RTNL lock
9726 *
9727 * Release RTNL lock
9728 *
9729 * Return: None
9730 */
9731static inline void hdd_release_rtnl_lock(void)
9732{
9733 rtnl_unlock();
9734}
9735#else
9736static inline bool hdd_hold_rtnl_lock(void) { return false; }
9737static inline void hdd_release_rtnl_lock(void) { }
9738#endif
9739
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009740#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009741
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309742/* MAX iwpriv command support */
9743#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309744#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309745#define MAX_PKTLOG_SIZE 16
9746
9747/**
9748 * hdd_pktlog_set_buff_size() - set pktlog buffer size
9749 * @hdd_ctx: hdd context
9750 * @set_value2: pktlog buffer size value
9751 *
9752 *
9753 * Return: 0 for success or error.
9754 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009755static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309756{
9757 struct sir_wifi_start_log start_log = { 0 };
9758 QDF_STATUS status;
9759
9760 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9761 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9762 start_log.ini_triggered = cds_is_packet_log_enabled();
9763 start_log.user_triggered = 1;
9764 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309765 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309766
Jeff Johnson16528362018-06-14 12:34:16 -07009767 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309768 if (!QDF_IS_STATUS_SUCCESS(status)) {
9769 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009770 hdd_exit();
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309771 return -EINVAL;
9772 }
9773
9774 return 0;
9775}
9776
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009777/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309778 * hdd_pktlog_clear_buff() - clear pktlog buffer
9779 * @hdd_ctx: hdd context
9780 *
9781 * Return: 0 for success or error.
9782 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009783static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309784{
9785 struct sir_wifi_start_log start_log;
9786 QDF_STATUS status;
9787
9788 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9789 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9790 start_log.ini_triggered = cds_is_packet_log_enabled();
9791 start_log.user_triggered = 1;
9792 start_log.size = 0;
9793 start_log.is_pktlog_buff_clear = true;
9794
Jeff Johnson16528362018-06-14 12:34:16 -07009795 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309796 if (!QDF_IS_STATUS_SUCCESS(status)) {
9797 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009798 hdd_exit();
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309799 return -EINVAL;
9800 }
9801
9802 return 0;
9803}
9804
9805
9806/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009807 * hdd_process_pktlog_command() - process pktlog command
9808 * @hdd_ctx: hdd context
9809 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309810 * @set_value2: pktlog buffer size value
9811 *
9812 * This function process pktlog command.
9813 * set_value2 only matters when set_value is 3 (set buff size)
9814 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009815 *
9816 * Return: 0 for success or error.
9817 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009818int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309819 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009820{
9821 int ret;
9822 bool enable;
9823 uint8_t user_triggered = 0;
9824
9825 ret = wlan_hdd_validate_context(hdd_ctx);
9826 if (0 != ret)
9827 return ret;
9828
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009829 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009830
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309831 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009832 hdd_err("invalid pktlog value %d", set_value);
9833 return -EINVAL;
9834 }
9835
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309836 if (set_value == PKTLOG_SET_BUFF_SIZE) {
9837 if (set_value2 <= 0) {
9838 hdd_err("invalid pktlog size %d", set_value2);
9839 return -EINVAL;
9840 } else if (set_value2 > MAX_PKTLOG_SIZE) {
9841 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
9842 return -EINVAL;
9843 }
9844 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309845 } else if (set_value == PKTLOG_CLEAR_BUFF) {
9846 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309847 }
9848
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009849 /*
9850 * set_value = 0 then disable packetlog
9851 * set_value = 1 enable packetlog forcefully
9852 * set_vlaue = 2 then disable packetlog if disabled through ini or
9853 * enable packetlog with AUTO type.
9854 */
9855 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
9856 true : false;
9857
9858 if (1 == set_value) {
9859 enable = true;
9860 user_triggered = 1;
9861 }
9862
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309863 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009864}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07009865
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009866/**
9867 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
9868 * @hdd_ctx: HDD context
9869 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309870 * @user_triggered: triggered through iwpriv
9871 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009872 *
9873 * Return: 0 on success; error number otherwise
9874 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009875int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309876 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009877{
9878 struct sir_wifi_start_log start_log;
9879 QDF_STATUS status;
9880
9881 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9882 start_log.verbose_level =
9883 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009884 start_log.ini_triggered = cds_is_packet_log_enabled();
9885 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309886 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309887 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05309888 /*
9889 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
9890 * commands. Host uses this flag to decide whether to send pktlog
9891 * disable command to fw without sending pktlog enable command
9892 * previously. For eg, If vendor sends pktlog disable command without
9893 * sending pktlog enable command, then host discards the packet
9894 * but for iwpriv command, host will send it to fw.
9895 */
9896 start_log.is_iwpriv_command = 1;
Jeff Johnson16528362018-06-14 12:34:16 -07009897 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009898 if (!QDF_IS_STATUS_SUCCESS(status)) {
9899 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009900 hdd_exit();
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009901 return -EINVAL;
9902 }
9903
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309904 if (enable == true)
9905 hdd_ctx->is_pktlog_enabled = 1;
9906 else
9907 hdd_ctx->is_pktlog_enabled = 0;
9908
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009909 return 0;
9910}
9911#endif /* REMOVE_PKT_LOG */
9912
Komal Seelam92fff912016-03-24 11:51:41 +05309913/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009914 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
9915 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05309916 * @dev: Device Pointer
9917 * @num: Number of Valid Mac address
9918 *
9919 * Return: Pointer to MAC address buffer
9920 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009921static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9922 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309923{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009924 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309925}
Komal Seelam92fff912016-03-24 11:51:41 +05309926
9927/**
9928 * hdd_populate_random_mac_addr() - API to populate random mac addresses
9929 * @hdd_ctx: HDD Context
9930 * @num: Number of random mac addresses needed
9931 *
9932 * Generate random addresses using bit manipulation on the base mac address
9933 *
9934 * Return: None
9935 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009936void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05309937{
9938 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
9939 uint32_t iter;
9940 struct hdd_config *ini = hdd_ctx->config;
9941 uint8_t *buf = NULL;
9942 uint8_t macaddr_b3, tmp_br3;
9943 uint8_t *src = ini->intfMacAddr[0].bytes;
9944
9945 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
9946 buf = ini->intfMacAddr[iter].bytes;
9947 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
9948 macaddr_b3 = buf[3];
9949 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
9950 INTF_MACADDR_MASK;
9951 macaddr_b3 += tmp_br3;
9952 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
9953 buf[0] |= 0x02;
9954 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009955 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309956 }
9957}
9958
9959/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009960 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05309961 * @hdd_ctx: HDD Context
9962 *
9963 * API to get mac addresses from platform driver and update the driver
9964 * structures and configure FW with the base mac address.
9965 * Return: int
9966 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009967static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309968{
9969 uint32_t no_of_mac_addr, iter;
9970 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
9971 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
9972 uint8_t *addr, *buf;
9973 struct device *dev = hdd_ctx->parent_dev;
9974 struct hdd_config *ini = hdd_ctx->config;
9975 tSirMacAddr mac_addr;
9976 QDF_STATUS status;
9977
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009978 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05309979
Dustin Brown7e761c72018-07-31 13:50:17 -07009980 if (no_of_mac_addr == 0 || !addr)
Komal Seelam92fff912016-03-24 11:51:41 +05309981 return -EINVAL;
Komal Seelam92fff912016-03-24 11:51:41 +05309982
9983 if (no_of_mac_addr > max_mac_addr)
9984 no_of_mac_addr = max_mac_addr;
9985
9986 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
9987
9988 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
9989 buf = ini->intfMacAddr[iter].bytes;
9990 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009991 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309992 }
9993
9994 status = sme_set_custom_mac_addr(mac_addr);
9995
9996 if (!QDF_IS_STATUS_SUCCESS(status))
9997 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009998
Komal Seelam92fff912016-03-24 11:51:41 +05309999 if (no_of_mac_addr < max_mac_addr)
10000 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
10001 no_of_mac_addr);
10002 return 0;
10003}
10004
10005/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010006 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
10007 * @hdd_ctx: HDD Context
10008 *
10009 * Update MAC address to FW. If MAC address passed by FW is invalid, host
10010 * will generate its own MAC and update it to FW.
10011 *
10012 * Return: 0 for success
10013 * Non-zero error code for failure
10014 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010015static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010016{
10017 tSirMacAddr customMacAddr;
10018 QDF_STATUS status;
10019
10020 qdf_mem_copy(&customMacAddr,
10021 &hdd_ctx->config->intfMacAddr[0].bytes[0],
10022 sizeof(tSirMacAddr));
10023 status = sme_set_custom_mac_addr(customMacAddr);
10024 if (!QDF_IS_STATUS_SUCCESS(status))
10025 return -EAGAIN;
10026 return 0;
10027}
10028
10029/**
Komal Seelam92fff912016-03-24 11:51:41 +053010030 * hdd_initialize_mac_address() - API to get wlan mac addresses
10031 * @hdd_ctx: HDD Context
10032 *
10033 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
10034 * is provisioned with mac addresses, driver uses it, else it will use
10035 * wlan_mac.bin to update HW MAC addresses.
10036 *
10037 * Return: None
10038 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010039static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +053010040{
10041 QDF_STATUS status;
10042 int ret;
10043
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010044 ret = hdd_platform_wlan_mac(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010045 if (!ret) {
10046 hdd_info("using MAC address from platform driver");
Komal Seelam92fff912016-03-24 11:51:41 +053010047 return;
Dustin Brown7e761c72018-07-31 13:50:17 -070010048 }
Komal Seelam92fff912016-03-24 11:51:41 +053010049
10050 status = hdd_update_mac_config(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010051 if (QDF_IS_STATUS_SUCCESS(status)) {
10052 hdd_info("using MAC address from wlan_mac.bin");
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010053 return;
Dustin Brown7e761c72018-07-31 13:50:17 -070010054 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010055
Dustin Brown7e761c72018-07-31 13:50:17 -070010056 hdd_info("using default MAC address");
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010057
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -080010058 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010059 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010060 if (ret)
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -080010061 hdd_err("MAC address out-of-sync, ret:%d", ret);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010062 }
Komal Seelam92fff912016-03-24 11:51:41 +053010063}
10064
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010065static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010066{
10067 int vdev_id = 0;
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053010068 QDF_STATUS status;
10069 bool smart_chainmask_enabled;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010070 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010071 int vpdev = PDEV_CMD;
10072 int ret;
10073
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053010074 status = ucfg_get_smart_chainmask_enabled(hdd_ctx->psoc,
10075 &smart_chainmask_enabled);
10076 if (QDF_IS_STATUS_ERROR(status))
10077 return -EINVAL;
10078
10079 ret = sme_cli_set_command(vdev_id, param_id,
10080 (int)smart_chainmask_enabled, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010081 if (ret)
10082 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
10083
10084 return ret;
10085}
10086
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010087static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010088{
10089 int vdev_id = 0;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010090 QDF_STATUS status;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010091 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010092 bool alternative_chainmask_enabled;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010093 int vpdev = PDEV_CMD;
10094 int ret;
10095
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010096 status = ucfg_get_alternative_chainmask_enabled(
10097 hdd_ctx->psoc,
10098 &alternative_chainmask_enabled);
10099 if (QDF_IS_STATUS_ERROR(status))
10100 return -EINVAL;
10101
10102 ret = sme_cli_set_command(vdev_id, param_id,
10103 (int)alternative_chainmask_enabled, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010104 if (ret)
10105 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
10106 ret);
10107
10108 return ret;
10109}
10110
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010111static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -070010112{
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010113 QDF_STATUS status;
Jeff Johnson12a744b2017-04-04 08:19:37 -070010114 int vdev_id = 0;
10115 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010116 bool value;
Jeff Johnson12a744b2017-04-04 08:19:37 -070010117 int vpdev = PDEV_CMD;
10118 int ret;
10119
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010120 status = ucfg_fwol_get_ani_enabled(hdd_ctx->psoc, &value);
10121 if (QDF_IS_STATUS_ERROR(status))
10122 return -EINVAL;
10123
10124 ret = sme_cli_set_command(vdev_id, param_id, (int)value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -070010125 if (ret)
10126 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
10127
10128 return ret;
10129}
10130
Jeff Johnson89c66ff2016-04-22 15:21:37 -070010131/**
Prashanth Bhatta07998752016-04-28 12:35:33 -070010132 * hdd_pre_enable_configure() - Configurations prior to cds_enable
10133 * @hdd_ctx: HDD context
10134 *
10135 * Pre configurations to be done at lower layer before calling cds enable.
10136 *
10137 * Return: 0 on success and errno on failure.
10138 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010139static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -070010140{
10141 int ret;
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010142 uint8_t val = 0;
Prashanth Bhatta07998752016-04-28 12:35:33 -070010143 QDF_STATUS status;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010144 uint32_t arp_ac_category;
Leo Changfdb45c32016-10-28 11:09:23 -070010145 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010146
Leo Changfdb45c32016-10-28 11:09:23 -070010147 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Ajit Pal Singh5d269612018-04-19 16:29:12 +053010148 /* Register HL netdev flow control callback */
10149 cdp_hl_fc_register(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010150
10151 /*
10152 * Note that the cds_pre_enable() sequence triggers the cfg download.
10153 * The cfg download must occur before we update the SME config
10154 * since the SME config operation must access the cfg database
10155 */
10156 status = hdd_set_sme_config(hdd_ctx);
10157
10158 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010159 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010160 ret = qdf_status_to_os_return(status);
10161 goto out;
10162 }
10163
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -070010164 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
10165 if (QDF_STATUS_SUCCESS != status) {
10166 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
10167 ret = qdf_status_to_os_return(status);
10168 goto out;
10169 }
10170
Dustin Brown1dbefe62018-09-11 16:32:03 -070010171 status = ucfg_mlme_get_tx_chainmask_1ss(hdd_ctx->psoc, &val);
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010172 if (QDF_STATUS_SUCCESS != status) {
10173 hdd_err("Get tx_chainmask_1ss from mlme failed");
10174 ret = qdf_status_to_os_return(status);
10175 goto out;
10176 }
10177 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS, val,
Prashanth Bhatta07998752016-04-28 12:35:33 -070010178 PDEV_CMD);
10179 if (0 != ret) {
10180 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
10181 goto out;
10182 }
10183
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010184 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
10185 if (ret)
10186 goto out;
10187
10188 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
10189 if (ret)
10190 goto out;
10191
Jeff Johnson12a744b2017-04-04 08:19:37 -070010192 ret = hdd_set_ani_enabled(hdd_ctx);
10193 if (ret)
10194 goto out;
10195
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010196 status = ucfg_get_arp_ac_category(hdd_ctx->psoc, &arp_ac_category);
10197
10198 if (QDF_IS_STATUS_ERROR(status))
10199 return -EINVAL;
10200
Naveen Rawat247a8682017-06-05 15:00:31 -070010201 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010202 arp_ac_category,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -080010203 PDEV_CMD);
10204 if (0 != ret) {
10205 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010206 arp_ac_category, ret);
Srinivas Girigowda70e169a2017-03-07 23:55:57 -080010207 goto out;
10208 }
10209
Prashanth Bhatta07998752016-04-28 12:35:33 -070010210 status = hdd_set_sme_chan_list(hdd_ctx);
10211 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010212 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010213 ret = qdf_status_to_os_return(status);
10214 goto out;
10215 }
10216
10217 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -070010218 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010219 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -070010220 ret = -EINVAL;
10221 goto out;
10222 }
10223
Prashanth Bhatta07998752016-04-28 12:35:33 -070010224 /*
10225 * Set the MAC Address Currently this is used by HAL to add self sta.
10226 * Remove this once self sta is added as part of session open.
10227 */
Jeff Johnson16528362018-06-14 12:34:16 -070010228 status = sme_cfg_set_str(hdd_ctx->mac_handle, WNI_CFG_STA_ID,
Jeff Johnsonbae59f92018-06-01 17:05:43 -070010229 hdd_ctx->config->intfMacAddr[0].bytes,
10230 sizeof(hdd_ctx->config->intfMacAddr[0]));
Prashanth Bhatta07998752016-04-28 12:35:33 -070010231
Jeff Johnsonbae59f92018-06-01 17:05:43 -070010232 if (QDF_IS_STATUS_ERROR(status)) {
10233 hdd_err("Failed to set MAC Address, status %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010234 ret = -EINVAL;
10235 goto out;
10236 }
10237
10238 hdd_init_channel_avoidance(hdd_ctx);
10239
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +053010240 /* update enable sap mandatory chan list */
Dustin Brown1dbefe62018-09-11 16:32:03 -070010241 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->psoc,
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +053010242 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010243out:
10244 return ret;
10245}
10246
Rachit Kankane026e77a2018-07-31 16:21:09 +053010247#ifdef FEATURE_P2P_LISTEN_OFFLOAD
Prashanth Bhatta07998752016-04-28 12:35:33 -070010248/**
Peng Xu8fdaa492016-06-22 10:20:47 -070010249 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010250 * @context: context registered with sme_register_p2p_lo_event(). HDD
10251 * always registers a hdd context pointer
10252 * @evt:event structure pointer
Peng Xu8fdaa492016-06-22 10:20:47 -070010253 *
10254 * This is the p2p listen offload stop event handler, it sends vendor
10255 * event back to supplicant to notify the stop reason.
10256 *
10257 * Return: None
10258 */
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010259static void wlan_hdd_p2p_lo_event_callback(void *context,
10260 struct sir_p2p_lo_event *evt)
Peng Xu8fdaa492016-06-22 10:20:47 -070010261{
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010262 struct hdd_context *hdd_ctx = context;
Peng Xu8fdaa492016-06-22 10:20:47 -070010263 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -070010264 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -070010265
Dustin Brown491d54b2018-03-14 12:39:11 -070010266 hdd_enter();
Peng Xu8fdaa492016-06-22 10:20:47 -070010267
10268 if (hdd_ctx == NULL) {
10269 hdd_err("Invalid HDD context pointer");
10270 return;
10271 }
10272
Peng Xu5c682812017-08-06 07:39:13 -070010273 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
10274 if (!adapter) {
10275 hdd_err("Cannot find adapter by vdev_id = %d",
10276 evt->vdev_id);
10277 return;
10278 }
10279
Peng Xu8fdaa492016-06-22 10:20:47 -070010280 vendor_event =
10281 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -070010282 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -070010283 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
10284 GFP_KERNEL);
10285
10286 if (!vendor_event) {
10287 hdd_err("cfg80211_vendor_event_alloc failed");
10288 return;
10289 }
10290
10291 if (nla_put_u32(vendor_event,
10292 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
10293 evt->reason_code)) {
10294 hdd_err("nla put failed");
10295 kfree_skb(vendor_event);
10296 return;
10297 }
10298
10299 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -070010300 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
10301 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -070010302}
Rachit Kankane026e77a2018-07-31 16:21:09 +053010303#else
10304static void wlan_hdd_p2p_lo_event_callback(void *context,
10305 struct sir_p2p_lo_event *evt)
10306{
10307}
10308#endif
Peng Xu8fdaa492016-06-22 10:20:47 -070010309
Rachit Kankanef6834c42018-08-02 18:47:50 +053010310#ifdef FEATURE_WLAN_DYNAMIC_CVM
10311static inline int hdd_set_vc_mode_config(struct hdd_context *hdd_ctx)
10312{
10313 return sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap);
10314}
10315#else
10316static inline int hdd_set_vc_mode_config(struct hdd_context *hdd_ctx)
10317{
10318 return QDF_STATUS_SUCCESS;
10319}
10320#endif
10321
Peng Xu8fdaa492016-06-22 10:20:47 -070010322/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010323 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
10324 * @hdd_ctx: HDD context
10325 *
10326 * This function sends the adaptive dwell time config configuration to the
10327 * firmware via WMA
10328 *
10329 * Return: 0 - success, < 0 - failure
10330 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010331static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010332{
10333 QDF_STATUS status;
10334 struct adaptive_dwelltime_params dwelltime_params;
10335
10336 dwelltime_params.is_enabled =
10337 hdd_ctx->config->adaptive_dwell_mode_enabled;
10338 dwelltime_params.dwelltime_mode =
10339 hdd_ctx->config->global_adapt_dwelltime_mode;
10340 dwelltime_params.lpf_weight =
10341 hdd_ctx->config->adapt_dwell_lpf_weight;
10342 dwelltime_params.passive_mon_intval =
10343 hdd_ctx->config->adapt_dwell_passive_mon_intval;
10344 dwelltime_params.wifi_act_threshold =
10345 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
10346
Jeff Johnson16528362018-06-14 12:34:16 -070010347 status = sme_set_adaptive_dwelltime_config(hdd_ctx->mac_handle,
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010348 &dwelltime_params);
10349
10350 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
10351 if (!QDF_IS_STATUS_SUCCESS(status)) {
10352 hdd_err("Failed to send Adaptive Dwelltime configuration!");
10353 return -EAGAIN;
10354 }
10355 return 0;
10356}
10357
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010358int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010359{
10360 QDF_STATUS status;
10361 struct wmi_dbs_scan_sel_params dbs_scan_params;
10362 uint32_t i = 0;
10363 uint8_t count = 0, numentries = 0;
10364 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
10365 * CDS_DBS_SCAN_CLIENTS_MAX];
10366
10367 /* check if DBS is enabled or supported */
Bala Venkateshc8236ca2018-03-09 12:38:29 +053010368 if ((hdd_ctx->config->dual_mac_feature_disable ==
10369 DISABLE_DBS_CXN_AND_SCAN) ||
10370 (hdd_ctx->config->dual_mac_feature_disable ==
10371 ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN))
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010372 return -EINVAL;
10373
10374 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
10375 dbs_scan_config, &numentries,
10376 (CDS_DBS_SCAN_PARAM_PER_CLIENT
10377 * CDS_DBS_SCAN_CLIENTS_MAX));
10378
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010379 if (!numentries) {
Dustin Brown6a8d39b2018-08-14 15:27:26 -070010380 hdd_debug("Do not send scan_selection_config");
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010381 return 0;
10382 }
10383
10384 /* hdd_set_fw_log_params */
10385 dbs_scan_params.num_clients = 0;
10386 while (count < (numentries - 2)) {
10387 dbs_scan_params.module_id[i] = dbs_scan_config[count];
10388 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
10389 dbs_scan_params.num_non_dbs_scans[i] =
10390 dbs_scan_config[count + 2];
10391 dbs_scan_params.num_clients++;
10392 hdd_debug("module:%d NDS:%d NNDS:%d",
10393 dbs_scan_params.module_id[i],
10394 dbs_scan_params.num_dbs_scans[i],
10395 dbs_scan_params.num_non_dbs_scans[i]);
10396 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
10397 i++;
10398 }
10399
10400 dbs_scan_params.pdev_id = 0;
10401
10402 hdd_debug("clients:%d pdev:%d",
10403 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
10404
Jeff Johnson16528362018-06-14 12:34:16 -070010405 status = sme_set_dbs_scan_selection_config(hdd_ctx->mac_handle,
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010406 &dbs_scan_params);
10407 hdd_debug("Sending DBS Scan Selection Configuration to fw");
10408 if (!QDF_IS_STATUS_SUCCESS(status)) {
10409 hdd_err("Failed to send DBS Scan selection configuration!");
10410 return -EAGAIN;
10411 }
10412 return 0;
10413}
10414
Arun Khandavallid4349a92016-07-25 11:10:43 +053010415#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10416/**
10417 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
10418 * @hdd_ctx: HDD context
10419 *
10420 * Set auto shutdown callback to get indications from firmware to indicate
10421 * userspace to shutdown WLAN after a configured amount of inactivity.
10422 *
10423 * Return: 0 on success and errno on failure.
10424 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010425static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010426{
10427 QDF_STATUS status;
10428
Dundi Raviteja8e338282018-09-25 17:16:04 +053010429 if (!hdd_ctx->config->wlan_auto_shutdown)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010430 return 0;
10431
Jeff Johnson16528362018-06-14 12:34:16 -070010432 status = sme_set_auto_shutdown_cb(hdd_ctx->mac_handle,
Arun Khandavallid4349a92016-07-25 11:10:43 +053010433 wlan_hdd_auto_shutdown_cb);
10434 if (status != QDF_STATUS_SUCCESS)
10435 hdd_err("Auto shutdown feature could not be enabled: %d",
10436 status);
10437
10438 return qdf_status_to_os_return(status);
10439}
10440#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010441static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010442{
10443 return 0;
10444}
10445#endif
10446
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010447#ifdef MWS_COEX
10448/**
10449 * hdd_set_mws_coex() - Set MWS coex configurations
10450 * @hdd_ctx: HDD context
10451 *
10452 * This function sends MWS-COEX 4G quick FTDM and
10453 * MWS-COEX 5G-NR power limit to FW
10454 *
10455 * Return: 0 on success and errno on failure.
10456 */
10457static int hdd_init_mws_coex(struct hdd_context *hdd_ctx)
10458{
10459 int ret = 0;
10460
10461 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_MWSCOEX_4G_ALLOW_QUICK_FTDM,
10462 hdd_ctx->config->mws_coex_4g_quick_tdm,
10463 PDEV_CMD);
10464 if (ret) {
10465 hdd_warn("Unable to send MWS-COEX 4G quick FTDM policy");
10466 return ret;
10467 }
10468
10469 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_MWSCOEX_SET_5GNR_PWR_LIMIT,
10470 hdd_ctx->config->mws_coex_5g_nr_pwr_limit,
10471 PDEV_CMD);
10472 if (ret) {
10473 hdd_warn("Unable to send MWS-COEX 4G quick FTDM policy");
10474 return ret;
10475 }
10476 return ret;
10477}
10478#else
10479static int hdd_init_mws_coex(struct hdd_context *hdd_ctx)
10480{
10481 return 0;
10482}
10483#endif
10484
Arun Khandavallid4349a92016-07-25 11:10:43 +053010485/**
10486 * hdd_features_init() - Init features
10487 * @hdd_ctx: HDD context
Arun Khandavallid4349a92016-07-25 11:10:43 +053010488 *
10489 * Initialize features and their feature context after WLAN firmware is up.
10490 *
10491 * Return: 0 on success and errno on failure.
10492 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010493static int hdd_features_init(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010494{
10495 tSirTxPowerLimit hddtxlimit;
10496 QDF_STATUS status;
10497 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070010498 mac_handle_t mac_handle;
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010499 struct hdd_config *cfg;
Wu Gao93816212018-08-31 16:49:54 +080010500 bool b_cts2self;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010501
Dustin Brown491d54b2018-03-14 12:39:11 -070010502 hdd_enter();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010503
Dustin Brownad698ae2018-09-05 17:19:30 -070010504 ret = hdd_update_country_code(hdd_ctx);
10505 if (ret) {
10506 hdd_err("Failed to update country code; errno:%d", ret);
10507 return -EINVAL;
10508 }
10509
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010510 ret = hdd_init_mws_coex(hdd_ctx);
10511 if (ret)
10512 hdd_warn("Error initializing mws-coex");
10513
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010514 cfg = hdd_ctx->config;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010515 /* FW capabilities received, Set the Dot11 mode */
Jeff Johnson16528362018-06-14 12:34:16 -070010516 mac_handle = hdd_ctx->mac_handle;
10517 sme_setdef_dot11mode(mac_handle);
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010518 sme_set_etsi13_srd_ch_in_master_mode(mac_handle,
10519 cfg->
10520 etsi13_srd_chan_in_master_mode);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010521
10522 if (hdd_ctx->config->fIsImpsEnabled)
10523 hdd_set_idle_ps_config(hdd_ctx, true);
10524 else
10525 hdd_set_idle_ps_config(hdd_ctx, false);
10526
Poddar, Siddarth37033032017-10-11 15:47:40 +053010527 /* Send Enable/Disable data stall detection cmd to FW */
10528 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
10529 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
10530
Dustin Brown1dbefe62018-09-11 16:32:03 -070010531 ucfg_mlme_get_go_cts2self_for_sta(hdd_ctx->psoc, &b_cts2self);
Wu Gao93816212018-08-31 16:49:54 +080010532 if (b_cts2self)
Jeff Johnson16528362018-06-14 12:34:16 -070010533 sme_set_cts2self_for_p2p_go(mac_handle);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010534
Rachit Kankanef6834c42018-08-02 18:47:50 +053010535 if (hdd_set_vc_mode_config(hdd_ctx))
Nachiket Kukade8983cf62017-10-12 18:14:48 +053010536 hdd_warn("Error in setting Voltage Corner mode config to FW");
10537
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010538 if (hdd_rx_ol_init(hdd_ctx))
10539 hdd_err("Unable to initialize Rx LRO/GRO in fw");
Arun Khandavallid4349a92016-07-25 11:10:43 +053010540
10541 if (hdd_adaptive_dwelltime_init(hdd_ctx))
10542 hdd_err("Unable to send adaptive dwelltime setting to FW");
10543
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010544 if (hdd_dbs_scan_selection_init(hdd_ctx))
10545 hdd_err("Unable to send DBS scan selection setting to FW");
10546
Arun Khandavallid4349a92016-07-25 11:10:43 +053010547 ret = hdd_init_thermal_info(hdd_ctx);
10548 if (ret) {
10549 hdd_err("Error while initializing thermal information");
Dustin Browne7e71d32018-05-11 16:00:08 -070010550 return ret;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010551 }
10552
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010553 /**
10554 * In case of SSR/PDR, if pktlog was enabled manually before
10555 * SSR/PDR, Then enabled it again automatically after Wlan
10556 * device up.
10557 */
10558 if (cds_is_driver_recovering()) {
10559 if (hdd_ctx->is_pktlog_enabled)
10560 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Alok Kumar5a75b9d2018-08-31 10:55:43 +053010561 } else if (cds_is_packet_log_enabled())
10562 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Poddar, Siddarth66a46592017-02-22 11:44:44 +053010563
Arun Khandavallid4349a92016-07-25 11:10:43 +053010564 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
10565 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
Jeff Johnson16528362018-06-14 12:34:16 -070010566 status = sme_txpower_limit(mac_handle, &hddtxlimit);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010567 if (!QDF_IS_STATUS_SUCCESS(status))
10568 hdd_err("Error setting txlimit in sme: %d", status);
10569
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010570 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010571
Arun Khandavallid4349a92016-07-25 11:10:43 +053010572 ret = hdd_register_cb(hdd_ctx);
10573 if (ret) {
10574 hdd_err("Failed to register HDD callbacks!");
Dustin Browne7e71d32018-05-11 16:00:08 -070010575 return ret;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010576 }
10577
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053010578 status = sme_enable_disable_chanavoidind_event(mac_handle, 0);
10579 if (QDF_IS_STATUS_ERROR(status) && (status != QDF_STATUS_E_NOSUPPORT)) {
10580 hdd_err("Failed to disable Chan Avoidance Indication");
10581 goto deregister_cb;
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +053010582 }
Arun Khandavallid4349a92016-07-25 11:10:43 +053010583
10584 /* register P2P Listen Offload event callback */
10585 if (wma_is_p2p_lo_capable())
Jeff Johnson16528362018-06-14 12:34:16 -070010586 sme_register_p2p_lo_event(mac_handle, hdd_ctx,
10587 wlan_hdd_p2p_lo_event_callback);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010588
10589 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
10590
10591 if (ret)
10592 goto deregister_cb;
10593
Dustin Brown11638b72018-01-25 17:37:25 +053010594 wlan_hdd_init_chan_info(hdd_ctx);
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010595 wlan_hdd_twt_init(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010596
Dustin Browne74003f2018-03-14 12:51:58 -070010597 hdd_exit();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010598 return 0;
10599
10600deregister_cb:
10601 hdd_deregister_cb(hdd_ctx);
Dustin Browne7e71d32018-05-11 16:00:08 -070010602
Arun Khandavallid4349a92016-07-25 11:10:43 +053010603 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010604}
10605
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010606/**
10607 * hdd_features_deinit() - Deinit features
10608 * @hdd_ctx: HDD context
10609 *
10610 * De-Initialize features and their feature context.
10611 *
10612 * Return: none.
10613 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010614static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010615{
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010616 wlan_hdd_twt_deinit(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010617 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010618 wlan_hdd_tsf_deinit(hdd_ctx);
10619}
10620
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010621/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010622 * hdd_register_bcn_cb() - register scan beacon callback
10623 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010624 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010625 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010626 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010627static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010628{
10629 QDF_STATUS status;
10630
Dustin Brown1dbefe62018-09-11 16:32:03 -070010631 status = ucfg_scan_register_bcn_cb(hdd_ctx->psoc,
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010632 wlan_cfg80211_inform_bss_frame,
10633 SCAN_CB_TYPE_INFORM_BCN);
10634 if (!QDF_IS_STATUS_SUCCESS(status)) {
10635 hdd_err("failed with status code %08d [x%08x]",
10636 status, status);
10637 return status;
10638 }
10639
10640 return QDF_STATUS_SUCCESS;
10641}
Arun Khandavallid4349a92016-07-25 11:10:43 +053010642
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010643/**
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070010644 * hdd_v2_flow_pool_map() - Flow pool create callback when vdev is active
10645 * @vdev_id: vdev_id, corresponds to flow_pool
10646 *
10647 * Return: none.
10648 */
10649static void hdd_v2_flow_pool_map(int vdev_id)
10650{
10651 QDF_STATUS status;
10652
10653 status = cdp_flow_pool_map(cds_get_context(QDF_MODULE_ID_SOC),
10654 cds_get_context(QDF_MODULE_ID_TXRX),
10655 vdev_id);
10656 /*
10657 * For Adrastea flow control v2 is based on FW MAP events,
10658 * so this above callback is not implemented.
10659 * Hence this is not actual failure. Dont return failure
10660 */
10661 if ((status != QDF_STATUS_SUCCESS) &&
10662 (status != QDF_STATUS_E_INVAL)) {
10663 hdd_err("vdev_id: %d, failed to create flow pool status %d",
10664 vdev_id, status);
10665 }
10666}
10667
10668/**
10669 * hdd_v2_flow_pool_unmap() - Flow pool create callback when vdev is not active
10670 * @vdev_id: vdev_id, corresponds to flow_pool
10671 *
10672 * Return: none.
10673 */
10674static void hdd_v2_flow_pool_unmap(int vdev_id)
10675{
10676 cdp_flow_pool_unmap(cds_get_context(QDF_MODULE_ID_SOC),
10677 cds_get_context(QDF_MODULE_ID_TXRX), vdev_id);
10678}
10679
10680/**
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010681 * hdd_action_oui_config() - Configure action_oui strings
10682 * @hdd_ctx: pointer to hdd context
10683 *
10684 * This is a HDD wrapper function which invokes ucfg api
10685 * of action_oui component to parse action oui strings.
10686 *
10687 * Return: None
10688 */
10689static void hdd_action_oui_config(struct hdd_context *hdd_ctx)
10690{
10691 QDF_STATUS status;
10692 uint32_t id;
10693 uint8_t *str;
10694
10695 if (!hdd_ctx->config->action_oui_enable)
10696 return;
10697
10698 for (id = 0; id < ACTION_OUI_MAXIMUM_ID; id++) {
10699 str = hdd_ctx->config->action_oui_str[id];
10700 if (!qdf_str_len(str))
10701 continue;
10702
Dustin Brown1dbefe62018-09-11 16:32:03 -070010703 status = ucfg_action_oui_parse(hdd_ctx->psoc, str, id);
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010704 if (!QDF_IS_STATUS_SUCCESS(status))
10705 hdd_err("Failed to parse action_oui str: %u", id);
10706 }
10707}
10708
10709/**
10710 * hdd_action_oui_send() - Send action_oui extensions to firmware
10711 * @hdd_ctx: pointer to hdd context
10712 *
10713 * This is a HDD wrapper function which invokes ucfg api
10714 * of action_oui component to send action oui extensions to firmware.
10715 *
10716 * Return: None
10717 */
10718static void hdd_action_oui_send(struct hdd_context *hdd_ctx)
10719{
10720 QDF_STATUS status;
10721
10722 if (!hdd_ctx->config->action_oui_enable)
10723 return;
10724
Dustin Brown1dbefe62018-09-11 16:32:03 -070010725 status = ucfg_action_oui_send(hdd_ctx->psoc);
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010726 if (!QDF_IS_STATUS_SUCCESS(status))
10727 hdd_err("Failed to send one or all action_ouis");
10728}
10729
10730/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010731 * hdd_configure_cds() - Configure cds modules
10732 * @hdd_ctx: HDD context
10733 * @adapter: Primary adapter context
10734 *
10735 * Enable Cds modules after WLAN firmware is up.
10736 *
10737 * Return: 0 on success and errno on failure.
10738 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010739int hdd_configure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010740{
10741 int ret;
10742 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010743 int set_value;
Jeff Johnson16528362018-06-14 12:34:16 -070010744 mac_handle_t mac_handle;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010745 bool enable_rts_sifsbursting;
10746 uint8_t enable_phy_reg_retention;
10747 uint8_t max_mpdus_inampdu;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010748 uint32_t num_abg_tx_chains = 0;
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010749 uint16_t num_11b_tx_chains = 0;
10750 uint16_t num_11ag_tx_chains = 0;
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010751 struct policy_mgr_dp_cbacks dp_cbs = {0};
Bala Venkatesh2fde2c62018-09-11 20:33:24 +053010752 bool value;
Wu Gao66454f12018-09-26 19:55:41 +080010753 enum pmo_auto_pwr_detect_failure_mode auto_power_fail_mode;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053010754 bool bval = false;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010755
Jeff Johnson16528362018-06-14 12:34:16 -070010756 mac_handle = hdd_ctx->mac_handle;
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010757
10758 hdd_action_oui_send(hdd_ctx);
10759
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010760 if (hdd_ctx->config->is_force_1x1)
10761 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
10762 1, PDEV_CMD);
10763 /* set chip power save failure detected callback */
Jeff Johnson16528362018-06-14 12:34:16 -070010764 sme_set_chip_pwr_save_fail_cb(mac_handle,
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010765 hdd_chip_pwr_save_fail_detected_cb);
10766
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010767 status = ucfg_get_max_mpdus_inampdu(hdd_ctx->psoc,
10768 &max_mpdus_inampdu);
10769 if (status)
10770 return status;
10771
10772 if (max_mpdus_inampdu) {
10773 set_value = max_mpdus_inampdu;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010774 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
10775 set_value, PDEV_CMD);
10776 }
10777
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010778 status = ucfg_get_enable_rts_sifsbursting(hdd_ctx->psoc,
10779 &enable_rts_sifsbursting);
10780 if (status)
10781 return status;
10782
10783 if (enable_rts_sifsbursting) {
10784 set_value = enable_rts_sifsbursting;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010785 sme_cli_set_command(0,
10786 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
10787 set_value, PDEV_CMD);
10788 }
10789
Dustin Brown05d81302018-09-11 16:49:22 -070010790 ucfg_mlme_get_sap_get_peer_info(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +053010791 if (value) {
10792 set_value = value;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010793 sme_cli_set_command(0,
10794 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
10795 set_value, PDEV_CMD);
10796 }
10797
Dustin Brown1dbefe62018-09-11 16:32:03 -070010798 status = ucfg_mlme_get_num_11b_tx_chains(hdd_ctx->psoc,
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010799 &num_11b_tx_chains);
10800 if (status != QDF_STATUS_SUCCESS) {
10801 hdd_err("Failed to get num_11b_tx_chains");
10802 goto out;
10803 }
10804
Dustin Brown1dbefe62018-09-11 16:32:03 -070010805 status = ucfg_mlme_get_num_11ag_tx_chains(hdd_ctx->psoc,
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010806 &num_11ag_tx_chains);
10807 if (status != QDF_STATUS_SUCCESS) {
10808 hdd_err("Failed to get num_11ag_tx_chains");
10809 goto out;
10810 }
10811
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053010812 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
10813 if (!QDF_IS_STATUS_SUCCESS(status))
10814 hdd_err("unable to get vht_enable2x2");
10815
10816 if (!bval) {
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010817 if (num_11b_tx_chains > 1)
10818 num_11b_tx_chains = 1;
10819 if (num_11ag_tx_chains > 1)
10820 num_11ag_tx_chains = 1;
10821 }
10822 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
10823 num_11b_tx_chains);
10824 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
10825 num_11ag_tx_chains);
10826 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
10827 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +053010828
Paul Zhang02526cd2018-09-20 17:47:46 +080010829 if (!ucfg_reg_is_regdb_offloaded(hdd_ctx->psoc))
10830 ucfg_reg_program_default_cc(hdd_ctx->pdev,
10831 hdd_ctx->reg.reg_domain);
10832
Arun Khandavallifae92942016-08-01 13:31:08 +053010833 ret = hdd_pre_enable_configure(hdd_ctx);
10834 if (ret) {
10835 hdd_err("Failed to pre-configure cds");
10836 goto out;
10837 }
10838
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010839 /* Always get latest IPA resources allocated from cds_open and configure
10840 * IPA module before configuring them to FW. Sequence required as crash
10841 * observed otherwise.
10842 */
Dustin Brown07901ec2018-09-07 11:02:41 -070010843 if (ucfg_ipa_uc_ol_init(hdd_ctx->pdev,
10844 cds_get_context(QDF_MODULE_ID_QDF_DEVICE))) {
Manikandan Mohan2e803a02017-02-14 14:57:53 -080010845 hdd_err("Failed to setup pipes");
10846 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010847 }
10848
Arun Khandavallifae92942016-08-01 13:31:08 +053010849 /*
10850 * Start CDS which starts up the SME/MAC/HAL modules and everything
10851 * else
10852 */
Dustin Brown1dbefe62018-09-11 16:32:03 -070010853 status = cds_enable(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010854
10855 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010856 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053010857 goto out;
10858 }
10859
10860 status = hdd_post_cds_enable_config(hdd_ctx);
10861 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010862 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010863 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010864 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010865 status = hdd_register_bcn_cb(hdd_ctx);
10866 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +080010867 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010868 goto cds_disable;
10869 }
Arun Khandavallifae92942016-08-01 13:31:08 +053010870
Dustin Browne7e71d32018-05-11 16:00:08 -070010871 ret = hdd_features_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010872 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010873 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010874
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010875 if (hdd_ctx->ol_enable)
10876 dp_cbs.hdd_disable_rx_ol_in_concurrency =
10877 hdd_disable_rx_ol_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -070010878 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
jiadbb47e132018-03-30 16:28:30 +080010879 dp_cbs.hdd_ipa_set_mcc_mode_cb = hdd_ipa_set_mcc_mode;
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070010880 dp_cbs.hdd_v2_flow_pool_map = hdd_v2_flow_pool_map;
10881 dp_cbs.hdd_v2_flow_pool_unmap = hdd_v2_flow_pool_unmap;
Dustin Brown1dbefe62018-09-11 16:32:03 -070010882 status = policy_mgr_register_dp_cb(hdd_ctx->psoc, &dp_cbs);
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010883 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -070010884 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010885 goto cds_disable;
10886 }
Dustin Brown1dbefe62018-09-11 16:32:03 -070010887 status = policy_mgr_register_mode_change_cb(hdd_ctx->psoc,
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010888 wlan_hdd_send_mode_change_event);
10889 if (!QDF_IS_STATUS_SUCCESS(status)) {
10890 hdd_debug("Failed to register mode change cb with Policy Manager");
10891 goto cds_disable;
10892 }
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010893
Jeff Johnson8bb61112018-03-31 13:33:54 -070010894 if (hdd_green_ap_enable_egap(hdd_ctx))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +053010895 hdd_debug("enhance green ap is not enabled");
10896
Nachiket Kukadedd302662017-07-13 17:31:44 +053010897 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
10898 hdd_debug("Failed to set wow pulse");
10899
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053010900 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
10901 hdd_ctx->config->gcmp_enabled, PDEV_CMD);
Wu Gao66454f12018-09-26 19:55:41 +080010902
10903 auto_power_fail_mode =
10904 ucfg_pmo_get_auto_power_fail_mode(hdd_ctx->psoc);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053010905 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
Wu Gao66454f12018-09-26 19:55:41 +080010906 auto_power_fail_mode, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053010907
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010908 status = ucfg_get_enable_phy_reg_retention(hdd_ctx->psoc,
10909 &enable_phy_reg_retention);
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053010910
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010911 if (QDF_IS_STATUS_ERROR(status))
10912 return -EINVAL;
10913
10914 if (enable_phy_reg_retention)
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053010915 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010916 enable_phy_reg_retention, PDEV_CMD);
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053010917
Arun Khandavallifae92942016-08-01 13:31:08 +053010918 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010919
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010920cds_disable:
Dustin Brown1dbefe62018-09-11 16:32:03 -070010921 cds_disable(hdd_ctx->psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010922
Arun Khandavallifae92942016-08-01 13:31:08 +053010923out:
10924 return -EINVAL;
10925}
10926
10927/**
10928 * hdd_deconfigure_cds() -De-Configure cds
10929 * @hdd_ctx: HDD context
10930 *
10931 * Deconfigure Cds modules before WLAN firmware is down.
10932 *
10933 * Return: 0 on success and errno on failure.
10934 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010935static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010936{
10937 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070010938 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053010939
Dustin Brown491d54b2018-03-14 12:39:11 -070010940 hdd_enter();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010941
10942 /* De-init features */
10943 hdd_features_deinit(hdd_ctx);
10944
Arun Khandavallifae92942016-08-01 13:31:08 +053010945 /* De-register the SME callbacks */
10946 hdd_deregister_cb(hdd_ctx);
10947
Dustin Brown1dbefe62018-09-11 16:32:03 -070010948 qdf_status = policy_mgr_deregister_mode_change_cb(hdd_ctx->psoc);
Srinivas Girigowdad2412882018-09-07 15:42:04 -070010949 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010950 hdd_debug("Failed to deregister mode change cb with Policy Manager");
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010951
Dustin Brown1dbefe62018-09-11 16:32:03 -070010952 qdf_status = cds_disable(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010953 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10954 hdd_err("Failed to Disable the CDS Modules! :%d",
10955 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070010956 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010957 }
10958
Dustin Brown07901ec2018-09-07 11:02:41 -070010959 if (ucfg_ipa_uc_ol_deinit(hdd_ctx->pdev) != QDF_STATUS_SUCCESS) {
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053010960 hdd_err("Failed to disconnect pipes");
10961 ret = -EINVAL;
10962 }
10963
Dustin Browne74003f2018-03-14 12:51:58 -070010964 hdd_exit();
Houston Hoffman6640cf32016-10-10 16:44:29 -070010965 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010966}
10967
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010968#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
10969static void hdd_deregister_policy_manager_callback(
10970 struct wlan_objmgr_psoc *psoc)
10971{
10972 if (QDF_STATUS_SUCCESS !=
10973 policy_mgr_deregister_hdd_cb(psoc)) {
10974 hdd_err("HDD callback deregister with policy manager failed");
10975 }
10976}
10977#else
10978static void hdd_deregister_policy_manager_callback(
10979 struct wlan_objmgr_psoc *psoc)
10980{
10981}
10982#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010983
10984/**
10985 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
10986 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010987 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +053010988 *
10989 * This function maintains the driver state machine it will be invoked from
10990 * exit, shutdown and con_mode change handler. Depending on the driver state
10991 * shall perform the stopping/closing of the modules.
10992 *
10993 * Return: 0 for success; non-zero for failure
10994 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010995int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053010996{
10997 void *hif_ctx;
10998 qdf_device_t qdf_ctx;
10999 QDF_STATUS qdf_status;
Dustin Brown4bc0a622017-12-06 15:56:50 -080011000 bool is_recovery_stop = cds_is_driver_recovering();
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053011001 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -070011002 int active_threads;
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053011003 int debugfs_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053011004 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053011005
Dustin Brown491d54b2018-03-14 12:39:11 -070011006 hdd_enter();
Arun Khandavallifae92942016-08-01 13:31:08 +053011007
Dustin Brown1dbefe62018-09-11 16:32:03 -070011008 hdd_deregister_policy_manager_callback(hdd_ctx->psoc);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070011009
Arun Khandavallifae92942016-08-01 13:31:08 +053011010 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11011 if (!qdf_ctx) {
11012 hdd_err("QDF device context NULL");
11013 return -EINVAL;
11014 }
11015
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011016 mutex_lock(&hdd_ctx->iface_change_lock);
11017 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011018 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011019
Dustin Brown70111822017-03-30 15:31:40 -070011020 active_threads = cds_return_external_threads_count();
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053011021 debugfs_threads = hdd_return_debugfs_threads_count();
Dustin Brown70111822017-03-30 15:31:40 -070011022
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053011023 if (active_threads > 0 || debugfs_threads > 0 ||
11024 hdd_ctx->is_wiphy_suspended) {
11025 hdd_warn("External threads %d, Debugfs threads %d, wiphy suspend %d",
11026 active_threads, debugfs_threads,
11027 hdd_ctx->is_wiphy_suspended);
11028
11029 if (active_threads)
11030 cds_print_external_threads();
Dustin Brown70111822017-03-30 15:31:40 -070011031
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053011032 if (IS_IDLE_STOP && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070011033 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -070011034 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
11035 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053011036 hdd_prevent_suspend_timeout(
11037 hdd_ctx->config->iface_change_wait_time,
11038 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011039 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011040 cds_set_module_stop_in_progress(false);
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011041
Dustin Brown70111822017-03-30 15:31:40 -070011042 return 0;
11043 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070011044 }
11045
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080011046 /* free user wowl patterns */
11047 hdd_free_user_wowl_ptrns();
11048
Arun Khandavallifae92942016-08-01 13:31:08 +053011049 switch (hdd_ctx->driver_status) {
11050 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011051 hdd_debug("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011052 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011053 case DRIVER_MODULES_CLOSED:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011054 hdd_debug("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011055 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011056 case DRIVER_MODULES_ENABLED:
Dustin Brown1a20b082018-08-03 17:27:15 -070011057 hdd_info("Wlan transitioning (CLOSED <- ENABLED)");
11058
11059 if (hdd_get_conparam() == QDF_GLOBAL_FTM_MODE)
11060 break;
Dustin Brown550f6d22017-12-14 15:44:01 -080011061
Komal Seelamf2136bb2016-09-28 18:30:44 +053011062 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053011063 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011064 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053011065 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011066 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011067 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011068 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080011069
Arun Khandavallifae92942016-08-01 13:31:08 +053011070 break;
11071 default:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011072 QDF_DEBUG_PANIC("Unknown driver state:%d",
Arun Khandavallifae92942016-08-01 13:31:08 +053011073 hdd_ctx->driver_status);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011074 ret = -EINVAL;
11075 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011076 }
11077
Amar Singhal18081642018-01-26 16:04:13 -080011078 hdd_sysfs_destroy_version_interface();
Dustin Brown550f6d22017-12-14 15:44:01 -080011079 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080011080
Rajeev Kumarbe021242017-02-16 16:12:23 -080011081 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053011082 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11083 hdd_err("Failed to process post CDS disable Modules! :%d",
11084 qdf_status);
11085 ret = -EINVAL;
11086 QDF_ASSERT(0);
11087 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011088
psimhadeea0a12017-12-18 14:50:02 -080011089 hdd_runtime_suspend_context_deinit(hdd_ctx);
11090
Dustin Brown1dbefe62018-09-11 16:32:03 -070011091 qdf_status = cds_dp_close(hdd_ctx->psoc);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011092 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11093 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
11094 ret = -EINVAL;
11095 QDF_ASSERT(0);
11096 }
11097
Dustin Brown1dbefe62018-09-11 16:32:03 -070011098 qdf_status = cds_close(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053011099 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011100 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053011101 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011102 QDF_ASSERT(0);
11103 }
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053011104
11105 qdf_status = wbuff_module_deinit();
11106 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
11107 hdd_err("WBUFF de-init unsuccessful; status: %d", qdf_status);
11108
Sandeep Puligillab7beb472018-08-13 22:54:20 -070011109 hdd_component_pdev_close(hdd_ctx->pdev);
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053011110
Dustin Brown1dbefe62018-09-11 16:32:03 -070011111 hdd_component_psoc_close(hdd_ctx->psoc);
Dustin Brown07901ec2018-09-07 11:02:41 -070011112 dispatcher_pdev_close(hdd_ctx->pdev);
Liangwei Dong50a64a72018-01-11 01:17:00 -050011113 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
11114 if (ret) {
11115 hdd_err("Failed to destroy pdev; errno:%d", ret);
11116 QDF_ASSERT(0);
11117 }
11118
11119 /*
11120 * Reset total mac phy during module stop such that during
11121 * next module start same psoc is used to populate new service
11122 * ready data
11123 */
Dustin Brown1dbefe62018-09-11 16:32:03 -070011124 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->psoc);
Arunk Khandavallia6305a32018-01-25 11:19:18 +053011125 if (tgt_hdl)
11126 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
11127
Liangwei Dong50a64a72018-01-11 01:17:00 -050011128
Arun Khandavallifae92942016-08-01 13:31:08 +053011129 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
11130 if (!hif_ctx) {
11131 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011132 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011133 }
11134
Arunk Khandavalli4b404332017-09-26 12:46:00 +053011135 if (hdd_ctx->target_hw_name) {
11136 qdf_mem_free(hdd_ctx->target_hw_name);
11137 hdd_ctx->target_hw_name = NULL;
11138 }
11139
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053011140 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053011141
11142 ol_cds_free();
11143
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053011144 if (IS_IDLE_STOP && cds_is_target_ready()) {
Arun Khandavallifae92942016-08-01 13:31:08 +053011145 ret = pld_power_off(qdf_ctx->dev);
11146 if (ret)
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011147 hdd_err("Failed to power down device; errno:%d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053011148 }
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011149
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011150 /* Free the cache channels of the command SET_DISABLE_CHANNEL_LIST */
11151 wlan_hdd_free_cache_channels(hdd_ctx);
Arunk Khandavalli847969d2017-09-25 15:15:36 +053011152
Dustin Brown29533f22018-07-24 13:11:56 -070011153 hdd_check_for_leaks(hdd_ctx, is_recovery_stop);
Dustin Brown26b3d042017-12-21 11:13:27 -080011154 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080011155
Arunk Khandavalli847969d2017-09-25 15:15:36 +053011156 /* Once the firmware sequence is completed reset this flag */
11157 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053011158 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080011159 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053011160
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011161done:
11162 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011163 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011164 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4bc0a622017-12-06 15:56:50 -080011165
Dustin Browne74003f2018-03-14 12:51:58 -070011166 hdd_exit();
Arun Khandavallifae92942016-08-01 13:31:08 +053011167
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011168 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053011169}
11170
Arun Khandavallifae92942016-08-01 13:31:08 +053011171
Wen Gong3f003382018-05-14 14:26:37 +080011172#ifdef WLAN_FEATURE_MEMDUMP_ENABLE
Arun Khandavallifae92942016-08-01 13:31:08 +053011173/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011174 * hdd_state_info_dump() - prints state information of hdd layer
11175 * @buf: buffer pointer
11176 * @size: size of buffer to be filled
11177 *
11178 * This function is used to dump state information of hdd layer
11179 *
11180 * Return: None
11181 */
11182static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
11183{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011184 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070011185 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070011186 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011187 uint16_t len = 0;
11188 char *buf = *buf_ptr;
11189
11190 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11191 if (!hdd_ctx) {
11192 hdd_err("Failed to get hdd context ");
11193 return;
11194 }
11195
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011196 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011197
11198 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070011199 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011200 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080011201 "\n is_scheduler_suspended %d",
11202 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011203
Dustin Brown920397d2017-12-13 16:27:50 -080011204 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011205 if (adapter->dev)
11206 len += scnprintf(buf + len, *size - len,
11207 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080011208 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011209 "\n device_mode: %d", adapter->device_mode);
11210 switch (adapter->device_mode) {
11211 case QDF_STA_MODE:
11212 case QDF_P2P_CLIENT_MODE:
11213 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11214 len += scnprintf(buf + len, *size - len,
11215 "\n connState: %d",
11216 hdd_sta_ctx->conn_info.connState);
11217 break;
11218
11219 default:
11220 break;
11221 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011222 }
11223
11224 *size -= len;
11225 *buf_ptr += len;
11226}
11227
11228/**
11229 * hdd_register_debug_callback() - registration function for hdd layer
11230 * to print hdd state information
11231 *
11232 * Return: None
11233 */
11234static void hdd_register_debug_callback(void)
11235{
11236 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
11237}
Wen Gong3f003382018-05-14 14:26:37 +080011238#else /* WLAN_FEATURE_MEMDUMP_ENABLE */
Wen Gongaa6d55d2018-04-26 16:33:21 +080011239static void hdd_register_debug_callback(void)
11240{
11241}
Wen Gong3f003382018-05-14 14:26:37 +080011242#endif /* WLAN_FEATURE_MEMDUMP_ENABLE */
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011243
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053011244/*
11245 * wlan_init_bug_report_lock() - Initialize bug report lock
11246 *
11247 * This function is used to create bug report lock
11248 *
11249 * Return: None
11250 */
11251static void wlan_init_bug_report_lock(void)
11252{
Jeff Johnson2b6982c2018-05-29 14:56:11 -070011253 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053011254
11255 p_cds_context = cds_get_global_context();
11256 if (!p_cds_context) {
11257 hdd_err("cds context is NULL");
11258 return;
11259 }
11260
11261 qdf_spinlock_create(&p_cds_context->bug_report_lock);
11262}
11263
Nirav Shahd21a2e32018-04-20 16:34:43 +053011264#ifdef CONFIG_DP_TRACE
Mohit Khannaf8f96822017-05-17 17:11:59 -070011265void hdd_dp_trace_init(struct hdd_config *config)
11266{
Mohit Khannaf8f96822017-05-17 17:11:59 -070011267 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
11268 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
11269 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
11270 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
11271 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
11272 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
11273 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080011274 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070011275
Nirav Shahd21a2e32018-04-20 16:34:43 +053011276 if (!config->enable_dp_trace) {
11277 hdd_err("dp trace is disabled from ini");
11278 return;
11279 }
11280
Mohit Khannaf8f96822017-05-17 17:11:59 -070011281 hdd_string_to_u8_array(config->dp_trace_config, config_params,
11282 &num_entries, sizeof(config_params));
11283
11284 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080011285 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080011286 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080011287 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080011288 else if (bw_compute_interval > 1000) {
11289 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
11290 thresh_time_limit = 1;
11291 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070011292 hdd_err("busBandwidthComputeInterval is 0, using defaults");
11293
11294 switch (num_entries) {
11295 case 4:
11296 proto_bitmap = config_params[3];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011297 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011298 case 3:
11299 verbosity = config_params[2];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011300 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011301 case 2:
11302 thresh = config_params[1];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011303 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011304 case 1:
11305 live_mode = config_params[0];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011306 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011307 default:
Dustin Browna7bb6ae2018-08-16 16:51:50 -070011308 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
11309 live_mode, thresh, thresh_time_limit,
11310 verbosity, proto_bitmap);
Mohit Khannaf8f96822017-05-17 17:11:59 -070011311 };
11312
11313 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
11314 verbosity, proto_bitmap);
11315
11316}
Nirav Shahd21a2e32018-04-20 16:34:43 +053011317#endif
11318
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011319#ifdef DISABLE_CHANNEL_LIST
11320static int wlan_hdd_cache_chann_mutex_create(struct hdd_context *hdd_ctx)
11321{
11322 return qdf_mutex_create(&hdd_ctx->cache_channel_lock);
11323}
11324#else
11325static int wlan_hdd_cache_chann_mutex_create(struct hdd_context *hdd_ctx)
11326{
11327 return 0;
11328}
11329#endif
11330
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011331/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011332 * hdd_wlan_startup() - HDD init function
11333 * @dev: Pointer to the underlying device
11334 *
11335 * This is the driver startup code executed once a WLAN device has been detected
11336 *
11337 * Return: 0 for success, < 0 for failure
11338 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011339int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011340{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011341 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011342 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011343 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080011344 bool rtnl_held;
Jeff Johnson16528362018-06-14 12:34:16 -070011345 mac_handle_t mac_handle;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011346
Dustin Brown491d54b2018-03-14 12:39:11 -070011347 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011348
Arun Khandavallifae92942016-08-01 13:31:08 +053011349 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011350
11351 if (IS_ERR(hdd_ctx))
11352 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011353
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011354 hdd_action_oui_config(hdd_ctx);
11355
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053011356 qdf_nbuf_init_replenish_timer();
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011357
11358 ret = wlan_hdd_cache_chann_mutex_create(hdd_ctx);
11359 if (QDF_IS_STATUS_ERROR(ret))
11360 goto err_hdd_free_context;
11361
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053011362#ifdef FEATURE_WLAN_CH_AVOID
11363 mutex_init(&hdd_ctx->avoid_freq_lock);
11364#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053011365
Naveen Rawate02f8f52018-04-05 11:58:04 -070011366 osif_request_manager_init();
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053011367 qdf_atomic_init(&hdd_ctx->con_mode_flag);
Dustin Brown021cecd2017-12-11 13:56:43 -080011368 hdd_driver_memdump_init();
Dustin Brown86d196b2018-08-02 11:51:49 -070011369 hdd_bus_bandwidth_init(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -080011370
Dustin Browne7e71d32018-05-11 16:00:08 -070011371 ret = hdd_wlan_start_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053011372 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011373 hdd_err("Failed to start modules: %d", ret);
Dustin Brown021cecd2017-12-11 13:56:43 -080011374 goto err_memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011375 }
11376
Yingying Tang80e15f32016-09-27 18:23:01 +080011377 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011378
Jeff Johnson16528362018-06-14 12:34:16 -070011379 mac_handle = cds_get_context(QDF_MODULE_ID_SME);
11380 hdd_ctx->mac_handle = mac_handle;
11381 if (!mac_handle) {
11382 hdd_err("Mac Handle is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053011383 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011384 }
11385
Prashanth Bhatta07998752016-04-28 12:35:33 -070011386 ret = hdd_wiphy_init(hdd_ctx);
11387 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011388 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053011389 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011390 }
11391
Nirav Shahd21a2e32018-04-20 16:34:43 +053011392 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053011393
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070011394 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080011395
Paul Zhangfb02f452017-12-22 11:58:43 +080011396 ret = register_netdevice_notifier(&hdd_netdev_notifier);
11397 if (ret) {
11398 hdd_err("register_netdevice_notifier failed: %d", ret);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053011399 goto err_wiphy_unregister;
Paul Zhangfb02f452017-12-22 11:58:43 +080011400 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053011401
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011402 ret = register_reboot_notifier(&system_reboot_notifier);
11403 if (ret) {
11404 hdd_err("Failed to register reboot notifier: %d", ret);
11405 goto err_unregister_netdev;
11406 }
11407
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080011408 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011409
Jeff Johnson957bc272017-02-02 08:54:48 -080011410 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11411 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011412 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080011413 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011414 }
11415
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080011416 hdd_release_rtnl_lock();
11417 rtnl_held = false;
11418
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080011419 wlan_hdd_update_11n_mode(hdd_ctx->config);
11420
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011421#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053011422 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053011423 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011424 hdd_skip_acs_scan_timer_handler,
11425 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011426 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070011427 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040011428 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011429#endif
11430
Arunk Khandavalli40943af2017-05-15 19:25:34 +053011431 hdd_lpass_notify_wlan_version(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011432
Nirav Shahbd36b062016-07-18 11:12:59 +053011433 if (hdd_ctx->rps)
11434 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070011435
Paul Zhangfb02f452017-12-22 11:58:43 +080011436 ret = hdd_register_notifiers(hdd_ctx);
11437 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -080011438 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070011439
Paul Zhangfb02f452017-12-22 11:58:43 +080011440 status = wlansap_global_init();
11441 if (QDF_IS_STATUS_ERROR(status)) {
11442 hdd_unregister_notifiers(hdd_ctx);
11443 goto err_close_adapters;
11444 }
11445
Arun Khandavallifae92942016-08-01 13:31:08 +053011446 if (hdd_ctx->config->fIsImpsEnabled)
11447 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070011448 else
11449 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011450
Mukul Sharma07bd8752017-10-10 16:58:14 +053011451 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070011452 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
11453 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053011454 hdd_prevent_suspend_timeout(
11455 hdd_ctx->config->iface_change_wait_time,
11456 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
11457 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053011458
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011459 goto success;
11460
Jeff Johnson957bc272017-02-02 08:54:48 -080011461err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080011462 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011463
Jeff Johnson46bde382017-02-01 15:31:16 -080011464err_release_rtnl_lock:
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011465 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavallid4349a92016-07-25 11:10:43 +053011466 if (rtnl_held)
11467 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011468
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011469err_unregister_netdev:
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011470 unregister_netdevice_notifier(&hdd_netdev_notifier);
11471
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011472err_wiphy_unregister:
Rachit Kankane30807332018-06-27 18:39:36 +053011473 qdf_dp_trace_deinit();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011474 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011475
Arun Khandavallifae92942016-08-01 13:31:08 +053011476err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011477 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053011478
Dustin Brown021cecd2017-12-11 13:56:43 -080011479err_memdump_deinit:
Dustin Brown86d196b2018-08-02 11:51:49 -070011480 hdd_bus_bandwidth_deinit(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -080011481 hdd_driver_memdump_deinit();
Dustin Brown021cecd2017-12-11 13:56:43 -080011482
Naveen Rawate02f8f52018-04-05 11:58:04 -070011483 osif_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070011484 hdd_exit_netlink_services(hdd_ctx);
11485
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011486err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053011487 if (cds_is_fw_down())
11488 hdd_err("Not setting the complete event as fw is down");
11489 else
11490 hdd_start_complete(ret);
11491
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053011492 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070011493 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070011494 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011495
11496success:
Dustin Browne74003f2018-03-14 12:51:58 -070011497 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011498 return 0;
11499}
11500
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011501/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011502 * hdd_wlan_update_target_info() - update target type info
11503 * @hdd_ctx: HDD context
11504 * @context: hif context
11505 *
11506 * Update target info received from firmware in hdd context
11507 * Return:None
11508 */
11509
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011510void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053011511{
11512 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
11513
11514 if (!tgt_info) {
11515 hdd_err("Target info is Null");
11516 return;
11517 }
11518
11519 hdd_ctx->target_type = tgt_info->target_type;
11520}
11521
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011522void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp, void *context)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011523{
11524 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011525 int status;
11526 struct hdd_adapter *adapter = NULL;
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011527 struct osif_request *request = NULL;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011528
Dustin Brown491d54b2018-03-14 12:39:11 -070011529 hdd_enter();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011530
11531 if (!rsp) {
11532 hdd_err("data is null");
11533 return;
11534 }
11535
11536 status = wlan_hdd_validate_context(hdd_ctx);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011537 if (status != 0)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011538 return;
11539
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011540 request = osif_request_get(context);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011541 if (!request) {
11542 hdd_err("obselete request");
11543 return;
11544 }
11545
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011546 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
11547 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
11548 hdd_err("Invalid adapter or adapter has invalid magic");
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011549 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011550 return;
11551 }
11552
Alok Kumarce2c29a2018-10-12 15:44:02 +053011553 hdd_debug("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
11554 hdd_debug("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
11555 hdd_debug("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
11556 hdd_debug("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
11557 hdd_debug("rsp->out_of_order_arp_rsp_drop_cnt :%x",
11558 rsp->out_of_order_arp_rsp_drop_cnt);
11559 hdd_debug("rsp->dad_detected :%x", rsp->dad_detected);
11560 hdd_debug("rsp->connect_status :%x", rsp->connect_status);
11561 hdd_debug("rsp->ba_session_establishment_status :%x",
11562 rsp->ba_session_establishment_status);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011563
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011564 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011565 adapter->dad |= rsp->dad_detected;
11566 adapter->con_status = rsp->connect_status;
11567
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053011568 /* Flag true indicates connectivity check stats present. */
11569 if (rsp->connect_stats_present) {
Alok Kumarce2c29a2018-10-12 15:44:02 +053011570 hdd_debug("rsp->tcp_ack_recvd :%x", rsp->tcp_ack_recvd);
11571 hdd_debug("rsp->icmpv4_rsp_recvd :%x", rsp->icmpv4_rsp_recvd);
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053011572 adapter->hdd_stats.hdd_tcp_stats.rx_fw_cnt = rsp->tcp_ack_recvd;
11573 adapter->hdd_stats.hdd_icmpv4_stats.rx_fw_cnt =
11574 rsp->icmpv4_rsp_recvd;
11575 }
11576
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011577 osif_request_complete(request);
11578 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011579
Dustin Browne74003f2018-03-14 12:51:58 -070011580 hdd_exit();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011581}
11582
11583/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011584 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011585 * @hdd_ctx: HDD context
11586 *
11587 * Register the HDD callbacks to CDS/SME.
11588 *
11589 * Return: 0 for success or Error code for failure
11590 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011591int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011592{
11593 QDF_STATUS status;
11594 int ret = 0;
Jeff Johnson16528362018-06-14 12:34:16 -070011595 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011596
Dustin Brown491d54b2018-03-14 12:39:11 -070011597 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011598
Jeff Johnson16528362018-06-14 12:34:16 -070011599 mac_handle = hdd_ctx->mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011600
Jeff Johnson16528362018-06-14 12:34:16 -070011601 sme_register_oem_data_rsp_callback(mac_handle,
11602 hdd_send_oem_data_rsp_msg);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011603
Jeff Johnson16528362018-06-14 12:34:16 -070011604 sme_register_mgmt_frame_ind_callback(mac_handle,
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053011605 hdd_indicate_mgmt_frame);
Jeff Johnson16528362018-06-14 12:34:16 -070011606 sme_set_tsfcb(mac_handle, hdd_get_tsf_cb, hdd_ctx);
11607 sme_nan_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011608 wlan_hdd_cfg80211_nan_callback);
Jeff Johnson16528362018-06-14 12:34:16 -070011609 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011610 wlan_hdd_cfg80211_stats_ext_callback);
11611
Jeff Johnson16528362018-06-14 12:34:16 -070011612 sme_ext_scan_register_callback(mac_handle,
11613 wlan_hdd_cfg80211_extscan_callback);
11614 sme_stats_ext2_register_callback(mac_handle,
lifeng66831662017-05-19 16:01:35 +080011615 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011616
Jeff Johnson16528362018-06-14 12:34:16 -070011617 sme_set_rssi_threshold_breached_cb(mac_handle,
11618 hdd_rssi_threshold_breached);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011619
Jeff Johnson16528362018-06-14 12:34:16 -070011620 sme_set_link_layer_stats_ind_cb(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011621 wlan_hdd_cfg80211_link_layer_stats_callback);
11622
Jeff Johnson16528362018-06-14 12:34:16 -070011623 sme_rso_cmd_status_cb(mac_handle, wlan_hdd_rso_cmd_status_cb);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053011624
Jeff Johnson16528362018-06-14 12:34:16 -070011625 sme_set_link_layer_ext_cb(mac_handle,
Zhang Qianca38fb12016-12-23 11:10:48 +080011626 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
11627
Jeff Johnson16528362018-06-14 12:34:16 -070011628 status = sme_set_lost_link_info_cb(mac_handle,
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053011629 hdd_lost_link_info_cb);
11630 /* print error and not block the startup process */
11631 if (!QDF_IS_STATUS_SUCCESS(status))
11632 hdd_err("set lost link info callback failed");
11633
Poddar, Siddarth34872782017-08-10 14:08:51 +053011634 ret = hdd_register_data_stall_detect_cb();
11635 if (ret) {
11636 hdd_err("Register data stall detect detect callback failed.");
11637 return ret;
11638 }
11639
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011640 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
11641
Jeff Johnson16528362018-06-14 12:34:16 -070011642 sme_register_set_connection_info_cb(mac_handle,
11643 hdd_set_connection_in_progress,
11644 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053011645
Jeff Johnson16528362018-06-14 12:34:16 -070011646 status = sme_congestion_register_callback(mac_handle,
11647 hdd_update_cca_info_cb);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053011648 if (!QDF_IS_STATUS_SUCCESS(status))
11649 hdd_err("set congestion callback failed");
11650
Jeff Johnson16528362018-06-14 12:34:16 -070011651 status = sme_set_bt_activity_info_cb(mac_handle,
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053011652 hdd_bt_activity_cb);
11653 if (!QDF_IS_STATUS_SUCCESS(status))
11654 hdd_err("set bt activity info callback failed");
11655
Jeff Johnson16528362018-06-14 12:34:16 -070011656 status = sme_register_tx_queue_cb(mac_handle,
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080011657 hdd_tx_queue_cb);
11658 if (!QDF_IS_STATUS_SUCCESS(status))
11659 hdd_err("Register tx queue callback failed");
11660
Dustin Browne74003f2018-03-14 12:51:58 -070011661 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011662
11663 return ret;
11664}
11665
11666/**
11667 * hdd_deregister_cb() - De-Register HDD callbacks.
11668 * @hdd_ctx: HDD context
11669 *
11670 * De-Register the HDD callbacks to CDS/SME.
11671 *
11672 * Return: void
11673 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011674void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011675{
11676 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053011677 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070011678 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011679
Dustin Brown491d54b2018-03-14 12:39:11 -070011680 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011681
Jeff Johnson16528362018-06-14 12:34:16 -070011682 mac_handle = hdd_ctx->mac_handle;
11683 sme_deregister_tx_queue_cb(mac_handle);
11684 status = sme_deregister_for_dcc_stats_event(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011685 if (!QDF_IS_STATUS_SUCCESS(status))
11686 hdd_err("De-register of dcc stats callback failed: %d",
11687 status);
11688
Jeff Johnson16528362018-06-14 12:34:16 -070011689 sme_reset_link_layer_stats_ind_cb(mac_handle);
11690 sme_reset_rssi_threshold_breached_cb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011691
Jeff Johnson16528362018-06-14 12:34:16 -070011692 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011693 wlan_hdd_cfg80211_stats_ext_callback);
11694
Jeff Johnson16528362018-06-14 12:34:16 -070011695 sme_nan_deregister_callback(mac_handle);
11696 status = sme_reset_tsfcb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011697 if (!QDF_IS_STATUS_SUCCESS(status))
11698 hdd_err("Failed to de-register tsfcb the callback:%d",
11699 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011700
Poddar, Siddarth34872782017-08-10 14:08:51 +053011701 ret = hdd_deregister_data_stall_detect_cb();
11702 if (ret)
11703 hdd_err("Failed to de-register data stall detect event callback");
11704
Jeff Johnson16528362018-06-14 12:34:16 -070011705 sme_deregister_oem_data_rsp_callback(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011706
Dustin Browne74003f2018-03-14 12:51:58 -070011707 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011708}
11709
11710/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011711 * hdd_softap_sta_deauth() - handle deauth req from HDD
11712 * @adapter: Pointer to the HDD
11713 * @enable: bool value
11714 *
11715 * This to take counter measure to handle deauth req from HDD
11716 *
11717 * Return: None
11718 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011719QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011720 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011721{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011722 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011723
Dustin Brown491d54b2018-03-14 12:39:11 -070011724 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011725
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011726 /* Ignore request to deauth bcmc station */
11727 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011728 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011729
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011730 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011731 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
11732 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011733
Dustin Browne74003f2018-03-14 12:51:58 -070011734 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011735 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011736}
11737
11738/**
11739 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
11740 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011741 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011742 *
11743 * This to take counter measure to handle deauth req from HDD
11744 *
11745 * Return: None
11746 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011747void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011748 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011749{
Dustin Brown491d54b2018-03-14 12:39:11 -070011750 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011751
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011752 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011753 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011754 return;
11755
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011756 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011757 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011758}
11759
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011760/**
11761 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
11762 * @hdd_ctx: HDD Context
11763 *
11764 * API to find if there is any STA or P2P-Client is connected
11765 *
11766 * Return: true if connected; false otherwise
11767 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011768QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011769{
Jeff Johnson16528362018-06-14 12:34:16 -070011770 return sme_is_sta_p2p_client_connected(hdd_ctx->mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011771}
11772
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011773void wlan_hdd_disable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011774{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011775 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
11776 struct hdd_adapter *adapter = NULL;
11777 struct csr_roam_profile *roam_profile;
11778 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011779
Dustin Brown1dbefe62018-09-11 16:32:03 -070011780 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->psoc)) {
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011781 hdd_debug("No active sta session");
11782 return;
11783 }
11784
11785 hdd_for_each_adapter(hdd_ctx, adapter) {
11786 roam_profile = hdd_roam_profile(adapter);
11787 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11788
11789 if (cur_adapter->session_id != adapter->session_id &&
11790 adapter->device_mode == QDF_STA_MODE &&
11791 hdd_conn_is_connected(sta_ctx)) {
11792 hdd_debug("%d Disable roaming", adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -070011793 sme_stop_roaming(hdd_ctx->mac_handle,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011794 adapter->session_id,
11795 ecsr_driver_disabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011796 }
11797 }
11798}
11799
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011800void wlan_hdd_enable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011801{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011802 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
11803 struct hdd_adapter *adapter = NULL;
11804 struct csr_roam_profile *roam_profile;
11805 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011806
Dustin Brown1dbefe62018-09-11 16:32:03 -070011807 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->psoc)) {
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011808 hdd_debug("No active sta session");
11809 return;
11810 }
11811
11812 hdd_for_each_adapter(hdd_ctx, adapter) {
11813 roam_profile = hdd_roam_profile(adapter);
11814 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11815
11816 if (cur_adapter->session_id != adapter->session_id &&
11817 adapter->device_mode == QDF_STA_MODE &&
11818 hdd_conn_is_connected(sta_ctx)) {
11819 hdd_debug("%d Enable roaming", adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -070011820 sme_start_roaming(hdd_ctx->mac_handle,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011821 adapter->session_id,
11822 REASON_DRIVER_ENABLED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011823 }
11824 }
11825}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011826
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011827/**
11828 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
11829 * @skb: sk buffer pointer
11830 *
11831 * Sends the bcast message to SVC multicast group with generic nl socket
11832 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
11833 *
11834 * Return: None
11835 */
11836static void nl_srv_bcast_svc(struct sk_buff *skb)
11837{
11838#ifdef CNSS_GENL
11839 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
11840#else
11841 nl_srv_bcast(skb);
11842#endif
11843}
11844
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011845void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011846{
11847 struct sk_buff *skb;
11848 struct nlmsghdr *nlh;
11849 tAniMsgHdr *ani_hdr;
11850 void *nl_data = NULL;
11851 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011852 struct radio_index_tlv *radio_info;
11853 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011854
11855 if (in_interrupt() || irqs_disabled() || in_atomic())
11856 flags = GFP_ATOMIC;
11857
11858 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
11859
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011860 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011861 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011862
11863 nlh = (struct nlmsghdr *)skb->data;
11864 nlh->nlmsg_pid = 0; /* from kernel */
11865 nlh->nlmsg_flags = 0;
11866 nlh->nlmsg_seq = 0;
11867 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
11868
11869 ani_hdr = NLMSG_DATA(nlh);
11870 ani_hdr->type = type;
11871
11872 switch (type) {
11873 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053011874 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011875 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011876 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011877 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011878 ani_hdr->length = 0;
11879 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011880 break;
11881 case WLAN_SVC_WLAN_STATUS_IND:
11882 case WLAN_SVC_WLAN_VERSION_IND:
11883 case WLAN_SVC_DFS_CAC_START_IND:
11884 case WLAN_SVC_DFS_CAC_END_IND:
11885 case WLAN_SVC_DFS_RADAR_DETECT_IND:
11886 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
11887 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080011888 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053011889 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080011890 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011891 ani_hdr->length = len;
11892 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
11893 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
11894 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011895 break;
11896
11897 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070011898 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011899 type);
11900 kfree_skb(skb);
11901 return;
11902 }
11903
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011904 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080011905 * Add radio index at the end of the svc event in TLV format
11906 * to maintain the backward compatibility with userspace
11907 * applications.
11908 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011909
11910 tlv_len = 0;
11911
11912 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
11913 < WLAN_NL_MAX_PAYLOAD) {
11914 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
11915 sizeof(*ani_hdr) + len);
11916 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
11917 radio_info->length = (unsigned short) sizeof(radio_info->radio);
11918 radio_info->radio = radio;
11919 tlv_len = sizeof(*radio_info);
Dustin Browna2868622018-03-20 11:38:14 -070011920 hdd_debug("Added radio index tlv - radio index %d",
11921 radio_info->radio);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011922 }
11923
11924 nlh->nlmsg_len += tlv_len;
11925 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
11926
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011927 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011928}
11929
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011930#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
11931void wlan_hdd_auto_shutdown_cb(void)
11932{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011933 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011934
11935 if (!hdd_ctx)
11936 return;
11937
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011938 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011939 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
11940 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011941}
11942
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011943void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011944{
Jeff Johnson9d295242017-08-29 14:39:48 -070011945 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011946 bool ap_connected = false, sta_connected = false;
Jeff Johnson16528362018-06-14 12:34:16 -070011947 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011948
Jeff Johnson16528362018-06-14 12:34:16 -070011949 mac_handle = hdd_ctx->mac_handle;
11950 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011951 return;
11952
Dundi Raviteja8e338282018-09-25 17:16:04 +053011953 if (hdd_ctx->config->wlan_auto_shutdown == 0)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011954 return;
11955
11956 if (enable == false) {
Jeff Johnson16528362018-06-14 12:34:16 -070011957 if (sme_set_auto_shutdown_timer(mac_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011958 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011959 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011960 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011961 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011962 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011963 return;
11964 }
11965
11966 /* To enable shutdown timer check conncurrency */
Dustin Brown1dbefe62018-09-11 16:32:03 -070011967 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->psoc)) {
Dustin Brown920397d2017-12-13 16:27:50 -080011968 hdd_for_each_adapter(hdd_ctx, adapter) {
11969 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011970 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11971 conn_info.connState ==
11972 eConnectionState_Associated) {
11973 sta_connected = true;
11974 break;
11975 }
11976 }
Dustin Brown920397d2017-12-13 16:27:50 -080011977
11978 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011979 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070011980 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011981 ap_connected = true;
11982 break;
11983 }
11984 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011985 }
11986 }
11987
11988 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011989 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011990 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011991 }
Jeff Johnson68755312017-02-10 11:46:55 -080011992
Jeff Johnson16528362018-06-14 12:34:16 -070011993 if (sme_set_auto_shutdown_timer(mac_handle,
Dundi Raviteja8e338282018-09-25 17:16:04 +053011994 hdd_ctx->config->wlan_auto_shutdown)
Jeff Johnson68755312017-02-10 11:46:55 -080011995 != QDF_STATUS_SUCCESS)
11996 hdd_err("Failed to start wlan auto shutdown timer");
11997 else
Dustin Brown5e89ef82018-03-14 11:50:23 -070011998 hdd_info("Auto Shutdown timer for %d seconds enabled",
Dundi Raviteja8e338282018-09-25 17:16:04 +053011999 hdd_ctx->config->wlan_auto_shutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012000}
12001#endif
12002
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070012003struct hdd_adapter *
12004hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
12005 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012006{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012007 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070012008 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012009
12010 con_sap_adapter = NULL;
12011
Dustin Brown920397d2017-12-13 16:27:50 -080012012 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012013 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
12014 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012015 adapter != this_sap_adapter) {
12016 if (check_start_bss) {
12017 if (test_bit(SOFTAP_BSS_STARTED,
12018 &adapter->event_flags)) {
12019 con_sap_adapter = adapter;
12020 break;
12021 }
12022 } else {
12023 con_sap_adapter = adapter;
12024 break;
12025 }
12026 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012027 }
12028
12029 return con_sap_adapter;
12030}
12031
12032#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070012033static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012034{
Dustin Brown5ec6b552017-03-31 12:11:40 -070012035 return adapter->device_mode == QDF_STA_MODE ||
12036 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012037}
12038
Jeff Johnson9d295242017-08-29 14:39:48 -070012039static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012040{
Dustin Brown5ec6b552017-03-31 12:11:40 -070012041 return adapter->device_mode == QDF_SAP_MODE ||
12042 adapter->device_mode == QDF_P2P_GO_MODE;
12043}
12044
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012045static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012046{
Dustin Brown920397d2017-12-13 16:27:50 -080012047 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070012048
Dustin Brown920397d2017-12-13 16:27:50 -080012049 hdd_for_each_adapter(hdd_ctx, adapter) {
12050 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070012051 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
12052 conn_info.connState == eConnectionState_Associated) {
12053 return true;
12054 }
12055
Dustin Brown920397d2017-12-13 16:27:50 -080012056 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070012057 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070012058 return true;
12059 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070012060 }
12061
12062 return false;
12063}
12064
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012065static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012066{
12067 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012068
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053012069 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012070 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053012071 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012072
Dustin Brown5ec6b552017-03-31 12:11:40 -070012073 return is_running;
12074}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012075
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012076static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012077{
12078 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
12079 hdd_ctx->bus_bw_timer_running = true;
12080 qdf_timer_start(&hdd_ctx->bus_bw_timer,
jitiphil869b9f72018-09-25 17:14:01 +053012081 hdd_ctx->config->bus_bw_compute_interval);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012082 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
12083}
12084
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012085void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012086{
Dustin Brown491d54b2018-03-14 12:39:11 -070012087 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012088
12089 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12090 hdd_debug("Bandwidth compute timer already started");
12091 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012092 }
12093
Dustin Brown5ec6b552017-03-31 12:11:40 -070012094 __hdd_bus_bw_compute_timer_start(hdd_ctx);
12095
Dustin Browne74003f2018-03-14 12:51:58 -070012096 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012097}
12098
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012099void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012100{
Dustin Brown491d54b2018-03-14 12:39:11 -070012101 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012102
12103 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12104 hdd_debug("Bandwidth compute timer already started");
12105 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070012106 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070012107
12108 if (hdd_any_adapter_is_assoc(hdd_ctx))
12109 __hdd_bus_bw_compute_timer_start(hdd_ctx);
12110
Dustin Browne74003f2018-03-14 12:51:58 -070012111 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012112}
12113
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012114static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012115{
Dustin Brown07901ec2018-09-07 11:02:41 -070012116 ucfg_ipa_set_perf_level(hdd_ctx->pdev, 0, 0);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012117
12118 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012119 hdd_ctx->bus_bw_timer_running = false;
Dustin Brown35008ba2018-08-23 14:34:21 -070012120 qdf_timer_sync_cancel(&hdd_ctx->bus_bw_timer);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012121 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
12122
Dustin Brown35008ba2018-08-23 14:34:21 -070012123 /* work callback is long running; flush outside of lock */
12124 cancel_work_sync(&hdd_ctx->bus_bw_work);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012125 hdd_reset_tcp_delack(hdd_ctx);
12126}
12127
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012128void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012129{
Dustin Brown491d54b2018-03-14 12:39:11 -070012130 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012131
12132 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12133 hdd_debug("Bandwidth compute timer already stopped");
12134 return;
12135 }
12136
12137 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
12138
Dustin Browne74003f2018-03-14 12:51:58 -070012139 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012140}
12141
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012142void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012143{
Dustin Brown491d54b2018-03-14 12:39:11 -070012144 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012145
12146 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12147 hdd_debug("Bandwidth compute timer already stopped");
12148 return;
12149 }
12150
12151 if (!hdd_any_adapter_is_assoc(hdd_ctx))
12152 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
12153
Dustin Browne74003f2018-03-14 12:51:58 -070012154 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012155}
12156#endif
12157
12158/**
12159 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
12160 * and sta's operating channel.
12161 * @sta_adapter: Describe the first argument to foobar.
12162 * @ap_adapter: Describe the second argument to foobar.
12163 * @roam_profile: Roam profile of AP to which STA wants to connect.
12164 * @concurrent_chnl_same: If both SAP and STA channels are same then
12165 * set this flag to true else false.
12166 *
12167 * This function checks the sap's operating channel and sta's operating channel.
12168 * if both are same then it will return false else it will restart the sap in
12169 * sta's channel and return true.
12170 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012171 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012172 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070012173QDF_STATUS
12174wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
12175 struct hdd_adapter *ap_adapter,
Jeff Johnson61b5e982018-03-15 11:33:31 -070012176 struct csr_roam_profile *roam_profile,
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070012177 tScanResultHandle *scan_cache,
12178 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012179{
Jeff Johnson87251032017-08-29 13:31:11 -070012180 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012181 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012182 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012183 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012184 *concurrent_chnl_same = true;
12185
12186 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12187 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070012188 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012189 scan_cache,
12190 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012191 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012192 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012193 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070012194 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012195 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012196 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012197 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012198 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012199 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070012200 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012201 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012202 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012203 }
12204 }
12205 } else {
12206 /*
12207 * Lets handle worst case scenario here, Scan cache lookup is
12208 * failed so we have to stop the SAP to avoid any channel
12209 * discrepancy between SAP's channel and STA's channel.
12210 * Return the status as failure so caller function could know
12211 * that scan look up is failed.
12212 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070012213 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012214 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012215 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012216 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012217}
12218
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012219/**
12220 * wlan_hdd_stop_sap() - This function stops bss of SAP.
12221 * @ap_adapter: SAP adapter
12222 *
12223 * This function will process the stopping of sap adapter.
12224 *
12225 * Return: None
12226 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012227void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012228{
Jeff Johnson87251032017-08-29 13:31:11 -070012229 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012230 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053012231 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012232 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012233
12234 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012235 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012236 return;
12237 }
12238
12239 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12240 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012241 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012242 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012243
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012244 mutex_lock(&hdd_ctx->sap_lock);
12245 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080012246 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012247 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012248 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053012249 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012250 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012251 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053012252 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080012253 qdf_stop_bss_event,
Vignesh Viswanathan865daaa2018-10-11 19:30:44 +053012254 SME_CMD_START_STOP_BSS_TIMEOUT);
Anurag Chouhance0dc992016-02-16 18:18:03 +053012255 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012256 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070012257 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012258 return;
12259 }
12260 }
12261 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -070012262 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012263 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012264 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012265 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012266 false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012267 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012268 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012269 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012270 }
12271 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012272}
12273
12274/**
12275 * wlan_hdd_start_sap() - this function starts bss of SAP.
12276 * @ap_adapter: SAP adapter
12277 *
12278 * This function will process the starting of sap adapter.
12279 *
12280 * Return: None
12281 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012282void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012283{
Jeff Johnson87251032017-08-29 13:31:11 -070012284 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012285 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053012286 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012287 struct hdd_context *hdd_ctx;
Jeff Johnsone4c11db2018-05-05 23:22:32 -070012288 tsap_config_t *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012289
12290 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012291 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012292 return;
12293 }
12294
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012295 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070012296 hdd_err("SoftAp role has not been enabled");
12297 return;
12298 }
12299
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012300 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
12301 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12302 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070012303 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012304
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012305 mutex_lock(&hdd_ctx->sap_lock);
12306 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
12307 goto end;
12308
12309 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012310 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012311 goto end;
12312 }
Dustin Brown07901ec2018-09-07 11:02:41 -070012313 wlan_reg_set_channel_params(hdd_ctx->pdev,
Abhinav Kumar6f694482018-09-04 16:07:39 +053012314 hdd_ap_ctx->sap_config.channel, 0,
12315 &hdd_ap_ctx->sap_config.ch_params);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012316
Wei Song2f76f642016-11-18 16:32:53 +080012317 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012318 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070012319 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012320 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012321 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012322 goto end;
12323
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012324 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053012325 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Vignesh Viswanathan865daaa2018-10-11 19:30:44 +053012326 SME_CMD_START_STOP_BSS_TIMEOUT);
Anurag Chouhance0dc992016-02-16 18:18:03 +053012327 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012328 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012329 goto end;
12330 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070012331 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012332 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012333 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012334 if (hostapd_state->bss_state == BSS_START) {
Dustin Brown1dbefe62018-09-11 16:32:03 -070012335 policy_mgr_incr_active_session(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012336 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012337 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012338 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012339 true);
12340 }
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053012341 mutex_unlock(&hdd_ctx->sap_lock);
12342
12343 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012344end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012345 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012346 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070012347 /* SAP context and beacon cleanup will happen during driver unload
12348 * in hdd_stop_adapter
12349 */
12350 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
12351
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012352}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012353
12354/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012355 * hdd_get_fw_version() - Get FW version
12356 * @hdd_ctx: pointer to HDD context.
12357 * @major_spid: FW version - major spid.
12358 * @minor_spid: FW version - minor spid
12359 * @ssid: FW version - ssid
12360 * @crmid: FW version - crmid
12361 *
12362 * This function is called to get the firmware build version stored
12363 * as part of the HDD context
12364 *
12365 * Return: None
12366 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012367void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012368 uint32_t *major_spid, uint32_t *minor_spid,
12369 uint32_t *siid, uint32_t *crmid)
12370{
12371 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
12372 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
12373 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
12374 *crmid = hdd_ctx->target_fw_version & 0x7fff;
12375}
12376
12377#ifdef QCA_CONFIG_SMP
12378/**
12379 * wlan_hdd_get_cpu() - get cpu_index
12380 *
12381 * Return: cpu_index
12382 */
12383int wlan_hdd_get_cpu(void)
12384{
12385 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012386
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012387 put_cpu();
12388 return cpu_index;
12389}
12390#endif
12391
12392/**
12393 * hdd_get_fwpath() - get framework path
12394 *
12395 * This function is used to get the string written by
12396 * userspace to start the wlan driver
12397 *
12398 * Return: string
12399 */
12400const char *hdd_get_fwpath(void)
12401{
12402 return fwpath.string;
12403}
12404
Dustin Brown94ce20f2018-09-04 13:11:38 -070012405static inline int hdd_state_query_cb(void)
12406{
12407 return !!wlan_hdd_validate_context(cds_get_context(QDF_MODULE_ID_HDD));
12408}
12409
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012410/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012411 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012412 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012413 * This function initilizes CDS global context with the help of cds_init. This
12414 * has to be the first function called after probe to get a valid global
12415 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012416 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012417 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012418 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012419int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012420{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012421 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012422 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012423
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012424 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080012425 if (QDF_IS_STATUS_ERROR(status)) {
12426 hdd_err("Failed to allocate CDS context");
12427 ret = -ENOMEM;
12428 goto err_out;
12429 }
Dustin Brown94ce20f2018-09-04 13:11:38 -070012430 qdf_register_module_state_query_callback(hdd_state_query_cb);
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053012431
12432 wlan_init_bug_report_lock();
12433
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012434#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12435 wlan_logging_sock_init_svc();
12436#endif
12437
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012438 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
12439 (void *)hdd_drv_ops_inactivity_handler, NULL,
12440 QDF_TIMER_TYPE_SW);
12441
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012442 hdd_trace_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053012443 hdd_register_debug_callback();
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012444 wlan_roam_debug_init();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012445
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012446err_out:
12447 return ret;
12448}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012449
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012450/**
12451 * hdd_deinit() - Deinitialize Driver
12452 *
12453 * This function frees CDS global context with the help of cds_deinit. This
12454 * has to be the last function call in remove callback to free the global
12455 * context.
12456 */
12457void hdd_deinit(void)
12458{
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012459 wlan_roam_debug_deinit();
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012460 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012461
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012462#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12463 wlan_logging_sock_deinit_svc();
12464#endif
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012465
12466 wlan_destroy_bug_report_lock();
12467 cds_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012468}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012469
Yue Ma6e7b1a02017-04-03 14:17:46 -070012470#ifdef QCA_WIFI_NAPIER_EMULATION
12471#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
12472#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012473#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070012474#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012475
Sachin Ahujadddd2632017-03-07 19:07:24 +053012476static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
12477 struct file *file)
12478{
12479 return 0;
12480}
12481
12482static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
12483 const char __user *user_buf,
12484 size_t count,
12485 loff_t *f_pos)
12486{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012487 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053012488 static const char wlan_off_str[] = "OFF";
12489 static const char wlan_on_str[] = "ON";
12490 int ret;
12491 unsigned long rc;
12492
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012493 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012494 pr_err("Failed to read buffer\n");
12495 return -EINVAL;
12496 }
12497
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012498 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012499 pr_debug("Wifi turning off from UI\n");
12500 goto exit;
12501 }
12502
Srinivas Girigowdad2412882018-09-07 15:42:04 -070012503 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) == 0)
Sachin Ahuja16904db2017-12-13 19:56:57 +053012504 pr_info("Wifi Turning On from UI\n");
Sachin Ahuja16904db2017-12-13 19:56:57 +053012505
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012506 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012507 pr_err("Invalid value received from framework");
12508 goto exit;
12509 }
12510
12511 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053012512 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053012513 rc = wait_for_completion_timeout(&wlan_start_comp,
12514 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
12515 if (!rc) {
Srinivas Girigowda09625b02018-09-10 15:28:09 -070012516 hdd_alert("Timed-out!!");
Sachin Ahujadddd2632017-03-07 19:07:24 +053012517 ret = -EINVAL;
Sachin Ahujadddd2632017-03-07 19:07:24 +053012518 return ret;
12519 }
12520
12521 hdd_start_complete(0);
12522 }
12523
12524exit:
12525 return count;
12526}
12527
12528
12529const struct file_operations wlan_hdd_state_fops = {
12530 .owner = THIS_MODULE,
12531 .open = wlan_hdd_state_ctrl_param_open,
12532 .write = wlan_hdd_state_ctrl_param_write,
12533};
12534
12535static int wlan_hdd_state_ctrl_param_create(void)
12536{
12537 unsigned int wlan_hdd_state_major = 0;
12538 int ret;
12539 struct device *dev;
12540
12541 device = MKDEV(wlan_hdd_state_major, 0);
12542
12543 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
12544 if (ret) {
12545 pr_err("Failed to register qcwlanstate");
12546 goto dev_alloc_err;
12547 }
12548 wlan_hdd_state_major = MAJOR(device);
12549
12550 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
12551 if (IS_ERR(class)) {
12552 pr_err("wlan_hdd_state class_create error");
12553 goto class_err;
12554 }
12555
12556 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
12557 if (IS_ERR(dev)) {
12558 pr_err("wlan_hdd_statedevice_create error");
12559 goto err_class_destroy;
12560 }
12561
12562 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
12563 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
12564 if (ret) {
12565 pr_err("Failed to add cdev error");
12566 goto cdev_add_err;
12567 }
12568
12569 pr_info("wlan_hdd_state %s major(%d) initialized",
12570 WLAN_MODULE_NAME, wlan_hdd_state_major);
12571
12572 return 0;
12573
12574cdev_add_err:
12575 device_destroy(class, device);
12576err_class_destroy:
12577 class_destroy(class);
12578class_err:
12579 unregister_chrdev_region(device, dev_num);
12580dev_alloc_err:
12581 return -ENODEV;
12582}
12583
12584static void wlan_hdd_state_ctrl_param_destroy(void)
12585{
12586 cdev_del(&wlan_hdd_state_cdev);
12587 device_destroy(class, device);
12588 class_destroy(class);
12589 unregister_chrdev_region(device, dev_num);
12590
12591 pr_info("Device node unregistered");
12592}
12593
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012594/**
Dustin Brownd585cb32018-09-12 17:12:23 -070012595 * hdd_component_init() - Initialize all components
Mukul Sharmad75a6672017-06-22 15:40:53 +053012596 *
Dustin Brownd585cb32018-09-12 17:12:23 -070012597 * Return: QDF_STATUS
Mukul Sharmad75a6672017-06-22 15:40:53 +053012598 */
Dustin Brownd585cb32018-09-12 17:12:23 -070012599static QDF_STATUS hdd_component_init(void)
Mukul Sharmad75a6672017-06-22 15:40:53 +053012600{
Dustin Brownd585cb32018-09-12 17:12:23 -070012601 QDF_STATUS status;
12602
12603 /* initialize converged components */
12604 status = dispatcher_init();
12605 if (QDF_IS_STATUS_ERROR(status))
12606 return status;
12607
12608 /* initialize non-converged components */
12609 status = ucfg_mlme_init();
12610 if (QDF_IS_STATUS_ERROR(status))
12611 goto dispatcher_deinit;
12612
12613 status = ucfg_fwol_init();
12614 if (QDF_IS_STATUS_ERROR(status))
12615 goto mlme_deinit;
12616
12617 status = disa_init();
12618 if (QDF_IS_STATUS_ERROR(status))
12619 goto fwol_deinit;
12620
12621 status = pmo_init();
12622 if (QDF_IS_STATUS_ERROR(status))
12623 goto disa_deinit;
12624
12625 status = ucfg_ocb_init();
12626 if (QDF_IS_STATUS_ERROR(status))
12627 goto pmo_deinit;
12628
12629 status = ipa_init();
12630 if (QDF_IS_STATUS_ERROR(status))
12631 goto ocb_deinit;
12632
12633 status = ucfg_action_oui_init();
12634 if (QDF_IS_STATUS_ERROR(status))
12635 goto ipa_deinit;
12636
12637 return QDF_STATUS_SUCCESS;
12638
12639ipa_deinit:
12640 ipa_deinit();
12641ocb_deinit:
12642 ucfg_ocb_deinit();
12643pmo_deinit:
12644 pmo_deinit();
12645disa_deinit:
12646 disa_deinit();
12647fwol_deinit:
12648 ucfg_fwol_deinit();
12649mlme_deinit:
12650 ucfg_mlme_deinit();
12651dispatcher_deinit:
12652 dispatcher_deinit();
12653
12654 return status;
Mukul Sharmad75a6672017-06-22 15:40:53 +053012655}
12656
12657/**
Dustin Brownd585cb32018-09-12 17:12:23 -070012658 * hdd_component_deinit() - Deinitialize all components
Mukul Sharmad75a6672017-06-22 15:40:53 +053012659 *
12660 * Return: None
12661 */
Dustin Brownd585cb32018-09-12 17:12:23 -070012662static void hdd_component_deinit(void)
Mukul Sharmad75a6672017-06-22 15:40:53 +053012663{
Dustin Brownd585cb32018-09-12 17:12:23 -070012664 /* deinitialize non-converged components */
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053012665 ucfg_action_oui_deinit();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053012666 ipa_deinit();
Zhang Qian47e22ce2018-01-04 15:38:38 +080012667 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053012668 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012669 disa_deinit();
Sourav Mohapatra113685f2018-08-29 14:21:55 +053012670 ucfg_fwol_deinit();
Vignesh Viswanathana0921c42018-09-04 19:03:35 +053012671 ucfg_mlme_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070012672
12673 /* deinitialize converged components */
12674 dispatcher_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012675}
12676
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053012677QDF_STATUS hdd_component_psoc_open(struct wlan_objmgr_psoc *psoc)
12678{
Sourav Mohapatra113685f2018-08-29 14:21:55 +053012679 QDF_STATUS status;
12680
12681 status = ucfg_mlme_psoc_open(psoc);
12682 if (QDF_IS_STATUS_ERROR(status))
12683 return status;
12684
12685 status = ucfg_fwol_psoc_open(psoc);
12686 if (QDF_IS_STATUS_ERROR(status))
Wu Gao66454f12018-09-26 19:55:41 +080012687 goto err_fwol;
12688
12689 status = ucfg_pmo_psoc_open(psoc);
12690 if (QDF_IS_STATUS_ERROR(status))
12691 goto err_pmo;
Sourav Mohapatra113685f2018-08-29 14:21:55 +053012692
Krunal Sonie9c12f52018-10-04 11:45:42 -070012693 status = ucfg_policy_mgr_psoc_open(psoc);
12694 if (QDF_IS_STATUS_ERROR(status))
12695 goto err_plcy_mgr;
12696
Sourav Mohapatra113685f2018-08-29 14:21:55 +053012697 return status;
12698
Krunal Sonie9c12f52018-10-04 11:45:42 -070012699err_plcy_mgr:
12700 ucfg_pmo_psoc_close(psoc);
Wu Gao66454f12018-09-26 19:55:41 +080012701err_pmo:
12702 ucfg_fwol_psoc_close(psoc);
12703err_fwol:
Sourav Mohapatra113685f2018-08-29 14:21:55 +053012704 ucfg_mlme_psoc_close(psoc);
Krunal Sonie9c12f52018-10-04 11:45:42 -070012705
Sourav Mohapatra113685f2018-08-29 14:21:55 +053012706 return status;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053012707}
12708
12709void hdd_component_psoc_close(struct wlan_objmgr_psoc *psoc)
12710{
Krunal Sonie9c12f52018-10-04 11:45:42 -070012711 ucfg_policy_mgr_psoc_close(psoc);
Wu Gao66454f12018-09-26 19:55:41 +080012712 ucfg_pmo_psoc_close(psoc);
Sourav Mohapatra113685f2018-08-29 14:21:55 +053012713 ucfg_fwol_psoc_close(psoc);
Vignesh Viswanathana0921c42018-09-04 19:03:35 +053012714 ucfg_mlme_psoc_close(psoc);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053012715}
12716
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012717void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
12718{
Zhang Qian47e22ce2018-01-04 15:38:38 +080012719 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012720 disa_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012721}
12722
12723void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
12724{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012725 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080012726 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053012727}
12728
Sandeep Puligillab7beb472018-08-13 22:54:20 -070012729QDF_STATUS hdd_component_pdev_open(struct wlan_objmgr_pdev *pdev)
12730{
12731 return ucfg_mlme_pdev_open(pdev);
12732}
12733
12734void hdd_component_pdev_close(struct wlan_objmgr_pdev *pdev)
12735{
12736 ucfg_mlme_pdev_close(pdev);
12737}
12738
Dustin Browna2a39dc2018-09-17 15:29:59 -070012739static QDF_STATUS hdd_qdf_print_init(void)
12740{
12741 QDF_STATUS status;
12742 int qdf_print_idx;
12743
12744 status = qdf_print_setup();
12745 if (QDF_IS_STATUS_ERROR(status)) {
12746 pr_err("Failed qdf_print_setup; status:%u\n", status);
12747 return status;
12748 }
12749
12750 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
12751 if (qdf_print_idx < 0) {
12752 pr_err("Failed to register for qdf_print_ctrl\n");
12753 return QDF_STATUS_E_FAILURE;
12754 }
12755
12756 qdf_set_pidx(qdf_print_idx);
12757
12758 return QDF_STATUS_SUCCESS;
12759}
12760
12761static void hdd_qdf_print_deinit(void)
12762{
12763 int qdf_pidx = qdf_get_pidx();
12764
12765 qdf_set_pidx(-1);
12766 qdf_print_ctrl_cleanup(qdf_pidx);
12767
12768 /* currently, no qdf print 'un-setup'*/
12769}
12770
12771static QDF_STATUS hdd_qdf_init(void)
12772{
12773 QDF_STATUS status;
12774
12775 status = hdd_qdf_print_init();
12776 if (QDF_IS_STATUS_ERROR(status))
12777 goto exit;
12778
12779 status = qdf_debugfs_init();
12780 if (QDF_IS_STATUS_ERROR(status)) {
12781 hdd_err("Failed to init debugfs; status:%u", status);
12782 goto print_deinit;
12783 }
12784
12785 qdf_lock_stats_init();
12786 qdf_mem_init();
12787 qdf_mc_timer_manager_init();
12788 qdf_event_list_init();
12789
12790 status = qdf_cpuhp_init();
12791 if (QDF_IS_STATUS_ERROR(status)) {
12792 hdd_err("Failed to init cpuhp; status:%u", status);
12793 goto event_deinit;
12794 }
12795
12796 status = qdf_trace_spin_lock_init();
12797 if (QDF_IS_STATUS_ERROR(status)) {
12798 hdd_err("Failed to init spinlock; status:%u", status);
12799 goto cpuhp_deinit;
12800 }
12801
12802 qdf_trace_init();
12803 qdf_register_debugcb_init();
12804
12805 return QDF_STATUS_SUCCESS;
12806
12807cpuhp_deinit:
12808 qdf_cpuhp_deinit();
12809event_deinit:
12810 qdf_event_list_destroy();
12811 qdf_mc_timer_manager_exit();
12812 qdf_mem_exit();
12813 qdf_lock_stats_deinit();
12814 qdf_debugfs_exit();
12815print_deinit:
12816 hdd_qdf_print_deinit();
12817
12818exit:
12819 return status;
12820}
12821
12822static void hdd_qdf_deinit(void)
12823{
12824 /* currently, no debugcb deinit */
12825
12826 qdf_trace_deinit();
12827
12828 /* currently, no trace spinlock deinit */
12829
12830 qdf_cpuhp_deinit();
12831 qdf_event_list_destroy();
12832 qdf_mc_timer_manager_exit();
12833 qdf_mem_exit();
12834 qdf_lock_stats_deinit();
12835 qdf_debugfs_exit();
12836 hdd_qdf_print_deinit();
12837}
Dustin Brownf0f70562018-09-14 10:29:38 -070012838
12839/**
12840 * hdd_driver_load() - Perform the driver-level load operation
12841 *
12842 * Note: this is used in both static and DLKM driver builds
12843 *
12844 * Return: Errno
12845 */
12846static int hdd_driver_load(void)
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012847{
Dustin Brownd585cb32018-09-12 17:12:23 -070012848 QDF_STATUS status;
Dustin Brownf0f70562018-09-14 10:29:38 -070012849 int errno;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012850
Rajeev Kumare555e2d2018-09-17 11:52:37 -070012851 pr_err("%s: Loading driver v%s\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070012852 WLAN_MODULE_NAME,
Rajeev Kumare555e2d2018-09-17 11:52:37 -070012853 g_wlan_driver_version);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012854
Dustin Browna2a39dc2018-09-17 15:29:59 -070012855 status = hdd_qdf_init();
12856 if (QDF_IS_STATUS_ERROR(status)) {
12857 errno = qdf_status_to_os_return(status);
12858 goto exit;
12859 }
12860
Dustin Brownf0f70562018-09-14 10:29:38 -070012861 errno = hdd_init();
12862 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070012863 hdd_err("Failed to init HDD; errno:%d", errno);
12864 goto qdf_deinit;
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012865 }
12866
Dustin Brownd585cb32018-09-12 17:12:23 -070012867 status = hdd_component_init();
12868 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070012869 hdd_err("Failed to init components; status:%u", status);
Dustin Brownf0f70562018-09-14 10:29:38 -070012870 errno = qdf_status_to_os_return(status);
Dustin Brownd585cb32018-09-12 17:12:23 -070012871 goto hdd_deinit;
12872 }
Mukul Sharmad75a6672017-06-22 15:40:53 +053012873
Dustin Brownf0f70562018-09-14 10:29:38 -070012874 status = qdf_wake_lock_create(&wlan_wake_lock, "wlan");
12875 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070012876 hdd_err("Failed to create wake lock; status:%u", status);
Dustin Brownf0f70562018-09-14 10:29:38 -070012877 errno = qdf_status_to_os_return(status);
12878 goto comp_deinit;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012879 }
12880
Dustin Brownf0f70562018-09-14 10:29:38 -070012881 hdd_set_conparam(con_mode);
12882
Dustin Brownf0f70562018-09-14 10:29:38 -070012883 errno = wlan_hdd_state_ctrl_param_create();
12884 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070012885 hdd_err("Failed to create ctrl param; errno:%d", errno);
Dustin Brown4b9dbe62018-09-14 15:41:11 -070012886 goto wakelock_destroy;
12887 }
12888
Dustin Brown25843ad2018-09-17 14:54:33 -070012889 errno = pld_init();
12890 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070012891 hdd_err("Failed to init PLD; errno:%d", errno);
Dustin Brown25843ad2018-09-17 14:54:33 -070012892 goto param_destroy;
12893 }
12894
Dustin Brown4b9dbe62018-09-14 15:41:11 -070012895 errno = wlan_hdd_register_driver();
12896 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070012897 hdd_err("Failed to register driver; errno:%d", errno);
Dustin Brown25843ad2018-09-17 14:54:33 -070012898 goto pld_deinit;
Sachin Ahuja16904db2017-12-13 19:56:57 +053012899 }
12900
Dustin Browna2a39dc2018-09-17 15:29:59 -070012901 hdd_debug("%s: driver loaded", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012902
12903 return 0;
Dustin Brownd585cb32018-09-12 17:12:23 -070012904
Dustin Brown25843ad2018-09-17 14:54:33 -070012905pld_deinit:
12906 pld_deinit();
Dustin Brown4b9dbe62018-09-14 15:41:11 -070012907param_destroy:
12908 wlan_hdd_state_ctrl_param_destroy();
Dustin Brownf0f70562018-09-14 10:29:38 -070012909wakelock_destroy:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012910 qdf_wake_lock_destroy(&wlan_wake_lock);
Dustin Brownf0f70562018-09-14 10:29:38 -070012911comp_deinit:
Dustin Brownd585cb32018-09-12 17:12:23 -070012912 hdd_component_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070012913hdd_deinit:
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012914 hdd_deinit();
Dustin Browna2a39dc2018-09-17 15:29:59 -070012915qdf_deinit:
12916 hdd_qdf_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070012917
Dustin Brown25843ad2018-09-17 14:54:33 -070012918exit:
Dustin Brownf0f70562018-09-14 10:29:38 -070012919 return errno;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012920}
12921
12922/**
Dustin Brownf0f70562018-09-14 10:29:38 -070012923 * hdd_driver_unload() - Performs the driver-level unload operation
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012924 *
Dustin Brownf0f70562018-09-14 10:29:38 -070012925 * Note: this is used in both static and DLKM driver builds
12926 *
12927 * Return: None
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012928 */
Dustin Brownf0f70562018-09-14 10:29:38 -070012929static void hdd_driver_unload(void)
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012930{
Will Huang36049722018-04-13 11:48:51 +080012931 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053012932
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012933 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
12934 QWLAN_VERSIONSTR);
12935
Arunk Khandavalli830c9692018-03-22 12:17:40 +053012936 if (!hdd_wait_for_recovery_completion())
12937 return;
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053012938
Will Huangba035ec2018-07-05 11:13:30 +080012939 cds_set_driver_loaded(false);
12940 cds_set_unload_in_progress(true);
12941
12942 if (!cds_wait_for_external_threads_completion(__func__))
12943 hdd_warn("External threads are still active attempting "
12944 "driver unload anyway");
12945
Rajeev Kumar3505ae52018-05-10 18:44:45 -070012946 if (hdd_ctx)
12947 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Will Huang36049722018-04-13 11:48:51 +080012948
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012949 wlan_hdd_unregister_driver();
Dustin Brown25843ad2018-09-17 14:54:33 -070012950 pld_deinit();
Dustin Brown4b9dbe62018-09-14 15:41:11 -070012951 wlan_hdd_state_ctrl_param_destroy();
Dustin Brownf0f70562018-09-14 10:29:38 -070012952 hdd_set_conparam(0);
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012953 qdf_wake_lock_destroy(&wlan_wake_lock);
Dustin Brownd585cb32018-09-12 17:12:23 -070012954 hdd_component_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012955 hdd_deinit();
Dustin Browna2a39dc2018-09-17 15:29:59 -070012956 hdd_qdf_deinit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012957}
12958
Arun Khandavallifae92942016-08-01 13:31:08 +053012959#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012960/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012961 * wlan_boot_cb() - Wlan boot callback
12962 * @kobj: object whose directory we're creating the link in.
12963 * @attr: attribute the user is interacting with
12964 * @buff: the buffer containing the user data
12965 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012966 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012967 * This callback is invoked when the fs is ready to start the
12968 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012969 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012970 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012971 */
Arun Khandavallifae92942016-08-01 13:31:08 +053012972static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012973 struct kobj_attribute *attr,
12974 const char *buf,
12975 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012976{
Arun Khandavallifae92942016-08-01 13:31:08 +053012977
Arun Khandavallifae92942016-08-01 13:31:08 +053012978 if (wlan_loader->loaded_state) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070012979 hdd_err("wlan driver already initialized");
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012980 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053012981 }
12982
Dustin Brownf0f70562018-09-14 10:29:38 -070012983 if (hdd_driver_load())
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012984 return -EIO;
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012985
12986 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053012987
12988 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012989}
Arun Khandavallifae92942016-08-01 13:31:08 +053012990
12991/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012992 * hdd_sysfs_cleanup() - cleanup sysfs
12993 *
12994 * Return: None
12995 *
12996 */
12997static void hdd_sysfs_cleanup(void)
12998{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012999 /* remove from group */
13000 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
13001 sysfs_remove_group(wlan_loader->boot_wlan_obj,
13002 wlan_loader->attr_group);
13003
13004 /* unlink the object from parent */
13005 kobject_del(wlan_loader->boot_wlan_obj);
13006
13007 /* free the object */
13008 kobject_put(wlan_loader->boot_wlan_obj);
13009
13010 kfree(wlan_loader->attr_group);
13011 kfree(wlan_loader);
13012
13013 wlan_loader = NULL;
13014}
13015
13016/**
Arun Khandavallifae92942016-08-01 13:31:08 +053013017 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
13018 * ready
13019 *
13020 * This is creates the syfs entry boot_wlan. Which shall be invoked
13021 * when the filesystem is ready.
13022 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013023 * QDF API cannot be used here since this function is called even before
13024 * initializing WLAN driver.
13025 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070013026 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053013027 */
13028static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013029{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013030 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053013031
13032 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013033 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013034 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053013035
13036 wlan_loader->boot_wlan_obj = NULL;
13037 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
13038 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013039 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053013040 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053013041
13042 wlan_loader->loaded_state = 0;
13043 wlan_loader->attr_group->attrs = attrs;
13044
Qun Zhang4a83a462018-09-11 16:28:51 +080013045 wlan_loader->boot_wlan_obj = kobject_create_and_add(WLAN_LOADER_NAME,
Arun Khandavallifae92942016-08-01 13:31:08 +053013046 kernel_kobj);
13047 if (!wlan_loader->boot_wlan_obj) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013048 hdd_err("sysfs create and add failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053013049 goto error_return;
13050 }
13051
13052 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
13053 wlan_loader->attr_group);
13054 if (ret) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013055 hdd_err("sysfs create group failed; errno:%d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053013056 goto error_return;
13057 }
13058
13059 return 0;
13060
13061error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013062 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053013063
13064 return ret;
13065}
13066
13067/**
13068 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
13069 *
13070 * Return: 0 on success or errno on failure
13071 */
13072static int wlan_deinit_sysfs(void)
13073{
Arun Khandavallifae92942016-08-01 13:31:08 +053013074 if (!wlan_loader) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013075 hdd_err("wlan_loader is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053013076 return -EINVAL;
13077 }
13078
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013079 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013080 return 0;
13081}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013082
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013083#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053013084
13085#ifdef MODULE
13086/**
Dustin Brownf0f70562018-09-14 10:29:38 -070013087 * hdd_module_init() - Module init helper
Arun Khandavallifae92942016-08-01 13:31:08 +053013088 *
13089 * Module init helper function used by both module and static driver.
13090 *
13091 * Return: 0 for success, errno on failure
13092 */
13093static int hdd_module_init(void)
13094{
Dustin Brownf0f70562018-09-14 10:29:38 -070013095 if (hdd_driver_load())
Dustin Brownab482ac2017-06-09 17:00:44 -070013096 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053013097
Dustin Brownab482ac2017-06-09 17:00:44 -070013098 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053013099}
13100#else
13101static int __init hdd_module_init(void)
13102{
13103 int ret = -EINVAL;
13104
13105 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070013106 if (ret)
Dustin Browna2a39dc2018-09-17 15:29:59 -070013107 hdd_err("Failed to create sysfs entry");
Arun Khandavallifae92942016-08-01 13:31:08 +053013108
13109 return ret;
13110}
13111#endif
13112
13113
13114#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013115/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013116 * hdd_module_exit() - Exit function
13117 *
13118 * This is the driver exit point (invoked when module is unloaded using rmmod)
13119 *
13120 * Return: None
13121 */
13122static void __exit hdd_module_exit(void)
13123{
Dustin Brownf0f70562018-09-14 10:29:38 -070013124 hdd_driver_unload();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013125}
Arun Khandavallifae92942016-08-01 13:31:08 +053013126#else
13127static void __exit hdd_module_exit(void)
13128{
Dustin Brownf0f70562018-09-14 10:29:38 -070013129 hdd_driver_unload();
Arun Khandavallifae92942016-08-01 13:31:08 +053013130 wlan_deinit_sysfs();
13131}
13132#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013133
Srinivas Girigowda841da292018-02-21 16:33:00 -080013134static int fwpath_changed_handler(const char *kmessage,
13135 const struct kernel_param *kp)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013136{
13137 return param_set_copystring(kmessage, kp);
13138}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013139
Nirav Shah73713f72018-05-17 14:50:41 +053013140#ifdef FEATURE_MONITOR_MODE_SUPPORT
13141static bool is_monitor_mode_supported(void)
13142{
13143 return true;
13144}
13145#else
13146static bool is_monitor_mode_supported(void)
13147{
13148 pr_err("Monitor mode not supported!");
13149 return false;
13150}
13151#endif
13152
13153#ifdef WLAN_FEATURE_EPPING
13154static bool is_epping_mode_supported(void)
13155{
13156 return true;
13157}
13158#else
13159static bool is_epping_mode_supported(void)
13160{
13161 pr_err("Epping mode not supported!");
13162 return false;
13163}
13164#endif
13165
Ryan Hsu6e9db0b2018-06-01 10:45:51 -070013166#ifdef QCA_WIFI_FTM
13167static bool is_ftm_mode_supported(void)
13168{
13169 return true;
13170}
13171#else
13172static bool is_ftm_mode_supported(void)
13173{
13174 pr_err("FTM mode not supported!");
13175 return false;
13176}
13177#endif
13178
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013179/**
13180 * is_con_mode_valid() check con mode is valid or not
13181 * @mode: global con mode
13182 *
13183 * Return: TRUE on success FALSE on failure
13184 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080013185static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013186{
13187 switch (mode) {
13188 case QDF_GLOBAL_MONITOR_MODE:
Nirav Shah73713f72018-05-17 14:50:41 +053013189 return is_monitor_mode_supported();
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013190 case QDF_GLOBAL_EPPING_MODE:
Nirav Shah73713f72018-05-17 14:50:41 +053013191 return is_epping_mode_supported();
13192 case QDF_GLOBAL_FTM_MODE:
Ryan Hsu6e9db0b2018-06-01 10:45:51 -070013193 return is_ftm_mode_supported();
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013194 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013195 return true;
13196 default:
13197 return false;
13198 }
13199}
13200
13201/**
13202 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
13203 * @mode: global con mode
13204 *
13205 * Return: adapter mode
13206 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080013207static enum QDF_OPMODE hdd_get_adpter_mode(
Jeff Johnson876c1a62017-12-12 10:43:07 -080013208 enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013209{
13210
13211 switch (mode) {
13212 case QDF_GLOBAL_MISSION_MODE:
13213 return QDF_STA_MODE;
13214 case QDF_GLOBAL_MONITOR_MODE:
13215 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013216 case QDF_GLOBAL_EPPING_MODE:
13217 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013218 case QDF_GLOBAL_FTM_MODE:
13219 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013220 case QDF_GLOBAL_QVIT_MODE:
13221 return QDF_QVIT_MODE;
13222 default:
13223 return QDF_MAX_NO_OF_MODE;
13224 }
13225}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013226
Dustin Brown27cd9942017-09-27 16:11:44 -070013227static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080013228 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070013229{
13230 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
13231 return;
13232
13233 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070013234 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053013235 hdd_info("Release wakelock for monitor mode!");
13236 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
13237 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
Dundi Raviteja0a2a65b2018-04-30 12:34:11 +053013238 /* fallthrough */
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053013239 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070013240 case QDF_GLOBAL_FTM_MODE:
13241 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brown07901ec2018-09-07 11:02:41 -070013242 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, NULL);
Dustin Browndb2a8be2017-12-20 11:49:56 -080013243 hdd_stop_all_adapters(hdd_ctx);
Ashish Kumar Dhanotiya6ff329e2018-10-05 20:38:10 +053013244 hdd_deinit_all_adapters(hdd_ctx, false);
Dustin Brown27cd9942017-09-27 16:11:44 -070013245
Dustin Brown27cd9942017-09-27 16:11:44 -070013246 break;
13247 default:
13248 break;
13249 }
13250}
13251
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013252static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080013253 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013254{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053013255 int driver_status;
13256
13257 driver_status = hdd_ctx->driver_status;
13258
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013259 switch (curr_mode) {
13260 case QDF_GLOBAL_MISSION_MODE:
13261 case QDF_GLOBAL_MONITOR_MODE:
13262 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013263 hdd_close_all_adapters(hdd_ctx, false);
13264 break;
13265 case QDF_GLOBAL_EPPING_MODE:
13266 epping_disable();
13267 epping_close();
13268 break;
13269 default:
13270 return;
13271 }
13272}
13273
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013274static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080013275 enum QDF_GLOBAL_MODE mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013276{
Jeff Johnson9d295242017-08-29 14:39:48 -070013277 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013278 int ret = 0;
13279 bool rtnl_held;
13280 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
13281 QDF_STATUS status;
13282
13283 if (!qdf_dev) {
13284 hdd_err("qdf device context is Null return!");
13285 return -EINVAL;
13286 }
13287
13288 rtnl_held = hdd_hold_rtnl_lock();
13289 switch (mode) {
13290 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080013291 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
13292 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013293 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013294 break;
13295 case QDF_GLOBAL_FTM_MODE:
13296 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
13297 wlan_hdd_get_intf_addr(hdd_ctx),
13298 NET_NAME_UNKNOWN, rtnl_held);
13299 if (adapter == NULL)
13300 ret = -EINVAL;
13301 break;
13302 case QDF_GLOBAL_MONITOR_MODE:
13303 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
13304 wlan_hdd_get_intf_addr(hdd_ctx),
13305 NET_NAME_UNKNOWN, rtnl_held);
13306 if (adapter == NULL)
13307 ret = -EINVAL;
13308 break;
13309 case QDF_GLOBAL_EPPING_MODE:
13310 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013311 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013312 hdd_err("Failed to open in eeping mode: %d", status);
13313 ret = -EINVAL;
13314 break;
13315 }
13316 ret = epping_enable(qdf_dev->dev);
13317 if (ret) {
13318 hdd_err("Failed to enable in epping mode : %d", ret);
13319 epping_close();
13320 }
13321 break;
13322 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013323 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013324 ret = -ENOTSUPP;
13325 break;
13326 }
13327 hdd_release_rtnl_lock();
13328 rtnl_held = false;
13329 return ret;
13330}
13331
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013332/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013333 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013334 * @kmessage: con mode name on which driver to be bring up
13335 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013336 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013337 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013338 * This function is invoked when user updates con mode using sys entry,
13339 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013340 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013341 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013342 */
Srinivas Girigowda841da292018-02-21 16:33:00 -080013343static int __con_mode_handler(const char *kmessage,
13344 const struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013345 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013346{
13347 int ret;
Jeff Johnson876c1a62017-12-12 10:43:07 -080013348 enum QDF_GLOBAL_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080013349 enum QDF_OPMODE adapter_mode;
Dustin Brown20024e32018-01-03 12:34:58 -080013350 int new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013351
Dustin Brownab6029b2017-05-24 13:04:19 -070013352 hdd_info("con_mode handler: %s", kmessage);
13353
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013354 ret = wlan_hdd_validate_context(hdd_ctx);
13355 if (ret)
13356 return ret;
13357
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013358 qdf_atomic_set(&hdd_ctx->con_mode_flag, 1);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013359
Dustin Brown20024e32018-01-03 12:34:58 -080013360 ret = kstrtoint(kmessage, 0, &new_con_mode);
13361 if (ret) {
13362 hdd_err("Failed to parse con_mode '%s'", kmessage);
13363 goto reset_flags;
13364 }
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013365 mutex_lock(&hdd_init_deinit_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +053013366
Dustin Brown20024e32018-01-03 12:34:58 -080013367 if (!is_con_mode_valid(new_con_mode)) {
13368 hdd_err("invalid con_mode %d", new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013369 ret = -EINVAL;
13370 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013371 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013372
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013373 curr_mode = hdd_get_conparam();
Dustin Brown20024e32018-01-03 12:34:58 -080013374 if (curr_mode == new_con_mode) {
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013375 hdd_err("curr mode: %d is same as user triggered mode %d",
Dustin Brown20024e32018-01-03 12:34:58 -080013376 curr_mode, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013377 ret = 0;
13378 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013379 }
13380
Dustin Brown27cd9942017-09-27 16:11:44 -070013381 /* ensure adapters are stopped */
13382 hdd_stop_present_mode(hdd_ctx, curr_mode);
13383
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070013384 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053013385 if (ret) {
13386 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013387 goto reset_flags;
13388 }
13389
Dustin Browndd4e50f2018-05-24 15:43:42 -070013390 /* Cleanup present mode before switching to new mode */
13391 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053013392
Dustin Brown20024e32018-01-03 12:34:58 -080013393 hdd_set_conparam(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013394
13395 /* Register for new con_mode & then kick_start modules again */
Dustin Brown20024e32018-01-03 12:34:58 -080013396 ret = hdd_register_req_mode(hdd_ctx, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013397 if (ret) {
13398 hdd_err("Failed to register for new mode");
13399 goto reset_flags;
13400 }
13401
Dustin Brown20024e32018-01-03 12:34:58 -080013402 adapter_mode = hdd_get_adpter_mode(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013403 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
13404 hdd_err("invalid adapter");
13405 ret = -EINVAL;
13406 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053013407 }
13408
Dustin Browne7e71d32018-05-11 16:00:08 -070013409 ret = hdd_wlan_start_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053013410 if (ret) {
13411 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013412 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053013413 }
13414
Dustin Brown20024e32018-01-03 12:34:58 -080013415 if (new_con_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Browne7e71d32018-05-11 16:00:08 -070013416 struct hdd_adapter *adapter =
13417 hdd_get_adapter(hdd_ctx, adapter_mode);
13418
13419 if (!adapter) {
13420 hdd_err("Failed to get adapter:%d", adapter_mode);
13421 goto reset_flags;
13422 }
13423
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013424 if (hdd_start_adapter(adapter)) {
13425 hdd_err("Failed to start %s adapter", kmessage);
13426 ret = -EINVAL;
13427 goto reset_flags;
13428 }
Arun Khandavallifae92942016-08-01 13:31:08 +053013429
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053013430 hdd_info("Acquire wakelock for monitor mode!");
13431 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
13432 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
13433 }
13434
Dustin Brown20024e32018-01-03 12:34:58 -080013435 /* con_mode is a global module parameter */
13436 con_mode = new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013437 hdd_info("Mode successfully changed to %s", kmessage);
13438 ret = 0;
13439
13440reset_flags:
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013441 mutex_unlock(&hdd_init_deinit_lock);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013442 qdf_atomic_set(&hdd_ctx->con_mode_flag, 0);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013443 return ret;
13444}
13445
13446
Srinivas Girigowda841da292018-02-21 16:33:00 -080013447static int con_mode_handler(const char *kmessage, const struct kernel_param *kp)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013448{
13449 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013450 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013451
13452 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13453 ret = wlan_hdd_validate_context(hdd_ctx);
13454 if (ret)
13455 return ret;
13456
Ashish Kumar Dhanotiya759b3272018-05-18 17:49:46 +053013457 if (!cds_wait_for_external_threads_completion(__func__)) {
13458 hdd_warn("External threads are still active, can not change mode");
13459 return -EAGAIN;
13460 }
13461
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013462 cds_ssr_protect(__func__);
13463 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
13464 cds_ssr_unprotect(__func__);
13465
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013466 return ret;
13467}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013468
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013469static int con_mode_handler_ftm(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080013470 const struct kernel_param *kp)
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013471{
13472 int ret;
13473
13474 ret = param_set_int(kmessage, kp);
13475
13476 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
13477 pr_err("Only FTM mode supported!");
13478 return -ENOTSUPP;
13479 }
13480
13481 hdd_set_conparam(con_mode_ftm);
13482 con_mode = con_mode_ftm;
13483
13484 return ret;
13485}
13486
Nirav Shah73713f72018-05-17 14:50:41 +053013487#ifdef FEATURE_MONITOR_MODE_SUPPORT
Ravi Joshia307f632017-07-17 23:41:41 -070013488static int con_mode_handler_monitor(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080013489 const struct kernel_param *kp)
Ravi Joshia307f632017-07-17 23:41:41 -070013490{
13491 int ret;
13492
13493 ret = param_set_int(kmessage, kp);
13494
13495 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
13496 pr_err("Only Monitor mode supported!");
13497 return -ENOTSUPP;
13498 }
13499
13500 hdd_set_conparam(con_mode_monitor);
13501 con_mode = con_mode_monitor;
13502
13503 return ret;
13504}
Nirav Shah73713f72018-05-17 14:50:41 +053013505#endif
Ravi Joshia307f632017-07-17 23:41:41 -070013506
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013507/**
13508 * hdd_get_conparam() - driver exit point
13509 *
13510 * This is the driver exit point (invoked when module is unloaded using rmmod)
13511 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080013512 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013513 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080013514enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013515{
Jeff Johnson876c1a62017-12-12 10:43:07 -080013516 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013517}
13518
Dustin Brownf0f70562018-09-14 10:29:38 -070013519void hdd_set_conparam(int32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013520{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080013521 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013522}
13523
Komal Seelamc11bb222016-01-27 18:57:10 +053013524/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013525 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
13526 * @hdd_ctx: HDD context
13527 *
13528 * Cleans up the pre cac interface, if it exists
13529 *
13530 * Return: None
13531 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013532void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013533{
13534 uint8_t session_id;
13535 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070013536 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013537
Jeff Johnson16528362018-06-14 12:34:16 -070013538 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->mac_handle, &session_id);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013539 if (QDF_IS_STATUS_ERROR(status)) {
13540 hdd_err("failed to get pre cac vdev id");
13541 return;
13542 }
13543
13544 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
13545 if (!precac_adapter) {
Jeff Johnsondd2f1fc2018-05-06 11:22:52 -070013546 hdd_err("invalid pre cac adapter");
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013547 return;
13548 }
13549
13550 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
13551 wlan_hdd_sap_pre_cac_failure,
13552 (void *)precac_adapter);
13553 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
13554
13555}
13556
13557/**
Komal Seelamec702b02016-02-24 18:42:16 +053013558 * hdd_update_ol_config - API to update ol configuration parameters
13559 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053013560 *
Komal Seelamc11bb222016-01-27 18:57:10 +053013561 * Return: void
13562 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013563static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053013564{
Komal Seelamec702b02016-02-24 18:42:16 +053013565 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053013566 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053013567 bool self_recovery = false;
13568 QDF_STATUS status;
Komal Seelamc11bb222016-01-27 18:57:10 +053013569
Komal Seelamec702b02016-02-24 18:42:16 +053013570 if (!ol_ctx)
13571 return;
13572
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053013573 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
13574 if (QDF_IS_STATUS_ERROR(status))
13575 hdd_err("Failed to get self recovery ini config");
13576
13577 cfg.enable_self_recovery = self_recovery;
Komal Seelamec702b02016-02-24 18:42:16 +053013578 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
13579 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
13580 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070013581 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053013582
13583 ol_init_ini_config(ol_ctx, &cfg);
13584}
13585
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013586#ifdef FEATURE_RUNTIME_PM
13587/**
13588 * hdd_populate_runtime_cfg() - populate runtime configuration
13589 * @hdd_ctx: hdd context
13590 * @cfg: pointer to the configuration memory being populated
13591 *
13592 * Return: void
13593 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013594static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013595 struct hif_config_info *cfg)
13596{
13597 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
Wu Gao66454f12018-09-26 19:55:41 +080013598 cfg->runtime_pm_delay =
13599 ucfg_pmo_get_runtime_pm_delay(hdd_ctx->psoc);
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013600}
13601#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013602static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013603 struct hif_config_info *cfg)
13604{
13605}
13606#endif
13607
Komal Seelamec702b02016-02-24 18:42:16 +053013608/**
13609 * hdd_update_hif_config - API to update HIF configuration parameters
13610 * @hdd_ctx: HDD Context
13611 *
13612 * Return: void
13613 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013614static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053013615{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053013616 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053013617 struct hif_config_info cfg;
Vignesh Viswanathana851d752018-10-03 19:44:38 +053013618 bool prevent_link_down = false;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053013619 bool self_recovery = false;
Vignesh Viswanathana851d752018-10-03 19:44:38 +053013620 QDF_STATUS status;
Komal Seelamec702b02016-02-24 18:42:16 +053013621
13622 if (!scn)
13623 return;
13624
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053013625 status = ucfg_mlme_get_prevent_link_down(hdd_ctx->psoc,
13626 &prevent_link_down);
Vignesh Viswanathana851d752018-10-03 19:44:38 +053013627 if (QDF_IS_STATUS_ERROR(status))
13628 hdd_err("Failed to get prevent_link_down config");
13629
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053013630 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
13631 if (QDF_IS_STATUS_ERROR(status))
13632 hdd_err("Failed to get self recovery ini config");
13633
13634 cfg.enable_self_recovery = self_recovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013635 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053013636 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070013637
Vignesh Viswanathana851d752018-10-03 19:44:38 +053013638 if (prevent_link_down)
Dustin Brownee3e0592017-09-07 13:50:11 -070013639 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053013640}
13641
13642/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013643 * hdd_update_dp_config() - Propagate config parameters to Lithium
13644 * datapath
13645 * @hdd_ctx: HDD Context
13646 *
13647 * Return: 0 for success/errno for failure
13648 */
13649static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
13650{
13651 struct cdp_config_params params;
13652 QDF_STATUS status;
13653
13654 params.tso_enable = hdd_ctx->config->tso_enable;
13655 params.lro_enable = hdd_ctx->config->lro_enable;
13656#ifdef QCA_LL_TX_FLOW_CONTROL_V2
13657 params.tx_flow_stop_queue_threshold =
13658 hdd_ctx->config->TxFlowStopQueueThreshold;
13659 params.tx_flow_start_queue_offset =
13660 hdd_ctx->config->TxFlowStartQueueOffset;
13661#endif
13662 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
13663 params.napi_enable = hdd_ctx->napi_enable;
13664 params.tcp_udp_checksumoffload =
13665 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Mohit Khannacabf5e72018-07-24 13:28:43 -070013666 params.ipa_enable = ucfg_ipa_is_enabled();
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013667
13668 status = cdp_update_config_parameters(
13669 cds_get_context(QDF_MODULE_ID_SOC),
13670 &params);
13671 if (status) {
Dustin Browna2868622018-03-20 11:38:14 -070013672 hdd_err("Failed to attach config parameters");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013673 return status;
13674 }
13675
13676 return 0;
13677}
13678
13679/**
Komal Seelamec702b02016-02-24 18:42:16 +053013680 * hdd_update_config() - Initialize driver per module ini parameters
13681 * @hdd_ctx: HDD Context
13682 *
13683 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013684 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053013685 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013686int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053013687{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013688 int ret;
13689
Wu Gao66454f12018-09-26 19:55:41 +080013690 if (ucfg_pmo_is_ns_offloaded(hdd_ctx->psoc))
13691 hdd_ctx->ns_offload_enable = true;
13692
Komal Seelamec702b02016-02-24 18:42:16 +053013693 hdd_update_ol_config(hdd_ctx);
13694 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013695 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
13696 ret = hdd_update_cds_config_ftm(hdd_ctx);
13697 else
13698 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080013699 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013700
13701 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053013702}
13703
Mukul Sharma9d797a02017-01-05 20:26:03 +053013704#ifdef FEATURE_WLAN_RA_FILTERING
13705/**
13706 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
13707 * @psoc_cfg: pmo psoc Configuration
13708 * @hdd_ctx: Pointer to hdd context
13709 *
13710 * Return: none
13711 */
13712static inline void hdd_ra_populate_pmo_config(
13713 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013714 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013715{
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053013716 bool is_rate_limit_enabled;
13717 QDF_STATUS status;
13718
13719 status = ucfg_fwol_get_is_rate_limit_enabled(hdd_ctx->psoc,
13720 &is_rate_limit_enabled);
13721 if (QDF_IS_STATUS_ERROR(status))
13722 return;
13723
Mukul Sharma9d797a02017-01-05 20:26:03 +053013724 psoc_cfg->ra_ratelimit_interval =
13725 hdd_ctx->config->RArateLimitInterval;
13726 psoc_cfg->ra_ratelimit_enable =
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053013727 is_rate_limit_enabled;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013728}
13729#else
13730static inline void hdd_ra_populate_pmo_config(
13731 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013732 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013733{
13734}
13735#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080013736
Mukul Sharma9d797a02017-01-05 20:26:03 +053013737/**
13738 * hdd_update_pmo_config - API to update pmo configuration parameters
13739 * @hdd_ctx: HDD context
13740 *
13741 * Return: void
13742 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013743static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013744{
Mukul Sharma9d797a02017-01-05 20:26:03 +053013745 struct pmo_psoc_cfg psoc_cfg;
13746 QDF_STATUS status;
Wu Gao66454f12018-09-26 19:55:41 +080013747 enum pmo_wow_enable_type wow_enable;
13748
13749 ucfg_pmo_get_psoc_config(hdd_ctx->psoc, &psoc_cfg);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013750
13751 /*
13752 * Value of hdd_ctx->wowEnable can be,
13753 * 0 - Disable both magic pattern match and pattern byte match.
13754 * 1 - Enable magic pattern match on all interfaces.
13755 * 2 - Enable pattern byte match on all interfaces.
13756 * 3 - Enable both magic patter and pattern byte match on
13757 * all interfaces.
13758 */
Wu Gao66454f12018-09-26 19:55:41 +080013759 wow_enable = ucfg_pmo_get_wow_enable(hdd_ctx->psoc);
13760 psoc_cfg.magic_ptrn_enable = (wow_enable & 0x01) ? true : false;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013761 psoc_cfg.ptrn_match_enable_all_vdev =
Wu Gao66454f12018-09-26 19:55:41 +080013762 (wow_enable & 0x02) ? true : false;
Dustin Brownb9987af2018-03-01 17:15:11 -080013763 psoc_cfg.packet_filter_enabled = !hdd_ctx->config->disablePacketFilter;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013764 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080013765 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9223f232017-03-08 18:42:27 +053013766 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013767
13768 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053013769 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013770
Dustin Brown1dbefe62018-09-11 16:32:03 -070013771 status = ucfg_pmo_update_psoc_config(hdd_ctx->psoc, &psoc_cfg);
Dustin Brownb9987af2018-03-01 17:15:11 -080013772 if (QDF_IS_STATUS_ERROR(status))
13773 hdd_err("failed pmo psoc configuration; status:%d", status);
13774
13775 return qdf_status_to_os_return(status);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013776}
13777
Abhishek Singhb20db962017-03-03 21:28:46 +053013778#ifdef FEATURE_WLAN_SCAN_PNO
13779static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
13780 struct hdd_config *cfg)
13781{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070013782 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
13783
Abhishek Singhb20db962017-03-03 21:28:46 +053013784 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
13785 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
13786 pno_cfg->stationary_thresh = cfg->stationary_thresh;
13787 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
13788 pno_cfg->channel_prediction_full_scan =
13789 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070013790 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
13791 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
13792 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
13793 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053013794}
13795#else
13796static inline void
13797hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070013798 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053013799{
Abhishek Singhb20db962017-03-03 21:28:46 +053013800}
13801#endif
13802
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013803void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
Dundi Raviteja85a240a2018-09-10 15:03:07 +053013804 struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013805{
Dundi Raviteja85a240a2018-09-10 15:03:07 +053013806 struct wlan_fwol_ie_whitelist whitelist = {0};
13807 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Dundi Raviteja85a240a2018-09-10 15:03:07 +053013808 QDF_STATUS status;
13809 bool is_ie_whitelist_enable = false;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013810 uint8_t i = 0;
13811
Dundi Raviteja85a240a2018-09-10 15:03:07 +053013812 status = ucfg_fwol_get_ie_whitelist(psoc, &is_ie_whitelist_enable);
13813 if (QDF_IS_STATUS_ERROR(status)) {
13814 hdd_err("Unable to get IE whitelist param");
13815 return;
13816 }
13817
13818 ie_whitelist->white_list = is_ie_whitelist_enable;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013819 if (!ie_whitelist->white_list)
13820 return;
13821
Dundi Raviteja85a240a2018-09-10 15:03:07 +053013822 status = ucfg_fwol_get_all_whitelist_params(psoc, &whitelist);
13823 if (QDF_IS_STATUS_ERROR(status)) {
13824 hdd_err("Unable to get all whitelist params");
13825 return;
13826 }
13827
13828 ie_whitelist->ie_bitmap[0] = whitelist.ie_bitmap_0;
13829 ie_whitelist->ie_bitmap[1] = whitelist.ie_bitmap_1;
13830 ie_whitelist->ie_bitmap[2] = whitelist.ie_bitmap_2;
13831 ie_whitelist->ie_bitmap[3] = whitelist.ie_bitmap_3;
13832 ie_whitelist->ie_bitmap[4] = whitelist.ie_bitmap_4;
13833 ie_whitelist->ie_bitmap[5] = whitelist.ie_bitmap_5;
13834 ie_whitelist->ie_bitmap[6] = whitelist.ie_bitmap_6;
13835 ie_whitelist->ie_bitmap[7] = whitelist.ie_bitmap_7;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013836
Dundi Raviteja9ab4e7b2018-09-28 14:18:28 +053013837 ie_whitelist->num_vendor_oui = whitelist.no_of_probe_req_ouis;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013838 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
Dundi Raviteja9ab4e7b2018-09-28 14:18:28 +053013839 ie_whitelist->voui[i] = whitelist.probe_req_voui[i];
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013840}
13841
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013842uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
13843{
13844 uint8_t i, score;
13845
13846 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
13847 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
13848 if (score > MAX_INDEX_SCORE)
13849 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
13850 MAX_INDEX_SCORE, i);
13851 }
13852
13853 return per_index_score;
13854}
13855
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053013856QDF_STATUS hdd_update_score_config(
13857 struct scoring_config *score_config, struct hdd_context *hdd_ctx)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013858{
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053013859 struct hdd_config *cfg = hdd_ctx->config;
gaurank kathpaliaae52c982018-10-04 01:35:18 +053013860 QDF_STATUS status;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053013861 bool bval = false;
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013862
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053013863 sme_update_score_config(hdd_ctx->mac_handle, score_config);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013864
13865 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
13866 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
gaurank kathpaliaae52c982018-10-04 01:35:18 +053013867
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053013868 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
gaurank kathpaliaae52c982018-10-04 01:35:18 +053013869 if (!QDF_IS_STATUS_SUCCESS(status))
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053013870 hdd_err("unable to get vht_enable2x2");
gaurank kathpaliaae52c982018-10-04 01:35:18 +053013871 score_config->vdev_nss_24g =
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053013872 bval ? CFG_STA_NSS(cfg->vdev_type_nss_2g) : 1;
gaurank kathpaliaae52c982018-10-04 01:35:18 +053013873 score_config->vdev_nss_5g =
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053013874 bval ? CFG_STA_NSS(cfg->vdev_type_nss_5g) : 1;
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013875
13876 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
13877 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
13878 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
13879 score_config->he_cap = 1;
13880
13881 if (score_config->he_cap ||
13882 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
13883 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
13884 score_config->vht_cap = 1;
13885
13886 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
13887 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
13888 score_config->ht_cap = 1;
13889
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053013890 status = ucfg_mlme_get_vht_for_24ghz(hdd_ctx->psoc, &bval);
13891 if (!QDF_IS_STATUS_SUCCESS(status))
13892 hdd_err("Failed to get vht_for_24ghz");
13893 if (score_config->vht_cap && bval)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013894 score_config->vht_24G_cap = 1;
13895
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053013896 status = ucfg_mlme_get_vht_enable_tx_bf(hdd_ctx->psoc,
13897 &bval);
13898 if (!QDF_IS_STATUS_SUCCESS(status))
13899 hdd_err("unable to get vht_enable_tx_bf");
13900
13901 if (bval)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013902 score_config->beamformee_cap = 1;
13903
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053013904 return QDF_STATUS_SUCCESS;
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013905}
13906
Abhishek Singh257a9482017-03-06 16:52:39 +053013907/**
bings81fe50a2017-11-27 14:33:26 +080013908 * hdd_update_dfs_config() - API to update dfs configuration parameters.
13909 * @hdd_ctx: HDD context
13910 *
13911 * Return: 0 if success else err
13912 */
13913static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
13914{
Dustin Brown1dbefe62018-09-11 16:32:03 -070013915 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
bings81fe50a2017-11-27 14:33:26 +080013916 struct hdd_config *cfg = hdd_ctx->config;
13917 struct dfs_user_config dfs_cfg;
13918 QDF_STATUS status;
13919
13920 dfs_cfg.dfs_is_phyerr_filter_offload = !!cfg->fDfsPhyerrFilterOffload;
13921 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
13922 if (QDF_IS_STATUS_ERROR(status)) {
13923 hdd_err("failed dfs psoc configuration");
13924 return -EINVAL;
13925 }
13926
13927 return 0;
13928}
13929
13930/**
Abhishek Singh257a9482017-03-06 16:52:39 +053013931 * hdd_update_scan_config - API to update scan configuration parameters
13932 * @hdd_ctx: HDD context
13933 *
13934 * Return: 0 if success else err
13935 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013936static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053013937{
Dustin Brown1dbefe62018-09-11 16:32:03 -070013938 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Abhishek Singh257a9482017-03-06 16:52:39 +053013939 struct scan_user_cfg scan_cfg;
13940 struct hdd_config *cfg = hdd_ctx->config;
13941 QDF_STATUS status;
Wu Gaoca416ff2018-09-17 11:05:07 +080013942 uint8_t scan_bucket_thre;
Vignesh Viswanathana851d752018-10-03 19:44:38 +053013943 uint8_t select_5ghz_margin;
13944
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053013945 status = ucfg_mlme_get_select_5ghz_margin(hdd_ctx->psoc,
13946 &select_5ghz_margin);
Vignesh Viswanathana851d752018-10-03 19:44:38 +053013947 if (QDF_IS_STATUS_ERROR(status)) {
13948 hdd_err("Failed to get select_5ghz_margin");
13949 return -EIO;
13950 }
Abhishek Singh257a9482017-03-06 16:52:39 +053013951
13952 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
13953 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
13954 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
13955 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
13956 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
13957 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
13958 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053013959 /* convert to ms */
13960 scan_cfg.scan_cache_aging_time =
13961 cfg->scanAgingTimeout * 1000;
13962 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
Vignesh Viswanathana851d752018-10-03 19:44:38 +053013963 scan_cfg.select_5ghz_margin = select_5ghz_margin;
Dustin Brown1dbefe62018-09-11 16:32:03 -070013964 ucfg_mlme_get_first_scan_bucket_threshold(hdd_ctx->psoc,
Wu Gaoca416ff2018-09-17 11:05:07 +080013965 &scan_bucket_thre);
13966 scan_cfg.scan_bucket_threshold = (int32_t)scan_bucket_thre;
Abhishek Singh158fe252017-03-23 11:09:34 +053013967 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053013968 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053013969 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080013970 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
13971 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053013972 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070013973 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singhc87bb042018-01-30 17:10:42 +053013974 scan_cfg.sta_miracast_mcc_rest_time =
13975 cfg->sta_miracast_mcc_rest_time_val;
Abhishek Singhb20db962017-03-03 21:28:46 +053013976 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Dundi Raviteja85a240a2018-09-10 15:03:07 +053013977 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, hdd_ctx);
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053013978
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053013979 status = hdd_update_score_config(&scan_cfg.score_config, hdd_ctx);
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053013980 if (QDF_IS_STATUS_ERROR(status)) {
13981 hdd_err("Failed to update scoring config");
13982 return -EINVAL;
13983 }
Abhishek Singhb20db962017-03-03 21:28:46 +053013984
Abhishek Singh257a9482017-03-06 16:52:39 +053013985 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
13986 if (status != QDF_STATUS_SUCCESS) {
13987 hdd_err("failed pmo psoc configuration");
13988 return -EINVAL;
13989 }
Liangwei Dongac3ddde2018-09-10 23:25:12 -040013990 ucfg_scan_set_global_config(
13991 psoc, SCAN_CFG_DROP_BCN_ON_CHANNEL_MISMATCH,
13992 cfg_get(psoc, CFG_DROP_BCN_ON_CHANNEL_MISMATCH));
Abhishek Singh257a9482017-03-06 16:52:39 +053013993
13994 return 0;
13995}
Abhishek Singh257a9482017-03-06 16:52:39 +053013996
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013997int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013998{
13999 int ret;
14000
14001 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053014002 if (ret)
14003 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014004
Abhishek Singh257a9482017-03-06 16:52:39 +053014005 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080014006 if (ret)
14007 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014008
Frank Liud4b2fa02017-03-29 11:46:48 +080014009 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014010 if (ret)
14011 return ret;
14012
14013 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080014014 if (ret)
14015 return ret;
14016
14017 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014018
14019 return ret;
14020}
14021
Agrawal Ashish65634612016-08-18 13:24:32 +053014022/**
14023 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
14024 * @mode : cfg80211 DFS mode
14025 *
14026 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
14027 */
14028enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
14029{
14030 switch (mode) {
14031 case DFS_MODE_ENABLE:
14032 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014033 case DFS_MODE_DISABLE:
14034 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014035 case DFS_MODE_DEPRIORITIZE:
14036 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014037 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080014038 hdd_debug("ACS dfs mode is NONE");
14039 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014040 }
14041}
14042
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014043/**
14044 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
14045 * @hddctx: pointer to hdd context
14046 * @set_value: enable/disable
14047 *
14048 * When Host sends vendor command enable, FW will send *ONE* CA ind to
14049 * Host(even though it is duplicate). When Host send vendor command
14050 * disable,FW doesn't perform any action. Whenever any change in
14051 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
14052 *
14053 * return - 0 on success, appropriate error values on failure.
14054 */
Jeff Johnson16528362018-06-14 12:34:16 -070014055int hdd_enable_disable_ca_event(struct hdd_context *hdd_ctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014056{
14057 QDF_STATUS status;
14058
Jeff Johnson16528362018-06-14 12:34:16 -070014059 if (0 != wlan_hdd_validate_context(hdd_ctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014060 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014061
Jeff Johnson16528362018-06-14 12:34:16 -070014062 status = sme_enable_disable_chanavoidind_event(hdd_ctx->mac_handle,
14063 set_value);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014064 if (!QDF_IS_STATUS_SUCCESS(status)) {
14065 hdd_err("Failed to send chan avoid command to SME");
14066 return -EINVAL;
14067 }
14068 return 0;
14069}
Agrawal Ashish65634612016-08-18 13:24:32 +053014070
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014071/**
14072 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
14073 * @value: value to set
14074 *
14075 * This function will set the passed value to roaming in progress flag.
14076 *
14077 * Return: None
14078 */
14079void hdd_set_roaming_in_progress(bool value)
14080{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014081 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014082
14083 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14084 if (!hdd_ctx) {
14085 hdd_err("HDD context is NULL");
14086 return;
14087 }
14088
14089 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080014090 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014091}
14092
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014093bool hdd_is_roaming_in_progress(struct hdd_context *hdd_ctx)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014094{
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014095 if (!hdd_ctx) {
14096 hdd_err("HDD context is NULL");
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014097 return false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014098 }
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080014099
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014100 hdd_debug("roaming_in_progress = %d", hdd_ctx->roaming_in_progress);
14101
14102 return hdd_ctx->roaming_in_progress;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014103}
14104
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014105/**
14106 * hdd_is_connection_in_progress() - check if connection is in
14107 * progress
14108 * @session_id: session id
14109 * @reason: scan reject reason
14110 *
14111 * Go through each adapter and check if Connection is in progress
14112 *
14113 * Return: true if connection is in progress else false
14114 */
14115bool hdd_is_connection_in_progress(uint8_t *session_id,
14116 enum scan_reject_states *reason)
14117{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070014118 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070014119 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014120 uint8_t sta_id = 0;
14121 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014122 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -070014123 mac_handle_t mac_handle;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014124
14125 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14126 if (!hdd_ctx) {
14127 hdd_err("HDD context is NULL");
14128 return false;
14129 }
14130
Jeff Johnson16528362018-06-14 12:34:16 -070014131 mac_handle = hdd_ctx->mac_handle;
14132
Dustin Brown920397d2017-12-13 16:27:50 -080014133 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya929afa42018-06-01 15:04:44 -070014134 hdd_debug("Adapter with device mode %s(%d) exists",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014135 hdd_device_mode_to_string(adapter->device_mode),
14136 adapter->device_mode);
14137 if (((QDF_STA_MODE == adapter->device_mode)
14138 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
14139 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
14140 && (eConnectionState_Connecting ==
14141 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
14142 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014143 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014144 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070014145 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014146 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070014147 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014148 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014149 }
14150 return true;
14151 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070014152 /*
14153 * sme_neighbor_middle_of_roaming is for LFR2
14154 * hdd_is_roaming_in_progress is for LFR3
14155 */
14156 if (((QDF_STA_MODE == adapter->device_mode) &&
14157 sme_neighbor_middle_of_roaming(
Jeff Johnson16528362018-06-14 12:34:16 -070014158 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -070014159 adapter->session_id)) ||
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014160 hdd_is_roaming_in_progress(hdd_ctx)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014161 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014162 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070014163 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014164 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070014165 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014166 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014167 }
14168 return true;
14169 }
14170 if ((QDF_STA_MODE == adapter->device_mode) ||
14171 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
14172 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
14173 hdd_sta_ctx =
14174 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
14175 if ((eConnectionState_Associated ==
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053014176 hdd_sta_ctx->conn_info.connState)
14177 && sme_is_sta_key_exchange_in_progress(
Jeff Johnson16528362018-06-14 12:34:16 -070014178 mac_handle, adapter->session_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014179 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070014180 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014181 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014182 " is in middle of WPS/EAPOL exchange.",
14183 MAC_ADDR_ARRAY(sta_mac));
14184 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070014185 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014186 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014187 }
14188 return true;
14189 }
14190 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
14191 (QDF_P2P_GO_MODE == adapter->device_mode)) {
14192 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
14193 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014194 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014195 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014196 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014197 continue;
14198
14199 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014200 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070014201 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014202 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014203 " of SAP/GO is in middle of WPS/EAPOL exchange",
14204 MAC_ADDR_ARRAY(sta_mac));
14205 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070014206 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014207 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014208 }
14209 return true;
14210 }
14211 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014212 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014213 return true;
14214 }
14215 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014216 }
Dustin Brown920397d2017-12-13 16:27:50 -080014217
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014218 return false;
14219}
14220
14221/**
14222 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070014223 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014224 *
14225 * Return: None
14226 */
Jeff Johnson9d295242017-08-29 14:39:48 -070014227void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014228{
Jeff Johnson87251032017-08-29 13:31:11 -070014229 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070014230 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014231 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014232 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Jeff Johnsone4c11db2018-05-05 23:22:32 -070014233 tsap_config_t *sap_config;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014234 void *sap_ctx;
14235
14236 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070014237 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070014238 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014239
14240 mutex_lock(&hdd_ctx->sap_lock);
14241 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
14242 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014243 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
14244 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
14245 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
14246 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053014247 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014248 qdf_stop_bss_event,
Vignesh Viswanathan865daaa2018-10-11 19:30:44 +053014249 SME_CMD_START_STOP_BSS_TIMEOUT);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014250
14251 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014252 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014253 goto end;
14254 }
14255 }
14256 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -070014257 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070014258 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070014259 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014260 false);
Jeff Johnson6867ec32017-09-29 20:30:20 -070014261 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014262
14263 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014264 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014265 wlansap_reset_sap_config_add_ie(sap_config,
14266 eUPDATE_IE_ALL);
14267 goto end;
14268 }
14269
14270 qdf_event_reset(&hostapd_state->qdf_event);
14271 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
14272 sap_config,
14273 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014274 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014275 wlansap_reset_sap_config_add_ie(sap_config,
14276 eUPDATE_IE_ALL);
14277 goto end;
14278 }
14279
Jeff Johnson6867ec32017-09-29 20:30:20 -070014280 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014281 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053014282 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Vignesh Viswanathan865daaa2018-10-11 19:30:44 +053014283 SME_CMD_START_STOP_BSS_TIMEOUT);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014284 wlansap_reset_sap_config_add_ie(sap_config,
14285 eUPDATE_IE_ALL);
14286 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014287 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014288 goto end;
14289 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070014290 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014291 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014292 if (hostapd_state->bss_state == BSS_START) {
Dustin Brown1dbefe62018-09-11 16:32:03 -070014293 policy_mgr_incr_active_session(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014294 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070014295 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070014296 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014297 ap_adapter->device_mode,
14298 true);
14299 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014300 }
14301end:
14302 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014303}
14304
14305/**
14306 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
14307 * with non dfs acs
14308 *
14309 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
14310 *
14311 * Return: None
14312 */
14313void hdd_check_and_restart_sap_with_non_dfs_acs(void)
14314{
Jeff Johnson9d295242017-08-29 14:39:48 -070014315 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014316 struct hdd_context *hdd_ctx;
Jeff Johnson2b6982c2018-05-29 14:56:11 -070014317 struct cds_context *cds_ctx;
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014318 uint8_t restart_chan;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014319
14320 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14321 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014322 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014323 return;
14324 }
14325
14326 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
14327 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014328 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014329 return;
14330 }
14331
Dustin Brown1dbefe62018-09-11 16:32:03 -070014332 if (policy_mgr_get_concurrency_mode(hdd_ctx->psoc)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014333 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Dustin Brown7e761c72018-07-31 13:50:17 -070014334 hdd_debug("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014335 return;
14336 }
14337
14338 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Dustin Brown07901ec2018-09-07 11:02:41 -070014339 if (ap_adapter &&
14340 test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags) &&
14341 wlan_reg_is_dfs_ch(hdd_ctx->pdev,
14342 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014343
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014344 hdd_warn("STA-AP Mode DFS not supported, Switch SAP channel to Non DFS");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014345
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014346 restart_chan =
14347 hdd_get_safe_channel_from_pcl_and_acs_range(ap_adapter);
14348 if (!restart_chan ||
Dustin Brown07901ec2018-09-07 11:02:41 -070014349 wlan_reg_is_dfs_ch(hdd_ctx->pdev, restart_chan))
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014350 restart_chan = SAP_DEFAULT_5GHZ_CHANNEL;
14351
14352 hdd_switch_sap_channel(ap_adapter, restart_chan, true);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014353 }
14354}
14355
14356/**
14357 * hdd_set_connection_in_progress() - to set the connection in
14358 * progress flag
14359 * @value: value to set
14360 *
14361 * This function will set the passed value to connection in progress flag.
14362 * If value is previously being set to true then no need to set it again.
14363 *
14364 * Return: true if value is being set correctly and false otherwise.
14365 */
14366bool hdd_set_connection_in_progress(bool value)
14367{
14368 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014369 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014370
14371 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14372 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014373 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014374 return false;
14375 }
14376
14377 qdf_spin_lock(&hdd_ctx->connection_status_lock);
14378 /*
14379 * if the value is set to true previously and if someone is
14380 * trying to make it true again then it could be some race
14381 * condition being triggered. Avoid this situation by returning
14382 * false
14383 */
14384 if (hdd_ctx->connection_in_progress && value)
14385 status = false;
14386 else
14387 hdd_ctx->connection_in_progress = value;
14388 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
14389 return status;
14390}
14391
Jeff Johnson9d295242017-08-29 14:39:48 -070014392int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014393{
14394 if (!adapter) {
14395 hdd_err("Invalid adapter");
14396 return -EINVAL;
14397 }
14398 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070014399 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014400 WMA_VDEV_MCC_SET_TIME_QUOTA,
14401 set_value, VDEV_CMD);
14402 return 0;
14403
14404}
14405
Jeff Johnson9d295242017-08-29 14:39:48 -070014406int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014407{
14408 if (!adapter) {
14409 hdd_err("Invalid adapter");
14410 return -EINVAL;
14411 }
14412
14413 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070014414 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014415 WMA_VDEV_MCC_SET_TIME_LATENCY,
14416 set_value, VDEV_CMD);
14417 return 0;
14418}
14419
Jeff Johnson9d295242017-08-29 14:39:48 -070014420struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070014421 *psoc, uint8_t vdev_id)
14422{
Jeff Johnson9d295242017-08-29 14:39:48 -070014423 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014424 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070014425
14426 /*
14427 * Currently PSOC is not being used. But this logic will
14428 * change once we have the converged implementation of
14429 * HDD context per PSOC in place. This would break if
14430 * multiple vdev objects reuse the vdev id.
14431 */
14432 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
14433 if (!adapter)
14434 hdd_err("Get adapter by vdev id failed");
14435
14436 return adapter;
14437}
14438
Jeff Johnson9d295242017-08-29 14:39:48 -070014439int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014440 int8_t *rssi, int8_t *snr)
14441{
14442 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -070014443 mac_handle_t mac_handle;
Jeff Johnson025618c2018-03-18 14:41:00 -070014444 struct csr_roam_profile *roam_profile;
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014445
Jeff Johnson025618c2018-03-18 14:41:00 -070014446 roam_profile = hdd_roam_profile(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -070014447 mac_handle = hdd_adapter_get_mac_handle(adapter);
14448 status = sme_get_rssi_snr_by_bssid(mac_handle,
Jeff Johnson025618c2018-03-18 14:41:00 -070014449 roam_profile, bssid, rssi, snr);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014450 if (QDF_STATUS_SUCCESS != status) {
14451 hdd_warn("sme_get_rssi_snr_by_bssid failed");
14452 return -EINVAL;
14453 }
14454
14455 return 0;
14456}
14457
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014458/**
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014459 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
14460 * @adapter - HDD adapter
14461 *
14462 * Return: 0 on success and non zero value on failure
14463 */
14464int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
14465{
14466 struct hdd_context *hdd_ctx;
14467 int ret;
14468 QDF_STATUS status;
Krunal Sonie71838d2018-09-27 10:45:05 -070014469 uint8_t sys_pref = 0;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014470
14471 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
14472 ret = wlan_hdd_validate_context(hdd_ctx);
14473 if (ret < 0)
14474 return ret;
14475
Krunal Sonie71838d2018-09-27 10:45:05 -070014476 ucfg_policy_mgr_get_sys_pref(hdd_ctx->psoc,
14477 &sys_pref);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014478 /* set the system preferece to default */
Krunal Sonie71838d2018-09-27 10:45:05 -070014479 policy_mgr_set_cur_conc_system_pref(hdd_ctx->psoc, sys_pref);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014480
14481 /* clear the bitmap */
14482 adapter->active_ac = 0;
14483
14484 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson16528362018-06-14 12:34:16 -070014485 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014486
Jeff Johnson16528362018-06-14 12:34:16 -070014487 status = sme_send_limit_off_channel_params(hdd_ctx->mac_handle,
14488 adapter->session_id,
14489 false, 0, 0, false);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014490 if (!QDF_IS_STATUS_SUCCESS(status)) {
14491 hdd_err("failed to reset limit off chan params");
14492 ret = -EINVAL;
14493 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014494
14495 return ret;
14496}
14497
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014498/**
14499 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
14500 * @drv_op: Enum indicating driver op
14501 *
14502 * Return: none
14503 */
14504void hdd_start_driver_ops_timer(int drv_op)
14505{
14506 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
14507 switch (drv_op) {
14508 case eHDD_DRV_OP_PROBE:
14509 memcpy(drv_ops_string, "probe", sizeof("probe"));
14510 break;
14511 case eHDD_DRV_OP_REMOVE:
14512 memcpy(drv_ops_string, "remove", sizeof("remove"));
14513 break;
14514 case eHDD_DRV_OP_SHUTDOWN:
14515 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
14516 break;
14517 case eHDD_DRV_OP_REINIT:
14518 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
14519 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053014520 case eHDD_DRV_OP_IFF_UP:
14521 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
14522 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014523 }
14524
Dustin Brown45ed4bb2017-12-18 12:00:13 -080014525 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014526 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
Dustin Browncfc54fe2018-06-18 16:17:41 -070014527 HDD_OPS_INACTIVITY_TIMEOUT * qdf_timer_get_multiplier());
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014528}
14529
14530/**
14531 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
14532 *
14533 * Return: none
14534 */
14535void hdd_stop_driver_ops_timer(void)
14536{
14537 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
14538}
14539
14540/**
14541 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
14542 * inactivity timer
14543 *
14544 * Return: None
14545 */
14546void hdd_drv_ops_inactivity_handler(void)
14547{
Rajeev Kumar4471f1b2018-06-08 14:18:28 -070014548 hdd_err("WLAN_BUG_RCA %s: %d Sec timer expired while in .%s",
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014549 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
14550
Dustin Brown45ed4bb2017-12-18 12:00:13 -080014551 if (hdd_drv_ops_task) {
14552 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
14553 qdf_print_thread_trace(hdd_drv_ops_task);
14554 } else {
14555 hdd_err("hdd_drv_ops_task is null");
14556 }
14557
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014558 /* Driver shutdown is stuck, no recovery possible at this point */
14559 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
14560 sizeof("shutdown")))
14561 QDF_BUG(0);
14562
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080014563 if (cds_is_fw_down()) {
14564 hdd_err("FW is down");
14565 return;
14566 }
14567
Dustin Brown83044c22018-08-13 15:00:44 -070014568 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014569}
14570
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053014571void hdd_pld_ipa_uc_shutdown_pipes(void)
14572{
14573 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14574
14575 if (!hdd_ctx)
14576 return;
14577
Dustin Brown07901ec2018-09-07 11:02:41 -070014578 ucfg_ipa_uc_force_pipe_shutdown(hdd_ctx->pdev);
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053014579}
14580
Yun Parkff6a16a2017-09-26 16:38:18 -070014581/**
14582 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
14583 * @struct hdd_context *hdd_ctx
14584 * @struct hdd_adapter *padapter
14585 * @bool enble
14586 *
14587 * Return: none
14588 */
14589void hdd_set_rx_mode_rps(bool enable)
14590{
14591 struct cds_config_info *cds_cfg = cds_get_ini_config();
Ryan Hsu0e878fa2018-05-04 15:22:09 -070014592 struct hdd_context *hdd_ctx;
14593 struct hdd_adapter *adapter;
Yun Parkff6a16a2017-09-26 16:38:18 -070014594
Ryan Hsu0e878fa2018-05-04 15:22:09 -070014595 if (!cds_cfg)
14596 return;
14597
14598 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14599 if (!hdd_ctx)
14600 return;
14601
14602 adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
14603 if (!adapter)
14604 return;
14605
14606 if (!hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
Yun Parkff6a16a2017-09-26 16:38:18 -070014607 if (enable && !cds_cfg->rps_enabled)
14608 hdd_send_rps_ind(adapter);
14609 else if (!enable && cds_cfg->rps_enabled)
14610 hdd_send_rps_disable_ind(adapter);
14611 }
14612}
14613
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +053014614bool hdd_is_cli_iface_up(struct hdd_context *hdd_ctx)
14615{
14616 struct hdd_adapter *adapter = NULL;
14617
14618 hdd_for_each_adapter(hdd_ctx, adapter) {
14619 if ((adapter->device_mode == QDF_STA_MODE ||
14620 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
14621 qdf_atomic_test_bit(DEVICE_IFACE_OPENED,
14622 &adapter->event_flags)){
14623 return true;
14624 }
14625 }
14626
14627 return false;
14628}
14629
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014630/* Register the module init/exit functions */
14631module_init(hdd_module_init);
14632module_exit(hdd_module_exit);
14633
14634MODULE_LICENSE("Dual BSD/GPL");
14635MODULE_AUTHOR("Qualcomm Atheros, Inc.");
14636MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
14637
Srinivas Girigowda841da292018-02-21 16:33:00 -080014638static const struct kernel_param_ops con_mode_ops = {
14639 .set = con_mode_handler,
14640 .get = param_get_int,
14641};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014642
Srinivas Girigowda841da292018-02-21 16:33:00 -080014643static const struct kernel_param_ops con_mode_ftm_ops = {
14644 .set = con_mode_handler_ftm,
14645 .get = param_get_int,
14646};
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053014647
Nirav Shah73713f72018-05-17 14:50:41 +053014648#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080014649static const struct kernel_param_ops con_mode_monitor_ops = {
14650 .set = con_mode_handler_monitor,
14651 .get = param_get_int,
14652};
Nirav Shah73713f72018-05-17 14:50:41 +053014653#endif
Ravi Joshia307f632017-07-17 23:41:41 -070014654
Srinivas Girigowda841da292018-02-21 16:33:00 -080014655static const struct kernel_param_ops fwpath_ops = {
14656 .set = fwpath_changed_handler,
14657 .get = param_get_string,
14658};
14659
14660module_param_cb(con_mode, &con_mode_ops, &con_mode,
14661 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
14662
14663module_param_cb(con_mode_ftm, &con_mode_ftm_ops, &con_mode_ftm,
14664 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
14665
Nirav Shah73713f72018-05-17 14:50:41 +053014666#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080014667module_param_cb(con_mode_monitor, &con_mode_monitor_ops, &con_mode_monitor,
14668 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Nirav Shah73713f72018-05-17 14:50:41 +053014669#endif
Srinivas Girigowda841da292018-02-21 16:33:00 -080014670
14671module_param_cb(fwpath, &fwpath_ops, &fwpath,
14672 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014673
14674module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
14675
14676module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
14677
14678module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);