blob: cd5de4ff988919dbd6c7275889eb587ccc62c6f6 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Jeff Johnson30e9bb62018-12-27 20:57:09 -08002 * Copyright (c) 2012-2019 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
7 * copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080019/**
20 * DOC: wlan_hdd_main.c
21 *
22 * WLAN Host Device Driver implementation
23 *
24 */
25
26/* Include Files */
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053027#include <wbuff.h>
Dustin Brown84f46ea2018-02-15 11:57:36 -080028#include "cfg_ucfg_api.h"
Dustin Brown21a1d462018-07-31 15:13:06 -070029#include "wlan_dsc.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080030#include <wlan_hdd_includes.h>
31#include <cds_api.h>
32#include <cds_sched.h>
Arun Khandavallifae92942016-08-01 13:31:08 +053033#include <linux/cpu.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080034#include <linux/etherdevice.h>
35#include <linux/firmware.h>
36#include <wlan_hdd_tx_rx.h>
37#include <wni_api.h>
38#include <wlan_hdd_cfg.h>
39#include <wlan_ptt_sock_svc.h>
40#include <dbglog_host.h>
41#include <wlan_logging_sock_svc.h>
Qiwei Caiad9b01c2018-07-09 17:21:31 +080042#include <wlan_roam_debug.h>
Dustin Brownfe50cef2018-12-10 10:42:37 -080043#include "wlan_hdd_dsc.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080044#include <wlan_hdd_wowl.h>
45#include <wlan_hdd_misc.h>
46#include <wlan_hdd_wext.h>
47#include "wlan_hdd_trace.h"
48#include "wlan_hdd_ioctl.h"
49#include "wlan_hdd_ftm.h"
50#include "wlan_hdd_power.h"
51#include "wlan_hdd_stats.h"
Prashanth Bhatta527fd752016-04-28 12:35:23 -070052#include "wlan_hdd_scan.h"
Krunal Sonie9c12f52018-10-04 11:45:42 -070053#include "wlan_policy_mgr_ucfg.h"
Naveen Rawate02f8f52018-04-05 11:58:04 -070054#include <wlan_osif_request_manager.h>
Dustin Brown26b3d042017-12-21 11:13:27 -080055#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4bc0a622017-12-06 15:56:50 -080056#include "qdf_debug_domain.h"
Dustin Brown26b3d042017-12-21 11:13:27 -080057#endif
Dustin Brownd4241942018-02-26 12:51:37 -080058#include "qdf_str.h"
Dustin Brownd315c452018-11-27 11:28:48 -080059#include "qdf_talloc.h"
Dustin Brownd4241942018-02-26 12:51:37 -080060#include "qdf_trace.h"
61#include "qdf_types.h"
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070062#include <cdp_txrx_peer_ops.h>
Dhanashri Atrea8f82f22017-01-23 12:58:24 -080063#include <cdp_txrx_misc.h>
Mohit Khannaca4173b2017-09-12 21:52:19 -070064#include <cdp_txrx_stats.h>
bings0e03a982018-05-09 08:40:59 +080065#include "cdp_txrx_flow_ctrl_legacy.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080066
67#include <net/addrconf.h>
68#include <linux/wireless.h>
69#include <net/cfg80211.h>
70#include <linux/inetdevice.h>
71#include <net/addrconf.h>
72#include "wlan_hdd_cfg80211.h"
73#include "wlan_hdd_ext_scan.h"
74#include "wlan_hdd_p2p.h"
75#include <linux/rtnetlink.h>
76#include "sap_api.h"
77#include <linux/semaphore.h>
78#include <linux/ctype.h>
79#include <linux/compat.h>
Arunk Khandavalli830c9692018-03-22 12:17:40 +053080#include <linux/reboot.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080081#ifdef MSM_PLATFORM
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080082#include <soc/qcom/subsystem_restart.h>
83#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080084#include <wlan_hdd_hostapd.h>
85#include <wlan_hdd_softap_tx_rx.h>
Jeff Johnson8bb61112018-03-31 13:33:54 -070086#include <wlan_hdd_green_ap.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080087#include "qwlan_version.h"
88#include "wma_types.h"
89#include "wlan_hdd_tdls.h"
90#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053091#include "cds_regdomain.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080092#endif /* FEATURE_WLAN_CH_AVOID */
Dustin Brownce46d1d2017-08-15 13:34:24 -070093#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070094#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -080095#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080096#include "wlan_hdd_nan.h"
97#include "wlan_hdd_debugfs.h"
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053098#include "wlan_hdd_debugfs_csr.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080099#include "wlan_hdd_driver_ops.h"
100#include "epping_main.h"
Poddar, Siddarth34872782017-08-10 14:08:51 +0530101#include "wlan_hdd_data_stall_detection.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800102
103#include <wlan_hdd_ipa.h>
104#include "hif.h"
105#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800106#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700107#include "wlan_hdd_tsf.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530108#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700109#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700110#include "wlan_hdd_lpass.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"
Nachiket Kukade85aa3782018-11-02 20:12:34 +0530127#include "nan_ucfg_api.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700128#include "wlan_reg_ucfg_api.h"
bings81fe50a2017-11-27 14:33:26 +0800129#include "wlan_dfs_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700130#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530131#include "sme_power_save_api.h"
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +0530132#include "enet.h"
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700133#include <cdp_txrx_cmn_struct.h>
Mohit Khanna70322002018-05-15 19:21:32 -0700134#include <dp_txrx.h>
Amar Singhal0928b192017-12-01 10:50:54 -0800135#include "wlan_hdd_sysfs.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530136#include "wlan_disa_ucfg_api.h"
Wu Gao52084c12018-05-17 20:47:11 +0800137#include "wlan_disa_obj_mgmt_api.h"
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +0530138#include "wlan_action_oui_ucfg_api.h"
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +0530139#include "wlan_ipa_ucfg_api.h"
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530140#include <target_if.h>
Alok Kumarb64650c2018-03-23 17:05:11 +0530141#include "wlan_hdd_nud_tracking.h"
Nachiket Kukaded0dd62e2018-05-21 18:39:22 +0530142#include "wlan_hdd_apf.h"
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -0700143#include "wlan_hdd_twt.h"
Rachit Kankane0dc3e852018-05-07 17:33:42 +0530144#include "qc_sap_ioctl.h"
Sandeep Puligillac5609d52018-05-17 19:23:41 -0700145#include "wlan_mlme_main.h"
Wu Gaoe5689792018-07-05 19:20:13 +0800146#include "wlan_p2p_cfg_api.h"
Wu Gao637d58a2018-12-08 10:37:34 +0800147#include "wlan_cfg80211_p2p.h"
Wu Gaobdb7f272018-07-05 19:33:26 +0800148#include "wlan_tdls_cfg_api.h"
Qiwei Caie689a262018-07-26 15:50:22 +0800149#include <wlan_hdd_rssi_monitor.h>
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +0530150#include "wlan_mlme_ucfg_api.h"
Sourav Mohapatra113685f2018-08-29 14:21:55 +0530151#include "wlan_fwol_ucfg_api.h"
Krunal Sonie71838d2018-09-27 10:45:05 -0700152#include "wlan_policy_mgr_ucfg.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530153#ifdef CNSS_GENL
154#include <net/cnss_nl.h>
155#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800156#include "wlan_reg_ucfg_api.h"
Zhang Qian47e22ce2018-01-04 15:38:38 +0800157#include "wlan_ocb_ucfg_api.h"
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -0800158#include <wlan_hdd_spectralscan.h>
gaurank kathpalia4a205fc2018-09-15 00:59:15 +0530159#include "wlan_green_ap_ucfg_api.h"
Liangwei Dong3abfe8f2018-09-20 02:25:44 -0400160#include <wlan_p2p_ucfg_api.h>
Mohit Khanna81418772018-10-30 14:14:46 -0700161#include <target_type.h>
Liangwei Dong3abfe8f2018-09-20 02:25:44 -0400162
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800163#ifdef MODULE
164#define WLAN_MODULE_NAME module_name(THIS_MODULE)
165#else
166#define WLAN_MODULE_NAME "wlan"
167#endif
168
169#ifdef TIMER_MANAGER
170#define TIMER_MANAGER_STR " +TIMER_MANAGER"
171#else
172#define TIMER_MANAGER_STR ""
173#endif
174
175#ifdef MEMORY_DEBUG
176#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
177#else
178#define MEMORY_DEBUG_STR ""
179#endif
180
Dustin Brownc1034df2018-02-07 14:51:32 -0800181#ifdef PANIC_ON_BUG
182#define PANIC_ON_BUG_STR " +PANIC_ON_BUG"
183#else
184#define PANIC_ON_BUG_STR ""
185#endif
186
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530187bool g_is_system_reboot_triggered;
Sachin Ahujadddd2632017-03-07 19:07:24 +0530188int wlan_start_ret_val;
189static DECLARE_COMPLETION(wlan_start_comp);
190static unsigned int dev_num = 1;
191static struct cdev wlan_hdd_state_cdev;
192static struct class *class;
193static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530194#ifndef MODULE
195static struct gwlan_loader *wlan_loader;
196static ssize_t wlan_boot_cb(struct kobject *kobj,
197 struct kobj_attribute *attr,
198 const char *buf, size_t count);
199struct gwlan_loader {
200 bool loaded_state;
201 struct kobject *boot_wlan_obj;
202 struct attribute_group *attr_group;
203};
204
205static struct kobj_attribute wlan_boot_attribute =
206 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
207
208static struct attribute *attrs[] = {
209 &wlan_boot_attribute.attr,
210 NULL,
211};
212
213#define MODULE_INITIALIZED 1
Qun Zhang4a83a462018-09-11 16:28:51 +0800214
215#ifdef MULTI_IF_NAME
216#define WLAN_LOADER_NAME "boot_" MULTI_IF_NAME
217#else
218#define WLAN_LOADER_NAME "boot_wlan"
219#endif
Arun Khandavallifae92942016-08-01 13:31:08 +0530220#endif
221
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530222#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
223#define MAX_OPS_NAME_STRING_SIZE 20
224
225static qdf_timer_t hdd_drv_ops_inactivity_timer;
Dustin Brown45ed4bb2017-12-18 12:00:13 -0800226static struct task_struct *hdd_drv_ops_task;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530227static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
228
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800229/* the Android framework expects this param even though we don't use it */
230#define BUF_LEN 20
231static char fwpath_buffer[BUF_LEN];
232static struct kparam_string fwpath = {
233 .string = fwpath_buffer,
234 .maxlen = BUF_LEN,
235};
236
237static char *country_code;
238static int enable_11d = -1;
239static int enable_dfs_chan_scan = -1;
240
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800241/*
242 * spinlock for synchronizing asynchronous request/response
243 * (full description of use in wlan_hdd_main.h)
244 */
245DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530246DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800247
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800248#define WLAN_NLINK_CESIUM 30
249
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530250static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800251
252#define WOW_MAX_FILTER_LISTS 1
253#define WOW_MAX_FILTERS_PER_LIST 4
254#define WOW_MIN_PATTERN_SIZE 6
255#define WOW_MAX_PATTERN_SIZE 64
256
Bala Venkatesh110b03e2018-07-10 16:02:08 +0530257/* max peer can be tdls peers + self peer + bss peer */
258#define HDD_MAX_VDEV_PEER_COUNT (HDD_MAX_NUM_TDLS_STA + 2)
Sourav Mohapatra808e3d42018-07-04 09:34:23 +0530259#define IS_IDLE_STOP (!cds_is_driver_unloading() && \
260 !cds_is_driver_recovering() && !cds_is_driver_loading())
Bala Venkatesh110b03e2018-07-10 16:02:08 +0530261
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800262#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
263static const struct wiphy_wowlan_support wowlan_support_reg_init = {
264 .flags = WIPHY_WOWLAN_ANY |
265 WIPHY_WOWLAN_MAGIC_PKT |
266 WIPHY_WOWLAN_DISCONNECT |
267 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
268 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
269 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
270 WIPHY_WOWLAN_4WAY_HANDSHAKE |
271 WIPHY_WOWLAN_RFKILL_RELEASE,
272 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
273 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
274 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
275};
276#endif
277
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700278static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
279 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
280 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
281 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
282 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
283 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
284 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
285 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
286 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
287 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
288 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
289 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
290 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
291 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
292 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
293 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
294 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
295 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
296 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
297 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
298 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
299 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
300 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
301 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
302 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
303 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
304 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
305 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
306 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
307 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
308 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
309 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
310 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
311 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
312 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700313 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700314 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700315 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530316 [QDF_MODULE_ID_GREEN_AP] = {QDF_TRACE_LEVEL_ALL},
Zhang Qian47e22ce2018-01-04 15:38:38 +0800317 [QDF_MODULE_ID_OCB] = {QDF_TRACE_LEVEL_ALL},
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530318 [QDF_MODULE_ID_IPA] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +0530319 [QDF_MODULE_ID_ACTION_OUI] = {QDF_TRACE_LEVEL_ALL},
Dustin Brown84f46ea2018-02-15 11:57:36 -0800320 [QDF_MODULE_ID_CONFIG] = {QDF_TRACE_LEVEL_ALL},
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +0530321 [QDF_MODULE_ID_MLME] = {QDF_TRACE_LEVEL_ALL},
Ashish Kumar Dhanotiya8d039c82018-07-11 20:41:14 +0530322 [QDF_MODULE_ID_TARGET] = {QDF_TRACE_LEVEL_ALL},
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -0700323 [QDF_MODULE_ID_CRYPTO] = {QDF_TRACE_LEVEL_ALL},
Sourav Mohapatra113685f2018-08-29 14:21:55 +0530324 [QDF_MODULE_ID_FWOL] = {QDF_TRACE_LEVEL_ALL},
Abhishek Singh0b0105f2018-09-25 10:44:16 +0530325 [QDF_MODULE_ID_SM_ENGINE] = {QDF_TRACE_LEVEL_ALL},
326 [QDF_MODULE_ID_CMN_MLME] = {QDF_TRACE_LEVEL_ALL},
Nachiket Kukade089b9832018-12-12 16:38:17 +0530327 [QDF_MODULE_ID_NAN] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700328};
329
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530330struct notifier_block hdd_netdev_notifier;
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530331struct notifier_block system_reboot_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800332
333struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800334#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700335static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800336#endif
337
Sachin Ahujadddd2632017-03-07 19:07:24 +0530338void hdd_start_complete(int ret)
339{
340 wlan_start_ret_val = ret;
341
342 complete(&wlan_start_comp);
343}
344
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800345/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530346 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700347 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530348 *
349 * Return: none
350 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700351static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530352{
Jeff Johnson9d295242017-08-29 14:39:48 -0700353 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530354
Dustin Brown920397d2017-12-13 16:27:50 -0800355 hdd_for_each_adapter(hdd_ctx, adapter)
356 hdd_send_rps_ind(adapter);
Nirav Shahbd36b062016-07-18 11:12:59 +0530357}
358
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530359#ifdef QCA_HL_NETDEV_FLOW_CONTROL
360void wlan_hdd_mod_fc_timer(struct hdd_adapter *adapter,
361 enum netif_action_type action)
362{
363 if (!adapter->tx_flow_timer_initialized)
364 return;
365
366 if (action == WLAN_WAKE_NON_PRIORITY_QUEUE) {
367 qdf_mc_timer_stop(&adapter->tx_flow_control_timer);
368 } else if (action == WLAN_STOP_NON_PRIORITY_QUEUE) {
369 QDF_STATUS status =
370 qdf_mc_timer_start(&adapter->tx_flow_control_timer,
371 WLAN_HDD_TX_FLOW_CONTROL_OS_Q_BLOCK_TIME);
372
373 if (!QDF_IS_STATUS_SUCCESS(status))
374 hdd_err("Failed to start tx_flow_control_timer");
375 else
376 adapter->
377 hdd_stats.tx_rx_stats.txflow_timer_cnt++;
378
379 adapter->hdd_stats.tx_rx_stats.txflow_pause_cnt++;
380 adapter->hdd_stats.tx_rx_stats.is_txflow_paused = true;
381 }
382}
383#endif /* QCA_HL_NETDEV_FLOW_CONTROL */
384
Alok Kumar2fad6442018-11-08 19:19:28 +0530385#ifdef MSM_PLATFORM
386void wlan_hdd_update_tcp_rx_param(struct hdd_context *hdd_ctx, void *data)
387{
388 if (!hdd_ctx) {
389 hdd_err("HDD context is null");
390 return;
391 }
392
393 if (!data) {
394 hdd_err("Data is null");
395 return;
396 }
397 if (hdd_ctx->config->enable_tcp_param_update)
398 wlan_hdd_send_tcp_param_update_event(hdd_ctx, data, 1);
399 else
400 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
401 WLAN_SVC_WLAN_TP_IND,
402 data,
403 sizeof(struct wlan_rx_tp_data));
404}
405
406void wlan_hdd_update_tcp_tx_param(struct hdd_context *hdd_ctx, void *data)
407{
408 enum wlan_tp_level next_tx_level;
409 struct wlan_tx_tp_data *tx_tp_data;
410
411 if (!hdd_ctx) {
412 hdd_err("HDD context is null");
413 return;
414 }
415
416 if (!data) {
417 hdd_err("Data is null");
418 return;
419 }
420
421 tx_tp_data = (struct wlan_tx_tp_data *)data;
422 next_tx_level = tx_tp_data->level;
423
424 if (hdd_ctx->config->enable_tcp_param_update)
425 wlan_hdd_send_tcp_param_update_event(hdd_ctx, data, 0);
426 else
427 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
428 WLAN_SVC_WLAN_TP_TX_IND,
429 &next_tx_level,
430 sizeof(next_tx_level));
431}
432
433/**
434 * wlan_hdd_send_tcp_param_update_event() - Send vendor event to update
435 * TCP parameter through Wi-Fi HAL
436 * @hdd_ctx: Pointer to HDD context
437 * @data: Parameters to update
438 * @dir: Direction(tx/rx) to update
439 *
440 * Return: None
441 */
442void wlan_hdd_send_tcp_param_update_event(struct hdd_context *hdd_ctx,
443 void *data,
444 uint8_t dir)
445{
446 struct sk_buff *vendor_event;
447 uint32_t event_len;
448 bool tcp_limit_output = false;
449 bool tcp_del_ack_ind_enabled = false;
450 bool tcp_adv_win_scl_enabled = false;
451 enum wlan_tp_level next_tp_level = WLAN_SVC_TP_NONE;
452
453 event_len = sizeof(uint8_t) + sizeof(uint8_t) + NLMSG_HDRLEN;
454
455 if (dir == 0) /*TX Flow */ {
456 struct wlan_tx_tp_data *tx_tp_data =
457 (struct wlan_tx_tp_data *)data;
458
459 next_tp_level = tx_tp_data->level;
460
461 if (tx_tp_data->tcp_limit_output) {
462 /* TCP_LIMIT_OUTPUT_BYTES */
463 event_len += sizeof(uint32_t);
464 tcp_limit_output = true;
465 }
466 } else if (dir == 1) /* RX Flow */ {
467 struct wlan_rx_tp_data *rx_tp_data =
468 (struct wlan_rx_tp_data *)data;
469
470 next_tp_level = rx_tp_data->level;
471
472 if (rx_tp_data->rx_tp_flags & TCP_DEL_ACK_IND_MASK) {
473 event_len += sizeof(uint32_t); /* TCP_DELACK_SEG */
474 tcp_del_ack_ind_enabled = true;
475 }
476 if (rx_tp_data->rx_tp_flags & TCP_ADV_WIN_SCL_MASK) {
477 event_len += sizeof(uint32_t); /* TCP_ADV_WIN_SCALE */
478 tcp_adv_win_scl_enabled = true;
479 }
480 } else {
481 hdd_err("Invalid Direction [%d]", dir);
482 return;
483 }
484
485 vendor_event =
486 cfg80211_vendor_event_alloc(
487 hdd_ctx->wiphy,
488 NULL, event_len,
489 QCA_NL80211_VENDOR_SUBCMD_THROUGHPUT_CHANGE_EVENT_INDEX,
490 GFP_KERNEL);
491
492 if (!vendor_event) {
493 hdd_err("cfg80211_vendor_event_alloc failed");
494 return;
495 }
496
497 if (nla_put_u8(
498 vendor_event,
499 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_DIRECTION,
500 dir))
501 goto tcp_param_change_nla_failed;
502
503 if (nla_put_u8(
504 vendor_event,
505 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_THROUGHPUT_LEVEL,
506 (next_tp_level == WLAN_SVC_TP_LOW ?
507 QCA_WLAN_THROUGHPUT_LEVEL_LOW :
508 QCA_WLAN_THROUGHPUT_LEVEL_HIGH)))
509 goto tcp_param_change_nla_failed;
510
511 if (tcp_limit_output &&
512 nla_put_u32(
513 vendor_event,
514 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_TCP_LIMIT_OUTPUT_BYTES,
515 (next_tp_level == WLAN_SVC_TP_LOW ?
516 TCP_LIMIT_OUTPUT_BYTES_LOW :
517 TCP_LIMIT_OUTPUT_BYTES_HI)))
518 goto tcp_param_change_nla_failed;
519
520 if (tcp_del_ack_ind_enabled &&
521 (nla_put_u32(
522 vendor_event,
523 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_TCP_DELACK_SEG,
524 (next_tp_level == WLAN_SVC_TP_LOW ?
525 TCP_DEL_ACK_LOW : TCP_DEL_ACK_HI))))
526 goto tcp_param_change_nla_failed;
527
528 if (tcp_adv_win_scl_enabled &&
529 (nla_put_u32(
530 vendor_event,
531 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_TCP_ADV_WIN_SCALE,
532 (next_tp_level == WLAN_SVC_TP_LOW ?
533 WIN_SCALE_LOW : WIN_SCALE_HI))))
534 goto tcp_param_change_nla_failed;
535
536 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
537 return;
538
539tcp_param_change_nla_failed:
540 hdd_err("nla_put api failed");
541 kfree_skb(vendor_event);
542}
543#endif /* MSM_PLATFORM */
544
Nirav Shahbd36b062016-07-18 11:12:59 +0530545/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800546 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
547 * @vdev_id: vdev_id
548 * @action: action type
549 * @reason: reason type
550 *
551 * Return: none
552 */
553void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
554 enum netif_action_type action, enum netif_reason_type reason)
555{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700556 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700557 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800558
559 if (!hdd_ctx) {
560 hdd_err("hdd ctx is NULL");
561 return;
562 }
563 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530564 wlan_hdd_mod_fc_timer(adapter, action);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800565 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800566}
567
568/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700569 * Store WLAN driver version and timestamp info in global variables such that
570 * crash debugger can extract them from driver debug symbol and crashdump for
571 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800572 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800573#ifdef BUILD_TAG
Rajeev Kumare555e2d2018-09-17 11:52:37 -0700574uint8_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 -0800575#else
Rajeev Kumare555e2d2018-09-17 11:52:37 -0700576uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR;
Naveen Rawat93836252017-06-20 16:30:59 -0700577#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800578
579/**
Liangwei Dong17bf2662018-01-05 02:02:05 -0500580 * hdd_get_valid_chan() - return current chan list from regulatory.
581 * @hdd_ctx: HDD context
582 * @chan_list: buf hold returned chan list
583 * @chan_num: input buf size and output returned chan num
584 *
585 * This function helps get current available chan list from regulatory
586 * module. It excludes the "disabled" and "invalid" channels.
587 *
588 * Return: 0 for success.
589 */
590static int hdd_get_valid_chan(struct hdd_context *hdd_ctx,
591 uint8_t *chan_list,
592 uint32_t *chan_num)
593{
594 int i = 0, j = 0;
595 struct regulatory_channel *cur_chan_list;
596 struct wlan_objmgr_pdev *pdev;
597
Dustin Brown07901ec2018-09-07 11:02:41 -0700598 if (!hdd_ctx || !hdd_ctx->pdev || !chan_list || !chan_num)
Liangwei Dong17bf2662018-01-05 02:02:05 -0500599 return -EINVAL;
600
Dustin Brown07901ec2018-09-07 11:02:41 -0700601 pdev = hdd_ctx->pdev;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500602 cur_chan_list = qdf_mem_malloc(NUM_CHANNELS *
603 sizeof(struct regulatory_channel));
604 if (!cur_chan_list)
605 return -ENOMEM;
606
607 if (wlan_reg_get_current_chan_list(pdev, cur_chan_list) !=
608 QDF_STATUS_SUCCESS) {
609 qdf_mem_free(cur_chan_list);
610 return -EINVAL;
611 }
612
613 for (i = 0; i < NUM_CHANNELS; i++) {
614 uint32_t ch = cur_chan_list[i].chan_num;
615 enum channel_state state = wlan_reg_get_channel_state(pdev,
616 ch);
617
618 if (state != CHANNEL_STATE_DISABLE &&
619 state != CHANNEL_STATE_INVALID &&
620 j < *chan_num) {
621 chan_list[j] = (uint8_t)ch;
622 j++;
623 }
624 }
625 *chan_num = j;
626 qdf_mem_free(cur_chan_list);
627 return 0;
628}
629
630/**
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530631 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
632 * @adapter: HDD adapter
633 * @chan_number: Channel number
634 * @chan_bw: Bandwidth
635 *
636 * Checks if the given bandwidth is valid for the given channel number.
637 *
638 * Return: 0 for success, non-zero for failure
639 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700640int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530641 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800642 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530643{
Liangwei Dong17bf2662018-01-05 02:02:05 -0500644 uint8_t chan[NUM_CHANNELS];
645 uint32_t len = NUM_CHANNELS, i;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530646 bool found = false;
Jeff Johnson16528362018-06-14 12:34:16 -0700647 mac_handle_t mac_handle;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500648 int ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530649
Jeff Johnson16528362018-06-14 12:34:16 -0700650 mac_handle = hdd_adapter_get_mac_handle(adapter);
651 if (!mac_handle) {
652 hdd_err("Invalid MAC handle");
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530653 return -EINVAL;
654 }
655
Liangwei Dong17bf2662018-01-05 02:02:05 -0500656 ret = hdd_get_valid_chan(adapter->hdd_ctx, chan,
657 &len);
658 if (ret) {
659 hdd_err("error %d in getting valid channel list", ret);
660 return ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530661 }
662
663 for (i = 0; i < len; i++) {
664 if (chan[i] == chan_number) {
665 found = true;
666 break;
667 }
668 }
669
670 if (found == false) {
671 hdd_err("Channel not in driver's valid channel list");
672 return -EOPNOTSUPP;
673 }
674
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700675 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
676 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530677 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
678 return -EINVAL;
679 }
680
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700681 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530682 if (chan_bw == CH_WIDTH_80MHZ) {
683 hdd_err("BW80 not possible in 2.4GHz band");
684 return -EINVAL;
685 }
686 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
687 (chan_bw != CH_WIDTH_MAX)) {
688 hdd_err("Only BW20 possible on channel 14");
689 return -EINVAL;
690 }
691 }
692
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700693 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530694 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
695 (chan_bw != CH_WIDTH_MAX)) {
696 hdd_err("Only BW20 possible on channel 165");
697 return -EINVAL;
698 }
699 }
700
701 return 0;
702}
703
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800704static int __hdd_netdev_notifier_call(struct notifier_block *nb,
705 unsigned long state, void *data)
706{
707#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
708 struct netdev_notifier_info *dev_notif_info = data;
709 struct net_device *dev = dev_notif_info->dev;
710#else
711 struct net_device *dev = data;
712#endif
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530713 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700714 struct hdd_context *hdd_ctx;
Min Liu8c5d99e2018-09-10 17:18:44 +0800715 struct wlan_objmgr_vdev *vdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800716
Dustin Brownfdf17c12018-03-14 12:55:34 -0700717 hdd_enter_dev(dev);
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800718
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800719 if (!dev->ieee80211_ptr) {
Dustin Brownaeb55642018-07-30 17:20:32 -0700720 hdd_debug("ieee80211_ptr is null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800721 return NOTIFY_DONE;
722 }
723
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530724 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
725 if (!hdd_ctx) {
726 hdd_err("HDD Context is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800727 return NOTIFY_DONE;
728 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800729
730 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -0700731 hdd_debug("%s: Driver module is closed", __func__);
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800732 return NOTIFY_DONE;
733 }
734
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530735 /* Make sure that this callback corresponds to our device. */
736 adapter = hdd_get_adapter_by_iface_name(hdd_ctx, dev->name);
737 if (!adapter) {
Dustin Brownaeb55642018-07-30 17:20:32 -0700738 hdd_debug("failed to look up adapter for '%s'", dev->name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800739 return NOTIFY_DONE;
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530740 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800741
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530742 if (adapter != WLAN_HDD_GET_PRIV_PTR(dev)) {
743 hdd_err("HDD adapter mismatch!");
744 return NOTIFY_DONE;
745 }
746
Dustin Brownaeb55642018-07-30 17:20:32 -0700747 if (cds_is_driver_recovering()) {
748 hdd_debug("Driver is recovering");
749 return NOTIFY_DONE;
750 }
751
752 if (cds_is_driver_in_bad_state()) {
753 hdd_debug("Driver is in failed recovery state");
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530754 return NOTIFY_DONE;
755 }
756
757 hdd_debug("%s New Net Device State = %lu", dev->name, state);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800758
759 switch (state) {
760 case NETDEV_REGISTER:
761 break;
762
763 case NETDEV_UNREGISTER:
764 break;
765
766 case NETDEV_UP:
Jeff Johnson16528362018-06-14 12:34:16 -0700767 sme_ch_avoid_update_req(hdd_ctx->mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800768 break;
769
770 case NETDEV_DOWN:
771 break;
772
773 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700774 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800775 complete(&adapter->linkup_event_var);
776 break;
777
778 case NETDEV_GOING_DOWN:
Min Liu8c5d99e2018-09-10 17:18:44 +0800779 vdev = hdd_objmgr_get_vdev(adapter);
780 if (!vdev)
781 break;
782 if (ucfg_scan_get_vdev_status(vdev) !=
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700783 SCAN_NOT_IN_PROGRESS) {
Dustin Brown07901ec2018-09-07 11:02:41 -0700784 wlan_abort_scan(hdd_ctx->pdev, INVAL_PDEV_ID,
785 adapter->session_id, INVALID_SCAN_ID,
786 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800787 }
Min Liu8c5d99e2018-09-10 17:18:44 +0800788 hdd_objmgr_put_vdev(adapter);
Min Liu9be5d4a2018-05-17 11:51:53 +0800789 cds_flush_work(&adapter->scan_block_work);
790 /* Need to clean up blocked scan request */
791 wlan_hdd_cfg80211_scan_block_cb(&adapter->scan_block_work);
Min Liu9be5d4a2018-05-17 11:51:53 +0800792 hdd_debug("Scan is not Pending from user");
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530793 /*
794 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
795 * of return status of hdd_stop call, kernel resets the IFF_UP
796 * flag after which driver does not send the cfg80211_scan_done.
797 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
798 */
Dustin Brown07901ec2018-09-07 11:02:41 -0700799 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800800 break;
801
802 default:
803 break;
804 }
805
806 return NOTIFY_DONE;
807}
808
809/**
810 * hdd_netdev_notifier_call() - netdev notifier callback function
811 * @nb: pointer to notifier block
812 * @state: state
813 * @ndev: ndev pointer
814 *
815 * Return: 0 on success, error number otherwise.
816 */
817static int hdd_netdev_notifier_call(struct notifier_block *nb,
818 unsigned long state,
819 void *ndev)
820{
821 int ret;
822
823 cds_ssr_protect(__func__);
824 ret = __hdd_netdev_notifier_call(nb, state, ndev);
825 cds_ssr_unprotect(__func__);
826
827 return ret;
828}
829
830struct notifier_block hdd_netdev_notifier = {
831 .notifier_call = hdd_netdev_notifier_call,
832};
833
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530834static int system_reboot_notifier_call(struct notifier_block *nb,
835 unsigned long msg_type, void *_unused)
836{
837 switch (msg_type) {
838 case SYS_DOWN:
839 case SYS_HALT:
840 case SYS_POWER_OFF:
841 g_is_system_reboot_triggered = true;
842 hdd_info("reboot, reason: %ld", msg_type);
843 break;
844 default:
845 break;
846 }
847
848 return NOTIFY_OK;
849}
850
851struct notifier_block system_reboot_notifier = {
852 .notifier_call = system_reboot_notifier_call,
853};
854
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800855/* variable to hold the insmod parameters */
856static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800857
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530858static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700859int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530860
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800861/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800862static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800863
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530864/**
865 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
866 * @ch_width: NL channel width
867 *
868 * Converts the NL channel width to the driver's internal representation
869 *
870 * Return: Converted channel width. In case of non matching NL channel width,
871 * CH_WIDTH_MAX will be returned.
872 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800873enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530874{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800875 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700876
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800877 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530878 switch (ch_width) {
879 case NL80211_CHAN_WIDTH_20_NOHT:
880 case NL80211_CHAN_WIDTH_20:
881 return CH_WIDTH_20MHZ;
882 case NL80211_CHAN_WIDTH_40:
883 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530884 case NL80211_CHAN_WIDTH_80:
885 return CH_WIDTH_80MHZ;
886 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800887 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
888 return CH_WIDTH_80P80MHZ;
889 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
890 return CH_WIDTH_160MHZ;
891 else
892 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530893 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800894 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
895 return CH_WIDTH_160MHZ;
896 else
897 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530898 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800899 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530900 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800901 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530902 default:
903 hdd_err("Invalid channel width %d, setting to default",
904 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800905 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530906 }
907}
908
Dustin Brown56377e12018-10-10 17:04:04 -0700909QDF_STATUS hdd_nl_to_qdf_iface_type(enum nl80211_iftype nl_type,
910 enum QDF_OPMODE *out_qdf_type)
911{
912 switch (nl_type) {
913 case NL80211_IFTYPE_ADHOC:
914 *out_qdf_type = QDF_IBSS_MODE;
915 break;
916 case NL80211_IFTYPE_AP:
917 *out_qdf_type = QDF_SAP_MODE;
918 break;
919 case NL80211_IFTYPE_MONITOR:
920 *out_qdf_type = QDF_MONITOR_MODE;
921 break;
922 case NL80211_IFTYPE_OCB:
923 *out_qdf_type = QDF_OCB_MODE;
924 break;
925 case NL80211_IFTYPE_P2P_CLIENT:
926 *out_qdf_type = QDF_P2P_CLIENT_MODE;
927 break;
928 case NL80211_IFTYPE_P2P_DEVICE:
929 *out_qdf_type = QDF_P2P_DEVICE_MODE;
930 break;
931 case NL80211_IFTYPE_P2P_GO:
932 *out_qdf_type = QDF_P2P_GO_MODE;
933 break;
934 case NL80211_IFTYPE_STATION:
935 *out_qdf_type = QDF_STA_MODE;
936 break;
937 case NL80211_IFTYPE_WDS:
938 *out_qdf_type = QDF_WDS_MODE;
939 break;
940 default:
941 hdd_err("Invalid nl80211 interface type %d", nl_type);
942 return QDF_STATUS_E_INVAL;
943 }
944
945 return QDF_STATUS_SUCCESS;
946}
947
Jeff Johnson16528362018-06-14 12:34:16 -0700948uint8_t wlan_hdd_find_opclass(mac_handle_t mac_handle, uint8_t channel,
949 uint8_t bw_offset)
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530950{
951 uint8_t opclass = 0;
952
Jeff Johnson16528362018-06-14 12:34:16 -0700953 sme_get_opclass(mac_handle, channel, bw_offset, &opclass);
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530954 return opclass;
955}
956
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800957/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530958 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530959 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800960 * @bitmask: Bitmask of log levels to be enabled
961 *
962 * Called immediately after the cfg.ini is read in order to configure
963 * the desired trace levels.
964 *
965 * Return: None
966 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530967int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800968{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530969 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530970 int qdf_print_idx = -1;
971 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800972 /*
973 * if the bitmask is the default value, then a bitmask was not
974 * specified in cfg.ini, so leave the logging level alone (it
975 * will remain at the "compiled in" default value)
976 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700977 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530978 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800979
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530980 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800981
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530982 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530983 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530984 QDF_TRACE_LEVEL_NONE, 0);
985
986 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530987 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800988 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530989 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800990 while (0 != bitmask) {
991 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530992 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530993 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530994 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530995 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800996 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700997
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800998 level++;
999 bitmask >>= 1;
1000 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301001 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001002}
1003
Dustin Brownda351e32018-07-23 15:48:22 -07001004int __wlan_hdd_validate_context(struct hdd_context *hdd_ctx, const char *func)
Chris Guo1751acf2017-07-03 14:09:01 +08001005{
Dustin Brownda351e32018-07-23 15:48:22 -07001006 if (!hdd_ctx) {
1007 hdd_err("HDD context is null (via %s)", func);
1008 return -ENODEV;
1009 }
1010
1011 if (!hdd_ctx->config) {
1012 hdd_err("HDD config is null (via %s)", func);
Chris Guo1751acf2017-07-03 14:09:01 +08001013 return -ENODEV;
1014 }
1015
1016 if (cds_is_driver_recovering()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001017 hdd_debug("Recovery in progress (via %s); state:0x%x",
1018 func, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001019 return -EAGAIN;
1020 }
1021
Yue Ma9f275d92017-09-14 16:58:41 -07001022 if (cds_is_load_or_unload_in_progress()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001023 hdd_debug("Load/unload in progress (via %s); state:0x%x",
1024 func, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001025 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -07001026 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05301027
Dustin Brownda351e32018-07-23 15:48:22 -07001028 if (hdd_ctx->start_modules_in_progress) {
1029 hdd_debug("Start modules in progress (via %s)", func);
1030 return -EAGAIN;
1031 }
1032
1033 if (hdd_ctx->stop_modules_in_progress) {
1034 hdd_debug("Stop modules in progress (via %s)", func);
Arun Khandavallia172c3e2016-08-26 17:33:13 +05301035 return -EAGAIN;
1036 }
1037
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301038 if (cds_is_driver_in_bad_state()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001039 hdd_debug("Driver in bad state (via %s); state:0x%x",
1040 func, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +05301041 return -EAGAIN;
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301042 }
1043
Arunk Khandavalli2859fa12018-02-14 10:46:26 +05301044 if (cds_is_fw_down()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001045 hdd_debug("FW is down (via %s); state:0x%x",
1046 func, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +05301047 return -EAGAIN;
Arunk Khandavalli2859fa12018-02-14 10:46:26 +05301048 }
1049
Liangwei Dong858feb12018-05-21 01:52:46 -04001050 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
Dustin Brownda351e32018-07-23 15:48:22 -07001051 hdd_debug("Driver mode change in progress (via %s)", func);
Liangwei Dong858feb12018-05-21 01:52:46 -04001052 return -EAGAIN;
1053 }
1054
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001055 return 0;
1056}
1057
Dustin Browna8700cc2018-08-07 12:04:47 -07001058int __hdd_validate_adapter(struct hdd_adapter *adapter, const char *func)
Dustin Brownf13b8c32017-05-19 17:23:08 -07001059{
1060 if (!adapter) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001061 hdd_err("adapter is null (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001062 return -EINVAL;
1063 }
1064
1065 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001066 hdd_err("bad adapter magic (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001067 return -EINVAL;
1068 }
1069
1070 if (!adapter->dev) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001071 hdd_err("adapter net_device is null (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001072 return -EINVAL;
1073 }
1074
1075 if (!(adapter->dev->flags & IFF_UP)) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001076 hdd_debug_rl("adapter '%s' is not up (via %s)",
1077 adapter->dev->name, func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001078 return -EAGAIN;
1079 }
1080
Dustin Browna8700cc2018-08-07 12:04:47 -07001081 return __wlan_hdd_validate_session_id(adapter->session_id, func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001082}
1083
Dustin Brown63500612018-08-07 11:36:09 -07001084int __wlan_hdd_validate_session_id(uint8_t session_id, const char *func)
1085{
1086 if (session_id == CSR_SESSION_ID_INVALID) {
1087 hdd_debug_rl("adapter is not up (via %s)", func);
1088 return -EINVAL;
1089 }
1090
1091 if (session_id >= CSR_ROAM_SESSION_MAX) {
1092 hdd_err("bad session Id:%u (via %s)", session_id, func);
1093 return -EINVAL;
1094 }
1095
1096 return 0;
1097}
1098
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05301099QDF_STATUS __wlan_hdd_validate_mac_address(struct qdf_mac_addr *mac_addr,
1100 const char *func)
1101{
1102 if (!mac_addr) {
1103 hdd_err("Received NULL mac address (via %s)", func);
1104 return QDF_STATUS_E_INVAL;
1105 }
1106
1107 if (qdf_is_macaddr_zero(mac_addr)) {
1108 hdd_err("MAC is all zero (via %s)", func);
1109 return QDF_STATUS_E_INVAL;
1110 }
1111
1112 if (qdf_is_macaddr_broadcast(mac_addr)) {
1113 hdd_err("MAC is Broadcast (via %s)", func);
1114 return QDF_STATUS_E_INVAL;
1115 }
1116
1117 if (QDF_NET_IS_MAC_MULTICAST(mac_addr->bytes)) {
1118 hdd_err("MAC is Multicast (via %s)", func);
1119 return QDF_STATUS_E_INVAL;
1120 }
1121
1122 return QDF_STATUS_SUCCESS;
1123}
1124
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001125/**
Arun Khandavallica892f62017-05-26 14:25:50 +05301126 * wlan_hdd_validate_modules_state() - Check modules status
1127 * @hdd_ctx: HDD context pointer
1128 *
1129 * Check's the driver module's state and returns true if the
1130 * modules are enabled returns false if modules are closed.
1131 *
1132 * Return: True if modules are enabled or false.
1133 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001134bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +05301135{
1136 mutex_lock(&hdd_ctx->iface_change_lock);
1137 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
1138 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown5e89ef82018-03-14 11:50:23 -07001139 hdd_info("Modules not enabled, Present status: %d",
1140 hdd_ctx->driver_status);
Arun Khandavallica892f62017-05-26 14:25:50 +05301141 return false;
1142 }
1143 mutex_unlock(&hdd_ctx->iface_change_lock);
1144 return true;
1145}
1146
1147/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001148 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -07001149 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001150 *
1151 * This function sets the IBSS power save config parameters to WMA
1152 * which will send it to firmware if FW supports IBSS power save
1153 * before vdev start.
1154 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301155 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001156 * on failure.
1157 */
Jeff Johnson9d295242017-08-29 14:39:48 -07001158QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001159{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001160 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001161
1162 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001163 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301164 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001165 }
1166
Manikandan Mohan2bd09772018-11-28 18:27:32 -08001167 return ucfg_mlme_ibss_power_save_setup(hdd_ctx->psoc,
1168 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001169}
1170
Yue Macd359b72017-10-03 15:21:00 -07001171#ifdef FEATURE_RUNTIME_PM
1172/**
1173 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
1174 * @hdd_ctx: HDD context
1175 *
1176 * Return: None
1177 */
1178static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
1179{
1180 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1181
Yue Macd359b72017-10-03 15:21:00 -07001182 qdf_runtime_lock_init(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001183 qdf_runtime_lock_init(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001184
Dustin Brown07901ec2018-09-07 11:02:41 -07001185 wlan_scan_runtime_pm_init(hdd_ctx->pdev);
Yue Macd359b72017-10-03 15:21:00 -07001186}
1187
1188/**
1189 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1190 * @hdd_ctx: HDD Context
1191 *
1192 * Return: None
1193 */
1194static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1195{
1196 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1197
Yue Macd359b72017-10-03 15:21:00 -07001198 qdf_runtime_lock_deinit(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001199 qdf_runtime_lock_deinit(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001200
Dustin Brown07901ec2018-09-07 11:02:41 -07001201 wlan_scan_runtime_pm_deinit(hdd_ctx->pdev);
Yue Macd359b72017-10-03 15:21:00 -07001202}
1203
Yue Macd359b72017-10-03 15:21:00 -07001204#else /* FEATURE_RUNTIME_PM */
1205static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1206static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Yue Macd359b72017-10-03 15:21:00 -07001207#endif /* FEATURE_RUNTIME_PM */
1208
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001209#define INTF_MACADDR_MASK 0x7
1210
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301211void hdd_update_macaddr(struct hdd_context *hdd_ctx,
1212 struct qdf_mac_addr hw_macaddr, bool generate_mac_auto)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001213{
1214 int8_t i;
1215 uint8_t macaddr_b3, tmp_br3;
1216
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301217 /*
1218 * If "generate_mac_auto" is true, it indicates that all the
1219 * addresses are derived addresses, else the first addresses
1220 * is not derived address (It is provided by fw).
1221 */
1222 if (!generate_mac_auto) {
1223 qdf_mem_copy(hdd_ctx->provisioned_mac_addr[0].bytes,
1224 hw_macaddr.bytes, QDF_MAC_ADDR_SIZE);
1225 hdd_ctx->num_provisioned_addr++;
1226 hdd_info("hdd_ctx->provisioned_mac_addr[0]: "
1227 MAC_ADDRESS_STR,
1228 MAC_ADDR_ARRAY(hdd_ctx->
1229 provisioned_mac_addr[0].bytes));
1230 } else {
1231 qdf_mem_copy(hdd_ctx->derived_mac_addr[0].bytes,
1232 hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301233 QDF_MAC_ADDR_SIZE);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301234 hdd_ctx->num_derived_addr++;
1235 hdd_info("hdd_ctx->derived_mac_addr[0]: "
1236 MAC_ADDRESS_STR,
1237 MAC_ADDR_ARRAY(hdd_ctx->derived_mac_addr[0].bytes));
1238 }
1239 for (i = hdd_ctx->num_derived_addr; i < (QDF_MAX_CONCURRENCY_PERSONA -
1240 hdd_ctx->num_provisioned_addr);
1241 i++) {
1242 qdf_mem_copy(hdd_ctx->derived_mac_addr[i].bytes,
1243 hw_macaddr.bytes,
1244 QDF_MAC_ADDR_SIZE);
1245 macaddr_b3 = hdd_ctx->derived_mac_addr[i].bytes[3];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001246 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1247 INTF_MACADDR_MASK;
1248 macaddr_b3 += tmp_br3;
1249
1250 /* XOR-ing bit-24 of the mac address. This will give enough
1251 * mac address range before collision
1252 */
1253 macaddr_b3 ^= (1 << 7);
1254
1255 /* Set locally administered bit */
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301256 hdd_ctx->derived_mac_addr[i].bytes[0] |= 0x02;
1257 hdd_ctx->derived_mac_addr[i].bytes[3] = macaddr_b3;
1258 hdd_info("hdd_ctx->derived_mac_addr[%d]: "
1259 MAC_ADDRESS_STR, i,
1260 MAC_ADDR_ARRAY(hdd_ctx->derived_mac_addr[i].bytes));
1261 hdd_ctx->num_derived_addr++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001262 }
1263}
1264
Kabilan Kannan44a58372017-12-06 18:16:11 -08001265static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1266{
Dustin Brown1dbefe62018-09-11 16:32:03 -07001267 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001268 struct tdls_start_params tdls_cfg;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001269 QDF_STATUS status;
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301270 struct wlan_mlme_nss_chains vdev_ini_cfg;
1271
1272 /* Populate the nss chain params from ini for this vdev type */
1273 sme_populate_nss_chain_params(hdd_ctx->mac_handle, &vdev_ini_cfg,
1274 QDF_TDLS_MODE,
1275 hdd_ctx->num_rf_chains);
Kabilan Kannan44a58372017-12-06 18:16:11 -08001276
Dustin Brown1dbefe62018-09-11 16:32:03 -07001277 cfg_tdls_set_vdev_nss_2g(hdd_ctx->psoc,
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301278 vdev_ini_cfg.rx_nss[NSS_CHAINS_BAND_2GHZ]);
Dustin Brown1dbefe62018-09-11 16:32:03 -07001279 cfg_tdls_set_vdev_nss_5g(hdd_ctx->psoc,
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301280 vdev_ini_cfg.rx_nss[NSS_CHAINS_BAND_5GHZ]);
jiad7b8a5e02018-11-26 16:37:57 +08001281 hdd_init_tdls_config(&tdls_cfg);
Kabilan Kannan44a58372017-12-06 18:16:11 -08001282 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1283 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1284 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1285 tdls_cfg.tdls_evt_cb_data = psoc;
Jeff Johnson1d40f5b2018-03-02 08:35:53 -08001286 tdls_cfg.tdls_peer_context = hdd_ctx;
1287 tdls_cfg.tdls_reg_peer = hdd_tdls_register_peer;
1288 tdls_cfg.tdls_dereg_peer = hdd_tdls_deregister_peer;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001289 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1290 tdls_cfg.tdls_wmm_cb_data = psoc;
1291 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1292 tdls_cfg.tdls_rx_cb_data = psoc;
1293 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1294
1295 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1296 if (status != QDF_STATUS_SUCCESS) {
1297 hdd_err("failed pmo psoc configuration");
1298 return -EINVAL;
1299 }
1300
1301 hdd_ctx->tdls_umac_comp_active = true;
1302 /* enable napier specific tdls data path */
1303 hdd_ctx->tdls_nap_active = true;
1304
1305 return 0;
1306}
1307
Wu Gaoca416ff2018-09-17 11:05:07 +08001308#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1309static void hdd_update_roam_offload(struct hdd_context *hdd_ctx,
1310 struct wma_tgt_services *cfg)
1311{
1312 bool roam_offload_enable;
1313
Dustin Brown1dbefe62018-09-11 16:32:03 -07001314 ucfg_mlme_get_roaming_offload(hdd_ctx->psoc, &roam_offload_enable);
1315 ucfg_mlme_set_roaming_offload(hdd_ctx->psoc,
Wu Gaoca416ff2018-09-17 11:05:07 +08001316 roam_offload_enable &
1317 cfg->en_roam_offload);
1318}
1319#else
1320static inline void hdd_update_roam_offload(struct hdd_context *hdd_ctx,
1321 struct wma_tgt_services *cfg)
1322{
1323}
1324#endif
1325
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001326static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001327 struct wma_tgt_services *cfg)
1328{
1329 struct hdd_config *config = hdd_ctx->config;
Wu Gao66454f12018-09-26 19:55:41 +08001330 bool arp_offload_enable;
Wu Gao1ab05582018-11-08 16:22:49 +08001331 bool mawc_enabled;
Wu Gaobdb7f272018-07-05 19:33:26 +08001332#ifdef FEATURE_WLAN_TDLS
1333 bool tdls_support;
1334 bool tdls_off_channel;
1335 bool tdls_buffer_sta;
1336 uint32_t tdls_uapsd_mask;
1337#endif
jiad7b8a5e02018-11-26 16:37:57 +08001338 bool value;
1339
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001340 /* Set up UAPSD */
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05301341 ucfg_mlme_set_sap_uapsd_flag(hdd_ctx->psoc, cfg->uapsd);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001342
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001343 /* 11AX mode support */
1344 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1345 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1346 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1347
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001348 /* 11AC mode support */
1349 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1350 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1351 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001352
1353 /* ARP offload: override user setting if invalid */
Wu Gao66454f12018-09-26 19:55:41 +08001354 arp_offload_enable =
1355 ucfg_pmo_is_arp_offload_enabled(hdd_ctx->psoc);
1356 ucfg_pmo_set_arp_offload_enabled(hdd_ctx->psoc,
1357 arp_offload_enable & cfg->arp_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001358#ifdef FEATURE_WLAN_SCAN_PNO
1359 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001360 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001361 if (cfg->pno_offload)
Pragaspathi Thilagaraj24789d32018-12-10 22:28:03 +05301362 ucfg_scan_set_pno_offload(hdd_ctx->psoc, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001363#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001364#ifdef FEATURE_WLAN_TDLS
Dustin Brown1dbefe62018-09-11 16:32:03 -07001365 cfg_tdls_get_support_enable(hdd_ctx->psoc, &tdls_support);
1366 cfg_tdls_set_support_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001367 tdls_support & cfg->en_tdls);
1368
Dustin Brown1dbefe62018-09-11 16:32:03 -07001369 cfg_tdls_get_off_channel_enable(hdd_ctx->psoc, &tdls_off_channel);
1370 cfg_tdls_set_off_channel_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001371 tdls_off_channel &&
1372 cfg->en_tdls_offchan);
1373
Dustin Brown1dbefe62018-09-11 16:32:03 -07001374 cfg_tdls_get_buffer_sta_enable(hdd_ctx->psoc, &tdls_buffer_sta);
1375 cfg_tdls_set_buffer_sta_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001376 tdls_buffer_sta &&
1377 cfg->en_tdls_uapsd_buf_sta);
1378
Dustin Brown1dbefe62018-09-11 16:32:03 -07001379 cfg_tdls_get_uapsd_mask(hdd_ctx->psoc, &tdls_uapsd_mask);
Wu Gaobdb7f272018-07-05 19:33:26 +08001380 if (tdls_uapsd_mask && cfg->en_tdls_uapsd_sleep_sta)
Dustin Brown1dbefe62018-09-11 16:32:03 -07001381 cfg_tdls_set_sleep_sta_enable(hdd_ctx->psoc, true);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001382 else
Dustin Brown1dbefe62018-09-11 16:32:03 -07001383 cfg_tdls_set_sleep_sta_enable(hdd_ctx->psoc, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001384#endif
Wu Gaoca416ff2018-09-17 11:05:07 +08001385 hdd_update_roam_offload(hdd_ctx, cfg);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05301386
Dustin Brown05d81302018-09-11 16:49:22 -07001387 if (ucfg_mlme_get_sap_get_peer_info(hdd_ctx->psoc, &value) ==
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05301388 QDF_STATUS_SUCCESS)
1389 value &= cfg->get_peer_info_enabled;
1390
Wu Gao1ab05582018-11-08 16:22:49 +08001391 ucfg_mlme_is_mawc_enabled(hdd_ctx->psoc, &mawc_enabled);
1392 ucfg_mlme_set_mawc_enabled(hdd_ctx->psoc,
1393 mawc_enabled & cfg->is_fw_mawc_capable);
Kabilan Kannan44a58372017-12-06 18:16:11 -08001394 hdd_update_tdls_config(hdd_ctx);
Jeff Johnson16528362018-06-14 12:34:16 -07001395 sme_update_tgt_services(hdd_ctx->mac_handle, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001396}
1397
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001398/**
1399 * hdd_update_vdev_nss() - sets the vdev nss
1400 * @hdd_ctx: HDD context
1401 *
1402 * Sets the Nss per vdev type based on INI
1403 *
1404 * Return: None
1405 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001406static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001407{
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001408 uint8_t max_supp_nss = 1;
Jeff Johnson16528362018-06-14 12:34:16 -07001409 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301410 QDF_STATUS status;
1411 bool bval;
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001412
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301413 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
1414 if (!QDF_IS_STATUS_SUCCESS(status))
1415 hdd_err("unable to get vht_enable2x2");
1416
1417 if (bval && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001418 max_supp_nss = 2;
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301419
1420 hdd_debug("max nss %d", max_supp_nss);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001421
Jeff Johnson16528362018-06-14 12:34:16 -07001422 mac_handle = hdd_ctx->mac_handle;
1423 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301424 NSS_CHAINS_BAND_2GHZ);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001425
Jeff Johnson16528362018-06-14 12:34:16 -07001426 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301427 NSS_CHAINS_BAND_5GHZ);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001428}
1429
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301430/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301431 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1432 * @hdd_ctx: HDD context
1433 *
1434 * Updates wiphy vhtcap fields
1435 *
1436 * Return: None
1437 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001438static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301439{
1440 struct ieee80211_supported_band *band_5g =
1441 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301442 QDF_STATUS status;
1443 uint8_t value = 0, value1 = 0;
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301444
1445 if (!band_5g) {
1446 hdd_debug("5GHz band disabled, skipping capability population");
1447 return;
1448 }
1449
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301450 status = ucfg_mlme_cfg_get_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
1451 &value);
1452 if (!QDF_IS_STATUS_SUCCESS(status))
1453 hdd_err("unable to get tx_bfee_ant_supp");
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301454
Abhinav Kumare057b412018-10-09 17:28:16 +05301455 band_5g->vht_cap.cap |=
1456 (value << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301457
1458 value1 = NUM_OF_SOUNDING_DIMENSIONS;
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301459 band_5g->vht_cap.cap |=
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301460 (value1 << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301461
Dustin Brown7e761c72018-07-31 13:50:17 -07001462 hdd_debug("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301463 band_5g->vht_cap.cap, value, value1);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301464}
1465
1466/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301467 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1468 * @hdd_ctx: HDD context
1469 *
1470 * Sets the DBS capability as per INI and firmware capability
1471 *
1472 * Return: None
1473 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001474static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301475{
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301476 uint8_t hw_dbs_capable = 0;
Krunal Sonidf29bc42018-11-15 13:26:29 -08001477 uint8_t dual_mac_feature = DISABLE_DBS_CXN_AND_SCAN;
1478 QDF_STATUS status;
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301479
Krunal Sonidf29bc42018-11-15 13:26:29 -08001480 status = ucfg_policy_mgr_get_dual_mac_feature(hdd_ctx->psoc,
1481 &dual_mac_feature);
1482 if (status != QDF_STATUS_SUCCESS)
1483 hdd_err("can't get dual_mac_feature value");
1484 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->psoc)) {
1485 switch (dual_mac_feature) {
1486 case ENABLE_DBS_CXN_AND_SCAN:
1487 case ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF:
1488 case ENABLE_DBS_CXN_AND_DISABLE_SIMULTANEOUS_SCAN:
1489 hw_dbs_capable = 1;
1490 break;
1491 default:
1492 hw_dbs_capable = 0;
1493 break;
1494 }
1495 }
Jeff Johnson16528362018-06-14 12:34:16 -07001496 sme_update_hw_dbs_capable(hdd_ctx->mac_handle, hw_dbs_capable);
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301497}
1498
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001499static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001500 struct wma_tgt_ht_cap *cfg)
1501{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301502 QDF_STATUS status;
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301503 qdf_size_t value_len;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301504 uint32_t value;
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05301505 uint8_t mpdu_density;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301506 struct mlme_ht_capabilities_info ht_cap_info;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001507 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301508 bool b_enable1x1;
Jeff Johnson16528362018-06-14 12:34:16 -07001509
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001510 /* get the MPDU density */
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05301511 status = ucfg_mlme_get_ht_mpdu_density(hdd_ctx->psoc, &mpdu_density);
1512 if (QDF_IS_STATUS_ERROR(status)) {
1513 hdd_err("could not get HT MPDU Density");
1514 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001515 }
1516
1517 /*
1518 * MPDU density:
1519 * override user's setting if value is larger
1520 * than the one supported by target
1521 */
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05301522 if (mpdu_density > cfg->mpdu_density) {
1523 status = ucfg_mlme_set_ht_mpdu_density(hdd_ctx->psoc,
1524 cfg->mpdu_density);
1525 if (QDF_IS_STATUS_ERROR(status))
1526 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001527 }
1528
1529 /* get the HT capability info */
Dustin Brown1dbefe62018-09-11 16:32:03 -07001530 status = ucfg_mlme_get_ht_cap_info(hdd_ctx->psoc, &ht_cap_info);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301531 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001532 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001533 return;
1534 }
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301535
1536 /* check and update RX STBC */
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301537 if (ht_cap_info.rx_stbc && !cfg->ht_rx_stbc)
1538 ht_cap_info.rx_stbc = cfg->ht_rx_stbc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001539
1540 /* Set the LDPC capability */
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301541 ht_cap_info.adv_coding_cap = cfg->ht_rx_ldpc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001542
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301543 if (ht_cap_info.short_gi_20_mhz && !cfg->ht_sgi_20)
1544 ht_cap_info.short_gi_20_mhz = cfg->ht_sgi_20;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001545
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301546 if (ht_cap_info.short_gi_40_mhz && !cfg->ht_sgi_40)
1547 ht_cap_info.short_gi_40_mhz = cfg->ht_sgi_40;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001548
1549 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1550 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1551
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301552 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &b_enable1x1);
1553 if (!QDF_IS_STATUS_SUCCESS(status))
1554 hdd_err("unable to get vht_enable2x2");
1555
1556 b_enable1x1 = b_enable1x1 && (cfg->num_rf_chains == 2);
1557
1558 status = ucfg_mlme_set_vht_enable2x2(hdd_ctx->psoc, b_enable1x1);
1559 if (!QDF_IS_STATUS_SUCCESS(status))
1560 hdd_err("unable to set vht_enable2x2");
1561
Abhinav Kumare057b412018-10-09 17:28:16 +05301562 if (!b_enable1x1) {
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301563 ht_cap_info.tx_stbc = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001564
1565 /* 1x1 */
1566 /* Update Rx Highest Long GI data Rate */
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301567 status = ucfg_mlme_cfg_set_vht_rx_supp_data_rate(
1568 hdd_ctx->psoc,
1569 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1);
1570 if (!QDF_IS_STATUS_SUCCESS(status))
1571 hdd_err("Failed to set rx_supp_data_rate");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001572 /* Update Tx Highest Long GI data Rate */
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301573 status = ucfg_mlme_cfg_set_vht_tx_supp_data_rate(
1574 hdd_ctx->psoc,
1575 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1);
1576 if (!QDF_IS_STATUS_SUCCESS(status))
1577 hdd_err("Failed to set tx_supp_data_rate");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001578 }
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301579 if (!(cfg->ht_tx_stbc && b_enable1x1))
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301580 ht_cap_info.tx_stbc = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001581
Dustin Brown1dbefe62018-09-11 16:32:03 -07001582 status = ucfg_mlme_set_ht_cap_info(hdd_ctx->psoc, ht_cap_info);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301583 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001584 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001585#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301586 value_len = SIZE_OF_SUPPORTED_MCS_SET;
1587 if (ucfg_mlme_get_supported_mcs_set(
1588 hdd_ctx->psoc, mcs_set,
1589 &value_len) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001590 hdd_debug("Read MCS rate set");
gaurank kathpalia18b49362018-04-15 23:12:03 +05301591 if (cfg->num_rf_chains > SIZE_OF_SUPPORTED_MCS_SET)
1592 cfg->num_rf_chains = SIZE_OF_SUPPORTED_MCS_SET;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301593
1594 if (b_enable1x1) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001595 for (value = 0; value < cfg->num_rf_chains; value++)
1596 mcs_set[value] =
1597 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1598
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301599 status = ucfg_mlme_set_supported_mcs_set(
1600 hdd_ctx->psoc,
1601 mcs_set,
1602 (qdf_size_t)SIZE_OF_SUPPORTED_MCS_SET);
1603 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001604 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001605 }
1606 }
1607#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1608}
1609
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001610static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001611 struct wma_tgt_vht_cap *cfg)
1612{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301613 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001614 struct wiphy *wiphy = hdd_ctx->wiphy;
1615 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001616 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001617 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001618 struct wma_caps_per_phy caps_per_phy;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301619 uint8_t val = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001620
Dustin Brown5e06bd32016-10-04 12:49:10 -07001621 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001622 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001623 return;
1624 }
1625
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301626 status = ucfg_mlme_update_vht_cap(hdd_ctx->psoc, cfg);
1627 if (QDF_IS_STATUS_ERROR(status))
1628 hdd_err("could not update vht capabilities");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001629
1630 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1631 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1632 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1633 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1634 else
1635 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1636
1637
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001638 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
Abhinav Kumare057b412018-10-09 17:28:16 +05301639 status = ucfg_mlme_set_vht_ch_width(hdd_ctx->psoc,
1640 VHT_CAP_160_AND_80P80_SUPP);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301641 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001642 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001643 band_5g->vht_cap.cap |=
1644 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001645 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1646 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
Abhinav Kumare057b412018-10-09 17:28:16 +05301647 status = ucfg_mlme_set_vht_ch_width(hdd_ctx->psoc,
1648 VHT_CAP_160_SUPP);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301649 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001650 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001651 band_5g->vht_cap.cap |=
1652 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001653 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1654 }
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001655
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301656 status =
1657 ucfg_mlme_cfg_get_vht_chan_width(hdd_ctx->psoc, &val);
1658 if (QDF_IS_STATUS_ERROR(status))
1659 hdd_err("could not get channel_width");
1660
1661 val = QDF_MIN(val, ch_width);
Abhinav Kumare057b412018-10-09 17:28:16 +05301662 status = ucfg_mlme_set_vht_ch_width(hdd_ctx->psoc, val);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301663 if (QDF_IS_STATUS_ERROR(status))
1664 hdd_err("could not set the channel width");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001665
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001666 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001667 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001668 hdd_debug("VHT RxLDPC capability is set");
1669 } else {
1670 /*
1671 * Get the RX LDPC capability for the NON DBS
1672 * hardware mode for 5G band
1673 */
1674 status = wma_get_caps_for_phyidx_hwmode(&caps_per_phy,
1675 HW_MODE_DBS_NONE, CDS_BAND_5GHZ);
1676 if ((QDF_IS_STATUS_SUCCESS(status)) &&
1677 (caps_per_phy.vht_5g & WMI_VHT_CAP_RX_LDPC)) {
1678 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1679 hdd_debug("VHT RX LDPC capability is set");
1680 }
1681 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001682
1683 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1684 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1685 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1686 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1687
1688 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1689 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1690
1691 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1692 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1693 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1694 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1695 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1696 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1697
1698 band_5g->vht_cap.cap |=
1699 (cfg->vht_max_ampdu_len_exp <<
1700 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1701
1702 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1703 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1704 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1705 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1706 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1707 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1708 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1709 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1710
1711 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1712 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1713
1714}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001715
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001716/**
1717 * hdd_generate_macaddr_auto() - Auto-generate mac address
1718 * @hdd_ctx: Pointer to the HDD context
1719 *
1720 * Auto-generate mac address using device serial number.
1721 * Keep the first 3 bytes of OUI as before and replace
1722 * the last 3 bytes with the lower 3 bytes of serial number.
1723 *
1724 * Return: 0 for success
1725 * Non zero failure code for errors
1726 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001727static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001728{
1729 unsigned int serialno = 0;
1730 struct qdf_mac_addr mac_addr = {
1731 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1732 };
1733
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001734 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001735 if (serialno == 0)
1736 return -EINVAL;
1737
1738 serialno &= 0x00ffffff;
1739
1740 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1741 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1742 mac_addr.bytes[5] = serialno & 0xff;
1743
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301744 hdd_update_macaddr(hdd_ctx, mac_addr, true);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001745 return 0;
1746}
1747
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301748/**
1749 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1750 * configuration to cfg_ini in HDD
1751 * @hdd_ctx: Pointer to hdd_ctx
1752 * @cfg: target configuration
1753 *
1754 * Return: None
1755 */
1756#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001757static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301758 struct wma_tgt_cfg *cfg)
1759{
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05301760 ucfg_fwol_set_is_rate_limit_enabled(hdd_ctx->psoc,
1761 cfg->is_ra_rate_limit_enabled);
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301762}
1763#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001764static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301765 struct wma_tgt_cfg *cfg)
1766{
1767}
1768#endif
1769
Jeff Johnsonf9176382018-07-17 19:15:58 -07001770static void hdd_sar_target_config(struct hdd_context *hdd_ctx,
1771 struct wma_tgt_cfg *cfg)
1772{
1773 hdd_ctx->sar_version = cfg->sar_version;
1774}
1775
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001776static void hdd_update_vhtcap_2g(struct hdd_context *hdd_ctx)
1777{
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001778 uint32_t chip_mode = 0;
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001779 QDF_STATUS status;
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001780 bool b2g_vht_cfg = false;
1781 bool b2g_vht_target = false;
1782 struct wma_caps_per_phy caps_per_phy;
1783 struct wmi_unified *wmi_handle;
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001784
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001785 wmi_handle = get_wmi_unified_hdl_from_psoc(hdd_ctx->psoc);
1786 if (!wmi_handle) {
1787 hdd_err("wmi handle is NULL");
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001788 return;
1789 }
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001790
1791 status = ucfg_mlme_get_vht_for_24ghz(hdd_ctx->psoc, &b2g_vht_cfg);
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001792 if (QDF_IS_STATUS_ERROR(status)) {
1793 hdd_err("Failed to get 2g vht mode");
1794 return;
1795 }
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001796 if (wmi_service_enabled(wmi_handle, wmi_service_ext_msg)) {
1797 status = wma_get_caps_for_phyidx_hwmode(&caps_per_phy,
1798 HW_MODE_DBS_NONE,
1799 CDS_BAND_ALL);
1800 if (QDF_IS_STATUS_ERROR(status)) {
1801 hdd_err("Failed to get phy caps");
1802 return;
1803 }
1804 if (caps_per_phy.vht_2g)
1805 b2g_vht_target = true;
1806 } else {
1807 status = wlan_reg_get_chip_mode(hdd_ctx->pdev, &chip_mode);
1808 if (QDF_IS_STATUS_ERROR(status)) {
1809 hdd_err("Failed to get chip mode");
1810 return;
1811 }
1812 b2g_vht_target =
1813 (chip_mode & WMI_HOST_REGDMN_MODE_11AC_VHT20_2G) ?
1814 true : false;
1815 }
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001816
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001817 b2g_vht_cfg = b2g_vht_cfg && b2g_vht_target;
1818 hdd_debug("vht 2g target: %d, cfg: %d", b2g_vht_target, b2g_vht_cfg);
1819 status = ucfg_mlme_set_vht_for_24ghz(hdd_ctx->psoc, b2g_vht_cfg);
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001820 if (QDF_IS_STATUS_ERROR(status)) {
1821 hdd_err("Failed to update 2g vht mode");
1822 return;
1823 }
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001824}
1825
Jeff Johnson8abc5932018-06-02 22:51:37 -07001826void hdd_update_tgt_cfg(hdd_handle_t hdd_handle, struct wma_tgt_cfg *cfg)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001827{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001828 int ret;
Jeff Johnsonea70b942018-07-02 09:42:31 -07001829 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301830 uint8_t temp_band_cap, band_capability;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001831 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301832 uint8_t antenna_mode;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301833 uint8_t sub_20_chan_width;
Arif Hussainee10f902017-12-27 16:30:17 -08001834 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -07001835 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301836 bool bval = false;
1837 uint8_t value = 0;
Arif Hussainbd5194c2018-11-27 19:01:15 -08001838 uint32_t fine_time_meas_cap = 0;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301839
gaurank kathpalia843f7c32018-07-02 18:04:14 +05301840 if (!hdd_ctx) {
1841 hdd_err("HDD context is NULL");
1842 return;
1843 }
Dustin Brownbd68fe12017-11-21 15:28:52 -08001844 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1845 if (ret) {
Dustin Brown64204d22018-08-15 16:35:19 -07001846 QDF_DEBUG_PANIC("Failed to create pdev; errno:%d", ret);
1847 return;
1848 }
1849
1850 hdd_debug("New pdev has been created with pdev_id = %u",
Dustin Brown07901ec2018-09-07 11:02:41 -07001851 hdd_ctx->pdev->pdev_objmgr.wlan_pdev_id);
Dustin Brown64204d22018-08-15 16:35:19 -07001852
Dustin Brown07901ec2018-09-07 11:02:41 -07001853 status = dispatcher_pdev_open(hdd_ctx->pdev);
Dustin Brown64204d22018-08-15 16:35:19 -07001854 if (QDF_IS_STATUS_ERROR(status)) {
1855 QDF_DEBUG_PANIC("dispatcher pdev open failed; status:%d",
1856 status);
1857 return;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301858 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001859
Sandeep Puligillab7beb472018-08-13 22:54:20 -07001860 status = hdd_component_pdev_open(hdd_ctx->pdev);
1861 if (QDF_IS_STATUS_ERROR(status)) {
1862 QDF_DEBUG_PANIC("hdd component pdev open failed; status:%d",
1863 status);
1864 return;
1865 }
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301866 cdp_pdev_set_ctrl_pdev(cds_get_context(QDF_MODULE_ID_SOC),
1867 cds_get_context(QDF_MODULE_ID_TXRX),
Dustin Brown07901ec2018-09-07 11:02:41 -07001868 (struct cdp_ctrl_objmgr_pdev *)hdd_ctx->pdev);
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301869
Dustin Brown07901ec2018-09-07 11:02:41 -07001870 wlan_pdev_set_dp_handle(hdd_ctx->pdev,
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301871 cds_get_context(QDF_MODULE_ID_TXRX));
1872
Will Huang07244172018-05-14 14:23:30 +08001873 hdd_objmgr_update_tgt_max_vdev_psoc(hdd_ctx, cfg->max_intf_count);
1874
Dustin Brown1dbefe62018-09-11 16:32:03 -07001875 ucfg_ipa_set_dp_handle(hdd_ctx->psoc,
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301876 cds_get_context(QDF_MODULE_ID_SOC));
Dustin Brown1dbefe62018-09-11 16:32:03 -07001877 ucfg_ipa_set_txrx_handle(hdd_ctx->psoc,
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301878 cds_get_context(QDF_MODULE_ID_TXRX));
Dustin Brown07901ec2018-09-07 11:02:41 -07001879 ucfg_ipa_reg_sap_xmit_cb(hdd_ctx->pdev,
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301880 hdd_softap_hard_start_xmit);
Dustin Brown07901ec2018-09-07 11:02:41 -07001881 ucfg_ipa_reg_send_to_nw_cb(hdd_ctx->pdev,
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301882 hdd_ipa_send_skb_to_network);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301883
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301884 status = ucfg_mlme_get_sub_20_chan_width(hdd_ctx->psoc,
1885 &sub_20_chan_width);
1886 if (QDF_IS_STATUS_ERROR(status)) {
1887 hdd_err("Failed to get sub_20_chan_width config");
1888 return;
1889 }
1890
Naveen Rawat64e477e2016-05-20 10:34:56 -07001891 if (cds_cfg) {
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301892 if (sub_20_chan_width !=
1893 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
Naveen Rawat64e477e2016-05-20 10:34:56 -07001894 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1895 cds_cfg->sub_20_channel_width =
1896 WLAN_SUB_20_CH_WIDTH_NONE;
1897 } else {
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301898 cds_cfg->sub_20_channel_width = sub_20_chan_width;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001899 }
1900 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001901
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301902 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
1903 if (QDF_IS_STATUS_ERROR(status)) {
1904 hdd_err("Failed to get MLME band capability");
1905 return;
1906 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001907
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301908 /* first store the INI band capability */
1909 temp_band_cap = band_capability;
1910
1911 band_capability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301912 hdd_ctx->is_fils_roaming_supported =
1913 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001914
Vignesh Viswanathan694e28e2018-01-18 20:53:57 +05301915 hdd_ctx->config->is_11k_offload_supported =
1916 cfg->services.is_11k_offload_supported;
1917
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001918 /*
1919 * now overwrite the target band capability with INI
1920 * setting if INI setting is a subset
1921 */
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301922 if ((band_capability == BAND_ALL) &&
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001923 (temp_band_cap != BAND_ALL))
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301924 band_capability = temp_band_cap;
1925 else if ((band_capability != BAND_ALL) &&
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001926 (temp_band_cap != BAND_ALL) &&
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301927 (band_capability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001928 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001929 }
1930
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301931 status = ucfg_mlme_set_band_capability(hdd_ctx->psoc, band_capability);
1932 if (QDF_IS_STATUS_ERROR(status)) {
1933 hdd_err("Failed to set MLME Band Capability");
1934 return;
1935 }
1936
1937 hdd_ctx->curr_band = band_capability;
Amar Singhal58b45ef2017-08-01 13:43:54 -07001938
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301939 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001940 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1941 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1942 }
1943
1944 /* This can be extended to other configurations like ht, vht cap... */
1945
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301946 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr))
1947 qdf_mem_copy(&hdd_ctx->hw_macaddr, &cfg->hw_macaddr,
1948 QDF_MAC_ADDR_SIZE);
1949 else
1950 hdd_info("hw_mac is zero");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001951
1952 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001953 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001954
Ryan Hsuc6918552018-05-16 13:29:59 -07001955 hdd_ctx->hw_bd_id = cfg->hw_bd_id;
1956 qdf_mem_copy(&hdd_ctx->hw_bd_info, &cfg->hw_bd_info,
1957 sizeof(cfg->hw_bd_info));
1958
Dustin Brownbee82832018-07-23 10:10:51 -07001959 if (cfg->max_intf_count > CSR_ROAM_SESSION_MAX) {
1960 hdd_err("fw max vdevs (%u) > host max vdevs (%u); using %u",
1961 cfg->max_intf_count, CSR_ROAM_SESSION_MAX,
1962 CSR_ROAM_SESSION_MAX);
1963 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
1964 } else {
1965 hdd_ctx->max_intf_count = cfg->max_intf_count;
1966 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001967
Jeff Johnsonf9176382018-07-17 19:15:58 -07001968 hdd_sar_target_config(hdd_ctx, cfg);
Jeff Johnsonc875e242016-09-23 18:12:34 -07001969 hdd_lpass_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001970
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001971 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1972 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1973
1974 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1975
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001976 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001977 if (cfg->services.en_11ax) {
1978 hdd_info("11AX: 11ax is enabled - update HDD config");
1979 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1980 }
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -07001981 hdd_update_tgt_twt_cap(hdd_ctx, cfg);
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001982
1983 hdd_update_vdev_nss(hdd_ctx);
1984
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301985 hdd_update_hw_dbs_capable(hdd_ctx);
gaurank kathpalia5fcefa92018-10-24 15:03:15 +05301986 hdd_ctx->dynamic_nss_chains_support =
1987 cfg->dynamic_nss_chains_support;
Arif Hussainbd5194c2018-11-27 19:01:15 -08001988 ucfg_mlme_get_fine_time_meas_cap(hdd_ctx->psoc, &fine_time_meas_cap);
1989 fine_time_meas_cap &= cfg->fine_time_measurement_cap;
1990 status = ucfg_mlme_set_fine_time_meas_cap(hdd_ctx->psoc,
1991 fine_time_meas_cap);
1992 if (QDF_IS_STATUS_ERROR(status)) {
1993 hdd_err("failed to set fine_time_meas_cap, 0x%x, ox%x",
1994 fine_time_meas_cap, cfg->fine_time_measurement_cap);
1995 ucfg_mlme_get_fine_time_meas_cap(hdd_ctx->psoc,
1996 &fine_time_meas_cap);
1997 }
1998
Krunal Sonie3531942016-04-12 17:43:53 -07001999 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Arif Hussainbd5194c2018-11-27 19:01:15 -08002000 hdd_debug("fine_time_meas_cap: 0x%x", fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08002001
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05302002 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
2003 if (!QDF_IS_STATUS_SUCCESS(status))
2004 hdd_err("unable to get vht_enable2x2");
2005
2006 antenna_mode = (bval == 0x01) ?
Nitesh Shahe50711f2017-04-26 16:30:45 +05302007 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
2008 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002009 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08002010 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08002011
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05302012 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05302013 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05302014
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05302015 status = ucfg_mlme_cfg_get_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
Abhinav Kumare057b412018-10-09 17:28:16 +05302016 &value);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05302017 if (QDF_IS_STATUS_ERROR(status)) {
2018 status = false;
2019 hdd_err("set tx_bfee_ant_supp failed");
2020 }
2021
2022 if ((value >
Arif Hussainee10f902017-12-27 16:30:17 -08002023 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05302024 !cfg->tx_bfee_8ss_enabled) {
2025 status =
2026 ucfg_mlme_cfg_set_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
2027 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF);
2028 if (QDF_IS_STATUS_ERROR(status)) {
2029 status = false;
2030 hdd_err("set tx_bfee_ant_supp failed");
2031 }
2032 }
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302033
Jeff Johnson16528362018-06-14 12:34:16 -07002034 mac_handle = hdd_ctx->mac_handle;
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302035
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05302036 hdd_debug("txBFCsnValue %d", value);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05302037
2038 /*
2039 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
2040 */
2041 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05302042
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08002043 hdd_update_vhtcap_2g(hdd_ctx);
2044
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05302045 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
2046
Yue Macd359b72017-10-03 15:21:00 -07002047 /*
2048 * This needs to be done after HDD pdev is created and stored since
2049 * it will access the HDD pdev object lock.
2050 */
2051 hdd_runtime_suspend_context_init(hdd_ctx);
2052
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07002053 /* Configure NAN datapath features */
2054 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Nachiket Kukade85aa3782018-11-02 20:12:34 +05302055 ucfg_nan_set_tgt_caps(hdd_ctx->psoc, &cfg->nan_caps);
Arif Hussain759a0232017-03-20 13:17:18 -07002056 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08002057 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Liangwei Dong0da14262018-07-03 03:30:23 -04002058 hdd_ctx->obss_scan_offload = cfg->services.obss_scan_offload;
Wu Gao5f764082019-01-04 15:54:38 +08002059 status = ucfg_mlme_set_obss_detection_offload_enabled(
2060 hdd_ctx->psoc, cfg->obss_detection_offloaded);
Arif Hussainee10f902017-12-27 16:30:17 -08002061 if (QDF_IS_STATUS_ERROR(status))
2062 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Arif Hussain05fb4872018-01-03 16:02:55 -08002063
Wu Gao5f764082019-01-04 15:54:38 +08002064 status = ucfg_mlme_set_obss_color_collision_offload_enabled(
2065 hdd_ctx->psoc, cfg->obss_color_collision_offloaded);
Arif Hussain05fb4872018-01-03 16:02:55 -08002066 if (QDF_IS_STATUS_ERROR(status))
2067 hdd_err("Failed to set WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002068}
2069
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002070bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002071{
Jeff Johnson9d295242017-08-29 14:39:48 -07002072 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002073 struct hdd_ap_ctx *ap_ctx;
Arif Hussain224d3812018-11-16 17:58:38 -08002074 bool dfs_disable_channel_switch = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002075
Jiachao Wuf610d912018-01-23 17:47:32 +08002076 if (!hdd_ctx) {
2077 hdd_info("Couldn't get hdd_ctx");
2078 return true;
2079 }
2080
Arif Hussain224d3812018-11-16 17:58:38 -08002081 ucfg_mlme_get_dfs_disable_channel_switch(hdd_ctx->psoc,
2082 &dfs_disable_channel_switch);
2083 if (dfs_disable_channel_switch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002084 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussain224d3812018-11-16 17:58:38 -08002085 hdd_ctx, dfs_disable_channel_switch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302086 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002087 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002088
Dustin Brown920397d2017-12-13 16:27:50 -08002089 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002090 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2091
2092 if ((QDF_SAP_MODE == adapter->device_mode ||
2093 QDF_P2P_GO_MODE == adapter->device_mode) &&
Dustin Brown07901ec2018-09-07 11:02:41 -07002094 (wlan_reg_is_passive_or_disable_ch(hdd_ctx->pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002095 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002096 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2097 true;
2098 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07002099 adapter->session_id);
bings6fb9bf62018-07-05 14:01:53 +08002100 if (adapter->txrx_vdev)
2101 cdp_fc_vdev_flush(
2102 cds_get_context(QDF_MODULE_ID_SOC),
bings0e03a982018-05-09 08:40:59 +08002103 adapter->txrx_vdev);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302104 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002105 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302106
2107 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002108}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002109
Jeff Johnson030cd902018-11-11 10:19:40 -08002110bool hdd_is_valid_mac_address(const uint8_t *mac_addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002111{
2112 int xdigit = 0;
2113 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002114
Jeff Johnson030cd902018-11-11 10:19:40 -08002115 while (*mac_addr) {
2116 if (isxdigit(*mac_addr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002117 xdigit++;
Jeff Johnson030cd902018-11-11 10:19:40 -08002118 } else if (':' == *mac_addr) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002119 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2120 break;
2121
2122 ++separator;
2123 } else {
2124 /* Invalid MAC found */
Jeff Johnson030cd902018-11-11 10:19:40 -08002125 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002126 }
Jeff Johnson030cd902018-11-11 10:19:40 -08002127 ++mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002128 }
2129 return xdigit == 12 && (separator == 5 || separator == 0);
2130}
2131
2132/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302133 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2134 * @dev: Handle to struct net_device to be updated.
2135 *
2136 * Return: None
2137 */
2138static void hdd_mon_mode_ether_setup(struct net_device *dev)
2139{
2140 dev->header_ops = NULL;
2141 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2142 dev->hard_header_len = ETH_HLEN;
2143 dev->mtu = ETH_DATA_LEN;
2144 dev->addr_len = ETH_ALEN;
2145 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2146 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2147 dev->priv_flags |= IFF_TX_SKB_SHARING;
2148
2149 memset(dev->broadcast, 0xFF, ETH_ALEN);
2150}
2151
Nirav Shah73713f72018-05-17 14:50:41 +05302152#ifdef FEATURE_MONITOR_MODE_SUPPORT
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302153/**
chenguo71303962018-10-24 19:44:34 +08002154 * hdd_mon_turn_off_ps_and_wow() - Update monitor mode struct net_device.
2155 * @hdd_ctx: Pointer to HDD context.
2156 *
2157 * Return: None
2158 */
2159static void hdd_mon_turn_off_ps_and_wow(struct hdd_context *hdd_ctx)
2160{
2161 ucfg_pmo_set_power_save_mode(hdd_ctx->psoc, PS_NOT_SUPPORTED);
2162 ucfg_pmo_set_wow_enable(hdd_ctx->psoc, PMO_WOW_DISABLE_BOTH);
2163}
2164
2165/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002166 * __hdd__mon_open() - HDD Open function
2167 * @dev: Pointer to net_device structure
2168 *
2169 * This is called in response to ifconfig up
2170 *
2171 * Return: 0 for success; non-zero for failure
2172 */
2173static int __hdd_mon_open(struct net_device *dev)
2174{
2175 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002176 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2177 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002178
Dustin Brownfdf17c12018-03-14 12:55:34 -07002179 hdd_enter_dev(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002180
2181 ret = wlan_hdd_validate_context(hdd_ctx);
2182 if (ret)
2183 return ret;
2184
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302185 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002186
2187 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Brown3ecc8782018-09-19 16:37:13 -07002188 ret = hdd_psoc_idle_restart(hdd_ctx);
Ravi Joshia307f632017-07-17 23:41:41 -07002189 if (ret) {
2190 hdd_err("Failed to start WLAN modules return");
2191 return ret;
2192 }
2193 hdd_err("hdd_wlan_start_modules() successful !");
2194
2195 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2196 ret = hdd_start_adapter(adapter);
2197 if (ret) {
2198 hdd_err("Failed to start adapter :%d",
2199 adapter->device_mode);
2200 return ret;
2201 }
2202 hdd_err("hdd_start_adapters() successful !");
2203 }
chenguo71303962018-10-24 19:44:34 +08002204 hdd_mon_turn_off_ps_and_wow(hdd_ctx);
Ravi Joshia307f632017-07-17 23:41:41 -07002205 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2206 }
2207
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002208 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002209
2210 if (!ret)
2211 ret = hdd_enable_monitor_mode(dev);
2212
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002213 return ret;
2214}
2215
2216/**
2217 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2218 * @dev: Pointer to net_device structure
2219 *
2220 * This is called in response to ifconfig up
2221 *
2222 * Return: 0 for success; non-zero for failure
2223 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002224static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002225{
2226 int ret;
2227
2228 cds_ssr_protect(__func__);
2229 ret = __hdd_mon_open(dev);
2230 cds_ssr_unprotect(__func__);
2231
2232 return ret;
2233}
Nirav Shah73713f72018-05-17 14:50:41 +05302234#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002235
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002236static QDF_STATUS
2237wlan_hdd_update_dbs_scan_and_fw_mode_config(void)
2238{
2239 struct policy_mgr_dual_mac_config cfg = {0};
2240 QDF_STATUS status;
Krunal Sonie64b17e2018-12-13 16:00:02 -08002241 uint32_t chnl_sel_logic_conc = 0;
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002242 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Krunal Sonidf29bc42018-11-15 13:26:29 -08002243 uint8_t dual_mac_feature = DISABLE_DBS_CXN_AND_SCAN;
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002244
2245 if (!hdd_ctx) {
2246 hdd_err("HDD context is NULL");
2247 return QDF_STATUS_E_FAILURE;
2248 }
2249
Krunal Sonie64b17e2018-12-13 16:00:02 -08002250 /*
2251 * ROME platform doesn't support any DBS related commands in FW,
2252 * so if driver sends wmi command with dual_mac_config with all set to
2253 * 0 then FW wouldn't respond back and driver would timeout on waiting
2254 * for response. Check if FW supports DBS to eliminate ROME vs
2255 * NON-ROME platform.
2256 */
2257 if (!policy_mgr_find_if_fw_supports_dbs(hdd_ctx->psoc))
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002258 return QDF_STATUS_SUCCESS;
2259
2260 cfg.scan_config = 0;
2261 cfg.fw_mode_config = 0;
2262 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Krunal Sonie64b17e2018-12-13 16:00:02 -08002263 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->psoc)) {
2264 status =
2265 ucfg_policy_mgr_get_chnl_select_plcy(hdd_ctx->psoc,
2266 &chnl_sel_logic_conc);
2267 if (status != QDF_STATUS_SUCCESS) {
2268 hdd_err("can't get chnl sel policy, use def");
2269 return status;
2270 }
Krunal Sonidf29bc42018-11-15 13:26:29 -08002271 }
2272 status =
2273 ucfg_policy_mgr_get_dual_mac_feature(hdd_ctx->psoc,
2274 &dual_mac_feature);
2275 if (status != QDF_STATUS_SUCCESS) {
2276 hdd_err("ucfg_policy_mgr_get_dual_mac_feature failed, use def");
2277 return status;
2278 }
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002279
Krunal Sonidf29bc42018-11-15 13:26:29 -08002280 if (dual_mac_feature != DISABLE_DBS_CXN_AND_SCAN) {
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002281 status = policy_mgr_get_updated_scan_and_fw_mode_config(
Dustin Brown1dbefe62018-09-11 16:32:03 -07002282 hdd_ctx->psoc, &cfg.scan_config,
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002283 &cfg.fw_mode_config,
Krunal Sonidf29bc42018-11-15 13:26:29 -08002284 dual_mac_feature,
Krunal Sonie64b17e2018-12-13 16:00:02 -08002285 chnl_sel_logic_conc);
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002286
2287 if (status != QDF_STATUS_SUCCESS) {
2288 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
2289 status);
2290 return status;
2291 }
2292 }
2293
2294 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
2295 cfg.scan_config, cfg.fw_mode_config);
2296
2297 status = sme_soc_set_dual_mac_config(cfg);
2298 if (status != QDF_STATUS_SUCCESS) {
2299 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
2300 return status;
2301 }
2302
2303 return QDF_STATUS_SUCCESS;
2304}
2305
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002306/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302307 * hdd_start_adapter() - Wrapper function for device specific adapter
2308 * @adapter: pointer to HDD adapter
2309 *
2310 * This function is called to start the device specific adapter for
2311 * the mode passed in the adapter's device_mode.
2312 *
2313 * Return: 0 for success; non-zero for failure
2314 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002315int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302316{
2317
2318 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002319 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302320
Dustin Brownfdf17c12018-03-14 12:55:34 -07002321 hdd_enter_dev(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002322 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302323
2324 switch (device_mode) {
2325 case QDF_P2P_CLIENT_MODE:
2326 case QDF_P2P_DEVICE_MODE:
2327 case QDF_OCB_MODE:
2328 case QDF_STA_MODE:
2329 case QDF_MONITOR_MODE:
2330 ret = hdd_start_station_adapter(adapter);
2331 if (ret)
2332 goto err_start_adapter;
Alok Kumar81e1d732018-09-04 11:10:36 +05302333
2334 hdd_nud_ignore_tracking(adapter, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05302335 break;
2336 case QDF_P2P_GO_MODE:
2337 case QDF_SAP_MODE:
2338 ret = hdd_start_ap_adapter(adapter);
2339 if (ret)
2340 goto err_start_adapter;
2341 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302342 case QDF_IBSS_MODE:
2343 /*
2344 * For IBSS interface is initialized as part of
2345 * hdd_init_station_mode()
2346 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002347 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302348 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002349 /* vdevs are dynamically managed by firmware in FTM */
2350 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302351 default:
2352 hdd_err("Invalid session type %d", device_mode);
2353 QDF_ASSERT(0);
2354 goto err_start_adapter;
2355 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002356
Arun Khandavallifae92942016-08-01 13:31:08 +05302357 if (hdd_set_fw_params(adapter))
2358 hdd_err("Failed to set the FW params for the adapter!");
2359
Dustin Browne7e71d32018-05-11 16:00:08 -07002360 if (adapter->session_id != HDD_SESSION_ID_INVALID) {
2361 ret = wlan_hdd_cfg80211_register_frames(adapter);
2362 if (ret < 0) {
2363 hdd_err("Failed to register frames - ret %d", ret);
2364 goto err_start_adapter;
2365 }
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302366 }
Dustin Browne7e71d32018-05-11 16:00:08 -07002367
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002368 wlan_hdd_update_dbs_scan_and_fw_mode_config();
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302369
Dustin Browndb2a8be2017-12-20 11:49:56 -08002370exit_with_success:
Dustin Browne74003f2018-03-14 12:51:58 -07002371 hdd_exit();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002372
Arun Khandavallifae92942016-08-01 13:31:08 +05302373 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002374
Arun Khandavallifae92942016-08-01 13:31:08 +05302375err_start_adapter:
2376 return -EINVAL;
2377}
2378
2379/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302380 * hdd_enable_power_management() - API to Enable Power Management
2381 *
2382 * API invokes Bus Interface Layer power management functionality
2383 *
2384 * Return: None
2385 */
2386static void hdd_enable_power_management(void)
2387{
2388 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2389
2390 if (!hif_ctx) {
2391 hdd_err("Bus Interface Context is Invalid");
2392 return;
2393 }
2394
2395 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2396}
2397
2398/**
2399 * hdd_disable_power_management() - API to disable Power Management
2400 *
2401 * API disable Bus Interface Layer Power management functionality
2402 *
2403 * Return: None
2404 */
2405static void hdd_disable_power_management(void)
2406{
2407 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2408
2409 if (!hif_ctx) {
2410 hdd_err("Bus Interface Context is Invalid");
2411 return;
2412 }
2413
2414 hif_disable_power_management(hif_ctx);
2415}
2416
Ryan Hsuaadba072018-04-20 13:01:53 -07002417void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302418{
2419 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002420 size_t target_hw_name_len;
2421 const char *target_hw_name;
Ryan Hsuaadba072018-04-20 13:01:53 -07002422 uint8_t *buf;
2423 uint32_t buf_len;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302424
2425 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2426 if (!hif_sc) {
2427 hdd_err("HIF context is NULL");
2428 return;
2429 }
2430
Ryan Hsuaadba072018-04-20 13:01:53 -07002431 hif_get_hw_info(hif_sc, &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302432 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002433 &target_hw_name);
2434
2435 if (hdd_ctx->target_hw_name)
2436 qdf_mem_free(hdd_ctx->target_hw_name);
2437
2438 target_hw_name_len = strlen(target_hw_name) + 1;
2439 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2440 if (hdd_ctx->target_hw_name)
2441 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2442 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302443
Ryan Hsuaadba072018-04-20 13:01:53 -07002444 buf = qdf_mem_malloc(WE_MAX_STR_LEN);
2445 if (buf) {
2446 buf_len = hdd_wlan_get_version(hdd_ctx, WE_MAX_STR_LEN, buf);
2447 hdd_info("%s", buf);
2448 qdf_mem_free(buf);
2449 }
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302450}
2451
2452/**
gbian62edd7e2017-03-07 13:12:13 +08002453 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2454 * @hdd_ctx: Pointer to hdd context
2455 *
2456 * Return: none
2457 */
2458static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002459hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002460{
jitiphil8e15ea62018-11-16 18:05:34 +05302461 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM] = {0};
2462 qdf_size_t out_size = 0;
gbian62edd7e2017-03-07 13:12:13 +08002463 int i;
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002464 struct cds_context *cds_ctx;
gbian62edd7e2017-03-07 13:12:13 +08002465
2466 if (NULL == hdd_ctx)
2467 return;
2468
2469 if (NULL == hdd_ctx->config) {
2470 /* Do nothing if hdd_ctx is invalid */
2471 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2472 return;
2473 }
2474
2475 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2476
2477 if (!cds_ctx) {
2478 hdd_err("Invalid CDS Context");
2479 return;
2480 }
2481
2482 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2483 switch (i) {
2484 case OL_TX_WMM_AC_BE:
jitiphil8e15ea62018-11-16 18:05:34 +05302485 qdf_uint8_array_parse(
2486 cfg_get(hdd_ctx->psoc,
2487 CFG_DP_ENABLE_TX_SCHED_WRR_BE),
2488 tx_sched_wrr_param,
2489 sizeof(tx_sched_wrr_param),
2490 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002491 break;
2492 case OL_TX_WMM_AC_BK:
jitiphil8e15ea62018-11-16 18:05:34 +05302493 qdf_uint8_array_parse(
2494 cfg_get(hdd_ctx->psoc,
2495 CFG_DP_ENABLE_TX_SCHED_WRR_BK),
2496 tx_sched_wrr_param,
2497 sizeof(tx_sched_wrr_param),
2498 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002499 break;
2500 case OL_TX_WMM_AC_VI:
jitiphil8e15ea62018-11-16 18:05:34 +05302501 qdf_uint8_array_parse(
2502 cfg_get(hdd_ctx->psoc,
2503 CFG_DP_ENABLE_TX_SCHED_WRR_VI),
2504 tx_sched_wrr_param,
2505 sizeof(tx_sched_wrr_param),
2506 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002507 break;
2508 case OL_TX_WMM_AC_VO:
jitiphil8e15ea62018-11-16 18:05:34 +05302509 qdf_uint8_array_parse(
2510 cfg_get(hdd_ctx->psoc,
2511 CFG_DP_ENABLE_TX_SCHED_WRR_VO),
2512 tx_sched_wrr_param,
2513 sizeof(tx_sched_wrr_param),
2514 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002515 break;
2516 default:
gbian62edd7e2017-03-07 13:12:13 +08002517 break;
2518 }
2519
jitiphil8e15ea62018-11-16 18:05:34 +05302520 if (out_size == TX_SCHED_WRR_PARAMS_NUM) {
gbian62edd7e2017-03-07 13:12:13 +08002521 cds_ctx->ac_specs[i].wrr_skip_weight =
2522 tx_sched_wrr_param[0];
2523 cds_ctx->ac_specs[i].credit_threshold =
2524 tx_sched_wrr_param[1];
2525 cds_ctx->ac_specs[i].send_limit =
2526 tx_sched_wrr_param[2];
2527 cds_ctx->ac_specs[i].credit_reserve =
2528 tx_sched_wrr_param[3];
2529 cds_ctx->ac_specs[i].discard_weight =
2530 tx_sched_wrr_param[4];
2531 }
2532
jitiphil8e15ea62018-11-16 18:05:34 +05302533 out_size = 0;
gbian62edd7e2017-03-07 13:12:13 +08002534 }
2535}
2536
Ryan Hsuaadba072018-04-20 13:01:53 -07002537uint32_t hdd_wlan_get_version(struct hdd_context *hdd_ctx,
2538 const size_t version_len, uint8_t *version)
2539{
2540 uint32_t size;
2541 uint32_t msp_id = 0, mspid = 0, siid = 0, crmid = 0, sub_id = 0;
2542
2543 if (!hdd_ctx) {
2544 hdd_err("Invalid context, HDD context is null");
2545 return 0;
2546 }
2547
Ashish Kumar Dhanotiya7353f882018-05-15 12:50:19 +05302548 if (!version || version_len == 0) {
Ryan Hsuaadba072018-04-20 13:01:53 -07002549 hdd_err("Invalid buffer pointr or buffer len\n");
2550 return 0;
2551 }
2552
2553 msp_id = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
2554 mspid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
2555 siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
2556 crmid = hdd_ctx->target_fw_version & 0x7fff;
2557 sub_id = (hdd_ctx->target_fw_vers_ext & 0xf0000000) >> 28;
2558
2559 size = scnprintf(version, version_len,
Ryan Hsuc6918552018-05-16 13:29:59 -07002560 "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 -07002561 QWLAN_VERSIONSTR,
2562 msp_id, mspid, siid, crmid, sub_id,
Ryan Hsuc6918552018-05-16 13:29:59 -07002563 hdd_ctx->target_hw_name,
2564 hdd_ctx->hw_bd_info.bdf_version,
2565 hdd_ctx->hw_bd_info.ref_design_id,
2566 hdd_ctx->hw_bd_info.customer_id,
2567 hdd_ctx->hw_bd_info.project_id,
2568 hdd_ctx->hw_bd_info.board_data_rev);
Ryan Hsuaadba072018-04-20 13:01:53 -07002569
2570 return size;
2571}
2572
Rachit Kankane0dc3e852018-05-07 17:33:42 +05302573int hdd_set_11ax_rate(struct hdd_adapter *adapter, int set_value,
2574 struct sap_config *sap_config)
2575{
2576 uint8_t preamble = 0, nss = 0, rix = 0;
2577 int ret;
2578 mac_handle_t mac_handle = adapter->hdd_ctx->mac_handle;
2579
2580 if (!sap_config) {
2581 if (!sme_is_feature_supported_by_fw(DOT11AX)) {
2582 hdd_err("Target does not support 11ax");
2583 return -EIO;
2584 }
2585 } else if (sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax &&
2586 sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax_ONLY) {
2587 hdd_err("Invalid hw mode, SAP hw_mode= 0x%x, ch = %d",
2588 sap_config->SapHw_mode, sap_config->channel);
2589 return -EIO;
2590 }
2591
2592 if (set_value != 0xff) {
2593 rix = RC_2_RATE_IDX_11AX(set_value);
2594 preamble = WMI_RATE_PREAMBLE_HE;
2595 nss = HT_RC_2_STREAMS_11AX(set_value);
2596
2597 set_value = hdd_assemble_rate_code(preamble, nss, rix);
2598 } else {
2599 ret = sme_set_auto_rate_he_ltf(mac_handle, adapter->session_id,
2600 QCA_WLAN_HE_LTF_AUTO);
2601 }
2602
2603 hdd_info("SET_11AX_RATE val %d rix %d preamble %x nss %d",
2604 set_value, rix, preamble, nss);
2605
2606 ret = wma_cli_set_command(adapter->session_id,
2607 WMI_VDEV_PARAM_FIXED_RATE,
2608 set_value, VDEV_CMD);
2609
2610 return ret;
2611}
2612
2613int hdd_assemble_rate_code(uint8_t preamble, uint8_t nss, uint8_t rate)
2614{
2615 int set_value;
2616
2617 if (sme_is_feature_supported_by_fw(DOT11AX))
2618 set_value = WMI_ASSEMBLE_RATECODE_V1(rate, nss, preamble);
2619 else
2620 set_value = (preamble << 6) | (nss << 4) | rate;
2621
2622 return set_value;
2623}
2624
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002625#ifdef FEATURE_WLAN_WAPI
2626/**
2627 * hdd_wapi_security_sta_exist() - return wapi security sta exist or not
2628 *
2629 * This API returns the wapi security station exist or not
2630 *
2631 * Return: true - wapi security station exist
2632 */
2633static bool hdd_wapi_security_sta_exist(void)
2634{
2635 struct hdd_adapter *adapter = NULL;
2636 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2637
2638 hdd_for_each_adapter(hdd_ctx, adapter) {
2639 if ((adapter->device_mode == QDF_STA_MODE) &&
2640 adapter->wapi_info.wapi_mode &&
2641 (adapter->wapi_info.wapi_auth_mode != WAPI_AUTH_MODE_OPEN))
2642 return true;
2643 }
2644 return false;
2645}
2646#else
2647static bool hdd_wapi_security_sta_exist(void)
2648{
2649 return false;
2650}
2651#endif
2652
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002653#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002654static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2655 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2656{
Jeff Johnson9d295242017-08-29 14:39:48 -07002657 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002658 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002659
2660 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2661 if (!adapter) {
2662 hdd_err("Adapter is NULL");
2663 return PM_MAX_NUM_OF_MODE;
2664 }
2665
2666 return policy_mgr_convert_device_mode_to_qdf_type(
2667 adapter->device_mode);
2668}
2669
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002670static void hdd_register_policy_manager_callback(
2671 struct wlan_objmgr_psoc *psoc)
2672{
2673 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002674
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002675 qdf_mem_zero(&hdd_cbacks, sizeof(hdd_cbacks));
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002676 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002677 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002678 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2679 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002680 hdd_cbacks.get_mode_for_non_connected_vdev =
2681 wlan_hdd_get_mode_for_non_connected_vdev;
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05302682 hdd_cbacks.hdd_get_device_mode = hdd_get_device_mode;
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002683 hdd_cbacks.hdd_wapi_security_sta_exist =
2684 hdd_wapi_security_sta_exist;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002685 if (QDF_STATUS_SUCCESS !=
2686 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2687 hdd_err("HDD callback registration with policy manager failed");
2688 }
2689}
2690#else
2691static void hdd_register_policy_manager_callback(
2692 struct wlan_objmgr_psoc *psoc)
2693{
2694}
2695#endif
2696
Nachiket Kukade2fb1fdb2019-01-08 15:35:27 +05302697#ifdef WLAN_FEATURE_NAN
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002698static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002699{
2700 struct nan_callbacks cb_obj = {0};
2701
2702 cb_obj.ndi_open = hdd_ndi_open;
2703 cb_obj.ndi_close = hdd_ndi_close;
2704 cb_obj.ndi_start = hdd_ndi_start;
2705 cb_obj.ndi_delete = hdd_ndi_delete;
2706 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2707 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2708
Naveen Rawat37f62c82017-03-26 22:24:43 -07002709 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2710 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002711 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002712
Dustin Brown1dbefe62018-09-11 16:32:03 -07002713 os_if_nan_register_hdd_callbacks(hdd_ctx->psoc, &cb_obj);
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002714}
jiadff1ac132018-11-26 16:27:48 +08002715#else
2716static inline void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
2717{
2718}
2719#endif
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002720
Dustin Brown26b3d042017-12-21 11:13:27 -08002721#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002722/**
2723 * hdd_check_for_leaks() - Perform runtime memory leak checks
Dustin Browna6246dd2018-05-24 14:35:58 -07002724 * @hdd_ctx: the global HDD context
Dustin Brown29533f22018-07-24 13:11:56 -07002725 * @is_ssr: true if SSR is in progress
Dustin Brown4c5b9902017-12-19 11:17:19 -08002726 *
2727 * This API triggers runtime memory leak detection. This feature enforces the
2728 * policy that any memory allocated at runtime must also be released at runtime.
2729 *
2730 * Allocating memory at runtime and releasing it at unload is effectively a
2731 * memory leak for configurations which never unload (e.g. LONU, statically
2732 * compiled driver). Such memory leaks are NOT false positives, and must be
2733 * fixed.
2734 *
2735 * Return: None
2736 */
Dustin Brown29533f22018-07-24 13:11:56 -07002737static void hdd_check_for_leaks(struct hdd_context *hdd_ctx, bool is_ssr)
Dustin Brown4bc0a622017-12-06 15:56:50 -08002738{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002739 /* DO NOT REMOVE these checks; for false positives, read above first */
2740
Dustin Brown1dbefe62018-09-11 16:32:03 -07002741 wlan_objmgr_psoc_check_for_peer_leaks(hdd_ctx->psoc);
2742 wlan_objmgr_psoc_check_for_vdev_leaks(hdd_ctx->psoc);
2743 wlan_objmgr_psoc_check_for_pdev_leaks(hdd_ctx->psoc);
Dustin Brown29533f22018-07-24 13:11:56 -07002744
2745 /* many adapter resources are not freed by design during SSR */
2746 if (is_ssr)
2747 return;
2748
Dustin Brown677e0862017-10-10 16:30:09 -07002749 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002750 qdf_nbuf_map_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002751 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002752}
2753
Dustin Brown26b3d042017-12-21 11:13:27 -08002754#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2755#else
Dustin Brown29533f22018-07-24 13:11:56 -07002756static inline void hdd_check_for_leaks(struct hdd_context *hdd_ctx, bool is_ssr)
2757{ }
Dustin Brown26b3d042017-12-21 11:13:27 -08002758
2759#define hdd_debug_domain_set(domain)
2760#endif /* CONFIG_LEAK_DETECTION */
2761
gbian62edd7e2017-03-07 13:12:13 +08002762/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002763 * hdd_update_country_code - Update country code
2764 * @hdd_ctx: HDD context
2765 *
2766 * Update country code based on module parameter country_code
2767 *
2768 * Return: 0 on success and errno on failure
2769 */
2770static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2771{
2772 if (!country_code)
2773 return 0;
2774
2775 return hdd_reg_set_country(hdd_ctx, country_code);
2776}
2777
Dustin Browne7e71d32018-05-11 16:00:08 -07002778int hdd_wlan_start_modules(struct hdd_context *hdd_ctx, bool reinit)
Arun Khandavallifae92942016-08-01 13:31:08 +05302779{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002780 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302781 qdf_device_t qdf_dev;
2782 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302783 bool unint = false;
2784 void *hif_ctx;
Jingxiang Ge95912f82018-04-19 12:01:26 +08002785 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +05302786
Arun Khandavallifae92942016-08-01 13:31:08 +05302787 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2788 if (!qdf_dev) {
2789 hdd_err("QDF Device Context is Invalid return");
2790 return -EINVAL;
2791 }
2792
Dustin Brown4c663222018-10-23 14:19:36 -07002793 hdd_psoc_idle_timer_stop(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302794
Dustin Brown1fe30a82017-10-03 16:13:36 -07002795 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302796 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2797 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002798 hdd_debug("Driver modules already Enabled");
Dustin Browne74003f2018-03-14 12:51:58 -07002799 hdd_exit();
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302800 return 0;
2801 }
2802
Dustin Brown1fe30a82017-10-03 16:13:36 -07002803 hdd_ctx->start_modules_in_progress = true;
2804
Arun Khandavallifae92942016-08-01 13:31:08 +05302805 switch (hdd_ctx->driver_status) {
2806 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002807 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302808 unint = true;
2809 /* Fall through dont add break here */
2810 case DRIVER_MODULES_CLOSED:
Dustin Brown1a20b082018-08-03 17:27:15 -07002811 hdd_info("Wlan transitioning (CLOSED -> ENABLED)");
Dustin Brown550f6d22017-12-14 15:44:01 -08002812
Dustin Brown26b3d042017-12-21 11:13:27 -08002813 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002814
Arun Khandavallifae92942016-08-01 13:31:08 +05302815 if (!reinit && !unint) {
2816 ret = pld_power_on(qdf_dev->dev);
2817 if (ret) {
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002818 hdd_err("Failed to power up device; errno:%d",
Dustin Browndca39692017-11-09 15:30:25 -08002819 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302820 goto release_lock;
2821 }
2822 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002823
2824 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2825 hdd_ctx->config->enable_fw_log);
Arun Khandavallifae92942016-08-01 13:31:08 +05302826 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2827 qdf_dev->bus_type,
2828 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2829 HIF_ENABLE_TYPE_PROBE);
2830 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002831 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302832 goto power_down;
2833 }
2834
2835 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302836 if (!hif_ctx) {
2837 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002838 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302839 goto power_down;
2840 }
2841
Arun Khandavallifae92942016-08-01 13:31:08 +05302842 status = ol_cds_init(qdf_dev, hif_ctx);
2843 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002844 hdd_err("No Memory to Create BMI Context; status: %d",
2845 status);
2846 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302847 goto hif_close;
2848 }
2849
jitiphil4c256a32018-09-07 08:51:52 +05302850 ucfg_ipa_component_config_update(hdd_ctx->psoc);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302851
gbian62edd7e2017-03-07 13:12:13 +08002852 hdd_update_cds_ac_specs_params(hdd_ctx);
2853
Dustin Brown1dbefe62018-09-11 16:32:03 -07002854 status = hdd_component_psoc_open(hdd_ctx->psoc);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05302855 if (QDF_IS_STATUS_ERROR(status)) {
2856 hdd_err("Failed to Open legacy components; status: %d",
2857 status);
2858 ret = qdf_status_to_os_return(status);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05302859 goto cds_free;
2860 }
2861
2862 ret = hdd_update_config(hdd_ctx);
2863 if (ret) {
2864 hdd_err("Failed to update configuration; errno: %d",
2865 ret);
2866 goto cds_free;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05302867 }
2868
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +05302869 status = wbuff_module_init();
2870 if (QDF_IS_STATUS_ERROR(status))
2871 hdd_err("WBUFF init unsuccessful; status: %d", status);
2872
Dustin Brown1dbefe62018-09-11 16:32:03 -07002873 status = cds_open(hdd_ctx->psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002874 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002875 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002876 ret = qdf_status_to_os_return(status);
Krunal Sonie71838d2018-09-27 10:45:05 -07002877 goto psoc_close;
Arun Khandavallifae92942016-08-01 13:31:08 +05302878 }
2879
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +05302880 hdd_ctx->mac_handle = cds_get_context(QDF_MODULE_ID_SME);
2881
Manjunathappa Prakashb6b4ff12018-06-04 12:32:33 -07002882 if (hdd_ctx->config->rx_thread_affinity_mask)
2883 cds_set_rx_thread_cpu_mask(
2884 hdd_ctx->config->rx_thread_affinity_mask);
2885
2886 /* initialize components configurations after psoc open */
Mukul Sharma9d797a02017-01-05 20:26:03 +05302887 ret = hdd_update_components_config(hdd_ctx);
2888 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002889 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302890 ret);
2891 goto close;
2892 }
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302893
Dustin Brown1dbefe62018-09-11 16:32:03 -07002894 status = cds_dp_open(hdd_ctx->psoc);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002895 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002896 hdd_err("Failed to Open cds post open; status: %d",
2897 status);
2898 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002899 goto close;
2900 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302901
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302902 ret = hdd_register_cb(hdd_ctx);
2903 if (ret) {
2904 hdd_err("Failed to register HDD callbacks!");
2905 goto cds_txrx_free;
2906 }
2907
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002908 /*
2909 * NAN compoenet requires certian operations like, open adapter,
2910 * close adapter, etc. to be initiated by HDD, for those
2911 * register HDD callbacks with UMAC's NAN componenet.
2912 */
2913 hdd_nan_register_callbacks(hdd_ctx);
2914
Jeff Johnson3a280122017-09-13 07:42:00 -07002915 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302916 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002917 hdd_err("Failed to pre-enable CDS; status: %d", status);
2918 ret = qdf_status_to_os_return(status);
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302919 goto deregister_cb;
Arun Khandavallifae92942016-08-01 13:31:08 +05302920 }
2921
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002922 hdd_register_policy_manager_callback(
Dustin Brown1dbefe62018-09-11 16:32:03 -07002923 hdd_ctx->psoc);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002924
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302925 hdd_sysfs_create_driver_root_obj();
Dustin Brown1dbefe62018-09-11 16:32:03 -07002926 hdd_sysfs_create_version_interface(hdd_ctx->psoc);
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302927 hdd_sysfs_create_powerstats_interface();
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302928 hdd_update_hw_sw_info(hdd_ctx);
Dustin Brown550f6d22017-12-14 15:44:01 -08002929
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302930 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2931 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002932 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302933 break;
2934 }
Dustin Browndca39692017-11-09 15:30:25 -08002935
Dustin Browne7e71d32018-05-11 16:00:08 -07002936 ret = hdd_configure_cds(hdd_ctx);
Dustin Browndca39692017-11-09 15:30:25 -08002937 if (ret) {
2938 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302939 goto destroy_driver_sysfs;
Arun Khandavallifae92942016-08-01 13:31:08 +05302940 }
Dustin Browndca39692017-11-09 15:30:25 -08002941
Komal Seelamf2136bb2016-09-28 18:30:44 +05302942 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002943
Arun Khandavallifae92942016-08-01 13:31:08 +05302944 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002945
Arun Khandavallifae92942016-08-01 13:31:08 +05302946 default:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002947 QDF_DEBUG_PANIC("Unknown driver state:%d",
Arun Khandavallifae92942016-08-01 13:31:08 +05302948 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002949 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302950 goto release_lock;
2951 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002952
Dustin Brown1a20b082018-08-03 17:27:15 -07002953 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2954 hdd_info("Wlan transitioned (now ENABLED)");
2955
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302956 hdd_ctx->start_modules_in_progress = false;
Dustin Brownad698ae2018-09-05 17:19:30 -07002957
Arun Khandavallifae92942016-08-01 13:31:08 +05302958 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002959
Dustin Browne74003f2018-03-14 12:51:58 -07002960 hdd_exit();
Dustin Brown550f6d22017-12-14 15:44:01 -08002961
Arun Khandavallifae92942016-08-01 13:31:08 +05302962 return 0;
2963
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302964destroy_driver_sysfs:
2965 hdd_sysfs_destroy_powerstats_interface();
2966 hdd_sysfs_destroy_version_interface();
2967 hdd_sysfs_destroy_driver_root_obj();
Rajeev Kumarbe021242017-02-16 16:12:23 -08002968 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002969
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302970deregister_cb:
2971 hdd_deregister_cb(hdd_ctx);
2972
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002973cds_txrx_free:
Dustin Brown1dbefe62018-09-11 16:32:03 -07002974 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->psoc);
Jingxiang Ge95912f82018-04-19 12:01:26 +08002975
2976 if (tgt_hdl && target_psoc_get_wmi_ready(tgt_hdl)) {
2977 hdd_runtime_suspend_context_deinit(hdd_ctx);
Dustin Brown07901ec2018-09-07 11:02:41 -07002978 dispatcher_pdev_close(hdd_ctx->pdev);
Jingxiang Ge95912f82018-04-19 12:01:26 +08002979 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
2980 }
2981
Dustin Brown1dbefe62018-09-11 16:32:03 -07002982 cds_dp_close(hdd_ctx->psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08002983
Arun Khandavallifae92942016-08-01 13:31:08 +05302984close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002985 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002986 hdd_info("Wlan transition aborted (now CLOSED)");
2987
Dustin Brown1dbefe62018-09-11 16:32:03 -07002988 cds_close(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302989
Krunal Sonie71838d2018-09-27 10:45:05 -07002990psoc_close:
Dustin Brown1dbefe62018-09-11 16:32:03 -07002991 hdd_component_psoc_close(hdd_ctx->psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002992 cds_deinit_ini_config();
2993
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002994cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302995 ol_cds_free();
2996
2997hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002998 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2999 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05303000power_down:
3001 if (!reinit && !unint)
3002 pld_power_off(qdf_dev->dev);
3003release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05303004 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05303005 mutex_unlock(&hdd_ctx->iface_change_lock);
Abhinav Kumar7ae9b7b2017-12-19 15:11:54 +05303006 if (hdd_ctx->target_hw_name) {
3007 qdf_mem_free(hdd_ctx->target_hw_name);
3008 hdd_ctx->target_hw_name = NULL;
3009 }
Dustin Brown29533f22018-07-24 13:11:56 -07003010
3011 hdd_check_for_leaks(hdd_ctx, reinit);
Dustin Brown26b3d042017-12-21 11:13:27 -08003012 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08003013
Dustin Browne74003f2018-03-14 12:51:58 -07003014 hdd_exit();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08003015
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07003016 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05303017}
3018
Naveen Rawat910726a2017-03-06 11:42:51 -08003019#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003020static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003021{
3022 int ret = os_if_wifi_pos_register_nl();
3023
3024 if (ret)
3025 hdd_err("os_if_wifi_pos_register_nl failed");
3026
3027 return ret;
3028}
3029
3030static int hdd_deactivate_wifi_pos(void)
3031{
3032 int ret = os_if_wifi_pos_deregister_nl();
3033
3034 if (ret)
3035 hdd_err("os_if_wifi_pos_deregister_nl failed");
3036
3037 return ret;
3038}
3039
3040/**
3041 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
3042 * @hdd_ctx: hdd context
3043 *
3044 * Return: status of operation
3045 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003046static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003047{
Dustin Brown1dbefe62018-09-11 16:32:03 -07003048 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Wu Gao1ab05582018-11-08 16:22:49 +08003049 uint16_t neighbor_scan_max_chan_time;
3050 uint16_t neighbor_scan_min_chan_time;
Naveen Rawat910726a2017-03-06 11:42:51 -08003051
3052 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
3053 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
3054 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
3055 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
3056 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
3057 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
Wu Gao1ab05582018-11-08 16:22:49 +08003058 ucfg_mlme_get_neighbor_scan_max_chan_time(psoc,
3059 &neighbor_scan_max_chan_time);
3060 ucfg_mlme_get_neighbor_scan_min_chan_time(psoc,
3061 &neighbor_scan_min_chan_time);
3062 wifi_pos_set_dwell_time_min(psoc, neighbor_scan_min_chan_time);
3063 wifi_pos_set_dwell_time_max(psoc, neighbor_scan_max_chan_time);
Naveen Rawat910726a2017-03-06 11:42:51 -08003064}
3065#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003066static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003067{
3068 return oem_activate_service(hdd_ctx);
3069}
3070
3071static int hdd_deactivate_wifi_pos(void)
3072{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05303073 return oem_deactivate_service();
Naveen Rawat910726a2017-03-06 11:42:51 -08003074}
3075
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003076static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003077{
3078}
3079#endif
3080
Arun Khandavallifae92942016-08-01 13:31:08 +05303081/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003082 * __hdd_open() - HDD Open function
3083 * @dev: Pointer to net_device structure
3084 *
3085 * This is called in response to ifconfig up
3086 *
3087 * Return: 0 for success; non-zero for failure
3088 */
3089static int __hdd_open(struct net_device *dev)
3090{
Jeff Johnson9d295242017-08-29 14:39:48 -07003091 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003092 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003093 int ret;
3094
Dustin Brownfdf17c12018-03-14 12:55:34 -07003095 hdd_enter_dev(dev);
Ashish Kumar Dhanotiyaf10aa5f2018-12-28 21:29:56 +05303096
3097 qdf_mtrace(QDF_MODULE_ID_HDD, QDF_MODULE_ID_HDD,
3098 TRACE_CODE_HDD_OPEN_REQUEST,
3099 adapter->session_id, adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003100
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05303101 /* Nothing to be done if device is unloading */
3102 if (cds_is_driver_unloading()) {
3103 hdd_err("Driver is unloading can not open the hdd");
3104 return -EBUSY;
3105 }
3106
Dustin Brown01847752017-10-25 13:56:27 -07003107 if (cds_is_driver_recovering()) {
3108 hdd_err("WLAN is currently recovering; Please try again.");
3109 return -EBUSY;
3110 }
3111
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05303112 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
3113 hdd_err("con_mode_handler is in progress; Please try again.");
3114 return -EBUSY;
3115 }
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303116
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05303117 mutex_lock(&hdd_init_deinit_lock);
Jeff Johnson5794d4f2018-12-04 11:57:09 -08003118 hdd_start_driver_ops_timer(HDD_DRV_OP_IFF_UP);
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05303119
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303120 /*
3121 * This scenario can be hit in cases where in the wlan driver after
3122 * registering the netdevices and there is a failure in driver
3123 * initialization. So return error gracefully because the netdevices
3124 * will be de-registered as part of the load failure.
3125 */
3126
3127 if (!cds_is_driver_loaded()) {
3128 hdd_err("Failed to start the wlan driver!!");
3129 ret = -EIO;
3130 goto err_hdd_hdd_init_deinit_lock;
3131 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303132
Dustin Brown3ecc8782018-09-19 16:37:13 -07003133 ret = hdd_psoc_idle_restart(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05303134 if (ret) {
3135 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303136 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05303137 }
3138
Arun Khandavallifae92942016-08-01 13:31:08 +05303139 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3140 ret = hdd_start_adapter(adapter);
3141 if (ret) {
3142 hdd_err("Failed to start adapter :%d",
3143 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303144 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05303145 }
3146 }
3147
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003148 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3149 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003150 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003151 /* Enable TX queues only when we are connected */
3152 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05303153 WLAN_START_ALL_NETIF_QUEUE,
3154 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003155 }
3156
Naveen Rawat286def52016-09-23 15:38:02 -07003157 /* Enable carrier and transmit queues for NDI */
3158 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003159 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07003160 wlan_hdd_netif_queue_control(adapter,
3161 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
3162 WLAN_CONTROL_PATH);
3163 }
3164
Naveen Rawat910726a2017-03-06 11:42:51 -08003165 hdd_populate_wifi_pos_cfg(hdd_ctx);
Arunk Khandavalli40943af2017-05-15 19:25:34 +05303166 hdd_lpass_notify_start(hdd_ctx, adapter);
Naveen Rawat910726a2017-03-06 11:42:51 -08003167
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303168err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05303169 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303170 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003171 return ret;
3172}
3173
Arun Khandavallifae92942016-08-01 13:31:08 +05303174
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003175/**
3176 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
3177 * @dev: Pointer to net_device structure
3178 *
3179 * This is called in response to ifconfig up
3180 *
3181 * Return: 0 for success; non-zero for failure
3182 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003183static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003184{
3185 int ret;
3186
3187 cds_ssr_protect(__func__);
3188 ret = __hdd_open(dev);
3189 cds_ssr_unprotect(__func__);
3190
3191 return ret;
3192}
3193
3194/**
3195 * __hdd_stop() - HDD stop function
3196 * @dev: Pointer to net_device structure
3197 *
3198 * This is called in response to ifconfig down
3199 *
3200 * Return: 0 for success; non-zero for failure
3201 */
3202static int __hdd_stop(struct net_device *dev)
3203{
Jeff Johnson9d295242017-08-29 14:39:48 -07003204 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003205 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003206 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -07003207 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003208
Dustin Brownfdf17c12018-03-14 12:55:34 -07003209 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003210
Ashish Kumar Dhanotiyaf10aa5f2018-12-28 21:29:56 +05303211 qdf_mtrace(QDF_MODULE_ID_HDD, QDF_MODULE_ID_HDD,
3212 TRACE_CODE_HDD_STOP_REQUEST,
3213 adapter->session_id, adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003214
3215 ret = wlan_hdd_validate_context(hdd_ctx);
Arunk Khandavalli987c8d52018-06-21 17:40:31 +05303216 if (ret) {
3217 set_bit(DOWN_DURING_SSR, &adapter->event_flags);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003218 return ret;
Arunk Khandavalli987c8d52018-06-21 17:40:31 +05303219 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003220
3221 /* Nothing to be done if the interface is not opened */
3222 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003223 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003224 return -ENODEV;
3225 }
3226
3227 /* Make sure the interface is marked as closed */
3228 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303229
Jeff Johnson16528362018-06-14 12:34:16 -07003230 mac_handle = hdd_ctx->mac_handle;
3231
Mukul Sharmad16c2022017-07-25 18:56:12 +05303232 hdd_debug("Disabling Auto Power save timer");
3233 sme_ps_disable_auto_ps_timer(
Jeff Johnson16528362018-06-14 12:34:16 -07003234 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003235 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303236
3237 /*
3238 * Disable TX on the interface, after this hard_start_xmit() will not
3239 * be called on that interface
3240 */
Dustin Browna7bb6ae2018-08-16 16:51:50 -07003241 hdd_debug("Disabling queues, adapter device mode: %s(%d)",
Dustin Brown458027c2018-10-19 12:26:27 -07003242 qdf_opmode_str(adapter->device_mode), adapter->device_mode);
Kabilan Kannan8dac3502017-10-30 12:40:27 -07003243
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303244 wlan_hdd_netif_queue_control(adapter,
3245 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3246 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003247
Arunk Khandavalli40943af2017-05-15 19:25:34 +05303248 if (adapter->device_mode == QDF_STA_MODE)
3249 hdd_lpass_notify_stop(hdd_ctx);
3250
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003251 /*
Naveen Rawat286def52016-09-23 15:38:02 -07003252 * NAN data interface is different in some sense. The traffic on NDI is
3253 * bursty in nature and depends on the need to transfer. The service
3254 * layer may down the interface after the usage and up again when
3255 * required. In some sense, the NDI is expected to be available
3256 * (like SAP) iface until NDI delete request is issued by the service
3257 * layer. Skip BSS termination and adapter deletion for NAN Data
3258 * interface (NDI).
3259 */
3260 if (WLAN_HDD_IS_NDI(adapter))
3261 return 0;
3262
3263 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003264 * The interface is marked as down for outside world (aka kernel)
3265 * But the driver is pretty much alive inside. The driver needs to
3266 * tear down the existing connection on the netdev (session)
3267 * cleanup the data pipes and wait until the control plane is stabilized
3268 * for this interface. The call also needs to wait until the above
3269 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003270 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003271 * That is intentional to be able to scan if it is a STA/P2P interface
3272 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08003273 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003274
3275 /* DeInit the adapter. This ensures datapath cleanup as well */
3276 hdd_deinit_adapter(hdd_ctx, adapter, true);
3277
Dustin Brown4c663222018-10-23 14:19:36 -07003278 if (!hdd_is_any_interface_open(hdd_ctx))
3279 hdd_psoc_idle_timer_start(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05303280
Dustin Browne74003f2018-03-14 12:51:58 -07003281 hdd_exit();
Dustin Brown4c663222018-10-23 14:19:36 -07003282
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003283 return 0;
3284}
3285
3286/**
3287 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3288 * @dev: pointer to net_device structure
3289 *
3290 * This is called in response to ifconfig down
3291 *
3292 * Return: 0 for success and error number for failure
3293 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003294static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003295{
3296 int ret;
3297
3298 cds_ssr_protect(__func__);
3299 ret = __hdd_stop(dev);
3300 cds_ssr_unprotect(__func__);
3301
3302 return ret;
3303}
3304
3305/**
3306 * __hdd_uninit() - HDD uninit function
3307 * @dev: Pointer to net_device structure
3308 *
3309 * This is called during the netdev unregister to uninitialize all data
3310 * associated with the device
3311 *
3312 * Return: None
3313 */
3314static void __hdd_uninit(struct net_device *dev)
3315{
Jeff Johnson9d295242017-08-29 14:39:48 -07003316 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003317 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003318
Dustin Brownfdf17c12018-03-14 12:55:34 -07003319 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003320
3321 do {
3322 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003323 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003324 break;
3325 }
3326
Jeff Johnson399c6272017-08-30 10:51:00 -07003327 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3328 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003329 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003330 break;
3331 }
3332
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003333 if (dev != adapter->dev)
3334 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003335
Jeff Johnson399c6272017-08-30 10:51:00 -07003336 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003337
3338 /* after uninit our adapter structure will no longer be valid */
3339 adapter->dev = NULL;
3340 adapter->magic = 0;
3341 } while (0);
3342
Dustin Browne74003f2018-03-14 12:51:58 -07003343 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003344}
3345
3346/**
3347 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
3348 * @dev: pointer to net_device structure
3349 *
3350 * This is called during the netdev unregister to uninitialize all data
3351 * associated with the device
3352 *
3353 * Return: none
3354 */
3355static void hdd_uninit(struct net_device *dev)
3356{
3357 cds_ssr_protect(__func__);
3358 __hdd_uninit(dev);
3359 cds_ssr_unprotect(__func__);
3360}
3361
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003362static int hdd_open_cesium_nl_sock(void)
3363{
3364#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3365 struct netlink_kernel_cfg cfg = {
3366 .groups = WLAN_NLINK_MCAST_GRP_ID,
3367 .input = NULL
3368 };
3369#endif
3370 int ret = 0;
3371
3372#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3373 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3374#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3375 THIS_MODULE,
3376#endif
3377 &cfg);
3378#else
3379 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3380 WLAN_NLINK_MCAST_GRP_ID,
3381 NULL, NULL, THIS_MODULE);
3382#endif
3383
3384 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003385 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003386 ret = -ECONNREFUSED;
3387 }
3388
3389 return ret;
3390}
3391
3392static void hdd_close_cesium_nl_sock(void)
3393{
3394 if (NULL != cesium_nl_srv_sock) {
3395 netlink_kernel_release(cesium_nl_srv_sock);
3396 cesium_nl_srv_sock = NULL;
3397 }
3398}
3399
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303400void hdd_update_dynamic_mac(struct hdd_context *hdd_ctx,
3401 struct qdf_mac_addr *curr_mac_addr,
3402 struct qdf_mac_addr *new_mac_addr)
3403{
3404 uint8_t i;
3405
3406 hdd_enter();
3407
3408 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303409 if (!qdf_mem_cmp(
3410 curr_mac_addr->bytes,
3411 &hdd_ctx->dynamic_mac_list[i].dynamic_mac.bytes[0],
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303412 sizeof(struct qdf_mac_addr))) {
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303413 qdf_mem_copy(&hdd_ctx->dynamic_mac_list[i].dynamic_mac,
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303414 new_mac_addr->bytes,
3415 sizeof(struct qdf_mac_addr));
3416 break;
3417 }
3418 }
3419
3420 hdd_exit();
3421}
3422
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003423/**
3424 * __hdd_set_mac_address() - set the user specified mac address
3425 * @dev: Pointer to the net device.
3426 * @addr: Pointer to the sockaddr.
3427 *
3428 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003429 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003430 *
3431 * Return: 0 for success, non zero for failure
3432 */
3433static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3434{
Jeff Johnson9d295242017-08-29 14:39:48 -07003435 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303436 struct hdd_adapter *adapter_temp;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003437 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003438 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303439 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003440 int ret;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303441 struct qdf_mac_addr mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003442
Dustin Brownfdf17c12018-03-14 12:55:34 -07003443 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003444
Hanumanth Reddy Pothula5c7a7812018-03-09 12:55:32 +05303445 if (netif_running(dev)) {
3446 hdd_err("On iface up, set mac address change isn't supported");
3447 return -EBUSY;
3448 }
3449
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003450 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3451 ret = wlan_hdd_validate_context(hdd_ctx);
3452 if (0 != ret)
3453 return ret;
3454
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303455 qdf_mem_copy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303456 adapter_temp = hdd_get_adapter_by_macaddr(hdd_ctx, mac_addr.bytes);
3457 if (adapter_temp) {
3458 if (!qdf_str_cmp(adapter_temp->dev->name, dev->name))
3459 return 0;
3460 hdd_err("%s adapter exist with same address " MAC_ADDRESS_STR,
3461 adapter_temp->dev->name,
Ashish Kumar Dhanotiyaf974f332018-04-19 16:03:15 +05303462 MAC_ADDR_ARRAY(mac_addr.bytes));
3463 return -EINVAL;
3464 }
3465
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05303466 qdf_ret_status = wlan_hdd_validate_mac_address(&mac_addr);
3467 if (QDF_IS_STATUS_ERROR(qdf_ret_status))
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303468 return -EINVAL;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303469
Ashish Kumar Dhanotiya8bfef122018-04-18 16:48:27 +05303470 hdd_info("Changing MAC to " MAC_ADDRESS_STR " of the interface %s ",
3471 MAC_ADDR_ARRAY(mac_addr.bytes), dev->name);
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303472
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303473 hdd_update_dynamic_mac(hdd_ctx, &adapter->mac_addr, &mac_addr);
Jeff Johnson1e851a12017-10-28 14:36:12 -07003474 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003475 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3476
Dustin Browne74003f2018-03-14 12:51:58 -07003477 hdd_exit();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303478 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003479}
3480
3481/**
3482 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3483 * function from SSR
3484 * @dev: pointer to net_device structure
3485 * @addr: Pointer to the sockaddr
3486 *
3487 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003488 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003489 *
3490 * Return: 0 for success.
3491 */
3492static int hdd_set_mac_address(struct net_device *dev, void *addr)
3493{
3494 int ret;
3495
3496 cds_ssr_protect(__func__);
3497 ret = __hdd_set_mac_address(dev, addr);
3498 cds_ssr_unprotect(__func__);
3499
3500 return ret;
3501}
3502
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303503static uint8_t *wlan_hdd_get_derived_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003504{
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303505 int i, j;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003506
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303507 i = qdf_ffz(hdd_ctx->derived_intf_addr_mask);
3508 if (i < 0 || i >= hdd_ctx->num_derived_addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003509 return NULL;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303510 qdf_atomic_set_bit(i, &hdd_ctx->derived_intf_addr_mask);
3511 hdd_info("Assigning MAC from derived list" MAC_ADDRESS_STR,
3512 MAC_ADDR_ARRAY(hdd_ctx->derived_mac_addr[i].bytes));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003513
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303514 /* Copy the mac in dynamic mac list at first free position */
3515 for (j = 0; j < QDF_MAX_CONCURRENCY_PERSONA; j++) {
3516 if (qdf_is_macaddr_zero(&hdd_ctx->
3517 dynamic_mac_list[j].dynamic_mac))
3518 break;
3519 }
3520 if (j == QDF_MAX_CONCURRENCY_PERSONA) {
3521 hdd_err("Max interfaces are up");
3522 return NULL;
3523 }
Dustin Brown61cc3932018-10-18 16:12:13 -07003524
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303525 qdf_mem_copy(&hdd_ctx->dynamic_mac_list[j].dynamic_mac.bytes,
3526 &hdd_ctx->derived_mac_addr[i].bytes,
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303527 sizeof(struct qdf_mac_addr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303528 hdd_ctx->dynamic_mac_list[j].is_provisioned_mac = false;
3529 hdd_ctx->dynamic_mac_list[j].bit_position = i;
3530
3531 return hdd_ctx->derived_mac_addr[i].bytes;
3532}
3533
3534static uint8_t *wlan_hdd_get_provisioned_intf_addr(struct hdd_context *hdd_ctx)
3535{
3536 int i, j;
3537
3538 i = qdf_ffz(hdd_ctx->provisioned_intf_addr_mask);
3539 if (i < 0 || i >= hdd_ctx->num_provisioned_addr)
3540 return NULL;
3541 qdf_atomic_set_bit(i, &hdd_ctx->provisioned_intf_addr_mask);
3542 hdd_info("Assigning MAC from provisioned list" MAC_ADDRESS_STR,
3543 MAC_ADDR_ARRAY(hdd_ctx->provisioned_mac_addr[i].bytes));
3544
3545 /* Copy the mac in dynamic mac list at first free position */
3546 for (j = 0; j < QDF_MAX_CONCURRENCY_PERSONA; j++) {
3547 if (qdf_is_macaddr_zero(&hdd_ctx->
3548 dynamic_mac_list[j].dynamic_mac))
3549 break;
3550 }
3551 if (j == QDF_MAX_CONCURRENCY_PERSONA) {
3552 hdd_err("Max interfaces are up");
3553 return NULL;
3554 }
3555
3556 qdf_mem_copy(&hdd_ctx->dynamic_mac_list[j].dynamic_mac.bytes,
3557 &hdd_ctx->provisioned_mac_addr[i].bytes,
3558 sizeof(struct qdf_mac_addr));
3559 hdd_ctx->dynamic_mac_list[j].is_provisioned_mac = true;
3560 hdd_ctx->dynamic_mac_list[j].bit_position = i;
3561 return hdd_ctx->provisioned_mac_addr[i].bytes;
3562}
3563
3564uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx,
3565 enum QDF_OPMODE interface_type)
3566{
3567 uint8_t *mac_addr = NULL;
3568
3569 if (qdf_atomic_test_bit(interface_type,
3570 (unsigned long *)
3571 (&hdd_ctx->config->provisioned_intf_pool)))
3572 mac_addr = wlan_hdd_get_provisioned_intf_addr(hdd_ctx);
3573
3574 if ((!mac_addr) &&
3575 (qdf_atomic_test_bit(interface_type,
3576 (unsigned long *)
3577 (&hdd_ctx->config->derived_intf_pool))))
3578 mac_addr = wlan_hdd_get_derived_intf_addr(hdd_ctx);
3579
3580 if (!mac_addr)
3581 hdd_err("MAC is not available in both the lists");
3582 return mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003583}
3584
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003585void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3586 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003587{
3588 int i;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303589 int mac_pos_in_mask;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003590
Anurag Chouhan6d760662016-02-20 16:05:43 +05303591 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003592 if (!memcmp(releaseAddr,
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303593 hdd_ctx->dynamic_mac_list[i].dynamic_mac.bytes,
3594 QDF_MAC_ADDR_SIZE)) {
3595 mac_pos_in_mask =
3596 hdd_ctx->dynamic_mac_list[i].bit_position;
3597 if (hdd_ctx->dynamic_mac_list[i].is_provisioned_mac) {
3598 qdf_atomic_clear_bit(
3599 mac_pos_in_mask,
3600 &hdd_ctx->
3601 provisioned_intf_addr_mask);
3602 hdd_info("Releasing MAC from provisioned list");
3603 hdd_info(
3604 MAC_ADDRESS_STR,
3605 MAC_ADDR_ARRAY(releaseAddr));
3606 } else {
3607 qdf_atomic_clear_bit(
3608 mac_pos_in_mask, &hdd_ctx->
3609 derived_intf_addr_mask);
3610 hdd_info("Releasing MAC from derived list");
3611 hdd_info(MAC_ADDRESS_STR,
3612 MAC_ADDR_ARRAY(releaseAddr));
3613 }
3614 qdf_zero_macaddr(&hdd_ctx->
3615 dynamic_mac_list[i].dynamic_mac);
3616 hdd_ctx->dynamic_mac_list[i].is_provisioned_mac =
3617 false;
3618 hdd_ctx->dynamic_mac_list[i].bit_position = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003619 break;
3620 }
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303621
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003622 }
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303623 if (i == QDF_MAX_CONCURRENCY_PERSONA)
3624 hdd_err("Releasing non existing MAC" MAC_ADDRESS_STR,
3625 MAC_ADDR_ARRAY(releaseAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003626}
3627
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003628/**
3629 * __hdd_set_multicast_list() - set the multicast address list
3630 * @dev: Pointer to the WLAN device.
3631 * @skb: Pointer to OS packet (sk_buff).
3632 *
3633 * This funciton sets the multicast address list.
3634 *
3635 * Return: None
3636 */
3637static void __hdd_set_multicast_list(struct net_device *dev)
3638{
Jeff Johnson9d295242017-08-29 14:39:48 -07003639 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Dustin Brown0f874482018-06-13 14:39:22 -07003640 int i = 0, errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003641 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003642 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303643 struct pmo_mc_addr_list_params *mc_list_request = NULL;
Dustin Brown1dbefe62018-09-11 16:32:03 -07003644 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303645 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003646
Dustin Brownfdf17c12018-03-14 12:55:34 -07003647 hdd_enter_dev(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303648 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303649 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303650
Dustin Brown0f874482018-06-13 14:39:22 -07003651 errno = wlan_hdd_validate_context(hdd_ctx);
3652 if (errno)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303653 goto out;
3654
Dustin Brown0f874482018-06-13 14:39:22 -07003655 errno = hdd_validate_adapter(adapter);
3656 if (errno)
Dustin Brownc788acb2017-08-01 17:43:51 -07003657 goto out;
3658
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303659 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3660 hdd_err("%s: Driver module is closed", __func__);
Dustin Brown0f874482018-06-13 14:39:22 -07003661 goto out;
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303662 }
3663
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303664 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
Min Liu74a1a502018-10-10 19:59:07 +08003665 if (!mc_list_request)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303666 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003667
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303668 /* Delete already configured multicast address list */
3669 if (adapter->mc_addr_list.mc_cnt > 0) {
Dustin Brown0f874482018-06-13 14:39:22 -07003670 hdd_debug("clear previously configured MC address list");
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303671 hdd_disable_and_flush_mc_addr_list(adapter,
3672 pmo_mc_list_change_notify);
3673 }
3674
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003675 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003676 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303677 hdd_disable_and_flush_mc_addr_list(adapter,
3678 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003679 } else {
3680 mc_count = netdev_mc_count(dev);
Wu Gaod7dd6e42018-10-16 17:22:56 +08003681 if (mc_count > ucfg_pmo_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003682 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Wu Gaod7dd6e42018-10-16 17:22:56 +08003683 ucfg_pmo_max_mc_addr_supported(psoc));
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303684 hdd_disable_and_flush_mc_addr_list(adapter,
3685 pmo_mc_list_change_notify);
stonezdf2bdfd2018-11-20 14:45:06 +08003686 adapter->mc_addr_list.mc_cnt = 0;
Dustin Brown0f874482018-06-13 14:39:22 -07003687 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003688 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003689 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003690 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303691 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003692 if (i == mc_count)
3693 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303694 memset(&(mc_list_request->mc_addr[i].bytes),
3695 0, ETH_ALEN);
3696 memcpy(&(mc_list_request->mc_addr[i].bytes),
3697 ha->addr, ETH_ALEN);
Dustin Brown0f874482018-06-13 14:39:22 -07003698 hdd_debug("mlist[%d] = %pM", i,
3699 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003700 i++;
3701 }
3702 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303703
stonezdf2bdfd2018-11-20 14:45:06 +08003704 adapter->mc_addr_list.mc_cnt = mc_count;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303705 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003706 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303707 mc_list_request->count = mc_count;
Dustin Brown0f874482018-06-13 14:39:22 -07003708
3709 errno = hdd_cache_mc_addr_list(mc_list_request);
3710 if (errno) {
3711 hdd_err("Failed to cache MC address list for vdev %u; errno:%d",
3712 adapter->session_id, errno);
3713 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003714 }
Dustin Brown0f874482018-06-13 14:39:22 -07003715
3716 hdd_enable_mc_addr_filtering(adapter, pmo_mc_list_change_notify);
3717
3718free_req:
3719 qdf_mem_free(mc_list_request);
3720
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303721out:
Dustin Browne74003f2018-03-14 12:51:58 -07003722 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003723}
3724
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303725
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003726/**
3727 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3728 * @dev: pointer to net_device
3729 *
3730 * Return: none
3731 */
3732static void hdd_set_multicast_list(struct net_device *dev)
3733{
3734 cds_ssr_protect(__func__);
3735 __hdd_set_multicast_list(dev);
3736 cds_ssr_unprotect(__func__);
3737}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003738
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003739static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003740 .ndo_open = hdd_open,
3741 .ndo_stop = hdd_stop,
3742 .ndo_uninit = hdd_uninit,
3743 .ndo_start_xmit = hdd_hard_start_xmit,
3744 .ndo_tx_timeout = hdd_tx_timeout,
3745 .ndo_get_stats = hdd_get_stats,
3746 .ndo_do_ioctl = hdd_ioctl,
3747 .ndo_set_mac_address = hdd_set_mac_address,
3748 .ndo_select_queue = hdd_select_queue,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003749 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003750};
3751
Nirav Shah73713f72018-05-17 14:50:41 +05303752#ifdef FEATURE_MONITOR_MODE_SUPPORT
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003753/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003754static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003755 .ndo_open = hdd_mon_open,
3756 .ndo_stop = hdd_stop,
3757 .ndo_get_stats = hdd_get_stats,
3758};
3759
3760/**
3761 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003762 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003763 * Return: None
3764 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003765void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003766{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003767 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003768 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003769 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003770 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003771}
Nirav Shah73713f72018-05-17 14:50:41 +05303772#else
3773void hdd_set_station_ops(struct net_device *dev)
3774{
3775 dev->netdev_ops = &wlan_drv_ops;
3776}
3777#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003778
3779/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003780 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3781 * @hdd_ctx: global hdd context
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003782 * @mac_addr: mac address to assign to the interface
Ryan Hsu07495ea2016-01-21 15:25:39 -08003783 * @name: User-visible name of the interface
3784 *
3785 * hdd adapter pointer would point to the netdev->priv space, this function
Jeff Johnson62018292018-05-06 16:18:35 -07003786 * would retrieve the pointer, and setup the hdd adapter configuration.
Ryan Hsu07495ea2016-01-21 15:25:39 -08003787 *
3788 * Return: the pointer to hdd adapter, otherwise NULL
3789 */
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003790static struct hdd_adapter *
3791hdd_alloc_station_adapter(struct hdd_context *hdd_ctx, tSirMacAddr mac_addr,
3792 unsigned char name_assign_type, const char *name)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003793{
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003794 struct net_device *dev;
3795 struct hdd_adapter *adapter;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003796 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303797 QDF_STATUS qdf_status;
jitiphil377bcc12018-10-05 19:46:08 +05303798 void *soc;
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003799
jitiphil377bcc12018-10-05 19:46:08 +05303800 soc = cds_get_context(QDF_MODULE_ID_SOC);
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003801 /* cfg80211 initialization and registration */
3802 dev = alloc_netdev_mq(sizeof(*adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003803#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003804 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003805#endif
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003806 (cds_get_conparam() == QDF_GLOBAL_MONITOR_MODE ?
3807 hdd_mon_mode_ether_setup : ether_setup),
3808 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003809
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003810 if (!dev) {
3811 hdd_err("Failed to allocate new net_device '%s'", name);
3812 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003813 }
3814
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003815 adapter = netdev_priv(dev);
3816
3817 qdf_mem_zero(adapter, sizeof(*adapter));
3818 sta_ctx = &adapter->session.station;
3819 qdf_mem_set(sta_ctx->conn_info.staId, sizeof(sta_ctx->conn_info.staId),
3820 HDD_WLAN_INVALID_STA_ID);
3821 adapter->dev = dev;
3822 adapter->hdd_ctx = hdd_ctx;
3823 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
3824 adapter->session_id = HDD_SESSION_ID_INVALID;
3825
3826 qdf_status = qdf_event_create(&adapter->qdf_session_open_event);
3827 if (QDF_IS_STATUS_ERROR(qdf_status))
3828 goto free_net_dev;
3829
3830 qdf_status = qdf_event_create(&adapter->qdf_session_close_event);
3831 if (QDF_IS_STATUS_ERROR(qdf_status))
3832 goto free_net_dev;
3833
3834 adapter->offloads_configured = false;
3835 adapter->is_link_up_service_needed = false;
3836 adapter->disconnection_in_progress = false;
3837 adapter->send_mode_change = true;
3838
3839 /* Init the net_device structure */
3840 strlcpy(dev->name, name, IFNAMSIZ);
3841
3842 qdf_mem_copy(dev->dev_addr, mac_addr, sizeof(tSirMacAddr));
3843 qdf_mem_copy(adapter->mac_addr.bytes, mac_addr, sizeof(tSirMacAddr));
3844 dev->watchdog_timeo = HDD_TX_TIMEOUT;
3845
jitiphil377bcc12018-10-05 19:46:08 +05303846 if (cdp_cfg_get(soc,
3847 cfg_dp_enable_ip_tcp_udp_checksum_offload))
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003848 dev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
3849 dev->features |= NETIF_F_RXCSUM;
3850
3851 hdd_set_tso_flags(hdd_ctx, dev);
3852 hdd_set_station_ops(adapter->dev);
3853
3854 hdd_dev_setup_destructor(dev);
3855 dev->ieee80211_ptr = &adapter->wdev;
3856 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
3857 adapter->wdev.wiphy = hdd_ctx->wiphy;
3858 adapter->wdev.netdev = dev;
3859
3860 /* set dev's parent to underlying device */
3861 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
3862 hdd_wmm_init(adapter);
3863 spin_lock_init(&adapter->pause_map_lock);
3864 adapter->start_time = qdf_system_ticks();
3865 adapter->last_time = adapter->start_time;
3866
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003867 return adapter;
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003868
3869free_net_dev:
3870 free_netdev(adapter->dev);
3871
3872 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003873}
3874
Jeff Johnson9d295242017-08-29 14:39:48 -07003875static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003876{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003877 struct net_device *dev = adapter->dev;
3878 int ret;
3879
Dustin Brown491d54b2018-03-14 12:39:11 -07003880 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003881
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003882 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003883 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3884
3885 ret = dev_alloc_name(dev, dev->name);
3886 if (ret < 0) {
3887 hdd_err(
3888 "unable to get dev name: %s, err = 0x%x",
3889 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303890 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003891 }
3892 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003893
3894 ret = register_netdevice(dev);
3895 if (ret) {
3896 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3897 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303898 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003899 }
3900 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003901 ret = register_netdev(dev);
3902 if (ret) {
3903 hdd_err("register_netdev(%s) failed, err = 0x%x",
3904 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303905 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003906 }
3907 }
3908 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3909
Dustin Browne74003f2018-03-14 12:51:58 -07003910 hdd_exit();
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003911
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303912 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003913}
3914
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05303915QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id,
3916 QDF_STATUS qdf_status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003917{
Krunal Sonib51eec72017-11-20 21:53:01 -08003918 struct hdd_adapter *adapter;
3919 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003920
Krunal Sonib51eec72017-11-20 21:53:01 -08003921 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3922 if (!hdd_ctx) {
3923 hdd_err("Invalid HDD_CTX");
3924 return QDF_STATUS_E_FAILURE;
3925 }
3926
3927 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3928 if (NULL == adapter) {
Naveen Rawat23a3b912018-05-30 17:45:52 -07003929 hdd_err("NULL adapter for %d", session_id);
Krunal Sonib51eec72017-11-20 21:53:01 -08003930 return QDF_STATUS_E_INVAL;
3931 }
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05303932
3933 if (qdf_status == QDF_STATUS_SUCCESS)
3934 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3935
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303936 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003937 hdd_debug("session %d opened", adapter->session_id);
3938
3939 return QDF_STATUS_SUCCESS;
3940}
3941
3942QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3943{
3944 struct hdd_adapter *adapter;
3945 struct hdd_context *hdd_ctx;
3946
3947 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3948 if (!hdd_ctx) {
3949 hdd_err("Invalid HDD_CTX");
3950 return QDF_STATUS_E_FAILURE;
3951 }
3952
3953 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003954 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003955 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303956 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003957 }
3958
3959 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003960 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303961 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003962 }
3963
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003964 /*
3965 * For NAN Data interface, the close session results in the final
3966 * indication to the userspace
3967 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003968 if (adapter->device_mode == QDF_NDI_MODE)
3969 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003970
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003971 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3972
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003973 /*
3974 * We can be blocked while waiting for scheduled work to be
3975 * flushed, and the adapter structure can potentially be freed, in
3976 * which case the magic will have been reset. So make sure the
3977 * magic is still good, and hence the adapter structure is still
3978 * valid, before signaling completion
3979 */
3980 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303981 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003982
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303983 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003984}
3985
Jeff Johnson9d295242017-08-29 14:39:48 -07003986int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003987{
Min Liu8c5d99e2018-09-10 17:18:44 +08003988 struct wlan_objmgr_vdev *vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07003989 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003990
Min Liu8c5d99e2018-09-10 17:18:44 +08003991 vdev = hdd_objmgr_get_vdev(adapter);
3992 if (!vdev)
3993 return -EINVAL;
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003994
Min Liu8c5d99e2018-09-10 17:18:44 +08003995 status = pmo_vdev_ready(vdev);
3996 if (QDF_IS_STATUS_ERROR(status)) {
3997 hdd_objmgr_put_vdev(adapter);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003998 return qdf_status_to_os_return(status);
Min Liu8c5d99e2018-09-10 17:18:44 +08003999 }
4000
4001 status = ucfg_reg_11d_vdev_created_update(vdev);
4002 if (QDF_IS_STATUS_ERROR(status)) {
4003 hdd_objmgr_put_vdev(adapter);
4004 return qdf_status_to_os_return(status);
4005 }
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07004006
4007 if (wma_capability_enhanced_mcast_filter())
Min Liu8c5d99e2018-09-10 17:18:44 +08004008 status = ucfg_pmo_enhanced_mc_filter_enable(vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07004009 else
Min Liu8c5d99e2018-09-10 17:18:44 +08004010 status = ucfg_pmo_enhanced_mc_filter_disable(vdev);
4011
4012 hdd_objmgr_put_vdev(adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07004013
4014 return qdf_status_to_os_return(status);
4015}
4016
Jeff Johnson9d295242017-08-29 14:39:48 -07004017int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07004018{
4019 QDF_STATUS status;
Dustin Brown2da29eb2018-07-13 14:23:12 -07004020 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004021 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004022 uint8_t vdev_id;
Min Liu8c5d99e2018-09-10 17:18:44 +08004023 struct wlan_objmgr_vdev *vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07004024
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004025 vdev_id = adapter->session_id;
4026 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004027
4028 /* vdev created sanity check */
4029 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Dustin Brown2da29eb2018-07-13 14:23:12 -07004030 hdd_err("vdev %u does not exist", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004031 return -EINVAL;
4032 }
Dustin Brown2da29eb2018-07-13 14:23:12 -07004033
Min Liu8c5d99e2018-09-10 17:18:44 +08004034 vdev = hdd_objmgr_get_vdev(adapter);
4035 if (!vdev)
4036 return -EINVAL;
Ashish Kumar Dhanotiya68ee2e42018-11-19 21:15:14 +05304037
4038 ucfg_pmo_del_wow_pattern(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08004039 status = ucfg_reg_11d_vdev_delete_update(vdev);
Abhishek Singh935e4772018-11-21 14:14:10 +05304040 ucfg_scan_vdev_set_disable(vdev, REASON_VDEV_DOWN);
Min Liu8c5d99e2018-09-10 17:18:44 +08004041 hdd_objmgr_put_vdev(adapter);
Yue Maf9782842017-05-08 12:49:49 -07004042
Dustin Brownd28772b2017-03-17 14:16:07 -07004043 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304044 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07004045 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -07004046 status = sme_close_session(hdd_ctx->mac_handle, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004047 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Brown2da29eb2018-07-13 14:23:12 -07004048 hdd_err("failed to close sme session; status:%d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08004049 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07004050 }
4051
4052 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304053 status = qdf_wait_for_event_completion(
4054 &adapter->qdf_session_close_event,
Abhishek Singh13bf0ce2018-10-24 14:26:14 +05304055 SME_CMD_VDEV_CREATE_DELETE_TIMEOUT);
Dustin Brown2da29eb2018-07-13 14:23:12 -07004056
4057 if (QDF_IS_STATUS_ERROR(status)) {
4058 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
4059
Dustin Brownd28772b2017-03-17 14:16:07 -07004060 if (adapter->device_mode == QDF_NDI_MODE)
4061 hdd_ndp_session_end_handler(adapter);
Dustin Brown2da29eb2018-07-13 14:23:12 -07004062
4063 if (status == QDF_STATUS_E_TIMEOUT)
4064 hdd_err("timed out waiting for sme close session");
4065 else if (adapter->qdf_session_close_event.force_set)
4066 hdd_info("SSR occurred during sme close session");
4067 else
4068 hdd_err("failed to wait for sme close session; status:%u",
4069 status);
Dustin Brownd28772b2017-03-17 14:16:07 -07004070 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08004071
Yue Maf9782842017-05-08 12:49:49 -07004072release_vdev:
Jiachao Wu2c42c222018-01-15 18:13:19 +08004073
Sandeep Puligillaef415362017-08-30 16:37:13 -07004074 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08004075 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07004076 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08004077 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07004078 return errno;
4079 }
4080
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004081 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004082
4083 return 0;
4084}
4085
Krunal Sonib51eec72017-11-20 21:53:01 -08004086static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
4087 struct sme_session_params *session_param,
Jeff Johnson6a18c962018-07-01 09:09:37 -07004088 csr_roam_complete_cb callback,
Krunal Sonib51eec72017-11-20 21:53:01 -08004089 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07004090{
Dustin Brownd28772b2017-03-17 14:16:07 -07004091 uint32_t type;
4092 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08004093 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07004094
4095 /* determine vdev (sub)type */
4096 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304097 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07004098 hdd_err("failed to get vdev type: %d", status);
4099 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004100 }
Krunal Sonib51eec72017-11-20 21:53:01 -08004101 session_param->sme_session_id = adapter->session_id;
4102 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
4103 session_param->type_of_persona = type;
4104 session_param->subtype_of_persona = sub_type;
4105 session_param->session_open_cb = hdd_sme_open_session_callback;
4106 session_param->session_close_cb = hdd_sme_close_session_callback;
4107 session_param->callback = callback;
4108 session_param->callback_ctx = callback_ctx;
4109
4110 return 0;
4111}
4112
gaurank kathpalia78af1932018-10-27 20:33:10 +05304113static void
4114hdd_store_nss_chains_cfg_in_vdev(struct hdd_adapter *adapter)
4115{
4116 struct wlan_mlme_nss_chains vdev_ini_cfg;
4117 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4118
gaurank kathpaliab414bce2018-11-09 18:44:46 +05304119 /* Populate the nss chain params from ini for this vdev type */
gaurank kathpalia78af1932018-10-27 20:33:10 +05304120 sme_populate_nss_chain_params(hdd_ctx->mac_handle, &vdev_ini_cfg,
4121 adapter->device_mode,
4122 hdd_ctx->num_rf_chains);
gaurank kathpaliab414bce2018-11-09 18:44:46 +05304123
4124 /* Store the nss chain config into the vdev */
4125 sme_store_nss_chains_cfg_in_vdev(adapter->vdev, &vdev_ini_cfg);
gaurank kathpalia78af1932018-10-27 20:33:10 +05304126}
gaurank kathpalia6982d472018-10-31 21:54:15 +05304127
4128bool hdd_is_vdev_in_conn_state(struct hdd_adapter *adapter)
4129{
4130 switch (adapter->device_mode) {
4131 case QDF_STA_MODE:
4132 case QDF_P2P_CLIENT_MODE:
4133 case QDF_P2P_DEVICE_MODE:
4134 return hdd_conn_is_connected(
4135 WLAN_HDD_GET_STATION_CTX_PTR(adapter));
4136 case QDF_SAP_MODE:
4137 case QDF_P2P_GO_MODE:
4138 return (test_bit(SOFTAP_BSS_STARTED,
4139 &adapter->event_flags));
4140 default:
4141 hdd_err("Device mode %d invalid", adapter->device_mode);
4142 return 0;
4143 }
4144
4145 return 0;
4146}
4147
Krunal Sonib51eec72017-11-20 21:53:01 -08004148int hdd_vdev_create(struct hdd_adapter *adapter,
Jeff Johnson6a18c962018-07-01 09:09:37 -07004149 csr_roam_complete_cb callback, void *ctx)
Krunal Sonib51eec72017-11-20 21:53:01 -08004150{
4151 QDF_STATUS status;
4152 int errno;
Karthik Kantamneni9180c752018-11-14 12:14:17 +05304153 bool bval;
Krunal Sonib51eec72017-11-20 21:53:01 -08004154 struct hdd_context *hdd_ctx;
4155 struct sme_session_params sme_session_params = {0};
Min Liu8c5d99e2018-09-10 17:18:44 +08004156 struct wlan_objmgr_vdev *vdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004157
4158 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07004159
4160 /* do vdev create via objmgr */
4161 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown07901ec2018-09-07 11:02:41 -07004162 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07004163 if (errno) {
4164 hdd_err("failed to create objmgr vdev: %d", errno);
4165 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004166 }
Dustin Brownd28772b2017-03-17 14:16:07 -07004167
4168 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304169 status = qdf_event_reset(&adapter->qdf_session_open_event);
4170 if (QDF_STATUS_SUCCESS != status) {
4171 hdd_err("failed to reinit session open event");
4172 return -EINVAL;
4173 }
Krunal Sonib51eec72017-11-20 21:53:01 -08004174 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
4175 callback, ctx);
4176 if (errno) {
4177 hdd_err("failed to populating SME params");
4178 goto objmgr_vdev_destroy_procedure;
4179 }
Jeff Johnson16528362018-06-14 12:34:16 -07004180 status = sme_open_session(hdd_ctx->mac_handle, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07004181 if (QDF_IS_STATUS_ERROR(status)) {
4182 hdd_err("failed to open sme session: %d", status);
4183 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07004184 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004185 }
4186
4187 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304188 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
Abhishek Singh13bf0ce2018-10-24 14:26:14 +05304189 SME_CMD_VDEV_CREATE_DELETE_TIMEOUT);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304190 if (QDF_STATUS_SUCCESS != status) {
4191 if (adapter->qdf_session_open_event.force_set) {
4192 /*
4193 * SSR/PDR has caused shutdown, which has forcefully
4194 * set the event. Return without the closing session.
4195 */
4196 adapter->session_id = HDD_SESSION_ID_INVALID;
4197 hdd_err("Session open event forcefully set");
4198 return -EINVAL;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304199 }
Jeff Johnsonc66d3102018-02-28 11:58:26 -08004200
4201 if (QDF_STATUS_E_TIMEOUT == status)
4202 hdd_err("Session failed to open within timeout period");
4203 else
4204 hdd_err("Failed to wait for session open event(status-%d)",
4205 status);
4206 errno = -ETIMEDOUT;
4207 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
4208 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004209 }
4210
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05304211 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
4212 hdd_err("Session failed to open due to vdev create failure");
4213 errno = -EINVAL;
4214 goto objmgr_vdev_destroy_procedure;
4215 }
4216
Dustin Brownd28772b2017-03-17 14:16:07 -07004217 /* firmware ready for component communication, raise vdev_ready event */
4218 errno = hdd_vdev_ready(adapter);
4219 if (errno) {
4220 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07004221 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004222 }
4223
Naveen Rawat2b430892018-03-13 13:58:18 -07004224 if (adapter->device_mode == QDF_STA_MODE) {
Karthik Kantamneni9180c752018-11-14 12:14:17 +05304225 bval = false;
4226 status = ucfg_mlme_get_rtt_mac_randomization(hdd_ctx->psoc,
4227 &bval);
4228 if (QDF_IS_STATUS_ERROR(status))
4229 hdd_err("unable to get RTT MAC randomization value");
4230
4231 hdd_debug("setting RTT mac randomization param: %d", bval);
Naveen Rawat2b430892018-03-13 13:58:18 -07004232 errno = sme_cli_set_command(adapter->session_id,
4233 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_INITIATOR_RANDOM_MAC,
Karthik Kantamneni9180c752018-11-14 12:14:17 +05304234 bval,
Naveen Rawat2b430892018-03-13 13:58:18 -07004235 VDEV_CMD);
4236 if (0 != errno)
4237 hdd_err("RTT mac randomization param set failed %d",
4238 errno);
4239 }
4240
Bala Venkatesh110b03e2018-07-10 16:02:08 +05304241 if (adapter->device_mode == QDF_STA_MODE ||
Min Liu8c5d99e2018-09-10 17:18:44 +08004242 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
4243 vdev = hdd_objmgr_get_vdev(adapter);
4244 if (!vdev)
4245 goto hdd_vdev_destroy_procedure;
4246 wlan_vdev_set_max_peer_count(vdev, HDD_MAX_VDEV_PEER_COUNT);
4247 hdd_objmgr_put_vdev(adapter);
4248 }
Bala Venkatesh110b03e2018-07-10 16:02:08 +05304249
gaurank kathpalia78af1932018-10-27 20:33:10 +05304250 hdd_store_nss_chains_cfg_in_vdev(adapter);
4251
Jeff Johnson1b780e42017-10-31 14:11:45 -07004252 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004253
4254 return 0;
4255
4256 /*
4257 * Due to legacy constraints, we need to destroy in the same order as
4258 * create. So, split error handling into 2 cases to accommodate.
4259 */
4260
Krunal Soni4a020c72017-10-30 20:58:40 -07004261objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07004262 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07004263
4264 return errno;
4265
Krunal Soni4a020c72017-10-30 20:58:40 -07004266hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07004267 QDF_BUG(!hdd_vdev_destroy(adapter));
4268
4269 return errno;
4270}
4271
Jeff Johnson9d295242017-08-29 14:39:48 -07004272QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07004273{
Jeff Johnsonb9424862017-10-30 08:49:35 -07004274 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004275 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07004276 QDF_STATUS status;
4277 int ret_val;
Jeff Johnson16528362018-06-14 12:34:16 -07004278 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304279 bool bval = false;
Dustin Brownd28772b2017-03-17 14:16:07 -07004280
Dustin Brownd28772b2017-03-17 14:16:07 -07004281 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -07004282 mac_handle = hdd_ctx->mac_handle;
4283 sme_set_curr_device_mode(mac_handle, adapter->device_mode);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304284 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
4285 if (!QDF_IS_STATUS_SUCCESS(status))
4286 hdd_err("unable to get vht_enable2x2");
4287 sme_set_pdev_ht_vht_ies(mac_handle, bval);
4288
Jeff Johnson16528362018-06-14 12:34:16 -07004289 sme_set_vdev_ies_per_band(mac_handle, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004290
Jeff Johnson7f2c5912018-03-23 11:42:28 -07004291 hdd_roam_profile_init(adapter);
4292 hdd_register_wext(adapter->dev);
4293
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07004294 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004295
Jeff Johnsond377dce2017-10-04 10:32:42 -07004296 qdf_mem_set(sta_ctx->conn_info.staId,
4297 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05304298
Deepak Dhamdherea2785822016-11-17 01:17:45 -08004299 /* set fast roaming capability in sme session */
Jeff Johnson16528362018-06-14 12:34:16 -07004300 status = sme_config_fast_roaming(mac_handle, adapter->session_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05304301 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004302 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004303 sta_ctx->conn_info.operationChannel =
Vignesh Viswanathana0358ff2018-11-27 09:53:07 +05304304 hdd_ctx->config->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004305
4306 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004307 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004308
4309 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304310 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004311 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004312 status, status);
4313 goto error_init_txrx;
4314 }
4315
4316 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4317
4318 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304319 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004320 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004321 status, status);
4322 goto error_wmm_init;
4323 }
4324
4325 set_bit(WMM_INIT_DONE, &adapter->event_flags);
4326
Jeff Johnson1b780e42017-10-31 14:11:45 -07004327 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004328 WMI_PDEV_PARAM_BURST_ENABLE,
Dundi Raviteja3aa01be2018-05-21 18:58:59 +05304329 HDD_ENABLE_SIFS_BURST_DEFAULT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004330 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07004331 if (ret_val)
4332 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004333
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05304334 /*
4335 * In case of USB tethering, LRO is disabled. If SSR happened
4336 * during that time, then as part of SSR init, do not enable
4337 * the LRO again. Keep the LRO state same as before SSR.
4338 */
jitiphil377bcc12018-10-05 19:46:08 +05304339 if (cdp_cfg_get(cds_get_context(QDF_MODULE_ID_SOC),
4340 cfg_dp_lro_enable) &&
4341 !(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07004342 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05304343
4344 /* rcpi info initialization */
4345 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
4346
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304347 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004348
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004349error_wmm_init:
4350 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4351 hdd_deinit_tx_rx(adapter);
4352error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07004353 hdd_unregister_wext(adapter->dev);
Dustin Brownd28772b2017-03-17 14:16:07 -07004354 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004355
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004356 return status;
4357}
4358
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304359/**
Krunal Soni4a020c72017-10-30 20:58:40 -07004360 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304361 * @hdd_ctx: global hdd context
4362 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07004363 * @rtnl_held: Used to indicate whether or not the caller is holding
4364 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304365 *
4366 * This function De-initializes the STA/P2P/OCB adapter.
4367 *
4368 * Return: None.
4369 */
Krunal Soni4a020c72017-10-30 20:58:40 -07004370static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004371 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004372 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304373{
Dustin Brownfdf17c12018-03-14 12:55:34 -07004374 hdd_enter_dev(adapter->dev);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304375
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05304376 if (adapter->dev) {
4377 if (rtnl_held)
4378 adapter->dev->wireless_handlers = NULL;
4379 else {
4380 rtnl_lock();
4381 adapter->dev->wireless_handlers = NULL;
4382 rtnl_unlock();
4383 }
4384 }
4385
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304386 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
4387 hdd_deinit_tx_rx(adapter);
4388 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4389 }
4390
4391 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4392 hdd_wmm_adapter_close(adapter);
4393 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4394 }
4395
Krunal Sonib51eec72017-11-20 21:53:01 -08004396
Dustin Browne74003f2018-03-14 12:51:58 -07004397 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304398}
4399
Krunal Sonib51eec72017-11-20 21:53:01 -08004400void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
4401 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004402 bool rtnl_held)
4403{
Dustin Brown491d54b2018-03-14 12:39:11 -07004404 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304405
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004406 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004407 case QDF_STA_MODE:
4408 case QDF_P2P_CLIENT_MODE:
4409 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08004410 case QDF_IBSS_MODE:
4411 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004412 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004413 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004414 break;
4415 }
4416
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004417 case QDF_SAP_MODE:
4418 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004419 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004420 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004421 break;
4422 }
4423
4424 default:
4425 break;
4426 }
4427
Dustin Browne74003f2018-03-14 12:51:58 -07004428 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004429}
4430
Min Liu8c5d99e2018-09-10 17:18:44 +08004431static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx,
4432 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004433 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004434{
Jeff Johnson5505db82017-11-02 21:19:23 -07004435 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004436
4437 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07004438 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004439 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004440 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004441 return;
4442 }
4443
Alok Kumarb64650c2018-03-23 17:05:11 +05304444 hdd_nud_deinit_tracking(adapter);
4445 qdf_mutex_destroy(&adapter->disconnection_status_lock);
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05304446 hdd_apf_context_destroy(adapter);
Min Liu8c5d99e2018-09-10 17:18:44 +08004447 qdf_spinlock_destroy(&adapter->vdev_lock);
Alok Kumarb64650c2018-03-23 17:05:11 +05304448
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05304449 wlan_hdd_debugfs_csr_deinit(adapter);
Arunk Khandavallica56d4b2018-11-29 15:46:00 +05304450 if (adapter->device_mode == QDF_STA_MODE)
4451 hdd_sysfs_destroy_adapter_root_obj(adapter);
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05304452
Rajeev Kumardca5f812016-02-04 17:28:06 -08004453 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05304454
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004455 /*
4456 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
4457 * the driver is almost closed and cannot handle either control
4458 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004459 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
4460 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004461 * is not right. Setting this flag helps hdd_stop() to recognize that
4462 * the interface is closed and restricts any operations on that
4463 */
4464 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
4465
4466 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004467 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07004468 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004469 else
Jeff Johnson5505db82017-11-02 21:19:23 -07004470 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004471 /*
4472 * Note that the adapter is no longer valid at this point
4473 * since the memory has been reclaimed
4474 */
4475 }
4476}
4477
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004478static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07004479 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004480{
Jeff Johnson9d295242017-08-29 14:39:48 -07004481 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004482
Dustin Brown920397d2017-12-13 16:27:50 -08004483 hdd_for_each_adapter(hdd_ctx, adapter) {
4484 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
4485 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304486 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004487 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004488 }
Dustin Brown920397d2017-12-13 16:27:50 -08004489
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304490 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004491}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004492
Arun Khandavalli2358d522016-05-16 18:05:37 +05304493#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4494/**
4495 * hdd_set_fw_log_params() - Set log parameters to FW
4496 * @hdd_ctx: HDD Context
4497 * @adapter: HDD Adapter
4498 *
4499 * This function set the FW Debug log level based on the INI.
4500 *
4501 * Return: None
4502 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004503static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004504 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304505{
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304506 QDF_STATUS status;
4507 uint16_t enable_fw_log_level, enable_fw_log_type;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304508 int ret;
4509
Arun Khandavallifae92942016-08-01 13:31:08 +05304510 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4511 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004512 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304513 return;
4514 }
4515
Arun Khandavallifae92942016-08-01 13:31:08 +05304516 /* Enable FW logs based on INI configuration */
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304517 status = ucfg_fwol_get_enable_fw_log_type(hdd_ctx->psoc,
4518 &enable_fw_log_type);
4519 if (QDF_IS_STATUS_ERROR(status))
4520 return;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004521 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304522 WMI_DBGLOG_TYPE,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304523 enable_fw_log_type,
Arun Khandavallifae92942016-08-01 13:31:08 +05304524 DBG_CMD);
4525 if (ret != 0)
4526 hdd_err("Failed to enable FW log type ret %d",
4527 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304528
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304529 status = ucfg_fwol_get_enable_fw_log_level(hdd_ctx->psoc,
4530 &enable_fw_log_level);
4531 if (QDF_IS_STATUS_ERROR(status))
4532 return;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004533 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304534 WMI_DBGLOG_LOG_LEVEL,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304535 enable_fw_log_level,
Arun Khandavallifae92942016-08-01 13:31:08 +05304536 DBG_CMD);
4537 if (ret != 0)
4538 hdd_err("Failed to enable FW log level ret %d",
4539 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304540
lifengfaa83cb2018-11-24 01:53:56 +08004541 sme_enable_fw_module_log_level(hdd_ctx->mac_handle,
4542 adapter->session_id);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304543}
4544#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004545static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004546 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304547{
4548}
4549
4550#endif
4551
4552/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004553 * hdd_configure_chain_mask() - programs chain mask to firmware
4554 * @adapter: HDD adapter
4555 *
4556 * Return: 0 on success or errno on failure
4557 */
4558static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4559{
Naveen Rawat98322472018-03-06 10:29:42 -08004560 QDF_STATUS status;
4561 struct wma_caps_per_phy non_dbs_phy_cap;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004562 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304563 bool enable2x2 = false, enable_bt_chain_sep = false;
Krunal Sonidf29bc42018-11-15 13:26:29 -08004564 uint8_t dual_mac_feature = DISABLE_DBS_CXN_AND_SCAN;
4565
4566 status = ucfg_policy_mgr_get_dual_mac_feature(hdd_ctx->psoc,
4567 &dual_mac_feature);
4568 if (!QDF_IS_STATUS_SUCCESS(status))
4569 hdd_err("unable to get dual mac feature");
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304570
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304571 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &enable2x2);
4572 if (QDF_IS_STATUS_ERROR(status))
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304573 hdd_err("unable to get vht_enable2x2");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004574
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304575 status = ucfg_mlme_get_bt_chain_separation_flag(hdd_ctx->psoc,
4576 &enable_bt_chain_sep);
4577 if (QDF_IS_STATUS_ERROR(status))
4578 hdd_debug("unable to get BT chain separation. using default");
4579
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304580 hdd_debug("enable2x2: %d, lte_coex: %d, disable_DBS: %d",
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304581 enable2x2, hdd_ctx->lte_coex_ant_share,
Krunal Sonidf29bc42018-11-15 13:26:29 -08004582 dual_mac_feature);
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304583 hdd_debug("enable_bt_chain_separation %d", enable_bt_chain_sep);
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004584
Naveen Rawat98322472018-03-06 10:29:42 -08004585 status = wma_get_caps_for_phyidx_hwmode(&non_dbs_phy_cap,
4586 HW_MODE_DBS_NONE,
4587 CDS_BAND_ALL);
4588 if (QDF_IS_STATUS_ERROR(status)) {
4589 hdd_err("couldn't get phy caps. skip chain mask programming");
4590 return qdf_status_to_os_return(status);
4591 }
4592
4593 if (non_dbs_phy_cap.tx_chain_mask_2G < 3 ||
4594 non_dbs_phy_cap.rx_chain_mask_2G < 3 ||
4595 non_dbs_phy_cap.tx_chain_mask_5G < 3 ||
4596 non_dbs_phy_cap.rx_chain_mask_5G < 3) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004597 hdd_debug("firmware not capable. skip chain mask programming");
Naveen Rawat98322472018-03-06 10:29:42 -08004598 return 0;
4599 }
4600
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304601 if (enable2x2 && !enable_bt_chain_sep) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004602 hdd_debug("2x2 enabled. skip chain mask programming");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004603 return 0;
4604 }
4605
Krunal Sonidf29bc42018-11-15 13:26:29 -08004606 if (dual_mac_feature != DISABLE_DBS_CXN_AND_SCAN) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004607 hdd_debug("DBS enabled(%d). skip chain mask programming",
Krunal Sonidf29bc42018-11-15 13:26:29 -08004608 dual_mac_feature);
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004609 return 0;
4610 }
4611
Naveen Rawatdacb5032018-02-08 15:23:24 -08004612 if (hdd_ctx->lte_coex_ant_share) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004613 hdd_debug("lte ant sharing enabled. skip chainmask programming");
Naveen Rawatdacb5032018-02-08 15:23:24 -08004614 return 0;
4615 }
4616
Dustin Brown1dbefe62018-09-11 16:32:03 -07004617 status = ucfg_mlme_configure_chain_mask(hdd_ctx->psoc,
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304618 adapter->session_id);
4619 if (status != QDF_STATUS_SUCCESS)
4620 goto error;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004621
4622 return 0;
4623
4624error:
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304625 hdd_err("WMI PDEV set param failed");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004626 return -EINVAL;
4627}
4628
4629/**
Dundi Raviteja3b637092018-09-12 13:42:50 +05304630 * hdd_send_coex_config_params() - Send coex config params to FW
4631 * @hdd_ctx: HDD context
4632 * @adapter: Primary adapter context
4633 *
4634 * This function is used to send all coex config related params to FW
4635 *
4636 * Return: 0 on success and -EINVAL on failure
4637 */
4638static int hdd_send_coex_config_params(struct hdd_context *hdd_ctx,
4639 struct hdd_adapter *adapter)
4640{
4641 struct coex_config_params coex_cfg_params = {0};
4642 struct wlan_fwol_coex_config config = {0};
Dustin Brown05d81302018-09-11 16:49:22 -07004643 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Dundi Raviteja3b637092018-09-12 13:42:50 +05304644 QDF_STATUS status;
4645
4646 if (!hdd_ctx) {
4647 hdd_err("hdd_ctx is invalid");
4648 goto err;
4649 }
4650
4651 if (!adapter) {
4652 hdd_err("adapter is invalid");
4653 goto err;
4654 }
4655
4656 if (!psoc) {
4657 hdd_err("HDD psoc is invalid");
4658 goto err;
4659 }
4660
4661 status = ucfg_fwol_get_coex_config_params(psoc, &config);
4662 if (QDF_IS_STATUS_ERROR(status)) {
4663 hdd_err("Unable to get coex config params");
4664 goto err;
4665 }
4666
4667 coex_cfg_params.vdev_id = adapter->session_id;
4668 coex_cfg_params.config_type = WMI_COEX_CONFIG_TX_POWER;
4669 coex_cfg_params.config_arg1 = config.max_tx_power_for_btc;
4670
4671 status = sme_send_coex_config_cmd(&coex_cfg_params);
4672 if (QDF_IS_STATUS_ERROR(status)) {
4673 hdd_err("Failed to send coex Tx power");
4674 goto err;
4675 }
4676
4677 coex_cfg_params.config_type = WMI_COEX_CONFIG_HANDOVER_RSSI;
4678 coex_cfg_params.config_arg1 = config.wlan_low_rssi_threshold;
4679
4680 status = sme_send_coex_config_cmd(&coex_cfg_params);
4681 if (QDF_IS_STATUS_ERROR(status)) {
4682 hdd_err("Failed to send coex handover RSSI");
4683 goto err;
4684 }
4685
4686 coex_cfg_params.config_type = WMI_COEX_CONFIG_BTC_MODE;
4687 coex_cfg_params.config_arg1 = config.btc_mode;
4688
4689 status = sme_send_coex_config_cmd(&coex_cfg_params);
4690 if (QDF_IS_STATUS_ERROR(status)) {
4691 hdd_err("Failed to send coex BTC mode");
4692 goto err;
4693 }
4694
4695 coex_cfg_params.config_type = WMI_COEX_CONFIG_ANTENNA_ISOLATION;
4696 coex_cfg_params.config_arg1 = config.antenna_isolation;
4697
4698 status = sme_send_coex_config_cmd(&coex_cfg_params);
4699 if (QDF_IS_STATUS_ERROR(status)) {
4700 hdd_err("Failed to send coex antenna isolation");
4701 goto err;
4702 }
4703
4704 coex_cfg_params.config_type = WMI_COEX_CONFIG_BT_LOW_RSSI_THRESHOLD;
4705 coex_cfg_params.config_arg1 = config.bt_low_rssi_threshold;
4706
4707 status = sme_send_coex_config_cmd(&coex_cfg_params);
4708 if (QDF_IS_STATUS_ERROR(status)) {
4709 hdd_err("Failed to send coex BT low RSSI threshold");
4710 goto err;
4711 }
4712
4713 coex_cfg_params.config_type = WMI_COEX_CONFIG_BT_INTERFERENCE_LEVEL;
4714 coex_cfg_params.config_arg1 = config.bt_interference_low_ll;
4715 coex_cfg_params.config_arg2 = config.bt_interference_low_ul;
4716 coex_cfg_params.config_arg3 = config.bt_interference_medium_ll;
4717 coex_cfg_params.config_arg4 = config.bt_interference_medium_ul;
4718 coex_cfg_params.config_arg5 = config.bt_interference_high_ll;
4719 coex_cfg_params.config_arg6 = config.bt_interference_high_ul;
4720
4721 status = sme_send_coex_config_cmd(&coex_cfg_params);
4722 if (QDF_IS_STATUS_ERROR(status)) {
4723 hdd_err("Failed to send coex BT interference level");
4724 goto err;
4725 }
4726 return 0;
4727err:
4728 return -EINVAL;
4729}
4730
4731/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304732 * hdd_set_fw_params() - Set parameters to firmware
4733 * @adapter: HDD adapter
4734 *
4735 * This function Sets various parameters to fw once the
4736 * adapter is started.
4737 *
4738 * Return: 0 on success or errno on failure
4739 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004740int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304741{
4742 int ret;
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304743 uint16_t upper_brssi_thresh, lower_brssi_thresh, rts_profile;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304744 bool enable_dtim_1chrx;
4745 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004746 struct hdd_context *hdd_ctx;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304747 bool bval = false;
Manikandan Mohand350c192018-11-29 14:01:12 -08004748 uint8_t max_amsdu_len, enable_tx_sch_delay;
4749 uint32_t dtim_sel_diversity, enable_secondary_rate;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304750
Dustin Brownfdf17c12018-03-14 12:55:34 -07004751 hdd_enter_dev(adapter->dev);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304752
4753 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4754 if (!hdd_ctx)
4755 return -EINVAL;
4756
Dustin Brown732ab9c2017-06-15 13:24:09 -07004757 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4758 hdd_debug("FTM Mode is active; nothing to do");
4759 return 0;
4760 }
4761
Manikandan Mohand350c192018-11-29 14:01:12 -08004762 ret = -1;
4763 if (QDF_IS_STATUS_SUCCESS(ucfg_fwol_get_lprx_enable(hdd_ctx->psoc,
4764 &bval))) {
4765 ret = sme_cli_set_command(adapter->session_id,
4766 WMI_PDEV_PARAM_DTIM_SYNTH,
4767 bval, PDEV_CMD);
4768 }
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304769 if (ret) {
4770 hdd_err("Failed to set LPRx");
4771 goto error;
4772 }
4773
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +05304774 ucfg_mlme_get_dtim_selection_diversity(hdd_ctx->psoc,
4775 &dtim_sel_diversity);
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304776
4777 ret = sme_cli_set_command(
4778 adapter->session_id,
4779 WMI_PDEV_PARAM_1CH_DTIM_OPTIMIZED_CHAIN_SELECTION,
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +05304780 dtim_sel_diversity, PDEV_CMD);
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304781 if (ret) {
4782 hdd_err("Failed to set DTIM_OPTIMIZED_CHAIN_SELECTION");
4783 goto error;
4784 }
4785
Manikandan Mohand350c192018-11-29 14:01:12 -08004786 ret = -1;
4787 if (QDF_IS_STATUS_SUCCESS(ucfg_fwol_get_enable_tx_sch_delay(
4788 hdd_ctx->psoc, &enable_tx_sch_delay))) {
4789 ret = sme_cli_set_command(adapter->session_id,
4790 WMI_PDEV_PARAM_TX_SCH_DELAY,
4791 enable_tx_sch_delay, PDEV_CMD);
4792 }
Ashish Kumar Dhanotiya48dac7d2018-03-28 14:59:50 +05304793 if (ret) {
4794 hdd_err("Failed to set WMI_PDEV_PARAM_TX_SCH_DELAY");
4795 goto error;
4796 }
4797
Manikandan Mohand350c192018-11-29 14:01:12 -08004798 ret = -1;
4799 if (QDF_IS_STATUS_SUCCESS(ucfg_fwol_get_enable_secondary_rate(
4800 hdd_ctx->psoc, &enable_secondary_rate))) {
4801 ret = sme_cli_set_command(adapter->session_id,
4802 WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE,
4803 enable_secondary_rate, PDEV_CMD);
4804 }
Ashish Kumar Dhanotiya959b38c2018-04-06 21:07:57 +05304805 if (ret) {
4806 hdd_err("Failed to set WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE");
4807 goto error;
4808 }
4809
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304810 if (adapter->device_mode == QDF_STA_MODE) {
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304811 status = ucfg_get_upper_brssi_thresh(hdd_ctx->psoc,
4812 &upper_brssi_thresh);
4813 if (QDF_IS_STATUS_ERROR(status))
4814 return -EINVAL;
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304815
Jeff Johnson1b780e42017-10-31 14:11:45 -07004816 sme_set_smps_cfg(adapter->session_id,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304817 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4818 upper_brssi_thresh);
4819
4820 status = ucfg_get_lower_brssi_thresh(hdd_ctx->psoc,
4821 &lower_brssi_thresh);
4822 if (QDF_IS_STATUS_ERROR(status))
4823 return -EINVAL;
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304824
Jeff Johnson1b780e42017-10-31 14:11:45 -07004825 sme_set_smps_cfg(adapter->session_id,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304826 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4827 lower_brssi_thresh);
4828
4829 status = ucfg_get_enable_dtim_1chrx(hdd_ctx->psoc,
4830 &enable_dtim_1chrx);
4831 if (QDF_IS_STATUS_ERROR(status))
4832 return -EINVAL;
4833
4834 sme_set_smps_cfg(adapter->session_id,
4835 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4836 enable_dtim_1chrx);
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304837 }
4838
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304839 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
4840 if (!QDF_IS_STATUS_SUCCESS(status))
4841 hdd_err("unable to get vht_enable2x2");
4842
4843 if (bval) {
Dustin Brown732ab9c2017-06-15 13:24:09 -07004844 hdd_debug("configuring 2x2 mode fw params");
4845
Vignesh Viswanathana851d752018-10-03 19:44:38 +05304846 ret = sme_set_cck_tx_fir_override(hdd_ctx->mac_handle,
4847 adapter->session_id);
Dustin Brown732ab9c2017-06-15 13:24:09 -07004848 if (ret) {
4849 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4850 ret);
4851 goto error;
4852 }
Liangwei Dong22810e82018-03-15 03:42:12 -04004853
4854 if (hdd_configure_chain_mask(adapter))
4855 goto error;
Dustin Brown732ab9c2017-06-15 13:24:09 -07004856 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304857#define HDD_DTIM_1CHAIN_RX_ID 0x5
4858#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004859 hdd_debug("configuring 1x1 mode fw params");
4860
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004861 /*
4862 * Disable DTIM 1 chain Rx when in 1x1,
4863 * we are passing two value
4864 * as param_id << 29 | param_value.
4865 * Below param_value = 0(disable)
4866 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004867 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004868 WMI_STA_SMPS_PARAM_CMDID,
4869 HDD_DTIM_1CHAIN_RX_ID <<
4870 HDD_SMPS_PARAM_VALUE_S,
4871 VDEV_CMD);
4872 if (ret) {
4873 hdd_err("DTIM 1 chain set failed %d", ret);
4874 goto error;
4875 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304876
Arun Khandavalli2358d522016-05-16 18:05:37 +05304877#undef HDD_DTIM_1CHAIN_RX_ID
4878#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004879
4880 if (hdd_configure_chain_mask(adapter))
4881 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004882 }
4883
Vignesh Viswanathana851d752018-10-03 19:44:38 +05304884 ret = sme_set_enable_mem_deep_sleep(hdd_ctx->mac_handle,
4885 adapter->session_id);
Dustin Brown732ab9c2017-06-15 13:24:09 -07004886 if (ret) {
4887 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4888 goto error;
4889 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304890
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304891 status = ucfg_fwol_get_rts_profile(hdd_ctx->psoc, &rts_profile);
4892 if (QDF_IS_STATUS_ERROR(status))
4893 return -EINVAL;
4894
Jeff Johnson1b780e42017-10-31 14:11:45 -07004895 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004896 WMI_VDEV_PARAM_ENABLE_RTSCTS,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304897 rts_profile,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004898 VDEV_CMD);
4899 if (ret) {
4900 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4901 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304902 }
4903
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05304904 status = ucfg_mlme_get_max_amsdu_num(hdd_ctx->psoc, &max_amsdu_len);
4905 if (QDF_IS_STATUS_ERROR(status)) {
4906 hdd_err("Failed to get Max AMSDU Num");
4907 goto error;
4908 }
4909
4910 hdd_debug("SET AMSDU num %d", max_amsdu_len);
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004911
Jeff Johnson1b780e42017-10-31 14:11:45 -07004912 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004913 GEN_VDEV_PARAM_AMSDU,
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05304914 max_amsdu_len,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004915 GEN_CMD);
4916 if (ret != 0) {
4917 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4918 goto error;
4919 }
4920
Arun Khandavalli2358d522016-05-16 18:05:37 +05304921 hdd_set_fw_log_params(hdd_ctx, adapter);
Dundi Raviteja3b637092018-09-12 13:42:50 +05304922
4923 ret = hdd_send_coex_config_params(hdd_ctx, adapter);
4924 if (ret) {
4925 hdd_warn("Error initializing coex config params");
4926 goto error;
4927 }
4928
Dustin Browne74003f2018-03-14 12:51:58 -07004929 hdd_exit();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004930
Arun Khandavalli2358d522016-05-16 18:05:37 +05304931 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304932
Arun Khandavalli2358d522016-05-16 18:05:37 +05304933error:
4934 return -EINVAL;
4935}
4936
Ryan Hsu07495ea2016-01-21 15:25:39 -08004937/**
Abhinav Kumarcc959f12018-08-09 13:58:30 +05304938 * hdd_init_completion() - Initialize Completion Variables
4939 * @adapter: HDD adapter
4940 *
4941 * This function Initialize the completion variables for
4942 * a particular adapter
4943 *
4944 * Return: None
4945 */
4946static void hdd_init_completion(struct hdd_adapter *adapter)
4947{
4948 init_completion(&adapter->disconnect_comp_var);
4949 init_completion(&adapter->roaming_comp_var);
4950 init_completion(&adapter->linkup_event_var);
Abhinav Kumarcc959f12018-08-09 13:58:30 +05304951 init_completion(&adapter->sta_authorized_event);
4952 init_completion(&adapter->offchannel_tx_event);
4953 init_completion(&adapter->tx_action_cnf_event);
4954 init_completion(&adapter->ibss_peer_info_comp);
4955 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
4956}
4957
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05304958static void hdd_reset_locally_admin_bit(struct hdd_context *hdd_ctx,
4959 tSirMacAddr macAddr)
4960{
4961 int i;
4962 /*
4963 * Reset locally administered bit for dynamic_mac_list
4964 * also as while releasing the MAC address for any
4965 * interface mac will be compared with dynamic mac list
4966 */
4967 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
4968 if (!qdf_mem_cmp(
4969 macAddr,
4970 &hdd_ctx->
4971 dynamic_mac_list[i].dynamic_mac.bytes[0],
4972 sizeof(struct qdf_mac_addr))) {
4973 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(
4974 hdd_ctx->
4975 dynamic_mac_list[i].dynamic_mac.bytes);
4976 break;
4977 }
4978 }
4979 /*
4980 * Reset locally administered bit if the device mode is
4981 * STA
4982 */
4983 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
4984 hdd_debug("locally administered bit reset in sta mode: "
4985 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
4986}
4987
Abhinav Kumarcc959f12018-08-09 13:58:30 +05304988/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08004989 * hdd_open_adapter() - open and setup the hdd adatper
4990 * @hdd_ctx: global hdd context
4991 * @session_type: type of the interface to be created
4992 * @iface_name: User-visible name of the interface
4993 * @macAddr: MAC address to assign to the interface
4994 * @name_assign_type: the name of assign type of the netdev
4995 * @rtnl_held: the rtnl lock hold flag
4996 *
4997 * This function open and setup the hdd adpater according to the device
4998 * type request, assign the name, the mac address assigned, and then prepared
4999 * the hdd related parameters, queue, lock and ready to start.
5000 *
5001 * Return: the pointer of hdd adapter, otherwise NULL.
5002 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005003struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005004 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08005005 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08005006 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005007{
Jeff Johnson9d295242017-08-29 14:39:48 -07005008 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305009 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005010
5011 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
5012 /*
5013 * Max limit reached on the number of vdevs configured by the
5014 * host. Return error
5015 */
Arun Khandavallifae92942016-08-01 13:31:08 +05305016 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
5017 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005018 return NULL;
5019 }
5020
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05305021 status = wlan_hdd_validate_mac_address((struct qdf_mac_addr *)macAddr);
5022 if (QDF_IS_STATUS_ERROR(status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005023 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05305024 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005025 return NULL;
5026 }
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05305027
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005028 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305029 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305030 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
5031 " already exists",
5032 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005033 return NULL;
5034 }
5035
5036 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005037 case QDF_STA_MODE:
Ashish Kumar Dhanotiya01485192018-12-24 12:44:06 +05305038 if (!hdd_ctx->config->mac_provision) {
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05305039 hdd_reset_locally_admin_bit(hdd_ctx, macAddr);
Ashish Kumar Dhanotiya01485192018-12-24 12:44:06 +05305040 /*
5041 * After resetting locally administered bit
5042 * again check if the new mac address is already
5043 * exists.
5044 */
5045 status = hdd_check_for_existing_macaddr(hdd_ctx,
5046 macAddr);
5047 if (QDF_STATUS_E_FAILURE == status) {
5048 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
5049 " already exists",
5050 MAC_ADDR_ARRAY(macAddr));
5051 return NULL;
5052 }
5053 }
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05305054
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005055 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005056 case QDF_P2P_CLIENT_MODE:
5057 case QDF_P2P_DEVICE_MODE:
5058 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07005059 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305060 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08005061 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
5062 name_assign_type,
5063 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005064
5065 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305066 hdd_err("failed to allocate adapter for session %d",
5067 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005068 return NULL;
5069 }
5070
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005071 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005072 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005073 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005074 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305075 else if (QDF_MONITOR_MODE == session_type)
5076 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005077 else
5078 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
5079
5080 adapter->device_mode = session_type;
5081
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005082
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005083 /*
5084 * Workqueue which gets scheduled in IPv4 notification
5085 * callback
5086 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005087 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005088 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005089
5090#ifdef WLAN_NS_OFFLOAD
5091 /*
5092 * Workqueue which gets scheduled in IPv6
5093 * notification callback.
5094 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005095 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005096 hdd_ipv6_notifier_work_queue);
5097#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005098 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08005099 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08005100 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005101
5102 /* Stop the Interface TX queue. */
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);
Arun Khandavallifae92942016-08-01 13:31:08 +05305107
Alok Kumarb64650c2018-03-23 17:05:11 +05305108 hdd_nud_init_tracking(adapter);
Arunk Khandavallica56d4b2018-11-29 15:46:00 +05305109 if (adapter->device_mode == QDF_STA_MODE ||
5110 adapter->device_mode == QDF_P2P_DEVICE_MODE)
5111 hdd_sysfs_create_adapter_root_obj(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05305112 qdf_mutex_create(&adapter->disconnection_status_lock);
5113
Ravi Joshi1a292562017-05-18 16:28:54 -07005114 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005115
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005116 case QDF_P2P_GO_MODE:
5117 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08005118 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
5119 name_assign_type,
5120 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005121 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005122 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05305123 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005124 return NULL;
5125 }
5126
5127 adapter->wdev.iftype =
5128 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005129 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005130 NL80211_IFTYPE_P2P_GO;
5131 adapter->device_mode = session_type;
5132
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07005133 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08005134 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005135 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08005136
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005137 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005138 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305139 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5140 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305141
5142 /*
5143 * Workqueue which gets scheduled in IPv4 notification
5144 * callback
5145 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005146 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305147 hdd_ipv4_notifier_work_queue);
5148
5149#ifdef WLAN_NS_OFFLOAD
5150 /*
5151 * Workqueue which gets scheduled in IPv6
5152 * notification callback.
5153 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005154 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305155 hdd_ipv6_notifier_work_queue);
5156#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005157 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305158 case QDF_FTM_MODE:
5159 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
5160 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08005161 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305162 if (NULL == adapter) {
5163 hdd_err("Failed to allocate adapter for FTM mode");
5164 return NULL;
5165 }
5166 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
5167 adapter->device_mode = session_type;
5168 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08005169 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08005170 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08005171
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305172 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005173 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305174 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305175 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5176 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305177 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005178 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005179 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305180 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005181 return NULL;
5182 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005183
Min Liu8c5d99e2018-09-10 17:18:44 +08005184 qdf_spinlock_create(&adapter->vdev_lock);
5185
Abhinav Kumarcc959f12018-08-09 13:58:30 +05305186 hdd_init_completion(adapter);
hqueaa33ee2017-05-04 17:56:35 +08005187 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
Min Liu9be5d4a2018-05-17 11:51:53 +08005188 qdf_list_create(&adapter->blocked_scan_request_q, WLAN_MAX_SCAN_COUNT);
5189 qdf_mutex_create(&adapter->blocked_scan_request_q_lock);
hqueaa33ee2017-05-04 17:56:35 +08005190
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305191 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005192 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08005193 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005194 }
5195
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305196 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005197 if (NULL != adapter) {
5198 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
5199 adapter = NULL;
5200 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005201
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005202 return NULL;
5203 }
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05305204 hdd_apf_context_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005205
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305206 if (QDF_STATUS_SUCCESS == status) {
Dustin Brown1dbefe62018-09-11 16:32:03 -07005207 policy_mgr_set_concurrency_mode(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005208 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005209
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005210 /* Adapter successfully added. Increment the vdev count */
5211 hdd_ctx->current_intf_count++;
5212
Jeff Johnson5880d792016-08-15 13:32:30 -07005213 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005214 hdd_ctx->current_intf_count);
5215
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08005216 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005217 }
5218
Rajeev Kumardca5f812016-02-04 17:28:06 -08005219 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07005220 hdd_err("Interface %s wow debug_fs init failed",
5221 netdev_name(adapter->dev));
5222
Ajit Pal Singh106c1412018-04-18 18:08:49 +05305223 hdd_register_hl_netdev_fc_timer(adapter,
5224 hdd_tx_resume_timer_expired_handler);
5225
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07005226 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
5227 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005228
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05305229 if (adapter->device_mode == QDF_STA_MODE)
5230 wlan_hdd_debugfs_csr_init(adapter);
5231
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005232 return adapter;
5233
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005234err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07005235 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05305236 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005237
5238 return NULL;
5239}
5240
Dustin Brown728d65a2018-10-02 16:27:52 -07005241static void __hdd_close_adapter(struct hdd_context *hdd_ctx,
5242 struct hdd_adapter *adapter,
5243 bool rtnl_held)
5244{
5245 qdf_list_destroy(&adapter->blocked_scan_request_q);
5246 qdf_mutex_destroy(&adapter->blocked_scan_request_q_lock);
5247 policy_mgr_clear_concurrency_mode(hdd_ctx->psoc, adapter->device_mode);
5248
5249 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
5250
5251 if (hdd_ctx->current_intf_count != 0)
5252 hdd_ctx->current_intf_count--;
5253}
5254
5255void hdd_close_adapter(struct hdd_context *hdd_ctx,
5256 struct hdd_adapter *adapter,
5257 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005258{
Dustin Brown920397d2017-12-13 16:27:50 -08005259 /*
Dustin Brown728d65a2018-10-02 16:27:52 -07005260 * Stop the global bus bandwidth timer while touching the adapter list
5261 * to avoid bad memory access by the timer handler.
Dustin Brown920397d2017-12-13 16:27:50 -08005262 */
Dustin Brown920397d2017-12-13 16:27:50 -08005263 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005264
Dustin Brown920397d2017-12-13 16:27:50 -08005265 hdd_remove_adapter(hdd_ctx, adapter);
Dustin Brown728d65a2018-10-02 16:27:52 -07005266 __hdd_close_adapter(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005267
Dustin Brown920397d2017-12-13 16:27:50 -08005268 /* conditionally restart the bw timer */
5269 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005270}
5271
Dustin Brown728d65a2018-10-02 16:27:52 -07005272void hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005273{
Dustin Brown920397d2017-12-13 16:27:50 -08005274 struct hdd_adapter *adapter;
Dustin Brown693b5352019-01-17 10:00:31 -08005275 struct hdd_vdev_sync *vdev_sync;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005276
Dustin Brown491d54b2018-03-14 12:39:11 -07005277 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005278
Dustin Brown728d65a2018-10-02 16:27:52 -07005279 while (QDF_IS_STATUS_SUCCESS(hdd_remove_front_adapter(hdd_ctx,
5280 &adapter))) {
Dustin Brown693b5352019-01-17 10:00:31 -08005281 vdev_sync = hdd_vdev_sync_unregister(adapter->dev);
5282 if (vdev_sync)
5283 hdd_vdev_sync_wait_for_ops(vdev_sync);
5284
Dustin Brown728d65a2018-10-02 16:27:52 -07005285 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
5286 __hdd_close_adapter(hdd_ctx, adapter, rtnl_held);
Dustin Brown693b5352019-01-17 10:00:31 -08005287
5288 if (vdev_sync)
5289 hdd_vdev_sync_destroy(vdev_sync);
Dustin Brown728d65a2018-10-02 16:27:52 -07005290 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005291
Dustin Browne74003f2018-03-14 12:51:58 -07005292 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005293}
5294
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005295void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005296{
Anurag Chouhan6d760662016-02-20 16:05:43 +05305297 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005298 tSirUpdateIE updateIE;
Jeff Johnson16528362018-06-14 12:34:16 -07005299 mac_handle_t mac_handle;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005300
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005301 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005302 case QDF_STA_MODE:
5303 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005304 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005305 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005306 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07005307 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005308 break;
5309 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005310 case QDF_SAP_MODE:
5311 case QDF_P2P_GO_MODE:
5312 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005313 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07005314 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005315 break;
5316 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005317 case QDF_FTM_MODE:
5318 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005319 default:
5320 /*
5321 * wlan_hdd_reset_prob_rspies should not have been called
5322 * for these kind of devices
5323 */
Jeff Johnson5880d792016-08-15 13:32:30 -07005324 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005325 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005326 return;
5327 }
5328
Anurag Chouhanc5548422016-02-24 18:33:27 +05305329 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005330 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005331 updateIE.ieBufferlength = 0;
5332 updateIE.pAdditionIEBuffer = NULL;
5333 updateIE.append = true;
5334 updateIE.notify = false;
Jeff Johnson16528362018-06-14 12:34:16 -07005335 mac_handle = hdd_adapter_get_mac_handle(adapter);
5336 if (sme_update_add_ie(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005337 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305338 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005339 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005340 }
5341}
5342
Dustin Browndb2a8be2017-12-20 11:49:56 -08005343QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
5344 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005345{
Dustin Brownd747ecd2018-10-26 16:32:22 -07005346 QDF_STATUS status = QDF_STATUS_SUCCESS;
5347 struct hdd_station_ctx *sta_ctx;
Dustin Brownb4260d52019-01-24 11:53:08 -08005348 struct sap_context *sap_ctx;
Jeff Johnson025618c2018-03-18 14:41:00 -07005349 struct csr_roam_profile *roam_profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005350 union iwreq_data wrqu;
5351 tSirUpdateIE updateIE;
5352 unsigned long rc;
Jeff Johnsone4c11db2018-05-05 23:22:32 -07005353 tsap_config_t *sap_config;
Jeff Johnson16528362018-06-14 12:34:16 -07005354 mac_handle_t mac_handle;
Min Liu8c5d99e2018-09-10 17:18:44 +08005355 struct wlan_objmgr_vdev *vdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005356
Dustin Brown491d54b2018-03-14 12:39:11 -07005357 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005358
Dustin Browne7e71d32018-05-11 16:00:08 -07005359 if (adapter->session_id != HDD_SESSION_ID_INVALID)
5360 wlan_hdd_cfg80211_deregister_frames(adapter);
5361
Alok Kumarb64650c2018-03-23 17:05:11 +05305362 hdd_nud_ignore_tracking(adapter, true);
5363 hdd_nud_reset_tracking(adapter);
Alok Kumar016a1ac2018-09-16 09:55:50 +05305364 hdd_nud_flush_work(adapter);
hangtian9c47aaf2018-11-26 17:59:39 +08005365 hdd_stop_tsf_sync(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05305366
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005367 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305368 wlan_hdd_netif_queue_control(adapter,
5369 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5370 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08005371 /*
5372 * if this is the last active connection check & stop the
5373 * opportunistic timer first
5374 */
Dustin Brownd747ecd2018-10-26 16:32:22 -07005375 if ((policy_mgr_get_connection_count(hdd_ctx->psoc) == 1 &&
5376 policy_mgr_mode_specific_connection_count(hdd_ctx->psoc,
5377 policy_mgr_convert_device_mode_to_qdf_type(
5378 adapter->device_mode), NULL) == 1) ||
5379 !policy_mgr_get_connection_count(hdd_ctx->psoc))
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08005380 policy_mgr_check_and_stop_opportunistic_timer(
Dustin Brown1dbefe62018-09-11 16:32:03 -07005381 hdd_ctx->psoc, adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -07005382
5383 mac_handle = hdd_ctx->mac_handle;
5384
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005385 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005386 case QDF_STA_MODE:
5387 case QDF_P2P_CLIENT_MODE:
5388 case QDF_IBSS_MODE:
5389 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005390 case QDF_NDI_MODE:
Dustin Brownd747ecd2018-10-26 16:32:22 -07005391 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
5392
5393 if (adapter->device_mode == QDF_NDI_MODE ||
5394 hdd_conn_is_connected(sta_ctx) ||
5395 hdd_is_connecting(sta_ctx)) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005396 INIT_COMPLETION(adapter->disconnect_comp_var);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005397
Jeff Johnson025618c2018-03-18 14:41:00 -07005398 roam_profile = hdd_roam_profile(adapter);
5399 /* For NDI do not use roam_profile */
Dustin Brownd747ecd2018-10-26 16:32:22 -07005400 if (adapter->device_mode == QDF_NDI_MODE)
5401 status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005402 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005403 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005404 eCSR_DISCONNECT_REASON_NDI_DELETE);
Jeff Johnson025618c2018-03-18 14:41:00 -07005405 else if (roam_profile->BSSType ==
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005406 eCSR_BSS_TYPE_START_IBSS)
Dustin Brownd747ecd2018-10-26 16:32:22 -07005407 status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005408 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005409 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005410 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Abhinav Kumar19a7a402018-07-12 17:36:57 +05305411 else if (adapter->device_mode == QDF_STA_MODE)
5412 wlan_hdd_disconnect(adapter,
5413 eCSR_DISCONNECT_REASON_DEAUTH);
5414 else
Dustin Brownd747ecd2018-10-26 16:32:22 -07005415 status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005416 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005417 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005418 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005419 /* success implies disconnect is queued */
5420 if (QDF_IS_STATUS_SUCCESS(status) &&
5421 adapter->device_mode != QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005422 rc = wait_for_completion_timeout(
5423 &adapter->disconnect_comp_var,
5424 msecs_to_jiffies
Abhishek Singhd1f21c72019-01-21 15:16:34 +05305425 (SME_DISCONNECT_TIMEOUT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005426 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005427 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005428 }
Dustin Brownd747ecd2018-10-26 16:32:22 -07005429 if (QDF_IS_STATUS_ERROR(status))
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005430 hdd_warn("failed to post disconnect");
Dustin Brownd747ecd2018-10-26 16:32:22 -07005431
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005432 memset(&wrqu, '\0', sizeof(wrqu));
5433 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5434 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5435 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
5436 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05305437 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005438
Dustin Brownd747ecd2018-10-26 16:32:22 -07005439 wlan_hdd_scan_abort(adapter);
Wu Gao4a1ec8c2018-07-23 19:18:40 +08005440 wlan_hdd_cleanup_actionframe(adapter);
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05305441 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05305442 hdd_clear_fils_connection_info(adapter);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005443 hdd_deregister_tx_flow_control(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005444
5445#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005446 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005447#ifdef WLAN_NS_OFFLOAD
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005448 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005449#endif
5450#endif
5451
Min Liu8c5d99e2018-09-10 17:18:44 +08005452 if (adapter->device_mode == QDF_STA_MODE) {
5453 struct wlan_objmgr_vdev *vdev;
5454
5455 vdev = hdd_objmgr_get_vdev(adapter);
5456 if (vdev) {
5457 wlan_cfg80211_sched_scan_stop(vdev);
5458 hdd_objmgr_put_vdev(adapter);
5459 }
5460 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08005461
Pragaspathi Thilagaraje6f37e02019-01-04 12:24:33 +05305462 /*
5463 * During vdev destroy, if any STA is in connecting state the
5464 * roam command will be in active queue and thus vdev destroy is
5465 * queued in pending queue. In case STA tries to connect to
5466 * multiple BSSID and fails to connect, due to auth/assoc
5467 * timeouts it may take more than vdev destroy time to get
5468 * completed. On vdev destroy timeout vdev is moved to logically
5469 * deleted state. Once connection is completed, vdev destroy is
5470 * activated and to release the self-peer ref count it try to
5471 * get the ref of the vdev, which fails as vdev is logically
5472 * deleted and this leads to peer ref leak. So before vdev
5473 * destroy is queued abort any STA ongoing connection to avoid
5474 * vdev destroy timeout.
5475 */
5476 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags))
5477 hdd_abort_ongoing_sta_connection(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08005478
Himanshu Agarwalb229a142017-12-21 10:16:45 +05305479 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005480 break;
5481
Rajeev Kumar3b906202018-02-01 10:55:14 -08005482 case QDF_MONITOR_MODE:
5483 wlan_hdd_scan_abort(adapter);
5484 hdd_deregister_tx_flow_control(adapter);
5485 hdd_vdev_destroy(adapter);
5486 break;
5487
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005488 case QDF_SAP_MODE:
Will Huang7049bae2018-08-13 17:25:02 +08005489 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
5490 cds_flush_delayed_work(&adapter->acs_pending_work);
5491 clear_bit(ACS_PENDING, &adapter->event_flags);
5492 }
Dustin Brownd747ecd2018-10-26 16:32:22 -07005493
wadesongf9b15ed2017-12-14 14:12:32 +08005494 wlan_hdd_scan_abort(adapter);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005495
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05305496 sap_config = &adapter->session.ap.sap_config;
Dustin Brownd747ecd2018-10-26 16:32:22 -07005497 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
5498
Dustin Brown07901ec2018-09-07 11:02:41 -07005499 ucfg_ipa_flush(hdd_ctx->pdev);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005500
Dustin Brownb4260d52019-01-24 11:53:08 -08005501 /* don't flush pre-cac destroy if we are destroying pre-cac */
5502 sap_ctx = WLAN_HDD_GET_SAP_CTX_PTR(adapter);
5503 if (!wlan_sap_is_pre_cac_context(sap_ctx))
Liangwei Dongad89c762018-06-01 01:56:23 -04005504 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Dustin Brownb4260d52019-01-24 11:53:08 -08005505
Jeff Johnson46807cd2018-04-29 21:32:22 -07005506 /* fallthrough */
Dustin Browna5cf8e02017-10-19 16:04:19 -07005507
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005508 case QDF_P2P_GO_MODE:
Krunal Soni22208392017-09-29 18:10:34 -07005509 cds_flush_work(&adapter->sap_stop_bss_work);
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305510 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005511 wlan_hdd_undo_acs(adapter);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005512
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005513 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005514 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5515
5516 hdd_deregister_tx_flow_control(adapter);
Kapil Guptac1224bf2017-06-22 21:22:40 +05305517 hdd_destroy_acs_timer(adapter);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005518
Pragaspathi Thilagaraje6f37e02019-01-04 12:24:33 +05305519 /**
5520 * During vdev destroy, If any STA is in connecting state the
5521 * roam command will be in active queue and thus vdev destroy is
5522 * queued in pending queue. In case STA is tries to connected to
5523 * multiple BSSID and fails to connect, due to auth/assoc
5524 * timeouts it may take more than vdev destroy time to get
5525 * completes. If vdev destroy timeout vdev is moved to logically
5526 * deleted state. Once connection is completed, vdev destroy is
5527 * activated and to release the self-peer ref count it try to
5528 * get the ref of the vdev, which fails as vdev is logically
5529 * deleted and this leads to peer ref leak. So before vdev
5530 * destroy is queued abort any STA ongoing connection to avoid
5531 * vdev destroy timeout.
5532 */
5533 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags))
5534 hdd_abort_ongoing_sta_connection(hdd_ctx);
5535
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005536 mutex_lock(&hdd_ctx->sap_lock);
5537 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005538 status = wlansap_stop_bss(
5539 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005540
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305541 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07005542 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005543 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305544 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305545 qdf_stop_bss_event);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005546 status = qdf_wait_for_event_completion(
Nachiket Kukade0396b732017-11-14 16:35:16 +05305547 &hostapd_state->qdf_stop_bss_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +05305548 SME_CMD_STOP_BSS_TIMEOUT);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005549 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson5880d792016-08-15 13:32:30 -07005550 hdd_err("failure waiting for wlansap_stop_bss %d",
Dustin Brownd747ecd2018-10-26 16:32:22 -07005551 status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005552 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07005553 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005554 }
Dustin Brownd747ecd2018-10-26 16:32:22 -07005555
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005556 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -07005557 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005558 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005559 adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005560 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305561 adapter->device_mode,
5562 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005563
Anurag Chouhanc5548422016-02-24 18:33:27 +05305564 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07005565 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005566 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005567 updateIE.ieBufferlength = 0;
5568 updateIE.pAdditionIEBuffer = NULL;
5569 updateIE.append = false;
5570 updateIE.notify = false;
Dustin Brownd747ecd2018-10-26 16:32:22 -07005571
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005572 /* Probe bcn reset */
Dustin Brownd747ecd2018-10-26 16:32:22 -07005573 status = sme_update_add_ie(mac_handle, &updateIE,
5574 eUPDATE_IE_PROBE_BCN);
5575 if (status == QDF_STATUS_E_FAILURE)
5576 hdd_err("Could not pass PROBE_RSP_BCN to PE");
5577
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005578 /* Assoc resp reset */
Dustin Brownd747ecd2018-10-26 16:32:22 -07005579 status = sme_update_add_ie(mac_handle, &updateIE,
5580 eUPDATE_IE_ASSOC_RESP);
5581 if (status == QDF_STATUS_E_FAILURE)
5582 hdd_err("Could not pass ASSOC_RSP to PE");
5583
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005584 /* Reset WNI_CFG_PROBE_RSP Flags */
5585 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005586 }
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005587 clear_bit(SOFTAP_INIT_DONE, &adapter->event_flags);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005588 qdf_mem_free(adapter->session.ap.beacon);
5589 adapter->session.ap.beacon = NULL;
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005590
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305591 /*
5592 * If Do_Not_Break_Stream was enabled clear avoid channel list.
5593 */
Min Liu8c5d99e2018-09-10 17:18:44 +08005594 vdev = hdd_objmgr_get_vdev(adapter);
5595 if (vdev) {
5596 if (policy_mgr_is_dnsc_set(vdev))
5597 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
5598 hdd_objmgr_put_vdev(adapter);
5599 }
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305600
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305601#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005602 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305603#ifdef WLAN_NS_OFFLOAD
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005604 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305605#endif
5606#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08005607
5608 hdd_vdev_destroy(adapter);
5609
Krunal Sonib51eec72017-11-20 21:53:01 -08005610 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005611 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005612 case QDF_OCB_MODE:
Dustin Brownd747ecd2018-10-26 16:32:22 -07005613 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08005614 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Dustin Brownd747ecd2018-10-26 16:32:22 -07005615 cds_get_context(QDF_MODULE_ID_TXRX),
5616 sta_ctx->conn_info.staId[0]);
Zhang Qian79d0d132018-02-05 13:40:16 +08005617 hdd_deregister_tx_flow_control(adapter);
5618 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005619 break;
5620 default:
5621 break;
5622 }
5623
Ajit Pal Singh106c1412018-04-18 18:08:49 +05305624 hdd_deregister_hl_netdev_fc_timer(adapter);
5625
Dustin Brown04348372017-12-14 16:13:39 -08005626 if (adapter->scan_info.default_scan_ies) {
5627 qdf_mem_free(adapter->scan_info.default_scan_ies);
5628 adapter->scan_info.default_scan_ies = NULL;
5629 }
5630
Dustin Browne74003f2018-03-14 12:51:58 -07005631 hdd_exit();
Dustin Brownd747ecd2018-10-26 16:32:22 -07005632
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305633 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005634}
5635
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305636/**
5637 * hdd_deinit_all_adapters - deinit all adapters
5638 * @hdd_ctx: HDD context
5639 * @rtnl_held: True if RTNL lock held
5640 *
5641 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005642void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305643{
Jeff Johnson9d295242017-08-29 14:39:48 -07005644 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305645
Dustin Brown491d54b2018-03-14 12:39:11 -07005646 hdd_enter();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305647
Dustin Brown920397d2017-12-13 16:27:50 -08005648 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305649 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305650
Dustin Browne74003f2018-03-14 12:51:58 -07005651 hdd_exit();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305652}
5653
Dustin Browndb2a8be2017-12-20 11:49:56 -08005654QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005655{
Jeff Johnson9d295242017-08-29 14:39:48 -07005656 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005657
Dustin Brown491d54b2018-03-14 12:39:11 -07005658 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005659
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305660 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5661
Dustin Brown920397d2017-12-13 16:27:50 -08005662 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08005663 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005664
Dustin Browne74003f2018-03-14 12:51:58 -07005665 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005666
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305667 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005668}
5669
Paul Zhang84fa9382017-11-10 21:18:21 +08005670static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
5671 struct hdd_adapter *adapter)
5672{
5673 switch (adapter->device_mode) {
5674 case QDF_STA_MODE:
5675 case QDF_P2P_CLIENT_MODE:
5676 case QDF_IBSS_MODE:
5677 case QDF_P2P_DEVICE_MODE:
5678 case QDF_NDI_MODE:
5679 wlan_hdd_scan_abort(adapter);
5680 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Min Liu8c5d99e2018-09-10 17:18:44 +08005681 if (adapter->device_mode == QDF_STA_MODE) {
5682 struct wlan_objmgr_vdev *vdev;
5683
5684 vdev = hdd_objmgr_get_vdev(adapter);
5685 if (vdev) {
5686 wlan_cfg80211_sched_scan_stop(vdev);
5687 hdd_objmgr_put_vdev(adapter);
5688 }
5689 }
Paul Zhang84fa9382017-11-10 21:18:21 +08005690 break;
5691 case QDF_P2P_GO_MODE:
5692 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5693 break;
5694 case QDF_SAP_MODE:
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305695 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Paul Zhang84fa9382017-11-10 21:18:21 +08005696 wlan_hdd_undo_acs(adapter);
5697 break;
5698 default:
5699 break;
5700 }
5701}
5702
Ke Huangc067b8d2018-05-21 15:50:13 +08005703#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
5704/**
5705 * hdd_adapter_abort_tx_flow() - Abort the tx flow control
5706 * @pAdapter: pointer to hdd_adapter_t
5707 *
5708 * Resume tx and stop the tx flow control timer if the tx is paused
5709 * and the flow control timer is running. This function is called by
5710 * SSR to avoid the inconsistency of tx status before and after SSR.
5711 *
5712 * Return: void
5713 */
5714static void hdd_adapter_abort_tx_flow(struct hdd_adapter *adapter)
5715{
5716 if (adapter->hdd_stats.tx_rx_stats.is_txflow_paused &&
5717 QDF_TIMER_STATE_RUNNING ==
5718 qdf_mc_timer_get_current_state(
5719 &adapter->tx_flow_control_timer)) {
5720 hdd_tx_resume_timer_expired_handler(adapter);
5721 qdf_mc_timer_stop(&adapter->tx_flow_control_timer);
5722 }
5723}
5724#endif
5725
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005726QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005727{
Jeff Johnson9d295242017-08-29 14:39:48 -07005728 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07005729 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07005730 struct qdf_mac_addr peerMacAddr;
Yue Ma42654682018-01-11 16:55:24 -08005731 int sta_id;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05305732 bool value;
Min Liu8c5d99e2018-09-10 17:18:44 +08005733 struct wlan_objmgr_vdev *vdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005734
Dustin Brown491d54b2018-03-14 12:39:11 -07005735 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005736
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305737 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5738
Dustin Brown920397d2017-12-13 16:27:50 -08005739 hdd_for_each_adapter(hdd_ctx, adapter) {
Dustin Brown5e89ef82018-03-14 11:50:23 -07005740 hdd_info("[SSR] reset adapter with device mode %s(%d)",
Dustin Brown458027c2018-10-19 12:26:27 -07005741 qdf_opmode_str(adapter->device_mode),
Dustin Brown5e89ef82018-03-14 11:50:23 -07005742 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305743
Ke Huangc067b8d2018-05-21 15:50:13 +08005744#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
5745 hdd_adapter_abort_tx_flow(adapter);
5746#endif
5747
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305748 if ((adapter->device_mode == QDF_STA_MODE) ||
Paul Zhang679025e2018-03-08 22:39:44 +08005749 (adapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305750 /* Stop tdls timers */
Min Liu8c5d99e2018-09-10 17:18:44 +08005751 vdev = hdd_objmgr_get_vdev(adapter);
5752 if (vdev) {
5753 hdd_notify_tdls_reset_adapter(vdev);
5754 hdd_objmgr_put_vdev(adapter);
5755 }
Paul Zhang679025e2018-03-08 22:39:44 +08005756 adapter->session.station.hdd_reassoc_scenario = false;
5757 }
Dustin Brown05d81302018-09-11 16:49:22 -07005758 ucfg_mlme_get_sap_internal_restart(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05305759 if (value &&
Arun Khandavallicc544b32017-01-30 19:52:16 +05305760 adapter->device_mode == QDF_SAP_MODE) {
5761 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305762 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05305763 WLAN_CONTROL_PATH);
Ashish Kumar Dhanotiyadc3900f2019-01-11 20:42:04 +05305764 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
5765 cds_flush_delayed_work(
5766 &adapter->acs_pending_work);
5767 clear_bit(ACS_PENDING, &adapter->event_flags);
5768 }
5769
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005770 if (test_bit(SOFTAP_BSS_STARTED,
Ashish Kumar Dhanotiyadc3900f2019-01-11 20:42:04 +05305771 &adapter->event_flags)) {
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005772 hdd_sap_indicate_disconnect_for_sta(adapter);
Ashish Kumar Dhanotiyadc3900f2019-01-11 20:42:04 +05305773 clear_bit(SOFTAP_BSS_STARTED,
5774 &adapter->event_flags);
5775 }
5776
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005777 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305778 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305779 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005780 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005781 }
Nijun Gong104ccc72018-08-07 10:43:56 +08005782 /*
5783 * Clear fc flag if it was set before SSR to avoid TX queues
5784 * permanently stopped after SSR.
5785 * Here WLAN_START_ALL_NETIF_QUEUE will actually not start any
5786 * queue since it's blocked by reason WLAN_CONTROL_PATH.
5787 */
5788 if (adapter->pause_map & (1 << WLAN_DATA_FLOW_CONTROL))
5789 wlan_hdd_netif_queue_control(adapter,
5790 WLAN_START_ALL_NETIF_QUEUE,
5791 WLAN_DATA_FLOW_CONTROL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005792
Paul Zhang84fa9382017-11-10 21:18:21 +08005793 hdd_reset_scan_operation(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005794
5795 hdd_deinit_tx_rx(adapter);
Dustin Brown1dbefe62018-09-11 16:32:03 -07005796 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005797 adapter->device_mode, adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005798 hdd_green_ap_start_state_mc(hdd_ctx, adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305799 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005800 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5801 hdd_wmm_adapter_close(adapter);
5802 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5803 }
5804
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305805 if (adapter->device_mode == QDF_STA_MODE)
5806 hdd_clear_fils_connection_info(adapter);
5807
Wu Gao3545e642017-07-14 19:24:41 +08005808 if (adapter->device_mode == QDF_SAP_MODE) {
Jingxiang Geec113592018-08-09 15:40:39 +08005809 wlansap_cleanup_cac_timer(
5810 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Wu Gao3545e642017-07-14 19:24:41 +08005811 /*
5812 * If adapter is SAP, set session ID to invalid
5813 * since SAP session will be cleanup during SSR.
5814 */
Wu Gao36717432016-11-21 15:09:48 +08005815 wlansap_set_invalid_session(
5816 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Wu Gao3545e642017-07-14 19:24:41 +08005817 }
5818
Yue Ma42654682018-01-11 16:55:24 -08005819 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005820 if (adapter->device_mode == QDF_STA_MODE ||
5821 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005822 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005823 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07005824 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005825
Yue Ma42654682018-01-11 16:55:24 -08005826 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
Wu Gao6b81fc52018-05-24 19:27:27 +08005827 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Yue Ma42654682018-01-11 16:55:24 -08005828 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5829 if (adapter->sta_info[sta_id].in_use) {
5830 hdd_debug("[SSR] deregister STA with ID %d",
5831 sta_id);
5832 hdd_softap_deregister_sta(adapter,
5833 sta_id);
5834 adapter->sta_info[sta_id].in_use = 0;
5835 }
5836 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005837 }
5838
Alok Kumarb64650c2018-03-23 17:05:11 +05305839 hdd_nud_ignore_tracking(adapter, true);
Alok Kumar016a1ac2018-09-16 09:55:50 +05305840 hdd_nud_reset_tracking(adapter);
5841 hdd_nud_flush_work(adapter);
Ashish Kumar Dhanotiyadc3900f2019-01-11 20:42:04 +05305842
5843 if (adapter->device_mode != QDF_SAP_MODE &&
5844 adapter->device_mode != QDF_P2P_GO_MODE &&
5845 adapter->device_mode != QDF_FTM_MODE)
5846 hdd_set_disconnect_status(adapter, false);
5847
hangtian9c47aaf2018-11-26 17:59:39 +08005848 hdd_stop_tsf_sync(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05305849
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005850 hdd_softap_deinit_tx_rx(adapter);
Tiger Yu8c387702018-07-06 16:56:42 +08005851 hdd_deregister_tx_flow_control(adapter);
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005852
Yue Maf9782842017-05-08 12:49:49 -07005853 /* Destroy vdev which will be recreated during reinit. */
5854 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005855 }
5856
Dustin Browne74003f2018-03-14 12:51:58 -07005857 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005858
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305859 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005860}
5861
Dustin Brown4c663222018-10-23 14:19:36 -07005862bool hdd_is_any_interface_open(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305863{
Dustin Brown920397d2017-12-13 16:27:50 -08005864 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305865
Dustin Brown4c663222018-10-23 14:19:36 -07005866 if (hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) {
Arun Khandavalliba479c42017-07-26 21:29:40 +05305867 hdd_info("FTM mode, don't close the module");
Dustin Brown4c663222018-10-23 14:19:36 -07005868 return true;
Arun Khandavalliba479c42017-07-26 21:29:40 +05305869 }
5870
Dustin Brown920397d2017-12-13 16:27:50 -08005871 hdd_for_each_adapter(hdd_ctx, adapter) {
5872 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
Dustin Brown4c663222018-10-23 14:19:36 -07005873 test_bit(SME_SESSION_OPENED, &adapter->event_flags))
5874 return true;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305875 }
5876
Dustin Brown4c663222018-10-23 14:19:36 -07005877 return false;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305878}
5879
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305880bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305881{
5882 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5883 return true;
5884 else
5885 return false;
5886}
5887
Anurag Chouhanc4092922016-09-08 15:56:11 +05305888#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08005889 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305890struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5891 struct ieee80211_channel *channel,
5892 const u8 *bssid, const u8 *ssid,
5893 size_t ssid_len)
5894{
5895 return cfg80211_get_bss(wiphy, channel, bssid,
5896 ssid, ssid_len,
5897 WLAN_CAPABILITY_ESS,
5898 WLAN_CAPABILITY_ESS);
5899}
5900#else
5901struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5902 struct ieee80211_channel *channel,
5903 const u8 *bssid, const u8 *ssid,
5904 size_t ssid_len)
5905{
5906 return cfg80211_get_bss(wiphy, channel, bssid,
5907 ssid, ssid_len,
5908 IEEE80211_BSS_TYPE_ESS,
5909 IEEE80211_PRIVACY_ANY);
5910}
5911#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305912
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305913#if defined CFG80211_CONNECT_BSS || \
5914 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305915#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305916 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305917/**
5918 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5919 * @timeout_reason: reason for connect timeout
5920 *
5921 * This function is used to convert host timeout
5922 * reason enum to kernel specific enum.
5923 *
5924 * Return: nl timeout enum
5925 */
5926static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5927 tSirResultCodes timeout_reason)
5928{
5929 switch (timeout_reason) {
5930 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5931 return NL80211_TIMEOUT_SCAN;
5932 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5933 return NL80211_TIMEOUT_AUTH;
5934 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5935 return NL80211_TIMEOUT_ASSOC;
5936 default:
5937 return NL80211_TIMEOUT_UNSPECIFIED;
5938 }
5939}
5940
5941/**
5942 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5943 * @dev: network device
5944 * @bssid: bssid to which we want to associate
5945 * @timeout_reason: reason for connect timeout
5946 *
5947 * This API is used to send connection timeout reason to supplicant
5948 *
5949 * Return: void
5950 */
5951static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5952 const u8 *bssid,
5953 tSirResultCodes timeout_reason)
5954{
5955 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005956
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305957 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5958
5959 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5960 nl_timeout_reason);
5961}
5962
5963/**
5964 * __hdd_connect_bss() - API to send connection status to supplicant
5965 * @dev: network device
5966 * @bssid: bssid to which we want to associate
5967 * @req_ie: Request Information Element
5968 * @req_ie_len: len of the req IE
5969 * @resp_ie: Response IE
5970 * @resp_ie_len: len of ht response IE
5971 * @status: status
5972 * @gfp: Kernel Flag
5973 * @timeout_reason: reason for connect timeout
5974 *
5975 * Return: void
5976 */
5977static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5978 struct cfg80211_bss *bss, const u8 *req_ie,
5979 size_t req_ie_len, const u8 *resp_ie,
5980 size_t resp_ie_len, int status, gfp_t gfp,
5981 tSirResultCodes timeout_reason)
5982{
5983 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005984
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305985 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5986
5987 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5988 resp_ie, resp_ie_len, status, gfp,
5989 nl_timeout_reason);
5990}
5991#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305992#if defined CFG80211_CONNECT_TIMEOUT || \
5993 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305994static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5995 const u8 *bssid,
5996 tSirResultCodes timeout_reason)
5997{
5998 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5999}
6000#endif
6001
6002static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
6003 struct cfg80211_bss *bss, const u8 *req_ie,
6004 size_t req_ie_len, const u8 *resp_ie,
6005 size_t resp_ie_len, int status, gfp_t gfp,
6006 tSirResultCodes timeout_reason)
6007{
6008 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
6009 resp_ie, resp_ie_len, status, gfp);
6010}
6011#endif
6012
Abhishek Singha84d3952016-09-13 13:45:05 +05306013/**
6014 * hdd_connect_bss() - API to send connection status to supplicant
6015 * @dev: network device
6016 * @bssid: bssid to which we want to associate
6017 * @req_ie: Request Information Element
6018 * @req_ie_len: len of the req IE
6019 * @resp_ie: Response IE
6020 * @resp_ie_len: len of ht response IE
6021 * @status: status
6022 * @gfp: Kernel Flag
6023 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306024 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05306025 *
6026 * The API is a wrapper to send connection status to supplicant
6027 *
6028 * Return: Void
6029 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306030#if defined CFG80211_CONNECT_TIMEOUT || \
6031 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05306032static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
6033 struct cfg80211_bss *bss, const u8 *req_ie,
6034 size_t req_ie_len, const u8 *resp_ie,
6035 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306036 bool connect_timeout,
6037 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05306038{
6039 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306040 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05306041 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306042 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
6043 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05306044}
6045#else
6046static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
6047 struct cfg80211_bss *bss, const u8 *req_ie,
6048 size_t req_ie_len, const u8 *resp_ie,
6049 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306050 bool connect_timeout,
6051 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05306052{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306053 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
6054 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05306055}
6056#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05306057
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306058#if defined(WLAN_FEATURE_FILS_SK)
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306059#if (defined(CFG80211_CONNECT_DONE) || \
6060 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))) && \
6061 (LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0))
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306062#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
6063 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306064/**
6065 * hdd_populate_fils_params() - Populate FILS keys to connect response
6066 * @fils_params: connect response to supplicant
6067 * @fils_kek: FILS kek
6068 * @fils_kek_len: FILS kek length
6069 * @pmk: FILS PMK
6070 * @pmk_len: FILS PMK length
6071 * @pmkid: PMKID
6072 * @fils_seq_num: FILS Seq number
6073 *
6074 * Return: None
6075 */
6076static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
6077 *fils_params, const uint8_t *fils_kek,
6078 size_t fils_kek_len, const uint8_t *pmk,
6079 size_t pmk_len, const uint8_t *pmkid,
6080 uint16_t fils_seq_num)
6081{
6082 /* Increament seq number to be used for next FILS */
6083 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
6084 fils_params->update_erp_next_seq_num = true;
6085 fils_params->fils_kek = fils_kek;
6086 fils_params->fils_kek_len = fils_kek_len;
6087 fils_params->pmk = pmk;
6088 fils_params->pmk_len = pmk_len;
6089 fils_params->pmkid = pmkid;
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306090 hdd_debug("FILS erp_next_seq_num:%d",
6091 fils_params->fils_erp_next_seq_num);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306092}
6093#else
6094static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
6095 *fils_params, const uint8_t
6096 *fils_kek, size_t fils_kek_len,
6097 const uint8_t *pmk, size_t pmk_len,
6098 const uint8_t *pmkid,
6099 uint16_t fils_seq_num)
6100{ }
6101#endif
6102
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306103#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0))
6104/**
6105 * hdd_populate_fils_params() - Populate FILS keys to connect response
6106 * @fils_params: connect response to supplicant
6107 * @fils_kek: FILS kek
6108 * @fils_kek_len: FILS kek length
6109 * @pmk: FILS PMK
6110 * @pmk_len: FILS PMK length
6111 * @pmkid: PMKID
6112 * @fils_seq_num: FILS Seq number
6113 *
6114 * Return: None
6115 */
6116static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
6117 *fils_params, const uint8_t *fils_kek,
6118 size_t fils_kek_len, const uint8_t *pmk,
6119 size_t pmk_len, const uint8_t *pmkid,
6120 uint16_t fils_seq_num)
6121{
6122 /* Increament seq number to be used for next FILS */
6123 fils_params->fils.erp_next_seq_num = fils_seq_num + 1;
6124 fils_params->fils.update_erp_next_seq_num = true;
6125 fils_params->fils.kek = fils_kek;
6126 fils_params->fils.kek_len = fils_kek_len;
6127 fils_params->fils.pmk = pmk;
6128 fils_params->fils.pmk_len = pmk_len;
6129 fils_params->fils.pmkid = pmkid;
6130 hdd_debug("FILS erp_next_seq_num:%d",
6131 fils_params->fils.erp_next_seq_num);
6132}
6133#endif /* CFG80211_CONNECT_DONE */
6134
6135#if defined(CFG80211_CONNECT_DONE) || \
6136 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
6137
Jeff Johnson172237b2017-11-07 15:32:59 -08006138void hdd_update_hlp_info(struct net_device *dev,
6139 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306140{
6141 struct sk_buff *skb;
6142 uint16_t skb_len;
6143 struct llc_snap_hdr_t *llc_hdr;
6144 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306145 uint8_t *hlp_data;
6146 uint16_t hlp_data_len;
6147 struct fils_join_rsp_params *roam_fils_params
6148 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306149 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
6150
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306151 if (!roam_fils_params) {
6152 hdd_err("FILS Roam Param NULL");
6153 return;
6154 }
6155
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08006156 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306157 hdd_err("FILS HLP Data NULL, len %d",
6158 roam_fils_params->hlp_data_len);
6159 return;
6160 }
6161
6162 hlp_data = roam_fils_params->hlp_data;
6163 hlp_data_len = roam_fils_params->hlp_data_len;
6164
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306165 /* Calculate skb length */
6166 skb_len = (2 * ETH_ALEN) + hlp_data_len;
6167 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
6168 if (skb == NULL) {
6169 hdd_err("HLP packet nbuf alloc fails");
6170 return;
6171 }
6172
6173 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
6174 QDF_MAC_ADDR_SIZE);
6175 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
6176 QDF_MAC_ADDR_SIZE);
6177
6178 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
6179 if (IS_SNAP(llc_hdr)) {
6180 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
6181 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
6182 }
6183
6184 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
6185
6186 /*
6187 * This HLP packet is formed from HLP info encapsulated
6188 * in assoc response frame which is AEAD encrypted.
6189 * Hence, this checksum validation can be set unnecessary.
6190 * i.e. network layer need not worry about checksum.
6191 */
6192 skb->ip_summed = CHECKSUM_UNNECESSARY;
6193
6194 status = hdd_rx_packet_cbk(padapter, skb);
6195 if (QDF_IS_STATUS_ERROR(status)) {
6196 hdd_err("Sending HLP packet fails");
6197 return;
6198 }
6199 hdd_debug("send HLP packet to netif successfully");
6200}
6201
6202/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306203 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
6204 * @dev: network device
6205 * @bssid: bssid to which we want to associate
6206 * @bss: cfg80211 bss info
6207 * @roam_info: information about connected bss
6208 * @req_ie: Request Information Element
6209 * @req_ie_len: len of the req IE
6210 * @resp_ie: Response IE
6211 * @resp_ie_len: len of ht response IE
6212 * @status: status
6213 * @gfp: allocation flags
6214 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
6215 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306216 *
6217 * This API is used as wrapper to send FILS key/sequence number
6218 * params etc. to supplicant in case of FILS connection
6219 *
6220 * Return: None
6221 */
6222static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006223 struct cfg80211_bss *bss,
6224 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306225 const u8 *req_ie, size_t req_ie_len,
6226 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006227 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306228 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306229{
6230 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306231 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
6232 struct fils_join_rsp_params *roam_fils_params =
6233 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006234
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306235 qdf_mem_zero(&fils_params, sizeof(fils_params));
6236
6237 if (!roam_fils_params) {
6238 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
6239 } else {
6240 fils_params.status = status;
6241 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08006242 fils_params.timeout_reason =
6243 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306244 fils_params.req_ie = req_ie;
6245 fils_params.req_ie_len = req_ie_len;
6246 fils_params.resp_ie = resp_ie;
6247 fils_params.resp_ie_len = resp_ie_len;
6248 fils_params.bss = bss;
6249 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
6250 roam_fils_params->kek_len,
6251 roam_fils_params->fils_pmk,
6252 roam_fils_params->fils_pmk_len,
6253 roam_fils_params->fils_pmkid,
6254 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05306255 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306256 }
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306257 hdd_debug("FILS indicate connect status %d", fils_params.status);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306258
6259 cfg80211_connect_done(dev, &fils_params, gfp);
6260
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306261 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306262 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306263
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306264 /* Clear all the FILS key info */
6265 if (roam_fils_params && roam_fils_params->fils_pmk)
6266 qdf_mem_free(roam_fils_params->fils_pmk);
6267 if (roam_fils_params)
6268 qdf_mem_free(roam_fils_params);
6269 roam_info->fils_join_rsp = NULL;
6270}
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306271#else /* CFG80211_CONNECT_DONE */
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006272static inline void
6273hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006274 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006275 const u8 *req_ie, size_t req_ie_len,
6276 const u8 *resp_ie, size_t resp_ie_len, u16 status,
6277 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306278 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306279{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306280#endif
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306281#endif /* WLAN_FEATURE_FILS_SK */
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306282
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306283#if defined(WLAN_FEATURE_FILS_SK) && \
6284 (defined(CFG80211_CONNECT_DONE) || \
6285 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306286/**
6287 * hdd_fils_update_connect_results() - API to send fils connection status to
6288 * supplicant.
6289 * @dev: network device
6290 * @bssid: bssid to which we want to associate
6291 * @bss: cfg80211 bss info
6292 * @roam_info: information about connected bss
6293 * @req_ie: Request Information Element
6294 * @req_ie_len: len of the req IE
6295 * @resp_ie: Response IE
6296 * @resp_ie_len: len of ht response IE
6297 * @status: status
6298 * @gfp: allocation flags
6299 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
6300 * @timeout_reason: reason for connect timeout
6301 *
6302 * The API is a wrapper to send connection status to supplicant
6303 *
6304 * Return: 0 if success else failure
6305 */
6306static int hdd_fils_update_connect_results(struct net_device *dev,
6307 const u8 *bssid,
6308 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08006309 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306310 size_t req_ie_len, const u8 *resp_ie,
6311 size_t resp_ie_len, u16 status, gfp_t gfp,
6312 bool connect_timeout,
6313 tSirResultCodes timeout_reason)
6314{
Dustin Brown491d54b2018-03-14 12:39:11 -07006315 hdd_enter();
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306316 if (!roam_info || !roam_info->is_fils_connection)
6317 return -EINVAL;
6318
6319 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
6320 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306321 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306322 return 0;
6323}
6324#else
6325static inline int hdd_fils_update_connect_results(struct net_device *dev,
6326 const u8 *bssid,
6327 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08006328 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306329 size_t req_ie_len, const u8 *resp_ie,
6330 size_t resp_ie_len, u16 status, gfp_t gfp,
6331 bool connect_timeout,
6332 tSirResultCodes timeout_reason)
6333{
6334 return -EINVAL;
6335}
6336#endif
6337
Anurag Chouhanc4092922016-09-08 15:56:11 +05306338/**
6339 * hdd_connect_result() - API to send connection status to supplicant
6340 * @dev: network device
6341 * @bssid: bssid to which we want to associate
6342 * @roam_info: information about connected bss
6343 * @req_ie: Request Information Element
6344 * @req_ie_len: len of the req IE
6345 * @resp_ie: Response IE
6346 * @resp_ie_len: len of ht response IE
6347 * @status: status
6348 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05306349 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306350 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05306351 *
6352 * The API is a wrapper to send connection status to supplicant
6353 * and allow runtime suspend
6354 *
6355 * Return: Void
6356 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306357void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006358 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05306359 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05306360 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306361 bool connect_timeout,
6362 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05306363{
Jeff Johnson9d295242017-08-29 14:39:48 -07006364 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306365 struct cfg80211_bss *bss = NULL;
Jingxiang Ge929c7932018-01-24 14:01:12 +08006366 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306367
6368 if (WLAN_STATUS_SUCCESS == status) {
6369 struct ieee80211_channel *chan;
6370 int freq;
6371 int chan_no = roam_info->pBssDesc->channelId;
6372
6373 if (chan_no <= 14)
6374 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07006375 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306376 else
6377 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07006378 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306379
6380 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
6381 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
6382 roam_info->u.pConnectedProfile->SSID.ssId,
6383 roam_info->u.pConnectedProfile->SSID.length);
6384 }
Komal Seelama89be8d2016-09-29 11:09:26 +05306385
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306386 if (hdd_fils_update_connect_results(dev, bssid, bss,
6387 roam_info, req_ie, req_ie_len, resp_ie,
6388 resp_ie_len, status, gfp, connect_timeout,
6389 timeout_reason) != 0) {
6390 hdd_connect_bss(dev, bssid, bss, req_ie,
6391 req_ie_len, resp_ie, resp_ie_len,
6392 status, gfp, connect_timeout, timeout_reason);
6393 }
Komal Seelama89be8d2016-09-29 11:09:26 +05306394
Jingxiang Geb49aa302018-01-17 20:54:15 +08006395 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07006396 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306397}
6398#else
6399void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006400 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05306401 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05306402 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306403 bool connect_timeout,
6404 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05306405{
Jeff Johnson9d295242017-08-29 14:39:48 -07006406 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Jingxiang Ge929c7932018-01-24 14:01:12 +08006407 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05306408
Anurag Chouhanc4092922016-09-08 15:56:11 +05306409 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
6410 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08006411
Jingxiang Geb49aa302018-01-17 20:54:15 +08006412 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07006413 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306414}
6415#endif
6416
Nirav Shah73713f72018-05-17 14:50:41 +05306417#ifdef FEATURE_MONITOR_MODE_SUPPORT
Jeff Johnsond9952752018-04-18 12:15:35 -07006418int wlan_hdd_set_mon_chan(struct hdd_adapter *adapter, uint32_t chan,
6419 uint32_t bandwidth)
6420{
6421 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6422 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
6423 struct hdd_mon_set_ch_info *ch_info = &sta_ctx->ch_info;
6424 QDF_STATUS status;
Jeff Johnson43837af2018-10-17 12:44:05 -07006425 mac_handle_t mac_handle = hdd_ctx->mac_handle;
Jeff Johnsond9952752018-04-18 12:15:35 -07006426 struct qdf_mac_addr bssid;
6427 struct csr_roam_profile roam_profile;
6428 struct ch_params ch_params;
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006429 eConnectionState connstate;
Jeff Johnsond9952752018-04-18 12:15:35 -07006430
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006431 if (hdd_get_conparam() != QDF_GLOBAL_MONITOR_MODE &&
6432 adapter->device_mode != QDF_STA_MODE) {
6433 hdd_err("Not supported, device is not in monitor mode or sta mission mode");
Jeff Johnsond9952752018-04-18 12:15:35 -07006434 return -EINVAL;
6435 }
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006436 if (adapter->device_mode == QDF_STA_MODE &&
6437 hdd_ctx->config->enable_change_channel_bandwidth) {
6438 connstate = sta_ctx->conn_info.connState;
6439 if (eConnectionState_Associated == connstate ||
6440 eConnectionState_Connecting == connstate) {
6441 return -EINVAL;
6442 }
6443 }
Jeff Johnsond9952752018-04-18 12:15:35 -07006444
Visweswara Tanuku006313a2018-04-12 12:26:34 +05306445 /* Validate Channel */
6446 if (!WLAN_REG_IS_24GHZ_CH(chan) && !WLAN_REG_IS_5GHZ_CH(chan)) {
6447 hdd_err("Channel %d Not supported", chan);
6448 return -EINVAL;
6449 }
6450
6451 if (WLAN_REG_IS_24GHZ_CH(chan)) {
6452 if (bandwidth == CH_WIDTH_80MHZ) {
6453 hdd_err("BW80 not possible in 2.4GHz band");
6454 return -EINVAL;
6455 }
6456 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 14) &&
6457 (bandwidth != CH_WIDTH_MAX)) {
6458 hdd_err("Only BW20 possible on channel 14");
6459 return -EINVAL;
6460 }
6461 }
6462
6463 if (WLAN_REG_IS_5GHZ_CH(chan)) {
6464 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 165) &&
6465 (bandwidth != CH_WIDTH_MAX)) {
6466 hdd_err("Only BW20 possible on channel 165");
6467 return -EINVAL;
6468 }
6469 }
6470
Jeff Johnsond9952752018-04-18 12:15:35 -07006471 hdd_debug("Set monitor mode Channel %d", chan);
6472 qdf_mem_zero(&roam_profile, sizeof(roam_profile));
6473 roam_profile.ChannelInfo.ChannelList = &ch_info->channel;
6474 roam_profile.ChannelInfo.numOfChannels = 1;
6475 roam_profile.phyMode = ch_info->phy_mode;
6476 roam_profile.ch_params.ch_width = bandwidth;
6477 hdd_select_cbmode(adapter, chan, &roam_profile.ch_params);
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006478 if (hdd_ctx->config->enable_change_channel_bandwidth &&
Jeff Johnson43837af2018-10-17 12:44:05 -07006479 (!sme_find_session_by_bssid(mac_handle, adapter->mac_addr.bytes))) {
6480 status = sme_create_mon_session(mac_handle,
Rajeev Kumar Sirasanagandlae3b59912018-08-24 15:53:31 +05306481 adapter->mac_addr.bytes,
6482 adapter->session_id);
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006483 if (status != QDF_STATUS_SUCCESS) {
6484 hdd_err("Status: %d Failed to create session.",
6485 status);
6486 return qdf_status_to_os_return(status);
6487 }
6488 }
Jeff Johnsond9952752018-04-18 12:15:35 -07006489 qdf_mem_copy(bssid.bytes, adapter->mac_addr.bytes,
6490 QDF_MAC_ADDR_SIZE);
6491
6492 ch_params.ch_width = bandwidth;
Dustin Brown07901ec2018-09-07 11:02:41 -07006493 wlan_reg_set_channel_params(hdd_ctx->pdev, chan, 0, &ch_params);
Jeff Johnsond9952752018-04-18 12:15:35 -07006494 if (ch_params.ch_width == CH_WIDTH_INVALID) {
6495 hdd_err("Invalid capture channel or bandwidth for a country");
6496 return -EINVAL;
6497 }
6498 if (wlan_hdd_change_hw_mode_for_given_chnl(adapter, chan,
6499 POLICY_MGR_UPDATE_REASON_SET_OPER_CHAN)) {
6500 hdd_err("Failed to change hw mode");
6501 return -EINVAL;
6502 }
6503
Jeff Johnson16528362018-06-14 12:34:16 -07006504 status = sme_roam_channel_change_req(hdd_ctx->mac_handle,
6505 bssid, &ch_params,
Jeff Johnsond9952752018-04-18 12:15:35 -07006506 &roam_profile);
6507 if (status) {
6508 hdd_err("Status: %d Failed to set sme_roam Channel for monitor mode",
6509 status);
6510 }
6511
6512 adapter->mon_chan = chan;
6513 adapter->mon_bandwidth = bandwidth;
6514 return qdf_status_to_os_return(status);
6515}
Nirav Shah73713f72018-05-17 14:50:41 +05306516#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05306517
Wu Gaodf929f12018-05-25 18:12:25 +08006518#ifdef MSM_PLATFORM
6519/**
6520 * hdd_stop_p2p_go() - call cfg80211 API to stop P2P GO
6521 * @adapter: pointer to adapter
6522 *
6523 * This function calls cfg80211 API to stop P2P GO
6524 *
6525 * Return: None
6526 */
6527static void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6528{
6529 hdd_debug("[SSR] send stop ap to supplicant");
6530 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
6531}
6532
6533static inline void hdd_delete_sta(struct hdd_adapter *adapter)
6534{
6535}
6536#else
6537static inline void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6538{
6539}
6540
6541/**
6542 * hdd_delete_sta() - call cfg80211 API to delete STA
6543 * @adapter: pointer to adapter
6544 *
6545 * This function calls cfg80211 API to delete STA
6546 *
6547 * Return: None
6548 */
6549static void hdd_delete_sta(struct hdd_adapter *adapter)
6550{
6551 struct qdf_mac_addr bcast_mac = QDF_MAC_ADDR_BCAST_INIT;
6552
6553 hdd_debug("[SSR] send restart supplicant");
6554 /* event supplicant to restart */
6555 cfg80211_del_sta(adapter->dev,
6556 (const u8 *)&bcast_mac.bytes[0],
6557 GFP_KERNEL);
6558}
6559#endif
6560
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006561QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006562{
Jeff Johnson9d295242017-08-29 14:39:48 -07006563 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006564 eConnectionState connState;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05306565 bool value;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006566
Dustin Brown491d54b2018-03-14 12:39:11 -07006567 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006568
Dustin Brown920397d2017-12-13 16:27:50 -08006569 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05306570 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08006571 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05306572
Yue Ma42654682018-01-11 16:55:24 -08006573 hdd_debug("[SSR] start adapter with device mode %s(%d)",
Dustin Brown458027c2018-10-19 12:26:27 -07006574 qdf_opmode_str(adapter->device_mode),
Yue Ma42654682018-01-11 16:55:24 -08006575 adapter->device_mode);
6576
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006577 hdd_wmm_init(adapter);
6578
6579 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006580 case QDF_STA_MODE:
6581 case QDF_P2P_CLIENT_MODE:
6582 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006583
6584 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
6585 ->conn_info.connState;
6586
Krunal Sonib51eec72017-11-20 21:53:01 -08006587 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006588 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07006589 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006590
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006591 /* Indicate disconnect event to supplicant
6592 * if associated previously
6593 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006594 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07006595 eConnectionState_IbssConnected == connState ||
6596 eConnectionState_NotConnected == connState ||
6597 eConnectionState_IbssDisconnected == connState ||
6598 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006599 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006600
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006601 memset(&wrqu, '\0', sizeof(wrqu));
6602 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
6603 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
6604 wireless_send_event(adapter->dev, SIOCGIWAP,
6605 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07006606 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07006607 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006608
6609 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05306610 wlan_hdd_cfg80211_indicate_disconnect(
6611 adapter->dev, false,
6612 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006613 } else if (eConnectionState_Connecting == connState) {
6614 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006615 * Indicate connect failure to supplicant if we
6616 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006617 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306618 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306619 NULL, 0, NULL, 0,
6620 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006621 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006622 }
6623
6624 hdd_register_tx_flow_control(adapter,
6625 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08006626 hdd_tx_resume_cb,
6627 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006628
Arunk Khandavalli40943af2017-05-15 19:25:34 +05306629 hdd_lpass_notify_start(hdd_ctx, adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05306630 hdd_nud_ignore_tracking(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006631 break;
6632
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006633 case QDF_SAP_MODE:
Dustin Brown05d81302018-09-11 16:49:22 -07006634 ucfg_mlme_get_sap_internal_restart(hdd_ctx->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05306635 &value);
6636 if (value)
Krunal Sonib51eec72017-11-20 21:53:01 -08006637 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05306638
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006639 break;
6640
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006641 case QDF_P2P_GO_MODE:
Wu Gaodf929f12018-05-25 18:12:25 +08006642 hdd_delete_sta(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006643 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306644 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08006645 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306646 hdd_set_mon_rx_cb(adapter->dev);
6647 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
6648 adapter->mon_bandwidth);
6649 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006650 default:
6651 break;
6652 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07006653 /*
6654 * Action frame registered in one adapter which will
6655 * applicable to all interfaces
6656 */
6657 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006658 }
6659
Wu Gaodf929f12018-05-25 18:12:25 +08006660 hdd_for_each_adapter(hdd_ctx, adapter) {
6661 if (!hdd_is_interface_up(adapter))
6662 continue;
6663
6664 if (adapter->device_mode == QDF_P2P_GO_MODE)
6665 hdd_stop_p2p_go(adapter);
6666 }
6667
Dustin Browne74003f2018-03-14 12:51:58 -07006668 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006669
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306670 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006671}
6672
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006673QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006674 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006675{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306676 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006677 qdf_list_node_t *node;
6678
6679 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006680
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006681 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006682 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006683 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006684
6685 if (QDF_IS_STATUS_ERROR(status))
6686 return status;
6687
6688 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6689
6690 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006691}
6692
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006693QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006694 struct hdd_adapter *current_adapter,
6695 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006696{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306697 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006698 qdf_list_node_t *node;
6699
6700 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006701
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006702 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006703 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08006704 &current_adapter->node,
6705 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006706 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006707
6708 if (QDF_IS_STATUS_ERROR(status))
6709 return status;
6710
6711 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6712
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006713 return status;
6714}
6715
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006716QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006717 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006718{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306719 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006720
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006721 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006722 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006723 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006724
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006725 return status;
6726}
6727
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006728QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006729 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006730{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306731 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006732 qdf_list_node_t *node;
6733
6734 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006735
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006736 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006737 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006738 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006739
6740 if (QDF_IS_STATUS_ERROR(status))
6741 return status;
6742
6743 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6744
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006745 return status;
6746}
6747
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006748QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006749 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006750{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306751 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006752
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006753 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006754 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006755 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006756
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006757 return status;
6758}
6759
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006760QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006761 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006762{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306763 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006764
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006765 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006766 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006767 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006768
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006769 return status;
6770}
6771
Liangwei Dong3abfe8f2018-09-20 02:25:44 -04006772struct hdd_adapter *hdd_get_adapter_by_rand_macaddr(
6773 struct hdd_context *hdd_ctx, tSirMacAddr mac_addr)
6774{
6775 struct hdd_adapter *adapter;
6776
6777 hdd_for_each_adapter(hdd_ctx, adapter) {
6778 if ((adapter->device_mode == QDF_STA_MODE ||
6779 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6780 adapter->device_mode == QDF_P2P_DEVICE_MODE) &&
6781 ucfg_p2p_check_random_mac(hdd_ctx->psoc,
6782 adapter->session_id, mac_addr))
6783 return adapter;
6784 }
6785
6786 return NULL;
6787}
6788
Jeff Johnson9d295242017-08-29 14:39:48 -07006789struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006790 tSirMacAddr macAddr)
6791{
Jeff Johnson9d295242017-08-29 14:39:48 -07006792 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006793
Dustin Brown920397d2017-12-13 16:27:50 -08006794 hdd_for_each_adapter(hdd_ctx, adapter) {
6795 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
6796 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006797 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006798 }
6799
6800 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006801}
6802
Jeff Johnson9d295242017-08-29 14:39:48 -07006803struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006804 uint32_t vdev_id)
6805{
Jeff Johnson9d295242017-08-29 14:39:48 -07006806 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006807
Dustin Brown920397d2017-12-13 16:27:50 -08006808 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07006809 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006810 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006811 }
6812
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006813 return NULL;
6814}
6815
Abhishek Singh7996eb72015-12-30 17:24:02 +05306816/**
6817 * hdd_get_adapter_by_sme_session_id() - Return adapter with
6818 * the sessionid
6819 * @hdd_ctx: hdd context.
6820 * @sme_session_id: sme session is for the adapter to get.
6821 *
6822 * This function is used to get the adapter with provided session id
6823 *
6824 * Return: adapter pointer if found
6825 *
6826 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07006827struct hdd_adapter *
6828hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
6829 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306830{
Jeff Johnson9d295242017-08-29 14:39:48 -07006831 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306832
Dustin Brown920397d2017-12-13 16:27:50 -08006833 hdd_for_each_adapter(hdd_ctx, adapter) {
6834 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306835 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306836 }
Dustin Brown920397d2017-12-13 16:27:50 -08006837
Abhishek Singh7996eb72015-12-30 17:24:02 +05306838 return NULL;
6839}
6840
Jeff Johnson9d295242017-08-29 14:39:48 -07006841struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07006842 const char *iface_name)
6843{
Jeff Johnson9d295242017-08-29 14:39:48 -07006844 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006845
Dustin Brown920397d2017-12-13 16:27:50 -08006846 hdd_for_each_adapter(hdd_ctx, adapter) {
6847 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07006848 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006849 }
Dustin Brown920397d2017-12-13 16:27:50 -08006850
Naveen Rawat4edb6822017-04-12 10:09:17 -07006851 return NULL;
6852}
6853
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006854/**
6855 * hdd_get_adapter() - to get adapter matching the mode
6856 * @hdd_ctx: hdd context
6857 * @mode: adapter mode
6858 *
6859 * This routine will return the pointer to adapter matching
6860 * with the passed mode.
6861 *
6862 * Return: pointer to adapter or null
6863 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006864struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006865 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006866{
Jeff Johnson9d295242017-08-29 14:39:48 -07006867 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006868
Dustin Brown920397d2017-12-13 16:27:50 -08006869 hdd_for_each_adapter(hdd_ctx, adapter) {
6870 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006871 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006872 }
6873
6874 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006875}
6876
Jeff Johnson36a0abf2018-05-20 11:24:25 -07006877enum QDF_OPMODE hdd_get_device_mode(uint32_t session_id)
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306878{
6879 struct hdd_context *hdd_ctx;
6880 struct hdd_adapter *adapter;
6881
6882 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
6883 if (!hdd_ctx) {
6884 hdd_err("Invalid HDD context");
6885 return QDF_MAX_NO_OF_MODE;
6886 }
6887
6888 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
6889 if (!adapter) {
6890 hdd_err("Invalid HDD adapter");
6891 return QDF_MAX_NO_OF_MODE;
6892 }
6893
6894 return adapter->device_mode;
6895}
6896
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006897/**
6898 * hdd_get_operating_channel() - return operating channel of the device mode
6899 * @hdd_ctx: Pointer to the HDD context.
6900 * @mode: Device mode for which operating channel is required.
Jeff Johnson77f89bb2018-05-06 16:21:36 -07006901 * Supported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006902 * QDF_STA_MODE,
6903 * QDF_P2P_CLIENT_MODE,
6904 * QDF_SAP_MODE,
6905 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006906 *
6907 * This API returns the operating channel of the requested device mode
6908 *
6909 * Return: channel number. "0" id the requested device is not found OR it is
6910 * not connected.
6911 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006912uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006913 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006914{
Jeff Johnson9d295242017-08-29 14:39:48 -07006915 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006916 uint8_t operatingChannel = 0;
6917
Dustin Brown920397d2017-12-13 16:27:50 -08006918 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006919 if (mode == adapter->device_mode) {
6920 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006921 case QDF_STA_MODE:
6922 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006923 if (hdd_conn_is_connected
6924 (WLAN_HDD_GET_STATION_CTX_PTR
6925 (adapter))) {
6926 operatingChannel =
6927 (WLAN_HDD_GET_STATION_CTX_PTR
6928 (adapter))->conn_info.
6929 operationChannel;
6930 }
6931 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006932 case QDF_SAP_MODE:
6933 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006934 /* softap connection info */
6935 if (test_bit
6936 (SOFTAP_BSS_STARTED,
6937 &adapter->event_flags))
6938 operatingChannel =
6939 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07006940 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006941 break;
6942 default:
6943 break;
6944 }
6945
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006946 /* Found the device of interest. break the loop */
6947 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006948 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006949 }
Dustin Brown920397d2017-12-13 16:27:50 -08006950
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006951 return operatingChannel;
6952}
6953
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006954static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006955 hdd_ctx)
6956{
Jeff Johnson9d295242017-08-29 14:39:48 -07006957 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006958
Dustin Brown491d54b2018-03-14 12:39:11 -07006959 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006960
Dustin Brown920397d2017-12-13 16:27:50 -08006961 hdd_for_each_adapter(hdd_ctx, adapter) {
6962 if (adapter->device_mode == QDF_STA_MODE ||
6963 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6964 adapter->device_mode == QDF_IBSS_MODE ||
6965 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6966 adapter->device_mode == QDF_SAP_MODE ||
6967 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006968 hdd_unregister_wext(adapter->dev);
6969 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006970 }
6971
Dustin Browne74003f2018-03-14 12:51:58 -07006972 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006973
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306974 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006975}
6976
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006977QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006978{
Jeff Johnson9d295242017-08-29 14:39:48 -07006979 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006980
Dustin Brown491d54b2018-03-14 12:39:11 -07006981 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006982
Dustin Brown920397d2017-12-13 16:27:50 -08006983 hdd_for_each_adapter(hdd_ctx, adapter) {
6984 if (adapter->device_mode == QDF_STA_MODE ||
6985 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6986 adapter->device_mode == QDF_IBSS_MODE ||
6987 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6988 adapter->device_mode == QDF_SAP_MODE ||
6989 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brown07901ec2018-09-07 11:02:41 -07006990 wlan_abort_scan(hdd_ctx->pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006991 adapter->session_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05306992 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006993 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006994 }
6995
Dustin Browne74003f2018-03-14 12:51:58 -07006996 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006997
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306998 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006999}
7000
Dustin Brownf27bce82016-11-03 12:52:27 -07007001/**
7002 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
7003 * adapters
7004 * @hdd_ctx: The HDD context containing the adapters to operate on
7005 *
7006 * return: QDF_STATUS_SUCCESS
7007 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007008static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07007009{
Jeff Johnson9d295242017-08-29 14:39:48 -07007010 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07007011 int err;
7012
Dustin Brown491d54b2018-03-14 12:39:11 -07007013 hdd_enter();
Dustin Brownf27bce82016-11-03 12:52:27 -07007014
Dustin Brown920397d2017-12-13 16:27:50 -08007015 hdd_for_each_adapter(hdd_ctx, adapter) {
7016 if (adapter->device_mode == QDF_STA_MODE ||
7017 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
7018 adapter->device_mode == QDF_IBSS_MODE ||
7019 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
7020 adapter->device_mode == QDF_SAP_MODE ||
7021 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07007022 err = wlan_hdd_sched_scan_stop(adapter->dev);
7023 if (err)
7024 hdd_err("Unable to stop scheduled scan");
7025 }
Dustin Brownf27bce82016-11-03 12:52:27 -07007026 }
7027
Dustin Browne74003f2018-03-14 12:51:58 -07007028 hdd_exit();
Dustin Brownf27bce82016-11-03 12:52:27 -07007029
7030 return QDF_STATUS_SUCCESS;
7031}
7032
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007033#ifdef WLAN_NS_OFFLOAD
7034/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007035 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007036 * @hdd_ctx: Pointer to hdd context
7037 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007038 * Unregister for IPv6 address change notifications.
7039 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007040 * Return: None
7041 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007042static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007043{
7044 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007045}
7046
7047/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007048 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007049 * @hdd_ctx: Pointer to hdd context
7050 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007051 * Register for IPv6 address change notifications.
7052 *
7053 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007054 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007055static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007056{
7057 int ret;
7058
7059 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
7060 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007061 if (ret) {
7062 hdd_err("Failed to register IPv6 notifier: %d", ret);
7063 goto out;
7064 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007065
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007066 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007067out:
7068 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007069}
7070#else
7071/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007072 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007073 * @hdd_ctx: Pointer to hdd context
7074 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007075 * Unregister for IPv6 address change notifications.
7076 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007077 * Return: None
7078 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007079static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007080{
7081}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007082
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007083/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007084 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007085 * @hdd_ctx: Pointer to hdd context
7086 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007087 * Register for IPv6 address change notifications.
7088 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007089 * Return: None
7090 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007091static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007092{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007093 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007094}
7095#endif
7096
Alok Kumarb64650c2018-03-23 17:05:11 +05307097void hdd_set_disconnect_status(struct hdd_adapter *adapter, bool status)
7098{
7099 qdf_mutex_acquire(&adapter->disconnection_status_lock);
7100 adapter->disconnection_in_progress = status;
7101 qdf_mutex_release(&adapter->disconnection_status_lock);
7102 hdd_debug("setting disconnection status: %d", status);
7103}
7104
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007105/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007106 * hdd_register_notifiers - Register netdev notifiers.
7107 * @hdd_ctx: HDD context
7108 *
7109 * Register netdev notifiers like IPv4 and IPv6.
7110 *
7111 * Return: 0 on success and errno on failure
7112 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007113static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007114{
7115 int ret;
7116
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007117 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
7118 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05307119 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007120
7121 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
7122 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
7123 if (ret) {
7124 hdd_err("Failed to register IPv4 notifier: %d", ret);
7125 goto unregister_ip6_notifier;
7126 }
7127
Alok Kumarb64650c2018-03-23 17:05:11 +05307128 ret = hdd_nud_register_netevent_notifier(hdd_ctx);
7129 if (ret) {
7130 hdd_err("Failed to register netevent notifier: %d",
7131 ret);
7132 goto unregister_inetaddr_notifier;
7133 }
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007134 return 0;
7135
Alok Kumarb64650c2018-03-23 17:05:11 +05307136unregister_inetaddr_notifier:
7137 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007138unregister_ip6_notifier:
7139 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007140out:
7141 return ret;
7142
7143}
7144
7145/**
7146 * hdd_unregister_notifiers - Unregister netdev notifiers.
7147 * @hdd_ctx: HDD context
7148 *
7149 * Unregister netdev notifiers like IPv4 and IPv6.
7150 *
7151 * Return: None.
7152 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007153void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007154{
Alok Kumarb64650c2018-03-23 17:05:11 +05307155 hdd_nud_unregister_netevent_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007156 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
7157
7158 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007159}
7160
7161/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007162 * hdd_exit_netlink_services - Exit netlink services
7163 * @hdd_ctx: HDD context
7164 *
7165 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
7166 * nl service.
7167 *
7168 * Return: None.
7169 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007170static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007171{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307172 spectral_scan_deactivate_service();
7173 cnss_diag_deactivate_service();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007174 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007175 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307176 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007177
7178 nl_srv_exit();
7179}
7180
7181/**
7182 * hdd_init_netlink_services- Init netlink services
7183 * @hdd_ctx: HDD context
7184 *
7185 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
7186 * nl service.
7187 *
7188 * Return: 0 on success and errno on failure.
7189 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007190static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007191{
7192 int ret;
7193
Ryan Hsuceddceb2016-04-28 10:20:14 -07007194 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007195 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007196 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007197 goto out;
7198 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07007199 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007200
Naveen Rawat910726a2017-03-06 11:42:51 -08007201 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007202 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007203 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007204 goto err_nl_srv;
7205 }
7206
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307207 ptt_sock_activate_svc();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007208
7209 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07007210 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007211 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007212
7213 ret = cnss_diag_activate_service();
7214 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007215 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007216 goto err_close_cesium;
7217 }
7218
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307219 spectral_scan_activate_service();
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08007220
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007221 return 0;
7222
7223err_close_cesium:
7224 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007225 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307226 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007227err_nl_srv:
7228 nl_srv_exit();
7229out:
7230 return ret;
7231}
7232
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007233/**
7234 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
7235 * @hdd_ctx: HDD context.
7236 *
7237 * Destroy RX wakelock.
7238 *
7239 * Return: None.
7240 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007241static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007242{
7243 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
7244}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007245
7246/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007247 * hdd_rx_wake_lock_create() - Create RX wakelock
7248 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007249 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007250 * Create RX wakelock.
7251 *
7252 * Return: None.
7253 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007254static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007255{
7256 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
7257}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007258
7259/**
Houston Hoffman160db392016-10-10 17:37:51 -07007260 * hdd_context_deinit() - Deinitialize HDD context
7261 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007262 *
Houston Hoffman160db392016-10-10 17:37:51 -07007263 * Deinitialize HDD context along with all the feature specific contexts but
7264 * do not free hdd context itself. Caller of this API is supposed to free
7265 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007266 *
Houston Hoffman160db392016-10-10 17:37:51 -07007267 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007268 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007269static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007270{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05307271 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
7272
Houston Hoffman160db392016-10-10 17:37:51 -07007273 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007274
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007275 hdd_sap_context_destroy(hdd_ctx);
7276
7277 hdd_rx_wake_lock_destroy(hdd_ctx);
7278
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007279 hdd_scan_context_destroy(hdd_ctx);
7280
Jeff Johnson19fc8e42017-10-30 19:53:49 -07007281 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007282
Houston Hoffman160db392016-10-10 17:37:51 -07007283 return 0;
7284}
7285
Dustin Brown623e7e32018-09-05 14:27:50 -07007286void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07007287{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07007288 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05307289
Dustin Brown623e7e32018-09-05 14:27:50 -07007290 hdd_exit_netlink_services(hdd_ctx);
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05307291 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7292
Houston Hoffman160db392016-10-10 17:37:51 -07007293 hdd_context_deinit(hdd_ctx);
7294
Dustin Browndb2df2e2018-10-31 15:29:24 -07007295 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
7296
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307297 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007298 hdd_ctx->config = NULL;
Dustin Brown84f46ea2018-02-15 11:57:36 -08007299 cfg_release();
7300
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007301 wiphy_free(hdd_ctx->wiphy);
7302}
7303
7304/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05307305 * wlan_destroy_bug_report_lock() - Destroy bug report lock
7306 *
7307 * This function is used to destroy bug report lock
7308 *
7309 * Return: None
7310 */
7311static void wlan_destroy_bug_report_lock(void)
7312{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07007313 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05307314
7315 p_cds_context = cds_get_global_context();
7316 if (!p_cds_context) {
7317 hdd_err("cds context is NULL");
7318 return;
7319 }
7320
7321 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
7322}
7323
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05307324#ifdef DISABLE_CHANNEL_LIST
7325static void wlan_hdd_cache_chann_mutex_destroy(struct hdd_context *hdd_ctx)
7326{
7327 qdf_mutex_destroy(&hdd_ctx->cache_channel_lock);
7328}
7329#else
7330static void wlan_hdd_cache_chann_mutex_destroy(struct hdd_context *hdd_ctx)
7331{
7332}
7333#endif
7334
Dustin Brown92bd8382018-10-31 15:49:46 -07007335void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007336{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007337 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05307338 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007339
Dustin Brown491d54b2018-03-14 12:39:11 -07007340 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007341
Dustin Brown4c663222018-10-23 14:19:36 -07007342 hdd_psoc_idle_timer_stop(hdd_ctx);
Dustin Brown6470aba2018-09-05 09:49:58 -07007343
Arun Khandavallifae92942016-08-01 13:31:08 +05307344 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007345
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007346#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05307347 if (QDF_TIMER_STATE_RUNNING ==
7348 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
7349 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007350 }
7351
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307352 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05307353 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07007354 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007355 }
Liangwei Dongaef84342016-10-21 05:28:00 -04007356 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
7357 qdf_mem_free(hdd_ctx->last_acs_channel_list);
7358 hdd_ctx->last_acs_channel_list = NULL;
7359 hdd_ctx->num_of_channels = 0;
7360 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007361#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007362
Arun Khandavallifae92942016-08-01 13:31:08 +05307363 mutex_lock(&hdd_ctx->iface_change_lock);
7364 driver_status = hdd_ctx->driver_status;
7365 mutex_unlock(&hdd_ctx->iface_change_lock);
7366
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007367 /*
7368 * Powersave Offload Case
7369 * Disable Idle Power Save Mode
7370 */
7371 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07007372 /* clear the scan queue in all the scenarios */
Dustin Brown07901ec2018-09-07 11:02:41 -07007373 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007374
Arun Khandavallifae92942016-08-01 13:31:08 +05307375 if (driver_status != DRIVER_MODULES_CLOSED) {
7376 hdd_unregister_wext_all_adapters(hdd_ctx);
7377 /*
7378 * Cancel any outstanding scan requests. We are about to close
7379 * all of our adapters, but an adapter structure is what SME
7380 * passes back to our callback function. Hence if there
7381 * are any outstanding scan requests then there is a
7382 * race condition between when the adapter is closed and
7383 * when the callback is invoked. We try to resolve that
7384 * race condition here by canceling any outstanding scans
7385 * before we close the adapters.
7386 * Note that the scans may be cancelled in an asynchronous
7387 * manner, so ideally there needs to be some kind of
7388 * synchronization. Rather than introduce a new
7389 * synchronization here, we will utilize the fact that we are
7390 * about to Request Full Power, and since that is synchronized,
7391 * the expectation is that by the time Request Full Power has
7392 * completed, all scans will be cancelled
7393 */
7394 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07007395 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08007396 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08007397 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007398 }
7399
Arunk Khandavalli830c9692018-03-22 12:17:40 +05307400 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavalli08479ba2017-08-07 19:56:23 +05307401 unregister_netdevice_notifier(&hdd_netdev_notifier);
7402
Rachit Kankane30807332018-06-27 18:39:36 +05307403 qdf_dp_trace_deinit();
7404
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07007405 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05307406
Visweswara Tanukuc029a202018-11-27 10:42:10 +05307407 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Dustin Brown86d196b2018-08-02 11:51:49 -07007408 hdd_bus_bandwidth_deinit(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -08007409 hdd_driver_memdump_deinit();
7410
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05307411 qdf_nbuf_deinit_replenish_timer();
7412
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05307413 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
7414 hdd_info("Release wakelock for monitor mode!");
7415 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
7416 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
7417 }
7418
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307419 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307420 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05307421 wlan_hdd_cache_chann_mutex_destroy(hdd_ctx);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307422
Naveen Rawate02f8f52018-04-05 11:58:04 -07007423 osif_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007424
Dustin Brownd005ad82018-01-19 10:32:13 -08007425 hdd_close_all_adapters(hdd_ctx, false);
7426
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05307427 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307428 /*
7429 * If there is re_init failure wiphy would have already de-registered
7430 * check the wiphy status before un-registering again
7431 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05307432 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307433 wiphy_unregister(wiphy);
7434 wlan_hdd_cfg80211_deinit(wiphy);
7435 hdd_lpass_notify_stop(hdd_ctx);
7436 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07007437
Arun Khandavallifae92942016-08-01 13:31:08 +05307438 hdd_exit_netlink_services(hdd_ctx);
7439 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307440#ifdef FEATURE_WLAN_CH_AVOID
7441 mutex_destroy(&hdd_ctx->avoid_freq_lock);
7442#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007443}
7444
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007445#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04007446/**
7447 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007448 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04007449 *
7450 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
7451 * Then new ACS request will do a fresh scan without reusing the cached
7452 * scan information.
7453 *
7454 * Return: void
7455 */
Tang Yingying523322d2017-01-17 23:28:43 +08007456static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007457{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007458 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Jeff Johnson16528362018-06-14 12:34:16 -07007459 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007460
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007461 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007462 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04007463 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
7464 qdf_mem_free(hdd_ctx->last_acs_channel_list);
7465 hdd_ctx->last_acs_channel_list = NULL;
7466 hdd_ctx->num_of_channels = 0;
7467 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007468
Jeff Johnson16528362018-06-14 12:34:16 -07007469 mac_handle = hdd_ctx->mac_handle;
7470 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007471 return;
Jeff Johnson16528362018-06-14 12:34:16 -07007472 sme_scan_flush_result(mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007473}
7474#endif
7475
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007476/**
7477 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
7478 * @state: state
7479 *
7480 * This function notifies FW with modem power status
7481 *
7482 * Return: 0 if successful, error number otherwise
7483 */
7484int hdd_wlan_notify_modem_power_state(int state)
7485{
7486 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307487 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007488 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07007489 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007490
Anurag Chouhan6d760662016-02-20 16:05:43 +05307491 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007492 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307493 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007494 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307495
Jeff Johnson16528362018-06-14 12:34:16 -07007496 mac_handle = hdd_ctx->mac_handle;
7497 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007498 return -EINVAL;
7499
Jeff Johnson16528362018-06-14 12:34:16 -07007500 qdf_status = sme_notify_modem_power_state(mac_handle, state);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307501 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007502 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007503 state);
7504 return -EINVAL;
7505 }
7506 return 0;
7507}
7508
7509/**
7510 *
7511 * hdd_post_cds_enable_config() - HDD post cds start config helper
7512 * @adapter - Pointer to the HDD
7513 *
7514 * Return: None
7515 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007516QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007517{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307518 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007519
7520 /*
7521 * Send ready indication to the HDD. This will kick off the MAC
7522 * into a 'running' state and should kick off an initial scan.
7523 */
Jeff Johnson16528362018-06-14 12:34:16 -07007524 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->mac_handle);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307525 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007526 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
7527 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307528 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007529 }
7530
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307531 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007532}
7533
Sourav Mohapatra92ea8d62018-02-05 10:03:10 +05307534struct hdd_adapter *hdd_get_first_valid_adapter(struct hdd_context *hdd_ctx)
7535{
7536 struct hdd_adapter *adapter;
7537
7538 hdd_for_each_adapter(hdd_ctx, adapter) {
7539 if (adapter && adapter->magic == WLAN_HDD_ADAPTER_MAGIC)
7540 return adapter;
7541 }
7542
7543 return NULL;
7544}
7545
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007546/* wake lock APIs for HDD */
7547void hdd_prevent_suspend(uint32_t reason)
7548{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307549 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007550}
7551
7552void hdd_allow_suspend(uint32_t reason)
7553{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307554 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007555}
7556
7557void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
7558{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05307559 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
7560 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007561}
7562
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007563/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007564QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007565{
Jeff Johnson16528362018-06-14 12:34:16 -07007566 return sme_init_chan_list(hdd_ctx->mac_handle,
Amar Singhal6f8592b2017-04-26 14:31:58 -07007567 hdd_ctx->reg.alpha2,
7568 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007569}
7570
7571/**
7572 * hdd_is_5g_supported() - check if hardware supports 5GHz
7573 * @hdd_ctx: Pointer to the hdd context
7574 *
7575 * HDD function to know if hardware supports 5GHz
7576 *
7577 * Return: true if hardware supports 5GHz
7578 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007579bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007580{
Amar Singhal58b45ef2017-08-01 13:43:54 -07007581 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08007582 return true;
7583
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08007584 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08007585 return true;
7586 else
7587 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007588}
7589
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007590static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007591{
7592 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07007593 int ret_val;
Wu Gaoed616a12019-01-16 15:19:21 +08007594 uint32_t channel_bonding_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007595
7596 wiphy = hdd_ctx->wiphy;
7597
7598 /*
7599 * The channel information in
7600 * wiphy needs to be initialized before wiphy registration
7601 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007602 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
7603 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007604 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07007605 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007606 }
7607
7608#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
7609 wiphy->wowlan = &wowlan_support_reg_init;
7610#else
7611 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
7612 WIPHY_WOWLAN_MAGIC_PKT |
7613 WIPHY_WOWLAN_DISCONNECT |
7614 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
7615 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
7616 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
7617 WIPHY_WOWLAN_4WAY_HANDSHAKE |
7618 WIPHY_WOWLAN_RFKILL_RELEASE;
7619
7620 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
7621 WOW_MAX_FILTERS_PER_LIST);
7622 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
7623 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
7624#endif
Wu Gaoed616a12019-01-16 15:19:21 +08007625 ucfg_mlme_get_channel_bonding_24ghz(hdd_ctx->psoc,
7626 &channel_bonding_mode);
Liangwei Dong0da14262018-07-03 03:30:23 -04007627 if (hdd_ctx->obss_scan_offload) {
7628 hdd_debug("wmi_service_obss_scan supported");
Wu Gaoed616a12019-01-16 15:19:21 +08007629 } else if (channel_bonding_mode) {
Liangwei Dong0da14262018-07-03 03:30:23 -04007630 hdd_debug("enable wpa_supp obss_scan");
7631 wiphy->features |= NL80211_FEATURE_NEED_OBSS_SCAN;
7632 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007633
7634 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007635 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307636 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07007637 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307638 return ret_val;
7639 }
Amar Singhalac26de22018-06-22 12:53:06 -07007640
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007641 /* Check the kernel version for upstream commit aced43ce780dc5 that
7642 * has support for processing user cell_base hints when wiphy is
7643 * self managed or check the backport flag for the same.
7644 */
Amar Singhalac26de22018-06-22 12:53:06 -07007645#if defined CFG80211_USER_HINT_CELL_BASE_SELF_MANAGED || \
7646 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0))
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007647 hdd_send_wiphy_regd_sync_event(hdd_ctx);
7648#endif
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307649
Amar Singhal2d812012018-02-03 15:06:47 +08007650 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007651
Amar Singhale4f28ee2015-10-21 14:36:56 -07007652 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007653}
7654
Mohit Khannaca4173b2017-09-12 21:52:19 -07007655#ifdef MSM_PLATFORM
7656/**
7657 * hdd_display_periodic_stats() - Function to display periodic stats
7658 * @hdd_ctx - handle to hdd context
7659 * @bool data_in_interval - true, if data detected in bw time interval
7660 *
7661 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
7662 * Stats show up in wlan driver logs.
7663 *
7664 * Returns: None
7665 */
Mohit Khanna70322002018-05-15 19:21:32 -07007666static void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
7667 bool data_in_interval)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007668{
Mohit Khanna70322002018-05-15 19:21:32 -07007669 static uint32_t counter;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007670 static bool data_in_time_period;
7671 ol_txrx_pdev_handle pdev;
Mohit Khanna81418772018-10-30 14:14:46 -07007672 ol_txrx_soc_handle soc;
Arif Hussaincca60432018-12-03 19:45:12 -08007673 uint32_t periodic_stats_disp_time = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007674
Arif Hussaincca60432018-12-03 19:45:12 -08007675 ucfg_mlme_stats_get_periodic_display_time(hdd_ctx->psoc,
7676 &periodic_stats_disp_time);
7677 if (!periodic_stats_disp_time)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007678 return;
7679
Mohit Khanna81418772018-10-30 14:14:46 -07007680 soc = cds_get_context(QDF_MODULE_ID_SOC);
7681 if (!soc) {
7682 hdd_err("soc is NULL");
7683 return;
7684 }
7685
Mohit Khannaca4173b2017-09-12 21:52:19 -07007686 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
7687 if (!pdev) {
7688 hdd_err("pdev is NULL");
7689 return;
7690 }
7691
7692 counter++;
7693 if (data_in_interval)
7694 data_in_time_period = data_in_interval;
7695
jitiphil869b9f72018-09-25 17:14:01 +05307696 if (counter * hdd_ctx->config->bus_bw_compute_interval >=
Arif Hussaincca60432018-12-03 19:45:12 -08007697 periodic_stats_disp_time * 1000) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007698 if (data_in_time_period) {
Mohit Khanna70322002018-05-15 19:21:32 -07007699 wlan_hdd_display_txrx_stats(hdd_ctx);
Mohit Khannac9649652018-11-28 18:10:28 -08007700 dp_txrx_ext_dump_stats(soc, CDP_DP_RX_THREAD_STATS);
Mohit Khanna81418772018-10-30 14:14:46 -07007701 cdp_display_stats(soc,
Mohit Khanna70322002018-05-15 19:21:32 -07007702 CDP_RX_RING_STATS,
7703 QDF_STATS_VERBOSITY_LEVEL_LOW);
Mohit Khanna81418772018-10-30 14:14:46 -07007704 cdp_display_stats(soc,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007705 CDP_TXRX_PATH_STATS,
7706 QDF_STATS_VERBOSITY_LEVEL_LOW);
7707 wlan_hdd_display_netif_queue_history
7708 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
7709 qdf_dp_trace_dump_stats();
7710 }
7711 counter = 0;
7712 data_in_time_period = false;
7713 }
7714}
7715
Ravi Joshie2331e82015-07-01 18:18:54 -07007716/**
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007717 * hdd_clear_rps_cpu_mask - clear RPS CPU mask for interfaces
7718 * @hdd_ctx: pointer to struct hdd_context
7719 *
7720 * Return: none
7721 */
7722static void hdd_clear_rps_cpu_mask(struct hdd_context *hdd_ctx)
7723{
7724 struct hdd_adapter *adapter;
7725
7726 hdd_for_each_adapter(hdd_ctx, adapter)
7727 hdd_send_rps_disable_ind(adapter);
7728}
7729
7730/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07007731 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07007732 * @hdd_ctx - handle to hdd context
7733 * @tx_packets - transmit packet count
7734 * @rx_packets - receive packet count
7735 *
7736 * The function controls the bus bandwidth and dynamic control of
7737 * tcp delayed ack configuration
7738 *
7739 * Returns: None
7740 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007741
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007742static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07007743 const uint64_t tx_packets,
7744 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007745{
Mohit Khannaca4173b2017-09-12 21:52:19 -07007746 u64 total_pkts = tx_packets + rx_packets;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007747 uint64_t temp_tx = 0, avg_rx = 0;
7748 uint64_t no_rx_offload_pkts = 0, avg_no_rx_offload_pkts = 0;
7749 uint64_t rx_offload_pkts = 0, avg_rx_offload_pkts = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007750 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08007751 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08007752 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007753 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007754 uint16_t index = 0;
7755 bool vote_level_change = false;
7756 bool rx_level_change = false;
7757 bool tx_level_change = false;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007758 bool rxthread_high_tput_req = false;
Mohit Khannaf7562c32018-07-05 17:42:36 -07007759 bool dptrace_high_tput_req;
Srinivas Girigowda50335342018-09-07 15:21:01 -07007760
jitiphil869b9f72018-09-25 17:14:01 +05307761 if (total_pkts > hdd_ctx->config->bus_bw_high_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007762 next_vote_level = PLD_BUS_WIDTH_HIGH;
jitiphil869b9f72018-09-25 17:14:01 +05307763 else if (total_pkts > hdd_ctx->config->bus_bw_medium_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007764 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
jitiphil869b9f72018-09-25 17:14:01 +05307765 else if (total_pkts > hdd_ctx->config->bus_bw_low_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007766 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07007767 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07007768 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007769
Mohit Khannaf7562c32018-07-05 17:42:36 -07007770 dptrace_high_tput_req =
7771 next_vote_level > PLD_BUS_WIDTH_NONE ? true : false;
7772
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007773 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07007774 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
7775 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007776 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007777 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007778 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007779 if ((next_vote_level == PLD_BUS_WIDTH_LOW) ||
7780 (next_vote_level == PLD_BUS_WIDTH_NONE)) {
Nirav Shahffc6a092016-06-09 16:09:08 +05307781 if (hdd_ctx->hbw_requested) {
7782 pld_remove_pm_qos(hdd_ctx->parent_dev);
7783 hdd_ctx->hbw_requested = false;
7784 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007785 if (hdd_ctx->dynamic_rps)
7786 hdd_clear_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007787 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05307788 if (!hdd_ctx->hbw_requested) {
7789 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
7790 hdd_ctx->hbw_requested = true;
7791 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007792 if (hdd_ctx->dynamic_rps)
7793 hdd_set_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007794 }
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007795
Manjunathappa Prakashcb6df762018-05-29 18:54:58 -07007796 if (hdd_ctx->config->napi_cpu_affinity_mask)
7797 hdd_napi_apply_throughput_policy(hdd_ctx,
7798 tx_packets,
7799 rx_packets);
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007800
jitiphil869b9f72018-09-25 17:14:01 +05307801 if (rx_packets < hdd_ctx->config->bus_bw_low_threshold)
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007802 hdd_disable_rx_ol_for_low_tput(hdd_ctx, true);
7803 else
7804 hdd_disable_rx_ol_for_low_tput(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007805 }
Mohit Khannae71e2262015-11-10 09:37:24 -08007806
Mohit Khannaf7562c32018-07-05 17:42:36 -07007807 qdf_dp_trace_apply_tput_policy(dptrace_high_tput_req);
7808
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007809 /*
7810 * Includes tcp+udp, if perf core is required for tcp, then
7811 * perf core is also required for udp.
7812 */
7813 no_rx_offload_pkts = hdd_ctx->no_rx_offload_pkt_cnt;
7814 hdd_ctx->no_rx_offload_pkt_cnt = 0;
7815 rx_offload_pkts = rx_packets - no_rx_offload_pkts;
Mohit Khannae71e2262015-11-10 09:37:24 -08007816
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007817 avg_no_rx_offload_pkts = (no_rx_offload_pkts +
7818 hdd_ctx->prev_no_rx_offload_pkts) / 2;
7819 hdd_ctx->prev_no_rx_offload_pkts = no_rx_offload_pkts;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08007820
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007821 avg_rx_offload_pkts = (rx_offload_pkts +
7822 hdd_ctx->prev_rx_offload_pkts) / 2;
7823 hdd_ctx->prev_rx_offload_pkts = rx_offload_pkts;
7824
7825 avg_rx = avg_no_rx_offload_pkts + avg_rx_offload_pkts;
7826 /*
7827 * Takes care to set Rx_thread affinity for below case
7828 * 1)LRO/GRO not supported ROME case
7829 * 2)when rx_ol is disabled in cases like concurrency etc
7830 * 3)For UDP cases
7831 */
7832 if (avg_no_rx_offload_pkts >
jitiphil869b9f72018-09-25 17:14:01 +05307833 hdd_ctx->config->bus_bw_high_threshold)
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007834 rxthread_high_tput_req = true;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307835 else
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007836 rxthread_high_tput_req = false;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307837
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007838 if (cds_sched_handle_throughput_req(rxthread_high_tput_req))
7839 hdd_warn("Rx thread high_tput(%d) affinity request failed",
7840 rxthread_high_tput_req);
7841
7842 /* fine-tuning parameters for RX Flows */
jitiphil869b9f72018-09-25 17:14:01 +05307843 if (avg_rx > hdd_ctx->config->tcp_delack_thres_high) {
Ravi Joshifed83572016-10-07 16:20:37 -07007844 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
7845 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
7846 next_rx_level = WLAN_SVC_TP_HIGH;
7847 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07007848 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07007849 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08007850 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007851 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007852
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007853 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007854 struct wlan_rx_tp_data rx_tp_data = {0};
7855
Ravi Joshie2331e82015-07-01 18:18:54 -07007856 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Jeff Johnsonb9feee42018-07-08 10:34:48 -07007857 next_rx_level, avg_rx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007858 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007859 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07007860 /* Send throughput indication only if it is enabled.
7861 * Disabling tcp_del_ack will revert the tcp stack behavior
7862 * to default delayed ack. Note that this will disable the
7863 * dynamic delayed ack mechanism across the system
7864 */
Manjunathappa Prakashbfd12762018-04-29 22:44:52 -07007865 if (hdd_ctx->en_tcp_delack_no_lro)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007866 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
7867
Mohit Khanna6272fb682017-04-13 09:34:36 -07007868 if (hdd_ctx->config->enable_tcp_adv_win_scale)
7869 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
7870
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007871 rx_tp_data.level = next_rx_level;
Alok Kumar2fad6442018-11-08 19:19:28 +05307872 wlan_hdd_update_tcp_rx_param(hdd_ctx, &rx_tp_data);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007873 }
7874
Mohit Khannae71e2262015-11-10 09:37:24 -08007875 /* fine-tuning parameters for TX Flows */
7876 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
7877 hdd_ctx->prev_tx = tx_packets;
7878 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
7879 next_tx_level = WLAN_SVC_TP_HIGH;
7880 else
7881 next_tx_level = WLAN_SVC_TP_LOW;
7882
Prakash Manjunathappae73e3b52018-02-27 18:56:22 -08007883 if ((hdd_ctx->config->enable_tcp_limit_output) &&
7884 (hdd_ctx->cur_tx_level != next_tx_level)) {
Alok Kumar2fad6442018-11-08 19:19:28 +05307885 struct wlan_tx_tp_data tx_tp_data = {0};
7886
Mohit Khannae71e2262015-11-10 09:37:24 -08007887 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
7888 next_tx_level, temp_tx);
7889 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007890 tx_level_change = true;
Alok Kumar2fad6442018-11-08 19:19:28 +05307891 tx_tp_data.level = next_tx_level;
7892 tx_tp_data.tcp_limit_output = true;
7893 wlan_hdd_update_tcp_tx_param(hdd_ctx, &tx_tp_data);
Mohit Khannae71e2262015-11-10 09:37:24 -08007894 }
7895
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007896 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007897 if (vote_level_change || tx_level_change || rx_level_change) {
7898 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
7899 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
7900 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
7901 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
7902 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
7903 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
7904 hdd_ctx->hdd_txrx_hist_idx++;
7905 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
7906 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07007907
7908 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007909}
7910
7911#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Rajeev Kumarb2b5e692018-08-31 15:12:40 -07007912static void __hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007913{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007914 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307915 bus_bw_work);
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307916 struct hdd_adapter *adapter = NULL, *con_sap_adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307917 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05307918 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
7919 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007920 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307921 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007922 bool connected = false;
7923 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
7924
Prashanth Bhattaab004382016-10-11 16:08:11 -07007925 if (wlan_hdd_validate_context(hdd_ctx))
7926 return;
7927
Jeff Johnson214671b2017-10-30 19:45:23 -07007928 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08007929 goto restart_timer;
7930
Dustin Brown920397d2017-12-13 16:27:50 -08007931 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05307932 /*
7933 * Validate magic so we don't end up accessing
7934 * an invalid adapter.
7935 */
7936 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
7937 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007938
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007939 if ((adapter->device_mode == QDF_STA_MODE ||
7940 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007941 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
7942 != eConnectionState_Associated) {
7943
7944 continue;
7945 }
7946
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007947 if ((adapter->device_mode == QDF_SAP_MODE ||
7948 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07007949 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007950
7951 continue;
7952 }
7953
7954 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
7955 adapter->prev_tx_packets);
7956 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
7957 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307958
7959 if (adapter->device_mode == QDF_SAP_MODE ||
7960 adapter->device_mode == QDF_P2P_GO_MODE ||
7961 adapter->device_mode == QDF_IBSS_MODE) {
7962
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08007963 ret = cdp_get_intra_bss_fwd_pkts_count(
7964 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007965 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307966 &fwd_tx_packets, &fwd_rx_packets);
7967 if (ret == A_OK) {
7968 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
7969 fwd_tx_packets,
7970 adapter->prev_fwd_tx_packets);
7971 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
7972 fwd_tx_packets,
7973 adapter->prev_fwd_rx_packets);
7974 }
7975 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007976
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307977 if (adapter->device_mode == QDF_SAP_MODE)
7978 con_sap_adapter = adapter;
7979
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007980 total_rx += adapter->stats.rx_packets;
7981 total_tx += adapter->stats.tx_packets;
7982
7983 spin_lock_bh(&hdd_ctx->bus_bw_lock);
7984 adapter->prev_tx_packets = adapter->stats.tx_packets;
7985 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307986 adapter->prev_fwd_tx_packets = fwd_tx_packets;
7987 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007988 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
7989 connected = true;
7990 }
7991
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007992 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007993 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007994 return;
7995 }
7996
Yun Parka29974a2018-04-09 12:05:49 -07007997 /* add intra bss forwarded tx and rx packets */
7998 tx_packets += fwd_tx_packets_diff;
7999 rx_packets += fwd_rx_packets_diff;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008000
Dustin Brown07901ec2018-09-07 11:02:41 -07008001 if (ucfg_ipa_is_fw_wdi_activated(hdd_ctx->pdev)) {
8002 ucfg_ipa_uc_stat_query(hdd_ctx->pdev, &ipa_tx_packets,
8003 &ipa_rx_packets);
Yun Parka29974a2018-04-09 12:05:49 -07008004 tx_packets += (uint64_t)ipa_tx_packets;
8005 rx_packets += (uint64_t)ipa_rx_packets;
8006
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05308007 if (con_sap_adapter) {
8008 con_sap_adapter->stats.tx_packets += ipa_tx_packets;
8009 con_sap_adapter->stats.rx_packets += ipa_rx_packets;
8010 }
8011
Dustin Brown07901ec2018-09-07 11:02:41 -07008012 ucfg_ipa_set_perf_level(hdd_ctx->pdev, tx_packets, rx_packets);
8013 ucfg_ipa_uc_stat_request(hdd_ctx->pdev, 2);
Yun Parka29974a2018-04-09 12:05:49 -07008014 }
8015
8016 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008017
Jingxiang Gec64e1932017-08-22 14:38:59 +08008018restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08008019 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08008020 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08008021 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05308022 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
jitiphil869b9f72018-09-25 17:14:01 +05308023 hdd_ctx->config->bus_bw_compute_interval);
Dustin Brownfce08d12017-01-17 16:29:38 -08008024 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008025}
Prashanth Bhattaab004382016-10-11 16:08:11 -07008026
Rajeev Kumarb2b5e692018-08-31 15:12:40 -07008027static void hdd_bus_bw_work_handler(struct work_struct *work)
8028{
8029 cds_ssr_protect(__func__);
8030 __hdd_bus_bw_work_handler(work);
8031 cds_ssr_unprotect(__func__);
8032}
8033
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05308034/**
8035 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
8036 * @arg: Argument of timer function
8037 *
8038 * Schedule a workqueue in this function where all the processing is done.
8039 *
8040 * Return: None.
8041 */
8042static void __hdd_bus_bw_cbk(void *arg)
8043{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008044 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05308045
8046 if (wlan_hdd_validate_context(hdd_ctx))
8047 return;
8048
8049 schedule_work(&hdd_ctx->bus_bw_work);
8050}
8051
8052/**
8053 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
8054 * @arg: Argument of timer function
8055 *
8056 * Return: None.
8057 */
8058static void hdd_bus_bw_cbk(void *arg)
8059{
8060 cds_ssr_protect(__func__);
8061 __hdd_bus_bw_cbk(arg);
8062 cds_ssr_unprotect(__func__);
8063}
8064
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008065int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07008066{
Dustin Brown35008ba2018-08-23 14:34:21 -07008067 hdd_enter();
8068
Prashanth Bhattaab004382016-10-11 16:08:11 -07008069 spin_lock_init(&hdd_ctx->bus_bw_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07008070 INIT_WORK(&hdd_ctx->bus_bw_work, hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08008071 hdd_ctx->bus_bw_timer_running = false;
8072 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07008073 qdf_timer_init(NULL, &hdd_ctx->bus_bw_timer, hdd_bus_bw_cbk,
8074 (void *)hdd_ctx, QDF_TIMER_TYPE_SW);
8075
8076 hdd_exit();
Prashanth Bhattaab004382016-10-11 16:08:11 -07008077
8078 return 0;
8079}
8080
Dustin Brown86d196b2018-08-02 11:51:49 -07008081void hdd_bus_bandwidth_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07008082{
Dustin Brown35008ba2018-08-23 14:34:21 -07008083 hdd_enter();
Prashanth Bhattaab004382016-10-11 16:08:11 -07008084
Rajeev Kumarc27efb62018-08-31 14:21:22 -07008085 QDF_BUG(!hdd_ctx->bus_bw_timer_running);
Dustin Brown35008ba2018-08-23 14:34:21 -07008086
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05308087 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08008088 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07008089
8090 hdd_exit();
Prashanth Bhattaab004382016-10-11 16:08:11 -07008091}
Lin Baic5c06882017-09-21 13:58:43 +08008092
Dustin Brown35008ba2018-08-23 14:34:21 -07008093#endif /* MSM_PLATFORM */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008094
8095/**
Nirav Shahed34b212016-04-25 10:59:16 +05308096 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
8097 * @hdd_ctx: hdd context
8098 *
8099 * Return: 0 for success or error code
8100 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008101static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05308102{
8103 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
8104 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Min Liu74a1a502018-10-10 19:59:07 +08008105 if (!hdd_ctx->hdd_txrx_hist)
Nirav Shahed34b212016-04-25 10:59:16 +05308106 return -ENOMEM;
Nirav Shahed34b212016-04-25 10:59:16 +05308107 return 0;
8108}
8109
8110/**
8111 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
8112 * @hdd_ctx: hdd context
8113 *
8114 * Return: none
8115 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008116void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05308117{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05308118 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
8119 return;
8120
8121 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
8122 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05308123}
8124
Nirav Shahda008342016-05-17 18:50:40 +05308125static uint8_t *convert_level_to_string(uint32_t level)
8126{
8127 switch (level) {
8128 /* initialize the wlan sub system */
8129 case WLAN_SVC_TP_NONE:
8130 return "NONE";
8131 case WLAN_SVC_TP_LOW:
8132 return "LOW";
8133 case WLAN_SVC_TP_MEDIUM:
8134 return "MED";
8135 case WLAN_SVC_TP_HIGH:
8136 return "HIGH";
8137 default:
8138 return "INVAL";
8139 }
8140}
8141
Nirav Shahed34b212016-04-25 10:59:16 +05308142
8143/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008144 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
8145 * @hdd_ctx: hdd context
8146 *
8147 * Return: none
8148 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008149void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008150{
8151 int i;
8152
8153#ifdef MSM_PLATFORM
Nirav Shahe6194ac2018-07-13 11:04:41 +05308154 hdd_nofl_info("BW compute Interval: %dms",
jitiphil869b9f72018-09-25 17:14:01 +05308155 hdd_ctx->config->bus_bw_compute_interval);
Nirav Shahe6194ac2018-07-13 11:04:41 +05308156 hdd_nofl_info("BW High TH: %d BW Med TH: %d BW Low TH: %d",
jitiphil869b9f72018-09-25 17:14:01 +05308157 hdd_ctx->config->bus_bw_high_threshold,
8158 hdd_ctx->config->bus_bw_medium_threshold,
8159 hdd_ctx->config->bus_bw_low_threshold);
Nirav Shahe6194ac2018-07-13 11:04:41 +05308160 hdd_nofl_info("Enable TCP DEL ACK: %d",
8161 hdd_ctx->en_tcp_delack_no_lro);
8162 hdd_nofl_info("TCP DEL High TH: %d TCP DEL Low TH: %d",
jitiphil869b9f72018-09-25 17:14:01 +05308163 hdd_ctx->config->tcp_delack_thres_high,
8164 hdd_ctx->config->tcp_delack_thres_low);
Nirav Shahe6194ac2018-07-13 11:04:41 +05308165 hdd_nofl_info("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
8166 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008167#endif
8168
Nirav Shahe6194ac2018-07-13 11:04:41 +05308169 hdd_nofl_info("Total entries: %d Current index: %d",
8170 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
Nirav Shahda008342016-05-17 18:50:40 +05308171
Nirav Shahe6194ac2018-07-13 11:04:41 +05308172 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 -08008173
8174 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008175 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08008176 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Nirav Shahe6194ac2018-07-13 11:04:41 +05308177 hdd_nofl_info("[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
8178 i, hdd_ctx->hdd_txrx_hist[i].qtime,
8179 hdd_ctx->hdd_txrx_hist[i].interval_rx,
8180 hdd_ctx->hdd_txrx_hist[i].interval_tx,
8181 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008182 hdd_ctx->hdd_txrx_hist[i].
8183 next_vote_level),
Nirav Shahe6194ac2018-07-13 11:04:41 +05308184 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008185 hdd_ctx->hdd_txrx_hist[i].
8186 next_rx_level),
Nirav Shahe6194ac2018-07-13 11:04:41 +05308187 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008188 hdd_ctx->hdd_txrx_hist[i].
8189 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008190 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008191}
8192
8193/**
8194 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
8195 * @hdd_ctx: hdd context
8196 *
8197 * Return: none
8198 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008199void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008200{
8201 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05308202 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
8203 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008204}
8205
Mohit Khannaca4173b2017-09-12 21:52:19 -07008206/* length of the netif queue log needed per adapter */
8207#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
8208
8209/**
8210 *
8211 * hdd_display_netif_queue_history_compact() - display compact netifq history
8212 * @hdd_ctx: hdd context
8213 *
8214 * Return: none
8215 */
8216static void
8217hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
8218{
8219 int adapter_num = 0;
8220 int i;
8221 int bytes_written;
8222 u32 tbytes;
8223 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008224 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08008225 char *comb_log_str;
8226 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008227 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008228
Dustin Brownbee82832018-07-23 10:10:51 -07008229 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * CSR_ROAM_SESSION_MAX) + 1;
jiadbdefb252018-01-03 14:27:06 +08008230 comb_log_str = qdf_mem_malloc(comb_log_str_size);
Min Liu74a1a502018-10-10 19:59:07 +08008231 if (!comb_log_str)
jiadbdefb252018-01-03 14:27:06 +08008232 return;
jiadbdefb252018-01-03 14:27:06 +08008233
Mohit Khannaca4173b2017-09-12 21:52:19 -07008234 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008235
Dustin Brown920397d2017-12-13 16:27:50 -08008236 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07008237 curr_time = qdf_system_ticks();
8238 total = curr_time - adapter->start_time;
8239 delta = curr_time - adapter->last_time;
8240
8241 if (adapter->pause_map) {
8242 pause = adapter->total_pause_time + delta;
8243 unpause = adapter->total_unpause_time;
8244 } else {
8245 unpause = adapter->total_unpause_time + delta;
8246 pause = adapter->total_pause_time;
8247 }
8248
8249 tbytes = 0;
hangtian127c9532019-01-12 13:29:07 +08008250 qdf_mem_zero(temp_str, sizeof(temp_str));
Mohit Khannaca4173b2017-09-12 21:52:19 -07008251 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
8252 if (adapter->queue_oper_stats[i].pause_count == 0)
8253 continue;
8254 tbytes +=
8255 snprintf(
8256 &temp_str[tbytes],
8257 (tbytes >= sizeof(temp_str) ?
8258 0 : sizeof(temp_str) - tbytes),
8259 "%d(%d,%d) ",
8260 i,
8261 adapter->queue_oper_stats[i].
8262 pause_count,
8263 adapter->queue_oper_stats[i].
8264 unpause_count);
8265 }
8266 if (tbytes >= sizeof(temp_str))
8267 hdd_warn("log truncated");
8268
8269 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08008270 bytes_written >= comb_log_str_size ? 0 :
8271 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07008272 "[%d %d] (%d) %u/%ums %s|",
8273 adapter->session_id, adapter->device_mode,
8274 adapter->pause_map,
8275 qdf_system_ticks_to_msecs(pause),
8276 qdf_system_ticks_to_msecs(total),
8277 temp_str);
8278
Mohit Khannaca4173b2017-09-12 21:52:19 -07008279 adapter_num++;
8280 }
8281
8282 /* using QDF_TRACE to avoid printing function name */
8283 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
8284 "STATS |%s", comb_log_str);
8285
jiadbdefb252018-01-03 14:27:06 +08008286 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07008287 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08008288
8289 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07008290}
8291
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008292/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008293 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07008294 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008295 *
8296 * Return: none
8297 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07008298void
8299wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
8300 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008301{
8302
Jeff Johnson9d295242017-08-29 14:39:48 -07008303 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008304 int i;
Nirav Shahda008342016-05-17 18:50:40 +05308305 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008306
Mohit Khannaca4173b2017-09-12 21:52:19 -07008307 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
8308 hdd_display_netif_queue_history_compact(hdd_ctx);
8309 return;
8310 }
8311
Dustin Brown920397d2017-12-13 16:27:50 -08008312 hdd_for_each_adapter(hdd_ctx, adapter) {
Nirav Shahe6194ac2018-07-13 11:04:41 +05308313 hdd_nofl_info("Netif queue operation statistics:");
8314 hdd_nofl_info("Session_id %d device mode %d",
8315 adapter->session_id, adapter->device_mode);
8316 hdd_nofl_info("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05308317 curr_time = qdf_system_ticks();
8318 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05308319 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05308320 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05308321 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05308322 unpause = adapter->total_unpause_time;
8323 } else {
Nirav Shahda008342016-05-17 18:50:40 +05308324 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05308325 pause = adapter->total_pause_time;
8326 }
Nirav Shahe6194ac2018-07-13 11:04:41 +05308327 hdd_nofl_info("Total: %ums Pause: %ums Unpause: %ums",
8328 qdf_system_ticks_to_msecs(total),
8329 qdf_system_ticks_to_msecs(pause),
8330 qdf_system_ticks_to_msecs(unpause));
8331 hdd_nofl_info("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008332
Nirav Shahda008342016-05-17 18:50:40 +05308333 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
8334 qdf_time_t pause_delta = 0;
8335
8336 if (adapter->pause_map & (1 << i))
8337 pause_delta = delta;
8338
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008339 /* using hdd_log to avoid printing function name */
Nirav Shahe6194ac2018-07-13 11:04:41 +05308340 hdd_nofl_info("%s: %d: %d: %ums",
8341 hdd_reason_type_to_string(i),
8342 adapter->queue_oper_stats[i].pause_count,
8343 adapter->queue_oper_stats[i].
8344 unpause_count,
8345 qdf_system_ticks_to_msecs(
8346 adapter->queue_oper_stats[i].
8347 total_pause_time + pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008348 }
8349
Nirav Shahe6194ac2018-07-13 11:04:41 +05308350 hdd_nofl_info("Netif queue operation history:");
8351 hdd_nofl_info("Total entries: %d current index %d",
8352 WLAN_HDD_MAX_HISTORY_ENTRY,
8353 adapter->history_index);
Nirav Shahda008342016-05-17 18:50:40 +05308354
Nirav Shahe6194ac2018-07-13 11:04:41 +05308355 hdd_nofl_info("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008356
8357 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008358 /* using hdd_log to avoid printing function name */
8359 if (adapter->queue_oper_history[i].time == 0)
8360 continue;
Nirav Shahe6194ac2018-07-13 11:04:41 +05308361 hdd_nofl_info("%d: %u: %s: %s: %x",
8362 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008363 adapter->queue_oper_history[i].time),
Nirav Shahe6194ac2018-07-13 11:04:41 +05308364 hdd_action_type_to_string(
8365 adapter->queue_oper_history[i].
8366 netif_action),
8367 hdd_reason_type_to_string(
8368 adapter->queue_oper_history[i].
8369 netif_reason),
8370 adapter->queue_oper_history[i].pause_map);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008371 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008372 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008373}
8374
8375/**
8376 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
8377 * @hdd_ctx: hdd context
8378 *
8379 * Return: none
8380 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008381void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008382{
Jeff Johnson9d295242017-08-29 14:39:48 -07008383 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008384
Dustin Brown920397d2017-12-13 16:27:50 -08008385 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308386 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008387 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308388 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008389 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05308390 adapter->history_index = 0;
8391 adapter->start_time = adapter->last_time = qdf_system_ticks();
8392 adapter->total_pause_time = 0;
8393 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008394 }
8395}
8396
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008397#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
8398/**
8399 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
8400 * @hdd_ctx: hdd global context
8401 *
8402 * Return: none
8403 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008404static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008405{
8406 uint8_t i;
8407
8408 mutex_init(&hdd_ctx->op_ctx.op_lock);
8409 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
8410 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
8411 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
8412 }
8413}
8414#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008415static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008416{
8417}
8418#endif
8419
Yingying Tang95409972016-10-20 15:16:15 +08008420#ifdef WLAN_FEATURE_WOW_PULSE
8421/**
8422 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008423 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08008424 * @enable: enable or disable this behaviour
8425 *
8426 * Return: int
8427 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008428static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008429{
Yingying Tang95409972016-10-20 15:16:15 +08008430 struct wow_pulse_mode wow_pulse_set_info;
8431 QDF_STATUS status;
8432
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008433 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08008434
Wu Gao66454f12018-09-26 19:55:41 +08008435 if (!ucfg_pmo_is_wow_pulse_enabled(phddctx->psoc))
Yingying Tang95409972016-10-20 15:16:15 +08008436 return 0;
8437
8438 /* prepare the request to send to SME */
8439 if (enable == true) {
8440 wow_pulse_set_info.wow_pulse_enable = true;
8441 wow_pulse_set_info.wow_pulse_pin =
Wu Gao66454f12018-09-26 19:55:41 +08008442 ucfg_pmo_get_wow_pulse_pin(phddctx->psoc);
8443
Yingying Tang95409972016-10-20 15:16:15 +08008444 wow_pulse_set_info.wow_pulse_interval_high =
Wu Gao66454f12018-09-26 19:55:41 +08008445 ucfg_pmo_get_wow_pulse_interval_high(phddctx->psoc);
8446
8447 wow_pulse_set_info.wow_pulse_interval_low =
8448 ucfg_pmo_get_wow_pulse_interval_low(phddctx->psoc);
Yingying Tang95409972016-10-20 15:16:15 +08008449 } else {
8450 wow_pulse_set_info.wow_pulse_enable = false;
8451 wow_pulse_set_info.wow_pulse_pin = 0;
8452 wow_pulse_set_info.wow_pulse_interval_low = 0;
8453 wow_pulse_set_info.wow_pulse_interval_high = 0;
8454 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008455 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08008456 wow_pulse_set_info.wow_pulse_enable,
8457 wow_pulse_set_info.wow_pulse_pin,
8458 wow_pulse_set_info.wow_pulse_interval_low,
8459 wow_pulse_set_info.wow_pulse_interval_high);
8460
8461 status = sme_set_wow_pulse(&wow_pulse_set_info);
8462 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008463 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08008464 return -EIO;
8465 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008466 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08008467 return 0;
8468}
8469#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008470static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008471{
8472 return 0;
8473}
8474#endif
8475
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008476#ifdef WLAN_FEATURE_FASTPATH
jitiphil377bcc12018-10-05 19:46:08 +05308477
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008478/**
8479 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
8480 * @hdd_cfg: hdd config
8481 * @context: lower layer context
8482 *
8483 * Return: none
8484 */
jitiphil377bcc12018-10-05 19:46:08 +05308485void hdd_enable_fastpath(struct hdd_context *hdd_ctx,
8486 void *context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008487{
jitiphil377bcc12018-10-05 19:46:08 +05308488 if (cfg_get(hdd_ctx->psoc, CFG_DP_ENABLE_FASTPATH))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008489 hif_enable_fastpath(context);
8490}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008491#endif
8492
Yuanyuan Liu13738502016-04-06 17:41:37 -07008493#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008494/**
8495 * hdd_set_thermal_level_cb() - set thermal level callback function
Jeff Johnson0e963082018-07-04 19:39:20 -07008496 * @hdd_handle: opaque handle for the hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008497 * @level: thermal level
8498 *
8499 * Change IPA data path to SW path when the thermal throttle level greater
8500 * than 0, and restore the original data path when throttle level is 0
8501 *
8502 * Return: none
8503 */
Jeff Johnson0e963082018-07-04 19:39:20 -07008504static void hdd_set_thermal_level_cb(hdd_handle_t hdd_handle, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008505{
Jeff Johnson0e963082018-07-04 19:39:20 -07008506 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008507
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008508 /* Change IPA to SW path when throttle level greater than 0 */
8509 if (level > THROTTLE_LEVEL_0)
Dustin Brown07901ec2018-09-07 11:02:41 -07008510 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->pdev, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008511 else
8512 /* restore original concurrency mode */
Dustin Brown07901ec2018-09-07 11:02:41 -07008513 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->pdev, hdd_ctx->mcc_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008514}
8515
8516/**
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308517 * hdd_get_safe_channel() - Get safe channel from current regulatory
8518 * @hdd_ctx: pointer to hdd context
8519 * @adapter: pointer to softap adapter
8520 *
8521 * This function is used to get safe channel from current regulatory valid
8522 * channels to restart SAP if failed to get safe channel from PCL.
8523 *
8524 * Return: Channel number to restart SAP in case of success. In case of any
8525 * failure, the channel number returned is zero.
8526 */
8527static uint8_t
8528hdd_get_safe_channel(struct hdd_context *hdd_ctx,
8529 struct hdd_adapter *adapter)
8530{
8531 struct sir_pcl_list pcl = {0};
8532 uint32_t i, j;
8533 bool found = false;
8534 int ret;
8535
8536 /* Try for safe channel from all valid channel */
8537 pcl.pcl_len = MAX_NUM_CHAN;
8538 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
8539 &pcl.pcl_len);
8540 if (ret) {
8541 hdd_err("error %d in getting valid channel list", ret);
8542 return INVALID_CHANNEL_ID;
8543 }
8544
8545 for (i = 0; i < pcl.pcl_len; i++) {
8546 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
8547 found = false;
8548 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
8549 if (pcl.pcl_list[i] ==
8550 hdd_ctx->unsafe_channel_list[j]) {
8551 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
8552 found = true;
8553 break;
8554 }
8555 }
8556
8557 if (found)
8558 continue;
8559
8560 if ((pcl.pcl_list[i] >=
8561 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
8562 (pcl.pcl_list[i] <=
8563 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
8564 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
8565 return pcl.pcl_list[i];
8566 }
8567 }
8568
8569 return INVALID_CHANNEL_ID;
8570}
8571
8572#else
8573/**
8574 * hdd_set_thermal_level_cb() - set thermal level callback function
8575 * @hdd_handle: opaque handle for the hdd context
8576 * @level: thermal level
8577 *
8578 * Change IPA data path to SW path when the thermal throttle level greater
8579 * than 0, and restore the original data path when throttle level is 0
8580 *
8581 * Return: none
8582 */
8583static void hdd_set_thermal_level_cb(hdd_handle_t hdd_handle, u_int8_t level)
8584{
8585}
8586
8587/**
8588 * hdd_get_safe_channel() - Get safe channel from current regulatory
8589 * @hdd_ctx: pointer to hdd context
8590 * @adapter: pointer to softap adapter
8591 *
8592 * This function is used to get safe channel from current regulatory valid
8593 * channels to restart SAP if failed to get safe channel from PCL.
8594 *
8595 * Return: Channel number to restart SAP in case of success. In case of any
8596 * failure, the channel number returned is zero.
8597 */
8598static uint8_t
8599hdd_get_safe_channel(struct hdd_context *hdd_ctx,
8600 struct hdd_adapter *adapter)
8601{
8602 return 0;
8603}
8604#endif
8605
8606/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308607 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
8608 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05308609 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008610 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308611 * Get a safe channel to restart SAP. PCL already takes into account the
8612 * unsafe channels. So, the PCL is validated with the ACS range to provide
8613 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008614 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308615 * Return: Channel number to restart SAP in case of success. In case of any
8616 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008617 */
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308618static uint8_t
8619hdd_get_safe_channel_from_pcl_and_acs_range(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008620{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308621 struct sir_pcl_list pcl;
8622 QDF_STATUS status;
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308623 uint32_t i;
Jeff Johnson16528362018-06-14 12:34:16 -07008624 mac_handle_t mac_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008625 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008626
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308627 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8628 if (!hdd_ctx) {
8629 hdd_err("invalid HDD context");
8630 return INVALID_CHANNEL_ID;
8631 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008632
Jeff Johnson16528362018-06-14 12:34:16 -07008633 mac_handle = hdd_ctx->mac_handle;
8634 if (!mac_handle) {
8635 hdd_err("invalid MAC handle");
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05308636 return INVALID_CHANNEL_ID;
8637 }
8638
Dustin Brown1dbefe62018-09-11 16:32:03 -07008639 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008640 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08008641 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
8642 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308643 if (QDF_IS_STATUS_ERROR(status)) {
8644 hdd_err("Get PCL failed");
8645 return INVALID_CHANNEL_ID;
8646 }
8647
Frank Liudc2cefb2017-06-21 15:38:18 +08008648 /*
8649 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
8650 * channel is unsafe channel, the pcl may be empty, instead of return,
8651 * try to choose a safe channel from acs range.
8652 */
8653 if (!pcl.pcl_len)
8654 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308655
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008656 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07008657 adapter->session.ap.sap_config.acs_cfg.start_ch,
8658 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308659
8660 /* PCL already takes unsafe channel into account */
8661 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008662 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308663 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008664 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308665 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008666 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008667 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308668 return pcl.pcl_list[i];
8669 }
8670 }
8671
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008672 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308673
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308674 return hdd_get_safe_channel(hdd_ctx, adapter);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308675}
8676
8677/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008678 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308679 * @adapter: AP adapter
8680 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08008681 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308682 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008683 * Moves the SAP interface by invoking the function which
8684 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308685 *
8686 * Return: None
8687 */
Min Liu2fef5792018-01-19 17:59:42 +08008688void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
8689 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308690{
Jeff Johnson87251032017-08-29 13:31:11 -07008691 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008692 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07008693 mac_handle_t mac_handle;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308694
8695 if (!adapter) {
8696 hdd_err("invalid adapter");
8697 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008698 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308699
8700 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
8701
Jeff Johnson16528362018-06-14 12:34:16 -07008702 mac_handle = hdd_adapter_get_mac_handle(adapter);
8703 if (!mac_handle) {
8704 hdd_err("invalid MAC handle");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308705 return;
8706 }
8707
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008708 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8709
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008710 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07008711 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308712
Dustin Brown1dbefe62018-09-11 16:32:03 -07008713 policy_mgr_change_sap_channel_with_csa(hdd_ctx->psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07008714 adapter->session_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08008715 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008716}
Kapil Gupta8878ad92017-02-13 11:56:04 +05308717
Jeff Johnson9d295242017-08-29 14:39:48 -07008718int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05308719{
8720 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308721 int status;
8722 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308723
8724 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8725
8726 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07008727 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05308728 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07008729 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308730 }
8731 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07008732 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308733 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308734 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07008735 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308736 WLAN_VENDOR_ACS_WAIT_TIME);
8737 if (qdf_status != QDF_STATUS_SUCCESS) {
8738 hdd_err("failed to start external acs timer");
8739 return -ENOSPC;
8740 }
8741 /* Update config to application */
8742 status = hdd_cfg80211_update_acs_config(adapter, reason);
Dustin Brown5e89ef82018-03-14 11:50:23 -07008743 hdd_info("Updated ACS config to nl with reason %d", reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308744
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308745 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308746}
8747
Nirav Shaheb017be2018-02-15 11:20:58 +05308748#if defined(FEATURE_WLAN_CH_AVOID)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308749/**
8750 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
8751 * @hdd_ctx: hdd context pointer
8752 *
8753 * hdd_unsafe_channel_restart_sap check all unsafe channel list
8754 * and if ACS is enabled, driver will ask userspace to restart the
8755 * sap. User space on LTE coex indication restart driver.
8756 *
8757 * Return - none
8758 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008759void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308760{
Dustin Brown920397d2017-12-13 16:27:50 -08008761 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308762 uint32_t i;
8763 bool found = false;
8764 uint8_t restart_chan;
Krunal Sonidf29bc42018-11-15 13:26:29 -08008765 uint8_t scc_on_lte_coex = 0;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05308766 bool value;
Harprit Chhabada1eeeb8d2018-09-14 15:16:56 -07008767 QDF_STATUS status;
8768 bool is_acs_support_for_dfs_ltecoex = cfg_default(CFG_USER_ACS_DFS_LTE);
8769 bool is_vendor_acs_support =
8770 cfg_default(CFG_USER_AUTO_CHANNEL_SELECTION);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008771
Dustin Brown920397d2017-12-13 16:27:50 -08008772 hdd_for_each_adapter(hdd_ctxt, adapter) {
8773 if (!(adapter->device_mode == QDF_SAP_MODE &&
8774 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008775 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08008776 adapter->device_mode,
8777 adapter->session.ap.sap_config.
8778 acs_cfg.acs_mode);
8779 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308780 }
8781
8782 found = false;
Krunal Sonidf29bc42018-11-15 13:26:29 -08008783 status =
8784 ucfg_policy_mgr_get_sta_sap_scc_lte_coex_chnl(hdd_ctxt->psoc,
8785 &scc_on_lte_coex);
8786 if (!QDF_IS_STATUS_SUCCESS(status))
8787 hdd_err("can't get scc on lte coex chnl, use def");
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008788 /*
8789 * If STA+SAP is doing SCC & g_sta_sap_scc_on_lte_coex_chan
8790 * is set, no need to move SAP.
8791 */
Dustin Brown1dbefe62018-09-11 16:32:03 -07008792 if (policy_mgr_is_sta_sap_scc(hdd_ctxt->psoc,
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008793 adapter->session.ap.operating_channel) &&
Krunal Sonidf29bc42018-11-15 13:26:29 -08008794 scc_on_lte_coex)
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008795 hdd_debug("SAP is allowed on SCC channel, no need to move SAP");
8796 else {
8797 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
8798 if (adapter->session.ap.operating_channel ==
8799 hdd_ctxt->unsafe_channel_list[i]) {
8800 found = true;
8801 hdd_debug("operating ch:%d is unsafe",
8802 adapter->session.ap.operating_channel);
8803 break;
8804 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308805 }
8806 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308807 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008808 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08008809 adapter->session.ap.operating_channel);
8810 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308811 }
8812
Harprit Chhabada1eeeb8d2018-09-14 15:16:56 -07008813 status = ucfg_mlme_get_acs_support_for_dfs_ltecoex(
8814 hdd_ctxt->psoc,
8815 &is_acs_support_for_dfs_ltecoex);
8816 if (!QDF_IS_STATUS_SUCCESS(status))
8817 hdd_err("get_acs_support_for_dfs_ltecoex failed,set def");
8818
8819 status = ucfg_mlme_get_vendor_acs_support(
8820 hdd_ctxt->psoc,
8821 &is_vendor_acs_support);
8822 if (!QDF_IS_STATUS_SUCCESS(status))
8823 hdd_err("get_vendor_acs_support failed, set default");
8824
8825 if (is_vendor_acs_support && is_acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08008826 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05308827 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08008828 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308829 } else
8830 restart_chan =
8831 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08008832 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308833 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008834 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308835 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008836 /*
8837 * SAP restart due to unsafe channel. While
8838 * restarting the SAP, make sure to clear
8839 * acs_channel, channel to reset to
8840 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308841 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008842 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308843 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008844 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308845 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
8846 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Dustin Brown05d81302018-09-11 16:49:22 -07008847 ucfg_mlme_get_sap_internal_restart(hdd_ctxt->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05308848 &value);
8849 hdd_debug("driver to start sap: %d", value);
8850 if (value)
Min Liu2fef5792018-01-19 17:59:42 +08008851 hdd_switch_sap_channel(adapter, restart_chan,
8852 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04008853 else
8854 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308855 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308856 }
8857}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05308858
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008859/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008860 * hdd_init_channel_avoidance() - Initialize channel avoidance
8861 * @hdd_ctx: HDD global context
8862 *
8863 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07008864 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008865 * down to the lower layers. Then subscribe to subsequent channel
8866 * avoidance events.
8867 *
8868 * Return: None
8869 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008870static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008871{
8872 uint16_t unsafe_channel_count;
8873 int index;
8874
Yuanyuan Liu13738502016-04-06 17:41:37 -07008875 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
8876 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008877 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08008878 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008879
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008880 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008881 hdd_ctx->unsafe_channel_count);
8882
Anurag Chouhan6d760662016-02-20 16:05:43 +05308883 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08008884 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008885
8886 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008887 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008888 hdd_ctx->unsafe_channel_list[index]);
8889
8890 }
8891
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008892}
Dustin Brown676a2322017-08-15 13:16:13 -07008893
Jeff Johnson9d295242017-08-29 14:39:48 -07008894static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008895 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008896{
8897 uint8_t restart_chan;
8898
8899 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
8900 if (!restart_chan) {
8901 hdd_alert("fail to restart SAP");
8902 return;
8903 }
8904
8905 /* SAP restart due to unsafe channel. While restarting
8906 * the SAP, make sure to clear acs_channel, channel to
8907 * reset to 0. Otherwise these settings will override
8908 * the ACS while restart.
8909 */
8910 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07008911
8912 hdd_debug("sending coex indication");
8913
8914 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
8915 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08008916 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07008917}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008918
8919int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
8920 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
8921{
8922 uint32_t size;
8923 uint16_t *unsafe_list;
8924 uint16_t chan_count;
8925
8926 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
8927 return -EINVAL;
8928
8929 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
8930 NUM_CHANNELS);
8931 if (chan_count) {
8932 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
8933 unsafe_list = qdf_mem_malloc(size);
Min Liu74a1a502018-10-10 19:59:07 +08008934 if (!unsafe_list)
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008935 return -ENOMEM;
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008936 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
8937 } else {
8938 unsafe_list = NULL;
8939 }
8940
8941 *local_unsafe_list = unsafe_list;
8942 *local_unsafe_list_count = chan_count;
8943
8944 return 0;
8945}
8946
8947bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
8948 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
8949{
8950 int i, j;
8951
8952 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
8953 return true;
8954 if (local_unsafe_list_count == 0)
8955 return false;
8956 for (i = 0; i < local_unsafe_list_count; i++) {
8957 for (j = 0; j < local_unsafe_list_count; j++)
8958 if (local_unsafe_list[i] ==
8959 hdd_ctx->unsafe_channel_list[j])
8960 break;
8961 if (j >= local_unsafe_list_count)
8962 break;
8963 }
8964 if (i >= local_unsafe_list_count) {
8965 hdd_info("unsafe chan list same");
8966 return false;
8967 }
8968
8969 return true;
8970}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008971#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008972static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008973{
8974}
Dustin Brown676a2322017-08-15 13:16:13 -07008975
Jeff Johnson9d295242017-08-29 14:39:48 -07008976static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008977 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008978{
8979 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
8980}
Yuanyuan Liu13738502016-04-06 17:41:37 -07008981#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008982
8983/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08008984 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
8985 * user space
8986 * @frame_ind: Management frame data to be informed.
8987 *
8988 * This function is used to indicate management frame to
8989 * user space
8990 *
8991 * Return: None
8992 *
8993 */
8994void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
8995{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008996 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07008997 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008998 int i;
Pragaspathi Thilagaraj28ffc042018-07-18 15:19:36 +05308999 struct ieee80211_mgmt *mgmt =
9000 (struct ieee80211_mgmt *)frame_ind->frameBuf;
Rajeev Kumard004abc2016-02-17 12:09:56 -08009001
Dustin Browne7e71d32018-05-11 16:00:08 -07009002 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9003 if (wlan_hdd_validate_context(hdd_ctx))
Rajeev Kumard004abc2016-02-17 12:09:56 -08009004 return;
9005
Pragaspathi Thilagaraj28ffc042018-07-18 15:19:36 +05309006 if (frame_ind->frame_len < ieee80211_hdrlen(mgmt->frame_control)) {
9007 hdd_err(" Invalid frame length");
9008 return;
9009 }
9010
Rajeev Kumard004abc2016-02-17 12:09:56 -08009011 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
9012 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
9013 adapter =
9014 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
9015 if (adapter)
9016 break;
9017 }
Wu Gaoa0230a62018-01-04 20:56:57 +08009018 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
9019 hdd_for_each_adapter(hdd_ctx, adapter) {
9020 if ((NULL != adapter) &&
9021 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
9022 __hdd_indicate_mgmt_frame(adapter,
9023 frame_ind->frame_len,
9024 frame_ind->frameBuf,
9025 frame_ind->frameType,
9026 frame_ind->rxChan,
9027 frame_ind->rxRssi);
9028 }
9029 }
9030 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08009031 } else {
9032 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
9033 frame_ind->sessionId);
9034 }
9035
9036 if ((NULL != adapter) &&
9037 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
9038 __hdd_indicate_mgmt_frame(adapter,
9039 frame_ind->frame_len,
9040 frame_ind->frameBuf,
9041 frame_ind->frameType,
9042 frame_ind->rxChan,
9043 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08009044}
9045
Kapil Gupta8878ad92017-02-13 11:56:04 +05309046void hdd_acs_response_timeout_handler(void *context)
9047{
9048 struct hdd_external_acs_timer_context *timer_context =
9049 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07009050 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009051 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05309052 uint8_t reason;
9053
Dustin Brown491d54b2018-03-14 12:39:11 -07009054 hdd_enter();
Kapil Gupta8878ad92017-02-13 11:56:04 +05309055 if (!timer_context) {
9056 hdd_err("invlaid timer context");
9057 return;
9058 }
9059 adapter = timer_context->adapter;
9060 reason = timer_context->reason;
9061
9062
9063 if ((!adapter) ||
9064 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
9065 hdd_err("invalid adapter or adapter has invalid magic");
9066 return;
9067 }
9068 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
9069 if (wlan_hdd_validate_context(hdd_ctx))
9070 return;
9071
9072 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
9073 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
9074 else
9075 return;
9076
9077 hdd_err("ACS timeout happened for %s reason %d",
9078 adapter->dev->name, reason);
Jeff Johnson16528362018-06-14 12:34:16 -07009079
Kapil Gupta8878ad92017-02-13 11:56:04 +05309080 switch (reason) {
9081 /* SAP init case */
9082 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
9083 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
9084 false);
9085 wlan_hdd_cfg80211_start_acs(adapter);
9086 break;
9087 /* DFS detected on current channel */
9088 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
9089 wlan_sap_update_next_channel(
9090 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
Jeff Johnson16528362018-06-14 12:34:16 -07009091 sme_update_new_channel_event(hdd_ctx->mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07009092 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05309093 break;
9094 /* LTE coex event on current channel */
9095 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
9096 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
9097 break;
9098 default:
9099 hdd_info("invalid reason for timer invoke");
9100
9101 }
9102}
9103
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009104/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009105 * hdd_override_ini_config - Override INI config
9106 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009107 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009108 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009109 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009110 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009111 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009112static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009113{
Abhinav Kumard4d6eb72018-12-04 20:30:37 +05309114 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009115
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009116 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
gaurank kathpalia97c070b2019-01-07 17:23:06 +05309117 ucfg_scan_cfg_set_dfs_chan_scan_allowed(hdd_ctx->psoc,
9118 enable_dfs_chan_scan);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009119 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009120 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009121 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009122 if (0 == enable_11d || 1 == enable_11d) {
Abhinav Kumard4d6eb72018-12-04 20:30:37 +05309123 status = ucfg_mlme_set_11d_enabled(hdd_ctx->psoc, enable_11d);
9124 if (!QDF_IS_STATUS_SUCCESS(status))
9125 hdd_err("Failed to set 11d_enable flag");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009126 }
Leo Chang11545d62016-10-17 14:53:50 -07009127
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +05309128 if (hdd_ctx->config->action_oui_enable && !ucfg_action_oui_enabled()) {
9129 hdd_ctx->config->action_oui_enable = 0;
Sourav Mohapatra58841062018-11-19 16:33:27 +05309130 hdd_err("Ignore action oui ini, since no action_oui component");
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +05309131 }
Will Huang14b120f2019-01-14 17:26:14 +08009132
9133 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
9134 hdd_override_all_ps(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009135}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009136
Ashish Kumar Dhanotiya12f68212018-09-04 22:00:14 +05309137#ifdef ENABLE_MTRACE_LOG
9138static void hdd_set_mtrace_for_each(struct hdd_context *hdd_ctx)
9139{
9140 uint8_t module_id = 0;
9141 int qdf_print_idx = -1;
9142
9143 qdf_print_idx = qdf_get_pidx();
9144 for (module_id = 0; module_id < QDF_MODULE_ID_MAX; module_id++)
9145 qdf_print_set_category_verbose(
9146 qdf_print_idx,
9147 module_id, QDF_TRACE_LEVEL_TRACE,
9148 hdd_ctx->config->enable_mtrace);
9149}
9150#else
9151static void hdd_set_mtrace_for_each(struct hdd_context *hdd_ctx)
9152{
9153}
9154
9155#endif
9156
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009157/**
9158 * hdd_set_trace_level_for_each - Set trace level for each INI config
9159 * @hdd_ctx - HDD context
9160 *
9161 * Set trace level for each module based on INI config.
9162 *
9163 * Return: None
9164 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009165static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009166{
Wu Gaobc6eaa12018-11-30 14:17:45 +08009167 hdd_qdf_trace_enable(QDF_MODULE_ID_DP, 0x7f);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05309168 hdd_qdf_trace_enable(QDF_MODULE_ID_MLME, 0xffff);
Sourav Mohapatra113685f2018-08-29 14:21:55 +05309169 hdd_qdf_trace_enable(QDF_MODULE_ID_FWOL, 0xffff);
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07009170 hdd_qdf_trace_enable(QDF_MODULE_ID_CRYPTO, 0xffff);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07009171
Ashish Kumar Dhanotiya12f68212018-09-04 22:00:14 +05309172 hdd_set_mtrace_for_each(hdd_ctx);
9173
Nirav Shah5c083da2018-08-03 13:46:02 +05309174 hdd_cfg_print_global_config(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009175}
9176
9177/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009178 * hdd_context_init() - Initialize HDD context
9179 * @hdd_ctx: HDD context.
9180 *
9181 * Initialize HDD context along with all the feature specific contexts.
9182 *
9183 * return: 0 on success and errno on failure.
9184 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009185static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009186{
9187 int ret;
9188
9189 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
9190 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
9191
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009192 init_completion(&hdd_ctx->mc_sus_event_var);
9193 init_completion(&hdd_ctx->ready_to_suspend);
9194
9195 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009196 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05309197
Dustin Brownbee82832018-07-23 10:10:51 -07009198 qdf_list_create(&hdd_ctx->hdd_adapters, 0);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009199
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009200 ret = hdd_scan_context_init(hdd_ctx);
9201 if (ret)
9202 goto list_destroy;
9203
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009204 hdd_rx_wake_lock_create(hdd_ctx);
9205
9206 ret = hdd_sap_context_init(hdd_ctx);
9207 if (ret)
9208 goto scan_destroy;
9209
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009210 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
9211
9212 hdd_init_offloaded_packets_ctx(hdd_ctx);
9213
9214 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
9215 hdd_ctx->config);
9216 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08009217 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009218
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05309219 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
9220 "monitor_mode_wakelock");
9221
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009222 return 0;
9223
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009224sap_destroy:
9225 hdd_sap_context_destroy(hdd_ctx);
9226
9227scan_destroy:
9228 hdd_scan_context_destroy(hdd_ctx);
9229 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009230list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07009231 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08009232
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009233 return ret;
9234}
9235
Dustin Brown4c663222018-10-23 14:19:36 -07009236void hdd_psoc_idle_timer_start(struct hdd_context *hdd_ctx)
9237{
9238 uint32_t timeout_ms = hdd_ctx->config->iface_change_wait_time;
9239 enum wake_lock_reason reason =
9240 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER;
9241
Rajeev Kumar7b7bb3f2018-12-20 12:09:54 -08009242 if (!timeout_ms) {
9243 hdd_info("psoc idle timer is disabled");
9244 return;
9245 }
9246
Dustin Brown4c663222018-10-23 14:19:36 -07009247 hdd_debug("Starting psoc idle timer");
9248 qdf_sched_delayed_work(&hdd_ctx->psoc_idle_timeout_work, timeout_ms);
9249 hdd_prevent_suspend_timeout(timeout_ms, reason);
9250}
9251
9252void hdd_psoc_idle_timer_stop(struct hdd_context *hdd_ctx)
9253{
9254 qdf_cancel_delayed_work(&hdd_ctx->psoc_idle_timeout_work);
9255 hdd_debug("Stopped psoc idle timer");
9256}
9257
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009258/**
Dustin Brown3ecc8782018-09-19 16:37:13 -07009259 * hdd_psoc_idle_shutdown() - perform an idle shutdown on the given psoc
9260 * @hdd_ctx: the hdd context which should be shutdown
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309261 *
Dustin Brown3ecc8782018-09-19 16:37:13 -07009262 * When no interfaces are "up" on a psoc, an idle shutdown timer is started.
9263 * If no interfaces are brought up before the timer expires, we do an
9264 * "idle shutdown," cutting power to the physical SoC to save power. This is
9265 * done completely transparently from the perspective of userspace.
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309266 *
Dustin Brown3ecc8782018-09-19 16:37:13 -07009267 * Return: None
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309268 */
Dustin Brown3ecc8782018-09-19 16:37:13 -07009269static void hdd_psoc_idle_shutdown(struct hdd_context *hdd_ctx)
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309270{
Dustin Browncfcb5762019-01-31 15:43:45 -08009271 struct hdd_psoc_sync *psoc_sync;
9272 int errno;
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309273
Dustin Brown491d54b2018-03-14 12:39:11 -07009274 hdd_enter();
Dustin Brown3ecc8782018-09-19 16:37:13 -07009275
Dustin Browncfcb5762019-01-31 15:43:45 -08009276 errno = hdd_psoc_sync_trans_start(hdd_ctx->parent_dev, &psoc_sync);
9277 if (errno) {
9278 hdd_info("psoc busy, abort idle shutdown; errno:%d", errno);
9279 goto exit;
Dustin Brown3ecc8782018-09-19 16:37:13 -07009280 }
9281
Dustin Browncfcb5762019-01-31 15:43:45 -08009282 hdd_psoc_sync_wait_for_ops(psoc_sync);
9283
Dustin Brown3ecc8782018-09-19 16:37:13 -07009284 QDF_BUG(!hdd_wlan_stop_modules(hdd_ctx, false));
9285
Dustin Browncfcb5762019-01-31 15:43:45 -08009286 hdd_psoc_sync_trans_stop(psoc_sync);
Dustin Brown3ecc8782018-09-19 16:37:13 -07009287
Dustin Browncfcb5762019-01-31 15:43:45 -08009288exit:
Dustin Browne74003f2018-03-14 12:51:58 -07009289 hdd_exit();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309290}
9291
Dustin Brown3ecc8782018-09-19 16:37:13 -07009292int hdd_psoc_idle_restart(struct hdd_context *hdd_ctx)
9293{
Dustin Brown693b5352019-01-17 10:00:31 -08009294 QDF_BUG(rtnl_is_locked());
Dustin Brown3ecc8782018-09-19 16:37:13 -07009295
Dustin Browncfcb5762019-01-31 15:43:45 -08009296 return hdd_wlan_start_modules(hdd_ctx, false);
Dustin Brown3ecc8782018-09-19 16:37:13 -07009297}
9298
9299/**
9300 * hdd_psoc_idle_timeout_callback() - Handler for psoc idle timeout
9301 * @priv: pointer to hdd context
9302 *
9303 * Return: None
9304 */
9305static void hdd_psoc_idle_timeout_callback(void *priv)
9306{
9307 struct hdd_context *hdd_ctx = priv;
9308
9309 if (wlan_hdd_validate_context(hdd_ctx))
9310 return;
9311
9312 hdd_debug("Psoc idle timeout elapsed; starting psoc shutdown");
9313 hdd_psoc_idle_shutdown(hdd_ctx);
9314}
9315
Nirav Shaheb017be2018-02-15 11:20:58 +05309316#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9317static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
9318{
9319 wlan_logging_set_log_to_console(hdd_ctx->config->
9320 wlan_logging_to_console);
9321 wlan_logging_set_active(hdd_ctx->config->wlan_logging_enable);
9322}
9323#else
9324static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
9325{ }
9326#endif
9327
Dundi Raviteja8e338282018-09-25 17:16:04 +05309328#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9329static void hdd_init_wlan_logging_params(struct hdd_config *config,
9330 struct wlan_objmgr_psoc *psoc)
9331{
9332 config->wlan_logging_enable = cfg_get(psoc, CFG_WLAN_LOGGING_SUPPORT);
9333
9334 config->wlan_logging_to_console =
9335 cfg_get(psoc, CFG_WLAN_LOGGING_CONSOLE_SUPPORT);
9336}
9337#else
9338static void hdd_init_wlan_logging_params(struct hdd_config *config,
9339 struct wlan_objmgr_psoc *psoc)
9340{
9341}
9342#endif
9343
9344#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9345static void hdd_init_wlan_auto_shutdown(struct hdd_config *config,
9346 struct wlan_objmgr_psoc *psoc)
9347{
9348 config->wlan_auto_shutdown = cfg_get(psoc, CFG_WLAN_AUTO_SHUTDOWN);
9349}
9350#else
9351static void hdd_init_wlan_auto_shutdown(struct hdd_config *config,
9352 struct wlan_objmgr_psoc *psoc)
9353{
9354}
9355#endif
9356
9357#ifndef REMOVE_PKT_LOG
9358static void hdd_init_packet_log(struct hdd_config *config,
9359 struct wlan_objmgr_psoc *psoc)
9360{
9361 config->enable_packet_log = cfg_get(psoc, CFG_ENABLE_PACKET_LOG);
9362}
9363#else
9364static void hdd_init_packet_log(struct hdd_config *config,
9365 struct wlan_objmgr_psoc *psoc)
9366{
9367}
9368#endif
9369
Sandeep Puligilla43b6d1a2018-12-03 09:16:13 -08009370#ifdef ENABLE_MTRACE_LOG
9371static void hdd_init_mtrace_log(struct hdd_config *config,
9372 struct wlan_objmgr_psoc *psoc)
9373{
9374 config->enable_mtrace = cfg_get(psoc, CFG_ENABLE_MTRACE);
9375}
9376#else
9377static void hdd_init_mtrace_log(struct hdd_config *config,
9378 struct wlan_objmgr_psoc *psoc)
9379{
9380}
9381#endif
9382
Sourav Mohapatra0dfe5552018-11-16 11:29:54 +05309383#ifdef FEATURE_RUNTIME_PM
9384static void hdd_init_runtime_pm(struct hdd_config *config,
9385 struct wlan_objmgr_psoc *psoc)
9386{
9387 config->runtime_pm = cfg_get(psoc, CFG_ENABLE_RUNTIME_PM);
9388}
9389#else
9390static void hdd_init_runtime_pm(struct hdd_config *config,
9391 struct wlan_objmgr_psoc *psoc)
9392
9393{
9394}
9395#endif
9396
9397#ifdef FEATURE_WLAN_DYNAMIC_CVM
9398static void hdd_init_vc_mode_cfg_bitmap(struct hdd_config *config,
9399 struct wlan_objmgr_psoc *psoc)
9400{
9401 config->vc_mode_cfg_bitmap = cfg_get(psoc, CFG_VC_MODE_BITMAP);
9402}
9403#else
9404static void hdd_init_vc_mode_cfg_bitmap(struct hdd_config *config,
9405 struct wlan_objmgr_psoc *psoc)
9406{
9407}
9408#endif
9409
Dundi Raviteja8e338282018-09-25 17:16:04 +05309410/**
9411 * hdd_cfg_params_init() - Initialize hdd params in hdd_config strucuture
9412 * @hdd_ctx - Pointer to HDD context
9413 *
9414 * Return: None
9415 */
9416static void hdd_cfg_params_init(struct hdd_context *hdd_ctx)
9417{
9418 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
9419 struct hdd_config *config = hdd_ctx->config;
9420
9421 if (!psoc) {
9422 hdd_err("Invalid psoc");
9423 return;
9424 }
9425
9426 if (!config) {
9427 hdd_err("Invalid hdd config");
9428 return;
9429 }
9430
9431 config->bug_on_reinit_failure = cfg_get(psoc,
9432 CFG_BUG_ON_REINIT_FAILURE);
9433
9434 config->is_ramdump_enabled = cfg_get(psoc,
9435 CFG_ENABLE_RAMDUMP_COLLECTION);
9436
9437 config->iface_change_wait_time = cfg_get(psoc,
9438 CFG_INTERFACE_CHANGE_WAIT);
9439
9440 config->multicast_host_fw_msgs = cfg_get(psoc,
9441 CFG_MULTICAST_HOST_FW_MSGS);
9442
9443 config->private_wext_control = cfg_get(psoc, CFG_PRIVATE_WEXT_CONTROL);
9444 config->timer_multiplier = cfg_get(psoc, CFG_TIMER_MULTIPLIER);
9445 config->enablefwprint = cfg_get(psoc, CFG_ENABLE_FW_UART_PRINT);
9446 config->enable_fw_log = cfg_get(psoc, CFG_ENABLE_FW_LOG);
Vignesh Viswanathana0358ff2018-11-27 09:53:07 +05309447 config->operating_channel = cfg_get(psoc, CFG_OPERATING_CHANNEL);
9448 config->num_vdevs = cfg_get(psoc, CFG_NUM_VDEV_ENABLE);
Vignesh Viswanathana0358ff2018-11-27 09:53:07 +05309449 qdf_str_lcopy(config->enable_concurrent_sta,
9450 cfg_get(psoc, CFG_ENABLE_CONCURRENT_STA),
9451 CFG_CONCURRENT_IFACE_MAX_LEN);
9452 qdf_str_lcopy(config->dbs_scan_selection,
9453 cfg_get(psoc, CFG_DBS_SCAN_SELECTION),
9454 CFG_DBS_SCAN_PARAM_LENGTH);
Sourav Mohapatra0dfe5552018-11-16 11:29:54 +05309455 config->inform_bss_rssi_raw = cfg_get(psoc, CFG_INFORM_BSS_RSSI_RAW);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05309456 config->mac_provision = cfg_get(psoc, CFG_ENABLE_MAC_PROVISION);
9457 config->provisioned_intf_pool =
9458 cfg_get(psoc, CFG_PROVISION_INTERFACE_POOL);
9459 config->derived_intf_pool = cfg_get(psoc, CFG_DERIVED_INTERFACE_POOL);
Sourav Mohapatra58841062018-11-19 16:33:27 +05309460 config->action_oui_enable = cfg_get(psoc, CFG_ENABLE_ACTION_OUI);
Sandeep Puligilladc6d68a2019-01-04 16:57:12 -08009461 config->advertiseConcurrentOperation =
9462 cfg_get(psoc,
9463 CFG_ADVERTISE_CONCURRENT_OPERATION);
Sourav Mohapatra58841062018-11-19 16:33:27 +05309464 qdf_str_lcopy(config->action_oui_str[0],
9465 cfg_get(psoc, CFG_ACTION_OUI_CONNECT_1X1),
9466 ACTION_OUI_MAX_STR_LEN);
9467 qdf_str_lcopy(config->action_oui_str[1],
9468 cfg_get(psoc, CFG_ACTION_OUI_ITO_EXTENSION),
9469 ACTION_OUI_MAX_STR_LEN);
9470 qdf_str_lcopy(config->action_oui_str[2],
9471 cfg_get(psoc, CFG_ACTION_OUI_CCKM_1X1),
9472 ACTION_OUI_MAX_STR_LEN);
9473 qdf_str_lcopy(config->action_oui_str[3],
9474 cfg_get(psoc, CFG_ACTION_OUI_ITO_ALTERNATE),
9475 ACTION_OUI_MAX_STR_LEN);
9476 qdf_str_lcopy(config->action_oui_str[4],
9477 cfg_get(psoc, CFG_ACTION_OUI_SWITCH_TO_11N_MODE),
9478 ACTION_OUI_MAX_STR_LEN);
9479 qdf_str_lcopy(config->action_oui_str[5],
9480 cfg_get(psoc,
9481 CFG_ACTION_OUI_CONNECT_1X1_WITH_1_CHAIN),
9482 ACTION_OUI_MAX_STR_LEN);
Rajeev Kumar Sirasanagandlad7987f12018-12-08 23:24:04 +05309483 qdf_str_lcopy(config->action_oui_str[6],
9484 cfg_get(psoc,
9485 CFG_ACTION_OUI_DISABLE_AGGRESSIVE_TX),
9486 ACTION_OUI_MAX_STR_LEN);
Sourav Mohapatra9e014cf2018-12-11 09:39:33 +05309487 config->enable_rtt_support = cfg_get(psoc, CFG_ENABLE_RTT_SUPPORT);
Sandeep Puligillaefeb4a92019-01-08 00:06:51 -08009488 config->is_unit_test_framework_enabled =
9489 cfg_get(psoc, CFG_ENABLE_UNIT_TEST_FRAMEWORK);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309490
Sourav Mohapatra0dfe5552018-11-16 11:29:54 +05309491 hdd_init_vc_mode_cfg_bitmap(config, psoc);
9492 hdd_init_runtime_pm(config, psoc);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309493 hdd_init_wlan_auto_shutdown(config, psoc);
9494 hdd_init_wlan_logging_params(config, psoc);
9495 hdd_init_packet_log(config, psoc);
Sandeep Puligilla43b6d1a2018-12-03 09:16:13 -08009496 hdd_init_mtrace_log(config, psoc);
jitiphil869b9f72018-09-25 17:14:01 +05309497 hdd_dp_cfg_update(psoc, hdd_ctx);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309498}
9499
Dustin Brown623e7e32018-09-05 14:27:50 -07009500struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009501{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309502 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009503 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009504 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009505
Dustin Brown491d54b2018-03-14 12:39:11 -07009506 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009507
Dustin Brown92bd8382018-10-31 15:49:46 -07009508 hdd_ctx = hdd_cfg80211_wiphy_alloc();
9509 if (!hdd_ctx) {
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009510 ret = -ENOMEM;
9511 goto err_out;
9512 }
9513
Dustin Brown4c663222018-10-23 14:19:36 -07009514 qdf_create_delayed_work(&hdd_ctx->psoc_idle_timeout_work,
Dustin Brown3ecc8782018-09-19 16:37:13 -07009515 hdd_psoc_idle_timeout_callback,
Dustin Brown4c663222018-10-23 14:19:36 -07009516 hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309517
9518 mutex_init(&hdd_ctx->iface_change_lock);
9519
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009520 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05309521 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009522
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309523 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Min Liu74a1a502018-10-10 19:59:07 +08009524 if (!hdd_ctx->config) {
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009525 ret = -ENOMEM;
9526 goto err_free_hdd_context;
9527 }
9528
9529 /* Read and parse the qcom_cfg.ini file */
9530 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309531 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309532 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009533 WLAN_INI_FILE);
9534 ret = -EINVAL;
9535 goto err_free_config;
9536 }
9537
Dustin Brown84f46ea2018-02-15 11:57:36 -08009538 status = cfg_parse(WLAN_INI_FILE);
9539 if (QDF_IS_STATUS_ERROR(status))
9540 hdd_err("Failed to parse cfg %s; status:%d\n",
9541 WLAN_INI_FILE, status);
9542
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309543 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx, DEFAULT_PSOC_ID);
9544 if (ret) {
Dundi Raviteja8e338282018-09-25 17:16:04 +05309545 QDF_DEBUG_PANIC("Psoc creation fails!");
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309546 goto err_free_config;
9547 }
9548
Dundi Raviteja8e338282018-09-25 17:16:04 +05309549 hdd_cfg_params_init(hdd_ctx);
9550
Dustin Brown7f939932017-05-18 15:02:17 -07009551 hdd_debug("setting timer multiplier: %u",
9552 hdd_ctx->config->timer_multiplier);
9553 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
9554
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309555 cds_set_fatal_event(cfg_get(hdd_ctx->psoc,
9556 CFG_ENABLE_FATAL_EVENT_TRIGGER));
Abhishek Singh5ea86532016-04-27 14:10:53 +05309557
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009558 hdd_override_ini_config(hdd_ctx);
9559
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009560 ret = hdd_context_init(hdd_ctx);
9561
9562 if (ret)
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309563 goto err_hdd_objmgr_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009564
Anurag Chouhan6d760662016-02-20 16:05:43 +05309565 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009566 goto skip_multicast_logging;
9567
9568 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
9569
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07009570 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
9571 if (ret)
9572 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05309573
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009574 ret = hdd_init_netlink_services(hdd_ctx);
9575 if (ret)
9576 goto err_deinit_txrx_histogram;
9577
Nirav Shaheb017be2018-02-15 11:20:58 +05309578 hdd_set_wlan_logging(hdd_ctx);
Nirav Shahed34b212016-04-25 10:59:16 +05309579
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009580skip_multicast_logging:
9581 hdd_set_trace_level_for_each(hdd_ctx);
9582
Rajeev Kumar493a31b2017-09-29 14:01:24 -07009583 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
9584
Dustin Browne74003f2018-03-14 12:51:58 -07009585 hdd_exit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07009586
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009587 return hdd_ctx;
9588
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009589err_deinit_txrx_histogram:
9590 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
9591
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07009592err_deinit_hdd_context:
9593 hdd_context_deinit(hdd_ctx);
9594
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309595err_hdd_objmgr_destroy:
9596 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9597
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009598err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309599 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009600
9601err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309602 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08009603 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009604
9605err_out:
9606 return ERR_PTR(ret);
9607}
9608
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009609/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309610 * hdd_start_station_adapter()- Start the Station Adapter
9611 * @adapter: HDD adapter
9612 *
9613 * This function initializes the adapter for the station mode.
9614 *
9615 * Return: 0 on success or errno on failure.
9616 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009617int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309618{
9619 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08009620 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309621
Dustin Brownfdf17c12018-03-14 12:55:34 -07009622 hdd_enter_dev(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08009623 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9624 hdd_err("session is already opened, %d",
9625 adapter->session_id);
9626 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9627 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309628
Krunal Sonib51eec72017-11-20 21:53:01 -08009629 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
9630 if (ret) {
9631 hdd_err("failed to create vdev: %d", ret);
9632 return ret;
9633 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309634 status = hdd_init_station_mode(adapter);
9635
9636 if (QDF_STATUS_SUCCESS != status) {
9637 hdd_err("Error Initializing station mode: %d", status);
9638 return qdf_status_to_os_return(status);
9639 }
9640
Arun Khandavallifae92942016-08-01 13:31:08 +05309641 hdd_register_tx_flow_control(adapter,
9642 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009643 hdd_tx_resume_cb,
9644 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309645
Dustin Browne74003f2018-03-14 12:51:58 -07009646 hdd_exit();
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05309647
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309648 return 0;
9649}
9650
9651/**
9652 * hdd_start_ap_adapter()- Start AP Adapter
9653 * @adapter: HDD adapter
9654 *
9655 * This function initializes the adapter for the AP mode.
9656 *
9657 * Return: 0 on success errno on failure.
9658 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009659int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309660{
9661 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009662 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08009663 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08009664 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arif Hussainbd5194c2018-11-27 19:01:15 -08009665 uint32_t fine_time_meas_cap = 0;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309666
Dustin Brown491d54b2018-03-14 12:39:11 -07009667 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309668
Krunal Sonib51eec72017-11-20 21:53:01 -08009669 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9670 hdd_err("session is already opened, %d",
9671 adapter->session_id);
9672 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9673 }
9674 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009675 * In SSR case no need to create new sap context.
9676 * Otherwise create sap context first and then create
9677 * vdev as while creating the vdev, driver needs to
9678 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08009679 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009680 if (adapter->session.ap.sap_context) {
9681 is_ssr = true;
9682 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08009683 hdd_err("sap creation failed");
9684 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
9685 }
9686
9687 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
9688 adapter->session.ap.sap_context);
9689 if (ret) {
9690 hdd_err("failed to create vdev, status:%d", ret);
9691 hdd_sap_destroy_ctx(adapter);
9692 return ret;
9693 }
Naveen Rawat1af09392018-01-03 17:28:21 -08009694
Arif Hussainbd5194c2018-11-27 19:01:15 -08009695 if (adapter->device_mode == QDF_SAP_MODE) {
9696 ucfg_mlme_get_fine_time_meas_cap(hdd_ctx->psoc,
9697 &fine_time_meas_cap);
Naveen Rawat1af09392018-01-03 17:28:21 -08009698 sme_cli_set_command(adapter->session_id,
9699 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
Arif Hussainbd5194c2018-11-27 19:01:15 -08009700 (bool)(fine_time_meas_cap & WMI_FW_AP_RTT_RESPR),
Naveen Rawat1af09392018-01-03 17:28:21 -08009701 VDEV_CMD);
Arif Hussainbd5194c2018-11-27 19:01:15 -08009702 }
Naveen Rawat1af09392018-01-03 17:28:21 -08009703
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009704 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309705
9706 if (QDF_STATUS_SUCCESS != status) {
9707 hdd_err("Error Initializing the AP mode: %d", status);
9708 return qdf_status_to_os_return(status);
9709 }
9710
Arun Khandavallifae92942016-08-01 13:31:08 +05309711 hdd_register_tx_flow_control(adapter,
9712 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009713 hdd_softap_tx_resume_cb,
9714 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309715
Dustin Browne74003f2018-03-14 12:51:58 -07009716 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309717 return 0;
9718}
9719
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309720#ifdef QCA_LL_TX_FLOW_CONTROL_V2
9721/**
9722 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
9723 * @cds_cfg: CDS Configuration
9724 * @hdd_ctx: Pointer to hdd context
9725 *
9726 * Return: none
9727 */
9728static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9729 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009730 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309731{
9732 cds_cfg->tx_flow_stop_queue_th =
jitiphil47c3d9a2018-11-08 18:30:55 +05309733 cfg_get(hdd_ctx->psoc, CFG_DP_TX_FLOW_STOP_QUEUE_TH);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309734 cds_cfg->tx_flow_start_queue_offset =
jitiphil47c3d9a2018-11-08 18:30:55 +05309735 cfg_get(hdd_ctx->psoc, CFG_DP_TX_FLOW_START_QUEUE_OFFSET);
Mohit Khanna70322002018-05-15 19:21:32 -07009736 /* configuration for DP RX Threads */
9737 cds_cfg->enable_dp_rx_threads = hdd_ctx->enable_dp_rx_threads;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309738}
9739#else
9740static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9741 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009742 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309743{
9744}
9745#endif
9746
9747#ifdef FEATURE_WLAN_RA_FILTERING
9748/**
9749 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
9750 * @cds_cfg: CDS Configuration
9751 * @hdd_ctx: Pointer to hdd context
9752 *
9753 * Return: none
9754 */
Anand Kumar3b92a912016-12-05 12:01:26 +05309755static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009756 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309757{
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05309758 bool is_rate_limit_enabled;
9759 QDF_STATUS status;
9760
9761 status = ucfg_fwol_get_is_rate_limit_enabled(hdd_ctx->psoc,
9762 &is_rate_limit_enabled);
9763 if (QDF_IS_STATUS_ERROR(status))
9764 return;
9765
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05309766 cds_cfg->is_ra_ratelimit_enabled = is_rate_limit_enabled;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309767}
9768#else
Anand Kumar3b92a912016-12-05 12:01:26 +05309769static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009770 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309771{
9772}
9773#endif
9774
9775/**
9776 * hdd_update_cds_config() - API to update cds configuration parameters
9777 * @hdd_ctx: HDD Context
9778 *
9779 * Return: 0 for Success, errno on failure
9780 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009781static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309782{
9783 struct cds_config_info *cds_cfg;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309784 int value;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309785 uint8_t band_capability;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309786 uint8_t ito_repeat_count;
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309787 bool crash_inject;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309788 bool self_recovery;
9789 bool fw_timeout_crash;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309790 QDF_STATUS status;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309791
Min Liu74a1a502018-10-10 19:59:07 +08009792 cds_cfg = qdf_mem_malloc(sizeof(*cds_cfg));
9793 if (!cds_cfg)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309794 return -ENOMEM;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309795
Srinivas Girigowda35b00312017-06-27 21:52:03 -07009796 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Bala Venkatesh46e29032018-11-14 18:24:55 +05309797 ucfg_mlme_get_sap_max_modulated_dtim(hdd_ctx->psoc,
9798 &cds_cfg->sta_maxlimod_dtim);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309799
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309800 status = ucfg_mlme_get_crash_inject(hdd_ctx->psoc, &crash_inject);
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309801 if (QDF_IS_STATUS_ERROR(status)) {
9802 hdd_err("Failed to get crash inject ini config");
9803 goto exit;
9804 }
9805
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309806 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
9807 if (QDF_IS_STATUS_ERROR(status)) {
9808 hdd_err("Failed to get self recovery ini config");
9809 goto exit;
9810 }
9811
9812 status = ucfg_mlme_get_fw_timeout_crash(hdd_ctx->psoc,
9813 &fw_timeout_crash);
9814 if (QDF_IS_STATUS_ERROR(status)) {
9815 hdd_err("Failed to get fw timeout crash ini config");
9816 goto exit;
9817 }
9818
9819 status = ucfg_mlme_get_ito_repeat_count(hdd_ctx->psoc,
9820 &ito_repeat_count);
9821 if (QDF_IS_STATUS_ERROR(status)) {
9822 hdd_err("Failed to get ITO repeat count ini config");
9823 goto exit;
9824 }
9825
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309826 cds_cfg->force_target_assert_enabled = crash_inject;
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05309827
Dustin Brown05d81302018-09-11 16:49:22 -07009828 ucfg_mlme_get_sap_max_offload_peers(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309829 cds_cfg->ap_maxoffload_peers = value;
Dustin Brown05d81302018-09-11 16:49:22 -07009830 ucfg_mlme_get_sap_max_offload_reorder_buffs(hdd_ctx->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309831 &value);
9832 cds_cfg->ap_maxoffload_reorderbuffs = value;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309833
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309834 cds_cfg->reorder_offload =
jitiphil47c3d9a2018-11-08 18:30:55 +05309835 cfg_get(hdd_ctx->psoc, CFG_DP_REORDER_OFFLOAD_SUPPORT);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309836
9837 /* IPA micro controller data path offload resource config item */
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05309838 cds_cfg->uc_offload_enabled = ucfg_ipa_uc_is_enabled();
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309839
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07009840 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Dustin Brown05d81302018-09-11 16:49:22 -07009841 ucfg_mlme_get_sap_max_peers(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309842 cds_cfg->max_station = value;
Naveen Rawat64e477e2016-05-20 10:34:56 -07009843 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07009844 cds_cfg->max_msdus_per_rxinorderind =
jitiphil8e15ea62018-11-16 18:05:34 +05309845 cfg_get(hdd_ctx->psoc, CFG_DP_MAX_MSDUS_PER_RXIND);
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309846 cds_cfg->self_recovery_enabled = self_recovery;
9847 cds_cfg->fw_timeout_crash = fw_timeout_crash;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309848
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309849 cds_cfg->ito_repeat_count = ito_repeat_count;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309850
9851 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
9852 if (QDF_IS_STATUS_ERROR(status))
9853 goto exit;
9854
9855 cds_cfg->bandcapability = band_capability;
Rachit Kankane0106e382018-05-16 18:59:28 +05309856 cds_cfg->num_vdevs = hdd_ctx->config->num_vdevs;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309857
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309858 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
9859 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07009860 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309861 cds_init_ini_config(cds_cfg);
9862 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309863
9864exit:
9865 qdf_mem_free(cds_cfg);
9866 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309867}
9868
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009869/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009870 * hdd_update_user_config() - API to update user configuration
9871 * parameters to obj mgr which are used by multiple components
9872 * @hdd_ctx: HDD Context
9873 *
9874 * Return: 0 for Success, errno on failure
9875 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009876static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009877{
9878 struct wlan_objmgr_psoc_user_config *user_config;
Wu Gaoe5689792018-07-05 19:20:13 +08009879 bool skip_dfs_in_p2p_search = false;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309880 uint8_t band_capability;
9881 QDF_STATUS status;
Abhinav Kumard4d6eb72018-12-04 20:30:37 +05309882 bool value = false;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309883
9884 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
9885 if (QDF_IS_STATUS_ERROR(status))
9886 return -EIO;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009887
9888 user_config = qdf_mem_malloc(sizeof(*user_config));
Min Liu74a1a502018-10-10 19:59:07 +08009889 if (!user_config)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009890 return -ENOMEM;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009891
9892 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
Abhinav Kumard4d6eb72018-12-04 20:30:37 +05309893 status = ucfg_mlme_is_11d_enabled(hdd_ctx->psoc, &value);
9894 if (!QDF_IS_STATUS_SUCCESS(status))
9895 hdd_err("Invalid 11d_enable flag");
9896 user_config->is_11d_support_enabled = value;
9897
9898 value = false;
9899 status = ucfg_mlme_is_11h_enabled(hdd_ctx->psoc, &value);
9900 if (!QDF_IS_STATUS_SUCCESS(status))
9901 hdd_err("Invalid 11h_enable flag");
9902 user_config->is_11h_support_enabled = value;
Dustin Brown1dbefe62018-09-11 16:32:03 -07009903 cfg_p2p_get_skip_dfs_channel_p2p_search(hdd_ctx->psoc,
Wu Gaoe5689792018-07-05 19:20:13 +08009904 &skip_dfs_in_p2p_search);
9905 user_config->skip_dfs_chnl_in_p2p_search = skip_dfs_in_p2p_search;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309906 user_config->band_capability = band_capability;
Dustin Brown1dbefe62018-09-11 16:32:03 -07009907 wlan_objmgr_psoc_set_user_config(hdd_ctx->psoc, user_config);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009908
9909 qdf_mem_free(user_config);
9910 return 0;
9911}
9912
9913/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009914 * hdd_init_thermal_info - Initialize thermal level
9915 * @hdd_ctx: HDD context
9916 *
9917 * Initialize thermal level at SME layer and set the thermal level callback
9918 * which would be called when a configured thermal threshold is hit.
9919 *
9920 * Return: 0 on success and errno on failure
9921 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009922static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009923{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309924 QDF_STATUS status;
Manikandan Mohan9045e2e2018-11-26 16:44:19 -08009925 mac_handle_t mac_handle = hdd_ctx->mac_handle;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009926
Manikandan Mohan9045e2e2018-11-26 16:44:19 -08009927 status = sme_init_thermal_info(mac_handle);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009928
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309929 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05309930 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009931
Jeff Johnson16528362018-06-14 12:34:16 -07009932 sme_add_set_thermal_level_callback(mac_handle,
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009933 hdd_set_thermal_level_cb);
9934
9935 return 0;
9936
9937}
9938
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009939#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
9940/**
9941 * hdd_hold_rtnl_lock - Hold RTNL lock
9942 *
9943 * Hold RTNL lock
9944 *
9945 * Return: True if held and false otherwise
9946 */
9947static inline bool hdd_hold_rtnl_lock(void)
9948{
9949 rtnl_lock();
9950 return true;
9951}
9952
9953/**
9954 * hdd_release_rtnl_lock - Release RTNL lock
9955 *
9956 * Release RTNL lock
9957 *
9958 * Return: None
9959 */
9960static inline void hdd_release_rtnl_lock(void)
9961{
9962 rtnl_unlock();
9963}
9964#else
9965static inline bool hdd_hold_rtnl_lock(void) { return false; }
9966static inline void hdd_release_rtnl_lock(void) { }
9967#endif
9968
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009969#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009970
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309971/* MAX iwpriv command support */
9972#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309973#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309974#define MAX_PKTLOG_SIZE 16
9975
9976/**
9977 * hdd_pktlog_set_buff_size() - set pktlog buffer size
9978 * @hdd_ctx: hdd context
9979 * @set_value2: pktlog buffer size value
9980 *
9981 *
9982 * Return: 0 for success or error.
9983 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009984static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309985{
9986 struct sir_wifi_start_log start_log = { 0 };
9987 QDF_STATUS status;
9988
9989 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9990 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9991 start_log.ini_triggered = cds_is_packet_log_enabled();
9992 start_log.user_triggered = 1;
9993 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309994 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309995
Jeff Johnson16528362018-06-14 12:34:16 -07009996 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309997 if (!QDF_IS_STATUS_SUCCESS(status)) {
9998 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009999 hdd_exit();
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010000 return -EINVAL;
10001 }
10002
10003 return 0;
10004}
10005
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010006/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010007 * hdd_pktlog_clear_buff() - clear pktlog buffer
10008 * @hdd_ctx: hdd context
10009 *
10010 * Return: 0 for success or error.
10011 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010012static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010013{
10014 struct sir_wifi_start_log start_log;
10015 QDF_STATUS status;
10016
10017 start_log.ring_id = RING_ID_PER_PACKET_STATS;
10018 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
10019 start_log.ini_triggered = cds_is_packet_log_enabled();
10020 start_log.user_triggered = 1;
10021 start_log.size = 0;
10022 start_log.is_pktlog_buff_clear = true;
10023
Jeff Johnson16528362018-06-14 12:34:16 -070010024 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010025 if (!QDF_IS_STATUS_SUCCESS(status)) {
10026 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -070010027 hdd_exit();
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010028 return -EINVAL;
10029 }
10030
10031 return 0;
10032}
10033
10034
10035/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010036 * hdd_process_pktlog_command() - process pktlog command
10037 * @hdd_ctx: hdd context
10038 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010039 * @set_value2: pktlog buffer size value
10040 *
10041 * This function process pktlog command.
10042 * set_value2 only matters when set_value is 3 (set buff size)
10043 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010044 *
10045 * Return: 0 for success or error.
10046 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010047int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010048 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010049{
10050 int ret;
10051 bool enable;
10052 uint8_t user_triggered = 0;
10053
10054 ret = wlan_hdd_validate_context(hdd_ctx);
10055 if (0 != ret)
10056 return ret;
10057
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010058 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010059
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010060 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010061 hdd_err("invalid pktlog value %d", set_value);
10062 return -EINVAL;
10063 }
10064
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010065 if (set_value == PKTLOG_SET_BUFF_SIZE) {
10066 if (set_value2 <= 0) {
10067 hdd_err("invalid pktlog size %d", set_value2);
10068 return -EINVAL;
10069 } else if (set_value2 > MAX_PKTLOG_SIZE) {
10070 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
10071 return -EINVAL;
10072 }
10073 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010074 } else if (set_value == PKTLOG_CLEAR_BUFF) {
10075 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010076 }
10077
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010078 /*
10079 * set_value = 0 then disable packetlog
10080 * set_value = 1 enable packetlog forcefully
10081 * set_vlaue = 2 then disable packetlog if disabled through ini or
10082 * enable packetlog with AUTO type.
10083 */
10084 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
10085 true : false;
10086
10087 if (1 == set_value) {
10088 enable = true;
10089 user_triggered = 1;
10090 }
10091
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010092 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010093}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010094
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010095/**
10096 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
10097 * @hdd_ctx: HDD context
10098 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010099 * @user_triggered: triggered through iwpriv
10100 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010101 *
10102 * Return: 0 on success; error number otherwise
10103 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010104int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010105 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010106{
10107 struct sir_wifi_start_log start_log;
10108 QDF_STATUS status;
10109
10110 start_log.ring_id = RING_ID_PER_PACKET_STATS;
10111 start_log.verbose_level =
10112 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010113 start_log.ini_triggered = cds_is_packet_log_enabled();
10114 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010115 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010116 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +053010117 /*
10118 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
10119 * commands. Host uses this flag to decide whether to send pktlog
10120 * disable command to fw without sending pktlog enable command
10121 * previously. For eg, If vendor sends pktlog disable command without
10122 * sending pktlog enable command, then host discards the packet
10123 * but for iwpriv command, host will send it to fw.
10124 */
10125 start_log.is_iwpriv_command = 1;
Jeff Johnson16528362018-06-14 12:34:16 -070010126 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010127 if (!QDF_IS_STATUS_SUCCESS(status)) {
10128 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -070010129 hdd_exit();
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010130 return -EINVAL;
10131 }
10132
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010133 if (enable == true)
10134 hdd_ctx->is_pktlog_enabled = 1;
10135 else
10136 hdd_ctx->is_pktlog_enabled = 0;
10137
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010138 return 0;
10139}
10140#endif /* REMOVE_PKT_LOG */
10141
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010142void hdd_free_mac_address_lists(struct hdd_context *hdd_ctx)
10143{
10144 hdd_debug("Resetting MAC address lists");
hangtian127c9532019-01-12 13:29:07 +080010145 qdf_mem_zero(hdd_ctx->provisioned_mac_addr,
10146 sizeof(hdd_ctx->provisioned_mac_addr));
10147 qdf_mem_zero(hdd_ctx->derived_mac_addr,
10148 sizeof(hdd_ctx->derived_mac_addr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010149 hdd_ctx->num_provisioned_addr = 0;
10150 hdd_ctx->num_derived_addr = 0;
10151 hdd_ctx->provisioned_intf_addr_mask = 0;
10152 hdd_ctx->derived_intf_addr_mask = 0;
10153}
10154
Komal Seelam92fff912016-03-24 11:51:41 +053010155/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010156 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
10157 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +053010158 * @dev: Device Pointer
10159 * @num: Number of Valid Mac address
10160 *
10161 * Return: Pointer to MAC address buffer
10162 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010163static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
10164 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +053010165{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010166 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +053010167}
Komal Seelam92fff912016-03-24 11:51:41 +053010168
10169/**
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010170 * hdd_get_platform_wlan_derived_mac_buff() - API to query platform driver
10171 * for derived MAC address
10172 * @dev: Device Pointer
10173 * @num: Number of Valid Mac address
10174 *
10175 * Return: Pointer to MAC address buffer
10176 */
10177static uint8_t *hdd_get_platform_wlan_derived_mac_buff(struct device *dev,
10178 uint32_t *num)
10179{
10180 return pld_get_wlan_derived_mac_address(dev, num);
10181}
10182
10183/**
Komal Seelam92fff912016-03-24 11:51:41 +053010184 * hdd_populate_random_mac_addr() - API to populate random mac addresses
10185 * @hdd_ctx: HDD Context
10186 * @num: Number of random mac addresses needed
10187 *
10188 * Generate random addresses using bit manipulation on the base mac address
10189 *
10190 * Return: None
10191 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010192void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +053010193{
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010194 uint32_t idx = hdd_ctx->num_derived_addr;
Komal Seelam92fff912016-03-24 11:51:41 +053010195 uint32_t iter;
Komal Seelam92fff912016-03-24 11:51:41 +053010196 uint8_t *buf = NULL;
10197 uint8_t macaddr_b3, tmp_br3;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010198 /*
10199 * Consider first provisioned mac address as source address to derive
10200 * remaining addresses
10201 */
Komal Seelam92fff912016-03-24 11:51:41 +053010202
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010203 uint8_t *src = hdd_ctx->provisioned_mac_addr[0].bytes;
10204
10205 for (iter = 0; iter < num; ++iter, ++idx) {
10206 buf = hdd_ctx->derived_mac_addr[idx].bytes;
Komal Seelam92fff912016-03-24 11:51:41 +053010207 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
10208 macaddr_b3 = buf[3];
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010209 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + idx) &
Komal Seelam92fff912016-03-24 11:51:41 +053010210 INTF_MACADDR_MASK;
10211 macaddr_b3 += tmp_br3;
10212 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
10213 buf[0] |= 0x02;
10214 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010215 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010216 hdd_ctx->num_derived_addr++;
Komal Seelam92fff912016-03-24 11:51:41 +053010217 }
10218}
10219
10220/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010221 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +053010222 * @hdd_ctx: HDD Context
10223 *
10224 * API to get mac addresses from platform driver and update the driver
10225 * structures and configure FW with the base mac address.
10226 * Return: int
10227 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010228static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +053010229{
10230 uint32_t no_of_mac_addr, iter;
10231 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
10232 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
10233 uint8_t *addr, *buf;
10234 struct device *dev = hdd_ctx->parent_dev;
Komal Seelam92fff912016-03-24 11:51:41 +053010235 tSirMacAddr mac_addr;
10236 QDF_STATUS status;
10237
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010238 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +053010239
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010240 if (no_of_mac_addr == 0 || !addr) {
10241 hdd_debug("No mac configured from platform driver");
Komal Seelam92fff912016-03-24 11:51:41 +053010242 return -EINVAL;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010243 }
10244
10245 hdd_free_mac_address_lists(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +053010246
10247 if (no_of_mac_addr > max_mac_addr)
10248 no_of_mac_addr = max_mac_addr;
10249
10250 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
10251
10252 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010253 buf = hdd_ctx->provisioned_mac_addr[iter].bytes;
Komal Seelam92fff912016-03-24 11:51:41 +053010254 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010255 hdd_info("provisioned MAC Addr [%d]" MAC_ADDRESS_STR, iter,
10256 MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +053010257 }
10258
Komal Seelam92fff912016-03-24 11:51:41 +053010259
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010260 hdd_ctx->num_provisioned_addr = no_of_mac_addr;
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010261
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010262 if (hdd_ctx->config->mac_provision) {
10263 addr = hdd_get_platform_wlan_derived_mac_buff(dev,
10264 &no_of_mac_addr);
10265
10266 if (no_of_mac_addr == 0 || !addr)
10267 hdd_warn("No derived address from platform driver");
10268 else if (no_of_mac_addr >
10269 (max_mac_addr - hdd_ctx->num_provisioned_addr))
10270 no_of_mac_addr = (max_mac_addr -
10271 hdd_ctx->num_provisioned_addr);
10272
10273 for (iter = 0; iter < no_of_mac_addr; ++iter,
10274 addr += mac_addr_size) {
10275 buf = hdd_ctx->derived_mac_addr[iter].bytes;
10276 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
10277 hdd_debug("derived MAC Addr [%d]" MAC_ADDRESS_STR, iter,
10278 MAC_ADDR_ARRAY(buf));
10279 }
10280 hdd_ctx->num_derived_addr = no_of_mac_addr;
10281 }
10282
10283 no_of_mac_addr = hdd_ctx->num_provisioned_addr +
10284 hdd_ctx->num_derived_addr;
Komal Seelam92fff912016-03-24 11:51:41 +053010285 if (no_of_mac_addr < max_mac_addr)
10286 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
10287 no_of_mac_addr);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010288
10289 status = sme_set_custom_mac_addr(mac_addr);
10290 if (!QDF_IS_STATUS_SUCCESS(status))
10291 return -EAGAIN;
10292
Komal Seelam92fff912016-03-24 11:51:41 +053010293 return 0;
10294}
10295
10296/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010297 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
10298 * @hdd_ctx: HDD Context
10299 *
10300 * Update MAC address to FW. If MAC address passed by FW is invalid, host
10301 * will generate its own MAC and update it to FW.
10302 *
10303 * Return: 0 for success
10304 * Non-zero error code for failure
10305 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010306static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010307{
10308 tSirMacAddr customMacAddr;
10309 QDF_STATUS status;
10310
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010311 if (hdd_ctx->num_provisioned_addr)
10312 qdf_mem_copy(&customMacAddr,
10313 &hdd_ctx->provisioned_mac_addr[0].bytes[0],
10314 sizeof(tSirMacAddr));
10315 else
10316 qdf_mem_copy(&customMacAddr,
10317 &hdd_ctx->derived_mac_addr[0].bytes[0],
10318 sizeof(tSirMacAddr));
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010319 status = sme_set_custom_mac_addr(customMacAddr);
10320 if (!QDF_IS_STATUS_SUCCESS(status))
10321 return -EAGAIN;
10322 return 0;
10323}
10324
10325/**
Komal Seelam92fff912016-03-24 11:51:41 +053010326 * hdd_initialize_mac_address() - API to get wlan mac addresses
10327 * @hdd_ctx: HDD Context
10328 *
10329 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
10330 * is provisioned with mac addresses, driver uses it, else it will use
10331 * wlan_mac.bin to update HW MAC addresses.
10332 *
10333 * Return: None
10334 */
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010335static int hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +053010336{
10337 QDF_STATUS status;
10338 int ret;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010339 bool update_mac_addr_to_fw = true;
Komal Seelam92fff912016-03-24 11:51:41 +053010340
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010341 ret = hdd_platform_wlan_mac(hdd_ctx);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010342 if (hdd_ctx->config->mac_provision || !ret) {
Dustin Brown7e761c72018-07-31 13:50:17 -070010343 hdd_info("using MAC address from platform driver");
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010344 return ret;
Dustin Brown7e761c72018-07-31 13:50:17 -070010345 }
Komal Seelam92fff912016-03-24 11:51:41 +053010346
10347 status = hdd_update_mac_config(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010348 if (QDF_IS_STATUS_SUCCESS(status)) {
10349 hdd_info("using MAC address from wlan_mac.bin");
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010350 return 0;
Dustin Brown7e761c72018-07-31 13:50:17 -070010351 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010352
Dustin Brown7e761c72018-07-31 13:50:17 -070010353 hdd_info("using default MAC address");
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010354
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010355 /* Use fw provided MAC */
10356 if (!qdf_is_macaddr_zero(&hdd_ctx->hw_macaddr)) {
10357 hdd_update_macaddr(hdd_ctx, hdd_ctx->hw_macaddr, false);
10358 update_mac_addr_to_fw = false;
10359 return 0;
10360 } else if (hdd_generate_macaddr_auto(hdd_ctx) != 0) {
10361 struct qdf_mac_addr mac_addr;
10362
10363 hdd_err("MAC failure from device serial no.");
Jeff Johnson51a80522018-12-11 20:19:44 -080010364 qdf_get_random_bytes(&mac_addr, sizeof(mac_addr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010365 /*
10366 * Reset multicast bit (bit-0) and set
10367 * locally-administered bit
10368 */
10369 mac_addr.bytes[0] = 0x2;
10370 hdd_update_macaddr(hdd_ctx, mac_addr, true);
10371 }
10372
10373 if (update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010374 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010375 if (ret)
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -080010376 hdd_err("MAC address out-of-sync, ret:%d", ret);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010377 }
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010378 return ret;
Komal Seelam92fff912016-03-24 11:51:41 +053010379}
10380
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010381static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010382{
10383 int vdev_id = 0;
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053010384 QDF_STATUS status;
10385 bool smart_chainmask_enabled;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010386 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010387 int vpdev = PDEV_CMD;
10388 int ret;
10389
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053010390 status = ucfg_get_smart_chainmask_enabled(hdd_ctx->psoc,
10391 &smart_chainmask_enabled);
10392 if (QDF_IS_STATUS_ERROR(status))
10393 return -EINVAL;
10394
10395 ret = sme_cli_set_command(vdev_id, param_id,
10396 (int)smart_chainmask_enabled, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010397 if (ret)
10398 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
10399
10400 return ret;
10401}
10402
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010403static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010404{
10405 int vdev_id = 0;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010406 QDF_STATUS status;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010407 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010408 bool alternative_chainmask_enabled;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010409 int vpdev = PDEV_CMD;
10410 int ret;
10411
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010412 status = ucfg_get_alternative_chainmask_enabled(
10413 hdd_ctx->psoc,
10414 &alternative_chainmask_enabled);
10415 if (QDF_IS_STATUS_ERROR(status))
10416 return -EINVAL;
10417
10418 ret = sme_cli_set_command(vdev_id, param_id,
10419 (int)alternative_chainmask_enabled, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010420 if (ret)
10421 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
10422 ret);
10423
10424 return ret;
10425}
10426
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010427static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -070010428{
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010429 QDF_STATUS status;
Jeff Johnson12a744b2017-04-04 08:19:37 -070010430 int vdev_id = 0;
10431 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010432 bool value;
Jeff Johnson12a744b2017-04-04 08:19:37 -070010433 int vpdev = PDEV_CMD;
10434 int ret;
10435
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010436 status = ucfg_fwol_get_ani_enabled(hdd_ctx->psoc, &value);
10437 if (QDF_IS_STATUS_ERROR(status))
10438 return -EINVAL;
10439
10440 ret = sme_cli_set_command(vdev_id, param_id, (int)value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -070010441 if (ret)
10442 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
10443
10444 return ret;
10445}
10446
Jeff Johnson89c66ff2016-04-22 15:21:37 -070010447/**
Prashanth Bhatta07998752016-04-28 12:35:33 -070010448 * hdd_pre_enable_configure() - Configurations prior to cds_enable
10449 * @hdd_ctx: HDD context
10450 *
10451 * Pre configurations to be done at lower layer before calling cds enable.
10452 *
10453 * Return: 0 on success and errno on failure.
10454 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010455static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -070010456{
10457 int ret;
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010458 uint8_t val = 0;
Prashanth Bhatta07998752016-04-28 12:35:33 -070010459 QDF_STATUS status;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010460 uint32_t arp_ac_category;
Leo Changfdb45c32016-10-28 11:09:23 -070010461 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010462
Leo Changfdb45c32016-10-28 11:09:23 -070010463 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Ajit Pal Singh5d269612018-04-19 16:29:12 +053010464 /* Register HL netdev flow control callback */
10465 cdp_hl_fc_register(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010466
10467 /*
10468 * Note that the cds_pre_enable() sequence triggers the cfg download.
10469 * The cfg download must occur before we update the SME config
10470 * since the SME config operation must access the cfg database
10471 */
10472 status = hdd_set_sme_config(hdd_ctx);
10473
10474 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010475 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010476 ret = qdf_status_to_os_return(status);
10477 goto out;
10478 }
10479
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -070010480 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
10481 if (QDF_STATUS_SUCCESS != status) {
10482 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
10483 ret = qdf_status_to_os_return(status);
10484 goto out;
10485 }
10486
Dustin Brown1dbefe62018-09-11 16:32:03 -070010487 status = ucfg_mlme_get_tx_chainmask_1ss(hdd_ctx->psoc, &val);
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010488 if (QDF_STATUS_SUCCESS != status) {
10489 hdd_err("Get tx_chainmask_1ss from mlme failed");
10490 ret = qdf_status_to_os_return(status);
10491 goto out;
10492 }
10493 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS, val,
Prashanth Bhatta07998752016-04-28 12:35:33 -070010494 PDEV_CMD);
10495 if (0 != ret) {
10496 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
10497 goto out;
10498 }
10499
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010500 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
10501 if (ret)
10502 goto out;
10503
10504 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
10505 if (ret)
10506 goto out;
10507
Jeff Johnson12a744b2017-04-04 08:19:37 -070010508 ret = hdd_set_ani_enabled(hdd_ctx);
10509 if (ret)
10510 goto out;
10511
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010512 status = ucfg_get_arp_ac_category(hdd_ctx->psoc, &arp_ac_category);
10513
10514 if (QDF_IS_STATUS_ERROR(status))
10515 return -EINVAL;
10516
Naveen Rawat247a8682017-06-05 15:00:31 -070010517 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010518 arp_ac_category,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -080010519 PDEV_CMD);
10520 if (0 != ret) {
10521 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010522 arp_ac_category, ret);
Srinivas Girigowda70e169a2017-03-07 23:55:57 -080010523 goto out;
10524 }
10525
Prashanth Bhatta07998752016-04-28 12:35:33 -070010526 status = hdd_set_sme_chan_list(hdd_ctx);
10527 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010528 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010529 ret = qdf_status_to_os_return(status);
10530 goto out;
10531 }
10532
10533 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -070010534 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010535 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -070010536 ret = -EINVAL;
10537 goto out;
10538 }
10539
Prashanth Bhatta07998752016-04-28 12:35:33 -070010540
10541 hdd_init_channel_avoidance(hdd_ctx);
10542
10543out:
10544 return ret;
10545}
10546
Rachit Kankane026e77a2018-07-31 16:21:09 +053010547#ifdef FEATURE_P2P_LISTEN_OFFLOAD
Prashanth Bhatta07998752016-04-28 12:35:33 -070010548/**
Peng Xu8fdaa492016-06-22 10:20:47 -070010549 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010550 * @context: context registered with sme_register_p2p_lo_event(). HDD
10551 * always registers a hdd context pointer
10552 * @evt:event structure pointer
Peng Xu8fdaa492016-06-22 10:20:47 -070010553 *
10554 * This is the p2p listen offload stop event handler, it sends vendor
10555 * event back to supplicant to notify the stop reason.
10556 *
10557 * Return: None
10558 */
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010559static void wlan_hdd_p2p_lo_event_callback(void *context,
10560 struct sir_p2p_lo_event *evt)
Peng Xu8fdaa492016-06-22 10:20:47 -070010561{
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010562 struct hdd_context *hdd_ctx = context;
Peng Xu8fdaa492016-06-22 10:20:47 -070010563 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -070010564 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -070010565
Dustin Brown491d54b2018-03-14 12:39:11 -070010566 hdd_enter();
Peng Xu8fdaa492016-06-22 10:20:47 -070010567
10568 if (hdd_ctx == NULL) {
10569 hdd_err("Invalid HDD context pointer");
10570 return;
10571 }
10572
Peng Xu5c682812017-08-06 07:39:13 -070010573 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
10574 if (!adapter) {
10575 hdd_err("Cannot find adapter by vdev_id = %d",
10576 evt->vdev_id);
10577 return;
10578 }
10579
Peng Xu8fdaa492016-06-22 10:20:47 -070010580 vendor_event =
10581 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -070010582 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -070010583 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
10584 GFP_KERNEL);
10585
10586 if (!vendor_event) {
10587 hdd_err("cfg80211_vendor_event_alloc failed");
10588 return;
10589 }
10590
10591 if (nla_put_u32(vendor_event,
10592 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
10593 evt->reason_code)) {
10594 hdd_err("nla put failed");
10595 kfree_skb(vendor_event);
10596 return;
10597 }
10598
10599 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -070010600 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
10601 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -070010602}
Rachit Kankane026e77a2018-07-31 16:21:09 +053010603#else
10604static void wlan_hdd_p2p_lo_event_callback(void *context,
10605 struct sir_p2p_lo_event *evt)
10606{
10607}
10608#endif
Peng Xu8fdaa492016-06-22 10:20:47 -070010609
Rachit Kankanef6834c42018-08-02 18:47:50 +053010610#ifdef FEATURE_WLAN_DYNAMIC_CVM
10611static inline int hdd_set_vc_mode_config(struct hdd_context *hdd_ctx)
10612{
10613 return sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap);
10614}
10615#else
10616static inline int hdd_set_vc_mode_config(struct hdd_context *hdd_ctx)
10617{
10618 return QDF_STATUS_SUCCESS;
10619}
10620#endif
10621
Peng Xu8fdaa492016-06-22 10:20:47 -070010622/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010623 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
10624 * @hdd_ctx: HDD context
10625 *
10626 * This function sends the adaptive dwell time config configuration to the
10627 * firmware via WMA
10628 *
10629 * Return: 0 - success, < 0 - failure
10630 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010631static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010632{
10633 QDF_STATUS status;
10634 struct adaptive_dwelltime_params dwelltime_params;
10635
Harprit Chhabadad59ae762019-01-08 16:40:43 -080010636 status = ucfg_fwol_get_all_adaptive_dwelltime_params(hdd_ctx->psoc,
10637 &dwelltime_params);
10638 status = ucfg_fwol_set_adaptive_dwelltime_config(&dwelltime_params);
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010639
10640 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
10641 if (!QDF_IS_STATUS_SUCCESS(status)) {
10642 hdd_err("Failed to send Adaptive Dwelltime configuration!");
10643 return -EAGAIN;
10644 }
10645 return 0;
10646}
10647
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010648int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010649{
10650 QDF_STATUS status;
10651 struct wmi_dbs_scan_sel_params dbs_scan_params;
10652 uint32_t i = 0;
10653 uint8_t count = 0, numentries = 0;
Krunal Sonidf29bc42018-11-15 13:26:29 -080010654 uint8_t dual_mac_feature;
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010655 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
10656 * CDS_DBS_SCAN_CLIENTS_MAX];
10657
Krunal Sonidf29bc42018-11-15 13:26:29 -080010658 status = ucfg_policy_mgr_get_dual_mac_feature(hdd_ctx->psoc,
10659 &dual_mac_feature);
10660
10661 if (status != QDF_STATUS_SUCCESS) {
10662 hdd_err("can't get dual mac feature flag");
10663 return -EINVAL;
10664 }
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010665 /* check if DBS is enabled or supported */
Krunal Sonidf29bc42018-11-15 13:26:29 -080010666 if ((dual_mac_feature == DISABLE_DBS_CXN_AND_SCAN) ||
10667 (dual_mac_feature == ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN))
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010668 return -EINVAL;
10669
10670 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
10671 dbs_scan_config, &numentries,
10672 (CDS_DBS_SCAN_PARAM_PER_CLIENT
10673 * CDS_DBS_SCAN_CLIENTS_MAX));
10674
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010675 if (!numentries) {
Dustin Brown6a8d39b2018-08-14 15:27:26 -070010676 hdd_debug("Do not send scan_selection_config");
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010677 return 0;
10678 }
10679
10680 /* hdd_set_fw_log_params */
10681 dbs_scan_params.num_clients = 0;
10682 while (count < (numentries - 2)) {
10683 dbs_scan_params.module_id[i] = dbs_scan_config[count];
10684 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
10685 dbs_scan_params.num_non_dbs_scans[i] =
10686 dbs_scan_config[count + 2];
10687 dbs_scan_params.num_clients++;
10688 hdd_debug("module:%d NDS:%d NNDS:%d",
10689 dbs_scan_params.module_id[i],
10690 dbs_scan_params.num_dbs_scans[i],
10691 dbs_scan_params.num_non_dbs_scans[i]);
10692 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
10693 i++;
10694 }
10695
10696 dbs_scan_params.pdev_id = 0;
10697
10698 hdd_debug("clients:%d pdev:%d",
10699 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
10700
Jeff Johnson16528362018-06-14 12:34:16 -070010701 status = sme_set_dbs_scan_selection_config(hdd_ctx->mac_handle,
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010702 &dbs_scan_params);
10703 hdd_debug("Sending DBS Scan Selection Configuration to fw");
10704 if (!QDF_IS_STATUS_SUCCESS(status)) {
10705 hdd_err("Failed to send DBS Scan selection configuration!");
10706 return -EAGAIN;
10707 }
10708 return 0;
10709}
10710
Arun Khandavallid4349a92016-07-25 11:10:43 +053010711#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10712/**
10713 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
10714 * @hdd_ctx: HDD context
10715 *
10716 * Set auto shutdown callback to get indications from firmware to indicate
10717 * userspace to shutdown WLAN after a configured amount of inactivity.
10718 *
10719 * Return: 0 on success and errno on failure.
10720 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010721static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010722{
10723 QDF_STATUS status;
10724
Dundi Raviteja8e338282018-09-25 17:16:04 +053010725 if (!hdd_ctx->config->wlan_auto_shutdown)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010726 return 0;
10727
Jeff Johnson16528362018-06-14 12:34:16 -070010728 status = sme_set_auto_shutdown_cb(hdd_ctx->mac_handle,
Arun Khandavallid4349a92016-07-25 11:10:43 +053010729 wlan_hdd_auto_shutdown_cb);
10730 if (status != QDF_STATUS_SUCCESS)
10731 hdd_err("Auto shutdown feature could not be enabled: %d",
10732 status);
10733
10734 return qdf_status_to_os_return(status);
10735}
10736#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010737static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010738{
10739 return 0;
10740}
10741#endif
10742
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010743#ifdef MWS_COEX
10744/**
10745 * hdd_set_mws_coex() - Set MWS coex configurations
10746 * @hdd_ctx: HDD context
10747 *
10748 * This function sends MWS-COEX 4G quick FTDM and
10749 * MWS-COEX 5G-NR power limit to FW
10750 *
10751 * Return: 0 on success and errno on failure.
10752 */
10753static int hdd_init_mws_coex(struct hdd_context *hdd_ctx)
10754{
10755 int ret = 0;
lifengdb340e72018-11-20 00:50:20 +080010756 uint32_t mws_coex_4g_quick_tdm = 0, mws_coex_5g_nr_pwr_limit = 0;
10757
10758 ucfg_mlme_get_mws_coex_4g_quick_tdm(hdd_ctx->psoc,
10759 &mws_coex_4g_quick_tdm);
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010760
10761 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_MWSCOEX_4G_ALLOW_QUICK_FTDM,
lifengdb340e72018-11-20 00:50:20 +080010762 mws_coex_4g_quick_tdm,
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010763 PDEV_CMD);
10764 if (ret) {
10765 hdd_warn("Unable to send MWS-COEX 4G quick FTDM policy");
10766 return ret;
10767 }
10768
lifengdb340e72018-11-20 00:50:20 +080010769 ucfg_mlme_get_mws_coex_5g_nr_pwr_limit(hdd_ctx->psoc,
10770 &mws_coex_5g_nr_pwr_limit);
10771
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010772 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_MWSCOEX_SET_5GNR_PWR_LIMIT,
lifengdb340e72018-11-20 00:50:20 +080010773 mws_coex_5g_nr_pwr_limit,
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010774 PDEV_CMD);
10775 if (ret) {
10776 hdd_warn("Unable to send MWS-COEX 4G quick FTDM policy");
10777 return ret;
10778 }
lifengdb340e72018-11-20 00:50:20 +080010779
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010780 return ret;
10781}
10782#else
10783static int hdd_init_mws_coex(struct hdd_context *hdd_ctx)
10784{
10785 return 0;
10786}
10787#endif
10788
Arun Khandavallid4349a92016-07-25 11:10:43 +053010789/**
10790 * hdd_features_init() - Init features
10791 * @hdd_ctx: HDD context
Arun Khandavallid4349a92016-07-25 11:10:43 +053010792 *
10793 * Initialize features and their feature context after WLAN firmware is up.
10794 *
10795 * Return: 0 on success and errno on failure.
10796 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010797static int hdd_features_init(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010798{
10799 tSirTxPowerLimit hddtxlimit;
10800 QDF_STATUS status;
10801 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070010802 mac_handle_t mac_handle;
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010803 struct hdd_config *cfg;
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +053010804 bool b_cts2self, is_imps_enabled;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010805
Dustin Brown491d54b2018-03-14 12:39:11 -070010806 hdd_enter();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010807
Dustin Brownad698ae2018-09-05 17:19:30 -070010808 ret = hdd_update_country_code(hdd_ctx);
10809 if (ret) {
10810 hdd_err("Failed to update country code; errno:%d", ret);
10811 return -EINVAL;
10812 }
10813
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010814 ret = hdd_init_mws_coex(hdd_ctx);
10815 if (ret)
10816 hdd_warn("Error initializing mws-coex");
10817
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010818 cfg = hdd_ctx->config;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010819 /* FW capabilities received, Set the Dot11 mode */
Jeff Johnson16528362018-06-14 12:34:16 -070010820 mac_handle = hdd_ctx->mac_handle;
10821 sme_setdef_dot11mode(mac_handle);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010822
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +053010823 ucfg_mlme_is_imps_enabled(hdd_ctx->psoc, &is_imps_enabled);
10824 hdd_set_idle_ps_config(hdd_ctx, is_imps_enabled);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010825
Poddar, Siddarth37033032017-10-11 15:47:40 +053010826 /* Send Enable/Disable data stall detection cmd to FW */
10827 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
jitiphil377bcc12018-10-05 19:46:08 +053010828 cdp_cfg_get(cds_get_context(QDF_MODULE_ID_SOC),
10829 cfg_dp_enable_data_stall), PDEV_CMD);
Poddar, Siddarth37033032017-10-11 15:47:40 +053010830
Dustin Brown1dbefe62018-09-11 16:32:03 -070010831 ucfg_mlme_get_go_cts2self_for_sta(hdd_ctx->psoc, &b_cts2self);
Wu Gao93816212018-08-31 16:49:54 +080010832 if (b_cts2self)
Jeff Johnson16528362018-06-14 12:34:16 -070010833 sme_set_cts2self_for_p2p_go(mac_handle);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010834
Rachit Kankanef6834c42018-08-02 18:47:50 +053010835 if (hdd_set_vc_mode_config(hdd_ctx))
Nachiket Kukade8983cf62017-10-12 18:14:48 +053010836 hdd_warn("Error in setting Voltage Corner mode config to FW");
10837
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010838 if (hdd_rx_ol_init(hdd_ctx))
10839 hdd_err("Unable to initialize Rx LRO/GRO in fw");
Arun Khandavallid4349a92016-07-25 11:10:43 +053010840
10841 if (hdd_adaptive_dwelltime_init(hdd_ctx))
10842 hdd_err("Unable to send adaptive dwelltime setting to FW");
10843
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010844 if (hdd_dbs_scan_selection_init(hdd_ctx))
10845 hdd_err("Unable to send DBS scan selection setting to FW");
10846
Arun Khandavallid4349a92016-07-25 11:10:43 +053010847 ret = hdd_init_thermal_info(hdd_ctx);
10848 if (ret) {
10849 hdd_err("Error while initializing thermal information");
Dustin Browne7e71d32018-05-11 16:00:08 -070010850 return ret;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010851 }
10852
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010853 /**
10854 * In case of SSR/PDR, if pktlog was enabled manually before
10855 * SSR/PDR, Then enabled it again automatically after Wlan
10856 * device up.
10857 */
10858 if (cds_is_driver_recovering()) {
10859 if (hdd_ctx->is_pktlog_enabled)
10860 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Alok Kumar5a75b9d2018-08-31 10:55:43 +053010861 } else if (cds_is_packet_log_enabled())
10862 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Poddar, Siddarth66a46592017-02-22 11:44:44 +053010863
gaurank kathpalia3d2e3852018-10-03 22:03:23 +053010864 hddtxlimit.txPower2g = ucfg_get_tx_power(hdd_ctx->psoc, BAND_2G);
10865 hddtxlimit.txPower5g = ucfg_get_tx_power(hdd_ctx->psoc, BAND_5G);
Jeff Johnson16528362018-06-14 12:34:16 -070010866 status = sme_txpower_limit(mac_handle, &hddtxlimit);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010867 if (!QDF_IS_STATUS_SUCCESS(status))
10868 hdd_err("Error setting txlimit in sme: %d", status);
10869
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010870 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010871
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053010872 status = sme_enable_disable_chanavoidind_event(mac_handle, 0);
10873 if (QDF_IS_STATUS_ERROR(status) && (status != QDF_STATUS_E_NOSUPPORT)) {
10874 hdd_err("Failed to disable Chan Avoidance Indication");
Sourav Mohapatra674925f2018-04-16 11:16:58 +053010875 return -EINVAL;
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +053010876 }
Arun Khandavallid4349a92016-07-25 11:10:43 +053010877
10878 /* register P2P Listen Offload event callback */
10879 if (wma_is_p2p_lo_capable())
Jeff Johnson16528362018-06-14 12:34:16 -070010880 sme_register_p2p_lo_event(mac_handle, hdd_ctx,
10881 wlan_hdd_p2p_lo_event_callback);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010882
10883 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
10884
10885 if (ret)
Sourav Mohapatra674925f2018-04-16 11:16:58 +053010886 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010887
Dustin Brown11638b72018-01-25 17:37:25 +053010888 wlan_hdd_init_chan_info(hdd_ctx);
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010889 wlan_hdd_twt_init(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010890
Dustin Browne74003f2018-03-14 12:51:58 -070010891 hdd_exit();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010892 return 0;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010893}
10894
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010895/**
10896 * hdd_features_deinit() - Deinit features
10897 * @hdd_ctx: HDD context
10898 *
10899 * De-Initialize features and their feature context.
10900 *
10901 * Return: none.
10902 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010903static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010904{
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010905 wlan_hdd_twt_deinit(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010906 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010907 wlan_hdd_tsf_deinit(hdd_ctx);
jitiphil4e3bef42018-11-14 14:31:13 +053010908 if (cds_is_packet_log_enabled())
10909 hdd_pktlog_enable_disable(hdd_ctx, false, 0, 0);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010910}
10911
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010912/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010913 * hdd_register_bcn_cb() - register scan beacon callback
10914 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010915 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010916 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010917 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010918static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010919{
10920 QDF_STATUS status;
10921
Dustin Brown1dbefe62018-09-11 16:32:03 -070010922 status = ucfg_scan_register_bcn_cb(hdd_ctx->psoc,
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010923 wlan_cfg80211_inform_bss_frame,
10924 SCAN_CB_TYPE_INFORM_BCN);
10925 if (!QDF_IS_STATUS_SUCCESS(status)) {
10926 hdd_err("failed with status code %08d [x%08x]",
10927 status, status);
10928 return status;
10929 }
10930
10931 return QDF_STATUS_SUCCESS;
10932}
Arun Khandavallid4349a92016-07-25 11:10:43 +053010933
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010934/**
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070010935 * hdd_v2_flow_pool_map() - Flow pool create callback when vdev is active
10936 * @vdev_id: vdev_id, corresponds to flow_pool
10937 *
10938 * Return: none.
10939 */
10940static void hdd_v2_flow_pool_map(int vdev_id)
10941{
10942 QDF_STATUS status;
10943
10944 status = cdp_flow_pool_map(cds_get_context(QDF_MODULE_ID_SOC),
10945 cds_get_context(QDF_MODULE_ID_TXRX),
10946 vdev_id);
10947 /*
10948 * For Adrastea flow control v2 is based on FW MAP events,
10949 * so this above callback is not implemented.
10950 * Hence this is not actual failure. Dont return failure
10951 */
10952 if ((status != QDF_STATUS_SUCCESS) &&
10953 (status != QDF_STATUS_E_INVAL)) {
10954 hdd_err("vdev_id: %d, failed to create flow pool status %d",
10955 vdev_id, status);
10956 }
10957}
10958
10959/**
10960 * hdd_v2_flow_pool_unmap() - Flow pool create callback when vdev is not active
10961 * @vdev_id: vdev_id, corresponds to flow_pool
10962 *
10963 * Return: none.
10964 */
10965static void hdd_v2_flow_pool_unmap(int vdev_id)
10966{
10967 cdp_flow_pool_unmap(cds_get_context(QDF_MODULE_ID_SOC),
10968 cds_get_context(QDF_MODULE_ID_TXRX), vdev_id);
10969}
10970
10971/**
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010972 * hdd_action_oui_config() - Configure action_oui strings
10973 * @hdd_ctx: pointer to hdd context
10974 *
10975 * This is a HDD wrapper function which invokes ucfg api
10976 * of action_oui component to parse action oui strings.
10977 *
10978 * Return: None
10979 */
10980static void hdd_action_oui_config(struct hdd_context *hdd_ctx)
10981{
10982 QDF_STATUS status;
10983 uint32_t id;
10984 uint8_t *str;
10985
10986 if (!hdd_ctx->config->action_oui_enable)
10987 return;
10988
10989 for (id = 0; id < ACTION_OUI_MAXIMUM_ID; id++) {
10990 str = hdd_ctx->config->action_oui_str[id];
10991 if (!qdf_str_len(str))
10992 continue;
10993
Dustin Brown1dbefe62018-09-11 16:32:03 -070010994 status = ucfg_action_oui_parse(hdd_ctx->psoc, str, id);
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010995 if (!QDF_IS_STATUS_SUCCESS(status))
10996 hdd_err("Failed to parse action_oui str: %u", id);
10997 }
10998}
10999
11000/**
11001 * hdd_action_oui_send() - Send action_oui extensions to firmware
11002 * @hdd_ctx: pointer to hdd context
11003 *
11004 * This is a HDD wrapper function which invokes ucfg api
11005 * of action_oui component to send action oui extensions to firmware.
11006 *
11007 * Return: None
11008 */
11009static void hdd_action_oui_send(struct hdd_context *hdd_ctx)
11010{
11011 QDF_STATUS status;
11012
11013 if (!hdd_ctx->config->action_oui_enable)
11014 return;
11015
Dustin Brown1dbefe62018-09-11 16:32:03 -070011016 status = ucfg_action_oui_send(hdd_ctx->psoc);
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011017 if (!QDF_IS_STATUS_SUCCESS(status))
11018 hdd_err("Failed to send one or all action_ouis");
11019}
11020
Jeff Johnson0187c622019-01-04 06:39:44 -080011021static void hdd_hastings_bt_war_initialize(struct hdd_context *hdd_ctx)
11022{
11023 if (hdd_ctx->config->iface_change_wait_time)
11024 hdd_hastings_bt_war_disable_fw(hdd_ctx);
11025 else
11026 hdd_hastings_bt_war_enable_fw(hdd_ctx);
11027}
11028
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011029/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011030 * hdd_configure_cds() - Configure cds modules
11031 * @hdd_ctx: HDD context
11032 * @adapter: Primary adapter context
11033 *
11034 * Enable Cds modules after WLAN firmware is up.
11035 *
11036 * Return: 0 on success and errno on failure.
11037 */
Dustin Browne7e71d32018-05-11 16:00:08 -070011038int hdd_configure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053011039{
11040 int ret;
11041 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011042 int set_value;
Jeff Johnson16528362018-06-14 12:34:16 -070011043 mac_handle_t mac_handle;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011044 bool enable_rts_sifsbursting;
11045 uint8_t enable_phy_reg_retention;
Krunal Sonidf29bc42018-11-15 13:26:29 -080011046 uint8_t max_mpdus_inampdu, is_force_1x1 = 0;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011047 uint32_t num_abg_tx_chains = 0;
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053011048 uint16_t num_11b_tx_chains = 0;
11049 uint16_t num_11ag_tx_chains = 0;
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070011050 struct policy_mgr_dp_cbacks dp_cbs = {0};
Bala Venkatesh2fde2c62018-09-11 20:33:24 +053011051 bool value;
Wu Gao66454f12018-09-26 19:55:41 +080011052 enum pmo_auto_pwr_detect_failure_mode auto_power_fail_mode;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053011053 bool bval = false;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011054
Jeff Johnson16528362018-06-14 12:34:16 -070011055 mac_handle = hdd_ctx->mac_handle;
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011056
11057 hdd_action_oui_send(hdd_ctx);
Krunal Sonidf29bc42018-11-15 13:26:29 -080011058 status = ucfg_policy_mgr_get_force_1x1(hdd_ctx->psoc, &is_force_1x1);
11059 if (status != QDF_STATUS_SUCCESS) {
11060 hdd_err("Failed to get force 1x1 value");
11061 goto out;
11062 }
11063 if (is_force_1x1)
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011064 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
11065 1, PDEV_CMD);
11066 /* set chip power save failure detected callback */
Jeff Johnson16528362018-06-14 12:34:16 -070011067 sme_set_chip_pwr_save_fail_cb(mac_handle,
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011068 hdd_chip_pwr_save_fail_detected_cb);
11069
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011070 status = ucfg_get_max_mpdus_inampdu(hdd_ctx->psoc,
11071 &max_mpdus_inampdu);
Krunal Sonidf29bc42018-11-15 13:26:29 -080011072 if (status) {
11073 hdd_err("Failed to get max mpdus in ampdu value");
11074 goto out;
11075 }
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011076
11077 if (max_mpdus_inampdu) {
11078 set_value = max_mpdus_inampdu;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011079 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
11080 set_value, PDEV_CMD);
11081 }
11082
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011083 status = ucfg_get_enable_rts_sifsbursting(hdd_ctx->psoc,
11084 &enable_rts_sifsbursting);
Krunal Sonidf29bc42018-11-15 13:26:29 -080011085 if (status) {
11086 hdd_err("Failed to get rts sifs bursting value");
11087 goto out;
11088 }
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011089
11090 if (enable_rts_sifsbursting) {
11091 set_value = enable_rts_sifsbursting;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011092 sme_cli_set_command(0,
11093 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
11094 set_value, PDEV_CMD);
11095 }
11096
Dustin Brown05d81302018-09-11 16:49:22 -070011097 ucfg_mlme_get_sap_get_peer_info(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +053011098 if (value) {
11099 set_value = value;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011100 sme_cli_set_command(0,
11101 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
11102 set_value, PDEV_CMD);
11103 }
11104
Dustin Brown1dbefe62018-09-11 16:32:03 -070011105 status = ucfg_mlme_get_num_11b_tx_chains(hdd_ctx->psoc,
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053011106 &num_11b_tx_chains);
11107 if (status != QDF_STATUS_SUCCESS) {
11108 hdd_err("Failed to get num_11b_tx_chains");
11109 goto out;
11110 }
11111
Dustin Brown1dbefe62018-09-11 16:32:03 -070011112 status = ucfg_mlme_get_num_11ag_tx_chains(hdd_ctx->psoc,
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053011113 &num_11ag_tx_chains);
11114 if (status != QDF_STATUS_SUCCESS) {
11115 hdd_err("Failed to get num_11ag_tx_chains");
11116 goto out;
11117 }
11118
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053011119 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
11120 if (!QDF_IS_STATUS_SUCCESS(status))
11121 hdd_err("unable to get vht_enable2x2");
11122
11123 if (!bval) {
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011124 if (num_11b_tx_chains > 1)
11125 num_11b_tx_chains = 1;
11126 if (num_11ag_tx_chains > 1)
11127 num_11ag_tx_chains = 1;
11128 }
11129 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
11130 num_11b_tx_chains);
11131 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
11132 num_11ag_tx_chains);
11133 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
11134 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +053011135
Paul Zhang02526cd2018-09-20 17:47:46 +080011136 if (!ucfg_reg_is_regdb_offloaded(hdd_ctx->psoc))
11137 ucfg_reg_program_default_cc(hdd_ctx->pdev,
11138 hdd_ctx->reg.reg_domain);
11139
Arun Khandavallifae92942016-08-01 13:31:08 +053011140 ret = hdd_pre_enable_configure(hdd_ctx);
11141 if (ret) {
11142 hdd_err("Failed to pre-configure cds");
11143 goto out;
11144 }
11145
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080011146 /* Always get latest IPA resources allocated from cds_open and configure
11147 * IPA module before configuring them to FW. Sequence required as crash
11148 * observed otherwise.
11149 */
Dustin Brown07901ec2018-09-07 11:02:41 -070011150 if (ucfg_ipa_uc_ol_init(hdd_ctx->pdev,
11151 cds_get_context(QDF_MODULE_ID_QDF_DEVICE))) {
Manikandan Mohan2e803a02017-02-14 14:57:53 -080011152 hdd_err("Failed to setup pipes");
11153 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080011154 }
11155
Arun Khandavallifae92942016-08-01 13:31:08 +053011156 /*
11157 * Start CDS which starts up the SME/MAC/HAL modules and everything
11158 * else
11159 */
Dustin Brown1dbefe62018-09-11 16:32:03 -070011160 status = cds_enable(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053011161
11162 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011163 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053011164 goto out;
11165 }
11166
11167 status = hdd_post_cds_enable_config(hdd_ctx);
11168 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011169 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011170 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053011171 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +053011172 status = hdd_register_bcn_cb(hdd_ctx);
11173 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +080011174 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +053011175 goto cds_disable;
11176 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011177
Dustin Browne7e71d32018-05-11 16:00:08 -070011178 ret = hdd_features_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053011179 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011180 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053011181
Mohit Khanna81418772018-10-30 14:14:46 -070011182 /* Donot disable rx offload on concurrency for lithium based targets */
11183 if (!(hdd_ctx->target_type == TARGET_TYPE_QCA6290 ||
11184 hdd_ctx->target_type == TARGET_TYPE_QCA6390))
11185 if (hdd_ctx->ol_enable)
11186 dp_cbs.hdd_disable_rx_ol_in_concurrency =
11187 hdd_disable_rx_ol_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -070011188 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
jiadbb47e132018-03-30 16:28:30 +080011189 dp_cbs.hdd_ipa_set_mcc_mode_cb = hdd_ipa_set_mcc_mode;
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070011190 dp_cbs.hdd_v2_flow_pool_map = hdd_v2_flow_pool_map;
11191 dp_cbs.hdd_v2_flow_pool_unmap = hdd_v2_flow_pool_unmap;
Dustin Brown1dbefe62018-09-11 16:32:03 -070011192 status = policy_mgr_register_dp_cb(hdd_ctx->psoc, &dp_cbs);
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070011193 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -070011194 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070011195 goto cds_disable;
11196 }
Dustin Brown1dbefe62018-09-11 16:32:03 -070011197 status = policy_mgr_register_mode_change_cb(hdd_ctx->psoc,
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053011198 wlan_hdd_send_mode_change_event);
11199 if (!QDF_IS_STATUS_SUCCESS(status)) {
11200 hdd_debug("Failed to register mode change cb with Policy Manager");
11201 goto cds_disable;
11202 }
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070011203
Jeff Johnson8bb61112018-03-31 13:33:54 -070011204 if (hdd_green_ap_enable_egap(hdd_ctx))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +053011205 hdd_debug("enhance green ap is not enabled");
11206
Nachiket Kukadedd302662017-07-13 17:31:44 +053011207 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
11208 hdd_debug("Failed to set wow pulse");
11209
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053011210 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
Manikandan Mohan66df7fc2019-01-08 17:57:05 -080011211 ucfg_fwol_get_gcmp_enable(hdd_ctx->psoc), PDEV_CMD);
Wu Gao66454f12018-09-26 19:55:41 +080011212
11213 auto_power_fail_mode =
11214 ucfg_pmo_get_auto_power_fail_mode(hdd_ctx->psoc);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053011215 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
Wu Gao66454f12018-09-26 19:55:41 +080011216 auto_power_fail_mode, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053011217
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011218 status = ucfg_get_enable_phy_reg_retention(hdd_ctx->psoc,
11219 &enable_phy_reg_retention);
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053011220
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011221 if (QDF_IS_STATUS_ERROR(status))
11222 return -EINVAL;
11223
11224 if (enable_phy_reg_retention)
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053011225 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011226 enable_phy_reg_retention, PDEV_CMD);
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053011227
Jeff Johnson0187c622019-01-04 06:39:44 -080011228 hdd_hastings_bt_war_initialize(hdd_ctx);
11229
Arun Khandavallifae92942016-08-01 13:31:08 +053011230 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011231
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011232cds_disable:
Dustin Brown1dbefe62018-09-11 16:32:03 -070011233 cds_disable(hdd_ctx->psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011234
Arun Khandavallifae92942016-08-01 13:31:08 +053011235out:
11236 return -EINVAL;
11237}
11238
11239/**
11240 * hdd_deconfigure_cds() -De-Configure cds
11241 * @hdd_ctx: HDD context
11242 *
11243 * Deconfigure Cds modules before WLAN firmware is down.
11244 *
11245 * Return: 0 on success and errno on failure.
11246 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011247static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053011248{
11249 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070011250 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011251
Dustin Brown491d54b2018-03-14 12:39:11 -070011252 hdd_enter();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080011253
11254 /* De-init features */
11255 hdd_features_deinit(hdd_ctx);
11256
Dustin Brown1dbefe62018-09-11 16:32:03 -070011257 qdf_status = policy_mgr_deregister_mode_change_cb(hdd_ctx->psoc);
Srinivas Girigowdad2412882018-09-07 15:42:04 -070011258 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053011259 hdd_debug("Failed to deregister mode change cb with Policy Manager");
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053011260
Dustin Brown1dbefe62018-09-11 16:32:03 -070011261 qdf_status = cds_disable(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053011262 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11263 hdd_err("Failed to Disable the CDS Modules! :%d",
11264 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070011265 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011266 }
11267
Dustin Brown07901ec2018-09-07 11:02:41 -070011268 if (ucfg_ipa_uc_ol_deinit(hdd_ctx->pdev) != QDF_STATUS_SUCCESS) {
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053011269 hdd_err("Failed to disconnect pipes");
11270 ret = -EINVAL;
11271 }
11272
Dustin Browne74003f2018-03-14 12:51:58 -070011273 hdd_exit();
Houston Hoffman6640cf32016-10-10 16:44:29 -070011274 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053011275}
11276
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070011277#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
11278static void hdd_deregister_policy_manager_callback(
11279 struct wlan_objmgr_psoc *psoc)
11280{
11281 if (QDF_STATUS_SUCCESS !=
11282 policy_mgr_deregister_hdd_cb(psoc)) {
11283 hdd_err("HDD callback deregister with policy manager failed");
11284 }
11285}
11286#else
11287static void hdd_deregister_policy_manager_callback(
11288 struct wlan_objmgr_psoc *psoc)
11289{
11290}
11291#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053011292
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011293int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053011294{
11295 void *hif_ctx;
11296 qdf_device_t qdf_ctx;
11297 QDF_STATUS qdf_status;
Dustin Brown4bc0a622017-12-06 15:56:50 -080011298 bool is_recovery_stop = cds_is_driver_recovering();
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053011299 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -070011300 int active_threads;
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053011301 int debugfs_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053011302 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053011303
Dustin Brown491d54b2018-03-14 12:39:11 -070011304 hdd_enter();
Arun Khandavallifae92942016-08-01 13:31:08 +053011305
Dustin Brown1dbefe62018-09-11 16:32:03 -070011306 hdd_deregister_policy_manager_callback(hdd_ctx->psoc);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070011307
Arun Khandavallifae92942016-08-01 13:31:08 +053011308 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11309 if (!qdf_ctx) {
11310 hdd_err("QDF device context NULL");
11311 return -EINVAL;
11312 }
11313
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011314 mutex_lock(&hdd_ctx->iface_change_lock);
11315 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011316 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011317
Dustin Brown70111822017-03-30 15:31:40 -070011318 active_threads = cds_return_external_threads_count();
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053011319 debugfs_threads = hdd_return_debugfs_threads_count();
Dustin Brown70111822017-03-30 15:31:40 -070011320
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053011321 if (active_threads > 0 || debugfs_threads > 0 ||
11322 hdd_ctx->is_wiphy_suspended) {
11323 hdd_warn("External threads %d, Debugfs threads %d, wiphy suspend %d",
11324 active_threads, debugfs_threads,
11325 hdd_ctx->is_wiphy_suspended);
11326
11327 if (active_threads)
11328 cds_print_external_threads();
Dustin Brown70111822017-03-30 15:31:40 -070011329
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053011330 if (IS_IDLE_STOP && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070011331 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4c663222018-10-23 14:19:36 -070011332 hdd_psoc_idle_timer_start(hdd_ctx);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011333 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011334 cds_set_module_stop_in_progress(false);
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011335
Dustin Brown70111822017-03-30 15:31:40 -070011336 return 0;
11337 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070011338 }
11339
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080011340 /* free user wowl patterns */
11341 hdd_free_user_wowl_ptrns();
11342
Arun Khandavallifae92942016-08-01 13:31:08 +053011343 switch (hdd_ctx->driver_status) {
11344 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011345 hdd_debug("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011346 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011347 case DRIVER_MODULES_CLOSED:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011348 hdd_debug("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011349 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011350 case DRIVER_MODULES_ENABLED:
Dustin Brown1a20b082018-08-03 17:27:15 -070011351 hdd_info("Wlan transitioning (CLOSED <- ENABLED)");
11352
11353 if (hdd_get_conparam() == QDF_GLOBAL_FTM_MODE)
11354 break;
Dustin Brown550f6d22017-12-14 15:44:01 -080011355
Komal Seelamf2136bb2016-09-28 18:30:44 +053011356 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053011357 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011358 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053011359 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011360 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011361 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011362 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080011363
Arun Khandavallifae92942016-08-01 13:31:08 +053011364 break;
11365 default:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011366 QDF_DEBUG_PANIC("Unknown driver state:%d",
Arun Khandavallifae92942016-08-01 13:31:08 +053011367 hdd_ctx->driver_status);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011368 ret = -EINVAL;
11369 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011370 }
11371
Arunk Khandavalli890f6d92018-10-30 20:18:28 +053011372 hdd_sysfs_destroy_powerstats_interface();
Amar Singhal18081642018-01-26 16:04:13 -080011373 hdd_sysfs_destroy_version_interface();
Arunk Khandavalli890f6d92018-10-30 20:18:28 +053011374 hdd_sysfs_destroy_driver_root_obj();
Dustin Brown550f6d22017-12-14 15:44:01 -080011375 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080011376
Rajeev Kumarbe021242017-02-16 16:12:23 -080011377 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053011378 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11379 hdd_err("Failed to process post CDS disable Modules! :%d",
11380 qdf_status);
11381 ret = -EINVAL;
11382 QDF_ASSERT(0);
11383 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011384
Sourav Mohapatra674925f2018-04-16 11:16:58 +053011385 /* De-register the SME callbacks */
11386 hdd_deregister_cb(hdd_ctx);
11387
psimhadeea0a12017-12-18 14:50:02 -080011388 hdd_runtime_suspend_context_deinit(hdd_ctx);
11389
Dustin Brown1dbefe62018-09-11 16:32:03 -070011390 qdf_status = cds_dp_close(hdd_ctx->psoc);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011391 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11392 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
11393 ret = -EINVAL;
11394 QDF_ASSERT(0);
11395 }
11396
Dustin Brown1dbefe62018-09-11 16:32:03 -070011397 qdf_status = cds_close(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053011398 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011399 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053011400 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011401 QDF_ASSERT(0);
11402 }
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053011403
11404 qdf_status = wbuff_module_deinit();
11405 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
11406 hdd_err("WBUFF de-init unsuccessful; status: %d", qdf_status);
11407
Sandeep Puligillab7beb472018-08-13 22:54:20 -070011408 hdd_component_pdev_close(hdd_ctx->pdev);
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053011409
Dustin Brown1dbefe62018-09-11 16:32:03 -070011410 hdd_component_psoc_close(hdd_ctx->psoc);
Dustin Brown07901ec2018-09-07 11:02:41 -070011411 dispatcher_pdev_close(hdd_ctx->pdev);
Liangwei Dong50a64a72018-01-11 01:17:00 -050011412 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
11413 if (ret) {
11414 hdd_err("Failed to destroy pdev; errno:%d", ret);
11415 QDF_ASSERT(0);
11416 }
11417
11418 /*
11419 * Reset total mac phy during module stop such that during
11420 * next module start same psoc is used to populate new service
11421 * ready data
11422 */
Dustin Brown1dbefe62018-09-11 16:32:03 -070011423 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->psoc);
Arunk Khandavallia6305a32018-01-25 11:19:18 +053011424 if (tgt_hdl)
11425 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
11426
Liangwei Dong50a64a72018-01-11 01:17:00 -050011427
Arun Khandavallifae92942016-08-01 13:31:08 +053011428 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
11429 if (!hif_ctx) {
11430 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011431 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011432 }
11433
Arunk Khandavalli4b404332017-09-26 12:46:00 +053011434 if (hdd_ctx->target_hw_name) {
11435 qdf_mem_free(hdd_ctx->target_hw_name);
11436 hdd_ctx->target_hw_name = NULL;
11437 }
11438
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053011439 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053011440
11441 ol_cds_free();
11442
Dustin Brownc2a156e2018-10-25 16:56:27 -070011443 if (IS_IDLE_STOP) {
Arun Khandavallifae92942016-08-01 13:31:08 +053011444 ret = pld_power_off(qdf_ctx->dev);
11445 if (ret)
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011446 hdd_err("Failed to power down device; errno:%d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053011447 }
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011448
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011449 /* Free the cache channels of the command SET_DISABLE_CHANNEL_LIST */
11450 wlan_hdd_free_cache_channels(hdd_ctx);
Arunk Khandavalli847969d2017-09-25 15:15:36 +053011451
Dustin Brown29533f22018-07-24 13:11:56 -070011452 hdd_check_for_leaks(hdd_ctx, is_recovery_stop);
Dustin Brown26b3d042017-12-21 11:13:27 -080011453 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080011454
Arunk Khandavalli847969d2017-09-25 15:15:36 +053011455 /* Once the firmware sequence is completed reset this flag */
11456 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053011457 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080011458 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053011459
Kai Liueabb1df2018-11-08 14:58:54 +080011460 pld_request_bus_bandwidth(hdd_ctx->parent_dev, PLD_BUS_WIDTH_NONE);
11461
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011462done:
11463 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011464 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011465 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4bc0a622017-12-06 15:56:50 -080011466
Dustin Browne74003f2018-03-14 12:51:58 -070011467 hdd_exit();
Arun Khandavallifae92942016-08-01 13:31:08 +053011468
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011469 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053011470}
11471
Arun Khandavallifae92942016-08-01 13:31:08 +053011472
Wen Gong3f003382018-05-14 14:26:37 +080011473#ifdef WLAN_FEATURE_MEMDUMP_ENABLE
Arun Khandavallifae92942016-08-01 13:31:08 +053011474/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011475 * hdd_state_info_dump() - prints state information of hdd layer
11476 * @buf: buffer pointer
11477 * @size: size of buffer to be filled
11478 *
11479 * This function is used to dump state information of hdd layer
11480 *
11481 * Return: None
11482 */
11483static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
11484{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011485 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070011486 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070011487 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011488 uint16_t len = 0;
11489 char *buf = *buf_ptr;
11490
11491 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11492 if (!hdd_ctx) {
11493 hdd_err("Failed to get hdd context ");
11494 return;
11495 }
11496
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011497 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011498
11499 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070011500 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011501 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080011502 "\n is_scheduler_suspended %d",
11503 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011504
Dustin Brown920397d2017-12-13 16:27:50 -080011505 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011506 if (adapter->dev)
11507 len += scnprintf(buf + len, *size - len,
11508 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080011509 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011510 "\n device_mode: %d", adapter->device_mode);
11511 switch (adapter->device_mode) {
11512 case QDF_STA_MODE:
11513 case QDF_P2P_CLIENT_MODE:
11514 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11515 len += scnprintf(buf + len, *size - len,
11516 "\n connState: %d",
11517 hdd_sta_ctx->conn_info.connState);
11518 break;
11519
11520 default:
11521 break;
11522 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011523 }
11524
11525 *size -= len;
11526 *buf_ptr += len;
11527}
11528
11529/**
11530 * hdd_register_debug_callback() - registration function for hdd layer
11531 * to print hdd state information
11532 *
11533 * Return: None
11534 */
11535static void hdd_register_debug_callback(void)
11536{
11537 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
11538}
Wen Gong3f003382018-05-14 14:26:37 +080011539#else /* WLAN_FEATURE_MEMDUMP_ENABLE */
Wen Gongaa6d55d2018-04-26 16:33:21 +080011540static void hdd_register_debug_callback(void)
11541{
11542}
Wen Gong3f003382018-05-14 14:26:37 +080011543#endif /* WLAN_FEATURE_MEMDUMP_ENABLE */
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011544
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053011545/*
11546 * wlan_init_bug_report_lock() - Initialize bug report lock
11547 *
11548 * This function is used to create bug report lock
11549 *
11550 * Return: None
11551 */
11552static void wlan_init_bug_report_lock(void)
11553{
Jeff Johnson2b6982c2018-05-29 14:56:11 -070011554 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053011555
11556 p_cds_context = cds_get_global_context();
11557 if (!p_cds_context) {
11558 hdd_err("cds context is NULL");
11559 return;
11560 }
11561
11562 qdf_spinlock_create(&p_cds_context->bug_report_lock);
11563}
11564
Nirav Shahd21a2e32018-04-20 16:34:43 +053011565#ifdef CONFIG_DP_TRACE
Mohit Khannaf8f96822017-05-17 17:11:59 -070011566void hdd_dp_trace_init(struct hdd_config *config)
11567{
Mohit Khannaf8f96822017-05-17 17:11:59 -070011568 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
11569 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
11570 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
11571 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
11572 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
11573 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
11574 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080011575 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070011576
Nirav Shahd21a2e32018-04-20 16:34:43 +053011577 if (!config->enable_dp_trace) {
11578 hdd_err("dp trace is disabled from ini");
11579 return;
11580 }
11581
Mohit Khannaf8f96822017-05-17 17:11:59 -070011582 hdd_string_to_u8_array(config->dp_trace_config, config_params,
11583 &num_entries, sizeof(config_params));
11584
11585 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080011586 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080011587 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080011588 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080011589 else if (bw_compute_interval > 1000) {
11590 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
11591 thresh_time_limit = 1;
11592 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070011593 hdd_err("busBandwidthComputeInterval is 0, using defaults");
11594
11595 switch (num_entries) {
11596 case 4:
11597 proto_bitmap = config_params[3];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011598 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011599 case 3:
11600 verbosity = config_params[2];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011601 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011602 case 2:
11603 thresh = config_params[1];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011604 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011605 case 1:
11606 live_mode = config_params[0];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011607 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011608 default:
Dustin Browna7bb6ae2018-08-16 16:51:50 -070011609 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
11610 live_mode, thresh, thresh_time_limit,
11611 verbosity, proto_bitmap);
Mohit Khannaf8f96822017-05-17 17:11:59 -070011612 };
11613
11614 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
11615 verbosity, proto_bitmap);
11616
11617}
Nirav Shahd21a2e32018-04-20 16:34:43 +053011618#endif
11619
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011620#ifdef DISABLE_CHANNEL_LIST
Dustin Brown623e7e32018-09-05 14:27:50 -070011621static QDF_STATUS wlan_hdd_cache_chann_mutex_create(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011622{
11623 return qdf_mutex_create(&hdd_ctx->cache_channel_lock);
11624}
11625#else
Dustin Brown623e7e32018-09-05 14:27:50 -070011626static QDF_STATUS wlan_hdd_cache_chann_mutex_create(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011627{
Dustin Brown623e7e32018-09-05 14:27:50 -070011628 return QDF_STATUS_SUCCESS;
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011629}
11630#endif
11631
Dustin Brown693b5352019-01-17 10:00:31 -080011632static QDF_STATUS hdd_open_adapter_no_trans(struct hdd_context *hdd_ctx,
11633 enum QDF_OPMODE op_mode,
11634 const char *iface_name,
11635 uint8_t *mac_addr_bytes)
11636{
11637 struct hdd_vdev_sync *vdev_sync;
11638 struct hdd_adapter *adapter;
11639 QDF_STATUS status;
11640 int errno;
11641
11642 QDF_BUG(rtnl_is_locked());
Dustin Brown693b5352019-01-17 10:00:31 -080011643
Dustin Brownd01590f2019-01-31 16:52:06 -080011644 errno = hdd_vdev_sync_create(hdd_ctx->parent_dev, &vdev_sync);
Dustin Brown693b5352019-01-17 10:00:31 -080011645 if (errno)
11646 return qdf_status_from_os_return(errno);
11647
11648 adapter = hdd_open_adapter(hdd_ctx, op_mode, iface_name,
11649 mac_addr_bytes, NET_NAME_UNKNOWN, true);
11650 if (!adapter) {
11651 status = QDF_STATUS_E_INVAL;
11652 goto destroy_sync;
11653 }
11654
11655 hdd_vdev_sync_register(adapter->dev, vdev_sync);
11656
11657 return QDF_STATUS_SUCCESS;
11658
11659destroy_sync:
11660 hdd_vdev_sync_destroy(vdev_sync);
11661
11662 return status;
11663}
11664
11665#ifdef WLAN_OPEN_P2P_INTERFACE
11666/**
11667 * hdd_open_p2p_interface - Open P2P interface
11668 * @hdd_ctx: HDD context
11669 *
11670 * Return: QDF_STATUS
11671 */
11672static QDF_STATUS hdd_open_p2p_interface(struct hdd_context *hdd_ctx)
11673{
11674 QDF_STATUS status;
11675 bool p2p_dev_addr_admin;
11676 bool is_p2p_locally_administered = false;
11677
11678 cfg_p2p_get_device_addr_admin(hdd_ctx->psoc, &p2p_dev_addr_admin);
11679
11680 if (p2p_dev_addr_admin) {
11681 if (hdd_ctx->num_provisioned_addr &&
11682 !(hdd_ctx->provisioned_mac_addr[0].bytes[0] & 0x02)) {
11683 hdd_ctx->p2p_device_address =
11684 hdd_ctx->provisioned_mac_addr[0];
11685
11686 /*
11687 * Generate the P2P Device Address. This consists of
11688 * the device's primary MAC address with the locally
11689 * administered bit set.
11690 */
11691
11692 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
11693 is_p2p_locally_administered = true;
11694 } else if (!(hdd_ctx->derived_mac_addr[0].bytes[0] & 0x02)) {
11695 hdd_ctx->p2p_device_address =
11696 hdd_ctx->derived_mac_addr[0];
11697 /*
11698 * Generate the P2P Device Address. This consists of
11699 * the device's primary MAC address with the locally
11700 * administered bit set.
11701 */
11702 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
11703 is_p2p_locally_administered = true;
11704 }
11705 }
11706 if (!is_p2p_locally_administered) {
11707 uint8_t *p2p_dev_addr;
11708
11709 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx,
11710 QDF_P2P_DEVICE_MODE);
11711 if (!p2p_dev_addr) {
11712 hdd_err("Failed to get MAC address for new p2p device");
11713 return QDF_STATUS_E_INVAL;
11714 }
11715
11716 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
11717 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
11718 }
11719
11720 status = hdd_open_adapter_no_trans(hdd_ctx, QDF_P2P_DEVICE_MODE,
11721 "p2p%d",
11722 hdd_ctx->p2p_device_address.bytes);
11723 if (QDF_IS_STATUS_ERROR(status)) {
11724 hdd_err("Failed to open p2p interface");
11725 return QDF_STATUS_E_INVAL;
11726 }
11727
11728 return QDF_STATUS_SUCCESS;
11729}
11730#else
11731static inline QDF_STATUS hdd_open_p2p_interface(struct hdd_context *hdd_ctx)
11732{
11733 return QDF_STATUS_SUCCESS;
11734}
11735#endif
11736
11737static QDF_STATUS hdd_open_ocb_interface(struct hdd_context *hdd_ctx)
11738{
11739 QDF_STATUS status;
11740 uint8_t *mac_addr;
11741
11742 mac_addr = wlan_hdd_get_intf_addr(hdd_ctx, QDF_OCB_MODE);
11743 status = hdd_open_adapter_no_trans(hdd_ctx, QDF_OCB_MODE,
11744 "wlanocb%d", mac_addr);
11745 if (QDF_IS_STATUS_ERROR(status))
11746 hdd_err("Failed to open 802.11p interface");
11747
11748 return status;
11749}
11750
11751static QDF_STATUS hdd_open_concurrent_interface(struct hdd_context *hdd_ctx)
11752{
11753 QDF_STATUS status;
11754 const char *iface_name;
11755 uint8_t *mac_addr;
11756
11757 if (qdf_str_eq(hdd_ctx->config->enable_concurrent_sta, ""))
11758 return QDF_STATUS_SUCCESS;
11759
11760 iface_name = hdd_ctx->config->enable_concurrent_sta;
11761 mac_addr = wlan_hdd_get_intf_addr(hdd_ctx, QDF_STA_MODE);
11762 status = hdd_open_adapter_no_trans(hdd_ctx, QDF_STA_MODE,
11763 iface_name, mac_addr);
11764 if (QDF_IS_STATUS_ERROR(status))
11765 hdd_err("Failed to open concurrent station interface");
11766
11767 return status;
11768}
11769
Dustin Brown61cc3932018-10-18 16:12:13 -070011770static QDF_STATUS
11771hdd_open_adapters_for_mission_mode(struct hdd_context *hdd_ctx)
Dustin Browna2deeb72018-10-18 14:19:27 -070011772{
Dustin Browna2deeb72018-10-18 14:19:27 -070011773 enum dot11p_mode dot11p_mode;
Dustin Brown61cc3932018-10-18 16:12:13 -070011774 QDF_STATUS status;
Dustin Brown693b5352019-01-17 10:00:31 -080011775 uint8_t *mac_addr;
Dustin Browna2deeb72018-10-18 14:19:27 -070011776
11777 ucfg_mlme_get_dot11p_mode(hdd_ctx->psoc, &dot11p_mode);
11778
11779 /* Create only 802.11p interface? */
11780 if (dot11p_mode == CFG_11P_STANDALONE)
Dustin Brown61cc3932018-10-18 16:12:13 -070011781 return hdd_open_ocb_interface(hdd_ctx);
Dustin Browna2deeb72018-10-18 14:19:27 -070011782
Dustin Brown693b5352019-01-17 10:00:31 -080011783 mac_addr = wlan_hdd_get_intf_addr(hdd_ctx, QDF_STA_MODE);
11784 status = hdd_open_adapter_no_trans(hdd_ctx, QDF_STA_MODE,
11785 "wlan%d", mac_addr);
11786 if (QDF_IS_STATUS_ERROR(status))
11787 return status;
Dustin Browna2deeb72018-10-18 14:19:27 -070011788
Dustin Brown61cc3932018-10-18 16:12:13 -070011789 /* opening concurrent STA is best effort, continue on error */
11790 hdd_open_concurrent_interface(hdd_ctx);
Dustin Browna2deeb72018-10-18 14:19:27 -070011791
Dustin Brown61cc3932018-10-18 16:12:13 -070011792 status = hdd_open_p2p_interface(hdd_ctx);
11793 if (status)
Dustin Browna2deeb72018-10-18 14:19:27 -070011794 goto err_close_adapters;
11795
11796 /* Open 802.11p Interface */
11797 if (dot11p_mode == CFG_11P_CONCURRENT) {
Dustin Brown61cc3932018-10-18 16:12:13 -070011798 status = hdd_open_ocb_interface(hdd_ctx);
11799 if (QDF_IS_STATUS_ERROR(status))
Dustin Browna2deeb72018-10-18 14:19:27 -070011800 goto err_close_adapters;
11801 }
11802
Dustin Brown61cc3932018-10-18 16:12:13 -070011803 return QDF_STATUS_SUCCESS;
Dustin Browna2deeb72018-10-18 14:19:27 -070011804
11805err_close_adapters:
11806 hdd_close_all_adapters(hdd_ctx, true);
11807
Dustin Brown61cc3932018-10-18 16:12:13 -070011808 return status;
Dustin Browna2deeb72018-10-18 14:19:27 -070011809}
11810
Dustin Brown61cc3932018-10-18 16:12:13 -070011811static QDF_STATUS hdd_open_adapters_for_ftm_mode(struct hdd_context *hdd_ctx)
Dustin Browna2deeb72018-10-18 14:19:27 -070011812{
Dustin Brown693b5352019-01-17 10:00:31 -080011813 uint8_t *mac_addr = wlan_hdd_get_intf_addr(hdd_ctx, QDF_FTM_MODE);
Dustin Brown61cc3932018-10-18 16:12:13 -070011814
Dustin Brown693b5352019-01-17 10:00:31 -080011815 return hdd_open_adapter_no_trans(hdd_ctx, QDF_FTM_MODE,
11816 "wlan%d", mac_addr);
Dustin Brown61cc3932018-10-18 16:12:13 -070011817}
11818
11819static QDF_STATUS
11820hdd_open_adapters_for_monitor_mode(struct hdd_context *hdd_ctx)
11821{
Dustin Brown693b5352019-01-17 10:00:31 -080011822 uint8_t *mac_addr = wlan_hdd_get_intf_addr(hdd_ctx, QDF_MONITOR_MODE);
Dustin Brown61cc3932018-10-18 16:12:13 -070011823
Dustin Brown693b5352019-01-17 10:00:31 -080011824 return hdd_open_adapter_no_trans(hdd_ctx, QDF_MONITOR_MODE,
11825 "wlan%d", mac_addr);
Dustin Brown61cc3932018-10-18 16:12:13 -070011826}
11827
11828static QDF_STATUS hdd_open_adapters_for_epping_mode(struct hdd_context *hdd_ctx)
11829{
Dustin Browna2deeb72018-10-18 14:19:27 -070011830 QDF_STATUS status;
Dustin Brown61cc3932018-10-18 16:12:13 -070011831 qdf_device_t qdf_dev;
Dustin Browna2deeb72018-10-18 14:19:27 -070011832
11833 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11834 QDF_BUG(qdf_dev);
11835 if (!qdf_dev)
Dustin Brown61cc3932018-10-18 16:12:13 -070011836 return QDF_STATUS_E_INVAL;
11837
11838 status = epping_open();
11839 if (QDF_IS_STATUS_ERROR(status))
11840 return status;
11841
11842 if (epping_enable(qdf_dev->dev)) {
11843 status = QDF_STATUS_E_INVAL;
11844 goto epping_close;
11845 }
11846
11847 return QDF_STATUS_SUCCESS;
11848
11849epping_close:
11850 epping_close();
11851
11852 return status;
11853}
11854
11855typedef QDF_STATUS (*hdd_open_mode_handler)(struct hdd_context *hdd_ctx);
11856
11857static const hdd_open_mode_handler
11858hdd_open_mode_handlers[QDF_GLOBAL_MAX_MODE] = {
11859 [QDF_GLOBAL_MISSION_MODE] = hdd_open_adapters_for_mission_mode,
11860 [QDF_GLOBAL_FTM_MODE] = hdd_open_adapters_for_ftm_mode,
11861 [QDF_GLOBAL_MONITOR_MODE] = hdd_open_adapters_for_monitor_mode,
11862 [QDF_GLOBAL_EPPING_MODE] = hdd_open_adapters_for_epping_mode,
11863};
11864
Dustin Brown92bd8382018-10-31 15:49:46 -070011865static QDF_STATUS hdd_open_adapters_for_mode(struct hdd_context *hdd_ctx,
11866 enum QDF_GLOBAL_MODE driver_mode)
Dustin Brown61cc3932018-10-18 16:12:13 -070011867{
11868 QDF_STATUS status;
11869
11870 if (driver_mode < 0 ||
11871 driver_mode >= QDF_GLOBAL_MAX_MODE ||
11872 !hdd_open_mode_handlers[driver_mode]) {
11873 hdd_err("Driver mode %d not supported", driver_mode);
11874 return -ENOTSUPP;
11875 }
Dustin Browna2deeb72018-10-18 14:19:27 -070011876
11877 hdd_hold_rtnl_lock();
Dustin Brown61cc3932018-10-18 16:12:13 -070011878 status = hdd_open_mode_handlers[driver_mode](hdd_ctx);
Dustin Browna2deeb72018-10-18 14:19:27 -070011879 hdd_release_rtnl_lock();
11880
Dustin Brown92bd8382018-10-31 15:49:46 -070011881 return status;
Dustin Browna2deeb72018-10-18 14:19:27 -070011882}
11883
Dustin Brown623e7e32018-09-05 14:27:50 -070011884int hdd_wlan_startup(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011885{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011886 QDF_STATUS status;
Dustin Brown623e7e32018-09-05 14:27:50 -070011887 int errno;
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +053011888 bool is_imps_enabled;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011889
Dustin Brown491d54b2018-03-14 12:39:11 -070011890 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011891
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011892 hdd_action_oui_config(hdd_ctx);
11893
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053011894 qdf_nbuf_init_replenish_timer();
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011895
Dustin Brown623e7e32018-09-05 14:27:50 -070011896 status = wlan_hdd_cache_chann_mutex_create(hdd_ctx);
11897 if (QDF_IS_STATUS_ERROR(status))
11898 return qdf_status_to_os_return(status);
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011899
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053011900#ifdef FEATURE_WLAN_CH_AVOID
11901 mutex_init(&hdd_ctx->avoid_freq_lock);
11902#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053011903
Naveen Rawate02f8f52018-04-05 11:58:04 -070011904 osif_request_manager_init();
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053011905 qdf_atomic_init(&hdd_ctx->con_mode_flag);
Dustin Brown021cecd2017-12-11 13:56:43 -080011906 hdd_driver_memdump_init();
Dustin Brown86d196b2018-08-02 11:51:49 -070011907 hdd_bus_bandwidth_init(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -080011908
Arunk Khandavalli5ff0375472019-01-11 17:26:47 +053011909#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
11910 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
11911 QDF_TIMER_TYPE_SW,
11912 hdd_skip_acs_scan_timer_handler,
11913 hdd_ctx);
11914 if (QDF_IS_STATUS_ERROR(status))
11915 hdd_err("Failed to init ACS Skip timer");
11916 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
11917#endif
11918
Dustin Brown623e7e32018-09-05 14:27:50 -070011919 errno = hdd_wlan_start_modules(hdd_ctx, false);
11920 if (errno) {
11921 hdd_err("Failed to start modules; errno:%d", errno);
11922 goto memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011923 }
11924
Yingying Tang80e15f32016-09-27 18:23:01 +080011925 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011926
Dustin Brown623e7e32018-09-05 14:27:50 -070011927 hdd_ctx->mac_handle = cds_get_context(QDF_MODULE_ID_SME);
11928 if (!hdd_ctx->mac_handle) {
Jeff Johnson16528362018-06-14 12:34:16 -070011929 hdd_err("Mac Handle is null");
Dustin Brown623e7e32018-09-05 14:27:50 -070011930 goto stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011931 }
11932
Dustin Brown623e7e32018-09-05 14:27:50 -070011933 errno = hdd_wiphy_init(hdd_ctx);
11934 if (errno) {
11935 hdd_err("Failed to initialize wiphy; errno:%d", errno);
11936 goto stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011937 }
11938
Nirav Shahd21a2e32018-04-20 16:34:43 +053011939 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053011940
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053011941 errno = hdd_initialize_mac_address(hdd_ctx);
11942 if (errno) {
11943 hdd_err("MAC initializtion failed: %d", errno);
11944 goto unregister_wiphy;
11945 }
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080011946
Dustin Brown623e7e32018-09-05 14:27:50 -070011947 errno = register_netdevice_notifier(&hdd_netdev_notifier);
11948 if (errno) {
11949 hdd_err("register_netdevice_notifier failed; errno:%d", errno);
11950 goto unregister_wiphy;
Paul Zhangfb02f452017-12-22 11:58:43 +080011951 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053011952
Dustin Brown623e7e32018-09-05 14:27:50 -070011953 errno = register_reboot_notifier(&system_reboot_notifier);
11954 if (errno) {
11955 hdd_err("Failed to register reboot notifier; errno:%d", errno);
11956 goto unregister_netdev;
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011957 }
11958
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080011959 wlan_hdd_update_11n_mode(hdd_ctx->config);
11960
Arunk Khandavalli40943af2017-05-15 19:25:34 +053011961 hdd_lpass_notify_wlan_version(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011962
Dustin Brown623e7e32018-09-05 14:27:50 -070011963 errno = hdd_register_notifiers(hdd_ctx);
11964 if (errno)
11965 goto unregister_reboot;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070011966
Paul Zhangfb02f452017-12-22 11:58:43 +080011967 status = wlansap_global_init();
Dustin Brown92bd8382018-10-31 15:49:46 -070011968 if (QDF_IS_STATUS_ERROR(status))
11969 goto unregister_notifiers;
Paul Zhangfb02f452017-12-22 11:58:43 +080011970
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +053011971 ucfg_mlme_is_imps_enabled(hdd_ctx->psoc, &is_imps_enabled);
11972 hdd_set_idle_ps_config(hdd_ctx, is_imps_enabled);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011973
Dustin Brown92bd8382018-10-31 15:49:46 -070011974 hdd_exit();
11975
11976 return 0;
11977
11978unregister_notifiers:
11979 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011980
Dustin Brown623e7e32018-09-05 14:27:50 -070011981unregister_reboot:
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011982 unregister_reboot_notifier(&system_reboot_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011983
Dustin Brown623e7e32018-09-05 14:27:50 -070011984unregister_netdev:
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011985 unregister_netdevice_notifier(&hdd_netdev_notifier);
11986
Dustin Brown623e7e32018-09-05 14:27:50 -070011987unregister_wiphy:
Rachit Kankane30807332018-06-27 18:39:36 +053011988 qdf_dp_trace_deinit();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011989 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011990
Dustin Brown623e7e32018-09-05 14:27:50 -070011991stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011992 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053011993
Dustin Brown623e7e32018-09-05 14:27:50 -070011994memdump_deinit:
Dustin Brown86d196b2018-08-02 11:51:49 -070011995 hdd_bus_bandwidth_deinit(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -080011996 hdd_driver_memdump_deinit();
Naveen Rawate02f8f52018-04-05 11:58:04 -070011997 osif_request_manager_deinit();
Dustin Brown623e7e32018-09-05 14:27:50 -070011998 qdf_nbuf_deinit_replenish_timer();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070011999
Nachiket Kukade8003d252017-03-30 15:55:58 +053012000 if (cds_is_fw_down())
12001 hdd_err("Not setting the complete event as fw is down");
12002 else
Dustin Brown623e7e32018-09-05 14:27:50 -070012003 hdd_start_complete(errno);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012004
Dustin Browne74003f2018-03-14 12:51:58 -070012005 hdd_exit();
Dustin Brown92bd8382018-10-31 15:49:46 -070012006
Dustin Brown623e7e32018-09-05 14:27:50 -070012007 return errno;
Dustin Brown92bd8382018-10-31 15:49:46 -070012008}
12009
12010QDF_STATUS hdd_psoc_create_vdevs(struct hdd_context *hdd_ctx)
12011{
12012 enum QDF_GLOBAL_MODE driver_mode = hdd_get_conparam();
12013 QDF_STATUS status;
12014
12015 status = hdd_open_adapters_for_mode(hdd_ctx, driver_mode);
12016 if (QDF_IS_STATUS_ERROR(status)) {
12017 hdd_err("Failed to create vdevs; status:%d", status);
12018 return status;
12019 }
12020
12021 if (hdd_ctx->rps)
12022 hdd_set_rps_cpu_mask(hdd_ctx);
12023
12024 if (driver_mode != QDF_GLOBAL_FTM_MODE)
12025 hdd_psoc_idle_timer_start(hdd_ctx);
12026
12027 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012028}
12029
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012030/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012031 * hdd_wlan_update_target_info() - update target type info
12032 * @hdd_ctx: HDD context
12033 * @context: hif context
12034 *
12035 * Update target info received from firmware in hdd context
12036 * Return:None
12037 */
12038
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012039void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053012040{
12041 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
12042
12043 if (!tgt_info) {
12044 hdd_err("Target info is Null");
12045 return;
12046 }
12047
12048 hdd_ctx->target_type = tgt_info->target_type;
12049}
12050
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053012051void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp, void *context)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012052{
12053 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012054 int status;
12055 struct hdd_adapter *adapter = NULL;
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070012056 struct osif_request *request = NULL;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012057
Dustin Brown491d54b2018-03-14 12:39:11 -070012058 hdd_enter();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012059
12060 if (!rsp) {
12061 hdd_err("data is null");
12062 return;
12063 }
12064
12065 status = wlan_hdd_validate_context(hdd_ctx);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053012066 if (status != 0)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012067 return;
12068
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070012069 request = osif_request_get(context);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053012070 if (!request) {
12071 hdd_err("obselete request");
12072 return;
12073 }
12074
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012075 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
12076 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
12077 hdd_err("Invalid adapter or adapter has invalid magic");
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070012078 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012079 return;
12080 }
12081
Alok Kumarce2c29a2018-10-12 15:44:02 +053012082 hdd_debug("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
12083 hdd_debug("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
12084 hdd_debug("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
12085 hdd_debug("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
12086 hdd_debug("rsp->out_of_order_arp_rsp_drop_cnt :%x",
12087 rsp->out_of_order_arp_rsp_drop_cnt);
12088 hdd_debug("rsp->dad_detected :%x", rsp->dad_detected);
12089 hdd_debug("rsp->connect_status :%x", rsp->connect_status);
12090 hdd_debug("rsp->ba_session_establishment_status :%x",
12091 rsp->ba_session_establishment_status);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012092
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012093 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012094 adapter->dad |= rsp->dad_detected;
12095 adapter->con_status = rsp->connect_status;
12096
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053012097 /* Flag true indicates connectivity check stats present. */
12098 if (rsp->connect_stats_present) {
Alok Kumarce2c29a2018-10-12 15:44:02 +053012099 hdd_debug("rsp->tcp_ack_recvd :%x", rsp->tcp_ack_recvd);
12100 hdd_debug("rsp->icmpv4_rsp_recvd :%x", rsp->icmpv4_rsp_recvd);
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053012101 adapter->hdd_stats.hdd_tcp_stats.rx_fw_cnt = rsp->tcp_ack_recvd;
12102 adapter->hdd_stats.hdd_icmpv4_stats.rx_fw_cnt =
12103 rsp->icmpv4_rsp_recvd;
12104 }
12105
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070012106 osif_request_complete(request);
12107 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012108
Dustin Browne74003f2018-03-14 12:51:58 -070012109 hdd_exit();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012110}
12111
Visweswara Tanuku633976b2019-01-07 16:13:12 +053012112#ifdef WLAN_FEATURE_MOTION_DETECTION
12113/**
12114 * hdd_md_host_evt_cb - Callback for Motion Detection Event
12115 * @ctx: HDD context
12116 * @event: motion detect event
12117 *
12118 * Callback for Motion Detection Event. Re-enables Motion
12119 * Detection again upon event
12120 *
12121 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and
12122 * QDF_STATUS_E_FAILURE on failure
12123 */
12124QDF_STATUS hdd_md_host_evt_cb(void *ctx, struct sir_md_evt *event)
12125{
12126 struct hdd_adapter *adapter = NULL;
12127 struct hdd_context *hdd_ctx;
12128 QDF_STATUS status;
12129 struct sme_motion_det_en motion_det;
12130
12131 if (!ctx || !event)
12132 return QDF_STATUS_E_INVAL;
12133
12134 hdd_ctx = (struct hdd_context *)ctx;
12135 status = wlan_hdd_validate_context(hdd_ctx);
12136 if (0 != status)
12137 return QDF_STATUS_E_INVAL;
12138
12139 adapter = hdd_get_adapter_by_vdev(hdd_ctx, event->vdev_id);
12140 if (!adapter || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
12141 hdd_err("Invalid adapter or adapter has invalid magic");
12142 return QDF_STATUS_E_INVAL;
12143 }
12144
12145 hdd_debug("Motion Detection CB vdev_id=%u, status=%u",
12146 event->vdev_id, event->status);
12147
12148 if (adapter->motion_detection_mode) {
12149 motion_det.vdev_id = event->vdev_id;
12150 motion_det.enable = 1;
12151 hdd_debug("Motion Detect CB -> Enable Motion Detection again");
12152 sme_motion_det_enable(hdd_ctx->mac_handle, &motion_det);
12153 }
12154
12155 return QDF_STATUS_SUCCESS;
12156}
12157#endif /* WLAN_FEATURE_MOTION_DETECTION */
12158
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012159/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012160 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012161 * @hdd_ctx: HDD context
12162 *
12163 * Register the HDD callbacks to CDS/SME.
12164 *
12165 * Return: 0 for success or Error code for failure
12166 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012167int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012168{
12169 QDF_STATUS status;
12170 int ret = 0;
Jeff Johnson16528362018-06-14 12:34:16 -070012171 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012172
Dustin Brown491d54b2018-03-14 12:39:11 -070012173 hdd_enter();
Sourav Mohapatra674925f2018-04-16 11:16:58 +053012174 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
12175 hdd_err("in ftm mode, no need to register callbacks");
12176 return ret;
12177 }
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012178
Jeff Johnson16528362018-06-14 12:34:16 -070012179 mac_handle = hdd_ctx->mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012180
Jeff Johnson16528362018-06-14 12:34:16 -070012181 sme_register_oem_data_rsp_callback(mac_handle,
12182 hdd_send_oem_data_rsp_msg);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012183
Jeff Johnson16528362018-06-14 12:34:16 -070012184 sme_register_mgmt_frame_ind_callback(mac_handle,
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053012185 hdd_indicate_mgmt_frame);
Jeff Johnson16528362018-06-14 12:34:16 -070012186 sme_set_tsfcb(mac_handle, hdd_get_tsf_cb, hdd_ctx);
Jeff Johnson16528362018-06-14 12:34:16 -070012187 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012188 wlan_hdd_cfg80211_stats_ext_callback);
12189
Jeff Johnson16528362018-06-14 12:34:16 -070012190 sme_ext_scan_register_callback(mac_handle,
12191 wlan_hdd_cfg80211_extscan_callback);
12192 sme_stats_ext2_register_callback(mac_handle,
lifeng66831662017-05-19 16:01:35 +080012193 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012194
Jeff Johnson16528362018-06-14 12:34:16 -070012195 sme_set_rssi_threshold_breached_cb(mac_handle,
12196 hdd_rssi_threshold_breached);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012197
Jeff Johnson16528362018-06-14 12:34:16 -070012198 sme_set_link_layer_stats_ind_cb(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012199 wlan_hdd_cfg80211_link_layer_stats_callback);
12200
Jeff Johnson16528362018-06-14 12:34:16 -070012201 sme_rso_cmd_status_cb(mac_handle, wlan_hdd_rso_cmd_status_cb);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053012202
Jeff Johnson16528362018-06-14 12:34:16 -070012203 sme_set_link_layer_ext_cb(mac_handle,
Zhang Qianca38fb12016-12-23 11:10:48 +080012204 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
12205
Jeff Johnson16528362018-06-14 12:34:16 -070012206 status = sme_set_lost_link_info_cb(mac_handle,
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053012207 hdd_lost_link_info_cb);
12208 /* print error and not block the startup process */
12209 if (!QDF_IS_STATUS_SUCCESS(status))
12210 hdd_err("set lost link info callback failed");
12211
Poddar, Siddarth34872782017-08-10 14:08:51 +053012212 ret = hdd_register_data_stall_detect_cb();
12213 if (ret) {
12214 hdd_err("Register data stall detect detect callback failed.");
12215 return ret;
12216 }
12217
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012218 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
12219
Jeff Johnson16528362018-06-14 12:34:16 -070012220 sme_register_set_connection_info_cb(mac_handle,
12221 hdd_set_connection_in_progress,
12222 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053012223
Jeff Johnson16528362018-06-14 12:34:16 -070012224 status = sme_congestion_register_callback(mac_handle,
12225 hdd_update_cca_info_cb);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053012226 if (!QDF_IS_STATUS_SUCCESS(status))
12227 hdd_err("set congestion callback failed");
12228
Jeff Johnson16528362018-06-14 12:34:16 -070012229 status = sme_set_bt_activity_info_cb(mac_handle,
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053012230 hdd_bt_activity_cb);
12231 if (!QDF_IS_STATUS_SUCCESS(status))
12232 hdd_err("set bt activity info callback failed");
12233
Jeff Johnson16528362018-06-14 12:34:16 -070012234 status = sme_register_tx_queue_cb(mac_handle,
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080012235 hdd_tx_queue_cb);
12236 if (!QDF_IS_STATUS_SUCCESS(status))
12237 hdd_err("Register tx queue callback failed");
12238
Visweswara Tanuku633976b2019-01-07 16:13:12 +053012239#ifdef WLAN_FEATURE_MOTION_DETECTION
12240 sme_set_md_host_evt_cb(mac_handle, hdd_md_host_evt_cb, (void *)hdd_ctx);
12241#endif /* WLAN_FEATURE_MOTION_DETECTION */
12242
Dustin Browne74003f2018-03-14 12:51:58 -070012243 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012244
12245 return ret;
12246}
12247
12248/**
12249 * hdd_deregister_cb() - De-Register HDD callbacks.
12250 * @hdd_ctx: HDD context
12251 *
12252 * De-Register the HDD callbacks to CDS/SME.
12253 *
12254 * Return: void
12255 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012256void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012257{
12258 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053012259 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070012260 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012261
Dustin Brown491d54b2018-03-14 12:39:11 -070012262 hdd_enter();
Sourav Mohapatra674925f2018-04-16 11:16:58 +053012263 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
12264 hdd_err("in ftm mode, no need to deregister callbacks");
12265 return;
12266 }
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012267
Jeff Johnson16528362018-06-14 12:34:16 -070012268 mac_handle = hdd_ctx->mac_handle;
12269 sme_deregister_tx_queue_cb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012270
Jeff Johnson16528362018-06-14 12:34:16 -070012271 sme_reset_link_layer_stats_ind_cb(mac_handle);
12272 sme_reset_rssi_threshold_breached_cb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012273
Jeff Johnson16528362018-06-14 12:34:16 -070012274 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012275 wlan_hdd_cfg80211_stats_ext_callback);
12276
Jeff Johnson16528362018-06-14 12:34:16 -070012277 status = sme_reset_tsfcb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012278 if (!QDF_IS_STATUS_SUCCESS(status))
12279 hdd_err("Failed to de-register tsfcb the callback:%d",
12280 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012281
Poddar, Siddarth34872782017-08-10 14:08:51 +053012282 ret = hdd_deregister_data_stall_detect_cb();
12283 if (ret)
12284 hdd_err("Failed to de-register data stall detect event callback");
12285
Jeff Johnson16528362018-06-14 12:34:16 -070012286 sme_deregister_oem_data_rsp_callback(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012287
Dustin Browne74003f2018-03-14 12:51:58 -070012288 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012289}
12290
12291/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012292 * hdd_softap_sta_deauth() - handle deauth req from HDD
12293 * @adapter: Pointer to the HDD
12294 * @enable: bool value
12295 *
12296 * This to take counter measure to handle deauth req from HDD
12297 *
12298 * Return: None
12299 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012300QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080012301 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012302{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012303 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012304
Dustin Brown491d54b2018-03-14 12:39:11 -070012305 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012306
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012307 /* Ignore request to deauth bcmc station */
12308 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012309 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012310
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012311 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012312 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
12313 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012314
Dustin Browne74003f2018-03-14 12:51:58 -070012315 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012316 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012317}
12318
12319/**
12320 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
12321 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053012322 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012323 *
12324 * This to take counter measure to handle deauth req from HDD
12325 *
12326 * Return: None
12327 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012328void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080012329 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012330{
Dustin Brown491d54b2018-03-14 12:39:11 -070012331 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012332
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012333 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053012334 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012335 return;
12336
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012337 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053012338 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012339}
12340
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012341void wlan_hdd_disable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012342{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012343 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
12344 struct hdd_adapter *adapter = NULL;
12345 struct csr_roam_profile *roam_profile;
12346 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012347
Dustin Brown1dbefe62018-09-11 16:32:03 -070012348 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->psoc)) {
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012349 hdd_debug("No active sta session");
12350 return;
12351 }
12352
12353 hdd_for_each_adapter(hdd_ctx, adapter) {
12354 roam_profile = hdd_roam_profile(adapter);
12355 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12356
12357 if (cur_adapter->session_id != adapter->session_id &&
12358 adapter->device_mode == QDF_STA_MODE &&
12359 hdd_conn_is_connected(sta_ctx)) {
12360 hdd_debug("%d Disable roaming", adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -070012361 sme_stop_roaming(hdd_ctx->mac_handle,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012362 adapter->session_id,
12363 ecsr_driver_disabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012364 }
12365 }
12366}
12367
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012368void wlan_hdd_enable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012369{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012370 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
12371 struct hdd_adapter *adapter = NULL;
12372 struct csr_roam_profile *roam_profile;
12373 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012374
Dustin Brown1dbefe62018-09-11 16:32:03 -070012375 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->psoc)) {
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012376 hdd_debug("No active sta session");
12377 return;
12378 }
12379
12380 hdd_for_each_adapter(hdd_ctx, adapter) {
12381 roam_profile = hdd_roam_profile(adapter);
12382 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12383
12384 if (cur_adapter->session_id != adapter->session_id &&
12385 adapter->device_mode == QDF_STA_MODE &&
12386 hdd_conn_is_connected(sta_ctx)) {
12387 hdd_debug("%d Enable roaming", adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -070012388 sme_start_roaming(hdd_ctx->mac_handle,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012389 adapter->session_id,
12390 REASON_DRIVER_ENABLED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012391 }
12392 }
12393}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012394
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053012395/**
12396 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
12397 * @skb: sk buffer pointer
12398 *
12399 * Sends the bcast message to SVC multicast group with generic nl socket
12400 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
12401 *
12402 * Return: None
12403 */
12404static void nl_srv_bcast_svc(struct sk_buff *skb)
12405{
12406#ifdef CNSS_GENL
12407 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
12408#else
12409 nl_srv_bcast(skb);
12410#endif
12411}
12412
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012413void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012414{
12415 struct sk_buff *skb;
12416 struct nlmsghdr *nlh;
12417 tAniMsgHdr *ani_hdr;
12418 void *nl_data = NULL;
12419 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012420 struct radio_index_tlv *radio_info;
12421 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012422
12423 if (in_interrupt() || irqs_disabled() || in_atomic())
12424 flags = GFP_ATOMIC;
12425
12426 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
12427
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012428 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012429 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012430
12431 nlh = (struct nlmsghdr *)skb->data;
12432 nlh->nlmsg_pid = 0; /* from kernel */
12433 nlh->nlmsg_flags = 0;
12434 nlh->nlmsg_seq = 0;
12435 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
12436
12437 ani_hdr = NLMSG_DATA(nlh);
12438 ani_hdr->type = type;
12439
12440 switch (type) {
12441 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053012442 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012443 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012444 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070012445 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012446 ani_hdr->length = 0;
12447 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012448 break;
12449 case WLAN_SVC_WLAN_STATUS_IND:
12450 case WLAN_SVC_WLAN_VERSION_IND:
12451 case WLAN_SVC_DFS_CAC_START_IND:
12452 case WLAN_SVC_DFS_CAC_END_IND:
12453 case WLAN_SVC_DFS_RADAR_DETECT_IND:
12454 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
12455 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080012456 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053012457 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080012458 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012459 ani_hdr->length = len;
12460 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
12461 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
12462 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012463 break;
12464
12465 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070012466 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012467 type);
12468 kfree_skb(skb);
12469 return;
12470 }
12471
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012472 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080012473 * Add radio index at the end of the svc event in TLV format
12474 * to maintain the backward compatibility with userspace
12475 * applications.
12476 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012477
12478 tlv_len = 0;
12479
12480 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
12481 < WLAN_NL_MAX_PAYLOAD) {
12482 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
12483 sizeof(*ani_hdr) + len);
12484 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
12485 radio_info->length = (unsigned short) sizeof(radio_info->radio);
12486 radio_info->radio = radio;
12487 tlv_len = sizeof(*radio_info);
Dustin Browna2868622018-03-20 11:38:14 -070012488 hdd_debug("Added radio index tlv - radio index %d",
12489 radio_info->radio);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012490 }
12491
12492 nlh->nlmsg_len += tlv_len;
12493 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
12494
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053012495 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012496}
12497
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012498#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
12499void wlan_hdd_auto_shutdown_cb(void)
12500{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012501 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012502
12503 if (!hdd_ctx)
12504 return;
12505
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012506 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012507 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
12508 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012509}
12510
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012511void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012512{
Jeff Johnson9d295242017-08-29 14:39:48 -070012513 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012514 bool ap_connected = false, sta_connected = false;
Jeff Johnson16528362018-06-14 12:34:16 -070012515 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012516
Jeff Johnson16528362018-06-14 12:34:16 -070012517 mac_handle = hdd_ctx->mac_handle;
12518 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012519 return;
12520
Dundi Raviteja8e338282018-09-25 17:16:04 +053012521 if (hdd_ctx->config->wlan_auto_shutdown == 0)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012522 return;
12523
12524 if (enable == false) {
Jeff Johnson16528362018-06-14 12:34:16 -070012525 if (sme_set_auto_shutdown_timer(mac_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012526 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012527 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012528 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012529 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070012530 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012531 return;
12532 }
12533
12534 /* To enable shutdown timer check conncurrency */
Dustin Brown1dbefe62018-09-11 16:32:03 -070012535 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->psoc)) {
Dustin Brown920397d2017-12-13 16:27:50 -080012536 hdd_for_each_adapter(hdd_ctx, adapter) {
12537 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012538 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
12539 conn_info.connState ==
12540 eConnectionState_Associated) {
12541 sta_connected = true;
12542 break;
12543 }
12544 }
Dustin Brown920397d2017-12-13 16:27:50 -080012545
12546 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012547 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070012548 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012549 ap_connected = true;
12550 break;
12551 }
12552 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012553 }
12554 }
12555
12556 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012557 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012558 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012559 }
Jeff Johnson68755312017-02-10 11:46:55 -080012560
Jeff Johnson16528362018-06-14 12:34:16 -070012561 if (sme_set_auto_shutdown_timer(mac_handle,
Dundi Raviteja8e338282018-09-25 17:16:04 +053012562 hdd_ctx->config->wlan_auto_shutdown)
Jeff Johnson68755312017-02-10 11:46:55 -080012563 != QDF_STATUS_SUCCESS)
12564 hdd_err("Failed to start wlan auto shutdown timer");
12565 else
Dustin Brown5e89ef82018-03-14 11:50:23 -070012566 hdd_info("Auto Shutdown timer for %d seconds enabled",
Dundi Raviteja8e338282018-09-25 17:16:04 +053012567 hdd_ctx->config->wlan_auto_shutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012568}
12569#endif
12570
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070012571struct hdd_adapter *
12572hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
12573 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012574{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012575 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070012576 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012577
12578 con_sap_adapter = NULL;
12579
Dustin Brown920397d2017-12-13 16:27:50 -080012580 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012581 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
12582 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012583 adapter != this_sap_adapter) {
12584 if (check_start_bss) {
12585 if (test_bit(SOFTAP_BSS_STARTED,
12586 &adapter->event_flags)) {
12587 con_sap_adapter = adapter;
12588 break;
12589 }
12590 } else {
12591 con_sap_adapter = adapter;
12592 break;
12593 }
12594 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012595 }
12596
12597 return con_sap_adapter;
12598}
12599
12600#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070012601static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012602{
Dustin Brown5ec6b552017-03-31 12:11:40 -070012603 return adapter->device_mode == QDF_STA_MODE ||
12604 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012605}
12606
Jeff Johnson9d295242017-08-29 14:39:48 -070012607static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012608{
Dustin Brown5ec6b552017-03-31 12:11:40 -070012609 return adapter->device_mode == QDF_SAP_MODE ||
12610 adapter->device_mode == QDF_P2P_GO_MODE;
12611}
12612
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012613static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012614{
Dustin Brown920397d2017-12-13 16:27:50 -080012615 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070012616
Dustin Brown920397d2017-12-13 16:27:50 -080012617 hdd_for_each_adapter(hdd_ctx, adapter) {
12618 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070012619 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
12620 conn_info.connState == eConnectionState_Associated) {
12621 return true;
12622 }
12623
Dustin Brown920397d2017-12-13 16:27:50 -080012624 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070012625 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070012626 return true;
12627 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070012628 }
12629
12630 return false;
12631}
12632
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012633static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012634{
12635 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012636
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053012637 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012638 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053012639 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012640
Dustin Brown5ec6b552017-03-31 12:11:40 -070012641 return is_running;
12642}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012643
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012644static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012645{
12646 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
12647 hdd_ctx->bus_bw_timer_running = true;
12648 qdf_timer_start(&hdd_ctx->bus_bw_timer,
jitiphil869b9f72018-09-25 17:14:01 +053012649 hdd_ctx->config->bus_bw_compute_interval);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012650 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
12651}
12652
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012653void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012654{
Dustin Brown491d54b2018-03-14 12:39:11 -070012655 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012656
12657 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12658 hdd_debug("Bandwidth compute timer already started");
12659 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012660 }
12661
Dustin Brown5ec6b552017-03-31 12:11:40 -070012662 __hdd_bus_bw_compute_timer_start(hdd_ctx);
12663
Dustin Browne74003f2018-03-14 12:51:58 -070012664 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012665}
12666
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012667void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012668{
Dustin Brown491d54b2018-03-14 12:39:11 -070012669 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012670
12671 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12672 hdd_debug("Bandwidth compute timer already started");
12673 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070012674 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070012675
12676 if (hdd_any_adapter_is_assoc(hdd_ctx))
12677 __hdd_bus_bw_compute_timer_start(hdd_ctx);
12678
Dustin Browne74003f2018-03-14 12:51:58 -070012679 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012680}
12681
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012682static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012683{
Dustin Brown07901ec2018-09-07 11:02:41 -070012684 ucfg_ipa_set_perf_level(hdd_ctx->pdev, 0, 0);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012685
12686 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012687 hdd_ctx->bus_bw_timer_running = false;
Dustin Brown35008ba2018-08-23 14:34:21 -070012688 qdf_timer_sync_cancel(&hdd_ctx->bus_bw_timer);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012689 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
12690
Dustin Brown35008ba2018-08-23 14:34:21 -070012691 /* work callback is long running; flush outside of lock */
12692 cancel_work_sync(&hdd_ctx->bus_bw_work);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012693 hdd_reset_tcp_delack(hdd_ctx);
12694}
12695
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012696void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012697{
Dustin Brown491d54b2018-03-14 12:39:11 -070012698 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012699
12700 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12701 hdd_debug("Bandwidth compute timer already stopped");
12702 return;
12703 }
12704
12705 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
12706
Dustin Browne74003f2018-03-14 12:51:58 -070012707 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012708}
12709
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012710void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012711{
Dustin Brown491d54b2018-03-14 12:39:11 -070012712 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012713
12714 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12715 hdd_debug("Bandwidth compute timer already stopped");
12716 return;
12717 }
12718
12719 if (!hdd_any_adapter_is_assoc(hdd_ctx))
12720 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
12721
Dustin Browne74003f2018-03-14 12:51:58 -070012722 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012723}
12724#endif
12725
12726/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012727 * wlan_hdd_stop_sap() - This function stops bss of SAP.
12728 * @ap_adapter: SAP adapter
12729 *
12730 * This function will process the stopping of sap adapter.
12731 *
12732 * Return: None
12733 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012734void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012735{
Jeff Johnson87251032017-08-29 13:31:11 -070012736 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012737 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053012738 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012739 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012740
12741 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012742 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012743 return;
12744 }
12745
12746 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12747 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012748 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012749 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012750
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012751 mutex_lock(&hdd_ctx->sap_lock);
12752 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080012753 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012754 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012755 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053012756 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012757 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012758 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053012759 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080012760 qdf_stop_bss_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +053012761 SME_CMD_STOP_BSS_TIMEOUT);
Anurag Chouhance0dc992016-02-16 18:18:03 +053012762 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012763 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070012764 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012765 return;
12766 }
12767 }
12768 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -070012769 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012770 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012771 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012772 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012773 false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012774 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012775 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012776 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012777 }
12778 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012779}
12780
12781/**
12782 * wlan_hdd_start_sap() - this function starts bss of SAP.
12783 * @ap_adapter: SAP adapter
12784 *
12785 * This function will process the starting of sap adapter.
12786 *
12787 * Return: None
12788 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012789void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012790{
Jeff Johnson87251032017-08-29 13:31:11 -070012791 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012792 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053012793 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012794 struct hdd_context *hdd_ctx;
Jeff Johnsone4c11db2018-05-05 23:22:32 -070012795 tsap_config_t *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012796
12797 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012798 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012799 return;
12800 }
12801
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012802 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070012803 hdd_err("SoftAp role has not been enabled");
12804 return;
12805 }
12806
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012807 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
12808 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12809 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070012810 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012811
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012812 mutex_lock(&hdd_ctx->sap_lock);
12813 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
12814 goto end;
12815
12816 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012817 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012818 goto end;
12819 }
Dustin Brown07901ec2018-09-07 11:02:41 -070012820 wlan_reg_set_channel_params(hdd_ctx->pdev,
Abhinav Kumar6f694482018-09-04 16:07:39 +053012821 hdd_ap_ctx->sap_config.channel, 0,
12822 &hdd_ap_ctx->sap_config.ch_params);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012823
Wei Song2f76f642016-11-18 16:32:53 +080012824 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012825 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070012826 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012827 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012828 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012829 goto end;
12830
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012831 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053012832 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +053012833 SME_CMD_START_BSS_TIMEOUT);
Anurag Chouhance0dc992016-02-16 18:18:03 +053012834 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012835 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012836 goto end;
12837 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070012838 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012839 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012840 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012841 if (hostapd_state->bss_state == BSS_START) {
Dustin Brown1dbefe62018-09-11 16:32:03 -070012842 policy_mgr_incr_active_session(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012843 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012844 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012845 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012846 true);
12847 }
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053012848 mutex_unlock(&hdd_ctx->sap_lock);
12849
12850 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012851end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012852 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012853 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070012854 /* SAP context and beacon cleanup will happen during driver unload
12855 * in hdd_stop_adapter
12856 */
12857 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
12858
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012859}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012860
12861/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012862 * hdd_get_fw_version() - Get FW version
12863 * @hdd_ctx: pointer to HDD context.
12864 * @major_spid: FW version - major spid.
12865 * @minor_spid: FW version - minor spid
12866 * @ssid: FW version - ssid
12867 * @crmid: FW version - crmid
12868 *
12869 * This function is called to get the firmware build version stored
12870 * as part of the HDD context
12871 *
12872 * Return: None
12873 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012874void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012875 uint32_t *major_spid, uint32_t *minor_spid,
12876 uint32_t *siid, uint32_t *crmid)
12877{
12878 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
12879 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
12880 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
12881 *crmid = hdd_ctx->target_fw_version & 0x7fff;
12882}
12883
12884#ifdef QCA_CONFIG_SMP
12885/**
12886 * wlan_hdd_get_cpu() - get cpu_index
12887 *
12888 * Return: cpu_index
12889 */
12890int wlan_hdd_get_cpu(void)
12891{
12892 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012893
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012894 put_cpu();
12895 return cpu_index;
12896}
12897#endif
12898
12899/**
12900 * hdd_get_fwpath() - get framework path
12901 *
12902 * This function is used to get the string written by
12903 * userspace to start the wlan driver
12904 *
12905 * Return: string
12906 */
12907const char *hdd_get_fwpath(void)
12908{
12909 return fwpath.string;
12910}
12911
Dustin Brown94ce20f2018-09-04 13:11:38 -070012912static inline int hdd_state_query_cb(void)
12913{
12914 return !!wlan_hdd_validate_context(cds_get_context(QDF_MODULE_ID_HDD));
12915}
12916
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012917/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012918 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012919 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012920 * This function initilizes CDS global context with the help of cds_init. This
12921 * has to be the first function called after probe to get a valid global
12922 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012923 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012924 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012925 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012926int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012927{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012928 QDF_STATUS status;
Dustin Brownfe50cef2018-12-10 10:42:37 -080012929 int ret;
12930
12931 hdd_dsc_init();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012932
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012933 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080012934 if (QDF_IS_STATUS_ERROR(status)) {
12935 hdd_err("Failed to allocate CDS context");
12936 ret = -ENOMEM;
Dustin Brownfe50cef2018-12-10 10:42:37 -080012937 goto deinit_dsc;
wadesongae4ffd12017-10-24 16:45:54 +080012938 }
Dustin Brown94ce20f2018-09-04 13:11:38 -070012939 qdf_register_module_state_query_callback(hdd_state_query_cb);
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053012940
12941 wlan_init_bug_report_lock();
12942
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012943#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12944 wlan_logging_sock_init_svc();
12945#endif
12946
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012947 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
12948 (void *)hdd_drv_ops_inactivity_handler, NULL,
12949 QDF_TIMER_TYPE_SW);
12950
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012951 hdd_trace_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053012952 hdd_register_debug_callback();
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012953 wlan_roam_debug_init();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012954
Dustin Brownfe50cef2018-12-10 10:42:37 -080012955 return 0;
12956
12957deinit_dsc:
12958 hdd_dsc_deinit();
12959
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012960 return ret;
12961}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012962
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012963/**
12964 * hdd_deinit() - Deinitialize Driver
12965 *
12966 * This function frees CDS global context with the help of cds_deinit. This
12967 * has to be the last function call in remove callback to free the global
12968 * context.
12969 */
12970void hdd_deinit(void)
12971{
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012972 wlan_roam_debug_deinit();
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012973 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012974
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012975#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12976 wlan_logging_sock_deinit_svc();
12977#endif
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012978
12979 wlan_destroy_bug_report_lock();
12980 cds_deinit();
Dustin Brownfe50cef2018-12-10 10:42:37 -080012981
12982 hdd_dsc_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012983}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012984
Yue Ma6e7b1a02017-04-03 14:17:46 -070012985#ifdef QCA_WIFI_NAPIER_EMULATION
12986#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
12987#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012988#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070012989#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012990
Sachin Ahujadddd2632017-03-07 19:07:24 +053012991static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
12992 struct file *file)
12993{
12994 return 0;
12995}
12996
12997static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
12998 const char __user *user_buf,
12999 size_t count,
13000 loff_t *f_pos)
13001{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053013002 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053013003 static const char wlan_off_str[] = "OFF";
13004 static const char wlan_on_str[] = "ON";
13005 int ret;
13006 unsigned long rc;
13007
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053013008 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053013009 pr_err("Failed to read buffer\n");
13010 return -EINVAL;
13011 }
13012
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053013013 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053013014 pr_debug("Wifi turning off from UI\n");
13015 goto exit;
13016 }
13017
Srinivas Girigowdad2412882018-09-07 15:42:04 -070013018 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) == 0)
Sachin Ahuja16904db2017-12-13 19:56:57 +053013019 pr_info("Wifi Turning On from UI\n");
Sachin Ahuja16904db2017-12-13 19:56:57 +053013020
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053013021 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053013022 pr_err("Invalid value received from framework");
13023 goto exit;
13024 }
13025
13026 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053013027 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053013028 rc = wait_for_completion_timeout(&wlan_start_comp,
13029 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
13030 if (!rc) {
Srinivas Girigowda09625b02018-09-10 15:28:09 -070013031 hdd_alert("Timed-out!!");
Sachin Ahujadddd2632017-03-07 19:07:24 +053013032 ret = -EINVAL;
Sachin Ahujadddd2632017-03-07 19:07:24 +053013033 return ret;
13034 }
13035
13036 hdd_start_complete(0);
13037 }
13038
13039exit:
13040 return count;
13041}
13042
13043
13044const struct file_operations wlan_hdd_state_fops = {
13045 .owner = THIS_MODULE,
13046 .open = wlan_hdd_state_ctrl_param_open,
13047 .write = wlan_hdd_state_ctrl_param_write,
13048};
13049
13050static int wlan_hdd_state_ctrl_param_create(void)
13051{
13052 unsigned int wlan_hdd_state_major = 0;
13053 int ret;
13054 struct device *dev;
13055
13056 device = MKDEV(wlan_hdd_state_major, 0);
13057
13058 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
13059 if (ret) {
13060 pr_err("Failed to register qcwlanstate");
13061 goto dev_alloc_err;
13062 }
13063 wlan_hdd_state_major = MAJOR(device);
13064
13065 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
13066 if (IS_ERR(class)) {
13067 pr_err("wlan_hdd_state class_create error");
13068 goto class_err;
13069 }
13070
13071 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
13072 if (IS_ERR(dev)) {
13073 pr_err("wlan_hdd_statedevice_create error");
13074 goto err_class_destroy;
13075 }
13076
13077 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
13078 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
13079 if (ret) {
13080 pr_err("Failed to add cdev error");
13081 goto cdev_add_err;
13082 }
13083
13084 pr_info("wlan_hdd_state %s major(%d) initialized",
13085 WLAN_MODULE_NAME, wlan_hdd_state_major);
13086
13087 return 0;
13088
13089cdev_add_err:
13090 device_destroy(class, device);
13091err_class_destroy:
13092 class_destroy(class);
13093class_err:
13094 unregister_chrdev_region(device, dev_num);
13095dev_alloc_err:
13096 return -ENODEV;
13097}
13098
13099static void wlan_hdd_state_ctrl_param_destroy(void)
13100{
13101 cdev_del(&wlan_hdd_state_cdev);
13102 device_destroy(class, device);
13103 class_destroy(class);
13104 unregister_chrdev_region(device, dev_num);
13105
13106 pr_info("Device node unregistered");
13107}
13108
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013109/**
Dustin Brownd585cb32018-09-12 17:12:23 -070013110 * hdd_component_init() - Initialize all components
Mukul Sharmad75a6672017-06-22 15:40:53 +053013111 *
Dustin Brownd585cb32018-09-12 17:12:23 -070013112 * Return: QDF_STATUS
Mukul Sharmad75a6672017-06-22 15:40:53 +053013113 */
Dustin Brownd585cb32018-09-12 17:12:23 -070013114static QDF_STATUS hdd_component_init(void)
Mukul Sharmad75a6672017-06-22 15:40:53 +053013115{
Dustin Brownd585cb32018-09-12 17:12:23 -070013116 QDF_STATUS status;
13117
13118 /* initialize converged components */
Arif Hussain49698112018-07-31 00:32:50 -070013119 status = target_if_init(wma_get_psoc_from_scn_handle);
Dustin Brownd585cb32018-09-12 17:12:23 -070013120 if (QDF_IS_STATUS_ERROR(status))
13121 return status;
13122
Abhishek Singhd5cf22d2019-01-08 19:51:09 +053013123 status = ucfg_mlme_global_init();
Arif Hussain49698112018-07-31 00:32:50 -070013124 if (QDF_IS_STATUS_ERROR(status))
13125 goto target_if_deinit;
13126
Abhishek Singhd5cf22d2019-01-08 19:51:09 +053013127 status = dispatcher_init();
13128 if (QDF_IS_STATUS_ERROR(status))
13129 goto mlme_global_deinit;
13130
Dustin Brownd585cb32018-09-12 17:12:23 -070013131 /* initialize non-converged components */
13132 status = ucfg_mlme_init();
13133 if (QDF_IS_STATUS_ERROR(status))
13134 goto dispatcher_deinit;
13135
13136 status = ucfg_fwol_init();
13137 if (QDF_IS_STATUS_ERROR(status))
13138 goto mlme_deinit;
13139
13140 status = disa_init();
13141 if (QDF_IS_STATUS_ERROR(status))
13142 goto fwol_deinit;
13143
13144 status = pmo_init();
13145 if (QDF_IS_STATUS_ERROR(status))
13146 goto disa_deinit;
13147
13148 status = ucfg_ocb_init();
13149 if (QDF_IS_STATUS_ERROR(status))
13150 goto pmo_deinit;
13151
13152 status = ipa_init();
13153 if (QDF_IS_STATUS_ERROR(status))
13154 goto ocb_deinit;
13155
13156 status = ucfg_action_oui_init();
13157 if (QDF_IS_STATUS_ERROR(status))
13158 goto ipa_deinit;
13159
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013160 status = nan_init();
13161 if (QDF_IS_STATUS_ERROR(status))
13162 goto action_oui_deinit;
13163
Wu Gao637d58a2018-12-08 10:37:34 +080013164 status = ucfg_p2p_init();
13165 if (QDF_IS_STATUS_ERROR(status))
13166 goto nan_deinit;
13167
Wu Gaod6b5e402018-12-03 22:09:24 +080013168 status = policy_mgr_init();
13169 if (QDF_IS_STATUS_ERROR(status))
13170 goto p2p_deinit;
13171
Wu Gao5f793402018-12-08 11:04:00 +080013172 status = ucfg_tdls_init();
13173 if (QDF_IS_STATUS_ERROR(status))
13174 goto policy_deinit;
13175
Dustin Brownd585cb32018-09-12 17:12:23 -070013176 return QDF_STATUS_SUCCESS;
13177
Wu Gao5f793402018-12-08 11:04:00 +080013178policy_deinit:
13179 policy_mgr_deinit();
Wu Gaod6b5e402018-12-03 22:09:24 +080013180p2p_deinit:
13181 ucfg_p2p_deinit();
Wu Gao637d58a2018-12-08 10:37:34 +080013182nan_deinit:
13183 nan_deinit();
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013184action_oui_deinit:
13185 ucfg_action_oui_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013186ipa_deinit:
13187 ipa_deinit();
13188ocb_deinit:
13189 ucfg_ocb_deinit();
13190pmo_deinit:
13191 pmo_deinit();
13192disa_deinit:
13193 disa_deinit();
13194fwol_deinit:
13195 ucfg_fwol_deinit();
13196mlme_deinit:
13197 ucfg_mlme_deinit();
13198dispatcher_deinit:
13199 dispatcher_deinit();
Abhishek Singhd5cf22d2019-01-08 19:51:09 +053013200mlme_global_deinit:
13201 ucfg_mlme_global_deinit();
Arif Hussain49698112018-07-31 00:32:50 -070013202target_if_deinit:
13203 target_if_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013204
13205 return status;
Mukul Sharmad75a6672017-06-22 15:40:53 +053013206}
13207
13208/**
Dustin Brownd585cb32018-09-12 17:12:23 -070013209 * hdd_component_deinit() - Deinitialize all components
Mukul Sharmad75a6672017-06-22 15:40:53 +053013210 *
13211 * Return: None
13212 */
Dustin Brownd585cb32018-09-12 17:12:23 -070013213static void hdd_component_deinit(void)
Mukul Sharmad75a6672017-06-22 15:40:53 +053013214{
Dustin Brownd585cb32018-09-12 17:12:23 -070013215 /* deinitialize non-converged components */
Wu Gao5f793402018-12-08 11:04:00 +080013216 ucfg_tdls_deinit();
Wu Gaod6b5e402018-12-03 22:09:24 +080013217 policy_mgr_deinit();
Wu Gao637d58a2018-12-08 10:37:34 +080013218 ucfg_p2p_deinit();
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013219 nan_deinit();
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053013220 ucfg_action_oui_deinit();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053013221 ipa_deinit();
Zhang Qian47e22ce2018-01-04 15:38:38 +080013222 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053013223 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013224 disa_deinit();
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013225 ucfg_fwol_deinit();
Vignesh Viswanathana0921c42018-09-04 19:03:35 +053013226 ucfg_mlme_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013227
13228 /* deinitialize converged components */
13229 dispatcher_deinit();
Abhishek Singhd5cf22d2019-01-08 19:51:09 +053013230 ucfg_mlme_global_deinit();
Arif Hussain49698112018-07-31 00:32:50 -070013231 target_if_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013232}
13233
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053013234QDF_STATUS hdd_component_psoc_open(struct wlan_objmgr_psoc *psoc)
13235{
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013236 QDF_STATUS status;
13237
13238 status = ucfg_mlme_psoc_open(psoc);
13239 if (QDF_IS_STATUS_ERROR(status))
13240 return status;
13241
13242 status = ucfg_fwol_psoc_open(psoc);
13243 if (QDF_IS_STATUS_ERROR(status))
Wu Gao66454f12018-09-26 19:55:41 +080013244 goto err_fwol;
13245
13246 status = ucfg_pmo_psoc_open(psoc);
13247 if (QDF_IS_STATUS_ERROR(status))
13248 goto err_pmo;
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013249
Krunal Sonie9c12f52018-10-04 11:45:42 -070013250 status = ucfg_policy_mgr_psoc_open(psoc);
13251 if (QDF_IS_STATUS_ERROR(status))
13252 goto err_plcy_mgr;
13253
Wu Gao637d58a2018-12-08 10:37:34 +080013254 status = ucfg_p2p_psoc_open(psoc);
13255 if (QDF_IS_STATUS_ERROR(status))
13256 goto err_p2p;
Wu Gao5f793402018-12-08 11:04:00 +080013257
13258 status = ucfg_tdls_psoc_open(psoc);
13259 if (QDF_IS_STATUS_ERROR(status))
13260 goto err_tdls;
13261
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013262 return status;
13263
Wu Gao5f793402018-12-08 11:04:00 +080013264err_tdls:
13265 ucfg_tdls_psoc_close(psoc);
Wu Gao637d58a2018-12-08 10:37:34 +080013266err_p2p:
13267 ucfg_p2p_psoc_close(psoc);
Krunal Sonie9c12f52018-10-04 11:45:42 -070013268err_plcy_mgr:
13269 ucfg_pmo_psoc_close(psoc);
Wu Gao66454f12018-09-26 19:55:41 +080013270err_pmo:
13271 ucfg_fwol_psoc_close(psoc);
13272err_fwol:
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013273 ucfg_mlme_psoc_close(psoc);
Krunal Sonie9c12f52018-10-04 11:45:42 -070013274
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013275 return status;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053013276}
13277
13278void hdd_component_psoc_close(struct wlan_objmgr_psoc *psoc)
13279{
Wu Gao5f793402018-12-08 11:04:00 +080013280 ucfg_tdls_psoc_close(psoc);
Wu Gao637d58a2018-12-08 10:37:34 +080013281 ucfg_p2p_psoc_close(psoc);
Krunal Sonie9c12f52018-10-04 11:45:42 -070013282 ucfg_policy_mgr_psoc_close(psoc);
Wu Gao66454f12018-09-26 19:55:41 +080013283 ucfg_pmo_psoc_close(psoc);
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013284 ucfg_fwol_psoc_close(psoc);
Vignesh Viswanathana0921c42018-09-04 19:03:35 +053013285 ucfg_mlme_psoc_close(psoc);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053013286}
13287
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013288void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
13289{
Zhang Qian47e22ce2018-01-04 15:38:38 +080013290 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013291 disa_psoc_enable(psoc);
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013292 nan_psoc_enable(psoc);
Wu Gao637d58a2018-12-08 10:37:34 +080013293 p2p_psoc_enable(psoc);
Wu Gaod6b5e402018-12-03 22:09:24 +080013294 policy_mgr_psoc_enable(psoc);
Wu Gaoa67c3802018-12-27 12:07:52 +080013295 ucfg_tdls_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013296}
13297
13298void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
13299{
Wu Gaoa67c3802018-12-27 12:07:52 +080013300 ucfg_tdls_psoc_disable(psoc);
Wu Gaod6b5e402018-12-03 22:09:24 +080013301 policy_mgr_psoc_disable(psoc);
Wu Gao637d58a2018-12-08 10:37:34 +080013302 p2p_psoc_disable(psoc);
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013303 nan_psoc_disable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013304 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080013305 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053013306}
13307
Sandeep Puligillab7beb472018-08-13 22:54:20 -070013308QDF_STATUS hdd_component_pdev_open(struct wlan_objmgr_pdev *pdev)
13309{
13310 return ucfg_mlme_pdev_open(pdev);
13311}
13312
13313void hdd_component_pdev_close(struct wlan_objmgr_pdev *pdev)
13314{
13315 ucfg_mlme_pdev_close(pdev);
13316}
13317
Dustin Brown21a1d462018-07-31 15:13:06 -070013318static struct hdd_driver __hdd_driver;
13319
13320static QDF_STATUS hdd_driver_ctx_init(struct hdd_driver *hdd_driver)
13321{
13322 QDF_BUG(hdd_driver);
13323 if (!hdd_driver)
13324 return QDF_STATUS_E_INVAL;
13325
13326 hdd_driver->state = driver_state_uninit;
13327
13328 return dsc_driver_create(&hdd_driver->dsc_driver);
13329}
13330
13331static void hdd_driver_ctx_deinit(struct hdd_driver *hdd_driver)
13332{
13333 QDF_BUG(hdd_driver);
13334 if (!hdd_driver)
13335 return;
13336
13337 dsc_driver_destroy(&hdd_driver->dsc_driver);
13338 qdf_mem_zero(hdd_driver, sizeof(*hdd_driver));
13339}
13340
13341struct hdd_driver *hdd_driver_get(void)
13342{
13343 return &__hdd_driver;
13344}
13345
Dustin Browna2a39dc2018-09-17 15:29:59 -070013346static QDF_STATUS hdd_qdf_print_init(void)
13347{
13348 QDF_STATUS status;
13349 int qdf_print_idx;
13350
13351 status = qdf_print_setup();
13352 if (QDF_IS_STATUS_ERROR(status)) {
13353 pr_err("Failed qdf_print_setup; status:%u\n", status);
13354 return status;
13355 }
13356
13357 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
13358 if (qdf_print_idx < 0) {
13359 pr_err("Failed to register for qdf_print_ctrl\n");
13360 return QDF_STATUS_E_FAILURE;
13361 }
13362
13363 qdf_set_pidx(qdf_print_idx);
13364
13365 return QDF_STATUS_SUCCESS;
13366}
13367
13368static void hdd_qdf_print_deinit(void)
13369{
13370 int qdf_pidx = qdf_get_pidx();
13371
13372 qdf_set_pidx(-1);
13373 qdf_print_ctrl_cleanup(qdf_pidx);
13374
13375 /* currently, no qdf print 'un-setup'*/
13376}
13377
13378static QDF_STATUS hdd_qdf_init(void)
13379{
13380 QDF_STATUS status;
13381
13382 status = hdd_qdf_print_init();
13383 if (QDF_IS_STATUS_ERROR(status))
13384 goto exit;
13385
13386 status = qdf_debugfs_init();
13387 if (QDF_IS_STATUS_ERROR(status)) {
13388 hdd_err("Failed to init debugfs; status:%u", status);
13389 goto print_deinit;
13390 }
13391
13392 qdf_lock_stats_init();
13393 qdf_mem_init();
13394 qdf_mc_timer_manager_init();
13395 qdf_event_list_init();
13396
Dustin Brownd315c452018-11-27 11:28:48 -080013397 status = qdf_talloc_feature_init();
13398 if (QDF_IS_STATUS_ERROR(status)) {
13399 hdd_err("Failed to init talloc; status:%u", status);
13400 goto event_deinit;
13401 }
13402
Dustin Browna2a39dc2018-09-17 15:29:59 -070013403 status = qdf_cpuhp_init();
13404 if (QDF_IS_STATUS_ERROR(status)) {
13405 hdd_err("Failed to init cpuhp; status:%u", status);
Dustin Brownd315c452018-11-27 11:28:48 -080013406 goto talloc_deinit;
Dustin Browna2a39dc2018-09-17 15:29:59 -070013407 }
13408
13409 status = qdf_trace_spin_lock_init();
13410 if (QDF_IS_STATUS_ERROR(status)) {
13411 hdd_err("Failed to init spinlock; status:%u", status);
13412 goto cpuhp_deinit;
13413 }
13414
13415 qdf_trace_init();
13416 qdf_register_debugcb_init();
13417
13418 return QDF_STATUS_SUCCESS;
13419
13420cpuhp_deinit:
13421 qdf_cpuhp_deinit();
Dustin Brownd315c452018-11-27 11:28:48 -080013422talloc_deinit:
13423 qdf_talloc_feature_deinit();
Dustin Browna2a39dc2018-09-17 15:29:59 -070013424event_deinit:
13425 qdf_event_list_destroy();
13426 qdf_mc_timer_manager_exit();
13427 qdf_mem_exit();
13428 qdf_lock_stats_deinit();
13429 qdf_debugfs_exit();
13430print_deinit:
13431 hdd_qdf_print_deinit();
13432
13433exit:
13434 return status;
13435}
13436
13437static void hdd_qdf_deinit(void)
13438{
13439 /* currently, no debugcb deinit */
13440
13441 qdf_trace_deinit();
13442
13443 /* currently, no trace spinlock deinit */
13444
13445 qdf_cpuhp_deinit();
Dustin Brownd315c452018-11-27 11:28:48 -080013446 qdf_talloc_feature_deinit();
Dustin Browna2a39dc2018-09-17 15:29:59 -070013447 qdf_event_list_destroy();
13448 qdf_mc_timer_manager_exit();
13449 qdf_mem_exit();
13450 qdf_lock_stats_deinit();
13451 qdf_debugfs_exit();
13452 hdd_qdf_print_deinit();
13453}
Dustin Brownf0f70562018-09-14 10:29:38 -070013454
13455/**
13456 * hdd_driver_load() - Perform the driver-level load operation
13457 *
13458 * Note: this is used in both static and DLKM driver builds
13459 *
13460 * Return: Errno
13461 */
13462static int hdd_driver_load(void)
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013463{
Dustin Brown21a1d462018-07-31 15:13:06 -070013464 struct hdd_driver *hdd_driver = hdd_driver_get();
Dustin Brownd585cb32018-09-12 17:12:23 -070013465 QDF_STATUS status;
Dustin Brownf0f70562018-09-14 10:29:38 -070013466 int errno;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013467
Rajeev Kumare555e2d2018-09-17 11:52:37 -070013468 pr_err("%s: Loading driver v%s\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070013469 WLAN_MODULE_NAME,
Rajeev Kumare555e2d2018-09-17 11:52:37 -070013470 g_wlan_driver_version);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013471
Dustin Browna2a39dc2018-09-17 15:29:59 -070013472 status = hdd_qdf_init();
13473 if (QDF_IS_STATUS_ERROR(status)) {
13474 errno = qdf_status_to_os_return(status);
13475 goto exit;
13476 }
13477
Dustin Brown21a1d462018-07-31 15:13:06 -070013478 status = hdd_driver_ctx_init(hdd_driver);
13479 if (QDF_IS_STATUS_ERROR(status)) {
13480 hdd_err("Failed to init driver context; status:%u", status);
13481 errno = qdf_status_to_os_return(status);
13482 goto qdf_deinit;
13483 }
13484
13485 status = dsc_driver_trans_start(hdd_driver->dsc_driver, "load");
13486 QDF_BUG(QDF_IS_STATUS_SUCCESS(status));
13487 if (QDF_IS_STATUS_ERROR(status)) {
13488 errno = qdf_status_to_os_return(status);
13489 goto hdd_driver_deinit;
13490 }
13491
Dustin Brownf0f70562018-09-14 10:29:38 -070013492 errno = hdd_init();
13493 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013494 hdd_err("Failed to init HDD; errno:%d", errno);
Dustin Brown21a1d462018-07-31 15:13:06 -070013495 goto trans_stop;
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013496 }
13497
Dustin Brownd585cb32018-09-12 17:12:23 -070013498 status = hdd_component_init();
13499 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013500 hdd_err("Failed to init components; status:%u", status);
Dustin Brownf0f70562018-09-14 10:29:38 -070013501 errno = qdf_status_to_os_return(status);
Dustin Brownd585cb32018-09-12 17:12:23 -070013502 goto hdd_deinit;
13503 }
Mukul Sharmad75a6672017-06-22 15:40:53 +053013504
Dustin Brownf0f70562018-09-14 10:29:38 -070013505 status = qdf_wake_lock_create(&wlan_wake_lock, "wlan");
13506 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013507 hdd_err("Failed to create wake lock; status:%u", status);
Dustin Brownf0f70562018-09-14 10:29:38 -070013508 errno = qdf_status_to_os_return(status);
13509 goto comp_deinit;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013510 }
13511
Dustin Brownf0f70562018-09-14 10:29:38 -070013512 hdd_set_conparam(con_mode);
13513
Dustin Brownf0f70562018-09-14 10:29:38 -070013514 errno = wlan_hdd_state_ctrl_param_create();
13515 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013516 hdd_err("Failed to create ctrl param; errno:%d", errno);
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013517 goto wakelock_destroy;
13518 }
13519
Dustin Brown25843ad2018-09-17 14:54:33 -070013520 errno = pld_init();
13521 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013522 hdd_err("Failed to init PLD; errno:%d", errno);
Dustin Brown25843ad2018-09-17 14:54:33 -070013523 goto param_destroy;
13524 }
13525
Dustin Brown21a1d462018-07-31 15:13:06 -070013526 hdd_driver->state = driver_state_loaded;
13527 dsc_driver_trans_stop(hdd_driver->dsc_driver);
13528
13529 /* psoc probe can happen in registration; do after 'load' transition */
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013530 errno = wlan_hdd_register_driver();
13531 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013532 hdd_err("Failed to register driver; errno:%d", errno);
Dustin Brown25843ad2018-09-17 14:54:33 -070013533 goto pld_deinit;
Sachin Ahuja16904db2017-12-13 19:56:57 +053013534 }
13535
Dustin Browna2a39dc2018-09-17 15:29:59 -070013536 hdd_debug("%s: driver loaded", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013537
13538 return 0;
Dustin Brownd585cb32018-09-12 17:12:23 -070013539
Dustin Brown25843ad2018-09-17 14:54:33 -070013540pld_deinit:
Dustin Brown21a1d462018-07-31 15:13:06 -070013541 status = dsc_driver_trans_start(hdd_driver->dsc_driver, "unload");
13542 QDF_BUG(QDF_IS_STATUS_SUCCESS(status));
13543
Dustin Brown25843ad2018-09-17 14:54:33 -070013544 pld_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013545
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013546param_destroy:
13547 wlan_hdd_state_ctrl_param_destroy();
Dustin Brownf0f70562018-09-14 10:29:38 -070013548wakelock_destroy:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053013549 qdf_wake_lock_destroy(&wlan_wake_lock);
Dustin Brownf0f70562018-09-14 10:29:38 -070013550comp_deinit:
Dustin Brownd585cb32018-09-12 17:12:23 -070013551 hdd_component_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013552hdd_deinit:
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013553 hdd_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013554trans_stop:
13555 hdd_driver->state = driver_state_deinit;
13556 dsc_driver_trans_stop(hdd_driver->dsc_driver);
13557hdd_driver_deinit:
13558 hdd_driver_ctx_deinit(hdd_driver);
Dustin Browna2a39dc2018-09-17 15:29:59 -070013559qdf_deinit:
13560 hdd_qdf_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013561
Dustin Brown25843ad2018-09-17 14:54:33 -070013562exit:
Dustin Brownf0f70562018-09-14 10:29:38 -070013563 return errno;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013564}
13565
13566/**
Dustin Brownf0f70562018-09-14 10:29:38 -070013567 * hdd_driver_unload() - Performs the driver-level unload operation
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013568 *
Dustin Brownf0f70562018-09-14 10:29:38 -070013569 * Note: this is used in both static and DLKM driver builds
13570 *
13571 * Return: None
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013572 */
Dustin Brownf0f70562018-09-14 10:29:38 -070013573static void hdd_driver_unload(void)
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013574{
Dustin Brown21a1d462018-07-31 15:13:06 -070013575 struct hdd_driver *hdd_driver = hdd_driver_get();
Will Huang36049722018-04-13 11:48:51 +080013576 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Dustin Brown21a1d462018-07-31 15:13:06 -070013577 QDF_STATUS status;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053013578
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013579 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
13580 QWLAN_VERSIONSTR);
13581
Dustin Brown8c0b5e32019-01-18 13:56:02 -080013582 if (g_is_system_reboot_triggered) {
13583 hdd_info("System rebooting; Skipping unload");
13584 return;
13585 }
13586
13587 if (hdd_ctx)
13588 hdd_psoc_idle_timer_stop(hdd_ctx);
13589
13590 /* trigger SoC remove */
13591 wlan_hdd_unregister_driver();
13592
Dustin Brown21a1d462018-07-31 15:13:06 -070013593 status = dsc_driver_trans_start_wait(hdd_driver->dsc_driver, "unload");
13594 QDF_BUG(QDF_IS_STATUS_SUCCESS(status));
13595 if (QDF_IS_STATUS_ERROR(status)) {
13596 hdd_err("Unable to unload wlan; status:%u", status);
Arunk Khandavalli830c9692018-03-22 12:17:40 +053013597 return;
Dustin Brown21a1d462018-07-31 15:13:06 -070013598 }
13599
13600 dsc_driver_wait_for_ops(hdd_driver->dsc_driver);
13601
Will Huangba035ec2018-07-05 11:13:30 +080013602 cds_set_driver_loaded(false);
13603 cds_set_unload_in_progress(true);
13604
13605 if (!cds_wait_for_external_threads_completion(__func__))
13606 hdd_warn("External threads are still active attempting "
13607 "driver unload anyway");
13608
Dustin Brown25843ad2018-09-17 14:54:33 -070013609 pld_deinit();
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013610 wlan_hdd_state_ctrl_param_destroy();
Dustin Brownf0f70562018-09-14 10:29:38 -070013611 hdd_set_conparam(0);
Anurag Chouhana37b5b72016-02-21 14:53:42 +053013612 qdf_wake_lock_destroy(&wlan_wake_lock);
Dustin Brownd585cb32018-09-12 17:12:23 -070013613 hdd_component_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013614 hdd_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013615
13616 hdd_driver->state = driver_state_deinit;
13617 dsc_driver_trans_stop(hdd_driver->dsc_driver);
Dustin Brown623e7e32018-09-05 14:27:50 -070013618
Dustin Brown21a1d462018-07-31 15:13:06 -070013619 hdd_driver_ctx_deinit(hdd_driver);
13620
Dustin Browna2a39dc2018-09-17 15:29:59 -070013621 hdd_qdf_deinit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013622}
13623
Arun Khandavallifae92942016-08-01 13:31:08 +053013624#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013625/**
Arun Khandavallifae92942016-08-01 13:31:08 +053013626 * wlan_boot_cb() - Wlan boot callback
13627 * @kobj: object whose directory we're creating the link in.
13628 * @attr: attribute the user is interacting with
13629 * @buff: the buffer containing the user data
13630 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013631 *
Arun Khandavallifae92942016-08-01 13:31:08 +053013632 * This callback is invoked when the fs is ready to start the
13633 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013634 *
Arun Khandavallifae92942016-08-01 13:31:08 +053013635 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013636 */
Arun Khandavallifae92942016-08-01 13:31:08 +053013637static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013638 struct kobj_attribute *attr,
13639 const char *buf,
13640 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013641{
Arun Khandavallifae92942016-08-01 13:31:08 +053013642
Arun Khandavallifae92942016-08-01 13:31:08 +053013643 if (wlan_loader->loaded_state) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013644 hdd_err("wlan driver already initialized");
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013645 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053013646 }
13647
Dustin Brownf0f70562018-09-14 10:29:38 -070013648 if (hdd_driver_load())
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013649 return -EIO;
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013650
13651 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053013652
13653 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013654}
Arun Khandavallifae92942016-08-01 13:31:08 +053013655
13656/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013657 * hdd_sysfs_cleanup() - cleanup sysfs
13658 *
13659 * Return: None
13660 *
13661 */
13662static void hdd_sysfs_cleanup(void)
13663{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013664 /* remove from group */
13665 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
13666 sysfs_remove_group(wlan_loader->boot_wlan_obj,
13667 wlan_loader->attr_group);
13668
13669 /* unlink the object from parent */
13670 kobject_del(wlan_loader->boot_wlan_obj);
13671
13672 /* free the object */
13673 kobject_put(wlan_loader->boot_wlan_obj);
13674
13675 kfree(wlan_loader->attr_group);
13676 kfree(wlan_loader);
13677
13678 wlan_loader = NULL;
13679}
13680
13681/**
Arun Khandavallifae92942016-08-01 13:31:08 +053013682 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
13683 * ready
13684 *
13685 * This is creates the syfs entry boot_wlan. Which shall be invoked
13686 * when the filesystem is ready.
13687 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013688 * QDF API cannot be used here since this function is called even before
13689 * initializing WLAN driver.
13690 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070013691 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053013692 */
13693static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013694{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013695 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053013696
13697 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013698 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013699 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053013700
13701 wlan_loader->boot_wlan_obj = NULL;
13702 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
13703 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013704 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053013705 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053013706
13707 wlan_loader->loaded_state = 0;
13708 wlan_loader->attr_group->attrs = attrs;
13709
Qun Zhang4a83a462018-09-11 16:28:51 +080013710 wlan_loader->boot_wlan_obj = kobject_create_and_add(WLAN_LOADER_NAME,
Arun Khandavallifae92942016-08-01 13:31:08 +053013711 kernel_kobj);
13712 if (!wlan_loader->boot_wlan_obj) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013713 hdd_err("sysfs create and add failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053013714 goto error_return;
13715 }
13716
13717 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
13718 wlan_loader->attr_group);
13719 if (ret) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013720 hdd_err("sysfs create group failed; errno:%d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053013721 goto error_return;
13722 }
13723
13724 return 0;
13725
13726error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013727 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053013728
13729 return ret;
13730}
13731
13732/**
13733 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
13734 *
13735 * Return: 0 on success or errno on failure
13736 */
13737static int wlan_deinit_sysfs(void)
13738{
Arun Khandavallifae92942016-08-01 13:31:08 +053013739 if (!wlan_loader) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013740 hdd_err("wlan_loader is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053013741 return -EINVAL;
13742 }
13743
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013744 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013745 return 0;
13746}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013747
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013748#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053013749
13750#ifdef MODULE
13751/**
Dustin Brownf0f70562018-09-14 10:29:38 -070013752 * hdd_module_init() - Module init helper
Arun Khandavallifae92942016-08-01 13:31:08 +053013753 *
13754 * Module init helper function used by both module and static driver.
13755 *
13756 * Return: 0 for success, errno on failure
13757 */
13758static int hdd_module_init(void)
13759{
Dustin Brownf0f70562018-09-14 10:29:38 -070013760 if (hdd_driver_load())
Dustin Brownab482ac2017-06-09 17:00:44 -070013761 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053013762
Dustin Brownab482ac2017-06-09 17:00:44 -070013763 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053013764}
13765#else
13766static int __init hdd_module_init(void)
13767{
13768 int ret = -EINVAL;
13769
13770 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070013771 if (ret)
Dustin Browna2a39dc2018-09-17 15:29:59 -070013772 hdd_err("Failed to create sysfs entry");
Arun Khandavallifae92942016-08-01 13:31:08 +053013773
13774 return ret;
13775}
13776#endif
13777
13778
13779#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013780/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013781 * hdd_module_exit() - Exit function
13782 *
13783 * This is the driver exit point (invoked when module is unloaded using rmmod)
13784 *
13785 * Return: None
13786 */
13787static void __exit hdd_module_exit(void)
13788{
Dustin Brownf0f70562018-09-14 10:29:38 -070013789 hdd_driver_unload();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013790}
Arun Khandavallifae92942016-08-01 13:31:08 +053013791#else
13792static void __exit hdd_module_exit(void)
13793{
Dustin Brownf0f70562018-09-14 10:29:38 -070013794 hdd_driver_unload();
Arun Khandavallifae92942016-08-01 13:31:08 +053013795 wlan_deinit_sysfs();
13796}
13797#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013798
Srinivas Girigowda841da292018-02-21 16:33:00 -080013799static int fwpath_changed_handler(const char *kmessage,
13800 const struct kernel_param *kp)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013801{
13802 return param_set_copystring(kmessage, kp);
13803}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013804
Nirav Shah73713f72018-05-17 14:50:41 +053013805#ifdef FEATURE_MONITOR_MODE_SUPPORT
13806static bool is_monitor_mode_supported(void)
13807{
13808 return true;
13809}
13810#else
13811static bool is_monitor_mode_supported(void)
13812{
13813 pr_err("Monitor mode not supported!");
13814 return false;
13815}
13816#endif
13817
13818#ifdef WLAN_FEATURE_EPPING
13819static bool is_epping_mode_supported(void)
13820{
13821 return true;
13822}
13823#else
13824static bool is_epping_mode_supported(void)
13825{
13826 pr_err("Epping mode not supported!");
13827 return false;
13828}
13829#endif
13830
Ryan Hsu6e9db0b2018-06-01 10:45:51 -070013831#ifdef QCA_WIFI_FTM
13832static bool is_ftm_mode_supported(void)
13833{
13834 return true;
13835}
13836#else
13837static bool is_ftm_mode_supported(void)
13838{
13839 pr_err("FTM mode not supported!");
13840 return false;
13841}
13842#endif
13843
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013844/**
13845 * is_con_mode_valid() check con mode is valid or not
13846 * @mode: global con mode
13847 *
13848 * Return: TRUE on success FALSE on failure
13849 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080013850static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013851{
13852 switch (mode) {
13853 case QDF_GLOBAL_MONITOR_MODE:
Nirav Shah73713f72018-05-17 14:50:41 +053013854 return is_monitor_mode_supported();
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013855 case QDF_GLOBAL_EPPING_MODE:
Nirav Shah73713f72018-05-17 14:50:41 +053013856 return is_epping_mode_supported();
13857 case QDF_GLOBAL_FTM_MODE:
Ryan Hsu6e9db0b2018-06-01 10:45:51 -070013858 return is_ftm_mode_supported();
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013859 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013860 return true;
13861 default:
13862 return false;
13863 }
13864}
13865
Dustin Brown27cd9942017-09-27 16:11:44 -070013866static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080013867 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070013868{
13869 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
13870 return;
13871
13872 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070013873 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053013874 hdd_info("Release wakelock for monitor mode!");
13875 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
13876 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
Dundi Raviteja0a2a65b2018-04-30 12:34:11 +053013877 /* fallthrough */
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053013878 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070013879 case QDF_GLOBAL_FTM_MODE:
13880 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brown07901ec2018-09-07 11:02:41 -070013881 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, NULL);
Dustin Browndb2a8be2017-12-20 11:49:56 -080013882 hdd_stop_all_adapters(hdd_ctx);
Ashish Kumar Dhanotiya6ff329e2018-10-05 20:38:10 +053013883 hdd_deinit_all_adapters(hdd_ctx, false);
Dustin Brown27cd9942017-09-27 16:11:44 -070013884
Dustin Brown27cd9942017-09-27 16:11:44 -070013885 break;
13886 default:
13887 break;
13888 }
13889}
13890
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013891static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080013892 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013893{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053013894 int driver_status;
13895
13896 driver_status = hdd_ctx->driver_status;
13897
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013898 switch (curr_mode) {
13899 case QDF_GLOBAL_MISSION_MODE:
13900 case QDF_GLOBAL_MONITOR_MODE:
13901 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013902 hdd_close_all_adapters(hdd_ctx, false);
13903 break;
13904 case QDF_GLOBAL_EPPING_MODE:
13905 epping_disable();
13906 epping_close();
13907 break;
13908 default:
13909 return;
13910 }
13911}
13912
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013913static int
13914hdd_parse_driver_mode(const char *mode_str, enum QDF_GLOBAL_MODE *out_mode)
13915{
13916 int mode;
13917 int errno;
13918
Dustin Brown62743f42018-10-24 14:53:18 -070013919 *out_mode = QDF_GLOBAL_MAX_MODE;
13920
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013921 errno = kstrtoint(mode_str, 0, &mode);
13922 if (!errno)
13923 *out_mode = (enum QDF_GLOBAL_MODE)mode;
13924
13925 return errno;
13926}
13927
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013928/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013929 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013930 * @kmessage: con mode name on which driver to be bring up
13931 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013932 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013933 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013934 * This function is invoked when user updates con mode using sys entry,
13935 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013936 *
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013937 * Return: Errno
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013938 */
Srinivas Girigowda841da292018-02-21 16:33:00 -080013939static int __con_mode_handler(const char *kmessage,
13940 const struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013941 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013942{
Jeff Johnson876c1a62017-12-12 10:43:07 -080013943 enum QDF_GLOBAL_MODE curr_mode;
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013944 enum QDF_GLOBAL_MODE next_mode;
13945 int errno;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013946
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013947 hdd_info("Driver mode changing to %s", kmessage);
Dustin Brownab6029b2017-05-24 13:04:19 -070013948
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013949 errno = wlan_hdd_validate_context(hdd_ctx);
13950 if (errno)
13951 return errno;
13952
13953 errno = hdd_parse_driver_mode(kmessage, &next_mode);
13954 if (errno) {
13955 hdd_err_rl("Failed to parse driver mode '%s'", kmessage);
13956 return errno;
13957 }
13958
13959 if (!is_con_mode_valid(next_mode)) {
13960 hdd_err_rl("Requested driver mode is invalid");
13961 return -EINVAL;
13962 }
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013963
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013964 qdf_atomic_set(&hdd_ctx->con_mode_flag, 1);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013965 mutex_lock(&hdd_init_deinit_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +053013966
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013967 curr_mode = hdd_get_conparam();
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013968 if (curr_mode == next_mode) {
13969 hdd_err_rl("Driver is already in the requested mode");
13970 errno = 0;
13971 goto unlock;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013972 }
13973
Dustin Brown27cd9942017-09-27 16:11:44 -070013974 /* ensure adapters are stopped */
13975 hdd_stop_present_mode(hdd_ctx, curr_mode);
13976
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013977 errno = hdd_wlan_stop_modules(hdd_ctx, true);
13978 if (errno) {
Arun Khandavallifae92942016-08-01 13:31:08 +053013979 hdd_err("Stop wlan modules failed");
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013980 goto unlock;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013981 }
13982
Dustin Browndd4e50f2018-05-24 15:43:42 -070013983 /* Cleanup present mode before switching to new mode */
13984 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053013985
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013986 hdd_set_conparam(next_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013987
Dustin Brownc07ce8e2018-10-23 17:01:58 -070013988 errno = hdd_wlan_start_modules(hdd_ctx, false);
13989 if (errno) {
13990 hdd_err("Start wlan modules failed: %d", errno);
13991 goto unlock;
Arun Khandavallifae92942016-08-01 13:31:08 +053013992 }
13993
jitiphil7af5cf22018-10-26 16:06:27 +053013994 errno = hdd_open_adapters_for_mode(hdd_ctx, next_mode);
13995 if (errno) {
13996 hdd_err("Failed to open adapters");
13997 goto unlock;
13998 }
13999
Dustin Brownc07ce8e2018-10-23 17:01:58 -070014000 if (next_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Browne7e71d32018-05-11 16:00:08 -070014001 struct hdd_adapter *adapter =
Dustin Brownc07ce8e2018-10-23 17:01:58 -070014002 hdd_get_adapter(hdd_ctx, QDF_MONITOR_MODE);
Dustin Browne7e71d32018-05-11 16:00:08 -070014003
Dustin Brownc07ce8e2018-10-23 17:01:58 -070014004 QDF_BUG(adapter);
Dustin Browne7e71d32018-05-11 16:00:08 -070014005 if (!adapter) {
Dustin Brownc07ce8e2018-10-23 17:01:58 -070014006 hdd_err("Failed to get monitor adapter");
14007 goto unlock;
Dustin Browne7e71d32018-05-11 16:00:08 -070014008 }
14009
Dustin Brownc07ce8e2018-10-23 17:01:58 -070014010 errno = hdd_start_adapter(adapter);
14011 if (errno) {
14012 hdd_err("Failed to start monitor adapter");
14013 goto unlock;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053014014 }
Arun Khandavallifae92942016-08-01 13:31:08 +053014015
Dustin Brownc07ce8e2018-10-23 17:01:58 -070014016 hdd_info("Acquire wakelock for monitor mode");
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053014017 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
14018 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
14019 }
14020
Dustin Brown20024e32018-01-03 12:34:58 -080014021 /* con_mode is a global module parameter */
Dustin Brownc07ce8e2018-10-23 17:01:58 -070014022 con_mode = next_mode;
14023 hdd_info("Driver mode successfully changed to %s", kmessage);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053014024
Dustin Brownc07ce8e2018-10-23 17:01:58 -070014025 errno = 0;
14026
14027unlock:
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053014028 mutex_unlock(&hdd_init_deinit_lock);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053014029 qdf_atomic_set(&hdd_ctx->con_mode_flag, 0);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053014030
Dustin Brownc07ce8e2018-10-23 17:01:58 -070014031 return errno;
14032}
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053014033
Srinivas Girigowda841da292018-02-21 16:33:00 -080014034static int con_mode_handler(const char *kmessage, const struct kernel_param *kp)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053014035{
Dustin Brown67d30412018-09-20 12:10:22 -070014036 struct hdd_driver *hdd_driver = hdd_driver_get();
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014037 struct hdd_context *hdd_ctx;
Dustin Brown67d30412018-09-20 12:10:22 -070014038 QDF_STATUS status;
14039 int errno;
14040
14041 hdd_enter();
14042
Dustin Brown13fa9872018-11-13 10:57:45 -080014043 /* This handler will be invoked before module init when the wlan driver
14044 * is loaded using 'insmod wlan.ko con_mode=5' for example. Return
14045 * success in this case, as module init will bring up the correct
14046 * con_mode when it runs.
14047 */
14048 if (hdd_driver->state == driver_state_uninit)
14049 return 0;
14050
Rajeev Kumaracb73d02018-12-18 14:07:40 -080014051 if (hdd_driver->state == driver_state_deinit) {
14052 hdd_err_rl("driver is unloaded so load again");
14053 return -EAGAIN;
14054 }
14055
Dustin Brown67d30412018-09-20 12:10:22 -070014056 status = dsc_driver_trans_start_wait(hdd_driver->dsc_driver,
14057 "mode change");
14058 if (QDF_IS_STATUS_ERROR(status)) {
14059 hdd_err("Failed to start 'mode change'; status:%u", status);
14060 errno = qdf_status_to_os_return(status);
14061 goto exit;
14062 }
14063
14064 dsc_driver_wait_for_ops(hdd_driver->dsc_driver);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053014065
14066 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Dustin Brown67d30412018-09-20 12:10:22 -070014067 errno = wlan_hdd_validate_context(hdd_ctx);
14068 if (errno)
14069 goto trans_stop;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053014070
Ashish Kumar Dhanotiya759b3272018-05-18 17:49:46 +053014071 if (!cds_wait_for_external_threads_completion(__func__)) {
14072 hdd_warn("External threads are still active, can not change mode");
Dustin Brown67d30412018-09-20 12:10:22 -070014073 errno = -EAGAIN;
14074 goto trans_stop;
Ashish Kumar Dhanotiya759b3272018-05-18 17:49:46 +053014075 }
14076
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053014077 cds_ssr_protect(__func__);
Dustin Brown67d30412018-09-20 12:10:22 -070014078 errno = __con_mode_handler(kmessage, kp, hdd_ctx);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053014079 cds_ssr_unprotect(__func__);
14080
Dustin Brown67d30412018-09-20 12:10:22 -070014081trans_stop:
14082 dsc_driver_trans_stop(hdd_driver->dsc_driver);
14083
14084exit:
14085 hdd_exit();
14086
14087 return errno;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014088}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014089
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053014090static int con_mode_handler_ftm(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080014091 const struct kernel_param *kp)
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053014092{
14093 int ret;
14094
14095 ret = param_set_int(kmessage, kp);
14096
14097 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
14098 pr_err("Only FTM mode supported!");
14099 return -ENOTSUPP;
14100 }
14101
14102 hdd_set_conparam(con_mode_ftm);
14103 con_mode = con_mode_ftm;
14104
14105 return ret;
14106}
14107
Nirav Shah73713f72018-05-17 14:50:41 +053014108#ifdef FEATURE_MONITOR_MODE_SUPPORT
Ravi Joshia307f632017-07-17 23:41:41 -070014109static int con_mode_handler_monitor(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080014110 const struct kernel_param *kp)
Ravi Joshia307f632017-07-17 23:41:41 -070014111{
14112 int ret;
14113
14114 ret = param_set_int(kmessage, kp);
14115
14116 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
14117 pr_err("Only Monitor mode supported!");
14118 return -ENOTSUPP;
14119 }
14120
14121 hdd_set_conparam(con_mode_monitor);
14122 con_mode = con_mode_monitor;
14123
14124 return ret;
14125}
Nirav Shah73713f72018-05-17 14:50:41 +053014126#endif
Ravi Joshia307f632017-07-17 23:41:41 -070014127
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014128/**
14129 * hdd_get_conparam() - driver exit point
14130 *
14131 * This is the driver exit point (invoked when module is unloaded using rmmod)
14132 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080014133 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014134 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080014135enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014136{
Jeff Johnson876c1a62017-12-12 10:43:07 -080014137 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014138}
14139
Dustin Brownf0f70562018-09-14 10:29:38 -070014140void hdd_set_conparam(int32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014141{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080014142 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014143}
14144
Komal Seelamc11bb222016-01-27 18:57:10 +053014145/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014146 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
14147 * @hdd_ctx: HDD context
14148 *
14149 * Cleans up the pre cac interface, if it exists
14150 *
14151 * Return: None
14152 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014153void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014154{
14155 uint8_t session_id;
14156 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070014157 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014158
Jeff Johnson16528362018-06-14 12:34:16 -070014159 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->mac_handle, &session_id);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014160 if (QDF_IS_STATUS_ERROR(status)) {
14161 hdd_err("failed to get pre cac vdev id");
14162 return;
14163 }
14164
14165 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
14166 if (!precac_adapter) {
Jeff Johnsondd2f1fc2018-05-06 11:22:52 -070014167 hdd_err("invalid pre cac adapter");
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014168 return;
14169 }
14170
14171 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
14172 wlan_hdd_sap_pre_cac_failure,
14173 (void *)precac_adapter);
14174 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
14175
14176}
14177
14178/**
Komal Seelamec702b02016-02-24 18:42:16 +053014179 * hdd_update_ol_config - API to update ol configuration parameters
14180 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053014181 *
Komal Seelamc11bb222016-01-27 18:57:10 +053014182 * Return: void
14183 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014184static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053014185{
Abhishek Singh98278ce2018-12-27 11:41:03 +053014186 struct ol_config_info cfg = {0};
Anurag Chouhandf2b2682016-02-29 14:15:27 +053014187 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014188 bool self_recovery = false;
14189 QDF_STATUS status;
Komal Seelamc11bb222016-01-27 18:57:10 +053014190
Komal Seelamec702b02016-02-24 18:42:16 +053014191 if (!ol_ctx)
14192 return;
14193
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014194 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
14195 if (QDF_IS_STATUS_ERROR(status))
14196 hdd_err("Failed to get self recovery ini config");
14197
14198 cfg.enable_self_recovery = self_recovery;
Komal Seelamec702b02016-02-24 18:42:16 +053014199 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
14200 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
14201 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070014202 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053014203
14204 ol_init_ini_config(ol_ctx, &cfg);
14205}
14206
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014207#ifdef FEATURE_RUNTIME_PM
14208/**
14209 * hdd_populate_runtime_cfg() - populate runtime configuration
14210 * @hdd_ctx: hdd context
14211 * @cfg: pointer to the configuration memory being populated
14212 *
14213 * Return: void
14214 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014215static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014216 struct hif_config_info *cfg)
14217{
14218 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
Wu Gao66454f12018-09-26 19:55:41 +080014219 cfg->runtime_pm_delay =
14220 ucfg_pmo_get_runtime_pm_delay(hdd_ctx->psoc);
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014221}
14222#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014223static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014224 struct hif_config_info *cfg)
14225{
14226}
14227#endif
14228
Komal Seelamec702b02016-02-24 18:42:16 +053014229/**
14230 * hdd_update_hif_config - API to update HIF configuration parameters
14231 * @hdd_ctx: HDD Context
14232 *
14233 * Return: void
14234 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014235static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053014236{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053014237 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Abhishek Singh98278ce2018-12-27 11:41:03 +053014238 struct hif_config_info cfg = {0};
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014239 bool prevent_link_down = false;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014240 bool self_recovery = false;
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014241 QDF_STATUS status;
Komal Seelamec702b02016-02-24 18:42:16 +053014242
14243 if (!scn)
14244 return;
14245
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014246 status = ucfg_mlme_get_prevent_link_down(hdd_ctx->psoc,
14247 &prevent_link_down);
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014248 if (QDF_IS_STATUS_ERROR(status))
14249 hdd_err("Failed to get prevent_link_down config");
14250
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014251 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
14252 if (QDF_IS_STATUS_ERROR(status))
14253 hdd_err("Failed to get self recovery ini config");
14254
14255 cfg.enable_self_recovery = self_recovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014256 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053014257 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070014258
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014259 if (prevent_link_down)
Dustin Brownee3e0592017-09-07 13:50:11 -070014260 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053014261}
14262
14263/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014264 * hdd_update_dp_config() - Propagate config parameters to Lithium
14265 * datapath
14266 * @hdd_ctx: HDD Context
14267 *
14268 * Return: 0 for success/errno for failure
14269 */
14270static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
14271{
Abhishek Singh98278ce2018-12-27 11:41:03 +053014272 struct cdp_config_params params = {0};
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014273 QDF_STATUS status;
jitiphil377bcc12018-10-05 19:46:08 +053014274 void *soc;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014275
jitiphil377bcc12018-10-05 19:46:08 +053014276 soc = cds_get_context(QDF_MODULE_ID_SOC);
14277 params.tso_enable = cfg_get(hdd_ctx->psoc, CFG_DP_TSO);
14278 params.lro_enable = cfg_get(hdd_ctx->psoc, CFG_DP_LRO);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014279#ifdef QCA_LL_TX_FLOW_CONTROL_V2
14280 params.tx_flow_stop_queue_threshold =
jitiphil47c3d9a2018-11-08 18:30:55 +053014281 cfg_get(hdd_ctx->psoc, CFG_DP_TX_FLOW_STOP_QUEUE_TH);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014282 params.tx_flow_start_queue_offset =
jitiphil47c3d9a2018-11-08 18:30:55 +053014283 cfg_get(hdd_ctx->psoc,
14284 CFG_DP_TX_FLOW_START_QUEUE_OFFSET);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014285#endif
jitiphil377bcc12018-10-05 19:46:08 +053014286 params.flow_steering_enable =
14287 cfg_get(hdd_ctx->psoc, CFG_DP_FLOW_STEERING_ENABLED);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014288 params.napi_enable = hdd_ctx->napi_enable;
14289 params.tcp_udp_checksumoffload =
jitiphil377bcc12018-10-05 19:46:08 +053014290 cfg_get(hdd_ctx->psoc,
14291 CFG_DP_TCP_UDP_CKSUM_OFFLOAD);
Sravan Kumar Kairam0af1ee52018-12-12 20:37:51 +053014292 params.ipa_enable = ucfg_ipa_is_enabled();
Mohit Khanna81418772018-10-30 14:14:46 -070014293 params.gro_enable = cfg_get(hdd_ctx->psoc, CFG_DP_GRO);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014294
jitiphil377bcc12018-10-05 19:46:08 +053014295 status = cdp_update_config_parameters(soc, &params);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014296 if (status) {
Dustin Browna2868622018-03-20 11:38:14 -070014297 hdd_err("Failed to attach config parameters");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014298 return status;
14299 }
14300
14301 return 0;
14302}
14303
14304/**
Komal Seelamec702b02016-02-24 18:42:16 +053014305 * hdd_update_config() - Initialize driver per module ini parameters
14306 * @hdd_ctx: HDD Context
14307 *
14308 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053014309 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053014310 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014311int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053014312{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053014313 int ret;
14314
Wu Gao66454f12018-09-26 19:55:41 +080014315 if (ucfg_pmo_is_ns_offloaded(hdd_ctx->psoc))
14316 hdd_ctx->ns_offload_enable = true;
14317
Komal Seelamec702b02016-02-24 18:42:16 +053014318 hdd_update_ol_config(hdd_ctx);
14319 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053014320 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
14321 ret = hdd_update_cds_config_ftm(hdd_ctx);
14322 else
14323 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080014324 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053014325
14326 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053014327}
14328
Mukul Sharma9d797a02017-01-05 20:26:03 +053014329#ifdef FEATURE_WLAN_RA_FILTERING
14330/**
14331 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
14332 * @psoc_cfg: pmo psoc Configuration
14333 * @hdd_ctx: Pointer to hdd context
14334 *
14335 * Return: none
14336 */
14337static inline void hdd_ra_populate_pmo_config(
14338 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014339 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053014340{
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053014341 bool is_rate_limit_enabled;
14342 QDF_STATUS status;
14343
14344 status = ucfg_fwol_get_is_rate_limit_enabled(hdd_ctx->psoc,
14345 &is_rate_limit_enabled);
14346 if (QDF_IS_STATUS_ERROR(status))
14347 return;
14348
Mukul Sharma9d797a02017-01-05 20:26:03 +053014349 psoc_cfg->ra_ratelimit_enable =
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053014350 is_rate_limit_enabled;
Mukul Sharma9d797a02017-01-05 20:26:03 +053014351}
14352#else
14353static inline void hdd_ra_populate_pmo_config(
14354 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014355 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053014356{
14357}
14358#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080014359
Mukul Sharma9d797a02017-01-05 20:26:03 +053014360/**
14361 * hdd_update_pmo_config - API to update pmo configuration parameters
14362 * @hdd_ctx: HDD context
14363 *
14364 * Return: void
14365 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014366static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053014367{
Abhishek Singh98278ce2018-12-27 11:41:03 +053014368 struct pmo_psoc_cfg psoc_cfg = {0};
Mukul Sharma9d797a02017-01-05 20:26:03 +053014369 QDF_STATUS status;
Wu Gao66454f12018-09-26 19:55:41 +080014370 enum pmo_wow_enable_type wow_enable;
14371
14372 ucfg_pmo_get_psoc_config(hdd_ctx->psoc, &psoc_cfg);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014373
14374 /*
14375 * Value of hdd_ctx->wowEnable can be,
14376 * 0 - Disable both magic pattern match and pattern byte match.
14377 * 1 - Enable magic pattern match on all interfaces.
14378 * 2 - Enable pattern byte match on all interfaces.
14379 * 3 - Enable both magic patter and pattern byte match on
14380 * all interfaces.
14381 */
Wu Gao66454f12018-09-26 19:55:41 +080014382 wow_enable = ucfg_pmo_get_wow_enable(hdd_ctx->psoc);
14383 psoc_cfg.magic_ptrn_enable = (wow_enable & 0x01) ? true : false;
Mukul Sharma9d797a02017-01-05 20:26:03 +053014384 psoc_cfg.ptrn_match_enable_all_vdev =
Wu Gao66454f12018-09-26 19:55:41 +080014385 (wow_enable & 0x02) ? true : false;
Mukul Sharma9d797a02017-01-05 20:26:03 +053014386 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080014387 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Bala Venkatesh46e29032018-11-14 18:24:55 +053014388 ucfg_mlme_get_sap_max_modulated_dtim(hdd_ctx->psoc,
14389 &psoc_cfg.sta_max_li_mod_dtim);
14390
Mukul Sharma9d797a02017-01-05 20:26:03 +053014391
14392 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053014393 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014394
Dustin Brown1dbefe62018-09-11 16:32:03 -070014395 status = ucfg_pmo_update_psoc_config(hdd_ctx->psoc, &psoc_cfg);
Dustin Brownb9987af2018-03-01 17:15:11 -080014396 if (QDF_IS_STATUS_ERROR(status))
14397 hdd_err("failed pmo psoc configuration; status:%d", status);
14398
14399 return qdf_status_to_os_return(status);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014400}
14401
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014402void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014403 struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014404{
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014405 struct wlan_fwol_ie_whitelist whitelist = {0};
14406 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014407 QDF_STATUS status;
14408 bool is_ie_whitelist_enable = false;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014409 uint8_t i = 0;
14410
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014411 status = ucfg_fwol_get_ie_whitelist(psoc, &is_ie_whitelist_enable);
14412 if (QDF_IS_STATUS_ERROR(status)) {
14413 hdd_err("Unable to get IE whitelist param");
14414 return;
14415 }
14416
14417 ie_whitelist->white_list = is_ie_whitelist_enable;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014418 if (!ie_whitelist->white_list)
14419 return;
14420
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014421 status = ucfg_fwol_get_all_whitelist_params(psoc, &whitelist);
14422 if (QDF_IS_STATUS_ERROR(status)) {
14423 hdd_err("Unable to get all whitelist params");
14424 return;
14425 }
14426
14427 ie_whitelist->ie_bitmap[0] = whitelist.ie_bitmap_0;
14428 ie_whitelist->ie_bitmap[1] = whitelist.ie_bitmap_1;
14429 ie_whitelist->ie_bitmap[2] = whitelist.ie_bitmap_2;
14430 ie_whitelist->ie_bitmap[3] = whitelist.ie_bitmap_3;
14431 ie_whitelist->ie_bitmap[4] = whitelist.ie_bitmap_4;
14432 ie_whitelist->ie_bitmap[5] = whitelist.ie_bitmap_5;
14433 ie_whitelist->ie_bitmap[6] = whitelist.ie_bitmap_6;
14434 ie_whitelist->ie_bitmap[7] = whitelist.ie_bitmap_7;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014435
Dundi Raviteja9ab4e7b2018-09-28 14:18:28 +053014436 ie_whitelist->num_vendor_oui = whitelist.no_of_probe_req_ouis;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014437 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
Dundi Raviteja9ab4e7b2018-09-28 14:18:28 +053014438 ie_whitelist->voui[i] = whitelist.probe_req_voui[i];
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014439}
14440
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014441uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
14442{
14443 uint8_t i, score;
14444
14445 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
14446 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
14447 if (score > MAX_INDEX_SCORE)
14448 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
14449 MAX_INDEX_SCORE, i);
14450 }
14451
14452 return per_index_score;
14453}
14454
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014455QDF_STATUS hdd_update_score_config(
14456 struct scoring_config *score_config, struct hdd_context *hdd_ctx)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014457{
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014458 struct hdd_config *cfg = hdd_ctx->config;
gaurank kathpaliaae52c982018-10-04 01:35:18 +053014459 QDF_STATUS status;
gaurank kathpalia651abcd2018-11-12 22:41:23 +053014460 struct wlan_mlme_nss_chains vdev_ini_cfg;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014461 bool bval = false;
Wu Gaoed616a12019-01-16 15:19:21 +080014462 uint32_t channel_bonding_mode;
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014463
Abhishek Singh98278ce2018-12-27 11:41:03 +053014464 qdf_mem_zero(&vdev_ini_cfg, sizeof(struct wlan_mlme_nss_chains));
gaurank kathpalia651abcd2018-11-12 22:41:23 +053014465 /* Populate the nss chain params from ini for this vdev type */
14466 sme_populate_nss_chain_params(hdd_ctx->mac_handle, &vdev_ini_cfg,
14467 QDF_STA_MODE,
14468 hdd_ctx->num_rf_chains);
14469
14470 score_config->vdev_nss_24g = vdev_ini_cfg.rx_nss[NSS_CHAINS_BAND_2GHZ];
14471 score_config->vdev_nss_24g = vdev_ini_cfg.rx_nss[NSS_CHAINS_BAND_5GHZ];
14472
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014473 sme_update_score_config(hdd_ctx->mac_handle, score_config);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014474
Wu Gaoed616a12019-01-16 15:19:21 +080014475 ucfg_mlme_get_channel_bonding_24ghz(hdd_ctx->psoc,
14476 &channel_bonding_mode);
14477 score_config->cb_mode_24G = channel_bonding_mode;
14478 ucfg_mlme_get_channel_bonding_5ghz(hdd_ctx->psoc,
14479 &channel_bonding_mode);
14480 score_config->cb_mode_5G = channel_bonding_mode;
gaurank kathpaliaae52c982018-10-04 01:35:18 +053014481
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014482 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
14483 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
14484 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
14485 score_config->he_cap = 1;
14486
14487 if (score_config->he_cap ||
14488 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
14489 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
14490 score_config->vht_cap = 1;
14491
14492 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
14493 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
14494 score_config->ht_cap = 1;
14495
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014496 status = ucfg_mlme_get_vht_for_24ghz(hdd_ctx->psoc, &bval);
14497 if (!QDF_IS_STATUS_SUCCESS(status))
14498 hdd_err("Failed to get vht_for_24ghz");
14499 if (score_config->vht_cap && bval)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014500 score_config->vht_24G_cap = 1;
14501
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014502 status = ucfg_mlme_get_vht_enable_tx_bf(hdd_ctx->psoc,
14503 &bval);
14504 if (!QDF_IS_STATUS_SUCCESS(status))
14505 hdd_err("unable to get vht_enable_tx_bf");
14506
14507 if (bval)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014508 score_config->beamformee_cap = 1;
14509
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014510 return QDF_STATUS_SUCCESS;
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014511}
14512
Abhishek Singh257a9482017-03-06 16:52:39 +053014513/**
bings81fe50a2017-11-27 14:33:26 +080014514 * hdd_update_dfs_config() - API to update dfs configuration parameters.
14515 * @hdd_ctx: HDD context
14516 *
14517 * Return: 0 if success else err
14518 */
14519static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
14520{
Dustin Brown1dbefe62018-09-11 16:32:03 -070014521 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Abhishek Singh98278ce2018-12-27 11:41:03 +053014522 struct dfs_user_config dfs_cfg = {0};
bings81fe50a2017-11-27 14:33:26 +080014523 QDF_STATUS status;
14524
Arif Hussain224d3812018-11-16 17:58:38 -080014525 ucfg_mlme_get_dfs_filter_offload(hdd_ctx->psoc,
14526 &dfs_cfg.dfs_is_phyerr_filter_offload);
bings81fe50a2017-11-27 14:33:26 +080014527 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
14528 if (QDF_IS_STATUS_ERROR(status)) {
14529 hdd_err("failed dfs psoc configuration");
14530 return -EINVAL;
14531 }
14532
14533 return 0;
14534}
14535
14536/**
Abhishek Singh257a9482017-03-06 16:52:39 +053014537 * hdd_update_scan_config - API to update scan configuration parameters
14538 * @hdd_ctx: HDD context
14539 *
14540 * Return: 0 if success else err
14541 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014542static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053014543{
Dustin Brown1dbefe62018-09-11 16:32:03 -070014544 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Abhishek Singh98278ce2018-12-27 11:41:03 +053014545 struct scan_user_cfg scan_cfg = {0};
Abhishek Singh257a9482017-03-06 16:52:39 +053014546 struct hdd_config *cfg = hdd_ctx->config;
14547 QDF_STATUS status;
Krunal Sonid2c33e12018-12-06 15:02:37 -080014548 uint32_t mcast_mcc_rest_time = 0;
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014549
Abhishek Singh158fe252017-03-23 11:09:34 +053014550 /* convert to ms */
14551 scan_cfg.scan_cache_aging_time =
14552 cfg->scanAgingTimeout * 1000;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053014553 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070014554 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Krunal Sonid2c33e12018-12-06 15:02:37 -080014555 status = ucfg_mlme_get_sta_miracast_mcc_rest_time(hdd_ctx->psoc,
14556 &mcast_mcc_rest_time);
14557 if (!QDF_IS_STATUS_SUCCESS(status)) {
14558 hdd_err("ucfg_mlme_get_sta_miracast_mcc_rest_time, use def");
14559 return -EIO;
14560 }
14561 scan_cfg.sta_miracast_mcc_rest_time = mcast_mcc_rest_time;
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014562 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, hdd_ctx);
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014563
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014564 status = hdd_update_score_config(&scan_cfg.score_config, hdd_ctx);
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014565 if (QDF_IS_STATUS_ERROR(status)) {
14566 hdd_err("Failed to update scoring config");
14567 return -EINVAL;
14568 }
Abhishek Singhb20db962017-03-03 21:28:46 +053014569
Abhishek Singh257a9482017-03-06 16:52:39 +053014570 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
14571 if (status != QDF_STATUS_SUCCESS) {
14572 hdd_err("failed pmo psoc configuration");
14573 return -EINVAL;
14574 }
14575
14576 return 0;
14577}
Abhishek Singh257a9482017-03-06 16:52:39 +053014578
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014579int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053014580{
14581 int ret;
14582
14583 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053014584 if (ret)
14585 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014586
Abhishek Singh257a9482017-03-06 16:52:39 +053014587 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080014588 if (ret)
14589 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014590
Frank Liud4b2fa02017-03-29 11:46:48 +080014591 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014592 if (ret)
14593 return ret;
14594
14595 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080014596 if (ret)
14597 return ret;
14598
14599 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014600
14601 return ret;
14602}
14603
Agrawal Ashish65634612016-08-18 13:24:32 +053014604/**
14605 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
14606 * @mode : cfg80211 DFS mode
14607 *
14608 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
14609 */
14610enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
14611{
14612 switch (mode) {
14613 case DFS_MODE_ENABLE:
14614 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014615 case DFS_MODE_DISABLE:
14616 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014617 case DFS_MODE_DEPRIORITIZE:
14618 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014619 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080014620 hdd_debug("ACS dfs mode is NONE");
14621 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014622 }
14623}
14624
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014625/**
14626 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
14627 * @hddctx: pointer to hdd context
14628 * @set_value: enable/disable
14629 *
14630 * When Host sends vendor command enable, FW will send *ONE* CA ind to
14631 * Host(even though it is duplicate). When Host send vendor command
14632 * disable,FW doesn't perform any action. Whenever any change in
14633 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
14634 *
14635 * return - 0 on success, appropriate error values on failure.
14636 */
Jeff Johnson16528362018-06-14 12:34:16 -070014637int hdd_enable_disable_ca_event(struct hdd_context *hdd_ctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014638{
14639 QDF_STATUS status;
14640
Jeff Johnson16528362018-06-14 12:34:16 -070014641 if (0 != wlan_hdd_validate_context(hdd_ctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014642 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014643
Jeff Johnson16528362018-06-14 12:34:16 -070014644 status = sme_enable_disable_chanavoidind_event(hdd_ctx->mac_handle,
14645 set_value);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014646 if (!QDF_IS_STATUS_SUCCESS(status)) {
14647 hdd_err("Failed to send chan avoid command to SME");
14648 return -EINVAL;
14649 }
14650 return 0;
14651}
Agrawal Ashish65634612016-08-18 13:24:32 +053014652
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014653/**
14654 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
14655 * @value: value to set
14656 *
14657 * This function will set the passed value to roaming in progress flag.
14658 *
14659 * Return: None
14660 */
14661void hdd_set_roaming_in_progress(bool value)
14662{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014663 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014664
14665 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14666 if (!hdd_ctx) {
14667 hdd_err("HDD context is NULL");
14668 return;
14669 }
14670
14671 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080014672 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014673}
14674
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014675bool hdd_is_roaming_in_progress(struct hdd_context *hdd_ctx)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014676{
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014677 if (!hdd_ctx) {
14678 hdd_err("HDD context is NULL");
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014679 return false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014680 }
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080014681
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014682 hdd_debug("roaming_in_progress = %d", hdd_ctx->roaming_in_progress);
14683
14684 return hdd_ctx->roaming_in_progress;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014685}
14686
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014687/**
14688 * hdd_is_connection_in_progress() - check if connection is in
14689 * progress
14690 * @session_id: session id
14691 * @reason: scan reject reason
14692 *
14693 * Go through each adapter and check if Connection is in progress
14694 *
14695 * Return: true if connection is in progress else false
14696 */
14697bool hdd_is_connection_in_progress(uint8_t *session_id,
14698 enum scan_reject_states *reason)
14699{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070014700 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070014701 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014702 uint8_t sta_id = 0;
14703 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014704 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -070014705 mac_handle_t mac_handle;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014706
14707 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14708 if (!hdd_ctx) {
14709 hdd_err("HDD context is NULL");
14710 return false;
14711 }
14712
Jeff Johnson16528362018-06-14 12:34:16 -070014713 mac_handle = hdd_ctx->mac_handle;
14714
Dustin Brown920397d2017-12-13 16:27:50 -080014715 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya929afa42018-06-01 15:04:44 -070014716 hdd_debug("Adapter with device mode %s(%d) exists",
Dustin Brown458027c2018-10-19 12:26:27 -070014717 qdf_opmode_str(adapter->device_mode),
14718 adapter->device_mode);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014719 if (((QDF_STA_MODE == adapter->device_mode)
14720 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
14721 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
14722 && (eConnectionState_Connecting ==
14723 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
14724 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014725 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014726 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070014727 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014728 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070014729 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014730 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014731 }
14732 return true;
14733 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070014734 /*
14735 * sme_neighbor_middle_of_roaming is for LFR2
14736 * hdd_is_roaming_in_progress is for LFR3
14737 */
14738 if (((QDF_STA_MODE == adapter->device_mode) &&
14739 sme_neighbor_middle_of_roaming(
Jeff Johnson16528362018-06-14 12:34:16 -070014740 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -070014741 adapter->session_id)) ||
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014742 hdd_is_roaming_in_progress(hdd_ctx)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014743 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014744 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070014745 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014746 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070014747 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014748 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014749 }
14750 return true;
14751 }
14752 if ((QDF_STA_MODE == adapter->device_mode) ||
14753 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
14754 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
14755 hdd_sta_ctx =
14756 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
14757 if ((eConnectionState_Associated ==
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053014758 hdd_sta_ctx->conn_info.connState)
14759 && sme_is_sta_key_exchange_in_progress(
Jeff Johnson16528362018-06-14 12:34:16 -070014760 mac_handle, adapter->session_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014761 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070014762 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014763 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014764 " is in middle of WPS/EAPOL exchange.",
14765 MAC_ADDR_ARRAY(sta_mac));
14766 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070014767 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014768 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014769 }
14770 return true;
14771 }
14772 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
14773 (QDF_P2P_GO_MODE == adapter->device_mode)) {
14774 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
14775 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014776 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014777 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014778 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014779 continue;
14780
14781 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014782 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070014783 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014784 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014785 " of SAP/GO is in middle of WPS/EAPOL exchange",
14786 MAC_ADDR_ARRAY(sta_mac));
14787 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070014788 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014789 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014790 }
14791 return true;
14792 }
14793 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014794 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014795 return true;
14796 }
14797 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014798 }
Dustin Brown920397d2017-12-13 16:27:50 -080014799
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014800 return false;
14801}
14802
14803/**
14804 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070014805 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014806 *
14807 * Return: None
14808 */
Jeff Johnson9d295242017-08-29 14:39:48 -070014809void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014810{
Jeff Johnson87251032017-08-29 13:31:11 -070014811 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070014812 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014813 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014814 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Jeff Johnsone4c11db2018-05-05 23:22:32 -070014815 tsap_config_t *sap_config;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014816 void *sap_ctx;
14817
14818 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070014819 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070014820 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014821
14822 mutex_lock(&hdd_ctx->sap_lock);
14823 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
14824 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014825 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
14826 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
14827 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
14828 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053014829 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014830 qdf_stop_bss_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +053014831 SME_CMD_STOP_BSS_TIMEOUT);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014832
14833 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014834 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014835 goto end;
14836 }
14837 }
14838 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -070014839 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070014840 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070014841 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014842 false);
Jeff Johnson6867ec32017-09-29 20:30:20 -070014843 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014844
14845 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014846 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014847 wlansap_reset_sap_config_add_ie(sap_config,
14848 eUPDATE_IE_ALL);
14849 goto end;
14850 }
14851
14852 qdf_event_reset(&hostapd_state->qdf_event);
14853 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
14854 sap_config,
14855 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014856 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014857 wlansap_reset_sap_config_add_ie(sap_config,
14858 eUPDATE_IE_ALL);
14859 goto end;
14860 }
14861
Jeff Johnson6867ec32017-09-29 20:30:20 -070014862 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014863 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053014864 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +053014865 SME_CMD_START_BSS_TIMEOUT);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014866 wlansap_reset_sap_config_add_ie(sap_config,
14867 eUPDATE_IE_ALL);
14868 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014869 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014870 goto end;
14871 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070014872 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014873 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014874 if (hostapd_state->bss_state == BSS_START) {
Dustin Brown1dbefe62018-09-11 16:32:03 -070014875 policy_mgr_incr_active_session(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014876 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070014877 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070014878 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014879 ap_adapter->device_mode,
14880 true);
14881 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014882 }
14883end:
14884 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014885}
14886
14887/**
14888 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
14889 * with non dfs acs
14890 *
14891 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
14892 *
14893 * Return: None
14894 */
14895void hdd_check_and_restart_sap_with_non_dfs_acs(void)
14896{
Jeff Johnson9d295242017-08-29 14:39:48 -070014897 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014898 struct hdd_context *hdd_ctx;
Jeff Johnson2b6982c2018-05-29 14:56:11 -070014899 struct cds_context *cds_ctx;
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014900 uint8_t restart_chan;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014901
14902 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14903 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014904 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014905 return;
14906 }
14907
14908 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
14909 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014910 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014911 return;
14912 }
14913
Dustin Brown1dbefe62018-09-11 16:32:03 -070014914 if (policy_mgr_get_concurrency_mode(hdd_ctx->psoc)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014915 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Dustin Brown7e761c72018-07-31 13:50:17 -070014916 hdd_debug("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014917 return;
14918 }
14919
14920 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Dustin Brown07901ec2018-09-07 11:02:41 -070014921 if (ap_adapter &&
14922 test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags) &&
14923 wlan_reg_is_dfs_ch(hdd_ctx->pdev,
14924 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014925
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014926 hdd_warn("STA-AP Mode DFS not supported, Switch SAP channel to Non DFS");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014927
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014928 restart_chan =
14929 hdd_get_safe_channel_from_pcl_and_acs_range(ap_adapter);
14930 if (!restart_chan ||
Dustin Brown07901ec2018-09-07 11:02:41 -070014931 wlan_reg_is_dfs_ch(hdd_ctx->pdev, restart_chan))
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014932 restart_chan = SAP_DEFAULT_5GHZ_CHANNEL;
14933
14934 hdd_switch_sap_channel(ap_adapter, restart_chan, true);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014935 }
14936}
14937
14938/**
14939 * hdd_set_connection_in_progress() - to set the connection in
14940 * progress flag
14941 * @value: value to set
14942 *
14943 * This function will set the passed value to connection in progress flag.
14944 * If value is previously being set to true then no need to set it again.
14945 *
14946 * Return: true if value is being set correctly and false otherwise.
14947 */
14948bool hdd_set_connection_in_progress(bool value)
14949{
14950 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014951 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014952
14953 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14954 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014955 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014956 return false;
14957 }
14958
14959 qdf_spin_lock(&hdd_ctx->connection_status_lock);
14960 /*
14961 * if the value is set to true previously and if someone is
14962 * trying to make it true again then it could be some race
14963 * condition being triggered. Avoid this situation by returning
14964 * false
14965 */
14966 if (hdd_ctx->connection_in_progress && value)
14967 status = false;
14968 else
14969 hdd_ctx->connection_in_progress = value;
14970 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
14971 return status;
14972}
14973
Jeff Johnson9d295242017-08-29 14:39:48 -070014974int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014975{
14976 if (!adapter) {
14977 hdd_err("Invalid adapter");
14978 return -EINVAL;
14979 }
14980 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070014981 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014982 WMA_VDEV_MCC_SET_TIME_QUOTA,
14983 set_value, VDEV_CMD);
14984 return 0;
14985
14986}
14987
Jeff Johnson9d295242017-08-29 14:39:48 -070014988int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014989{
14990 if (!adapter) {
14991 hdd_err("Invalid adapter");
14992 return -EINVAL;
14993 }
14994
14995 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070014996 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014997 WMA_VDEV_MCC_SET_TIME_LATENCY,
14998 set_value, VDEV_CMD);
14999 return 0;
15000}
15001
Jeff Johnson9d295242017-08-29 14:39:48 -070015002struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070015003 *psoc, uint8_t vdev_id)
15004{
Jeff Johnson9d295242017-08-29 14:39:48 -070015005 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070015006 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070015007
15008 /*
15009 * Currently PSOC is not being used. But this logic will
15010 * change once we have the converged implementation of
15011 * HDD context per PSOC in place. This would break if
15012 * multiple vdev objects reuse the vdev id.
15013 */
15014 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
15015 if (!adapter)
15016 hdd_err("Get adapter by vdev id failed");
15017
15018 return adapter;
15019}
15020
Jeff Johnson9d295242017-08-29 14:39:48 -070015021int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053015022 int8_t *rssi, int8_t *snr)
15023{
15024 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -070015025 mac_handle_t mac_handle;
Jeff Johnson025618c2018-03-18 14:41:00 -070015026 struct csr_roam_profile *roam_profile;
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053015027
Jeff Johnson025618c2018-03-18 14:41:00 -070015028 roam_profile = hdd_roam_profile(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -070015029 mac_handle = hdd_adapter_get_mac_handle(adapter);
15030 status = sme_get_rssi_snr_by_bssid(mac_handle,
Jeff Johnson025618c2018-03-18 14:41:00 -070015031 roam_profile, bssid, rssi, snr);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053015032 if (QDF_STATUS_SUCCESS != status) {
15033 hdd_warn("sme_get_rssi_snr_by_bssid failed");
15034 return -EINVAL;
15035 }
15036
15037 return 0;
15038}
15039
Ganesh Kondabattini35739572017-06-21 16:26:39 +053015040/**
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053015041 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
15042 * @adapter - HDD adapter
15043 *
15044 * Return: 0 on success and non zero value on failure
15045 */
15046int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
15047{
15048 struct hdd_context *hdd_ctx;
15049 int ret;
15050 QDF_STATUS status;
Krunal Sonie71838d2018-09-27 10:45:05 -070015051 uint8_t sys_pref = 0;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053015052
15053 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
15054 ret = wlan_hdd_validate_context(hdd_ctx);
15055 if (ret < 0)
15056 return ret;
15057
Krunal Sonie71838d2018-09-27 10:45:05 -070015058 ucfg_policy_mgr_get_sys_pref(hdd_ctx->psoc,
15059 &sys_pref);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053015060 /* set the system preferece to default */
Krunal Sonie71838d2018-09-27 10:45:05 -070015061 policy_mgr_set_cur_conc_system_pref(hdd_ctx->psoc, sys_pref);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053015062
15063 /* clear the bitmap */
15064 adapter->active_ac = 0;
15065
15066 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson16528362018-06-14 12:34:16 -070015067 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053015068
Jeff Johnson16528362018-06-14 12:34:16 -070015069 status = sme_send_limit_off_channel_params(hdd_ctx->mac_handle,
15070 adapter->session_id,
15071 false, 0, 0, false);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053015072 if (!QDF_IS_STATUS_SUCCESS(status)) {
15073 hdd_err("failed to reset limit off chan params");
15074 ret = -EINVAL;
15075 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053015076
15077 return ret;
15078}
15079
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053015080/**
15081 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
15082 * @drv_op: Enum indicating driver op
15083 *
15084 * Return: none
15085 */
15086void hdd_start_driver_ops_timer(int drv_op)
15087{
15088 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
15089 switch (drv_op) {
Jeff Johnson5794d4f2018-12-04 11:57:09 -080015090 case HDD_DRV_OP_PROBE:
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053015091 memcpy(drv_ops_string, "probe", sizeof("probe"));
15092 break;
Jeff Johnson5794d4f2018-12-04 11:57:09 -080015093 case HDD_DRV_OP_REMOVE:
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053015094 memcpy(drv_ops_string, "remove", sizeof("remove"));
15095 break;
Jeff Johnson5794d4f2018-12-04 11:57:09 -080015096 case HDD_DRV_OP_SHUTDOWN:
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053015097 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
15098 break;
Jeff Johnson5794d4f2018-12-04 11:57:09 -080015099 case HDD_DRV_OP_REINIT:
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053015100 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
15101 break;
Jeff Johnson5794d4f2018-12-04 11:57:09 -080015102 case HDD_DRV_OP_IFF_UP:
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053015103 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
15104 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053015105 }
15106
Dustin Brown45ed4bb2017-12-18 12:00:13 -080015107 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053015108 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
Dustin Browncfc54fe2018-06-18 16:17:41 -070015109 HDD_OPS_INACTIVITY_TIMEOUT * qdf_timer_get_multiplier());
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053015110}
15111
15112/**
15113 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
15114 *
15115 * Return: none
15116 */
15117void hdd_stop_driver_ops_timer(void)
15118{
15119 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
15120}
15121
15122/**
15123 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
15124 * inactivity timer
15125 *
15126 * Return: None
15127 */
15128void hdd_drv_ops_inactivity_handler(void)
15129{
Rajeev Kumar4471f1b2018-06-08 14:18:28 -070015130 hdd_err("WLAN_BUG_RCA %s: %d Sec timer expired while in .%s",
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053015131 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
15132
Dustin Brown45ed4bb2017-12-18 12:00:13 -080015133 if (hdd_drv_ops_task) {
15134 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
15135 qdf_print_thread_trace(hdd_drv_ops_task);
15136 } else {
15137 hdd_err("hdd_drv_ops_task is null");
15138 }
15139
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053015140 /* Driver shutdown is stuck, no recovery possible at this point */
15141 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
15142 sizeof("shutdown")))
15143 QDF_BUG(0);
15144
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080015145 if (cds_is_fw_down()) {
15146 hdd_err("FW is down");
15147 return;
15148 }
15149
Dustin Brown83044c22018-08-13 15:00:44 -070015150 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053015151}
15152
Yun Parkff6a16a2017-09-26 16:38:18 -070015153/**
15154 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
15155 * @struct hdd_context *hdd_ctx
15156 * @struct hdd_adapter *padapter
15157 * @bool enble
15158 *
15159 * Return: none
15160 */
15161void hdd_set_rx_mode_rps(bool enable)
15162{
15163 struct cds_config_info *cds_cfg = cds_get_ini_config();
Ryan Hsu0e878fa2018-05-04 15:22:09 -070015164 struct hdd_context *hdd_ctx;
15165 struct hdd_adapter *adapter;
Yun Parkff6a16a2017-09-26 16:38:18 -070015166
Ryan Hsu0e878fa2018-05-04 15:22:09 -070015167 if (!cds_cfg)
15168 return;
15169
15170 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
15171 if (!hdd_ctx)
15172 return;
15173
15174 adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
15175 if (!adapter)
15176 return;
15177
15178 if (!hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
Yun Parkff6a16a2017-09-26 16:38:18 -070015179 if (enable && !cds_cfg->rps_enabled)
15180 hdd_send_rps_ind(adapter);
15181 else if (!enable && cds_cfg->rps_enabled)
15182 hdd_send_rps_disable_ind(adapter);
15183 }
15184}
15185
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015186/* Register the module init/exit functions */
15187module_init(hdd_module_init);
15188module_exit(hdd_module_exit);
15189
15190MODULE_LICENSE("Dual BSD/GPL");
15191MODULE_AUTHOR("Qualcomm Atheros, Inc.");
15192MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
15193
Srinivas Girigowda841da292018-02-21 16:33:00 -080015194static const struct kernel_param_ops con_mode_ops = {
15195 .set = con_mode_handler,
15196 .get = param_get_int,
15197};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015198
Srinivas Girigowda841da292018-02-21 16:33:00 -080015199static const struct kernel_param_ops con_mode_ftm_ops = {
15200 .set = con_mode_handler_ftm,
15201 .get = param_get_int,
15202};
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053015203
Nirav Shah73713f72018-05-17 14:50:41 +053015204#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080015205static const struct kernel_param_ops con_mode_monitor_ops = {
15206 .set = con_mode_handler_monitor,
15207 .get = param_get_int,
15208};
Nirav Shah73713f72018-05-17 14:50:41 +053015209#endif
Ravi Joshia307f632017-07-17 23:41:41 -070015210
Srinivas Girigowda841da292018-02-21 16:33:00 -080015211static const struct kernel_param_ops fwpath_ops = {
15212 .set = fwpath_changed_handler,
15213 .get = param_get_string,
15214};
15215
15216module_param_cb(con_mode, &con_mode_ops, &con_mode,
15217 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
15218
15219module_param_cb(con_mode_ftm, &con_mode_ftm_ops, &con_mode_ftm,
15220 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
15221
Nirav Shah73713f72018-05-17 14:50:41 +053015222#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080015223module_param_cb(con_mode_monitor, &con_mode_monitor_ops, &con_mode_monitor,
15224 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Nirav Shah73713f72018-05-17 14:50:41 +053015225#endif
Srinivas Girigowda841da292018-02-21 16:33:00 -080015226
15227module_param_cb(fwpath, &fwpath_ops, &fwpath,
15228 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015229
15230module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
15231
15232module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
15233
15234module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);