blob: 7f5b17d330ee90ac18a571f1dc0389e069211e60 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Dustin Browndb2a8be2017-12-20 11:49:56 -08002 * Copyright (c) 2012-2018 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
7 * copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080019/**
20 * DOC: wlan_hdd_main.c
21 *
22 * WLAN Host Device Driver implementation
23 *
24 */
25
26/* Include Files */
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053027#include <wbuff.h>
Dustin Brown84f46ea2018-02-15 11:57:36 -080028#include "cfg_ucfg_api.h"
Dustin Brown21a1d462018-07-31 15:13:06 -070029#include "wlan_dsc.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080030#include <wlan_hdd_includes.h>
31#include <cds_api.h>
32#include <cds_sched.h>
Arun Khandavallifae92942016-08-01 13:31:08 +053033#include <linux/cpu.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080034#include <linux/etherdevice.h>
35#include <linux/firmware.h>
36#include <wlan_hdd_tx_rx.h>
37#include <wni_api.h>
38#include <wlan_hdd_cfg.h>
39#include <wlan_ptt_sock_svc.h>
40#include <dbglog_host.h>
41#include <wlan_logging_sock_svc.h>
Qiwei Caiad9b01c2018-07-09 17:21:31 +080042#include <wlan_roam_debug.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080043#include <wlan_hdd_wowl.h>
44#include <wlan_hdd_misc.h>
45#include <wlan_hdd_wext.h>
46#include "wlan_hdd_trace.h"
47#include "wlan_hdd_ioctl.h"
48#include "wlan_hdd_ftm.h"
49#include "wlan_hdd_power.h"
50#include "wlan_hdd_stats.h"
Prashanth Bhatta527fd752016-04-28 12:35:23 -070051#include "wlan_hdd_scan.h"
Krunal Sonie9c12f52018-10-04 11:45:42 -070052#include "wlan_policy_mgr_ucfg.h"
Naveen Rawate02f8f52018-04-05 11:58:04 -070053#include <wlan_osif_request_manager.h>
Dustin Brown26b3d042017-12-21 11:13:27 -080054#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4bc0a622017-12-06 15:56:50 -080055#include "qdf_debug_domain.h"
Dustin Brown26b3d042017-12-21 11:13:27 -080056#endif
Dustin Brownd4241942018-02-26 12:51:37 -080057#include "qdf_str.h"
58#include "qdf_trace.h"
59#include "qdf_types.h"
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070060#include <cdp_txrx_peer_ops.h>
Dhanashri Atrea8f82f22017-01-23 12:58:24 -080061#include <cdp_txrx_misc.h>
Mohit Khannaca4173b2017-09-12 21:52:19 -070062#include <cdp_txrx_stats.h>
bings0e03a982018-05-09 08:40:59 +080063#include "cdp_txrx_flow_ctrl_legacy.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080064
65#include <net/addrconf.h>
66#include <linux/wireless.h>
67#include <net/cfg80211.h>
68#include <linux/inetdevice.h>
69#include <net/addrconf.h>
70#include "wlan_hdd_cfg80211.h"
71#include "wlan_hdd_ext_scan.h"
72#include "wlan_hdd_p2p.h"
73#include <linux/rtnetlink.h>
74#include "sap_api.h"
75#include <linux/semaphore.h>
76#include <linux/ctype.h>
77#include <linux/compat.h>
Arunk Khandavalli830c9692018-03-22 12:17:40 +053078#include <linux/reboot.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080079#ifdef MSM_PLATFORM
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080080#include <soc/qcom/subsystem_restart.h>
81#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080082#include <wlan_hdd_hostapd.h>
83#include <wlan_hdd_softap_tx_rx.h>
Jeff Johnson8bb61112018-03-31 13:33:54 -070084#include <wlan_hdd_green_ap.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080085#include "cfg_api.h"
86#include "qwlan_version.h"
87#include "wma_types.h"
88#include "wlan_hdd_tdls.h"
89#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053090#include "cds_regdomain.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080091#endif /* FEATURE_WLAN_CH_AVOID */
Dustin Brownce46d1d2017-08-15 13:34:24 -070092#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070093#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -080094#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080095#include "wlan_hdd_nan.h"
96#include "wlan_hdd_debugfs.h"
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053097#include "wlan_hdd_debugfs_csr.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080098#include "wlan_hdd_driver_ops.h"
99#include "epping_main.h"
Poddar, Siddarth34872782017-08-10 14:08:51 +0530100#include "wlan_hdd_data_stall_detection.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800101
102#include <wlan_hdd_ipa.h>
103#include "hif.h"
104#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800105#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700106#include "wlan_hdd_tsf.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530107#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700108#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700109#include "wlan_hdd_lpass.h"
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530110#include "nan_api.h"
Nachiket Kukade63bb63d2018-11-21 14:42:14 +0530111#include "wlan_nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700112#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530113#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800114#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800115#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530116#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800117#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800118#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530119#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530120#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800121#include "os_if_wifi_pos.h"
122#include "wifi_pos_api.h"
123#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800124#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700125#include "os_if_nan.h"
126#include "nan_public_structs.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700127#include "wlan_reg_ucfg_api.h"
bings81fe50a2017-11-27 14:33:26 +0800128#include "wlan_dfs_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700129#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530130#include "sme_power_save_api.h"
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +0530131#include "enet.h"
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700132#include <cdp_txrx_cmn_struct.h>
Mohit Khanna70322002018-05-15 19:21:32 -0700133#include <dp_txrx.h>
Amar Singhal0928b192017-12-01 10:50:54 -0800134#include "wlan_hdd_sysfs.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530135#include "wlan_disa_ucfg_api.h"
Wu Gao52084c12018-05-17 20:47:11 +0800136#include "wlan_disa_obj_mgmt_api.h"
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +0530137#include "wlan_action_oui_ucfg_api.h"
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +0530138#include "wlan_ipa_ucfg_api.h"
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530139#include <target_if.h>
Alok Kumarb64650c2018-03-23 17:05:11 +0530140#include "wlan_hdd_nud_tracking.h"
Nachiket Kukaded0dd62e2018-05-21 18:39:22 +0530141#include "wlan_hdd_apf.h"
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -0700142#include "wlan_hdd_twt.h"
Rachit Kankane0dc3e852018-05-07 17:33:42 +0530143#include "qc_sap_ioctl.h"
Sandeep Puligillac5609d52018-05-17 19:23:41 -0700144#include "wlan_mlme_main.h"
Wu Gaoe5689792018-07-05 19:20:13 +0800145#include "wlan_p2p_cfg_api.h"
Wu Gaobdb7f272018-07-05 19:33:26 +0800146#include "wlan_tdls_cfg_api.h"
Qiwei Caie689a262018-07-26 15:50:22 +0800147#include <wlan_hdd_rssi_monitor.h>
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +0530148#include "wlan_mlme_ucfg_api.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"
Liangwei Dong3abfe8f2018-09-20 02:25:44 -0400158#include <wlan_p2p_ucfg_api.h>
159
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800160#ifdef MODULE
161#define WLAN_MODULE_NAME module_name(THIS_MODULE)
162#else
163#define WLAN_MODULE_NAME "wlan"
164#endif
165
166#ifdef TIMER_MANAGER
167#define TIMER_MANAGER_STR " +TIMER_MANAGER"
168#else
169#define TIMER_MANAGER_STR ""
170#endif
171
172#ifdef MEMORY_DEBUG
173#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
174#else
175#define MEMORY_DEBUG_STR ""
176#endif
177
Dustin Brownc1034df2018-02-07 14:51:32 -0800178#ifdef PANIC_ON_BUG
179#define PANIC_ON_BUG_STR " +PANIC_ON_BUG"
180#else
181#define PANIC_ON_BUG_STR ""
182#endif
183
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530184bool g_is_system_reboot_triggered;
Sachin Ahujadddd2632017-03-07 19:07:24 +0530185int wlan_start_ret_val;
186static DECLARE_COMPLETION(wlan_start_comp);
187static unsigned int dev_num = 1;
188static struct cdev wlan_hdd_state_cdev;
189static struct class *class;
190static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530191#ifndef MODULE
192static struct gwlan_loader *wlan_loader;
193static ssize_t wlan_boot_cb(struct kobject *kobj,
194 struct kobj_attribute *attr,
195 const char *buf, size_t count);
196struct gwlan_loader {
197 bool loaded_state;
198 struct kobject *boot_wlan_obj;
199 struct attribute_group *attr_group;
200};
201
202static struct kobj_attribute wlan_boot_attribute =
203 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
204
205static struct attribute *attrs[] = {
206 &wlan_boot_attribute.attr,
207 NULL,
208};
209
210#define MODULE_INITIALIZED 1
Qun Zhang4a83a462018-09-11 16:28:51 +0800211
212#ifdef MULTI_IF_NAME
213#define WLAN_LOADER_NAME "boot_" MULTI_IF_NAME
214#else
215#define WLAN_LOADER_NAME "boot_wlan"
216#endif
Arun Khandavallifae92942016-08-01 13:31:08 +0530217#endif
218
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530219#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
220#define MAX_OPS_NAME_STRING_SIZE 20
Rajeev Kumar6d0b2ea2017-12-26 17:55:33 -0800221#define RATE_LIMIT_ERROR_LOG (256)
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530222
223static qdf_timer_t hdd_drv_ops_inactivity_timer;
Dustin Brown45ed4bb2017-12-18 12:00:13 -0800224static struct task_struct *hdd_drv_ops_task;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530225static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
226
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800227/* the Android framework expects this param even though we don't use it */
228#define BUF_LEN 20
229static char fwpath_buffer[BUF_LEN];
230static struct kparam_string fwpath = {
231 .string = fwpath_buffer,
232 .maxlen = BUF_LEN,
233};
234
235static char *country_code;
236static int enable_11d = -1;
237static int enable_dfs_chan_scan = -1;
238
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800239/*
240 * spinlock for synchronizing asynchronous request/response
241 * (full description of use in wlan_hdd_main.h)
242 */
243DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530244DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800245
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800246#define WLAN_NLINK_CESIUM 30
247
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530248static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800249
250#define WOW_MAX_FILTER_LISTS 1
251#define WOW_MAX_FILTERS_PER_LIST 4
252#define WOW_MIN_PATTERN_SIZE 6
253#define WOW_MAX_PATTERN_SIZE 64
254
Bala Venkatesh110b03e2018-07-10 16:02:08 +0530255/* max peer can be tdls peers + self peer + bss peer */
256#define HDD_MAX_VDEV_PEER_COUNT (HDD_MAX_NUM_TDLS_STA + 2)
Sourav Mohapatra808e3d42018-07-04 09:34:23 +0530257#define IS_IDLE_STOP (!cds_is_driver_unloading() && \
258 !cds_is_driver_recovering() && !cds_is_driver_loading())
Bala Venkatesh110b03e2018-07-10 16:02:08 +0530259
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800260#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
261static const struct wiphy_wowlan_support wowlan_support_reg_init = {
262 .flags = WIPHY_WOWLAN_ANY |
263 WIPHY_WOWLAN_MAGIC_PKT |
264 WIPHY_WOWLAN_DISCONNECT |
265 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
266 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
267 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
268 WIPHY_WOWLAN_4WAY_HANDSHAKE |
269 WIPHY_WOWLAN_RFKILL_RELEASE,
270 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
271 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
272 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
273};
274#endif
275
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700276static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
277 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
278 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
279 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
280 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
281 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
282 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
283 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
284 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
285 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
286 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
287 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
288 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
289 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
290 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
291 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
292 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
293 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
294 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
295 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
296 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
297 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
298 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
299 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
300 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
301 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
302 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
303 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
304 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
305 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
306 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
307 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
308 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
309 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
310 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700311 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700312 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700313 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530314 [QDF_MODULE_ID_GREEN_AP] = {QDF_TRACE_LEVEL_ALL},
Zhang Qian47e22ce2018-01-04 15:38:38 +0800315 [QDF_MODULE_ID_OCB] = {QDF_TRACE_LEVEL_ALL},
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530316 [QDF_MODULE_ID_IPA] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +0530317 [QDF_MODULE_ID_ACTION_OUI] = {QDF_TRACE_LEVEL_ALL},
Dustin Brown84f46ea2018-02-15 11:57:36 -0800318 [QDF_MODULE_ID_CONFIG] = {QDF_TRACE_LEVEL_ALL},
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +0530319 [QDF_MODULE_ID_MLME] = {QDF_TRACE_LEVEL_ALL},
Ashish Kumar Dhanotiya8d039c82018-07-11 20:41:14 +0530320 [QDF_MODULE_ID_TARGET] = {QDF_TRACE_LEVEL_ALL},
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -0700321 [QDF_MODULE_ID_CRYPTO] = {QDF_TRACE_LEVEL_ALL},
Sourav Mohapatra113685f2018-08-29 14:21:55 +0530322 [QDF_MODULE_ID_FWOL] = {QDF_TRACE_LEVEL_ALL},
Abhishek Singh0b0105f2018-09-25 10:44:16 +0530323 [QDF_MODULE_ID_SM_ENGINE] = {QDF_TRACE_LEVEL_ALL},
324 [QDF_MODULE_ID_CMN_MLME] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700325};
326
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530327struct notifier_block hdd_netdev_notifier;
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530328struct notifier_block system_reboot_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800329
330struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800331#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700332static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800333#endif
334
Sachin Ahujadddd2632017-03-07 19:07:24 +0530335void hdd_start_complete(int ret)
336{
337 wlan_start_ret_val = ret;
338
339 complete(&wlan_start_comp);
340}
341
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800342/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530343 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700344 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530345 *
346 * Return: none
347 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700348static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530349{
Jeff Johnson9d295242017-08-29 14:39:48 -0700350 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530351
Dustin Brown920397d2017-12-13 16:27:50 -0800352 hdd_for_each_adapter(hdd_ctx, adapter)
353 hdd_send_rps_ind(adapter);
Nirav Shahbd36b062016-07-18 11:12:59 +0530354}
355
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530356#ifdef QCA_HL_NETDEV_FLOW_CONTROL
357void wlan_hdd_mod_fc_timer(struct hdd_adapter *adapter,
358 enum netif_action_type action)
359{
360 if (!adapter->tx_flow_timer_initialized)
361 return;
362
363 if (action == WLAN_WAKE_NON_PRIORITY_QUEUE) {
364 qdf_mc_timer_stop(&adapter->tx_flow_control_timer);
365 } else if (action == WLAN_STOP_NON_PRIORITY_QUEUE) {
366 QDF_STATUS status =
367 qdf_mc_timer_start(&adapter->tx_flow_control_timer,
368 WLAN_HDD_TX_FLOW_CONTROL_OS_Q_BLOCK_TIME);
369
370 if (!QDF_IS_STATUS_SUCCESS(status))
371 hdd_err("Failed to start tx_flow_control_timer");
372 else
373 adapter->
374 hdd_stats.tx_rx_stats.txflow_timer_cnt++;
375
376 adapter->hdd_stats.tx_rx_stats.txflow_pause_cnt++;
377 adapter->hdd_stats.tx_rx_stats.is_txflow_paused = true;
378 }
379}
380#endif /* QCA_HL_NETDEV_FLOW_CONTROL */
381
Alok Kumar2fad6442018-11-08 19:19:28 +0530382#ifdef MSM_PLATFORM
383void wlan_hdd_update_tcp_rx_param(struct hdd_context *hdd_ctx, void *data)
384{
385 if (!hdd_ctx) {
386 hdd_err("HDD context is null");
387 return;
388 }
389
390 if (!data) {
391 hdd_err("Data is null");
392 return;
393 }
394 if (hdd_ctx->config->enable_tcp_param_update)
395 wlan_hdd_send_tcp_param_update_event(hdd_ctx, data, 1);
396 else
397 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
398 WLAN_SVC_WLAN_TP_IND,
399 data,
400 sizeof(struct wlan_rx_tp_data));
401}
402
403void wlan_hdd_update_tcp_tx_param(struct hdd_context *hdd_ctx, void *data)
404{
405 enum wlan_tp_level next_tx_level;
406 struct wlan_tx_tp_data *tx_tp_data;
407
408 if (!hdd_ctx) {
409 hdd_err("HDD context is null");
410 return;
411 }
412
413 if (!data) {
414 hdd_err("Data is null");
415 return;
416 }
417
418 tx_tp_data = (struct wlan_tx_tp_data *)data;
419 next_tx_level = tx_tp_data->level;
420
421 if (hdd_ctx->config->enable_tcp_param_update)
422 wlan_hdd_send_tcp_param_update_event(hdd_ctx, data, 0);
423 else
424 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
425 WLAN_SVC_WLAN_TP_TX_IND,
426 &next_tx_level,
427 sizeof(next_tx_level));
428}
429
430/**
431 * wlan_hdd_send_tcp_param_update_event() - Send vendor event to update
432 * TCP parameter through Wi-Fi HAL
433 * @hdd_ctx: Pointer to HDD context
434 * @data: Parameters to update
435 * @dir: Direction(tx/rx) to update
436 *
437 * Return: None
438 */
439void wlan_hdd_send_tcp_param_update_event(struct hdd_context *hdd_ctx,
440 void *data,
441 uint8_t dir)
442{
443 struct sk_buff *vendor_event;
444 uint32_t event_len;
445 bool tcp_limit_output = false;
446 bool tcp_del_ack_ind_enabled = false;
447 bool tcp_adv_win_scl_enabled = false;
448 enum wlan_tp_level next_tp_level = WLAN_SVC_TP_NONE;
449
450 event_len = sizeof(uint8_t) + sizeof(uint8_t) + NLMSG_HDRLEN;
451
452 if (dir == 0) /*TX Flow */ {
453 struct wlan_tx_tp_data *tx_tp_data =
454 (struct wlan_tx_tp_data *)data;
455
456 next_tp_level = tx_tp_data->level;
457
458 if (tx_tp_data->tcp_limit_output) {
459 /* TCP_LIMIT_OUTPUT_BYTES */
460 event_len += sizeof(uint32_t);
461 tcp_limit_output = true;
462 }
463 } else if (dir == 1) /* RX Flow */ {
464 struct wlan_rx_tp_data *rx_tp_data =
465 (struct wlan_rx_tp_data *)data;
466
467 next_tp_level = rx_tp_data->level;
468
469 if (rx_tp_data->rx_tp_flags & TCP_DEL_ACK_IND_MASK) {
470 event_len += sizeof(uint32_t); /* TCP_DELACK_SEG */
471 tcp_del_ack_ind_enabled = true;
472 }
473 if (rx_tp_data->rx_tp_flags & TCP_ADV_WIN_SCL_MASK) {
474 event_len += sizeof(uint32_t); /* TCP_ADV_WIN_SCALE */
475 tcp_adv_win_scl_enabled = true;
476 }
477 } else {
478 hdd_err("Invalid Direction [%d]", dir);
479 return;
480 }
481
482 vendor_event =
483 cfg80211_vendor_event_alloc(
484 hdd_ctx->wiphy,
485 NULL, event_len,
486 QCA_NL80211_VENDOR_SUBCMD_THROUGHPUT_CHANGE_EVENT_INDEX,
487 GFP_KERNEL);
488
489 if (!vendor_event) {
490 hdd_err("cfg80211_vendor_event_alloc failed");
491 return;
492 }
493
494 if (nla_put_u8(
495 vendor_event,
496 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_DIRECTION,
497 dir))
498 goto tcp_param_change_nla_failed;
499
500 if (nla_put_u8(
501 vendor_event,
502 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_THROUGHPUT_LEVEL,
503 (next_tp_level == WLAN_SVC_TP_LOW ?
504 QCA_WLAN_THROUGHPUT_LEVEL_LOW :
505 QCA_WLAN_THROUGHPUT_LEVEL_HIGH)))
506 goto tcp_param_change_nla_failed;
507
508 if (tcp_limit_output &&
509 nla_put_u32(
510 vendor_event,
511 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_TCP_LIMIT_OUTPUT_BYTES,
512 (next_tp_level == WLAN_SVC_TP_LOW ?
513 TCP_LIMIT_OUTPUT_BYTES_LOW :
514 TCP_LIMIT_OUTPUT_BYTES_HI)))
515 goto tcp_param_change_nla_failed;
516
517 if (tcp_del_ack_ind_enabled &&
518 (nla_put_u32(
519 vendor_event,
520 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_TCP_DELACK_SEG,
521 (next_tp_level == WLAN_SVC_TP_LOW ?
522 TCP_DEL_ACK_LOW : TCP_DEL_ACK_HI))))
523 goto tcp_param_change_nla_failed;
524
525 if (tcp_adv_win_scl_enabled &&
526 (nla_put_u32(
527 vendor_event,
528 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_TCP_ADV_WIN_SCALE,
529 (next_tp_level == WLAN_SVC_TP_LOW ?
530 WIN_SCALE_LOW : WIN_SCALE_HI))))
531 goto tcp_param_change_nla_failed;
532
533 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
534 return;
535
536tcp_param_change_nla_failed:
537 hdd_err("nla_put api failed");
538 kfree_skb(vendor_event);
539}
540#endif /* MSM_PLATFORM */
541
Nirav Shahbd36b062016-07-18 11:12:59 +0530542/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800543 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
544 * @vdev_id: vdev_id
545 * @action: action type
546 * @reason: reason type
547 *
548 * Return: none
549 */
550void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
551 enum netif_action_type action, enum netif_reason_type reason)
552{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700553 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700554 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800555
556 if (!hdd_ctx) {
557 hdd_err("hdd ctx is NULL");
558 return;
559 }
560 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530561 wlan_hdd_mod_fc_timer(adapter, action);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800562 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800563}
564
565/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700566 * Store WLAN driver version and timestamp info in global variables such that
567 * crash debugger can extract them from driver debug symbol and crashdump for
568 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800569 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800570#ifdef BUILD_TAG
Rajeev Kumare555e2d2018-09-17 11:52:37 -0700571uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR "; " BUILD_TAG;
Dustin Brown96cd9632017-11-13 12:45:04 -0800572#else
Rajeev Kumare555e2d2018-09-17 11:52:37 -0700573uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR;
Naveen Rawat93836252017-06-20 16:30:59 -0700574#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800575
576/**
Liangwei Dong17bf2662018-01-05 02:02:05 -0500577 * hdd_get_valid_chan() - return current chan list from regulatory.
578 * @hdd_ctx: HDD context
579 * @chan_list: buf hold returned chan list
580 * @chan_num: input buf size and output returned chan num
581 *
582 * This function helps get current available chan list from regulatory
583 * module. It excludes the "disabled" and "invalid" channels.
584 *
585 * Return: 0 for success.
586 */
587static int hdd_get_valid_chan(struct hdd_context *hdd_ctx,
588 uint8_t *chan_list,
589 uint32_t *chan_num)
590{
591 int i = 0, j = 0;
592 struct regulatory_channel *cur_chan_list;
593 struct wlan_objmgr_pdev *pdev;
594
Dustin Brown07901ec2018-09-07 11:02:41 -0700595 if (!hdd_ctx || !hdd_ctx->pdev || !chan_list || !chan_num)
Liangwei Dong17bf2662018-01-05 02:02:05 -0500596 return -EINVAL;
597
Dustin Brown07901ec2018-09-07 11:02:41 -0700598 pdev = hdd_ctx->pdev;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500599 cur_chan_list = qdf_mem_malloc(NUM_CHANNELS *
600 sizeof(struct regulatory_channel));
601 if (!cur_chan_list)
602 return -ENOMEM;
603
604 if (wlan_reg_get_current_chan_list(pdev, cur_chan_list) !=
605 QDF_STATUS_SUCCESS) {
606 qdf_mem_free(cur_chan_list);
607 return -EINVAL;
608 }
609
610 for (i = 0; i < NUM_CHANNELS; i++) {
611 uint32_t ch = cur_chan_list[i].chan_num;
612 enum channel_state state = wlan_reg_get_channel_state(pdev,
613 ch);
614
615 if (state != CHANNEL_STATE_DISABLE &&
616 state != CHANNEL_STATE_INVALID &&
617 j < *chan_num) {
618 chan_list[j] = (uint8_t)ch;
619 j++;
620 }
621 }
622 *chan_num = j;
623 qdf_mem_free(cur_chan_list);
624 return 0;
625}
626
627/**
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530628 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
629 * @adapter: HDD adapter
630 * @chan_number: Channel number
631 * @chan_bw: Bandwidth
632 *
633 * Checks if the given bandwidth is valid for the given channel number.
634 *
635 * Return: 0 for success, non-zero for failure
636 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700637int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530638 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800639 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530640{
Liangwei Dong17bf2662018-01-05 02:02:05 -0500641 uint8_t chan[NUM_CHANNELS];
642 uint32_t len = NUM_CHANNELS, i;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530643 bool found = false;
Jeff Johnson16528362018-06-14 12:34:16 -0700644 mac_handle_t mac_handle;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500645 int ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530646
Jeff Johnson16528362018-06-14 12:34:16 -0700647 mac_handle = hdd_adapter_get_mac_handle(adapter);
648 if (!mac_handle) {
649 hdd_err("Invalid MAC handle");
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530650 return -EINVAL;
651 }
652
Liangwei Dong17bf2662018-01-05 02:02:05 -0500653 ret = hdd_get_valid_chan(adapter->hdd_ctx, chan,
654 &len);
655 if (ret) {
656 hdd_err("error %d in getting valid channel list", ret);
657 return ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530658 }
659
660 for (i = 0; i < len; i++) {
661 if (chan[i] == chan_number) {
662 found = true;
663 break;
664 }
665 }
666
667 if (found == false) {
668 hdd_err("Channel not in driver's valid channel list");
669 return -EOPNOTSUPP;
670 }
671
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700672 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
673 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530674 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
675 return -EINVAL;
676 }
677
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700678 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530679 if (chan_bw == CH_WIDTH_80MHZ) {
680 hdd_err("BW80 not possible in 2.4GHz band");
681 return -EINVAL;
682 }
683 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
684 (chan_bw != CH_WIDTH_MAX)) {
685 hdd_err("Only BW20 possible on channel 14");
686 return -EINVAL;
687 }
688 }
689
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700690 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530691 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
692 (chan_bw != CH_WIDTH_MAX)) {
693 hdd_err("Only BW20 possible on channel 165");
694 return -EINVAL;
695 }
696 }
697
698 return 0;
699}
700
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530701/**
702 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
703 *
704 * Block the unloading of the driver (or) interface up until the
705 * cds recovery is completed
706 *
707 * Return: true for recovery completion else false
708 */
709static bool hdd_wait_for_recovery_completion(void)
710{
711 int retry = 0;
712
713 /* Wait for recovery to complete */
714 while (cds_is_driver_recovering()) {
715 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
716 hdd_err("Recovery in progress; wait here!!!");
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530717
718 if (g_is_system_reboot_triggered) {
719 hdd_info("System Reboot happening ignore unload!!");
720 return false;
721 }
722
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530723 msleep(1000);
724 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
725 hdd_err("SSR never completed, error");
726 /*
727 * Trigger the bug_on in the internal builds, in the
728 * customer builds self-recovery will be enabled
729 * in those cases just return error.
730 */
731 if (cds_is_self_recovery_enabled())
732 return false;
733 QDF_BUG(0);
734 }
735 }
736
737 hdd_info("Recovery completed successfully!");
738 return true;
739}
740
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530741
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800742static int __hdd_netdev_notifier_call(struct notifier_block *nb,
743 unsigned long state, void *data)
744{
745#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
746 struct netdev_notifier_info *dev_notif_info = data;
747 struct net_device *dev = dev_notif_info->dev;
748#else
749 struct net_device *dev = data;
750#endif
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530751 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700752 struct hdd_context *hdd_ctx;
Min Liu8c5d99e2018-09-10 17:18:44 +0800753 struct wlan_objmgr_vdev *vdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800754
Dustin Brownfdf17c12018-03-14 12:55:34 -0700755 hdd_enter_dev(dev);
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800756
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800757 if (!dev->ieee80211_ptr) {
Dustin Brownaeb55642018-07-30 17:20:32 -0700758 hdd_debug("ieee80211_ptr is null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800759 return NOTIFY_DONE;
760 }
761
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530762 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
763 if (!hdd_ctx) {
764 hdd_err("HDD Context is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800765 return NOTIFY_DONE;
766 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800767
768 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -0700769 hdd_debug("%s: Driver module is closed", __func__);
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800770 return NOTIFY_DONE;
771 }
772
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530773 /* Make sure that this callback corresponds to our device. */
774 adapter = hdd_get_adapter_by_iface_name(hdd_ctx, dev->name);
775 if (!adapter) {
Dustin Brownaeb55642018-07-30 17:20:32 -0700776 hdd_debug("failed to look up adapter for '%s'", dev->name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800777 return NOTIFY_DONE;
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530778 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800779
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530780 if (adapter != WLAN_HDD_GET_PRIV_PTR(dev)) {
781 hdd_err("HDD adapter mismatch!");
782 return NOTIFY_DONE;
783 }
784
Dustin Brownaeb55642018-07-30 17:20:32 -0700785 if (cds_is_driver_recovering()) {
786 hdd_debug("Driver is recovering");
787 return NOTIFY_DONE;
788 }
789
790 if (cds_is_driver_in_bad_state()) {
791 hdd_debug("Driver is in failed recovery state");
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530792 return NOTIFY_DONE;
793 }
794
795 hdd_debug("%s New Net Device State = %lu", dev->name, state);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800796
797 switch (state) {
798 case NETDEV_REGISTER:
799 break;
800
801 case NETDEV_UNREGISTER:
802 break;
803
804 case NETDEV_UP:
Jeff Johnson16528362018-06-14 12:34:16 -0700805 sme_ch_avoid_update_req(hdd_ctx->mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800806 break;
807
808 case NETDEV_DOWN:
809 break;
810
811 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700812 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800813 complete(&adapter->linkup_event_var);
814 break;
815
816 case NETDEV_GOING_DOWN:
Min Liu8c5d99e2018-09-10 17:18:44 +0800817 vdev = hdd_objmgr_get_vdev(adapter);
818 if (!vdev)
819 break;
820 if (ucfg_scan_get_vdev_status(vdev) !=
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700821 SCAN_NOT_IN_PROGRESS) {
Dustin Brown07901ec2018-09-07 11:02:41 -0700822 wlan_abort_scan(hdd_ctx->pdev, INVAL_PDEV_ID,
823 adapter->session_id, INVALID_SCAN_ID,
824 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800825 }
Min Liu8c5d99e2018-09-10 17:18:44 +0800826 hdd_objmgr_put_vdev(adapter);
Min Liu9be5d4a2018-05-17 11:51:53 +0800827 cds_flush_work(&adapter->scan_block_work);
828 /* Need to clean up blocked scan request */
829 wlan_hdd_cfg80211_scan_block_cb(&adapter->scan_block_work);
Min Liu9be5d4a2018-05-17 11:51:53 +0800830 hdd_debug("Scan is not Pending from user");
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530831 /*
832 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
833 * of return status of hdd_stop call, kernel resets the IFF_UP
834 * flag after which driver does not send the cfg80211_scan_done.
835 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
836 */
Dustin Brown07901ec2018-09-07 11:02:41 -0700837 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800838 break;
839
840 default:
841 break;
842 }
843
844 return NOTIFY_DONE;
845}
846
847/**
848 * hdd_netdev_notifier_call() - netdev notifier callback function
849 * @nb: pointer to notifier block
850 * @state: state
851 * @ndev: ndev pointer
852 *
853 * Return: 0 on success, error number otherwise.
854 */
855static int hdd_netdev_notifier_call(struct notifier_block *nb,
856 unsigned long state,
857 void *ndev)
858{
859 int ret;
860
861 cds_ssr_protect(__func__);
862 ret = __hdd_netdev_notifier_call(nb, state, ndev);
863 cds_ssr_unprotect(__func__);
864
865 return ret;
866}
867
868struct notifier_block hdd_netdev_notifier = {
869 .notifier_call = hdd_netdev_notifier_call,
870};
871
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530872static int system_reboot_notifier_call(struct notifier_block *nb,
873 unsigned long msg_type, void *_unused)
874{
875 switch (msg_type) {
876 case SYS_DOWN:
877 case SYS_HALT:
878 case SYS_POWER_OFF:
879 g_is_system_reboot_triggered = true;
880 hdd_info("reboot, reason: %ld", msg_type);
881 break;
882 default:
883 break;
884 }
885
886 return NOTIFY_OK;
887}
888
889struct notifier_block system_reboot_notifier = {
890 .notifier_call = system_reboot_notifier_call,
891};
892
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800893/* variable to hold the insmod parameters */
894static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800895
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530896static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700897int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530898
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800899/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800900static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800901
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530902/**
903 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
904 * @ch_width: NL channel width
905 *
906 * Converts the NL channel width to the driver's internal representation
907 *
908 * Return: Converted channel width. In case of non matching NL channel width,
909 * CH_WIDTH_MAX will be returned.
910 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800911enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530912{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800913 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700914
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800915 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530916 switch (ch_width) {
917 case NL80211_CHAN_WIDTH_20_NOHT:
918 case NL80211_CHAN_WIDTH_20:
919 return CH_WIDTH_20MHZ;
920 case NL80211_CHAN_WIDTH_40:
921 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530922 case NL80211_CHAN_WIDTH_80:
923 return CH_WIDTH_80MHZ;
924 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800925 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
926 return CH_WIDTH_80P80MHZ;
927 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
928 return CH_WIDTH_160MHZ;
929 else
930 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530931 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800932 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
933 return CH_WIDTH_160MHZ;
934 else
935 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530936 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800937 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530938 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800939 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530940 default:
941 hdd_err("Invalid channel width %d, setting to default",
942 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800943 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530944 }
945}
946
Dustin Brown56377e12018-10-10 17:04:04 -0700947QDF_STATUS hdd_nl_to_qdf_iface_type(enum nl80211_iftype nl_type,
948 enum QDF_OPMODE *out_qdf_type)
949{
950 switch (nl_type) {
951 case NL80211_IFTYPE_ADHOC:
952 *out_qdf_type = QDF_IBSS_MODE;
953 break;
954 case NL80211_IFTYPE_AP:
955 *out_qdf_type = QDF_SAP_MODE;
956 break;
957 case NL80211_IFTYPE_MONITOR:
958 *out_qdf_type = QDF_MONITOR_MODE;
959 break;
960 case NL80211_IFTYPE_OCB:
961 *out_qdf_type = QDF_OCB_MODE;
962 break;
963 case NL80211_IFTYPE_P2P_CLIENT:
964 *out_qdf_type = QDF_P2P_CLIENT_MODE;
965 break;
966 case NL80211_IFTYPE_P2P_DEVICE:
967 *out_qdf_type = QDF_P2P_DEVICE_MODE;
968 break;
969 case NL80211_IFTYPE_P2P_GO:
970 *out_qdf_type = QDF_P2P_GO_MODE;
971 break;
972 case NL80211_IFTYPE_STATION:
973 *out_qdf_type = QDF_STA_MODE;
974 break;
975 case NL80211_IFTYPE_WDS:
976 *out_qdf_type = QDF_WDS_MODE;
977 break;
978 default:
979 hdd_err("Invalid nl80211 interface type %d", nl_type);
980 return QDF_STATUS_E_INVAL;
981 }
982
983 return QDF_STATUS_SUCCESS;
984}
985
Jeff Johnson16528362018-06-14 12:34:16 -0700986uint8_t wlan_hdd_find_opclass(mac_handle_t mac_handle, uint8_t channel,
987 uint8_t bw_offset)
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530988{
989 uint8_t opclass = 0;
990
Jeff Johnson16528362018-06-14 12:34:16 -0700991 sme_get_opclass(mac_handle, channel, bw_offset, &opclass);
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530992 return opclass;
993}
994
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800995/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530996 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530997 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800998 * @bitmask: Bitmask of log levels to be enabled
999 *
1000 * Called immediately after the cfg.ini is read in order to configure
1001 * the desired trace levels.
1002 *
1003 * Return: None
1004 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301005int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001006{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301007 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05301008 int qdf_print_idx = -1;
1009 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001010 /*
1011 * if the bitmask is the default value, then a bitmask was not
1012 * specified in cfg.ini, so leave the logging level alone (it
1013 * will remain at the "compiled in" default value)
1014 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001015 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301016 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001017
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05301018 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001019
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05301020 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301021 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05301022 QDF_TRACE_LEVEL_NONE, 0);
1023
1024 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301025 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001026 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +05301027 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001028 while (0 != bitmask) {
1029 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05301030 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301031 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05301032 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301033 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001034 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001035
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001036 level++;
1037 bitmask >>= 1;
1038 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301039 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001040}
1041
Dustin Brownda351e32018-07-23 15:48:22 -07001042int __wlan_hdd_validate_context(struct hdd_context *hdd_ctx, const char *func)
Chris Guo1751acf2017-07-03 14:09:01 +08001043{
Dustin Brownda351e32018-07-23 15:48:22 -07001044 if (!hdd_ctx) {
1045 hdd_err("HDD context is null (via %s)", func);
1046 return -ENODEV;
1047 }
1048
1049 if (!hdd_ctx->config) {
1050 hdd_err("HDD config is null (via %s)", func);
Chris Guo1751acf2017-07-03 14:09:01 +08001051 return -ENODEV;
1052 }
1053
1054 if (cds_is_driver_recovering()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001055 hdd_debug("Recovery in progress (via %s); state:0x%x",
1056 func, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001057 return -EAGAIN;
1058 }
1059
Yue Ma9f275d92017-09-14 16:58:41 -07001060 if (cds_is_load_or_unload_in_progress()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001061 hdd_debug("Load/unload in progress (via %s); state:0x%x",
1062 func, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001063 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -07001064 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05301065
Dustin Brownda351e32018-07-23 15:48:22 -07001066 if (hdd_ctx->start_modules_in_progress) {
1067 hdd_debug("Start modules in progress (via %s)", func);
1068 return -EAGAIN;
1069 }
1070
1071 if (hdd_ctx->stop_modules_in_progress) {
1072 hdd_debug("Stop modules in progress (via %s)", func);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05301073 return -EAGAIN;
1074 }
1075
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301076 if (cds_is_driver_in_bad_state()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001077 hdd_debug("Driver in bad state (via %s); state:0x%x",
1078 func, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +05301079 return -EAGAIN;
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301080 }
1081
Arunk Khandavalli2859fa12018-02-14 10:46:26 +05301082 if (cds_is_fw_down()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001083 hdd_debug("FW is down (via %s); state:0x%x",
1084 func, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +05301085 return -EAGAIN;
Arunk Khandavalli2859fa12018-02-14 10:46:26 +05301086 }
1087
Liangwei Dong858feb12018-05-21 01:52:46 -04001088 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
Dustin Brownda351e32018-07-23 15:48:22 -07001089 hdd_debug("Driver mode change in progress (via %s)", func);
Liangwei Dong858feb12018-05-21 01:52:46 -04001090 return -EAGAIN;
1091 }
1092
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001093 return 0;
1094}
1095
Dustin Browna8700cc2018-08-07 12:04:47 -07001096int __hdd_validate_adapter(struct hdd_adapter *adapter, const char *func)
Dustin Brownf13b8c32017-05-19 17:23:08 -07001097{
1098 if (!adapter) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001099 hdd_err("adapter is null (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001100 return -EINVAL;
1101 }
1102
1103 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001104 hdd_err("bad adapter magic (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001105 return -EINVAL;
1106 }
1107
1108 if (!adapter->dev) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001109 hdd_err("adapter net_device is null (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001110 return -EINVAL;
1111 }
1112
1113 if (!(adapter->dev->flags & IFF_UP)) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001114 hdd_debug_rl("adapter '%s' is not up (via %s)",
1115 adapter->dev->name, func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001116 return -EAGAIN;
1117 }
1118
Dustin Browna8700cc2018-08-07 12:04:47 -07001119 return __wlan_hdd_validate_session_id(adapter->session_id, func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001120}
1121
Dustin Brown63500612018-08-07 11:36:09 -07001122int __wlan_hdd_validate_session_id(uint8_t session_id, const char *func)
1123{
1124 if (session_id == CSR_SESSION_ID_INVALID) {
1125 hdd_debug_rl("adapter is not up (via %s)", func);
1126 return -EINVAL;
1127 }
1128
1129 if (session_id >= CSR_ROAM_SESSION_MAX) {
1130 hdd_err("bad session Id:%u (via %s)", session_id, func);
1131 return -EINVAL;
1132 }
1133
1134 return 0;
1135}
1136
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05301137QDF_STATUS __wlan_hdd_validate_mac_address(struct qdf_mac_addr *mac_addr,
1138 const char *func)
1139{
1140 if (!mac_addr) {
1141 hdd_err("Received NULL mac address (via %s)", func);
1142 return QDF_STATUS_E_INVAL;
1143 }
1144
1145 if (qdf_is_macaddr_zero(mac_addr)) {
1146 hdd_err("MAC is all zero (via %s)", func);
1147 return QDF_STATUS_E_INVAL;
1148 }
1149
1150 if (qdf_is_macaddr_broadcast(mac_addr)) {
1151 hdd_err("MAC is Broadcast (via %s)", func);
1152 return QDF_STATUS_E_INVAL;
1153 }
1154
1155 if (QDF_NET_IS_MAC_MULTICAST(mac_addr->bytes)) {
1156 hdd_err("MAC is Multicast (via %s)", func);
1157 return QDF_STATUS_E_INVAL;
1158 }
1159
1160 return QDF_STATUS_SUCCESS;
1161}
1162
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001163/**
Arun Khandavallica892f62017-05-26 14:25:50 +05301164 * wlan_hdd_validate_modules_state() - Check modules status
1165 * @hdd_ctx: HDD context pointer
1166 *
1167 * Check's the driver module's state and returns true if the
1168 * modules are enabled returns false if modules are closed.
1169 *
1170 * Return: True if modules are enabled or false.
1171 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001172bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +05301173{
1174 mutex_lock(&hdd_ctx->iface_change_lock);
1175 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
1176 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown5e89ef82018-03-14 11:50:23 -07001177 hdd_info("Modules not enabled, Present status: %d",
1178 hdd_ctx->driver_status);
Arun Khandavallica892f62017-05-26 14:25:50 +05301179 return false;
1180 }
1181 mutex_unlock(&hdd_ctx->iface_change_lock);
1182 return true;
1183}
1184
1185/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001186 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -07001187 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001188 *
1189 * This function sets the IBSS power save config parameters to WMA
1190 * which will send it to firmware if FW supports IBSS power save
1191 * before vdev start.
1192 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301193 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001194 * on failure.
1195 */
Jeff Johnson9d295242017-08-29 14:39:48 -07001196QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001197{
1198 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001199 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001200
1201 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001202 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301203 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001204 }
1205
Jeff Johnson1b780e42017-10-31 14:11:45 -07001206 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001207 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
1208 hdd_ctx->config->ibssATIMWinSize,
1209 VDEV_CMD);
1210 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001211 hdd_err("atim window set failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301212 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001213 }
1214
Jeff Johnson1b780e42017-10-31 14:11:45 -07001215 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001216 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
1217 hdd_ctx->config->isIbssPowerSaveAllowed,
1218 VDEV_CMD);
1219 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001220 hdd_err("power save allow failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001221 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301222 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001223 }
1224
Jeff Johnson1b780e42017-10-31 14:11:45 -07001225 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001226 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
1227 hdd_ctx->config->
1228 isIbssPowerCollapseAllowed, VDEV_CMD);
1229 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001230 hdd_err("power collapse allow failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001231 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301232 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001233 }
1234
Jeff Johnson1b780e42017-10-31 14:11:45 -07001235 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001236 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
1237 hdd_ctx->config->isIbssAwakeOnTxRx,
1238 VDEV_CMD);
1239 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001240 hdd_err("set awake on tx/rx failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301241 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001242 }
1243
Jeff Johnson1b780e42017-10-31 14:11:45 -07001244 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001245 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
1246 hdd_ctx->config->ibssInactivityCount,
1247 VDEV_CMD);
1248 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001249 hdd_err("set inactivity time failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301250 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001251 }
1252
Jeff Johnson1b780e42017-10-31 14:11:45 -07001253 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001254 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
1255 hdd_ctx->config->ibssTxSpEndInactivityTime,
1256 VDEV_CMD);
1257 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001258 hdd_err("set txsp end failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001259 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301260 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001261 }
1262
Jeff Johnson1b780e42017-10-31 14:11:45 -07001263 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001264 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
1265 hdd_ctx->config->ibssPsWarmupTime,
1266 VDEV_CMD);
1267 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001268 hdd_err("set ps warmup failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001269 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301270 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001271 }
1272
Jeff Johnson1b780e42017-10-31 14:11:45 -07001273 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001274 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
1275 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
1276 VDEV_CMD);
1277 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001278 hdd_err("set 1rx chain atim failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001279 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301280 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001281 }
1282
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301283 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001284}
1285
Yue Macd359b72017-10-03 15:21:00 -07001286#ifdef FEATURE_RUNTIME_PM
1287/**
1288 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
1289 * @hdd_ctx: HDD context
1290 *
1291 * Return: None
1292 */
1293static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
1294{
1295 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1296
Yue Macd359b72017-10-03 15:21:00 -07001297 qdf_runtime_lock_init(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001298 qdf_runtime_lock_init(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001299
Dustin Brown07901ec2018-09-07 11:02:41 -07001300 wlan_scan_runtime_pm_init(hdd_ctx->pdev);
Yue Macd359b72017-10-03 15:21:00 -07001301}
1302
1303/**
1304 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1305 * @hdd_ctx: HDD Context
1306 *
1307 * Return: None
1308 */
1309static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1310{
1311 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1312
Yue Macd359b72017-10-03 15:21:00 -07001313 qdf_runtime_lock_deinit(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001314 qdf_runtime_lock_deinit(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001315
Dustin Brown07901ec2018-09-07 11:02:41 -07001316 wlan_scan_runtime_pm_deinit(hdd_ctx->pdev);
Yue Macd359b72017-10-03 15:21:00 -07001317}
1318
Yue Macd359b72017-10-03 15:21:00 -07001319#else /* FEATURE_RUNTIME_PM */
1320static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1321static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Yue Macd359b72017-10-03 15:21:00 -07001322#endif /* FEATURE_RUNTIME_PM */
1323
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001324#define INTF_MACADDR_MASK 0x7
1325
1326/**
1327 * hdd_update_macaddr() - update mac address
1328 * @config: hdd configuration
1329 * @hw_macaddr: mac address
1330 *
1331 * Mac address for multiple virtual interface is found as following
1332 * i) The mac address of the first interface is just the actual hw mac address.
1333 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
1334 * define the mac address for the remaining interfaces and locally
1335 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1336 * supported virtual interfaces, right now this is 0x07 (meaning 8
1337 * interface).
1338 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1339 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1340 *
1341 * Return: None
1342 */
1343void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301344 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001345{
1346 int8_t i;
1347 uint8_t macaddr_b3, tmp_br3;
1348
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301349 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301350 QDF_MAC_ADDR_SIZE);
1351 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301352 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301353 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001354 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1355 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1356 INTF_MACADDR_MASK;
1357 macaddr_b3 += tmp_br3;
1358
1359 /* XOR-ing bit-24 of the mac address. This will give enough
1360 * mac address range before collision
1361 */
1362 macaddr_b3 ^= (1 << 7);
1363
1364 /* Set locally administered bit */
1365 config->intfMacAddr[i].bytes[0] |= 0x02;
1366 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001367 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001368 MAC_ADDRESS_STR, i,
1369 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1370 }
1371}
1372
Kabilan Kannan44a58372017-12-06 18:16:11 -08001373static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1374{
Dustin Brown1dbefe62018-09-11 16:32:03 -07001375 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001376 struct tdls_start_params tdls_cfg;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001377 QDF_STATUS status;
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301378 struct wlan_mlme_nss_chains vdev_ini_cfg;
1379
1380 /* Populate the nss chain params from ini for this vdev type */
1381 sme_populate_nss_chain_params(hdd_ctx->mac_handle, &vdev_ini_cfg,
1382 QDF_TDLS_MODE,
1383 hdd_ctx->num_rf_chains);
Kabilan Kannan44a58372017-12-06 18:16:11 -08001384
Dustin Brown1dbefe62018-09-11 16:32:03 -07001385 cfg_tdls_set_vdev_nss_2g(hdd_ctx->psoc,
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301386 vdev_ini_cfg.rx_nss[NSS_CHAINS_BAND_2GHZ]);
Dustin Brown1dbefe62018-09-11 16:32:03 -07001387 cfg_tdls_set_vdev_nss_5g(hdd_ctx->psoc,
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301388 vdev_ini_cfg.rx_nss[NSS_CHAINS_BAND_5GHZ]);
jiad7b8a5e02018-11-26 16:37:57 +08001389 hdd_init_tdls_config(&tdls_cfg);
Kabilan Kannan44a58372017-12-06 18:16:11 -08001390 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1391 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1392 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1393 tdls_cfg.tdls_evt_cb_data = psoc;
Jeff Johnson1d40f5b2018-03-02 08:35:53 -08001394 tdls_cfg.tdls_peer_context = hdd_ctx;
1395 tdls_cfg.tdls_reg_peer = hdd_tdls_register_peer;
1396 tdls_cfg.tdls_dereg_peer = hdd_tdls_deregister_peer;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001397 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1398 tdls_cfg.tdls_wmm_cb_data = psoc;
1399 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1400 tdls_cfg.tdls_rx_cb_data = psoc;
1401 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1402
1403 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1404 if (status != QDF_STATUS_SUCCESS) {
1405 hdd_err("failed pmo psoc configuration");
1406 return -EINVAL;
1407 }
1408
1409 hdd_ctx->tdls_umac_comp_active = true;
1410 /* enable napier specific tdls data path */
1411 hdd_ctx->tdls_nap_active = true;
1412
1413 return 0;
1414}
1415
Wu Gaoca416ff2018-09-17 11:05:07 +08001416#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1417static void hdd_update_roam_offload(struct hdd_context *hdd_ctx,
1418 struct wma_tgt_services *cfg)
1419{
1420 bool roam_offload_enable;
1421
Dustin Brown1dbefe62018-09-11 16:32:03 -07001422 ucfg_mlme_get_roaming_offload(hdd_ctx->psoc, &roam_offload_enable);
1423 ucfg_mlme_set_roaming_offload(hdd_ctx->psoc,
Wu Gaoca416ff2018-09-17 11:05:07 +08001424 roam_offload_enable &
1425 cfg->en_roam_offload);
1426}
1427#else
1428static inline void hdd_update_roam_offload(struct hdd_context *hdd_ctx,
1429 struct wma_tgt_services *cfg)
1430{
1431}
1432#endif
1433
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001434static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001435 struct wma_tgt_services *cfg)
1436{
1437 struct hdd_config *config = hdd_ctx->config;
Wu Gao66454f12018-09-26 19:55:41 +08001438 bool arp_offload_enable;
Wu Gao1ab05582018-11-08 16:22:49 +08001439 bool mawc_enabled;
Wu Gaobdb7f272018-07-05 19:33:26 +08001440#ifdef FEATURE_WLAN_TDLS
1441 bool tdls_support;
1442 bool tdls_off_channel;
1443 bool tdls_buffer_sta;
1444 uint32_t tdls_uapsd_mask;
1445#endif
jiad7b8a5e02018-11-26 16:37:57 +08001446 bool value;
1447
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001448 /* Set up UAPSD */
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05301449 ucfg_mlme_set_sap_uapsd_flag(hdd_ctx->psoc, cfg->uapsd);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001450
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001451 /* 11AX mode support */
1452 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1453 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1454 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1455
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001456 /* 11AC mode support */
1457 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1458 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1459 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001460
1461 /* ARP offload: override user setting if invalid */
Wu Gao66454f12018-09-26 19:55:41 +08001462 arp_offload_enable =
1463 ucfg_pmo_is_arp_offload_enabled(hdd_ctx->psoc);
1464 ucfg_pmo_set_arp_offload_enabled(hdd_ctx->psoc,
1465 arp_offload_enable & cfg->arp_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001466#ifdef FEATURE_WLAN_SCAN_PNO
1467 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001468 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001469 if (cfg->pno_offload)
1470 config->PnoOffload = true;
1471#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001472#ifdef FEATURE_WLAN_TDLS
Dustin Brown1dbefe62018-09-11 16:32:03 -07001473 cfg_tdls_get_support_enable(hdd_ctx->psoc, &tdls_support);
1474 cfg_tdls_set_support_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001475 tdls_support & cfg->en_tdls);
1476
Dustin Brown1dbefe62018-09-11 16:32:03 -07001477 cfg_tdls_get_off_channel_enable(hdd_ctx->psoc, &tdls_off_channel);
1478 cfg_tdls_set_off_channel_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001479 tdls_off_channel &&
1480 cfg->en_tdls_offchan);
1481
Dustin Brown1dbefe62018-09-11 16:32:03 -07001482 cfg_tdls_get_buffer_sta_enable(hdd_ctx->psoc, &tdls_buffer_sta);
1483 cfg_tdls_set_buffer_sta_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001484 tdls_buffer_sta &&
1485 cfg->en_tdls_uapsd_buf_sta);
1486
Dustin Brown1dbefe62018-09-11 16:32:03 -07001487 cfg_tdls_get_uapsd_mask(hdd_ctx->psoc, &tdls_uapsd_mask);
Wu Gaobdb7f272018-07-05 19:33:26 +08001488 if (tdls_uapsd_mask && cfg->en_tdls_uapsd_sleep_sta)
Dustin Brown1dbefe62018-09-11 16:32:03 -07001489 cfg_tdls_set_sleep_sta_enable(hdd_ctx->psoc, true);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001490 else
Dustin Brown1dbefe62018-09-11 16:32:03 -07001491 cfg_tdls_set_sleep_sta_enable(hdd_ctx->psoc, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001492#endif
Wu Gaoca416ff2018-09-17 11:05:07 +08001493 hdd_update_roam_offload(hdd_ctx, cfg);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05301494
Dustin Brown05d81302018-09-11 16:49:22 -07001495 if (ucfg_mlme_get_sap_get_peer_info(hdd_ctx->psoc, &value) ==
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05301496 QDF_STATUS_SUCCESS)
1497 value &= cfg->get_peer_info_enabled;
1498
Wu Gao1ab05582018-11-08 16:22:49 +08001499 ucfg_mlme_is_mawc_enabled(hdd_ctx->psoc, &mawc_enabled);
1500 ucfg_mlme_set_mawc_enabled(hdd_ctx->psoc,
1501 mawc_enabled & cfg->is_fw_mawc_capable);
Kabilan Kannan44a58372017-12-06 18:16:11 -08001502 hdd_update_tdls_config(hdd_ctx);
Jeff Johnson16528362018-06-14 12:34:16 -07001503 sme_update_tgt_services(hdd_ctx->mac_handle, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001504}
1505
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001506/**
1507 * hdd_update_vdev_nss() - sets the vdev nss
1508 * @hdd_ctx: HDD context
1509 *
1510 * Sets the Nss per vdev type based on INI
1511 *
1512 * Return: None
1513 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001514static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001515{
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001516 uint8_t max_supp_nss = 1;
Jeff Johnson16528362018-06-14 12:34:16 -07001517 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301518 QDF_STATUS status;
1519 bool bval;
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001520
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301521 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
1522 if (!QDF_IS_STATUS_SUCCESS(status))
1523 hdd_err("unable to get vht_enable2x2");
1524
1525 if (bval && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001526 max_supp_nss = 2;
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301527
1528 hdd_debug("max nss %d", max_supp_nss);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001529
Jeff Johnson16528362018-06-14 12:34:16 -07001530 mac_handle = hdd_ctx->mac_handle;
1531 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301532 NSS_CHAINS_BAND_2GHZ);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001533
Jeff Johnson16528362018-06-14 12:34:16 -07001534 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301535 NSS_CHAINS_BAND_5GHZ);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001536}
1537
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301538/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301539 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1540 * @hdd_ctx: HDD context
1541 *
1542 * Updates wiphy vhtcap fields
1543 *
1544 * Return: None
1545 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001546static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301547{
1548 struct ieee80211_supported_band *band_5g =
1549 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301550 QDF_STATUS status;
1551 uint8_t value = 0, value1 = 0;
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301552
1553 if (!band_5g) {
1554 hdd_debug("5GHz band disabled, skipping capability population");
1555 return;
1556 }
1557
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301558 status = ucfg_mlme_cfg_get_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
1559 &value);
1560 if (!QDF_IS_STATUS_SUCCESS(status))
1561 hdd_err("unable to get tx_bfee_ant_supp");
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301562
Abhinav Kumare057b412018-10-09 17:28:16 +05301563 band_5g->vht_cap.cap |=
1564 (value << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301565
1566 value1 = NUM_OF_SOUNDING_DIMENSIONS;
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301567 band_5g->vht_cap.cap |=
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301568 (value1 << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301569
Dustin Brown7e761c72018-07-31 13:50:17 -07001570 hdd_debug("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301571 band_5g->vht_cap.cap, value, value1);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301572}
1573
1574/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301575 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1576 * @hdd_ctx: HDD context
1577 *
1578 * Sets the DBS capability as per INI and firmware capability
1579 *
1580 * Return: None
1581 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001582static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301583{
1584 struct hdd_config *cfg_ini = hdd_ctx->config;
1585 uint8_t hw_dbs_capable = 0;
1586
Dustin Brown1dbefe62018-09-11 16:32:03 -07001587 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->psoc) &&
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001588 ((cfg_ini->dual_mac_feature_disable ==
1589 ENABLE_DBS_CXN_AND_SCAN) ||
1590 (cfg_ini->dual_mac_feature_disable ==
Tushnim Bhattacharyyaaececb22018-08-06 14:27:46 -07001591 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF) ||
1592 (cfg_ini->dual_mac_feature_disable ==
1593 ENABLE_DBS_CXN_AND_DISABLE_SIMULTANEOUS_SCAN)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301594 hw_dbs_capable = 1;
1595
Jeff Johnson16528362018-06-14 12:34:16 -07001596 sme_update_hw_dbs_capable(hdd_ctx->mac_handle, hw_dbs_capable);
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301597}
1598
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001599static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001600 struct wma_tgt_ht_cap *cfg)
1601{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301602 QDF_STATUS status;
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301603 qdf_size_t value_len;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301604 uint32_t value;
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05301605 uint8_t mpdu_density;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301606 struct mlme_ht_capabilities_info ht_cap_info;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001607 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301608 bool b_enable1x1;
Jeff Johnson16528362018-06-14 12:34:16 -07001609
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001610 /* get the MPDU density */
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05301611 status = ucfg_mlme_get_ht_mpdu_density(hdd_ctx->psoc, &mpdu_density);
1612 if (QDF_IS_STATUS_ERROR(status)) {
1613 hdd_err("could not get HT MPDU Density");
1614 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001615 }
1616
1617 /*
1618 * MPDU density:
1619 * override user's setting if value is larger
1620 * than the one supported by target
1621 */
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05301622 if (mpdu_density > cfg->mpdu_density) {
1623 status = ucfg_mlme_set_ht_mpdu_density(hdd_ctx->psoc,
1624 cfg->mpdu_density);
1625 if (QDF_IS_STATUS_ERROR(status))
1626 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001627 }
1628
1629 /* get the HT capability info */
Dustin Brown1dbefe62018-09-11 16:32:03 -07001630 status = ucfg_mlme_get_ht_cap_info(hdd_ctx->psoc, &ht_cap_info);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301631 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001632 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001633 return;
1634 }
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301635
1636 /* check and update RX STBC */
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301637 if (ht_cap_info.rx_stbc && !cfg->ht_rx_stbc)
1638 ht_cap_info.rx_stbc = cfg->ht_rx_stbc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001639
1640 /* Set the LDPC capability */
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301641 ht_cap_info.adv_coding_cap = cfg->ht_rx_ldpc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001642
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301643 if (ht_cap_info.short_gi_20_mhz && !cfg->ht_sgi_20)
1644 ht_cap_info.short_gi_20_mhz = cfg->ht_sgi_20;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001645
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301646 if (ht_cap_info.short_gi_40_mhz && !cfg->ht_sgi_40)
1647 ht_cap_info.short_gi_40_mhz = cfg->ht_sgi_40;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001648
1649 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1650 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1651
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301652 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &b_enable1x1);
1653 if (!QDF_IS_STATUS_SUCCESS(status))
1654 hdd_err("unable to get vht_enable2x2");
1655
1656 b_enable1x1 = b_enable1x1 && (cfg->num_rf_chains == 2);
1657
1658 status = ucfg_mlme_set_vht_enable2x2(hdd_ctx->psoc, b_enable1x1);
1659 if (!QDF_IS_STATUS_SUCCESS(status))
1660 hdd_err("unable to set vht_enable2x2");
1661
Abhinav Kumare057b412018-10-09 17:28:16 +05301662 if (!b_enable1x1) {
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301663 ht_cap_info.tx_stbc = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001664
1665 /* 1x1 */
1666 /* Update Rx Highest Long GI data Rate */
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301667 status = ucfg_mlme_cfg_set_vht_rx_supp_data_rate(
1668 hdd_ctx->psoc,
1669 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1);
1670 if (!QDF_IS_STATUS_SUCCESS(status))
1671 hdd_err("Failed to set rx_supp_data_rate");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001672 /* Update Tx Highest Long GI data Rate */
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301673 status = ucfg_mlme_cfg_set_vht_tx_supp_data_rate(
1674 hdd_ctx->psoc,
1675 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1);
1676 if (!QDF_IS_STATUS_SUCCESS(status))
1677 hdd_err("Failed to set tx_supp_data_rate");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001678 }
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301679 if (!(cfg->ht_tx_stbc && b_enable1x1))
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301680 ht_cap_info.tx_stbc = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001681
Dustin Brown1dbefe62018-09-11 16:32:03 -07001682 status = ucfg_mlme_set_ht_cap_info(hdd_ctx->psoc, ht_cap_info);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301683 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001684 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001685#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301686 value_len = SIZE_OF_SUPPORTED_MCS_SET;
1687 if (ucfg_mlme_get_supported_mcs_set(
1688 hdd_ctx->psoc, mcs_set,
1689 &value_len) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001690 hdd_debug("Read MCS rate set");
gaurank kathpalia18b49362018-04-15 23:12:03 +05301691 if (cfg->num_rf_chains > SIZE_OF_SUPPORTED_MCS_SET)
1692 cfg->num_rf_chains = SIZE_OF_SUPPORTED_MCS_SET;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301693
1694 if (b_enable1x1) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001695 for (value = 0; value < cfg->num_rf_chains; value++)
1696 mcs_set[value] =
1697 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1698
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301699 status = ucfg_mlme_set_supported_mcs_set(
1700 hdd_ctx->psoc,
1701 mcs_set,
1702 (qdf_size_t)SIZE_OF_SUPPORTED_MCS_SET);
1703 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001704 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001705 }
1706 }
1707#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1708}
1709
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001710static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001711 struct wma_tgt_vht_cap *cfg)
1712{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301713 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001714 struct wiphy *wiphy = hdd_ctx->wiphy;
1715 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001716 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001717 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001718 struct wma_caps_per_phy caps_per_phy;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301719 uint8_t val = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001720
Dustin Brown5e06bd32016-10-04 12:49:10 -07001721 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001722 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001723 return;
1724 }
1725
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301726 status = ucfg_mlme_update_vht_cap(hdd_ctx->psoc, cfg);
1727 if (QDF_IS_STATUS_ERROR(status))
1728 hdd_err("could not update vht capabilities");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001729
1730 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1731 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1732 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1733 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1734 else
1735 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1736
1737
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001738 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
Abhinav Kumare057b412018-10-09 17:28:16 +05301739 status = ucfg_mlme_set_vht_ch_width(hdd_ctx->psoc,
1740 VHT_CAP_160_AND_80P80_SUPP);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301741 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001742 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001743 band_5g->vht_cap.cap |=
1744 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001745 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1746 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
Abhinav Kumare057b412018-10-09 17:28:16 +05301747 status = ucfg_mlme_set_vht_ch_width(hdd_ctx->psoc,
1748 VHT_CAP_160_SUPP);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301749 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001750 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001751 band_5g->vht_cap.cap |=
1752 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001753 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1754 }
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001755
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301756 status =
1757 ucfg_mlme_cfg_get_vht_chan_width(hdd_ctx->psoc, &val);
1758 if (QDF_IS_STATUS_ERROR(status))
1759 hdd_err("could not get channel_width");
1760
1761 val = QDF_MIN(val, ch_width);
Abhinav Kumare057b412018-10-09 17:28:16 +05301762 status = ucfg_mlme_set_vht_ch_width(hdd_ctx->psoc, val);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301763 if (QDF_IS_STATUS_ERROR(status))
1764 hdd_err("could not set the channel width");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001765
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001766 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001767 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001768 hdd_debug("VHT RxLDPC capability is set");
1769 } else {
1770 /*
1771 * Get the RX LDPC capability for the NON DBS
1772 * hardware mode for 5G band
1773 */
1774 status = wma_get_caps_for_phyidx_hwmode(&caps_per_phy,
1775 HW_MODE_DBS_NONE, CDS_BAND_5GHZ);
1776 if ((QDF_IS_STATUS_SUCCESS(status)) &&
1777 (caps_per_phy.vht_5g & WMI_VHT_CAP_RX_LDPC)) {
1778 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1779 hdd_debug("VHT RX LDPC capability is set");
1780 }
1781 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001782
1783 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1784 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1785 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1786 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1787
1788 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1789 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1790
1791 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1792 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1793 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1794 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1795 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1796 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1797
1798 band_5g->vht_cap.cap |=
1799 (cfg->vht_max_ampdu_len_exp <<
1800 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1801
1802 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1803 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1804 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1805 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1806 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1807 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1808 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1809 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1810
1811 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1812 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1813
1814}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001815
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001816/**
1817 * hdd_generate_macaddr_auto() - Auto-generate mac address
1818 * @hdd_ctx: Pointer to the HDD context
1819 *
1820 * Auto-generate mac address using device serial number.
1821 * Keep the first 3 bytes of OUI as before and replace
1822 * the last 3 bytes with the lower 3 bytes of serial number.
1823 *
1824 * Return: 0 for success
1825 * Non zero failure code for errors
1826 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001827static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001828{
1829 unsigned int serialno = 0;
1830 struct qdf_mac_addr mac_addr = {
1831 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1832 };
1833
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001834 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001835 if (serialno == 0)
1836 return -EINVAL;
1837
1838 serialno &= 0x00ffffff;
1839
1840 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1841 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1842 mac_addr.bytes[5] = serialno & 0xff;
1843
1844 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1845 return 0;
1846}
1847
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301848/**
1849 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1850 * configuration to cfg_ini in HDD
1851 * @hdd_ctx: Pointer to hdd_ctx
1852 * @cfg: target configuration
1853 *
1854 * Return: None
1855 */
1856#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001857static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301858 struct wma_tgt_cfg *cfg)
1859{
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05301860 ucfg_fwol_set_is_rate_limit_enabled(hdd_ctx->psoc,
1861 cfg->is_ra_rate_limit_enabled);
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301862}
1863#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001864static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301865 struct wma_tgt_cfg *cfg)
1866{
1867}
1868#endif
1869
Jeff Johnsonf9176382018-07-17 19:15:58 -07001870static void hdd_sar_target_config(struct hdd_context *hdd_ctx,
1871 struct wma_tgt_cfg *cfg)
1872{
1873 hdd_ctx->sar_version = cfg->sar_version;
1874}
1875
Jeff Johnson8abc5932018-06-02 22:51:37 -07001876void hdd_update_tgt_cfg(hdd_handle_t hdd_handle, struct wma_tgt_cfg *cfg)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001877{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001878 int ret;
Jeff Johnsonea70b942018-07-02 09:42:31 -07001879 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301880 uint8_t temp_band_cap, band_capability;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001881 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301882 uint8_t antenna_mode;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301883 uint8_t sub_20_chan_width;
Arif Hussainee10f902017-12-27 16:30:17 -08001884 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -07001885 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301886 bool bval = false;
1887 uint8_t value = 0;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301888
gaurank kathpalia843f7c32018-07-02 18:04:14 +05301889 if (!hdd_ctx) {
1890 hdd_err("HDD context is NULL");
1891 return;
1892 }
Dustin Brownbd68fe12017-11-21 15:28:52 -08001893 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1894 if (ret) {
Dustin Brown64204d22018-08-15 16:35:19 -07001895 QDF_DEBUG_PANIC("Failed to create pdev; errno:%d", ret);
1896 return;
1897 }
1898
1899 hdd_debug("New pdev has been created with pdev_id = %u",
Dustin Brown07901ec2018-09-07 11:02:41 -07001900 hdd_ctx->pdev->pdev_objmgr.wlan_pdev_id);
Dustin Brown64204d22018-08-15 16:35:19 -07001901
Dustin Brown07901ec2018-09-07 11:02:41 -07001902 status = dispatcher_pdev_open(hdd_ctx->pdev);
Dustin Brown64204d22018-08-15 16:35:19 -07001903 if (QDF_IS_STATUS_ERROR(status)) {
1904 QDF_DEBUG_PANIC("dispatcher pdev open failed; status:%d",
1905 status);
1906 return;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301907 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001908
Sandeep Puligillab7beb472018-08-13 22:54:20 -07001909 status = hdd_component_pdev_open(hdd_ctx->pdev);
1910 if (QDF_IS_STATUS_ERROR(status)) {
1911 QDF_DEBUG_PANIC("hdd component pdev open failed; status:%d",
1912 status);
1913 return;
1914 }
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301915 cdp_pdev_set_ctrl_pdev(cds_get_context(QDF_MODULE_ID_SOC),
1916 cds_get_context(QDF_MODULE_ID_TXRX),
Dustin Brown07901ec2018-09-07 11:02:41 -07001917 (struct cdp_ctrl_objmgr_pdev *)hdd_ctx->pdev);
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301918
Dustin Brown07901ec2018-09-07 11:02:41 -07001919 wlan_pdev_set_dp_handle(hdd_ctx->pdev,
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301920 cds_get_context(QDF_MODULE_ID_TXRX));
1921
Will Huang07244172018-05-14 14:23:30 +08001922 hdd_objmgr_update_tgt_max_vdev_psoc(hdd_ctx, cfg->max_intf_count);
1923
Dustin Brown1dbefe62018-09-11 16:32:03 -07001924 ucfg_ipa_set_dp_handle(hdd_ctx->psoc,
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301925 cds_get_context(QDF_MODULE_ID_SOC));
Dustin Brown1dbefe62018-09-11 16:32:03 -07001926 ucfg_ipa_set_txrx_handle(hdd_ctx->psoc,
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301927 cds_get_context(QDF_MODULE_ID_TXRX));
Dustin Brown07901ec2018-09-07 11:02:41 -07001928 ucfg_ipa_reg_sap_xmit_cb(hdd_ctx->pdev,
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301929 hdd_softap_hard_start_xmit);
Dustin Brown07901ec2018-09-07 11:02:41 -07001930 ucfg_ipa_reg_send_to_nw_cb(hdd_ctx->pdev,
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301931 hdd_ipa_send_skb_to_network);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301932
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301933 status = ucfg_mlme_get_sub_20_chan_width(hdd_ctx->psoc,
1934 &sub_20_chan_width);
1935 if (QDF_IS_STATUS_ERROR(status)) {
1936 hdd_err("Failed to get sub_20_chan_width config");
1937 return;
1938 }
1939
Naveen Rawat64e477e2016-05-20 10:34:56 -07001940 if (cds_cfg) {
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301941 if (sub_20_chan_width !=
1942 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
Naveen Rawat64e477e2016-05-20 10:34:56 -07001943 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1944 cds_cfg->sub_20_channel_width =
1945 WLAN_SUB_20_CH_WIDTH_NONE;
1946 } else {
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301947 cds_cfg->sub_20_channel_width = sub_20_chan_width;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001948 }
1949 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001950
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301951 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
1952 if (QDF_IS_STATUS_ERROR(status)) {
1953 hdd_err("Failed to get MLME band capability");
1954 return;
1955 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001956
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301957 /* first store the INI band capability */
1958 temp_band_cap = band_capability;
1959
1960 band_capability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301961 hdd_ctx->is_fils_roaming_supported =
1962 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001963
Vignesh Viswanathan694e28e2018-01-18 20:53:57 +05301964 hdd_ctx->config->is_11k_offload_supported =
1965 cfg->services.is_11k_offload_supported;
1966
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001967 /*
1968 * now overwrite the target band capability with INI
1969 * setting if INI setting is a subset
1970 */
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301971 if ((band_capability == BAND_ALL) &&
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001972 (temp_band_cap != BAND_ALL))
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301973 band_capability = temp_band_cap;
1974 else if ((band_capability != BAND_ALL) &&
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001975 (temp_band_cap != BAND_ALL) &&
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301976 (band_capability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001977 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001978 }
1979
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301980 status = ucfg_mlme_set_band_capability(hdd_ctx->psoc, band_capability);
1981 if (QDF_IS_STATUS_ERROR(status)) {
1982 hdd_err("Failed to set MLME Band Capability");
1983 return;
1984 }
1985
1986 hdd_ctx->curr_band = band_capability;
Amar Singhal58b45ef2017-08-01 13:43:54 -07001987
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301988 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001989 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1990 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1991 }
1992
1993 /* This can be extended to other configurations like ht, vht cap... */
1994
Anurag Chouhanc5548422016-02-24 18:33:27 +05301995 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001996 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001997 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001998 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001999 static struct qdf_mac_addr default_mac_addr = {
2000 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
2001 };
2002 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
2003 &default_mac_addr)) {
2004 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
2005 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
2006 MAC_ADDRESS_STR,
2007 MAC_ADDR_ARRAY(hdd_ctx->config->
2008 intfMacAddr[0].bytes));
2009 } else {
2010 hdd_err("Invalid MAC passed from target, using MAC from ini file "
2011 MAC_ADDRESS_STR,
2012 MAC_ADDR_ARRAY(hdd_ctx->config->
2013 intfMacAddr[0].bytes));
2014 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07002015 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002016 }
2017
2018 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07002019 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002020
Ryan Hsuc6918552018-05-16 13:29:59 -07002021 hdd_ctx->hw_bd_id = cfg->hw_bd_id;
2022 qdf_mem_copy(&hdd_ctx->hw_bd_info, &cfg->hw_bd_info,
2023 sizeof(cfg->hw_bd_info));
2024
Dustin Brownbee82832018-07-23 10:10:51 -07002025 if (cfg->max_intf_count > CSR_ROAM_SESSION_MAX) {
2026 hdd_err("fw max vdevs (%u) > host max vdevs (%u); using %u",
2027 cfg->max_intf_count, CSR_ROAM_SESSION_MAX,
2028 CSR_ROAM_SESSION_MAX);
2029 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
2030 } else {
2031 hdd_ctx->max_intf_count = cfg->max_intf_count;
2032 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002033
Jeff Johnsonf9176382018-07-17 19:15:58 -07002034 hdd_sar_target_config(hdd_ctx, cfg);
Jeff Johnsonc875e242016-09-23 18:12:34 -07002035 hdd_lpass_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08002036
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002037 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
2038 hdd_update_tgt_services(hdd_ctx, &cfg->services);
2039
2040 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
2041
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002042 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07002043 if (cfg->services.en_11ax) {
2044 hdd_info("11AX: 11ax is enabled - update HDD config");
2045 hdd_update_tgt_he_cap(hdd_ctx, cfg);
2046 }
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -07002047 hdd_update_tgt_twt_cap(hdd_ctx, cfg);
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07002048
2049 hdd_update_vdev_nss(hdd_ctx);
2050
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05302051 hdd_update_hw_dbs_capable(hdd_ctx);
gaurank kathpalia5fcefa92018-10-24 15:03:15 +05302052 hdd_ctx->dynamic_nss_chains_support =
2053 cfg->dynamic_nss_chains_support;
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08002054 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07002055 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002056 hdd_debug("fine_time_meas_cap: 0x%x",
Arif Hussainee10f902017-12-27 16:30:17 -08002057 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08002058
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05302059 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
2060 if (!QDF_IS_STATUS_SUCCESS(status))
2061 hdd_err("unable to get vht_enable2x2");
2062
2063 antenna_mode = (bval == 0x01) ?
Nitesh Shahe50711f2017-04-26 16:30:45 +05302064 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
2065 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002066 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08002067 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08002068
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05302069 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05302070 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05302071
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05302072 status = ucfg_mlme_cfg_get_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
Abhinav Kumare057b412018-10-09 17:28:16 +05302073 &value);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05302074 if (QDF_IS_STATUS_ERROR(status)) {
2075 status = false;
2076 hdd_err("set tx_bfee_ant_supp failed");
2077 }
2078
2079 if ((value >
Arif Hussainee10f902017-12-27 16:30:17 -08002080 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05302081 !cfg->tx_bfee_8ss_enabled) {
2082 status =
2083 ucfg_mlme_cfg_set_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
2084 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF);
2085 if (QDF_IS_STATUS_ERROR(status)) {
2086 status = false;
2087 hdd_err("set tx_bfee_ant_supp failed");
2088 }
2089 }
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302090
Jeff Johnson16528362018-06-14 12:34:16 -07002091 mac_handle = hdd_ctx->mac_handle;
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302092
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05302093 hdd_debug("txBFCsnValue %d", value);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05302094
2095 /*
2096 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
2097 */
2098 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05302099
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05302100 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
2101
Yue Macd359b72017-10-03 15:21:00 -07002102 /*
2103 * This needs to be done after HDD pdev is created and stored since
2104 * it will access the HDD pdev object lock.
2105 */
2106 hdd_runtime_suspend_context_init(hdd_ctx);
2107
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07002108 /* Configure NAN datapath features */
2109 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07002110 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08002111 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Liangwei Dong0da14262018-07-03 03:30:23 -04002112 hdd_ctx->obss_scan_offload = cfg->services.obss_scan_offload;
Jeff Johnson16528362018-06-14 12:34:16 -07002113 status = sme_cfg_set_int(mac_handle, WNI_CFG_OBSS_DETECTION_OFFLOAD,
Arif Hussainee10f902017-12-27 16:30:17 -08002114 cfg->obss_detection_offloaded);
2115 if (QDF_IS_STATUS_ERROR(status))
2116 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Arif Hussain05fb4872018-01-03 16:02:55 -08002117
Jeff Johnson16528362018-06-14 12:34:16 -07002118 status = sme_cfg_set_int(mac_handle,
Arif Hussain05fb4872018-01-03 16:02:55 -08002119 WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD,
2120 cfg->obss_color_collision_offloaded);
2121 if (QDF_IS_STATUS_ERROR(status))
2122 hdd_err("Failed to set WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002123}
2124
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002125bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002126{
Jeff Johnson9d295242017-08-29 14:39:48 -07002127 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002128 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002129
Jiachao Wuf610d912018-01-23 17:47:32 +08002130 if (!hdd_ctx) {
2131 hdd_info("Couldn't get hdd_ctx");
2132 return true;
2133 }
2134
2135 if (hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002136 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08002137 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302138 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002139 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002140
Dustin Brown920397d2017-12-13 16:27:50 -08002141 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002142 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2143
2144 if ((QDF_SAP_MODE == adapter->device_mode ||
2145 QDF_P2P_GO_MODE == adapter->device_mode) &&
Dustin Brown07901ec2018-09-07 11:02:41 -07002146 (wlan_reg_is_passive_or_disable_ch(hdd_ctx->pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002147 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002148 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2149 true;
2150 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07002151 adapter->session_id);
bings6fb9bf62018-07-05 14:01:53 +08002152 if (adapter->txrx_vdev)
2153 cdp_fc_vdev_flush(
2154 cds_get_context(QDF_MODULE_ID_SOC),
bings0e03a982018-05-09 08:40:59 +08002155 adapter->txrx_vdev);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302156 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002157 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302158
2159 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002160}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002161
Jeff Johnson030cd902018-11-11 10:19:40 -08002162bool hdd_is_valid_mac_address(const uint8_t *mac_addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002163{
2164 int xdigit = 0;
2165 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002166
Jeff Johnson030cd902018-11-11 10:19:40 -08002167 while (*mac_addr) {
2168 if (isxdigit(*mac_addr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002169 xdigit++;
Jeff Johnson030cd902018-11-11 10:19:40 -08002170 } else if (':' == *mac_addr) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002171 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2172 break;
2173
2174 ++separator;
2175 } else {
2176 /* Invalid MAC found */
Jeff Johnson030cd902018-11-11 10:19:40 -08002177 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002178 }
Jeff Johnson030cd902018-11-11 10:19:40 -08002179 ++mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002180 }
2181 return xdigit == 12 && (separator == 5 || separator == 0);
2182}
2183
2184/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302185 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2186 * @dev: Handle to struct net_device to be updated.
2187 *
2188 * Return: None
2189 */
2190static void hdd_mon_mode_ether_setup(struct net_device *dev)
2191{
2192 dev->header_ops = NULL;
2193 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2194 dev->hard_header_len = ETH_HLEN;
2195 dev->mtu = ETH_DATA_LEN;
2196 dev->addr_len = ETH_ALEN;
2197 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2198 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2199 dev->priv_flags |= IFF_TX_SKB_SHARING;
2200
2201 memset(dev->broadcast, 0xFF, ETH_ALEN);
2202}
2203
Nirav Shah73713f72018-05-17 14:50:41 +05302204#ifdef FEATURE_MONITOR_MODE_SUPPORT
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302205/**
chenguo71303962018-10-24 19:44:34 +08002206 * hdd_mon_turn_off_ps_and_wow() - Update monitor mode struct net_device.
2207 * @hdd_ctx: Pointer to HDD context.
2208 *
2209 * Return: None
2210 */
2211static void hdd_mon_turn_off_ps_and_wow(struct hdd_context *hdd_ctx)
2212{
2213 ucfg_pmo_set_power_save_mode(hdd_ctx->psoc, PS_NOT_SUPPORTED);
2214 ucfg_pmo_set_wow_enable(hdd_ctx->psoc, PMO_WOW_DISABLE_BOTH);
2215}
2216
2217/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002218 * __hdd__mon_open() - HDD Open function
2219 * @dev: Pointer to net_device structure
2220 *
2221 * This is called in response to ifconfig up
2222 *
2223 * Return: 0 for success; non-zero for failure
2224 */
2225static int __hdd_mon_open(struct net_device *dev)
2226{
2227 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002228 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2229 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002230
Dustin Brownfdf17c12018-03-14 12:55:34 -07002231 hdd_enter_dev(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002232
2233 ret = wlan_hdd_validate_context(hdd_ctx);
2234 if (ret)
2235 return ret;
2236
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302237 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002238
2239 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Brown3ecc8782018-09-19 16:37:13 -07002240 ret = hdd_psoc_idle_restart(hdd_ctx);
Ravi Joshia307f632017-07-17 23:41:41 -07002241 if (ret) {
2242 hdd_err("Failed to start WLAN modules return");
2243 return ret;
2244 }
2245 hdd_err("hdd_wlan_start_modules() successful !");
2246
2247 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2248 ret = hdd_start_adapter(adapter);
2249 if (ret) {
2250 hdd_err("Failed to start adapter :%d",
2251 adapter->device_mode);
2252 return ret;
2253 }
2254 hdd_err("hdd_start_adapters() successful !");
2255 }
chenguo71303962018-10-24 19:44:34 +08002256 hdd_mon_turn_off_ps_and_wow(hdd_ctx);
Ravi Joshia307f632017-07-17 23:41:41 -07002257 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2258 }
2259
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002260 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002261
2262 if (!ret)
2263 ret = hdd_enable_monitor_mode(dev);
2264
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002265 return ret;
2266}
2267
2268/**
2269 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2270 * @dev: Pointer to net_device structure
2271 *
2272 * This is called in response to ifconfig up
2273 *
2274 * Return: 0 for success; non-zero for failure
2275 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002276static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002277{
2278 int ret;
2279
2280 cds_ssr_protect(__func__);
2281 ret = __hdd_mon_open(dev);
2282 cds_ssr_unprotect(__func__);
2283
2284 return ret;
2285}
Nirav Shah73713f72018-05-17 14:50:41 +05302286#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002287
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002288static QDF_STATUS
2289wlan_hdd_update_dbs_scan_and_fw_mode_config(void)
2290{
2291 struct policy_mgr_dual_mac_config cfg = {0};
2292 QDF_STATUS status;
Krunal Soni13b50f82018-09-27 12:37:03 -07002293 uint32_t channel_select_logic_conc = 0;
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002294 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2295
2296 if (!hdd_ctx) {
2297 hdd_err("HDD context is NULL");
2298 return QDF_STATUS_E_FAILURE;
2299 }
2300
2301
Dustin Brown1dbefe62018-09-11 16:32:03 -07002302 if (!policy_mgr_is_hw_dbs_capable(hdd_ctx->psoc))
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002303 return QDF_STATUS_SUCCESS;
2304
2305 cfg.scan_config = 0;
2306 cfg.fw_mode_config = 0;
2307 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Krunal Soni13b50f82018-09-27 12:37:03 -07002308 ucfg_policy_mgr_get_chnl_select_plcy(hdd_ctx->psoc,
2309 &channel_select_logic_conc);
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002310
2311 if (hdd_ctx->config->dual_mac_feature_disable !=
2312 DISABLE_DBS_CXN_AND_SCAN) {
2313 status = policy_mgr_get_updated_scan_and_fw_mode_config(
Dustin Brown1dbefe62018-09-11 16:32:03 -07002314 hdd_ctx->psoc, &cfg.scan_config,
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002315 &cfg.fw_mode_config,
2316 hdd_ctx->config->dual_mac_feature_disable,
2317 channel_select_logic_conc);
2318
2319 if (status != QDF_STATUS_SUCCESS) {
2320 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
2321 status);
2322 return status;
2323 }
2324 }
2325
2326 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
2327 cfg.scan_config, cfg.fw_mode_config);
2328
2329 status = sme_soc_set_dual_mac_config(cfg);
2330 if (status != QDF_STATUS_SUCCESS) {
2331 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
2332 return status;
2333 }
2334
2335 return QDF_STATUS_SUCCESS;
2336}
2337
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002338/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302339 * hdd_start_adapter() - Wrapper function for device specific adapter
2340 * @adapter: pointer to HDD adapter
2341 *
2342 * This function is called to start the device specific adapter for
2343 * the mode passed in the adapter's device_mode.
2344 *
2345 * Return: 0 for success; non-zero for failure
2346 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002347int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302348{
2349
2350 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002351 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302352
Dustin Brownfdf17c12018-03-14 12:55:34 -07002353 hdd_enter_dev(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002354 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302355
2356 switch (device_mode) {
2357 case QDF_P2P_CLIENT_MODE:
2358 case QDF_P2P_DEVICE_MODE:
2359 case QDF_OCB_MODE:
2360 case QDF_STA_MODE:
2361 case QDF_MONITOR_MODE:
2362 ret = hdd_start_station_adapter(adapter);
2363 if (ret)
2364 goto err_start_adapter;
Alok Kumar81e1d732018-09-04 11:10:36 +05302365
2366 hdd_nud_ignore_tracking(adapter, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05302367 break;
2368 case QDF_P2P_GO_MODE:
2369 case QDF_SAP_MODE:
2370 ret = hdd_start_ap_adapter(adapter);
2371 if (ret)
2372 goto err_start_adapter;
2373 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302374 case QDF_IBSS_MODE:
2375 /*
2376 * For IBSS interface is initialized as part of
2377 * hdd_init_station_mode()
2378 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002379 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302380 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002381 /* vdevs are dynamically managed by firmware in FTM */
2382 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302383 default:
2384 hdd_err("Invalid session type %d", device_mode);
2385 QDF_ASSERT(0);
2386 goto err_start_adapter;
2387 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002388
Arun Khandavallifae92942016-08-01 13:31:08 +05302389 if (hdd_set_fw_params(adapter))
2390 hdd_err("Failed to set the FW params for the adapter!");
2391
Dustin Browne7e71d32018-05-11 16:00:08 -07002392 if (adapter->session_id != HDD_SESSION_ID_INVALID) {
2393 ret = wlan_hdd_cfg80211_register_frames(adapter);
2394 if (ret < 0) {
2395 hdd_err("Failed to register frames - ret %d", ret);
2396 goto err_start_adapter;
2397 }
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302398 }
Dustin Browne7e71d32018-05-11 16:00:08 -07002399
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002400 wlan_hdd_update_dbs_scan_and_fw_mode_config();
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302401
Dustin Browndb2a8be2017-12-20 11:49:56 -08002402exit_with_success:
Dustin Browne74003f2018-03-14 12:51:58 -07002403 hdd_exit();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002404
Arun Khandavallifae92942016-08-01 13:31:08 +05302405 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002406
Arun Khandavallifae92942016-08-01 13:31:08 +05302407err_start_adapter:
2408 return -EINVAL;
2409}
2410
2411/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302412 * hdd_enable_power_management() - API to Enable Power Management
2413 *
2414 * API invokes Bus Interface Layer power management functionality
2415 *
2416 * Return: None
2417 */
2418static void hdd_enable_power_management(void)
2419{
2420 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2421
2422 if (!hif_ctx) {
2423 hdd_err("Bus Interface Context is Invalid");
2424 return;
2425 }
2426
2427 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2428}
2429
2430/**
2431 * hdd_disable_power_management() - API to disable Power Management
2432 *
2433 * API disable Bus Interface Layer Power management functionality
2434 *
2435 * Return: None
2436 */
2437static void hdd_disable_power_management(void)
2438{
2439 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2440
2441 if (!hif_ctx) {
2442 hdd_err("Bus Interface Context is Invalid");
2443 return;
2444 }
2445
2446 hif_disable_power_management(hif_ctx);
2447}
2448
Ryan Hsuaadba072018-04-20 13:01:53 -07002449void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302450{
2451 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002452 size_t target_hw_name_len;
2453 const char *target_hw_name;
Ryan Hsuaadba072018-04-20 13:01:53 -07002454 uint8_t *buf;
2455 uint32_t buf_len;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302456
2457 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2458 if (!hif_sc) {
2459 hdd_err("HIF context is NULL");
2460 return;
2461 }
2462
Ryan Hsuaadba072018-04-20 13:01:53 -07002463 hif_get_hw_info(hif_sc, &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302464 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002465 &target_hw_name);
2466
2467 if (hdd_ctx->target_hw_name)
2468 qdf_mem_free(hdd_ctx->target_hw_name);
2469
2470 target_hw_name_len = strlen(target_hw_name) + 1;
2471 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2472 if (hdd_ctx->target_hw_name)
2473 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2474 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302475
Ryan Hsuaadba072018-04-20 13:01:53 -07002476 buf = qdf_mem_malloc(WE_MAX_STR_LEN);
2477 if (buf) {
2478 buf_len = hdd_wlan_get_version(hdd_ctx, WE_MAX_STR_LEN, buf);
2479 hdd_info("%s", buf);
2480 qdf_mem_free(buf);
2481 }
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302482}
2483
2484/**
gbian62edd7e2017-03-07 13:12:13 +08002485 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2486 * @hdd_ctx: Pointer to hdd context
2487 *
2488 * Return: none
2489 */
2490static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002491hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002492{
jitiphil8e15ea62018-11-16 18:05:34 +05302493 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM] = {0};
2494 qdf_size_t out_size = 0;
gbian62edd7e2017-03-07 13:12:13 +08002495 int i;
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002496 struct cds_context *cds_ctx;
gbian62edd7e2017-03-07 13:12:13 +08002497
2498 if (NULL == hdd_ctx)
2499 return;
2500
2501 if (NULL == hdd_ctx->config) {
2502 /* Do nothing if hdd_ctx is invalid */
2503 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2504 return;
2505 }
2506
2507 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2508
2509 if (!cds_ctx) {
2510 hdd_err("Invalid CDS Context");
2511 return;
2512 }
2513
2514 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2515 switch (i) {
2516 case OL_TX_WMM_AC_BE:
jitiphil8e15ea62018-11-16 18:05:34 +05302517 qdf_uint8_array_parse(
2518 cfg_get(hdd_ctx->psoc,
2519 CFG_DP_ENABLE_TX_SCHED_WRR_BE),
2520 tx_sched_wrr_param,
2521 sizeof(tx_sched_wrr_param),
2522 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002523 break;
2524 case OL_TX_WMM_AC_BK:
jitiphil8e15ea62018-11-16 18:05:34 +05302525 qdf_uint8_array_parse(
2526 cfg_get(hdd_ctx->psoc,
2527 CFG_DP_ENABLE_TX_SCHED_WRR_BK),
2528 tx_sched_wrr_param,
2529 sizeof(tx_sched_wrr_param),
2530 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002531 break;
2532 case OL_TX_WMM_AC_VI:
jitiphil8e15ea62018-11-16 18:05:34 +05302533 qdf_uint8_array_parse(
2534 cfg_get(hdd_ctx->psoc,
2535 CFG_DP_ENABLE_TX_SCHED_WRR_VI),
2536 tx_sched_wrr_param,
2537 sizeof(tx_sched_wrr_param),
2538 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002539 break;
2540 case OL_TX_WMM_AC_VO:
jitiphil8e15ea62018-11-16 18:05:34 +05302541 qdf_uint8_array_parse(
2542 cfg_get(hdd_ctx->psoc,
2543 CFG_DP_ENABLE_TX_SCHED_WRR_VO),
2544 tx_sched_wrr_param,
2545 sizeof(tx_sched_wrr_param),
2546 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002547 break;
2548 default:
gbian62edd7e2017-03-07 13:12:13 +08002549 break;
2550 }
2551
jitiphil8e15ea62018-11-16 18:05:34 +05302552 if (out_size == TX_SCHED_WRR_PARAMS_NUM) {
gbian62edd7e2017-03-07 13:12:13 +08002553 cds_ctx->ac_specs[i].wrr_skip_weight =
2554 tx_sched_wrr_param[0];
2555 cds_ctx->ac_specs[i].credit_threshold =
2556 tx_sched_wrr_param[1];
2557 cds_ctx->ac_specs[i].send_limit =
2558 tx_sched_wrr_param[2];
2559 cds_ctx->ac_specs[i].credit_reserve =
2560 tx_sched_wrr_param[3];
2561 cds_ctx->ac_specs[i].discard_weight =
2562 tx_sched_wrr_param[4];
2563 }
2564
jitiphil8e15ea62018-11-16 18:05:34 +05302565 out_size = 0;
gbian62edd7e2017-03-07 13:12:13 +08002566 }
2567}
2568
Ryan Hsuaadba072018-04-20 13:01:53 -07002569uint32_t hdd_wlan_get_version(struct hdd_context *hdd_ctx,
2570 const size_t version_len, uint8_t *version)
2571{
2572 uint32_t size;
2573 uint32_t msp_id = 0, mspid = 0, siid = 0, crmid = 0, sub_id = 0;
2574
2575 if (!hdd_ctx) {
2576 hdd_err("Invalid context, HDD context is null");
2577 return 0;
2578 }
2579
Ashish Kumar Dhanotiya7353f882018-05-15 12:50:19 +05302580 if (!version || version_len == 0) {
Ryan Hsuaadba072018-04-20 13:01:53 -07002581 hdd_err("Invalid buffer pointr or buffer len\n");
2582 return 0;
2583 }
2584
2585 msp_id = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
2586 mspid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
2587 siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
2588 crmid = hdd_ctx->target_fw_version & 0x7fff;
2589 sub_id = (hdd_ctx->target_fw_vers_ext & 0xf0000000) >> 28;
2590
2591 size = scnprintf(version, version_len,
Ryan Hsuc6918552018-05-16 13:29:59 -07002592 "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 -07002593 QWLAN_VERSIONSTR,
2594 msp_id, mspid, siid, crmid, sub_id,
Ryan Hsuc6918552018-05-16 13:29:59 -07002595 hdd_ctx->target_hw_name,
2596 hdd_ctx->hw_bd_info.bdf_version,
2597 hdd_ctx->hw_bd_info.ref_design_id,
2598 hdd_ctx->hw_bd_info.customer_id,
2599 hdd_ctx->hw_bd_info.project_id,
2600 hdd_ctx->hw_bd_info.board_data_rev);
Ryan Hsuaadba072018-04-20 13:01:53 -07002601
2602 return size;
2603}
2604
Rachit Kankane0dc3e852018-05-07 17:33:42 +05302605int hdd_set_11ax_rate(struct hdd_adapter *adapter, int set_value,
2606 struct sap_config *sap_config)
2607{
2608 uint8_t preamble = 0, nss = 0, rix = 0;
2609 int ret;
2610 mac_handle_t mac_handle = adapter->hdd_ctx->mac_handle;
2611
2612 if (!sap_config) {
2613 if (!sme_is_feature_supported_by_fw(DOT11AX)) {
2614 hdd_err("Target does not support 11ax");
2615 return -EIO;
2616 }
2617 } else if (sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax &&
2618 sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax_ONLY) {
2619 hdd_err("Invalid hw mode, SAP hw_mode= 0x%x, ch = %d",
2620 sap_config->SapHw_mode, sap_config->channel);
2621 return -EIO;
2622 }
2623
2624 if (set_value != 0xff) {
2625 rix = RC_2_RATE_IDX_11AX(set_value);
2626 preamble = WMI_RATE_PREAMBLE_HE;
2627 nss = HT_RC_2_STREAMS_11AX(set_value);
2628
2629 set_value = hdd_assemble_rate_code(preamble, nss, rix);
2630 } else {
2631 ret = sme_set_auto_rate_he_ltf(mac_handle, adapter->session_id,
2632 QCA_WLAN_HE_LTF_AUTO);
2633 }
2634
2635 hdd_info("SET_11AX_RATE val %d rix %d preamble %x nss %d",
2636 set_value, rix, preamble, nss);
2637
2638 ret = wma_cli_set_command(adapter->session_id,
2639 WMI_VDEV_PARAM_FIXED_RATE,
2640 set_value, VDEV_CMD);
2641
2642 return ret;
2643}
2644
2645int hdd_assemble_rate_code(uint8_t preamble, uint8_t nss, uint8_t rate)
2646{
2647 int set_value;
2648
2649 if (sme_is_feature_supported_by_fw(DOT11AX))
2650 set_value = WMI_ASSEMBLE_RATECODE_V1(rate, nss, preamble);
2651 else
2652 set_value = (preamble << 6) | (nss << 4) | rate;
2653
2654 return set_value;
2655}
2656
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002657#ifdef FEATURE_WLAN_WAPI
2658/**
2659 * hdd_wapi_security_sta_exist() - return wapi security sta exist or not
2660 *
2661 * This API returns the wapi security station exist or not
2662 *
2663 * Return: true - wapi security station exist
2664 */
2665static bool hdd_wapi_security_sta_exist(void)
2666{
2667 struct hdd_adapter *adapter = NULL;
2668 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2669
2670 hdd_for_each_adapter(hdd_ctx, adapter) {
2671 if ((adapter->device_mode == QDF_STA_MODE) &&
2672 adapter->wapi_info.wapi_mode &&
2673 (adapter->wapi_info.wapi_auth_mode != WAPI_AUTH_MODE_OPEN))
2674 return true;
2675 }
2676 return false;
2677}
2678#else
2679static bool hdd_wapi_security_sta_exist(void)
2680{
2681 return false;
2682}
2683#endif
2684
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002685#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002686static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2687 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2688{
Jeff Johnson9d295242017-08-29 14:39:48 -07002689 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002690 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002691
2692 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2693 if (!adapter) {
2694 hdd_err("Adapter is NULL");
2695 return PM_MAX_NUM_OF_MODE;
2696 }
2697
2698 return policy_mgr_convert_device_mode_to_qdf_type(
2699 adapter->device_mode);
2700}
2701
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002702static void hdd_register_policy_manager_callback(
2703 struct wlan_objmgr_psoc *psoc)
2704{
2705 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002706
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002707 qdf_mem_zero(&hdd_cbacks, sizeof(hdd_cbacks));
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002708 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002709 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002710 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2711 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002712 hdd_cbacks.get_mode_for_non_connected_vdev =
2713 wlan_hdd_get_mode_for_non_connected_vdev;
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05302714 hdd_cbacks.hdd_get_device_mode = hdd_get_device_mode;
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002715 hdd_cbacks.hdd_wapi_security_sta_exist =
2716 hdd_wapi_security_sta_exist;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002717 if (QDF_STATUS_SUCCESS !=
2718 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2719 hdd_err("HDD callback registration with policy manager failed");
2720 }
2721}
2722#else
2723static void hdd_register_policy_manager_callback(
2724 struct wlan_objmgr_psoc *psoc)
2725{
2726}
2727#endif
2728
jiadff1ac132018-11-26 16:27:48 +08002729#ifdef WLAN_FEATURE_NAN_DATAPATH
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002730static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002731{
2732 struct nan_callbacks cb_obj = {0};
2733
2734 cb_obj.ndi_open = hdd_ndi_open;
2735 cb_obj.ndi_close = hdd_ndi_close;
2736 cb_obj.ndi_start = hdd_ndi_start;
2737 cb_obj.ndi_delete = hdd_ndi_delete;
2738 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2739 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2740
Naveen Rawat37f62c82017-03-26 22:24:43 -07002741 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2742 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002743 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002744
Dustin Brown1dbefe62018-09-11 16:32:03 -07002745 os_if_nan_register_hdd_callbacks(hdd_ctx->psoc, &cb_obj);
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002746}
jiadff1ac132018-11-26 16:27:48 +08002747#else
2748static inline void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
2749{
2750}
2751#endif
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002752
Dustin Brown26b3d042017-12-21 11:13:27 -08002753#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002754/**
2755 * hdd_check_for_leaks() - Perform runtime memory leak checks
Dustin Browna6246dd2018-05-24 14:35:58 -07002756 * @hdd_ctx: the global HDD context
Dustin Brown29533f22018-07-24 13:11:56 -07002757 * @is_ssr: true if SSR is in progress
Dustin Brown4c5b9902017-12-19 11:17:19 -08002758 *
2759 * This API triggers runtime memory leak detection. This feature enforces the
2760 * policy that any memory allocated at runtime must also be released at runtime.
2761 *
2762 * Allocating memory at runtime and releasing it at unload is effectively a
2763 * memory leak for configurations which never unload (e.g. LONU, statically
2764 * compiled driver). Such memory leaks are NOT false positives, and must be
2765 * fixed.
2766 *
2767 * Return: None
2768 */
Dustin Brown29533f22018-07-24 13:11:56 -07002769static void hdd_check_for_leaks(struct hdd_context *hdd_ctx, bool is_ssr)
Dustin Brown4bc0a622017-12-06 15:56:50 -08002770{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002771 /* DO NOT REMOVE these checks; for false positives, read above first */
2772
Dustin Brown1dbefe62018-09-11 16:32:03 -07002773 wlan_objmgr_psoc_check_for_peer_leaks(hdd_ctx->psoc);
2774 wlan_objmgr_psoc_check_for_vdev_leaks(hdd_ctx->psoc);
2775 wlan_objmgr_psoc_check_for_pdev_leaks(hdd_ctx->psoc);
Dustin Brown29533f22018-07-24 13:11:56 -07002776
2777 /* many adapter resources are not freed by design during SSR */
2778 if (is_ssr)
2779 return;
2780
Dustin Brown677e0862017-10-10 16:30:09 -07002781 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002782 qdf_nbuf_map_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002783 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002784}
2785
Dustin Brown26b3d042017-12-21 11:13:27 -08002786#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2787#else
Dustin Brown29533f22018-07-24 13:11:56 -07002788static inline void hdd_check_for_leaks(struct hdd_context *hdd_ctx, bool is_ssr)
2789{ }
Dustin Brown26b3d042017-12-21 11:13:27 -08002790
2791#define hdd_debug_domain_set(domain)
2792#endif /* CONFIG_LEAK_DETECTION */
2793
gbian62edd7e2017-03-07 13:12:13 +08002794/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002795 * hdd_update_country_code - Update country code
2796 * @hdd_ctx: HDD context
2797 *
2798 * Update country code based on module parameter country_code
2799 *
2800 * Return: 0 on success and errno on failure
2801 */
2802static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2803{
2804 if (!country_code)
2805 return 0;
2806
2807 return hdd_reg_set_country(hdd_ctx, country_code);
2808}
2809
Dustin Browne7e71d32018-05-11 16:00:08 -07002810int hdd_wlan_start_modules(struct hdd_context *hdd_ctx, bool reinit)
Arun Khandavallifae92942016-08-01 13:31:08 +05302811{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002812 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302813 qdf_device_t qdf_dev;
2814 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302815 bool unint = false;
2816 void *hif_ctx;
Jingxiang Ge95912f82018-04-19 12:01:26 +08002817 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +05302818
Arun Khandavallifae92942016-08-01 13:31:08 +05302819 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2820 if (!qdf_dev) {
2821 hdd_err("QDF Device Context is Invalid return");
2822 return -EINVAL;
2823 }
2824
Dustin Brown4c663222018-10-23 14:19:36 -07002825 hdd_psoc_idle_timer_stop(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302826
Dustin Brown1fe30a82017-10-03 16:13:36 -07002827 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302828 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2829 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002830 hdd_debug("Driver modules already Enabled");
Dustin Browne74003f2018-03-14 12:51:58 -07002831 hdd_exit();
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302832 return 0;
2833 }
2834
Dustin Brown1fe30a82017-10-03 16:13:36 -07002835 hdd_ctx->start_modules_in_progress = true;
2836
Arun Khandavallifae92942016-08-01 13:31:08 +05302837 switch (hdd_ctx->driver_status) {
2838 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002839 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302840 unint = true;
2841 /* Fall through dont add break here */
2842 case DRIVER_MODULES_CLOSED:
Dustin Brown1a20b082018-08-03 17:27:15 -07002843 hdd_info("Wlan transitioning (CLOSED -> ENABLED)");
Dustin Brown550f6d22017-12-14 15:44:01 -08002844
Dustin Brown26b3d042017-12-21 11:13:27 -08002845 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002846
Arun Khandavallifae92942016-08-01 13:31:08 +05302847 if (!reinit && !unint) {
2848 ret = pld_power_on(qdf_dev->dev);
2849 if (ret) {
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002850 hdd_err("Failed to power up device; errno:%d",
Dustin Browndca39692017-11-09 15:30:25 -08002851 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302852 goto release_lock;
2853 }
2854 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002855
2856 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2857 hdd_ctx->config->enable_fw_log);
Arun Khandavallifae92942016-08-01 13:31:08 +05302858 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2859 qdf_dev->bus_type,
2860 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2861 HIF_ENABLE_TYPE_PROBE);
2862 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002863 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302864 goto power_down;
2865 }
2866
2867 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302868 if (!hif_ctx) {
2869 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002870 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302871 goto power_down;
2872 }
2873
Arun Khandavallifae92942016-08-01 13:31:08 +05302874 status = ol_cds_init(qdf_dev, hif_ctx);
2875 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002876 hdd_err("No Memory to Create BMI Context; status: %d",
2877 status);
2878 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302879 goto hif_close;
2880 }
2881
jitiphil4c256a32018-09-07 08:51:52 +05302882 ucfg_ipa_component_config_update(hdd_ctx->psoc);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302883
gbian62edd7e2017-03-07 13:12:13 +08002884 hdd_update_cds_ac_specs_params(hdd_ctx);
2885
Dustin Brown1dbefe62018-09-11 16:32:03 -07002886 status = hdd_component_psoc_open(hdd_ctx->psoc);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05302887 if (QDF_IS_STATUS_ERROR(status)) {
2888 hdd_err("Failed to Open legacy components; status: %d",
2889 status);
2890 ret = qdf_status_to_os_return(status);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05302891 goto cds_free;
2892 }
2893
2894 ret = hdd_update_config(hdd_ctx);
2895 if (ret) {
2896 hdd_err("Failed to update configuration; errno: %d",
2897 ret);
2898 goto cds_free;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05302899 }
2900
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +05302901 status = wbuff_module_init();
2902 if (QDF_IS_STATUS_ERROR(status))
2903 hdd_err("WBUFF init unsuccessful; status: %d", status);
2904
Dustin Brown1dbefe62018-09-11 16:32:03 -07002905 status = cds_open(hdd_ctx->psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002906 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002907 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002908 ret = qdf_status_to_os_return(status);
Krunal Sonie71838d2018-09-27 10:45:05 -07002909 goto psoc_close;
Arun Khandavallifae92942016-08-01 13:31:08 +05302910 }
2911
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +05302912 hdd_ctx->mac_handle = cds_get_context(QDF_MODULE_ID_SME);
2913
Manjunathappa Prakashb6b4ff12018-06-04 12:32:33 -07002914 if (hdd_ctx->config->rx_thread_affinity_mask)
2915 cds_set_rx_thread_cpu_mask(
2916 hdd_ctx->config->rx_thread_affinity_mask);
2917
2918 /* initialize components configurations after psoc open */
Mukul Sharma9d797a02017-01-05 20:26:03 +05302919 ret = hdd_update_components_config(hdd_ctx);
2920 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002921 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302922 ret);
2923 goto close;
2924 }
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302925
Dustin Brown1dbefe62018-09-11 16:32:03 -07002926 status = cds_dp_open(hdd_ctx->psoc);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002927 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002928 hdd_err("Failed to Open cds post open; status: %d",
2929 status);
2930 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002931 goto close;
2932 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302933
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302934 ret = hdd_register_cb(hdd_ctx);
2935 if (ret) {
2936 hdd_err("Failed to register HDD callbacks!");
2937 goto cds_txrx_free;
2938 }
2939
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002940 /*
2941 * NAN compoenet requires certian operations like, open adapter,
2942 * close adapter, etc. to be initiated by HDD, for those
2943 * register HDD callbacks with UMAC's NAN componenet.
2944 */
2945 hdd_nan_register_callbacks(hdd_ctx);
2946
Jeff Johnson3a280122017-09-13 07:42:00 -07002947 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302948 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002949 hdd_err("Failed to pre-enable CDS; status: %d", status);
2950 ret = qdf_status_to_os_return(status);
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302951 goto deregister_cb;
Arun Khandavallifae92942016-08-01 13:31:08 +05302952 }
2953
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002954 hdd_register_policy_manager_callback(
Dustin Brown1dbefe62018-09-11 16:32:03 -07002955 hdd_ctx->psoc);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002956
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302957 hdd_sysfs_create_driver_root_obj();
Dustin Brown1dbefe62018-09-11 16:32:03 -07002958 hdd_sysfs_create_version_interface(hdd_ctx->psoc);
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302959 hdd_sysfs_create_powerstats_interface();
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302960 hdd_update_hw_sw_info(hdd_ctx);
Dustin Brown550f6d22017-12-14 15:44:01 -08002961
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302962 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2963 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002964 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302965 break;
2966 }
Dustin Browndca39692017-11-09 15:30:25 -08002967
Dustin Browne7e71d32018-05-11 16:00:08 -07002968 ret = hdd_configure_cds(hdd_ctx);
Dustin Browndca39692017-11-09 15:30:25 -08002969 if (ret) {
2970 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302971 goto destroy_driver_sysfs;
Arun Khandavallifae92942016-08-01 13:31:08 +05302972 }
Dustin Browndca39692017-11-09 15:30:25 -08002973
Komal Seelamf2136bb2016-09-28 18:30:44 +05302974 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002975
Arun Khandavallifae92942016-08-01 13:31:08 +05302976 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002977
Arun Khandavallifae92942016-08-01 13:31:08 +05302978 default:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002979 QDF_DEBUG_PANIC("Unknown driver state:%d",
Arun Khandavallifae92942016-08-01 13:31:08 +05302980 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002981 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302982 goto release_lock;
2983 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002984
Dustin Brown1a20b082018-08-03 17:27:15 -07002985 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2986 hdd_info("Wlan transitioned (now ENABLED)");
2987
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302988 hdd_ctx->start_modules_in_progress = false;
Dustin Brownad698ae2018-09-05 17:19:30 -07002989
Arun Khandavallifae92942016-08-01 13:31:08 +05302990 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002991
Dustin Browne74003f2018-03-14 12:51:58 -07002992 hdd_exit();
Dustin Brown550f6d22017-12-14 15:44:01 -08002993
Arun Khandavallifae92942016-08-01 13:31:08 +05302994 return 0;
2995
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302996destroy_driver_sysfs:
2997 hdd_sysfs_destroy_powerstats_interface();
2998 hdd_sysfs_destroy_version_interface();
2999 hdd_sysfs_destroy_driver_root_obj();
Rajeev Kumarbe021242017-02-16 16:12:23 -08003000 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08003001
Sourav Mohapatra674925f2018-04-16 11:16:58 +05303002deregister_cb:
3003 hdd_deregister_cb(hdd_ctx);
3004
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07003005cds_txrx_free:
Dustin Brown1dbefe62018-09-11 16:32:03 -07003006 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->psoc);
Jingxiang Ge95912f82018-04-19 12:01:26 +08003007
3008 if (tgt_hdl && target_psoc_get_wmi_ready(tgt_hdl)) {
3009 hdd_runtime_suspend_context_deinit(hdd_ctx);
Dustin Brown07901ec2018-09-07 11:02:41 -07003010 dispatcher_pdev_close(hdd_ctx->pdev);
Jingxiang Ge95912f82018-04-19 12:01:26 +08003011 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
3012 }
3013
Dustin Brown1dbefe62018-09-11 16:32:03 -07003014 cds_dp_close(hdd_ctx->psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08003015
Arun Khandavallifae92942016-08-01 13:31:08 +05303016close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08003017 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08003018 hdd_info("Wlan transition aborted (now CLOSED)");
3019
Dustin Brown1dbefe62018-09-11 16:32:03 -07003020 cds_close(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05303021
Krunal Sonie71838d2018-09-27 10:45:05 -07003022psoc_close:
Dustin Brown1dbefe62018-09-11 16:32:03 -07003023 hdd_component_psoc_close(hdd_ctx->psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07003024 cds_deinit_ini_config();
3025
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07003026cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05303027 ol_cds_free();
3028
3029hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07003030 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
3031 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05303032power_down:
3033 if (!reinit && !unint)
3034 pld_power_off(qdf_dev->dev);
3035release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05303036 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05303037 mutex_unlock(&hdd_ctx->iface_change_lock);
Abhinav Kumar7ae9b7b2017-12-19 15:11:54 +05303038 if (hdd_ctx->target_hw_name) {
3039 qdf_mem_free(hdd_ctx->target_hw_name);
3040 hdd_ctx->target_hw_name = NULL;
3041 }
Dustin Brown29533f22018-07-24 13:11:56 -07003042
3043 hdd_check_for_leaks(hdd_ctx, reinit);
Dustin Brown26b3d042017-12-21 11:13:27 -08003044 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08003045
Dustin Browne74003f2018-03-14 12:51:58 -07003046 hdd_exit();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08003047
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07003048 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05303049}
3050
Naveen Rawat910726a2017-03-06 11:42:51 -08003051#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003052static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003053{
3054 int ret = os_if_wifi_pos_register_nl();
3055
3056 if (ret)
3057 hdd_err("os_if_wifi_pos_register_nl failed");
3058
3059 return ret;
3060}
3061
3062static int hdd_deactivate_wifi_pos(void)
3063{
3064 int ret = os_if_wifi_pos_deregister_nl();
3065
3066 if (ret)
3067 hdd_err("os_if_wifi_pos_deregister_nl failed");
3068
3069 return ret;
3070}
3071
3072/**
3073 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
3074 * @hdd_ctx: hdd context
3075 *
3076 * Return: status of operation
3077 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003078static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003079{
Dustin Brown1dbefe62018-09-11 16:32:03 -07003080 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Wu Gao1ab05582018-11-08 16:22:49 +08003081 uint16_t neighbor_scan_max_chan_time;
3082 uint16_t neighbor_scan_min_chan_time;
Naveen Rawat910726a2017-03-06 11:42:51 -08003083
3084 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
3085 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
3086 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
3087 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
3088 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
3089 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
Wu Gao1ab05582018-11-08 16:22:49 +08003090 ucfg_mlme_get_neighbor_scan_max_chan_time(psoc,
3091 &neighbor_scan_max_chan_time);
3092 ucfg_mlme_get_neighbor_scan_min_chan_time(psoc,
3093 &neighbor_scan_min_chan_time);
3094 wifi_pos_set_dwell_time_min(psoc, neighbor_scan_min_chan_time);
3095 wifi_pos_set_dwell_time_max(psoc, neighbor_scan_max_chan_time);
Naveen Rawat910726a2017-03-06 11:42:51 -08003096}
3097#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003098static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003099{
3100 return oem_activate_service(hdd_ctx);
3101}
3102
3103static int hdd_deactivate_wifi_pos(void)
3104{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05303105 return oem_deactivate_service();
Naveen Rawat910726a2017-03-06 11:42:51 -08003106}
3107
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003108static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003109{
3110}
3111#endif
3112
Arun Khandavallifae92942016-08-01 13:31:08 +05303113/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003114 * __hdd_open() - HDD Open function
3115 * @dev: Pointer to net_device structure
3116 *
3117 * This is called in response to ifconfig up
3118 *
3119 * Return: 0 for success; non-zero for failure
3120 */
3121static int __hdd_open(struct net_device *dev)
3122{
Jeff Johnson9d295242017-08-29 14:39:48 -07003123 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003124 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003125 int ret;
3126
Dustin Brownfdf17c12018-03-14 12:55:34 -07003127 hdd_enter_dev(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303128 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003129 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003130
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05303131 /* Nothing to be done if device is unloading */
3132 if (cds_is_driver_unloading()) {
3133 hdd_err("Driver is unloading can not open the hdd");
3134 return -EBUSY;
3135 }
3136
Dustin Brown01847752017-10-25 13:56:27 -07003137 if (cds_is_driver_recovering()) {
3138 hdd_err("WLAN is currently recovering; Please try again.");
3139 return -EBUSY;
3140 }
3141
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05303142 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
3143 hdd_err("con_mode_handler is in progress; Please try again.");
3144 return -EBUSY;
3145 }
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303146
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05303147 mutex_lock(&hdd_init_deinit_lock);
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05303148 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
3149
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303150 /*
3151 * This scenario can be hit in cases where in the wlan driver after
3152 * registering the netdevices and there is a failure in driver
3153 * initialization. So return error gracefully because the netdevices
3154 * will be de-registered as part of the load failure.
3155 */
3156
3157 if (!cds_is_driver_loaded()) {
3158 hdd_err("Failed to start the wlan driver!!");
3159 ret = -EIO;
3160 goto err_hdd_hdd_init_deinit_lock;
3161 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303162
Dustin Brown3ecc8782018-09-19 16:37:13 -07003163 ret = hdd_psoc_idle_restart(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05303164 if (ret) {
3165 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303166 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05303167 }
3168
Arun Khandavallifae92942016-08-01 13:31:08 +05303169 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3170 ret = hdd_start_adapter(adapter);
3171 if (ret) {
3172 hdd_err("Failed to start adapter :%d",
3173 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303174 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05303175 }
3176 }
3177
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003178 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3179 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003180 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003181 /* Enable TX queues only when we are connected */
3182 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05303183 WLAN_START_ALL_NETIF_QUEUE,
3184 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003185 }
3186
Naveen Rawat286def52016-09-23 15:38:02 -07003187 /* Enable carrier and transmit queues for NDI */
3188 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003189 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07003190 wlan_hdd_netif_queue_control(adapter,
3191 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
3192 WLAN_CONTROL_PATH);
3193 }
3194
Naveen Rawat910726a2017-03-06 11:42:51 -08003195 hdd_populate_wifi_pos_cfg(hdd_ctx);
Arunk Khandavalli40943af2017-05-15 19:25:34 +05303196 hdd_lpass_notify_start(hdd_ctx, adapter);
Naveen Rawat910726a2017-03-06 11:42:51 -08003197
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303198err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05303199 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303200 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003201 return ret;
3202}
3203
Arun Khandavallifae92942016-08-01 13:31:08 +05303204
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003205/**
3206 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
3207 * @dev: Pointer to net_device structure
3208 *
3209 * This is called in response to ifconfig up
3210 *
3211 * Return: 0 for success; non-zero for failure
3212 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003213static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003214{
3215 int ret;
3216
3217 cds_ssr_protect(__func__);
3218 ret = __hdd_open(dev);
3219 cds_ssr_unprotect(__func__);
3220
3221 return ret;
3222}
3223
3224/**
3225 * __hdd_stop() - HDD stop function
3226 * @dev: Pointer to net_device structure
3227 *
3228 * This is called in response to ifconfig down
3229 *
3230 * Return: 0 for success; non-zero for failure
3231 */
3232static int __hdd_stop(struct net_device *dev)
3233{
Jeff Johnson9d295242017-08-29 14:39:48 -07003234 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003235 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003236 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -07003237 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003238
Dustin Brownfdf17c12018-03-14 12:55:34 -07003239 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003240
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303241 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003242 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003243
3244 ret = wlan_hdd_validate_context(hdd_ctx);
Arunk Khandavalli987c8d52018-06-21 17:40:31 +05303245 if (ret) {
3246 set_bit(DOWN_DURING_SSR, &adapter->event_flags);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003247 return ret;
Arunk Khandavalli987c8d52018-06-21 17:40:31 +05303248 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003249
3250 /* Nothing to be done if the interface is not opened */
3251 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003252 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003253 return -ENODEV;
3254 }
3255
3256 /* Make sure the interface is marked as closed */
3257 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303258
Jeff Johnson16528362018-06-14 12:34:16 -07003259 mac_handle = hdd_ctx->mac_handle;
3260
Mukul Sharmad16c2022017-07-25 18:56:12 +05303261 hdd_debug("Disabling Auto Power save timer");
3262 sme_ps_disable_auto_ps_timer(
Jeff Johnson16528362018-06-14 12:34:16 -07003263 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003264 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303265
3266 /*
3267 * Disable TX on the interface, after this hard_start_xmit() will not
3268 * be called on that interface
3269 */
Dustin Browna7bb6ae2018-08-16 16:51:50 -07003270 hdd_debug("Disabling queues, adapter device mode: %s(%d)",
Dustin Brown458027c2018-10-19 12:26:27 -07003271 qdf_opmode_str(adapter->device_mode), adapter->device_mode);
Kabilan Kannan8dac3502017-10-30 12:40:27 -07003272
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303273 wlan_hdd_netif_queue_control(adapter,
3274 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3275 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003276
Arunk Khandavalli40943af2017-05-15 19:25:34 +05303277 if (adapter->device_mode == QDF_STA_MODE)
3278 hdd_lpass_notify_stop(hdd_ctx);
3279
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003280 /*
Naveen Rawat286def52016-09-23 15:38:02 -07003281 * NAN data interface is different in some sense. The traffic on NDI is
3282 * bursty in nature and depends on the need to transfer. The service
3283 * layer may down the interface after the usage and up again when
3284 * required. In some sense, the NDI is expected to be available
3285 * (like SAP) iface until NDI delete request is issued by the service
3286 * layer. Skip BSS termination and adapter deletion for NAN Data
3287 * interface (NDI).
3288 */
3289 if (WLAN_HDD_IS_NDI(adapter))
3290 return 0;
3291
3292 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003293 * The interface is marked as down for outside world (aka kernel)
3294 * But the driver is pretty much alive inside. The driver needs to
3295 * tear down the existing connection on the netdev (session)
3296 * cleanup the data pipes and wait until the control plane is stabilized
3297 * for this interface. The call also needs to wait until the above
3298 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003299 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003300 * That is intentional to be able to scan if it is a STA/P2P interface
3301 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08003302 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003303
3304 /* DeInit the adapter. This ensures datapath cleanup as well */
3305 hdd_deinit_adapter(hdd_ctx, adapter, true);
3306
Arun Khandavallifae92942016-08-01 13:31:08 +05303307 /*
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +05303308 * Upon wifi turn off, DUT has to flush the scan results so if
3309 * this is the last cli iface, flush the scan database.
3310 */
3311 if (!hdd_is_cli_iface_up(hdd_ctx))
Jeff Johnson16528362018-06-14 12:34:16 -07003312 sme_scan_flush_result(mac_handle);
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +05303313
Dustin Brown4c663222018-10-23 14:19:36 -07003314 if (!hdd_is_any_interface_open(hdd_ctx))
3315 hdd_psoc_idle_timer_start(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05303316
Dustin Browne74003f2018-03-14 12:51:58 -07003317 hdd_exit();
Dustin Brown4c663222018-10-23 14:19:36 -07003318
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003319 return 0;
3320}
3321
3322/**
3323 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3324 * @dev: pointer to net_device structure
3325 *
3326 * This is called in response to ifconfig down
3327 *
3328 * Return: 0 for success and error number for failure
3329 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003330static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003331{
3332 int ret;
3333
3334 cds_ssr_protect(__func__);
3335 ret = __hdd_stop(dev);
3336 cds_ssr_unprotect(__func__);
3337
3338 return ret;
3339}
3340
3341/**
3342 * __hdd_uninit() - HDD uninit function
3343 * @dev: Pointer to net_device structure
3344 *
3345 * This is called during the netdev unregister to uninitialize all data
3346 * associated with the device
3347 *
3348 * Return: None
3349 */
3350static void __hdd_uninit(struct net_device *dev)
3351{
Jeff Johnson9d295242017-08-29 14:39:48 -07003352 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003353 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003354
Dustin Brownfdf17c12018-03-14 12:55:34 -07003355 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003356
3357 do {
3358 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003359 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003360 break;
3361 }
3362
Jeff Johnson399c6272017-08-30 10:51:00 -07003363 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3364 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003365 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003366 break;
3367 }
3368
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003369 if (dev != adapter->dev)
3370 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003371
Jeff Johnson399c6272017-08-30 10:51:00 -07003372 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003373
3374 /* after uninit our adapter structure will no longer be valid */
3375 adapter->dev = NULL;
3376 adapter->magic = 0;
3377 } while (0);
3378
Dustin Browne74003f2018-03-14 12:51:58 -07003379 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003380}
3381
3382/**
3383 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
3384 * @dev: pointer to net_device structure
3385 *
3386 * This is called during the netdev unregister to uninitialize all data
3387 * associated with the device
3388 *
3389 * Return: none
3390 */
3391static void hdd_uninit(struct net_device *dev)
3392{
3393 cds_ssr_protect(__func__);
3394 __hdd_uninit(dev);
3395 cds_ssr_unprotect(__func__);
3396}
3397
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003398static int hdd_open_cesium_nl_sock(void)
3399{
3400#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3401 struct netlink_kernel_cfg cfg = {
3402 .groups = WLAN_NLINK_MCAST_GRP_ID,
3403 .input = NULL
3404 };
3405#endif
3406 int ret = 0;
3407
3408#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3409 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3410#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3411 THIS_MODULE,
3412#endif
3413 &cfg);
3414#else
3415 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3416 WLAN_NLINK_MCAST_GRP_ID,
3417 NULL, NULL, THIS_MODULE);
3418#endif
3419
3420 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003421 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003422 ret = -ECONNREFUSED;
3423 }
3424
3425 return ret;
3426}
3427
3428static void hdd_close_cesium_nl_sock(void)
3429{
3430 if (NULL != cesium_nl_srv_sock) {
3431 netlink_kernel_release(cesium_nl_srv_sock);
3432 cesium_nl_srv_sock = NULL;
3433 }
3434}
3435
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303436void hdd_update_dynamic_mac(struct hdd_context *hdd_ctx,
3437 struct qdf_mac_addr *curr_mac_addr,
3438 struct qdf_mac_addr *new_mac_addr)
3439{
3440 uint8_t i;
3441
3442 hdd_enter();
3443
3444 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
3445 if (!qdf_mem_cmp(curr_mac_addr->bytes,
3446 &hdd_ctx->dynamic_mac_list[i].bytes[0],
3447 sizeof(struct qdf_mac_addr))) {
3448 qdf_mem_copy(&hdd_ctx->dynamic_mac_list[i],
3449 new_mac_addr->bytes,
3450 sizeof(struct qdf_mac_addr));
3451 break;
3452 }
3453 }
3454
3455 hdd_exit();
3456}
3457
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003458/**
3459 * __hdd_set_mac_address() - set the user specified mac address
3460 * @dev: Pointer to the net device.
3461 * @addr: Pointer to the sockaddr.
3462 *
3463 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003464 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003465 *
3466 * Return: 0 for success, non zero for failure
3467 */
3468static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3469{
Jeff Johnson9d295242017-08-29 14:39:48 -07003470 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303471 struct hdd_adapter *adapter_temp;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003472 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003473 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303474 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003475 int ret;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303476 struct qdf_mac_addr mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003477
Dustin Brownfdf17c12018-03-14 12:55:34 -07003478 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003479
Hanumanth Reddy Pothula5c7a7812018-03-09 12:55:32 +05303480 if (netif_running(dev)) {
3481 hdd_err("On iface up, set mac address change isn't supported");
3482 return -EBUSY;
3483 }
3484
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003485 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3486 ret = wlan_hdd_validate_context(hdd_ctx);
3487 if (0 != ret)
3488 return ret;
3489
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303490 qdf_mem_copy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303491 adapter_temp = hdd_get_adapter_by_macaddr(hdd_ctx, mac_addr.bytes);
3492 if (adapter_temp) {
3493 if (!qdf_str_cmp(adapter_temp->dev->name, dev->name))
3494 return 0;
3495 hdd_err("%s adapter exist with same address " MAC_ADDRESS_STR,
3496 adapter_temp->dev->name,
Ashish Kumar Dhanotiyaf974f332018-04-19 16:03:15 +05303497 MAC_ADDR_ARRAY(mac_addr.bytes));
3498 return -EINVAL;
3499 }
3500
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05303501 qdf_ret_status = wlan_hdd_validate_mac_address(&mac_addr);
3502 if (QDF_IS_STATUS_ERROR(qdf_ret_status))
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303503 return -EINVAL;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303504
Ashish Kumar Dhanotiya8bfef122018-04-18 16:48:27 +05303505 hdd_info("Changing MAC to " MAC_ADDRESS_STR " of the interface %s ",
3506 MAC_ADDR_ARRAY(mac_addr.bytes), dev->name);
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303507
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303508 hdd_update_dynamic_mac(hdd_ctx, &adapter->mac_addr, &mac_addr);
Jeff Johnson1e851a12017-10-28 14:36:12 -07003509 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003510 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3511
Dustin Browne74003f2018-03-14 12:51:58 -07003512 hdd_exit();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303513 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003514}
3515
3516/**
3517 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3518 * function from SSR
3519 * @dev: pointer to net_device structure
3520 * @addr: Pointer to the sockaddr
3521 *
3522 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003523 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003524 *
3525 * Return: 0 for success.
3526 */
3527static int hdd_set_mac_address(struct net_device *dev, void *addr)
3528{
3529 int ret;
3530
3531 cds_ssr_protect(__func__);
3532 ret = __hdd_set_mac_address(dev, addr);
3533 cds_ssr_unprotect(__func__);
3534
3535 return ret;
3536}
3537
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003538uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003539{
3540 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003541
Dustin Brown61cc3932018-10-18 16:12:13 -07003542 i = qdf_ffz(hdd_ctx->config->intfAddrMask);
3543 if (i < 0 || i >= QDF_MAX_CONCURRENCY_PERSONA)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003544 return NULL;
3545
3546 hdd_ctx->config->intfAddrMask |= (1 << i);
Dustin Brown61cc3932018-10-18 16:12:13 -07003547
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303548 qdf_mem_copy(&hdd_ctx->dynamic_mac_list[i].bytes,
3549 &hdd_ctx->config->intfMacAddr[i].bytes,
3550 sizeof(struct qdf_mac_addr));
Dustin Brown61cc3932018-10-18 16:12:13 -07003551 return hdd_ctx->config->intfMacAddr[i].bytes;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003552}
3553
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003554void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3555 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003556{
3557 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003558
Anurag Chouhan6d760662016-02-20 16:05:43 +05303559 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003560 if (!memcmp(releaseAddr,
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303561 hdd_ctx->dynamic_mac_list[i].bytes,
Dustin Brown61cc3932018-10-18 16:12:13 -07003562 QDF_MAC_ADDR_SIZE)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003563 hdd_ctx->config->intfAddrMask &= ~(1 << i);
3564 break;
3565 }
3566 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003567}
3568
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003569/**
3570 * __hdd_set_multicast_list() - set the multicast address list
3571 * @dev: Pointer to the WLAN device.
3572 * @skb: Pointer to OS packet (sk_buff).
3573 *
3574 * This funciton sets the multicast address list.
3575 *
3576 * Return: None
3577 */
3578static void __hdd_set_multicast_list(struct net_device *dev)
3579{
Jeff Johnson9d295242017-08-29 14:39:48 -07003580 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Dustin Brown0f874482018-06-13 14:39:22 -07003581 int i = 0, errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003582 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003583 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303584 struct pmo_mc_addr_list_params *mc_list_request = NULL;
Dustin Brown1dbefe62018-09-11 16:32:03 -07003585 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303586 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003587
Dustin Brownfdf17c12018-03-14 12:55:34 -07003588 hdd_enter_dev(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303589 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303590 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303591
Dustin Brown0f874482018-06-13 14:39:22 -07003592 errno = wlan_hdd_validate_context(hdd_ctx);
3593 if (errno)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303594 goto out;
3595
Dustin Brown0f874482018-06-13 14:39:22 -07003596 errno = hdd_validate_adapter(adapter);
3597 if (errno)
Dustin Brownc788acb2017-08-01 17:43:51 -07003598 goto out;
3599
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303600 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3601 hdd_err("%s: Driver module is closed", __func__);
Dustin Brown0f874482018-06-13 14:39:22 -07003602 goto out;
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303603 }
3604
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303605 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
Min Liu74a1a502018-10-10 19:59:07 +08003606 if (!mc_list_request)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303607 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003608
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303609 /* Delete already configured multicast address list */
3610 if (adapter->mc_addr_list.mc_cnt > 0) {
Dustin Brown0f874482018-06-13 14:39:22 -07003611 hdd_debug("clear previously configured MC address list");
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303612 hdd_disable_and_flush_mc_addr_list(adapter,
3613 pmo_mc_list_change_notify);
3614 }
3615
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003616 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003617 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303618 hdd_disable_and_flush_mc_addr_list(adapter,
3619 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003620 } else {
3621 mc_count = netdev_mc_count(dev);
Wu Gaod7dd6e42018-10-16 17:22:56 +08003622 if (mc_count > ucfg_pmo_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003623 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Wu Gaod7dd6e42018-10-16 17:22:56 +08003624 ucfg_pmo_max_mc_addr_supported(psoc));
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303625 hdd_disable_and_flush_mc_addr_list(adapter,
3626 pmo_mc_list_change_notify);
stonezdf2bdfd2018-11-20 14:45:06 +08003627 adapter->mc_addr_list.mc_cnt = 0;
Dustin Brown0f874482018-06-13 14:39:22 -07003628 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003629 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003630 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003631 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303632 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003633 if (i == mc_count)
3634 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303635 memset(&(mc_list_request->mc_addr[i].bytes),
3636 0, ETH_ALEN);
3637 memcpy(&(mc_list_request->mc_addr[i].bytes),
3638 ha->addr, ETH_ALEN);
Dustin Brown0f874482018-06-13 14:39:22 -07003639 hdd_debug("mlist[%d] = %pM", i,
3640 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003641 i++;
3642 }
3643 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303644
stonezdf2bdfd2018-11-20 14:45:06 +08003645 adapter->mc_addr_list.mc_cnt = mc_count;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303646 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003647 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303648 mc_list_request->count = mc_count;
Dustin Brown0f874482018-06-13 14:39:22 -07003649
3650 errno = hdd_cache_mc_addr_list(mc_list_request);
3651 if (errno) {
3652 hdd_err("Failed to cache MC address list for vdev %u; errno:%d",
3653 adapter->session_id, errno);
3654 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003655 }
Dustin Brown0f874482018-06-13 14:39:22 -07003656
3657 hdd_enable_mc_addr_filtering(adapter, pmo_mc_list_change_notify);
3658
3659free_req:
3660 qdf_mem_free(mc_list_request);
3661
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303662out:
Dustin Browne74003f2018-03-14 12:51:58 -07003663 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003664}
3665
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303666
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003667/**
3668 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3669 * @dev: pointer to net_device
3670 *
3671 * Return: none
3672 */
3673static void hdd_set_multicast_list(struct net_device *dev)
3674{
3675 cds_ssr_protect(__func__);
3676 __hdd_set_multicast_list(dev);
3677 cds_ssr_unprotect(__func__);
3678}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003679
3680/**
3681 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3682 * @dev: Pointer to the WLAN device.
3683 * @skb: Pointer to OS packet (sk_buff).
3684 *
3685 * This function is registered with the Linux OS for network
3686 * core to decide which queue to use first.
3687 *
3688 * Return: ac, Queue Index/access category corresponding to UP in IP header
3689 */
3690static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3691#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3692 , void *accel_priv
3693#endif
3694#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3695 , select_queue_fallback_t fallback
3696#endif
3697)
3698{
3699 return hdd_wmm_select_queue(dev, skb);
3700}
3701
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003702static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003703 .ndo_open = hdd_open,
3704 .ndo_stop = hdd_stop,
3705 .ndo_uninit = hdd_uninit,
3706 .ndo_start_xmit = hdd_hard_start_xmit,
3707 .ndo_tx_timeout = hdd_tx_timeout,
3708 .ndo_get_stats = hdd_get_stats,
3709 .ndo_do_ioctl = hdd_ioctl,
3710 .ndo_set_mac_address = hdd_set_mac_address,
3711 .ndo_select_queue = hdd_select_queue,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003712 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003713};
3714
Nirav Shah73713f72018-05-17 14:50:41 +05303715#ifdef FEATURE_MONITOR_MODE_SUPPORT
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003716/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003717static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003718 .ndo_open = hdd_mon_open,
3719 .ndo_stop = hdd_stop,
3720 .ndo_get_stats = hdd_get_stats,
3721};
3722
3723/**
3724 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003725 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003726 * Return: None
3727 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003728void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003729{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003730 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003731 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003732 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003733 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003734}
Nirav Shah73713f72018-05-17 14:50:41 +05303735#else
3736void hdd_set_station_ops(struct net_device *dev)
3737{
3738 dev->netdev_ops = &wlan_drv_ops;
3739}
3740#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003741
3742/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003743 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3744 * @hdd_ctx: global hdd context
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003745 * @mac_addr: mac address to assign to the interface
Ryan Hsu07495ea2016-01-21 15:25:39 -08003746 * @name: User-visible name of the interface
3747 *
3748 * hdd adapter pointer would point to the netdev->priv space, this function
Jeff Johnson62018292018-05-06 16:18:35 -07003749 * would retrieve the pointer, and setup the hdd adapter configuration.
Ryan Hsu07495ea2016-01-21 15:25:39 -08003750 *
3751 * Return: the pointer to hdd adapter, otherwise NULL
3752 */
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003753static struct hdd_adapter *
3754hdd_alloc_station_adapter(struct hdd_context *hdd_ctx, tSirMacAddr mac_addr,
3755 unsigned char name_assign_type, const char *name)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003756{
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003757 struct net_device *dev;
3758 struct hdd_adapter *adapter;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003759 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303760 QDF_STATUS qdf_status;
jitiphil377bcc12018-10-05 19:46:08 +05303761 void *soc;
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003762
jitiphil377bcc12018-10-05 19:46:08 +05303763 soc = cds_get_context(QDF_MODULE_ID_SOC);
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003764 /* cfg80211 initialization and registration */
3765 dev = alloc_netdev_mq(sizeof(*adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003766#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003767 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003768#endif
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003769 (cds_get_conparam() == QDF_GLOBAL_MONITOR_MODE ?
3770 hdd_mon_mode_ether_setup : ether_setup),
3771 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003772
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003773 if (!dev) {
3774 hdd_err("Failed to allocate new net_device '%s'", name);
3775 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003776 }
3777
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003778 adapter = netdev_priv(dev);
3779
3780 qdf_mem_zero(adapter, sizeof(*adapter));
3781 sta_ctx = &adapter->session.station;
3782 qdf_mem_set(sta_ctx->conn_info.staId, sizeof(sta_ctx->conn_info.staId),
3783 HDD_WLAN_INVALID_STA_ID);
3784 adapter->dev = dev;
3785 adapter->hdd_ctx = hdd_ctx;
3786 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
3787 adapter->session_id = HDD_SESSION_ID_INVALID;
3788
3789 qdf_status = qdf_event_create(&adapter->qdf_session_open_event);
3790 if (QDF_IS_STATUS_ERROR(qdf_status))
3791 goto free_net_dev;
3792
3793 qdf_status = qdf_event_create(&adapter->qdf_session_close_event);
3794 if (QDF_IS_STATUS_ERROR(qdf_status))
3795 goto free_net_dev;
3796
3797 adapter->offloads_configured = false;
3798 adapter->is_link_up_service_needed = false;
3799 adapter->disconnection_in_progress = false;
3800 adapter->send_mode_change = true;
3801
3802 /* Init the net_device structure */
3803 strlcpy(dev->name, name, IFNAMSIZ);
3804
3805 qdf_mem_copy(dev->dev_addr, mac_addr, sizeof(tSirMacAddr));
3806 qdf_mem_copy(adapter->mac_addr.bytes, mac_addr, sizeof(tSirMacAddr));
3807 dev->watchdog_timeo = HDD_TX_TIMEOUT;
3808
jitiphil377bcc12018-10-05 19:46:08 +05303809 if (cdp_cfg_get(soc,
3810 cfg_dp_enable_ip_tcp_udp_checksum_offload))
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003811 dev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
3812 dev->features |= NETIF_F_RXCSUM;
3813
3814 hdd_set_tso_flags(hdd_ctx, dev);
3815 hdd_set_station_ops(adapter->dev);
3816
3817 hdd_dev_setup_destructor(dev);
3818 dev->ieee80211_ptr = &adapter->wdev;
3819 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
3820 adapter->wdev.wiphy = hdd_ctx->wiphy;
3821 adapter->wdev.netdev = dev;
3822
3823 /* set dev's parent to underlying device */
3824 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
3825 hdd_wmm_init(adapter);
3826 spin_lock_init(&adapter->pause_map_lock);
3827 adapter->start_time = qdf_system_ticks();
3828 adapter->last_time = adapter->start_time;
3829
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003830 return adapter;
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003831
3832free_net_dev:
3833 free_netdev(adapter->dev);
3834
3835 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003836}
3837
Jeff Johnson9d295242017-08-29 14:39:48 -07003838static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003839{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003840 struct net_device *dev = adapter->dev;
3841 int ret;
3842
Dustin Brown491d54b2018-03-14 12:39:11 -07003843 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003844
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003845 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003846 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3847
3848 ret = dev_alloc_name(dev, dev->name);
3849 if (ret < 0) {
3850 hdd_err(
3851 "unable to get dev name: %s, err = 0x%x",
3852 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303853 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003854 }
3855 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003856
3857 ret = register_netdevice(dev);
3858 if (ret) {
3859 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3860 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303861 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003862 }
3863 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003864 ret = register_netdev(dev);
3865 if (ret) {
3866 hdd_err("register_netdev(%s) failed, err = 0x%x",
3867 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303868 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003869 }
3870 }
3871 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3872
Dustin Browne74003f2018-03-14 12:51:58 -07003873 hdd_exit();
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003874
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303875 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003876}
3877
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05303878QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id,
3879 QDF_STATUS qdf_status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003880{
Krunal Sonib51eec72017-11-20 21:53:01 -08003881 struct hdd_adapter *adapter;
3882 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003883
Krunal Sonib51eec72017-11-20 21:53:01 -08003884 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3885 if (!hdd_ctx) {
3886 hdd_err("Invalid HDD_CTX");
3887 return QDF_STATUS_E_FAILURE;
3888 }
3889
3890 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3891 if (NULL == adapter) {
Naveen Rawat23a3b912018-05-30 17:45:52 -07003892 hdd_err("NULL adapter for %d", session_id);
Krunal Sonib51eec72017-11-20 21:53:01 -08003893 return QDF_STATUS_E_INVAL;
3894 }
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05303895
3896 if (qdf_status == QDF_STATUS_SUCCESS)
3897 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3898
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303899 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003900 hdd_debug("session %d opened", adapter->session_id);
3901
3902 return QDF_STATUS_SUCCESS;
3903}
3904
3905QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3906{
3907 struct hdd_adapter *adapter;
3908 struct hdd_context *hdd_ctx;
3909
3910 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3911 if (!hdd_ctx) {
3912 hdd_err("Invalid HDD_CTX");
3913 return QDF_STATUS_E_FAILURE;
3914 }
3915
3916 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003917 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003918 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303919 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003920 }
3921
3922 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003923 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303924 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003925 }
3926
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003927 /*
3928 * For NAN Data interface, the close session results in the final
3929 * indication to the userspace
3930 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003931 if (adapter->device_mode == QDF_NDI_MODE)
3932 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003933
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003934 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3935
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003936 /*
3937 * We can be blocked while waiting for scheduled work to be
3938 * flushed, and the adapter structure can potentially be freed, in
3939 * which case the magic will have been reset. So make sure the
3940 * magic is still good, and hence the adapter structure is still
3941 * valid, before signaling completion
3942 */
3943 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303944 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003945
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303946 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003947}
3948
Jeff Johnson9d295242017-08-29 14:39:48 -07003949int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003950{
Min Liu8c5d99e2018-09-10 17:18:44 +08003951 struct wlan_objmgr_vdev *vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07003952 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003953
Min Liu8c5d99e2018-09-10 17:18:44 +08003954 vdev = hdd_objmgr_get_vdev(adapter);
3955 if (!vdev)
3956 return -EINVAL;
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003957
Min Liu8c5d99e2018-09-10 17:18:44 +08003958 status = pmo_vdev_ready(vdev);
3959 if (QDF_IS_STATUS_ERROR(status)) {
3960 hdd_objmgr_put_vdev(adapter);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003961 return qdf_status_to_os_return(status);
Min Liu8c5d99e2018-09-10 17:18:44 +08003962 }
3963
3964 status = ucfg_reg_11d_vdev_created_update(vdev);
3965 if (QDF_IS_STATUS_ERROR(status)) {
3966 hdd_objmgr_put_vdev(adapter);
3967 return qdf_status_to_os_return(status);
3968 }
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003969
3970 if (wma_capability_enhanced_mcast_filter())
Min Liu8c5d99e2018-09-10 17:18:44 +08003971 status = ucfg_pmo_enhanced_mc_filter_enable(vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003972 else
Min Liu8c5d99e2018-09-10 17:18:44 +08003973 status = ucfg_pmo_enhanced_mc_filter_disable(vdev);
3974
3975 hdd_objmgr_put_vdev(adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003976
3977 return qdf_status_to_os_return(status);
3978}
3979
Jeff Johnson9d295242017-08-29 14:39:48 -07003980int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003981{
3982 QDF_STATUS status;
Dustin Brown2da29eb2018-07-13 14:23:12 -07003983 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003984 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003985 uint8_t vdev_id;
Min Liu8c5d99e2018-09-10 17:18:44 +08003986 struct wlan_objmgr_vdev *vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07003987
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003988 vdev_id = adapter->session_id;
3989 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003990
3991 /* vdev created sanity check */
3992 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Dustin Brown2da29eb2018-07-13 14:23:12 -07003993 hdd_err("vdev %u does not exist", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003994 return -EINVAL;
3995 }
Dustin Brown2da29eb2018-07-13 14:23:12 -07003996
Min Liu8c5d99e2018-09-10 17:18:44 +08003997 vdev = hdd_objmgr_get_vdev(adapter);
3998 if (!vdev)
3999 return -EINVAL;
Ashish Kumar Dhanotiya68ee2e42018-11-19 21:15:14 +05304000
4001 ucfg_pmo_del_wow_pattern(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08004002 status = ucfg_reg_11d_vdev_delete_update(vdev);
4003 ucfg_scan_set_vdev_del_in_progress(vdev);
4004 hdd_objmgr_put_vdev(adapter);
Yue Maf9782842017-05-08 12:49:49 -07004005
Dustin Brownd28772b2017-03-17 14:16:07 -07004006 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304007 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07004008 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -07004009 status = sme_close_session(hdd_ctx->mac_handle, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004010 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Brown2da29eb2018-07-13 14:23:12 -07004011 hdd_err("failed to close sme session; status:%d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08004012 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07004013 }
4014
4015 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304016 status = qdf_wait_for_event_completion(
4017 &adapter->qdf_session_close_event,
Abhishek Singh13bf0ce2018-10-24 14:26:14 +05304018 SME_CMD_VDEV_CREATE_DELETE_TIMEOUT);
Dustin Brown2da29eb2018-07-13 14:23:12 -07004019
4020 if (QDF_IS_STATUS_ERROR(status)) {
4021 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
4022
Dustin Brownd28772b2017-03-17 14:16:07 -07004023 if (adapter->device_mode == QDF_NDI_MODE)
4024 hdd_ndp_session_end_handler(adapter);
Dustin Brown2da29eb2018-07-13 14:23:12 -07004025
4026 if (status == QDF_STATUS_E_TIMEOUT)
4027 hdd_err("timed out waiting for sme close session");
4028 else if (adapter->qdf_session_close_event.force_set)
4029 hdd_info("SSR occurred during sme close session");
4030 else
4031 hdd_err("failed to wait for sme close session; status:%u",
4032 status);
Dustin Brownd28772b2017-03-17 14:16:07 -07004033 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08004034
Yue Maf9782842017-05-08 12:49:49 -07004035release_vdev:
Jiachao Wu2c42c222018-01-15 18:13:19 +08004036
Sandeep Puligillaef415362017-08-30 16:37:13 -07004037 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08004038 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07004039 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08004040 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07004041 return errno;
4042 }
4043
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004044 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004045
4046 return 0;
4047}
4048
Krunal Sonib51eec72017-11-20 21:53:01 -08004049static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
4050 struct sme_session_params *session_param,
Jeff Johnson6a18c962018-07-01 09:09:37 -07004051 csr_roam_complete_cb callback,
Krunal Sonib51eec72017-11-20 21:53:01 -08004052 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07004053{
Dustin Brownd28772b2017-03-17 14:16:07 -07004054 uint32_t type;
4055 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08004056 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07004057
4058 /* determine vdev (sub)type */
4059 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304060 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07004061 hdd_err("failed to get vdev type: %d", status);
4062 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004063 }
Krunal Sonib51eec72017-11-20 21:53:01 -08004064 session_param->sme_session_id = adapter->session_id;
4065 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
4066 session_param->type_of_persona = type;
4067 session_param->subtype_of_persona = sub_type;
4068 session_param->session_open_cb = hdd_sme_open_session_callback;
4069 session_param->session_close_cb = hdd_sme_close_session_callback;
4070 session_param->callback = callback;
4071 session_param->callback_ctx = callback_ctx;
4072
4073 return 0;
4074}
4075
gaurank kathpalia78af1932018-10-27 20:33:10 +05304076static void
4077hdd_store_nss_chains_cfg_in_vdev(struct hdd_adapter *adapter)
4078{
4079 struct wlan_mlme_nss_chains vdev_ini_cfg;
4080 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4081
gaurank kathpaliab414bce2018-11-09 18:44:46 +05304082 /* Populate the nss chain params from ini for this vdev type */
gaurank kathpalia78af1932018-10-27 20:33:10 +05304083 sme_populate_nss_chain_params(hdd_ctx->mac_handle, &vdev_ini_cfg,
4084 adapter->device_mode,
4085 hdd_ctx->num_rf_chains);
gaurank kathpaliab414bce2018-11-09 18:44:46 +05304086
4087 /* Store the nss chain config into the vdev */
4088 sme_store_nss_chains_cfg_in_vdev(adapter->vdev, &vdev_ini_cfg);
gaurank kathpalia78af1932018-10-27 20:33:10 +05304089}
gaurank kathpalia6982d472018-10-31 21:54:15 +05304090
4091bool hdd_is_vdev_in_conn_state(struct hdd_adapter *adapter)
4092{
4093 switch (adapter->device_mode) {
4094 case QDF_STA_MODE:
4095 case QDF_P2P_CLIENT_MODE:
4096 case QDF_P2P_DEVICE_MODE:
4097 return hdd_conn_is_connected(
4098 WLAN_HDD_GET_STATION_CTX_PTR(adapter));
4099 case QDF_SAP_MODE:
4100 case QDF_P2P_GO_MODE:
4101 return (test_bit(SOFTAP_BSS_STARTED,
4102 &adapter->event_flags));
4103 default:
4104 hdd_err("Device mode %d invalid", adapter->device_mode);
4105 return 0;
4106 }
4107
4108 return 0;
4109}
4110
Krunal Sonib51eec72017-11-20 21:53:01 -08004111int hdd_vdev_create(struct hdd_adapter *adapter,
Jeff Johnson6a18c962018-07-01 09:09:37 -07004112 csr_roam_complete_cb callback, void *ctx)
Krunal Sonib51eec72017-11-20 21:53:01 -08004113{
4114 QDF_STATUS status;
4115 int errno;
Karthik Kantamneni9180c752018-11-14 12:14:17 +05304116 bool bval;
Krunal Sonib51eec72017-11-20 21:53:01 -08004117 struct hdd_context *hdd_ctx;
4118 struct sme_session_params sme_session_params = {0};
Min Liu8c5d99e2018-09-10 17:18:44 +08004119 struct wlan_objmgr_vdev *vdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004120
4121 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07004122
4123 /* do vdev create via objmgr */
4124 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown07901ec2018-09-07 11:02:41 -07004125 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07004126 if (errno) {
4127 hdd_err("failed to create objmgr vdev: %d", errno);
4128 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004129 }
Dustin Brownd28772b2017-03-17 14:16:07 -07004130
4131 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304132 status = qdf_event_reset(&adapter->qdf_session_open_event);
4133 if (QDF_STATUS_SUCCESS != status) {
4134 hdd_err("failed to reinit session open event");
4135 return -EINVAL;
4136 }
Krunal Sonib51eec72017-11-20 21:53:01 -08004137 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
4138 callback, ctx);
4139 if (errno) {
4140 hdd_err("failed to populating SME params");
4141 goto objmgr_vdev_destroy_procedure;
4142 }
Jeff Johnson16528362018-06-14 12:34:16 -07004143 status = sme_open_session(hdd_ctx->mac_handle, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07004144 if (QDF_IS_STATUS_ERROR(status)) {
4145 hdd_err("failed to open sme session: %d", status);
4146 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07004147 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004148 }
4149
4150 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304151 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
Abhishek Singh13bf0ce2018-10-24 14:26:14 +05304152 SME_CMD_VDEV_CREATE_DELETE_TIMEOUT);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304153 if (QDF_STATUS_SUCCESS != status) {
4154 if (adapter->qdf_session_open_event.force_set) {
4155 /*
4156 * SSR/PDR has caused shutdown, which has forcefully
4157 * set the event. Return without the closing session.
4158 */
4159 adapter->session_id = HDD_SESSION_ID_INVALID;
4160 hdd_err("Session open event forcefully set");
4161 return -EINVAL;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304162 }
Jeff Johnsonc66d3102018-02-28 11:58:26 -08004163
4164 if (QDF_STATUS_E_TIMEOUT == status)
4165 hdd_err("Session failed to open within timeout period");
4166 else
4167 hdd_err("Failed to wait for session open event(status-%d)",
4168 status);
4169 errno = -ETIMEDOUT;
4170 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
4171 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004172 }
4173
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05304174 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
4175 hdd_err("Session failed to open due to vdev create failure");
4176 errno = -EINVAL;
4177 goto objmgr_vdev_destroy_procedure;
4178 }
4179
Dustin Brownd28772b2017-03-17 14:16:07 -07004180 /* firmware ready for component communication, raise vdev_ready event */
4181 errno = hdd_vdev_ready(adapter);
4182 if (errno) {
4183 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07004184 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004185 }
4186
Naveen Rawat2b430892018-03-13 13:58:18 -07004187 if (adapter->device_mode == QDF_STA_MODE) {
Karthik Kantamneni9180c752018-11-14 12:14:17 +05304188 bval = false;
4189 status = ucfg_mlme_get_rtt_mac_randomization(hdd_ctx->psoc,
4190 &bval);
4191 if (QDF_IS_STATUS_ERROR(status))
4192 hdd_err("unable to get RTT MAC randomization value");
4193
4194 hdd_debug("setting RTT mac randomization param: %d", bval);
Naveen Rawat2b430892018-03-13 13:58:18 -07004195 errno = sme_cli_set_command(adapter->session_id,
4196 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_INITIATOR_RANDOM_MAC,
Karthik Kantamneni9180c752018-11-14 12:14:17 +05304197 bval,
Naveen Rawat2b430892018-03-13 13:58:18 -07004198 VDEV_CMD);
4199 if (0 != errno)
4200 hdd_err("RTT mac randomization param set failed %d",
4201 errno);
4202 }
4203
Bala Venkatesh110b03e2018-07-10 16:02:08 +05304204 if (adapter->device_mode == QDF_STA_MODE ||
Min Liu8c5d99e2018-09-10 17:18:44 +08004205 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
4206 vdev = hdd_objmgr_get_vdev(adapter);
4207 if (!vdev)
4208 goto hdd_vdev_destroy_procedure;
4209 wlan_vdev_set_max_peer_count(vdev, HDD_MAX_VDEV_PEER_COUNT);
4210 hdd_objmgr_put_vdev(adapter);
4211 }
Bala Venkatesh110b03e2018-07-10 16:02:08 +05304212
gaurank kathpalia78af1932018-10-27 20:33:10 +05304213 hdd_store_nss_chains_cfg_in_vdev(adapter);
4214
Jeff Johnson1b780e42017-10-31 14:11:45 -07004215 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004216
4217 return 0;
4218
4219 /*
4220 * Due to legacy constraints, we need to destroy in the same order as
4221 * create. So, split error handling into 2 cases to accommodate.
4222 */
4223
Krunal Soni4a020c72017-10-30 20:58:40 -07004224objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07004225 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07004226
4227 return errno;
4228
Krunal Soni4a020c72017-10-30 20:58:40 -07004229hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07004230 QDF_BUG(!hdd_vdev_destroy(adapter));
4231
4232 return errno;
4233}
4234
Jeff Johnson9d295242017-08-29 14:39:48 -07004235QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07004236{
Jeff Johnsonb9424862017-10-30 08:49:35 -07004237 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004238 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07004239 QDF_STATUS status;
4240 int ret_val;
Jeff Johnson16528362018-06-14 12:34:16 -07004241 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304242 bool bval = false;
Dustin Brownd28772b2017-03-17 14:16:07 -07004243
Dustin Brownd28772b2017-03-17 14:16:07 -07004244 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -07004245 mac_handle = hdd_ctx->mac_handle;
4246 sme_set_curr_device_mode(mac_handle, adapter->device_mode);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304247 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
4248 if (!QDF_IS_STATUS_SUCCESS(status))
4249 hdd_err("unable to get vht_enable2x2");
4250 sme_set_pdev_ht_vht_ies(mac_handle, bval);
4251
Jeff Johnson16528362018-06-14 12:34:16 -07004252 sme_set_vdev_ies_per_band(mac_handle, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004253
Jeff Johnson7f2c5912018-03-23 11:42:28 -07004254 hdd_roam_profile_init(adapter);
4255 hdd_register_wext(adapter->dev);
4256
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07004257 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004258
Jeff Johnsond377dce2017-10-04 10:32:42 -07004259 qdf_mem_set(sta_ctx->conn_info.staId,
4260 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05304261
Deepak Dhamdherea2785822016-11-17 01:17:45 -08004262 /* set fast roaming capability in sme session */
Jeff Johnson16528362018-06-14 12:34:16 -07004263 status = sme_config_fast_roaming(mac_handle, adapter->session_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05304264 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004265 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004266 sta_ctx->conn_info.operationChannel =
Vignesh Viswanathana0358ff2018-11-27 09:53:07 +05304267 hdd_ctx->config->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004268
4269 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004270 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004271
4272 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304273 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004274 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004275 status, status);
4276 goto error_init_txrx;
4277 }
4278
4279 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4280
4281 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304282 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004283 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004284 status, status);
4285 goto error_wmm_init;
4286 }
4287
4288 set_bit(WMM_INIT_DONE, &adapter->event_flags);
4289
Jeff Johnson1b780e42017-10-31 14:11:45 -07004290 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004291 WMI_PDEV_PARAM_BURST_ENABLE,
Dundi Raviteja3aa01be2018-05-21 18:58:59 +05304292 HDD_ENABLE_SIFS_BURST_DEFAULT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004293 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07004294 if (ret_val)
4295 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004296
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05304297 /*
4298 * In case of USB tethering, LRO is disabled. If SSR happened
4299 * during that time, then as part of SSR init, do not enable
4300 * the LRO again. Keep the LRO state same as before SSR.
4301 */
jitiphil377bcc12018-10-05 19:46:08 +05304302 if (cdp_cfg_get(cds_get_context(QDF_MODULE_ID_SOC),
4303 cfg_dp_lro_enable) &&
4304 !(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07004305 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05304306
4307 /* rcpi info initialization */
4308 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
4309
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304310 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004311
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004312error_wmm_init:
4313 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4314 hdd_deinit_tx_rx(adapter);
4315error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07004316 hdd_unregister_wext(adapter->dev);
Dustin Brownd28772b2017-03-17 14:16:07 -07004317 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004318
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004319 return status;
4320}
4321
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304322/**
Krunal Soni4a020c72017-10-30 20:58:40 -07004323 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304324 * @hdd_ctx: global hdd context
4325 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07004326 * @rtnl_held: Used to indicate whether or not the caller is holding
4327 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304328 *
4329 * This function De-initializes the STA/P2P/OCB adapter.
4330 *
4331 * Return: None.
4332 */
Krunal Soni4a020c72017-10-30 20:58:40 -07004333static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004334 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004335 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304336{
Dustin Brownfdf17c12018-03-14 12:55:34 -07004337 hdd_enter_dev(adapter->dev);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304338
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05304339 if (adapter->dev) {
4340 if (rtnl_held)
4341 adapter->dev->wireless_handlers = NULL;
4342 else {
4343 rtnl_lock();
4344 adapter->dev->wireless_handlers = NULL;
4345 rtnl_unlock();
4346 }
4347 }
4348
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304349 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
4350 hdd_deinit_tx_rx(adapter);
4351 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4352 }
4353
4354 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4355 hdd_wmm_adapter_close(adapter);
4356 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4357 }
4358
Krunal Sonib51eec72017-11-20 21:53:01 -08004359
Dustin Browne74003f2018-03-14 12:51:58 -07004360 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304361}
4362
Krunal Sonib51eec72017-11-20 21:53:01 -08004363void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
4364 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004365 bool rtnl_held)
4366{
Dustin Brown491d54b2018-03-14 12:39:11 -07004367 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304368
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004369 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004370 case QDF_STA_MODE:
4371 case QDF_P2P_CLIENT_MODE:
4372 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08004373 case QDF_IBSS_MODE:
4374 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004375 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004376 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004377 break;
4378 }
4379
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004380 case QDF_SAP_MODE:
4381 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004382 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004383 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004384 break;
4385 }
4386
4387 default:
4388 break;
4389 }
4390
Dustin Browne74003f2018-03-14 12:51:58 -07004391 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004392}
4393
Min Liu8c5d99e2018-09-10 17:18:44 +08004394static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx,
4395 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004396 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004397{
Jeff Johnson5505db82017-11-02 21:19:23 -07004398 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004399
4400 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07004401 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004402 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004403 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004404 return;
4405 }
4406
Alok Kumarb64650c2018-03-23 17:05:11 +05304407 hdd_nud_deinit_tracking(adapter);
4408 qdf_mutex_destroy(&adapter->disconnection_status_lock);
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05304409 hdd_apf_context_destroy(adapter);
Min Liu8c5d99e2018-09-10 17:18:44 +08004410 qdf_spinlock_destroy(&adapter->vdev_lock);
Alok Kumarb64650c2018-03-23 17:05:11 +05304411
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05304412 wlan_hdd_debugfs_csr_deinit(adapter);
4413
Rajeev Kumardca5f812016-02-04 17:28:06 -08004414 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05304415
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004416 /*
4417 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
4418 * the driver is almost closed and cannot handle either control
4419 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004420 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
4421 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004422 * is not right. Setting this flag helps hdd_stop() to recognize that
4423 * the interface is closed and restricts any operations on that
4424 */
4425 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
4426
4427 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004428 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07004429 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004430 else
Jeff Johnson5505db82017-11-02 21:19:23 -07004431 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004432 /*
4433 * Note that the adapter is no longer valid at this point
4434 * since the memory has been reclaimed
4435 */
4436 }
4437}
4438
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004439static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07004440 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004441{
Jeff Johnson9d295242017-08-29 14:39:48 -07004442 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004443
Dustin Brown920397d2017-12-13 16:27:50 -08004444 hdd_for_each_adapter(hdd_ctx, adapter) {
4445 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
4446 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304447 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004448 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004449 }
Dustin Brown920397d2017-12-13 16:27:50 -08004450
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304451 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004452}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004453
Arun Khandavalli2358d522016-05-16 18:05:37 +05304454#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4455/**
4456 * hdd_set_fw_log_params() - Set log parameters to FW
4457 * @hdd_ctx: HDD Context
4458 * @adapter: HDD Adapter
4459 *
4460 * This function set the FW Debug log level based on the INI.
4461 *
4462 * Return: None
4463 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004464static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004465 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304466{
4467 uint8_t count = 0, numentries = 0,
4468 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
4469 uint32_t value = 0;
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304470 QDF_STATUS status;
4471 uint16_t enable_fw_log_level, enable_fw_log_type;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304472 int ret;
4473
Arun Khandavallifae92942016-08-01 13:31:08 +05304474 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4475 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004476 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304477 return;
4478 }
4479
Arun Khandavallifae92942016-08-01 13:31:08 +05304480 /* Enable FW logs based on INI configuration */
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304481 status = ucfg_fwol_get_enable_fw_log_type(hdd_ctx->psoc,
4482 &enable_fw_log_type);
4483 if (QDF_IS_STATUS_ERROR(status))
4484 return;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004485 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304486 WMI_DBGLOG_TYPE,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304487 enable_fw_log_type,
Arun Khandavallifae92942016-08-01 13:31:08 +05304488 DBG_CMD);
4489 if (ret != 0)
4490 hdd_err("Failed to enable FW log type ret %d",
4491 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304492
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304493 status = ucfg_fwol_get_enable_fw_log_level(hdd_ctx->psoc,
4494 &enable_fw_log_level);
4495 if (QDF_IS_STATUS_ERROR(status))
4496 return;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004497 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304498 WMI_DBGLOG_LOG_LEVEL,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304499 enable_fw_log_level,
Arun Khandavallifae92942016-08-01 13:31:08 +05304500 DBG_CMD);
4501 if (ret != 0)
4502 hdd_err("Failed to enable FW log level ret %d",
4503 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304504
4505 hdd_string_to_u8_array(
4506 hdd_ctx->config->enableFwModuleLogLevel,
4507 moduleloglevel,
4508 &numentries,
4509 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
4510
4511 while (count < numentries) {
4512 /*
4513 * FW module log level input string looks like
4514 * below:
4515 * gFwDebugModuleLoglevel=<FW Module ID>,
4516 * <Log Level>,...
4517 * For example:
4518 * gFwDebugModuleLoglevel=
4519 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
4520 * Above input string means :
4521 * For FW module ID 1 enable log level 0
4522 * For FW module ID 2 enable log level 1
4523 * For FW module ID 3 enable log level 2
4524 * For FW module ID 4 enable log level 3
4525 * For FW module ID 5 enable log level 4
4526 * For FW module ID 6 enable log level 5
4527 * For FW module ID 7 enable log level 6
4528 */
4529
Nishank Aggarwale239d962017-03-03 12:26:02 +05304530 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
4531 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
4532 hdd_err("Module id %d and dbglog level %d input length is more than max",
4533 moduleloglevel[count],
4534 moduleloglevel[count + 1]);
4535 return;
4536 }
4537
4538 value = moduleloglevel[count] << 16;
4539 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07004540 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304541 WMI_DBGLOG_MOD_LOG_LEVEL,
4542 value, DBG_CMD);
4543 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304544 hdd_err("Failed to enable FW module log level %d ret %d",
4545 value, ret);
4546
4547 count += 2;
4548 }
Arun Khandavallifae92942016-08-01 13:31:08 +05304549
Arun Khandavalli2358d522016-05-16 18:05:37 +05304550}
4551#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004552static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004553 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304554{
4555}
4556
4557#endif
4558
4559/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004560 * hdd_configure_chain_mask() - programs chain mask to firmware
4561 * @adapter: HDD adapter
4562 *
4563 * Return: 0 on success or errno on failure
4564 */
4565static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4566{
Naveen Rawat98322472018-03-06 10:29:42 -08004567 QDF_STATUS status;
4568 struct wma_caps_per_phy non_dbs_phy_cap;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004569 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304570 bool enable2x2 = false, enable_bt_chain_sep = false;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304571
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304572 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &enable2x2);
4573 if (QDF_IS_STATUS_ERROR(status))
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304574 hdd_err("unable to get vht_enable2x2");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004575
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304576 status = ucfg_mlme_get_bt_chain_separation_flag(hdd_ctx->psoc,
4577 &enable_bt_chain_sep);
4578 if (QDF_IS_STATUS_ERROR(status))
4579 hdd_debug("unable to get BT chain separation. using default");
4580
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304581 hdd_debug("enable2x2: %d, lte_coex: %d, disable_DBS: %d",
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304582 enable2x2, hdd_ctx->lte_coex_ant_share,
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304583 hdd_ctx->config->dual_mac_feature_disable);
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304584 hdd_debug("enable_bt_chain_separation %d", enable_bt_chain_sep);
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004585
Naveen Rawat98322472018-03-06 10:29:42 -08004586 status = wma_get_caps_for_phyidx_hwmode(&non_dbs_phy_cap,
4587 HW_MODE_DBS_NONE,
4588 CDS_BAND_ALL);
4589 if (QDF_IS_STATUS_ERROR(status)) {
4590 hdd_err("couldn't get phy caps. skip chain mask programming");
4591 return qdf_status_to_os_return(status);
4592 }
4593
4594 if (non_dbs_phy_cap.tx_chain_mask_2G < 3 ||
4595 non_dbs_phy_cap.rx_chain_mask_2G < 3 ||
4596 non_dbs_phy_cap.tx_chain_mask_5G < 3 ||
4597 non_dbs_phy_cap.rx_chain_mask_5G < 3) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004598 hdd_debug("firmware not capable. skip chain mask programming");
Naveen Rawat98322472018-03-06 10:29:42 -08004599 return 0;
4600 }
4601
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304602 if (enable2x2 && !enable_bt_chain_sep) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004603 hdd_debug("2x2 enabled. skip chain mask programming");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004604 return 0;
4605 }
4606
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004607 if (hdd_ctx->config->dual_mac_feature_disable !=
4608 DISABLE_DBS_CXN_AND_SCAN) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004609 hdd_debug("DBS enabled(%d). skip chain mask programming",
4610 hdd_ctx->config->dual_mac_feature_disable);
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004611 return 0;
4612 }
4613
Naveen Rawatdacb5032018-02-08 15:23:24 -08004614 if (hdd_ctx->lte_coex_ant_share) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004615 hdd_debug("lte ant sharing enabled. skip chainmask programming");
Naveen Rawatdacb5032018-02-08 15:23:24 -08004616 return 0;
4617 }
4618
Dustin Brown1dbefe62018-09-11 16:32:03 -07004619 status = ucfg_mlme_configure_chain_mask(hdd_ctx->psoc,
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304620 adapter->session_id);
4621 if (status != QDF_STATUS_SUCCESS)
4622 goto error;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004623
4624 return 0;
4625
4626error:
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304627 hdd_err("WMI PDEV set param failed");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004628 return -EINVAL;
4629}
4630
4631/**
Dundi Raviteja3b637092018-09-12 13:42:50 +05304632 * hdd_send_coex_config_params() - Send coex config params to FW
4633 * @hdd_ctx: HDD context
4634 * @adapter: Primary adapter context
4635 *
4636 * This function is used to send all coex config related params to FW
4637 *
4638 * Return: 0 on success and -EINVAL on failure
4639 */
4640static int hdd_send_coex_config_params(struct hdd_context *hdd_ctx,
4641 struct hdd_adapter *adapter)
4642{
4643 struct coex_config_params coex_cfg_params = {0};
4644 struct wlan_fwol_coex_config config = {0};
Dustin Brown05d81302018-09-11 16:49:22 -07004645 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Dundi Raviteja3b637092018-09-12 13:42:50 +05304646 QDF_STATUS status;
4647
4648 if (!hdd_ctx) {
4649 hdd_err("hdd_ctx is invalid");
4650 goto err;
4651 }
4652
4653 if (!adapter) {
4654 hdd_err("adapter is invalid");
4655 goto err;
4656 }
4657
4658 if (!psoc) {
4659 hdd_err("HDD psoc is invalid");
4660 goto err;
4661 }
4662
4663 status = ucfg_fwol_get_coex_config_params(psoc, &config);
4664 if (QDF_IS_STATUS_ERROR(status)) {
4665 hdd_err("Unable to get coex config params");
4666 goto err;
4667 }
4668
4669 coex_cfg_params.vdev_id = adapter->session_id;
4670 coex_cfg_params.config_type = WMI_COEX_CONFIG_TX_POWER;
4671 coex_cfg_params.config_arg1 = config.max_tx_power_for_btc;
4672
4673 status = sme_send_coex_config_cmd(&coex_cfg_params);
4674 if (QDF_IS_STATUS_ERROR(status)) {
4675 hdd_err("Failed to send coex Tx power");
4676 goto err;
4677 }
4678
4679 coex_cfg_params.config_type = WMI_COEX_CONFIG_HANDOVER_RSSI;
4680 coex_cfg_params.config_arg1 = config.wlan_low_rssi_threshold;
4681
4682 status = sme_send_coex_config_cmd(&coex_cfg_params);
4683 if (QDF_IS_STATUS_ERROR(status)) {
4684 hdd_err("Failed to send coex handover RSSI");
4685 goto err;
4686 }
4687
4688 coex_cfg_params.config_type = WMI_COEX_CONFIG_BTC_MODE;
4689 coex_cfg_params.config_arg1 = config.btc_mode;
4690
4691 status = sme_send_coex_config_cmd(&coex_cfg_params);
4692 if (QDF_IS_STATUS_ERROR(status)) {
4693 hdd_err("Failed to send coex BTC mode");
4694 goto err;
4695 }
4696
4697 coex_cfg_params.config_type = WMI_COEX_CONFIG_ANTENNA_ISOLATION;
4698 coex_cfg_params.config_arg1 = config.antenna_isolation;
4699
4700 status = sme_send_coex_config_cmd(&coex_cfg_params);
4701 if (QDF_IS_STATUS_ERROR(status)) {
4702 hdd_err("Failed to send coex antenna isolation");
4703 goto err;
4704 }
4705
4706 coex_cfg_params.config_type = WMI_COEX_CONFIG_BT_LOW_RSSI_THRESHOLD;
4707 coex_cfg_params.config_arg1 = config.bt_low_rssi_threshold;
4708
4709 status = sme_send_coex_config_cmd(&coex_cfg_params);
4710 if (QDF_IS_STATUS_ERROR(status)) {
4711 hdd_err("Failed to send coex BT low RSSI threshold");
4712 goto err;
4713 }
4714
4715 coex_cfg_params.config_type = WMI_COEX_CONFIG_BT_INTERFERENCE_LEVEL;
4716 coex_cfg_params.config_arg1 = config.bt_interference_low_ll;
4717 coex_cfg_params.config_arg2 = config.bt_interference_low_ul;
4718 coex_cfg_params.config_arg3 = config.bt_interference_medium_ll;
4719 coex_cfg_params.config_arg4 = config.bt_interference_medium_ul;
4720 coex_cfg_params.config_arg5 = config.bt_interference_high_ll;
4721 coex_cfg_params.config_arg6 = config.bt_interference_high_ul;
4722
4723 status = sme_send_coex_config_cmd(&coex_cfg_params);
4724 if (QDF_IS_STATUS_ERROR(status)) {
4725 hdd_err("Failed to send coex BT interference level");
4726 goto err;
4727 }
4728 return 0;
4729err:
4730 return -EINVAL;
4731}
4732
4733/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304734 * hdd_set_fw_params() - Set parameters to firmware
4735 * @adapter: HDD adapter
4736 *
4737 * This function Sets various parameters to fw once the
4738 * adapter is started.
4739 *
4740 * Return: 0 on success or errno on failure
4741 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004742int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304743{
4744 int ret;
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304745 uint16_t upper_brssi_thresh, lower_brssi_thresh, rts_profile;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304746 bool enable_dtim_1chrx;
4747 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004748 struct hdd_context *hdd_ctx;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304749 bool bval = false;
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05304750 uint8_t max_amsdu_len;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304751
Dustin Brownfdf17c12018-03-14 12:55:34 -07004752 hdd_enter_dev(adapter->dev);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304753
4754 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4755 if (!hdd_ctx)
4756 return -EINVAL;
4757
Dustin Brown732ab9c2017-06-15 13:24:09 -07004758 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4759 hdd_debug("FTM Mode is active; nothing to do");
4760 return 0;
4761 }
4762
Jeff Johnson1b780e42017-10-31 14:11:45 -07004763 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304764 WMI_PDEV_PARAM_DTIM_SYNTH,
4765 hdd_ctx->config->enable_lprx, PDEV_CMD);
4766 if (ret) {
4767 hdd_err("Failed to set LPRx");
4768 goto error;
4769 }
4770
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304771
4772 ret = sme_cli_set_command(
4773 adapter->session_id,
4774 WMI_PDEV_PARAM_1CH_DTIM_OPTIMIZED_CHAIN_SELECTION,
4775 hdd_ctx->config->enable_dtim_selection_diversity,
4776 PDEV_CMD);
4777 if (ret) {
4778 hdd_err("Failed to set DTIM_OPTIMIZED_CHAIN_SELECTION");
4779 goto error;
4780 }
4781
Ashish Kumar Dhanotiya48dac7d2018-03-28 14:59:50 +05304782 ret = sme_cli_set_command(
4783 adapter->session_id,
4784 WMI_PDEV_PARAM_TX_SCH_DELAY,
4785 hdd_ctx->config->enable_tx_sch_delay,
4786 PDEV_CMD);
4787 if (ret) {
4788 hdd_err("Failed to set WMI_PDEV_PARAM_TX_SCH_DELAY");
4789 goto error;
4790 }
4791
Ashish Kumar Dhanotiya959b38c2018-04-06 21:07:57 +05304792 ret = sme_cli_set_command(
4793 adapter->session_id,
4794 WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE,
4795 hdd_ctx->config->enable_secondary_rate,
4796 PDEV_CMD);
4797 if (ret) {
4798 hdd_err("Failed to set WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE");
4799 goto error;
4800 }
4801
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304802 if (adapter->device_mode == QDF_STA_MODE) {
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304803 status = ucfg_get_upper_brssi_thresh(hdd_ctx->psoc,
4804 &upper_brssi_thresh);
4805 if (QDF_IS_STATUS_ERROR(status))
4806 return -EINVAL;
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304807
Jeff Johnson1b780e42017-10-31 14:11:45 -07004808 sme_set_smps_cfg(adapter->session_id,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304809 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4810 upper_brssi_thresh);
4811
4812 status = ucfg_get_lower_brssi_thresh(hdd_ctx->psoc,
4813 &lower_brssi_thresh);
4814 if (QDF_IS_STATUS_ERROR(status))
4815 return -EINVAL;
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304816
Jeff Johnson1b780e42017-10-31 14:11:45 -07004817 sme_set_smps_cfg(adapter->session_id,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304818 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4819 lower_brssi_thresh);
4820
4821 status = ucfg_get_enable_dtim_1chrx(hdd_ctx->psoc,
4822 &enable_dtim_1chrx);
4823 if (QDF_IS_STATUS_ERROR(status))
4824 return -EINVAL;
4825
4826 sme_set_smps_cfg(adapter->session_id,
4827 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4828 enable_dtim_1chrx);
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304829 }
4830
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304831 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
4832 if (!QDF_IS_STATUS_SUCCESS(status))
4833 hdd_err("unable to get vht_enable2x2");
4834
4835 if (bval) {
Dustin Brown732ab9c2017-06-15 13:24:09 -07004836 hdd_debug("configuring 2x2 mode fw params");
4837
Vignesh Viswanathana851d752018-10-03 19:44:38 +05304838 ret = sme_set_cck_tx_fir_override(hdd_ctx->mac_handle,
4839 adapter->session_id);
Dustin Brown732ab9c2017-06-15 13:24:09 -07004840 if (ret) {
4841 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4842 ret);
4843 goto error;
4844 }
Liangwei Dong22810e82018-03-15 03:42:12 -04004845
4846 if (hdd_configure_chain_mask(adapter))
4847 goto error;
Dustin Brown732ab9c2017-06-15 13:24:09 -07004848 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304849#define HDD_DTIM_1CHAIN_RX_ID 0x5
4850#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004851 hdd_debug("configuring 1x1 mode fw params");
4852
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004853 /*
4854 * Disable DTIM 1 chain Rx when in 1x1,
4855 * we are passing two value
4856 * as param_id << 29 | param_value.
4857 * Below param_value = 0(disable)
4858 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004859 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004860 WMI_STA_SMPS_PARAM_CMDID,
4861 HDD_DTIM_1CHAIN_RX_ID <<
4862 HDD_SMPS_PARAM_VALUE_S,
4863 VDEV_CMD);
4864 if (ret) {
4865 hdd_err("DTIM 1 chain set failed %d", ret);
4866 goto error;
4867 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304868
Arun Khandavalli2358d522016-05-16 18:05:37 +05304869#undef HDD_DTIM_1CHAIN_RX_ID
4870#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004871
4872 if (hdd_configure_chain_mask(adapter))
4873 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004874 }
4875
Vignesh Viswanathana851d752018-10-03 19:44:38 +05304876 ret = sme_set_enable_mem_deep_sleep(hdd_ctx->mac_handle,
4877 adapter->session_id);
Dustin Brown732ab9c2017-06-15 13:24:09 -07004878 if (ret) {
4879 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4880 goto error;
4881 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304882
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304883 status = ucfg_fwol_get_rts_profile(hdd_ctx->psoc, &rts_profile);
4884 if (QDF_IS_STATUS_ERROR(status))
4885 return -EINVAL;
4886
Jeff Johnson1b780e42017-10-31 14:11:45 -07004887 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004888 WMI_VDEV_PARAM_ENABLE_RTSCTS,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304889 rts_profile,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004890 VDEV_CMD);
4891 if (ret) {
4892 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4893 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304894 }
4895
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05304896 status = ucfg_mlme_get_max_amsdu_num(hdd_ctx->psoc, &max_amsdu_len);
4897 if (QDF_IS_STATUS_ERROR(status)) {
4898 hdd_err("Failed to get Max AMSDU Num");
4899 goto error;
4900 }
4901
4902 hdd_debug("SET AMSDU num %d", max_amsdu_len);
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004903
Jeff Johnson1b780e42017-10-31 14:11:45 -07004904 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004905 GEN_VDEV_PARAM_AMSDU,
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05304906 max_amsdu_len,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004907 GEN_CMD);
4908 if (ret != 0) {
4909 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4910 goto error;
4911 }
4912
Arun Khandavalli2358d522016-05-16 18:05:37 +05304913 hdd_set_fw_log_params(hdd_ctx, adapter);
Dundi Raviteja3b637092018-09-12 13:42:50 +05304914
4915 ret = hdd_send_coex_config_params(hdd_ctx, adapter);
4916 if (ret) {
4917 hdd_warn("Error initializing coex config params");
4918 goto error;
4919 }
4920
Dustin Browne74003f2018-03-14 12:51:58 -07004921 hdd_exit();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004922
Arun Khandavalli2358d522016-05-16 18:05:37 +05304923 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304924
Arun Khandavalli2358d522016-05-16 18:05:37 +05304925error:
4926 return -EINVAL;
4927}
4928
Ryan Hsu07495ea2016-01-21 15:25:39 -08004929/**
Abhinav Kumarcc959f12018-08-09 13:58:30 +05304930 * hdd_init_completion() - Initialize Completion Variables
4931 * @adapter: HDD adapter
4932 *
4933 * This function Initialize the completion variables for
4934 * a particular adapter
4935 *
4936 * Return: None
4937 */
4938static void hdd_init_completion(struct hdd_adapter *adapter)
4939{
4940 init_completion(&adapter->disconnect_comp_var);
4941 init_completion(&adapter->roaming_comp_var);
4942 init_completion(&adapter->linkup_event_var);
4943 init_completion(&adapter->cancel_rem_on_chan_var);
4944 init_completion(&adapter->rem_on_chan_ready_event);
4945 init_completion(&adapter->sta_authorized_event);
4946 init_completion(&adapter->offchannel_tx_event);
4947 init_completion(&adapter->tx_action_cnf_event);
4948 init_completion(&adapter->ibss_peer_info_comp);
4949 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
4950}
4951
4952/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08004953 * hdd_open_adapter() - open and setup the hdd adatper
4954 * @hdd_ctx: global hdd context
4955 * @session_type: type of the interface to be created
4956 * @iface_name: User-visible name of the interface
4957 * @macAddr: MAC address to assign to the interface
4958 * @name_assign_type: the name of assign type of the netdev
4959 * @rtnl_held: the rtnl lock hold flag
4960 *
4961 * This function open and setup the hdd adpater according to the device
4962 * type request, assign the name, the mac address assigned, and then prepared
4963 * the hdd related parameters, queue, lock and ready to start.
4964 *
4965 * Return: the pointer of hdd adapter, otherwise NULL.
4966 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004967struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004968 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08004969 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004970 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004971{
Jeff Johnson9d295242017-08-29 14:39:48 -07004972 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304973 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05304974 uint8_t i;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004975
4976 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4977 /*
4978 * Max limit reached on the number of vdevs configured by the
4979 * host. Return error
4980 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304981 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4982 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004983 return NULL;
4984 }
4985
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05304986 status = wlan_hdd_validate_mac_address((struct qdf_mac_addr *)macAddr);
4987 if (QDF_IS_STATUS_ERROR(status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004988 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304989 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004990 return NULL;
4991 }
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05304992
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004993 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304994 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304995 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4996 " already exists",
4997 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004998 return NULL;
4999 }
5000
5001 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005002 case QDF_STA_MODE:
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05305003 /*
5004 * Reset locally administered bit for dynamic_mac_list
5005 * also as while releasing the MAC address for any interface
5006 * mac will be compared with dynamic mac list
5007 */
5008 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
5009 if (!qdf_mem_cmp(
5010 macAddr,
5011 &hdd_ctx->dynamic_mac_list[i].bytes[0],
5012 sizeof(struct qdf_mac_addr))) {
5013 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(
5014 hdd_ctx->dynamic_mac_list[i].bytes);
5015 break;
5016 }
5017 }
5018
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005019 /* Reset locally administered bit if the device mode is STA */
5020 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Dustin Brown7e761c72018-07-31 13:50:17 -07005021 hdd_debug("locally administered bit reset in sta mode: "
5022 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005023 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005024 case QDF_P2P_CLIENT_MODE:
5025 case QDF_P2P_DEVICE_MODE:
5026 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07005027 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305028 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08005029 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
5030 name_assign_type,
5031 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005032
5033 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305034 hdd_err("failed to allocate adapter for session %d",
5035 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005036 return NULL;
5037 }
5038
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005039 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005040 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005041 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005042 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305043 else if (QDF_MONITOR_MODE == session_type)
5044 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005045 else
5046 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
5047
5048 adapter->device_mode = session_type;
5049
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005050
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005051 /*
5052 * Workqueue which gets scheduled in IPv4 notification
5053 * callback
5054 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005055 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005056 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005057
5058#ifdef WLAN_NS_OFFLOAD
5059 /*
5060 * Workqueue which gets scheduled in IPv6
5061 * notification callback.
5062 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005063 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005064 hdd_ipv6_notifier_work_queue);
5065#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005066 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08005067 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08005068 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005069
5070 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005071 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005072 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305073 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5074 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05305075
Alok Kumarb64650c2018-03-23 17:05:11 +05305076 hdd_nud_init_tracking(adapter);
5077
5078 qdf_mutex_create(&adapter->disconnection_status_lock);
5079
Ravi Joshi1a292562017-05-18 16:28:54 -07005080 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005081
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005082 case QDF_P2P_GO_MODE:
5083 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08005084 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
5085 name_assign_type,
5086 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005087 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005088 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05305089 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005090 return NULL;
5091 }
5092
5093 adapter->wdev.iftype =
5094 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005095 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005096 NL80211_IFTYPE_P2P_GO;
5097 adapter->device_mode = session_type;
5098
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07005099 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08005100 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005101 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08005102
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005103 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005104 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305105 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5106 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305107
5108 /*
5109 * Workqueue which gets scheduled in IPv4 notification
5110 * callback
5111 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005112 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305113 hdd_ipv4_notifier_work_queue);
5114
5115#ifdef WLAN_NS_OFFLOAD
5116 /*
5117 * Workqueue which gets scheduled in IPv6
5118 * notification callback.
5119 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005120 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305121 hdd_ipv6_notifier_work_queue);
5122#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005123 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305124 case QDF_FTM_MODE:
5125 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
5126 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08005127 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305128 if (NULL == adapter) {
5129 hdd_err("Failed to allocate adapter for FTM mode");
5130 return NULL;
5131 }
5132 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
5133 adapter->device_mode = session_type;
5134 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08005135 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08005136 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08005137
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305138 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005139 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305140 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305141 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5142 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305143 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005144 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005145 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305146 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005147 return NULL;
5148 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005149
Min Liu8c5d99e2018-09-10 17:18:44 +08005150 qdf_spinlock_create(&adapter->vdev_lock);
5151
Abhinav Kumarcc959f12018-08-09 13:58:30 +05305152 hdd_init_completion(adapter);
hqueaa33ee2017-05-04 17:56:35 +08005153 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
Min Liu9be5d4a2018-05-17 11:51:53 +08005154 qdf_list_create(&adapter->blocked_scan_request_q, WLAN_MAX_SCAN_COUNT);
5155 qdf_mutex_create(&adapter->blocked_scan_request_q_lock);
hqueaa33ee2017-05-04 17:56:35 +08005156
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305157 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005158 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08005159 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005160 }
5161
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305162 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005163 if (NULL != adapter) {
5164 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
5165 adapter = NULL;
5166 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005167
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005168 return NULL;
5169 }
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05305170 hdd_apf_context_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005171
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305172 if (QDF_STATUS_SUCCESS == status) {
Dustin Brown1dbefe62018-09-11 16:32:03 -07005173 policy_mgr_set_concurrency_mode(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005174 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005175
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005176 /* Adapter successfully added. Increment the vdev count */
5177 hdd_ctx->current_intf_count++;
5178
Jeff Johnson5880d792016-08-15 13:32:30 -07005179 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005180 hdd_ctx->current_intf_count);
5181
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08005182 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005183 }
5184
Rajeev Kumardca5f812016-02-04 17:28:06 -08005185 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07005186 hdd_err("Interface %s wow debug_fs init failed",
5187 netdev_name(adapter->dev));
5188
Ajit Pal Singh106c1412018-04-18 18:08:49 +05305189 hdd_register_hl_netdev_fc_timer(adapter,
5190 hdd_tx_resume_timer_expired_handler);
5191
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07005192 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
5193 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005194
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05305195 if (adapter->device_mode == QDF_STA_MODE)
5196 wlan_hdd_debugfs_csr_init(adapter);
5197
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005198 return adapter;
5199
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005200err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07005201 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05305202 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005203
5204 return NULL;
5205}
5206
Dustin Brown728d65a2018-10-02 16:27:52 -07005207static void __hdd_close_adapter(struct hdd_context *hdd_ctx,
5208 struct hdd_adapter *adapter,
5209 bool rtnl_held)
5210{
5211 qdf_list_destroy(&adapter->blocked_scan_request_q);
5212 qdf_mutex_destroy(&adapter->blocked_scan_request_q_lock);
5213 policy_mgr_clear_concurrency_mode(hdd_ctx->psoc, adapter->device_mode);
5214
5215 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
5216
5217 if (hdd_ctx->current_intf_count != 0)
5218 hdd_ctx->current_intf_count--;
5219}
5220
5221void hdd_close_adapter(struct hdd_context *hdd_ctx,
5222 struct hdd_adapter *adapter,
5223 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005224{
Dustin Brown920397d2017-12-13 16:27:50 -08005225 /*
Dustin Brown728d65a2018-10-02 16:27:52 -07005226 * Stop the global bus bandwidth timer while touching the adapter list
5227 * to avoid bad memory access by the timer handler.
Dustin Brown920397d2017-12-13 16:27:50 -08005228 */
Dustin Brown920397d2017-12-13 16:27:50 -08005229 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005230
Dustin Brown920397d2017-12-13 16:27:50 -08005231 hdd_remove_adapter(hdd_ctx, adapter);
Dustin Brown728d65a2018-10-02 16:27:52 -07005232 __hdd_close_adapter(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005233
Dustin Brown920397d2017-12-13 16:27:50 -08005234 /* conditionally restart the bw timer */
5235 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005236}
5237
Dustin Brown728d65a2018-10-02 16:27:52 -07005238void hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005239{
Dustin Brown920397d2017-12-13 16:27:50 -08005240 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005241
Dustin Brown491d54b2018-03-14 12:39:11 -07005242 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005243
Dustin Brown728d65a2018-10-02 16:27:52 -07005244 while (QDF_IS_STATUS_SUCCESS(hdd_remove_front_adapter(hdd_ctx,
5245 &adapter))) {
5246 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
5247 __hdd_close_adapter(hdd_ctx, adapter, rtnl_held);
5248 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005249
Dustin Browne74003f2018-03-14 12:51:58 -07005250 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005251}
5252
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005253void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005254{
Anurag Chouhan6d760662016-02-20 16:05:43 +05305255 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005256 tSirUpdateIE updateIE;
Jeff Johnson16528362018-06-14 12:34:16 -07005257 mac_handle_t mac_handle;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005258
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005259 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005260 case QDF_STA_MODE:
5261 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005262 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005263 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005264 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07005265 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005266 break;
5267 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005268 case QDF_SAP_MODE:
5269 case QDF_P2P_GO_MODE:
5270 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005271 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07005272 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005273 break;
5274 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005275 case QDF_FTM_MODE:
5276 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005277 default:
5278 /*
5279 * wlan_hdd_reset_prob_rspies should not have been called
5280 * for these kind of devices
5281 */
Jeff Johnson5880d792016-08-15 13:32:30 -07005282 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005283 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005284 return;
5285 }
5286
Anurag Chouhanc5548422016-02-24 18:33:27 +05305287 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005288 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005289 updateIE.ieBufferlength = 0;
5290 updateIE.pAdditionIEBuffer = NULL;
5291 updateIE.append = true;
5292 updateIE.notify = false;
Jeff Johnson16528362018-06-14 12:34:16 -07005293 mac_handle = hdd_adapter_get_mac_handle(adapter);
5294 if (sme_update_add_ie(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005295 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305296 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005297 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005298 }
5299}
5300
Dustin Browndb2a8be2017-12-20 11:49:56 -08005301QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
5302 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005303{
Liangwei Dongad89c762018-06-01 01:56:23 -04005304 return hdd_stop_adapter_ext(hdd_ctx, adapter, 0);
5305}
5306
5307QDF_STATUS hdd_stop_adapter_ext(struct hdd_context *hdd_ctx,
5308 struct hdd_adapter *adapter,
5309 enum hdd_adapter_stop_flag_t flag)
5310{
Dustin Brownd747ecd2018-10-26 16:32:22 -07005311 QDF_STATUS status = QDF_STATUS_SUCCESS;
5312 struct hdd_station_ctx *sta_ctx;
Jeff Johnson025618c2018-03-18 14:41:00 -07005313 struct csr_roam_profile *roam_profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005314 union iwreq_data wrqu;
5315 tSirUpdateIE updateIE;
5316 unsigned long rc;
Jeff Johnsone4c11db2018-05-05 23:22:32 -07005317 tsap_config_t *sap_config;
Jeff Johnson16528362018-06-14 12:34:16 -07005318 mac_handle_t mac_handle;
Min Liu8c5d99e2018-09-10 17:18:44 +08005319 struct wlan_objmgr_vdev *vdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005320
Dustin Brown491d54b2018-03-14 12:39:11 -07005321 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005322
Dustin Browne7e71d32018-05-11 16:00:08 -07005323 if (adapter->session_id != HDD_SESSION_ID_INVALID)
5324 wlan_hdd_cfg80211_deregister_frames(adapter);
5325
Alok Kumarb64650c2018-03-23 17:05:11 +05305326 hdd_nud_ignore_tracking(adapter, true);
5327 hdd_nud_reset_tracking(adapter);
Alok Kumar016a1ac2018-09-16 09:55:50 +05305328 hdd_nud_flush_work(adapter);
hangtian9c47aaf2018-11-26 17:59:39 +08005329 hdd_stop_tsf_sync(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05305330
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005331 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305332 wlan_hdd_netif_queue_control(adapter,
5333 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5334 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08005335 /*
5336 * if this is the last active connection check & stop the
5337 * opportunistic timer first
5338 */
Dustin Brownd747ecd2018-10-26 16:32:22 -07005339 if ((policy_mgr_get_connection_count(hdd_ctx->psoc) == 1 &&
5340 policy_mgr_mode_specific_connection_count(hdd_ctx->psoc,
5341 policy_mgr_convert_device_mode_to_qdf_type(
5342 adapter->device_mode), NULL) == 1) ||
5343 !policy_mgr_get_connection_count(hdd_ctx->psoc))
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08005344 policy_mgr_check_and_stop_opportunistic_timer(
Dustin Brown1dbefe62018-09-11 16:32:03 -07005345 hdd_ctx->psoc, adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -07005346
5347 mac_handle = hdd_ctx->mac_handle;
5348
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005349 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005350 case QDF_STA_MODE:
5351 case QDF_P2P_CLIENT_MODE:
5352 case QDF_IBSS_MODE:
5353 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005354 case QDF_NDI_MODE:
Dustin Brownd747ecd2018-10-26 16:32:22 -07005355 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
5356
5357 if (adapter->device_mode == QDF_NDI_MODE ||
5358 hdd_conn_is_connected(sta_ctx) ||
5359 hdd_is_connecting(sta_ctx)) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005360 INIT_COMPLETION(adapter->disconnect_comp_var);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005361
Jeff Johnson025618c2018-03-18 14:41:00 -07005362 roam_profile = hdd_roam_profile(adapter);
5363 /* For NDI do not use roam_profile */
Dustin Brownd747ecd2018-10-26 16:32:22 -07005364 if (adapter->device_mode == QDF_NDI_MODE)
5365 status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005366 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005367 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005368 eCSR_DISCONNECT_REASON_NDI_DELETE);
Jeff Johnson025618c2018-03-18 14:41:00 -07005369 else if (roam_profile->BSSType ==
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005370 eCSR_BSS_TYPE_START_IBSS)
Dustin Brownd747ecd2018-10-26 16:32:22 -07005371 status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005372 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005373 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005374 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Abhinav Kumar19a7a402018-07-12 17:36:57 +05305375 else if (adapter->device_mode == QDF_STA_MODE)
5376 wlan_hdd_disconnect(adapter,
5377 eCSR_DISCONNECT_REASON_DEAUTH);
5378 else
Dustin Brownd747ecd2018-10-26 16:32:22 -07005379 status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005380 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005381 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005382 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005383 /* success implies disconnect is queued */
5384 if (QDF_IS_STATUS_SUCCESS(status) &&
5385 adapter->device_mode != QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005386 rc = wait_for_completion_timeout(
5387 &adapter->disconnect_comp_var,
5388 msecs_to_jiffies
5389 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005390 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005391 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005392 }
Dustin Brownd747ecd2018-10-26 16:32:22 -07005393 if (QDF_IS_STATUS_ERROR(status))
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005394 hdd_warn("failed to post disconnect");
Dustin Brownd747ecd2018-10-26 16:32:22 -07005395
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005396 memset(&wrqu, '\0', sizeof(wrqu));
5397 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5398 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5399 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
5400 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05305401 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005402
Dustin Brownd747ecd2018-10-26 16:32:22 -07005403 wlan_hdd_scan_abort(adapter);
Wu Gao4a1ec8c2018-07-23 19:18:40 +08005404 wlan_hdd_cleanup_actionframe(adapter);
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05305405 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05305406 hdd_clear_fils_connection_info(adapter);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005407 hdd_deregister_tx_flow_control(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005408
5409#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005410 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005411#ifdef WLAN_NS_OFFLOAD
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005412 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005413#endif
5414#endif
5415
Min Liu8c5d99e2018-09-10 17:18:44 +08005416 if (adapter->device_mode == QDF_STA_MODE) {
5417 struct wlan_objmgr_vdev *vdev;
5418
5419 vdev = hdd_objmgr_get_vdev(adapter);
5420 if (vdev) {
5421 wlan_cfg80211_sched_scan_stop(vdev);
5422 hdd_objmgr_put_vdev(adapter);
5423 }
5424 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08005425
5426 if (wlan_hdd_try_disconnect(adapter)) {
Dustin Brownd747ecd2018-10-26 16:32:22 -07005427 hdd_err("Can't disconnect adapter");
Dustin Browndb2a8be2017-12-20 11:49:56 -08005428 return QDF_STATUS_E_FAILURE;
Krunal Soni985b8132017-02-10 18:49:08 -08005429 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08005430
Himanshu Agarwalb229a142017-12-21 10:16:45 +05305431 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005432 break;
5433
Rajeev Kumar3b906202018-02-01 10:55:14 -08005434 case QDF_MONITOR_MODE:
5435 wlan_hdd_scan_abort(adapter);
5436 hdd_deregister_tx_flow_control(adapter);
5437 hdd_vdev_destroy(adapter);
5438 break;
5439
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005440 case QDF_SAP_MODE:
Will Huang7049bae2018-08-13 17:25:02 +08005441 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
5442 cds_flush_delayed_work(&adapter->acs_pending_work);
5443 clear_bit(ACS_PENDING, &adapter->event_flags);
5444 }
Dustin Brownd747ecd2018-10-26 16:32:22 -07005445
wadesongf9b15ed2017-12-14 14:12:32 +08005446 wlan_hdd_scan_abort(adapter);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005447
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05305448 sap_config = &adapter->session.ap.sap_config;
Dustin Brownd747ecd2018-10-26 16:32:22 -07005449 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
5450
Dustin Brown07901ec2018-09-07 11:02:41 -07005451 ucfg_ipa_flush(hdd_ctx->pdev);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005452
Liangwei Dongad89c762018-06-01 01:56:23 -04005453 if (!(flag & HDD_IN_CAC_WORK_TH_CONTEXT))
5454 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Jeff Johnson46807cd2018-04-29 21:32:22 -07005455 /* fallthrough */
Dustin Browna5cf8e02017-10-19 16:04:19 -07005456
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005457 case QDF_P2P_GO_MODE:
Krunal Soni22208392017-09-29 18:10:34 -07005458 cds_flush_work(&adapter->sap_stop_bss_work);
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305459 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005460 wlan_hdd_undo_acs(adapter);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005461
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005462 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005463 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5464
5465 hdd_deregister_tx_flow_control(adapter);
Kapil Guptac1224bf2017-06-22 21:22:40 +05305466 hdd_destroy_acs_timer(adapter);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005467
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005468 mutex_lock(&hdd_ctx->sap_lock);
5469 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005470 status = wlansap_stop_bss(
5471 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005472
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305473 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07005474 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005475 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305476 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305477 qdf_stop_bss_event);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005478 status = qdf_wait_for_event_completion(
Nachiket Kukade0396b732017-11-14 16:35:16 +05305479 &hostapd_state->qdf_stop_bss_event,
Vignesh Viswanathan865daaa2018-10-11 19:30:44 +05305480 SME_CMD_START_STOP_BSS_TIMEOUT);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005481 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson5880d792016-08-15 13:32:30 -07005482 hdd_err("failure waiting for wlansap_stop_bss %d",
Dustin Brownd747ecd2018-10-26 16:32:22 -07005483 status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005484 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07005485 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005486 }
Dustin Brownd747ecd2018-10-26 16:32:22 -07005487
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005488 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -07005489 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005490 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005491 adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005492 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305493 adapter->device_mode,
5494 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005495
Anurag Chouhanc5548422016-02-24 18:33:27 +05305496 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07005497 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005498 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005499 updateIE.ieBufferlength = 0;
5500 updateIE.pAdditionIEBuffer = NULL;
5501 updateIE.append = false;
5502 updateIE.notify = false;
Dustin Brownd747ecd2018-10-26 16:32:22 -07005503
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005504 /* Probe bcn reset */
Dustin Brownd747ecd2018-10-26 16:32:22 -07005505 status = sme_update_add_ie(mac_handle, &updateIE,
5506 eUPDATE_IE_PROBE_BCN);
5507 if (status == QDF_STATUS_E_FAILURE)
5508 hdd_err("Could not pass PROBE_RSP_BCN to PE");
5509
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005510 /* Assoc resp reset */
Dustin Brownd747ecd2018-10-26 16:32:22 -07005511 status = sme_update_add_ie(mac_handle, &updateIE,
5512 eUPDATE_IE_ASSOC_RESP);
5513 if (status == QDF_STATUS_E_FAILURE)
5514 hdd_err("Could not pass ASSOC_RSP to PE");
5515
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005516 /* Reset WNI_CFG_PROBE_RSP Flags */
5517 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005518 }
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005519 clear_bit(SOFTAP_INIT_DONE, &adapter->event_flags);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005520 qdf_mem_free(adapter->session.ap.beacon);
5521 adapter->session.ap.beacon = NULL;
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005522
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305523 /*
5524 * If Do_Not_Break_Stream was enabled clear avoid channel list.
5525 */
Min Liu8c5d99e2018-09-10 17:18:44 +08005526 vdev = hdd_objmgr_get_vdev(adapter);
5527 if (vdev) {
5528 if (policy_mgr_is_dnsc_set(vdev))
5529 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
5530 hdd_objmgr_put_vdev(adapter);
5531 }
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305532
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305533#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005534 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305535#ifdef WLAN_NS_OFFLOAD
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005536 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305537#endif
5538#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08005539
5540 hdd_vdev_destroy(adapter);
5541
Krunal Sonib51eec72017-11-20 21:53:01 -08005542 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005543 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005544 case QDF_OCB_MODE:
Dustin Brownd747ecd2018-10-26 16:32:22 -07005545 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08005546 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Dustin Brownd747ecd2018-10-26 16:32:22 -07005547 cds_get_context(QDF_MODULE_ID_TXRX),
5548 sta_ctx->conn_info.staId[0]);
Zhang Qian79d0d132018-02-05 13:40:16 +08005549 hdd_deregister_tx_flow_control(adapter);
5550 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005551 break;
5552 default:
5553 break;
5554 }
5555
Ajit Pal Singh106c1412018-04-18 18:08:49 +05305556 hdd_deregister_hl_netdev_fc_timer(adapter);
5557
Dustin Brown04348372017-12-14 16:13:39 -08005558 if (adapter->scan_info.default_scan_ies) {
5559 qdf_mem_free(adapter->scan_info.default_scan_ies);
5560 adapter->scan_info.default_scan_ies = NULL;
5561 }
5562
Dustin Browne74003f2018-03-14 12:51:58 -07005563 hdd_exit();
Dustin Brownd747ecd2018-10-26 16:32:22 -07005564
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305565 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005566}
5567
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305568/**
5569 * hdd_deinit_all_adapters - deinit all adapters
5570 * @hdd_ctx: HDD context
5571 * @rtnl_held: True if RTNL lock held
5572 *
5573 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005574void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305575{
Jeff Johnson9d295242017-08-29 14:39:48 -07005576 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305577
Dustin Brown491d54b2018-03-14 12:39:11 -07005578 hdd_enter();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305579
Dustin Brown920397d2017-12-13 16:27:50 -08005580 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305581 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305582
Dustin Browne74003f2018-03-14 12:51:58 -07005583 hdd_exit();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305584}
5585
Dustin Browndb2a8be2017-12-20 11:49:56 -08005586QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005587{
Jeff Johnson9d295242017-08-29 14:39:48 -07005588 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005589
Dustin Brown491d54b2018-03-14 12:39:11 -07005590 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005591
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305592 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5593
Dustin Brown920397d2017-12-13 16:27:50 -08005594 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08005595 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005596
Dustin Browne74003f2018-03-14 12:51:58 -07005597 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005598
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305599 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005600}
5601
Paul Zhang84fa9382017-11-10 21:18:21 +08005602static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
5603 struct hdd_adapter *adapter)
5604{
5605 switch (adapter->device_mode) {
5606 case QDF_STA_MODE:
5607 case QDF_P2P_CLIENT_MODE:
5608 case QDF_IBSS_MODE:
5609 case QDF_P2P_DEVICE_MODE:
5610 case QDF_NDI_MODE:
5611 wlan_hdd_scan_abort(adapter);
5612 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Min Liu8c5d99e2018-09-10 17:18:44 +08005613 if (adapter->device_mode == QDF_STA_MODE) {
5614 struct wlan_objmgr_vdev *vdev;
5615
5616 vdev = hdd_objmgr_get_vdev(adapter);
5617 if (vdev) {
5618 wlan_cfg80211_sched_scan_stop(vdev);
5619 hdd_objmgr_put_vdev(adapter);
5620 }
5621 }
Paul Zhang84fa9382017-11-10 21:18:21 +08005622 break;
5623 case QDF_P2P_GO_MODE:
5624 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5625 break;
5626 case QDF_SAP_MODE:
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305627 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Paul Zhang84fa9382017-11-10 21:18:21 +08005628 wlan_hdd_undo_acs(adapter);
5629 break;
5630 default:
5631 break;
5632 }
5633}
5634
Ke Huangc067b8d2018-05-21 15:50:13 +08005635#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
5636/**
5637 * hdd_adapter_abort_tx_flow() - Abort the tx flow control
5638 * @pAdapter: pointer to hdd_adapter_t
5639 *
5640 * Resume tx and stop the tx flow control timer if the tx is paused
5641 * and the flow control timer is running. This function is called by
5642 * SSR to avoid the inconsistency of tx status before and after SSR.
5643 *
5644 * Return: void
5645 */
5646static void hdd_adapter_abort_tx_flow(struct hdd_adapter *adapter)
5647{
5648 if (adapter->hdd_stats.tx_rx_stats.is_txflow_paused &&
5649 QDF_TIMER_STATE_RUNNING ==
5650 qdf_mc_timer_get_current_state(
5651 &adapter->tx_flow_control_timer)) {
5652 hdd_tx_resume_timer_expired_handler(adapter);
5653 qdf_mc_timer_stop(&adapter->tx_flow_control_timer);
5654 }
5655}
5656#endif
5657
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005658QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005659{
Jeff Johnson9d295242017-08-29 14:39:48 -07005660 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07005661 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07005662 struct qdf_mac_addr peerMacAddr;
Yue Ma42654682018-01-11 16:55:24 -08005663 int sta_id;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05305664 bool value;
Min Liu8c5d99e2018-09-10 17:18:44 +08005665 struct wlan_objmgr_vdev *vdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005666
Dustin Brown491d54b2018-03-14 12:39:11 -07005667 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005668
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305669 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5670
Dustin Brown920397d2017-12-13 16:27:50 -08005671 hdd_for_each_adapter(hdd_ctx, adapter) {
Dustin Brown5e89ef82018-03-14 11:50:23 -07005672 hdd_info("[SSR] reset adapter with device mode %s(%d)",
Dustin Brown458027c2018-10-19 12:26:27 -07005673 qdf_opmode_str(adapter->device_mode),
Dustin Brown5e89ef82018-03-14 11:50:23 -07005674 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305675
Ke Huangc067b8d2018-05-21 15:50:13 +08005676#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
5677 hdd_adapter_abort_tx_flow(adapter);
5678#endif
5679
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305680 if ((adapter->device_mode == QDF_STA_MODE) ||
Paul Zhang679025e2018-03-08 22:39:44 +08005681 (adapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305682 /* Stop tdls timers */
Min Liu8c5d99e2018-09-10 17:18:44 +08005683 vdev = hdd_objmgr_get_vdev(adapter);
5684 if (vdev) {
5685 hdd_notify_tdls_reset_adapter(vdev);
5686 hdd_objmgr_put_vdev(adapter);
5687 }
Paul Zhang679025e2018-03-08 22:39:44 +08005688 adapter->session.station.hdd_reassoc_scenario = false;
5689 }
Dustin Brown05d81302018-09-11 16:49:22 -07005690 ucfg_mlme_get_sap_internal_restart(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05305691 if (value &&
Arun Khandavallicc544b32017-01-30 19:52:16 +05305692 adapter->device_mode == QDF_SAP_MODE) {
5693 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305694 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05305695 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005696 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08005697 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005698 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005699 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
5700 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305701 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305702 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005703 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005704 }
Nijun Gong104ccc72018-08-07 10:43:56 +08005705 /*
5706 * Clear fc flag if it was set before SSR to avoid TX queues
5707 * permanently stopped after SSR.
5708 * Here WLAN_START_ALL_NETIF_QUEUE will actually not start any
5709 * queue since it's blocked by reason WLAN_CONTROL_PATH.
5710 */
5711 if (adapter->pause_map & (1 << WLAN_DATA_FLOW_CONTROL))
5712 wlan_hdd_netif_queue_control(adapter,
5713 WLAN_START_ALL_NETIF_QUEUE,
5714 WLAN_DATA_FLOW_CONTROL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005715
Paul Zhang84fa9382017-11-10 21:18:21 +08005716 hdd_reset_scan_operation(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005717
5718 hdd_deinit_tx_rx(adapter);
Dustin Brown1dbefe62018-09-11 16:32:03 -07005719 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005720 adapter->device_mode, adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005721 hdd_green_ap_start_state_mc(hdd_ctx, adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305722 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005723 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5724 hdd_wmm_adapter_close(adapter);
5725 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5726 }
5727
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305728 if (adapter->device_mode == QDF_STA_MODE)
5729 hdd_clear_fils_connection_info(adapter);
5730
Wu Gao3545e642017-07-14 19:24:41 +08005731 if (adapter->device_mode == QDF_SAP_MODE) {
Jingxiang Geec113592018-08-09 15:40:39 +08005732 wlansap_cleanup_cac_timer(
5733 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Wu Gao3545e642017-07-14 19:24:41 +08005734 /*
5735 * If adapter is SAP, set session ID to invalid
5736 * since SAP session will be cleanup during SSR.
5737 */
Wu Gao36717432016-11-21 15:09:48 +08005738 wlansap_set_invalid_session(
5739 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Wu Gao3545e642017-07-14 19:24:41 +08005740 }
5741
Yue Ma42654682018-01-11 16:55:24 -08005742 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005743 if (adapter->device_mode == QDF_STA_MODE ||
5744 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005745 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005746 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07005747 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005748
Yue Ma42654682018-01-11 16:55:24 -08005749 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
Wu Gao6b81fc52018-05-24 19:27:27 +08005750 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Yue Ma42654682018-01-11 16:55:24 -08005751 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5752 if (adapter->sta_info[sta_id].in_use) {
5753 hdd_debug("[SSR] deregister STA with ID %d",
5754 sta_id);
5755 hdd_softap_deregister_sta(adapter,
5756 sta_id);
5757 adapter->sta_info[sta_id].in_use = 0;
5758 }
5759 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005760 }
5761
Alok Kumarb64650c2018-03-23 17:05:11 +05305762 hdd_nud_ignore_tracking(adapter, true);
Alok Kumar016a1ac2018-09-16 09:55:50 +05305763 hdd_nud_reset_tracking(adapter);
5764 hdd_nud_flush_work(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05305765 hdd_set_disconnect_status(adapter, false);
hangtian9c47aaf2018-11-26 17:59:39 +08005766 hdd_stop_tsf_sync(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05305767
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005768 hdd_softap_deinit_tx_rx(adapter);
Tiger Yu8c387702018-07-06 16:56:42 +08005769 hdd_deregister_tx_flow_control(adapter);
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005770
Yue Maf9782842017-05-08 12:49:49 -07005771 /* Destroy vdev which will be recreated during reinit. */
5772 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005773 }
5774
Dustin Browne74003f2018-03-14 12:51:58 -07005775 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005776
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305777 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005778}
5779
Dustin Brown4c663222018-10-23 14:19:36 -07005780bool hdd_is_any_interface_open(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305781{
Dustin Brown920397d2017-12-13 16:27:50 -08005782 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305783
Dustin Brown4c663222018-10-23 14:19:36 -07005784 if (hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) {
Arun Khandavalliba479c42017-07-26 21:29:40 +05305785 hdd_info("FTM mode, don't close the module");
Dustin Brown4c663222018-10-23 14:19:36 -07005786 return true;
Arun Khandavalliba479c42017-07-26 21:29:40 +05305787 }
5788
Dustin Brown920397d2017-12-13 16:27:50 -08005789 hdd_for_each_adapter(hdd_ctx, adapter) {
5790 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
Dustin Brown4c663222018-10-23 14:19:36 -07005791 test_bit(SME_SESSION_OPENED, &adapter->event_flags))
5792 return true;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305793 }
5794
Dustin Brown4c663222018-10-23 14:19:36 -07005795 return false;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305796}
5797
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305798bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305799{
5800 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5801 return true;
5802 else
5803 return false;
5804}
5805
Anurag Chouhanc4092922016-09-08 15:56:11 +05305806#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08005807 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305808struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5809 struct ieee80211_channel *channel,
5810 const u8 *bssid, const u8 *ssid,
5811 size_t ssid_len)
5812{
5813 return cfg80211_get_bss(wiphy, channel, bssid,
5814 ssid, ssid_len,
5815 WLAN_CAPABILITY_ESS,
5816 WLAN_CAPABILITY_ESS);
5817}
5818#else
5819struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5820 struct ieee80211_channel *channel,
5821 const u8 *bssid, const u8 *ssid,
5822 size_t ssid_len)
5823{
5824 return cfg80211_get_bss(wiphy, channel, bssid,
5825 ssid, ssid_len,
5826 IEEE80211_BSS_TYPE_ESS,
5827 IEEE80211_PRIVACY_ANY);
5828}
5829#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305830
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305831#if defined CFG80211_CONNECT_BSS || \
5832 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305833#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305834 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305835/**
5836 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5837 * @timeout_reason: reason for connect timeout
5838 *
5839 * This function is used to convert host timeout
5840 * reason enum to kernel specific enum.
5841 *
5842 * Return: nl timeout enum
5843 */
5844static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5845 tSirResultCodes timeout_reason)
5846{
5847 switch (timeout_reason) {
5848 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5849 return NL80211_TIMEOUT_SCAN;
5850 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5851 return NL80211_TIMEOUT_AUTH;
5852 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5853 return NL80211_TIMEOUT_ASSOC;
5854 default:
5855 return NL80211_TIMEOUT_UNSPECIFIED;
5856 }
5857}
5858
5859/**
5860 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5861 * @dev: network device
5862 * @bssid: bssid to which we want to associate
5863 * @timeout_reason: reason for connect timeout
5864 *
5865 * This API is used to send connection timeout reason to supplicant
5866 *
5867 * Return: void
5868 */
5869static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5870 const u8 *bssid,
5871 tSirResultCodes timeout_reason)
5872{
5873 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005874
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305875 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5876
5877 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5878 nl_timeout_reason);
5879}
5880
5881/**
5882 * __hdd_connect_bss() - API to send connection status to supplicant
5883 * @dev: network device
5884 * @bssid: bssid to which we want to associate
5885 * @req_ie: Request Information Element
5886 * @req_ie_len: len of the req IE
5887 * @resp_ie: Response IE
5888 * @resp_ie_len: len of ht response IE
5889 * @status: status
5890 * @gfp: Kernel Flag
5891 * @timeout_reason: reason for connect timeout
5892 *
5893 * Return: void
5894 */
5895static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5896 struct cfg80211_bss *bss, const u8 *req_ie,
5897 size_t req_ie_len, const u8 *resp_ie,
5898 size_t resp_ie_len, int status, gfp_t gfp,
5899 tSirResultCodes timeout_reason)
5900{
5901 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005902
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305903 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5904
5905 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5906 resp_ie, resp_ie_len, status, gfp,
5907 nl_timeout_reason);
5908}
5909#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305910#if defined CFG80211_CONNECT_TIMEOUT || \
5911 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305912static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5913 const u8 *bssid,
5914 tSirResultCodes timeout_reason)
5915{
5916 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5917}
5918#endif
5919
5920static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5921 struct cfg80211_bss *bss, const u8 *req_ie,
5922 size_t req_ie_len, const u8 *resp_ie,
5923 size_t resp_ie_len, int status, gfp_t gfp,
5924 tSirResultCodes timeout_reason)
5925{
5926 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5927 resp_ie, resp_ie_len, status, gfp);
5928}
5929#endif
5930
Abhishek Singha84d3952016-09-13 13:45:05 +05305931/**
5932 * hdd_connect_bss() - API to send connection status to supplicant
5933 * @dev: network device
5934 * @bssid: bssid to which we want to associate
5935 * @req_ie: Request Information Element
5936 * @req_ie_len: len of the req IE
5937 * @resp_ie: Response IE
5938 * @resp_ie_len: len of ht response IE
5939 * @status: status
5940 * @gfp: Kernel Flag
5941 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305942 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05305943 *
5944 * The API is a wrapper to send connection status to supplicant
5945 *
5946 * Return: Void
5947 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305948#if defined CFG80211_CONNECT_TIMEOUT || \
5949 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05305950static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5951 struct cfg80211_bss *bss, const u8 *req_ie,
5952 size_t req_ie_len, const u8 *resp_ie,
5953 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305954 bool connect_timeout,
5955 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305956{
5957 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305958 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305959 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305960 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5961 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305962}
5963#else
5964static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5965 struct cfg80211_bss *bss, const u8 *req_ie,
5966 size_t req_ie_len, const u8 *resp_ie,
5967 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305968 bool connect_timeout,
5969 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305970{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305971 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5972 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305973}
5974#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305975
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305976#if defined(WLAN_FEATURE_FILS_SK)
5977#if defined(CFG80211_CONNECT_DONE) || \
5978 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
5979#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
5980 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305981/**
5982 * hdd_populate_fils_params() - Populate FILS keys to connect response
5983 * @fils_params: connect response to supplicant
5984 * @fils_kek: FILS kek
5985 * @fils_kek_len: FILS kek length
5986 * @pmk: FILS PMK
5987 * @pmk_len: FILS PMK length
5988 * @pmkid: PMKID
5989 * @fils_seq_num: FILS Seq number
5990 *
5991 * Return: None
5992 */
5993static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5994 *fils_params, const uint8_t *fils_kek,
5995 size_t fils_kek_len, const uint8_t *pmk,
5996 size_t pmk_len, const uint8_t *pmkid,
5997 uint16_t fils_seq_num)
5998{
5999 /* Increament seq number to be used for next FILS */
6000 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
6001 fils_params->update_erp_next_seq_num = true;
6002 fils_params->fils_kek = fils_kek;
6003 fils_params->fils_kek_len = fils_kek_len;
6004 fils_params->pmk = pmk;
6005 fils_params->pmk_len = pmk_len;
6006 fils_params->pmkid = pmkid;
6007}
6008#else
6009static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
6010 *fils_params, const uint8_t
6011 *fils_kek, size_t fils_kek_len,
6012 const uint8_t *pmk, size_t pmk_len,
6013 const uint8_t *pmkid,
6014 uint16_t fils_seq_num)
6015{ }
6016#endif
6017
Jeff Johnson172237b2017-11-07 15:32:59 -08006018void hdd_update_hlp_info(struct net_device *dev,
6019 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306020{
6021 struct sk_buff *skb;
6022 uint16_t skb_len;
6023 struct llc_snap_hdr_t *llc_hdr;
6024 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306025 uint8_t *hlp_data;
6026 uint16_t hlp_data_len;
6027 struct fils_join_rsp_params *roam_fils_params
6028 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306029 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
6030
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306031 if (!roam_fils_params) {
6032 hdd_err("FILS Roam Param NULL");
6033 return;
6034 }
6035
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08006036 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306037 hdd_err("FILS HLP Data NULL, len %d",
6038 roam_fils_params->hlp_data_len);
6039 return;
6040 }
6041
6042 hlp_data = roam_fils_params->hlp_data;
6043 hlp_data_len = roam_fils_params->hlp_data_len;
6044
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306045 /* Calculate skb length */
6046 skb_len = (2 * ETH_ALEN) + hlp_data_len;
6047 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
6048 if (skb == NULL) {
6049 hdd_err("HLP packet nbuf alloc fails");
6050 return;
6051 }
6052
6053 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
6054 QDF_MAC_ADDR_SIZE);
6055 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
6056 QDF_MAC_ADDR_SIZE);
6057
6058 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
6059 if (IS_SNAP(llc_hdr)) {
6060 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
6061 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
6062 }
6063
6064 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
6065
6066 /*
6067 * This HLP packet is formed from HLP info encapsulated
6068 * in assoc response frame which is AEAD encrypted.
6069 * Hence, this checksum validation can be set unnecessary.
6070 * i.e. network layer need not worry about checksum.
6071 */
6072 skb->ip_summed = CHECKSUM_UNNECESSARY;
6073
6074 status = hdd_rx_packet_cbk(padapter, skb);
6075 if (QDF_IS_STATUS_ERROR(status)) {
6076 hdd_err("Sending HLP packet fails");
6077 return;
6078 }
6079 hdd_debug("send HLP packet to netif successfully");
6080}
6081
6082/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306083 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
6084 * @dev: network device
6085 * @bssid: bssid to which we want to associate
6086 * @bss: cfg80211 bss info
6087 * @roam_info: information about connected bss
6088 * @req_ie: Request Information Element
6089 * @req_ie_len: len of the req IE
6090 * @resp_ie: Response IE
6091 * @resp_ie_len: len of ht response IE
6092 * @status: status
6093 * @gfp: allocation flags
6094 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
6095 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306096 *
6097 * This API is used as wrapper to send FILS key/sequence number
6098 * params etc. to supplicant in case of FILS connection
6099 *
6100 * Return: None
6101 */
6102static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006103 struct cfg80211_bss *bss,
6104 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306105 const u8 *req_ie, size_t req_ie_len,
6106 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006107 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306108 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306109{
6110 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306111 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
6112 struct fils_join_rsp_params *roam_fils_params =
6113 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006114
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306115 qdf_mem_zero(&fils_params, sizeof(fils_params));
6116
6117 if (!roam_fils_params) {
6118 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
6119 } else {
6120 fils_params.status = status;
6121 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08006122 fils_params.timeout_reason =
6123 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306124 fils_params.req_ie = req_ie;
6125 fils_params.req_ie_len = req_ie_len;
6126 fils_params.resp_ie = resp_ie;
6127 fils_params.resp_ie_len = resp_ie_len;
6128 fils_params.bss = bss;
6129 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
6130 roam_fils_params->kek_len,
6131 roam_fils_params->fils_pmk,
6132 roam_fils_params->fils_pmk_len,
6133 roam_fils_params->fils_pmkid,
6134 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05306135 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306136 }
6137 hdd_debug("FILS indicate connect status %d seq no %d",
6138 fils_params.status,
6139 fils_params.fils_erp_next_seq_num);
6140
6141 cfg80211_connect_done(dev, &fils_params, gfp);
6142
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306143 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306144 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306145
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306146 /* Clear all the FILS key info */
6147 if (roam_fils_params && roam_fils_params->fils_pmk)
6148 qdf_mem_free(roam_fils_params->fils_pmk);
6149 if (roam_fils_params)
6150 qdf_mem_free(roam_fils_params);
6151 roam_info->fils_join_rsp = NULL;
6152}
6153#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006154static inline void
6155hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006156 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006157 const u8 *req_ie, size_t req_ie_len,
6158 const u8 *resp_ie, size_t resp_ie_len, u16 status,
6159 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306160 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306161{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306162#endif
6163#endif
6164
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306165#if defined(WLAN_FEATURE_FILS_SK) && \
6166 (defined(CFG80211_CONNECT_DONE) || \
6167 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306168/**
6169 * hdd_fils_update_connect_results() - API to send fils connection status to
6170 * supplicant.
6171 * @dev: network device
6172 * @bssid: bssid to which we want to associate
6173 * @bss: cfg80211 bss info
6174 * @roam_info: information about connected bss
6175 * @req_ie: Request Information Element
6176 * @req_ie_len: len of the req IE
6177 * @resp_ie: Response IE
6178 * @resp_ie_len: len of ht response IE
6179 * @status: status
6180 * @gfp: allocation flags
6181 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
6182 * @timeout_reason: reason for connect timeout
6183 *
6184 * The API is a wrapper to send connection status to supplicant
6185 *
6186 * Return: 0 if success else failure
6187 */
6188static int hdd_fils_update_connect_results(struct net_device *dev,
6189 const u8 *bssid,
6190 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08006191 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306192 size_t req_ie_len, const u8 *resp_ie,
6193 size_t resp_ie_len, u16 status, gfp_t gfp,
6194 bool connect_timeout,
6195 tSirResultCodes timeout_reason)
6196{
Dustin Brown491d54b2018-03-14 12:39:11 -07006197 hdd_enter();
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306198 if (!roam_info || !roam_info->is_fils_connection)
6199 return -EINVAL;
6200
6201 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
6202 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306203 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306204 return 0;
6205}
6206#else
6207static inline int hdd_fils_update_connect_results(struct net_device *dev,
6208 const u8 *bssid,
6209 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08006210 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306211 size_t req_ie_len, const u8 *resp_ie,
6212 size_t resp_ie_len, u16 status, gfp_t gfp,
6213 bool connect_timeout,
6214 tSirResultCodes timeout_reason)
6215{
6216 return -EINVAL;
6217}
6218#endif
6219
Anurag Chouhanc4092922016-09-08 15:56:11 +05306220/**
6221 * hdd_connect_result() - API to send connection status to supplicant
6222 * @dev: network device
6223 * @bssid: bssid to which we want to associate
6224 * @roam_info: information about connected bss
6225 * @req_ie: Request Information Element
6226 * @req_ie_len: len of the req IE
6227 * @resp_ie: Response IE
6228 * @resp_ie_len: len of ht response IE
6229 * @status: status
6230 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05306231 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306232 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05306233 *
6234 * The API is a wrapper to send connection status to supplicant
6235 * and allow runtime suspend
6236 *
6237 * Return: Void
6238 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306239void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006240 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05306241 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05306242 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306243 bool connect_timeout,
6244 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05306245{
Jeff Johnson9d295242017-08-29 14:39:48 -07006246 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306247 struct cfg80211_bss *bss = NULL;
Jingxiang Ge929c7932018-01-24 14:01:12 +08006248 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306249
6250 if (WLAN_STATUS_SUCCESS == status) {
6251 struct ieee80211_channel *chan;
6252 int freq;
6253 int chan_no = roam_info->pBssDesc->channelId;
6254
6255 if (chan_no <= 14)
6256 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07006257 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306258 else
6259 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07006260 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306261
6262 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
6263 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
6264 roam_info->u.pConnectedProfile->SSID.ssId,
6265 roam_info->u.pConnectedProfile->SSID.length);
6266 }
Komal Seelama89be8d2016-09-29 11:09:26 +05306267
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306268 if (hdd_fils_update_connect_results(dev, bssid, bss,
6269 roam_info, req_ie, req_ie_len, resp_ie,
6270 resp_ie_len, status, gfp, connect_timeout,
6271 timeout_reason) != 0) {
6272 hdd_connect_bss(dev, bssid, bss, req_ie,
6273 req_ie_len, resp_ie, resp_ie_len,
6274 status, gfp, connect_timeout, timeout_reason);
6275 }
Komal Seelama89be8d2016-09-29 11:09:26 +05306276
Jingxiang Geb49aa302018-01-17 20:54:15 +08006277 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07006278 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306279}
6280#else
6281void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006282 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05306283 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05306284 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306285 bool connect_timeout,
6286 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05306287{
Jeff Johnson9d295242017-08-29 14:39:48 -07006288 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Jingxiang Ge929c7932018-01-24 14:01:12 +08006289 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05306290
Anurag Chouhanc4092922016-09-08 15:56:11 +05306291 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
6292 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08006293
Jingxiang Geb49aa302018-01-17 20:54:15 +08006294 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07006295 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306296}
6297#endif
6298
Nirav Shah73713f72018-05-17 14:50:41 +05306299#ifdef FEATURE_MONITOR_MODE_SUPPORT
Jeff Johnsond9952752018-04-18 12:15:35 -07006300int wlan_hdd_set_mon_chan(struct hdd_adapter *adapter, uint32_t chan,
6301 uint32_t bandwidth)
6302{
6303 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6304 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
6305 struct hdd_mon_set_ch_info *ch_info = &sta_ctx->ch_info;
6306 QDF_STATUS status;
Jeff Johnson43837af2018-10-17 12:44:05 -07006307 mac_handle_t mac_handle = hdd_ctx->mac_handle;
Jeff Johnsond9952752018-04-18 12:15:35 -07006308 struct qdf_mac_addr bssid;
6309 struct csr_roam_profile roam_profile;
6310 struct ch_params ch_params;
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006311 eConnectionState connstate;
Jeff Johnsond9952752018-04-18 12:15:35 -07006312
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006313 if (hdd_get_conparam() != QDF_GLOBAL_MONITOR_MODE &&
6314 adapter->device_mode != QDF_STA_MODE) {
6315 hdd_err("Not supported, device is not in monitor mode or sta mission mode");
Jeff Johnsond9952752018-04-18 12:15:35 -07006316 return -EINVAL;
6317 }
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006318 if (adapter->device_mode == QDF_STA_MODE &&
6319 hdd_ctx->config->enable_change_channel_bandwidth) {
6320 connstate = sta_ctx->conn_info.connState;
6321 if (eConnectionState_Associated == connstate ||
6322 eConnectionState_Connecting == connstate) {
6323 return -EINVAL;
6324 }
6325 }
Jeff Johnsond9952752018-04-18 12:15:35 -07006326
Visweswara Tanuku006313a2018-04-12 12:26:34 +05306327 /* Validate Channel */
6328 if (!WLAN_REG_IS_24GHZ_CH(chan) && !WLAN_REG_IS_5GHZ_CH(chan)) {
6329 hdd_err("Channel %d Not supported", chan);
6330 return -EINVAL;
6331 }
6332
6333 if (WLAN_REG_IS_24GHZ_CH(chan)) {
6334 if (bandwidth == CH_WIDTH_80MHZ) {
6335 hdd_err("BW80 not possible in 2.4GHz band");
6336 return -EINVAL;
6337 }
6338 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 14) &&
6339 (bandwidth != CH_WIDTH_MAX)) {
6340 hdd_err("Only BW20 possible on channel 14");
6341 return -EINVAL;
6342 }
6343 }
6344
6345 if (WLAN_REG_IS_5GHZ_CH(chan)) {
6346 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 165) &&
6347 (bandwidth != CH_WIDTH_MAX)) {
6348 hdd_err("Only BW20 possible on channel 165");
6349 return -EINVAL;
6350 }
6351 }
6352
Jeff Johnsond9952752018-04-18 12:15:35 -07006353 hdd_debug("Set monitor mode Channel %d", chan);
6354 qdf_mem_zero(&roam_profile, sizeof(roam_profile));
6355 roam_profile.ChannelInfo.ChannelList = &ch_info->channel;
6356 roam_profile.ChannelInfo.numOfChannels = 1;
6357 roam_profile.phyMode = ch_info->phy_mode;
6358 roam_profile.ch_params.ch_width = bandwidth;
6359 hdd_select_cbmode(adapter, chan, &roam_profile.ch_params);
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006360 if (hdd_ctx->config->enable_change_channel_bandwidth &&
Jeff Johnson43837af2018-10-17 12:44:05 -07006361 (!sme_find_session_by_bssid(mac_handle, adapter->mac_addr.bytes))) {
6362 status = sme_create_mon_session(mac_handle,
Rajeev Kumar Sirasanagandlae3b59912018-08-24 15:53:31 +05306363 adapter->mac_addr.bytes,
6364 adapter->session_id);
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006365 if (status != QDF_STATUS_SUCCESS) {
6366 hdd_err("Status: %d Failed to create session.",
6367 status);
6368 return qdf_status_to_os_return(status);
6369 }
6370 }
Jeff Johnsond9952752018-04-18 12:15:35 -07006371 qdf_mem_copy(bssid.bytes, adapter->mac_addr.bytes,
6372 QDF_MAC_ADDR_SIZE);
6373
6374 ch_params.ch_width = bandwidth;
Dustin Brown07901ec2018-09-07 11:02:41 -07006375 wlan_reg_set_channel_params(hdd_ctx->pdev, chan, 0, &ch_params);
Jeff Johnsond9952752018-04-18 12:15:35 -07006376 if (ch_params.ch_width == CH_WIDTH_INVALID) {
6377 hdd_err("Invalid capture channel or bandwidth for a country");
6378 return -EINVAL;
6379 }
6380 if (wlan_hdd_change_hw_mode_for_given_chnl(adapter, chan,
6381 POLICY_MGR_UPDATE_REASON_SET_OPER_CHAN)) {
6382 hdd_err("Failed to change hw mode");
6383 return -EINVAL;
6384 }
6385
Jeff Johnson16528362018-06-14 12:34:16 -07006386 status = sme_roam_channel_change_req(hdd_ctx->mac_handle,
6387 bssid, &ch_params,
Jeff Johnsond9952752018-04-18 12:15:35 -07006388 &roam_profile);
6389 if (status) {
6390 hdd_err("Status: %d Failed to set sme_roam Channel for monitor mode",
6391 status);
6392 }
6393
6394 adapter->mon_chan = chan;
6395 adapter->mon_bandwidth = bandwidth;
6396 return qdf_status_to_os_return(status);
6397}
Nirav Shah73713f72018-05-17 14:50:41 +05306398#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05306399
Wu Gaodf929f12018-05-25 18:12:25 +08006400#ifdef MSM_PLATFORM
6401/**
6402 * hdd_stop_p2p_go() - call cfg80211 API to stop P2P GO
6403 * @adapter: pointer to adapter
6404 *
6405 * This function calls cfg80211 API to stop P2P GO
6406 *
6407 * Return: None
6408 */
6409static void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6410{
6411 hdd_debug("[SSR] send stop ap to supplicant");
6412 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
6413}
6414
6415static inline void hdd_delete_sta(struct hdd_adapter *adapter)
6416{
6417}
6418#else
6419static inline void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6420{
6421}
6422
6423/**
6424 * hdd_delete_sta() - call cfg80211 API to delete STA
6425 * @adapter: pointer to adapter
6426 *
6427 * This function calls cfg80211 API to delete STA
6428 *
6429 * Return: None
6430 */
6431static void hdd_delete_sta(struct hdd_adapter *adapter)
6432{
6433 struct qdf_mac_addr bcast_mac = QDF_MAC_ADDR_BCAST_INIT;
6434
6435 hdd_debug("[SSR] send restart supplicant");
6436 /* event supplicant to restart */
6437 cfg80211_del_sta(adapter->dev,
6438 (const u8 *)&bcast_mac.bytes[0],
6439 GFP_KERNEL);
6440}
6441#endif
6442
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006443QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006444{
Jeff Johnson9d295242017-08-29 14:39:48 -07006445 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006446 eConnectionState connState;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05306447 bool value;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006448
Dustin Brown491d54b2018-03-14 12:39:11 -07006449 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006450
Dustin Brown920397d2017-12-13 16:27:50 -08006451 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05306452 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08006453 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05306454
Yue Ma42654682018-01-11 16:55:24 -08006455 hdd_debug("[SSR] start adapter with device mode %s(%d)",
Dustin Brown458027c2018-10-19 12:26:27 -07006456 qdf_opmode_str(adapter->device_mode),
Yue Ma42654682018-01-11 16:55:24 -08006457 adapter->device_mode);
6458
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006459 hdd_wmm_init(adapter);
6460
6461 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006462 case QDF_STA_MODE:
6463 case QDF_P2P_CLIENT_MODE:
6464 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006465
6466 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
6467 ->conn_info.connState;
6468
Krunal Sonib51eec72017-11-20 21:53:01 -08006469 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006470 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07006471 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006472
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006473 /* Indicate disconnect event to supplicant
6474 * if associated previously
6475 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006476 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07006477 eConnectionState_IbssConnected == connState ||
6478 eConnectionState_NotConnected == connState ||
6479 eConnectionState_IbssDisconnected == connState ||
6480 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006481 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006482
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006483 memset(&wrqu, '\0', sizeof(wrqu));
6484 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
6485 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
6486 wireless_send_event(adapter->dev, SIOCGIWAP,
6487 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07006488 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07006489 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006490
6491 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05306492 wlan_hdd_cfg80211_indicate_disconnect(
6493 adapter->dev, false,
6494 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006495 } else if (eConnectionState_Connecting == connState) {
6496 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006497 * Indicate connect failure to supplicant if we
6498 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006499 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306500 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306501 NULL, 0, NULL, 0,
6502 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006503 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006504 }
6505
6506 hdd_register_tx_flow_control(adapter,
6507 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08006508 hdd_tx_resume_cb,
6509 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006510
Arunk Khandavalli40943af2017-05-15 19:25:34 +05306511 hdd_lpass_notify_start(hdd_ctx, adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05306512 hdd_nud_ignore_tracking(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006513 break;
6514
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006515 case QDF_SAP_MODE:
Dustin Brown05d81302018-09-11 16:49:22 -07006516 ucfg_mlme_get_sap_internal_restart(hdd_ctx->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05306517 &value);
6518 if (value)
Krunal Sonib51eec72017-11-20 21:53:01 -08006519 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05306520
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006521 break;
6522
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006523 case QDF_P2P_GO_MODE:
Wu Gaodf929f12018-05-25 18:12:25 +08006524 hdd_delete_sta(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006525 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306526 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08006527 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306528 hdd_set_mon_rx_cb(adapter->dev);
6529 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
6530 adapter->mon_bandwidth);
6531 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006532 default:
6533 break;
6534 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07006535 /*
6536 * Action frame registered in one adapter which will
6537 * applicable to all interfaces
6538 */
6539 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006540 }
6541
Wu Gaodf929f12018-05-25 18:12:25 +08006542 hdd_for_each_adapter(hdd_ctx, adapter) {
6543 if (!hdd_is_interface_up(adapter))
6544 continue;
6545
6546 if (adapter->device_mode == QDF_P2P_GO_MODE)
6547 hdd_stop_p2p_go(adapter);
6548 }
6549
Dustin Browne74003f2018-03-14 12:51:58 -07006550 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006551
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306552 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006553}
6554
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006555QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006556 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006557{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306558 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006559 qdf_list_node_t *node;
6560
6561 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006562
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006563 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006564 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006565 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006566
6567 if (QDF_IS_STATUS_ERROR(status))
6568 return status;
6569
6570 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6571
6572 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006573}
6574
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006575QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006576 struct hdd_adapter *current_adapter,
6577 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006578{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306579 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006580 qdf_list_node_t *node;
6581
6582 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006583
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006584 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006585 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08006586 &current_adapter->node,
6587 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006588 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006589
6590 if (QDF_IS_STATUS_ERROR(status))
6591 return status;
6592
6593 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6594
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006595 return status;
6596}
6597
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006598QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006599 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006600{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306601 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006602
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006603 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006604 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006605 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006606
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006607 return status;
6608}
6609
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006610QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006611 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006612{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306613 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006614 qdf_list_node_t *node;
6615
6616 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006617
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006618 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006619 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006620 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006621
6622 if (QDF_IS_STATUS_ERROR(status))
6623 return status;
6624
6625 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6626
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006627 return status;
6628}
6629
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006630QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006631 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006632{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306633 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006634
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006635 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006636 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006637 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006638
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006639 return status;
6640}
6641
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006642QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006643 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006644{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306645 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006646
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006647 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006648 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006649 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006650
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006651 return status;
6652}
6653
Liangwei Dong3abfe8f2018-09-20 02:25:44 -04006654struct hdd_adapter *hdd_get_adapter_by_rand_macaddr(
6655 struct hdd_context *hdd_ctx, tSirMacAddr mac_addr)
6656{
6657 struct hdd_adapter *adapter;
6658
6659 hdd_for_each_adapter(hdd_ctx, adapter) {
6660 if ((adapter->device_mode == QDF_STA_MODE ||
6661 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6662 adapter->device_mode == QDF_P2P_DEVICE_MODE) &&
6663 ucfg_p2p_check_random_mac(hdd_ctx->psoc,
6664 adapter->session_id, mac_addr))
6665 return adapter;
6666 }
6667
6668 return NULL;
6669}
6670
Jeff Johnson9d295242017-08-29 14:39:48 -07006671struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006672 tSirMacAddr macAddr)
6673{
Jeff Johnson9d295242017-08-29 14:39:48 -07006674 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006675
Dustin Brown920397d2017-12-13 16:27:50 -08006676 hdd_for_each_adapter(hdd_ctx, adapter) {
6677 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
6678 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006679 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006680 }
6681
6682 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006683}
6684
Jeff Johnson9d295242017-08-29 14:39:48 -07006685struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006686 uint32_t vdev_id)
6687{
Jeff Johnson9d295242017-08-29 14:39:48 -07006688 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006689
Dustin Brown920397d2017-12-13 16:27:50 -08006690 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07006691 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006692 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006693 }
6694
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006695 return NULL;
6696}
6697
Abhishek Singh7996eb72015-12-30 17:24:02 +05306698/**
6699 * hdd_get_adapter_by_sme_session_id() - Return adapter with
6700 * the sessionid
6701 * @hdd_ctx: hdd context.
6702 * @sme_session_id: sme session is for the adapter to get.
6703 *
6704 * This function is used to get the adapter with provided session id
6705 *
6706 * Return: adapter pointer if found
6707 *
6708 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07006709struct hdd_adapter *
6710hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
6711 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306712{
Jeff Johnson9d295242017-08-29 14:39:48 -07006713 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306714
Dustin Brown920397d2017-12-13 16:27:50 -08006715 hdd_for_each_adapter(hdd_ctx, adapter) {
6716 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306717 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306718 }
Dustin Brown920397d2017-12-13 16:27:50 -08006719
Abhishek Singh7996eb72015-12-30 17:24:02 +05306720 return NULL;
6721}
6722
Jeff Johnson9d295242017-08-29 14:39:48 -07006723struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07006724 const char *iface_name)
6725{
Jeff Johnson9d295242017-08-29 14:39:48 -07006726 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006727
Dustin Brown920397d2017-12-13 16:27:50 -08006728 hdd_for_each_adapter(hdd_ctx, adapter) {
6729 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07006730 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006731 }
Dustin Brown920397d2017-12-13 16:27:50 -08006732
Naveen Rawat4edb6822017-04-12 10:09:17 -07006733 return NULL;
6734}
6735
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006736/**
6737 * hdd_get_adapter() - to get adapter matching the mode
6738 * @hdd_ctx: hdd context
6739 * @mode: adapter mode
6740 *
6741 * This routine will return the pointer to adapter matching
6742 * with the passed mode.
6743 *
6744 * Return: pointer to adapter or null
6745 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006746struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006747 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006748{
Jeff Johnson9d295242017-08-29 14:39:48 -07006749 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006750
Dustin Brown920397d2017-12-13 16:27:50 -08006751 hdd_for_each_adapter(hdd_ctx, adapter) {
6752 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006753 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006754 }
6755
6756 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006757}
6758
Jeff Johnson36a0abf2018-05-20 11:24:25 -07006759enum QDF_OPMODE hdd_get_device_mode(uint32_t session_id)
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306760{
6761 struct hdd_context *hdd_ctx;
6762 struct hdd_adapter *adapter;
6763
6764 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
6765 if (!hdd_ctx) {
6766 hdd_err("Invalid HDD context");
6767 return QDF_MAX_NO_OF_MODE;
6768 }
6769
6770 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
6771 if (!adapter) {
6772 hdd_err("Invalid HDD adapter");
6773 return QDF_MAX_NO_OF_MODE;
6774 }
6775
6776 return adapter->device_mode;
6777}
6778
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006779/**
6780 * hdd_get_operating_channel() - return operating channel of the device mode
6781 * @hdd_ctx: Pointer to the HDD context.
6782 * @mode: Device mode for which operating channel is required.
Jeff Johnson77f89bb2018-05-06 16:21:36 -07006783 * Supported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006784 * QDF_STA_MODE,
6785 * QDF_P2P_CLIENT_MODE,
6786 * QDF_SAP_MODE,
6787 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006788 *
6789 * This API returns the operating channel of the requested device mode
6790 *
6791 * Return: channel number. "0" id the requested device is not found OR it is
6792 * not connected.
6793 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006794uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006795 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006796{
Jeff Johnson9d295242017-08-29 14:39:48 -07006797 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006798 uint8_t operatingChannel = 0;
6799
Dustin Brown920397d2017-12-13 16:27:50 -08006800 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006801 if (mode == adapter->device_mode) {
6802 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006803 case QDF_STA_MODE:
6804 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006805 if (hdd_conn_is_connected
6806 (WLAN_HDD_GET_STATION_CTX_PTR
6807 (adapter))) {
6808 operatingChannel =
6809 (WLAN_HDD_GET_STATION_CTX_PTR
6810 (adapter))->conn_info.
6811 operationChannel;
6812 }
6813 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006814 case QDF_SAP_MODE:
6815 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006816 /* softap connection info */
6817 if (test_bit
6818 (SOFTAP_BSS_STARTED,
6819 &adapter->event_flags))
6820 operatingChannel =
6821 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07006822 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006823 break;
6824 default:
6825 break;
6826 }
6827
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006828 /* Found the device of interest. break the loop */
6829 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006830 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006831 }
Dustin Brown920397d2017-12-13 16:27:50 -08006832
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006833 return operatingChannel;
6834}
6835
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006836static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006837 hdd_ctx)
6838{
Jeff Johnson9d295242017-08-29 14:39:48 -07006839 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006840
Dustin Brown491d54b2018-03-14 12:39:11 -07006841 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006842
Dustin Brown920397d2017-12-13 16:27:50 -08006843 hdd_for_each_adapter(hdd_ctx, adapter) {
6844 if (adapter->device_mode == QDF_STA_MODE ||
6845 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6846 adapter->device_mode == QDF_IBSS_MODE ||
6847 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6848 adapter->device_mode == QDF_SAP_MODE ||
6849 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006850 hdd_unregister_wext(adapter->dev);
6851 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006852 }
6853
Dustin Browne74003f2018-03-14 12:51:58 -07006854 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006855
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306856 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006857}
6858
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006859QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006860{
Jeff Johnson9d295242017-08-29 14:39:48 -07006861 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006862
Dustin Brown491d54b2018-03-14 12:39:11 -07006863 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006864
Dustin Brown920397d2017-12-13 16:27:50 -08006865 hdd_for_each_adapter(hdd_ctx, adapter) {
6866 if (adapter->device_mode == QDF_STA_MODE ||
6867 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6868 adapter->device_mode == QDF_IBSS_MODE ||
6869 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6870 adapter->device_mode == QDF_SAP_MODE ||
6871 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brown07901ec2018-09-07 11:02:41 -07006872 wlan_abort_scan(hdd_ctx->pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006873 adapter->session_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05306874 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006875 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006876 }
6877
Dustin Browne74003f2018-03-14 12:51:58 -07006878 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006879
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306880 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006881}
6882
Dustin Brownf27bce82016-11-03 12:52:27 -07006883/**
6884 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
6885 * adapters
6886 * @hdd_ctx: The HDD context containing the adapters to operate on
6887 *
6888 * return: QDF_STATUS_SUCCESS
6889 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006890static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07006891{
Jeff Johnson9d295242017-08-29 14:39:48 -07006892 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07006893 int err;
6894
Dustin Brown491d54b2018-03-14 12:39:11 -07006895 hdd_enter();
Dustin Brownf27bce82016-11-03 12:52:27 -07006896
Dustin Brown920397d2017-12-13 16:27:50 -08006897 hdd_for_each_adapter(hdd_ctx, adapter) {
6898 if (adapter->device_mode == QDF_STA_MODE ||
6899 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6900 adapter->device_mode == QDF_IBSS_MODE ||
6901 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6902 adapter->device_mode == QDF_SAP_MODE ||
6903 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07006904 err = wlan_hdd_sched_scan_stop(adapter->dev);
6905 if (err)
6906 hdd_err("Unable to stop scheduled scan");
6907 }
Dustin Brownf27bce82016-11-03 12:52:27 -07006908 }
6909
Dustin Browne74003f2018-03-14 12:51:58 -07006910 hdd_exit();
Dustin Brownf27bce82016-11-03 12:52:27 -07006911
6912 return QDF_STATUS_SUCCESS;
6913}
6914
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006915#ifdef WLAN_NS_OFFLOAD
6916/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006917 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006918 * @hdd_ctx: Pointer to hdd context
6919 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006920 * Unregister for IPv6 address change notifications.
6921 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006922 * Return: None
6923 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006924static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006925{
6926 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006927}
6928
6929/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006930 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006931 * @hdd_ctx: Pointer to hdd context
6932 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006933 * Register for IPv6 address change notifications.
6934 *
6935 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006936 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006937static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006938{
6939 int ret;
6940
6941 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
6942 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006943 if (ret) {
6944 hdd_err("Failed to register IPv6 notifier: %d", ret);
6945 goto out;
6946 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006947
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006948 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006949out:
6950 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006951}
6952#else
6953/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006954 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006955 * @hdd_ctx: Pointer to hdd context
6956 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006957 * Unregister for IPv6 address change notifications.
6958 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006959 * Return: None
6960 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006961static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006962{
6963}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006964
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006965/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006966 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006967 * @hdd_ctx: Pointer to hdd context
6968 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006969 * Register for IPv6 address change notifications.
6970 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006971 * Return: None
6972 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006973static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006974{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006975 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006976}
6977#endif
6978
Alok Kumarb64650c2018-03-23 17:05:11 +05306979void hdd_set_disconnect_status(struct hdd_adapter *adapter, bool status)
6980{
6981 qdf_mutex_acquire(&adapter->disconnection_status_lock);
6982 adapter->disconnection_in_progress = status;
6983 qdf_mutex_release(&adapter->disconnection_status_lock);
6984 hdd_debug("setting disconnection status: %d", status);
6985}
6986
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006987/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006988 * hdd_register_notifiers - Register netdev notifiers.
6989 * @hdd_ctx: HDD context
6990 *
6991 * Register netdev notifiers like IPv4 and IPv6.
6992 *
6993 * Return: 0 on success and errno on failure
6994 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006995static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006996{
6997 int ret;
6998
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006999 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
7000 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05307001 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007002
7003 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
7004 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
7005 if (ret) {
7006 hdd_err("Failed to register IPv4 notifier: %d", ret);
7007 goto unregister_ip6_notifier;
7008 }
7009
Alok Kumarb64650c2018-03-23 17:05:11 +05307010 ret = hdd_nud_register_netevent_notifier(hdd_ctx);
7011 if (ret) {
7012 hdd_err("Failed to register netevent notifier: %d",
7013 ret);
7014 goto unregister_inetaddr_notifier;
7015 }
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007016 return 0;
7017
Alok Kumarb64650c2018-03-23 17:05:11 +05307018unregister_inetaddr_notifier:
7019 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007020unregister_ip6_notifier:
7021 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007022out:
7023 return ret;
7024
7025}
7026
7027/**
7028 * hdd_unregister_notifiers - Unregister netdev notifiers.
7029 * @hdd_ctx: HDD context
7030 *
7031 * Unregister netdev notifiers like IPv4 and IPv6.
7032 *
7033 * Return: None.
7034 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007035void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007036{
Alok Kumarb64650c2018-03-23 17:05:11 +05307037 hdd_nud_unregister_netevent_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007038 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
7039
7040 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007041}
7042
7043/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007044 * hdd_exit_netlink_services - Exit netlink services
7045 * @hdd_ctx: HDD context
7046 *
7047 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
7048 * nl service.
7049 *
7050 * Return: None.
7051 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007052static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007053{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307054 spectral_scan_deactivate_service();
7055 cnss_diag_deactivate_service();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007056 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007057 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307058 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007059
7060 nl_srv_exit();
7061}
7062
7063/**
7064 * hdd_init_netlink_services- Init netlink services
7065 * @hdd_ctx: HDD context
7066 *
7067 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
7068 * nl service.
7069 *
7070 * Return: 0 on success and errno on failure.
7071 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007072static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007073{
7074 int ret;
7075
Ryan Hsuceddceb2016-04-28 10:20:14 -07007076 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007077 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007078 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007079 goto out;
7080 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07007081 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007082
Naveen Rawat910726a2017-03-06 11:42:51 -08007083 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007084 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007085 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007086 goto err_nl_srv;
7087 }
7088
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307089 ptt_sock_activate_svc();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007090
7091 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07007092 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007093 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007094
7095 ret = cnss_diag_activate_service();
7096 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007097 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007098 goto err_close_cesium;
7099 }
7100
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307101 spectral_scan_activate_service();
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08007102
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007103 return 0;
7104
7105err_close_cesium:
7106 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007107 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307108 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007109err_nl_srv:
7110 nl_srv_exit();
7111out:
7112 return ret;
7113}
7114
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007115/**
7116 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
7117 * @hdd_ctx: HDD context.
7118 *
7119 * Destroy RX wakelock.
7120 *
7121 * Return: None.
7122 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007123static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007124{
7125 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
7126}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007127
7128/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007129 * hdd_rx_wake_lock_create() - Create RX wakelock
7130 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007131 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007132 * Create RX wakelock.
7133 *
7134 * Return: None.
7135 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007136static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007137{
7138 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
7139}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007140
7141/**
Houston Hoffman160db392016-10-10 17:37:51 -07007142 * hdd_context_deinit() - Deinitialize HDD context
7143 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007144 *
Houston Hoffman160db392016-10-10 17:37:51 -07007145 * Deinitialize HDD context along with all the feature specific contexts but
7146 * do not free hdd context itself. Caller of this API is supposed to free
7147 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007148 *
Houston Hoffman160db392016-10-10 17:37:51 -07007149 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007150 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007151static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007152{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05307153 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
7154
Houston Hoffman160db392016-10-10 17:37:51 -07007155 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007156
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007157 hdd_sap_context_destroy(hdd_ctx);
7158
7159 hdd_rx_wake_lock_destroy(hdd_ctx);
7160
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007161 hdd_scan_context_destroy(hdd_ctx);
7162
Jeff Johnson19fc8e42017-10-30 19:53:49 -07007163 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007164
Houston Hoffman160db392016-10-10 17:37:51 -07007165 return 0;
7166}
7167
Dustin Brown623e7e32018-09-05 14:27:50 -07007168void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07007169{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07007170 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05307171
Dustin Brown623e7e32018-09-05 14:27:50 -07007172 hdd_exit_netlink_services(hdd_ctx);
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05307173 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7174
Houston Hoffman160db392016-10-10 17:37:51 -07007175 hdd_context_deinit(hdd_ctx);
7176
Dustin Browndb2df2e2018-10-31 15:29:24 -07007177 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
7178
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307179 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007180 hdd_ctx->config = NULL;
Dustin Brown84f46ea2018-02-15 11:57:36 -08007181 cfg_release();
7182
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007183 wiphy_free(hdd_ctx->wiphy);
7184}
7185
7186/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05307187 * wlan_destroy_bug_report_lock() - Destroy bug report lock
7188 *
7189 * This function is used to destroy bug report lock
7190 *
7191 * Return: None
7192 */
7193static void wlan_destroy_bug_report_lock(void)
7194{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07007195 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05307196
7197 p_cds_context = cds_get_global_context();
7198 if (!p_cds_context) {
7199 hdd_err("cds context is NULL");
7200 return;
7201 }
7202
7203 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
7204}
7205
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05307206#ifdef DISABLE_CHANNEL_LIST
7207static void wlan_hdd_cache_chann_mutex_destroy(struct hdd_context *hdd_ctx)
7208{
7209 qdf_mutex_destroy(&hdd_ctx->cache_channel_lock);
7210}
7211#else
7212static void wlan_hdd_cache_chann_mutex_destroy(struct hdd_context *hdd_ctx)
7213{
7214}
7215#endif
7216
Dustin Brown92bd8382018-10-31 15:49:46 -07007217void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007218{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007219 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05307220 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007221
Dustin Brown491d54b2018-03-14 12:39:11 -07007222 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007223
Dustin Brown4c663222018-10-23 14:19:36 -07007224 hdd_psoc_idle_timer_stop(hdd_ctx);
Dustin Brown6470aba2018-09-05 09:49:58 -07007225
Arun Khandavallifae92942016-08-01 13:31:08 +05307226 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007227
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007228#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05307229 if (QDF_TIMER_STATE_RUNNING ==
7230 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
7231 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007232 }
7233
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307234 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05307235 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07007236 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007237 }
Liangwei Dongaef84342016-10-21 05:28:00 -04007238 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
7239 qdf_mem_free(hdd_ctx->last_acs_channel_list);
7240 hdd_ctx->last_acs_channel_list = NULL;
7241 hdd_ctx->num_of_channels = 0;
7242 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007243#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007244
Arun Khandavallifae92942016-08-01 13:31:08 +05307245 mutex_lock(&hdd_ctx->iface_change_lock);
7246 driver_status = hdd_ctx->driver_status;
7247 mutex_unlock(&hdd_ctx->iface_change_lock);
7248
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007249 /*
7250 * Powersave Offload Case
7251 * Disable Idle Power Save Mode
7252 */
7253 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07007254 /* clear the scan queue in all the scenarios */
Dustin Brown07901ec2018-09-07 11:02:41 -07007255 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007256
Arun Khandavallifae92942016-08-01 13:31:08 +05307257 if (driver_status != DRIVER_MODULES_CLOSED) {
7258 hdd_unregister_wext_all_adapters(hdd_ctx);
7259 /*
7260 * Cancel any outstanding scan requests. We are about to close
7261 * all of our adapters, but an adapter structure is what SME
7262 * passes back to our callback function. Hence if there
7263 * are any outstanding scan requests then there is a
7264 * race condition between when the adapter is closed and
7265 * when the callback is invoked. We try to resolve that
7266 * race condition here by canceling any outstanding scans
7267 * before we close the adapters.
7268 * Note that the scans may be cancelled in an asynchronous
7269 * manner, so ideally there needs to be some kind of
7270 * synchronization. Rather than introduce a new
7271 * synchronization here, we will utilize the fact that we are
7272 * about to Request Full Power, and since that is synchronized,
7273 * the expectation is that by the time Request Full Power has
7274 * completed, all scans will be cancelled
7275 */
7276 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07007277 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08007278 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08007279 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007280 }
7281
Arunk Khandavalli830c9692018-03-22 12:17:40 +05307282 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavalli08479ba2017-08-07 19:56:23 +05307283 unregister_netdevice_notifier(&hdd_netdev_notifier);
7284
Rachit Kankane30807332018-06-27 18:39:36 +05307285 qdf_dp_trace_deinit();
7286
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07007287 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05307288
Dustin Brown86d196b2018-08-02 11:51:49 -07007289 hdd_bus_bandwidth_deinit(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -08007290 hdd_driver_memdump_deinit();
7291
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05307292 qdf_nbuf_deinit_replenish_timer();
7293
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05307294 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
7295 hdd_info("Release wakelock for monitor mode!");
7296 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
7297 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
7298 }
7299
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307300 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
7301 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
7302 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05307303 wlan_hdd_cache_chann_mutex_destroy(hdd_ctx);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307304
Naveen Rawate02f8f52018-04-05 11:58:04 -07007305 osif_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007306
Dustin Brownd005ad82018-01-19 10:32:13 -08007307 hdd_close_all_adapters(hdd_ctx, false);
7308
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05307309 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307310 /*
7311 * If there is re_init failure wiphy would have already de-registered
7312 * check the wiphy status before un-registering again
7313 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05307314 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307315 wiphy_unregister(wiphy);
7316 wlan_hdd_cfg80211_deinit(wiphy);
7317 hdd_lpass_notify_stop(hdd_ctx);
7318 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07007319
Arun Khandavallifae92942016-08-01 13:31:08 +05307320 hdd_exit_netlink_services(hdd_ctx);
7321 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307322#ifdef FEATURE_WLAN_CH_AVOID
7323 mutex_destroy(&hdd_ctx->avoid_freq_lock);
7324#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007325}
7326
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007327#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04007328/**
7329 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007330 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04007331 *
7332 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
7333 * Then new ACS request will do a fresh scan without reusing the cached
7334 * scan information.
7335 *
7336 * Return: void
7337 */
Tang Yingying523322d2017-01-17 23:28:43 +08007338static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007339{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007340 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Jeff Johnson16528362018-06-14 12:34:16 -07007341 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007342
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007343 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007344 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04007345 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
7346 qdf_mem_free(hdd_ctx->last_acs_channel_list);
7347 hdd_ctx->last_acs_channel_list = NULL;
7348 hdd_ctx->num_of_channels = 0;
7349 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007350
Jeff Johnson16528362018-06-14 12:34:16 -07007351 mac_handle = hdd_ctx->mac_handle;
7352 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007353 return;
Jeff Johnson16528362018-06-14 12:34:16 -07007354 sme_scan_flush_result(mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007355}
7356#endif
7357
7358#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07007359int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
7360 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007361{
7362 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307363 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07007364 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07007365 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007366
7367 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7368
7369 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307370 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007371 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307372
Jeff Johnson16528362018-06-14 12:34:16 -07007373 mac_handle = hdd_ctx->mac_handle;
7374 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007375 return -EINVAL;
7376
Jeff Johnson16528362018-06-14 12:34:16 -07007377 qdf_status = sme_notify_ht2040_mode(mac_handle, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007378 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307379 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007380 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007381 return -EINVAL;
7382 }
7383
7384 return 0;
7385}
7386#endif
7387
7388/**
7389 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
7390 * @state: state
7391 *
7392 * This function notifies FW with modem power status
7393 *
7394 * Return: 0 if successful, error number otherwise
7395 */
7396int hdd_wlan_notify_modem_power_state(int state)
7397{
7398 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307399 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007400 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07007401 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007402
Anurag Chouhan6d760662016-02-20 16:05:43 +05307403 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007404 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307405 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007406 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307407
Jeff Johnson16528362018-06-14 12:34:16 -07007408 mac_handle = hdd_ctx->mac_handle;
7409 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007410 return -EINVAL;
7411
Jeff Johnson16528362018-06-14 12:34:16 -07007412 qdf_status = sme_notify_modem_power_state(mac_handle, state);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307413 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007414 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007415 state);
7416 return -EINVAL;
7417 }
7418 return 0;
7419}
7420
7421/**
7422 *
7423 * hdd_post_cds_enable_config() - HDD post cds start config helper
7424 * @adapter - Pointer to the HDD
7425 *
7426 * Return: None
7427 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007428QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007429{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307430 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007431
7432 /*
7433 * Send ready indication to the HDD. This will kick off the MAC
7434 * into a 'running' state and should kick off an initial scan.
7435 */
Jeff Johnson16528362018-06-14 12:34:16 -07007436 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->mac_handle);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307437 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007438 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
7439 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307440 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007441 }
7442
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307443 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007444}
7445
Sourav Mohapatra92ea8d62018-02-05 10:03:10 +05307446struct hdd_adapter *hdd_get_first_valid_adapter(struct hdd_context *hdd_ctx)
7447{
7448 struct hdd_adapter *adapter;
7449
7450 hdd_for_each_adapter(hdd_ctx, adapter) {
7451 if (adapter && adapter->magic == WLAN_HDD_ADAPTER_MAGIC)
7452 return adapter;
7453 }
7454
7455 return NULL;
7456}
7457
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007458/* wake lock APIs for HDD */
7459void hdd_prevent_suspend(uint32_t reason)
7460{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307461 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007462}
7463
7464void hdd_allow_suspend(uint32_t reason)
7465{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307466 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007467}
7468
7469void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
7470{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05307471 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
7472 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007473}
7474
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007475/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007476QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007477{
Jeff Johnson16528362018-06-14 12:34:16 -07007478 return sme_init_chan_list(hdd_ctx->mac_handle,
Amar Singhal6f8592b2017-04-26 14:31:58 -07007479 hdd_ctx->reg.alpha2,
7480 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007481}
7482
7483/**
7484 * hdd_is_5g_supported() - check if hardware supports 5GHz
7485 * @hdd_ctx: Pointer to the hdd context
7486 *
7487 * HDD function to know if hardware supports 5GHz
7488 *
7489 * Return: true if hardware supports 5GHz
7490 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007491bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007492{
Amar Singhal58b45ef2017-08-01 13:43:54 -07007493 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08007494 return true;
7495
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08007496 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08007497 return true;
7498 else
7499 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007500}
7501
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007502static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007503{
7504 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07007505 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007506
7507 wiphy = hdd_ctx->wiphy;
7508
7509 /*
7510 * The channel information in
7511 * wiphy needs to be initialized before wiphy registration
7512 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007513 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
7514 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007515 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07007516 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007517 }
7518
7519#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
7520 wiphy->wowlan = &wowlan_support_reg_init;
7521#else
7522 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
7523 WIPHY_WOWLAN_MAGIC_PKT |
7524 WIPHY_WOWLAN_DISCONNECT |
7525 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
7526 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
7527 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
7528 WIPHY_WOWLAN_4WAY_HANDSHAKE |
7529 WIPHY_WOWLAN_RFKILL_RELEASE;
7530
7531 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
7532 WOW_MAX_FILTERS_PER_LIST);
7533 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
7534 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
7535#endif
Liangwei Dong0da14262018-07-03 03:30:23 -04007536 if (hdd_ctx->obss_scan_offload) {
7537 hdd_debug("wmi_service_obss_scan supported");
7538 } else if (hdd_ctx->config->nChannelBondingMode24GHz) {
7539 hdd_debug("enable wpa_supp obss_scan");
7540 wiphy->features |= NL80211_FEATURE_NEED_OBSS_SCAN;
7541 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007542
7543 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007544 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307545 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07007546 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307547 return ret_val;
7548 }
Amar Singhalac26de22018-06-22 12:53:06 -07007549
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007550 /* Check the kernel version for upstream commit aced43ce780dc5 that
7551 * has support for processing user cell_base hints when wiphy is
7552 * self managed or check the backport flag for the same.
7553 */
Amar Singhalac26de22018-06-22 12:53:06 -07007554#if defined CFG80211_USER_HINT_CELL_BASE_SELF_MANAGED || \
7555 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0))
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007556 hdd_send_wiphy_regd_sync_event(hdd_ctx);
7557#endif
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307558
Amar Singhal2d812012018-02-03 15:06:47 +08007559 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007560
Amar Singhale4f28ee2015-10-21 14:36:56 -07007561 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007562}
7563
Mohit Khannaca4173b2017-09-12 21:52:19 -07007564#ifdef MSM_PLATFORM
7565/**
7566 * hdd_display_periodic_stats() - Function to display periodic stats
7567 * @hdd_ctx - handle to hdd context
7568 * @bool data_in_interval - true, if data detected in bw time interval
7569 *
7570 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
7571 * Stats show up in wlan driver logs.
7572 *
7573 * Returns: None
7574 */
Mohit Khanna70322002018-05-15 19:21:32 -07007575static void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
7576 bool data_in_interval)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007577{
Mohit Khanna70322002018-05-15 19:21:32 -07007578 static uint32_t counter;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007579 static bool data_in_time_period;
7580 ol_txrx_pdev_handle pdev;
7581
7582 if (hdd_ctx->config->periodic_stats_disp_time == 0)
7583 return;
7584
7585 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
7586 if (!pdev) {
7587 hdd_err("pdev is NULL");
7588 return;
7589 }
7590
7591 counter++;
7592 if (data_in_interval)
7593 data_in_time_period = data_in_interval;
7594
jitiphil869b9f72018-09-25 17:14:01 +05307595 if (counter * hdd_ctx->config->bus_bw_compute_interval >=
Mohit Khannaca4173b2017-09-12 21:52:19 -07007596 hdd_ctx->config->periodic_stats_disp_time * 1000) {
7597 if (data_in_time_period) {
Mohit Khanna70322002018-05-15 19:21:32 -07007598 wlan_hdd_display_txrx_stats(hdd_ctx);
7599 dp_txrx_dump_stats(cds_get_context(QDF_MODULE_ID_SOC));
7600 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
7601 CDP_RX_RING_STATS,
7602 QDF_STATS_VERBOSITY_LEVEL_LOW);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007603 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
7604 CDP_TXRX_PATH_STATS,
7605 QDF_STATS_VERBOSITY_LEVEL_LOW);
7606 wlan_hdd_display_netif_queue_history
7607 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
7608 qdf_dp_trace_dump_stats();
7609 }
7610 counter = 0;
7611 data_in_time_period = false;
7612 }
7613}
7614
Ravi Joshie2331e82015-07-01 18:18:54 -07007615/**
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007616 * hdd_clear_rps_cpu_mask - clear RPS CPU mask for interfaces
7617 * @hdd_ctx: pointer to struct hdd_context
7618 *
7619 * Return: none
7620 */
7621static void hdd_clear_rps_cpu_mask(struct hdd_context *hdd_ctx)
7622{
7623 struct hdd_adapter *adapter;
7624
7625 hdd_for_each_adapter(hdd_ctx, adapter)
7626 hdd_send_rps_disable_ind(adapter);
7627}
7628
7629/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07007630 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07007631 * @hdd_ctx - handle to hdd context
7632 * @tx_packets - transmit packet count
7633 * @rx_packets - receive packet count
7634 *
7635 * The function controls the bus bandwidth and dynamic control of
7636 * tcp delayed ack configuration
7637 *
7638 * Returns: None
7639 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007640
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007641static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07007642 const uint64_t tx_packets,
7643 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007644{
Mohit Khannaca4173b2017-09-12 21:52:19 -07007645 u64 total_pkts = tx_packets + rx_packets;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007646 uint64_t temp_tx = 0, avg_rx = 0;
7647 uint64_t no_rx_offload_pkts = 0, avg_no_rx_offload_pkts = 0;
7648 uint64_t rx_offload_pkts = 0, avg_rx_offload_pkts = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007649 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08007650 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08007651 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007652 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007653 uint16_t index = 0;
7654 bool vote_level_change = false;
7655 bool rx_level_change = false;
7656 bool tx_level_change = false;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007657 bool rxthread_high_tput_req = false;
Mohit Khannaf7562c32018-07-05 17:42:36 -07007658 bool dptrace_high_tput_req;
Srinivas Girigowda50335342018-09-07 15:21:01 -07007659
jitiphil869b9f72018-09-25 17:14:01 +05307660 if (total_pkts > hdd_ctx->config->bus_bw_high_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007661 next_vote_level = PLD_BUS_WIDTH_HIGH;
jitiphil869b9f72018-09-25 17:14:01 +05307662 else if (total_pkts > hdd_ctx->config->bus_bw_medium_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007663 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
jitiphil869b9f72018-09-25 17:14:01 +05307664 else if (total_pkts > hdd_ctx->config->bus_bw_low_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007665 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07007666 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07007667 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007668
Mohit Khannaf7562c32018-07-05 17:42:36 -07007669 dptrace_high_tput_req =
7670 next_vote_level > PLD_BUS_WIDTH_NONE ? true : false;
7671
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007672 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07007673 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
7674 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007675 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007676 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007677 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007678 if ((next_vote_level == PLD_BUS_WIDTH_LOW) ||
7679 (next_vote_level == PLD_BUS_WIDTH_NONE)) {
Nirav Shahffc6a092016-06-09 16:09:08 +05307680 if (hdd_ctx->hbw_requested) {
7681 pld_remove_pm_qos(hdd_ctx->parent_dev);
7682 hdd_ctx->hbw_requested = false;
7683 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007684 if (hdd_ctx->dynamic_rps)
7685 hdd_clear_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007686 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05307687 if (!hdd_ctx->hbw_requested) {
7688 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
7689 hdd_ctx->hbw_requested = true;
7690 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007691 if (hdd_ctx->dynamic_rps)
7692 hdd_set_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007693 }
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007694
Manjunathappa Prakashcb6df762018-05-29 18:54:58 -07007695 if (hdd_ctx->config->napi_cpu_affinity_mask)
7696 hdd_napi_apply_throughput_policy(hdd_ctx,
7697 tx_packets,
7698 rx_packets);
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007699
jitiphil869b9f72018-09-25 17:14:01 +05307700 if (rx_packets < hdd_ctx->config->bus_bw_low_threshold)
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007701 hdd_disable_rx_ol_for_low_tput(hdd_ctx, true);
7702 else
7703 hdd_disable_rx_ol_for_low_tput(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007704 }
Mohit Khannae71e2262015-11-10 09:37:24 -08007705
Mohit Khannaf7562c32018-07-05 17:42:36 -07007706 qdf_dp_trace_apply_tput_policy(dptrace_high_tput_req);
7707
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007708 /*
7709 * Includes tcp+udp, if perf core is required for tcp, then
7710 * perf core is also required for udp.
7711 */
7712 no_rx_offload_pkts = hdd_ctx->no_rx_offload_pkt_cnt;
7713 hdd_ctx->no_rx_offload_pkt_cnt = 0;
7714 rx_offload_pkts = rx_packets - no_rx_offload_pkts;
Mohit Khannae71e2262015-11-10 09:37:24 -08007715
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007716 avg_no_rx_offload_pkts = (no_rx_offload_pkts +
7717 hdd_ctx->prev_no_rx_offload_pkts) / 2;
7718 hdd_ctx->prev_no_rx_offload_pkts = no_rx_offload_pkts;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08007719
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007720 avg_rx_offload_pkts = (rx_offload_pkts +
7721 hdd_ctx->prev_rx_offload_pkts) / 2;
7722 hdd_ctx->prev_rx_offload_pkts = rx_offload_pkts;
7723
7724 avg_rx = avg_no_rx_offload_pkts + avg_rx_offload_pkts;
7725 /*
7726 * Takes care to set Rx_thread affinity for below case
7727 * 1)LRO/GRO not supported ROME case
7728 * 2)when rx_ol is disabled in cases like concurrency etc
7729 * 3)For UDP cases
7730 */
7731 if (avg_no_rx_offload_pkts >
jitiphil869b9f72018-09-25 17:14:01 +05307732 hdd_ctx->config->bus_bw_high_threshold)
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007733 rxthread_high_tput_req = true;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307734 else
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007735 rxthread_high_tput_req = false;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307736
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007737 if (cds_sched_handle_throughput_req(rxthread_high_tput_req))
7738 hdd_warn("Rx thread high_tput(%d) affinity request failed",
7739 rxthread_high_tput_req);
7740
7741 /* fine-tuning parameters for RX Flows */
jitiphil869b9f72018-09-25 17:14:01 +05307742 if (avg_rx > hdd_ctx->config->tcp_delack_thres_high) {
Ravi Joshifed83572016-10-07 16:20:37 -07007743 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
7744 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
7745 next_rx_level = WLAN_SVC_TP_HIGH;
7746 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07007747 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07007748 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08007749 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007750 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007751
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007752 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007753 struct wlan_rx_tp_data rx_tp_data = {0};
7754
Ravi Joshie2331e82015-07-01 18:18:54 -07007755 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Jeff Johnsonb9feee42018-07-08 10:34:48 -07007756 next_rx_level, avg_rx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007757 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007758 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07007759 /* Send throughput indication only if it is enabled.
7760 * Disabling tcp_del_ack will revert the tcp stack behavior
7761 * to default delayed ack. Note that this will disable the
7762 * dynamic delayed ack mechanism across the system
7763 */
Manjunathappa Prakashbfd12762018-04-29 22:44:52 -07007764 if (hdd_ctx->en_tcp_delack_no_lro)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007765 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
7766
Mohit Khanna6272fb682017-04-13 09:34:36 -07007767 if (hdd_ctx->config->enable_tcp_adv_win_scale)
7768 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
7769
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007770 rx_tp_data.level = next_rx_level;
Alok Kumar2fad6442018-11-08 19:19:28 +05307771 wlan_hdd_update_tcp_rx_param(hdd_ctx, &rx_tp_data);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007772 }
7773
Mohit Khannae71e2262015-11-10 09:37:24 -08007774 /* fine-tuning parameters for TX Flows */
7775 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
7776 hdd_ctx->prev_tx = tx_packets;
7777 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
7778 next_tx_level = WLAN_SVC_TP_HIGH;
7779 else
7780 next_tx_level = WLAN_SVC_TP_LOW;
7781
Prakash Manjunathappae73e3b52018-02-27 18:56:22 -08007782 if ((hdd_ctx->config->enable_tcp_limit_output) &&
7783 (hdd_ctx->cur_tx_level != next_tx_level)) {
Alok Kumar2fad6442018-11-08 19:19:28 +05307784 struct wlan_tx_tp_data tx_tp_data = {0};
7785
Mohit Khannae71e2262015-11-10 09:37:24 -08007786 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
7787 next_tx_level, temp_tx);
7788 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007789 tx_level_change = true;
Alok Kumar2fad6442018-11-08 19:19:28 +05307790 tx_tp_data.level = next_tx_level;
7791 tx_tp_data.tcp_limit_output = true;
7792 wlan_hdd_update_tcp_tx_param(hdd_ctx, &tx_tp_data);
Mohit Khannae71e2262015-11-10 09:37:24 -08007793 }
7794
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007795 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007796 if (vote_level_change || tx_level_change || rx_level_change) {
7797 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
7798 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
7799 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
7800 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
7801 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
7802 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
7803 hdd_ctx->hdd_txrx_hist_idx++;
7804 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
7805 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07007806
7807 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007808}
7809
7810#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Rajeev Kumarb2b5e692018-08-31 15:12:40 -07007811static void __hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007812{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007813 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307814 bus_bw_work);
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307815 struct hdd_adapter *adapter = NULL, *con_sap_adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307816 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05307817 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
7818 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007819 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307820 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007821 bool connected = false;
7822 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
7823
Prashanth Bhattaab004382016-10-11 16:08:11 -07007824 if (wlan_hdd_validate_context(hdd_ctx))
7825 return;
7826
Jeff Johnson214671b2017-10-30 19:45:23 -07007827 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08007828 goto restart_timer;
7829
Dustin Brown920397d2017-12-13 16:27:50 -08007830 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05307831 /*
7832 * Validate magic so we don't end up accessing
7833 * an invalid adapter.
7834 */
7835 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
7836 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007837
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007838 if ((adapter->device_mode == QDF_STA_MODE ||
7839 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007840 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
7841 != eConnectionState_Associated) {
7842
7843 continue;
7844 }
7845
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007846 if ((adapter->device_mode == QDF_SAP_MODE ||
7847 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07007848 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007849
7850 continue;
7851 }
7852
7853 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
7854 adapter->prev_tx_packets);
7855 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
7856 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307857
7858 if (adapter->device_mode == QDF_SAP_MODE ||
7859 adapter->device_mode == QDF_P2P_GO_MODE ||
7860 adapter->device_mode == QDF_IBSS_MODE) {
7861
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08007862 ret = cdp_get_intra_bss_fwd_pkts_count(
7863 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007864 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307865 &fwd_tx_packets, &fwd_rx_packets);
7866 if (ret == A_OK) {
7867 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
7868 fwd_tx_packets,
7869 adapter->prev_fwd_tx_packets);
7870 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
7871 fwd_tx_packets,
7872 adapter->prev_fwd_rx_packets);
7873 }
7874 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007875
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307876 if (adapter->device_mode == QDF_SAP_MODE)
7877 con_sap_adapter = adapter;
7878
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007879 total_rx += adapter->stats.rx_packets;
7880 total_tx += adapter->stats.tx_packets;
7881
7882 spin_lock_bh(&hdd_ctx->bus_bw_lock);
7883 adapter->prev_tx_packets = adapter->stats.tx_packets;
7884 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307885 adapter->prev_fwd_tx_packets = fwd_tx_packets;
7886 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007887 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
7888 connected = true;
7889 }
7890
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007891 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007892 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007893 return;
7894 }
7895
Yun Parka29974a2018-04-09 12:05:49 -07007896 /* add intra bss forwarded tx and rx packets */
7897 tx_packets += fwd_tx_packets_diff;
7898 rx_packets += fwd_rx_packets_diff;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007899
Dustin Brown07901ec2018-09-07 11:02:41 -07007900 if (ucfg_ipa_is_fw_wdi_activated(hdd_ctx->pdev)) {
7901 ucfg_ipa_uc_stat_query(hdd_ctx->pdev, &ipa_tx_packets,
7902 &ipa_rx_packets);
Yun Parka29974a2018-04-09 12:05:49 -07007903 tx_packets += (uint64_t)ipa_tx_packets;
7904 rx_packets += (uint64_t)ipa_rx_packets;
7905
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307906 if (con_sap_adapter) {
7907 con_sap_adapter->stats.tx_packets += ipa_tx_packets;
7908 con_sap_adapter->stats.rx_packets += ipa_rx_packets;
7909 }
7910
Dustin Brown07901ec2018-09-07 11:02:41 -07007911 ucfg_ipa_set_perf_level(hdd_ctx->pdev, tx_packets, rx_packets);
7912 ucfg_ipa_uc_stat_request(hdd_ctx->pdev, 2);
Yun Parka29974a2018-04-09 12:05:49 -07007913 }
7914
7915 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007916
Jingxiang Gec64e1932017-08-22 14:38:59 +08007917restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08007918 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08007919 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08007920 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05307921 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
jitiphil869b9f72018-09-25 17:14:01 +05307922 hdd_ctx->config->bus_bw_compute_interval);
Dustin Brownfce08d12017-01-17 16:29:38 -08007923 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007924}
Prashanth Bhattaab004382016-10-11 16:08:11 -07007925
Rajeev Kumarb2b5e692018-08-31 15:12:40 -07007926static void hdd_bus_bw_work_handler(struct work_struct *work)
7927{
7928 cds_ssr_protect(__func__);
7929 __hdd_bus_bw_work_handler(work);
7930 cds_ssr_unprotect(__func__);
7931}
7932
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307933/**
7934 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
7935 * @arg: Argument of timer function
7936 *
7937 * Schedule a workqueue in this function where all the processing is done.
7938 *
7939 * Return: None.
7940 */
7941static void __hdd_bus_bw_cbk(void *arg)
7942{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007943 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307944
7945 if (wlan_hdd_validate_context(hdd_ctx))
7946 return;
7947
7948 schedule_work(&hdd_ctx->bus_bw_work);
7949}
7950
7951/**
7952 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
7953 * @arg: Argument of timer function
7954 *
7955 * Return: None.
7956 */
7957static void hdd_bus_bw_cbk(void *arg)
7958{
7959 cds_ssr_protect(__func__);
7960 __hdd_bus_bw_cbk(arg);
7961 cds_ssr_unprotect(__func__);
7962}
7963
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007964int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007965{
Dustin Brown35008ba2018-08-23 14:34:21 -07007966 hdd_enter();
7967
Prashanth Bhattaab004382016-10-11 16:08:11 -07007968 spin_lock_init(&hdd_ctx->bus_bw_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07007969 INIT_WORK(&hdd_ctx->bus_bw_work, hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08007970 hdd_ctx->bus_bw_timer_running = false;
7971 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07007972 qdf_timer_init(NULL, &hdd_ctx->bus_bw_timer, hdd_bus_bw_cbk,
7973 (void *)hdd_ctx, QDF_TIMER_TYPE_SW);
7974
7975 hdd_exit();
Prashanth Bhattaab004382016-10-11 16:08:11 -07007976
7977 return 0;
7978}
7979
Dustin Brown86d196b2018-08-02 11:51:49 -07007980void hdd_bus_bandwidth_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007981{
Dustin Brown35008ba2018-08-23 14:34:21 -07007982 hdd_enter();
Prashanth Bhattaab004382016-10-11 16:08:11 -07007983
Rajeev Kumarc27efb62018-08-31 14:21:22 -07007984 QDF_BUG(!hdd_ctx->bus_bw_timer_running);
Dustin Brown35008ba2018-08-23 14:34:21 -07007985
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307986 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08007987 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07007988
7989 hdd_exit();
Prashanth Bhattaab004382016-10-11 16:08:11 -07007990}
Lin Baic5c06882017-09-21 13:58:43 +08007991
Dustin Brown35008ba2018-08-23 14:34:21 -07007992#endif /* MSM_PLATFORM */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007993
7994/**
Nirav Shahed34b212016-04-25 10:59:16 +05307995 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
7996 * @hdd_ctx: hdd context
7997 *
7998 * Return: 0 for success or error code
7999 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008000static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05308001{
8002 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
8003 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Min Liu74a1a502018-10-10 19:59:07 +08008004 if (!hdd_ctx->hdd_txrx_hist)
Nirav Shahed34b212016-04-25 10:59:16 +05308005 return -ENOMEM;
Nirav Shahed34b212016-04-25 10:59:16 +05308006 return 0;
8007}
8008
8009/**
8010 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
8011 * @hdd_ctx: hdd context
8012 *
8013 * Return: none
8014 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008015void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05308016{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05308017 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
8018 return;
8019
8020 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
8021 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05308022}
8023
Nirav Shahda008342016-05-17 18:50:40 +05308024static uint8_t *convert_level_to_string(uint32_t level)
8025{
8026 switch (level) {
8027 /* initialize the wlan sub system */
8028 case WLAN_SVC_TP_NONE:
8029 return "NONE";
8030 case WLAN_SVC_TP_LOW:
8031 return "LOW";
8032 case WLAN_SVC_TP_MEDIUM:
8033 return "MED";
8034 case WLAN_SVC_TP_HIGH:
8035 return "HIGH";
8036 default:
8037 return "INVAL";
8038 }
8039}
8040
Nirav Shahed34b212016-04-25 10:59:16 +05308041
8042/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008043 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
8044 * @hdd_ctx: hdd context
8045 *
8046 * Return: none
8047 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008048void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008049{
8050 int i;
8051
8052#ifdef MSM_PLATFORM
Nirav Shahe6194ac2018-07-13 11:04:41 +05308053 hdd_nofl_info("BW compute Interval: %dms",
jitiphil869b9f72018-09-25 17:14:01 +05308054 hdd_ctx->config->bus_bw_compute_interval);
Nirav Shahe6194ac2018-07-13 11:04:41 +05308055 hdd_nofl_info("BW High TH: %d BW Med TH: %d BW Low TH: %d",
jitiphil869b9f72018-09-25 17:14:01 +05308056 hdd_ctx->config->bus_bw_high_threshold,
8057 hdd_ctx->config->bus_bw_medium_threshold,
8058 hdd_ctx->config->bus_bw_low_threshold);
Nirav Shahe6194ac2018-07-13 11:04:41 +05308059 hdd_nofl_info("Enable TCP DEL ACK: %d",
8060 hdd_ctx->en_tcp_delack_no_lro);
8061 hdd_nofl_info("TCP DEL High TH: %d TCP DEL Low TH: %d",
jitiphil869b9f72018-09-25 17:14:01 +05308062 hdd_ctx->config->tcp_delack_thres_high,
8063 hdd_ctx->config->tcp_delack_thres_low);
Nirav Shahe6194ac2018-07-13 11:04:41 +05308064 hdd_nofl_info("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
8065 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008066#endif
8067
Nirav Shahe6194ac2018-07-13 11:04:41 +05308068 hdd_nofl_info("Total entries: %d Current index: %d",
8069 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
Nirav Shahda008342016-05-17 18:50:40 +05308070
Nirav Shahe6194ac2018-07-13 11:04:41 +05308071 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 -08008072
8073 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008074 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08008075 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Nirav Shahe6194ac2018-07-13 11:04:41 +05308076 hdd_nofl_info("[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
8077 i, hdd_ctx->hdd_txrx_hist[i].qtime,
8078 hdd_ctx->hdd_txrx_hist[i].interval_rx,
8079 hdd_ctx->hdd_txrx_hist[i].interval_tx,
8080 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008081 hdd_ctx->hdd_txrx_hist[i].
8082 next_vote_level),
Nirav Shahe6194ac2018-07-13 11:04:41 +05308083 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008084 hdd_ctx->hdd_txrx_hist[i].
8085 next_rx_level),
Nirav Shahe6194ac2018-07-13 11:04:41 +05308086 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008087 hdd_ctx->hdd_txrx_hist[i].
8088 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008089 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008090}
8091
8092/**
8093 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
8094 * @hdd_ctx: hdd context
8095 *
8096 * Return: none
8097 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008098void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008099{
8100 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05308101 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
8102 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008103}
8104
Mohit Khannaca4173b2017-09-12 21:52:19 -07008105/* length of the netif queue log needed per adapter */
8106#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
8107
8108/**
8109 *
8110 * hdd_display_netif_queue_history_compact() - display compact netifq history
8111 * @hdd_ctx: hdd context
8112 *
8113 * Return: none
8114 */
8115static void
8116hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
8117{
8118 int adapter_num = 0;
8119 int i;
8120 int bytes_written;
8121 u32 tbytes;
8122 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008123 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08008124 char *comb_log_str;
8125 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008126 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008127
Dustin Brownbee82832018-07-23 10:10:51 -07008128 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * CSR_ROAM_SESSION_MAX) + 1;
jiadbdefb252018-01-03 14:27:06 +08008129 comb_log_str = qdf_mem_malloc(comb_log_str_size);
Min Liu74a1a502018-10-10 19:59:07 +08008130 if (!comb_log_str)
jiadbdefb252018-01-03 14:27:06 +08008131 return;
jiadbdefb252018-01-03 14:27:06 +08008132
Mohit Khannaca4173b2017-09-12 21:52:19 -07008133 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008134
Dustin Brown920397d2017-12-13 16:27:50 -08008135 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07008136 curr_time = qdf_system_ticks();
8137 total = curr_time - adapter->start_time;
8138 delta = curr_time - adapter->last_time;
8139
8140 if (adapter->pause_map) {
8141 pause = adapter->total_pause_time + delta;
8142 unpause = adapter->total_unpause_time;
8143 } else {
8144 unpause = adapter->total_unpause_time + delta;
8145 pause = adapter->total_pause_time;
8146 }
8147
8148 tbytes = 0;
8149 qdf_mem_set(temp_str, 0, sizeof(temp_str));
8150 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
8151 if (adapter->queue_oper_stats[i].pause_count == 0)
8152 continue;
8153 tbytes +=
8154 snprintf(
8155 &temp_str[tbytes],
8156 (tbytes >= sizeof(temp_str) ?
8157 0 : sizeof(temp_str) - tbytes),
8158 "%d(%d,%d) ",
8159 i,
8160 adapter->queue_oper_stats[i].
8161 pause_count,
8162 adapter->queue_oper_stats[i].
8163 unpause_count);
8164 }
8165 if (tbytes >= sizeof(temp_str))
8166 hdd_warn("log truncated");
8167
8168 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08008169 bytes_written >= comb_log_str_size ? 0 :
8170 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07008171 "[%d %d] (%d) %u/%ums %s|",
8172 adapter->session_id, adapter->device_mode,
8173 adapter->pause_map,
8174 qdf_system_ticks_to_msecs(pause),
8175 qdf_system_ticks_to_msecs(total),
8176 temp_str);
8177
Mohit Khannaca4173b2017-09-12 21:52:19 -07008178 adapter_num++;
8179 }
8180
8181 /* using QDF_TRACE to avoid printing function name */
8182 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
8183 "STATS |%s", comb_log_str);
8184
jiadbdefb252018-01-03 14:27:06 +08008185 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07008186 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08008187
8188 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07008189}
8190
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008191/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008192 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07008193 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008194 *
8195 * Return: none
8196 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07008197void
8198wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
8199 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008200{
8201
Jeff Johnson9d295242017-08-29 14:39:48 -07008202 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008203 int i;
Nirav Shahda008342016-05-17 18:50:40 +05308204 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008205
Mohit Khannaca4173b2017-09-12 21:52:19 -07008206 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
8207 hdd_display_netif_queue_history_compact(hdd_ctx);
8208 return;
8209 }
8210
Dustin Brown920397d2017-12-13 16:27:50 -08008211 hdd_for_each_adapter(hdd_ctx, adapter) {
Nirav Shahe6194ac2018-07-13 11:04:41 +05308212 hdd_nofl_info("Netif queue operation statistics:");
8213 hdd_nofl_info("Session_id %d device mode %d",
8214 adapter->session_id, adapter->device_mode);
8215 hdd_nofl_info("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05308216 curr_time = qdf_system_ticks();
8217 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05308218 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05308219 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05308220 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05308221 unpause = adapter->total_unpause_time;
8222 } else {
Nirav Shahda008342016-05-17 18:50:40 +05308223 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05308224 pause = adapter->total_pause_time;
8225 }
Nirav Shahe6194ac2018-07-13 11:04:41 +05308226 hdd_nofl_info("Total: %ums Pause: %ums Unpause: %ums",
8227 qdf_system_ticks_to_msecs(total),
8228 qdf_system_ticks_to_msecs(pause),
8229 qdf_system_ticks_to_msecs(unpause));
8230 hdd_nofl_info("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008231
Nirav Shahda008342016-05-17 18:50:40 +05308232 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
8233 qdf_time_t pause_delta = 0;
8234
8235 if (adapter->pause_map & (1 << i))
8236 pause_delta = delta;
8237
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008238 /* using hdd_log to avoid printing function name */
Nirav Shahe6194ac2018-07-13 11:04:41 +05308239 hdd_nofl_info("%s: %d: %d: %ums",
8240 hdd_reason_type_to_string(i),
8241 adapter->queue_oper_stats[i].pause_count,
8242 adapter->queue_oper_stats[i].
8243 unpause_count,
8244 qdf_system_ticks_to_msecs(
8245 adapter->queue_oper_stats[i].
8246 total_pause_time + pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008247 }
8248
Nirav Shahe6194ac2018-07-13 11:04:41 +05308249 hdd_nofl_info("Netif queue operation history:");
8250 hdd_nofl_info("Total entries: %d current index %d",
8251 WLAN_HDD_MAX_HISTORY_ENTRY,
8252 adapter->history_index);
Nirav Shahda008342016-05-17 18:50:40 +05308253
Nirav Shahe6194ac2018-07-13 11:04:41 +05308254 hdd_nofl_info("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008255
8256 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008257 /* using hdd_log to avoid printing function name */
8258 if (adapter->queue_oper_history[i].time == 0)
8259 continue;
Nirav Shahe6194ac2018-07-13 11:04:41 +05308260 hdd_nofl_info("%d: %u: %s: %s: %x",
8261 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008262 adapter->queue_oper_history[i].time),
Nirav Shahe6194ac2018-07-13 11:04:41 +05308263 hdd_action_type_to_string(
8264 adapter->queue_oper_history[i].
8265 netif_action),
8266 hdd_reason_type_to_string(
8267 adapter->queue_oper_history[i].
8268 netif_reason),
8269 adapter->queue_oper_history[i].pause_map);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008270 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008271 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008272}
8273
8274/**
8275 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
8276 * @hdd_ctx: hdd context
8277 *
8278 * Return: none
8279 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008280void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008281{
Jeff Johnson9d295242017-08-29 14:39:48 -07008282 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008283
Dustin Brown920397d2017-12-13 16:27:50 -08008284 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308285 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008286 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308287 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008288 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05308289 adapter->history_index = 0;
8290 adapter->start_time = adapter->last_time = qdf_system_ticks();
8291 adapter->total_pause_time = 0;
8292 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008293 }
8294}
8295
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008296#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
8297/**
8298 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
8299 * @hdd_ctx: hdd global context
8300 *
8301 * Return: none
8302 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008303static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008304{
8305 uint8_t i;
8306
8307 mutex_init(&hdd_ctx->op_ctx.op_lock);
8308 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
8309 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
8310 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
8311 }
8312}
8313#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008314static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008315{
8316}
8317#endif
8318
Yingying Tang95409972016-10-20 15:16:15 +08008319#ifdef WLAN_FEATURE_WOW_PULSE
8320/**
8321 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008322 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08008323 * @enable: enable or disable this behaviour
8324 *
8325 * Return: int
8326 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008327static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008328{
Yingying Tang95409972016-10-20 15:16:15 +08008329 struct wow_pulse_mode wow_pulse_set_info;
8330 QDF_STATUS status;
8331
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008332 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08008333
Wu Gao66454f12018-09-26 19:55:41 +08008334 if (!ucfg_pmo_is_wow_pulse_enabled(phddctx->psoc))
Yingying Tang95409972016-10-20 15:16:15 +08008335 return 0;
8336
8337 /* prepare the request to send to SME */
8338 if (enable == true) {
8339 wow_pulse_set_info.wow_pulse_enable = true;
8340 wow_pulse_set_info.wow_pulse_pin =
Wu Gao66454f12018-09-26 19:55:41 +08008341 ucfg_pmo_get_wow_pulse_pin(phddctx->psoc);
8342
Yingying Tang95409972016-10-20 15:16:15 +08008343 wow_pulse_set_info.wow_pulse_interval_high =
Wu Gao66454f12018-09-26 19:55:41 +08008344 ucfg_pmo_get_wow_pulse_interval_high(phddctx->psoc);
8345
8346 wow_pulse_set_info.wow_pulse_interval_low =
8347 ucfg_pmo_get_wow_pulse_interval_low(phddctx->psoc);
Yingying Tang95409972016-10-20 15:16:15 +08008348 } else {
8349 wow_pulse_set_info.wow_pulse_enable = false;
8350 wow_pulse_set_info.wow_pulse_pin = 0;
8351 wow_pulse_set_info.wow_pulse_interval_low = 0;
8352 wow_pulse_set_info.wow_pulse_interval_high = 0;
8353 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008354 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08008355 wow_pulse_set_info.wow_pulse_enable,
8356 wow_pulse_set_info.wow_pulse_pin,
8357 wow_pulse_set_info.wow_pulse_interval_low,
8358 wow_pulse_set_info.wow_pulse_interval_high);
8359
8360 status = sme_set_wow_pulse(&wow_pulse_set_info);
8361 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008362 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08008363 return -EIO;
8364 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008365 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08008366 return 0;
8367}
8368#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008369static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008370{
8371 return 0;
8372}
8373#endif
8374
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008375#ifdef WLAN_FEATURE_FASTPATH
jitiphil377bcc12018-10-05 19:46:08 +05308376
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008377/**
8378 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
8379 * @hdd_cfg: hdd config
8380 * @context: lower layer context
8381 *
8382 * Return: none
8383 */
jitiphil377bcc12018-10-05 19:46:08 +05308384void hdd_enable_fastpath(struct hdd_context *hdd_ctx,
8385 void *context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008386{
jitiphil377bcc12018-10-05 19:46:08 +05308387 if (cfg_get(hdd_ctx->psoc, CFG_DP_ENABLE_FASTPATH))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008388 hif_enable_fastpath(context);
8389}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008390#endif
8391
Yuanyuan Liu13738502016-04-06 17:41:37 -07008392#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008393/**
8394 * hdd_set_thermal_level_cb() - set thermal level callback function
Jeff Johnson0e963082018-07-04 19:39:20 -07008395 * @hdd_handle: opaque handle for the hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008396 * @level: thermal level
8397 *
8398 * Change IPA data path to SW path when the thermal throttle level greater
8399 * than 0, and restore the original data path when throttle level is 0
8400 *
8401 * Return: none
8402 */
Jeff Johnson0e963082018-07-04 19:39:20 -07008403static void hdd_set_thermal_level_cb(hdd_handle_t hdd_handle, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008404{
Jeff Johnson0e963082018-07-04 19:39:20 -07008405 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008406
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008407 /* Change IPA to SW path when throttle level greater than 0 */
8408 if (level > THROTTLE_LEVEL_0)
Dustin Brown07901ec2018-09-07 11:02:41 -07008409 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->pdev, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008410 else
8411 /* restore original concurrency mode */
Dustin Brown07901ec2018-09-07 11:02:41 -07008412 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->pdev, hdd_ctx->mcc_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008413}
8414
8415/**
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308416 * hdd_get_safe_channel() - Get safe channel from current regulatory
8417 * @hdd_ctx: pointer to hdd context
8418 * @adapter: pointer to softap adapter
8419 *
8420 * This function is used to get safe channel from current regulatory valid
8421 * channels to restart SAP if failed to get safe channel from PCL.
8422 *
8423 * Return: Channel number to restart SAP in case of success. In case of any
8424 * failure, the channel number returned is zero.
8425 */
8426static uint8_t
8427hdd_get_safe_channel(struct hdd_context *hdd_ctx,
8428 struct hdd_adapter *adapter)
8429{
8430 struct sir_pcl_list pcl = {0};
8431 uint32_t i, j;
8432 bool found = false;
8433 int ret;
8434
8435 /* Try for safe channel from all valid channel */
8436 pcl.pcl_len = MAX_NUM_CHAN;
8437 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
8438 &pcl.pcl_len);
8439 if (ret) {
8440 hdd_err("error %d in getting valid channel list", ret);
8441 return INVALID_CHANNEL_ID;
8442 }
8443
8444 for (i = 0; i < pcl.pcl_len; i++) {
8445 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
8446 found = false;
8447 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
8448 if (pcl.pcl_list[i] ==
8449 hdd_ctx->unsafe_channel_list[j]) {
8450 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
8451 found = true;
8452 break;
8453 }
8454 }
8455
8456 if (found)
8457 continue;
8458
8459 if ((pcl.pcl_list[i] >=
8460 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
8461 (pcl.pcl_list[i] <=
8462 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
8463 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
8464 return pcl.pcl_list[i];
8465 }
8466 }
8467
8468 return INVALID_CHANNEL_ID;
8469}
8470
8471#else
8472/**
8473 * hdd_set_thermal_level_cb() - set thermal level callback function
8474 * @hdd_handle: opaque handle for the hdd context
8475 * @level: thermal level
8476 *
8477 * Change IPA data path to SW path when the thermal throttle level greater
8478 * than 0, and restore the original data path when throttle level is 0
8479 *
8480 * Return: none
8481 */
8482static void hdd_set_thermal_level_cb(hdd_handle_t hdd_handle, u_int8_t level)
8483{
8484}
8485
8486/**
8487 * hdd_get_safe_channel() - Get safe channel from current regulatory
8488 * @hdd_ctx: pointer to hdd context
8489 * @adapter: pointer to softap adapter
8490 *
8491 * This function is used to get safe channel from current regulatory valid
8492 * channels to restart SAP if failed to get safe channel from PCL.
8493 *
8494 * Return: Channel number to restart SAP in case of success. In case of any
8495 * failure, the channel number returned is zero.
8496 */
8497static uint8_t
8498hdd_get_safe_channel(struct hdd_context *hdd_ctx,
8499 struct hdd_adapter *adapter)
8500{
8501 return 0;
8502}
8503#endif
8504
8505/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308506 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
8507 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05308508 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008509 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308510 * Get a safe channel to restart SAP. PCL already takes into account the
8511 * unsafe channels. So, the PCL is validated with the ACS range to provide
8512 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008513 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308514 * Return: Channel number to restart SAP in case of success. In case of any
8515 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008516 */
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308517static uint8_t
8518hdd_get_safe_channel_from_pcl_and_acs_range(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008519{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308520 struct sir_pcl_list pcl;
8521 QDF_STATUS status;
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308522 uint32_t i;
Jeff Johnson16528362018-06-14 12:34:16 -07008523 mac_handle_t mac_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008524 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008525
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308526 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8527 if (!hdd_ctx) {
8528 hdd_err("invalid HDD context");
8529 return INVALID_CHANNEL_ID;
8530 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008531
Jeff Johnson16528362018-06-14 12:34:16 -07008532 mac_handle = hdd_ctx->mac_handle;
8533 if (!mac_handle) {
8534 hdd_err("invalid MAC handle");
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05308535 return INVALID_CHANNEL_ID;
8536 }
8537
Dustin Brown1dbefe62018-09-11 16:32:03 -07008538 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008539 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08008540 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
8541 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308542 if (QDF_IS_STATUS_ERROR(status)) {
8543 hdd_err("Get PCL failed");
8544 return INVALID_CHANNEL_ID;
8545 }
8546
Frank Liudc2cefb2017-06-21 15:38:18 +08008547 /*
8548 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
8549 * channel is unsafe channel, the pcl may be empty, instead of return,
8550 * try to choose a safe channel from acs range.
8551 */
8552 if (!pcl.pcl_len)
8553 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308554
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008555 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07008556 adapter->session.ap.sap_config.acs_cfg.start_ch,
8557 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308558
8559 /* PCL already takes unsafe channel into account */
8560 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008561 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308562 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008563 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308564 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008565 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008566 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308567 return pcl.pcl_list[i];
8568 }
8569 }
8570
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008571 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308572
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308573 return hdd_get_safe_channel(hdd_ctx, adapter);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308574}
8575
8576/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008577 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308578 * @adapter: AP adapter
8579 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08008580 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308581 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008582 * Moves the SAP interface by invoking the function which
8583 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308584 *
8585 * Return: None
8586 */
Min Liu2fef5792018-01-19 17:59:42 +08008587void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
8588 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308589{
Jeff Johnson87251032017-08-29 13:31:11 -07008590 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008591 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07008592 mac_handle_t mac_handle;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308593
8594 if (!adapter) {
8595 hdd_err("invalid adapter");
8596 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008597 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308598
8599 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
8600
Jeff Johnson16528362018-06-14 12:34:16 -07008601 mac_handle = hdd_adapter_get_mac_handle(adapter);
8602 if (!mac_handle) {
8603 hdd_err("invalid MAC handle");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308604 return;
8605 }
8606
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008607 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8608
Jeff Johnson91df29d2017-10-27 19:29:50 -07008609 hdd_ap_ctx->sap_config.channel = channel;
Himanshu Agarwalf5c5b102018-05-22 20:13:57 +05308610 hdd_ap_ctx->sap_config.ch_params.ch_width = CH_WIDTH_MAX;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308611
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008612 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07008613 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308614
Dustin Brown07901ec2018-09-07 11:02:41 -07008615 wlan_reg_set_channel_params(hdd_ctx->pdev,
8616 hdd_ap_ctx->sap_config.channel,
8617 hdd_ap_ctx->sap_config.sec_ch,
8618 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308619
Dustin Brown1dbefe62018-09-11 16:32:03 -07008620 policy_mgr_change_sap_channel_with_csa(hdd_ctx->psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07008621 adapter->session_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08008622 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008623}
Kapil Gupta8878ad92017-02-13 11:56:04 +05308624
Jeff Johnson9d295242017-08-29 14:39:48 -07008625int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05308626{
8627 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308628 int status;
8629 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308630
8631 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8632
8633 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07008634 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05308635 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07008636 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308637 }
8638 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07008639 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308640 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308641 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07008642 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308643 WLAN_VENDOR_ACS_WAIT_TIME);
8644 if (qdf_status != QDF_STATUS_SUCCESS) {
8645 hdd_err("failed to start external acs timer");
8646 return -ENOSPC;
8647 }
8648 /* Update config to application */
8649 status = hdd_cfg80211_update_acs_config(adapter, reason);
Dustin Brown5e89ef82018-03-14 11:50:23 -07008650 hdd_info("Updated ACS config to nl with reason %d", reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308651
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308652 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308653}
8654
Nirav Shaheb017be2018-02-15 11:20:58 +05308655#if defined(FEATURE_WLAN_CH_AVOID)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308656/**
8657 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
8658 * @hdd_ctx: hdd context pointer
8659 *
8660 * hdd_unsafe_channel_restart_sap check all unsafe channel list
8661 * and if ACS is enabled, driver will ask userspace to restart the
8662 * sap. User space on LTE coex indication restart driver.
8663 *
8664 * Return - none
8665 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008666void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308667{
Dustin Brown920397d2017-12-13 16:27:50 -08008668 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308669 uint32_t i;
8670 bool found = false;
8671 uint8_t restart_chan;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05308672 bool value;
Harprit Chhabada1eeeb8d2018-09-14 15:16:56 -07008673 QDF_STATUS status;
8674 bool is_acs_support_for_dfs_ltecoex = cfg_default(CFG_USER_ACS_DFS_LTE);
8675 bool is_vendor_acs_support =
8676 cfg_default(CFG_USER_AUTO_CHANNEL_SELECTION);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008677
Dustin Brown920397d2017-12-13 16:27:50 -08008678 hdd_for_each_adapter(hdd_ctxt, adapter) {
8679 if (!(adapter->device_mode == QDF_SAP_MODE &&
8680 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008681 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08008682 adapter->device_mode,
8683 adapter->session.ap.sap_config.
8684 acs_cfg.acs_mode);
8685 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308686 }
8687
8688 found = false;
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008689 /*
8690 * If STA+SAP is doing SCC & g_sta_sap_scc_on_lte_coex_chan
8691 * is set, no need to move SAP.
8692 */
Dustin Brown1dbefe62018-09-11 16:32:03 -07008693 if (policy_mgr_is_sta_sap_scc(hdd_ctxt->psoc,
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008694 adapter->session.ap.operating_channel) &&
8695 hdd_ctxt->config->sta_sap_scc_on_lte_coex_chan)
8696 hdd_debug("SAP is allowed on SCC channel, no need to move SAP");
8697 else {
8698 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
8699 if (adapter->session.ap.operating_channel ==
8700 hdd_ctxt->unsafe_channel_list[i]) {
8701 found = true;
8702 hdd_debug("operating ch:%d is unsafe",
8703 adapter->session.ap.operating_channel);
8704 break;
8705 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308706 }
8707 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308708 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008709 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08008710 adapter->session.ap.operating_channel);
8711 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308712 }
8713
Harprit Chhabada1eeeb8d2018-09-14 15:16:56 -07008714 status = ucfg_mlme_get_acs_support_for_dfs_ltecoex(
8715 hdd_ctxt->psoc,
8716 &is_acs_support_for_dfs_ltecoex);
8717 if (!QDF_IS_STATUS_SUCCESS(status))
8718 hdd_err("get_acs_support_for_dfs_ltecoex failed,set def");
8719
8720 status = ucfg_mlme_get_vendor_acs_support(
8721 hdd_ctxt->psoc,
8722 &is_vendor_acs_support);
8723 if (!QDF_IS_STATUS_SUCCESS(status))
8724 hdd_err("get_vendor_acs_support failed, set default");
8725
8726 if (is_vendor_acs_support && is_acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08008727 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05308728 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08008729 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308730 } else
8731 restart_chan =
8732 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08008733 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308734 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008735 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308736 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008737 /*
8738 * SAP restart due to unsafe channel. While
8739 * restarting the SAP, make sure to clear
8740 * acs_channel, channel to reset to
8741 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308742 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008743 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308744 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008745 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308746 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
8747 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Dustin Brown05d81302018-09-11 16:49:22 -07008748 ucfg_mlme_get_sap_internal_restart(hdd_ctxt->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05308749 &value);
8750 hdd_debug("driver to start sap: %d", value);
8751 if (value)
Min Liu2fef5792018-01-19 17:59:42 +08008752 hdd_switch_sap_channel(adapter, restart_chan,
8753 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04008754 else
8755 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308756 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308757 }
8758}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05308759
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008760/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008761 * hdd_init_channel_avoidance() - Initialize channel avoidance
8762 * @hdd_ctx: HDD global context
8763 *
8764 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07008765 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008766 * down to the lower layers. Then subscribe to subsequent channel
8767 * avoidance events.
8768 *
8769 * Return: None
8770 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008771static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008772{
8773 uint16_t unsafe_channel_count;
8774 int index;
8775
Yuanyuan Liu13738502016-04-06 17:41:37 -07008776 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
8777 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008778 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08008779 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008780
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008781 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008782 hdd_ctx->unsafe_channel_count);
8783
Anurag Chouhan6d760662016-02-20 16:05:43 +05308784 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08008785 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008786
8787 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008788 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008789 hdd_ctx->unsafe_channel_list[index]);
8790
8791 }
8792
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008793}
Dustin Brown676a2322017-08-15 13:16:13 -07008794
Jeff Johnson9d295242017-08-29 14:39:48 -07008795static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008796 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008797{
8798 uint8_t restart_chan;
8799
8800 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
8801 if (!restart_chan) {
8802 hdd_alert("fail to restart SAP");
8803 return;
8804 }
8805
8806 /* SAP restart due to unsafe channel. While restarting
8807 * the SAP, make sure to clear acs_channel, channel to
8808 * reset to 0. Otherwise these settings will override
8809 * the ACS while restart.
8810 */
8811 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07008812
8813 hdd_debug("sending coex indication");
8814
8815 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
8816 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08008817 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07008818}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008819
8820int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
8821 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
8822{
8823 uint32_t size;
8824 uint16_t *unsafe_list;
8825 uint16_t chan_count;
8826
8827 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
8828 return -EINVAL;
8829
8830 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
8831 NUM_CHANNELS);
8832 if (chan_count) {
8833 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
8834 unsafe_list = qdf_mem_malloc(size);
Min Liu74a1a502018-10-10 19:59:07 +08008835 if (!unsafe_list)
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008836 return -ENOMEM;
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008837 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
8838 } else {
8839 unsafe_list = NULL;
8840 }
8841
8842 *local_unsafe_list = unsafe_list;
8843 *local_unsafe_list_count = chan_count;
8844
8845 return 0;
8846}
8847
8848bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
8849 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
8850{
8851 int i, j;
8852
8853 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
8854 return true;
8855 if (local_unsafe_list_count == 0)
8856 return false;
8857 for (i = 0; i < local_unsafe_list_count; i++) {
8858 for (j = 0; j < local_unsafe_list_count; j++)
8859 if (local_unsafe_list[i] ==
8860 hdd_ctx->unsafe_channel_list[j])
8861 break;
8862 if (j >= local_unsafe_list_count)
8863 break;
8864 }
8865 if (i >= local_unsafe_list_count) {
8866 hdd_info("unsafe chan list same");
8867 return false;
8868 }
8869
8870 return true;
8871}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008872#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008873static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008874{
8875}
Dustin Brown676a2322017-08-15 13:16:13 -07008876
Jeff Johnson9d295242017-08-29 14:39:48 -07008877static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008878 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008879{
8880 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
8881}
Yuanyuan Liu13738502016-04-06 17:41:37 -07008882#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008883
8884/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08008885 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
8886 * user space
8887 * @frame_ind: Management frame data to be informed.
8888 *
8889 * This function is used to indicate management frame to
8890 * user space
8891 *
8892 * Return: None
8893 *
8894 */
8895void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
8896{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008897 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07008898 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008899 int i;
Pragaspathi Thilagaraj28ffc042018-07-18 15:19:36 +05308900 struct ieee80211_mgmt *mgmt =
8901 (struct ieee80211_mgmt *)frame_ind->frameBuf;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008902
Dustin Browne7e71d32018-05-11 16:00:08 -07008903 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
8904 if (wlan_hdd_validate_context(hdd_ctx))
Rajeev Kumard004abc2016-02-17 12:09:56 -08008905 return;
8906
Pragaspathi Thilagaraj28ffc042018-07-18 15:19:36 +05308907 if (frame_ind->frame_len < ieee80211_hdrlen(mgmt->frame_control)) {
8908 hdd_err(" Invalid frame length");
8909 return;
8910 }
8911
Rajeev Kumard004abc2016-02-17 12:09:56 -08008912 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
8913 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
8914 adapter =
8915 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
8916 if (adapter)
8917 break;
8918 }
Wu Gaoa0230a62018-01-04 20:56:57 +08008919 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
8920 hdd_for_each_adapter(hdd_ctx, adapter) {
8921 if ((NULL != adapter) &&
8922 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
8923 __hdd_indicate_mgmt_frame(adapter,
8924 frame_ind->frame_len,
8925 frame_ind->frameBuf,
8926 frame_ind->frameType,
8927 frame_ind->rxChan,
8928 frame_ind->rxRssi);
8929 }
8930 }
8931 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008932 } else {
8933 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
8934 frame_ind->sessionId);
8935 }
8936
8937 if ((NULL != adapter) &&
8938 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
8939 __hdd_indicate_mgmt_frame(adapter,
8940 frame_ind->frame_len,
8941 frame_ind->frameBuf,
8942 frame_ind->frameType,
8943 frame_ind->rxChan,
8944 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008945}
8946
Kapil Gupta8878ad92017-02-13 11:56:04 +05308947void hdd_acs_response_timeout_handler(void *context)
8948{
8949 struct hdd_external_acs_timer_context *timer_context =
8950 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07008951 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008952 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308953 uint8_t reason;
8954
Dustin Brown491d54b2018-03-14 12:39:11 -07008955 hdd_enter();
Kapil Gupta8878ad92017-02-13 11:56:04 +05308956 if (!timer_context) {
8957 hdd_err("invlaid timer context");
8958 return;
8959 }
8960 adapter = timer_context->adapter;
8961 reason = timer_context->reason;
8962
8963
8964 if ((!adapter) ||
8965 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
8966 hdd_err("invalid adapter or adapter has invalid magic");
8967 return;
8968 }
8969 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8970 if (wlan_hdd_validate_context(hdd_ctx))
8971 return;
8972
8973 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
8974 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8975 else
8976 return;
8977
8978 hdd_err("ACS timeout happened for %s reason %d",
8979 adapter->dev->name, reason);
Jeff Johnson16528362018-06-14 12:34:16 -07008980
Kapil Gupta8878ad92017-02-13 11:56:04 +05308981 switch (reason) {
8982 /* SAP init case */
8983 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
8984 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
8985 false);
8986 wlan_hdd_cfg80211_start_acs(adapter);
8987 break;
8988 /* DFS detected on current channel */
8989 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
8990 wlan_sap_update_next_channel(
8991 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
Jeff Johnson16528362018-06-14 12:34:16 -07008992 sme_update_new_channel_event(hdd_ctx->mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07008993 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308994 break;
8995 /* LTE coex event on current channel */
8996 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
8997 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
8998 break;
8999 default:
9000 hdd_info("invalid reason for timer invoke");
9001
9002 }
9003}
9004
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009005/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009006 * hdd_override_ini_config - Override INI config
9007 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009008 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009009 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009010 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009011 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009012 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009013static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009014{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009015
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009016 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
9017 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009018 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009019 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009020 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009021 if (0 == enable_11d || 1 == enable_11d) {
9022 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009023 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009024 }
Leo Chang11545d62016-10-17 14:53:50 -07009025
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +05309026 if (hdd_ctx->config->action_oui_enable && !ucfg_action_oui_enabled()) {
9027 hdd_ctx->config->action_oui_enable = 0;
9028 hdd_err("Ignore ini: %s, since no action_oui component",
9029 CFG_ENABLE_ACTION_OUI);
9030 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009031}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009032
Ashish Kumar Dhanotiya12f68212018-09-04 22:00:14 +05309033#ifdef ENABLE_MTRACE_LOG
9034static void hdd_set_mtrace_for_each(struct hdd_context *hdd_ctx)
9035{
9036 uint8_t module_id = 0;
9037 int qdf_print_idx = -1;
9038
9039 qdf_print_idx = qdf_get_pidx();
9040 for (module_id = 0; module_id < QDF_MODULE_ID_MAX; module_id++)
9041 qdf_print_set_category_verbose(
9042 qdf_print_idx,
9043 module_id, QDF_TRACE_LEVEL_TRACE,
9044 hdd_ctx->config->enable_mtrace);
9045}
9046#else
9047static void hdd_set_mtrace_for_each(struct hdd_context *hdd_ctx)
9048{
9049}
9050
9051#endif
9052
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009053/**
9054 * hdd_set_trace_level_for_each - Set trace level for each INI config
9055 * @hdd_ctx - HDD context
9056 *
9057 * Set trace level for each module based on INI config.
9058 *
9059 * Return: None
9060 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009061static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009062{
Wu Gaobc6eaa12018-11-30 14:17:45 +08009063 hdd_qdf_trace_enable(QDF_MODULE_ID_DP, 0x7f);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05309064 hdd_qdf_trace_enable(QDF_MODULE_ID_MLME, 0xffff);
Sourav Mohapatra113685f2018-08-29 14:21:55 +05309065 hdd_qdf_trace_enable(QDF_MODULE_ID_FWOL, 0xffff);
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07009066 hdd_qdf_trace_enable(QDF_MODULE_ID_CRYPTO, 0xffff);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07009067
Ashish Kumar Dhanotiya12f68212018-09-04 22:00:14 +05309068 hdd_set_mtrace_for_each(hdd_ctx);
9069
Nirav Shah5c083da2018-08-03 13:46:02 +05309070 hdd_cfg_print_global_config(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009071}
9072
9073/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009074 * hdd_context_init() - Initialize HDD context
9075 * @hdd_ctx: HDD context.
9076 *
9077 * Initialize HDD context along with all the feature specific contexts.
9078 *
9079 * return: 0 on success and errno on failure.
9080 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009081static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009082{
9083 int ret;
9084
9085 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
9086 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
9087
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009088 init_completion(&hdd_ctx->mc_sus_event_var);
9089 init_completion(&hdd_ctx->ready_to_suspend);
9090
9091 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05309092 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009093 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05309094
Dustin Brownbee82832018-07-23 10:10:51 -07009095 qdf_list_create(&hdd_ctx->hdd_adapters, 0);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009096
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009097 ret = hdd_scan_context_init(hdd_ctx);
9098 if (ret)
9099 goto list_destroy;
9100
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009101 hdd_rx_wake_lock_create(hdd_ctx);
9102
9103 ret = hdd_sap_context_init(hdd_ctx);
9104 if (ret)
9105 goto scan_destroy;
9106
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009107 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
9108
9109 hdd_init_offloaded_packets_ctx(hdd_ctx);
9110
9111 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
9112 hdd_ctx->config);
9113 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08009114 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009115
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05309116 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
9117 "monitor_mode_wakelock");
9118
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009119 return 0;
9120
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009121sap_destroy:
9122 hdd_sap_context_destroy(hdd_ctx);
9123
9124scan_destroy:
9125 hdd_scan_context_destroy(hdd_ctx);
9126 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009127list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07009128 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08009129
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009130 return ret;
9131}
9132
Dustin Brown4c663222018-10-23 14:19:36 -07009133void hdd_psoc_idle_timer_start(struct hdd_context *hdd_ctx)
9134{
9135 uint32_t timeout_ms = hdd_ctx->config->iface_change_wait_time;
9136 enum wake_lock_reason reason =
9137 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER;
9138
9139 hdd_debug("Starting psoc idle timer");
9140 qdf_sched_delayed_work(&hdd_ctx->psoc_idle_timeout_work, timeout_ms);
9141 hdd_prevent_suspend_timeout(timeout_ms, reason);
9142}
9143
9144void hdd_psoc_idle_timer_stop(struct hdd_context *hdd_ctx)
9145{
9146 qdf_cancel_delayed_work(&hdd_ctx->psoc_idle_timeout_work);
9147 hdd_debug("Stopped psoc idle timer");
9148}
9149
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009150/**
Dustin Brown3ecc8782018-09-19 16:37:13 -07009151 * hdd_psoc_idle_shutdown() - perform an idle shutdown on the given psoc
9152 * @hdd_ctx: the hdd context which should be shutdown
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309153 *
Dustin Brown3ecc8782018-09-19 16:37:13 -07009154 * When no interfaces are "up" on a psoc, an idle shutdown timer is started.
9155 * If no interfaces are brought up before the timer expires, we do an
9156 * "idle shutdown," cutting power to the physical SoC to save power. This is
9157 * done completely transparently from the perspective of userspace.
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309158 *
Dustin Brown3ecc8782018-09-19 16:37:13 -07009159 * Return: None
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309160 */
Dustin Brown3ecc8782018-09-19 16:37:13 -07009161static void hdd_psoc_idle_shutdown(struct hdd_context *hdd_ctx)
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309162{
Dustin Brown3ecc8782018-09-19 16:37:13 -07009163 struct hdd_psoc *hdd_psoc = hdd_ctx->hdd_psoc;
9164 QDF_STATUS status;
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309165
Dustin Brown491d54b2018-03-14 12:39:11 -07009166 hdd_enter();
Dustin Brown3ecc8782018-09-19 16:37:13 -07009167
9168 status = dsc_psoc_trans_start(hdd_psoc->dsc_psoc, "idle shutdown");
9169 if (QDF_IS_STATUS_ERROR(status)) {
9170 hdd_info("psoc busy, abort idle shutdown; status:%u", status);
9171 return;
9172 }
9173
9174 QDF_BUG(!hdd_wlan_stop_modules(hdd_ctx, false));
9175
9176 hdd_psoc->state = psoc_state_idle;
9177 dsc_psoc_trans_stop(hdd_psoc->dsc_psoc);
9178
Dustin Browne74003f2018-03-14 12:51:58 -07009179 hdd_exit();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309180}
9181
Dustin Brown3ecc8782018-09-19 16:37:13 -07009182int hdd_psoc_idle_restart(struct hdd_context *hdd_ctx)
9183{
9184 struct hdd_psoc *hdd_psoc = hdd_ctx->hdd_psoc;
9185 QDF_STATUS status;
9186 int errno;
9187
9188 status = dsc_psoc_trans_start_wait(hdd_psoc->dsc_psoc, "idle restart");
9189 if (QDF_IS_STATUS_ERROR(status)) {
9190 hdd_info("unable to start 'idle restart'; status:%u", status);
9191 return qdf_status_to_os_return(status);
9192 }
9193
9194 errno = hdd_wlan_start_modules(hdd_ctx, false);
9195 if (!errno)
9196 hdd_psoc->state = psoc_state_active;
9197
9198 dsc_psoc_trans_stop(hdd_psoc->dsc_psoc);
9199
9200 return errno;
9201}
9202
9203/**
9204 * hdd_psoc_idle_timeout_callback() - Handler for psoc idle timeout
9205 * @priv: pointer to hdd context
9206 *
9207 * Return: None
9208 */
9209static void hdd_psoc_idle_timeout_callback(void *priv)
9210{
9211 struct hdd_context *hdd_ctx = priv;
9212
9213 if (wlan_hdd_validate_context(hdd_ctx))
9214 return;
9215
9216 hdd_debug("Psoc idle timeout elapsed; starting psoc shutdown");
9217 hdd_psoc_idle_shutdown(hdd_ctx);
9218}
9219
Nirav Shaheb017be2018-02-15 11:20:58 +05309220#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9221static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
9222{
9223 wlan_logging_set_log_to_console(hdd_ctx->config->
9224 wlan_logging_to_console);
9225 wlan_logging_set_active(hdd_ctx->config->wlan_logging_enable);
9226}
9227#else
9228static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
9229{ }
9230#endif
9231
Dundi Raviteja8e338282018-09-25 17:16:04 +05309232#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9233static void hdd_init_wlan_logging_params(struct hdd_config *config,
9234 struct wlan_objmgr_psoc *psoc)
9235{
9236 config->wlan_logging_enable = cfg_get(psoc, CFG_WLAN_LOGGING_SUPPORT);
9237
9238 config->wlan_logging_to_console =
9239 cfg_get(psoc, CFG_WLAN_LOGGING_CONSOLE_SUPPORT);
9240}
9241#else
9242static void hdd_init_wlan_logging_params(struct hdd_config *config,
9243 struct wlan_objmgr_psoc *psoc)
9244{
9245}
9246#endif
9247
9248#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9249static void hdd_init_wlan_auto_shutdown(struct hdd_config *config,
9250 struct wlan_objmgr_psoc *psoc)
9251{
9252 config->wlan_auto_shutdown = cfg_get(psoc, CFG_WLAN_AUTO_SHUTDOWN);
9253}
9254#else
9255static void hdd_init_wlan_auto_shutdown(struct hdd_config *config,
9256 struct wlan_objmgr_psoc *psoc)
9257{
9258}
9259#endif
9260
9261#ifndef REMOVE_PKT_LOG
9262static void hdd_init_packet_log(struct hdd_config *config,
9263 struct wlan_objmgr_psoc *psoc)
9264{
9265 config->enable_packet_log = cfg_get(psoc, CFG_ENABLE_PACKET_LOG);
9266}
9267#else
9268static void hdd_init_packet_log(struct hdd_config *config,
9269 struct wlan_objmgr_psoc *psoc)
9270{
9271}
9272#endif
9273
9274/**
9275 * hdd_cfg_params_init() - Initialize hdd params in hdd_config strucuture
9276 * @hdd_ctx - Pointer to HDD context
9277 *
9278 * Return: None
9279 */
9280static void hdd_cfg_params_init(struct hdd_context *hdd_ctx)
9281{
9282 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
9283 struct hdd_config *config = hdd_ctx->config;
9284
9285 if (!psoc) {
9286 hdd_err("Invalid psoc");
9287 return;
9288 }
9289
9290 if (!config) {
9291 hdd_err("Invalid hdd config");
9292 return;
9293 }
9294
9295 config->bug_on_reinit_failure = cfg_get(psoc,
9296 CFG_BUG_ON_REINIT_FAILURE);
9297
9298 config->is_ramdump_enabled = cfg_get(psoc,
9299 CFG_ENABLE_RAMDUMP_COLLECTION);
9300
9301 config->iface_change_wait_time = cfg_get(psoc,
9302 CFG_INTERFACE_CHANGE_WAIT);
9303
9304 config->multicast_host_fw_msgs = cfg_get(psoc,
9305 CFG_MULTICAST_HOST_FW_MSGS);
9306
9307 config->private_wext_control = cfg_get(psoc, CFG_PRIVATE_WEXT_CONTROL);
9308 config->timer_multiplier = cfg_get(psoc, CFG_TIMER_MULTIPLIER);
9309 config->enablefwprint = cfg_get(psoc, CFG_ENABLE_FW_UART_PRINT);
9310 config->enable_fw_log = cfg_get(psoc, CFG_ENABLE_FW_LOG);
Vignesh Viswanathana0358ff2018-11-27 09:53:07 +05309311 config->operating_channel = cfg_get(psoc, CFG_OPERATING_CHANNEL);
9312 config->num_vdevs = cfg_get(psoc, CFG_NUM_VDEV_ENABLE);
9313
9314 qdf_str_lcopy(config->enable_concurrent_sta,
9315 cfg_get(psoc, CFG_ENABLE_CONCURRENT_STA),
9316 CFG_CONCURRENT_IFACE_MAX_LEN);
9317 qdf_str_lcopy(config->dbs_scan_selection,
9318 cfg_get(psoc, CFG_DBS_SCAN_SELECTION),
9319 CFG_DBS_SCAN_PARAM_LENGTH);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309320
9321 hdd_init_wlan_auto_shutdown(config, psoc);
9322 hdd_init_wlan_logging_params(config, psoc);
9323 hdd_init_packet_log(config, psoc);
jitiphil869b9f72018-09-25 17:14:01 +05309324 hdd_dp_cfg_update(psoc, hdd_ctx);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309325}
9326
Dustin Brown623e7e32018-09-05 14:27:50 -07009327struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009328{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309329 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009330 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009331 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009332
Dustin Brown491d54b2018-03-14 12:39:11 -07009333 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009334
Dustin Brown92bd8382018-10-31 15:49:46 -07009335 hdd_ctx = hdd_cfg80211_wiphy_alloc();
9336 if (!hdd_ctx) {
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009337 ret = -ENOMEM;
9338 goto err_out;
9339 }
9340
Dustin Brown4c663222018-10-23 14:19:36 -07009341 qdf_create_delayed_work(&hdd_ctx->psoc_idle_timeout_work,
Dustin Brown3ecc8782018-09-19 16:37:13 -07009342 hdd_psoc_idle_timeout_callback,
Dustin Brown4c663222018-10-23 14:19:36 -07009343 hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309344
9345 mutex_init(&hdd_ctx->iface_change_lock);
9346
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009347 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05309348 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009349
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309350 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Min Liu74a1a502018-10-10 19:59:07 +08009351 if (!hdd_ctx->config) {
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009352 ret = -ENOMEM;
9353 goto err_free_hdd_context;
9354 }
9355
9356 /* Read and parse the qcom_cfg.ini file */
9357 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309358 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309359 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009360 WLAN_INI_FILE);
9361 ret = -EINVAL;
9362 goto err_free_config;
9363 }
9364
Dustin Brown84f46ea2018-02-15 11:57:36 -08009365 status = cfg_parse(WLAN_INI_FILE);
9366 if (QDF_IS_STATUS_ERROR(status))
9367 hdd_err("Failed to parse cfg %s; status:%d\n",
9368 WLAN_INI_FILE, status);
9369
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309370 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx, DEFAULT_PSOC_ID);
9371 if (ret) {
Dundi Raviteja8e338282018-09-25 17:16:04 +05309372 QDF_DEBUG_PANIC("Psoc creation fails!");
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309373 goto err_free_config;
9374 }
9375
Dundi Raviteja8e338282018-09-25 17:16:04 +05309376 hdd_cfg_params_init(hdd_ctx);
9377
Dustin Brown7f939932017-05-18 15:02:17 -07009378 hdd_debug("setting timer multiplier: %u",
9379 hdd_ctx->config->timer_multiplier);
9380 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
9381
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309382 cds_set_fatal_event(cfg_get(hdd_ctx->psoc,
9383 CFG_ENABLE_FATAL_EVENT_TRIGGER));
Abhishek Singh5ea86532016-04-27 14:10:53 +05309384
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009385 hdd_override_ini_config(hdd_ctx);
9386
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009387 ret = hdd_context_init(hdd_ctx);
9388
9389 if (ret)
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309390 goto err_hdd_objmgr_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009391
Anurag Chouhan6d760662016-02-20 16:05:43 +05309392 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009393 goto skip_multicast_logging;
9394
9395 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
9396
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07009397 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
9398 if (ret)
9399 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05309400
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009401 ret = hdd_init_netlink_services(hdd_ctx);
9402 if (ret)
9403 goto err_deinit_txrx_histogram;
9404
Nirav Shaheb017be2018-02-15 11:20:58 +05309405 hdd_set_wlan_logging(hdd_ctx);
Nirav Shahed34b212016-04-25 10:59:16 +05309406
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009407skip_multicast_logging:
9408 hdd_set_trace_level_for_each(hdd_ctx);
9409
Rajeev Kumar493a31b2017-09-29 14:01:24 -07009410 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
9411
Dustin Browne74003f2018-03-14 12:51:58 -07009412 hdd_exit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07009413
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009414 return hdd_ctx;
9415
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009416err_deinit_txrx_histogram:
9417 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
9418
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07009419err_deinit_hdd_context:
9420 hdd_context_deinit(hdd_ctx);
9421
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309422err_hdd_objmgr_destroy:
9423 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9424
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009425err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309426 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009427
9428err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309429 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08009430 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009431
9432err_out:
9433 return ERR_PTR(ret);
9434}
9435
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009436#ifdef WLAN_OPEN_P2P_INTERFACE
9437/**
9438 * hdd_open_p2p_interface - Open P2P interface
Dustin Brown61cc3932018-10-18 16:12:13 -07009439 * @hdd_ctx: HDD context
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009440 *
Dustin Brown61cc3932018-10-18 16:12:13 -07009441 * Return: QDF_STATUS
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009442 */
Dustin Brown61cc3932018-10-18 16:12:13 -07009443static QDF_STATUS hdd_open_p2p_interface(struct hdd_context *hdd_ctx)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009444{
Jeff Johnson9d295242017-08-29 14:39:48 -07009445 struct hdd_adapter *adapter;
Dustin Brown61cc3932018-10-18 16:12:13 -07009446 bool p2p_dev_addr_admin;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009447
Dustin Brown1dbefe62018-09-11 16:32:03 -07009448 cfg_p2p_get_device_addr_admin(hdd_ctx->psoc, &p2p_dev_addr_admin);
Dustin Brown61cc3932018-10-18 16:12:13 -07009449
Wu Gaoe5689792018-07-05 19:20:13 +08009450 if (p2p_dev_addr_admin &&
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009451 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Dustin Brown61cc3932018-10-18 16:12:13 -07009452 hdd_ctx->p2p_device_address = hdd_ctx->config->intfMacAddr[0];
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009453
9454 /*
Dustin Brown61cc3932018-10-18 16:12:13 -07009455 * Generate the P2P Device Address. This consists of
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009456 * the device's primary MAC address with the locally
9457 * administered bit set.
9458 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009459 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009460 } else {
Dustin Brown61cc3932018-10-18 16:12:13 -07009461 uint8_t *p2p_dev_addr;
9462
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009463 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
Dustin Brown61cc3932018-10-18 16:12:13 -07009464 if (!p2p_dev_addr) {
9465 hdd_err("Failed to get MAC address for new p2p device");
9466 return QDF_STATUS_E_INVAL;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009467 }
9468
Dustin Brown61cc3932018-10-18 16:12:13 -07009469 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009470 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009471 }
9472
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009473 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Dustin Brown61cc3932018-10-18 16:12:13 -07009474 hdd_ctx->p2p_device_address.bytes,
9475 NET_NAME_UNKNOWN, true);
9476 if (!adapter) {
9477 hdd_err("Failed to open p2p interface");
9478 return QDF_STATUS_E_INVAL;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009479 }
9480
Dustin Brown61cc3932018-10-18 16:12:13 -07009481 return QDF_STATUS_SUCCESS;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009482}
9483#else
Dustin Brown61cc3932018-10-18 16:12:13 -07009484static inline QDF_STATUS hdd_open_p2p_interface(struct hdd_context *hdd_ctx)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009485{
Dustin Brown61cc3932018-10-18 16:12:13 -07009486 return QDF_STATUS_SUCCESS;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009487}
9488#endif
9489
Dustin Brown61cc3932018-10-18 16:12:13 -07009490static QDF_STATUS hdd_open_ocb_interface(struct hdd_context *hdd_ctx)
Jeff Johnson957bc272017-02-02 08:54:48 -08009491{
Jeff Johnson9d295242017-08-29 14:39:48 -07009492 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08009493
9494 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
9495 wlan_hdd_get_intf_addr(hdd_ctx),
Dustin Brown61cc3932018-10-18 16:12:13 -07009496 NET_NAME_UNKNOWN, true);
9497 if (!adapter) {
Jeff Johnson957bc272017-02-02 08:54:48 -08009498 hdd_err("Failed to open 802.11p interface");
Dustin Brown61cc3932018-10-18 16:12:13 -07009499 return QDF_STATUS_E_INVAL;
Jeff Johnson957bc272017-02-02 08:54:48 -08009500 }
9501
Dustin Brown61cc3932018-10-18 16:12:13 -07009502 return QDF_STATUS_SUCCESS;
9503}
9504
9505static QDF_STATUS hdd_open_concurrent_interface(struct hdd_context *hdd_ctx)
9506{
9507 struct hdd_adapter *adapter;
9508
Vignesh Viswanathana0358ff2018-11-27 09:53:07 +05309509 if (qdf_str_eq(hdd_ctx->config->enable_concurrent_sta, ""))
Dustin Brown61cc3932018-10-18 16:12:13 -07009510 return QDF_STATUS_SUCCESS;
9511
9512 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
Vignesh Viswanathana0358ff2018-11-27 09:53:07 +05309513 hdd_ctx->config->enable_concurrent_sta,
Dustin Brown61cc3932018-10-18 16:12:13 -07009514 wlan_hdd_get_intf_addr(hdd_ctx),
9515 NET_NAME_UNKNOWN, true);
9516 if (!adapter) {
9517 hdd_err("Failed to open concurrent station interface");
9518 return QDF_STATUS_E_INVAL;
9519 }
9520
9521 return QDF_STATUS_SUCCESS;
Jeff Johnson957bc272017-02-02 08:54:48 -08009522}
9523
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009524/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309525 * hdd_start_station_adapter()- Start the Station Adapter
9526 * @adapter: HDD adapter
9527 *
9528 * This function initializes the adapter for the station mode.
9529 *
9530 * Return: 0 on success or errno on failure.
9531 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009532int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309533{
9534 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08009535 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309536
Dustin Brownfdf17c12018-03-14 12:55:34 -07009537 hdd_enter_dev(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08009538 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9539 hdd_err("session is already opened, %d",
9540 adapter->session_id);
9541 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9542 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309543
Krunal Sonib51eec72017-11-20 21:53:01 -08009544 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
9545 if (ret) {
9546 hdd_err("failed to create vdev: %d", ret);
9547 return ret;
9548 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309549 status = hdd_init_station_mode(adapter);
9550
9551 if (QDF_STATUS_SUCCESS != status) {
9552 hdd_err("Error Initializing station mode: %d", status);
9553 return qdf_status_to_os_return(status);
9554 }
9555
Arun Khandavallifae92942016-08-01 13:31:08 +05309556 hdd_register_tx_flow_control(adapter,
9557 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009558 hdd_tx_resume_cb,
9559 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309560
Dustin Browne74003f2018-03-14 12:51:58 -07009561 hdd_exit();
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05309562
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309563 return 0;
9564}
9565
9566/**
9567 * hdd_start_ap_adapter()- Start AP Adapter
9568 * @adapter: HDD adapter
9569 *
9570 * This function initializes the adapter for the AP mode.
9571 *
9572 * Return: 0 on success errno on failure.
9573 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009574int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309575{
9576 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009577 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08009578 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08009579 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309580
Dustin Brown491d54b2018-03-14 12:39:11 -07009581 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309582
Krunal Sonib51eec72017-11-20 21:53:01 -08009583 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9584 hdd_err("session is already opened, %d",
9585 adapter->session_id);
9586 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9587 }
9588 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009589 * In SSR case no need to create new sap context.
9590 * Otherwise create sap context first and then create
9591 * vdev as while creating the vdev, driver needs to
9592 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08009593 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009594 if (adapter->session.ap.sap_context) {
9595 is_ssr = true;
9596 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08009597 hdd_err("sap creation failed");
9598 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
9599 }
9600
9601 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
9602 adapter->session.ap.sap_context);
9603 if (ret) {
9604 hdd_err("failed to create vdev, status:%d", ret);
9605 hdd_sap_destroy_ctx(adapter);
9606 return ret;
9607 }
Naveen Rawat1af09392018-01-03 17:28:21 -08009608
9609 if (adapter->device_mode == QDF_SAP_MODE)
9610 sme_cli_set_command(adapter->session_id,
9611 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
9612 (bool)(hdd_ctx->config->fine_time_meas_cap &
9613 WMI_FW_AP_RTT_RESPR),
9614 VDEV_CMD);
9615
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009616 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309617
9618 if (QDF_STATUS_SUCCESS != status) {
9619 hdd_err("Error Initializing the AP mode: %d", status);
9620 return qdf_status_to_os_return(status);
9621 }
9622
Arun Khandavallifae92942016-08-01 13:31:08 +05309623 hdd_register_tx_flow_control(adapter,
9624 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009625 hdd_softap_tx_resume_cb,
9626 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309627
Dustin Browne74003f2018-03-14 12:51:58 -07009628 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309629 return 0;
9630}
9631
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309632#ifdef QCA_LL_TX_FLOW_CONTROL_V2
9633/**
9634 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
9635 * @cds_cfg: CDS Configuration
9636 * @hdd_ctx: Pointer to hdd context
9637 *
9638 * Return: none
9639 */
9640static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9641 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009642 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309643{
9644 cds_cfg->tx_flow_stop_queue_th =
jitiphil47c3d9a2018-11-08 18:30:55 +05309645 cfg_get(hdd_ctx->psoc, CFG_DP_TX_FLOW_STOP_QUEUE_TH);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309646 cds_cfg->tx_flow_start_queue_offset =
jitiphil47c3d9a2018-11-08 18:30:55 +05309647 cfg_get(hdd_ctx->psoc, CFG_DP_TX_FLOW_START_QUEUE_OFFSET);
Mohit Khanna70322002018-05-15 19:21:32 -07009648 /* configuration for DP RX Threads */
9649 cds_cfg->enable_dp_rx_threads = hdd_ctx->enable_dp_rx_threads;
9650 cds_cfg->num_dp_rx_threads = hdd_ctx->config->num_dp_rx_threads;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309651}
9652#else
9653static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9654 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009655 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309656{
9657}
9658#endif
9659
9660#ifdef FEATURE_WLAN_RA_FILTERING
9661/**
9662 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
9663 * @cds_cfg: CDS Configuration
9664 * @hdd_ctx: Pointer to hdd context
9665 *
9666 * Return: none
9667 */
Anand Kumar3b92a912016-12-05 12:01:26 +05309668static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009669 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309670{
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05309671 bool is_rate_limit_enabled;
9672 QDF_STATUS status;
9673
9674 status = ucfg_fwol_get_is_rate_limit_enabled(hdd_ctx->psoc,
9675 &is_rate_limit_enabled);
9676 if (QDF_IS_STATUS_ERROR(status))
9677 return;
9678
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309679 cds_cfg->ra_ratelimit_interval =
9680 hdd_ctx->config->RArateLimitInterval;
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05309681 cds_cfg->is_ra_ratelimit_enabled = is_rate_limit_enabled;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309682}
9683#else
Anand Kumar3b92a912016-12-05 12:01:26 +05309684static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009685 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309686{
9687}
9688#endif
9689
9690/**
9691 * hdd_update_cds_config() - API to update cds configuration parameters
9692 * @hdd_ctx: HDD Context
9693 *
9694 * Return: 0 for Success, errno on failure
9695 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009696static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309697{
9698 struct cds_config_info *cds_cfg;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309699 int value;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309700 uint8_t band_capability;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309701 uint8_t ito_repeat_count;
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309702 bool crash_inject;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309703 bool self_recovery;
9704 bool fw_timeout_crash;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309705 QDF_STATUS status;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309706
Min Liu74a1a502018-10-10 19:59:07 +08009707 cds_cfg = qdf_mem_malloc(sizeof(*cds_cfg));
9708 if (!cds_cfg)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309709 return -ENOMEM;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309710
Srinivas Girigowda35b00312017-06-27 21:52:03 -07009711 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Bala Venkatesh46e29032018-11-14 18:24:55 +05309712 ucfg_mlme_get_sap_max_modulated_dtim(hdd_ctx->psoc,
9713 &cds_cfg->sta_maxlimod_dtim);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309714
9715 /*
9716 * Copy the DFS Phyerr Filtering Offload status.
9717 * This parameter reflects the value of the
9718 * dfs_phyerr_filter_offload flag as set in the ini.
9719 */
9720 cds_cfg->dfs_phyerr_filter_offload =
9721 hdd_ctx->config->fDfsPhyerrFilterOffload;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309722
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309723 status = ucfg_mlme_get_crash_inject(hdd_ctx->psoc, &crash_inject);
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309724 if (QDF_IS_STATUS_ERROR(status)) {
9725 hdd_err("Failed to get crash inject ini config");
9726 goto exit;
9727 }
9728
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309729 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
9730 if (QDF_IS_STATUS_ERROR(status)) {
9731 hdd_err("Failed to get self recovery ini config");
9732 goto exit;
9733 }
9734
9735 status = ucfg_mlme_get_fw_timeout_crash(hdd_ctx->psoc,
9736 &fw_timeout_crash);
9737 if (QDF_IS_STATUS_ERROR(status)) {
9738 hdd_err("Failed to get fw timeout crash ini config");
9739 goto exit;
9740 }
9741
9742 status = ucfg_mlme_get_ito_repeat_count(hdd_ctx->psoc,
9743 &ito_repeat_count);
9744 if (QDF_IS_STATUS_ERROR(status)) {
9745 hdd_err("Failed to get ITO repeat count ini config");
9746 goto exit;
9747 }
9748
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309749 cds_cfg->force_target_assert_enabled = crash_inject;
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05309750
Dustin Brown05d81302018-09-11 16:49:22 -07009751 ucfg_mlme_get_sap_max_offload_peers(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309752 cds_cfg->ap_maxoffload_peers = value;
Dustin Brown05d81302018-09-11 16:49:22 -07009753 ucfg_mlme_get_sap_max_offload_reorder_buffs(hdd_ctx->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309754 &value);
9755 cds_cfg->ap_maxoffload_reorderbuffs = value;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309756
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309757 cds_cfg->dfs_pri_multiplier =
9758 hdd_ctx->config->dfsRadarPriMultiplier;
9759 cds_cfg->reorder_offload =
jitiphil47c3d9a2018-11-08 18:30:55 +05309760 cfg_get(hdd_ctx->psoc, CFG_DP_REORDER_OFFLOAD_SUPPORT);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309761
9762 /* IPA micro controller data path offload resource config item */
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05309763 cds_cfg->uc_offload_enabled = ucfg_ipa_uc_is_enabled();
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309764 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
9765
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07009766 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309767 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
Dustin Brown05d81302018-09-11 16:49:22 -07009768 ucfg_mlme_get_sap_max_peers(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309769 cds_cfg->max_station = value;
Naveen Rawat64e477e2016-05-20 10:34:56 -07009770 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07009771 cds_cfg->max_msdus_per_rxinorderind =
jitiphil8e15ea62018-11-16 18:05:34 +05309772 cfg_get(hdd_ctx->psoc, CFG_DP_MAX_MSDUS_PER_RXIND);
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309773 cds_cfg->self_recovery_enabled = self_recovery;
9774 cds_cfg->fw_timeout_crash = fw_timeout_crash;
Nachiket Kukadee547a482018-05-22 16:43:30 +05309775 cds_cfg->active_uc_apf_mode = hdd_ctx->config->active_uc_apf_mode;
9776 cds_cfg->active_mc_bc_apf_mode = hdd_ctx->config->active_mc_bc_apf_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309777
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309778 cds_cfg->ito_repeat_count = ito_repeat_count;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309779
9780 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
9781 if (QDF_IS_STATUS_ERROR(status))
9782 goto exit;
9783
9784 cds_cfg->bandcapability = band_capability;
Rachit Kankane0106e382018-05-16 18:59:28 +05309785 cds_cfg->num_vdevs = hdd_ctx->config->num_vdevs;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309786
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309787 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
9788 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07009789 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309790 cds_init_ini_config(cds_cfg);
9791 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309792
9793exit:
9794 qdf_mem_free(cds_cfg);
9795 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309796}
9797
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009798/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009799 * hdd_update_user_config() - API to update user configuration
9800 * parameters to obj mgr which are used by multiple components
9801 * @hdd_ctx: HDD Context
9802 *
9803 * Return: 0 for Success, errno on failure
9804 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009805static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009806{
9807 struct wlan_objmgr_psoc_user_config *user_config;
Wu Gaoe5689792018-07-05 19:20:13 +08009808 bool skip_dfs_in_p2p_search = false;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309809 uint8_t band_capability;
9810 QDF_STATUS status;
9811
9812 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
9813 if (QDF_IS_STATUS_ERROR(status))
9814 return -EIO;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009815
9816 user_config = qdf_mem_malloc(sizeof(*user_config));
Min Liu74a1a502018-10-10 19:59:07 +08009817 if (!user_config)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009818 return -ENOMEM;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009819
9820 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
9821 user_config->dual_mac_feature_disable =
9822 hdd_ctx->config->dual_mac_feature_disable;
9823 user_config->indoor_channel_support =
9824 hdd_ctx->config->indoor_channel_support;
9825 user_config->is_11d_support_enabled =
9826 hdd_ctx->config->Is11dSupportEnabled;
9827 user_config->is_11h_support_enabled =
9828 hdd_ctx->config->Is11hSupportEnabled;
Dustin Brown1dbefe62018-09-11 16:32:03 -07009829 cfg_p2p_get_skip_dfs_channel_p2p_search(hdd_ctx->psoc,
Wu Gaoe5689792018-07-05 19:20:13 +08009830 &skip_dfs_in_p2p_search);
9831 user_config->skip_dfs_chnl_in_p2p_search = skip_dfs_in_p2p_search;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309832 user_config->band_capability = band_capability;
Dustin Brown1dbefe62018-09-11 16:32:03 -07009833 wlan_objmgr_psoc_set_user_config(hdd_ctx->psoc, user_config);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009834
9835 qdf_mem_free(user_config);
9836 return 0;
9837}
9838
9839/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009840 * hdd_init_thermal_info - Initialize thermal level
9841 * @hdd_ctx: HDD context
9842 *
9843 * Initialize thermal level at SME layer and set the thermal level callback
9844 * which would be called when a configured thermal threshold is hit.
9845 *
9846 * Return: 0 on success and errno on failure
9847 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009848static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009849{
9850 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309851 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -07009852 mac_handle_t mac_handle;
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309853 struct wlan_fwol_thermal_temp thermal_temp = {0};
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009854
9855 thermal_param.smeThermalMgmtEnabled =
9856 hdd_ctx->config->thermalMitigationEnable;
9857 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
9858
Poddar, Siddarth83905022016-04-16 17:56:08 -07009859 thermal_param.sme_throttle_duty_cycle_tbl[0] =
9860 hdd_ctx->config->throttle_dutycycle_level0;
9861 thermal_param.sme_throttle_duty_cycle_tbl[1] =
9862 hdd_ctx->config->throttle_dutycycle_level1;
9863 thermal_param.sme_throttle_duty_cycle_tbl[2] =
9864 hdd_ctx->config->throttle_dutycycle_level2;
9865 thermal_param.sme_throttle_duty_cycle_tbl[3] =
9866 hdd_ctx->config->throttle_dutycycle_level3;
9867
Dustin Brown05d81302018-09-11 16:49:22 -07009868 status = ucfg_fwol_get_thermal_temp(hdd_ctx->psoc, &thermal_temp);
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309869 if (QDF_IS_STATUS_ERROR(status))
9870 return qdf_status_to_os_return(status);
9871
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009872 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309873 thermal_temp.thermal_temp_min_level0;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009874 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309875 thermal_temp.thermal_temp_max_level0;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009876 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309877 thermal_temp.thermal_temp_min_level1;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009878 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309879 thermal_temp.thermal_temp_max_level1;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009880 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309881 thermal_temp.thermal_temp_min_level2;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009882 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309883 thermal_temp.thermal_temp_max_level2;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009884 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309885 thermal_temp.thermal_temp_min_level3;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009886 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
Dundi Raviteja47ac7092018-09-07 10:40:28 +05309887 thermal_temp.thermal_temp_max_level3;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009888
Jeff Johnson16528362018-06-14 12:34:16 -07009889 mac_handle = hdd_ctx->mac_handle;
9890 status = sme_init_thermal_info(mac_handle, thermal_param);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009891
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309892 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05309893 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009894
Jeff Johnson16528362018-06-14 12:34:16 -07009895 sme_add_set_thermal_level_callback(mac_handle,
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009896 hdd_set_thermal_level_cb);
9897
9898 return 0;
9899
9900}
9901
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009902#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
9903/**
9904 * hdd_hold_rtnl_lock - Hold RTNL lock
9905 *
9906 * Hold RTNL lock
9907 *
9908 * Return: True if held and false otherwise
9909 */
9910static inline bool hdd_hold_rtnl_lock(void)
9911{
9912 rtnl_lock();
9913 return true;
9914}
9915
9916/**
9917 * hdd_release_rtnl_lock - Release RTNL lock
9918 *
9919 * Release RTNL lock
9920 *
9921 * Return: None
9922 */
9923static inline void hdd_release_rtnl_lock(void)
9924{
9925 rtnl_unlock();
9926}
9927#else
9928static inline bool hdd_hold_rtnl_lock(void) { return false; }
9929static inline void hdd_release_rtnl_lock(void) { }
9930#endif
9931
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009932#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009933
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309934/* MAX iwpriv command support */
9935#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309936#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309937#define MAX_PKTLOG_SIZE 16
9938
9939/**
9940 * hdd_pktlog_set_buff_size() - set pktlog buffer size
9941 * @hdd_ctx: hdd context
9942 * @set_value2: pktlog buffer size value
9943 *
9944 *
9945 * Return: 0 for success or error.
9946 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009947static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309948{
9949 struct sir_wifi_start_log start_log = { 0 };
9950 QDF_STATUS status;
9951
9952 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9953 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9954 start_log.ini_triggered = cds_is_packet_log_enabled();
9955 start_log.user_triggered = 1;
9956 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309957 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309958
Jeff Johnson16528362018-06-14 12:34:16 -07009959 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309960 if (!QDF_IS_STATUS_SUCCESS(status)) {
9961 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009962 hdd_exit();
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309963 return -EINVAL;
9964 }
9965
9966 return 0;
9967}
9968
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009969/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309970 * hdd_pktlog_clear_buff() - clear pktlog buffer
9971 * @hdd_ctx: hdd context
9972 *
9973 * Return: 0 for success or error.
9974 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009975static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309976{
9977 struct sir_wifi_start_log start_log;
9978 QDF_STATUS status;
9979
9980 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9981 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9982 start_log.ini_triggered = cds_is_packet_log_enabled();
9983 start_log.user_triggered = 1;
9984 start_log.size = 0;
9985 start_log.is_pktlog_buff_clear = true;
9986
Jeff Johnson16528362018-06-14 12:34:16 -07009987 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309988 if (!QDF_IS_STATUS_SUCCESS(status)) {
9989 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009990 hdd_exit();
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309991 return -EINVAL;
9992 }
9993
9994 return 0;
9995}
9996
9997
9998/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009999 * hdd_process_pktlog_command() - process pktlog command
10000 * @hdd_ctx: hdd context
10001 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010002 * @set_value2: pktlog buffer size value
10003 *
10004 * This function process pktlog command.
10005 * set_value2 only matters when set_value is 3 (set buff size)
10006 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010007 *
10008 * Return: 0 for success or error.
10009 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010010int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010011 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010012{
10013 int ret;
10014 bool enable;
10015 uint8_t user_triggered = 0;
10016
10017 ret = wlan_hdd_validate_context(hdd_ctx);
10018 if (0 != ret)
10019 return ret;
10020
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010021 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010022
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010023 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010024 hdd_err("invalid pktlog value %d", set_value);
10025 return -EINVAL;
10026 }
10027
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010028 if (set_value == PKTLOG_SET_BUFF_SIZE) {
10029 if (set_value2 <= 0) {
10030 hdd_err("invalid pktlog size %d", set_value2);
10031 return -EINVAL;
10032 } else if (set_value2 > MAX_PKTLOG_SIZE) {
10033 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
10034 return -EINVAL;
10035 }
10036 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010037 } else if (set_value == PKTLOG_CLEAR_BUFF) {
10038 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010039 }
10040
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010041 /*
10042 * set_value = 0 then disable packetlog
10043 * set_value = 1 enable packetlog forcefully
10044 * set_vlaue = 2 then disable packetlog if disabled through ini or
10045 * enable packetlog with AUTO type.
10046 */
10047 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
10048 true : false;
10049
10050 if (1 == set_value) {
10051 enable = true;
10052 user_triggered = 1;
10053 }
10054
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010055 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010056}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010057
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010058/**
10059 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
10060 * @hdd_ctx: HDD context
10061 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010062 * @user_triggered: triggered through iwpriv
10063 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010064 *
10065 * Return: 0 on success; error number otherwise
10066 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010067int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010068 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010069{
10070 struct sir_wifi_start_log start_log;
10071 QDF_STATUS status;
10072
10073 start_log.ring_id = RING_ID_PER_PACKET_STATS;
10074 start_log.verbose_level =
10075 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010076 start_log.ini_triggered = cds_is_packet_log_enabled();
10077 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010078 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010079 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +053010080 /*
10081 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
10082 * commands. Host uses this flag to decide whether to send pktlog
10083 * disable command to fw without sending pktlog enable command
10084 * previously. For eg, If vendor sends pktlog disable command without
10085 * sending pktlog enable command, then host discards the packet
10086 * but for iwpriv command, host will send it to fw.
10087 */
10088 start_log.is_iwpriv_command = 1;
Jeff Johnson16528362018-06-14 12:34:16 -070010089 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010090 if (!QDF_IS_STATUS_SUCCESS(status)) {
10091 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -070010092 hdd_exit();
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010093 return -EINVAL;
10094 }
10095
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010096 if (enable == true)
10097 hdd_ctx->is_pktlog_enabled = 1;
10098 else
10099 hdd_ctx->is_pktlog_enabled = 0;
10100
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010101 return 0;
10102}
10103#endif /* REMOVE_PKT_LOG */
10104
Komal Seelam92fff912016-03-24 11:51:41 +053010105/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010106 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
10107 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +053010108 * @dev: Device Pointer
10109 * @num: Number of Valid Mac address
10110 *
10111 * Return: Pointer to MAC address buffer
10112 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010113static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
10114 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +053010115{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010116 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +053010117}
Komal Seelam92fff912016-03-24 11:51:41 +053010118
10119/**
10120 * hdd_populate_random_mac_addr() - API to populate random mac addresses
10121 * @hdd_ctx: HDD Context
10122 * @num: Number of random mac addresses needed
10123 *
10124 * Generate random addresses using bit manipulation on the base mac address
10125 *
10126 * Return: None
10127 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010128void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +053010129{
10130 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
10131 uint32_t iter;
10132 struct hdd_config *ini = hdd_ctx->config;
10133 uint8_t *buf = NULL;
10134 uint8_t macaddr_b3, tmp_br3;
10135 uint8_t *src = ini->intfMacAddr[0].bytes;
10136
10137 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
10138 buf = ini->intfMacAddr[iter].bytes;
10139 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
10140 macaddr_b3 = buf[3];
10141 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
10142 INTF_MACADDR_MASK;
10143 macaddr_b3 += tmp_br3;
10144 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
10145 buf[0] |= 0x02;
10146 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010147 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +053010148 }
10149}
10150
10151/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010152 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +053010153 * @hdd_ctx: HDD Context
10154 *
10155 * API to get mac addresses from platform driver and update the driver
10156 * structures and configure FW with the base mac address.
10157 * Return: int
10158 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010159static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +053010160{
10161 uint32_t no_of_mac_addr, iter;
10162 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
10163 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
10164 uint8_t *addr, *buf;
10165 struct device *dev = hdd_ctx->parent_dev;
10166 struct hdd_config *ini = hdd_ctx->config;
10167 tSirMacAddr mac_addr;
10168 QDF_STATUS status;
10169
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010170 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +053010171
Dustin Brown7e761c72018-07-31 13:50:17 -070010172 if (no_of_mac_addr == 0 || !addr)
Komal Seelam92fff912016-03-24 11:51:41 +053010173 return -EINVAL;
Komal Seelam92fff912016-03-24 11:51:41 +053010174
10175 if (no_of_mac_addr > max_mac_addr)
10176 no_of_mac_addr = max_mac_addr;
10177
10178 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
10179
10180 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
10181 buf = ini->intfMacAddr[iter].bytes;
10182 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010183 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +053010184 }
10185
10186 status = sme_set_custom_mac_addr(mac_addr);
10187
10188 if (!QDF_IS_STATUS_SUCCESS(status))
10189 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010190
Komal Seelam92fff912016-03-24 11:51:41 +053010191 if (no_of_mac_addr < max_mac_addr)
10192 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
10193 no_of_mac_addr);
10194 return 0;
10195}
10196
10197/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010198 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
10199 * @hdd_ctx: HDD Context
10200 *
10201 * Update MAC address to FW. If MAC address passed by FW is invalid, host
10202 * will generate its own MAC and update it to FW.
10203 *
10204 * Return: 0 for success
10205 * Non-zero error code for failure
10206 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010207static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010208{
10209 tSirMacAddr customMacAddr;
10210 QDF_STATUS status;
10211
10212 qdf_mem_copy(&customMacAddr,
10213 &hdd_ctx->config->intfMacAddr[0].bytes[0],
10214 sizeof(tSirMacAddr));
10215 status = sme_set_custom_mac_addr(customMacAddr);
10216 if (!QDF_IS_STATUS_SUCCESS(status))
10217 return -EAGAIN;
10218 return 0;
10219}
10220
10221/**
Komal Seelam92fff912016-03-24 11:51:41 +053010222 * hdd_initialize_mac_address() - API to get wlan mac addresses
10223 * @hdd_ctx: HDD Context
10224 *
10225 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
10226 * is provisioned with mac addresses, driver uses it, else it will use
10227 * wlan_mac.bin to update HW MAC addresses.
10228 *
10229 * Return: None
10230 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010231static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +053010232{
10233 QDF_STATUS status;
10234 int ret;
10235
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010236 ret = hdd_platform_wlan_mac(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010237 if (!ret) {
10238 hdd_info("using MAC address from platform driver");
Komal Seelam92fff912016-03-24 11:51:41 +053010239 return;
Dustin Brown7e761c72018-07-31 13:50:17 -070010240 }
Komal Seelam92fff912016-03-24 11:51:41 +053010241
10242 status = hdd_update_mac_config(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010243 if (QDF_IS_STATUS_SUCCESS(status)) {
10244 hdd_info("using MAC address from wlan_mac.bin");
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010245 return;
Dustin Brown7e761c72018-07-31 13:50:17 -070010246 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010247
Dustin Brown7e761c72018-07-31 13:50:17 -070010248 hdd_info("using default MAC address");
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010249
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -080010250 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010251 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010252 if (ret)
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -080010253 hdd_err("MAC address out-of-sync, ret:%d", ret);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010254 }
Komal Seelam92fff912016-03-24 11:51:41 +053010255}
10256
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010257static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010258{
10259 int vdev_id = 0;
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053010260 QDF_STATUS status;
10261 bool smart_chainmask_enabled;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010262 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010263 int vpdev = PDEV_CMD;
10264 int ret;
10265
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053010266 status = ucfg_get_smart_chainmask_enabled(hdd_ctx->psoc,
10267 &smart_chainmask_enabled);
10268 if (QDF_IS_STATUS_ERROR(status))
10269 return -EINVAL;
10270
10271 ret = sme_cli_set_command(vdev_id, param_id,
10272 (int)smart_chainmask_enabled, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010273 if (ret)
10274 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
10275
10276 return ret;
10277}
10278
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010279static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010280{
10281 int vdev_id = 0;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010282 QDF_STATUS status;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010283 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010284 bool alternative_chainmask_enabled;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010285 int vpdev = PDEV_CMD;
10286 int ret;
10287
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010288 status = ucfg_get_alternative_chainmask_enabled(
10289 hdd_ctx->psoc,
10290 &alternative_chainmask_enabled);
10291 if (QDF_IS_STATUS_ERROR(status))
10292 return -EINVAL;
10293
10294 ret = sme_cli_set_command(vdev_id, param_id,
10295 (int)alternative_chainmask_enabled, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010296 if (ret)
10297 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
10298 ret);
10299
10300 return ret;
10301}
10302
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010303static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -070010304{
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010305 QDF_STATUS status;
Jeff Johnson12a744b2017-04-04 08:19:37 -070010306 int vdev_id = 0;
10307 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010308 bool value;
Jeff Johnson12a744b2017-04-04 08:19:37 -070010309 int vpdev = PDEV_CMD;
10310 int ret;
10311
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010312 status = ucfg_fwol_get_ani_enabled(hdd_ctx->psoc, &value);
10313 if (QDF_IS_STATUS_ERROR(status))
10314 return -EINVAL;
10315
10316 ret = sme_cli_set_command(vdev_id, param_id, (int)value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -070010317 if (ret)
10318 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
10319
10320 return ret;
10321}
10322
Jeff Johnson89c66ff2016-04-22 15:21:37 -070010323/**
Prashanth Bhatta07998752016-04-28 12:35:33 -070010324 * hdd_pre_enable_configure() - Configurations prior to cds_enable
10325 * @hdd_ctx: HDD context
10326 *
10327 * Pre configurations to be done at lower layer before calling cds enable.
10328 *
10329 * Return: 0 on success and errno on failure.
10330 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010331static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -070010332{
10333 int ret;
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010334 uint8_t val = 0;
Prashanth Bhatta07998752016-04-28 12:35:33 -070010335 QDF_STATUS status;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010336 uint32_t arp_ac_category;
Leo Changfdb45c32016-10-28 11:09:23 -070010337 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010338
Leo Changfdb45c32016-10-28 11:09:23 -070010339 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Ajit Pal Singh5d269612018-04-19 16:29:12 +053010340 /* Register HL netdev flow control callback */
10341 cdp_hl_fc_register(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010342
10343 /*
10344 * Note that the cds_pre_enable() sequence triggers the cfg download.
10345 * The cfg download must occur before we update the SME config
10346 * since the SME config operation must access the cfg database
10347 */
10348 status = hdd_set_sme_config(hdd_ctx);
10349
10350 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010351 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010352 ret = qdf_status_to_os_return(status);
10353 goto out;
10354 }
10355
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -070010356 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
10357 if (QDF_STATUS_SUCCESS != status) {
10358 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
10359 ret = qdf_status_to_os_return(status);
10360 goto out;
10361 }
10362
Dustin Brown1dbefe62018-09-11 16:32:03 -070010363 status = ucfg_mlme_get_tx_chainmask_1ss(hdd_ctx->psoc, &val);
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010364 if (QDF_STATUS_SUCCESS != status) {
10365 hdd_err("Get tx_chainmask_1ss from mlme failed");
10366 ret = qdf_status_to_os_return(status);
10367 goto out;
10368 }
10369 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS, val,
Prashanth Bhatta07998752016-04-28 12:35:33 -070010370 PDEV_CMD);
10371 if (0 != ret) {
10372 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
10373 goto out;
10374 }
10375
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010376 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
10377 if (ret)
10378 goto out;
10379
10380 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
10381 if (ret)
10382 goto out;
10383
Jeff Johnson12a744b2017-04-04 08:19:37 -070010384 ret = hdd_set_ani_enabled(hdd_ctx);
10385 if (ret)
10386 goto out;
10387
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010388 status = ucfg_get_arp_ac_category(hdd_ctx->psoc, &arp_ac_category);
10389
10390 if (QDF_IS_STATUS_ERROR(status))
10391 return -EINVAL;
10392
Naveen Rawat247a8682017-06-05 15:00:31 -070010393 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010394 arp_ac_category,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -080010395 PDEV_CMD);
10396 if (0 != ret) {
10397 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010398 arp_ac_category, ret);
Srinivas Girigowda70e169a2017-03-07 23:55:57 -080010399 goto out;
10400 }
10401
Prashanth Bhatta07998752016-04-28 12:35:33 -070010402 status = hdd_set_sme_chan_list(hdd_ctx);
10403 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010404 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010405 ret = qdf_status_to_os_return(status);
10406 goto out;
10407 }
10408
10409 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -070010410 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010411 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -070010412 ret = -EINVAL;
10413 goto out;
10414 }
10415
Prashanth Bhatta07998752016-04-28 12:35:33 -070010416 /*
10417 * Set the MAC Address Currently this is used by HAL to add self sta.
10418 * Remove this once self sta is added as part of session open.
10419 */
Jeff Johnson16528362018-06-14 12:34:16 -070010420 status = sme_cfg_set_str(hdd_ctx->mac_handle, WNI_CFG_STA_ID,
Jeff Johnsonbae59f92018-06-01 17:05:43 -070010421 hdd_ctx->config->intfMacAddr[0].bytes,
10422 sizeof(hdd_ctx->config->intfMacAddr[0]));
Prashanth Bhatta07998752016-04-28 12:35:33 -070010423
Jeff Johnsonbae59f92018-06-01 17:05:43 -070010424 if (QDF_IS_STATUS_ERROR(status)) {
10425 hdd_err("Failed to set MAC Address, status %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010426 ret = -EINVAL;
10427 goto out;
10428 }
10429
10430 hdd_init_channel_avoidance(hdd_ctx);
10431
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +053010432 /* update enable sap mandatory chan list */
Dustin Brown1dbefe62018-09-11 16:32:03 -070010433 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->psoc,
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +053010434 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010435out:
10436 return ret;
10437}
10438
Rachit Kankane026e77a2018-07-31 16:21:09 +053010439#ifdef FEATURE_P2P_LISTEN_OFFLOAD
Prashanth Bhatta07998752016-04-28 12:35:33 -070010440/**
Peng Xu8fdaa492016-06-22 10:20:47 -070010441 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010442 * @context: context registered with sme_register_p2p_lo_event(). HDD
10443 * always registers a hdd context pointer
10444 * @evt:event structure pointer
Peng Xu8fdaa492016-06-22 10:20:47 -070010445 *
10446 * This is the p2p listen offload stop event handler, it sends vendor
10447 * event back to supplicant to notify the stop reason.
10448 *
10449 * Return: None
10450 */
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010451static void wlan_hdd_p2p_lo_event_callback(void *context,
10452 struct sir_p2p_lo_event *evt)
Peng Xu8fdaa492016-06-22 10:20:47 -070010453{
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010454 struct hdd_context *hdd_ctx = context;
Peng Xu8fdaa492016-06-22 10:20:47 -070010455 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -070010456 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -070010457
Dustin Brown491d54b2018-03-14 12:39:11 -070010458 hdd_enter();
Peng Xu8fdaa492016-06-22 10:20:47 -070010459
10460 if (hdd_ctx == NULL) {
10461 hdd_err("Invalid HDD context pointer");
10462 return;
10463 }
10464
Peng Xu5c682812017-08-06 07:39:13 -070010465 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
10466 if (!adapter) {
10467 hdd_err("Cannot find adapter by vdev_id = %d",
10468 evt->vdev_id);
10469 return;
10470 }
10471
Peng Xu8fdaa492016-06-22 10:20:47 -070010472 vendor_event =
10473 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -070010474 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -070010475 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
10476 GFP_KERNEL);
10477
10478 if (!vendor_event) {
10479 hdd_err("cfg80211_vendor_event_alloc failed");
10480 return;
10481 }
10482
10483 if (nla_put_u32(vendor_event,
10484 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
10485 evt->reason_code)) {
10486 hdd_err("nla put failed");
10487 kfree_skb(vendor_event);
10488 return;
10489 }
10490
10491 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -070010492 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
10493 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -070010494}
Rachit Kankane026e77a2018-07-31 16:21:09 +053010495#else
10496static void wlan_hdd_p2p_lo_event_callback(void *context,
10497 struct sir_p2p_lo_event *evt)
10498{
10499}
10500#endif
Peng Xu8fdaa492016-06-22 10:20:47 -070010501
Rachit Kankanef6834c42018-08-02 18:47:50 +053010502#ifdef FEATURE_WLAN_DYNAMIC_CVM
10503static inline int hdd_set_vc_mode_config(struct hdd_context *hdd_ctx)
10504{
10505 return sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap);
10506}
10507#else
10508static inline int hdd_set_vc_mode_config(struct hdd_context *hdd_ctx)
10509{
10510 return QDF_STATUS_SUCCESS;
10511}
10512#endif
10513
Peng Xu8fdaa492016-06-22 10:20:47 -070010514/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010515 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
10516 * @hdd_ctx: HDD context
10517 *
10518 * This function sends the adaptive dwell time config configuration to the
10519 * firmware via WMA
10520 *
10521 * Return: 0 - success, < 0 - failure
10522 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010523static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010524{
10525 QDF_STATUS status;
10526 struct adaptive_dwelltime_params dwelltime_params;
10527
10528 dwelltime_params.is_enabled =
10529 hdd_ctx->config->adaptive_dwell_mode_enabled;
10530 dwelltime_params.dwelltime_mode =
10531 hdd_ctx->config->global_adapt_dwelltime_mode;
10532 dwelltime_params.lpf_weight =
10533 hdd_ctx->config->adapt_dwell_lpf_weight;
10534 dwelltime_params.passive_mon_intval =
10535 hdd_ctx->config->adapt_dwell_passive_mon_intval;
10536 dwelltime_params.wifi_act_threshold =
10537 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
10538
Jeff Johnson16528362018-06-14 12:34:16 -070010539 status = sme_set_adaptive_dwelltime_config(hdd_ctx->mac_handle,
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010540 &dwelltime_params);
10541
10542 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
10543 if (!QDF_IS_STATUS_SUCCESS(status)) {
10544 hdd_err("Failed to send Adaptive Dwelltime configuration!");
10545 return -EAGAIN;
10546 }
10547 return 0;
10548}
10549
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010550int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010551{
10552 QDF_STATUS status;
10553 struct wmi_dbs_scan_sel_params dbs_scan_params;
10554 uint32_t i = 0;
10555 uint8_t count = 0, numentries = 0;
10556 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
10557 * CDS_DBS_SCAN_CLIENTS_MAX];
10558
10559 /* check if DBS is enabled or supported */
Bala Venkateshc8236ca2018-03-09 12:38:29 +053010560 if ((hdd_ctx->config->dual_mac_feature_disable ==
10561 DISABLE_DBS_CXN_AND_SCAN) ||
10562 (hdd_ctx->config->dual_mac_feature_disable ==
10563 ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN))
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010564 return -EINVAL;
10565
10566 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
10567 dbs_scan_config, &numentries,
10568 (CDS_DBS_SCAN_PARAM_PER_CLIENT
10569 * CDS_DBS_SCAN_CLIENTS_MAX));
10570
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010571 if (!numentries) {
Dustin Brown6a8d39b2018-08-14 15:27:26 -070010572 hdd_debug("Do not send scan_selection_config");
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010573 return 0;
10574 }
10575
10576 /* hdd_set_fw_log_params */
10577 dbs_scan_params.num_clients = 0;
10578 while (count < (numentries - 2)) {
10579 dbs_scan_params.module_id[i] = dbs_scan_config[count];
10580 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
10581 dbs_scan_params.num_non_dbs_scans[i] =
10582 dbs_scan_config[count + 2];
10583 dbs_scan_params.num_clients++;
10584 hdd_debug("module:%d NDS:%d NNDS:%d",
10585 dbs_scan_params.module_id[i],
10586 dbs_scan_params.num_dbs_scans[i],
10587 dbs_scan_params.num_non_dbs_scans[i]);
10588 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
10589 i++;
10590 }
10591
10592 dbs_scan_params.pdev_id = 0;
10593
10594 hdd_debug("clients:%d pdev:%d",
10595 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
10596
Jeff Johnson16528362018-06-14 12:34:16 -070010597 status = sme_set_dbs_scan_selection_config(hdd_ctx->mac_handle,
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010598 &dbs_scan_params);
10599 hdd_debug("Sending DBS Scan Selection Configuration to fw");
10600 if (!QDF_IS_STATUS_SUCCESS(status)) {
10601 hdd_err("Failed to send DBS Scan selection configuration!");
10602 return -EAGAIN;
10603 }
10604 return 0;
10605}
10606
Arun Khandavallid4349a92016-07-25 11:10:43 +053010607#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10608/**
10609 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
10610 * @hdd_ctx: HDD context
10611 *
10612 * Set auto shutdown callback to get indications from firmware to indicate
10613 * userspace to shutdown WLAN after a configured amount of inactivity.
10614 *
10615 * Return: 0 on success and errno on failure.
10616 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010617static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010618{
10619 QDF_STATUS status;
10620
Dundi Raviteja8e338282018-09-25 17:16:04 +053010621 if (!hdd_ctx->config->wlan_auto_shutdown)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010622 return 0;
10623
Jeff Johnson16528362018-06-14 12:34:16 -070010624 status = sme_set_auto_shutdown_cb(hdd_ctx->mac_handle,
Arun Khandavallid4349a92016-07-25 11:10:43 +053010625 wlan_hdd_auto_shutdown_cb);
10626 if (status != QDF_STATUS_SUCCESS)
10627 hdd_err("Auto shutdown feature could not be enabled: %d",
10628 status);
10629
10630 return qdf_status_to_os_return(status);
10631}
10632#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010633static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010634{
10635 return 0;
10636}
10637#endif
10638
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010639#ifdef MWS_COEX
10640/**
10641 * hdd_set_mws_coex() - Set MWS coex configurations
10642 * @hdd_ctx: HDD context
10643 *
10644 * This function sends MWS-COEX 4G quick FTDM and
10645 * MWS-COEX 5G-NR power limit to FW
10646 *
10647 * Return: 0 on success and errno on failure.
10648 */
10649static int hdd_init_mws_coex(struct hdd_context *hdd_ctx)
10650{
10651 int ret = 0;
10652
10653 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_MWSCOEX_4G_ALLOW_QUICK_FTDM,
10654 hdd_ctx->config->mws_coex_4g_quick_tdm,
10655 PDEV_CMD);
10656 if (ret) {
10657 hdd_warn("Unable to send MWS-COEX 4G quick FTDM policy");
10658 return ret;
10659 }
10660
10661 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_MWSCOEX_SET_5GNR_PWR_LIMIT,
10662 hdd_ctx->config->mws_coex_5g_nr_pwr_limit,
10663 PDEV_CMD);
10664 if (ret) {
10665 hdd_warn("Unable to send MWS-COEX 4G quick FTDM policy");
10666 return ret;
10667 }
10668 return ret;
10669}
10670#else
10671static int hdd_init_mws_coex(struct hdd_context *hdd_ctx)
10672{
10673 return 0;
10674}
10675#endif
10676
Arun Khandavallid4349a92016-07-25 11:10:43 +053010677/**
10678 * hdd_features_init() - Init features
10679 * @hdd_ctx: HDD context
Arun Khandavallid4349a92016-07-25 11:10:43 +053010680 *
10681 * Initialize features and their feature context after WLAN firmware is up.
10682 *
10683 * Return: 0 on success and errno on failure.
10684 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010685static int hdd_features_init(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010686{
10687 tSirTxPowerLimit hddtxlimit;
10688 QDF_STATUS status;
10689 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070010690 mac_handle_t mac_handle;
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010691 struct hdd_config *cfg;
Wu Gao93816212018-08-31 16:49:54 +080010692 bool b_cts2self;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010693
Dustin Brown491d54b2018-03-14 12:39:11 -070010694 hdd_enter();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010695
Dustin Brownad698ae2018-09-05 17:19:30 -070010696 ret = hdd_update_country_code(hdd_ctx);
10697 if (ret) {
10698 hdd_err("Failed to update country code; errno:%d", ret);
10699 return -EINVAL;
10700 }
10701
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010702 ret = hdd_init_mws_coex(hdd_ctx);
10703 if (ret)
10704 hdd_warn("Error initializing mws-coex");
10705
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010706 cfg = hdd_ctx->config;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010707 /* FW capabilities received, Set the Dot11 mode */
Jeff Johnson16528362018-06-14 12:34:16 -070010708 mac_handle = hdd_ctx->mac_handle;
10709 sme_setdef_dot11mode(mac_handle);
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010710 sme_set_etsi13_srd_ch_in_master_mode(mac_handle,
10711 cfg->
10712 etsi13_srd_chan_in_master_mode);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010713
10714 if (hdd_ctx->config->fIsImpsEnabled)
10715 hdd_set_idle_ps_config(hdd_ctx, true);
10716 else
10717 hdd_set_idle_ps_config(hdd_ctx, false);
10718
Poddar, Siddarth37033032017-10-11 15:47:40 +053010719 /* Send Enable/Disable data stall detection cmd to FW */
10720 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
jitiphil377bcc12018-10-05 19:46:08 +053010721 cdp_cfg_get(cds_get_context(QDF_MODULE_ID_SOC),
10722 cfg_dp_enable_data_stall), PDEV_CMD);
Poddar, Siddarth37033032017-10-11 15:47:40 +053010723
Dustin Brown1dbefe62018-09-11 16:32:03 -070010724 ucfg_mlme_get_go_cts2self_for_sta(hdd_ctx->psoc, &b_cts2self);
Wu Gao93816212018-08-31 16:49:54 +080010725 if (b_cts2self)
Jeff Johnson16528362018-06-14 12:34:16 -070010726 sme_set_cts2self_for_p2p_go(mac_handle);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010727
Rachit Kankanef6834c42018-08-02 18:47:50 +053010728 if (hdd_set_vc_mode_config(hdd_ctx))
Nachiket Kukade8983cf62017-10-12 18:14:48 +053010729 hdd_warn("Error in setting Voltage Corner mode config to FW");
10730
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010731 if (hdd_rx_ol_init(hdd_ctx))
10732 hdd_err("Unable to initialize Rx LRO/GRO in fw");
Arun Khandavallid4349a92016-07-25 11:10:43 +053010733
10734 if (hdd_adaptive_dwelltime_init(hdd_ctx))
10735 hdd_err("Unable to send adaptive dwelltime setting to FW");
10736
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010737 if (hdd_dbs_scan_selection_init(hdd_ctx))
10738 hdd_err("Unable to send DBS scan selection setting to FW");
10739
Arun Khandavallid4349a92016-07-25 11:10:43 +053010740 ret = hdd_init_thermal_info(hdd_ctx);
10741 if (ret) {
10742 hdd_err("Error while initializing thermal information");
Dustin Browne7e71d32018-05-11 16:00:08 -070010743 return ret;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010744 }
10745
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010746 /**
10747 * In case of SSR/PDR, if pktlog was enabled manually before
10748 * SSR/PDR, Then enabled it again automatically after Wlan
10749 * device up.
10750 */
10751 if (cds_is_driver_recovering()) {
10752 if (hdd_ctx->is_pktlog_enabled)
10753 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Alok Kumar5a75b9d2018-08-31 10:55:43 +053010754 } else if (cds_is_packet_log_enabled())
10755 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Poddar, Siddarth66a46592017-02-22 11:44:44 +053010756
gaurank kathpalia3d2e3852018-10-03 22:03:23 +053010757 hddtxlimit.txPower2g = ucfg_get_tx_power(hdd_ctx->psoc, BAND_2G);
10758 hddtxlimit.txPower5g = ucfg_get_tx_power(hdd_ctx->psoc, BAND_5G);
Jeff Johnson16528362018-06-14 12:34:16 -070010759 status = sme_txpower_limit(mac_handle, &hddtxlimit);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010760 if (!QDF_IS_STATUS_SUCCESS(status))
10761 hdd_err("Error setting txlimit in sme: %d", status);
10762
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010763 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010764
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053010765 status = sme_enable_disable_chanavoidind_event(mac_handle, 0);
10766 if (QDF_IS_STATUS_ERROR(status) && (status != QDF_STATUS_E_NOSUPPORT)) {
10767 hdd_err("Failed to disable Chan Avoidance Indication");
Sourav Mohapatra674925f2018-04-16 11:16:58 +053010768 return -EINVAL;
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +053010769 }
Arun Khandavallid4349a92016-07-25 11:10:43 +053010770
10771 /* register P2P Listen Offload event callback */
10772 if (wma_is_p2p_lo_capable())
Jeff Johnson16528362018-06-14 12:34:16 -070010773 sme_register_p2p_lo_event(mac_handle, hdd_ctx,
10774 wlan_hdd_p2p_lo_event_callback);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010775
10776 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
10777
10778 if (ret)
Sourav Mohapatra674925f2018-04-16 11:16:58 +053010779 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010780
Dustin Brown11638b72018-01-25 17:37:25 +053010781 wlan_hdd_init_chan_info(hdd_ctx);
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010782 wlan_hdd_twt_init(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010783
Dustin Browne74003f2018-03-14 12:51:58 -070010784 hdd_exit();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010785 return 0;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010786}
10787
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010788/**
10789 * hdd_features_deinit() - Deinit features
10790 * @hdd_ctx: HDD context
10791 *
10792 * De-Initialize features and their feature context.
10793 *
10794 * Return: none.
10795 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010796static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010797{
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010798 wlan_hdd_twt_deinit(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010799 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010800 wlan_hdd_tsf_deinit(hdd_ctx);
jitiphil4e3bef42018-11-14 14:31:13 +053010801 if (cds_is_packet_log_enabled())
10802 hdd_pktlog_enable_disable(hdd_ctx, false, 0, 0);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010803}
10804
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010805/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010806 * hdd_register_bcn_cb() - register scan beacon callback
10807 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010808 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010809 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010810 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010811static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010812{
10813 QDF_STATUS status;
10814
Dustin Brown1dbefe62018-09-11 16:32:03 -070010815 status = ucfg_scan_register_bcn_cb(hdd_ctx->psoc,
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010816 wlan_cfg80211_inform_bss_frame,
10817 SCAN_CB_TYPE_INFORM_BCN);
10818 if (!QDF_IS_STATUS_SUCCESS(status)) {
10819 hdd_err("failed with status code %08d [x%08x]",
10820 status, status);
10821 return status;
10822 }
10823
10824 return QDF_STATUS_SUCCESS;
10825}
Arun Khandavallid4349a92016-07-25 11:10:43 +053010826
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010827/**
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070010828 * hdd_v2_flow_pool_map() - Flow pool create callback when vdev is active
10829 * @vdev_id: vdev_id, corresponds to flow_pool
10830 *
10831 * Return: none.
10832 */
10833static void hdd_v2_flow_pool_map(int vdev_id)
10834{
10835 QDF_STATUS status;
10836
10837 status = cdp_flow_pool_map(cds_get_context(QDF_MODULE_ID_SOC),
10838 cds_get_context(QDF_MODULE_ID_TXRX),
10839 vdev_id);
10840 /*
10841 * For Adrastea flow control v2 is based on FW MAP events,
10842 * so this above callback is not implemented.
10843 * Hence this is not actual failure. Dont return failure
10844 */
10845 if ((status != QDF_STATUS_SUCCESS) &&
10846 (status != QDF_STATUS_E_INVAL)) {
10847 hdd_err("vdev_id: %d, failed to create flow pool status %d",
10848 vdev_id, status);
10849 }
10850}
10851
10852/**
10853 * hdd_v2_flow_pool_unmap() - Flow pool create callback when vdev is not active
10854 * @vdev_id: vdev_id, corresponds to flow_pool
10855 *
10856 * Return: none.
10857 */
10858static void hdd_v2_flow_pool_unmap(int vdev_id)
10859{
10860 cdp_flow_pool_unmap(cds_get_context(QDF_MODULE_ID_SOC),
10861 cds_get_context(QDF_MODULE_ID_TXRX), vdev_id);
10862}
10863
10864/**
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010865 * hdd_action_oui_config() - Configure action_oui strings
10866 * @hdd_ctx: pointer to hdd context
10867 *
10868 * This is a HDD wrapper function which invokes ucfg api
10869 * of action_oui component to parse action oui strings.
10870 *
10871 * Return: None
10872 */
10873static void hdd_action_oui_config(struct hdd_context *hdd_ctx)
10874{
10875 QDF_STATUS status;
10876 uint32_t id;
10877 uint8_t *str;
10878
10879 if (!hdd_ctx->config->action_oui_enable)
10880 return;
10881
10882 for (id = 0; id < ACTION_OUI_MAXIMUM_ID; id++) {
10883 str = hdd_ctx->config->action_oui_str[id];
10884 if (!qdf_str_len(str))
10885 continue;
10886
Dustin Brown1dbefe62018-09-11 16:32:03 -070010887 status = ucfg_action_oui_parse(hdd_ctx->psoc, str, id);
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010888 if (!QDF_IS_STATUS_SUCCESS(status))
10889 hdd_err("Failed to parse action_oui str: %u", id);
10890 }
10891}
10892
10893/**
10894 * hdd_action_oui_send() - Send action_oui extensions to firmware
10895 * @hdd_ctx: pointer to hdd context
10896 *
10897 * This is a HDD wrapper function which invokes ucfg api
10898 * of action_oui component to send action oui extensions to firmware.
10899 *
10900 * Return: None
10901 */
10902static void hdd_action_oui_send(struct hdd_context *hdd_ctx)
10903{
10904 QDF_STATUS status;
10905
10906 if (!hdd_ctx->config->action_oui_enable)
10907 return;
10908
Dustin Brown1dbefe62018-09-11 16:32:03 -070010909 status = ucfg_action_oui_send(hdd_ctx->psoc);
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010910 if (!QDF_IS_STATUS_SUCCESS(status))
10911 hdd_err("Failed to send one or all action_ouis");
10912}
10913
10914/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010915 * hdd_configure_cds() - Configure cds modules
10916 * @hdd_ctx: HDD context
10917 * @adapter: Primary adapter context
10918 *
10919 * Enable Cds modules after WLAN firmware is up.
10920 *
10921 * Return: 0 on success and errno on failure.
10922 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010923int hdd_configure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010924{
10925 int ret;
10926 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010927 int set_value;
Jeff Johnson16528362018-06-14 12:34:16 -070010928 mac_handle_t mac_handle;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010929 bool enable_rts_sifsbursting;
10930 uint8_t enable_phy_reg_retention;
10931 uint8_t max_mpdus_inampdu;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010932 uint32_t num_abg_tx_chains = 0;
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010933 uint16_t num_11b_tx_chains = 0;
10934 uint16_t num_11ag_tx_chains = 0;
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010935 struct policy_mgr_dp_cbacks dp_cbs = {0};
Bala Venkatesh2fde2c62018-09-11 20:33:24 +053010936 bool value;
Wu Gao66454f12018-09-26 19:55:41 +080010937 enum pmo_auto_pwr_detect_failure_mode auto_power_fail_mode;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053010938 bool bval = false;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010939
Jeff Johnson16528362018-06-14 12:34:16 -070010940 mac_handle = hdd_ctx->mac_handle;
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010941
10942 hdd_action_oui_send(hdd_ctx);
10943
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010944 if (hdd_ctx->config->is_force_1x1)
10945 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
10946 1, PDEV_CMD);
10947 /* set chip power save failure detected callback */
Jeff Johnson16528362018-06-14 12:34:16 -070010948 sme_set_chip_pwr_save_fail_cb(mac_handle,
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010949 hdd_chip_pwr_save_fail_detected_cb);
10950
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010951 status = ucfg_get_max_mpdus_inampdu(hdd_ctx->psoc,
10952 &max_mpdus_inampdu);
10953 if (status)
10954 return status;
10955
10956 if (max_mpdus_inampdu) {
10957 set_value = max_mpdus_inampdu;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010958 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
10959 set_value, PDEV_CMD);
10960 }
10961
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010962 status = ucfg_get_enable_rts_sifsbursting(hdd_ctx->psoc,
10963 &enable_rts_sifsbursting);
10964 if (status)
10965 return status;
10966
10967 if (enable_rts_sifsbursting) {
10968 set_value = enable_rts_sifsbursting;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010969 sme_cli_set_command(0,
10970 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
10971 set_value, PDEV_CMD);
10972 }
10973
Dustin Brown05d81302018-09-11 16:49:22 -070010974 ucfg_mlme_get_sap_get_peer_info(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +053010975 if (value) {
10976 set_value = value;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010977 sme_cli_set_command(0,
10978 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
10979 set_value, PDEV_CMD);
10980 }
10981
Dustin Brown1dbefe62018-09-11 16:32:03 -070010982 status = ucfg_mlme_get_num_11b_tx_chains(hdd_ctx->psoc,
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010983 &num_11b_tx_chains);
10984 if (status != QDF_STATUS_SUCCESS) {
10985 hdd_err("Failed to get num_11b_tx_chains");
10986 goto out;
10987 }
10988
Dustin Brown1dbefe62018-09-11 16:32:03 -070010989 status = ucfg_mlme_get_num_11ag_tx_chains(hdd_ctx->psoc,
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010990 &num_11ag_tx_chains);
10991 if (status != QDF_STATUS_SUCCESS) {
10992 hdd_err("Failed to get num_11ag_tx_chains");
10993 goto out;
10994 }
10995
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053010996 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
10997 if (!QDF_IS_STATUS_SUCCESS(status))
10998 hdd_err("unable to get vht_enable2x2");
10999
11000 if (!bval) {
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011001 if (num_11b_tx_chains > 1)
11002 num_11b_tx_chains = 1;
11003 if (num_11ag_tx_chains > 1)
11004 num_11ag_tx_chains = 1;
11005 }
11006 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
11007 num_11b_tx_chains);
11008 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
11009 num_11ag_tx_chains);
11010 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
11011 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +053011012
Paul Zhang02526cd2018-09-20 17:47:46 +080011013 if (!ucfg_reg_is_regdb_offloaded(hdd_ctx->psoc))
11014 ucfg_reg_program_default_cc(hdd_ctx->pdev,
11015 hdd_ctx->reg.reg_domain);
11016
Arun Khandavallifae92942016-08-01 13:31:08 +053011017 ret = hdd_pre_enable_configure(hdd_ctx);
11018 if (ret) {
11019 hdd_err("Failed to pre-configure cds");
11020 goto out;
11021 }
11022
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080011023 /* Always get latest IPA resources allocated from cds_open and configure
11024 * IPA module before configuring them to FW. Sequence required as crash
11025 * observed otherwise.
11026 */
Dustin Brown07901ec2018-09-07 11:02:41 -070011027 if (ucfg_ipa_uc_ol_init(hdd_ctx->pdev,
11028 cds_get_context(QDF_MODULE_ID_QDF_DEVICE))) {
Manikandan Mohan2e803a02017-02-14 14:57:53 -080011029 hdd_err("Failed to setup pipes");
11030 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080011031 }
11032
Arun Khandavallifae92942016-08-01 13:31:08 +053011033 /*
11034 * Start CDS which starts up the SME/MAC/HAL modules and everything
11035 * else
11036 */
Dustin Brown1dbefe62018-09-11 16:32:03 -070011037 status = cds_enable(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053011038
11039 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011040 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053011041 goto out;
11042 }
11043
11044 status = hdd_post_cds_enable_config(hdd_ctx);
11045 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011046 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011047 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053011048 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +053011049 status = hdd_register_bcn_cb(hdd_ctx);
11050 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +080011051 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +053011052 goto cds_disable;
11053 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011054
Dustin Browne7e71d32018-05-11 16:00:08 -070011055 ret = hdd_features_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053011056 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011057 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053011058
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070011059 if (hdd_ctx->ol_enable)
11060 dp_cbs.hdd_disable_rx_ol_in_concurrency =
11061 hdd_disable_rx_ol_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -070011062 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
jiadbb47e132018-03-30 16:28:30 +080011063 dp_cbs.hdd_ipa_set_mcc_mode_cb = hdd_ipa_set_mcc_mode;
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070011064 dp_cbs.hdd_v2_flow_pool_map = hdd_v2_flow_pool_map;
11065 dp_cbs.hdd_v2_flow_pool_unmap = hdd_v2_flow_pool_unmap;
Dustin Brown1dbefe62018-09-11 16:32:03 -070011066 status = policy_mgr_register_dp_cb(hdd_ctx->psoc, &dp_cbs);
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070011067 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -070011068 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070011069 goto cds_disable;
11070 }
Dustin Brown1dbefe62018-09-11 16:32:03 -070011071 status = policy_mgr_register_mode_change_cb(hdd_ctx->psoc,
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053011072 wlan_hdd_send_mode_change_event);
11073 if (!QDF_IS_STATUS_SUCCESS(status)) {
11074 hdd_debug("Failed to register mode change cb with Policy Manager");
11075 goto cds_disable;
11076 }
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070011077
Jeff Johnson8bb61112018-03-31 13:33:54 -070011078 if (hdd_green_ap_enable_egap(hdd_ctx))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +053011079 hdd_debug("enhance green ap is not enabled");
11080
Nachiket Kukadedd302662017-07-13 17:31:44 +053011081 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
11082 hdd_debug("Failed to set wow pulse");
11083
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053011084 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
11085 hdd_ctx->config->gcmp_enabled, PDEV_CMD);
Wu Gao66454f12018-09-26 19:55:41 +080011086
11087 auto_power_fail_mode =
11088 ucfg_pmo_get_auto_power_fail_mode(hdd_ctx->psoc);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053011089 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
Wu Gao66454f12018-09-26 19:55:41 +080011090 auto_power_fail_mode, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053011091
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011092 status = ucfg_get_enable_phy_reg_retention(hdd_ctx->psoc,
11093 &enable_phy_reg_retention);
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053011094
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011095 if (QDF_IS_STATUS_ERROR(status))
11096 return -EINVAL;
11097
11098 if (enable_phy_reg_retention)
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053011099 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011100 enable_phy_reg_retention, PDEV_CMD);
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053011101
Arun Khandavallifae92942016-08-01 13:31:08 +053011102 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011103
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011104cds_disable:
Dustin Brown1dbefe62018-09-11 16:32:03 -070011105 cds_disable(hdd_ctx->psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011106
Arun Khandavallifae92942016-08-01 13:31:08 +053011107out:
11108 return -EINVAL;
11109}
11110
11111/**
11112 * hdd_deconfigure_cds() -De-Configure cds
11113 * @hdd_ctx: HDD context
11114 *
11115 * Deconfigure Cds modules before WLAN firmware is down.
11116 *
11117 * Return: 0 on success and errno on failure.
11118 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011119static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053011120{
11121 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070011122 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011123
Dustin Brown491d54b2018-03-14 12:39:11 -070011124 hdd_enter();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080011125
11126 /* De-init features */
11127 hdd_features_deinit(hdd_ctx);
11128
Dustin Brown1dbefe62018-09-11 16:32:03 -070011129 qdf_status = policy_mgr_deregister_mode_change_cb(hdd_ctx->psoc);
Srinivas Girigowdad2412882018-09-07 15:42:04 -070011130 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053011131 hdd_debug("Failed to deregister mode change cb with Policy Manager");
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053011132
Dustin Brown1dbefe62018-09-11 16:32:03 -070011133 qdf_status = cds_disable(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053011134 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11135 hdd_err("Failed to Disable the CDS Modules! :%d",
11136 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070011137 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011138 }
11139
Dustin Brown07901ec2018-09-07 11:02:41 -070011140 if (ucfg_ipa_uc_ol_deinit(hdd_ctx->pdev) != QDF_STATUS_SUCCESS) {
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053011141 hdd_err("Failed to disconnect pipes");
11142 ret = -EINVAL;
11143 }
11144
Dustin Browne74003f2018-03-14 12:51:58 -070011145 hdd_exit();
Houston Hoffman6640cf32016-10-10 16:44:29 -070011146 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053011147}
11148
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070011149#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
11150static void hdd_deregister_policy_manager_callback(
11151 struct wlan_objmgr_psoc *psoc)
11152{
11153 if (QDF_STATUS_SUCCESS !=
11154 policy_mgr_deregister_hdd_cb(psoc)) {
11155 hdd_err("HDD callback deregister with policy manager failed");
11156 }
11157}
11158#else
11159static void hdd_deregister_policy_manager_callback(
11160 struct wlan_objmgr_psoc *psoc)
11161{
11162}
11163#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053011164
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011165int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053011166{
11167 void *hif_ctx;
11168 qdf_device_t qdf_ctx;
11169 QDF_STATUS qdf_status;
Dustin Brown4bc0a622017-12-06 15:56:50 -080011170 bool is_recovery_stop = cds_is_driver_recovering();
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053011171 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -070011172 int active_threads;
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053011173 int debugfs_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053011174 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053011175
Dustin Brown491d54b2018-03-14 12:39:11 -070011176 hdd_enter();
Arun Khandavallifae92942016-08-01 13:31:08 +053011177
Dustin Brown1dbefe62018-09-11 16:32:03 -070011178 hdd_deregister_policy_manager_callback(hdd_ctx->psoc);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070011179
Arun Khandavallifae92942016-08-01 13:31:08 +053011180 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11181 if (!qdf_ctx) {
11182 hdd_err("QDF device context NULL");
11183 return -EINVAL;
11184 }
11185
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011186 mutex_lock(&hdd_ctx->iface_change_lock);
11187 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011188 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011189
Dustin Brown70111822017-03-30 15:31:40 -070011190 active_threads = cds_return_external_threads_count();
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053011191 debugfs_threads = hdd_return_debugfs_threads_count();
Dustin Brown70111822017-03-30 15:31:40 -070011192
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053011193 if (active_threads > 0 || debugfs_threads > 0 ||
11194 hdd_ctx->is_wiphy_suspended) {
11195 hdd_warn("External threads %d, Debugfs threads %d, wiphy suspend %d",
11196 active_threads, debugfs_threads,
11197 hdd_ctx->is_wiphy_suspended);
11198
11199 if (active_threads)
11200 cds_print_external_threads();
Dustin Brown70111822017-03-30 15:31:40 -070011201
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053011202 if (IS_IDLE_STOP && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070011203 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4c663222018-10-23 14:19:36 -070011204 hdd_psoc_idle_timer_start(hdd_ctx);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011205 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011206 cds_set_module_stop_in_progress(false);
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011207
Dustin Brown70111822017-03-30 15:31:40 -070011208 return 0;
11209 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070011210 }
11211
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080011212 /* free user wowl patterns */
11213 hdd_free_user_wowl_ptrns();
11214
Arun Khandavallifae92942016-08-01 13:31:08 +053011215 switch (hdd_ctx->driver_status) {
11216 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011217 hdd_debug("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011218 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011219 case DRIVER_MODULES_CLOSED:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011220 hdd_debug("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011221 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011222 case DRIVER_MODULES_ENABLED:
Dustin Brown1a20b082018-08-03 17:27:15 -070011223 hdd_info("Wlan transitioning (CLOSED <- ENABLED)");
11224
11225 if (hdd_get_conparam() == QDF_GLOBAL_FTM_MODE)
11226 break;
Dustin Brown550f6d22017-12-14 15:44:01 -080011227
Komal Seelamf2136bb2016-09-28 18:30:44 +053011228 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053011229 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011230 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053011231 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011232 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011233 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011234 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080011235
Arun Khandavallifae92942016-08-01 13:31:08 +053011236 break;
11237 default:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011238 QDF_DEBUG_PANIC("Unknown driver state:%d",
Arun Khandavallifae92942016-08-01 13:31:08 +053011239 hdd_ctx->driver_status);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011240 ret = -EINVAL;
11241 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011242 }
11243
Arunk Khandavalli890f6d92018-10-30 20:18:28 +053011244 hdd_sysfs_destroy_powerstats_interface();
Amar Singhal18081642018-01-26 16:04:13 -080011245 hdd_sysfs_destroy_version_interface();
Arunk Khandavalli890f6d92018-10-30 20:18:28 +053011246 hdd_sysfs_destroy_driver_root_obj();
Dustin Brown550f6d22017-12-14 15:44:01 -080011247 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080011248
Rajeev Kumarbe021242017-02-16 16:12:23 -080011249 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053011250 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11251 hdd_err("Failed to process post CDS disable Modules! :%d",
11252 qdf_status);
11253 ret = -EINVAL;
11254 QDF_ASSERT(0);
11255 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011256
Sourav Mohapatra674925f2018-04-16 11:16:58 +053011257 /* De-register the SME callbacks */
11258 hdd_deregister_cb(hdd_ctx);
11259
psimhadeea0a12017-12-18 14:50:02 -080011260 hdd_runtime_suspend_context_deinit(hdd_ctx);
11261
Dustin Brown1dbefe62018-09-11 16:32:03 -070011262 qdf_status = cds_dp_close(hdd_ctx->psoc);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011263 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11264 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
11265 ret = -EINVAL;
11266 QDF_ASSERT(0);
11267 }
11268
Dustin Brown1dbefe62018-09-11 16:32:03 -070011269 qdf_status = cds_close(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053011270 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011271 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053011272 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011273 QDF_ASSERT(0);
11274 }
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053011275
11276 qdf_status = wbuff_module_deinit();
11277 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
11278 hdd_err("WBUFF de-init unsuccessful; status: %d", qdf_status);
11279
Sandeep Puligillab7beb472018-08-13 22:54:20 -070011280 hdd_component_pdev_close(hdd_ctx->pdev);
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053011281
Dustin Brown1dbefe62018-09-11 16:32:03 -070011282 hdd_component_psoc_close(hdd_ctx->psoc);
Dustin Brown07901ec2018-09-07 11:02:41 -070011283 dispatcher_pdev_close(hdd_ctx->pdev);
Liangwei Dong50a64a72018-01-11 01:17:00 -050011284 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
11285 if (ret) {
11286 hdd_err("Failed to destroy pdev; errno:%d", ret);
11287 QDF_ASSERT(0);
11288 }
11289
11290 /*
11291 * Reset total mac phy during module stop such that during
11292 * next module start same psoc is used to populate new service
11293 * ready data
11294 */
Dustin Brown1dbefe62018-09-11 16:32:03 -070011295 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->psoc);
Arunk Khandavallia6305a32018-01-25 11:19:18 +053011296 if (tgt_hdl)
11297 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
11298
Liangwei Dong50a64a72018-01-11 01:17:00 -050011299
Arun Khandavallifae92942016-08-01 13:31:08 +053011300 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
11301 if (!hif_ctx) {
11302 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011303 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011304 }
11305
Arunk Khandavalli4b404332017-09-26 12:46:00 +053011306 if (hdd_ctx->target_hw_name) {
11307 qdf_mem_free(hdd_ctx->target_hw_name);
11308 hdd_ctx->target_hw_name = NULL;
11309 }
11310
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053011311 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053011312
11313 ol_cds_free();
11314
Dustin Brownc2a156e2018-10-25 16:56:27 -070011315 if (IS_IDLE_STOP) {
Arun Khandavallifae92942016-08-01 13:31:08 +053011316 ret = pld_power_off(qdf_ctx->dev);
11317 if (ret)
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011318 hdd_err("Failed to power down device; errno:%d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053011319 }
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011320
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011321 /* Free the cache channels of the command SET_DISABLE_CHANNEL_LIST */
11322 wlan_hdd_free_cache_channels(hdd_ctx);
Arunk Khandavalli847969d2017-09-25 15:15:36 +053011323
Dustin Brown29533f22018-07-24 13:11:56 -070011324 hdd_check_for_leaks(hdd_ctx, is_recovery_stop);
Dustin Brown26b3d042017-12-21 11:13:27 -080011325 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080011326
Arunk Khandavalli847969d2017-09-25 15:15:36 +053011327 /* Once the firmware sequence is completed reset this flag */
11328 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053011329 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080011330 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053011331
Kai Liueabb1df2018-11-08 14:58:54 +080011332 pld_request_bus_bandwidth(hdd_ctx->parent_dev, PLD_BUS_WIDTH_NONE);
11333
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011334done:
11335 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011336 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011337 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4bc0a622017-12-06 15:56:50 -080011338
Dustin Browne74003f2018-03-14 12:51:58 -070011339 hdd_exit();
Arun Khandavallifae92942016-08-01 13:31:08 +053011340
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011341 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053011342}
11343
Arun Khandavallifae92942016-08-01 13:31:08 +053011344
Wen Gong3f003382018-05-14 14:26:37 +080011345#ifdef WLAN_FEATURE_MEMDUMP_ENABLE
Arun Khandavallifae92942016-08-01 13:31:08 +053011346/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011347 * hdd_state_info_dump() - prints state information of hdd layer
11348 * @buf: buffer pointer
11349 * @size: size of buffer to be filled
11350 *
11351 * This function is used to dump state information of hdd layer
11352 *
11353 * Return: None
11354 */
11355static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
11356{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011357 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070011358 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070011359 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011360 uint16_t len = 0;
11361 char *buf = *buf_ptr;
11362
11363 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11364 if (!hdd_ctx) {
11365 hdd_err("Failed to get hdd context ");
11366 return;
11367 }
11368
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011369 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011370
11371 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070011372 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011373 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080011374 "\n is_scheduler_suspended %d",
11375 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011376
Dustin Brown920397d2017-12-13 16:27:50 -080011377 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011378 if (adapter->dev)
11379 len += scnprintf(buf + len, *size - len,
11380 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080011381 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011382 "\n device_mode: %d", adapter->device_mode);
11383 switch (adapter->device_mode) {
11384 case QDF_STA_MODE:
11385 case QDF_P2P_CLIENT_MODE:
11386 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11387 len += scnprintf(buf + len, *size - len,
11388 "\n connState: %d",
11389 hdd_sta_ctx->conn_info.connState);
11390 break;
11391
11392 default:
11393 break;
11394 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011395 }
11396
11397 *size -= len;
11398 *buf_ptr += len;
11399}
11400
11401/**
11402 * hdd_register_debug_callback() - registration function for hdd layer
11403 * to print hdd state information
11404 *
11405 * Return: None
11406 */
11407static void hdd_register_debug_callback(void)
11408{
11409 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
11410}
Wen Gong3f003382018-05-14 14:26:37 +080011411#else /* WLAN_FEATURE_MEMDUMP_ENABLE */
Wen Gongaa6d55d2018-04-26 16:33:21 +080011412static void hdd_register_debug_callback(void)
11413{
11414}
Wen Gong3f003382018-05-14 14:26:37 +080011415#endif /* WLAN_FEATURE_MEMDUMP_ENABLE */
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011416
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053011417/*
11418 * wlan_init_bug_report_lock() - Initialize bug report lock
11419 *
11420 * This function is used to create bug report lock
11421 *
11422 * Return: None
11423 */
11424static void wlan_init_bug_report_lock(void)
11425{
Jeff Johnson2b6982c2018-05-29 14:56:11 -070011426 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053011427
11428 p_cds_context = cds_get_global_context();
11429 if (!p_cds_context) {
11430 hdd_err("cds context is NULL");
11431 return;
11432 }
11433
11434 qdf_spinlock_create(&p_cds_context->bug_report_lock);
11435}
11436
Nirav Shahd21a2e32018-04-20 16:34:43 +053011437#ifdef CONFIG_DP_TRACE
Mohit Khannaf8f96822017-05-17 17:11:59 -070011438void hdd_dp_trace_init(struct hdd_config *config)
11439{
Mohit Khannaf8f96822017-05-17 17:11:59 -070011440 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
11441 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
11442 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
11443 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
11444 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
11445 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
11446 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080011447 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070011448
Nirav Shahd21a2e32018-04-20 16:34:43 +053011449 if (!config->enable_dp_trace) {
11450 hdd_err("dp trace is disabled from ini");
11451 return;
11452 }
11453
Mohit Khannaf8f96822017-05-17 17:11:59 -070011454 hdd_string_to_u8_array(config->dp_trace_config, config_params,
11455 &num_entries, sizeof(config_params));
11456
11457 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080011458 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080011459 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080011460 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080011461 else if (bw_compute_interval > 1000) {
11462 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
11463 thresh_time_limit = 1;
11464 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070011465 hdd_err("busBandwidthComputeInterval is 0, using defaults");
11466
11467 switch (num_entries) {
11468 case 4:
11469 proto_bitmap = config_params[3];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011470 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011471 case 3:
11472 verbosity = config_params[2];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011473 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011474 case 2:
11475 thresh = config_params[1];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011476 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011477 case 1:
11478 live_mode = config_params[0];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011479 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011480 default:
Dustin Browna7bb6ae2018-08-16 16:51:50 -070011481 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
11482 live_mode, thresh, thresh_time_limit,
11483 verbosity, proto_bitmap);
Mohit Khannaf8f96822017-05-17 17:11:59 -070011484 };
11485
11486 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
11487 verbosity, proto_bitmap);
11488
11489}
Nirav Shahd21a2e32018-04-20 16:34:43 +053011490#endif
11491
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011492#ifdef DISABLE_CHANNEL_LIST
Dustin Brown623e7e32018-09-05 14:27:50 -070011493static QDF_STATUS wlan_hdd_cache_chann_mutex_create(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011494{
11495 return qdf_mutex_create(&hdd_ctx->cache_channel_lock);
11496}
11497#else
Dustin Brown623e7e32018-09-05 14:27:50 -070011498static QDF_STATUS wlan_hdd_cache_chann_mutex_create(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011499{
Dustin Brown623e7e32018-09-05 14:27:50 -070011500 return QDF_STATUS_SUCCESS;
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011501}
11502#endif
11503
Dustin Brown61cc3932018-10-18 16:12:13 -070011504static QDF_STATUS
11505hdd_open_adapters_for_mission_mode(struct hdd_context *hdd_ctx)
Dustin Browna2deeb72018-10-18 14:19:27 -070011506{
11507 struct hdd_adapter *adapter;
11508 enum dot11p_mode dot11p_mode;
Dustin Brown61cc3932018-10-18 16:12:13 -070011509 QDF_STATUS status;
Dustin Browna2deeb72018-10-18 14:19:27 -070011510
11511 ucfg_mlme_get_dot11p_mode(hdd_ctx->psoc, &dot11p_mode);
11512
11513 /* Create only 802.11p interface? */
11514 if (dot11p_mode == CFG_11P_STANDALONE)
Dustin Brown61cc3932018-10-18 16:12:13 -070011515 return hdd_open_ocb_interface(hdd_ctx);
Dustin Browna2deeb72018-10-18 14:19:27 -070011516
11517 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
11518 wlan_hdd_get_intf_addr(hdd_ctx),
11519 NET_NAME_UNKNOWN, true);
11520 if (!adapter)
Dustin Brown61cc3932018-10-18 16:12:13 -070011521 return QDF_STATUS_E_INVAL;
Dustin Browna2deeb72018-10-18 14:19:27 -070011522
Dustin Brown61cc3932018-10-18 16:12:13 -070011523 /* opening concurrent STA is best effort, continue on error */
11524 hdd_open_concurrent_interface(hdd_ctx);
Dustin Browna2deeb72018-10-18 14:19:27 -070011525
Dustin Brown61cc3932018-10-18 16:12:13 -070011526 status = hdd_open_p2p_interface(hdd_ctx);
11527 if (status)
Dustin Browna2deeb72018-10-18 14:19:27 -070011528 goto err_close_adapters;
11529
11530 /* Open 802.11p Interface */
11531 if (dot11p_mode == CFG_11P_CONCURRENT) {
Dustin Brown61cc3932018-10-18 16:12:13 -070011532 status = hdd_open_ocb_interface(hdd_ctx);
11533 if (QDF_IS_STATUS_ERROR(status))
Dustin Browna2deeb72018-10-18 14:19:27 -070011534 goto err_close_adapters;
11535 }
11536
Dustin Brown61cc3932018-10-18 16:12:13 -070011537 return QDF_STATUS_SUCCESS;
Dustin Browna2deeb72018-10-18 14:19:27 -070011538
11539err_close_adapters:
11540 hdd_close_all_adapters(hdd_ctx, true);
11541
Dustin Brown61cc3932018-10-18 16:12:13 -070011542 return status;
Dustin Browna2deeb72018-10-18 14:19:27 -070011543}
11544
Dustin Brown61cc3932018-10-18 16:12:13 -070011545static QDF_STATUS hdd_open_adapters_for_ftm_mode(struct hdd_context *hdd_ctx)
Dustin Browna2deeb72018-10-18 14:19:27 -070011546{
11547 struct hdd_adapter *adapter;
Dustin Brown61cc3932018-10-18 16:12:13 -070011548
11549 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
11550 wlan_hdd_get_intf_addr(hdd_ctx),
11551 NET_NAME_UNKNOWN, true);
11552
11553 return adapter ? QDF_STATUS_SUCCESS : QDF_STATUS_E_INVAL;
11554}
11555
11556static QDF_STATUS
11557hdd_open_adapters_for_monitor_mode(struct hdd_context *hdd_ctx)
11558{
11559 struct hdd_adapter *adapter;
11560
11561 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
11562 wlan_hdd_get_intf_addr(hdd_ctx),
11563 NET_NAME_UNKNOWN, true);
11564
11565 return adapter ? QDF_STATUS_SUCCESS : QDF_STATUS_E_INVAL;
11566}
11567
11568static QDF_STATUS hdd_open_adapters_for_epping_mode(struct hdd_context *hdd_ctx)
11569{
Dustin Browna2deeb72018-10-18 14:19:27 -070011570 QDF_STATUS status;
Dustin Brown61cc3932018-10-18 16:12:13 -070011571 qdf_device_t qdf_dev;
Dustin Browna2deeb72018-10-18 14:19:27 -070011572
11573 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11574 QDF_BUG(qdf_dev);
11575 if (!qdf_dev)
Dustin Brown61cc3932018-10-18 16:12:13 -070011576 return QDF_STATUS_E_INVAL;
11577
11578 status = epping_open();
11579 if (QDF_IS_STATUS_ERROR(status))
11580 return status;
11581
11582 if (epping_enable(qdf_dev->dev)) {
11583 status = QDF_STATUS_E_INVAL;
11584 goto epping_close;
11585 }
11586
11587 return QDF_STATUS_SUCCESS;
11588
11589epping_close:
11590 epping_close();
11591
11592 return status;
11593}
11594
11595typedef QDF_STATUS (*hdd_open_mode_handler)(struct hdd_context *hdd_ctx);
11596
11597static const hdd_open_mode_handler
11598hdd_open_mode_handlers[QDF_GLOBAL_MAX_MODE] = {
11599 [QDF_GLOBAL_MISSION_MODE] = hdd_open_adapters_for_mission_mode,
11600 [QDF_GLOBAL_FTM_MODE] = hdd_open_adapters_for_ftm_mode,
11601 [QDF_GLOBAL_MONITOR_MODE] = hdd_open_adapters_for_monitor_mode,
11602 [QDF_GLOBAL_EPPING_MODE] = hdd_open_adapters_for_epping_mode,
11603};
11604
Dustin Brown92bd8382018-10-31 15:49:46 -070011605static QDF_STATUS hdd_open_adapters_for_mode(struct hdd_context *hdd_ctx,
11606 enum QDF_GLOBAL_MODE driver_mode)
Dustin Brown61cc3932018-10-18 16:12:13 -070011607{
11608 QDF_STATUS status;
11609
11610 if (driver_mode < 0 ||
11611 driver_mode >= QDF_GLOBAL_MAX_MODE ||
11612 !hdd_open_mode_handlers[driver_mode]) {
11613 hdd_err("Driver mode %d not supported", driver_mode);
11614 return -ENOTSUPP;
11615 }
Dustin Browna2deeb72018-10-18 14:19:27 -070011616
11617 hdd_hold_rtnl_lock();
Dustin Brown61cc3932018-10-18 16:12:13 -070011618 status = hdd_open_mode_handlers[driver_mode](hdd_ctx);
Dustin Browna2deeb72018-10-18 14:19:27 -070011619 hdd_release_rtnl_lock();
11620
Dustin Brown92bd8382018-10-31 15:49:46 -070011621 return status;
Dustin Browna2deeb72018-10-18 14:19:27 -070011622}
11623
Dustin Brown623e7e32018-09-05 14:27:50 -070011624int hdd_wlan_startup(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011625{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011626 QDF_STATUS status;
Dustin Brown623e7e32018-09-05 14:27:50 -070011627 int errno;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011628
Dustin Brown491d54b2018-03-14 12:39:11 -070011629 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011630
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011631 hdd_action_oui_config(hdd_ctx);
11632
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053011633 qdf_nbuf_init_replenish_timer();
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011634
Dustin Brown623e7e32018-09-05 14:27:50 -070011635 status = wlan_hdd_cache_chann_mutex_create(hdd_ctx);
11636 if (QDF_IS_STATUS_ERROR(status))
11637 return qdf_status_to_os_return(status);
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011638
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053011639#ifdef FEATURE_WLAN_CH_AVOID
11640 mutex_init(&hdd_ctx->avoid_freq_lock);
11641#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053011642
Naveen Rawate02f8f52018-04-05 11:58:04 -070011643 osif_request_manager_init();
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053011644 qdf_atomic_init(&hdd_ctx->con_mode_flag);
Dustin Brown021cecd2017-12-11 13:56:43 -080011645 hdd_driver_memdump_init();
Dustin Brown86d196b2018-08-02 11:51:49 -070011646 hdd_bus_bandwidth_init(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -080011647
Dustin Brown623e7e32018-09-05 14:27:50 -070011648 errno = hdd_wlan_start_modules(hdd_ctx, false);
11649 if (errno) {
11650 hdd_err("Failed to start modules; errno:%d", errno);
11651 goto memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011652 }
11653
Yingying Tang80e15f32016-09-27 18:23:01 +080011654 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011655
Dustin Brown623e7e32018-09-05 14:27:50 -070011656 hdd_ctx->mac_handle = cds_get_context(QDF_MODULE_ID_SME);
11657 if (!hdd_ctx->mac_handle) {
Jeff Johnson16528362018-06-14 12:34:16 -070011658 hdd_err("Mac Handle is null");
Dustin Brown623e7e32018-09-05 14:27:50 -070011659 goto stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011660 }
11661
Dustin Brown623e7e32018-09-05 14:27:50 -070011662 errno = hdd_wiphy_init(hdd_ctx);
11663 if (errno) {
11664 hdd_err("Failed to initialize wiphy; errno:%d", errno);
11665 goto stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011666 }
11667
Nirav Shahd21a2e32018-04-20 16:34:43 +053011668 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053011669
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070011670 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080011671
Dustin Brown623e7e32018-09-05 14:27:50 -070011672 errno = register_netdevice_notifier(&hdd_netdev_notifier);
11673 if (errno) {
11674 hdd_err("register_netdevice_notifier failed; errno:%d", errno);
11675 goto unregister_wiphy;
Paul Zhangfb02f452017-12-22 11:58:43 +080011676 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053011677
Dustin Brown623e7e32018-09-05 14:27:50 -070011678 errno = register_reboot_notifier(&system_reboot_notifier);
11679 if (errno) {
11680 hdd_err("Failed to register reboot notifier; errno:%d", errno);
11681 goto unregister_netdev;
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011682 }
11683
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080011684 wlan_hdd_update_11n_mode(hdd_ctx->config);
11685
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011686#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053011687 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053011688 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011689 hdd_skip_acs_scan_timer_handler,
Dustin Browna2deeb72018-10-18 14:19:27 -070011690 hdd_ctx);
Dustin Brown92bd8382018-10-31 15:49:46 -070011691 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070011692 hdd_err("Failed to init ACS Skip timer");
Dustin Brown92bd8382018-10-31 15:49:46 -070011693
Liangwei Dongaef84342016-10-21 05:28:00 -040011694 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011695#endif
11696
Arunk Khandavalli40943af2017-05-15 19:25:34 +053011697 hdd_lpass_notify_wlan_version(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011698
Dustin Brown623e7e32018-09-05 14:27:50 -070011699 errno = hdd_register_notifiers(hdd_ctx);
11700 if (errno)
11701 goto unregister_reboot;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070011702
Paul Zhangfb02f452017-12-22 11:58:43 +080011703 status = wlansap_global_init();
Dustin Brown92bd8382018-10-31 15:49:46 -070011704 if (QDF_IS_STATUS_ERROR(status))
11705 goto unregister_notifiers;
Paul Zhangfb02f452017-12-22 11:58:43 +080011706
Dustin Brown92bd8382018-10-31 15:49:46 -070011707 hdd_set_idle_ps_config(hdd_ctx, hdd_ctx->config->fIsImpsEnabled);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011708
Dustin Brown92bd8382018-10-31 15:49:46 -070011709 hdd_exit();
11710
11711 return 0;
11712
11713unregister_notifiers:
11714 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011715
Dustin Brown623e7e32018-09-05 14:27:50 -070011716unregister_reboot:
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011717 unregister_reboot_notifier(&system_reboot_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011718
Dustin Brown623e7e32018-09-05 14:27:50 -070011719unregister_netdev:
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011720 unregister_netdevice_notifier(&hdd_netdev_notifier);
11721
Dustin Brown623e7e32018-09-05 14:27:50 -070011722unregister_wiphy:
Rachit Kankane30807332018-06-27 18:39:36 +053011723 qdf_dp_trace_deinit();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011724 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011725
Dustin Brown623e7e32018-09-05 14:27:50 -070011726stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011727 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053011728
Dustin Brown623e7e32018-09-05 14:27:50 -070011729memdump_deinit:
Dustin Brown86d196b2018-08-02 11:51:49 -070011730 hdd_bus_bandwidth_deinit(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -080011731 hdd_driver_memdump_deinit();
Naveen Rawate02f8f52018-04-05 11:58:04 -070011732 osif_request_manager_deinit();
Dustin Brown623e7e32018-09-05 14:27:50 -070011733 qdf_nbuf_deinit_replenish_timer();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070011734
Nachiket Kukade8003d252017-03-30 15:55:58 +053011735 if (cds_is_fw_down())
11736 hdd_err("Not setting the complete event as fw is down");
11737 else
Dustin Brown623e7e32018-09-05 14:27:50 -070011738 hdd_start_complete(errno);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011739
Dustin Browne74003f2018-03-14 12:51:58 -070011740 hdd_exit();
Dustin Brown92bd8382018-10-31 15:49:46 -070011741
Dustin Brown623e7e32018-09-05 14:27:50 -070011742 return errno;
Dustin Brown92bd8382018-10-31 15:49:46 -070011743}
11744
11745QDF_STATUS hdd_psoc_create_vdevs(struct hdd_context *hdd_ctx)
11746{
11747 enum QDF_GLOBAL_MODE driver_mode = hdd_get_conparam();
11748 QDF_STATUS status;
11749
11750 status = hdd_open_adapters_for_mode(hdd_ctx, driver_mode);
11751 if (QDF_IS_STATUS_ERROR(status)) {
11752 hdd_err("Failed to create vdevs; status:%d", status);
11753 return status;
11754 }
11755
11756 if (hdd_ctx->rps)
11757 hdd_set_rps_cpu_mask(hdd_ctx);
11758
11759 if (driver_mode != QDF_GLOBAL_FTM_MODE)
11760 hdd_psoc_idle_timer_start(hdd_ctx);
11761
11762 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011763}
11764
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011765/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011766 * hdd_wlan_update_target_info() - update target type info
11767 * @hdd_ctx: HDD context
11768 * @context: hif context
11769 *
11770 * Update target info received from firmware in hdd context
11771 * Return:None
11772 */
11773
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011774void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053011775{
11776 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
11777
11778 if (!tgt_info) {
11779 hdd_err("Target info is Null");
11780 return;
11781 }
11782
11783 hdd_ctx->target_type = tgt_info->target_type;
11784}
11785
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011786void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp, void *context)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011787{
11788 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011789 int status;
11790 struct hdd_adapter *adapter = NULL;
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011791 struct osif_request *request = NULL;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011792
Dustin Brown491d54b2018-03-14 12:39:11 -070011793 hdd_enter();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011794
11795 if (!rsp) {
11796 hdd_err("data is null");
11797 return;
11798 }
11799
11800 status = wlan_hdd_validate_context(hdd_ctx);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011801 if (status != 0)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011802 return;
11803
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011804 request = osif_request_get(context);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011805 if (!request) {
11806 hdd_err("obselete request");
11807 return;
11808 }
11809
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011810 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
11811 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
11812 hdd_err("Invalid adapter or adapter has invalid magic");
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011813 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011814 return;
11815 }
11816
Alok Kumarce2c29a2018-10-12 15:44:02 +053011817 hdd_debug("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
11818 hdd_debug("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
11819 hdd_debug("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
11820 hdd_debug("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
11821 hdd_debug("rsp->out_of_order_arp_rsp_drop_cnt :%x",
11822 rsp->out_of_order_arp_rsp_drop_cnt);
11823 hdd_debug("rsp->dad_detected :%x", rsp->dad_detected);
11824 hdd_debug("rsp->connect_status :%x", rsp->connect_status);
11825 hdd_debug("rsp->ba_session_establishment_status :%x",
11826 rsp->ba_session_establishment_status);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011827
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011828 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011829 adapter->dad |= rsp->dad_detected;
11830 adapter->con_status = rsp->connect_status;
11831
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053011832 /* Flag true indicates connectivity check stats present. */
11833 if (rsp->connect_stats_present) {
Alok Kumarce2c29a2018-10-12 15:44:02 +053011834 hdd_debug("rsp->tcp_ack_recvd :%x", rsp->tcp_ack_recvd);
11835 hdd_debug("rsp->icmpv4_rsp_recvd :%x", rsp->icmpv4_rsp_recvd);
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053011836 adapter->hdd_stats.hdd_tcp_stats.rx_fw_cnt = rsp->tcp_ack_recvd;
11837 adapter->hdd_stats.hdd_icmpv4_stats.rx_fw_cnt =
11838 rsp->icmpv4_rsp_recvd;
11839 }
11840
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011841 osif_request_complete(request);
11842 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011843
Dustin Browne74003f2018-03-14 12:51:58 -070011844 hdd_exit();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011845}
11846
11847/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011848 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011849 * @hdd_ctx: HDD context
11850 *
11851 * Register the HDD callbacks to CDS/SME.
11852 *
11853 * Return: 0 for success or Error code for failure
11854 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011855int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011856{
11857 QDF_STATUS status;
11858 int ret = 0;
Jeff Johnson16528362018-06-14 12:34:16 -070011859 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011860
Dustin Brown491d54b2018-03-14 12:39:11 -070011861 hdd_enter();
Sourav Mohapatra674925f2018-04-16 11:16:58 +053011862 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
11863 hdd_err("in ftm mode, no need to register callbacks");
11864 return ret;
11865 }
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011866
Jeff Johnson16528362018-06-14 12:34:16 -070011867 mac_handle = hdd_ctx->mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011868
Jeff Johnson16528362018-06-14 12:34:16 -070011869 sme_register_oem_data_rsp_callback(mac_handle,
11870 hdd_send_oem_data_rsp_msg);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011871
Jeff Johnson16528362018-06-14 12:34:16 -070011872 sme_register_mgmt_frame_ind_callback(mac_handle,
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053011873 hdd_indicate_mgmt_frame);
Jeff Johnson16528362018-06-14 12:34:16 -070011874 sme_set_tsfcb(mac_handle, hdd_get_tsf_cb, hdd_ctx);
11875 sme_nan_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011876 wlan_hdd_cfg80211_nan_callback);
Jeff Johnson16528362018-06-14 12:34:16 -070011877 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011878 wlan_hdd_cfg80211_stats_ext_callback);
11879
Jeff Johnson16528362018-06-14 12:34:16 -070011880 sme_ext_scan_register_callback(mac_handle,
11881 wlan_hdd_cfg80211_extscan_callback);
11882 sme_stats_ext2_register_callback(mac_handle,
lifeng66831662017-05-19 16:01:35 +080011883 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011884
Jeff Johnson16528362018-06-14 12:34:16 -070011885 sme_set_rssi_threshold_breached_cb(mac_handle,
11886 hdd_rssi_threshold_breached);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011887
Jeff Johnson16528362018-06-14 12:34:16 -070011888 sme_set_link_layer_stats_ind_cb(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011889 wlan_hdd_cfg80211_link_layer_stats_callback);
11890
Jeff Johnson16528362018-06-14 12:34:16 -070011891 sme_rso_cmd_status_cb(mac_handle, wlan_hdd_rso_cmd_status_cb);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053011892
Jeff Johnson16528362018-06-14 12:34:16 -070011893 sme_set_link_layer_ext_cb(mac_handle,
Zhang Qianca38fb12016-12-23 11:10:48 +080011894 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
11895
Jeff Johnson16528362018-06-14 12:34:16 -070011896 status = sme_set_lost_link_info_cb(mac_handle,
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053011897 hdd_lost_link_info_cb);
11898 /* print error and not block the startup process */
11899 if (!QDF_IS_STATUS_SUCCESS(status))
11900 hdd_err("set lost link info callback failed");
11901
Poddar, Siddarth34872782017-08-10 14:08:51 +053011902 ret = hdd_register_data_stall_detect_cb();
11903 if (ret) {
11904 hdd_err("Register data stall detect detect callback failed.");
11905 return ret;
11906 }
11907
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011908 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
11909
Jeff Johnson16528362018-06-14 12:34:16 -070011910 sme_register_set_connection_info_cb(mac_handle,
11911 hdd_set_connection_in_progress,
11912 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053011913
Jeff Johnson16528362018-06-14 12:34:16 -070011914 status = sme_congestion_register_callback(mac_handle,
11915 hdd_update_cca_info_cb);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053011916 if (!QDF_IS_STATUS_SUCCESS(status))
11917 hdd_err("set congestion callback failed");
11918
Jeff Johnson16528362018-06-14 12:34:16 -070011919 status = sme_set_bt_activity_info_cb(mac_handle,
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053011920 hdd_bt_activity_cb);
11921 if (!QDF_IS_STATUS_SUCCESS(status))
11922 hdd_err("set bt activity info callback failed");
11923
Jeff Johnson16528362018-06-14 12:34:16 -070011924 status = sme_register_tx_queue_cb(mac_handle,
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080011925 hdd_tx_queue_cb);
11926 if (!QDF_IS_STATUS_SUCCESS(status))
11927 hdd_err("Register tx queue callback failed");
11928
Dustin Browne74003f2018-03-14 12:51:58 -070011929 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011930
11931 return ret;
11932}
11933
11934/**
11935 * hdd_deregister_cb() - De-Register HDD callbacks.
11936 * @hdd_ctx: HDD context
11937 *
11938 * De-Register the HDD callbacks to CDS/SME.
11939 *
11940 * Return: void
11941 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011942void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011943{
11944 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053011945 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070011946 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011947
Dustin Brown491d54b2018-03-14 12:39:11 -070011948 hdd_enter();
Sourav Mohapatra674925f2018-04-16 11:16:58 +053011949 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
11950 hdd_err("in ftm mode, no need to deregister callbacks");
11951 return;
11952 }
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011953
Jeff Johnson16528362018-06-14 12:34:16 -070011954 mac_handle = hdd_ctx->mac_handle;
11955 sme_deregister_tx_queue_cb(mac_handle);
11956 status = sme_deregister_for_dcc_stats_event(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011957 if (!QDF_IS_STATUS_SUCCESS(status))
11958 hdd_err("De-register of dcc stats callback failed: %d",
11959 status);
11960
Jeff Johnson16528362018-06-14 12:34:16 -070011961 sme_reset_link_layer_stats_ind_cb(mac_handle);
11962 sme_reset_rssi_threshold_breached_cb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011963
Jeff Johnson16528362018-06-14 12:34:16 -070011964 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011965 wlan_hdd_cfg80211_stats_ext_callback);
11966
Jeff Johnson16528362018-06-14 12:34:16 -070011967 sme_nan_deregister_callback(mac_handle);
11968 status = sme_reset_tsfcb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011969 if (!QDF_IS_STATUS_SUCCESS(status))
11970 hdd_err("Failed to de-register tsfcb the callback:%d",
11971 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011972
Poddar, Siddarth34872782017-08-10 14:08:51 +053011973 ret = hdd_deregister_data_stall_detect_cb();
11974 if (ret)
11975 hdd_err("Failed to de-register data stall detect event callback");
11976
Jeff Johnson16528362018-06-14 12:34:16 -070011977 sme_deregister_oem_data_rsp_callback(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011978
Dustin Browne74003f2018-03-14 12:51:58 -070011979 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011980}
11981
11982/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011983 * hdd_softap_sta_deauth() - handle deauth req from HDD
11984 * @adapter: Pointer to the HDD
11985 * @enable: bool value
11986 *
11987 * This to take counter measure to handle deauth req from HDD
11988 *
11989 * Return: None
11990 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011991QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011992 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011993{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011994 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011995
Dustin Brown491d54b2018-03-14 12:39:11 -070011996 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011997
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011998 /* Ignore request to deauth bcmc station */
11999 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012000 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012001
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012002 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012003 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
12004 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012005
Dustin Browne74003f2018-03-14 12:51:58 -070012006 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012007 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012008}
12009
12010/**
12011 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
12012 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053012013 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012014 *
12015 * This to take counter measure to handle deauth req from HDD
12016 *
12017 * Return: None
12018 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012019void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080012020 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012021{
Dustin Brown491d54b2018-03-14 12:39:11 -070012022 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012023
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012024 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053012025 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012026 return;
12027
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012028 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053012029 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012030}
12031
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012032/**
12033 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
12034 * @hdd_ctx: HDD Context
12035 *
12036 * API to find if there is any STA or P2P-Client is connected
12037 *
12038 * Return: true if connected; false otherwise
12039 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012040QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012041{
Jeff Johnson16528362018-06-14 12:34:16 -070012042 return sme_is_sta_p2p_client_connected(hdd_ctx->mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012043}
12044
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012045void wlan_hdd_disable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012046{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012047 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
12048 struct hdd_adapter *adapter = NULL;
12049 struct csr_roam_profile *roam_profile;
12050 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012051
Dustin Brown1dbefe62018-09-11 16:32:03 -070012052 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->psoc)) {
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012053 hdd_debug("No active sta session");
12054 return;
12055 }
12056
12057 hdd_for_each_adapter(hdd_ctx, adapter) {
12058 roam_profile = hdd_roam_profile(adapter);
12059 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12060
12061 if (cur_adapter->session_id != adapter->session_id &&
12062 adapter->device_mode == QDF_STA_MODE &&
12063 hdd_conn_is_connected(sta_ctx)) {
12064 hdd_debug("%d Disable roaming", adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -070012065 sme_stop_roaming(hdd_ctx->mac_handle,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012066 adapter->session_id,
12067 ecsr_driver_disabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012068 }
12069 }
12070}
12071
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012072void wlan_hdd_enable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012073{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012074 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
12075 struct hdd_adapter *adapter = NULL;
12076 struct csr_roam_profile *roam_profile;
12077 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012078
Dustin Brown1dbefe62018-09-11 16:32:03 -070012079 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->psoc)) {
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012080 hdd_debug("No active sta session");
12081 return;
12082 }
12083
12084 hdd_for_each_adapter(hdd_ctx, adapter) {
12085 roam_profile = hdd_roam_profile(adapter);
12086 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12087
12088 if (cur_adapter->session_id != adapter->session_id &&
12089 adapter->device_mode == QDF_STA_MODE &&
12090 hdd_conn_is_connected(sta_ctx)) {
12091 hdd_debug("%d Enable roaming", adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -070012092 sme_start_roaming(hdd_ctx->mac_handle,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012093 adapter->session_id,
12094 REASON_DRIVER_ENABLED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012095 }
12096 }
12097}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012098
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053012099/**
12100 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
12101 * @skb: sk buffer pointer
12102 *
12103 * Sends the bcast message to SVC multicast group with generic nl socket
12104 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
12105 *
12106 * Return: None
12107 */
12108static void nl_srv_bcast_svc(struct sk_buff *skb)
12109{
12110#ifdef CNSS_GENL
12111 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
12112#else
12113 nl_srv_bcast(skb);
12114#endif
12115}
12116
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012117void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012118{
12119 struct sk_buff *skb;
12120 struct nlmsghdr *nlh;
12121 tAniMsgHdr *ani_hdr;
12122 void *nl_data = NULL;
12123 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012124 struct radio_index_tlv *radio_info;
12125 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012126
12127 if (in_interrupt() || irqs_disabled() || in_atomic())
12128 flags = GFP_ATOMIC;
12129
12130 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
12131
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012132 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012133 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012134
12135 nlh = (struct nlmsghdr *)skb->data;
12136 nlh->nlmsg_pid = 0; /* from kernel */
12137 nlh->nlmsg_flags = 0;
12138 nlh->nlmsg_seq = 0;
12139 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
12140
12141 ani_hdr = NLMSG_DATA(nlh);
12142 ani_hdr->type = type;
12143
12144 switch (type) {
12145 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053012146 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012147 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012148 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070012149 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012150 ani_hdr->length = 0;
12151 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012152 break;
12153 case WLAN_SVC_WLAN_STATUS_IND:
12154 case WLAN_SVC_WLAN_VERSION_IND:
12155 case WLAN_SVC_DFS_CAC_START_IND:
12156 case WLAN_SVC_DFS_CAC_END_IND:
12157 case WLAN_SVC_DFS_RADAR_DETECT_IND:
12158 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
12159 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080012160 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053012161 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080012162 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012163 ani_hdr->length = len;
12164 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
12165 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
12166 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012167 break;
12168
12169 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070012170 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012171 type);
12172 kfree_skb(skb);
12173 return;
12174 }
12175
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012176 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080012177 * Add radio index at the end of the svc event in TLV format
12178 * to maintain the backward compatibility with userspace
12179 * applications.
12180 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012181
12182 tlv_len = 0;
12183
12184 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
12185 < WLAN_NL_MAX_PAYLOAD) {
12186 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
12187 sizeof(*ani_hdr) + len);
12188 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
12189 radio_info->length = (unsigned short) sizeof(radio_info->radio);
12190 radio_info->radio = radio;
12191 tlv_len = sizeof(*radio_info);
Dustin Browna2868622018-03-20 11:38:14 -070012192 hdd_debug("Added radio index tlv - radio index %d",
12193 radio_info->radio);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012194 }
12195
12196 nlh->nlmsg_len += tlv_len;
12197 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
12198
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053012199 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012200}
12201
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012202#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
12203void wlan_hdd_auto_shutdown_cb(void)
12204{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012205 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012206
12207 if (!hdd_ctx)
12208 return;
12209
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012210 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012211 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
12212 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012213}
12214
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012215void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012216{
Jeff Johnson9d295242017-08-29 14:39:48 -070012217 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012218 bool ap_connected = false, sta_connected = false;
Jeff Johnson16528362018-06-14 12:34:16 -070012219 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012220
Jeff Johnson16528362018-06-14 12:34:16 -070012221 mac_handle = hdd_ctx->mac_handle;
12222 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012223 return;
12224
Dundi Raviteja8e338282018-09-25 17:16:04 +053012225 if (hdd_ctx->config->wlan_auto_shutdown == 0)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012226 return;
12227
12228 if (enable == false) {
Jeff Johnson16528362018-06-14 12:34:16 -070012229 if (sme_set_auto_shutdown_timer(mac_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012230 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012231 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012232 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012233 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070012234 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012235 return;
12236 }
12237
12238 /* To enable shutdown timer check conncurrency */
Dustin Brown1dbefe62018-09-11 16:32:03 -070012239 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->psoc)) {
Dustin Brown920397d2017-12-13 16:27:50 -080012240 hdd_for_each_adapter(hdd_ctx, adapter) {
12241 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012242 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
12243 conn_info.connState ==
12244 eConnectionState_Associated) {
12245 sta_connected = true;
12246 break;
12247 }
12248 }
Dustin Brown920397d2017-12-13 16:27:50 -080012249
12250 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012251 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070012252 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012253 ap_connected = true;
12254 break;
12255 }
12256 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012257 }
12258 }
12259
12260 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012261 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012262 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012263 }
Jeff Johnson68755312017-02-10 11:46:55 -080012264
Jeff Johnson16528362018-06-14 12:34:16 -070012265 if (sme_set_auto_shutdown_timer(mac_handle,
Dundi Raviteja8e338282018-09-25 17:16:04 +053012266 hdd_ctx->config->wlan_auto_shutdown)
Jeff Johnson68755312017-02-10 11:46:55 -080012267 != QDF_STATUS_SUCCESS)
12268 hdd_err("Failed to start wlan auto shutdown timer");
12269 else
Dustin Brown5e89ef82018-03-14 11:50:23 -070012270 hdd_info("Auto Shutdown timer for %d seconds enabled",
Dundi Raviteja8e338282018-09-25 17:16:04 +053012271 hdd_ctx->config->wlan_auto_shutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012272}
12273#endif
12274
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070012275struct hdd_adapter *
12276hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
12277 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012278{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012279 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070012280 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012281
12282 con_sap_adapter = NULL;
12283
Dustin Brown920397d2017-12-13 16:27:50 -080012284 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012285 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
12286 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012287 adapter != this_sap_adapter) {
12288 if (check_start_bss) {
12289 if (test_bit(SOFTAP_BSS_STARTED,
12290 &adapter->event_flags)) {
12291 con_sap_adapter = adapter;
12292 break;
12293 }
12294 } else {
12295 con_sap_adapter = adapter;
12296 break;
12297 }
12298 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012299 }
12300
12301 return con_sap_adapter;
12302}
12303
12304#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070012305static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012306{
Dustin Brown5ec6b552017-03-31 12:11:40 -070012307 return adapter->device_mode == QDF_STA_MODE ||
12308 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012309}
12310
Jeff Johnson9d295242017-08-29 14:39:48 -070012311static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012312{
Dustin Brown5ec6b552017-03-31 12:11:40 -070012313 return adapter->device_mode == QDF_SAP_MODE ||
12314 adapter->device_mode == QDF_P2P_GO_MODE;
12315}
12316
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012317static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012318{
Dustin Brown920397d2017-12-13 16:27:50 -080012319 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070012320
Dustin Brown920397d2017-12-13 16:27:50 -080012321 hdd_for_each_adapter(hdd_ctx, adapter) {
12322 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070012323 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
12324 conn_info.connState == eConnectionState_Associated) {
12325 return true;
12326 }
12327
Dustin Brown920397d2017-12-13 16:27:50 -080012328 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070012329 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070012330 return true;
12331 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070012332 }
12333
12334 return false;
12335}
12336
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012337static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012338{
12339 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012340
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053012341 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012342 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053012343 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012344
Dustin Brown5ec6b552017-03-31 12:11:40 -070012345 return is_running;
12346}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012347
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012348static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012349{
12350 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
12351 hdd_ctx->bus_bw_timer_running = true;
12352 qdf_timer_start(&hdd_ctx->bus_bw_timer,
jitiphil869b9f72018-09-25 17:14:01 +053012353 hdd_ctx->config->bus_bw_compute_interval);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012354 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
12355}
12356
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012357void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012358{
Dustin Brown491d54b2018-03-14 12:39:11 -070012359 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012360
12361 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12362 hdd_debug("Bandwidth compute timer already started");
12363 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012364 }
12365
Dustin Brown5ec6b552017-03-31 12:11:40 -070012366 __hdd_bus_bw_compute_timer_start(hdd_ctx);
12367
Dustin Browne74003f2018-03-14 12:51:58 -070012368 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012369}
12370
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012371void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012372{
Dustin Brown491d54b2018-03-14 12:39:11 -070012373 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012374
12375 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12376 hdd_debug("Bandwidth compute timer already started");
12377 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070012378 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070012379
12380 if (hdd_any_adapter_is_assoc(hdd_ctx))
12381 __hdd_bus_bw_compute_timer_start(hdd_ctx);
12382
Dustin Browne74003f2018-03-14 12:51:58 -070012383 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012384}
12385
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012386static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012387{
Dustin Brown07901ec2018-09-07 11:02:41 -070012388 ucfg_ipa_set_perf_level(hdd_ctx->pdev, 0, 0);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012389
12390 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012391 hdd_ctx->bus_bw_timer_running = false;
Dustin Brown35008ba2018-08-23 14:34:21 -070012392 qdf_timer_sync_cancel(&hdd_ctx->bus_bw_timer);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012393 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
12394
Dustin Brown35008ba2018-08-23 14:34:21 -070012395 /* work callback is long running; flush outside of lock */
12396 cancel_work_sync(&hdd_ctx->bus_bw_work);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012397 hdd_reset_tcp_delack(hdd_ctx);
12398}
12399
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012400void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012401{
Dustin Brown491d54b2018-03-14 12:39:11 -070012402 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012403
12404 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12405 hdd_debug("Bandwidth compute timer already stopped");
12406 return;
12407 }
12408
12409 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
12410
Dustin Browne74003f2018-03-14 12:51:58 -070012411 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012412}
12413
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012414void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012415{
Dustin Brown491d54b2018-03-14 12:39:11 -070012416 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012417
12418 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12419 hdd_debug("Bandwidth compute timer already stopped");
12420 return;
12421 }
12422
12423 if (!hdd_any_adapter_is_assoc(hdd_ctx))
12424 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
12425
Dustin Browne74003f2018-03-14 12:51:58 -070012426 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012427}
12428#endif
12429
12430/**
12431 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
12432 * and sta's operating channel.
12433 * @sta_adapter: Describe the first argument to foobar.
12434 * @ap_adapter: Describe the second argument to foobar.
12435 * @roam_profile: Roam profile of AP to which STA wants to connect.
12436 * @concurrent_chnl_same: If both SAP and STA channels are same then
12437 * set this flag to true else false.
12438 *
12439 * This function checks the sap's operating channel and sta's operating channel.
12440 * if both are same then it will return false else it will restart the sap in
12441 * sta's channel and return true.
12442 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012443 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012444 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070012445QDF_STATUS
12446wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
12447 struct hdd_adapter *ap_adapter,
Jeff Johnson61b5e982018-03-15 11:33:31 -070012448 struct csr_roam_profile *roam_profile,
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070012449 tScanResultHandle *scan_cache,
12450 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012451{
Jeff Johnson87251032017-08-29 13:31:11 -070012452 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012453 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012454 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012455 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012456 *concurrent_chnl_same = true;
12457
12458 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12459 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070012460 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012461 scan_cache,
12462 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012463 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012464 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012465 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070012466 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012467 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012468 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012469 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012470 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012471 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070012472 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012473 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012474 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012475 }
12476 }
12477 } else {
12478 /*
12479 * Lets handle worst case scenario here, Scan cache lookup is
12480 * failed so we have to stop the SAP to avoid any channel
12481 * discrepancy between SAP's channel and STA's channel.
12482 * Return the status as failure so caller function could know
12483 * that scan look up is failed.
12484 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070012485 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012486 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012487 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012488 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012489}
12490
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012491/**
12492 * wlan_hdd_stop_sap() - This function stops bss of SAP.
12493 * @ap_adapter: SAP adapter
12494 *
12495 * This function will process the stopping of sap adapter.
12496 *
12497 * Return: None
12498 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012499void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012500{
Jeff Johnson87251032017-08-29 13:31:11 -070012501 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012502 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053012503 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012504 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012505
12506 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012507 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012508 return;
12509 }
12510
12511 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12512 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012513 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012514 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012515
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012516 mutex_lock(&hdd_ctx->sap_lock);
12517 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080012518 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012519 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012520 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053012521 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012522 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012523 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053012524 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080012525 qdf_stop_bss_event,
Vignesh Viswanathan865daaa2018-10-11 19:30:44 +053012526 SME_CMD_START_STOP_BSS_TIMEOUT);
Anurag Chouhance0dc992016-02-16 18:18:03 +053012527 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012528 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070012529 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012530 return;
12531 }
12532 }
12533 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -070012534 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012535 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012536 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012537 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012538 false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012539 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012540 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012541 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012542 }
12543 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012544}
12545
12546/**
12547 * wlan_hdd_start_sap() - this function starts bss of SAP.
12548 * @ap_adapter: SAP adapter
12549 *
12550 * This function will process the starting of sap adapter.
12551 *
12552 * Return: None
12553 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012554void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012555{
Jeff Johnson87251032017-08-29 13:31:11 -070012556 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012557 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053012558 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012559 struct hdd_context *hdd_ctx;
Jeff Johnsone4c11db2018-05-05 23:22:32 -070012560 tsap_config_t *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012561
12562 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012563 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012564 return;
12565 }
12566
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012567 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070012568 hdd_err("SoftAp role has not been enabled");
12569 return;
12570 }
12571
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012572 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
12573 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12574 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070012575 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012576
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012577 mutex_lock(&hdd_ctx->sap_lock);
12578 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
12579 goto end;
12580
12581 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012582 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012583 goto end;
12584 }
Dustin Brown07901ec2018-09-07 11:02:41 -070012585 wlan_reg_set_channel_params(hdd_ctx->pdev,
Abhinav Kumar6f694482018-09-04 16:07:39 +053012586 hdd_ap_ctx->sap_config.channel, 0,
12587 &hdd_ap_ctx->sap_config.ch_params);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012588
Wei Song2f76f642016-11-18 16:32:53 +080012589 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012590 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070012591 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012592 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012593 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012594 goto end;
12595
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012596 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053012597 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Vignesh Viswanathan865daaa2018-10-11 19:30:44 +053012598 SME_CMD_START_STOP_BSS_TIMEOUT);
Anurag Chouhance0dc992016-02-16 18:18:03 +053012599 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012600 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012601 goto end;
12602 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070012603 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012604 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012605 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012606 if (hostapd_state->bss_state == BSS_START) {
Dustin Brown1dbefe62018-09-11 16:32:03 -070012607 policy_mgr_incr_active_session(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012608 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012609 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012610 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012611 true);
12612 }
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053012613 mutex_unlock(&hdd_ctx->sap_lock);
12614
12615 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012616end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012617 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012618 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070012619 /* SAP context and beacon cleanup will happen during driver unload
12620 * in hdd_stop_adapter
12621 */
12622 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
12623
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012624}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012625
12626/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012627 * hdd_get_fw_version() - Get FW version
12628 * @hdd_ctx: pointer to HDD context.
12629 * @major_spid: FW version - major spid.
12630 * @minor_spid: FW version - minor spid
12631 * @ssid: FW version - ssid
12632 * @crmid: FW version - crmid
12633 *
12634 * This function is called to get the firmware build version stored
12635 * as part of the HDD context
12636 *
12637 * Return: None
12638 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012639void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012640 uint32_t *major_spid, uint32_t *minor_spid,
12641 uint32_t *siid, uint32_t *crmid)
12642{
12643 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
12644 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
12645 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
12646 *crmid = hdd_ctx->target_fw_version & 0x7fff;
12647}
12648
12649#ifdef QCA_CONFIG_SMP
12650/**
12651 * wlan_hdd_get_cpu() - get cpu_index
12652 *
12653 * Return: cpu_index
12654 */
12655int wlan_hdd_get_cpu(void)
12656{
12657 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012658
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012659 put_cpu();
12660 return cpu_index;
12661}
12662#endif
12663
12664/**
12665 * hdd_get_fwpath() - get framework path
12666 *
12667 * This function is used to get the string written by
12668 * userspace to start the wlan driver
12669 *
12670 * Return: string
12671 */
12672const char *hdd_get_fwpath(void)
12673{
12674 return fwpath.string;
12675}
12676
Dustin Brown94ce20f2018-09-04 13:11:38 -070012677static inline int hdd_state_query_cb(void)
12678{
12679 return !!wlan_hdd_validate_context(cds_get_context(QDF_MODULE_ID_HDD));
12680}
12681
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012682/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012683 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012684 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012685 * This function initilizes CDS global context with the help of cds_init. This
12686 * has to be the first function called after probe to get a valid global
12687 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012688 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012689 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012690 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012691int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012692{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012693 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012694 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012695
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012696 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080012697 if (QDF_IS_STATUS_ERROR(status)) {
12698 hdd_err("Failed to allocate CDS context");
12699 ret = -ENOMEM;
12700 goto err_out;
12701 }
Dustin Brown94ce20f2018-09-04 13:11:38 -070012702 qdf_register_module_state_query_callback(hdd_state_query_cb);
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053012703
12704 wlan_init_bug_report_lock();
12705
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012706#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12707 wlan_logging_sock_init_svc();
12708#endif
12709
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012710 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
12711 (void *)hdd_drv_ops_inactivity_handler, NULL,
12712 QDF_TIMER_TYPE_SW);
12713
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012714 hdd_trace_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053012715 hdd_register_debug_callback();
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012716 wlan_roam_debug_init();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012717
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012718err_out:
12719 return ret;
12720}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012721
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012722/**
12723 * hdd_deinit() - Deinitialize Driver
12724 *
12725 * This function frees CDS global context with the help of cds_deinit. This
12726 * has to be the last function call in remove callback to free the global
12727 * context.
12728 */
12729void hdd_deinit(void)
12730{
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012731 wlan_roam_debug_deinit();
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012732 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012733
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012734#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12735 wlan_logging_sock_deinit_svc();
12736#endif
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012737
12738 wlan_destroy_bug_report_lock();
12739 cds_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012740}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012741
Yue Ma6e7b1a02017-04-03 14:17:46 -070012742#ifdef QCA_WIFI_NAPIER_EMULATION
12743#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
12744#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012745#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070012746#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012747
Sachin Ahujadddd2632017-03-07 19:07:24 +053012748static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
12749 struct file *file)
12750{
12751 return 0;
12752}
12753
12754static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
12755 const char __user *user_buf,
12756 size_t count,
12757 loff_t *f_pos)
12758{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012759 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053012760 static const char wlan_off_str[] = "OFF";
12761 static const char wlan_on_str[] = "ON";
12762 int ret;
12763 unsigned long rc;
12764
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012765 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012766 pr_err("Failed to read buffer\n");
12767 return -EINVAL;
12768 }
12769
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012770 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012771 pr_debug("Wifi turning off from UI\n");
12772 goto exit;
12773 }
12774
Srinivas Girigowdad2412882018-09-07 15:42:04 -070012775 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) == 0)
Sachin Ahuja16904db2017-12-13 19:56:57 +053012776 pr_info("Wifi Turning On from UI\n");
Sachin Ahuja16904db2017-12-13 19:56:57 +053012777
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012778 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012779 pr_err("Invalid value received from framework");
12780 goto exit;
12781 }
12782
12783 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053012784 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053012785 rc = wait_for_completion_timeout(&wlan_start_comp,
12786 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
12787 if (!rc) {
Srinivas Girigowda09625b02018-09-10 15:28:09 -070012788 hdd_alert("Timed-out!!");
Sachin Ahujadddd2632017-03-07 19:07:24 +053012789 ret = -EINVAL;
Sachin Ahujadddd2632017-03-07 19:07:24 +053012790 return ret;
12791 }
12792
12793 hdd_start_complete(0);
12794 }
12795
12796exit:
12797 return count;
12798}
12799
12800
12801const struct file_operations wlan_hdd_state_fops = {
12802 .owner = THIS_MODULE,
12803 .open = wlan_hdd_state_ctrl_param_open,
12804 .write = wlan_hdd_state_ctrl_param_write,
12805};
12806
12807static int wlan_hdd_state_ctrl_param_create(void)
12808{
12809 unsigned int wlan_hdd_state_major = 0;
12810 int ret;
12811 struct device *dev;
12812
12813 device = MKDEV(wlan_hdd_state_major, 0);
12814
12815 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
12816 if (ret) {
12817 pr_err("Failed to register qcwlanstate");
12818 goto dev_alloc_err;
12819 }
12820 wlan_hdd_state_major = MAJOR(device);
12821
12822 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
12823 if (IS_ERR(class)) {
12824 pr_err("wlan_hdd_state class_create error");
12825 goto class_err;
12826 }
12827
12828 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
12829 if (IS_ERR(dev)) {
12830 pr_err("wlan_hdd_statedevice_create error");
12831 goto err_class_destroy;
12832 }
12833
12834 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
12835 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
12836 if (ret) {
12837 pr_err("Failed to add cdev error");
12838 goto cdev_add_err;
12839 }
12840
12841 pr_info("wlan_hdd_state %s major(%d) initialized",
12842 WLAN_MODULE_NAME, wlan_hdd_state_major);
12843
12844 return 0;
12845
12846cdev_add_err:
12847 device_destroy(class, device);
12848err_class_destroy:
12849 class_destroy(class);
12850class_err:
12851 unregister_chrdev_region(device, dev_num);
12852dev_alloc_err:
12853 return -ENODEV;
12854}
12855
12856static void wlan_hdd_state_ctrl_param_destroy(void)
12857{
12858 cdev_del(&wlan_hdd_state_cdev);
12859 device_destroy(class, device);
12860 class_destroy(class);
12861 unregister_chrdev_region(device, dev_num);
12862
12863 pr_info("Device node unregistered");
12864}
12865
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012866/**
Dustin Brownd585cb32018-09-12 17:12:23 -070012867 * hdd_component_init() - Initialize all components
Mukul Sharmad75a6672017-06-22 15:40:53 +053012868 *
Dustin Brownd585cb32018-09-12 17:12:23 -070012869 * Return: QDF_STATUS
Mukul Sharmad75a6672017-06-22 15:40:53 +053012870 */
Dustin Brownd585cb32018-09-12 17:12:23 -070012871static QDF_STATUS hdd_component_init(void)
Mukul Sharmad75a6672017-06-22 15:40:53 +053012872{
Dustin Brownd585cb32018-09-12 17:12:23 -070012873 QDF_STATUS status;
12874
12875 /* initialize converged components */
12876 status = dispatcher_init();
12877 if (QDF_IS_STATUS_ERROR(status))
12878 return status;
12879
12880 /* initialize non-converged components */
12881 status = ucfg_mlme_init();
12882 if (QDF_IS_STATUS_ERROR(status))
12883 goto dispatcher_deinit;
12884
12885 status = ucfg_fwol_init();
12886 if (QDF_IS_STATUS_ERROR(status))
12887 goto mlme_deinit;
12888
12889 status = disa_init();
12890 if (QDF_IS_STATUS_ERROR(status))
12891 goto fwol_deinit;
12892
12893 status = pmo_init();
12894 if (QDF_IS_STATUS_ERROR(status))
12895 goto disa_deinit;
12896
12897 status = ucfg_ocb_init();
12898 if (QDF_IS_STATUS_ERROR(status))
12899 goto pmo_deinit;
12900
12901 status = ipa_init();
12902 if (QDF_IS_STATUS_ERROR(status))
12903 goto ocb_deinit;
12904
12905 status = ucfg_action_oui_init();
12906 if (QDF_IS_STATUS_ERROR(status))
12907 goto ipa_deinit;
12908
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053012909 status = nan_init();
12910 if (QDF_IS_STATUS_ERROR(status))
12911 goto action_oui_deinit;
12912
Dustin Brownd585cb32018-09-12 17:12:23 -070012913 return QDF_STATUS_SUCCESS;
12914
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053012915action_oui_deinit:
12916 ucfg_action_oui_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070012917ipa_deinit:
12918 ipa_deinit();
12919ocb_deinit:
12920 ucfg_ocb_deinit();
12921pmo_deinit:
12922 pmo_deinit();
12923disa_deinit:
12924 disa_deinit();
12925fwol_deinit:
12926 ucfg_fwol_deinit();
12927mlme_deinit:
12928 ucfg_mlme_deinit();
12929dispatcher_deinit:
12930 dispatcher_deinit();
12931
12932 return status;
Mukul Sharmad75a6672017-06-22 15:40:53 +053012933}
12934
12935/**
Dustin Brownd585cb32018-09-12 17:12:23 -070012936 * hdd_component_deinit() - Deinitialize all components
Mukul Sharmad75a6672017-06-22 15:40:53 +053012937 *
12938 * Return: None
12939 */
Dustin Brownd585cb32018-09-12 17:12:23 -070012940static void hdd_component_deinit(void)
Mukul Sharmad75a6672017-06-22 15:40:53 +053012941{
Dustin Brownd585cb32018-09-12 17:12:23 -070012942 /* deinitialize non-converged components */
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053012943 nan_deinit();
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053012944 ucfg_action_oui_deinit();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053012945 ipa_deinit();
Zhang Qian47e22ce2018-01-04 15:38:38 +080012946 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053012947 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012948 disa_deinit();
Sourav Mohapatra113685f2018-08-29 14:21:55 +053012949 ucfg_fwol_deinit();
Vignesh Viswanathana0921c42018-09-04 19:03:35 +053012950 ucfg_mlme_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070012951
12952 /* deinitialize converged components */
12953 dispatcher_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012954}
12955
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053012956QDF_STATUS hdd_component_psoc_open(struct wlan_objmgr_psoc *psoc)
12957{
Sourav Mohapatra113685f2018-08-29 14:21:55 +053012958 QDF_STATUS status;
12959
12960 status = ucfg_mlme_psoc_open(psoc);
12961 if (QDF_IS_STATUS_ERROR(status))
12962 return status;
12963
12964 status = ucfg_fwol_psoc_open(psoc);
12965 if (QDF_IS_STATUS_ERROR(status))
Wu Gao66454f12018-09-26 19:55:41 +080012966 goto err_fwol;
12967
12968 status = ucfg_pmo_psoc_open(psoc);
12969 if (QDF_IS_STATUS_ERROR(status))
12970 goto err_pmo;
Sourav Mohapatra113685f2018-08-29 14:21:55 +053012971
Krunal Sonie9c12f52018-10-04 11:45:42 -070012972 status = ucfg_policy_mgr_psoc_open(psoc);
12973 if (QDF_IS_STATUS_ERROR(status))
12974 goto err_plcy_mgr;
12975
Sourav Mohapatra113685f2018-08-29 14:21:55 +053012976 return status;
12977
Krunal Sonie9c12f52018-10-04 11:45:42 -070012978err_plcy_mgr:
12979 ucfg_pmo_psoc_close(psoc);
Wu Gao66454f12018-09-26 19:55:41 +080012980err_pmo:
12981 ucfg_fwol_psoc_close(psoc);
12982err_fwol:
Sourav Mohapatra113685f2018-08-29 14:21:55 +053012983 ucfg_mlme_psoc_close(psoc);
Krunal Sonie9c12f52018-10-04 11:45:42 -070012984
Sourav Mohapatra113685f2018-08-29 14:21:55 +053012985 return status;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053012986}
12987
12988void hdd_component_psoc_close(struct wlan_objmgr_psoc *psoc)
12989{
Krunal Sonie9c12f52018-10-04 11:45:42 -070012990 ucfg_policy_mgr_psoc_close(psoc);
Wu Gao66454f12018-09-26 19:55:41 +080012991 ucfg_pmo_psoc_close(psoc);
Sourav Mohapatra113685f2018-08-29 14:21:55 +053012992 ucfg_fwol_psoc_close(psoc);
Vignesh Viswanathana0921c42018-09-04 19:03:35 +053012993 ucfg_mlme_psoc_close(psoc);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053012994}
12995
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012996void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
12997{
Zhang Qian47e22ce2018-01-04 15:38:38 +080012998 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012999 disa_psoc_enable(psoc);
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013000 nan_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013001}
13002
13003void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
13004{
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013005 nan_psoc_disable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013006 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080013007 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053013008}
13009
Sandeep Puligillab7beb472018-08-13 22:54:20 -070013010QDF_STATUS hdd_component_pdev_open(struct wlan_objmgr_pdev *pdev)
13011{
13012 return ucfg_mlme_pdev_open(pdev);
13013}
13014
13015void hdd_component_pdev_close(struct wlan_objmgr_pdev *pdev)
13016{
13017 ucfg_mlme_pdev_close(pdev);
13018}
13019
Dustin Brown21a1d462018-07-31 15:13:06 -070013020static struct hdd_driver __hdd_driver;
13021
13022static QDF_STATUS hdd_driver_ctx_init(struct hdd_driver *hdd_driver)
13023{
13024 QDF_BUG(hdd_driver);
13025 if (!hdd_driver)
13026 return QDF_STATUS_E_INVAL;
13027
13028 hdd_driver->state = driver_state_uninit;
13029
13030 return dsc_driver_create(&hdd_driver->dsc_driver);
13031}
13032
13033static void hdd_driver_ctx_deinit(struct hdd_driver *hdd_driver)
13034{
13035 QDF_BUG(hdd_driver);
13036 if (!hdd_driver)
13037 return;
13038
13039 dsc_driver_destroy(&hdd_driver->dsc_driver);
13040 qdf_mem_zero(hdd_driver, sizeof(*hdd_driver));
13041}
13042
13043struct hdd_driver *hdd_driver_get(void)
13044{
13045 return &__hdd_driver;
13046}
13047
Dustin Browna2a39dc2018-09-17 15:29:59 -070013048static QDF_STATUS hdd_qdf_print_init(void)
13049{
13050 QDF_STATUS status;
13051 int qdf_print_idx;
13052
13053 status = qdf_print_setup();
13054 if (QDF_IS_STATUS_ERROR(status)) {
13055 pr_err("Failed qdf_print_setup; status:%u\n", status);
13056 return status;
13057 }
13058
13059 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
13060 if (qdf_print_idx < 0) {
13061 pr_err("Failed to register for qdf_print_ctrl\n");
13062 return QDF_STATUS_E_FAILURE;
13063 }
13064
13065 qdf_set_pidx(qdf_print_idx);
13066
13067 return QDF_STATUS_SUCCESS;
13068}
13069
13070static void hdd_qdf_print_deinit(void)
13071{
13072 int qdf_pidx = qdf_get_pidx();
13073
13074 qdf_set_pidx(-1);
13075 qdf_print_ctrl_cleanup(qdf_pidx);
13076
13077 /* currently, no qdf print 'un-setup'*/
13078}
13079
13080static QDF_STATUS hdd_qdf_init(void)
13081{
13082 QDF_STATUS status;
13083
13084 status = hdd_qdf_print_init();
13085 if (QDF_IS_STATUS_ERROR(status))
13086 goto exit;
13087
13088 status = qdf_debugfs_init();
13089 if (QDF_IS_STATUS_ERROR(status)) {
13090 hdd_err("Failed to init debugfs; status:%u", status);
13091 goto print_deinit;
13092 }
13093
13094 qdf_lock_stats_init();
13095 qdf_mem_init();
13096 qdf_mc_timer_manager_init();
13097 qdf_event_list_init();
13098
13099 status = qdf_cpuhp_init();
13100 if (QDF_IS_STATUS_ERROR(status)) {
13101 hdd_err("Failed to init cpuhp; status:%u", status);
13102 goto event_deinit;
13103 }
13104
13105 status = qdf_trace_spin_lock_init();
13106 if (QDF_IS_STATUS_ERROR(status)) {
13107 hdd_err("Failed to init spinlock; status:%u", status);
13108 goto cpuhp_deinit;
13109 }
13110
13111 qdf_trace_init();
13112 qdf_register_debugcb_init();
13113
13114 return QDF_STATUS_SUCCESS;
13115
13116cpuhp_deinit:
13117 qdf_cpuhp_deinit();
13118event_deinit:
13119 qdf_event_list_destroy();
13120 qdf_mc_timer_manager_exit();
13121 qdf_mem_exit();
13122 qdf_lock_stats_deinit();
13123 qdf_debugfs_exit();
13124print_deinit:
13125 hdd_qdf_print_deinit();
13126
13127exit:
13128 return status;
13129}
13130
13131static void hdd_qdf_deinit(void)
13132{
13133 /* currently, no debugcb deinit */
13134
13135 qdf_trace_deinit();
13136
13137 /* currently, no trace spinlock deinit */
13138
13139 qdf_cpuhp_deinit();
13140 qdf_event_list_destroy();
13141 qdf_mc_timer_manager_exit();
13142 qdf_mem_exit();
13143 qdf_lock_stats_deinit();
13144 qdf_debugfs_exit();
13145 hdd_qdf_print_deinit();
13146}
Dustin Brownf0f70562018-09-14 10:29:38 -070013147
13148/**
13149 * hdd_driver_load() - Perform the driver-level load operation
13150 *
13151 * Note: this is used in both static and DLKM driver builds
13152 *
13153 * Return: Errno
13154 */
13155static int hdd_driver_load(void)
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013156{
Dustin Brown21a1d462018-07-31 15:13:06 -070013157 struct hdd_driver *hdd_driver = hdd_driver_get();
Dustin Brownd585cb32018-09-12 17:12:23 -070013158 QDF_STATUS status;
Dustin Brownf0f70562018-09-14 10:29:38 -070013159 int errno;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013160
Rajeev Kumare555e2d2018-09-17 11:52:37 -070013161 pr_err("%s: Loading driver v%s\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070013162 WLAN_MODULE_NAME,
Rajeev Kumare555e2d2018-09-17 11:52:37 -070013163 g_wlan_driver_version);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013164
Dustin Browna2a39dc2018-09-17 15:29:59 -070013165 status = hdd_qdf_init();
13166 if (QDF_IS_STATUS_ERROR(status)) {
13167 errno = qdf_status_to_os_return(status);
13168 goto exit;
13169 }
13170
Dustin Brown21a1d462018-07-31 15:13:06 -070013171 status = hdd_driver_ctx_init(hdd_driver);
13172 if (QDF_IS_STATUS_ERROR(status)) {
13173 hdd_err("Failed to init driver context; status:%u", status);
13174 errno = qdf_status_to_os_return(status);
13175 goto qdf_deinit;
13176 }
13177
13178 status = dsc_driver_trans_start(hdd_driver->dsc_driver, "load");
13179 QDF_BUG(QDF_IS_STATUS_SUCCESS(status));
13180 if (QDF_IS_STATUS_ERROR(status)) {
13181 errno = qdf_status_to_os_return(status);
13182 goto hdd_driver_deinit;
13183 }
13184
Dustin Brownf0f70562018-09-14 10:29:38 -070013185 errno = hdd_init();
13186 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013187 hdd_err("Failed to init HDD; errno:%d", errno);
Dustin Brown21a1d462018-07-31 15:13:06 -070013188 goto trans_stop;
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013189 }
13190
Dustin Brownd585cb32018-09-12 17:12:23 -070013191 status = hdd_component_init();
13192 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013193 hdd_err("Failed to init components; status:%u", status);
Dustin Brownf0f70562018-09-14 10:29:38 -070013194 errno = qdf_status_to_os_return(status);
Dustin Brownd585cb32018-09-12 17:12:23 -070013195 goto hdd_deinit;
13196 }
Mukul Sharmad75a6672017-06-22 15:40:53 +053013197
Dustin Brownf0f70562018-09-14 10:29:38 -070013198 status = qdf_wake_lock_create(&wlan_wake_lock, "wlan");
13199 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013200 hdd_err("Failed to create wake lock; status:%u", status);
Dustin Brownf0f70562018-09-14 10:29:38 -070013201 errno = qdf_status_to_os_return(status);
13202 goto comp_deinit;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013203 }
13204
Dustin Brownf0f70562018-09-14 10:29:38 -070013205 hdd_set_conparam(con_mode);
13206
Dustin Brownf0f70562018-09-14 10:29:38 -070013207 errno = wlan_hdd_state_ctrl_param_create();
13208 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013209 hdd_err("Failed to create ctrl param; errno:%d", errno);
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013210 goto wakelock_destroy;
13211 }
13212
Dustin Brown25843ad2018-09-17 14:54:33 -070013213 errno = pld_init();
13214 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013215 hdd_err("Failed to init PLD; errno:%d", errno);
Dustin Brown25843ad2018-09-17 14:54:33 -070013216 goto param_destroy;
13217 }
13218
Dustin Brown21a1d462018-07-31 15:13:06 -070013219 hdd_driver->state = driver_state_loaded;
13220 dsc_driver_trans_stop(hdd_driver->dsc_driver);
13221
13222 /* psoc probe can happen in registration; do after 'load' transition */
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013223 errno = wlan_hdd_register_driver();
13224 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013225 hdd_err("Failed to register driver; errno:%d", errno);
Dustin Brown25843ad2018-09-17 14:54:33 -070013226 goto pld_deinit;
Sachin Ahuja16904db2017-12-13 19:56:57 +053013227 }
13228
Dustin Browna2a39dc2018-09-17 15:29:59 -070013229 hdd_debug("%s: driver loaded", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013230
13231 return 0;
Dustin Brownd585cb32018-09-12 17:12:23 -070013232
Dustin Brown25843ad2018-09-17 14:54:33 -070013233pld_deinit:
Dustin Brown21a1d462018-07-31 15:13:06 -070013234 status = dsc_driver_trans_start(hdd_driver->dsc_driver, "unload");
13235 QDF_BUG(QDF_IS_STATUS_SUCCESS(status));
13236
Dustin Brown25843ad2018-09-17 14:54:33 -070013237 pld_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013238
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013239param_destroy:
13240 wlan_hdd_state_ctrl_param_destroy();
Dustin Brownf0f70562018-09-14 10:29:38 -070013241wakelock_destroy:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053013242 qdf_wake_lock_destroy(&wlan_wake_lock);
Dustin Brownf0f70562018-09-14 10:29:38 -070013243comp_deinit:
Dustin Brownd585cb32018-09-12 17:12:23 -070013244 hdd_component_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013245hdd_deinit:
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013246 hdd_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013247trans_stop:
13248 hdd_driver->state = driver_state_deinit;
13249 dsc_driver_trans_stop(hdd_driver->dsc_driver);
13250hdd_driver_deinit:
13251 hdd_driver_ctx_deinit(hdd_driver);
Dustin Browna2a39dc2018-09-17 15:29:59 -070013252qdf_deinit:
13253 hdd_qdf_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013254
Dustin Brown25843ad2018-09-17 14:54:33 -070013255exit:
Dustin Brownf0f70562018-09-14 10:29:38 -070013256 return errno;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013257}
13258
13259/**
Dustin Brownf0f70562018-09-14 10:29:38 -070013260 * hdd_driver_unload() - Performs the driver-level unload operation
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013261 *
Dustin Brownf0f70562018-09-14 10:29:38 -070013262 * Note: this is used in both static and DLKM driver builds
13263 *
13264 * Return: None
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013265 */
Dustin Brownf0f70562018-09-14 10:29:38 -070013266static void hdd_driver_unload(void)
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013267{
Dustin Brown21a1d462018-07-31 15:13:06 -070013268 struct hdd_driver *hdd_driver = hdd_driver_get();
Will Huang36049722018-04-13 11:48:51 +080013269 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Dustin Brown21a1d462018-07-31 15:13:06 -070013270 QDF_STATUS status;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053013271
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013272 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
13273 QWLAN_VERSIONSTR);
13274
Dustin Brown21a1d462018-07-31 15:13:06 -070013275 status = dsc_driver_trans_start_wait(hdd_driver->dsc_driver, "unload");
13276 QDF_BUG(QDF_IS_STATUS_SUCCESS(status));
13277 if (QDF_IS_STATUS_ERROR(status)) {
13278 hdd_err("Unable to unload wlan; status:%u", status);
Arunk Khandavalli830c9692018-03-22 12:17:40 +053013279 return;
Dustin Brown21a1d462018-07-31 15:13:06 -070013280 }
13281
13282 dsc_driver_wait_for_ops(hdd_driver->dsc_driver);
13283
13284 if (!hdd_wait_for_recovery_completion()) {
13285 dsc_driver_trans_stop(hdd_driver->dsc_driver);
13286 return;
13287 }
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053013288
Will Huangba035ec2018-07-05 11:13:30 +080013289 cds_set_driver_loaded(false);
13290 cds_set_unload_in_progress(true);
13291
13292 if (!cds_wait_for_external_threads_completion(__func__))
13293 hdd_warn("External threads are still active attempting "
13294 "driver unload anyway");
13295
Rajeev Kumar3505ae52018-05-10 18:44:45 -070013296 if (hdd_ctx)
Dustin Brown4c663222018-10-23 14:19:36 -070013297 hdd_psoc_idle_timer_stop(hdd_ctx);
Will Huang36049722018-04-13 11:48:51 +080013298
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013299 wlan_hdd_unregister_driver();
Dustin Brown25843ad2018-09-17 14:54:33 -070013300 pld_deinit();
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013301 wlan_hdd_state_ctrl_param_destroy();
Dustin Brownf0f70562018-09-14 10:29:38 -070013302 hdd_set_conparam(0);
Anurag Chouhana37b5b72016-02-21 14:53:42 +053013303 qdf_wake_lock_destroy(&wlan_wake_lock);
Dustin Brownd585cb32018-09-12 17:12:23 -070013304 hdd_component_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013305 hdd_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013306
13307 hdd_driver->state = driver_state_deinit;
13308 dsc_driver_trans_stop(hdd_driver->dsc_driver);
Dustin Brown623e7e32018-09-05 14:27:50 -070013309
Dustin Brown21a1d462018-07-31 15:13:06 -070013310 hdd_driver_ctx_deinit(hdd_driver);
13311
Dustin Browna2a39dc2018-09-17 15:29:59 -070013312 hdd_qdf_deinit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013313}
13314
Arun Khandavallifae92942016-08-01 13:31:08 +053013315#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013316/**
Arun Khandavallifae92942016-08-01 13:31:08 +053013317 * wlan_boot_cb() - Wlan boot callback
13318 * @kobj: object whose directory we're creating the link in.
13319 * @attr: attribute the user is interacting with
13320 * @buff: the buffer containing the user data
13321 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013322 *
Arun Khandavallifae92942016-08-01 13:31:08 +053013323 * This callback is invoked when the fs is ready to start the
13324 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013325 *
Arun Khandavallifae92942016-08-01 13:31:08 +053013326 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013327 */
Arun Khandavallifae92942016-08-01 13:31:08 +053013328static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013329 struct kobj_attribute *attr,
13330 const char *buf,
13331 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013332{
Arun Khandavallifae92942016-08-01 13:31:08 +053013333
Arun Khandavallifae92942016-08-01 13:31:08 +053013334 if (wlan_loader->loaded_state) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013335 hdd_err("wlan driver already initialized");
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013336 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053013337 }
13338
Dustin Brownf0f70562018-09-14 10:29:38 -070013339 if (hdd_driver_load())
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013340 return -EIO;
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013341
13342 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053013343
13344 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013345}
Arun Khandavallifae92942016-08-01 13:31:08 +053013346
13347/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013348 * hdd_sysfs_cleanup() - cleanup sysfs
13349 *
13350 * Return: None
13351 *
13352 */
13353static void hdd_sysfs_cleanup(void)
13354{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013355 /* remove from group */
13356 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
13357 sysfs_remove_group(wlan_loader->boot_wlan_obj,
13358 wlan_loader->attr_group);
13359
13360 /* unlink the object from parent */
13361 kobject_del(wlan_loader->boot_wlan_obj);
13362
13363 /* free the object */
13364 kobject_put(wlan_loader->boot_wlan_obj);
13365
13366 kfree(wlan_loader->attr_group);
13367 kfree(wlan_loader);
13368
13369 wlan_loader = NULL;
13370}
13371
13372/**
Arun Khandavallifae92942016-08-01 13:31:08 +053013373 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
13374 * ready
13375 *
13376 * This is creates the syfs entry boot_wlan. Which shall be invoked
13377 * when the filesystem is ready.
13378 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013379 * QDF API cannot be used here since this function is called even before
13380 * initializing WLAN driver.
13381 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070013382 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053013383 */
13384static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013385{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013386 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053013387
13388 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013389 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013390 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053013391
13392 wlan_loader->boot_wlan_obj = NULL;
13393 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
13394 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013395 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053013396 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053013397
13398 wlan_loader->loaded_state = 0;
13399 wlan_loader->attr_group->attrs = attrs;
13400
Qun Zhang4a83a462018-09-11 16:28:51 +080013401 wlan_loader->boot_wlan_obj = kobject_create_and_add(WLAN_LOADER_NAME,
Arun Khandavallifae92942016-08-01 13:31:08 +053013402 kernel_kobj);
13403 if (!wlan_loader->boot_wlan_obj) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013404 hdd_err("sysfs create and add failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053013405 goto error_return;
13406 }
13407
13408 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
13409 wlan_loader->attr_group);
13410 if (ret) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013411 hdd_err("sysfs create group failed; errno:%d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053013412 goto error_return;
13413 }
13414
13415 return 0;
13416
13417error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013418 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053013419
13420 return ret;
13421}
13422
13423/**
13424 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
13425 *
13426 * Return: 0 on success or errno on failure
13427 */
13428static int wlan_deinit_sysfs(void)
13429{
Arun Khandavallifae92942016-08-01 13:31:08 +053013430 if (!wlan_loader) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013431 hdd_err("wlan_loader is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053013432 return -EINVAL;
13433 }
13434
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013435 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013436 return 0;
13437}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013438
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013439#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053013440
13441#ifdef MODULE
13442/**
Dustin Brownf0f70562018-09-14 10:29:38 -070013443 * hdd_module_init() - Module init helper
Arun Khandavallifae92942016-08-01 13:31:08 +053013444 *
13445 * Module init helper function used by both module and static driver.
13446 *
13447 * Return: 0 for success, errno on failure
13448 */
13449static int hdd_module_init(void)
13450{
Dustin Brownf0f70562018-09-14 10:29:38 -070013451 if (hdd_driver_load())
Dustin Brownab482ac2017-06-09 17:00:44 -070013452 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053013453
Dustin Brownab482ac2017-06-09 17:00:44 -070013454 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053013455}
13456#else
13457static int __init hdd_module_init(void)
13458{
13459 int ret = -EINVAL;
13460
13461 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070013462 if (ret)
Dustin Browna2a39dc2018-09-17 15:29:59 -070013463 hdd_err("Failed to create sysfs entry");
Arun Khandavallifae92942016-08-01 13:31:08 +053013464
13465 return ret;
13466}
13467#endif
13468
13469
13470#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013471/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013472 * hdd_module_exit() - Exit function
13473 *
13474 * This is the driver exit point (invoked when module is unloaded using rmmod)
13475 *
13476 * Return: None
13477 */
13478static void __exit hdd_module_exit(void)
13479{
Dustin Brownf0f70562018-09-14 10:29:38 -070013480 hdd_driver_unload();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013481}
Arun Khandavallifae92942016-08-01 13:31:08 +053013482#else
13483static void __exit hdd_module_exit(void)
13484{
Dustin Brownf0f70562018-09-14 10:29:38 -070013485 hdd_driver_unload();
Arun Khandavallifae92942016-08-01 13:31:08 +053013486 wlan_deinit_sysfs();
13487}
13488#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013489
Srinivas Girigowda841da292018-02-21 16:33:00 -080013490static int fwpath_changed_handler(const char *kmessage,
13491 const struct kernel_param *kp)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013492{
13493 return param_set_copystring(kmessage, kp);
13494}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013495
Nirav Shah73713f72018-05-17 14:50:41 +053013496#ifdef FEATURE_MONITOR_MODE_SUPPORT
13497static bool is_monitor_mode_supported(void)
13498{
13499 return true;
13500}
13501#else
13502static bool is_monitor_mode_supported(void)
13503{
13504 pr_err("Monitor mode not supported!");
13505 return false;
13506}
13507#endif
13508
13509#ifdef WLAN_FEATURE_EPPING
13510static bool is_epping_mode_supported(void)
13511{
13512 return true;
13513}
13514#else
13515static bool is_epping_mode_supported(void)
13516{
13517 pr_err("Epping mode not supported!");
13518 return false;
13519}
13520#endif
13521
Ryan Hsu6e9db0b2018-06-01 10:45:51 -070013522#ifdef QCA_WIFI_FTM
13523static bool is_ftm_mode_supported(void)
13524{
13525 return true;
13526}
13527#else
13528static bool is_ftm_mode_supported(void)
13529{
13530 pr_err("FTM mode not supported!");
13531 return false;
13532}
13533#endif
13534
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013535/**
13536 * is_con_mode_valid() check con mode is valid or not
13537 * @mode: global con mode
13538 *
13539 * Return: TRUE on success FALSE on failure
13540 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080013541static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013542{
13543 switch (mode) {
13544 case QDF_GLOBAL_MONITOR_MODE:
Nirav Shah73713f72018-05-17 14:50:41 +053013545 return is_monitor_mode_supported();
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013546 case QDF_GLOBAL_EPPING_MODE:
Nirav Shah73713f72018-05-17 14:50:41 +053013547 return is_epping_mode_supported();
13548 case QDF_GLOBAL_FTM_MODE:
Ryan Hsu6e9db0b2018-06-01 10:45:51 -070013549 return is_ftm_mode_supported();
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013550 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013551 return true;
13552 default:
13553 return false;
13554 }
13555}
13556
Dustin Brown27cd9942017-09-27 16:11:44 -070013557static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080013558 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070013559{
13560 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
13561 return;
13562
13563 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070013564 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053013565 hdd_info("Release wakelock for monitor mode!");
13566 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
13567 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
Dundi Raviteja0a2a65b2018-04-30 12:34:11 +053013568 /* fallthrough */
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053013569 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070013570 case QDF_GLOBAL_FTM_MODE:
13571 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brown07901ec2018-09-07 11:02:41 -070013572 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, NULL);
Dustin Browndb2a8be2017-12-20 11:49:56 -080013573 hdd_stop_all_adapters(hdd_ctx);
Ashish Kumar Dhanotiya6ff329e2018-10-05 20:38:10 +053013574 hdd_deinit_all_adapters(hdd_ctx, false);
Dustin Brown27cd9942017-09-27 16:11:44 -070013575
Dustin Brown27cd9942017-09-27 16:11:44 -070013576 break;
13577 default:
13578 break;
13579 }
13580}
13581
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013582static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080013583 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013584{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053013585 int driver_status;
13586
13587 driver_status = hdd_ctx->driver_status;
13588
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013589 switch (curr_mode) {
13590 case QDF_GLOBAL_MISSION_MODE:
13591 case QDF_GLOBAL_MONITOR_MODE:
13592 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013593 hdd_close_all_adapters(hdd_ctx, false);
13594 break;
13595 case QDF_GLOBAL_EPPING_MODE:
13596 epping_disable();
13597 epping_close();
13598 break;
13599 default:
13600 return;
13601 }
13602}
13603
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013604static int
13605hdd_parse_driver_mode(const char *mode_str, enum QDF_GLOBAL_MODE *out_mode)
13606{
13607 int mode;
13608 int errno;
13609
Dustin Brown62743f42018-10-24 14:53:18 -070013610 *out_mode = QDF_GLOBAL_MAX_MODE;
13611
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013612 errno = kstrtoint(mode_str, 0, &mode);
13613 if (!errno)
13614 *out_mode = (enum QDF_GLOBAL_MODE)mode;
13615
13616 return errno;
13617}
13618
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013619/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013620 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013621 * @kmessage: con mode name on which driver to be bring up
13622 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013623 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013624 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013625 * This function is invoked when user updates con mode using sys entry,
13626 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013627 *
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013628 * Return: Errno
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013629 */
Srinivas Girigowda841da292018-02-21 16:33:00 -080013630static int __con_mode_handler(const char *kmessage,
13631 const struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013632 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013633{
Jeff Johnson876c1a62017-12-12 10:43:07 -080013634 enum QDF_GLOBAL_MODE curr_mode;
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013635 enum QDF_GLOBAL_MODE next_mode;
13636 int errno;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013637
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013638 hdd_info("Driver mode changing to %s", kmessage);
Dustin Brownab6029b2017-05-24 13:04:19 -070013639
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013640 errno = wlan_hdd_validate_context(hdd_ctx);
13641 if (errno)
13642 return errno;
13643
13644 errno = hdd_parse_driver_mode(kmessage, &next_mode);
13645 if (errno) {
13646 hdd_err_rl("Failed to parse driver mode '%s'", kmessage);
13647 return errno;
13648 }
13649
13650 if (!is_con_mode_valid(next_mode)) {
13651 hdd_err_rl("Requested driver mode is invalid");
13652 return -EINVAL;
13653 }
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013654
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013655 qdf_atomic_set(&hdd_ctx->con_mode_flag, 1);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013656 mutex_lock(&hdd_init_deinit_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +053013657
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013658 curr_mode = hdd_get_conparam();
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013659 if (curr_mode == next_mode) {
13660 hdd_err_rl("Driver is already in the requested mode");
13661 errno = 0;
13662 goto unlock;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013663 }
13664
Dustin Brown27cd9942017-09-27 16:11:44 -070013665 /* ensure adapters are stopped */
13666 hdd_stop_present_mode(hdd_ctx, curr_mode);
13667
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013668 errno = hdd_wlan_stop_modules(hdd_ctx, true);
13669 if (errno) {
Arun Khandavallifae92942016-08-01 13:31:08 +053013670 hdd_err("Stop wlan modules failed");
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013671 goto unlock;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013672 }
13673
Dustin Browndd4e50f2018-05-24 15:43:42 -070013674 /* Cleanup present mode before switching to new mode */
13675 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053013676
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013677 hdd_set_conparam(next_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013678
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013679 errno = hdd_wlan_start_modules(hdd_ctx, false);
13680 if (errno) {
13681 hdd_err("Start wlan modules failed: %d", errno);
13682 goto unlock;
Arun Khandavallifae92942016-08-01 13:31:08 +053013683 }
13684
jitiphil7af5cf22018-10-26 16:06:27 +053013685 errno = hdd_open_adapters_for_mode(hdd_ctx, next_mode);
13686 if (errno) {
13687 hdd_err("Failed to open adapters");
13688 goto unlock;
13689 }
13690
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013691 if (next_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Browne7e71d32018-05-11 16:00:08 -070013692 struct hdd_adapter *adapter =
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013693 hdd_get_adapter(hdd_ctx, QDF_MONITOR_MODE);
Dustin Browne7e71d32018-05-11 16:00:08 -070013694
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013695 QDF_BUG(adapter);
Dustin Browne7e71d32018-05-11 16:00:08 -070013696 if (!adapter) {
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013697 hdd_err("Failed to get monitor adapter");
13698 goto unlock;
Dustin Browne7e71d32018-05-11 16:00:08 -070013699 }
13700
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013701 errno = hdd_start_adapter(adapter);
13702 if (errno) {
13703 hdd_err("Failed to start monitor adapter");
13704 goto unlock;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013705 }
Arun Khandavallifae92942016-08-01 13:31:08 +053013706
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013707 hdd_info("Acquire wakelock for monitor mode");
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053013708 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
13709 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
13710 }
13711
Dustin Brown20024e32018-01-03 12:34:58 -080013712 /* con_mode is a global module parameter */
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013713 con_mode = next_mode;
13714 hdd_info("Driver mode successfully changed to %s", kmessage);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013715
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013716 errno = 0;
13717
13718unlock:
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013719 mutex_unlock(&hdd_init_deinit_lock);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013720 qdf_atomic_set(&hdd_ctx->con_mode_flag, 0);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013721
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013722 return errno;
13723}
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013724
Srinivas Girigowda841da292018-02-21 16:33:00 -080013725static int con_mode_handler(const char *kmessage, const struct kernel_param *kp)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013726{
Dustin Brown67d30412018-09-20 12:10:22 -070013727 struct hdd_driver *hdd_driver = hdd_driver_get();
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013728 struct hdd_context *hdd_ctx;
Dustin Brown67d30412018-09-20 12:10:22 -070013729 QDF_STATUS status;
13730 int errno;
13731
13732 hdd_enter();
13733
Dustin Brown13fa9872018-11-13 10:57:45 -080013734 /* This handler will be invoked before module init when the wlan driver
13735 * is loaded using 'insmod wlan.ko con_mode=5' for example. Return
13736 * success in this case, as module init will bring up the correct
13737 * con_mode when it runs.
13738 */
13739 if (hdd_driver->state == driver_state_uninit)
13740 return 0;
13741
Dustin Brown67d30412018-09-20 12:10:22 -070013742 status = dsc_driver_trans_start_wait(hdd_driver->dsc_driver,
13743 "mode change");
13744 if (QDF_IS_STATUS_ERROR(status)) {
13745 hdd_err("Failed to start 'mode change'; status:%u", status);
13746 errno = qdf_status_to_os_return(status);
13747 goto exit;
13748 }
13749
13750 dsc_driver_wait_for_ops(hdd_driver->dsc_driver);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013751
13752 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Dustin Brown67d30412018-09-20 12:10:22 -070013753 errno = wlan_hdd_validate_context(hdd_ctx);
13754 if (errno)
13755 goto trans_stop;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013756
Ashish Kumar Dhanotiya759b3272018-05-18 17:49:46 +053013757 if (!cds_wait_for_external_threads_completion(__func__)) {
13758 hdd_warn("External threads are still active, can not change mode");
Dustin Brown67d30412018-09-20 12:10:22 -070013759 errno = -EAGAIN;
13760 goto trans_stop;
Ashish Kumar Dhanotiya759b3272018-05-18 17:49:46 +053013761 }
13762
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013763 cds_ssr_protect(__func__);
Dustin Brown67d30412018-09-20 12:10:22 -070013764 errno = __con_mode_handler(kmessage, kp, hdd_ctx);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013765 cds_ssr_unprotect(__func__);
13766
Dustin Brown67d30412018-09-20 12:10:22 -070013767trans_stop:
13768 dsc_driver_trans_stop(hdd_driver->dsc_driver);
13769
13770exit:
13771 hdd_exit();
13772
13773 return errno;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013774}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013775
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013776static int con_mode_handler_ftm(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080013777 const struct kernel_param *kp)
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013778{
13779 int ret;
13780
13781 ret = param_set_int(kmessage, kp);
13782
13783 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
13784 pr_err("Only FTM mode supported!");
13785 return -ENOTSUPP;
13786 }
13787
13788 hdd_set_conparam(con_mode_ftm);
13789 con_mode = con_mode_ftm;
13790
13791 return ret;
13792}
13793
Nirav Shah73713f72018-05-17 14:50:41 +053013794#ifdef FEATURE_MONITOR_MODE_SUPPORT
Ravi Joshia307f632017-07-17 23:41:41 -070013795static int con_mode_handler_monitor(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080013796 const struct kernel_param *kp)
Ravi Joshia307f632017-07-17 23:41:41 -070013797{
13798 int ret;
13799
13800 ret = param_set_int(kmessage, kp);
13801
13802 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
13803 pr_err("Only Monitor mode supported!");
13804 return -ENOTSUPP;
13805 }
13806
13807 hdd_set_conparam(con_mode_monitor);
13808 con_mode = con_mode_monitor;
13809
13810 return ret;
13811}
Nirav Shah73713f72018-05-17 14:50:41 +053013812#endif
Ravi Joshia307f632017-07-17 23:41:41 -070013813
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013814/**
13815 * hdd_get_conparam() - driver exit point
13816 *
13817 * This is the driver exit point (invoked when module is unloaded using rmmod)
13818 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080013819 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013820 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080013821enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013822{
Jeff Johnson876c1a62017-12-12 10:43:07 -080013823 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013824}
13825
Dustin Brownf0f70562018-09-14 10:29:38 -070013826void hdd_set_conparam(int32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013827{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080013828 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013829}
13830
Komal Seelamc11bb222016-01-27 18:57:10 +053013831/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013832 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
13833 * @hdd_ctx: HDD context
13834 *
13835 * Cleans up the pre cac interface, if it exists
13836 *
13837 * Return: None
13838 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013839void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013840{
13841 uint8_t session_id;
13842 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070013843 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013844
Jeff Johnson16528362018-06-14 12:34:16 -070013845 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->mac_handle, &session_id);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013846 if (QDF_IS_STATUS_ERROR(status)) {
13847 hdd_err("failed to get pre cac vdev id");
13848 return;
13849 }
13850
13851 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
13852 if (!precac_adapter) {
Jeff Johnsondd2f1fc2018-05-06 11:22:52 -070013853 hdd_err("invalid pre cac adapter");
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013854 return;
13855 }
13856
13857 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
13858 wlan_hdd_sap_pre_cac_failure,
13859 (void *)precac_adapter);
13860 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
13861
13862}
13863
13864/**
Komal Seelamec702b02016-02-24 18:42:16 +053013865 * hdd_update_ol_config - API to update ol configuration parameters
13866 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053013867 *
Komal Seelamc11bb222016-01-27 18:57:10 +053013868 * Return: void
13869 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013870static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053013871{
Komal Seelamec702b02016-02-24 18:42:16 +053013872 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053013873 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053013874 bool self_recovery = false;
13875 QDF_STATUS status;
Komal Seelamc11bb222016-01-27 18:57:10 +053013876
Komal Seelamec702b02016-02-24 18:42:16 +053013877 if (!ol_ctx)
13878 return;
13879
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053013880 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
13881 if (QDF_IS_STATUS_ERROR(status))
13882 hdd_err("Failed to get self recovery ini config");
13883
13884 cfg.enable_self_recovery = self_recovery;
Komal Seelamec702b02016-02-24 18:42:16 +053013885 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
13886 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
13887 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070013888 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053013889
13890 ol_init_ini_config(ol_ctx, &cfg);
13891}
13892
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013893#ifdef FEATURE_RUNTIME_PM
13894/**
13895 * hdd_populate_runtime_cfg() - populate runtime configuration
13896 * @hdd_ctx: hdd context
13897 * @cfg: pointer to the configuration memory being populated
13898 *
13899 * Return: void
13900 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013901static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013902 struct hif_config_info *cfg)
13903{
13904 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
Wu Gao66454f12018-09-26 19:55:41 +080013905 cfg->runtime_pm_delay =
13906 ucfg_pmo_get_runtime_pm_delay(hdd_ctx->psoc);
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013907}
13908#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013909static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013910 struct hif_config_info *cfg)
13911{
13912}
13913#endif
13914
Komal Seelamec702b02016-02-24 18:42:16 +053013915/**
13916 * hdd_update_hif_config - API to update HIF configuration parameters
13917 * @hdd_ctx: HDD Context
13918 *
13919 * Return: void
13920 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013921static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053013922{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053013923 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053013924 struct hif_config_info cfg;
Vignesh Viswanathana851d752018-10-03 19:44:38 +053013925 bool prevent_link_down = false;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053013926 bool self_recovery = false;
Vignesh Viswanathana851d752018-10-03 19:44:38 +053013927 QDF_STATUS status;
Komal Seelamec702b02016-02-24 18:42:16 +053013928
13929 if (!scn)
13930 return;
13931
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053013932 status = ucfg_mlme_get_prevent_link_down(hdd_ctx->psoc,
13933 &prevent_link_down);
Vignesh Viswanathana851d752018-10-03 19:44:38 +053013934 if (QDF_IS_STATUS_ERROR(status))
13935 hdd_err("Failed to get prevent_link_down config");
13936
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053013937 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
13938 if (QDF_IS_STATUS_ERROR(status))
13939 hdd_err("Failed to get self recovery ini config");
13940
13941 cfg.enable_self_recovery = self_recovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013942 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053013943 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070013944
Vignesh Viswanathana851d752018-10-03 19:44:38 +053013945 if (prevent_link_down)
Dustin Brownee3e0592017-09-07 13:50:11 -070013946 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053013947}
13948
13949/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013950 * hdd_update_dp_config() - Propagate config parameters to Lithium
13951 * datapath
13952 * @hdd_ctx: HDD Context
13953 *
13954 * Return: 0 for success/errno for failure
13955 */
13956static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
13957{
13958 struct cdp_config_params params;
13959 QDF_STATUS status;
jitiphil377bcc12018-10-05 19:46:08 +053013960 void *soc;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013961
jitiphil377bcc12018-10-05 19:46:08 +053013962 soc = cds_get_context(QDF_MODULE_ID_SOC);
13963 params.tso_enable = cfg_get(hdd_ctx->psoc, CFG_DP_TSO);
13964 params.lro_enable = cfg_get(hdd_ctx->psoc, CFG_DP_LRO);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013965#ifdef QCA_LL_TX_FLOW_CONTROL_V2
13966 params.tx_flow_stop_queue_threshold =
jitiphil47c3d9a2018-11-08 18:30:55 +053013967 cfg_get(hdd_ctx->psoc, CFG_DP_TX_FLOW_STOP_QUEUE_TH);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013968 params.tx_flow_start_queue_offset =
jitiphil47c3d9a2018-11-08 18:30:55 +053013969 cfg_get(hdd_ctx->psoc,
13970 CFG_DP_TX_FLOW_START_QUEUE_OFFSET);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013971#endif
jitiphil377bcc12018-10-05 19:46:08 +053013972 params.flow_steering_enable =
13973 cfg_get(hdd_ctx->psoc, CFG_DP_FLOW_STEERING_ENABLED);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013974 params.napi_enable = hdd_ctx->napi_enable;
13975 params.tcp_udp_checksumoffload =
jitiphil377bcc12018-10-05 19:46:08 +053013976 cfg_get(hdd_ctx->psoc,
13977 CFG_DP_TCP_UDP_CKSUM_OFFLOAD);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013978
jitiphil377bcc12018-10-05 19:46:08 +053013979 status = cdp_update_config_parameters(soc, &params);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013980 if (status) {
Dustin Browna2868622018-03-20 11:38:14 -070013981 hdd_err("Failed to attach config parameters");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013982 return status;
13983 }
13984
13985 return 0;
13986}
13987
13988/**
Komal Seelamec702b02016-02-24 18:42:16 +053013989 * hdd_update_config() - Initialize driver per module ini parameters
13990 * @hdd_ctx: HDD Context
13991 *
13992 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013993 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053013994 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013995int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053013996{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013997 int ret;
13998
Wu Gao66454f12018-09-26 19:55:41 +080013999 if (ucfg_pmo_is_ns_offloaded(hdd_ctx->psoc))
14000 hdd_ctx->ns_offload_enable = true;
14001
Komal Seelamec702b02016-02-24 18:42:16 +053014002 hdd_update_ol_config(hdd_ctx);
14003 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053014004 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
14005 ret = hdd_update_cds_config_ftm(hdd_ctx);
14006 else
14007 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080014008 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053014009
14010 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053014011}
14012
Mukul Sharma9d797a02017-01-05 20:26:03 +053014013#ifdef FEATURE_WLAN_RA_FILTERING
14014/**
14015 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
14016 * @psoc_cfg: pmo psoc Configuration
14017 * @hdd_ctx: Pointer to hdd context
14018 *
14019 * Return: none
14020 */
14021static inline void hdd_ra_populate_pmo_config(
14022 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014023 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053014024{
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053014025 bool is_rate_limit_enabled;
14026 QDF_STATUS status;
14027
14028 status = ucfg_fwol_get_is_rate_limit_enabled(hdd_ctx->psoc,
14029 &is_rate_limit_enabled);
14030 if (QDF_IS_STATUS_ERROR(status))
14031 return;
14032
Mukul Sharma9d797a02017-01-05 20:26:03 +053014033 psoc_cfg->ra_ratelimit_interval =
14034 hdd_ctx->config->RArateLimitInterval;
14035 psoc_cfg->ra_ratelimit_enable =
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053014036 is_rate_limit_enabled;
Mukul Sharma9d797a02017-01-05 20:26:03 +053014037}
14038#else
14039static inline void hdd_ra_populate_pmo_config(
14040 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014041 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053014042{
14043}
14044#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080014045
Mukul Sharma9d797a02017-01-05 20:26:03 +053014046/**
14047 * hdd_update_pmo_config - API to update pmo configuration parameters
14048 * @hdd_ctx: HDD context
14049 *
14050 * Return: void
14051 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014052static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053014053{
Mukul Sharma9d797a02017-01-05 20:26:03 +053014054 struct pmo_psoc_cfg psoc_cfg;
14055 QDF_STATUS status;
Wu Gao66454f12018-09-26 19:55:41 +080014056 enum pmo_wow_enable_type wow_enable;
14057
14058 ucfg_pmo_get_psoc_config(hdd_ctx->psoc, &psoc_cfg);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014059
14060 /*
14061 * Value of hdd_ctx->wowEnable can be,
14062 * 0 - Disable both magic pattern match and pattern byte match.
14063 * 1 - Enable magic pattern match on all interfaces.
14064 * 2 - Enable pattern byte match on all interfaces.
14065 * 3 - Enable both magic patter and pattern byte match on
14066 * all interfaces.
14067 */
Wu Gao66454f12018-09-26 19:55:41 +080014068 wow_enable = ucfg_pmo_get_wow_enable(hdd_ctx->psoc);
14069 psoc_cfg.magic_ptrn_enable = (wow_enable & 0x01) ? true : false;
Mukul Sharma9d797a02017-01-05 20:26:03 +053014070 psoc_cfg.ptrn_match_enable_all_vdev =
Wu Gao66454f12018-09-26 19:55:41 +080014071 (wow_enable & 0x02) ? true : false;
Dustin Brownb9987af2018-03-01 17:15:11 -080014072 psoc_cfg.packet_filter_enabled = !hdd_ctx->config->disablePacketFilter;
Mukul Sharma9d797a02017-01-05 20:26:03 +053014073 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080014074 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Bala Venkatesh46e29032018-11-14 18:24:55 +053014075 ucfg_mlme_get_sap_max_modulated_dtim(hdd_ctx->psoc,
14076 &psoc_cfg.sta_max_li_mod_dtim);
14077
Mukul Sharma9d797a02017-01-05 20:26:03 +053014078
14079 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053014080 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014081
Dustin Brown1dbefe62018-09-11 16:32:03 -070014082 status = ucfg_pmo_update_psoc_config(hdd_ctx->psoc, &psoc_cfg);
Dustin Brownb9987af2018-03-01 17:15:11 -080014083 if (QDF_IS_STATUS_ERROR(status))
14084 hdd_err("failed pmo psoc configuration; status:%d", status);
14085
14086 return qdf_status_to_os_return(status);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014087}
14088
Abhishek Singhb20db962017-03-03 21:28:46 +053014089#ifdef FEATURE_WLAN_SCAN_PNO
14090static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Wu Gao1ab05582018-11-08 16:22:49 +080014091 struct hdd_context *hdd_ctx)
Abhishek Singhb20db962017-03-03 21:28:46 +053014092{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070014093 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
Wu Gao1ab05582018-11-08 16:22:49 +080014094 struct hdd_config *cfg = hdd_ctx->config;
14095 bool mawc_enabled;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070014096
Abhishek Singhb20db962017-03-03 21:28:46 +053014097 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
14098 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
14099 pno_cfg->stationary_thresh = cfg->stationary_thresh;
14100 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
14101 pno_cfg->channel_prediction_full_scan =
14102 cfg->channel_prediction_full_scan;
Wu Gao1ab05582018-11-08 16:22:49 +080014103
14104 ucfg_mlme_is_mawc_enabled(hdd_ctx->psoc, &mawc_enabled);
14105 mawc_cfg->enable = mawc_enabled && cfg->mawc_nlo_enabled;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070014106 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
14107 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
14108 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053014109}
14110#else
14111static inline void
14112hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Wu Gao1ab05582018-11-08 16:22:49 +080014113 struct hdd_context *hdd_ctx)
Abhishek Singhb20db962017-03-03 21:28:46 +053014114{
Abhishek Singhb20db962017-03-03 21:28:46 +053014115}
14116#endif
14117
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014118void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014119 struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014120{
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014121 struct wlan_fwol_ie_whitelist whitelist = {0};
14122 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014123 QDF_STATUS status;
14124 bool is_ie_whitelist_enable = false;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014125 uint8_t i = 0;
14126
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014127 status = ucfg_fwol_get_ie_whitelist(psoc, &is_ie_whitelist_enable);
14128 if (QDF_IS_STATUS_ERROR(status)) {
14129 hdd_err("Unable to get IE whitelist param");
14130 return;
14131 }
14132
14133 ie_whitelist->white_list = is_ie_whitelist_enable;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014134 if (!ie_whitelist->white_list)
14135 return;
14136
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014137 status = ucfg_fwol_get_all_whitelist_params(psoc, &whitelist);
14138 if (QDF_IS_STATUS_ERROR(status)) {
14139 hdd_err("Unable to get all whitelist params");
14140 return;
14141 }
14142
14143 ie_whitelist->ie_bitmap[0] = whitelist.ie_bitmap_0;
14144 ie_whitelist->ie_bitmap[1] = whitelist.ie_bitmap_1;
14145 ie_whitelist->ie_bitmap[2] = whitelist.ie_bitmap_2;
14146 ie_whitelist->ie_bitmap[3] = whitelist.ie_bitmap_3;
14147 ie_whitelist->ie_bitmap[4] = whitelist.ie_bitmap_4;
14148 ie_whitelist->ie_bitmap[5] = whitelist.ie_bitmap_5;
14149 ie_whitelist->ie_bitmap[6] = whitelist.ie_bitmap_6;
14150 ie_whitelist->ie_bitmap[7] = whitelist.ie_bitmap_7;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014151
Dundi Raviteja9ab4e7b2018-09-28 14:18:28 +053014152 ie_whitelist->num_vendor_oui = whitelist.no_of_probe_req_ouis;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014153 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
Dundi Raviteja9ab4e7b2018-09-28 14:18:28 +053014154 ie_whitelist->voui[i] = whitelist.probe_req_voui[i];
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014155}
14156
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014157uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
14158{
14159 uint8_t i, score;
14160
14161 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
14162 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
14163 if (score > MAX_INDEX_SCORE)
14164 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
14165 MAX_INDEX_SCORE, i);
14166 }
14167
14168 return per_index_score;
14169}
14170
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014171QDF_STATUS hdd_update_score_config(
14172 struct scoring_config *score_config, struct hdd_context *hdd_ctx)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014173{
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014174 struct hdd_config *cfg = hdd_ctx->config;
gaurank kathpaliaae52c982018-10-04 01:35:18 +053014175 QDF_STATUS status;
gaurank kathpalia651abcd2018-11-12 22:41:23 +053014176 struct wlan_mlme_nss_chains vdev_ini_cfg;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014177 bool bval = false;
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014178
gaurank kathpalia651abcd2018-11-12 22:41:23 +053014179 /* Populate the nss chain params from ini for this vdev type */
14180 sme_populate_nss_chain_params(hdd_ctx->mac_handle, &vdev_ini_cfg,
14181 QDF_STA_MODE,
14182 hdd_ctx->num_rf_chains);
14183
14184 score_config->vdev_nss_24g = vdev_ini_cfg.rx_nss[NSS_CHAINS_BAND_2GHZ];
14185 score_config->vdev_nss_24g = vdev_ini_cfg.rx_nss[NSS_CHAINS_BAND_5GHZ];
14186
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014187 sme_update_score_config(hdd_ctx->mac_handle, score_config);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014188
14189 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
14190 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
gaurank kathpaliaae52c982018-10-04 01:35:18 +053014191
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014192 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
14193 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
14194 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
14195 score_config->he_cap = 1;
14196
14197 if (score_config->he_cap ||
14198 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
14199 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
14200 score_config->vht_cap = 1;
14201
14202 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
14203 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
14204 score_config->ht_cap = 1;
14205
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014206 status = ucfg_mlme_get_vht_for_24ghz(hdd_ctx->psoc, &bval);
14207 if (!QDF_IS_STATUS_SUCCESS(status))
14208 hdd_err("Failed to get vht_for_24ghz");
14209 if (score_config->vht_cap && bval)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014210 score_config->vht_24G_cap = 1;
14211
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014212 status = ucfg_mlme_get_vht_enable_tx_bf(hdd_ctx->psoc,
14213 &bval);
14214 if (!QDF_IS_STATUS_SUCCESS(status))
14215 hdd_err("unable to get vht_enable_tx_bf");
14216
14217 if (bval)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014218 score_config->beamformee_cap = 1;
14219
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014220 return QDF_STATUS_SUCCESS;
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014221}
14222
Abhishek Singh257a9482017-03-06 16:52:39 +053014223/**
bings81fe50a2017-11-27 14:33:26 +080014224 * hdd_update_dfs_config() - API to update dfs configuration parameters.
14225 * @hdd_ctx: HDD context
14226 *
14227 * Return: 0 if success else err
14228 */
14229static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
14230{
Dustin Brown1dbefe62018-09-11 16:32:03 -070014231 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
bings81fe50a2017-11-27 14:33:26 +080014232 struct hdd_config *cfg = hdd_ctx->config;
14233 struct dfs_user_config dfs_cfg;
14234 QDF_STATUS status;
14235
14236 dfs_cfg.dfs_is_phyerr_filter_offload = !!cfg->fDfsPhyerrFilterOffload;
14237 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
14238 if (QDF_IS_STATUS_ERROR(status)) {
14239 hdd_err("failed dfs psoc configuration");
14240 return -EINVAL;
14241 }
14242
14243 return 0;
14244}
14245
14246/**
Abhishek Singh257a9482017-03-06 16:52:39 +053014247 * hdd_update_scan_config - API to update scan configuration parameters
14248 * @hdd_ctx: HDD context
14249 *
14250 * Return: 0 if success else err
14251 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014252static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053014253{
Dustin Brown1dbefe62018-09-11 16:32:03 -070014254 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Abhishek Singh257a9482017-03-06 16:52:39 +053014255 struct scan_user_cfg scan_cfg;
14256 struct hdd_config *cfg = hdd_ctx->config;
14257 QDF_STATUS status;
Wu Gaoca416ff2018-09-17 11:05:07 +080014258 uint8_t scan_bucket_thre;
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014259 uint8_t select_5ghz_margin;
Wu Gao1ab05582018-11-08 16:22:49 +080014260 bool roam_prefer_5ghz;
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014261
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014262 status = ucfg_mlme_get_select_5ghz_margin(hdd_ctx->psoc,
14263 &select_5ghz_margin);
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014264 if (QDF_IS_STATUS_ERROR(status)) {
14265 hdd_err("Failed to get select_5ghz_margin");
14266 return -EIO;
14267 }
Abhishek Singh257a9482017-03-06 16:52:39 +053014268
14269 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
14270 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
14271 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
14272 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
14273 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
14274 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
14275 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053014276 /* convert to ms */
14277 scan_cfg.scan_cache_aging_time =
14278 cfg->scanAgingTimeout * 1000;
Wu Gao1ab05582018-11-08 16:22:49 +080014279 ucfg_mlme_is_roam_prefer_5ghz(hdd_ctx->psoc, &roam_prefer_5ghz);
14280 scan_cfg.prefer_5ghz = (uint32_t)roam_prefer_5ghz;
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014281 scan_cfg.select_5ghz_margin = select_5ghz_margin;
Dustin Brown1dbefe62018-09-11 16:32:03 -070014282 ucfg_mlme_get_first_scan_bucket_threshold(hdd_ctx->psoc,
Wu Gaoca416ff2018-09-17 11:05:07 +080014283 &scan_bucket_thre);
14284 scan_cfg.scan_bucket_threshold = (int32_t)scan_bucket_thre;
Abhishek Singh158fe252017-03-23 11:09:34 +053014285 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053014286 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053014287 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080014288 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
14289 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053014290 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070014291 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singhc87bb042018-01-30 17:10:42 +053014292 scan_cfg.sta_miracast_mcc_rest_time =
14293 cfg->sta_miracast_mcc_rest_time_val;
Wu Gao1ab05582018-11-08 16:22:49 +080014294 hdd_update_pno_config(&scan_cfg.pno_cfg, hdd_ctx);
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014295 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, hdd_ctx);
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014296
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014297 status = hdd_update_score_config(&scan_cfg.score_config, hdd_ctx);
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014298 if (QDF_IS_STATUS_ERROR(status)) {
14299 hdd_err("Failed to update scoring config");
14300 return -EINVAL;
14301 }
Abhishek Singhb20db962017-03-03 21:28:46 +053014302
Abhishek Singh257a9482017-03-06 16:52:39 +053014303 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
14304 if (status != QDF_STATUS_SUCCESS) {
14305 hdd_err("failed pmo psoc configuration");
14306 return -EINVAL;
14307 }
Liangwei Dongac3ddde2018-09-10 23:25:12 -040014308 ucfg_scan_set_global_config(
14309 psoc, SCAN_CFG_DROP_BCN_ON_CHANNEL_MISMATCH,
14310 cfg_get(psoc, CFG_DROP_BCN_ON_CHANNEL_MISMATCH));
Abhishek Singh257a9482017-03-06 16:52:39 +053014311
14312 return 0;
14313}
Abhishek Singh257a9482017-03-06 16:52:39 +053014314
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014315int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053014316{
14317 int ret;
14318
14319 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053014320 if (ret)
14321 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014322
Abhishek Singh257a9482017-03-06 16:52:39 +053014323 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080014324 if (ret)
14325 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014326
Frank Liud4b2fa02017-03-29 11:46:48 +080014327 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014328 if (ret)
14329 return ret;
14330
14331 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080014332 if (ret)
14333 return ret;
14334
14335 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014336
14337 return ret;
14338}
14339
Agrawal Ashish65634612016-08-18 13:24:32 +053014340/**
14341 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
14342 * @mode : cfg80211 DFS mode
14343 *
14344 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
14345 */
14346enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
14347{
14348 switch (mode) {
14349 case DFS_MODE_ENABLE:
14350 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014351 case DFS_MODE_DISABLE:
14352 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014353 case DFS_MODE_DEPRIORITIZE:
14354 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014355 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080014356 hdd_debug("ACS dfs mode is NONE");
14357 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014358 }
14359}
14360
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014361/**
14362 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
14363 * @hddctx: pointer to hdd context
14364 * @set_value: enable/disable
14365 *
14366 * When Host sends vendor command enable, FW will send *ONE* CA ind to
14367 * Host(even though it is duplicate). When Host send vendor command
14368 * disable,FW doesn't perform any action. Whenever any change in
14369 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
14370 *
14371 * return - 0 on success, appropriate error values on failure.
14372 */
Jeff Johnson16528362018-06-14 12:34:16 -070014373int hdd_enable_disable_ca_event(struct hdd_context *hdd_ctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014374{
14375 QDF_STATUS status;
14376
Jeff Johnson16528362018-06-14 12:34:16 -070014377 if (0 != wlan_hdd_validate_context(hdd_ctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014378 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014379
Jeff Johnson16528362018-06-14 12:34:16 -070014380 status = sme_enable_disable_chanavoidind_event(hdd_ctx->mac_handle,
14381 set_value);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014382 if (!QDF_IS_STATUS_SUCCESS(status)) {
14383 hdd_err("Failed to send chan avoid command to SME");
14384 return -EINVAL;
14385 }
14386 return 0;
14387}
Agrawal Ashish65634612016-08-18 13:24:32 +053014388
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014389/**
14390 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
14391 * @value: value to set
14392 *
14393 * This function will set the passed value to roaming in progress flag.
14394 *
14395 * Return: None
14396 */
14397void hdd_set_roaming_in_progress(bool value)
14398{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014399 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014400
14401 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14402 if (!hdd_ctx) {
14403 hdd_err("HDD context is NULL");
14404 return;
14405 }
14406
14407 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080014408 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014409}
14410
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014411bool hdd_is_roaming_in_progress(struct hdd_context *hdd_ctx)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014412{
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014413 if (!hdd_ctx) {
14414 hdd_err("HDD context is NULL");
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014415 return false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014416 }
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080014417
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014418 hdd_debug("roaming_in_progress = %d", hdd_ctx->roaming_in_progress);
14419
14420 return hdd_ctx->roaming_in_progress;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014421}
14422
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014423/**
14424 * hdd_is_connection_in_progress() - check if connection is in
14425 * progress
14426 * @session_id: session id
14427 * @reason: scan reject reason
14428 *
14429 * Go through each adapter and check if Connection is in progress
14430 *
14431 * Return: true if connection is in progress else false
14432 */
14433bool hdd_is_connection_in_progress(uint8_t *session_id,
14434 enum scan_reject_states *reason)
14435{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070014436 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070014437 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014438 uint8_t sta_id = 0;
14439 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014440 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -070014441 mac_handle_t mac_handle;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014442
14443 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14444 if (!hdd_ctx) {
14445 hdd_err("HDD context is NULL");
14446 return false;
14447 }
14448
Jeff Johnson16528362018-06-14 12:34:16 -070014449 mac_handle = hdd_ctx->mac_handle;
14450
Dustin Brown920397d2017-12-13 16:27:50 -080014451 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya929afa42018-06-01 15:04:44 -070014452 hdd_debug("Adapter with device mode %s(%d) exists",
Dustin Brown458027c2018-10-19 12:26:27 -070014453 qdf_opmode_str(adapter->device_mode),
14454 adapter->device_mode);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014455 if (((QDF_STA_MODE == adapter->device_mode)
14456 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
14457 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
14458 && (eConnectionState_Connecting ==
14459 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
14460 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014461 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014462 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070014463 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014464 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070014465 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014466 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014467 }
14468 return true;
14469 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070014470 /*
14471 * sme_neighbor_middle_of_roaming is for LFR2
14472 * hdd_is_roaming_in_progress is for LFR3
14473 */
14474 if (((QDF_STA_MODE == adapter->device_mode) &&
14475 sme_neighbor_middle_of_roaming(
Jeff Johnson16528362018-06-14 12:34:16 -070014476 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -070014477 adapter->session_id)) ||
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014478 hdd_is_roaming_in_progress(hdd_ctx)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014479 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014480 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070014481 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014482 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070014483 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014484 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014485 }
14486 return true;
14487 }
14488 if ((QDF_STA_MODE == adapter->device_mode) ||
14489 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
14490 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
14491 hdd_sta_ctx =
14492 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
14493 if ((eConnectionState_Associated ==
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053014494 hdd_sta_ctx->conn_info.connState)
14495 && sme_is_sta_key_exchange_in_progress(
Jeff Johnson16528362018-06-14 12:34:16 -070014496 mac_handle, adapter->session_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014497 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070014498 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014499 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014500 " is in middle of WPS/EAPOL exchange.",
14501 MAC_ADDR_ARRAY(sta_mac));
14502 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070014503 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014504 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014505 }
14506 return true;
14507 }
14508 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
14509 (QDF_P2P_GO_MODE == adapter->device_mode)) {
14510 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
14511 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014512 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014513 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014514 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014515 continue;
14516
14517 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014518 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070014519 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014520 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014521 " of SAP/GO is in middle of WPS/EAPOL exchange",
14522 MAC_ADDR_ARRAY(sta_mac));
14523 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070014524 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014525 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014526 }
14527 return true;
14528 }
14529 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014530 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014531 return true;
14532 }
14533 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014534 }
Dustin Brown920397d2017-12-13 16:27:50 -080014535
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014536 return false;
14537}
14538
14539/**
14540 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070014541 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014542 *
14543 * Return: None
14544 */
Jeff Johnson9d295242017-08-29 14:39:48 -070014545void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014546{
Jeff Johnson87251032017-08-29 13:31:11 -070014547 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070014548 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014549 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014550 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Jeff Johnsone4c11db2018-05-05 23:22:32 -070014551 tsap_config_t *sap_config;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014552 void *sap_ctx;
14553
14554 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070014555 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070014556 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014557
14558 mutex_lock(&hdd_ctx->sap_lock);
14559 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
14560 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014561 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
14562 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
14563 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
14564 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053014565 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014566 qdf_stop_bss_event,
Vignesh Viswanathan865daaa2018-10-11 19:30:44 +053014567 SME_CMD_START_STOP_BSS_TIMEOUT);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014568
14569 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014570 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014571 goto end;
14572 }
14573 }
14574 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -070014575 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070014576 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070014577 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014578 false);
Jeff Johnson6867ec32017-09-29 20:30:20 -070014579 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014580
14581 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014582 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014583 wlansap_reset_sap_config_add_ie(sap_config,
14584 eUPDATE_IE_ALL);
14585 goto end;
14586 }
14587
14588 qdf_event_reset(&hostapd_state->qdf_event);
14589 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
14590 sap_config,
14591 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014592 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014593 wlansap_reset_sap_config_add_ie(sap_config,
14594 eUPDATE_IE_ALL);
14595 goto end;
14596 }
14597
Jeff Johnson6867ec32017-09-29 20:30:20 -070014598 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014599 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053014600 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Vignesh Viswanathan865daaa2018-10-11 19:30:44 +053014601 SME_CMD_START_STOP_BSS_TIMEOUT);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014602 wlansap_reset_sap_config_add_ie(sap_config,
14603 eUPDATE_IE_ALL);
14604 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014605 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014606 goto end;
14607 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070014608 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014609 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014610 if (hostapd_state->bss_state == BSS_START) {
Dustin Brown1dbefe62018-09-11 16:32:03 -070014611 policy_mgr_incr_active_session(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014612 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070014613 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070014614 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014615 ap_adapter->device_mode,
14616 true);
14617 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014618 }
14619end:
14620 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014621}
14622
14623/**
14624 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
14625 * with non dfs acs
14626 *
14627 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
14628 *
14629 * Return: None
14630 */
14631void hdd_check_and_restart_sap_with_non_dfs_acs(void)
14632{
Jeff Johnson9d295242017-08-29 14:39:48 -070014633 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014634 struct hdd_context *hdd_ctx;
Jeff Johnson2b6982c2018-05-29 14:56:11 -070014635 struct cds_context *cds_ctx;
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014636 uint8_t restart_chan;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014637
14638 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14639 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014640 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014641 return;
14642 }
14643
14644 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
14645 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014646 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014647 return;
14648 }
14649
Dustin Brown1dbefe62018-09-11 16:32:03 -070014650 if (policy_mgr_get_concurrency_mode(hdd_ctx->psoc)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014651 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Dustin Brown7e761c72018-07-31 13:50:17 -070014652 hdd_debug("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014653 return;
14654 }
14655
14656 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Dustin Brown07901ec2018-09-07 11:02:41 -070014657 if (ap_adapter &&
14658 test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags) &&
14659 wlan_reg_is_dfs_ch(hdd_ctx->pdev,
14660 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014661
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014662 hdd_warn("STA-AP Mode DFS not supported, Switch SAP channel to Non DFS");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014663
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014664 restart_chan =
14665 hdd_get_safe_channel_from_pcl_and_acs_range(ap_adapter);
14666 if (!restart_chan ||
Dustin Brown07901ec2018-09-07 11:02:41 -070014667 wlan_reg_is_dfs_ch(hdd_ctx->pdev, restart_chan))
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014668 restart_chan = SAP_DEFAULT_5GHZ_CHANNEL;
14669
14670 hdd_switch_sap_channel(ap_adapter, restart_chan, true);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014671 }
14672}
14673
14674/**
14675 * hdd_set_connection_in_progress() - to set the connection in
14676 * progress flag
14677 * @value: value to set
14678 *
14679 * This function will set the passed value to connection in progress flag.
14680 * If value is previously being set to true then no need to set it again.
14681 *
14682 * Return: true if value is being set correctly and false otherwise.
14683 */
14684bool hdd_set_connection_in_progress(bool value)
14685{
14686 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014687 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014688
14689 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14690 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014691 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014692 return false;
14693 }
14694
14695 qdf_spin_lock(&hdd_ctx->connection_status_lock);
14696 /*
14697 * if the value is set to true previously and if someone is
14698 * trying to make it true again then it could be some race
14699 * condition being triggered. Avoid this situation by returning
14700 * false
14701 */
14702 if (hdd_ctx->connection_in_progress && value)
14703 status = false;
14704 else
14705 hdd_ctx->connection_in_progress = value;
14706 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
14707 return status;
14708}
14709
Jeff Johnson9d295242017-08-29 14:39:48 -070014710int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014711{
14712 if (!adapter) {
14713 hdd_err("Invalid adapter");
14714 return -EINVAL;
14715 }
14716 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070014717 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014718 WMA_VDEV_MCC_SET_TIME_QUOTA,
14719 set_value, VDEV_CMD);
14720 return 0;
14721
14722}
14723
Jeff Johnson9d295242017-08-29 14:39:48 -070014724int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014725{
14726 if (!adapter) {
14727 hdd_err("Invalid adapter");
14728 return -EINVAL;
14729 }
14730
14731 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070014732 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014733 WMA_VDEV_MCC_SET_TIME_LATENCY,
14734 set_value, VDEV_CMD);
14735 return 0;
14736}
14737
Jeff Johnson9d295242017-08-29 14:39:48 -070014738struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070014739 *psoc, uint8_t vdev_id)
14740{
Jeff Johnson9d295242017-08-29 14:39:48 -070014741 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014742 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070014743
14744 /*
14745 * Currently PSOC is not being used. But this logic will
14746 * change once we have the converged implementation of
14747 * HDD context per PSOC in place. This would break if
14748 * multiple vdev objects reuse the vdev id.
14749 */
14750 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
14751 if (!adapter)
14752 hdd_err("Get adapter by vdev id failed");
14753
14754 return adapter;
14755}
14756
Jeff Johnson9d295242017-08-29 14:39:48 -070014757int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014758 int8_t *rssi, int8_t *snr)
14759{
14760 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -070014761 mac_handle_t mac_handle;
Jeff Johnson025618c2018-03-18 14:41:00 -070014762 struct csr_roam_profile *roam_profile;
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014763
Jeff Johnson025618c2018-03-18 14:41:00 -070014764 roam_profile = hdd_roam_profile(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -070014765 mac_handle = hdd_adapter_get_mac_handle(adapter);
14766 status = sme_get_rssi_snr_by_bssid(mac_handle,
Jeff Johnson025618c2018-03-18 14:41:00 -070014767 roam_profile, bssid, rssi, snr);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014768 if (QDF_STATUS_SUCCESS != status) {
14769 hdd_warn("sme_get_rssi_snr_by_bssid failed");
14770 return -EINVAL;
14771 }
14772
14773 return 0;
14774}
14775
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014776/**
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014777 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
14778 * @adapter - HDD adapter
14779 *
14780 * Return: 0 on success and non zero value on failure
14781 */
14782int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
14783{
14784 struct hdd_context *hdd_ctx;
14785 int ret;
14786 QDF_STATUS status;
Krunal Sonie71838d2018-09-27 10:45:05 -070014787 uint8_t sys_pref = 0;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014788
14789 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
14790 ret = wlan_hdd_validate_context(hdd_ctx);
14791 if (ret < 0)
14792 return ret;
14793
Krunal Sonie71838d2018-09-27 10:45:05 -070014794 ucfg_policy_mgr_get_sys_pref(hdd_ctx->psoc,
14795 &sys_pref);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014796 /* set the system preferece to default */
Krunal Sonie71838d2018-09-27 10:45:05 -070014797 policy_mgr_set_cur_conc_system_pref(hdd_ctx->psoc, sys_pref);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014798
14799 /* clear the bitmap */
14800 adapter->active_ac = 0;
14801
14802 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson16528362018-06-14 12:34:16 -070014803 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014804
Jeff Johnson16528362018-06-14 12:34:16 -070014805 status = sme_send_limit_off_channel_params(hdd_ctx->mac_handle,
14806 adapter->session_id,
14807 false, 0, 0, false);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014808 if (!QDF_IS_STATUS_SUCCESS(status)) {
14809 hdd_err("failed to reset limit off chan params");
14810 ret = -EINVAL;
14811 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014812
14813 return ret;
14814}
14815
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014816/**
14817 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
14818 * @drv_op: Enum indicating driver op
14819 *
14820 * Return: none
14821 */
14822void hdd_start_driver_ops_timer(int drv_op)
14823{
14824 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
14825 switch (drv_op) {
14826 case eHDD_DRV_OP_PROBE:
14827 memcpy(drv_ops_string, "probe", sizeof("probe"));
14828 break;
14829 case eHDD_DRV_OP_REMOVE:
14830 memcpy(drv_ops_string, "remove", sizeof("remove"));
14831 break;
14832 case eHDD_DRV_OP_SHUTDOWN:
14833 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
14834 break;
14835 case eHDD_DRV_OP_REINIT:
14836 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
14837 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053014838 case eHDD_DRV_OP_IFF_UP:
14839 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
14840 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014841 }
14842
Dustin Brown45ed4bb2017-12-18 12:00:13 -080014843 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014844 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
Dustin Browncfc54fe2018-06-18 16:17:41 -070014845 HDD_OPS_INACTIVITY_TIMEOUT * qdf_timer_get_multiplier());
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014846}
14847
14848/**
14849 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
14850 *
14851 * Return: none
14852 */
14853void hdd_stop_driver_ops_timer(void)
14854{
14855 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
14856}
14857
14858/**
14859 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
14860 * inactivity timer
14861 *
14862 * Return: None
14863 */
14864void hdd_drv_ops_inactivity_handler(void)
14865{
Rajeev Kumar4471f1b2018-06-08 14:18:28 -070014866 hdd_err("WLAN_BUG_RCA %s: %d Sec timer expired while in .%s",
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014867 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
14868
Dustin Brown45ed4bb2017-12-18 12:00:13 -080014869 if (hdd_drv_ops_task) {
14870 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
14871 qdf_print_thread_trace(hdd_drv_ops_task);
14872 } else {
14873 hdd_err("hdd_drv_ops_task is null");
14874 }
14875
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014876 /* Driver shutdown is stuck, no recovery possible at this point */
14877 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
14878 sizeof("shutdown")))
14879 QDF_BUG(0);
14880
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080014881 if (cds_is_fw_down()) {
14882 hdd_err("FW is down");
14883 return;
14884 }
14885
Dustin Brown83044c22018-08-13 15:00:44 -070014886 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014887}
14888
Yun Parkff6a16a2017-09-26 16:38:18 -070014889/**
14890 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
14891 * @struct hdd_context *hdd_ctx
14892 * @struct hdd_adapter *padapter
14893 * @bool enble
14894 *
14895 * Return: none
14896 */
14897void hdd_set_rx_mode_rps(bool enable)
14898{
14899 struct cds_config_info *cds_cfg = cds_get_ini_config();
Ryan Hsu0e878fa2018-05-04 15:22:09 -070014900 struct hdd_context *hdd_ctx;
14901 struct hdd_adapter *adapter;
Yun Parkff6a16a2017-09-26 16:38:18 -070014902
Ryan Hsu0e878fa2018-05-04 15:22:09 -070014903 if (!cds_cfg)
14904 return;
14905
14906 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14907 if (!hdd_ctx)
14908 return;
14909
14910 adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
14911 if (!adapter)
14912 return;
14913
14914 if (!hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
Yun Parkff6a16a2017-09-26 16:38:18 -070014915 if (enable && !cds_cfg->rps_enabled)
14916 hdd_send_rps_ind(adapter);
14917 else if (!enable && cds_cfg->rps_enabled)
14918 hdd_send_rps_disable_ind(adapter);
14919 }
14920}
14921
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +053014922bool hdd_is_cli_iface_up(struct hdd_context *hdd_ctx)
14923{
14924 struct hdd_adapter *adapter = NULL;
14925
14926 hdd_for_each_adapter(hdd_ctx, adapter) {
14927 if ((adapter->device_mode == QDF_STA_MODE ||
14928 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
14929 qdf_atomic_test_bit(DEVICE_IFACE_OPENED,
14930 &adapter->event_flags)){
14931 return true;
14932 }
14933 }
14934
14935 return false;
14936}
14937
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014938/* Register the module init/exit functions */
14939module_init(hdd_module_init);
14940module_exit(hdd_module_exit);
14941
14942MODULE_LICENSE("Dual BSD/GPL");
14943MODULE_AUTHOR("Qualcomm Atheros, Inc.");
14944MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
14945
Srinivas Girigowda841da292018-02-21 16:33:00 -080014946static const struct kernel_param_ops con_mode_ops = {
14947 .set = con_mode_handler,
14948 .get = param_get_int,
14949};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014950
Srinivas Girigowda841da292018-02-21 16:33:00 -080014951static const struct kernel_param_ops con_mode_ftm_ops = {
14952 .set = con_mode_handler_ftm,
14953 .get = param_get_int,
14954};
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053014955
Nirav Shah73713f72018-05-17 14:50:41 +053014956#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080014957static const struct kernel_param_ops con_mode_monitor_ops = {
14958 .set = con_mode_handler_monitor,
14959 .get = param_get_int,
14960};
Nirav Shah73713f72018-05-17 14:50:41 +053014961#endif
Ravi Joshia307f632017-07-17 23:41:41 -070014962
Srinivas Girigowda841da292018-02-21 16:33:00 -080014963static const struct kernel_param_ops fwpath_ops = {
14964 .set = fwpath_changed_handler,
14965 .get = param_get_string,
14966};
14967
14968module_param_cb(con_mode, &con_mode_ops, &con_mode,
14969 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
14970
14971module_param_cb(con_mode_ftm, &con_mode_ftm_ops, &con_mode_ftm,
14972 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
14973
Nirav Shah73713f72018-05-17 14:50:41 +053014974#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080014975module_param_cb(con_mode_monitor, &con_mode_monitor_ops, &con_mode_monitor,
14976 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Nirav Shah73713f72018-05-17 14:50:41 +053014977#endif
Srinivas Girigowda841da292018-02-21 16:33:00 -080014978
14979module_param_cb(fwpath, &fwpath_ops, &fwpath,
14980 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014981
14982module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
14983
14984module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
14985
14986module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);