blob: 966c9f68bc142191c0b3d8d7bf066395ac748e60 [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"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080029#include <wlan_hdd_includes.h>
30#include <cds_api.h>
31#include <cds_sched.h>
Arun Khandavallifae92942016-08-01 13:31:08 +053032#include <linux/cpu.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080033#include <linux/etherdevice.h>
34#include <linux/firmware.h>
35#include <wlan_hdd_tx_rx.h>
36#include <wni_api.h>
37#include <wlan_hdd_cfg.h>
38#include <wlan_ptt_sock_svc.h>
39#include <dbglog_host.h>
40#include <wlan_logging_sock_svc.h>
Qiwei Caiad9b01c2018-07-09 17:21:31 +080041#include <wlan_roam_debug.h>
Dustin Brown6412d1f2019-02-05 14:52:29 -080042#include "osif_sync.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080043#include <wlan_hdd_wowl.h>
44#include <wlan_hdd_misc.h>
45#include <wlan_hdd_wext.h>
46#include "wlan_hdd_trace.h"
47#include "wlan_hdd_ioctl.h"
48#include "wlan_hdd_ftm.h"
49#include "wlan_hdd_power.h"
50#include "wlan_hdd_stats.h"
Prashanth Bhatta527fd752016-04-28 12:35:23 -070051#include "wlan_hdd_scan.h"
Krunal Sonie9c12f52018-10-04 11:45:42 -070052#include "wlan_policy_mgr_ucfg.h"
Naveen Rawate02f8f52018-04-05 11:58:04 -070053#include <wlan_osif_request_manager.h>
Dustin Brown26b3d042017-12-21 11:13:27 -080054#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4bc0a622017-12-06 15:56:50 -080055#include "qdf_debug_domain.h"
Dustin Brown26b3d042017-12-21 11:13:27 -080056#endif
Dustin Brown8d8ab302019-03-05 16:19:36 -080057#include "qdf_delayed_work.h"
Dustin Brown4a93bb52019-03-13 11:46:34 -070058#include "qdf_periodic_work.h"
Dustin Brownd4241942018-02-26 12:51:37 -080059#include "qdf_str.h"
Dustin Brownd315c452018-11-27 11:28:48 -080060#include "qdf_talloc.h"
Dustin Brownd4241942018-02-26 12:51:37 -080061#include "qdf_trace.h"
62#include "qdf_types.h"
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070063#include <cdp_txrx_peer_ops.h>
Dhanashri Atrea8f82f22017-01-23 12:58:24 -080064#include <cdp_txrx_misc.h>
Mohit Khannaca4173b2017-09-12 21:52:19 -070065#include <cdp_txrx_stats.h>
bings0e03a982018-05-09 08:40:59 +080066#include "cdp_txrx_flow_ctrl_legacy.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080067
68#include <net/addrconf.h>
69#include <linux/wireless.h>
70#include <net/cfg80211.h>
71#include <linux/inetdevice.h>
72#include <net/addrconf.h>
73#include "wlan_hdd_cfg80211.h"
74#include "wlan_hdd_ext_scan.h"
75#include "wlan_hdd_p2p.h"
76#include <linux/rtnetlink.h>
77#include "sap_api.h"
78#include <linux/semaphore.h>
79#include <linux/ctype.h>
80#include <linux/compat.h>
Arunk Khandavalli830c9692018-03-22 12:17:40 +053081#include <linux/reboot.h>
Subrat Dash5f36fbe2019-02-12 16:28:14 +053082#include <linux/ethtool.h>
Tiger Yu8b119e92019-04-09 13:55:07 +080083
84#ifdef WLAN_FEATURE_DP_BUS_BANDWIDTH
85#include "qdf_periodic_work.h"
86#endif
87
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080088#ifdef MSM_PLATFORM
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080089#include <soc/qcom/subsystem_restart.h>
90#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080091#include <wlan_hdd_hostapd.h>
92#include <wlan_hdd_softap_tx_rx.h>
Jeff Johnson8bb61112018-03-31 13:33:54 -070093#include <wlan_hdd_green_ap.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080094#include "qwlan_version.h"
95#include "wma_types.h"
96#include "wlan_hdd_tdls.h"
97#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053098#include "cds_regdomain.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080099#endif /* FEATURE_WLAN_CH_AVOID */
Dustin Brownce46d1d2017-08-15 13:34:24 -0700100#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -0700101#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -0800102#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800103#include "wlan_hdd_nan.h"
104#include "wlan_hdd_debugfs.h"
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +0530105#include "wlan_hdd_debugfs_csr.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800106#include "wlan_hdd_driver_ops.h"
107#include "epping_main.h"
Poddar, Siddarth34872782017-08-10 14:08:51 +0530108#include "wlan_hdd_data_stall_detection.h"
stonezc9936cb2019-03-11 16:41:22 +0800109#include "wlan_hdd_mpta_helper.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800110
111#include <wlan_hdd_ipa.h>
112#include "hif.h"
113#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800114#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700115#include "wlan_hdd_tsf.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530116#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700117#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700118#include "wlan_hdd_lpass.h"
Nachiket Kukade63bb63d2018-11-21 14:42:14 +0530119#include "wlan_nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700120#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530121#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800122#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800123#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530124#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800125#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800126#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530127#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530128#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800129#include "os_if_wifi_pos.h"
130#include "wifi_pos_api.h"
131#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800132#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700133#include "os_if_nan.h"
134#include "nan_public_structs.h"
Nachiket Kukade85aa3782018-11-02 20:12:34 +0530135#include "nan_ucfg_api.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700136#include "wlan_reg_ucfg_api.h"
bings81fe50a2017-11-27 14:33:26 +0800137#include "wlan_dfs_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700138#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530139#include "sme_power_save_api.h"
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +0530140#include "enet.h"
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700141#include <cdp_txrx_cmn_struct.h>
Mohit Khanna70322002018-05-15 19:21:32 -0700142#include <dp_txrx.h>
Amar Singhal0928b192017-12-01 10:50:54 -0800143#include "wlan_hdd_sysfs.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530144#include "wlan_disa_ucfg_api.h"
Wu Gao52084c12018-05-17 20:47:11 +0800145#include "wlan_disa_obj_mgmt_api.h"
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +0530146#include "wlan_action_oui_ucfg_api.h"
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +0530147#include "wlan_ipa_ucfg_api.h"
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530148#include <target_if.h>
Alok Kumarb64650c2018-03-23 17:05:11 +0530149#include "wlan_hdd_nud_tracking.h"
Nachiket Kukaded0dd62e2018-05-21 18:39:22 +0530150#include "wlan_hdd_apf.h"
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -0700151#include "wlan_hdd_twt.h"
Rachit Kankane0dc3e852018-05-07 17:33:42 +0530152#include "qc_sap_ioctl.h"
Sandeep Puligillac5609d52018-05-17 19:23:41 -0700153#include "wlan_mlme_main.h"
Wu Gaoe5689792018-07-05 19:20:13 +0800154#include "wlan_p2p_cfg_api.h"
Wu Gao637d58a2018-12-08 10:37:34 +0800155#include "wlan_cfg80211_p2p.h"
Wu Gaobdb7f272018-07-05 19:33:26 +0800156#include "wlan_tdls_cfg_api.h"
Qiwei Caie689a262018-07-26 15:50:22 +0800157#include <wlan_hdd_rssi_monitor.h>
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +0530158#include "wlan_mlme_ucfg_api.h"
Sourav Mohapatra113685f2018-08-29 14:21:55 +0530159#include "wlan_fwol_ucfg_api.h"
Krunal Sonie71838d2018-09-27 10:45:05 -0700160#include "wlan_policy_mgr_ucfg.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530161#ifdef CNSS_GENL
162#include <net/cnss_nl.h>
163#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800164#include "wlan_reg_ucfg_api.h"
Zhang Qian47e22ce2018-01-04 15:38:38 +0800165#include "wlan_ocb_ucfg_api.h"
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -0800166#include <wlan_hdd_spectralscan.h>
gaurank kathpalia4a205fc2018-09-15 00:59:15 +0530167#include "wlan_green_ap_ucfg_api.h"
Liangwei Dong3abfe8f2018-09-20 02:25:44 -0400168#include <wlan_p2p_ucfg_api.h>
Mohit Khanna81418772018-10-30 14:14:46 -0700169#include <target_type.h>
Arun Kumar Khandavallideda5a82019-03-11 15:32:19 +0530170#include <wlan_hdd_debugfs_coex.h>
Liangwei Dong3abfe8f2018-09-20 02:25:44 -0400171
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800172#ifdef MODULE
173#define WLAN_MODULE_NAME module_name(THIS_MODULE)
174#else
175#define WLAN_MODULE_NAME "wlan"
176#endif
177
178#ifdef TIMER_MANAGER
179#define TIMER_MANAGER_STR " +TIMER_MANAGER"
180#else
181#define TIMER_MANAGER_STR ""
182#endif
183
184#ifdef MEMORY_DEBUG
185#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
186#else
187#define MEMORY_DEBUG_STR ""
188#endif
189
Dustin Brownc1034df2018-02-07 14:51:32 -0800190#ifdef PANIC_ON_BUG
191#define PANIC_ON_BUG_STR " +PANIC_ON_BUG"
192#else
193#define PANIC_ON_BUG_STR ""
194#endif
195
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530196bool g_is_system_reboot_triggered;
Sachin Ahujadddd2632017-03-07 19:07:24 +0530197int wlan_start_ret_val;
198static DECLARE_COMPLETION(wlan_start_comp);
199static unsigned int dev_num = 1;
200static struct cdev wlan_hdd_state_cdev;
201static struct class *class;
202static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530203#ifndef MODULE
204static struct gwlan_loader *wlan_loader;
205static ssize_t wlan_boot_cb(struct kobject *kobj,
206 struct kobj_attribute *attr,
207 const char *buf, size_t count);
208struct gwlan_loader {
209 bool loaded_state;
210 struct kobject *boot_wlan_obj;
211 struct attribute_group *attr_group;
212};
213
214static struct kobj_attribute wlan_boot_attribute =
215 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
216
217static struct attribute *attrs[] = {
218 &wlan_boot_attribute.attr,
219 NULL,
220};
221
222#define MODULE_INITIALIZED 1
Qun Zhang4a83a462018-09-11 16:28:51 +0800223
224#ifdef MULTI_IF_NAME
225#define WLAN_LOADER_NAME "boot_" MULTI_IF_NAME
226#else
227#define WLAN_LOADER_NAME "boot_wlan"
228#endif
Arun Khandavallifae92942016-08-01 13:31:08 +0530229#endif
230
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800231/* the Android framework expects this param even though we don't use it */
232#define BUF_LEN 20
233static char fwpath_buffer[BUF_LEN];
234static struct kparam_string fwpath = {
235 .string = fwpath_buffer,
236 .maxlen = BUF_LEN,
237};
238
239static char *country_code;
240static int enable_11d = -1;
241static int enable_dfs_chan_scan = -1;
242
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800243#define WLAN_NLINK_CESIUM 30
244
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530245static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800246
247#define WOW_MAX_FILTER_LISTS 1
248#define WOW_MAX_FILTERS_PER_LIST 4
249#define WOW_MIN_PATTERN_SIZE 6
250#define WOW_MAX_PATTERN_SIZE 64
251
Bala Venkatesh110b03e2018-07-10 16:02:08 +0530252/* max peer can be tdls peers + self peer + bss peer */
253#define HDD_MAX_VDEV_PEER_COUNT (HDD_MAX_NUM_TDLS_STA + 2)
Sourav Mohapatra808e3d42018-07-04 09:34:23 +0530254#define IS_IDLE_STOP (!cds_is_driver_unloading() && \
255 !cds_is_driver_recovering() && !cds_is_driver_loading())
Bala Venkatesh110b03e2018-07-10 16:02:08 +0530256
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800257#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
258static const struct wiphy_wowlan_support wowlan_support_reg_init = {
259 .flags = WIPHY_WOWLAN_ANY |
260 WIPHY_WOWLAN_MAGIC_PKT |
261 WIPHY_WOWLAN_DISCONNECT |
262 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
263 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
264 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
265 WIPHY_WOWLAN_4WAY_HANDSHAKE |
266 WIPHY_WOWLAN_RFKILL_RELEASE,
267 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
268 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
269 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
270};
271#endif
272
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700273static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
274 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
275 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
276 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
277 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
278 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
279 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
280 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
281 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
282 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
283 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
284 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
285 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
286 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
287 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
288 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
289 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
290 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
291 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
292 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
293 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
294 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
295 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
296 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
297 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
298 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
299 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
300 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
301 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
302 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
303 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
304 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
305 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
306 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
307 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700308 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700309 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700310 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530311 [QDF_MODULE_ID_GREEN_AP] = {QDF_TRACE_LEVEL_ALL},
Zhang Qian47e22ce2018-01-04 15:38:38 +0800312 [QDF_MODULE_ID_OCB] = {QDF_TRACE_LEVEL_ALL},
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530313 [QDF_MODULE_ID_IPA] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +0530314 [QDF_MODULE_ID_ACTION_OUI] = {QDF_TRACE_LEVEL_ALL},
Dustin Brown84f46ea2018-02-15 11:57:36 -0800315 [QDF_MODULE_ID_CONFIG] = {QDF_TRACE_LEVEL_ALL},
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +0530316 [QDF_MODULE_ID_MLME] = {QDF_TRACE_LEVEL_ALL},
Ashish Kumar Dhanotiya8d039c82018-07-11 20:41:14 +0530317 [QDF_MODULE_ID_TARGET] = {QDF_TRACE_LEVEL_ALL},
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -0700318 [QDF_MODULE_ID_CRYPTO] = {QDF_TRACE_LEVEL_ALL},
Sourav Mohapatra113685f2018-08-29 14:21:55 +0530319 [QDF_MODULE_ID_FWOL] = {QDF_TRACE_LEVEL_ALL},
Abhishek Singh0b0105f2018-09-25 10:44:16 +0530320 [QDF_MODULE_ID_SM_ENGINE] = {QDF_TRACE_LEVEL_ALL},
321 [QDF_MODULE_ID_CMN_MLME] = {QDF_TRACE_LEVEL_ALL},
Nachiket Kukade089b9832018-12-12 16:38:17 +0530322 [QDF_MODULE_ID_NAN] = {QDF_TRACE_LEVEL_ALL},
Ashish Kumar Dhanotiya6ed44342019-02-07 21:11:00 +0530323 [QDF_MODULE_ID_CP_STATS] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700324};
325
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530326struct notifier_block hdd_netdev_notifier;
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530327struct notifier_block system_reboot_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800328
329struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800330#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700331static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800332#endif
333
Sachin Ahujadddd2632017-03-07 19:07:24 +0530334void hdd_start_complete(int ret)
335{
336 wlan_start_ret_val = ret;
337
338 complete(&wlan_start_comp);
339}
340
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800341/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530342 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700343 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530344 *
345 * Return: none
346 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700347static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530348{
Jeff Johnson9d295242017-08-29 14:39:48 -0700349 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530350
Dustin Brown920397d2017-12-13 16:27:50 -0800351 hdd_for_each_adapter(hdd_ctx, adapter)
352 hdd_send_rps_ind(adapter);
Nirav Shahbd36b062016-07-18 11:12:59 +0530353}
354
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530355#ifdef QCA_HL_NETDEV_FLOW_CONTROL
356void wlan_hdd_mod_fc_timer(struct hdd_adapter *adapter,
357 enum netif_action_type action)
358{
359 if (!adapter->tx_flow_timer_initialized)
360 return;
361
362 if (action == WLAN_WAKE_NON_PRIORITY_QUEUE) {
363 qdf_mc_timer_stop(&adapter->tx_flow_control_timer);
Ajit Pal Singhe6da1de2018-12-27 16:20:45 +0530364 adapter->hdd_stats.tx_rx_stats.is_txflow_paused = false;
365 adapter->hdd_stats.tx_rx_stats.txflow_unpause_cnt++;
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530366 } else if (action == WLAN_STOP_NON_PRIORITY_QUEUE) {
367 QDF_STATUS status =
368 qdf_mc_timer_start(&adapter->tx_flow_control_timer,
369 WLAN_HDD_TX_FLOW_CONTROL_OS_Q_BLOCK_TIME);
370
371 if (!QDF_IS_STATUS_SUCCESS(status))
372 hdd_err("Failed to start tx_flow_control_timer");
373 else
374 adapter->
375 hdd_stats.tx_rx_stats.txflow_timer_cnt++;
376
377 adapter->hdd_stats.tx_rx_stats.txflow_pause_cnt++;
378 adapter->hdd_stats.tx_rx_stats.is_txflow_paused = true;
379 }
380}
381#endif /* QCA_HL_NETDEV_FLOW_CONTROL */
382
Tiger Yu8b119e92019-04-09 13:55:07 +0800383#ifdef WLAN_FEATURE_DP_BUS_BANDWIDTH
Alok Kumar2fad6442018-11-08 19:19:28 +0530384void wlan_hdd_update_tcp_rx_param(struct hdd_context *hdd_ctx, void *data)
385{
386 if (!hdd_ctx) {
387 hdd_err("HDD context is null");
388 return;
389 }
390
391 if (!data) {
392 hdd_err("Data is null");
393 return;
394 }
395 if (hdd_ctx->config->enable_tcp_param_update)
396 wlan_hdd_send_tcp_param_update_event(hdd_ctx, data, 1);
397 else
398 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
399 WLAN_SVC_WLAN_TP_IND,
400 data,
401 sizeof(struct wlan_rx_tp_data));
402}
403
404void wlan_hdd_update_tcp_tx_param(struct hdd_context *hdd_ctx, void *data)
405{
406 enum wlan_tp_level next_tx_level;
407 struct wlan_tx_tp_data *tx_tp_data;
408
409 if (!hdd_ctx) {
410 hdd_err("HDD context is null");
411 return;
412 }
413
414 if (!data) {
415 hdd_err("Data is null");
416 return;
417 }
418
419 tx_tp_data = (struct wlan_tx_tp_data *)data;
420 next_tx_level = tx_tp_data->level;
421
422 if (hdd_ctx->config->enable_tcp_param_update)
423 wlan_hdd_send_tcp_param_update_event(hdd_ctx, data, 0);
424 else
425 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
426 WLAN_SVC_WLAN_TP_TX_IND,
427 &next_tx_level,
428 sizeof(next_tx_level));
429}
430
431/**
432 * wlan_hdd_send_tcp_param_update_event() - Send vendor event to update
433 * TCP parameter through Wi-Fi HAL
434 * @hdd_ctx: Pointer to HDD context
435 * @data: Parameters to update
436 * @dir: Direction(tx/rx) to update
437 *
438 * Return: None
439 */
440void wlan_hdd_send_tcp_param_update_event(struct hdd_context *hdd_ctx,
441 void *data,
442 uint8_t dir)
443{
444 struct sk_buff *vendor_event;
445 uint32_t event_len;
446 bool tcp_limit_output = false;
447 bool tcp_del_ack_ind_enabled = false;
448 bool tcp_adv_win_scl_enabled = false;
449 enum wlan_tp_level next_tp_level = WLAN_SVC_TP_NONE;
450
451 event_len = sizeof(uint8_t) + sizeof(uint8_t) + NLMSG_HDRLEN;
452
453 if (dir == 0) /*TX Flow */ {
454 struct wlan_tx_tp_data *tx_tp_data =
455 (struct wlan_tx_tp_data *)data;
456
457 next_tp_level = tx_tp_data->level;
458
459 if (tx_tp_data->tcp_limit_output) {
460 /* TCP_LIMIT_OUTPUT_BYTES */
461 event_len += sizeof(uint32_t);
462 tcp_limit_output = true;
463 }
464 } else if (dir == 1) /* RX Flow */ {
465 struct wlan_rx_tp_data *rx_tp_data =
466 (struct wlan_rx_tp_data *)data;
467
468 next_tp_level = rx_tp_data->level;
469
470 if (rx_tp_data->rx_tp_flags & TCP_DEL_ACK_IND_MASK) {
471 event_len += sizeof(uint32_t); /* TCP_DELACK_SEG */
472 tcp_del_ack_ind_enabled = true;
473 }
474 if (rx_tp_data->rx_tp_flags & TCP_ADV_WIN_SCL_MASK) {
475 event_len += sizeof(uint32_t); /* TCP_ADV_WIN_SCALE */
476 tcp_adv_win_scl_enabled = true;
477 }
478 } else {
479 hdd_err("Invalid Direction [%d]", dir);
480 return;
481 }
482
483 vendor_event =
484 cfg80211_vendor_event_alloc(
485 hdd_ctx->wiphy,
486 NULL, event_len,
487 QCA_NL80211_VENDOR_SUBCMD_THROUGHPUT_CHANGE_EVENT_INDEX,
488 GFP_KERNEL);
489
490 if (!vendor_event) {
491 hdd_err("cfg80211_vendor_event_alloc failed");
492 return;
493 }
494
495 if (nla_put_u8(
496 vendor_event,
497 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_DIRECTION,
498 dir))
499 goto tcp_param_change_nla_failed;
500
501 if (nla_put_u8(
502 vendor_event,
503 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_THROUGHPUT_LEVEL,
504 (next_tp_level == WLAN_SVC_TP_LOW ?
505 QCA_WLAN_THROUGHPUT_LEVEL_LOW :
506 QCA_WLAN_THROUGHPUT_LEVEL_HIGH)))
507 goto tcp_param_change_nla_failed;
508
509 if (tcp_limit_output &&
510 nla_put_u32(
511 vendor_event,
512 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_TCP_LIMIT_OUTPUT_BYTES,
513 (next_tp_level == WLAN_SVC_TP_LOW ?
514 TCP_LIMIT_OUTPUT_BYTES_LOW :
515 TCP_LIMIT_OUTPUT_BYTES_HI)))
516 goto tcp_param_change_nla_failed;
517
518 if (tcp_del_ack_ind_enabled &&
519 (nla_put_u32(
520 vendor_event,
521 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_TCP_DELACK_SEG,
522 (next_tp_level == WLAN_SVC_TP_LOW ?
523 TCP_DEL_ACK_LOW : TCP_DEL_ACK_HI))))
524 goto tcp_param_change_nla_failed;
525
526 if (tcp_adv_win_scl_enabled &&
527 (nla_put_u32(
528 vendor_event,
529 QCA_WLAN_VENDOR_ATTR_THROUGHPUT_CHANGE_TCP_ADV_WIN_SCALE,
530 (next_tp_level == WLAN_SVC_TP_LOW ?
531 WIN_SCALE_LOW : WIN_SCALE_HI))))
532 goto tcp_param_change_nla_failed;
533
534 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
535 return;
536
537tcp_param_change_nla_failed:
538 hdd_err("nla_put api failed");
539 kfree_skb(vendor_event);
540}
Tiger Yu8b119e92019-04-09 13:55:07 +0800541#endif /*WLAN_FEATURE_DP_BUS_BANDWIDTH*/
Alok Kumar2fad6442018-11-08 19:19:28 +0530542
Nirav Shahbd36b062016-07-18 11:12:59 +0530543/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800544 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
545 * @vdev_id: vdev_id
546 * @action: action type
547 * @reason: reason type
548 *
549 * Return: none
550 */
551void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
552 enum netif_action_type action, enum netif_reason_type reason)
553{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700554 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700555 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800556
557 if (!hdd_ctx) {
558 hdd_err("hdd ctx is NULL");
559 return;
560 }
561 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530562 wlan_hdd_mod_fc_timer(adapter, action);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800563 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800564}
565
566/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700567 * Store WLAN driver version and timestamp info in global variables such that
568 * crash debugger can extract them from driver debug symbol and crashdump for
569 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800570 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800571#ifdef BUILD_TAG
Rajeev Kumare555e2d2018-09-17 11:52:37 -0700572uint8_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 -0800573#else
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;
Naveen Rawat93836252017-06-20 16:30:59 -0700575#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800576
577/**
Liangwei Dong17bf2662018-01-05 02:02:05 -0500578 * hdd_get_valid_chan() - return current chan list from regulatory.
579 * @hdd_ctx: HDD context
580 * @chan_list: buf hold returned chan list
581 * @chan_num: input buf size and output returned chan num
582 *
583 * This function helps get current available chan list from regulatory
584 * module. It excludes the "disabled" and "invalid" channels.
585 *
586 * Return: 0 for success.
587 */
588static int hdd_get_valid_chan(struct hdd_context *hdd_ctx,
589 uint8_t *chan_list,
590 uint32_t *chan_num)
591{
592 int i = 0, j = 0;
593 struct regulatory_channel *cur_chan_list;
594 struct wlan_objmgr_pdev *pdev;
595
Dustin Brown07901ec2018-09-07 11:02:41 -0700596 if (!hdd_ctx || !hdd_ctx->pdev || !chan_list || !chan_num)
Liangwei Dong17bf2662018-01-05 02:02:05 -0500597 return -EINVAL;
598
Dustin Brown07901ec2018-09-07 11:02:41 -0700599 pdev = hdd_ctx->pdev;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500600 cur_chan_list = qdf_mem_malloc(NUM_CHANNELS *
601 sizeof(struct regulatory_channel));
602 if (!cur_chan_list)
603 return -ENOMEM;
604
605 if (wlan_reg_get_current_chan_list(pdev, cur_chan_list) !=
606 QDF_STATUS_SUCCESS) {
607 qdf_mem_free(cur_chan_list);
608 return -EINVAL;
609 }
610
611 for (i = 0; i < NUM_CHANNELS; i++) {
612 uint32_t ch = cur_chan_list[i].chan_num;
613 enum channel_state state = wlan_reg_get_channel_state(pdev,
614 ch);
615
616 if (state != CHANNEL_STATE_DISABLE &&
617 state != CHANNEL_STATE_INVALID &&
618 j < *chan_num) {
619 chan_list[j] = (uint8_t)ch;
620 j++;
621 }
622 }
623 *chan_num = j;
624 qdf_mem_free(cur_chan_list);
625 return 0;
626}
627
628/**
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530629 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
630 * @adapter: HDD adapter
631 * @chan_number: Channel number
632 * @chan_bw: Bandwidth
633 *
634 * Checks if the given bandwidth is valid for the given channel number.
635 *
636 * Return: 0 for success, non-zero for failure
637 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700638int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530639 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800640 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530641{
Liangwei Dong17bf2662018-01-05 02:02:05 -0500642 uint8_t chan[NUM_CHANNELS];
643 uint32_t len = NUM_CHANNELS, i;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530644 bool found = false;
Jeff Johnson16528362018-06-14 12:34:16 -0700645 mac_handle_t mac_handle;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500646 int ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530647
Jeff Johnson16528362018-06-14 12:34:16 -0700648 mac_handle = hdd_adapter_get_mac_handle(adapter);
649 if (!mac_handle) {
650 hdd_err("Invalid MAC handle");
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530651 return -EINVAL;
652 }
653
Liangwei Dong17bf2662018-01-05 02:02:05 -0500654 ret = hdd_get_valid_chan(adapter->hdd_ctx, chan,
655 &len);
656 if (ret) {
657 hdd_err("error %d in getting valid channel list", ret);
658 return ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530659 }
660
661 for (i = 0; i < len; i++) {
662 if (chan[i] == chan_number) {
663 found = true;
664 break;
665 }
666 }
667
668 if (found == false) {
669 hdd_err("Channel not in driver's valid channel list");
670 return -EOPNOTSUPP;
671 }
672
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700673 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
674 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530675 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
676 return -EINVAL;
677 }
678
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700679 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530680 if (chan_bw == CH_WIDTH_80MHZ) {
681 hdd_err("BW80 not possible in 2.4GHz band");
682 return -EINVAL;
683 }
684 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
685 (chan_bw != CH_WIDTH_MAX)) {
686 hdd_err("Only BW20 possible on channel 14");
687 return -EINVAL;
688 }
689 }
690
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700691 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530692 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
693 (chan_bw != CH_WIDTH_MAX)) {
694 hdd_err("Only BW20 possible on channel 165");
695 return -EINVAL;
696 }
697 }
698
699 return 0;
700}
701
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800702#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
Dustin Brown98f7c822019-03-06 12:25:49 -0800703static inline struct net_device *hdd_net_dev_from_notifier(void *context)
704{
705 struct netdev_notifier_info *info = context;
706
707 return info->dev;
708}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800709#else
Dustin Brown98f7c822019-03-06 12:25:49 -0800710static inline struct net_device *hdd_net_dev_from_notifier(void *context)
711{
712 return context;
713}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800714#endif
Dustin Brown98f7c822019-03-06 12:25:49 -0800715
716static int __hdd_netdev_notifier_call(struct net_device *net_dev,
717 unsigned long state)
718{
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530719 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700720 struct hdd_context *hdd_ctx;
Min Liu8c5d99e2018-09-10 17:18:44 +0800721 struct wlan_objmgr_vdev *vdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800722
Dustin Brown98f7c822019-03-06 12:25:49 -0800723 hdd_enter_dev(net_dev);
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800724
Dustin Brown98f7c822019-03-06 12:25:49 -0800725 if (!net_dev->ieee80211_ptr) {
Dustin Brownaeb55642018-07-30 17:20:32 -0700726 hdd_debug("ieee80211_ptr is null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800727 return NOTIFY_DONE;
728 }
729
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530730 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
731 if (!hdd_ctx) {
732 hdd_err("HDD Context is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800733 return NOTIFY_DONE;
734 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800735
736 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -0700737 hdd_debug("%s: Driver module is closed", __func__);
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800738 return NOTIFY_DONE;
739 }
740
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530741 /* Make sure that this callback corresponds to our device. */
Dustin Brown98f7c822019-03-06 12:25:49 -0800742 adapter = hdd_get_adapter_by_iface_name(hdd_ctx, net_dev->name);
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530743 if (!adapter) {
Dustin Brown98f7c822019-03-06 12:25:49 -0800744 hdd_debug("failed to look up adapter for '%s'", net_dev->name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800745 return NOTIFY_DONE;
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530746 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800747
Dustin Brown98f7c822019-03-06 12:25:49 -0800748 if (adapter != WLAN_HDD_GET_PRIV_PTR(net_dev)) {
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530749 hdd_err("HDD adapter mismatch!");
750 return NOTIFY_DONE;
751 }
752
Dustin Brownaeb55642018-07-30 17:20:32 -0700753 if (cds_is_driver_recovering()) {
754 hdd_debug("Driver is recovering");
755 return NOTIFY_DONE;
756 }
757
758 if (cds_is_driver_in_bad_state()) {
759 hdd_debug("Driver is in failed recovery state");
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530760 return NOTIFY_DONE;
761 }
762
Dustin Brown98f7c822019-03-06 12:25:49 -0800763 hdd_debug("%s New Net Device State = %lu", net_dev->name, state);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800764
765 switch (state) {
766 case NETDEV_REGISTER:
767 break;
768
769 case NETDEV_UNREGISTER:
770 break;
771
772 case NETDEV_UP:
Jeff Johnson16528362018-06-14 12:34:16 -0700773 sme_ch_avoid_update_req(hdd_ctx->mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800774 break;
775
776 case NETDEV_DOWN:
777 break;
778
779 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700780 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800781 complete(&adapter->linkup_event_var);
782 break;
783
784 case NETDEV_GOING_DOWN:
Min Liu8c5d99e2018-09-10 17:18:44 +0800785 vdev = hdd_objmgr_get_vdev(adapter);
786 if (!vdev)
787 break;
788 if (ucfg_scan_get_vdev_status(vdev) !=
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700789 SCAN_NOT_IN_PROGRESS) {
Dustin Brown07901ec2018-09-07 11:02:41 -0700790 wlan_abort_scan(hdd_ctx->pdev, INVAL_PDEV_ID,
Jeff Johnson5a6fc962019-02-04 14:20:25 -0800791 adapter->vdev_id, INVALID_SCAN_ID,
Dustin Brown07901ec2018-09-07 11:02:41 -0700792 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800793 }
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +0530794 hdd_objmgr_put_vdev(vdev);
Min Liu9be5d4a2018-05-17 11:51:53 +0800795 cds_flush_work(&adapter->scan_block_work);
796 /* Need to clean up blocked scan request */
Dustin Brown96b98dd2019-03-06 12:39:37 -0800797 wlan_hdd_cfg80211_scan_block(adapter);
Min Liu9be5d4a2018-05-17 11:51:53 +0800798 hdd_debug("Scan is not Pending from user");
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530799 /*
800 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
801 * of return status of hdd_stop call, kernel resets the IFF_UP
802 * flag after which driver does not send the cfg80211_scan_done.
803 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
804 */
Dustin Brown98f7c822019-03-06 12:25:49 -0800805 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, net_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800806 break;
807
808 default:
809 break;
810 }
811
812 return NOTIFY_DONE;
813}
814
815/**
816 * hdd_netdev_notifier_call() - netdev notifier callback function
817 * @nb: pointer to notifier block
818 * @state: state
Dustin Brown98f7c822019-03-06 12:25:49 -0800819 * @context: notifier callback context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800820 *
821 * Return: 0 on success, error number otherwise.
822 */
823static int hdd_netdev_notifier_call(struct notifier_block *nb,
824 unsigned long state,
Dustin Brown98f7c822019-03-06 12:25:49 -0800825 void *context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800826{
Dustin Brown98f7c822019-03-06 12:25:49 -0800827 struct net_device *net_dev = hdd_net_dev_from_notifier(context);
828 struct osif_vdev_sync *vdev_sync;
829 int errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800830
Dustin Brown98f7c822019-03-06 12:25:49 -0800831 errno = osif_vdev_sync_op_start(net_dev, &vdev_sync);
832 if (errno)
833 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800834
Dustin Brown98f7c822019-03-06 12:25:49 -0800835 errno = __hdd_netdev_notifier_call(net_dev, state);
836
837 osif_vdev_sync_op_stop(vdev_sync);
838
839 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800840}
841
842struct notifier_block hdd_netdev_notifier = {
843 .notifier_call = hdd_netdev_notifier_call,
844};
845
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530846static int system_reboot_notifier_call(struct notifier_block *nb,
847 unsigned long msg_type, void *_unused)
848{
849 switch (msg_type) {
850 case SYS_DOWN:
851 case SYS_HALT:
852 case SYS_POWER_OFF:
853 g_is_system_reboot_triggered = true;
854 hdd_info("reboot, reason: %ld", msg_type);
855 break;
856 default:
857 break;
858 }
859
860 return NOTIFY_OK;
861}
862
863struct notifier_block system_reboot_notifier = {
864 .notifier_call = system_reboot_notifier_call,
865};
866
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800867/* variable to hold the insmod parameters */
868static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800869
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530870static int con_mode_ftm;
Nirav Shah6aeecf92019-02-13 14:05:03 +0530871int con_mode_epping;
Ravi Joshia307f632017-07-17 23:41:41 -0700872int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530873
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800874/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800875static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800876
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530877/**
878 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
879 * @ch_width: NL channel width
880 *
881 * Converts the NL channel width to the driver's internal representation
882 *
883 * Return: Converted channel width. In case of non matching NL channel width,
884 * CH_WIDTH_MAX will be returned.
885 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800886enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530887{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800888 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700889
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800890 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530891 switch (ch_width) {
892 case NL80211_CHAN_WIDTH_20_NOHT:
893 case NL80211_CHAN_WIDTH_20:
894 return CH_WIDTH_20MHZ;
895 case NL80211_CHAN_WIDTH_40:
896 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530897 case NL80211_CHAN_WIDTH_80:
898 return CH_WIDTH_80MHZ;
899 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800900 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
901 return CH_WIDTH_80P80MHZ;
902 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
903 return CH_WIDTH_160MHZ;
904 else
905 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530906 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800907 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
908 return CH_WIDTH_160MHZ;
909 else
910 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530911 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800912 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530913 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800914 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530915 default:
916 hdd_err("Invalid channel width %d, setting to default",
917 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800918 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530919 }
920}
921
Dustin Brown56377e12018-10-10 17:04:04 -0700922QDF_STATUS hdd_nl_to_qdf_iface_type(enum nl80211_iftype nl_type,
923 enum QDF_OPMODE *out_qdf_type)
924{
925 switch (nl_type) {
926 case NL80211_IFTYPE_ADHOC:
927 *out_qdf_type = QDF_IBSS_MODE;
928 break;
929 case NL80211_IFTYPE_AP:
930 *out_qdf_type = QDF_SAP_MODE;
931 break;
932 case NL80211_IFTYPE_MONITOR:
933 *out_qdf_type = QDF_MONITOR_MODE;
934 break;
935 case NL80211_IFTYPE_OCB:
936 *out_qdf_type = QDF_OCB_MODE;
937 break;
938 case NL80211_IFTYPE_P2P_CLIENT:
939 *out_qdf_type = QDF_P2P_CLIENT_MODE;
940 break;
941 case NL80211_IFTYPE_P2P_DEVICE:
942 *out_qdf_type = QDF_P2P_DEVICE_MODE;
943 break;
944 case NL80211_IFTYPE_P2P_GO:
945 *out_qdf_type = QDF_P2P_GO_MODE;
946 break;
947 case NL80211_IFTYPE_STATION:
948 *out_qdf_type = QDF_STA_MODE;
949 break;
950 case NL80211_IFTYPE_WDS:
951 *out_qdf_type = QDF_WDS_MODE;
952 break;
953 default:
954 hdd_err("Invalid nl80211 interface type %d", nl_type);
955 return QDF_STATUS_E_INVAL;
956 }
957
958 return QDF_STATUS_SUCCESS;
959}
960
Jeff Johnson16528362018-06-14 12:34:16 -0700961uint8_t wlan_hdd_find_opclass(mac_handle_t mac_handle, uint8_t channel,
962 uint8_t bw_offset)
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530963{
964 uint8_t opclass = 0;
965
Jeff Johnson16528362018-06-14 12:34:16 -0700966 sme_get_opclass(mac_handle, channel, bw_offset, &opclass);
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530967 return opclass;
968}
969
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800970/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530971 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530972 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800973 * @bitmask: Bitmask of log levels to be enabled
974 *
975 * Called immediately after the cfg.ini is read in order to configure
976 * the desired trace levels.
977 *
978 * Return: None
979 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530980int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800981{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530982 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530983 int qdf_print_idx = -1;
984 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800985 /*
986 * if the bitmask is the default value, then a bitmask was not
987 * specified in cfg.ini, so leave the logging level alone (it
988 * will remain at the "compiled in" default value)
989 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700990 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530991 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800992
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530993 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800994
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530995 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530996 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530997 QDF_TRACE_LEVEL_NONE, 0);
998
999 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301000 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001001 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +05301002 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001003 while (0 != bitmask) {
1004 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05301005 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301006 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +05301007 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301008 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001009 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001010
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001011 level++;
1012 bitmask >>= 1;
1013 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301014 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001015}
1016
Dustin Brownda351e32018-07-23 15:48:22 -07001017int __wlan_hdd_validate_context(struct hdd_context *hdd_ctx, const char *func)
Chris Guo1751acf2017-07-03 14:09:01 +08001018{
Dustin Brownda351e32018-07-23 15:48:22 -07001019 if (!hdd_ctx) {
1020 hdd_err("HDD context is null (via %s)", func);
1021 return -ENODEV;
1022 }
1023
1024 if (!hdd_ctx->config) {
1025 hdd_err("HDD config is null (via %s)", func);
Chris Guo1751acf2017-07-03 14:09:01 +08001026 return -ENODEV;
1027 }
1028
1029 if (cds_is_driver_recovering()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001030 hdd_debug("Recovery in progress (via %s); state:0x%x",
1031 func, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001032 return -EAGAIN;
1033 }
1034
Yue Ma9f275d92017-09-14 16:58:41 -07001035 if (cds_is_load_or_unload_in_progress()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001036 hdd_debug("Load/unload in progress (via %s); state:0x%x",
1037 func, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001038 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -07001039 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05301040
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301041 if (cds_is_driver_in_bad_state()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001042 hdd_debug("Driver in bad state (via %s); state:0x%x",
1043 func, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +05301044 return -EAGAIN;
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301045 }
1046
Arunk Khandavalli2859fa12018-02-14 10:46:26 +05301047 if (cds_is_fw_down()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001048 hdd_debug("FW is down (via %s); state:0x%x",
1049 func, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +05301050 return -EAGAIN;
Arunk Khandavalli2859fa12018-02-14 10:46:26 +05301051 }
1052
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001053 return 0;
1054}
1055
Dustin Browna8700cc2018-08-07 12:04:47 -07001056int __hdd_validate_adapter(struct hdd_adapter *adapter, const char *func)
Dustin Brownf13b8c32017-05-19 17:23:08 -07001057{
1058 if (!adapter) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001059 hdd_err("adapter is null (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001060 return -EINVAL;
1061 }
1062
1063 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001064 hdd_err("bad adapter magic (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001065 return -EINVAL;
1066 }
1067
1068 if (!adapter->dev) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001069 hdd_err("adapter net_device is null (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001070 return -EINVAL;
1071 }
1072
1073 if (!(adapter->dev->flags & IFF_UP)) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001074 hdd_debug_rl("adapter '%s' is not up (via %s)",
1075 adapter->dev->name, func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001076 return -EAGAIN;
1077 }
1078
Jeff Johnson7eb6e842019-02-23 14:33:34 -08001079 return __wlan_hdd_validate_vdev_id(adapter->vdev_id, func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001080}
1081
Jeff Johnson7eb6e842019-02-23 14:33:34 -08001082int __wlan_hdd_validate_vdev_id(uint8_t vdev_id, const char *func)
Dustin Brown63500612018-08-07 11:36:09 -07001083{
Srinivas Girigowdad8697d42019-03-08 15:34:39 -08001084 if (vdev_id == WLAN_UMAC_VDEV_ID_MAX) {
Dustin Brown63500612018-08-07 11:36:09 -07001085 hdd_debug_rl("adapter is not up (via %s)", func);
1086 return -EINVAL;
1087 }
1088
Jeff Johnson7eb6e842019-02-23 14:33:34 -08001089 if (vdev_id >= WLAN_MAX_VDEVS) {
1090 hdd_err("bad vdev Id:%u (via %s)", vdev_id, func);
Dustin Brown63500612018-08-07 11:36:09 -07001091 return -EINVAL;
1092 }
1093
1094 return 0;
1095}
1096
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05301097QDF_STATUS __wlan_hdd_validate_mac_address(struct qdf_mac_addr *mac_addr,
1098 const char *func)
1099{
1100 if (!mac_addr) {
1101 hdd_err("Received NULL mac address (via %s)", func);
1102 return QDF_STATUS_E_INVAL;
1103 }
1104
1105 if (qdf_is_macaddr_zero(mac_addr)) {
1106 hdd_err("MAC is all zero (via %s)", func);
1107 return QDF_STATUS_E_INVAL;
1108 }
1109
1110 if (qdf_is_macaddr_broadcast(mac_addr)) {
1111 hdd_err("MAC is Broadcast (via %s)", func);
1112 return QDF_STATUS_E_INVAL;
1113 }
1114
1115 if (QDF_NET_IS_MAC_MULTICAST(mac_addr->bytes)) {
1116 hdd_err("MAC is Multicast (via %s)", func);
1117 return QDF_STATUS_E_INVAL;
1118 }
1119
1120 return QDF_STATUS_SUCCESS;
1121}
1122
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001123/**
Arun Khandavallica892f62017-05-26 14:25:50 +05301124 * wlan_hdd_validate_modules_state() - Check modules status
1125 * @hdd_ctx: HDD context pointer
1126 *
1127 * Check's the driver module's state and returns true if the
1128 * modules are enabled returns false if modules are closed.
1129 *
1130 * Return: True if modules are enabled or false.
1131 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001132bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +05301133{
Arun Khandavallica892f62017-05-26 14:25:50 +05301134 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
Dustin Brown5e89ef82018-03-14 11:50:23 -07001135 hdd_info("Modules not enabled, Present status: %d",
1136 hdd_ctx->driver_status);
Arun Khandavallica892f62017-05-26 14:25:50 +05301137 return false;
1138 }
Dustin Brownf688ea12019-03-19 17:02:32 -07001139
Arun Khandavallica892f62017-05-26 14:25:50 +05301140 return true;
1141}
1142
1143/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001144 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -07001145 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001146 *
1147 * This function sets the IBSS power save config parameters to WMA
1148 * which will send it to firmware if FW supports IBSS power save
1149 * before vdev start.
1150 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301151 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001152 * on failure.
1153 */
Jeff Johnson9d295242017-08-29 14:39:48 -07001154QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001155{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001156 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001157
Jeff Johnsond36fa332019-03-18 13:42:25 -07001158 if (!hdd_ctx) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001159 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301160 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001161 }
1162
Manikandan Mohan2bd09772018-11-28 18:27:32 -08001163 return ucfg_mlme_ibss_power_save_setup(hdd_ctx->psoc,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08001164 adapter->vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001165}
1166
Yue Macd359b72017-10-03 15:21:00 -07001167#ifdef FEATURE_RUNTIME_PM
1168/**
1169 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
1170 * @hdd_ctx: HDD context
1171 *
1172 * Return: None
1173 */
1174static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
1175{
1176 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1177
Yue Macd359b72017-10-03 15:21:00 -07001178 qdf_runtime_lock_init(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001179 qdf_runtime_lock_init(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001180
Dustin Brown07901ec2018-09-07 11:02:41 -07001181 wlan_scan_runtime_pm_init(hdd_ctx->pdev);
Yue Macd359b72017-10-03 15:21:00 -07001182}
1183
1184/**
1185 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1186 * @hdd_ctx: HDD Context
1187 *
1188 * Return: None
1189 */
1190static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1191{
1192 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1193
Yue Macd359b72017-10-03 15:21:00 -07001194 qdf_runtime_lock_deinit(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001195 qdf_runtime_lock_deinit(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001196
Dustin Brown07901ec2018-09-07 11:02:41 -07001197 wlan_scan_runtime_pm_deinit(hdd_ctx->pdev);
Yue Macd359b72017-10-03 15:21:00 -07001198}
1199
Yue Macd359b72017-10-03 15:21:00 -07001200#else /* FEATURE_RUNTIME_PM */
1201static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1202static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Yue Macd359b72017-10-03 15:21:00 -07001203#endif /* FEATURE_RUNTIME_PM */
1204
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001205#define INTF_MACADDR_MASK 0x7
1206
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301207void hdd_update_macaddr(struct hdd_context *hdd_ctx,
1208 struct qdf_mac_addr hw_macaddr, bool generate_mac_auto)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001209{
1210 int8_t i;
1211 uint8_t macaddr_b3, tmp_br3;
1212
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301213 /*
1214 * If "generate_mac_auto" is true, it indicates that all the
1215 * addresses are derived addresses, else the first addresses
1216 * is not derived address (It is provided by fw).
1217 */
1218 if (!generate_mac_auto) {
1219 qdf_mem_copy(hdd_ctx->provisioned_mac_addr[0].bytes,
1220 hw_macaddr.bytes, QDF_MAC_ADDR_SIZE);
1221 hdd_ctx->num_provisioned_addr++;
1222 hdd_info("hdd_ctx->provisioned_mac_addr[0]: "
1223 MAC_ADDRESS_STR,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07001224 QDF_MAC_ADDR_ARRAY(hdd_ctx->
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301225 provisioned_mac_addr[0].bytes));
1226 } else {
1227 qdf_mem_copy(hdd_ctx->derived_mac_addr[0].bytes,
1228 hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301229 QDF_MAC_ADDR_SIZE);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301230 hdd_ctx->num_derived_addr++;
1231 hdd_info("hdd_ctx->derived_mac_addr[0]: "
1232 MAC_ADDRESS_STR,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07001233 QDF_MAC_ADDR_ARRAY(hdd_ctx->derived_mac_addr[0].bytes));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301234 }
1235 for (i = hdd_ctx->num_derived_addr; i < (QDF_MAX_CONCURRENCY_PERSONA -
1236 hdd_ctx->num_provisioned_addr);
1237 i++) {
1238 qdf_mem_copy(hdd_ctx->derived_mac_addr[i].bytes,
1239 hw_macaddr.bytes,
1240 QDF_MAC_ADDR_SIZE);
1241 macaddr_b3 = hdd_ctx->derived_mac_addr[i].bytes[3];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001242 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1243 INTF_MACADDR_MASK;
1244 macaddr_b3 += tmp_br3;
1245
1246 /* XOR-ing bit-24 of the mac address. This will give enough
1247 * mac address range before collision
1248 */
1249 macaddr_b3 ^= (1 << 7);
1250
1251 /* Set locally administered bit */
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301252 hdd_ctx->derived_mac_addr[i].bytes[0] |= 0x02;
1253 hdd_ctx->derived_mac_addr[i].bytes[3] = macaddr_b3;
1254 hdd_info("hdd_ctx->derived_mac_addr[%d]: "
1255 MAC_ADDRESS_STR, i,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07001256 QDF_MAC_ADDR_ARRAY(hdd_ctx->derived_mac_addr[i].bytes));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301257 hdd_ctx->num_derived_addr++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001258 }
1259}
1260
Jeff Johnson2de58792019-02-08 07:49:17 -08001261#ifdef FEATURE_WLAN_TDLS
Kabilan Kannan44a58372017-12-06 18:16:11 -08001262static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1263{
Dustin Brown1dbefe62018-09-11 16:32:03 -07001264 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001265 struct tdls_start_params tdls_cfg;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001266 QDF_STATUS status;
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301267 struct wlan_mlme_nss_chains vdev_ini_cfg;
1268
1269 /* Populate the nss chain params from ini for this vdev type */
1270 sme_populate_nss_chain_params(hdd_ctx->mac_handle, &vdev_ini_cfg,
1271 QDF_TDLS_MODE,
1272 hdd_ctx->num_rf_chains);
Kabilan Kannan44a58372017-12-06 18:16:11 -08001273
Dustin Brown1dbefe62018-09-11 16:32:03 -07001274 cfg_tdls_set_vdev_nss_2g(hdd_ctx->psoc,
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301275 vdev_ini_cfg.rx_nss[NSS_CHAINS_BAND_2GHZ]);
Dustin Brown1dbefe62018-09-11 16:32:03 -07001276 cfg_tdls_set_vdev_nss_5g(hdd_ctx->psoc,
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301277 vdev_ini_cfg.rx_nss[NSS_CHAINS_BAND_5GHZ]);
jiad7b8a5e02018-11-26 16:37:57 +08001278 hdd_init_tdls_config(&tdls_cfg);
Kabilan Kannan44a58372017-12-06 18:16:11 -08001279 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1280 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1281 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1282 tdls_cfg.tdls_evt_cb_data = psoc;
Jeff Johnson1d40f5b2018-03-02 08:35:53 -08001283 tdls_cfg.tdls_peer_context = hdd_ctx;
1284 tdls_cfg.tdls_reg_peer = hdd_tdls_register_peer;
1285 tdls_cfg.tdls_dereg_peer = hdd_tdls_deregister_peer;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001286 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1287 tdls_cfg.tdls_wmm_cb_data = psoc;
1288 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1289 tdls_cfg.tdls_rx_cb_data = psoc;
1290 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1291
1292 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1293 if (status != QDF_STATUS_SUCCESS) {
1294 hdd_err("failed pmo psoc configuration");
1295 return -EINVAL;
1296 }
1297
1298 hdd_ctx->tdls_umac_comp_active = true;
1299 /* enable napier specific tdls data path */
1300 hdd_ctx->tdls_nap_active = true;
1301
1302 return 0;
1303}
Jeff Johnson74c6bb22019-02-15 10:15:07 -08001304#else
1305static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1306{
1307 return 0;
1308}
1309#endif
Kabilan Kannan44a58372017-12-06 18:16:11 -08001310
Wu Gaoca416ff2018-09-17 11:05:07 +08001311#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1312static void hdd_update_roam_offload(struct hdd_context *hdd_ctx,
1313 struct wma_tgt_services *cfg)
1314{
1315 bool roam_offload_enable;
1316
Dustin Brown1dbefe62018-09-11 16:32:03 -07001317 ucfg_mlme_get_roaming_offload(hdd_ctx->psoc, &roam_offload_enable);
1318 ucfg_mlme_set_roaming_offload(hdd_ctx->psoc,
Wu Gaoca416ff2018-09-17 11:05:07 +08001319 roam_offload_enable &
1320 cfg->en_roam_offload);
1321}
1322#else
1323static inline void hdd_update_roam_offload(struct hdd_context *hdd_ctx,
1324 struct wma_tgt_services *cfg)
1325{
1326}
1327#endif
1328
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001329static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001330 struct wma_tgt_services *cfg)
1331{
1332 struct hdd_config *config = hdd_ctx->config;
Wu Gao66454f12018-09-26 19:55:41 +08001333 bool arp_offload_enable;
Wu Gao1ab05582018-11-08 16:22:49 +08001334 bool mawc_enabled;
Wu Gaobdb7f272018-07-05 19:33:26 +08001335#ifdef FEATURE_WLAN_TDLS
1336 bool tdls_support;
1337 bool tdls_off_channel;
1338 bool tdls_buffer_sta;
1339 uint32_t tdls_uapsd_mask;
1340#endif
jiad7b8a5e02018-11-26 16:37:57 +08001341 bool value;
1342
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001343 /* Set up UAPSD */
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05301344 ucfg_mlme_set_sap_uapsd_flag(hdd_ctx->psoc, cfg->uapsd);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001345
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001346 /* 11AX mode support */
1347 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1348 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1349 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1350
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001351 /* 11AC mode support */
1352 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1353 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1354 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001355
1356 /* ARP offload: override user setting if invalid */
Wu Gao66454f12018-09-26 19:55:41 +08001357 arp_offload_enable =
1358 ucfg_pmo_is_arp_offload_enabled(hdd_ctx->psoc);
1359 ucfg_pmo_set_arp_offload_enabled(hdd_ctx->psoc,
1360 arp_offload_enable & cfg->arp_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001361#ifdef FEATURE_WLAN_SCAN_PNO
1362 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001363 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001364 if (cfg->pno_offload)
Pragaspathi Thilagaraj24789d32018-12-10 22:28:03 +05301365 ucfg_scan_set_pno_offload(hdd_ctx->psoc, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001366#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001367#ifdef FEATURE_WLAN_TDLS
Dustin Brown1dbefe62018-09-11 16:32:03 -07001368 cfg_tdls_get_support_enable(hdd_ctx->psoc, &tdls_support);
1369 cfg_tdls_set_support_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001370 tdls_support & cfg->en_tdls);
1371
Dustin Brown1dbefe62018-09-11 16:32:03 -07001372 cfg_tdls_get_off_channel_enable(hdd_ctx->psoc, &tdls_off_channel);
1373 cfg_tdls_set_off_channel_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001374 tdls_off_channel &&
1375 cfg->en_tdls_offchan);
1376
Dustin Brown1dbefe62018-09-11 16:32:03 -07001377 cfg_tdls_get_buffer_sta_enable(hdd_ctx->psoc, &tdls_buffer_sta);
1378 cfg_tdls_set_buffer_sta_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001379 tdls_buffer_sta &&
1380 cfg->en_tdls_uapsd_buf_sta);
1381
Dustin Brown1dbefe62018-09-11 16:32:03 -07001382 cfg_tdls_get_uapsd_mask(hdd_ctx->psoc, &tdls_uapsd_mask);
Wu Gaobdb7f272018-07-05 19:33:26 +08001383 if (tdls_uapsd_mask && cfg->en_tdls_uapsd_sleep_sta)
Dustin Brown1dbefe62018-09-11 16:32:03 -07001384 cfg_tdls_set_sleep_sta_enable(hdd_ctx->psoc, true);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001385 else
Dustin Brown1dbefe62018-09-11 16:32:03 -07001386 cfg_tdls_set_sleep_sta_enable(hdd_ctx->psoc, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001387#endif
Wu Gaoca416ff2018-09-17 11:05:07 +08001388 hdd_update_roam_offload(hdd_ctx, cfg);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05301389
Dustin Brown05d81302018-09-11 16:49:22 -07001390 if (ucfg_mlme_get_sap_get_peer_info(hdd_ctx->psoc, &value) ==
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05301391 QDF_STATUS_SUCCESS)
1392 value &= cfg->get_peer_info_enabled;
1393
Wu Gao1ab05582018-11-08 16:22:49 +08001394 ucfg_mlme_is_mawc_enabled(hdd_ctx->psoc, &mawc_enabled);
1395 ucfg_mlme_set_mawc_enabled(hdd_ctx->psoc,
1396 mawc_enabled & cfg->is_fw_mawc_capable);
Kabilan Kannan44a58372017-12-06 18:16:11 -08001397 hdd_update_tdls_config(hdd_ctx);
Jeff Johnson16528362018-06-14 12:34:16 -07001398 sme_update_tgt_services(hdd_ctx->mac_handle, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001399}
1400
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001401/**
1402 * hdd_update_vdev_nss() - sets the vdev nss
1403 * @hdd_ctx: HDD context
1404 *
1405 * Sets the Nss per vdev type based on INI
1406 *
1407 * Return: None
1408 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001409static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001410{
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001411 uint8_t max_supp_nss = 1;
Jeff Johnson16528362018-06-14 12:34:16 -07001412 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301413 QDF_STATUS status;
1414 bool bval;
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001415
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301416 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
1417 if (!QDF_IS_STATUS_SUCCESS(status))
1418 hdd_err("unable to get vht_enable2x2");
1419
1420 if (bval && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001421 max_supp_nss = 2;
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301422
1423 hdd_debug("max nss %d", max_supp_nss);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001424
Jeff Johnson16528362018-06-14 12:34:16 -07001425 mac_handle = hdd_ctx->mac_handle;
1426 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301427 NSS_CHAINS_BAND_2GHZ);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001428
Jeff Johnson16528362018-06-14 12:34:16 -07001429 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301430 NSS_CHAINS_BAND_5GHZ);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001431}
1432
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301433/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301434 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1435 * @hdd_ctx: HDD context
1436 *
1437 * Updates wiphy vhtcap fields
1438 *
1439 * Return: None
1440 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001441static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301442{
1443 struct ieee80211_supported_band *band_5g =
1444 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301445 QDF_STATUS status;
1446 uint8_t value = 0, value1 = 0;
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301447
1448 if (!band_5g) {
1449 hdd_debug("5GHz band disabled, skipping capability population");
1450 return;
1451 }
1452
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301453 status = ucfg_mlme_cfg_get_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
1454 &value);
1455 if (!QDF_IS_STATUS_SUCCESS(status))
1456 hdd_err("unable to get tx_bfee_ant_supp");
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301457
Abhinav Kumare057b412018-10-09 17:28:16 +05301458 band_5g->vht_cap.cap |=
1459 (value << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301460
1461 value1 = NUM_OF_SOUNDING_DIMENSIONS;
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301462 band_5g->vht_cap.cap |=
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301463 (value1 << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301464
Dustin Brown7e761c72018-07-31 13:50:17 -07001465 hdd_debug("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301466 band_5g->vht_cap.cap, value, value1);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301467}
1468
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001469static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001470 struct wma_tgt_ht_cap *cfg)
1471{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301472 QDF_STATUS status;
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301473 qdf_size_t value_len;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301474 uint32_t value;
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05301475 uint8_t mpdu_density;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301476 struct mlme_ht_capabilities_info ht_cap_info;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001477 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301478 bool b_enable1x1;
Jeff Johnson16528362018-06-14 12:34:16 -07001479
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001480 /* get the MPDU density */
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05301481 status = ucfg_mlme_get_ht_mpdu_density(hdd_ctx->psoc, &mpdu_density);
1482 if (QDF_IS_STATUS_ERROR(status)) {
1483 hdd_err("could not get HT MPDU Density");
1484 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001485 }
1486
1487 /*
1488 * MPDU density:
1489 * override user's setting if value is larger
1490 * than the one supported by target
1491 */
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05301492 if (mpdu_density > cfg->mpdu_density) {
1493 status = ucfg_mlme_set_ht_mpdu_density(hdd_ctx->psoc,
1494 cfg->mpdu_density);
1495 if (QDF_IS_STATUS_ERROR(status))
1496 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001497 }
1498
1499 /* get the HT capability info */
Dustin Brown1dbefe62018-09-11 16:32:03 -07001500 status = ucfg_mlme_get_ht_cap_info(hdd_ctx->psoc, &ht_cap_info);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301501 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001502 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001503 return;
1504 }
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301505
1506 /* check and update RX STBC */
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301507 if (ht_cap_info.rx_stbc && !cfg->ht_rx_stbc)
1508 ht_cap_info.rx_stbc = cfg->ht_rx_stbc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001509
1510 /* Set the LDPC capability */
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301511 ht_cap_info.adv_coding_cap = cfg->ht_rx_ldpc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001512
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301513 if (ht_cap_info.short_gi_20_mhz && !cfg->ht_sgi_20)
1514 ht_cap_info.short_gi_20_mhz = cfg->ht_sgi_20;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001515
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301516 if (ht_cap_info.short_gi_40_mhz && !cfg->ht_sgi_40)
1517 ht_cap_info.short_gi_40_mhz = cfg->ht_sgi_40;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001518
1519 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1520 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1521
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301522 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &b_enable1x1);
1523 if (!QDF_IS_STATUS_SUCCESS(status))
1524 hdd_err("unable to get vht_enable2x2");
1525
1526 b_enable1x1 = b_enable1x1 && (cfg->num_rf_chains == 2);
1527
1528 status = ucfg_mlme_set_vht_enable2x2(hdd_ctx->psoc, b_enable1x1);
1529 if (!QDF_IS_STATUS_SUCCESS(status))
1530 hdd_err("unable to set vht_enable2x2");
1531
Abhinav Kumare057b412018-10-09 17:28:16 +05301532 if (!b_enable1x1) {
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301533 ht_cap_info.tx_stbc = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001534
1535 /* 1x1 */
1536 /* Update Rx Highest Long GI data Rate */
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301537 status = ucfg_mlme_cfg_set_vht_rx_supp_data_rate(
1538 hdd_ctx->psoc,
1539 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1);
1540 if (!QDF_IS_STATUS_SUCCESS(status))
1541 hdd_err("Failed to set rx_supp_data_rate");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001542 /* Update Tx Highest Long GI data Rate */
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301543 status = ucfg_mlme_cfg_set_vht_tx_supp_data_rate(
1544 hdd_ctx->psoc,
1545 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1);
1546 if (!QDF_IS_STATUS_SUCCESS(status))
1547 hdd_err("Failed to set tx_supp_data_rate");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001548 }
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301549 if (!(cfg->ht_tx_stbc && b_enable1x1))
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301550 ht_cap_info.tx_stbc = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001551
Dustin Brown1dbefe62018-09-11 16:32:03 -07001552 status = ucfg_mlme_set_ht_cap_info(hdd_ctx->psoc, ht_cap_info);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301553 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001554 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001555#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301556 value_len = SIZE_OF_SUPPORTED_MCS_SET;
1557 if (ucfg_mlme_get_supported_mcs_set(
1558 hdd_ctx->psoc, mcs_set,
1559 &value_len) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001560 hdd_debug("Read MCS rate set");
gaurank kathpalia18b49362018-04-15 23:12:03 +05301561 if (cfg->num_rf_chains > SIZE_OF_SUPPORTED_MCS_SET)
1562 cfg->num_rf_chains = SIZE_OF_SUPPORTED_MCS_SET;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301563
1564 if (b_enable1x1) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001565 for (value = 0; value < cfg->num_rf_chains; value++)
1566 mcs_set[value] =
1567 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1568
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301569 status = ucfg_mlme_set_supported_mcs_set(
1570 hdd_ctx->psoc,
1571 mcs_set,
1572 (qdf_size_t)SIZE_OF_SUPPORTED_MCS_SET);
1573 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001574 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001575 }
1576 }
1577#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1578}
1579
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001580static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001581 struct wma_tgt_vht_cap *cfg)
1582{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301583 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001584 struct wiphy *wiphy = hdd_ctx->wiphy;
1585 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001586 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001587 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001588 struct wma_caps_per_phy caps_per_phy;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301589 uint8_t val = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001590
Dustin Brown5e06bd32016-10-04 12:49:10 -07001591 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001592 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001593 return;
1594 }
1595
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301596 status = ucfg_mlme_update_vht_cap(hdd_ctx->psoc, cfg);
1597 if (QDF_IS_STATUS_ERROR(status))
1598 hdd_err("could not update vht capabilities");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001599
1600 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1601 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1602 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1603 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1604 else
1605 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1606
1607
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001608 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
Abhinav Kumare057b412018-10-09 17:28:16 +05301609 status = ucfg_mlme_set_vht_ch_width(hdd_ctx->psoc,
1610 VHT_CAP_160_AND_80P80_SUPP);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301611 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001612 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001613 band_5g->vht_cap.cap |=
1614 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001615 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1616 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
Abhinav Kumare057b412018-10-09 17:28:16 +05301617 status = ucfg_mlme_set_vht_ch_width(hdd_ctx->psoc,
1618 VHT_CAP_160_SUPP);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301619 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001620 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001621 band_5g->vht_cap.cap |=
1622 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001623 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1624 }
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001625
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301626 status =
1627 ucfg_mlme_cfg_get_vht_chan_width(hdd_ctx->psoc, &val);
1628 if (QDF_IS_STATUS_ERROR(status))
1629 hdd_err("could not get channel_width");
1630
1631 val = QDF_MIN(val, ch_width);
Abhinav Kumare057b412018-10-09 17:28:16 +05301632 status = ucfg_mlme_set_vht_ch_width(hdd_ctx->psoc, val);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301633 if (QDF_IS_STATUS_ERROR(status))
1634 hdd_err("could not set the channel width");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001635
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001636 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001637 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001638 hdd_debug("VHT RxLDPC capability is set");
1639 } else {
1640 /*
1641 * Get the RX LDPC capability for the NON DBS
1642 * hardware mode for 5G band
1643 */
1644 status = wma_get_caps_for_phyidx_hwmode(&caps_per_phy,
1645 HW_MODE_DBS_NONE, CDS_BAND_5GHZ);
1646 if ((QDF_IS_STATUS_SUCCESS(status)) &&
1647 (caps_per_phy.vht_5g & WMI_VHT_CAP_RX_LDPC)) {
1648 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1649 hdd_debug("VHT RX LDPC capability is set");
1650 }
1651 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001652
1653 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1654 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1655 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1656 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1657
1658 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1659 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1660
1661 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1662 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1663 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1664 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1665 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1666 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1667
1668 band_5g->vht_cap.cap |=
1669 (cfg->vht_max_ampdu_len_exp <<
1670 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1671
1672 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1673 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1674 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1675 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1676 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1677 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1678 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1679 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1680
1681 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1682 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1683
1684}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001685
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001686/**
1687 * hdd_generate_macaddr_auto() - Auto-generate mac address
1688 * @hdd_ctx: Pointer to the HDD context
1689 *
1690 * Auto-generate mac address using device serial number.
1691 * Keep the first 3 bytes of OUI as before and replace
1692 * the last 3 bytes with the lower 3 bytes of serial number.
1693 *
1694 * Return: 0 for success
1695 * Non zero failure code for errors
1696 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001697static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001698{
1699 unsigned int serialno = 0;
1700 struct qdf_mac_addr mac_addr = {
1701 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1702 };
1703
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001704 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001705 if (serialno == 0)
1706 return -EINVAL;
1707
1708 serialno &= 0x00ffffff;
1709
1710 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1711 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1712 mac_addr.bytes[5] = serialno & 0xff;
1713
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301714 hdd_update_macaddr(hdd_ctx, mac_addr, true);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001715 return 0;
1716}
1717
Jeff Johnsonf9176382018-07-17 19:15:58 -07001718static void hdd_sar_target_config(struct hdd_context *hdd_ctx,
1719 struct wma_tgt_cfg *cfg)
1720{
1721 hdd_ctx->sar_version = cfg->sar_version;
1722}
1723
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001724static void hdd_update_vhtcap_2g(struct hdd_context *hdd_ctx)
1725{
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001726 uint32_t chip_mode = 0;
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001727 QDF_STATUS status;
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001728 bool b2g_vht_cfg = false;
1729 bool b2g_vht_target = false;
1730 struct wma_caps_per_phy caps_per_phy;
1731 struct wmi_unified *wmi_handle;
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001732
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001733 wmi_handle = get_wmi_unified_hdl_from_psoc(hdd_ctx->psoc);
1734 if (!wmi_handle) {
1735 hdd_err("wmi handle is NULL");
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001736 return;
1737 }
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001738
1739 status = ucfg_mlme_get_vht_for_24ghz(hdd_ctx->psoc, &b2g_vht_cfg);
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001740 if (QDF_IS_STATUS_ERROR(status)) {
1741 hdd_err("Failed to get 2g vht mode");
1742 return;
1743 }
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001744 if (wmi_service_enabled(wmi_handle, wmi_service_ext_msg)) {
1745 status = wma_get_caps_for_phyidx_hwmode(&caps_per_phy,
1746 HW_MODE_DBS_NONE,
1747 CDS_BAND_ALL);
1748 if (QDF_IS_STATUS_ERROR(status)) {
1749 hdd_err("Failed to get phy caps");
1750 return;
1751 }
1752 if (caps_per_phy.vht_2g)
1753 b2g_vht_target = true;
1754 } else {
1755 status = wlan_reg_get_chip_mode(hdd_ctx->pdev, &chip_mode);
1756 if (QDF_IS_STATUS_ERROR(status)) {
1757 hdd_err("Failed to get chip mode");
1758 return;
1759 }
1760 b2g_vht_target =
1761 (chip_mode & WMI_HOST_REGDMN_MODE_11AC_VHT20_2G) ?
1762 true : false;
1763 }
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001764
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001765 b2g_vht_cfg = b2g_vht_cfg && b2g_vht_target;
1766 hdd_debug("vht 2g target: %d, cfg: %d", b2g_vht_target, b2g_vht_cfg);
1767 status = ucfg_mlme_set_vht_for_24ghz(hdd_ctx->psoc, b2g_vht_cfg);
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001768 if (QDF_IS_STATUS_ERROR(status)) {
1769 hdd_err("Failed to update 2g vht mode");
1770 return;
1771 }
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001772}
1773
Jeff Johnson8abc5932018-06-02 22:51:37 -07001774void hdd_update_tgt_cfg(hdd_handle_t hdd_handle, struct wma_tgt_cfg *cfg)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001775{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001776 int ret;
Jeff Johnsonea70b942018-07-02 09:42:31 -07001777 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301778 uint8_t temp_band_cap, band_capability;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001779 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301780 uint8_t antenna_mode;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301781 uint8_t sub_20_chan_width;
Arif Hussainee10f902017-12-27 16:30:17 -08001782 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -07001783 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301784 bool bval = false;
1785 uint8_t value = 0;
Arif Hussainbd5194c2018-11-27 19:01:15 -08001786 uint32_t fine_time_meas_cap = 0;
gaurank kathpaliafa7ad0a2019-03-12 19:17:56 +05301787 enum nss_chains_band_info band;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301788
gaurank kathpalia843f7c32018-07-02 18:04:14 +05301789 if (!hdd_ctx) {
1790 hdd_err("HDD context is NULL");
1791 return;
1792 }
Dustin Brownbd68fe12017-11-21 15:28:52 -08001793 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1794 if (ret) {
Dustin Brown64204d22018-08-15 16:35:19 -07001795 QDF_DEBUG_PANIC("Failed to create pdev; errno:%d", ret);
1796 return;
1797 }
1798
1799 hdd_debug("New pdev has been created with pdev_id = %u",
Dustin Brown07901ec2018-09-07 11:02:41 -07001800 hdd_ctx->pdev->pdev_objmgr.wlan_pdev_id);
Dustin Brown64204d22018-08-15 16:35:19 -07001801
Dustin Brown07901ec2018-09-07 11:02:41 -07001802 status = dispatcher_pdev_open(hdd_ctx->pdev);
Dustin Brown64204d22018-08-15 16:35:19 -07001803 if (QDF_IS_STATUS_ERROR(status)) {
1804 QDF_DEBUG_PANIC("dispatcher pdev open failed; status:%d",
1805 status);
1806 return;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301807 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001808
Sandeep Puligillab7beb472018-08-13 22:54:20 -07001809 status = hdd_component_pdev_open(hdd_ctx->pdev);
1810 if (QDF_IS_STATUS_ERROR(status)) {
1811 QDF_DEBUG_PANIC("hdd component pdev open failed; status:%d",
1812 status);
1813 return;
1814 }
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301815 cdp_pdev_set_ctrl_pdev(cds_get_context(QDF_MODULE_ID_SOC),
1816 cds_get_context(QDF_MODULE_ID_TXRX),
Dustin Brown07901ec2018-09-07 11:02:41 -07001817 (struct cdp_ctrl_objmgr_pdev *)hdd_ctx->pdev);
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301818
Dustin Brown07901ec2018-09-07 11:02:41 -07001819 wlan_pdev_set_dp_handle(hdd_ctx->pdev,
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301820 cds_get_context(QDF_MODULE_ID_TXRX));
1821
Will Huang07244172018-05-14 14:23:30 +08001822 hdd_objmgr_update_tgt_max_vdev_psoc(hdd_ctx, cfg->max_intf_count);
1823
Dustin Brown1dbefe62018-09-11 16:32:03 -07001824 ucfg_ipa_set_dp_handle(hdd_ctx->psoc,
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301825 cds_get_context(QDF_MODULE_ID_SOC));
Dustin Brown1dbefe62018-09-11 16:32:03 -07001826 ucfg_ipa_set_txrx_handle(hdd_ctx->psoc,
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301827 cds_get_context(QDF_MODULE_ID_TXRX));
Dustin Brown07901ec2018-09-07 11:02:41 -07001828 ucfg_ipa_reg_sap_xmit_cb(hdd_ctx->pdev,
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301829 hdd_softap_hard_start_xmit);
Dustin Brown07901ec2018-09-07 11:02:41 -07001830 ucfg_ipa_reg_send_to_nw_cb(hdd_ctx->pdev,
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301831 hdd_ipa_send_skb_to_network);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301832
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301833 status = ucfg_mlme_get_sub_20_chan_width(hdd_ctx->psoc,
1834 &sub_20_chan_width);
1835 if (QDF_IS_STATUS_ERROR(status)) {
1836 hdd_err("Failed to get sub_20_chan_width config");
1837 return;
1838 }
1839
Naveen Rawat64e477e2016-05-20 10:34:56 -07001840 if (cds_cfg) {
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301841 if (sub_20_chan_width !=
1842 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
Naveen Rawat64e477e2016-05-20 10:34:56 -07001843 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1844 cds_cfg->sub_20_channel_width =
1845 WLAN_SUB_20_CH_WIDTH_NONE;
1846 } else {
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301847 cds_cfg->sub_20_channel_width = sub_20_chan_width;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001848 }
1849 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001850
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301851 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
1852 if (QDF_IS_STATUS_ERROR(status)) {
1853 hdd_err("Failed to get MLME band capability");
1854 return;
1855 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001856
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301857 /* first store the INI band capability */
1858 temp_band_cap = band_capability;
1859
1860 band_capability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301861 hdd_ctx->is_fils_roaming_supported =
1862 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001863
Vignesh Viswanathan694e28e2018-01-18 20:53:57 +05301864 hdd_ctx->config->is_11k_offload_supported =
1865 cfg->services.is_11k_offload_supported;
1866
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001867 /*
1868 * now overwrite the target band capability with INI
1869 * setting if INI setting is a subset
1870 */
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301871 if ((band_capability == BAND_ALL) &&
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001872 (temp_band_cap != BAND_ALL))
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301873 band_capability = temp_band_cap;
1874 else if ((band_capability != BAND_ALL) &&
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001875 (temp_band_cap != BAND_ALL) &&
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301876 (band_capability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001877 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001878 }
1879
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301880 status = ucfg_mlme_set_band_capability(hdd_ctx->psoc, band_capability);
1881 if (QDF_IS_STATUS_ERROR(status)) {
1882 hdd_err("Failed to set MLME Band Capability");
1883 return;
1884 }
1885
1886 hdd_ctx->curr_band = band_capability;
Amar Singhal58b45ef2017-08-01 13:43:54 -07001887
Qun Zhang043635a2019-02-27 15:19:29 +08001888 status = wlan_hdd_update_wiphy_supported_band(hdd_ctx);
1889 if (QDF_IS_STATUS_ERROR(status)) {
1890 hdd_err("Failed to update wiphy band info");
1891 return;
1892 }
1893
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301894 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001895 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1896 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1897 }
1898
1899 /* This can be extended to other configurations like ht, vht cap... */
1900
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301901 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr))
1902 qdf_mem_copy(&hdd_ctx->hw_macaddr, &cfg->hw_macaddr,
1903 QDF_MAC_ADDR_SIZE);
1904 else
1905 hdd_info("hw_mac is zero");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001906
1907 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001908 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001909
Ryan Hsuc6918552018-05-16 13:29:59 -07001910 hdd_ctx->hw_bd_id = cfg->hw_bd_id;
1911 qdf_mem_copy(&hdd_ctx->hw_bd_info, &cfg->hw_bd_info,
1912 sizeof(cfg->hw_bd_info));
1913
Dustin Brownad06be62019-02-04 14:52:56 -08001914 if (cfg->max_intf_count > WLAN_MAX_VDEVS) {
Dustin Brownbee82832018-07-23 10:10:51 -07001915 hdd_err("fw max vdevs (%u) > host max vdevs (%u); using %u",
Dustin Brownad06be62019-02-04 14:52:56 -08001916 cfg->max_intf_count, WLAN_MAX_VDEVS, WLAN_MAX_VDEVS);
1917 hdd_ctx->max_intf_count = WLAN_MAX_VDEVS;
Dustin Brownbee82832018-07-23 10:10:51 -07001918 } else {
1919 hdd_ctx->max_intf_count = cfg->max_intf_count;
1920 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001921
Jeff Johnsonf9176382018-07-17 19:15:58 -07001922 hdd_sar_target_config(hdd_ctx, cfg);
Jeff Johnsonc875e242016-09-23 18:12:34 -07001923 hdd_lpass_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001924
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001925 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1926 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1927
1928 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1929
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001930 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001931 if (cfg->services.en_11ax) {
1932 hdd_info("11AX: 11ax is enabled - update HDD config");
1933 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1934 }
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -07001935 hdd_update_tgt_twt_cap(hdd_ctx, cfg);
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001936
gaurank kathpaliafa7ad0a2019-03-12 19:17:56 +05301937 for (band = NSS_CHAINS_BAND_2GHZ; band < NSS_CHAINS_BAND_MAX; band++) {
1938 sme_modify_nss_chains_tgt_cfg(hdd_ctx->mac_handle,
1939 QDF_STA_MODE, band);
1940 sme_modify_nss_chains_tgt_cfg(hdd_ctx->mac_handle,
1941 QDF_SAP_MODE, band);
1942 sme_modify_nss_chains_tgt_cfg(hdd_ctx->mac_handle,
1943 QDF_TDLS_MODE, band);
1944 sme_modify_nss_chains_tgt_cfg(hdd_ctx->mac_handle,
1945 QDF_P2P_DEVICE_MODE,
1946 band);
1947 sme_modify_nss_chains_tgt_cfg(hdd_ctx->mac_handle,
1948 QDF_OCB_MODE, band);
1949 sme_modify_nss_chains_tgt_cfg(hdd_ctx->mac_handle,
1950 QDF_TDLS_MODE, band);
1951 }
1952
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001953 hdd_update_vdev_nss(hdd_ctx);
1954
gaurank kathpalia5fcefa92018-10-24 15:03:15 +05301955 hdd_ctx->dynamic_nss_chains_support =
1956 cfg->dynamic_nss_chains_support;
Arif Hussainbd5194c2018-11-27 19:01:15 -08001957 ucfg_mlme_get_fine_time_meas_cap(hdd_ctx->psoc, &fine_time_meas_cap);
1958 fine_time_meas_cap &= cfg->fine_time_measurement_cap;
1959 status = ucfg_mlme_set_fine_time_meas_cap(hdd_ctx->psoc,
1960 fine_time_meas_cap);
1961 if (QDF_IS_STATUS_ERROR(status)) {
1962 hdd_err("failed to set fine_time_meas_cap, 0x%x, ox%x",
1963 fine_time_meas_cap, cfg->fine_time_measurement_cap);
1964 ucfg_mlme_get_fine_time_meas_cap(hdd_ctx->psoc,
1965 &fine_time_meas_cap);
1966 }
1967
Krunal Sonie3531942016-04-12 17:43:53 -07001968 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Arif Hussainbd5194c2018-11-27 19:01:15 -08001969 hdd_debug("fine_time_meas_cap: 0x%x", fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001970
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301971 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
1972 if (!QDF_IS_STATUS_SUCCESS(status))
1973 hdd_err("unable to get vht_enable2x2");
1974
1975 antenna_mode = (bval == 0x01) ?
Nitesh Shahe50711f2017-04-26 16:30:45 +05301976 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1977 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001978 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08001979 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001980
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05301981 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301982
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301983 status = ucfg_mlme_cfg_get_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
Abhinav Kumare057b412018-10-09 17:28:16 +05301984 &value);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301985 if (QDF_IS_STATUS_ERROR(status)) {
1986 status = false;
1987 hdd_err("set tx_bfee_ant_supp failed");
1988 }
1989
1990 if ((value >
Arif Hussainee10f902017-12-27 16:30:17 -08001991 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301992 !cfg->tx_bfee_8ss_enabled) {
1993 status =
1994 ucfg_mlme_cfg_set_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
1995 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF);
1996 if (QDF_IS_STATUS_ERROR(status)) {
1997 status = false;
1998 hdd_err("set tx_bfee_ant_supp failed");
1999 }
2000 }
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302001
Jeff Johnson16528362018-06-14 12:34:16 -07002002 mac_handle = hdd_ctx->mac_handle;
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302003
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05302004 hdd_debug("txBFCsnValue %d", value);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05302005
2006 /*
2007 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
2008 */
2009 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05302010
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08002011 hdd_update_vhtcap_2g(hdd_ctx);
2012
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05302013 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
2014
Ashish Kumar Dhanotiya908925d2019-03-01 17:35:30 +05302015 wlan_config_sched_scan_plans_to_wiphy(hdd_ctx->wiphy, hdd_ctx->psoc);
Yue Macd359b72017-10-03 15:21:00 -07002016 /*
2017 * This needs to be done after HDD pdev is created and stored since
2018 * it will access the HDD pdev object lock.
2019 */
2020 hdd_runtime_suspend_context_init(hdd_ctx);
2021
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07002022 /* Configure NAN datapath features */
2023 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Nachiket Kukade85aa3782018-11-02 20:12:34 +05302024 ucfg_nan_set_tgt_caps(hdd_ctx->psoc, &cfg->nan_caps);
Arif Hussain759a0232017-03-20 13:17:18 -07002025 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08002026 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Liangwei Dong0da14262018-07-03 03:30:23 -04002027 hdd_ctx->obss_scan_offload = cfg->services.obss_scan_offload;
Wu Gao5f764082019-01-04 15:54:38 +08002028 status = ucfg_mlme_set_obss_detection_offload_enabled(
2029 hdd_ctx->psoc, cfg->obss_detection_offloaded);
Arif Hussainee10f902017-12-27 16:30:17 -08002030 if (QDF_IS_STATUS_ERROR(status))
2031 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Arif Hussain05fb4872018-01-03 16:02:55 -08002032
Wu Gao5f764082019-01-04 15:54:38 +08002033 status = ucfg_mlme_set_obss_color_collision_offload_enabled(
2034 hdd_ctx->psoc, cfg->obss_color_collision_offloaded);
Arif Hussain05fb4872018-01-03 16:02:55 -08002035 if (QDF_IS_STATUS_ERROR(status))
2036 hdd_err("Failed to set WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD");
Arif Hussain50689082019-03-26 12:07:58 -07002037
2038 ucfg_mlme_get_bcast_twt(hdd_ctx->psoc, &bval);
2039 if (bval)
2040 ucfg_mlme_set_bcast_twt(hdd_ctx->psoc, cfg->bcast_twt_support);
2041 else
2042 hdd_debug("bcast twt is disable in ini, fw cap %d",
2043 cfg->bcast_twt_support);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002044}
2045
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002046bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002047{
Jeff Johnson9d295242017-08-29 14:39:48 -07002048 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002049 struct hdd_ap_ctx *ap_ctx;
Arif Hussain224d3812018-11-16 17:58:38 -08002050 bool dfs_disable_channel_switch = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002051
Jiachao Wuf610d912018-01-23 17:47:32 +08002052 if (!hdd_ctx) {
2053 hdd_info("Couldn't get hdd_ctx");
2054 return true;
2055 }
2056
Arif Hussain224d3812018-11-16 17:58:38 -08002057 ucfg_mlme_get_dfs_disable_channel_switch(hdd_ctx->psoc,
2058 &dfs_disable_channel_switch);
2059 if (dfs_disable_channel_switch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002060 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussain224d3812018-11-16 17:58:38 -08002061 hdd_ctx, dfs_disable_channel_switch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302062 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002063 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002064
Dustin Brown920397d2017-12-13 16:27:50 -08002065 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002066 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2067
2068 if ((QDF_SAP_MODE == adapter->device_mode ||
2069 QDF_P2P_GO_MODE == adapter->device_mode) &&
Dustin Brown07901ec2018-09-07 11:02:41 -07002070 (wlan_reg_is_passive_or_disable_ch(hdd_ctx->pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002071 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002072 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2073 true;
Jeff Johnson7eb6e842019-02-23 14:33:34 -08002074 hdd_info("tx blocked for vdev: %d",
Jeff Johnson5a6fc962019-02-04 14:20:25 -08002075 adapter->vdev_id);
bings6fb9bf62018-07-05 14:01:53 +08002076 if (adapter->txrx_vdev)
2077 cdp_fc_vdev_flush(
2078 cds_get_context(QDF_MODULE_ID_SOC),
bings0e03a982018-05-09 08:40:59 +08002079 adapter->txrx_vdev);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302080 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002081 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302082
2083 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002084}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002085
Jeff Johnson030cd902018-11-11 10:19:40 -08002086bool hdd_is_valid_mac_address(const uint8_t *mac_addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002087{
2088 int xdigit = 0;
2089 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002090
Jeff Johnson030cd902018-11-11 10:19:40 -08002091 while (*mac_addr) {
2092 if (isxdigit(*mac_addr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002093 xdigit++;
Jeff Johnson030cd902018-11-11 10:19:40 -08002094 } else if (':' == *mac_addr) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002095 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2096 break;
2097
2098 ++separator;
2099 } else {
2100 /* Invalid MAC found */
Jeff Johnson030cd902018-11-11 10:19:40 -08002101 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002102 }
Jeff Johnson030cd902018-11-11 10:19:40 -08002103 ++mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002104 }
2105 return xdigit == 12 && (separator == 5 || separator == 0);
2106}
2107
2108/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302109 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2110 * @dev: Handle to struct net_device to be updated.
2111 *
2112 * Return: None
2113 */
2114static void hdd_mon_mode_ether_setup(struct net_device *dev)
2115{
2116 dev->header_ops = NULL;
2117 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2118 dev->hard_header_len = ETH_HLEN;
2119 dev->mtu = ETH_DATA_LEN;
2120 dev->addr_len = ETH_ALEN;
2121 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2122 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2123 dev->priv_flags |= IFF_TX_SKB_SHARING;
2124
2125 memset(dev->broadcast, 0xFF, ETH_ALEN);
2126}
2127
Nirav Shah73713f72018-05-17 14:50:41 +05302128#ifdef FEATURE_MONITOR_MODE_SUPPORT
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302129/**
chenguo71303962018-10-24 19:44:34 +08002130 * hdd_mon_turn_off_ps_and_wow() - Update monitor mode struct net_device.
2131 * @hdd_ctx: Pointer to HDD context.
2132 *
2133 * Return: None
2134 */
2135static void hdd_mon_turn_off_ps_and_wow(struct hdd_context *hdd_ctx)
2136{
2137 ucfg_pmo_set_power_save_mode(hdd_ctx->psoc, PS_NOT_SUPPORTED);
2138 ucfg_pmo_set_wow_enable(hdd_ctx->psoc, PMO_WOW_DISABLE_BOTH);
2139}
2140
2141/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002142 * __hdd__mon_open() - HDD Open function
2143 * @dev: Pointer to net_device structure
2144 *
2145 * This is called in response to ifconfig up
2146 *
2147 * Return: 0 for success; non-zero for failure
2148 */
2149static int __hdd_mon_open(struct net_device *dev)
2150{
2151 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002152 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2153 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002154
Dustin Brownfdf17c12018-03-14 12:55:34 -07002155 hdd_enter_dev(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002156
2157 ret = wlan_hdd_validate_context(hdd_ctx);
2158 if (ret)
2159 return ret;
2160
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302161 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002162
2163 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Brown3ecc8782018-09-19 16:37:13 -07002164 ret = hdd_psoc_idle_restart(hdd_ctx);
Ravi Joshia307f632017-07-17 23:41:41 -07002165 if (ret) {
2166 hdd_err("Failed to start WLAN modules return");
2167 return ret;
2168 }
2169 hdd_err("hdd_wlan_start_modules() successful !");
2170
2171 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2172 ret = hdd_start_adapter(adapter);
2173 if (ret) {
2174 hdd_err("Failed to start adapter :%d",
2175 adapter->device_mode);
2176 return ret;
2177 }
2178 hdd_err("hdd_start_adapters() successful !");
2179 }
chenguo71303962018-10-24 19:44:34 +08002180 hdd_mon_turn_off_ps_and_wow(hdd_ctx);
Ravi Joshia307f632017-07-17 23:41:41 -07002181 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2182 }
2183
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002184 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002185
2186 if (!ret)
2187 ret = hdd_enable_monitor_mode(dev);
2188
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002189 return ret;
2190}
2191
2192/**
2193 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2194 * @dev: Pointer to net_device structure
2195 *
2196 * This is called in response to ifconfig up
2197 *
2198 * Return: 0 for success; non-zero for failure
2199 */
Dustin Brown0e1e1622019-01-17 11:00:22 -08002200static int hdd_mon_open(struct net_device *net_dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002201{
Dustin Brown0e1e1622019-01-17 11:00:22 -08002202 int errno;
2203 struct osif_vdev_sync *vdev_sync;
2204
2205 errno = osif_vdev_sync_trans_start(net_dev, &vdev_sync);
2206 if (errno)
2207 return errno;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002208
Dustin Brown0e1e1622019-01-17 11:00:22 -08002209 errno = __hdd_mon_open(net_dev);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002210
Dustin Brown0e1e1622019-01-17 11:00:22 -08002211 osif_vdev_sync_trans_stop(vdev_sync);
2212
2213 return errno;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002214}
Nirav Shah73713f72018-05-17 14:50:41 +05302215#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002216
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002217static QDF_STATUS
2218wlan_hdd_update_dbs_scan_and_fw_mode_config(void)
2219{
2220 struct policy_mgr_dual_mac_config cfg = {0};
2221 QDF_STATUS status;
Krunal Sonie64b17e2018-12-13 16:00:02 -08002222 uint32_t chnl_sel_logic_conc = 0;
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002223 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Krunal Sonidf29bc42018-11-15 13:26:29 -08002224 uint8_t dual_mac_feature = DISABLE_DBS_CXN_AND_SCAN;
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002225
2226 if (!hdd_ctx) {
2227 hdd_err("HDD context is NULL");
2228 return QDF_STATUS_E_FAILURE;
2229 }
2230
Krunal Sonie64b17e2018-12-13 16:00:02 -08002231 /*
2232 * ROME platform doesn't support any DBS related commands in FW,
2233 * so if driver sends wmi command with dual_mac_config with all set to
2234 * 0 then FW wouldn't respond back and driver would timeout on waiting
2235 * for response. Check if FW supports DBS to eliminate ROME vs
2236 * NON-ROME platform.
2237 */
2238 if (!policy_mgr_find_if_fw_supports_dbs(hdd_ctx->psoc))
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002239 return QDF_STATUS_SUCCESS;
2240
2241 cfg.scan_config = 0;
2242 cfg.fw_mode_config = 0;
2243 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Krunal Sonie64b17e2018-12-13 16:00:02 -08002244 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->psoc)) {
2245 status =
2246 ucfg_policy_mgr_get_chnl_select_plcy(hdd_ctx->psoc,
2247 &chnl_sel_logic_conc);
2248 if (status != QDF_STATUS_SUCCESS) {
2249 hdd_err("can't get chnl sel policy, use def");
2250 return status;
2251 }
Krunal Sonidf29bc42018-11-15 13:26:29 -08002252 }
2253 status =
2254 ucfg_policy_mgr_get_dual_mac_feature(hdd_ctx->psoc,
2255 &dual_mac_feature);
2256 if (status != QDF_STATUS_SUCCESS) {
2257 hdd_err("ucfg_policy_mgr_get_dual_mac_feature failed, use def");
2258 return status;
2259 }
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002260
Krunal Sonidf29bc42018-11-15 13:26:29 -08002261 if (dual_mac_feature != DISABLE_DBS_CXN_AND_SCAN) {
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002262 status = policy_mgr_get_updated_scan_and_fw_mode_config(
Dustin Brown1dbefe62018-09-11 16:32:03 -07002263 hdd_ctx->psoc, &cfg.scan_config,
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002264 &cfg.fw_mode_config,
Krunal Sonidf29bc42018-11-15 13:26:29 -08002265 dual_mac_feature,
Krunal Sonie64b17e2018-12-13 16:00:02 -08002266 chnl_sel_logic_conc);
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002267
2268 if (status != QDF_STATUS_SUCCESS) {
2269 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
2270 status);
2271 return status;
2272 }
2273 }
2274
2275 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
2276 cfg.scan_config, cfg.fw_mode_config);
2277
2278 status = sme_soc_set_dual_mac_config(cfg);
2279 if (status != QDF_STATUS_SUCCESS) {
2280 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
2281 return status;
2282 }
2283
2284 return QDF_STATUS_SUCCESS;
2285}
2286
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002287/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302288 * hdd_start_adapter() - Wrapper function for device specific adapter
2289 * @adapter: pointer to HDD adapter
2290 *
2291 * This function is called to start the device specific adapter for
2292 * the mode passed in the adapter's device_mode.
2293 *
2294 * Return: 0 for success; non-zero for failure
2295 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002296int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302297{
2298
2299 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002300 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302301
Dustin Brownfdf17c12018-03-14 12:55:34 -07002302 hdd_enter_dev(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002303 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302304
2305 switch (device_mode) {
2306 case QDF_P2P_CLIENT_MODE:
2307 case QDF_P2P_DEVICE_MODE:
2308 case QDF_OCB_MODE:
2309 case QDF_STA_MODE:
2310 case QDF_MONITOR_MODE:
2311 ret = hdd_start_station_adapter(adapter);
2312 if (ret)
2313 goto err_start_adapter;
Alok Kumar81e1d732018-09-04 11:10:36 +05302314
2315 hdd_nud_ignore_tracking(adapter, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05302316 break;
2317 case QDF_P2P_GO_MODE:
2318 case QDF_SAP_MODE:
2319 ret = hdd_start_ap_adapter(adapter);
2320 if (ret)
2321 goto err_start_adapter;
2322 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302323 case QDF_IBSS_MODE:
2324 /*
2325 * For IBSS interface is initialized as part of
2326 * hdd_init_station_mode()
2327 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002328 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302329 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002330 /* vdevs are dynamically managed by firmware in FTM */
2331 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302332 default:
2333 hdd_err("Invalid session type %d", device_mode);
2334 QDF_ASSERT(0);
2335 goto err_start_adapter;
2336 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002337
Arun Khandavallifae92942016-08-01 13:31:08 +05302338 if (hdd_set_fw_params(adapter))
2339 hdd_err("Failed to set the FW params for the adapter!");
2340
Jeff Johnson912b1bb2019-03-06 10:12:36 -08002341 if (adapter->vdev_id != WLAN_UMAC_VDEV_ID_MAX) {
Dustin Browne7e71d32018-05-11 16:00:08 -07002342 ret = wlan_hdd_cfg80211_register_frames(adapter);
2343 if (ret < 0) {
2344 hdd_err("Failed to register frames - ret %d", ret);
2345 goto err_start_adapter;
2346 }
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302347 }
Dustin Browne7e71d32018-05-11 16:00:08 -07002348
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002349 wlan_hdd_update_dbs_scan_and_fw_mode_config();
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302350
Dustin Browndb2a8be2017-12-20 11:49:56 -08002351exit_with_success:
Dustin Browne74003f2018-03-14 12:51:58 -07002352 hdd_exit();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002353
Arun Khandavallifae92942016-08-01 13:31:08 +05302354 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002355
Arun Khandavallifae92942016-08-01 13:31:08 +05302356err_start_adapter:
2357 return -EINVAL;
2358}
2359
2360/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302361 * hdd_enable_power_management() - API to Enable Power Management
2362 *
2363 * API invokes Bus Interface Layer power management functionality
2364 *
2365 * Return: None
2366 */
2367static void hdd_enable_power_management(void)
2368{
2369 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2370
2371 if (!hif_ctx) {
2372 hdd_err("Bus Interface Context is Invalid");
2373 return;
2374 }
2375
2376 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2377}
2378
2379/**
2380 * hdd_disable_power_management() - API to disable Power Management
2381 *
2382 * API disable Bus Interface Layer Power management functionality
2383 *
2384 * Return: None
2385 */
2386static void hdd_disable_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_disable_power_management(hif_ctx);
2396}
2397
Ryan Hsuaadba072018-04-20 13:01:53 -07002398void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302399{
2400 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002401 size_t target_hw_name_len;
2402 const char *target_hw_name;
Ryan Hsuaadba072018-04-20 13:01:53 -07002403 uint8_t *buf;
2404 uint32_t buf_len;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302405
2406 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2407 if (!hif_sc) {
2408 hdd_err("HIF context is NULL");
2409 return;
2410 }
2411
Ryan Hsuaadba072018-04-20 13:01:53 -07002412 hif_get_hw_info(hif_sc, &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302413 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002414 &target_hw_name);
2415
2416 if (hdd_ctx->target_hw_name)
2417 qdf_mem_free(hdd_ctx->target_hw_name);
2418
2419 target_hw_name_len = strlen(target_hw_name) + 1;
2420 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2421 if (hdd_ctx->target_hw_name)
2422 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2423 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302424
Ryan Hsuaadba072018-04-20 13:01:53 -07002425 buf = qdf_mem_malloc(WE_MAX_STR_LEN);
2426 if (buf) {
2427 buf_len = hdd_wlan_get_version(hdd_ctx, WE_MAX_STR_LEN, buf);
2428 hdd_info("%s", buf);
2429 qdf_mem_free(buf);
2430 }
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302431}
2432
2433/**
gbian62edd7e2017-03-07 13:12:13 +08002434 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2435 * @hdd_ctx: Pointer to hdd context
2436 *
2437 * Return: none
2438 */
2439static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002440hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002441{
jitiphil8e15ea62018-11-16 18:05:34 +05302442 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM] = {0};
2443 qdf_size_t out_size = 0;
gbian62edd7e2017-03-07 13:12:13 +08002444 int i;
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002445 struct cds_context *cds_ctx;
gbian62edd7e2017-03-07 13:12:13 +08002446
Jeff Johnsond36fa332019-03-18 13:42:25 -07002447 if (!hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002448 return;
2449
Jeff Johnsond36fa332019-03-18 13:42:25 -07002450 if (!hdd_ctx->config) {
gbian62edd7e2017-03-07 13:12:13 +08002451 /* Do nothing if hdd_ctx is invalid */
2452 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2453 return;
2454 }
2455
2456 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2457
2458 if (!cds_ctx) {
2459 hdd_err("Invalid CDS Context");
2460 return;
2461 }
2462
Srinivas Girigowdad462f3b2019-03-25 14:05:33 -07002463 for (i = 0; i < QCA_WLAN_AC_ALL; i++) {
gbian62edd7e2017-03-07 13:12:13 +08002464 switch (i) {
Srinivas Girigowdad462f3b2019-03-25 14:05:33 -07002465 case QCA_WLAN_AC_BE:
jitiphil8e15ea62018-11-16 18:05:34 +05302466 qdf_uint8_array_parse(
2467 cfg_get(hdd_ctx->psoc,
2468 CFG_DP_ENABLE_TX_SCHED_WRR_BE),
2469 tx_sched_wrr_param,
2470 sizeof(tx_sched_wrr_param),
2471 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002472 break;
Srinivas Girigowdad462f3b2019-03-25 14:05:33 -07002473 case QCA_WLAN_AC_BK:
jitiphil8e15ea62018-11-16 18:05:34 +05302474 qdf_uint8_array_parse(
2475 cfg_get(hdd_ctx->psoc,
2476 CFG_DP_ENABLE_TX_SCHED_WRR_BK),
2477 tx_sched_wrr_param,
2478 sizeof(tx_sched_wrr_param),
2479 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002480 break;
Srinivas Girigowdad462f3b2019-03-25 14:05:33 -07002481 case QCA_WLAN_AC_VI:
jitiphil8e15ea62018-11-16 18:05:34 +05302482 qdf_uint8_array_parse(
2483 cfg_get(hdd_ctx->psoc,
2484 CFG_DP_ENABLE_TX_SCHED_WRR_VI),
2485 tx_sched_wrr_param,
2486 sizeof(tx_sched_wrr_param),
2487 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002488 break;
Srinivas Girigowdad462f3b2019-03-25 14:05:33 -07002489 case QCA_WLAN_AC_VO:
jitiphil8e15ea62018-11-16 18:05:34 +05302490 qdf_uint8_array_parse(
2491 cfg_get(hdd_ctx->psoc,
2492 CFG_DP_ENABLE_TX_SCHED_WRR_VO),
2493 tx_sched_wrr_param,
2494 sizeof(tx_sched_wrr_param),
2495 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002496 break;
2497 default:
gbian62edd7e2017-03-07 13:12:13 +08002498 break;
2499 }
2500
jitiphil8e15ea62018-11-16 18:05:34 +05302501 if (out_size == TX_SCHED_WRR_PARAMS_NUM) {
gbian62edd7e2017-03-07 13:12:13 +08002502 cds_ctx->ac_specs[i].wrr_skip_weight =
2503 tx_sched_wrr_param[0];
2504 cds_ctx->ac_specs[i].credit_threshold =
2505 tx_sched_wrr_param[1];
2506 cds_ctx->ac_specs[i].send_limit =
2507 tx_sched_wrr_param[2];
2508 cds_ctx->ac_specs[i].credit_reserve =
2509 tx_sched_wrr_param[3];
2510 cds_ctx->ac_specs[i].discard_weight =
2511 tx_sched_wrr_param[4];
2512 }
2513
jitiphil8e15ea62018-11-16 18:05:34 +05302514 out_size = 0;
gbian62edd7e2017-03-07 13:12:13 +08002515 }
2516}
2517
Ryan Hsuaadba072018-04-20 13:01:53 -07002518uint32_t hdd_wlan_get_version(struct hdd_context *hdd_ctx,
2519 const size_t version_len, uint8_t *version)
2520{
2521 uint32_t size;
2522 uint32_t msp_id = 0, mspid = 0, siid = 0, crmid = 0, sub_id = 0;
2523
2524 if (!hdd_ctx) {
2525 hdd_err("Invalid context, HDD context is null");
2526 return 0;
2527 }
2528
Ashish Kumar Dhanotiya7353f882018-05-15 12:50:19 +05302529 if (!version || version_len == 0) {
Ryan Hsuaadba072018-04-20 13:01:53 -07002530 hdd_err("Invalid buffer pointr or buffer len\n");
2531 return 0;
2532 }
2533
2534 msp_id = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
2535 mspid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
2536 siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
2537 crmid = hdd_ctx->target_fw_version & 0x7fff;
2538 sub_id = (hdd_ctx->target_fw_vers_ext & 0xf0000000) >> 28;
2539
2540 size = scnprintf(version, version_len,
Ryan Hsuc6918552018-05-16 13:29:59 -07002541 "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 -07002542 QWLAN_VERSIONSTR,
2543 msp_id, mspid, siid, crmid, sub_id,
Ryan Hsuc6918552018-05-16 13:29:59 -07002544 hdd_ctx->target_hw_name,
2545 hdd_ctx->hw_bd_info.bdf_version,
2546 hdd_ctx->hw_bd_info.ref_design_id,
2547 hdd_ctx->hw_bd_info.customer_id,
2548 hdd_ctx->hw_bd_info.project_id,
2549 hdd_ctx->hw_bd_info.board_data_rev);
Ryan Hsuaadba072018-04-20 13:01:53 -07002550
2551 return size;
2552}
2553
Rachit Kankane0dc3e852018-05-07 17:33:42 +05302554int hdd_set_11ax_rate(struct hdd_adapter *adapter, int set_value,
2555 struct sap_config *sap_config)
2556{
2557 uint8_t preamble = 0, nss = 0, rix = 0;
2558 int ret;
2559 mac_handle_t mac_handle = adapter->hdd_ctx->mac_handle;
2560
2561 if (!sap_config) {
2562 if (!sme_is_feature_supported_by_fw(DOT11AX)) {
2563 hdd_err("Target does not support 11ax");
2564 return -EIO;
2565 }
2566 } else if (sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax &&
2567 sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax_ONLY) {
2568 hdd_err("Invalid hw mode, SAP hw_mode= 0x%x, ch = %d",
2569 sap_config->SapHw_mode, sap_config->channel);
2570 return -EIO;
2571 }
2572
2573 if (set_value != 0xff) {
2574 rix = RC_2_RATE_IDX_11AX(set_value);
2575 preamble = WMI_RATE_PREAMBLE_HE;
2576 nss = HT_RC_2_STREAMS_11AX(set_value);
2577
2578 set_value = hdd_assemble_rate_code(preamble, nss, rix);
2579 } else {
Jeff Johnson5a6fc962019-02-04 14:20:25 -08002580 ret = sme_set_auto_rate_he_ltf(mac_handle, adapter->vdev_id,
Rachit Kankane0dc3e852018-05-07 17:33:42 +05302581 QCA_WLAN_HE_LTF_AUTO);
2582 }
2583
2584 hdd_info("SET_11AX_RATE val %d rix %d preamble %x nss %d",
2585 set_value, rix, preamble, nss);
2586
Jeff Johnson5a6fc962019-02-04 14:20:25 -08002587 ret = wma_cli_set_command(adapter->vdev_id,
Rachit Kankane0dc3e852018-05-07 17:33:42 +05302588 WMI_VDEV_PARAM_FIXED_RATE,
2589 set_value, VDEV_CMD);
2590
2591 return ret;
2592}
2593
2594int hdd_assemble_rate_code(uint8_t preamble, uint8_t nss, uint8_t rate)
2595{
2596 int set_value;
2597
2598 if (sme_is_feature_supported_by_fw(DOT11AX))
2599 set_value = WMI_ASSEMBLE_RATECODE_V1(rate, nss, preamble);
2600 else
2601 set_value = (preamble << 6) | (nss << 4) | rate;
2602
2603 return set_value;
2604}
2605
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002606#ifdef FEATURE_WLAN_WAPI
2607/**
2608 * hdd_wapi_security_sta_exist() - return wapi security sta exist or not
2609 *
2610 * This API returns the wapi security station exist or not
2611 *
2612 * Return: true - wapi security station exist
2613 */
2614static bool hdd_wapi_security_sta_exist(void)
2615{
2616 struct hdd_adapter *adapter = NULL;
2617 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2618
2619 hdd_for_each_adapter(hdd_ctx, adapter) {
2620 if ((adapter->device_mode == QDF_STA_MODE) &&
2621 adapter->wapi_info.wapi_mode &&
2622 (adapter->wapi_info.wapi_auth_mode != WAPI_AUTH_MODE_OPEN))
2623 return true;
2624 }
2625 return false;
2626}
2627#else
2628static bool hdd_wapi_security_sta_exist(void)
2629{
2630 return false;
2631}
2632#endif
2633
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002634#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002635static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2636 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2637{
Jeff Johnson9d295242017-08-29 14:39:48 -07002638 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002639 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002640
2641 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2642 if (!adapter) {
2643 hdd_err("Adapter is NULL");
2644 return PM_MAX_NUM_OF_MODE;
2645 }
2646
2647 return policy_mgr_convert_device_mode_to_qdf_type(
2648 adapter->device_mode);
2649}
2650
Abhishek Singh3bbf6cb2019-03-28 14:05:43 +05302651/**
2652 * hdd_is_chan_switch_in_progress() - Check if any adapter has channel switch in
2653 * progress
2654 *
2655 * Return: true, if any adapter has channel switch in
2656 * progress else false
2657 */
2658static bool hdd_is_chan_switch_in_progress(void)
2659{
2660 struct hdd_adapter *adapter = NULL;
2661 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2662
2663 hdd_for_each_adapter(hdd_ctx, adapter) {
2664 if ((adapter->device_mode == QDF_SAP_MODE ||
2665 adapter->device_mode == QDF_P2P_GO_MODE) &&
2666 qdf_atomic_read(&adapter->ch_switch_in_progress)) {
2667 hdd_debug("channel switch progress for vdev_id %d",
2668 adapter->vdev_id);
2669 return true;
2670 }
2671 }
2672
2673 return false;
2674}
2675
2676
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002677static void hdd_register_policy_manager_callback(
2678 struct wlan_objmgr_psoc *psoc)
2679{
2680 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002681
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002682 qdf_mem_zero(&hdd_cbacks, sizeof(hdd_cbacks));
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002683 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002684 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002685 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2686 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002687 hdd_cbacks.get_mode_for_non_connected_vdev =
2688 wlan_hdd_get_mode_for_non_connected_vdev;
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05302689 hdd_cbacks.hdd_get_device_mode = hdd_get_device_mode;
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002690 hdd_cbacks.hdd_wapi_security_sta_exist =
2691 hdd_wapi_security_sta_exist;
Abhishek Singh3bbf6cb2019-03-28 14:05:43 +05302692 hdd_cbacks.hdd_is_chan_switch_in_progress =
2693 hdd_is_chan_switch_in_progress;
2694
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002695 if (QDF_STATUS_SUCCESS !=
2696 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2697 hdd_err("HDD callback registration with policy manager failed");
2698 }
2699}
2700#else
2701static void hdd_register_policy_manager_callback(
2702 struct wlan_objmgr_psoc *psoc)
2703{
2704}
2705#endif
2706
Nachiket Kukade2fb1fdb2019-01-08 15:35:27 +05302707#ifdef WLAN_FEATURE_NAN
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002708static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002709{
2710 struct nan_callbacks cb_obj = {0};
2711
2712 cb_obj.ndi_open = hdd_ndi_open;
2713 cb_obj.ndi_close = hdd_ndi_close;
2714 cb_obj.ndi_start = hdd_ndi_start;
2715 cb_obj.ndi_delete = hdd_ndi_delete;
2716 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2717 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2718
Naveen Rawat37f62c82017-03-26 22:24:43 -07002719 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002720 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002721
Dustin Brown1dbefe62018-09-11 16:32:03 -07002722 os_if_nan_register_hdd_callbacks(hdd_ctx->psoc, &cb_obj);
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002723}
jiadff1ac132018-11-26 16:27:48 +08002724#else
2725static inline void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
2726{
2727}
2728#endif
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002729
Dustin Brown26b3d042017-12-21 11:13:27 -08002730#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002731/**
2732 * hdd_check_for_leaks() - Perform runtime memory leak checks
Dustin Browna6246dd2018-05-24 14:35:58 -07002733 * @hdd_ctx: the global HDD context
Dustin Brown29533f22018-07-24 13:11:56 -07002734 * @is_ssr: true if SSR is in progress
Dustin Brown4c5b9902017-12-19 11:17:19 -08002735 *
2736 * This API triggers runtime memory leak detection. This feature enforces the
2737 * policy that any memory allocated at runtime must also be released at runtime.
2738 *
2739 * Allocating memory at runtime and releasing it at unload is effectively a
2740 * memory leak for configurations which never unload (e.g. LONU, statically
2741 * compiled driver). Such memory leaks are NOT false positives, and must be
2742 * fixed.
2743 *
2744 * Return: None
2745 */
Dustin Brown29533f22018-07-24 13:11:56 -07002746static void hdd_check_for_leaks(struct hdd_context *hdd_ctx, bool is_ssr)
Dustin Brown4bc0a622017-12-06 15:56:50 -08002747{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002748 /* DO NOT REMOVE these checks; for false positives, read above first */
2749
Dustin Brown1dbefe62018-09-11 16:32:03 -07002750 wlan_objmgr_psoc_check_for_peer_leaks(hdd_ctx->psoc);
2751 wlan_objmgr_psoc_check_for_vdev_leaks(hdd_ctx->psoc);
2752 wlan_objmgr_psoc_check_for_pdev_leaks(hdd_ctx->psoc);
Dustin Brown29533f22018-07-24 13:11:56 -07002753
2754 /* many adapter resources are not freed by design during SSR */
2755 if (is_ssr)
2756 return;
2757
Dustin Brownc2796312019-03-13 16:43:36 -07002758 qdf_delayed_work_check_for_leaks();
Dustin Brown677e0862017-10-10 16:30:09 -07002759 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002760 qdf_nbuf_map_check_for_leaks();
Dustin Brown4a93bb52019-03-13 11:46:34 -07002761 qdf_periodic_work_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002762 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002763}
2764
Dustin Brown26b3d042017-12-21 11:13:27 -08002765#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2766#else
Dustin Brown29533f22018-07-24 13:11:56 -07002767static inline void hdd_check_for_leaks(struct hdd_context *hdd_ctx, bool is_ssr)
2768{ }
Dustin Brown26b3d042017-12-21 11:13:27 -08002769
2770#define hdd_debug_domain_set(domain)
2771#endif /* CONFIG_LEAK_DETECTION */
2772
gbian62edd7e2017-03-07 13:12:13 +08002773/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002774 * hdd_update_country_code - Update country code
2775 * @hdd_ctx: HDD context
2776 *
2777 * Update country code based on module parameter country_code
2778 *
2779 * Return: 0 on success and errno on failure
2780 */
2781static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2782{
2783 if (!country_code)
2784 return 0;
2785
2786 return hdd_reg_set_country(hdd_ctx, country_code);
2787}
2788
Dustin Browne7e71d32018-05-11 16:00:08 -07002789int hdd_wlan_start_modules(struct hdd_context *hdd_ctx, bool reinit)
Arun Khandavallifae92942016-08-01 13:31:08 +05302790{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002791 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302792 qdf_device_t qdf_dev;
2793 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302794 bool unint = false;
2795 void *hif_ctx;
Jingxiang Ge95912f82018-04-19 12:01:26 +08002796 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +05302797
Arun Khandavallifae92942016-08-01 13:31:08 +05302798 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2799 if (!qdf_dev) {
2800 hdd_err("QDF Device Context is Invalid return");
2801 return -EINVAL;
2802 }
2803
Dustin Brown4c663222018-10-23 14:19:36 -07002804 hdd_psoc_idle_timer_stop(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302805
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302806 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002807 hdd_debug("Driver modules already Enabled");
Dustin Browne74003f2018-03-14 12:51:58 -07002808 hdd_exit();
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302809 return 0;
2810 }
2811
Arun Khandavallifae92942016-08-01 13:31:08 +05302812 switch (hdd_ctx->driver_status) {
2813 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002814 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302815 unint = true;
2816 /* Fall through dont add break here */
2817 case DRIVER_MODULES_CLOSED:
Dustin Brown1a20b082018-08-03 17:27:15 -07002818 hdd_info("Wlan transitioning (CLOSED -> ENABLED)");
Dustin Brown550f6d22017-12-14 15:44:01 -08002819
Dustin Brown26b3d042017-12-21 11:13:27 -08002820 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002821
Arun Khandavallifae92942016-08-01 13:31:08 +05302822 if (!reinit && !unint) {
2823 ret = pld_power_on(qdf_dev->dev);
2824 if (ret) {
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002825 hdd_err("Failed to power up device; errno:%d",
Dustin Browndca39692017-11-09 15:30:25 -08002826 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302827 goto release_lock;
2828 }
2829 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002830
2831 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2832 hdd_ctx->config->enable_fw_log);
Arun Khandavallifae92942016-08-01 13:31:08 +05302833 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2834 qdf_dev->bus_type,
2835 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2836 HIF_ENABLE_TYPE_PROBE);
2837 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002838 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302839 goto power_down;
2840 }
2841
2842 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302843 if (!hif_ctx) {
2844 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002845 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302846 goto power_down;
2847 }
2848
Arun Khandavallifae92942016-08-01 13:31:08 +05302849 status = ol_cds_init(qdf_dev, hif_ctx);
2850 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002851 hdd_err("No Memory to Create BMI Context; status: %d",
2852 status);
2853 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302854 goto hif_close;
2855 }
2856
Nirav Shah6aeecf92019-02-13 14:05:03 +05302857 if (hdd_get_conparam() == QDF_GLOBAL_EPPING_MODE) {
2858 status = epping_open();
2859 if (status) {
2860 hdd_err("Failed to open in epping mode: %d",
2861 status);
2862 ret = -EINVAL;
2863 goto cds_free;
2864 }
2865
2866 status = epping_enable(qdf_dev->dev, false);
2867 if (status) {
2868 hdd_err("Failed to enable in epping mode : %d",
2869 status);
2870 epping_close();
2871 goto cds_free;
2872 }
2873
2874 hdd_info("epping mode enabled");
2875 break;
2876 }
2877
jitiphil4c256a32018-09-07 08:51:52 +05302878 ucfg_ipa_component_config_update(hdd_ctx->psoc);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302879
gbian62edd7e2017-03-07 13:12:13 +08002880 hdd_update_cds_ac_specs_params(hdd_ctx);
2881
Dustin Brown1dbefe62018-09-11 16:32:03 -07002882 status = hdd_component_psoc_open(hdd_ctx->psoc);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05302883 if (QDF_IS_STATUS_ERROR(status)) {
2884 hdd_err("Failed to Open legacy components; status: %d",
2885 status);
2886 ret = qdf_status_to_os_return(status);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05302887 goto cds_free;
2888 }
2889
2890 ret = hdd_update_config(hdd_ctx);
2891 if (ret) {
2892 hdd_err("Failed to update configuration; errno: %d",
2893 ret);
2894 goto cds_free;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05302895 }
2896
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +05302897 status = wbuff_module_init();
2898 if (QDF_IS_STATUS_ERROR(status))
2899 hdd_err("WBUFF init unsuccessful; status: %d", status);
2900
Dustin Brown1dbefe62018-09-11 16:32:03 -07002901 status = cds_open(hdd_ctx->psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002902 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002903 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002904 ret = qdf_status_to_os_return(status);
Krunal Sonie71838d2018-09-27 10:45:05 -07002905 goto psoc_close;
Arun Khandavallifae92942016-08-01 13:31:08 +05302906 }
2907
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +05302908 hdd_ctx->mac_handle = cds_get_context(QDF_MODULE_ID_SME);
2909
Manjunathappa Prakashb6b4ff12018-06-04 12:32:33 -07002910 if (hdd_ctx->config->rx_thread_affinity_mask)
2911 cds_set_rx_thread_cpu_mask(
2912 hdd_ctx->config->rx_thread_affinity_mask);
2913
2914 /* initialize components configurations after psoc open */
Mukul Sharma9d797a02017-01-05 20:26:03 +05302915 ret = hdd_update_components_config(hdd_ctx);
2916 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002917 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302918 ret);
2919 goto close;
2920 }
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302921
Dustin Brown1dbefe62018-09-11 16:32:03 -07002922 status = cds_dp_open(hdd_ctx->psoc);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002923 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002924 hdd_err("Failed to Open cds post open; status: %d",
2925 status);
2926 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002927 goto close;
2928 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302929
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302930 ret = hdd_register_cb(hdd_ctx);
2931 if (ret) {
2932 hdd_err("Failed to register HDD callbacks!");
2933 goto cds_txrx_free;
2934 }
2935
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002936 /*
2937 * NAN compoenet requires certian operations like, open adapter,
2938 * close adapter, etc. to be initiated by HDD, for those
2939 * register HDD callbacks with UMAC's NAN componenet.
2940 */
2941 hdd_nan_register_callbacks(hdd_ctx);
2942
Jeff Johnson3a280122017-09-13 07:42:00 -07002943 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302944 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002945 hdd_err("Failed to pre-enable CDS; status: %d", status);
2946 ret = qdf_status_to_os_return(status);
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302947 goto deregister_cb;
Arun Khandavallifae92942016-08-01 13:31:08 +05302948 }
2949
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002950 hdd_register_policy_manager_callback(
Dustin Brown1dbefe62018-09-11 16:32:03 -07002951 hdd_ctx->psoc);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002952
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302953 hdd_sysfs_create_driver_root_obj();
Dustin Brown1dbefe62018-09-11 16:32:03 -07002954 hdd_sysfs_create_version_interface(hdd_ctx->psoc);
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302955 hdd_sysfs_create_powerstats_interface();
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302956 hdd_update_hw_sw_info(hdd_ctx);
Dustin Brown550f6d22017-12-14 15:44:01 -08002957
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302958 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2959 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002960 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302961 break;
2962 }
Dustin Browndca39692017-11-09 15:30:25 -08002963
Dustin Browne7e71d32018-05-11 16:00:08 -07002964 ret = hdd_configure_cds(hdd_ctx);
Dustin Browndca39692017-11-09 15:30:25 -08002965 if (ret) {
2966 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302967 goto destroy_driver_sysfs;
Arun Khandavallifae92942016-08-01 13:31:08 +05302968 }
Dustin Browndca39692017-11-09 15:30:25 -08002969
Komal Seelamf2136bb2016-09-28 18:30:44 +05302970 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002971
Arun Khandavallifae92942016-08-01 13:31:08 +05302972 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002973
Arun Khandavallifae92942016-08-01 13:31:08 +05302974 default:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002975 QDF_DEBUG_PANIC("Unknown driver state:%d",
Arun Khandavallifae92942016-08-01 13:31:08 +05302976 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002977 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302978 goto release_lock;
2979 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002980
Dustin Brown1a20b082018-08-03 17:27:15 -07002981 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
2982 hdd_info("Wlan transitioned (now ENABLED)");
2983
Dustin Browne74003f2018-03-14 12:51:58 -07002984 hdd_exit();
Dustin Brown550f6d22017-12-14 15:44:01 -08002985
Arun Khandavallifae92942016-08-01 13:31:08 +05302986 return 0;
2987
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302988destroy_driver_sysfs:
2989 hdd_sysfs_destroy_powerstats_interface();
2990 hdd_sysfs_destroy_version_interface();
2991 hdd_sysfs_destroy_driver_root_obj();
Rajeev Kumarbe021242017-02-16 16:12:23 -08002992 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002993
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302994deregister_cb:
2995 hdd_deregister_cb(hdd_ctx);
2996
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002997cds_txrx_free:
Dustin Brown1dbefe62018-09-11 16:32:03 -07002998 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->psoc);
Jingxiang Ge95912f82018-04-19 12:01:26 +08002999
3000 if (tgt_hdl && target_psoc_get_wmi_ready(tgt_hdl)) {
3001 hdd_runtime_suspend_context_deinit(hdd_ctx);
Dustin Brown07901ec2018-09-07 11:02:41 -07003002 dispatcher_pdev_close(hdd_ctx->pdev);
Jingxiang Ge95912f82018-04-19 12:01:26 +08003003 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
3004 }
3005
Dustin Brown1dbefe62018-09-11 16:32:03 -07003006 cds_dp_close(hdd_ctx->psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08003007
Arun Khandavallifae92942016-08-01 13:31:08 +05303008close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08003009 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08003010 hdd_info("Wlan transition aborted (now CLOSED)");
3011
Dustin Brown1dbefe62018-09-11 16:32:03 -07003012 cds_close(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05303013
Krunal Sonie71838d2018-09-27 10:45:05 -07003014psoc_close:
Dustin Brown1dbefe62018-09-11 16:32:03 -07003015 hdd_component_psoc_close(hdd_ctx->psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07003016 cds_deinit_ini_config();
3017
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07003018cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05303019 ol_cds_free();
3020
3021hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07003022 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
3023 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05303024power_down:
3025 if (!reinit && !unint)
3026 pld_power_off(qdf_dev->dev);
3027release_lock:
Abhinav Kumar7ae9b7b2017-12-19 15:11:54 +05303028 if (hdd_ctx->target_hw_name) {
3029 qdf_mem_free(hdd_ctx->target_hw_name);
3030 hdd_ctx->target_hw_name = NULL;
3031 }
Dustin Brown29533f22018-07-24 13:11:56 -07003032
3033 hdd_check_for_leaks(hdd_ctx, reinit);
Dustin Brown26b3d042017-12-21 11:13:27 -08003034 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08003035
Dustin Browne74003f2018-03-14 12:51:58 -07003036 hdd_exit();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08003037
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07003038 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05303039}
3040
Naveen Rawat910726a2017-03-06 11:42:51 -08003041#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003042static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003043{
3044 int ret = os_if_wifi_pos_register_nl();
3045
3046 if (ret)
3047 hdd_err("os_if_wifi_pos_register_nl failed");
3048
3049 return ret;
3050}
3051
3052static int hdd_deactivate_wifi_pos(void)
3053{
3054 int ret = os_if_wifi_pos_deregister_nl();
3055
3056 if (ret)
3057 hdd_err("os_if_wifi_pos_deregister_nl failed");
3058
3059 return ret;
3060}
3061
3062/**
3063 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
3064 * @hdd_ctx: hdd context
3065 *
3066 * Return: status of operation
3067 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003068static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003069{
Dustin Brown1dbefe62018-09-11 16:32:03 -07003070 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Wu Gao1ab05582018-11-08 16:22:49 +08003071 uint16_t neighbor_scan_max_chan_time;
3072 uint16_t neighbor_scan_min_chan_time;
Naveen Rawat910726a2017-03-06 11:42:51 -08003073
3074 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
3075 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
3076 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
3077 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
3078 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
3079 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
Wu Gao1ab05582018-11-08 16:22:49 +08003080 ucfg_mlme_get_neighbor_scan_max_chan_time(psoc,
3081 &neighbor_scan_max_chan_time);
3082 ucfg_mlme_get_neighbor_scan_min_chan_time(psoc,
3083 &neighbor_scan_min_chan_time);
3084 wifi_pos_set_dwell_time_min(psoc, neighbor_scan_min_chan_time);
3085 wifi_pos_set_dwell_time_max(psoc, neighbor_scan_max_chan_time);
Naveen Rawat910726a2017-03-06 11:42:51 -08003086}
3087#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003088static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003089{
3090 return oem_activate_service(hdd_ctx);
3091}
3092
3093static int hdd_deactivate_wifi_pos(void)
3094{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05303095 return oem_deactivate_service();
Naveen Rawat910726a2017-03-06 11:42:51 -08003096}
3097
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003098static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003099{
3100}
3101#endif
3102
Arun Khandavallifae92942016-08-01 13:31:08 +05303103/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003104 * __hdd_open() - HDD Open function
3105 * @dev: Pointer to net_device structure
3106 *
3107 * This is called in response to ifconfig up
3108 *
3109 * Return: 0 for success; non-zero for failure
3110 */
3111static int __hdd_open(struct net_device *dev)
3112{
Jeff Johnson9d295242017-08-29 14:39:48 -07003113 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003114 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003115 int ret;
3116
Dustin Brownfdf17c12018-03-14 12:55:34 -07003117 hdd_enter_dev(dev);
Ashish Kumar Dhanotiyaf10aa5f2018-12-28 21:29:56 +05303118
3119 qdf_mtrace(QDF_MODULE_ID_HDD, QDF_MODULE_ID_HDD,
3120 TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08003121 adapter->vdev_id, adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003122
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05303123 /* Nothing to be done if device is unloading */
3124 if (cds_is_driver_unloading()) {
3125 hdd_err("Driver is unloading can not open the hdd");
3126 return -EBUSY;
3127 }
3128
Dustin Brown01847752017-10-25 13:56:27 -07003129 if (cds_is_driver_recovering()) {
3130 hdd_err("WLAN is currently recovering; Please try again.");
3131 return -EBUSY;
3132 }
3133
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303134 /*
3135 * This scenario can be hit in cases where in the wlan driver after
3136 * registering the netdevices and there is a failure in driver
3137 * initialization. So return error gracefully because the netdevices
3138 * will be de-registered as part of the load failure.
3139 */
3140
3141 if (!cds_is_driver_loaded()) {
3142 hdd_err("Failed to start the wlan driver!!");
Dustin Brown3da3a832019-03-19 15:51:54 -07003143 return -EIO;
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303144 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303145
Dustin Brown3ecc8782018-09-19 16:37:13 -07003146 ret = hdd_psoc_idle_restart(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05303147 if (ret) {
3148 hdd_err("Failed to start WLAN modules return");
Dustin Brown3da3a832019-03-19 15:51:54 -07003149 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05303150 }
3151
Arun Khandavallifae92942016-08-01 13:31:08 +05303152 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3153 ret = hdd_start_adapter(adapter);
3154 if (ret) {
3155 hdd_err("Failed to start adapter :%d",
3156 adapter->device_mode);
Dustin Brown3da3a832019-03-19 15:51:54 -07003157 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05303158 }
3159 }
3160
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003161 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3162 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003163 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003164 /* Enable TX queues only when we are connected */
3165 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05303166 WLAN_START_ALL_NETIF_QUEUE,
3167 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003168 }
3169
Naveen Rawat286def52016-09-23 15:38:02 -07003170 /* Enable carrier and transmit queues for NDI */
3171 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003172 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07003173 wlan_hdd_netif_queue_control(adapter,
3174 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
3175 WLAN_CONTROL_PATH);
3176 }
3177
Naveen Rawat910726a2017-03-06 11:42:51 -08003178 hdd_populate_wifi_pos_cfg(hdd_ctx);
Arunk Khandavalli40943af2017-05-15 19:25:34 +05303179 hdd_lpass_notify_start(hdd_ctx, adapter);
Naveen Rawat910726a2017-03-06 11:42:51 -08003180
Dustin Brown3da3a832019-03-19 15:51:54 -07003181 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003182}
3183
3184/**
3185 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
Dustin Brown98f7c822019-03-06 12:25:49 -08003186 * @net_dev: Pointer to net_device structure
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003187 *
3188 * This is called in response to ifconfig up
3189 *
3190 * Return: 0 for success; non-zero for failure
3191 */
Dustin Brown0e1e1622019-01-17 11:00:22 -08003192static int hdd_open(struct net_device *net_dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003193{
Dustin Brown0e1e1622019-01-17 11:00:22 -08003194 int errno;
3195 struct osif_vdev_sync *vdev_sync;
3196
3197 errno = osif_vdev_sync_trans_start(net_dev, &vdev_sync);
3198 if (errno)
3199 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003200
Dustin Brown0e1e1622019-01-17 11:00:22 -08003201 errno = __hdd_open(net_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003202
Dustin Brown0e1e1622019-01-17 11:00:22 -08003203 osif_vdev_sync_trans_stop(vdev_sync);
3204
3205 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003206}
3207
3208/**
3209 * __hdd_stop() - HDD stop function
3210 * @dev: Pointer to net_device structure
3211 *
3212 * This is called in response to ifconfig down
3213 *
3214 * Return: 0 for success; non-zero for failure
3215 */
3216static int __hdd_stop(struct net_device *dev)
3217{
Jeff Johnson9d295242017-08-29 14:39:48 -07003218 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003219 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003220 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -07003221 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003222
Dustin Brownfdf17c12018-03-14 12:55:34 -07003223 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003224
Ashish Kumar Dhanotiyaf10aa5f2018-12-28 21:29:56 +05303225 qdf_mtrace(QDF_MODULE_ID_HDD, QDF_MODULE_ID_HDD,
3226 TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08003227 adapter->vdev_id, adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003228
3229 ret = wlan_hdd_validate_context(hdd_ctx);
Arunk Khandavalli987c8d52018-06-21 17:40:31 +05303230 if (ret) {
3231 set_bit(DOWN_DURING_SSR, &adapter->event_flags);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003232 return ret;
Arunk Khandavalli987c8d52018-06-21 17:40:31 +05303233 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003234
3235 /* Nothing to be done if the interface is not opened */
3236 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003237 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003238 return -ENODEV;
3239 }
3240
3241 /* Make sure the interface is marked as closed */
3242 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303243
Jeff Johnson16528362018-06-14 12:34:16 -07003244 mac_handle = hdd_ctx->mac_handle;
3245
Mukul Sharmad16c2022017-07-25 18:56:12 +05303246 hdd_debug("Disabling Auto Power save timer");
3247 sme_ps_disable_auto_ps_timer(
Jeff Johnson16528362018-06-14 12:34:16 -07003248 mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08003249 adapter->vdev_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303250
3251 /*
3252 * Disable TX on the interface, after this hard_start_xmit() will not
3253 * be called on that interface
3254 */
Dustin Browna7bb6ae2018-08-16 16:51:50 -07003255 hdd_debug("Disabling queues, adapter device mode: %s(%d)",
Dustin Brown458027c2018-10-19 12:26:27 -07003256 qdf_opmode_str(adapter->device_mode), adapter->device_mode);
Kabilan Kannan8dac3502017-10-30 12:40:27 -07003257
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303258 wlan_hdd_netif_queue_control(adapter,
3259 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3260 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003261
Arunk Khandavalli40943af2017-05-15 19:25:34 +05303262 if (adapter->device_mode == QDF_STA_MODE)
3263 hdd_lpass_notify_stop(hdd_ctx);
3264
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003265 /*
Naveen Rawat286def52016-09-23 15:38:02 -07003266 * NAN data interface is different in some sense. The traffic on NDI is
3267 * bursty in nature and depends on the need to transfer. The service
3268 * layer may down the interface after the usage and up again when
3269 * required. In some sense, the NDI is expected to be available
3270 * (like SAP) iface until NDI delete request is issued by the service
3271 * layer. Skip BSS termination and adapter deletion for NAN Data
3272 * interface (NDI).
3273 */
3274 if (WLAN_HDD_IS_NDI(adapter))
3275 return 0;
3276
3277 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003278 * The interface is marked as down for outside world (aka kernel)
3279 * But the driver is pretty much alive inside. The driver needs to
3280 * tear down the existing connection on the netdev (session)
3281 * cleanup the data pipes and wait until the control plane is stabilized
3282 * for this interface. The call also needs to wait until the above
3283 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003284 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003285 * That is intentional to be able to scan if it is a STA/P2P interface
3286 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08003287 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003288
3289 /* DeInit the adapter. This ensures datapath cleanup as well */
3290 hdd_deinit_adapter(hdd_ctx, adapter, true);
3291
Dustin Brown4c663222018-10-23 14:19:36 -07003292 if (!hdd_is_any_interface_open(hdd_ctx))
3293 hdd_psoc_idle_timer_start(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05303294
Dustin Browne74003f2018-03-14 12:51:58 -07003295 hdd_exit();
Dustin Brown4c663222018-10-23 14:19:36 -07003296
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003297 return 0;
3298}
3299
3300/**
3301 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3302 * @dev: pointer to net_device structure
3303 *
3304 * This is called in response to ifconfig down
3305 *
3306 * Return: 0 for success and error number for failure
3307 */
Dustin Brown0e1e1622019-01-17 11:00:22 -08003308static int hdd_stop(struct net_device *net_dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003309{
Dustin Brown0e1e1622019-01-17 11:00:22 -08003310 int errno;
3311 struct osif_vdev_sync *vdev_sync;
3312
3313 errno = osif_vdev_sync_trans_start(net_dev, &vdev_sync);
3314 if (errno)
3315 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003316
Dustin Brown0e1e1622019-01-17 11:00:22 -08003317 errno = __hdd_stop(net_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003318
Dustin Brown0e1e1622019-01-17 11:00:22 -08003319 osif_vdev_sync_trans_stop(vdev_sync);
3320
3321 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003322}
3323
3324/**
Dustin Brown96b98dd2019-03-06 12:39:37 -08003325 * hdd_uninit() - HDD uninit function
3326 * @dev: Pointer to net_device structure
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003327 *
3328 * This is called during the netdev unregister to uninitialize all data
3329 * associated with the device
3330 *
Dustin Brown96b98dd2019-03-06 12:39:37 -08003331 * This function must be protected by a transition
3332 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003333 * Return: None
3334 */
Dustin Brown96b98dd2019-03-06 12:39:37 -08003335static void hdd_uninit(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003336{
Jeff Johnson9d295242017-08-29 14:39:48 -07003337 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003338 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003339
Dustin Brownfdf17c12018-03-14 12:55:34 -07003340 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003341
Dustin Brown96b98dd2019-03-06 12:39:37 -08003342 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
3343 hdd_err("Invalid magic");
3344 goto exit;
3345 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003346
Dustin Brown96b98dd2019-03-06 12:39:37 -08003347 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3348 if (!hdd_ctx) {
3349 hdd_err("NULL hdd_ctx");
3350 goto exit;
3351 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003352
Dustin Brown96b98dd2019-03-06 12:39:37 -08003353 if (dev != adapter->dev)
3354 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003355
Dustin Brown96b98dd2019-03-06 12:39:37 -08003356 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003357
Dustin Brown96b98dd2019-03-06 12:39:37 -08003358 /* after uninit our adapter structure will no longer be valid */
3359 adapter->dev = NULL;
3360 adapter->magic = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003361
Dustin Brown96b98dd2019-03-06 12:39:37 -08003362exit:
Dustin Browne74003f2018-03-14 12:51:58 -07003363 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003364}
3365
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003366static int hdd_open_cesium_nl_sock(void)
3367{
3368#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3369 struct netlink_kernel_cfg cfg = {
3370 .groups = WLAN_NLINK_MCAST_GRP_ID,
3371 .input = NULL
3372 };
3373#endif
3374 int ret = 0;
3375
3376#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3377 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3378#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3379 THIS_MODULE,
3380#endif
3381 &cfg);
3382#else
3383 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3384 WLAN_NLINK_MCAST_GRP_ID,
3385 NULL, NULL, THIS_MODULE);
3386#endif
3387
Jeff Johnsond36fa332019-03-18 13:42:25 -07003388 if (!cesium_nl_srv_sock) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003389 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003390 ret = -ECONNREFUSED;
3391 }
3392
3393 return ret;
3394}
3395
3396static void hdd_close_cesium_nl_sock(void)
3397{
Jeff Johnsond36fa332019-03-18 13:42:25 -07003398 if (cesium_nl_srv_sock) {
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003399 netlink_kernel_release(cesium_nl_srv_sock);
3400 cesium_nl_srv_sock = NULL;
3401 }
3402}
3403
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303404void hdd_update_dynamic_mac(struct hdd_context *hdd_ctx,
3405 struct qdf_mac_addr *curr_mac_addr,
3406 struct qdf_mac_addr *new_mac_addr)
3407{
3408 uint8_t i;
3409
3410 hdd_enter();
3411
3412 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303413 if (!qdf_mem_cmp(
3414 curr_mac_addr->bytes,
3415 &hdd_ctx->dynamic_mac_list[i].dynamic_mac.bytes[0],
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303416 sizeof(struct qdf_mac_addr))) {
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303417 qdf_mem_copy(&hdd_ctx->dynamic_mac_list[i].dynamic_mac,
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303418 new_mac_addr->bytes,
3419 sizeof(struct qdf_mac_addr));
3420 break;
3421 }
3422 }
3423
3424 hdd_exit();
3425}
3426
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003427/**
3428 * __hdd_set_mac_address() - set the user specified mac address
3429 * @dev: Pointer to the net device.
3430 * @addr: Pointer to the sockaddr.
3431 *
3432 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003433 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003434 *
3435 * Return: 0 for success, non zero for failure
3436 */
3437static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3438{
Jeff Johnson9d295242017-08-29 14:39:48 -07003439 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303440 struct hdd_adapter *adapter_temp;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003441 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003442 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303443 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003444 int ret;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303445 struct qdf_mac_addr mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003446
Dustin Brownfdf17c12018-03-14 12:55:34 -07003447 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003448
Hanumanth Reddy Pothula5c7a7812018-03-09 12:55:32 +05303449 if (netif_running(dev)) {
3450 hdd_err("On iface up, set mac address change isn't supported");
3451 return -EBUSY;
3452 }
3453
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003454 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3455 ret = wlan_hdd_validate_context(hdd_ctx);
3456 if (0 != ret)
3457 return ret;
3458
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303459 qdf_mem_copy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303460 adapter_temp = hdd_get_adapter_by_macaddr(hdd_ctx, mac_addr.bytes);
3461 if (adapter_temp) {
3462 if (!qdf_str_cmp(adapter_temp->dev->name, dev->name))
3463 return 0;
3464 hdd_err("%s adapter exist with same address " MAC_ADDRESS_STR,
3465 adapter_temp->dev->name,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07003466 QDF_MAC_ADDR_ARRAY(mac_addr.bytes));
Ashish Kumar Dhanotiyaf974f332018-04-19 16:03:15 +05303467 return -EINVAL;
3468 }
3469
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05303470 qdf_ret_status = wlan_hdd_validate_mac_address(&mac_addr);
3471 if (QDF_IS_STATUS_ERROR(qdf_ret_status))
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303472 return -EINVAL;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303473
Ashish Kumar Dhanotiya8bfef122018-04-18 16:48:27 +05303474 hdd_info("Changing MAC to " MAC_ADDRESS_STR " of the interface %s ",
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07003475 QDF_MAC_ADDR_ARRAY(mac_addr.bytes), dev->name);
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303476
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303477 hdd_update_dynamic_mac(hdd_ctx, &adapter->mac_addr, &mac_addr);
Jeff Johnson1e851a12017-10-28 14:36:12 -07003478 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003479 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3480
Dustin Browne74003f2018-03-14 12:51:58 -07003481 hdd_exit();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303482 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003483}
3484
3485/**
3486 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
Dustin Brown98f7c822019-03-06 12:25:49 -08003487 * function from SSR
3488 * @net_dev: pointer to net_device structure
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003489 * @addr: Pointer to the sockaddr
3490 *
3491 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003492 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003493 *
3494 * Return: 0 for success.
3495 */
Dustin Brown98f7c822019-03-06 12:25:49 -08003496static int hdd_set_mac_address(struct net_device *net_dev, void *addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003497{
Dustin Brown98f7c822019-03-06 12:25:49 -08003498 struct osif_vdev_sync *vdev_sync;
3499 int errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003500
Dustin Brown98f7c822019-03-06 12:25:49 -08003501 errno = osif_vdev_sync_op_start(net_dev, &vdev_sync);
3502 if (errno)
3503 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003504
Dustin Brown98f7c822019-03-06 12:25:49 -08003505 errno = __hdd_set_mac_address(net_dev, addr);
3506
3507 osif_vdev_sync_op_stop(vdev_sync);
3508
3509 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003510}
3511
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303512static uint8_t *wlan_hdd_get_derived_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003513{
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303514 int i, j;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003515
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303516 i = qdf_ffz(hdd_ctx->derived_intf_addr_mask);
3517 if (i < 0 || i >= hdd_ctx->num_derived_addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003518 return NULL;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303519 qdf_atomic_set_bit(i, &hdd_ctx->derived_intf_addr_mask);
3520 hdd_info("Assigning MAC from derived list" MAC_ADDRESS_STR,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07003521 QDF_MAC_ADDR_ARRAY(hdd_ctx->derived_mac_addr[i].bytes));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003522
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303523 /* Copy the mac in dynamic mac list at first free position */
3524 for (j = 0; j < QDF_MAX_CONCURRENCY_PERSONA; j++) {
3525 if (qdf_is_macaddr_zero(&hdd_ctx->
3526 dynamic_mac_list[j].dynamic_mac))
3527 break;
3528 }
3529 if (j == QDF_MAX_CONCURRENCY_PERSONA) {
3530 hdd_err("Max interfaces are up");
3531 return NULL;
3532 }
Dustin Brown61cc3932018-10-18 16:12:13 -07003533
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303534 qdf_mem_copy(&hdd_ctx->dynamic_mac_list[j].dynamic_mac.bytes,
3535 &hdd_ctx->derived_mac_addr[i].bytes,
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303536 sizeof(struct qdf_mac_addr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303537 hdd_ctx->dynamic_mac_list[j].is_provisioned_mac = false;
3538 hdd_ctx->dynamic_mac_list[j].bit_position = i;
3539
3540 return hdd_ctx->derived_mac_addr[i].bytes;
3541}
3542
3543static uint8_t *wlan_hdd_get_provisioned_intf_addr(struct hdd_context *hdd_ctx)
3544{
3545 int i, j;
3546
3547 i = qdf_ffz(hdd_ctx->provisioned_intf_addr_mask);
3548 if (i < 0 || i >= hdd_ctx->num_provisioned_addr)
3549 return NULL;
3550 qdf_atomic_set_bit(i, &hdd_ctx->provisioned_intf_addr_mask);
3551 hdd_info("Assigning MAC from provisioned list" MAC_ADDRESS_STR,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07003552 QDF_MAC_ADDR_ARRAY(hdd_ctx->provisioned_mac_addr[i].bytes));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303553
3554 /* Copy the mac in dynamic mac list at first free position */
3555 for (j = 0; j < QDF_MAX_CONCURRENCY_PERSONA; j++) {
3556 if (qdf_is_macaddr_zero(&hdd_ctx->
3557 dynamic_mac_list[j].dynamic_mac))
3558 break;
3559 }
3560 if (j == QDF_MAX_CONCURRENCY_PERSONA) {
3561 hdd_err("Max interfaces are up");
3562 return NULL;
3563 }
3564
3565 qdf_mem_copy(&hdd_ctx->dynamic_mac_list[j].dynamic_mac.bytes,
3566 &hdd_ctx->provisioned_mac_addr[i].bytes,
3567 sizeof(struct qdf_mac_addr));
3568 hdd_ctx->dynamic_mac_list[j].is_provisioned_mac = true;
3569 hdd_ctx->dynamic_mac_list[j].bit_position = i;
3570 return hdd_ctx->provisioned_mac_addr[i].bytes;
3571}
3572
3573uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx,
3574 enum QDF_OPMODE interface_type)
3575{
3576 uint8_t *mac_addr = NULL;
3577
3578 if (qdf_atomic_test_bit(interface_type,
3579 (unsigned long *)
3580 (&hdd_ctx->config->provisioned_intf_pool)))
3581 mac_addr = wlan_hdd_get_provisioned_intf_addr(hdd_ctx);
3582
3583 if ((!mac_addr) &&
3584 (qdf_atomic_test_bit(interface_type,
3585 (unsigned long *)
3586 (&hdd_ctx->config->derived_intf_pool))))
3587 mac_addr = wlan_hdd_get_derived_intf_addr(hdd_ctx);
3588
3589 if (!mac_addr)
3590 hdd_err("MAC is not available in both the lists");
3591 return mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003592}
3593
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003594void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3595 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003596{
3597 int i;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303598 int mac_pos_in_mask;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003599
Anurag Chouhan6d760662016-02-20 16:05:43 +05303600 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003601 if (!memcmp(releaseAddr,
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303602 hdd_ctx->dynamic_mac_list[i].dynamic_mac.bytes,
3603 QDF_MAC_ADDR_SIZE)) {
3604 mac_pos_in_mask =
3605 hdd_ctx->dynamic_mac_list[i].bit_position;
3606 if (hdd_ctx->dynamic_mac_list[i].is_provisioned_mac) {
3607 qdf_atomic_clear_bit(
3608 mac_pos_in_mask,
3609 &hdd_ctx->
3610 provisioned_intf_addr_mask);
3611 hdd_info("Releasing MAC from provisioned list");
3612 hdd_info(
3613 MAC_ADDRESS_STR,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07003614 QDF_MAC_ADDR_ARRAY(releaseAddr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303615 } else {
3616 qdf_atomic_clear_bit(
3617 mac_pos_in_mask, &hdd_ctx->
3618 derived_intf_addr_mask);
3619 hdd_info("Releasing MAC from derived list");
3620 hdd_info(MAC_ADDRESS_STR,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07003621 QDF_MAC_ADDR_ARRAY(releaseAddr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303622 }
3623 qdf_zero_macaddr(&hdd_ctx->
3624 dynamic_mac_list[i].dynamic_mac);
3625 hdd_ctx->dynamic_mac_list[i].is_provisioned_mac =
3626 false;
3627 hdd_ctx->dynamic_mac_list[i].bit_position = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003628 break;
3629 }
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303630
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003631 }
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303632 if (i == QDF_MAX_CONCURRENCY_PERSONA)
3633 hdd_err("Releasing non existing MAC" MAC_ADDRESS_STR,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07003634 QDF_MAC_ADDR_ARRAY(releaseAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003635}
3636
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003637/**
3638 * __hdd_set_multicast_list() - set the multicast address list
3639 * @dev: Pointer to the WLAN device.
3640 * @skb: Pointer to OS packet (sk_buff).
3641 *
3642 * This funciton sets the multicast address list.
3643 *
3644 * Return: None
3645 */
3646static void __hdd_set_multicast_list(struct net_device *dev)
3647{
Jeff Johnson9d295242017-08-29 14:39:48 -07003648 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Dustin Brown0f874482018-06-13 14:39:22 -07003649 int i = 0, errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003650 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003651 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303652 struct pmo_mc_addr_list_params *mc_list_request = NULL;
Dustin Brown1dbefe62018-09-11 16:32:03 -07003653 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303654 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003655
Dustin Brownfdf17c12018-03-14 12:55:34 -07003656 hdd_enter_dev(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303657 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303658 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303659
Dustin Brown0f874482018-06-13 14:39:22 -07003660 errno = wlan_hdd_validate_context(hdd_ctx);
3661 if (errno)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303662 goto out;
3663
Dustin Brown0f874482018-06-13 14:39:22 -07003664 errno = hdd_validate_adapter(adapter);
3665 if (errno)
Dustin Brownc788acb2017-08-01 17:43:51 -07003666 goto out;
3667
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303668 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3669 hdd_err("%s: Driver module is closed", __func__);
Dustin Brown0f874482018-06-13 14:39:22 -07003670 goto out;
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303671 }
3672
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303673 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
Min Liu74a1a502018-10-10 19:59:07 +08003674 if (!mc_list_request)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303675 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003676
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303677 /* Delete already configured multicast address list */
3678 if (adapter->mc_addr_list.mc_cnt > 0) {
Dustin Brown0f874482018-06-13 14:39:22 -07003679 hdd_debug("clear previously configured MC address list");
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303680 hdd_disable_and_flush_mc_addr_list(adapter,
3681 pmo_mc_list_change_notify);
3682 }
3683
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003684 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003685 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303686 hdd_disable_and_flush_mc_addr_list(adapter,
3687 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003688 } else {
3689 mc_count = netdev_mc_count(dev);
Wu Gaod7dd6e42018-10-16 17:22:56 +08003690 if (mc_count > ucfg_pmo_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003691 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Wu Gaod7dd6e42018-10-16 17:22:56 +08003692 ucfg_pmo_max_mc_addr_supported(psoc));
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303693 hdd_disable_and_flush_mc_addr_list(adapter,
3694 pmo_mc_list_change_notify);
stonezdf2bdfd2018-11-20 14:45:06 +08003695 adapter->mc_addr_list.mc_cnt = 0;
Dustin Brown0f874482018-06-13 14:39:22 -07003696 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003697 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003698 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003699 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07003700 i, QDF_MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003701 if (i == mc_count)
3702 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303703 memset(&(mc_list_request->mc_addr[i].bytes),
3704 0, ETH_ALEN);
3705 memcpy(&(mc_list_request->mc_addr[i].bytes),
3706 ha->addr, ETH_ALEN);
Dustin Brown0f874482018-06-13 14:39:22 -07003707 hdd_debug("mlist[%d] = %pM", i,
3708 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003709 i++;
3710 }
3711 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303712
stonezdf2bdfd2018-11-20 14:45:06 +08003713 adapter->mc_addr_list.mc_cnt = mc_count;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303714 mc_list_request->psoc = psoc;
Jeff Johnson5a6fc962019-02-04 14:20:25 -08003715 mc_list_request->vdev_id = adapter->vdev_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303716 mc_list_request->count = mc_count;
Dustin Brown0f874482018-06-13 14:39:22 -07003717
3718 errno = hdd_cache_mc_addr_list(mc_list_request);
3719 if (errno) {
3720 hdd_err("Failed to cache MC address list for vdev %u; errno:%d",
Jeff Johnson5a6fc962019-02-04 14:20:25 -08003721 adapter->vdev_id, errno);
Dustin Brown0f874482018-06-13 14:39:22 -07003722 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003723 }
Dustin Brown0f874482018-06-13 14:39:22 -07003724
3725 hdd_enable_mc_addr_filtering(adapter, pmo_mc_list_change_notify);
3726
3727free_req:
3728 qdf_mem_free(mc_list_request);
3729
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303730out:
Dustin Browne74003f2018-03-14 12:51:58 -07003731 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003732}
3733
3734/**
3735 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
Dustin Brown98f7c822019-03-06 12:25:49 -08003736 * @net_dev: pointer to net_device
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003737 *
3738 * Return: none
3739 */
Dustin Brown98f7c822019-03-06 12:25:49 -08003740static void hdd_set_multicast_list(struct net_device *net_dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003741{
Dustin Brown98f7c822019-03-06 12:25:49 -08003742 struct osif_vdev_sync *vdev_sync;
3743
3744 if (osif_vdev_sync_op_start(net_dev, &vdev_sync))
3745 return;
3746
3747 __hdd_set_multicast_list(net_dev);
3748
3749 osif_vdev_sync_op_stop(vdev_sync);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003750}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003751
Subrat Dash5f36fbe2019-02-12 16:28:14 +05303752#ifdef WLAN_FEATURE_TSF_PTP
3753static const struct ethtool_ops wlan_ethtool_ops = {
3754 .get_ts_info = wlan_get_ts_info,
3755};
3756#endif
3757
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003758static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003759 .ndo_open = hdd_open,
3760 .ndo_stop = hdd_stop,
3761 .ndo_uninit = hdd_uninit,
3762 .ndo_start_xmit = hdd_hard_start_xmit,
3763 .ndo_tx_timeout = hdd_tx_timeout,
3764 .ndo_get_stats = hdd_get_stats,
3765 .ndo_do_ioctl = hdd_ioctl,
3766 .ndo_set_mac_address = hdd_set_mac_address,
3767 .ndo_select_queue = hdd_select_queue,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003768 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003769};
3770
Nirav Shah73713f72018-05-17 14:50:41 +05303771#ifdef FEATURE_MONITOR_MODE_SUPPORT
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003772/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003773static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003774 .ndo_open = hdd_mon_open,
3775 .ndo_stop = hdd_stop,
3776 .ndo_get_stats = hdd_get_stats,
3777};
3778
Subrat Dash5f36fbe2019-02-12 16:28:14 +05303779#ifdef WLAN_FEATURE_TSF_PTP
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003780/**
3781 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003782 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003783 * Return: None
3784 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003785void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003786{
Subrat Dash5f36fbe2019-02-12 16:28:14 +05303787 if (cds_get_conparam() == QDF_GLOBAL_MONITOR_MODE) {
3788 dev->netdev_ops = &wlan_mon_drv_ops;
3789 } else {
3790 dev->netdev_ops = &wlan_drv_ops;
3791 dev->ethtool_ops = &wlan_ethtool_ops;
3792 }
3793}
3794#else
3795void hdd_set_station_ops(struct net_device *dev)
3796{
3797 if (cds_get_conparam() == QDF_GLOBAL_MONITOR_MODE)
Jeff Johnson5505db82017-11-02 21:19:23 -07003798 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003799 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003800 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003801}
Subrat Dash5f36fbe2019-02-12 16:28:14 +05303802
3803#endif
3804#else
3805#ifdef WLAN_FEATURE_TSF_PTP
3806void hdd_set_station_ops(struct net_device *dev)
3807{
3808 dev->netdev_ops = &wlan_drv_ops;
3809 dev->ethtool_ops = &wlan_ethtool_ops;
3810}
Nirav Shah73713f72018-05-17 14:50:41 +05303811#else
3812void hdd_set_station_ops(struct net_device *dev)
3813{
3814 dev->netdev_ops = &wlan_drv_ops;
3815}
3816#endif
Subrat Dash5f36fbe2019-02-12 16:28:14 +05303817#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003818
3819/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003820 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3821 * @hdd_ctx: global hdd context
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003822 * @mac_addr: mac address to assign to the interface
Ryan Hsu07495ea2016-01-21 15:25:39 -08003823 * @name: User-visible name of the interface
3824 *
3825 * hdd adapter pointer would point to the netdev->priv space, this function
Jeff Johnson62018292018-05-06 16:18:35 -07003826 * would retrieve the pointer, and setup the hdd adapter configuration.
Ryan Hsu07495ea2016-01-21 15:25:39 -08003827 *
3828 * Return: the pointer to hdd adapter, otherwise NULL
3829 */
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003830static struct hdd_adapter *
3831hdd_alloc_station_adapter(struct hdd_context *hdd_ctx, tSirMacAddr mac_addr,
3832 unsigned char name_assign_type, const char *name)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003833{
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003834 struct net_device *dev;
3835 struct hdd_adapter *adapter;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003836 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303837 QDF_STATUS qdf_status;
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003838
3839 /* cfg80211 initialization and registration */
3840 dev = alloc_netdev_mq(sizeof(*adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003841#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003842 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003843#endif
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003844 (cds_get_conparam() == QDF_GLOBAL_MONITOR_MODE ?
3845 hdd_mon_mode_ether_setup : ether_setup),
3846 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003847
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003848 if (!dev) {
3849 hdd_err("Failed to allocate new net_device '%s'", name);
3850 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003851 }
3852
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003853 adapter = netdev_priv(dev);
3854
3855 qdf_mem_zero(adapter, sizeof(*adapter));
3856 sta_ctx = &adapter->session.station;
Jeff Johnson0a082d92019-03-04 12:25:49 -08003857 qdf_mem_set(sta_ctx->conn_info.sta_id,
3858 sizeof(sta_ctx->conn_info.sta_id),
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003859 HDD_WLAN_INVALID_STA_ID);
3860 adapter->dev = dev;
3861 adapter->hdd_ctx = hdd_ctx;
3862 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson912b1bb2019-03-06 10:12:36 -08003863 adapter->vdev_id = WLAN_UMAC_VDEV_ID_MAX;
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003864
3865 qdf_status = qdf_event_create(&adapter->qdf_session_open_event);
3866 if (QDF_IS_STATUS_ERROR(qdf_status))
3867 goto free_net_dev;
3868
3869 qdf_status = qdf_event_create(&adapter->qdf_session_close_event);
3870 if (QDF_IS_STATUS_ERROR(qdf_status))
3871 goto free_net_dev;
3872
3873 adapter->offloads_configured = false;
3874 adapter->is_link_up_service_needed = false;
3875 adapter->disconnection_in_progress = false;
3876 adapter->send_mode_change = true;
3877
3878 /* Init the net_device structure */
3879 strlcpy(dev->name, name, IFNAMSIZ);
3880
3881 qdf_mem_copy(dev->dev_addr, mac_addr, sizeof(tSirMacAddr));
3882 qdf_mem_copy(adapter->mac_addr.bytes, mac_addr, sizeof(tSirMacAddr));
3883 dev->watchdog_timeo = HDD_TX_TIMEOUT;
3884
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003885 hdd_set_station_ops(adapter->dev);
3886
3887 hdd_dev_setup_destructor(dev);
3888 dev->ieee80211_ptr = &adapter->wdev;
3889 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
3890 adapter->wdev.wiphy = hdd_ctx->wiphy;
3891 adapter->wdev.netdev = dev;
3892
3893 /* set dev's parent to underlying device */
3894 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
3895 hdd_wmm_init(adapter);
3896 spin_lock_init(&adapter->pause_map_lock);
3897 adapter->start_time = qdf_system_ticks();
3898 adapter->last_time = adapter->start_time;
3899
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003900 return adapter;
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003901
3902free_net_dev:
3903 free_netdev(adapter->dev);
3904
3905 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003906}
3907
Jeff Johnson9d295242017-08-29 14:39:48 -07003908static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003909{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003910 struct net_device *dev = adapter->dev;
3911 int ret;
3912
Dustin Brown491d54b2018-03-14 12:39:11 -07003913 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003914
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003915 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003916 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3917
3918 ret = dev_alloc_name(dev, dev->name);
3919 if (ret < 0) {
3920 hdd_err(
3921 "unable to get dev name: %s, err = 0x%x",
3922 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303923 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003924 }
3925 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003926
3927 ret = register_netdevice(dev);
3928 if (ret) {
3929 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3930 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303931 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003932 }
3933 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003934 ret = register_netdev(dev);
3935 if (ret) {
3936 hdd_err("register_netdev(%s) failed, err = 0x%x",
3937 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303938 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003939 }
3940 }
3941 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3942
Dustin Browne74003f2018-03-14 12:51:58 -07003943 hdd_exit();
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003944
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303945 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003946}
3947
Jeff Johnson55d2ab42019-03-06 11:43:49 -08003948QDF_STATUS hdd_sme_open_session_callback(uint8_t vdev_id,
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05303949 QDF_STATUS qdf_status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003950{
Krunal Sonib51eec72017-11-20 21:53:01 -08003951 struct hdd_adapter *adapter;
3952 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003953
Krunal Sonib51eec72017-11-20 21:53:01 -08003954 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3955 if (!hdd_ctx) {
3956 hdd_err("Invalid HDD_CTX");
3957 return QDF_STATUS_E_FAILURE;
3958 }
3959
Jeff Johnson55d2ab42019-03-06 11:43:49 -08003960 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Jeff Johnsond36fa332019-03-18 13:42:25 -07003961 if (!adapter) {
Jeff Johnson55d2ab42019-03-06 11:43:49 -08003962 hdd_err("NULL adapter for %d", vdev_id);
Krunal Sonib51eec72017-11-20 21:53:01 -08003963 return QDF_STATUS_E_INVAL;
3964 }
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05303965
3966 if (qdf_status == QDF_STATUS_SUCCESS)
3967 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3968
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303969 qdf_event_set(&adapter->qdf_session_open_event);
Jeff Johnson5a6fc962019-02-04 14:20:25 -08003970 hdd_debug("session %d opened", adapter->vdev_id);
Krunal Sonib51eec72017-11-20 21:53:01 -08003971
3972 return QDF_STATUS_SUCCESS;
3973}
3974
Jeff Johnson55d2ab42019-03-06 11:43:49 -08003975QDF_STATUS hdd_sme_close_session_callback(uint8_t vdev_id)
Krunal Sonib51eec72017-11-20 21:53:01 -08003976{
3977 struct hdd_adapter *adapter;
3978 struct hdd_context *hdd_ctx;
3979
3980 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3981 if (!hdd_ctx) {
3982 hdd_err("Invalid HDD_CTX");
3983 return QDF_STATUS_E_FAILURE;
3984 }
3985
Jeff Johnson55d2ab42019-03-06 11:43:49 -08003986 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Jeff Johnsond36fa332019-03-18 13:42:25 -07003987 if (!adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003988 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303989 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003990 }
3991
3992 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003993 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303994 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003995 }
3996
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003997 /*
3998 * For NAN Data interface, the close session results in the final
3999 * indication to the userspace
4000 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07004001 if (adapter->device_mode == QDF_NDI_MODE)
4002 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004003
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004004 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
4005
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004006 /*
4007 * We can be blocked while waiting for scheduled work to be
4008 * flushed, and the adapter structure can potentially be freed, in
4009 * which case the magic will have been reset. So make sure the
4010 * magic is still good, and hence the adapter structure is still
4011 * valid, before signaling completion
4012 */
4013 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304014 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004015
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304016 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004017}
4018
Jeff Johnson9d295242017-08-29 14:39:48 -07004019int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004020{
Min Liu8c5d99e2018-09-10 17:18:44 +08004021 struct wlan_objmgr_vdev *vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07004022 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004023
Min Liu8c5d99e2018-09-10 17:18:44 +08004024 vdev = hdd_objmgr_get_vdev(adapter);
4025 if (!vdev)
4026 return -EINVAL;
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07004027
Min Liu8c5d99e2018-09-10 17:18:44 +08004028 status = pmo_vdev_ready(vdev);
4029 if (QDF_IS_STATUS_ERROR(status)) {
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05304030 hdd_objmgr_put_vdev(vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07004031 return qdf_status_to_os_return(status);
Min Liu8c5d99e2018-09-10 17:18:44 +08004032 }
4033
4034 status = ucfg_reg_11d_vdev_created_update(vdev);
4035 if (QDF_IS_STATUS_ERROR(status)) {
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05304036 hdd_objmgr_put_vdev(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08004037 return qdf_status_to_os_return(status);
4038 }
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07004039
4040 if (wma_capability_enhanced_mcast_filter())
Min Liu8c5d99e2018-09-10 17:18:44 +08004041 status = ucfg_pmo_enhanced_mc_filter_enable(vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07004042 else
Min Liu8c5d99e2018-09-10 17:18:44 +08004043 status = ucfg_pmo_enhanced_mc_filter_disable(vdev);
4044
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05304045 hdd_objmgr_put_vdev(vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07004046
4047 return qdf_status_to_os_return(status);
4048}
4049
Jeff Johnson9d295242017-08-29 14:39:48 -07004050int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07004051{
4052 QDF_STATUS status;
Dustin Brown2da29eb2018-07-13 14:23:12 -07004053 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004054 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004055 uint8_t vdev_id;
Min Liu8c5d99e2018-09-10 17:18:44 +08004056 struct wlan_objmgr_vdev *vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07004057
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004058 vdev_id = adapter->vdev_id;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004059 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004060
4061 /* vdev created sanity check */
4062 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Dustin Brown2da29eb2018-07-13 14:23:12 -07004063 hdd_err("vdev %u does not exist", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004064 return -EINVAL;
4065 }
Dustin Brown2da29eb2018-07-13 14:23:12 -07004066
Abhishek Singh628bb6f2019-03-26 14:52:40 +05304067 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4068
4069 /*
4070 * if this is the last active connection check & stop the
4071 * opportunistic timer first
4072 */
4073 if ((policy_mgr_get_connection_count(hdd_ctx->psoc) == 1 &&
4074 policy_mgr_mode_specific_connection_count(hdd_ctx->psoc,
4075 policy_mgr_convert_device_mode_to_qdf_type(
4076 adapter->device_mode), NULL) == 1) ||
4077 !policy_mgr_get_connection_count(hdd_ctx->psoc))
4078 policy_mgr_check_and_stop_opportunistic_timer(hdd_ctx->psoc,
4079 adapter->vdev_id);
4080
Min Liu8c5d99e2018-09-10 17:18:44 +08004081 vdev = hdd_objmgr_get_vdev(adapter);
4082 if (!vdev)
4083 return -EINVAL;
Ashish Kumar Dhanotiya68ee2e42018-11-19 21:15:14 +05304084
4085 ucfg_pmo_del_wow_pattern(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08004086 status = ucfg_reg_11d_vdev_delete_update(vdev);
Abhishek Singh935e4772018-11-21 14:14:10 +05304087 ucfg_scan_vdev_set_disable(vdev, REASON_VDEV_DOWN);
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05304088 hdd_objmgr_put_vdev(vdev);
Yue Maf9782842017-05-08 12:49:49 -07004089
Dustin Brownd28772b2017-03-17 14:16:07 -07004090 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304091 qdf_event_reset(&adapter->qdf_session_close_event);
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004092 status = sme_close_session(hdd_ctx->mac_handle, adapter->vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004093 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Brown2da29eb2018-07-13 14:23:12 -07004094 hdd_err("failed to close sme session; status:%d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08004095 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07004096 }
4097
4098 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304099 status = qdf_wait_for_event_completion(
4100 &adapter->qdf_session_close_event,
Abhishek Singh13bf0ce2018-10-24 14:26:14 +05304101 SME_CMD_VDEV_CREATE_DELETE_TIMEOUT);
Dustin Brown2da29eb2018-07-13 14:23:12 -07004102
4103 if (QDF_IS_STATUS_ERROR(status)) {
4104 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
4105
Dustin Brownd28772b2017-03-17 14:16:07 -07004106 if (adapter->device_mode == QDF_NDI_MODE)
4107 hdd_ndp_session_end_handler(adapter);
Dustin Brown2da29eb2018-07-13 14:23:12 -07004108
4109 if (status == QDF_STATUS_E_TIMEOUT)
4110 hdd_err("timed out waiting for sme close session");
4111 else if (adapter->qdf_session_close_event.force_set)
4112 hdd_info("SSR occurred during sme close session");
4113 else
4114 hdd_err("failed to wait for sme close session; status:%u",
4115 status);
Dustin Brownd28772b2017-03-17 14:16:07 -07004116 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08004117
Yue Maf9782842017-05-08 12:49:49 -07004118release_vdev:
Jiachao Wu2c42c222018-01-15 18:13:19 +08004119
Sandeep Puligillaef415362017-08-30 16:37:13 -07004120 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08004121 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07004122 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08004123 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07004124 return errno;
4125 }
4126
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004127 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004128
4129 return 0;
4130}
4131
Krunal Sonib51eec72017-11-20 21:53:01 -08004132static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
4133 struct sme_session_params *session_param,
Jeff Johnson6a18c962018-07-01 09:09:37 -07004134 csr_roam_complete_cb callback,
Krunal Sonib51eec72017-11-20 21:53:01 -08004135 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07004136{
Dustin Brownd28772b2017-03-17 14:16:07 -07004137 uint32_t type;
4138 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08004139 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07004140
4141 /* determine vdev (sub)type */
4142 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304143 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07004144 hdd_err("failed to get vdev type: %d", status);
4145 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004146 }
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004147 session_param->sme_session_id = adapter->vdev_id;
Krunal Sonib51eec72017-11-20 21:53:01 -08004148 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
4149 session_param->type_of_persona = type;
4150 session_param->subtype_of_persona = sub_type;
4151 session_param->session_open_cb = hdd_sme_open_session_callback;
4152 session_param->session_close_cb = hdd_sme_close_session_callback;
4153 session_param->callback = callback;
4154 session_param->callback_ctx = callback_ctx;
4155
4156 return 0;
4157}
4158
gaurank kathpalia6c4b50c2019-02-28 14:07:48 +05304159void
gaurank kathpalia78af1932018-10-27 20:33:10 +05304160hdd_store_nss_chains_cfg_in_vdev(struct hdd_adapter *adapter)
4161{
4162 struct wlan_mlme_nss_chains vdev_ini_cfg;
4163 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4164
gaurank kathpaliab414bce2018-11-09 18:44:46 +05304165 /* Populate the nss chain params from ini for this vdev type */
gaurank kathpalia78af1932018-10-27 20:33:10 +05304166 sme_populate_nss_chain_params(hdd_ctx->mac_handle, &vdev_ini_cfg,
4167 adapter->device_mode,
4168 hdd_ctx->num_rf_chains);
gaurank kathpaliab414bce2018-11-09 18:44:46 +05304169
4170 /* Store the nss chain config into the vdev */
4171 sme_store_nss_chains_cfg_in_vdev(adapter->vdev, &vdev_ini_cfg);
gaurank kathpalia78af1932018-10-27 20:33:10 +05304172}
gaurank kathpalia6982d472018-10-31 21:54:15 +05304173
4174bool hdd_is_vdev_in_conn_state(struct hdd_adapter *adapter)
4175{
4176 switch (adapter->device_mode) {
4177 case QDF_STA_MODE:
4178 case QDF_P2P_CLIENT_MODE:
4179 case QDF_P2P_DEVICE_MODE:
4180 return hdd_conn_is_connected(
4181 WLAN_HDD_GET_STATION_CTX_PTR(adapter));
4182 case QDF_SAP_MODE:
4183 case QDF_P2P_GO_MODE:
4184 return (test_bit(SOFTAP_BSS_STARTED,
4185 &adapter->event_flags));
4186 default:
4187 hdd_err("Device mode %d invalid", adapter->device_mode);
4188 return 0;
4189 }
4190
4191 return 0;
4192}
4193
Krunal Sonib51eec72017-11-20 21:53:01 -08004194int hdd_vdev_create(struct hdd_adapter *adapter,
Jeff Johnson6a18c962018-07-01 09:09:37 -07004195 csr_roam_complete_cb callback, void *ctx)
Krunal Sonib51eec72017-11-20 21:53:01 -08004196{
4197 QDF_STATUS status;
4198 int errno;
Karthik Kantamneni9180c752018-11-14 12:14:17 +05304199 bool bval;
Krunal Sonib51eec72017-11-20 21:53:01 -08004200 struct hdd_context *hdd_ctx;
4201 struct sme_session_params sme_session_params = {0};
Min Liu8c5d99e2018-09-10 17:18:44 +08004202 struct wlan_objmgr_vdev *vdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004203
4204 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07004205
4206 /* do vdev create via objmgr */
4207 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown07901ec2018-09-07 11:02:41 -07004208 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07004209 if (errno) {
4210 hdd_err("failed to create objmgr vdev: %d", errno);
4211 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004212 }
Dustin Brownd28772b2017-03-17 14:16:07 -07004213
4214 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304215 status = qdf_event_reset(&adapter->qdf_session_open_event);
4216 if (QDF_STATUS_SUCCESS != status) {
4217 hdd_err("failed to reinit session open event");
4218 return -EINVAL;
4219 }
Krunal Sonib51eec72017-11-20 21:53:01 -08004220 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
4221 callback, ctx);
4222 if (errno) {
4223 hdd_err("failed to populating SME params");
4224 goto objmgr_vdev_destroy_procedure;
4225 }
Jeff Johnson16528362018-06-14 12:34:16 -07004226 status = sme_open_session(hdd_ctx->mac_handle, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07004227 if (QDF_IS_STATUS_ERROR(status)) {
4228 hdd_err("failed to open sme session: %d", status);
4229 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07004230 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004231 }
4232
4233 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304234 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
Abhishek Singh13bf0ce2018-10-24 14:26:14 +05304235 SME_CMD_VDEV_CREATE_DELETE_TIMEOUT);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304236 if (QDF_STATUS_SUCCESS != status) {
4237 if (adapter->qdf_session_open_event.force_set) {
4238 /*
4239 * SSR/PDR has caused shutdown, which has forcefully
4240 * set the event. Return without the closing session.
4241 */
Jeff Johnson912b1bb2019-03-06 10:12:36 -08004242 adapter->vdev_id = WLAN_UMAC_VDEV_ID_MAX;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304243 hdd_err("Session open event forcefully set");
4244 return -EINVAL;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304245 }
Jeff Johnsonc66d3102018-02-28 11:58:26 -08004246
4247 if (QDF_STATUS_E_TIMEOUT == status)
4248 hdd_err("Session failed to open within timeout period");
4249 else
4250 hdd_err("Failed to wait for session open event(status-%d)",
4251 status);
4252 errno = -ETIMEDOUT;
4253 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
4254 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004255 }
4256
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05304257 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
4258 hdd_err("Session failed to open due to vdev create failure");
4259 errno = -EINVAL;
4260 goto objmgr_vdev_destroy_procedure;
4261 }
4262
Dustin Brownd28772b2017-03-17 14:16:07 -07004263 /* firmware ready for component communication, raise vdev_ready event */
4264 errno = hdd_vdev_ready(adapter);
4265 if (errno) {
4266 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07004267 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004268 }
4269
Naveen Rawat2b430892018-03-13 13:58:18 -07004270 if (adapter->device_mode == QDF_STA_MODE) {
Karthik Kantamneni9180c752018-11-14 12:14:17 +05304271 bval = false;
4272 status = ucfg_mlme_get_rtt_mac_randomization(hdd_ctx->psoc,
4273 &bval);
4274 if (QDF_IS_STATUS_ERROR(status))
4275 hdd_err("unable to get RTT MAC randomization value");
4276
4277 hdd_debug("setting RTT mac randomization param: %d", bval);
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004278 errno = sme_cli_set_command(adapter->vdev_id,
Naveen Rawat2b430892018-03-13 13:58:18 -07004279 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_INITIATOR_RANDOM_MAC,
Karthik Kantamneni9180c752018-11-14 12:14:17 +05304280 bval,
Naveen Rawat2b430892018-03-13 13:58:18 -07004281 VDEV_CMD);
4282 if (0 != errno)
4283 hdd_err("RTT mac randomization param set failed %d",
4284 errno);
4285 }
4286
Bala Venkatesh110b03e2018-07-10 16:02:08 +05304287 if (adapter->device_mode == QDF_STA_MODE ||
Min Liu8c5d99e2018-09-10 17:18:44 +08004288 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
4289 vdev = hdd_objmgr_get_vdev(adapter);
4290 if (!vdev)
4291 goto hdd_vdev_destroy_procedure;
4292 wlan_vdev_set_max_peer_count(vdev, HDD_MAX_VDEV_PEER_COUNT);
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05304293 hdd_objmgr_put_vdev(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08004294 }
Bala Venkatesh110b03e2018-07-10 16:02:08 +05304295
gaurank kathpalia78af1932018-10-27 20:33:10 +05304296 hdd_store_nss_chains_cfg_in_vdev(adapter);
4297
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004298 hdd_info("vdev %d created successfully", adapter->vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004299
4300 return 0;
4301
4302 /*
4303 * Due to legacy constraints, we need to destroy in the same order as
4304 * create. So, split error handling into 2 cases to accommodate.
4305 */
4306
Krunal Soni4a020c72017-10-30 20:58:40 -07004307objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07004308 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07004309
4310 return errno;
4311
Krunal Soni4a020c72017-10-30 20:58:40 -07004312hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07004313 QDF_BUG(!hdd_vdev_destroy(adapter));
4314
4315 return errno;
4316}
4317
Jeff Johnson9d295242017-08-29 14:39:48 -07004318QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07004319{
Jeff Johnsonb9424862017-10-30 08:49:35 -07004320 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004321 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07004322 QDF_STATUS status;
4323 int ret_val;
Jeff Johnson16528362018-06-14 12:34:16 -07004324 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304325 bool bval = false;
Dustin Brownd28772b2017-03-17 14:16:07 -07004326
Dustin Brownd28772b2017-03-17 14:16:07 -07004327 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -07004328 mac_handle = hdd_ctx->mac_handle;
4329 sme_set_curr_device_mode(mac_handle, adapter->device_mode);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304330 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
4331 if (!QDF_IS_STATUS_SUCCESS(status))
4332 hdd_err("unable to get vht_enable2x2");
4333 sme_set_pdev_ht_vht_ies(mac_handle, bval);
4334
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004335 sme_set_vdev_ies_per_band(mac_handle, adapter->vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004336
Jeff Johnson7f2c5912018-03-23 11:42:28 -07004337 hdd_roam_profile_init(adapter);
4338 hdd_register_wext(adapter->dev);
4339
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07004340 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004341
Jeff Johnson0a082d92019-03-04 12:25:49 -08004342 qdf_mem_set(sta_ctx->conn_info.sta_id,
4343 sizeof(sta_ctx->conn_info.sta_id),
4344 HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05304345
Deepak Dhamdherea2785822016-11-17 01:17:45 -08004346 /* set fast roaming capability in sme session */
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004347 status = sme_config_fast_roaming(mac_handle, adapter->vdev_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05304348 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004349 /* Set the default operation channel */
Jeff Johnson8626e932019-02-27 18:35:22 -08004350 sta_ctx->conn_info.channel =
Vignesh Viswanathana0358ff2018-11-27 09:53:07 +05304351 hdd_ctx->config->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004352
4353 /* Make the default Auth Type as OPEN */
Jeff Johnson96e33512019-02-27 15:10:21 -08004354 sta_ctx->conn_info.auth_type = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004355
4356 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304357 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004358 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004359 status, status);
4360 goto error_init_txrx;
4361 }
4362
4363 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4364
4365 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304366 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004367 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004368 status, status);
4369 goto error_wmm_init;
4370 }
4371
4372 set_bit(WMM_INIT_DONE, &adapter->event_flags);
4373
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004374 ret_val = sme_cli_set_command(adapter->vdev_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004375 WMI_PDEV_PARAM_BURST_ENABLE,
Dundi Raviteja3aa01be2018-05-21 18:58:59 +05304376 HDD_ENABLE_SIFS_BURST_DEFAULT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004377 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07004378 if (ret_val)
4379 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004380
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05304381 /*
4382 * In case of USB tethering, LRO is disabled. If SSR happened
4383 * during that time, then as part of SSR init, do not enable
4384 * the LRO again. Keep the LRO state same as before SSR.
4385 */
jitiphil377bcc12018-10-05 19:46:08 +05304386 if (cdp_cfg_get(cds_get_context(QDF_MODULE_ID_SOC),
4387 cfg_dp_lro_enable) &&
4388 !(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07004389 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05304390
Rakshith Suresh Patkar9f5c5862019-02-04 16:23:02 +05304391 if (cdp_cfg_get(cds_get_context(QDF_MODULE_ID_SOC),
4392 cfg_dp_enable_ip_tcp_udp_checksum_offload))
4393 adapter->dev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
4394 adapter->dev->features |= NETIF_F_RXCSUM;
4395
4396 hdd_set_tso_flags(hdd_ctx, adapter->dev);
4397
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05304398 /* rcpi info initialization */
4399 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
4400
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304401 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004402
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004403error_wmm_init:
4404 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4405 hdd_deinit_tx_rx(adapter);
4406error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07004407 hdd_unregister_wext(adapter->dev);
Dustin Brownd28772b2017-03-17 14:16:07 -07004408 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004409
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004410 return status;
4411}
4412
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304413/**
Krunal Soni4a020c72017-10-30 20:58:40 -07004414 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304415 * @hdd_ctx: global hdd context
4416 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07004417 * @rtnl_held: Used to indicate whether or not the caller is holding
4418 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304419 *
4420 * This function De-initializes the STA/P2P/OCB adapter.
4421 *
4422 * Return: None.
4423 */
Krunal Soni4a020c72017-10-30 20:58:40 -07004424static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004425 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004426 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304427{
Dustin Brownfdf17c12018-03-14 12:55:34 -07004428 hdd_enter_dev(adapter->dev);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304429
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05304430 if (adapter->dev) {
4431 if (rtnl_held)
4432 adapter->dev->wireless_handlers = NULL;
4433 else {
4434 rtnl_lock();
4435 adapter->dev->wireless_handlers = NULL;
4436 rtnl_unlock();
4437 }
4438 }
4439
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304440 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
4441 hdd_deinit_tx_rx(adapter);
4442 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4443 }
4444
4445 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4446 hdd_wmm_adapter_close(adapter);
4447 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4448 }
4449
Krunal Sonib51eec72017-11-20 21:53:01 -08004450
Dustin Browne74003f2018-03-14 12:51:58 -07004451 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304452}
4453
Krunal Sonib51eec72017-11-20 21:53:01 -08004454void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
4455 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004456 bool rtnl_held)
4457{
Dustin Brown491d54b2018-03-14 12:39:11 -07004458 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304459
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004460 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004461 case QDF_STA_MODE:
4462 case QDF_P2P_CLIENT_MODE:
4463 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08004464 case QDF_IBSS_MODE:
4465 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004466 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004467 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004468 break;
4469 }
4470
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004471 case QDF_SAP_MODE:
4472 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004473 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004474 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004475 break;
4476 }
4477
4478 default:
4479 break;
4480 }
4481
Dustin Browne74003f2018-03-14 12:51:58 -07004482 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004483}
4484
Min Liu8c5d99e2018-09-10 17:18:44 +08004485static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx,
4486 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004487 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004488{
Jeff Johnson5505db82017-11-02 21:19:23 -07004489 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004490
4491 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07004492 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004493 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004494 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004495 return;
4496 }
4497
Alok Kumarb64650c2018-03-23 17:05:11 +05304498 hdd_nud_deinit_tracking(adapter);
4499 qdf_mutex_destroy(&adapter->disconnection_status_lock);
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05304500 hdd_apf_context_destroy(adapter);
Min Liu8c5d99e2018-09-10 17:18:44 +08004501 qdf_spinlock_destroy(&adapter->vdev_lock);
Alok Kumarb64650c2018-03-23 17:05:11 +05304502
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05304503 wlan_hdd_debugfs_csr_deinit(adapter);
Arunk Khandavallica56d4b2018-11-29 15:46:00 +05304504 if (adapter->device_mode == QDF_STA_MODE)
4505 hdd_sysfs_destroy_adapter_root_obj(adapter);
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05304506
Rajeev Kumardca5f812016-02-04 17:28:06 -08004507 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05304508
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004509 /*
4510 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
4511 * the driver is almost closed and cannot handle either control
4512 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004513 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
4514 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004515 * is not right. Setting this flag helps hdd_stop() to recognize that
4516 * the interface is closed and restricts any operations on that
4517 */
4518 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
4519
4520 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004521 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07004522 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004523 else
Jeff Johnson5505db82017-11-02 21:19:23 -07004524 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004525 /*
4526 * Note that the adapter is no longer valid at this point
4527 * since the memory has been reclaimed
4528 */
4529 }
4530}
4531
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004532static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07004533 tSirMacAddr mac_addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004534{
Jeff Johnson9d295242017-08-29 14:39:48 -07004535 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004536
Dustin Brown920397d2017-12-13 16:27:50 -08004537 hdd_for_each_adapter(hdd_ctx, adapter) {
4538 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07004539 mac_addr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304540 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004541 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004542 }
Dustin Brown920397d2017-12-13 16:27:50 -08004543
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304544 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004545}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004546
Arun Khandavalli2358d522016-05-16 18:05:37 +05304547#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4548/**
4549 * hdd_set_fw_log_params() - Set log parameters to FW
4550 * @hdd_ctx: HDD Context
4551 * @adapter: HDD Adapter
4552 *
4553 * This function set the FW Debug log level based on the INI.
4554 *
4555 * Return: None
4556 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004557static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004558 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304559{
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304560 QDF_STATUS status;
4561 uint16_t enable_fw_log_level, enable_fw_log_type;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304562 int ret;
4563
Arun Khandavallifae92942016-08-01 13:31:08 +05304564 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4565 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004566 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304567 return;
4568 }
4569
Arun Khandavallifae92942016-08-01 13:31:08 +05304570 /* Enable FW logs based on INI configuration */
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304571 status = ucfg_fwol_get_enable_fw_log_type(hdd_ctx->psoc,
4572 &enable_fw_log_type);
4573 if (QDF_IS_STATUS_ERROR(status))
4574 return;
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004575 ret = sme_cli_set_command(adapter->vdev_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304576 WMI_DBGLOG_TYPE,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304577 enable_fw_log_type,
Arun Khandavallifae92942016-08-01 13:31:08 +05304578 DBG_CMD);
4579 if (ret != 0)
4580 hdd_err("Failed to enable FW log type ret %d",
4581 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304582
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304583 status = ucfg_fwol_get_enable_fw_log_level(hdd_ctx->psoc,
4584 &enable_fw_log_level);
4585 if (QDF_IS_STATUS_ERROR(status))
4586 return;
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004587 ret = sme_cli_set_command(adapter->vdev_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304588 WMI_DBGLOG_LOG_LEVEL,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304589 enable_fw_log_level,
Arun Khandavallifae92942016-08-01 13:31:08 +05304590 DBG_CMD);
4591 if (ret != 0)
4592 hdd_err("Failed to enable FW log level ret %d",
4593 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304594
lifengfaa83cb2018-11-24 01:53:56 +08004595 sme_enable_fw_module_log_level(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004596 adapter->vdev_id);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304597}
4598#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004599static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004600 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304601{
4602}
4603
4604#endif
4605
4606/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004607 * hdd_configure_chain_mask() - programs chain mask to firmware
4608 * @adapter: HDD adapter
4609 *
4610 * Return: 0 on success or errno on failure
4611 */
4612static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4613{
Naveen Rawat98322472018-03-06 10:29:42 -08004614 QDF_STATUS status;
4615 struct wma_caps_per_phy non_dbs_phy_cap;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004616 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304617 bool enable2x2 = false, enable_bt_chain_sep = false;
Krunal Sonidf29bc42018-11-15 13:26:29 -08004618 uint8_t dual_mac_feature = DISABLE_DBS_CXN_AND_SCAN;
4619
4620 status = ucfg_policy_mgr_get_dual_mac_feature(hdd_ctx->psoc,
4621 &dual_mac_feature);
4622 if (!QDF_IS_STATUS_SUCCESS(status))
4623 hdd_err("unable to get dual mac feature");
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304624
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304625 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &enable2x2);
4626 if (QDF_IS_STATUS_ERROR(status))
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304627 hdd_err("unable to get vht_enable2x2");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004628
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304629 status = ucfg_mlme_get_bt_chain_separation_flag(hdd_ctx->psoc,
4630 &enable_bt_chain_sep);
4631 if (QDF_IS_STATUS_ERROR(status))
4632 hdd_debug("unable to get BT chain separation. using default");
4633
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304634 hdd_debug("enable2x2: %d, lte_coex: %d, disable_DBS: %d",
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304635 enable2x2, hdd_ctx->lte_coex_ant_share,
Krunal Sonidf29bc42018-11-15 13:26:29 -08004636 dual_mac_feature);
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304637 hdd_debug("enable_bt_chain_separation %d", enable_bt_chain_sep);
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004638
Naveen Rawat98322472018-03-06 10:29:42 -08004639 status = wma_get_caps_for_phyidx_hwmode(&non_dbs_phy_cap,
4640 HW_MODE_DBS_NONE,
4641 CDS_BAND_ALL);
4642 if (QDF_IS_STATUS_ERROR(status)) {
4643 hdd_err("couldn't get phy caps. skip chain mask programming");
4644 return qdf_status_to_os_return(status);
4645 }
4646
4647 if (non_dbs_phy_cap.tx_chain_mask_2G < 3 ||
4648 non_dbs_phy_cap.rx_chain_mask_2G < 3 ||
4649 non_dbs_phy_cap.tx_chain_mask_5G < 3 ||
4650 non_dbs_phy_cap.rx_chain_mask_5G < 3) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004651 hdd_debug("firmware not capable. skip chain mask programming");
Naveen Rawat98322472018-03-06 10:29:42 -08004652 return 0;
4653 }
4654
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304655 if (enable2x2 && !enable_bt_chain_sep) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004656 hdd_debug("2x2 enabled. skip chain mask programming");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004657 return 0;
4658 }
4659
Krunal Sonidf29bc42018-11-15 13:26:29 -08004660 if (dual_mac_feature != DISABLE_DBS_CXN_AND_SCAN) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004661 hdd_debug("DBS enabled(%d). skip chain mask programming",
Krunal Sonidf29bc42018-11-15 13:26:29 -08004662 dual_mac_feature);
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004663 return 0;
4664 }
4665
Naveen Rawatdacb5032018-02-08 15:23:24 -08004666 if (hdd_ctx->lte_coex_ant_share) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004667 hdd_debug("lte ant sharing enabled. skip chainmask programming");
Naveen Rawatdacb5032018-02-08 15:23:24 -08004668 return 0;
4669 }
4670
Dustin Brown1dbefe62018-09-11 16:32:03 -07004671 status = ucfg_mlme_configure_chain_mask(hdd_ctx->psoc,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004672 adapter->vdev_id);
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304673 if (status != QDF_STATUS_SUCCESS)
4674 goto error;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004675
4676 return 0;
4677
4678error:
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304679 hdd_err("WMI PDEV set param failed");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004680 return -EINVAL;
4681}
4682
4683/**
Dundi Raviteja3b637092018-09-12 13:42:50 +05304684 * hdd_send_coex_config_params() - Send coex config params to FW
4685 * @hdd_ctx: HDD context
4686 * @adapter: Primary adapter context
4687 *
4688 * This function is used to send all coex config related params to FW
4689 *
4690 * Return: 0 on success and -EINVAL on failure
4691 */
4692static int hdd_send_coex_config_params(struct hdd_context *hdd_ctx,
4693 struct hdd_adapter *adapter)
4694{
4695 struct coex_config_params coex_cfg_params = {0};
4696 struct wlan_fwol_coex_config config = {0};
Dustin Brown05d81302018-09-11 16:49:22 -07004697 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Dundi Raviteja3b637092018-09-12 13:42:50 +05304698 QDF_STATUS status;
4699
4700 if (!hdd_ctx) {
4701 hdd_err("hdd_ctx is invalid");
4702 goto err;
4703 }
4704
4705 if (!adapter) {
4706 hdd_err("adapter is invalid");
4707 goto err;
4708 }
4709
4710 if (!psoc) {
4711 hdd_err("HDD psoc is invalid");
4712 goto err;
4713 }
4714
4715 status = ucfg_fwol_get_coex_config_params(psoc, &config);
4716 if (QDF_IS_STATUS_ERROR(status)) {
4717 hdd_err("Unable to get coex config params");
4718 goto err;
4719 }
4720
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004721 coex_cfg_params.vdev_id = adapter->vdev_id;
Dundi Raviteja3b637092018-09-12 13:42:50 +05304722 coex_cfg_params.config_type = WMI_COEX_CONFIG_TX_POWER;
4723 coex_cfg_params.config_arg1 = config.max_tx_power_for_btc;
4724
4725 status = sme_send_coex_config_cmd(&coex_cfg_params);
4726 if (QDF_IS_STATUS_ERROR(status)) {
4727 hdd_err("Failed to send coex Tx power");
4728 goto err;
4729 }
4730
4731 coex_cfg_params.config_type = WMI_COEX_CONFIG_HANDOVER_RSSI;
4732 coex_cfg_params.config_arg1 = config.wlan_low_rssi_threshold;
4733
4734 status = sme_send_coex_config_cmd(&coex_cfg_params);
4735 if (QDF_IS_STATUS_ERROR(status)) {
4736 hdd_err("Failed to send coex handover RSSI");
4737 goto err;
4738 }
4739
4740 coex_cfg_params.config_type = WMI_COEX_CONFIG_BTC_MODE;
4741 coex_cfg_params.config_arg1 = config.btc_mode;
4742
4743 status = sme_send_coex_config_cmd(&coex_cfg_params);
4744 if (QDF_IS_STATUS_ERROR(status)) {
4745 hdd_err("Failed to send coex BTC mode");
4746 goto err;
4747 }
4748
4749 coex_cfg_params.config_type = WMI_COEX_CONFIG_ANTENNA_ISOLATION;
4750 coex_cfg_params.config_arg1 = config.antenna_isolation;
4751
4752 status = sme_send_coex_config_cmd(&coex_cfg_params);
4753 if (QDF_IS_STATUS_ERROR(status)) {
4754 hdd_err("Failed to send coex antenna isolation");
4755 goto err;
4756 }
4757
4758 coex_cfg_params.config_type = WMI_COEX_CONFIG_BT_LOW_RSSI_THRESHOLD;
4759 coex_cfg_params.config_arg1 = config.bt_low_rssi_threshold;
4760
4761 status = sme_send_coex_config_cmd(&coex_cfg_params);
4762 if (QDF_IS_STATUS_ERROR(status)) {
4763 hdd_err("Failed to send coex BT low RSSI threshold");
4764 goto err;
4765 }
4766
4767 coex_cfg_params.config_type = WMI_COEX_CONFIG_BT_INTERFERENCE_LEVEL;
4768 coex_cfg_params.config_arg1 = config.bt_interference_low_ll;
4769 coex_cfg_params.config_arg2 = config.bt_interference_low_ul;
4770 coex_cfg_params.config_arg3 = config.bt_interference_medium_ll;
4771 coex_cfg_params.config_arg4 = config.bt_interference_medium_ul;
4772 coex_cfg_params.config_arg5 = config.bt_interference_high_ll;
4773 coex_cfg_params.config_arg6 = config.bt_interference_high_ul;
4774
4775 status = sme_send_coex_config_cmd(&coex_cfg_params);
4776 if (QDF_IS_STATUS_ERROR(status)) {
4777 hdd_err("Failed to send coex BT interference level");
4778 goto err;
4779 }
stonezc9936cb2019-03-11 16:41:22 +08004780
4781 if (wlan_hdd_mpta_helper_enable(&coex_cfg_params, &config))
4782 goto err;
4783
Dundi Raviteja3b637092018-09-12 13:42:50 +05304784 return 0;
4785err:
4786 return -EINVAL;
4787}
4788
4789/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304790 * hdd_set_fw_params() - Set parameters to firmware
4791 * @adapter: HDD adapter
4792 *
4793 * This function Sets various parameters to fw once the
4794 * adapter is started.
4795 *
4796 * Return: 0 on success or errno on failure
4797 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004798int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304799{
4800 int ret;
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304801 uint16_t upper_brssi_thresh, lower_brssi_thresh, rts_profile;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304802 bool enable_dtim_1chrx;
4803 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004804 struct hdd_context *hdd_ctx;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304805 bool bval = false;
Manikandan Mohand350c192018-11-29 14:01:12 -08004806 uint8_t max_amsdu_len, enable_tx_sch_delay;
4807 uint32_t dtim_sel_diversity, enable_secondary_rate;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304808
Dustin Brownfdf17c12018-03-14 12:55:34 -07004809 hdd_enter_dev(adapter->dev);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304810
4811 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4812 if (!hdd_ctx)
4813 return -EINVAL;
4814
Dustin Brown732ab9c2017-06-15 13:24:09 -07004815 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4816 hdd_debug("FTM Mode is active; nothing to do");
4817 return 0;
4818 }
4819
Manikandan Mohand350c192018-11-29 14:01:12 -08004820 ret = -1;
4821 if (QDF_IS_STATUS_SUCCESS(ucfg_fwol_get_lprx_enable(hdd_ctx->psoc,
4822 &bval))) {
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004823 ret = sme_cli_set_command(adapter->vdev_id,
Manikandan Mohand350c192018-11-29 14:01:12 -08004824 WMI_PDEV_PARAM_DTIM_SYNTH,
4825 bval, PDEV_CMD);
4826 }
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304827 if (ret) {
4828 hdd_err("Failed to set LPRx");
4829 goto error;
4830 }
4831
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +05304832 ucfg_mlme_get_dtim_selection_diversity(hdd_ctx->psoc,
4833 &dtim_sel_diversity);
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304834
4835 ret = sme_cli_set_command(
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004836 adapter->vdev_id,
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304837 WMI_PDEV_PARAM_1CH_DTIM_OPTIMIZED_CHAIN_SELECTION,
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +05304838 dtim_sel_diversity, PDEV_CMD);
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304839 if (ret) {
4840 hdd_err("Failed to set DTIM_OPTIMIZED_CHAIN_SELECTION");
4841 goto error;
4842 }
4843
Manikandan Mohand350c192018-11-29 14:01:12 -08004844 ret = -1;
4845 if (QDF_IS_STATUS_SUCCESS(ucfg_fwol_get_enable_tx_sch_delay(
4846 hdd_ctx->psoc, &enable_tx_sch_delay))) {
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004847 ret = sme_cli_set_command(adapter->vdev_id,
Manikandan Mohand350c192018-11-29 14:01:12 -08004848 WMI_PDEV_PARAM_TX_SCH_DELAY,
4849 enable_tx_sch_delay, PDEV_CMD);
4850 }
Ashish Kumar Dhanotiya48dac7d2018-03-28 14:59:50 +05304851 if (ret) {
4852 hdd_err("Failed to set WMI_PDEV_PARAM_TX_SCH_DELAY");
4853 goto error;
4854 }
4855
Manikandan Mohand350c192018-11-29 14:01:12 -08004856 ret = -1;
4857 if (QDF_IS_STATUS_SUCCESS(ucfg_fwol_get_enable_secondary_rate(
4858 hdd_ctx->psoc, &enable_secondary_rate))) {
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004859 ret = sme_cli_set_command(adapter->vdev_id,
Manikandan Mohand350c192018-11-29 14:01:12 -08004860 WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE,
4861 enable_secondary_rate, PDEV_CMD);
4862 }
Ashish Kumar Dhanotiya959b38c2018-04-06 21:07:57 +05304863 if (ret) {
4864 hdd_err("Failed to set WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE");
4865 goto error;
4866 }
4867
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304868 if (adapter->device_mode == QDF_STA_MODE) {
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304869 status = ucfg_get_upper_brssi_thresh(hdd_ctx->psoc,
4870 &upper_brssi_thresh);
4871 if (QDF_IS_STATUS_ERROR(status))
4872 return -EINVAL;
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304873
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004874 sme_set_smps_cfg(adapter->vdev_id,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304875 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4876 upper_brssi_thresh);
4877
4878 status = ucfg_get_lower_brssi_thresh(hdd_ctx->psoc,
4879 &lower_brssi_thresh);
4880 if (QDF_IS_STATUS_ERROR(status))
4881 return -EINVAL;
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304882
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004883 sme_set_smps_cfg(adapter->vdev_id,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304884 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4885 lower_brssi_thresh);
4886
4887 status = ucfg_get_enable_dtim_1chrx(hdd_ctx->psoc,
4888 &enable_dtim_1chrx);
4889 if (QDF_IS_STATUS_ERROR(status))
4890 return -EINVAL;
4891
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004892 sme_set_smps_cfg(adapter->vdev_id,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304893 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4894 enable_dtim_1chrx);
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304895 }
4896
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304897 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
4898 if (!QDF_IS_STATUS_SUCCESS(status))
4899 hdd_err("unable to get vht_enable2x2");
4900
4901 if (bval) {
Dustin Brown732ab9c2017-06-15 13:24:09 -07004902 hdd_debug("configuring 2x2 mode fw params");
4903
Vignesh Viswanathana851d752018-10-03 19:44:38 +05304904 ret = sme_set_cck_tx_fir_override(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004905 adapter->vdev_id);
Dustin Brown732ab9c2017-06-15 13:24:09 -07004906 if (ret) {
4907 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4908 ret);
4909 goto error;
4910 }
Liangwei Dong22810e82018-03-15 03:42:12 -04004911
4912 if (hdd_configure_chain_mask(adapter))
4913 goto error;
Dustin Brown732ab9c2017-06-15 13:24:09 -07004914 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304915#define HDD_DTIM_1CHAIN_RX_ID 0x5
4916#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004917 hdd_debug("configuring 1x1 mode fw params");
4918
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004919 /*
4920 * Disable DTIM 1 chain Rx when in 1x1,
4921 * we are passing two value
4922 * as param_id << 29 | param_value.
4923 * Below param_value = 0(disable)
4924 */
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004925 ret = sme_cli_set_command(adapter->vdev_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004926 WMI_STA_SMPS_PARAM_CMDID,
4927 HDD_DTIM_1CHAIN_RX_ID <<
4928 HDD_SMPS_PARAM_VALUE_S,
4929 VDEV_CMD);
4930 if (ret) {
4931 hdd_err("DTIM 1 chain set failed %d", ret);
4932 goto error;
4933 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304934
Arun Khandavalli2358d522016-05-16 18:05:37 +05304935#undef HDD_DTIM_1CHAIN_RX_ID
4936#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004937
4938 if (hdd_configure_chain_mask(adapter))
4939 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004940 }
4941
Vignesh Viswanathana851d752018-10-03 19:44:38 +05304942 ret = sme_set_enable_mem_deep_sleep(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004943 adapter->vdev_id);
Dustin Brown732ab9c2017-06-15 13:24:09 -07004944 if (ret) {
4945 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4946 goto error;
4947 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304948
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304949 status = ucfg_fwol_get_rts_profile(hdd_ctx->psoc, &rts_profile);
4950 if (QDF_IS_STATUS_ERROR(status))
4951 return -EINVAL;
4952
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004953 ret = sme_cli_set_command(adapter->vdev_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004954 WMI_VDEV_PARAM_ENABLE_RTSCTS,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304955 rts_profile,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004956 VDEV_CMD);
4957 if (ret) {
4958 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4959 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304960 }
4961
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05304962 status = ucfg_mlme_get_max_amsdu_num(hdd_ctx->psoc, &max_amsdu_len);
4963 if (QDF_IS_STATUS_ERROR(status)) {
4964 hdd_err("Failed to get Max AMSDU Num");
4965 goto error;
4966 }
4967
4968 hdd_debug("SET AMSDU num %d", max_amsdu_len);
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004969
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004970 ret = wma_cli_set_command(adapter->vdev_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004971 GEN_VDEV_PARAM_AMSDU,
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05304972 max_amsdu_len,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004973 GEN_CMD);
4974 if (ret != 0) {
4975 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4976 goto error;
4977 }
4978
Arun Khandavalli2358d522016-05-16 18:05:37 +05304979 hdd_set_fw_log_params(hdd_ctx, adapter);
Dundi Raviteja3b637092018-09-12 13:42:50 +05304980
4981 ret = hdd_send_coex_config_params(hdd_ctx, adapter);
4982 if (ret) {
4983 hdd_warn("Error initializing coex config params");
4984 goto error;
4985 }
4986
Dustin Browne74003f2018-03-14 12:51:58 -07004987 hdd_exit();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004988
Arun Khandavalli2358d522016-05-16 18:05:37 +05304989 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304990
Arun Khandavalli2358d522016-05-16 18:05:37 +05304991error:
4992 return -EINVAL;
4993}
4994
Ryan Hsu07495ea2016-01-21 15:25:39 -08004995/**
Abhinav Kumarcc959f12018-08-09 13:58:30 +05304996 * hdd_init_completion() - Initialize Completion Variables
4997 * @adapter: HDD adapter
4998 *
4999 * This function Initialize the completion variables for
5000 * a particular adapter
5001 *
5002 * Return: None
5003 */
5004static void hdd_init_completion(struct hdd_adapter *adapter)
5005{
5006 init_completion(&adapter->disconnect_comp_var);
5007 init_completion(&adapter->roaming_comp_var);
5008 init_completion(&adapter->linkup_event_var);
Abhinav Kumarcc959f12018-08-09 13:58:30 +05305009 init_completion(&adapter->sta_authorized_event);
5010 init_completion(&adapter->offchannel_tx_event);
5011 init_completion(&adapter->tx_action_cnf_event);
5012 init_completion(&adapter->ibss_peer_info_comp);
5013 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
5014}
5015
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05305016static void hdd_reset_locally_admin_bit(struct hdd_context *hdd_ctx,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005017 tSirMacAddr mac_addr)
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05305018{
5019 int i;
5020 /*
5021 * Reset locally administered bit for dynamic_mac_list
5022 * also as while releasing the MAC address for any
5023 * interface mac will be compared with dynamic mac list
5024 */
5025 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
5026 if (!qdf_mem_cmp(
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005027 mac_addr,
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05305028 &hdd_ctx->
5029 dynamic_mac_list[i].dynamic_mac.bytes[0],
5030 sizeof(struct qdf_mac_addr))) {
5031 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(
5032 hdd_ctx->
5033 dynamic_mac_list[i].dynamic_mac.bytes);
5034 break;
5035 }
5036 }
5037 /*
5038 * Reset locally administered bit if the device mode is
5039 * STA
5040 */
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005041 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(mac_addr);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05305042 hdd_debug("locally administered bit reset in sta mode: "
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07005043 MAC_ADDRESS_STR, QDF_MAC_ADDR_ARRAY(mac_addr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05305044}
5045
Dustin Brown96b98dd2019-03-06 12:39:37 -08005046static void wlan_hdd_cfg80211_scan_block_cb(struct work_struct *work)
5047{
5048 struct hdd_adapter *adapter =
5049 container_of(work, struct hdd_adapter, scan_block_work);
5050 struct osif_vdev_sync *vdev_sync;
5051
5052 if (osif_vdev_sync_op_start(adapter->dev, &vdev_sync))
5053 return;
5054
5055 wlan_hdd_cfg80211_scan_block(adapter);
5056
5057 osif_vdev_sync_op_stop(vdev_sync);
5058}
5059
Abhinav Kumarcc959f12018-08-09 13:58:30 +05305060/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08005061 * hdd_open_adapter() - open and setup the hdd adatper
5062 * @hdd_ctx: global hdd context
5063 * @session_type: type of the interface to be created
5064 * @iface_name: User-visible name of the interface
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005065 * @mac_addr: MAC address to assign to the interface
Ryan Hsu07495ea2016-01-21 15:25:39 -08005066 * @name_assign_type: the name of assign type of the netdev
5067 * @rtnl_held: the rtnl lock hold flag
5068 *
5069 * This function open and setup the hdd adpater according to the device
5070 * type request, assign the name, the mac address assigned, and then prepared
5071 * the hdd related parameters, queue, lock and ready to start.
5072 *
5073 * Return: the pointer of hdd adapter, otherwise NULL.
5074 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005075struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005076 const char *iface_name, tSirMacAddr mac_addr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08005077 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08005078 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005079{
Madhvapathi Sriram8b056652019-03-27 17:38:12 +05305080 struct net_device *ndev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005081 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305082 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005083
5084 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
5085 /*
5086 * Max limit reached on the number of vdevs configured by the
5087 * host. Return error
5088 */
Arun Khandavallifae92942016-08-01 13:31:08 +05305089 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
5090 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005091 return NULL;
5092 }
5093
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005094 status = wlan_hdd_validate_mac_address((struct qdf_mac_addr *)mac_addr);
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05305095 if (QDF_IS_STATUS_ERROR(status)) {
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005096 /* Not received valid mac_addr */
Arun Khandavallifae92942016-08-01 13:31:08 +05305097 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005098 return NULL;
5099 }
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05305100
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005101 status = hdd_check_for_existing_macaddr(hdd_ctx, mac_addr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305102 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305103 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
5104 " already exists",
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07005105 QDF_MAC_ADDR_ARRAY(mac_addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005106 return NULL;
5107 }
5108
5109 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005110 case QDF_STA_MODE:
Ashish Kumar Dhanotiya01485192018-12-24 12:44:06 +05305111 if (!hdd_ctx->config->mac_provision) {
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005112 hdd_reset_locally_admin_bit(hdd_ctx, mac_addr);
Ashish Kumar Dhanotiya01485192018-12-24 12:44:06 +05305113 /*
5114 * After resetting locally administered bit
5115 * again check if the new mac address is already
5116 * exists.
5117 */
5118 status = hdd_check_for_existing_macaddr(hdd_ctx,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005119 mac_addr);
Ashish Kumar Dhanotiya01485192018-12-24 12:44:06 +05305120 if (QDF_STATUS_E_FAILURE == status) {
5121 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
5122 " already exists",
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07005123 QDF_MAC_ADDR_ARRAY(mac_addr));
Ashish Kumar Dhanotiya01485192018-12-24 12:44:06 +05305124 return NULL;
5125 }
5126 }
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05305127
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005128 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005129 case QDF_P2P_CLIENT_MODE:
5130 case QDF_P2P_DEVICE_MODE:
5131 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07005132 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305133 case QDF_MONITOR_MODE:
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005134 adapter = hdd_alloc_station_adapter(hdd_ctx, mac_addr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08005135 name_assign_type,
5136 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005137
Jeff Johnsond36fa332019-03-18 13:42:25 -07005138 if (!adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305139 hdd_err("failed to allocate adapter for session %d",
5140 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005141 return NULL;
5142 }
5143
Madhvapathi Sriram8b056652019-03-27 17:38:12 +05305144 ndev = adapter->dev;
5145
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005146 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005147 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005148 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005149 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305150 else if (QDF_MONITOR_MODE == session_type)
5151 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005152 else
5153 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
5154
5155 adapter->device_mode = session_type;
5156
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005157
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005158 /*
5159 * Workqueue which gets scheduled in IPv4 notification
5160 * callback
5161 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005162 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005163 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005164
5165#ifdef WLAN_NS_OFFLOAD
5166 /*
5167 * Workqueue which gets scheduled in IPv6
5168 * notification callback.
5169 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005170 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005171 hdd_ipv6_notifier_work_queue);
5172#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005173 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08005174 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08005175 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005176
5177 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005178 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005179 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305180 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5181 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05305182
Alok Kumarb64650c2018-03-23 17:05:11 +05305183 hdd_nud_init_tracking(adapter);
Arunk Khandavallica56d4b2018-11-29 15:46:00 +05305184 if (adapter->device_mode == QDF_STA_MODE ||
5185 adapter->device_mode == QDF_P2P_DEVICE_MODE)
5186 hdd_sysfs_create_adapter_root_obj(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05305187 qdf_mutex_create(&adapter->disconnection_status_lock);
5188
Ravi Joshi1a292562017-05-18 16:28:54 -07005189 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005190
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005191 case QDF_P2P_GO_MODE:
5192 case QDF_SAP_MODE:
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005193 adapter = hdd_wlan_create_ap_dev(hdd_ctx, mac_addr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08005194 name_assign_type,
5195 (uint8_t *) iface_name);
Jeff Johnsond36fa332019-03-18 13:42:25 -07005196 if (!adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005197 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05305198 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005199 return NULL;
5200 }
5201
Madhvapathi Sriram8b056652019-03-27 17:38:12 +05305202 ndev = adapter->dev;
5203
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005204 adapter->wdev.iftype =
5205 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005206 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005207 NL80211_IFTYPE_P2P_GO;
5208 adapter->device_mode = session_type;
5209
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07005210 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08005211 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005212 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08005213
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005214 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005215 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305216 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5217 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305218
5219 /*
5220 * Workqueue which gets scheduled in IPv4 notification
5221 * callback
5222 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005223 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305224 hdd_ipv4_notifier_work_queue);
5225
5226#ifdef WLAN_NS_OFFLOAD
5227 /*
5228 * Workqueue which gets scheduled in IPv6
5229 * notification callback.
5230 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005231 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305232 hdd_ipv6_notifier_work_queue);
5233#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005234 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305235 case QDF_FTM_MODE:
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005236 adapter = hdd_alloc_station_adapter(hdd_ctx, mac_addr,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305237 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08005238 iface_name);
Jeff Johnsond36fa332019-03-18 13:42:25 -07005239 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305240 hdd_err("Failed to allocate adapter for FTM mode");
5241 return NULL;
5242 }
Madhvapathi Sriram8b056652019-03-27 17:38:12 +05305243
5244 ndev = adapter->dev;
5245
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305246 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
5247 adapter->device_mode = session_type;
5248 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08005249 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08005250 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08005251
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305252 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005253 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305254 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305255 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5256 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305257 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005258 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005259 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305260 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005261 return NULL;
5262 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005263
Min Liu8c5d99e2018-09-10 17:18:44 +08005264 qdf_spinlock_create(&adapter->vdev_lock);
5265
Abhinav Kumarcc959f12018-08-09 13:58:30 +05305266 hdd_init_completion(adapter);
hqueaa33ee2017-05-04 17:56:35 +08005267 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
Min Liu9be5d4a2018-05-17 11:51:53 +08005268 qdf_list_create(&adapter->blocked_scan_request_q, WLAN_MAX_SCAN_COUNT);
5269 qdf_mutex_create(&adapter->blocked_scan_request_q_lock);
hqueaa33ee2017-05-04 17:56:35 +08005270
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305271 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005272 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08005273 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005274 }
5275
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305276 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsond36fa332019-03-18 13:42:25 -07005277 if (adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005278 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
5279 adapter = NULL;
5280 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005281
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005282 return NULL;
5283 }
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05305284 hdd_apf_context_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005285
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305286 if (QDF_STATUS_SUCCESS == status) {
Dustin Brown1dbefe62018-09-11 16:32:03 -07005287 policy_mgr_set_concurrency_mode(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005288 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005289
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005290 /* Adapter successfully added. Increment the vdev count */
5291 hdd_ctx->current_intf_count++;
5292
Jeff Johnson5880d792016-08-15 13:32:30 -07005293 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005294 hdd_ctx->current_intf_count);
5295
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08005296 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005297 }
5298
Rajeev Kumardca5f812016-02-04 17:28:06 -08005299 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07005300 hdd_err("Interface %s wow debug_fs init failed",
5301 netdev_name(adapter->dev));
5302
5303 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
5304 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005305
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05305306 if (adapter->device_mode == QDF_STA_MODE)
5307 wlan_hdd_debugfs_csr_init(adapter);
5308
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005309 return adapter;
5310
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005311err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07005312 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Madhvapathi Sriram8b056652019-03-27 17:38:12 +05305313
5314 if (ndev)
5315 free_netdev(ndev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005316
5317 return NULL;
5318}
5319
Dustin Brown728d65a2018-10-02 16:27:52 -07005320static void __hdd_close_adapter(struct hdd_context *hdd_ctx,
5321 struct hdd_adapter *adapter,
5322 bool rtnl_held)
5323{
5324 qdf_list_destroy(&adapter->blocked_scan_request_q);
5325 qdf_mutex_destroy(&adapter->blocked_scan_request_q_lock);
5326 policy_mgr_clear_concurrency_mode(hdd_ctx->psoc, adapter->device_mode);
5327
5328 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
5329
5330 if (hdd_ctx->current_intf_count != 0)
5331 hdd_ctx->current_intf_count--;
5332}
5333
5334void hdd_close_adapter(struct hdd_context *hdd_ctx,
5335 struct hdd_adapter *adapter,
5336 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005337{
Dustin Brown920397d2017-12-13 16:27:50 -08005338 /*
Dustin Brown728d65a2018-10-02 16:27:52 -07005339 * Stop the global bus bandwidth timer while touching the adapter list
5340 * to avoid bad memory access by the timer handler.
Dustin Brown920397d2017-12-13 16:27:50 -08005341 */
Dustin Brown920397d2017-12-13 16:27:50 -08005342 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005343
Dustin Brown920397d2017-12-13 16:27:50 -08005344 hdd_remove_adapter(hdd_ctx, adapter);
Dustin Brown728d65a2018-10-02 16:27:52 -07005345 __hdd_close_adapter(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005346
Dustin Brown920397d2017-12-13 16:27:50 -08005347 /* conditionally restart the bw timer */
5348 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005349}
5350
Dustin Brown728d65a2018-10-02 16:27:52 -07005351void hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005352{
Dustin Brown920397d2017-12-13 16:27:50 -08005353 struct hdd_adapter *adapter;
Dustin Brown2c5e0482019-02-05 16:14:43 -08005354 struct osif_vdev_sync *vdev_sync;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005355
Dustin Brown491d54b2018-03-14 12:39:11 -07005356 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005357
Dustin Brown728d65a2018-10-02 16:27:52 -07005358 while (QDF_IS_STATUS_SUCCESS(hdd_remove_front_adapter(hdd_ctx,
5359 &adapter))) {
Dustin Brown2c5e0482019-02-05 16:14:43 -08005360 vdev_sync = osif_vdev_sync_unregister(adapter->dev);
Dustin Brown693b5352019-01-17 10:00:31 -08005361 if (vdev_sync)
Dustin Brown2c5e0482019-02-05 16:14:43 -08005362 osif_vdev_sync_wait_for_ops(vdev_sync);
Dustin Brown693b5352019-01-17 10:00:31 -08005363
Dustin Brown728d65a2018-10-02 16:27:52 -07005364 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
5365 __hdd_close_adapter(hdd_ctx, adapter, rtnl_held);
Dustin Brown693b5352019-01-17 10:00:31 -08005366
5367 if (vdev_sync)
Dustin Brown2c5e0482019-02-05 16:14:43 -08005368 osif_vdev_sync_destroy(vdev_sync);
Dustin Brown728d65a2018-10-02 16:27:52 -07005369 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005370
Dustin Browne74003f2018-03-14 12:51:58 -07005371 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005372}
5373
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005374void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005375{
Anurag Chouhan6d760662016-02-20 16:05:43 +05305376 struct qdf_mac_addr *bssid = NULL;
Jeff Johnsonc565af12019-03-10 21:09:47 -07005377 tSirUpdateIE update_ie;
Jeff Johnson16528362018-06-14 12:34:16 -07005378 mac_handle_t mac_handle;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005379
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005380 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005381 case QDF_STA_MODE:
5382 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005383 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005384 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005385 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsone04b6992019-02-27 14:06:55 -08005386 bssid = &sta_ctx->conn_info.bssid;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005387 break;
5388 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005389 case QDF_SAP_MODE:
5390 case QDF_P2P_GO_MODE:
5391 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005392 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07005393 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005394 break;
5395 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005396 case QDF_FTM_MODE:
5397 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005398 default:
5399 /*
5400 * wlan_hdd_reset_prob_rspies should not have been called
5401 * for these kind of devices
5402 */
Jeff Johnson5880d792016-08-15 13:32:30 -07005403 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005404 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005405 return;
5406 }
5407
Jeff Johnsonc565af12019-03-10 21:09:47 -07005408 qdf_copy_macaddr(&update_ie.bssid, bssid);
5409 update_ie.smeSessionId = adapter->vdev_id;
5410 update_ie.ieBufferlength = 0;
5411 update_ie.pAdditionIEBuffer = NULL;
5412 update_ie.append = true;
5413 update_ie.notify = false;
Jeff Johnson16528362018-06-14 12:34:16 -07005414 mac_handle = hdd_adapter_get_mac_handle(adapter);
5415 if (sme_update_add_ie(mac_handle,
Jeff Johnsonc565af12019-03-10 21:09:47 -07005416 &update_ie,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305417 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005418 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005419 }
5420}
5421
Dustin Browndb2a8be2017-12-20 11:49:56 -08005422QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
5423 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005424{
Dustin Brownd747ecd2018-10-26 16:32:22 -07005425 QDF_STATUS status = QDF_STATUS_SUCCESS;
5426 struct hdd_station_ctx *sta_ctx;
Dustin Brownb4260d52019-01-24 11:53:08 -08005427 struct sap_context *sap_ctx;
Jeff Johnson025618c2018-03-18 14:41:00 -07005428 struct csr_roam_profile *roam_profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005429 union iwreq_data wrqu;
Jeff Johnsonc565af12019-03-10 21:09:47 -07005430 tSirUpdateIE update_ie;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005431 unsigned long rc;
Jeff Johnson8f8ceb92019-03-24 08:16:55 -07005432 struct sap_config *sap_config;
Jeff Johnson16528362018-06-14 12:34:16 -07005433 mac_handle_t mac_handle;
Min Liu8c5d99e2018-09-10 17:18:44 +08005434 struct wlan_objmgr_vdev *vdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005435
Dustin Brown491d54b2018-03-14 12:39:11 -07005436 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005437
Jeff Johnson912b1bb2019-03-06 10:12:36 -08005438 if (adapter->vdev_id != WLAN_UMAC_VDEV_ID_MAX)
Dustin Browne7e71d32018-05-11 16:00:08 -07005439 wlan_hdd_cfg80211_deregister_frames(adapter);
5440
Alok Kumarb64650c2018-03-23 17:05:11 +05305441 hdd_nud_ignore_tracking(adapter, true);
5442 hdd_nud_reset_tracking(adapter);
Alok Kumar016a1ac2018-09-16 09:55:50 +05305443 hdd_nud_flush_work(adapter);
hangtian9c47aaf2018-11-26 17:59:39 +08005444 hdd_stop_tsf_sync(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05305445
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005446 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305447 wlan_hdd_netif_queue_control(adapter,
5448 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5449 WLAN_CONTROL_PATH);
Jeff Johnson16528362018-06-14 12:34:16 -07005450
5451 mac_handle = hdd_ctx->mac_handle;
5452
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005453 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005454 case QDF_STA_MODE:
5455 case QDF_P2P_CLIENT_MODE:
5456 case QDF_IBSS_MODE:
5457 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005458 case QDF_NDI_MODE:
Dustin Brownd747ecd2018-10-26 16:32:22 -07005459 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
5460
5461 if (adapter->device_mode == QDF_NDI_MODE ||
5462 hdd_conn_is_connected(sta_ctx) ||
5463 hdd_is_connecting(sta_ctx)) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005464 INIT_COMPLETION(adapter->disconnect_comp_var);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005465
Jeff Johnson025618c2018-03-18 14:41:00 -07005466 roam_profile = hdd_roam_profile(adapter);
5467 /* For NDI do not use roam_profile */
Dustin Brownd747ecd2018-10-26 16:32:22 -07005468 if (adapter->device_mode == QDF_NDI_MODE)
5469 status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005470 mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08005471 adapter->vdev_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005472 eCSR_DISCONNECT_REASON_NDI_DELETE);
Jeff Johnson025618c2018-03-18 14:41:00 -07005473 else if (roam_profile->BSSType ==
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005474 eCSR_BSS_TYPE_START_IBSS)
Dustin Brownd747ecd2018-10-26 16:32:22 -07005475 status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005476 mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08005477 adapter->vdev_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005478 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Abhinav Kumar19a7a402018-07-12 17:36:57 +05305479 else if (adapter->device_mode == QDF_STA_MODE)
5480 wlan_hdd_disconnect(adapter,
5481 eCSR_DISCONNECT_REASON_DEAUTH);
5482 else
Dustin Brownd747ecd2018-10-26 16:32:22 -07005483 status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005484 mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08005485 adapter->vdev_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005486 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005487 /* success implies disconnect is queued */
5488 if (QDF_IS_STATUS_SUCCESS(status) &&
5489 adapter->device_mode != QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005490 rc = wait_for_completion_timeout(
5491 &adapter->disconnect_comp_var,
5492 msecs_to_jiffies
Abhishek Singhd1f21c72019-01-21 15:16:34 +05305493 (SME_DISCONNECT_TIMEOUT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005494 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005495 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005496 }
Dustin Brownd747ecd2018-10-26 16:32:22 -07005497 if (QDF_IS_STATUS_ERROR(status))
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005498 hdd_warn("failed to post disconnect");
Dustin Brownd747ecd2018-10-26 16:32:22 -07005499
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005500 memset(&wrqu, '\0', sizeof(wrqu));
5501 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5502 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5503 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
5504 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05305505 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005506
Dustin Brownd747ecd2018-10-26 16:32:22 -07005507 wlan_hdd_scan_abort(adapter);
Wu Gao4a1ec8c2018-07-23 19:18:40 +08005508 wlan_hdd_cleanup_actionframe(adapter);
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05305509 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05305510 hdd_clear_fils_connection_info(adapter);
Ashish Kumar Dhanotiya36510832019-02-20 22:13:25 +05305511
Liangwei Donga44d55b2019-03-20 03:22:08 -04005512 status = wlan_hdd_flush_pmksa_cache(adapter);
Ashish Kumar Dhanotiya36510832019-02-20 22:13:25 +05305513 if (QDF_IS_STATUS_ERROR(status))
5514 hdd_err("Cannot flush PMKIDCache");
5515
Visweswara Tanukub5a61242019-03-26 12:24:13 +05305516 hdd_deregister_hl_netdev_fc_timer(adapter);
5517
Dustin Brownd747ecd2018-10-26 16:32:22 -07005518 hdd_deregister_tx_flow_control(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005519
5520#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005521 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005522#ifdef WLAN_NS_OFFLOAD
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005523 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005524#endif
5525#endif
5526
Min Liu8c5d99e2018-09-10 17:18:44 +08005527 if (adapter->device_mode == QDF_STA_MODE) {
5528 struct wlan_objmgr_vdev *vdev;
5529
5530 vdev = hdd_objmgr_get_vdev(adapter);
5531 if (vdev) {
5532 wlan_cfg80211_sched_scan_stop(vdev);
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05305533 hdd_objmgr_put_vdev(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08005534 }
5535 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08005536
Pragaspathi Thilagaraje6f37e02019-01-04 12:24:33 +05305537 /*
5538 * During vdev destroy, if any STA is in connecting state the
5539 * roam command will be in active queue and thus vdev destroy is
5540 * queued in pending queue. In case STA tries to connect to
5541 * multiple BSSID and fails to connect, due to auth/assoc
5542 * timeouts it may take more than vdev destroy time to get
5543 * completed. On vdev destroy timeout vdev is moved to logically
5544 * deleted state. Once connection is completed, vdev destroy is
5545 * activated and to release the self-peer ref count it try to
5546 * get the ref of the vdev, which fails as vdev is logically
5547 * deleted and this leads to peer ref leak. So before vdev
5548 * destroy is queued abort any STA ongoing connection to avoid
5549 * vdev destroy timeout.
5550 */
5551 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags))
5552 hdd_abort_ongoing_sta_connection(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08005553
Himanshu Agarwalb229a142017-12-21 10:16:45 +05305554 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005555 break;
5556
Rajeev Kumar3b906202018-02-01 10:55:14 -08005557 case QDF_MONITOR_MODE:
5558 wlan_hdd_scan_abort(adapter);
Visweswara Tanukub5a61242019-03-26 12:24:13 +05305559 hdd_deregister_hl_netdev_fc_timer(adapter);
Rajeev Kumar3b906202018-02-01 10:55:14 -08005560 hdd_deregister_tx_flow_control(adapter);
5561 hdd_vdev_destroy(adapter);
5562 break;
5563
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005564 case QDF_SAP_MODE:
Will Huang7049bae2018-08-13 17:25:02 +08005565 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
5566 cds_flush_delayed_work(&adapter->acs_pending_work);
5567 clear_bit(ACS_PENDING, &adapter->event_flags);
5568 }
Dustin Brownd747ecd2018-10-26 16:32:22 -07005569
wadesongf9b15ed2017-12-14 14:12:32 +08005570 wlan_hdd_scan_abort(adapter);
gaurank kathpaliab7a9f702019-02-15 18:09:58 +05305571 /* Diassociate with all the peers before stop ap post */
5572 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags))
5573 wlan_hdd_del_station(adapter);
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05305574 sap_config = &adapter->session.ap.sap_config;
Dustin Brownd747ecd2018-10-26 16:32:22 -07005575 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
5576
Dustin Brown07901ec2018-09-07 11:02:41 -07005577 ucfg_ipa_flush(hdd_ctx->pdev);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005578
Dustin Brownb4260d52019-01-24 11:53:08 -08005579 /* don't flush pre-cac destroy if we are destroying pre-cac */
5580 sap_ctx = WLAN_HDD_GET_SAP_CTX_PTR(adapter);
5581 if (!wlan_sap_is_pre_cac_context(sap_ctx))
Liangwei Dongad89c762018-06-01 01:56:23 -04005582 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Dustin Brownb4260d52019-01-24 11:53:08 -08005583
Jeff Johnson46807cd2018-04-29 21:32:22 -07005584 /* fallthrough */
Dustin Browna5cf8e02017-10-19 16:04:19 -07005585
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005586 case QDF_P2P_GO_MODE:
Krunal Soni22208392017-09-29 18:10:34 -07005587 cds_flush_work(&adapter->sap_stop_bss_work);
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305588 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005589 wlan_hdd_undo_acs(adapter);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005590
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005591 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005592 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5593
Visweswara Tanukub5a61242019-03-26 12:24:13 +05305594 hdd_deregister_hl_netdev_fc_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005595 hdd_deregister_tx_flow_control(adapter);
Kapil Guptac1224bf2017-06-22 21:22:40 +05305596 hdd_destroy_acs_timer(adapter);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005597
Pragaspathi Thilagaraje6f37e02019-01-04 12:24:33 +05305598 /**
5599 * During vdev destroy, If any STA is in connecting state the
5600 * roam command will be in active queue and thus vdev destroy is
5601 * queued in pending queue. In case STA is tries to connected to
5602 * multiple BSSID and fails to connect, due to auth/assoc
5603 * timeouts it may take more than vdev destroy time to get
5604 * completes. If vdev destroy timeout vdev is moved to logically
5605 * deleted state. Once connection is completed, vdev destroy is
5606 * activated and to release the self-peer ref count it try to
5607 * get the ref of the vdev, which fails as vdev is logically
5608 * deleted and this leads to peer ref leak. So before vdev
5609 * destroy is queued abort any STA ongoing connection to avoid
5610 * vdev destroy timeout.
5611 */
5612 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags))
5613 hdd_abort_ongoing_sta_connection(hdd_ctx);
5614
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005615 mutex_lock(&hdd_ctx->sap_lock);
5616 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005617 status = wlansap_stop_bss(
5618 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005619
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305620 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07005621 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005622 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305623 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305624 qdf_stop_bss_event);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005625 status = qdf_wait_for_event_completion(
Nachiket Kukade0396b732017-11-14 16:35:16 +05305626 &hostapd_state->qdf_stop_bss_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +05305627 SME_CMD_STOP_BSS_TIMEOUT);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005628 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson5880d792016-08-15 13:32:30 -07005629 hdd_err("failure waiting for wlansap_stop_bss %d",
Dustin Brownd747ecd2018-10-26 16:32:22 -07005630 status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005631 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07005632 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005633 }
Dustin Brownd747ecd2018-10-26 16:32:22 -07005634
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005635 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -07005636 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005637 adapter->device_mode,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08005638 adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005639 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305640 adapter->device_mode,
5641 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005642
Jeff Johnsonc565af12019-03-10 21:09:47 -07005643 qdf_copy_macaddr(&update_ie.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07005644 &adapter->mac_addr);
Jeff Johnsonc565af12019-03-10 21:09:47 -07005645 update_ie.smeSessionId = adapter->vdev_id;
5646 update_ie.ieBufferlength = 0;
5647 update_ie.pAdditionIEBuffer = NULL;
5648 update_ie.append = false;
5649 update_ie.notify = false;
Dustin Brownd747ecd2018-10-26 16:32:22 -07005650
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005651 /* Probe bcn reset */
Jeff Johnsonc565af12019-03-10 21:09:47 -07005652 status = sme_update_add_ie(mac_handle, &update_ie,
Dustin Brownd747ecd2018-10-26 16:32:22 -07005653 eUPDATE_IE_PROBE_BCN);
5654 if (status == QDF_STATUS_E_FAILURE)
5655 hdd_err("Could not pass PROBE_RSP_BCN to PE");
5656
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005657 /* Assoc resp reset */
Jeff Johnsonc565af12019-03-10 21:09:47 -07005658 status = sme_update_add_ie(mac_handle, &update_ie,
Dustin Brownd747ecd2018-10-26 16:32:22 -07005659 eUPDATE_IE_ASSOC_RESP);
5660 if (status == QDF_STATUS_E_FAILURE)
5661 hdd_err("Could not pass ASSOC_RSP to PE");
5662
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005663 /* Reset WNI_CFG_PROBE_RSP Flags */
5664 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005665 }
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005666 clear_bit(SOFTAP_INIT_DONE, &adapter->event_flags);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005667 qdf_mem_free(adapter->session.ap.beacon);
5668 adapter->session.ap.beacon = NULL;
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005669
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305670 /*
5671 * If Do_Not_Break_Stream was enabled clear avoid channel list.
5672 */
Min Liu8c5d99e2018-09-10 17:18:44 +08005673 vdev = hdd_objmgr_get_vdev(adapter);
5674 if (vdev) {
5675 if (policy_mgr_is_dnsc_set(vdev))
5676 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05305677 hdd_objmgr_put_vdev(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08005678 }
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305679
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305680#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005681 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305682#ifdef WLAN_NS_OFFLOAD
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005683 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305684#endif
5685#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08005686
5687 hdd_vdev_destroy(adapter);
5688
Krunal Sonib51eec72017-11-20 21:53:01 -08005689 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005690 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005691 case QDF_OCB_MODE:
Dustin Brownd747ecd2018-10-26 16:32:22 -07005692 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08005693 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Dustin Brownd747ecd2018-10-26 16:32:22 -07005694 cds_get_context(QDF_MODULE_ID_TXRX),
Jeff Johnson0a082d92019-03-04 12:25:49 -08005695 sta_ctx->conn_info.sta_id[0]);
Visweswara Tanukub5a61242019-03-26 12:24:13 +05305696 hdd_deregister_hl_netdev_fc_timer(adapter);
Zhang Qian79d0d132018-02-05 13:40:16 +08005697 hdd_deregister_tx_flow_control(adapter);
5698 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005699 break;
5700 default:
5701 break;
5702 }
5703
Dustin Brown04348372017-12-14 16:13:39 -08005704 if (adapter->scan_info.default_scan_ies) {
5705 qdf_mem_free(adapter->scan_info.default_scan_ies);
5706 adapter->scan_info.default_scan_ies = NULL;
5707 }
5708
Dustin Browne74003f2018-03-14 12:51:58 -07005709 hdd_exit();
Dustin Brownd747ecd2018-10-26 16:32:22 -07005710
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305711 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005712}
5713
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305714/**
5715 * hdd_deinit_all_adapters - deinit all adapters
5716 * @hdd_ctx: HDD context
5717 * @rtnl_held: True if RTNL lock held
5718 *
5719 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005720void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305721{
Jeff Johnson9d295242017-08-29 14:39:48 -07005722 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305723
Dustin Brown491d54b2018-03-14 12:39:11 -07005724 hdd_enter();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305725
Dustin Brown920397d2017-12-13 16:27:50 -08005726 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305727 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305728
Dustin Browne74003f2018-03-14 12:51:58 -07005729 hdd_exit();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305730}
5731
Dustin Browndb2a8be2017-12-20 11:49:56 -08005732QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005733{
Jeff Johnson9d295242017-08-29 14:39:48 -07005734 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005735
Dustin Brown491d54b2018-03-14 12:39:11 -07005736 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005737
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305738 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5739
Dustin Brown920397d2017-12-13 16:27:50 -08005740 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08005741 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005742
Dustin Browne74003f2018-03-14 12:51:58 -07005743 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005744
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305745 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005746}
5747
Paul Zhang84fa9382017-11-10 21:18:21 +08005748static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
5749 struct hdd_adapter *adapter)
5750{
5751 switch (adapter->device_mode) {
5752 case QDF_STA_MODE:
5753 case QDF_P2P_CLIENT_MODE:
5754 case QDF_IBSS_MODE:
5755 case QDF_P2P_DEVICE_MODE:
5756 case QDF_NDI_MODE:
5757 wlan_hdd_scan_abort(adapter);
5758 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Min Liu8c5d99e2018-09-10 17:18:44 +08005759 if (adapter->device_mode == QDF_STA_MODE) {
5760 struct wlan_objmgr_vdev *vdev;
5761
5762 vdev = hdd_objmgr_get_vdev(adapter);
5763 if (vdev) {
5764 wlan_cfg80211_sched_scan_stop(vdev);
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05305765 hdd_objmgr_put_vdev(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08005766 }
5767 }
Paul Zhang84fa9382017-11-10 21:18:21 +08005768 break;
5769 case QDF_P2P_GO_MODE:
5770 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5771 break;
5772 case QDF_SAP_MODE:
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305773 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Paul Zhang84fa9382017-11-10 21:18:21 +08005774 wlan_hdd_undo_acs(adapter);
5775 break;
5776 default:
5777 break;
5778 }
5779}
5780
Ke Huangc067b8d2018-05-21 15:50:13 +08005781#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
5782/**
5783 * hdd_adapter_abort_tx_flow() - Abort the tx flow control
5784 * @pAdapter: pointer to hdd_adapter_t
5785 *
5786 * Resume tx and stop the tx flow control timer if the tx is paused
5787 * and the flow control timer is running. This function is called by
5788 * SSR to avoid the inconsistency of tx status before and after SSR.
5789 *
5790 * Return: void
5791 */
5792static void hdd_adapter_abort_tx_flow(struct hdd_adapter *adapter)
5793{
5794 if (adapter->hdd_stats.tx_rx_stats.is_txflow_paused &&
5795 QDF_TIMER_STATE_RUNNING ==
5796 qdf_mc_timer_get_current_state(
5797 &adapter->tx_flow_control_timer)) {
5798 hdd_tx_resume_timer_expired_handler(adapter);
5799 qdf_mc_timer_stop(&adapter->tx_flow_control_timer);
5800 }
5801}
5802#endif
5803
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005804QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005805{
Jeff Johnson9d295242017-08-29 14:39:48 -07005806 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07005807 struct hdd_station_ctx *sta_ctx;
Jeff Johnson2d044612019-02-26 20:08:43 -08005808 struct qdf_mac_addr peer_macaddr;
Yue Ma42654682018-01-11 16:55:24 -08005809 int sta_id;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05305810 bool value;
Min Liu8c5d99e2018-09-10 17:18:44 +08005811 struct wlan_objmgr_vdev *vdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005812
Dustin Brown491d54b2018-03-14 12:39:11 -07005813 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005814
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305815 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5816
Dustin Brown920397d2017-12-13 16:27:50 -08005817 hdd_for_each_adapter(hdd_ctx, adapter) {
Dustin Brown5e89ef82018-03-14 11:50:23 -07005818 hdd_info("[SSR] reset adapter with device mode %s(%d)",
Dustin Brown458027c2018-10-19 12:26:27 -07005819 qdf_opmode_str(adapter->device_mode),
Dustin Brown5e89ef82018-03-14 11:50:23 -07005820 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305821
Ke Huangc067b8d2018-05-21 15:50:13 +08005822#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
5823 hdd_adapter_abort_tx_flow(adapter);
5824#endif
5825
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305826 if ((adapter->device_mode == QDF_STA_MODE) ||
Paul Zhang679025e2018-03-08 22:39:44 +08005827 (adapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305828 /* Stop tdls timers */
Min Liu8c5d99e2018-09-10 17:18:44 +08005829 vdev = hdd_objmgr_get_vdev(adapter);
5830 if (vdev) {
5831 hdd_notify_tdls_reset_adapter(vdev);
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05305832 hdd_objmgr_put_vdev(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08005833 }
Paul Zhang679025e2018-03-08 22:39:44 +08005834 adapter->session.station.hdd_reassoc_scenario = false;
5835 }
Dustin Brown05d81302018-09-11 16:49:22 -07005836 ucfg_mlme_get_sap_internal_restart(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05305837 if (value &&
Arun Khandavallicc544b32017-01-30 19:52:16 +05305838 adapter->device_mode == QDF_SAP_MODE) {
5839 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305840 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05305841 WLAN_CONTROL_PATH);
Ashish Kumar Dhanotiyadc3900f2019-01-11 20:42:04 +05305842 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
5843 cds_flush_delayed_work(
5844 &adapter->acs_pending_work);
5845 clear_bit(ACS_PENDING, &adapter->event_flags);
5846 }
5847
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005848 if (test_bit(SOFTAP_BSS_STARTED,
Ashish Kumar Dhanotiyadc3900f2019-01-11 20:42:04 +05305849 &adapter->event_flags)) {
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005850 hdd_sap_indicate_disconnect_for_sta(adapter);
Ashish Kumar Dhanotiyadc3900f2019-01-11 20:42:04 +05305851 clear_bit(SOFTAP_BSS_STARTED,
5852 &adapter->event_flags);
5853 }
5854
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005855 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305856 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305857 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005858 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005859 }
Nijun Gong104ccc72018-08-07 10:43:56 +08005860 /*
5861 * Clear fc flag if it was set before SSR to avoid TX queues
5862 * permanently stopped after SSR.
5863 * Here WLAN_START_ALL_NETIF_QUEUE will actually not start any
5864 * queue since it's blocked by reason WLAN_CONTROL_PATH.
5865 */
5866 if (adapter->pause_map & (1 << WLAN_DATA_FLOW_CONTROL))
5867 wlan_hdd_netif_queue_control(adapter,
5868 WLAN_START_ALL_NETIF_QUEUE,
5869 WLAN_DATA_FLOW_CONTROL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005870
Paul Zhang84fa9382017-11-10 21:18:21 +08005871 hdd_reset_scan_operation(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005872
5873 hdd_deinit_tx_rx(adapter);
Dustin Brown1dbefe62018-09-11 16:32:03 -07005874 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08005875 adapter->device_mode, adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005876 hdd_green_ap_start_state_mc(hdd_ctx, adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305877 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005878 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5879 hdd_wmm_adapter_close(adapter);
5880 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5881 }
5882
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305883 if (adapter->device_mode == QDF_STA_MODE)
5884 hdd_clear_fils_connection_info(adapter);
5885
Wu Gao3545e642017-07-14 19:24:41 +08005886 if (adapter->device_mode == QDF_SAP_MODE) {
Jingxiang Geec113592018-08-09 15:40:39 +08005887 wlansap_cleanup_cac_timer(
5888 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Wu Gao3545e642017-07-14 19:24:41 +08005889 /*
5890 * If adapter is SAP, set session ID to invalid
5891 * since SAP session will be cleanup during SSR.
5892 */
Wu Gao36717432016-11-21 15:09:48 +08005893 wlansap_set_invalid_session(
5894 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Wu Gao3545e642017-07-14 19:24:41 +08005895 }
5896
Abhishek Singh8f4aa182019-03-06 10:29:24 +05305897 /* Release vdev ref count to avoid vdev object leak */
5898 if (adapter->device_mode == QDF_P2P_GO_MODE ||
5899 adapter->device_mode == QDF_SAP_MODE)
5900 wlansap_release_vdev_ref(
5901 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5902
Yue Ma42654682018-01-11 16:55:24 -08005903 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005904 if (adapter->device_mode == QDF_STA_MODE ||
5905 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005906 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnson2d044612019-02-26 20:08:43 -08005907 qdf_copy_macaddr(&peer_macaddr,
Jeff Johnsone04b6992019-02-27 14:06:55 -08005908 &sta_ctx->conn_info.bssid);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005909
Yue Ma42654682018-01-11 16:55:24 -08005910 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
Wu Gao6b81fc52018-05-24 19:27:27 +08005911 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Yue Ma42654682018-01-11 16:55:24 -08005912 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5913 if (adapter->sta_info[sta_id].in_use) {
5914 hdd_debug("[SSR] deregister STA with ID %d",
5915 sta_id);
5916 hdd_softap_deregister_sta(adapter,
5917 sta_id);
5918 adapter->sta_info[sta_id].in_use = 0;
5919 }
5920 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005921 }
5922
Alok Kumarb64650c2018-03-23 17:05:11 +05305923 hdd_nud_ignore_tracking(adapter, true);
Alok Kumar016a1ac2018-09-16 09:55:50 +05305924 hdd_nud_reset_tracking(adapter);
5925 hdd_nud_flush_work(adapter);
Ashish Kumar Dhanotiyadc3900f2019-01-11 20:42:04 +05305926
5927 if (adapter->device_mode != QDF_SAP_MODE &&
5928 adapter->device_mode != QDF_P2P_GO_MODE &&
5929 adapter->device_mode != QDF_FTM_MODE)
5930 hdd_set_disconnect_status(adapter, false);
5931
hangtian9c47aaf2018-11-26 17:59:39 +08005932 hdd_stop_tsf_sync(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05305933
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005934 hdd_softap_deinit_tx_rx(adapter);
Visweswara Tanukub5a61242019-03-26 12:24:13 +05305935 hdd_deregister_hl_netdev_fc_timer(adapter);
Tiger Yu8c387702018-07-06 16:56:42 +08005936 hdd_deregister_tx_flow_control(adapter);
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005937
Yue Maf9782842017-05-08 12:49:49 -07005938 /* Destroy vdev which will be recreated during reinit. */
5939 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005940 }
5941
Dustin Browne74003f2018-03-14 12:51:58 -07005942 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005943
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305944 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005945}
5946
Dustin Brown4c663222018-10-23 14:19:36 -07005947bool hdd_is_any_interface_open(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305948{
Dustin Brown920397d2017-12-13 16:27:50 -08005949 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305950
Dustin Brown4c663222018-10-23 14:19:36 -07005951 if (hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) {
Arun Khandavalliba479c42017-07-26 21:29:40 +05305952 hdd_info("FTM mode, don't close the module");
Dustin Brown4c663222018-10-23 14:19:36 -07005953 return true;
Arun Khandavalliba479c42017-07-26 21:29:40 +05305954 }
5955
Dustin Brown920397d2017-12-13 16:27:50 -08005956 hdd_for_each_adapter(hdd_ctx, adapter) {
5957 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
Dustin Brown4c663222018-10-23 14:19:36 -07005958 test_bit(SME_SESSION_OPENED, &adapter->event_flags))
5959 return true;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305960 }
5961
Dustin Brown4c663222018-10-23 14:19:36 -07005962 return false;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305963}
5964
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305965bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305966{
5967 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5968 return true;
5969 else
5970 return false;
5971}
5972
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305973#if defined CFG80211_CONNECT_BSS || \
5974 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305975#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305976 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305977/**
5978 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5979 * @timeout_reason: reason for connect timeout
5980 *
5981 * This function is used to convert host timeout
5982 * reason enum to kernel specific enum.
5983 *
5984 * Return: nl timeout enum
5985 */
5986static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5987 tSirResultCodes timeout_reason)
5988{
5989 switch (timeout_reason) {
5990 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5991 return NL80211_TIMEOUT_SCAN;
5992 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5993 return NL80211_TIMEOUT_AUTH;
5994 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5995 return NL80211_TIMEOUT_ASSOC;
5996 default:
5997 return NL80211_TIMEOUT_UNSPECIFIED;
5998 }
5999}
6000
6001/**
6002 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
6003 * @dev: network device
6004 * @bssid: bssid to which we want to associate
6005 * @timeout_reason: reason for connect timeout
6006 *
6007 * This API is used to send connection timeout reason to supplicant
6008 *
6009 * Return: void
6010 */
6011static void hdd_cfg80211_connect_timeout(struct net_device *dev,
6012 const u8 *bssid,
6013 tSirResultCodes timeout_reason)
6014{
6015 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006016
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306017 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
6018
6019 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
6020 nl_timeout_reason);
6021}
6022
6023/**
6024 * __hdd_connect_bss() - API to send connection status to supplicant
6025 * @dev: network device
6026 * @bssid: bssid to which we want to associate
6027 * @req_ie: Request Information Element
6028 * @req_ie_len: len of the req IE
6029 * @resp_ie: Response IE
6030 * @resp_ie_len: len of ht response IE
6031 * @status: status
6032 * @gfp: Kernel Flag
6033 * @timeout_reason: reason for connect timeout
6034 *
6035 * Return: void
6036 */
6037static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
6038 struct cfg80211_bss *bss, const u8 *req_ie,
6039 size_t req_ie_len, const u8 *resp_ie,
6040 size_t resp_ie_len, int status, gfp_t gfp,
6041 tSirResultCodes timeout_reason)
6042{
6043 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006044
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306045 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
6046
6047 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
6048 resp_ie, resp_ie_len, status, gfp,
6049 nl_timeout_reason);
6050}
6051#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306052#if defined CFG80211_CONNECT_TIMEOUT || \
6053 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306054static void hdd_cfg80211_connect_timeout(struct net_device *dev,
6055 const u8 *bssid,
6056 tSirResultCodes timeout_reason)
6057{
6058 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
6059}
6060#endif
6061
6062static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
6063 struct cfg80211_bss *bss, const u8 *req_ie,
6064 size_t req_ie_len, const u8 *resp_ie,
6065 size_t resp_ie_len, int status, gfp_t gfp,
6066 tSirResultCodes timeout_reason)
6067{
6068 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
6069 resp_ie, resp_ie_len, status, gfp);
6070}
6071#endif
6072
Abhishek Singha84d3952016-09-13 13:45:05 +05306073/**
6074 * hdd_connect_bss() - API to send connection status to supplicant
6075 * @dev: network device
6076 * @bssid: bssid to which we want to associate
6077 * @req_ie: Request Information Element
6078 * @req_ie_len: len of the req IE
6079 * @resp_ie: Response IE
6080 * @resp_ie_len: len of ht response IE
6081 * @status: status
6082 * @gfp: Kernel Flag
6083 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306084 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05306085 *
6086 * The API is a wrapper to send connection status to supplicant
6087 *
6088 * Return: Void
6089 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306090#if defined CFG80211_CONNECT_TIMEOUT || \
6091 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05306092static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
6093 struct cfg80211_bss *bss, const u8 *req_ie,
6094 size_t req_ie_len, const u8 *resp_ie,
6095 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306096 bool connect_timeout,
6097 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05306098{
6099 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306100 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05306101 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306102 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
6103 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05306104}
6105#else
6106static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
6107 struct cfg80211_bss *bss, const u8 *req_ie,
6108 size_t req_ie_len, const u8 *resp_ie,
6109 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306110 bool connect_timeout,
6111 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05306112{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306113 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
6114 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05306115}
6116#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05306117
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306118#if defined(WLAN_FEATURE_FILS_SK)
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306119#if (defined(CFG80211_CONNECT_DONE) || \
6120 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))) && \
6121 (LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0))
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306122#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
6123 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306124/**
6125 * hdd_populate_fils_params() - Populate FILS keys to connect response
6126 * @fils_params: connect response to supplicant
6127 * @fils_kek: FILS kek
6128 * @fils_kek_len: FILS kek length
6129 * @pmk: FILS PMK
6130 * @pmk_len: FILS PMK length
6131 * @pmkid: PMKID
6132 * @fils_seq_num: FILS Seq number
6133 *
6134 * Return: None
6135 */
6136static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
6137 *fils_params, const uint8_t *fils_kek,
6138 size_t fils_kek_len, const uint8_t *pmk,
6139 size_t pmk_len, const uint8_t *pmkid,
6140 uint16_t fils_seq_num)
6141{
6142 /* Increament seq number to be used for next FILS */
6143 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
6144 fils_params->update_erp_next_seq_num = true;
6145 fils_params->fils_kek = fils_kek;
6146 fils_params->fils_kek_len = fils_kek_len;
6147 fils_params->pmk = pmk;
6148 fils_params->pmk_len = pmk_len;
6149 fils_params->pmkid = pmkid;
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306150 hdd_debug("FILS erp_next_seq_num:%d",
6151 fils_params->fils_erp_next_seq_num);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306152}
6153#else
6154static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
6155 *fils_params, const uint8_t
6156 *fils_kek, size_t fils_kek_len,
6157 const uint8_t *pmk, size_t pmk_len,
6158 const uint8_t *pmkid,
6159 uint16_t fils_seq_num)
6160{ }
6161#endif
6162
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306163#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0))
6164/**
6165 * hdd_populate_fils_params() - Populate FILS keys to connect response
6166 * @fils_params: connect response to supplicant
6167 * @fils_kek: FILS kek
6168 * @fils_kek_len: FILS kek length
6169 * @pmk: FILS PMK
6170 * @pmk_len: FILS PMK length
6171 * @pmkid: PMKID
6172 * @fils_seq_num: FILS Seq number
6173 *
6174 * Return: None
6175 */
6176static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
6177 *fils_params, const uint8_t *fils_kek,
6178 size_t fils_kek_len, const uint8_t *pmk,
6179 size_t pmk_len, const uint8_t *pmkid,
6180 uint16_t fils_seq_num)
6181{
6182 /* Increament seq number to be used for next FILS */
6183 fils_params->fils.erp_next_seq_num = fils_seq_num + 1;
6184 fils_params->fils.update_erp_next_seq_num = true;
6185 fils_params->fils.kek = fils_kek;
6186 fils_params->fils.kek_len = fils_kek_len;
6187 fils_params->fils.pmk = pmk;
6188 fils_params->fils.pmk_len = pmk_len;
6189 fils_params->fils.pmkid = pmkid;
6190 hdd_debug("FILS erp_next_seq_num:%d",
6191 fils_params->fils.erp_next_seq_num);
6192}
6193#endif /* CFG80211_CONNECT_DONE */
6194
6195#if defined(CFG80211_CONNECT_DONE) || \
6196 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
6197
Jeff Johnson172237b2017-11-07 15:32:59 -08006198void hdd_update_hlp_info(struct net_device *dev,
6199 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306200{
6201 struct sk_buff *skb;
6202 uint16_t skb_len;
6203 struct llc_snap_hdr_t *llc_hdr;
6204 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306205 uint8_t *hlp_data;
6206 uint16_t hlp_data_len;
6207 struct fils_join_rsp_params *roam_fils_params
6208 = roam_info->fils_join_rsp;
Jeff Johnsona1382382019-03-31 11:08:27 -07006209 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306210
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306211 if (!roam_fils_params) {
6212 hdd_err("FILS Roam Param NULL");
6213 return;
6214 }
6215
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08006216 if (!roam_fils_params->hlp_data_len) {
Jianmin Zhucc6b3d02019-03-07 14:19:34 +08006217 hdd_debug("FILS HLP Data NULL, len %d",
6218 roam_fils_params->hlp_data_len);
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306219 return;
6220 }
6221
6222 hlp_data = roam_fils_params->hlp_data;
6223 hlp_data_len = roam_fils_params->hlp_data_len;
6224
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306225 /* Calculate skb length */
6226 skb_len = (2 * ETH_ALEN) + hlp_data_len;
6227 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
Jeff Johnsond36fa332019-03-18 13:42:25 -07006228 if (!skb) {
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306229 hdd_err("HLP packet nbuf alloc fails");
6230 return;
6231 }
6232
6233 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
6234 QDF_MAC_ADDR_SIZE);
6235 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
6236 QDF_MAC_ADDR_SIZE);
6237
6238 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
6239 if (IS_SNAP(llc_hdr)) {
6240 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
6241 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
6242 }
6243
6244 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
6245
6246 /*
6247 * This HLP packet is formed from HLP info encapsulated
6248 * in assoc response frame which is AEAD encrypted.
6249 * Hence, this checksum validation can be set unnecessary.
6250 * i.e. network layer need not worry about checksum.
6251 */
6252 skb->ip_summed = CHECKSUM_UNNECESSARY;
6253
Jeff Johnsona1382382019-03-31 11:08:27 -07006254 status = hdd_rx_packet_cbk(adapter, skb);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306255 if (QDF_IS_STATUS_ERROR(status)) {
6256 hdd_err("Sending HLP packet fails");
6257 return;
6258 }
6259 hdd_debug("send HLP packet to netif successfully");
6260}
6261
6262/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306263 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
6264 * @dev: network device
6265 * @bssid: bssid to which we want to associate
6266 * @bss: cfg80211 bss info
6267 * @roam_info: information about connected bss
6268 * @req_ie: Request Information Element
6269 * @req_ie_len: len of the req IE
6270 * @resp_ie: Response IE
6271 * @resp_ie_len: len of ht response IE
6272 * @status: status
6273 * @gfp: allocation flags
6274 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
6275 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306276 *
6277 * This API is used as wrapper to send FILS key/sequence number
6278 * params etc. to supplicant in case of FILS connection
6279 *
6280 * Return: None
6281 */
6282static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006283 struct cfg80211_bss *bss,
6284 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306285 const u8 *req_ie, size_t req_ie_len,
6286 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006287 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306288 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306289{
6290 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306291 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
6292 struct fils_join_rsp_params *roam_fils_params =
6293 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006294
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306295 qdf_mem_zero(&fils_params, sizeof(fils_params));
6296
6297 if (!roam_fils_params) {
6298 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
6299 } else {
6300 fils_params.status = status;
6301 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08006302 fils_params.timeout_reason =
6303 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306304 fils_params.req_ie = req_ie;
6305 fils_params.req_ie_len = req_ie_len;
6306 fils_params.resp_ie = resp_ie;
6307 fils_params.resp_ie_len = resp_ie_len;
6308 fils_params.bss = bss;
6309 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
6310 roam_fils_params->kek_len,
6311 roam_fils_params->fils_pmk,
6312 roam_fils_params->fils_pmk_len,
6313 roam_fils_params->fils_pmkid,
6314 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05306315 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306316 }
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306317 hdd_debug("FILS indicate connect status %d", fils_params.status);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306318
6319 cfg80211_connect_done(dev, &fils_params, gfp);
6320
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306321 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306322 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306323
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306324 /* Clear all the FILS key info */
6325 if (roam_fils_params && roam_fils_params->fils_pmk)
6326 qdf_mem_free(roam_fils_params->fils_pmk);
6327 if (roam_fils_params)
6328 qdf_mem_free(roam_fils_params);
6329 roam_info->fils_join_rsp = NULL;
6330}
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306331#else /* CFG80211_CONNECT_DONE */
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006332static inline void
6333hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006334 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006335 const u8 *req_ie, size_t req_ie_len,
6336 const u8 *resp_ie, size_t resp_ie_len, u16 status,
6337 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306338 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306339{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306340#endif
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306341#endif /* WLAN_FEATURE_FILS_SK */
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306342
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306343#if defined(WLAN_FEATURE_FILS_SK) && \
6344 (defined(CFG80211_CONNECT_DONE) || \
6345 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306346/**
6347 * hdd_fils_update_connect_results() - API to send fils connection status to
6348 * supplicant.
6349 * @dev: network device
6350 * @bssid: bssid to which we want to associate
6351 * @bss: cfg80211 bss info
6352 * @roam_info: information about connected bss
6353 * @req_ie: Request Information Element
6354 * @req_ie_len: len of the req IE
6355 * @resp_ie: Response IE
6356 * @resp_ie_len: len of ht response IE
6357 * @status: status
6358 * @gfp: allocation flags
6359 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
6360 * @timeout_reason: reason for connect timeout
6361 *
6362 * The API is a wrapper to send connection status to supplicant
6363 *
6364 * Return: 0 if success else failure
6365 */
6366static int hdd_fils_update_connect_results(struct net_device *dev,
6367 const u8 *bssid,
6368 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08006369 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306370 size_t req_ie_len, const u8 *resp_ie,
6371 size_t resp_ie_len, u16 status, gfp_t gfp,
6372 bool connect_timeout,
6373 tSirResultCodes timeout_reason)
6374{
Dustin Brown491d54b2018-03-14 12:39:11 -07006375 hdd_enter();
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306376 if (!roam_info || !roam_info->is_fils_connection)
6377 return -EINVAL;
6378
6379 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
6380 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306381 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306382 return 0;
6383}
6384#else
6385static inline int hdd_fils_update_connect_results(struct net_device *dev,
6386 const u8 *bssid,
6387 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08006388 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306389 size_t req_ie_len, const u8 *resp_ie,
6390 size_t resp_ie_len, u16 status, gfp_t gfp,
6391 bool connect_timeout,
6392 tSirResultCodes timeout_reason)
6393{
6394 return -EINVAL;
6395}
6396#endif
6397
Anurag Chouhanc4092922016-09-08 15:56:11 +05306398/**
6399 * hdd_connect_result() - API to send connection status to supplicant
6400 * @dev: network device
6401 * @bssid: bssid to which we want to associate
6402 * @roam_info: information about connected bss
6403 * @req_ie: Request Information Element
6404 * @req_ie_len: len of the req IE
6405 * @resp_ie: Response IE
6406 * @resp_ie_len: len of ht response IE
6407 * @status: status
6408 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05306409 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306410 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05306411 *
6412 * The API is a wrapper to send connection status to supplicant
6413 * and allow runtime suspend
6414 *
6415 * Return: Void
6416 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306417void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006418 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05306419 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05306420 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306421 bool connect_timeout,
6422 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05306423{
Jeff Johnsona1382382019-03-31 11:08:27 -07006424 struct hdd_adapter *adapter = netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306425 struct cfg80211_bss *bss = NULL;
Jeff Johnsona1382382019-03-31 11:08:27 -07006426 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306427
6428 if (WLAN_STATUS_SUCCESS == status) {
6429 struct ieee80211_channel *chan;
6430 int freq;
6431 int chan_no = roam_info->pBssDesc->channelId;
6432
6433 if (chan_no <= 14)
6434 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07006435 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306436 else
6437 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07006438 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306439
Jeff Johnsona1382382019-03-31 11:08:27 -07006440 chan = ieee80211_get_channel(adapter->wdev.wiphy, freq);
6441 bss = wlan_cfg80211_get_bss(adapter->wdev.wiphy, chan, bssid,
Anurag Chouhanc4092922016-09-08 15:56:11 +05306442 roam_info->u.pConnectedProfile->SSID.ssId,
6443 roam_info->u.pConnectedProfile->SSID.length);
6444 }
Komal Seelama89be8d2016-09-29 11:09:26 +05306445
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306446 if (hdd_fils_update_connect_results(dev, bssid, bss,
6447 roam_info, req_ie, req_ie_len, resp_ie,
6448 resp_ie_len, status, gfp, connect_timeout,
6449 timeout_reason) != 0) {
6450 hdd_connect_bss(dev, bssid, bss, req_ie,
6451 req_ie_len, resp_ie, resp_ie_len,
6452 status, gfp, connect_timeout, timeout_reason);
6453 }
Komal Seelama89be8d2016-09-29 11:09:26 +05306454
Jingxiang Geb49aa302018-01-17 20:54:15 +08006455 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07006456 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306457}
6458#else
6459void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006460 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05306461 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05306462 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306463 bool connect_timeout,
6464 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05306465{
Jeff Johnsona1382382019-03-31 11:08:27 -07006466 struct hdd_adapter *adapter = netdev_priv(dev);
6467 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05306468
Anurag Chouhanc4092922016-09-08 15:56:11 +05306469 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
6470 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08006471
Jingxiang Geb49aa302018-01-17 20:54:15 +08006472 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07006473 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306474}
6475#endif
6476
Nirav Shah73713f72018-05-17 14:50:41 +05306477#ifdef FEATURE_MONITOR_MODE_SUPPORT
Jeff Johnsond9952752018-04-18 12:15:35 -07006478int wlan_hdd_set_mon_chan(struct hdd_adapter *adapter, uint32_t chan,
6479 uint32_t bandwidth)
6480{
6481 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6482 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
6483 struct hdd_mon_set_ch_info *ch_info = &sta_ctx->ch_info;
6484 QDF_STATUS status;
Jeff Johnson43837af2018-10-17 12:44:05 -07006485 mac_handle_t mac_handle = hdd_ctx->mac_handle;
Jeff Johnsond9952752018-04-18 12:15:35 -07006486 struct qdf_mac_addr bssid;
6487 struct csr_roam_profile roam_profile;
6488 struct ch_params ch_params;
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006489 eConnectionState connstate;
Jeff Johnsond9952752018-04-18 12:15:35 -07006490
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006491 if (hdd_get_conparam() != QDF_GLOBAL_MONITOR_MODE &&
6492 adapter->device_mode != QDF_STA_MODE) {
6493 hdd_err("Not supported, device is not in monitor mode or sta mission mode");
Jeff Johnsond9952752018-04-18 12:15:35 -07006494 return -EINVAL;
6495 }
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006496 if (adapter->device_mode == QDF_STA_MODE &&
Pragaspathi Thilagaraja8893752019-02-06 19:58:59 +05306497 ucfg_mlme_is_change_channel_bandwidth_enabled(hdd_ctx->psoc)) {
Jeff Johnsone7951512019-02-27 10:02:51 -08006498 connstate = sta_ctx->conn_info.conn_state;
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006499 if (eConnectionState_Associated == connstate ||
6500 eConnectionState_Connecting == connstate) {
6501 return -EINVAL;
6502 }
6503 }
Jeff Johnsond9952752018-04-18 12:15:35 -07006504
Visweswara Tanuku006313a2018-04-12 12:26:34 +05306505 /* Validate Channel */
6506 if (!WLAN_REG_IS_24GHZ_CH(chan) && !WLAN_REG_IS_5GHZ_CH(chan)) {
6507 hdd_err("Channel %d Not supported", chan);
6508 return -EINVAL;
6509 }
6510
6511 if (WLAN_REG_IS_24GHZ_CH(chan)) {
6512 if (bandwidth == CH_WIDTH_80MHZ) {
6513 hdd_err("BW80 not possible in 2.4GHz band");
6514 return -EINVAL;
6515 }
6516 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 14) &&
6517 (bandwidth != CH_WIDTH_MAX)) {
6518 hdd_err("Only BW20 possible on channel 14");
6519 return -EINVAL;
6520 }
6521 }
6522
6523 if (WLAN_REG_IS_5GHZ_CH(chan)) {
6524 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 165) &&
6525 (bandwidth != CH_WIDTH_MAX)) {
6526 hdd_err("Only BW20 possible on channel 165");
6527 return -EINVAL;
6528 }
6529 }
6530
Jeff Johnsond9952752018-04-18 12:15:35 -07006531 hdd_debug("Set monitor mode Channel %d", chan);
6532 qdf_mem_zero(&roam_profile, sizeof(roam_profile));
6533 roam_profile.ChannelInfo.ChannelList = &ch_info->channel;
6534 roam_profile.ChannelInfo.numOfChannels = 1;
6535 roam_profile.phyMode = ch_info->phy_mode;
6536 roam_profile.ch_params.ch_width = bandwidth;
6537 hdd_select_cbmode(adapter, chan, &roam_profile.ch_params);
Pragaspathi Thilagaraja8893752019-02-06 19:58:59 +05306538 if (ucfg_mlme_is_change_channel_bandwidth_enabled(hdd_ctx->psoc) &&
Jeff Johnson43837af2018-10-17 12:44:05 -07006539 (!sme_find_session_by_bssid(mac_handle, adapter->mac_addr.bytes))) {
6540 status = sme_create_mon_session(mac_handle,
Rajeev Kumar Sirasanagandlae3b59912018-08-24 15:53:31 +05306541 adapter->mac_addr.bytes,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08006542 adapter->vdev_id);
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006543 if (status != QDF_STATUS_SUCCESS) {
6544 hdd_err("Status: %d Failed to create session.",
6545 status);
6546 return qdf_status_to_os_return(status);
6547 }
6548 }
Jeff Johnsond9952752018-04-18 12:15:35 -07006549 qdf_mem_copy(bssid.bytes, adapter->mac_addr.bytes,
6550 QDF_MAC_ADDR_SIZE);
6551
6552 ch_params.ch_width = bandwidth;
Dustin Brown07901ec2018-09-07 11:02:41 -07006553 wlan_reg_set_channel_params(hdd_ctx->pdev, chan, 0, &ch_params);
Jeff Johnsond9952752018-04-18 12:15:35 -07006554 if (ch_params.ch_width == CH_WIDTH_INVALID) {
6555 hdd_err("Invalid capture channel or bandwidth for a country");
6556 return -EINVAL;
6557 }
6558 if (wlan_hdd_change_hw_mode_for_given_chnl(adapter, chan,
6559 POLICY_MGR_UPDATE_REASON_SET_OPER_CHAN)) {
6560 hdd_err("Failed to change hw mode");
6561 return -EINVAL;
6562 }
6563
Jeff Johnson16528362018-06-14 12:34:16 -07006564 status = sme_roam_channel_change_req(hdd_ctx->mac_handle,
6565 bssid, &ch_params,
Jeff Johnsond9952752018-04-18 12:15:35 -07006566 &roam_profile);
6567 if (status) {
6568 hdd_err("Status: %d Failed to set sme_roam Channel for monitor mode",
6569 status);
6570 }
6571
6572 adapter->mon_chan = chan;
6573 adapter->mon_bandwidth = bandwidth;
6574 return qdf_status_to_os_return(status);
6575}
Nirav Shah73713f72018-05-17 14:50:41 +05306576#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05306577
Wu Gaodf929f12018-05-25 18:12:25 +08006578#ifdef MSM_PLATFORM
6579/**
6580 * hdd_stop_p2p_go() - call cfg80211 API to stop P2P GO
6581 * @adapter: pointer to adapter
6582 *
6583 * This function calls cfg80211 API to stop P2P GO
6584 *
6585 * Return: None
6586 */
6587static void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6588{
6589 hdd_debug("[SSR] send stop ap to supplicant");
6590 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
6591}
6592
6593static inline void hdd_delete_sta(struct hdd_adapter *adapter)
6594{
6595}
6596#else
6597static inline void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6598{
6599}
6600
6601/**
6602 * hdd_delete_sta() - call cfg80211 API to delete STA
6603 * @adapter: pointer to adapter
6604 *
6605 * This function calls cfg80211 API to delete STA
6606 *
6607 * Return: None
6608 */
6609static void hdd_delete_sta(struct hdd_adapter *adapter)
6610{
6611 struct qdf_mac_addr bcast_mac = QDF_MAC_ADDR_BCAST_INIT;
6612
6613 hdd_debug("[SSR] send restart supplicant");
6614 /* event supplicant to restart */
6615 cfg80211_del_sta(adapter->dev,
6616 (const u8 *)&bcast_mac.bytes[0],
6617 GFP_KERNEL);
6618}
6619#endif
6620
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006621QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006622{
Jeff Johnson9d295242017-08-29 14:39:48 -07006623 struct hdd_adapter *adapter;
Jeff Johnsone7951512019-02-27 10:02:51 -08006624 eConnectionState conn_state;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05306625 bool value;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006626
Dustin Brown491d54b2018-03-14 12:39:11 -07006627 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006628
Dustin Brown920397d2017-12-13 16:27:50 -08006629 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05306630 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08006631 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05306632
Yue Ma42654682018-01-11 16:55:24 -08006633 hdd_debug("[SSR] start adapter with device mode %s(%d)",
Dustin Brown458027c2018-10-19 12:26:27 -07006634 qdf_opmode_str(adapter->device_mode),
Yue Ma42654682018-01-11 16:55:24 -08006635 adapter->device_mode);
6636
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006637 hdd_wmm_init(adapter);
6638
6639 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006640 case QDF_STA_MODE:
6641 case QDF_P2P_CLIENT_MODE:
6642 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006643
Jeff Johnsone7951512019-02-27 10:02:51 -08006644 conn_state = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
6645 ->conn_info.conn_state;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006646
Krunal Sonib51eec72017-11-20 21:53:01 -08006647 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006648 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07006649 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006650
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006651 /* Indicate disconnect event to supplicant
6652 * if associated previously
6653 */
Jeff Johnsone7951512019-02-27 10:02:51 -08006654 if (eConnectionState_Associated == conn_state ||
6655 eConnectionState_IbssConnected == conn_state ||
6656 eConnectionState_NotConnected == conn_state ||
6657 eConnectionState_IbssDisconnected == conn_state ||
6658 eConnectionState_Disconnecting == conn_state) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006659 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006660
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006661 memset(&wrqu, '\0', sizeof(wrqu));
6662 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
6663 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
6664 wireless_send_event(adapter->dev, SIOCGIWAP,
6665 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07006666 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07006667 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006668
6669 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05306670 wlan_hdd_cfg80211_indicate_disconnect(
6671 adapter->dev, false,
6672 WLAN_REASON_UNSPECIFIED);
Jeff Johnsone7951512019-02-27 10:02:51 -08006673 } else if (eConnectionState_Connecting == conn_state) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006674 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006675 * Indicate connect failure to supplicant if we
6676 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006677 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306678 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306679 NULL, 0, NULL, 0,
6680 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006681 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006682 }
6683
6684 hdd_register_tx_flow_control(adapter,
6685 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08006686 hdd_tx_resume_cb,
6687 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006688
Visweswara Tanukub5a61242019-03-26 12:24:13 +05306689 hdd_register_hl_netdev_fc_timer(
6690 adapter,
6691 hdd_tx_resume_timer_expired_handler);
6692
Arunk Khandavalli40943af2017-05-15 19:25:34 +05306693 hdd_lpass_notify_start(hdd_ctx, adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05306694 hdd_nud_ignore_tracking(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006695 break;
6696
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006697 case QDF_SAP_MODE:
Dustin Brown05d81302018-09-11 16:49:22 -07006698 ucfg_mlme_get_sap_internal_restart(hdd_ctx->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05306699 &value);
6700 if (value)
Krunal Sonib51eec72017-11-20 21:53:01 -08006701 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05306702
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006703 break;
6704
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006705 case QDF_P2P_GO_MODE:
Wu Gaodf929f12018-05-25 18:12:25 +08006706 hdd_delete_sta(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006707 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306708 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08006709 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306710 hdd_set_mon_rx_cb(adapter->dev);
6711 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
6712 adapter->mon_bandwidth);
6713 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006714 default:
6715 break;
6716 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07006717 /*
6718 * Action frame registered in one adapter which will
6719 * applicable to all interfaces
6720 */
6721 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006722 }
6723
Wu Gaodf929f12018-05-25 18:12:25 +08006724 hdd_for_each_adapter(hdd_ctx, adapter) {
6725 if (!hdd_is_interface_up(adapter))
6726 continue;
6727
6728 if (adapter->device_mode == QDF_P2P_GO_MODE)
6729 hdd_stop_p2p_go(adapter);
6730 }
6731
Dustin Browne74003f2018-03-14 12:51:58 -07006732 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006733
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306734 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006735}
6736
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006737QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006738 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006739{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306740 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006741 qdf_list_node_t *node;
6742
6743 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006744
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006745 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006746 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006747 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006748
6749 if (QDF_IS_STATUS_ERROR(status))
6750 return status;
6751
6752 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6753
6754 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006755}
6756
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006757QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006758 struct hdd_adapter *current_adapter,
6759 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006760{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306761 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006762 qdf_list_node_t *node;
6763
6764 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006765
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006766 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006767 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08006768 &current_adapter->node,
6769 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006770 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006771
6772 if (QDF_IS_STATUS_ERROR(status))
6773 return status;
6774
6775 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6776
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006777 return status;
6778}
6779
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006780QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006781 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006782{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306783 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006784
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006785 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006786 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006787 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006788
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006789 return status;
6790}
6791
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006792QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006793 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006794{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306795 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006796 qdf_list_node_t *node;
6797
6798 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006799
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006800 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006801 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006802 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006803
6804 if (QDF_IS_STATUS_ERROR(status))
6805 return status;
6806
6807 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6808
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006809 return status;
6810}
6811
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006812QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006813 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006814{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306815 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006816
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006817 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006818 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006819 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006820
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006821 return status;
6822}
6823
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006824QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006825 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006826{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306827 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006828
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006829 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006830 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006831 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006832
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006833 return status;
6834}
6835
Liangwei Dong3abfe8f2018-09-20 02:25:44 -04006836struct hdd_adapter *hdd_get_adapter_by_rand_macaddr(
6837 struct hdd_context *hdd_ctx, tSirMacAddr mac_addr)
6838{
6839 struct hdd_adapter *adapter;
6840
6841 hdd_for_each_adapter(hdd_ctx, adapter) {
6842 if ((adapter->device_mode == QDF_STA_MODE ||
6843 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6844 adapter->device_mode == QDF_P2P_DEVICE_MODE) &&
6845 ucfg_p2p_check_random_mac(hdd_ctx->psoc,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08006846 adapter->vdev_id, mac_addr))
Liangwei Dong3abfe8f2018-09-20 02:25:44 -04006847 return adapter;
6848 }
6849
6850 return NULL;
6851}
6852
Jeff Johnson9d295242017-08-29 14:39:48 -07006853struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07006854 tSirMacAddr mac_addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006855{
Jeff Johnson9d295242017-08-29 14:39:48 -07006856 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006857
Dustin Brown920397d2017-12-13 16:27:50 -08006858 hdd_for_each_adapter(hdd_ctx, adapter) {
6859 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07006860 mac_addr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006861 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006862 }
6863
6864 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006865}
6866
Jeff Johnson9d295242017-08-29 14:39:48 -07006867struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Jeff Johnson55d2ab42019-03-06 11:43:49 -08006868 uint32_t vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006869{
Jeff Johnson9d295242017-08-29 14:39:48 -07006870 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006871
Dustin Brown920397d2017-12-13 16:27:50 -08006872 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson5a6fc962019-02-04 14:20:25 -08006873 if (adapter->vdev_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006874 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006875 }
6876
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006877 return NULL;
6878}
6879
Jeff Johnson9d295242017-08-29 14:39:48 -07006880struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07006881 const char *iface_name)
6882{
Jeff Johnson9d295242017-08-29 14:39:48 -07006883 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006884
Dustin Brown920397d2017-12-13 16:27:50 -08006885 hdd_for_each_adapter(hdd_ctx, adapter) {
6886 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07006887 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006888 }
Dustin Brown920397d2017-12-13 16:27:50 -08006889
Naveen Rawat4edb6822017-04-12 10:09:17 -07006890 return NULL;
6891}
6892
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006893/**
6894 * hdd_get_adapter() - to get adapter matching the mode
6895 * @hdd_ctx: hdd context
6896 * @mode: adapter mode
6897 *
6898 * This routine will return the pointer to adapter matching
6899 * with the passed mode.
6900 *
6901 * Return: pointer to adapter or null
6902 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006903struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006904 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006905{
Jeff Johnson9d295242017-08-29 14:39:48 -07006906 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006907
Dustin Brown920397d2017-12-13 16:27:50 -08006908 hdd_for_each_adapter(hdd_ctx, adapter) {
6909 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006910 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006911 }
6912
6913 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006914}
6915
Jeff Johnson55d2ab42019-03-06 11:43:49 -08006916enum QDF_OPMODE hdd_get_device_mode(uint32_t vdev_id)
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306917{
6918 struct hdd_context *hdd_ctx;
6919 struct hdd_adapter *adapter;
6920
6921 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
6922 if (!hdd_ctx) {
6923 hdd_err("Invalid HDD context");
6924 return QDF_MAX_NO_OF_MODE;
6925 }
6926
Jeff Johnson55d2ab42019-03-06 11:43:49 -08006927 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306928 if (!adapter) {
6929 hdd_err("Invalid HDD adapter");
6930 return QDF_MAX_NO_OF_MODE;
6931 }
6932
6933 return adapter->device_mode;
6934}
6935
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006936/**
6937 * hdd_get_operating_channel() - return operating channel of the device mode
6938 * @hdd_ctx: Pointer to the HDD context.
6939 * @mode: Device mode for which operating channel is required.
Jeff Johnson77f89bb2018-05-06 16:21:36 -07006940 * Supported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006941 * QDF_STA_MODE,
6942 * QDF_P2P_CLIENT_MODE,
6943 * QDF_SAP_MODE,
6944 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006945 *
6946 * This API returns the operating channel of the requested device mode
6947 *
6948 * Return: channel number. "0" id the requested device is not found OR it is
6949 * not connected.
6950 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006951uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006952 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006953{
Jeff Johnson9d295242017-08-29 14:39:48 -07006954 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006955 uint8_t operatingChannel = 0;
6956
Dustin Brown920397d2017-12-13 16:27:50 -08006957 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006958 if (mode == adapter->device_mode) {
6959 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006960 case QDF_STA_MODE:
6961 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006962 if (hdd_conn_is_connected
6963 (WLAN_HDD_GET_STATION_CTX_PTR
6964 (adapter))) {
6965 operatingChannel =
6966 (WLAN_HDD_GET_STATION_CTX_PTR
6967 (adapter))->conn_info.
Jeff Johnson8626e932019-02-27 18:35:22 -08006968 channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006969 }
6970 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006971 case QDF_SAP_MODE:
6972 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006973 /* softap connection info */
6974 if (test_bit
6975 (SOFTAP_BSS_STARTED,
6976 &adapter->event_flags))
6977 operatingChannel =
6978 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07006979 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006980 break;
6981 default:
6982 break;
6983 }
6984
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006985 /* Found the device of interest. break the loop */
6986 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006987 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006988 }
Dustin Brown920397d2017-12-13 16:27:50 -08006989
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006990 return operatingChannel;
6991}
6992
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006993static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006994 hdd_ctx)
6995{
Jeff Johnson9d295242017-08-29 14:39:48 -07006996 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006997
Dustin Brown491d54b2018-03-14 12:39:11 -07006998 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006999
Dustin Brown920397d2017-12-13 16:27:50 -08007000 hdd_for_each_adapter(hdd_ctx, adapter) {
7001 if (adapter->device_mode == QDF_STA_MODE ||
7002 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
7003 adapter->device_mode == QDF_IBSS_MODE ||
7004 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
7005 adapter->device_mode == QDF_SAP_MODE ||
7006 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007007 hdd_unregister_wext(adapter->dev);
7008 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007009 }
7010
Dustin Browne74003f2018-03-14 12:51:58 -07007011 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007012
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307013 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007014}
7015
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007016QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007017{
Jeff Johnson9d295242017-08-29 14:39:48 -07007018 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007019
Dustin Brown491d54b2018-03-14 12:39:11 -07007020 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007021
Dustin Brown920397d2017-12-13 16:27:50 -08007022 hdd_for_each_adapter(hdd_ctx, adapter) {
7023 if (adapter->device_mode == QDF_STA_MODE ||
7024 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
7025 adapter->device_mode == QDF_IBSS_MODE ||
7026 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
7027 adapter->device_mode == QDF_SAP_MODE ||
7028 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brown07901ec2018-09-07 11:02:41 -07007029 wlan_abort_scan(hdd_ctx->pdev, INVAL_PDEV_ID,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08007030 adapter->vdev_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05307031 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007032 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007033 }
7034
Dustin Browne74003f2018-03-14 12:51:58 -07007035 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007036
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307037 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007038}
7039
Dustin Brownf27bce82016-11-03 12:52:27 -07007040/**
7041 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
7042 * adapters
7043 * @hdd_ctx: The HDD context containing the adapters to operate on
7044 *
7045 * return: QDF_STATUS_SUCCESS
7046 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007047static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07007048{
Jeff Johnson9d295242017-08-29 14:39:48 -07007049 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07007050 int err;
7051
Dustin Brown491d54b2018-03-14 12:39:11 -07007052 hdd_enter();
Dustin Brownf27bce82016-11-03 12:52:27 -07007053
Dustin Brown920397d2017-12-13 16:27:50 -08007054 hdd_for_each_adapter(hdd_ctx, adapter) {
7055 if (adapter->device_mode == QDF_STA_MODE ||
7056 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
7057 adapter->device_mode == QDF_IBSS_MODE ||
7058 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
7059 adapter->device_mode == QDF_SAP_MODE ||
7060 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07007061 err = wlan_hdd_sched_scan_stop(adapter->dev);
7062 if (err)
7063 hdd_err("Unable to stop scheduled scan");
7064 }
Dustin Brownf27bce82016-11-03 12:52:27 -07007065 }
7066
Dustin Browne74003f2018-03-14 12:51:58 -07007067 hdd_exit();
Dustin Brownf27bce82016-11-03 12:52:27 -07007068
7069 return QDF_STATUS_SUCCESS;
7070}
7071
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007072#ifdef WLAN_NS_OFFLOAD
7073/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007074 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007075 * @hdd_ctx: Pointer to hdd context
7076 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007077 * Unregister for IPv6 address change notifications.
7078 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007079 * Return: None
7080 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007081static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007082{
7083 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007084}
7085
7086/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007087 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007088 * @hdd_ctx: Pointer to hdd context
7089 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007090 * Register for IPv6 address change notifications.
7091 *
7092 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007093 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007094static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007095{
7096 int ret;
7097
7098 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
7099 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007100 if (ret) {
7101 hdd_err("Failed to register IPv6 notifier: %d", ret);
7102 goto out;
7103 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007104
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007105 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007106out:
7107 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007108}
7109#else
7110/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007111 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007112 * @hdd_ctx: Pointer to hdd context
7113 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007114 * Unregister for IPv6 address change notifications.
7115 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007116 * Return: None
7117 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007118static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007119{
7120}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007121
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007122/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007123 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007124 * @hdd_ctx: Pointer to hdd context
7125 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007126 * Register for IPv6 address change notifications.
7127 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007128 * Return: None
7129 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007130static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007131{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007132 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007133}
7134#endif
7135
Alok Kumarb64650c2018-03-23 17:05:11 +05307136void hdd_set_disconnect_status(struct hdd_adapter *adapter, bool status)
7137{
7138 qdf_mutex_acquire(&adapter->disconnection_status_lock);
7139 adapter->disconnection_in_progress = status;
7140 qdf_mutex_release(&adapter->disconnection_status_lock);
7141 hdd_debug("setting disconnection status: %d", status);
7142}
7143
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007144/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007145 * hdd_register_notifiers - Register netdev notifiers.
7146 * @hdd_ctx: HDD context
7147 *
7148 * Register netdev notifiers like IPv4 and IPv6.
7149 *
7150 * Return: 0 on success and errno on failure
7151 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007152static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007153{
7154 int ret;
7155
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007156 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
7157 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05307158 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007159
7160 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
7161 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
7162 if (ret) {
7163 hdd_err("Failed to register IPv4 notifier: %d", ret);
7164 goto unregister_ip6_notifier;
7165 }
7166
Alok Kumarb64650c2018-03-23 17:05:11 +05307167 ret = hdd_nud_register_netevent_notifier(hdd_ctx);
7168 if (ret) {
7169 hdd_err("Failed to register netevent notifier: %d",
7170 ret);
7171 goto unregister_inetaddr_notifier;
7172 }
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007173 return 0;
7174
Alok Kumarb64650c2018-03-23 17:05:11 +05307175unregister_inetaddr_notifier:
7176 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007177unregister_ip6_notifier:
7178 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007179out:
7180 return ret;
7181
7182}
7183
7184/**
7185 * hdd_unregister_notifiers - Unregister netdev notifiers.
7186 * @hdd_ctx: HDD context
7187 *
7188 * Unregister netdev notifiers like IPv4 and IPv6.
7189 *
7190 * Return: None.
7191 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007192void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007193{
Alok Kumarb64650c2018-03-23 17:05:11 +05307194 hdd_nud_unregister_netevent_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007195 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
7196
7197 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007198}
7199
7200/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007201 * hdd_exit_netlink_services - Exit netlink services
7202 * @hdd_ctx: HDD context
7203 *
7204 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
7205 * nl service.
7206 *
7207 * Return: None.
7208 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007209static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007210{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307211 spectral_scan_deactivate_service();
7212 cnss_diag_deactivate_service();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007213 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007214 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307215 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007216
7217 nl_srv_exit();
7218}
7219
7220/**
7221 * hdd_init_netlink_services- Init netlink services
7222 * @hdd_ctx: HDD context
7223 *
7224 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
7225 * nl service.
7226 *
7227 * Return: 0 on success and errno on failure.
7228 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007229static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007230{
7231 int ret;
7232
Ryan Hsuceddceb2016-04-28 10:20:14 -07007233 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007234 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007235 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007236 goto out;
7237 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07007238 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007239
Naveen Rawat910726a2017-03-06 11:42:51 -08007240 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007241 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007242 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007243 goto err_nl_srv;
7244 }
7245
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307246 ptt_sock_activate_svc();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007247
7248 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07007249 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007250 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007251
7252 ret = cnss_diag_activate_service();
7253 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007254 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007255 goto err_close_cesium;
7256 }
7257
Dustin Brown01520852019-02-27 12:14:16 -08007258 spectral_scan_activate_service(hdd_ctx);
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08007259
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007260 return 0;
7261
7262err_close_cesium:
7263 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007264 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307265 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007266err_nl_srv:
7267 nl_srv_exit();
7268out:
7269 return ret;
7270}
7271
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007272/**
7273 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
7274 * @hdd_ctx: HDD context.
7275 *
7276 * Destroy RX wakelock.
7277 *
7278 * Return: None.
7279 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007280static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007281{
7282 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
7283}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007284
7285/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007286 * hdd_rx_wake_lock_create() - Create RX wakelock
7287 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007288 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007289 * Create RX wakelock.
7290 *
7291 * Return: None.
7292 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007293static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007294{
7295 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
7296}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007297
7298/**
Houston Hoffman160db392016-10-10 17:37:51 -07007299 * hdd_context_deinit() - Deinitialize HDD context
7300 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007301 *
Houston Hoffman160db392016-10-10 17:37:51 -07007302 * Deinitialize HDD context along with all the feature specific contexts but
7303 * do not free hdd context itself. Caller of this API is supposed to free
7304 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007305 *
Houston Hoffman160db392016-10-10 17:37:51 -07007306 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007307 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007308static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007309{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05307310 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
7311
Houston Hoffman160db392016-10-10 17:37:51 -07007312 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007313
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007314 hdd_sap_context_destroy(hdd_ctx);
7315
7316 hdd_rx_wake_lock_destroy(hdd_ctx);
7317
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007318 hdd_scan_context_destroy(hdd_ctx);
7319
Jeff Johnson19fc8e42017-10-30 19:53:49 -07007320 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007321
Houston Hoffman160db392016-10-10 17:37:51 -07007322 return 0;
7323}
7324
Dustin Brown623e7e32018-09-05 14:27:50 -07007325void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07007326{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07007327 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05307328
Dustin Brown623e7e32018-09-05 14:27:50 -07007329 hdd_exit_netlink_services(hdd_ctx);
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05307330 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7331
Houston Hoffman160db392016-10-10 17:37:51 -07007332 hdd_context_deinit(hdd_ctx);
7333
Dustin Browndb2df2e2018-10-31 15:29:24 -07007334 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
7335
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307336 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007337 hdd_ctx->config = NULL;
Dustin Brown84f46ea2018-02-15 11:57:36 -08007338 cfg_release();
7339
Min Liu47104042019-04-09 17:49:21 +08007340 qdf_delayed_work_destroy(&hdd_ctx->psoc_idle_timeout_work);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007341 wiphy_free(hdd_ctx->wiphy);
7342}
7343
7344/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05307345 * wlan_destroy_bug_report_lock() - Destroy bug report lock
7346 *
7347 * This function is used to destroy bug report lock
7348 *
7349 * Return: None
7350 */
7351static void wlan_destroy_bug_report_lock(void)
7352{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07007353 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05307354
7355 p_cds_context = cds_get_global_context();
7356 if (!p_cds_context) {
7357 hdd_err("cds context is NULL");
7358 return;
7359 }
7360
7361 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
7362}
7363
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05307364#ifdef DISABLE_CHANNEL_LIST
7365static void wlan_hdd_cache_chann_mutex_destroy(struct hdd_context *hdd_ctx)
7366{
7367 qdf_mutex_destroy(&hdd_ctx->cache_channel_lock);
7368}
7369#else
7370static void wlan_hdd_cache_chann_mutex_destroy(struct hdd_context *hdd_ctx)
7371{
7372}
7373#endif
7374
Dustin Brown92bd8382018-10-31 15:49:46 -07007375void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007376{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007377 struct wiphy *wiphy = hdd_ctx->wiphy;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007378
Dustin Brown491d54b2018-03-14 12:39:11 -07007379 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007380
Arun Kumar Khandavallideda5a82019-03-11 15:32:19 +05307381 hdd_debugfs_mws_coex_info_deinit(hdd_ctx);
Dustin Brown4c663222018-10-23 14:19:36 -07007382 hdd_psoc_idle_timer_stop(hdd_ctx);
Dustin Brown6470aba2018-09-05 09:49:58 -07007383
Arun Khandavallifae92942016-08-01 13:31:08 +05307384 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007385
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007386#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05307387 if (QDF_TIMER_STATE_RUNNING ==
7388 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
7389 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007390 }
7391
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307392 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05307393 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07007394 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007395 }
Liangwei Dongaef84342016-10-21 05:28:00 -04007396 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
7397 qdf_mem_free(hdd_ctx->last_acs_channel_list);
7398 hdd_ctx->last_acs_channel_list = NULL;
7399 hdd_ctx->num_of_channels = 0;
7400 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007401#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007402
7403 /*
7404 * Powersave Offload Case
7405 * Disable Idle Power Save Mode
7406 */
7407 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07007408 /* clear the scan queue in all the scenarios */
Dustin Brown07901ec2018-09-07 11:02:41 -07007409 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007410
Dustin Brownf688ea12019-03-19 17:02:32 -07007411 if (hdd_ctx->driver_status != DRIVER_MODULES_CLOSED) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307412 hdd_unregister_wext_all_adapters(hdd_ctx);
7413 /*
7414 * Cancel any outstanding scan requests. We are about to close
7415 * all of our adapters, but an adapter structure is what SME
7416 * passes back to our callback function. Hence if there
7417 * are any outstanding scan requests then there is a
7418 * race condition between when the adapter is closed and
7419 * when the callback is invoked. We try to resolve that
7420 * race condition here by canceling any outstanding scans
7421 * before we close the adapters.
7422 * Note that the scans may be cancelled in an asynchronous
7423 * manner, so ideally there needs to be some kind of
7424 * synchronization. Rather than introduce a new
7425 * synchronization here, we will utilize the fact that we are
7426 * about to Request Full Power, and since that is synchronized,
7427 * the expectation is that by the time Request Full Power has
7428 * completed, all scans will be cancelled
7429 */
7430 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07007431 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08007432 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08007433 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007434 }
7435
Arunk Khandavalli830c9692018-03-22 12:17:40 +05307436 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavalli08479ba2017-08-07 19:56:23 +05307437 unregister_netdevice_notifier(&hdd_netdev_notifier);
7438
Rachit Kankane30807332018-06-27 18:39:36 +05307439 qdf_dp_trace_deinit();
7440
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07007441 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05307442
Visweswara Tanukuc029a202018-11-27 10:42:10 +05307443 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Dustin Brown86d196b2018-08-02 11:51:49 -07007444 hdd_bus_bandwidth_deinit(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -08007445 hdd_driver_memdump_deinit();
7446
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05307447 qdf_nbuf_deinit_replenish_timer();
7448
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05307449 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
7450 hdd_info("Release wakelock for monitor mode!");
7451 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
7452 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
7453 }
7454
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307455 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307456 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05307457 wlan_hdd_cache_chann_mutex_destroy(hdd_ctx);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307458
Naveen Rawate02f8f52018-04-05 11:58:04 -07007459 osif_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007460
Dustin Brownd005ad82018-01-19 10:32:13 -08007461 hdd_close_all_adapters(hdd_ctx, false);
7462
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05307463 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307464 /*
7465 * If there is re_init failure wiphy would have already de-registered
7466 * check the wiphy status before un-registering again
7467 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05307468 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307469 wiphy_unregister(wiphy);
7470 wlan_hdd_cfg80211_deinit(wiphy);
7471 hdd_lpass_notify_stop(hdd_ctx);
7472 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07007473
Arun Khandavallifae92942016-08-01 13:31:08 +05307474 hdd_exit_netlink_services(hdd_ctx);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307475#ifdef FEATURE_WLAN_CH_AVOID
7476 mutex_destroy(&hdd_ctx->avoid_freq_lock);
7477#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007478}
7479
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007480#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04007481/**
7482 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007483 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04007484 *
7485 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
7486 * Then new ACS request will do a fresh scan without reusing the cached
7487 * scan information.
7488 *
7489 * Return: void
7490 */
Tang Yingying523322d2017-01-17 23:28:43 +08007491static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007492{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007493 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Jeff Johnson16528362018-06-14 12:34:16 -07007494 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007495
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007496 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007497 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04007498 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
7499 qdf_mem_free(hdd_ctx->last_acs_channel_list);
7500 hdd_ctx->last_acs_channel_list = NULL;
7501 hdd_ctx->num_of_channels = 0;
7502 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007503
Jeff Johnson16528362018-06-14 12:34:16 -07007504 mac_handle = hdd_ctx->mac_handle;
7505 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007506 return;
Jeff Johnson16528362018-06-14 12:34:16 -07007507 sme_scan_flush_result(mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007508}
7509#endif
7510
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007511/**
7512 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
7513 * @state: state
7514 *
7515 * This function notifies FW with modem power status
7516 *
7517 * Return: 0 if successful, error number otherwise
7518 */
7519int hdd_wlan_notify_modem_power_state(int state)
7520{
7521 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307522 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007523 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07007524 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007525
Anurag Chouhan6d760662016-02-20 16:05:43 +05307526 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007527 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307528 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007529 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307530
Jeff Johnson16528362018-06-14 12:34:16 -07007531 mac_handle = hdd_ctx->mac_handle;
7532 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007533 return -EINVAL;
7534
Jeff Johnson16528362018-06-14 12:34:16 -07007535 qdf_status = sme_notify_modem_power_state(mac_handle, state);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307536 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007537 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007538 state);
7539 return -EINVAL;
7540 }
7541 return 0;
7542}
7543
7544/**
7545 *
7546 * hdd_post_cds_enable_config() - HDD post cds start config helper
7547 * @adapter - Pointer to the HDD
7548 *
7549 * Return: None
7550 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007551QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007552{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307553 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007554
7555 /*
7556 * Send ready indication to the HDD. This will kick off the MAC
7557 * into a 'running' state and should kick off an initial scan.
7558 */
Jeff Johnson16528362018-06-14 12:34:16 -07007559 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->mac_handle);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307560 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007561 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
7562 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307563 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007564 }
7565
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307566 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007567}
7568
Sourav Mohapatra92ea8d62018-02-05 10:03:10 +05307569struct hdd_adapter *hdd_get_first_valid_adapter(struct hdd_context *hdd_ctx)
7570{
7571 struct hdd_adapter *adapter;
7572
7573 hdd_for_each_adapter(hdd_ctx, adapter) {
7574 if (adapter && adapter->magic == WLAN_HDD_ADAPTER_MAGIC)
7575 return adapter;
7576 }
7577
7578 return NULL;
7579}
7580
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007581/* wake lock APIs for HDD */
7582void hdd_prevent_suspend(uint32_t reason)
7583{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307584 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007585}
7586
7587void hdd_allow_suspend(uint32_t reason)
7588{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307589 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007590}
7591
7592void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
7593{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05307594 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
7595 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007596}
7597
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007598/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007599QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007600{
Jeff Johnson16528362018-06-14 12:34:16 -07007601 return sme_init_chan_list(hdd_ctx->mac_handle,
Amar Singhal6f8592b2017-04-26 14:31:58 -07007602 hdd_ctx->reg.alpha2,
7603 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007604}
7605
7606/**
7607 * hdd_is_5g_supported() - check if hardware supports 5GHz
7608 * @hdd_ctx: Pointer to the hdd context
7609 *
7610 * HDD function to know if hardware supports 5GHz
7611 *
7612 * Return: true if hardware supports 5GHz
7613 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007614bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007615{
Amar Singhal58b45ef2017-08-01 13:43:54 -07007616 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08007617 return true;
7618
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08007619 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08007620 return true;
7621 else
7622 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007623}
7624
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007625static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007626{
7627 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07007628 int ret_val;
Wu Gaoed616a12019-01-16 15:19:21 +08007629 uint32_t channel_bonding_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007630
7631 wiphy = hdd_ctx->wiphy;
7632
7633 /*
7634 * The channel information in
7635 * wiphy needs to be initialized before wiphy registration
7636 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007637 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
7638 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007639 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07007640 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007641 }
7642
7643#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
7644 wiphy->wowlan = &wowlan_support_reg_init;
7645#else
7646 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
7647 WIPHY_WOWLAN_MAGIC_PKT |
7648 WIPHY_WOWLAN_DISCONNECT |
7649 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
7650 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
7651 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
7652 WIPHY_WOWLAN_4WAY_HANDSHAKE |
7653 WIPHY_WOWLAN_RFKILL_RELEASE;
7654
7655 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
7656 WOW_MAX_FILTERS_PER_LIST);
7657 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
7658 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
7659#endif
Wu Gaoed616a12019-01-16 15:19:21 +08007660 ucfg_mlme_get_channel_bonding_24ghz(hdd_ctx->psoc,
7661 &channel_bonding_mode);
Liangwei Dong0da14262018-07-03 03:30:23 -04007662 if (hdd_ctx->obss_scan_offload) {
7663 hdd_debug("wmi_service_obss_scan supported");
Wu Gaoed616a12019-01-16 15:19:21 +08007664 } else if (channel_bonding_mode) {
Liangwei Dong0da14262018-07-03 03:30:23 -04007665 hdd_debug("enable wpa_supp obss_scan");
7666 wiphy->features |= NL80211_FEATURE_NEED_OBSS_SCAN;
7667 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007668
7669 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007670 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307671 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07007672 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307673 return ret_val;
7674 }
Amar Singhalac26de22018-06-22 12:53:06 -07007675
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007676 /* Check the kernel version for upstream commit aced43ce780dc5 that
7677 * has support for processing user cell_base hints when wiphy is
7678 * self managed or check the backport flag for the same.
7679 */
Amar Singhalac26de22018-06-22 12:53:06 -07007680#if defined CFG80211_USER_HINT_CELL_BASE_SELF_MANAGED || \
7681 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0))
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007682 hdd_send_wiphy_regd_sync_event(hdd_ctx);
7683#endif
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307684
Amar Singhal2d812012018-02-03 15:06:47 +08007685 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007686
Amar Singhale4f28ee2015-10-21 14:36:56 -07007687 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007688}
7689
Tiger Yu8b119e92019-04-09 13:55:07 +08007690#ifdef WLAN_FEATURE_DP_BUS_BANDWIDTH
Mohit Khannaca4173b2017-09-12 21:52:19 -07007691/**
7692 * hdd_display_periodic_stats() - Function to display periodic stats
7693 * @hdd_ctx - handle to hdd context
7694 * @bool data_in_interval - true, if data detected in bw time interval
7695 *
7696 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
7697 * Stats show up in wlan driver logs.
7698 *
7699 * Returns: None
7700 */
Mohit Khanna70322002018-05-15 19:21:32 -07007701static void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
7702 bool data_in_interval)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007703{
Mohit Khanna70322002018-05-15 19:21:32 -07007704 static uint32_t counter;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007705 static bool data_in_time_period;
7706 ol_txrx_pdev_handle pdev;
Mohit Khanna81418772018-10-30 14:14:46 -07007707 ol_txrx_soc_handle soc;
Arif Hussaincca60432018-12-03 19:45:12 -08007708 uint32_t periodic_stats_disp_time = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007709
Arif Hussaincca60432018-12-03 19:45:12 -08007710 ucfg_mlme_stats_get_periodic_display_time(hdd_ctx->psoc,
7711 &periodic_stats_disp_time);
7712 if (!periodic_stats_disp_time)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007713 return;
7714
Mohit Khanna81418772018-10-30 14:14:46 -07007715 soc = cds_get_context(QDF_MODULE_ID_SOC);
7716 if (!soc) {
7717 hdd_err("soc is NULL");
7718 return;
7719 }
7720
Mohit Khannaca4173b2017-09-12 21:52:19 -07007721 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
7722 if (!pdev) {
7723 hdd_err("pdev is NULL");
7724 return;
7725 }
7726
7727 counter++;
7728 if (data_in_interval)
7729 data_in_time_period = data_in_interval;
7730
jitiphil869b9f72018-09-25 17:14:01 +05307731 if (counter * hdd_ctx->config->bus_bw_compute_interval >=
Arif Hussaincca60432018-12-03 19:45:12 -08007732 periodic_stats_disp_time * 1000) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007733 if (data_in_time_period) {
Mohit Khanna70322002018-05-15 19:21:32 -07007734 wlan_hdd_display_txrx_stats(hdd_ctx);
Mohit Khannac9649652018-11-28 18:10:28 -08007735 dp_txrx_ext_dump_stats(soc, CDP_DP_RX_THREAD_STATS);
Mohit Khanna81418772018-10-30 14:14:46 -07007736 cdp_display_stats(soc,
Mohit Khanna70322002018-05-15 19:21:32 -07007737 CDP_RX_RING_STATS,
7738 QDF_STATS_VERBOSITY_LEVEL_LOW);
Mohit Khanna81418772018-10-30 14:14:46 -07007739 cdp_display_stats(soc,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007740 CDP_TXRX_PATH_STATS,
7741 QDF_STATS_VERBOSITY_LEVEL_LOW);
7742 wlan_hdd_display_netif_queue_history
7743 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
7744 qdf_dp_trace_dump_stats();
7745 }
7746 counter = 0;
7747 data_in_time_period = false;
7748 }
7749}
7750
Ravi Joshie2331e82015-07-01 18:18:54 -07007751/**
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007752 * hdd_clear_rps_cpu_mask - clear RPS CPU mask for interfaces
7753 * @hdd_ctx: pointer to struct hdd_context
7754 *
7755 * Return: none
7756 */
7757static void hdd_clear_rps_cpu_mask(struct hdd_context *hdd_ctx)
7758{
7759 struct hdd_adapter *adapter;
7760
7761 hdd_for_each_adapter(hdd_ctx, adapter)
7762 hdd_send_rps_disable_ind(adapter);
7763}
7764
7765/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07007766 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07007767 * @hdd_ctx - handle to hdd context
7768 * @tx_packets - transmit packet count
7769 * @rx_packets - receive packet count
7770 *
7771 * The function controls the bus bandwidth and dynamic control of
7772 * tcp delayed ack configuration
7773 *
7774 * Returns: None
7775 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007776
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007777static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07007778 const uint64_t tx_packets,
7779 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007780{
Mohit Khannaca4173b2017-09-12 21:52:19 -07007781 u64 total_pkts = tx_packets + rx_packets;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007782 uint64_t temp_tx = 0, avg_rx = 0;
7783 uint64_t no_rx_offload_pkts = 0, avg_no_rx_offload_pkts = 0;
7784 uint64_t rx_offload_pkts = 0, avg_rx_offload_pkts = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007785 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08007786 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08007787 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007788 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007789 uint16_t index = 0;
7790 bool vote_level_change = false;
7791 bool rx_level_change = false;
7792 bool tx_level_change = false;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007793 bool rxthread_high_tput_req = false;
Mohit Khannaf7562c32018-07-05 17:42:36 -07007794 bool dptrace_high_tput_req;
Srinivas Girigowda50335342018-09-07 15:21:01 -07007795
jitiphil869b9f72018-09-25 17:14:01 +05307796 if (total_pkts > hdd_ctx->config->bus_bw_high_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007797 next_vote_level = PLD_BUS_WIDTH_HIGH;
jitiphil869b9f72018-09-25 17:14:01 +05307798 else if (total_pkts > hdd_ctx->config->bus_bw_medium_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007799 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
jitiphil869b9f72018-09-25 17:14:01 +05307800 else if (total_pkts > hdd_ctx->config->bus_bw_low_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007801 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07007802 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07007803 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007804
Mohit Khannaf7562c32018-07-05 17:42:36 -07007805 dptrace_high_tput_req =
7806 next_vote_level > PLD_BUS_WIDTH_NONE ? true : false;
7807
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007808 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07007809 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
7810 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007811 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007812 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007813 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007814 if ((next_vote_level == PLD_BUS_WIDTH_LOW) ||
7815 (next_vote_level == PLD_BUS_WIDTH_NONE)) {
Nirav Shahffc6a092016-06-09 16:09:08 +05307816 if (hdd_ctx->hbw_requested) {
7817 pld_remove_pm_qos(hdd_ctx->parent_dev);
7818 hdd_ctx->hbw_requested = false;
7819 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007820 if (hdd_ctx->dynamic_rps)
7821 hdd_clear_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007822 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05307823 if (!hdd_ctx->hbw_requested) {
7824 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
7825 hdd_ctx->hbw_requested = true;
7826 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007827 if (hdd_ctx->dynamic_rps)
7828 hdd_set_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007829 }
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007830
Manjunathappa Prakashcb6df762018-05-29 18:54:58 -07007831 if (hdd_ctx->config->napi_cpu_affinity_mask)
7832 hdd_napi_apply_throughput_policy(hdd_ctx,
7833 tx_packets,
7834 rx_packets);
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007835
jitiphil869b9f72018-09-25 17:14:01 +05307836 if (rx_packets < hdd_ctx->config->bus_bw_low_threshold)
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007837 hdd_disable_rx_ol_for_low_tput(hdd_ctx, true);
7838 else
7839 hdd_disable_rx_ol_for_low_tput(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007840 }
Mohit Khannae71e2262015-11-10 09:37:24 -08007841
Mohit Khannaf7562c32018-07-05 17:42:36 -07007842 qdf_dp_trace_apply_tput_policy(dptrace_high_tput_req);
7843
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007844 /*
7845 * Includes tcp+udp, if perf core is required for tcp, then
7846 * perf core is also required for udp.
7847 */
7848 no_rx_offload_pkts = hdd_ctx->no_rx_offload_pkt_cnt;
7849 hdd_ctx->no_rx_offload_pkt_cnt = 0;
7850 rx_offload_pkts = rx_packets - no_rx_offload_pkts;
Mohit Khannae71e2262015-11-10 09:37:24 -08007851
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007852 avg_no_rx_offload_pkts = (no_rx_offload_pkts +
7853 hdd_ctx->prev_no_rx_offload_pkts) / 2;
7854 hdd_ctx->prev_no_rx_offload_pkts = no_rx_offload_pkts;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08007855
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007856 avg_rx_offload_pkts = (rx_offload_pkts +
7857 hdd_ctx->prev_rx_offload_pkts) / 2;
7858 hdd_ctx->prev_rx_offload_pkts = rx_offload_pkts;
7859
7860 avg_rx = avg_no_rx_offload_pkts + avg_rx_offload_pkts;
7861 /*
7862 * Takes care to set Rx_thread affinity for below case
7863 * 1)LRO/GRO not supported ROME case
7864 * 2)when rx_ol is disabled in cases like concurrency etc
7865 * 3)For UDP cases
7866 */
7867 if (avg_no_rx_offload_pkts >
jitiphil869b9f72018-09-25 17:14:01 +05307868 hdd_ctx->config->bus_bw_high_threshold)
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007869 rxthread_high_tput_req = true;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307870 else
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007871 rxthread_high_tput_req = false;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307872
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007873 if (cds_sched_handle_throughput_req(rxthread_high_tput_req))
7874 hdd_warn("Rx thread high_tput(%d) affinity request failed",
7875 rxthread_high_tput_req);
7876
7877 /* fine-tuning parameters for RX Flows */
jitiphil869b9f72018-09-25 17:14:01 +05307878 if (avg_rx > hdd_ctx->config->tcp_delack_thres_high) {
Ravi Joshifed83572016-10-07 16:20:37 -07007879 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
7880 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
7881 next_rx_level = WLAN_SVC_TP_HIGH;
7882 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07007883 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07007884 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08007885 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007886 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007887
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007888 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007889 struct wlan_rx_tp_data rx_tp_data = {0};
7890
Ravi Joshie2331e82015-07-01 18:18:54 -07007891 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Jeff Johnsonb9feee42018-07-08 10:34:48 -07007892 next_rx_level, avg_rx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007893 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007894 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07007895 /* Send throughput indication only if it is enabled.
7896 * Disabling tcp_del_ack will revert the tcp stack behavior
7897 * to default delayed ack. Note that this will disable the
7898 * dynamic delayed ack mechanism across the system
7899 */
Manjunathappa Prakashbfd12762018-04-29 22:44:52 -07007900 if (hdd_ctx->en_tcp_delack_no_lro)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007901 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
7902
Mohit Khanna6272fb682017-04-13 09:34:36 -07007903 if (hdd_ctx->config->enable_tcp_adv_win_scale)
7904 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
7905
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007906 rx_tp_data.level = next_rx_level;
Alok Kumar2fad6442018-11-08 19:19:28 +05307907 wlan_hdd_update_tcp_rx_param(hdd_ctx, &rx_tp_data);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007908 }
7909
Mohit Khannae71e2262015-11-10 09:37:24 -08007910 /* fine-tuning parameters for TX Flows */
7911 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
7912 hdd_ctx->prev_tx = tx_packets;
7913 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
7914 next_tx_level = WLAN_SVC_TP_HIGH;
7915 else
7916 next_tx_level = WLAN_SVC_TP_LOW;
7917
Prakash Manjunathappae73e3b52018-02-27 18:56:22 -08007918 if ((hdd_ctx->config->enable_tcp_limit_output) &&
7919 (hdd_ctx->cur_tx_level != next_tx_level)) {
Alok Kumar2fad6442018-11-08 19:19:28 +05307920 struct wlan_tx_tp_data tx_tp_data = {0};
7921
Mohit Khannae71e2262015-11-10 09:37:24 -08007922 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
7923 next_tx_level, temp_tx);
7924 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007925 tx_level_change = true;
Alok Kumar2fad6442018-11-08 19:19:28 +05307926 tx_tp_data.level = next_tx_level;
7927 tx_tp_data.tcp_limit_output = true;
7928 wlan_hdd_update_tcp_tx_param(hdd_ctx, &tx_tp_data);
Mohit Khannae71e2262015-11-10 09:37:24 -08007929 }
7930
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007931 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007932 if (vote_level_change || tx_level_change || rx_level_change) {
7933 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
7934 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
7935 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
7936 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
7937 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
7938 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
7939 hdd_ctx->hdd_txrx_hist_idx++;
7940 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
7941 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07007942
7943 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007944}
7945
7946#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Dustin Browna20bad52019-03-05 12:03:30 -08007947static void __hdd_bus_bw_work_handler(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007948{
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307949 struct hdd_adapter *adapter = NULL, *con_sap_adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307950 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05307951 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
7952 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007953 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307954 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007955 bool connected = false;
7956 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
7957
Prashanth Bhattaab004382016-10-11 16:08:11 -07007958 if (wlan_hdd_validate_context(hdd_ctx))
Dustin Browna20bad52019-03-05 12:03:30 -08007959 goto stop_work;
Prashanth Bhattaab004382016-10-11 16:08:11 -07007960
Jeff Johnson214671b2017-10-30 19:45:23 -07007961 if (hdd_ctx->is_wiphy_suspended)
Dustin Browna20bad52019-03-05 12:03:30 -08007962 return;
Jingxiang Gec64e1932017-08-22 14:38:59 +08007963
Dustin Brown920397d2017-12-13 16:27:50 -08007964 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05307965 /*
7966 * Validate magic so we don't end up accessing
7967 * an invalid adapter.
7968 */
7969 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
7970 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007971
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007972 if ((adapter->device_mode == QDF_STA_MODE ||
7973 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Jeff Johnsone7951512019-02-27 10:02:51 -08007974 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.conn_state
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007975 != eConnectionState_Associated) {
7976
7977 continue;
7978 }
7979
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007980 if ((adapter->device_mode == QDF_SAP_MODE ||
7981 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07007982 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007983
7984 continue;
7985 }
7986
7987 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
7988 adapter->prev_tx_packets);
7989 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
7990 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307991
7992 if (adapter->device_mode == QDF_SAP_MODE ||
7993 adapter->device_mode == QDF_P2P_GO_MODE ||
7994 adapter->device_mode == QDF_IBSS_MODE) {
7995
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08007996 ret = cdp_get_intra_bss_fwd_pkts_count(
7997 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson5a6fc962019-02-04 14:20:25 -08007998 adapter->vdev_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307999 &fwd_tx_packets, &fwd_rx_packets);
8000 if (ret == A_OK) {
8001 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
8002 fwd_tx_packets,
8003 adapter->prev_fwd_tx_packets);
8004 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
8005 fwd_tx_packets,
8006 adapter->prev_fwd_rx_packets);
8007 }
8008 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008009
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05308010 if (adapter->device_mode == QDF_SAP_MODE)
8011 con_sap_adapter = adapter;
8012
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008013 total_rx += adapter->stats.rx_packets;
8014 total_tx += adapter->stats.tx_packets;
8015
8016 spin_lock_bh(&hdd_ctx->bus_bw_lock);
8017 adapter->prev_tx_packets = adapter->stats.tx_packets;
8018 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05308019 adapter->prev_fwd_tx_packets = fwd_tx_packets;
8020 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008021 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
8022 connected = true;
8023 }
8024
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008025 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07008026 hdd_err("bus bandwidth timer running in disconnected state");
Dustin Browna20bad52019-03-05 12:03:30 -08008027 goto stop_work;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008028 }
8029
Yun Parka29974a2018-04-09 12:05:49 -07008030 /* add intra bss forwarded tx and rx packets */
8031 tx_packets += fwd_tx_packets_diff;
8032 rx_packets += fwd_rx_packets_diff;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008033
Dustin Brown07901ec2018-09-07 11:02:41 -07008034 if (ucfg_ipa_is_fw_wdi_activated(hdd_ctx->pdev)) {
8035 ucfg_ipa_uc_stat_query(hdd_ctx->pdev, &ipa_tx_packets,
8036 &ipa_rx_packets);
Yun Parka29974a2018-04-09 12:05:49 -07008037 tx_packets += (uint64_t)ipa_tx_packets;
8038 rx_packets += (uint64_t)ipa_rx_packets;
8039
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05308040 if (con_sap_adapter) {
8041 con_sap_adapter->stats.tx_packets += ipa_tx_packets;
8042 con_sap_adapter->stats.rx_packets += ipa_rx_packets;
8043 }
8044
Dustin Brown07901ec2018-09-07 11:02:41 -07008045 ucfg_ipa_set_perf_level(hdd_ctx->pdev, tx_packets, rx_packets);
8046 ucfg_ipa_uc_stat_request(hdd_ctx->pdev, 2);
Yun Parka29974a2018-04-09 12:05:49 -07008047 }
8048
8049 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008050
Dustin Browna20bad52019-03-05 12:03:30 -08008051 return;
8052
8053stop_work:
8054 qdf_periodic_work_stop_async(&hdd_ctx->bus_bw_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008055}
Prashanth Bhattaab004382016-10-11 16:08:11 -07008056
Dustin Browna20bad52019-03-05 12:03:30 -08008057static void hdd_bus_bw_work_handler(void *context)
Rajeev Kumarb2b5e692018-08-31 15:12:40 -07008058{
Dustin Brown3fdaaf62019-03-18 14:00:16 -07008059 struct hdd_context *hdd_ctx = context;
8060 struct qdf_op_sync *op_sync;
Dustin Browna20bad52019-03-05 12:03:30 -08008061
Dustin Brown3fdaaf62019-03-18 14:00:16 -07008062 if (qdf_op_protect(&op_sync))
8063 return;
8064
8065 __hdd_bus_bw_work_handler(hdd_ctx);
8066
8067 qdf_op_unprotect(op_sync);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05308068}
8069
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008070int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07008071{
Dustin Browna20bad52019-03-05 12:03:30 -08008072 QDF_STATUS status;
8073
Dustin Brown35008ba2018-08-23 14:34:21 -07008074 hdd_enter();
8075
Prashanth Bhattaab004382016-10-11 16:08:11 -07008076 spin_lock_init(&hdd_ctx->bus_bw_lock);
Dustin Browna20bad52019-03-05 12:03:30 -08008077 status = qdf_periodic_work_create(&hdd_ctx->bus_bw_work,
8078 hdd_bus_bw_work_handler,
Dustin Brown3fdaaf62019-03-18 14:00:16 -07008079 hdd_ctx);
Dustin Brown35008ba2018-08-23 14:34:21 -07008080
8081 hdd_exit();
Prashanth Bhattaab004382016-10-11 16:08:11 -07008082
Dustin Browna20bad52019-03-05 12:03:30 -08008083 return qdf_status_to_os_return(status);
Prashanth Bhattaab004382016-10-11 16:08:11 -07008084}
8085
Dustin Brown86d196b2018-08-02 11:51:49 -07008086void hdd_bus_bandwidth_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07008087{
Dustin Brown35008ba2018-08-23 14:34:21 -07008088 hdd_enter();
Prashanth Bhattaab004382016-10-11 16:08:11 -07008089
Dustin Browna20bad52019-03-05 12:03:30 -08008090 QDF_BUG(!qdf_periodic_work_stop_sync(&hdd_ctx->bus_bw_work));
8091 qdf_periodic_work_destroy(&hdd_ctx->bus_bw_work);
Dustin Brown35008ba2018-08-23 14:34:21 -07008092
8093 hdd_exit();
Prashanth Bhattaab004382016-10-11 16:08:11 -07008094}
Tiger Yu8b119e92019-04-09 13:55:07 +08008095#endif /*WLAN_FEATURE_DP_BUS_BANDWIDTH*/
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008096
8097/**
Nirav Shahed34b212016-04-25 10:59:16 +05308098 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
8099 * @hdd_ctx: hdd context
8100 *
8101 * Return: 0 for success or error code
8102 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008103static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05308104{
8105 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
8106 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Min Liu74a1a502018-10-10 19:59:07 +08008107 if (!hdd_ctx->hdd_txrx_hist)
Nirav Shahed34b212016-04-25 10:59:16 +05308108 return -ENOMEM;
Nirav Shahed34b212016-04-25 10:59:16 +05308109 return 0;
8110}
8111
8112/**
8113 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
8114 * @hdd_ctx: hdd context
8115 *
8116 * Return: none
8117 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008118void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05308119{
Jeff Johnsond36fa332019-03-18 13:42:25 -07008120 if (!hdd_ctx || !hdd_ctx->hdd_txrx_hist)
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05308121 return;
8122
8123 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
8124 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05308125}
8126
Nirav Shahda008342016-05-17 18:50:40 +05308127static uint8_t *convert_level_to_string(uint32_t level)
8128{
8129 switch (level) {
8130 /* initialize the wlan sub system */
8131 case WLAN_SVC_TP_NONE:
8132 return "NONE";
8133 case WLAN_SVC_TP_LOW:
8134 return "LOW";
8135 case WLAN_SVC_TP_MEDIUM:
8136 return "MED";
8137 case WLAN_SVC_TP_HIGH:
8138 return "HIGH";
8139 default:
8140 return "INVAL";
8141 }
8142}
8143
Nirav Shahed34b212016-04-25 10:59:16 +05308144
8145/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008146 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
8147 * @hdd_ctx: hdd context
8148 *
8149 * Return: none
8150 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008151void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008152{
8153 int i;
8154
Tiger Yu8b119e92019-04-09 13:55:07 +08008155#ifdef WLAN_FEATURE_DP_BUS_BANDWIDTH
Nirav Shahe6194ac2018-07-13 11:04:41 +05308156 hdd_nofl_info("BW compute Interval: %dms",
jitiphil869b9f72018-09-25 17:14:01 +05308157 hdd_ctx->config->bus_bw_compute_interval);
Nirav Shahe6194ac2018-07-13 11:04:41 +05308158 hdd_nofl_info("BW High TH: %d BW Med TH: %d BW Low TH: %d",
jitiphil869b9f72018-09-25 17:14:01 +05308159 hdd_ctx->config->bus_bw_high_threshold,
8160 hdd_ctx->config->bus_bw_medium_threshold,
8161 hdd_ctx->config->bus_bw_low_threshold);
Nirav Shahe6194ac2018-07-13 11:04:41 +05308162 hdd_nofl_info("Enable TCP DEL ACK: %d",
8163 hdd_ctx->en_tcp_delack_no_lro);
8164 hdd_nofl_info("TCP DEL High TH: %d TCP DEL Low TH: %d",
jitiphil869b9f72018-09-25 17:14:01 +05308165 hdd_ctx->config->tcp_delack_thres_high,
8166 hdd_ctx->config->tcp_delack_thres_low);
Nirav Shahe6194ac2018-07-13 11:04:41 +05308167 hdd_nofl_info("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
8168 hdd_ctx->config->tcp_tx_high_tput_thres);
Tiger Yu8b119e92019-04-09 13:55:07 +08008169#endif /*WLAN_FEATURE_DP_BUS_BANDWIDTH*/
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008170
Nirav Shahe6194ac2018-07-13 11:04:41 +05308171 hdd_nofl_info("Total entries: %d Current index: %d",
8172 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
Nirav Shahda008342016-05-17 18:50:40 +05308173
Nirav Shahe6194ac2018-07-13 11:04:41 +05308174 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 -08008175
8176 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008177 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08008178 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Nirav Shahe6194ac2018-07-13 11:04:41 +05308179 hdd_nofl_info("[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
8180 i, hdd_ctx->hdd_txrx_hist[i].qtime,
8181 hdd_ctx->hdd_txrx_hist[i].interval_rx,
8182 hdd_ctx->hdd_txrx_hist[i].interval_tx,
8183 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008184 hdd_ctx->hdd_txrx_hist[i].
8185 next_vote_level),
Nirav Shahe6194ac2018-07-13 11:04:41 +05308186 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008187 hdd_ctx->hdd_txrx_hist[i].
8188 next_rx_level),
Nirav Shahe6194ac2018-07-13 11:04:41 +05308189 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008190 hdd_ctx->hdd_txrx_hist[i].
8191 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008192 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008193}
8194
8195/**
8196 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
8197 * @hdd_ctx: hdd context
8198 *
8199 * Return: none
8200 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008201void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008202{
8203 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05308204 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
8205 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008206}
8207
Mohit Khannaca4173b2017-09-12 21:52:19 -07008208/* length of the netif queue log needed per adapter */
8209#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
8210
8211/**
8212 *
8213 * hdd_display_netif_queue_history_compact() - display compact netifq history
8214 * @hdd_ctx: hdd context
8215 *
8216 * Return: none
8217 */
8218static void
8219hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
8220{
8221 int adapter_num = 0;
8222 int i;
8223 int bytes_written;
8224 u32 tbytes;
8225 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008226 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08008227 char *comb_log_str;
8228 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008229 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008230
Dustin Brownad06be62019-02-04 14:52:56 -08008231 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * WLAN_MAX_VDEVS) + 1;
jiadbdefb252018-01-03 14:27:06 +08008232 comb_log_str = qdf_mem_malloc(comb_log_str_size);
Min Liu74a1a502018-10-10 19:59:07 +08008233 if (!comb_log_str)
jiadbdefb252018-01-03 14:27:06 +08008234 return;
jiadbdefb252018-01-03 14:27:06 +08008235
Mohit Khannaca4173b2017-09-12 21:52:19 -07008236 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008237
Dustin Brown920397d2017-12-13 16:27:50 -08008238 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07008239 curr_time = qdf_system_ticks();
8240 total = curr_time - adapter->start_time;
8241 delta = curr_time - adapter->last_time;
8242
8243 if (adapter->pause_map) {
8244 pause = adapter->total_pause_time + delta;
8245 unpause = adapter->total_unpause_time;
8246 } else {
8247 unpause = adapter->total_unpause_time + delta;
8248 pause = adapter->total_pause_time;
8249 }
8250
8251 tbytes = 0;
hangtian127c9532019-01-12 13:29:07 +08008252 qdf_mem_zero(temp_str, sizeof(temp_str));
Mohit Khannaca4173b2017-09-12 21:52:19 -07008253 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
8254 if (adapter->queue_oper_stats[i].pause_count == 0)
8255 continue;
8256 tbytes +=
8257 snprintf(
8258 &temp_str[tbytes],
8259 (tbytes >= sizeof(temp_str) ?
8260 0 : sizeof(temp_str) - tbytes),
8261 "%d(%d,%d) ",
8262 i,
8263 adapter->queue_oper_stats[i].
8264 pause_count,
8265 adapter->queue_oper_stats[i].
8266 unpause_count);
8267 }
8268 if (tbytes >= sizeof(temp_str))
8269 hdd_warn("log truncated");
8270
8271 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08008272 bytes_written >= comb_log_str_size ? 0 :
8273 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07008274 "[%d %d] (%d) %u/%ums %s|",
Jeff Johnson5a6fc962019-02-04 14:20:25 -08008275 adapter->vdev_id, adapter->device_mode,
Mohit Khannaca4173b2017-09-12 21:52:19 -07008276 adapter->pause_map,
8277 qdf_system_ticks_to_msecs(pause),
8278 qdf_system_ticks_to_msecs(total),
8279 temp_str);
8280
Mohit Khannaca4173b2017-09-12 21:52:19 -07008281 adapter_num++;
8282 }
8283
8284 /* using QDF_TRACE to avoid printing function name */
8285 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
8286 "STATS |%s", comb_log_str);
8287
jiadbdefb252018-01-03 14:27:06 +08008288 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07008289 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08008290
8291 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07008292}
8293
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008294/* Max size of a single netdev tx queue state string. e.g. "1: 0x1" */
8295#define HDD_NETDEV_TX_Q_STATE_STRLEN 15
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008296/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008297 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07008298 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008299 *
8300 * Return: none
8301 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07008302void
8303wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
8304 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008305{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008306 int i;
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008307 struct hdd_adapter *adapter = NULL;
Nirav Shahda008342016-05-17 18:50:40 +05308308 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008309 struct hdd_netif_queue_history *q_hist_ptr;
8310 char q_status_buf[NUM_TX_QUEUES * HDD_NETDEV_TX_Q_STATE_STRLEN] = {0};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008311
Mohit Khannaca4173b2017-09-12 21:52:19 -07008312 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
8313 hdd_display_netif_queue_history_compact(hdd_ctx);
8314 return;
8315 }
8316
Dustin Brown920397d2017-12-13 16:27:50 -08008317 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008318 if (adapter->vdev_id == CDP_INVALID_VDEV_ID)
8319 continue;
Nirav Shahe6194ac2018-07-13 11:04:41 +05308320 hdd_nofl_info("Netif queue operation statistics:");
Jeff Johnson55d2ab42019-03-06 11:43:49 -08008321 hdd_nofl_info("vdev_id %d device mode %d",
Jeff Johnson5a6fc962019-02-04 14:20:25 -08008322 adapter->vdev_id, adapter->device_mode);
Nirav Shahe6194ac2018-07-13 11:04:41 +05308323 hdd_nofl_info("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05308324 curr_time = qdf_system_ticks();
8325 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05308326 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05308327 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05308328 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05308329 unpause = adapter->total_unpause_time;
8330 } else {
Nirav Shahda008342016-05-17 18:50:40 +05308331 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05308332 pause = adapter->total_pause_time;
8333 }
Nirav Shahe6194ac2018-07-13 11:04:41 +05308334 hdd_nofl_info("Total: %ums Pause: %ums Unpause: %ums",
8335 qdf_system_ticks_to_msecs(total),
8336 qdf_system_ticks_to_msecs(pause),
8337 qdf_system_ticks_to_msecs(unpause));
8338 hdd_nofl_info("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008339
Nirav Shahda008342016-05-17 18:50:40 +05308340 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
8341 qdf_time_t pause_delta = 0;
8342
8343 if (adapter->pause_map & (1 << i))
8344 pause_delta = delta;
8345
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008346 /* using hdd_log to avoid printing function name */
Nirav Shahe6194ac2018-07-13 11:04:41 +05308347 hdd_nofl_info("%s: %d: %d: %ums",
8348 hdd_reason_type_to_string(i),
8349 adapter->queue_oper_stats[i].pause_count,
8350 adapter->queue_oper_stats[i].
8351 unpause_count,
8352 qdf_system_ticks_to_msecs(
8353 adapter->queue_oper_stats[i].
8354 total_pause_time + pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008355 }
8356
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008357 hdd_nofl_info("Netif queue operation history: Total entries: %d current index %d(-1) time %u",
Nirav Shahe6194ac2018-07-13 11:04:41 +05308358 WLAN_HDD_MAX_HISTORY_ENTRY,
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008359 adapter->history_index,
8360 qdf_system_ticks_to_msecs(qdf_system_ticks()));
Nirav Shahda008342016-05-17 18:50:40 +05308361
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008362 hdd_nofl_info("%2s%20s%50s%30s%10s %s",
8363 "#", "time(ms)", "action_type", "reason_type",
8364 "pause_map", "netdev-queue-status");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008365
8366 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008367 /* using hdd_log to avoid printing function name */
8368 if (adapter->queue_oper_history[i].time == 0)
8369 continue;
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008370 q_hist_ptr = &adapter->queue_oper_history[i];
8371 wlan_hdd_dump_queue_history_state(q_hist_ptr,
8372 q_status_buf,
8373 sizeof(q_status_buf));
8374 hdd_nofl_info("%2d%20u%50s%30s%10x %s",
Nirav Shahe6194ac2018-07-13 11:04:41 +05308375 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008376 adapter->queue_oper_history[i].time),
Nirav Shahe6194ac2018-07-13 11:04:41 +05308377 hdd_action_type_to_string(
8378 adapter->queue_oper_history[i].
8379 netif_action),
8380 hdd_reason_type_to_string(
8381 adapter->queue_oper_history[i].
8382 netif_reason),
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008383 adapter->queue_oper_history[i].pause_map,
8384 q_status_buf);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008385 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008386 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008387}
8388
8389/**
8390 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
8391 * @hdd_ctx: hdd context
8392 *
8393 * Return: none
8394 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008395void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008396{
Jeff Johnson9d295242017-08-29 14:39:48 -07008397 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008398
Dustin Brown920397d2017-12-13 16:27:50 -08008399 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308400 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008401 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308402 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008403 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05308404 adapter->history_index = 0;
8405 adapter->start_time = adapter->last_time = qdf_system_ticks();
8406 adapter->total_pause_time = 0;
8407 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008408 }
8409}
8410
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008411#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
8412/**
8413 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
8414 * @hdd_ctx: hdd global context
8415 *
8416 * Return: none
8417 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008418static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008419{
8420 uint8_t i;
8421
8422 mutex_init(&hdd_ctx->op_ctx.op_lock);
8423 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
8424 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
8425 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
8426 }
8427}
8428#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008429static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008430{
8431}
8432#endif
8433
Yingying Tang95409972016-10-20 15:16:15 +08008434#ifdef WLAN_FEATURE_WOW_PULSE
8435/**
8436 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsonfd7d1ef2019-03-31 10:41:37 -07008437 * @hdd_ctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08008438 * @enable: enable or disable this behaviour
8439 *
8440 * Return: int
8441 */
Jeff Johnsonfd7d1ef2019-03-31 10:41:37 -07008442static int wlan_hdd_set_wow_pulse(struct hdd_context *hdd_ctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008443{
Yingying Tang95409972016-10-20 15:16:15 +08008444 struct wow_pulse_mode wow_pulse_set_info;
8445 QDF_STATUS status;
8446
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008447 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08008448
Jeff Johnsonfd7d1ef2019-03-31 10:41:37 -07008449 if (!ucfg_pmo_is_wow_pulse_enabled(hdd_ctx->psoc))
Yingying Tang95409972016-10-20 15:16:15 +08008450 return 0;
8451
8452 /* prepare the request to send to SME */
8453 if (enable == true) {
8454 wow_pulse_set_info.wow_pulse_enable = true;
8455 wow_pulse_set_info.wow_pulse_pin =
Jeff Johnsonfd7d1ef2019-03-31 10:41:37 -07008456 ucfg_pmo_get_wow_pulse_pin(hdd_ctx->psoc);
Wu Gao66454f12018-09-26 19:55:41 +08008457
Yingying Tang95409972016-10-20 15:16:15 +08008458 wow_pulse_set_info.wow_pulse_interval_high =
Jeff Johnsonfd7d1ef2019-03-31 10:41:37 -07008459 ucfg_pmo_get_wow_pulse_interval_high(hdd_ctx->psoc);
Wu Gao66454f12018-09-26 19:55:41 +08008460
8461 wow_pulse_set_info.wow_pulse_interval_low =
Jeff Johnsonfd7d1ef2019-03-31 10:41:37 -07008462 ucfg_pmo_get_wow_pulse_interval_low(hdd_ctx->psoc);
Yingying Tang95409972016-10-20 15:16:15 +08008463 } else {
8464 wow_pulse_set_info.wow_pulse_enable = false;
8465 wow_pulse_set_info.wow_pulse_pin = 0;
8466 wow_pulse_set_info.wow_pulse_interval_low = 0;
8467 wow_pulse_set_info.wow_pulse_interval_high = 0;
8468 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008469 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08008470 wow_pulse_set_info.wow_pulse_enable,
8471 wow_pulse_set_info.wow_pulse_pin,
8472 wow_pulse_set_info.wow_pulse_interval_low,
8473 wow_pulse_set_info.wow_pulse_interval_high);
8474
8475 status = sme_set_wow_pulse(&wow_pulse_set_info);
8476 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008477 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08008478 return -EIO;
8479 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008480 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08008481 return 0;
8482}
8483#else
Jeff Johnsonfd7d1ef2019-03-31 10:41:37 -07008484static inline int wlan_hdd_set_wow_pulse(struct hdd_context *hdd_ctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008485{
8486 return 0;
8487}
8488#endif
8489
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008490#ifdef WLAN_FEATURE_FASTPATH
jitiphil377bcc12018-10-05 19:46:08 +05308491
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008492/**
8493 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
8494 * @hdd_cfg: hdd config
8495 * @context: lower layer context
8496 *
8497 * Return: none
8498 */
jitiphil377bcc12018-10-05 19:46:08 +05308499void hdd_enable_fastpath(struct hdd_context *hdd_ctx,
8500 void *context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008501{
jitiphil377bcc12018-10-05 19:46:08 +05308502 if (cfg_get(hdd_ctx->psoc, CFG_DP_ENABLE_FASTPATH))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008503 hif_enable_fastpath(context);
8504}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008505#endif
8506
Yuanyuan Liu13738502016-04-06 17:41:37 -07008507#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008508/**
8509 * hdd_set_thermal_level_cb() - set thermal level callback function
Jeff Johnson0e963082018-07-04 19:39:20 -07008510 * @hdd_handle: opaque handle for the hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008511 * @level: thermal level
8512 *
8513 * Change IPA data path to SW path when the thermal throttle level greater
8514 * than 0, and restore the original data path when throttle level is 0
8515 *
8516 * Return: none
8517 */
Jeff Johnson0e963082018-07-04 19:39:20 -07008518static void hdd_set_thermal_level_cb(hdd_handle_t hdd_handle, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008519{
Jeff Johnson0e963082018-07-04 19:39:20 -07008520 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008521
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008522 /* Change IPA to SW path when throttle level greater than 0 */
8523 if (level > THROTTLE_LEVEL_0)
Dustin Brown07901ec2018-09-07 11:02:41 -07008524 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->pdev, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008525 else
8526 /* restore original concurrency mode */
Dustin Brown07901ec2018-09-07 11:02:41 -07008527 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->pdev, hdd_ctx->mcc_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008528}
8529
8530/**
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308531 * hdd_get_safe_channel() - Get safe channel from current regulatory
8532 * @hdd_ctx: pointer to hdd context
8533 * @adapter: pointer to softap adapter
8534 *
8535 * This function is used to get safe channel from current regulatory valid
8536 * channels to restart SAP if failed to get safe channel from PCL.
8537 *
8538 * Return: Channel number to restart SAP in case of success. In case of any
8539 * failure, the channel number returned is zero.
8540 */
8541static uint8_t
8542hdd_get_safe_channel(struct hdd_context *hdd_ctx,
8543 struct hdd_adapter *adapter)
8544{
8545 struct sir_pcl_list pcl = {0};
8546 uint32_t i, j;
8547 bool found = false;
8548 int ret;
8549
8550 /* Try for safe channel from all valid channel */
8551 pcl.pcl_len = MAX_NUM_CHAN;
8552 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
8553 &pcl.pcl_len);
8554 if (ret) {
8555 hdd_err("error %d in getting valid channel list", ret);
8556 return INVALID_CHANNEL_ID;
8557 }
8558
8559 for (i = 0; i < pcl.pcl_len; i++) {
8560 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
8561 found = false;
8562 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
8563 if (pcl.pcl_list[i] ==
8564 hdd_ctx->unsafe_channel_list[j]) {
8565 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
8566 found = true;
8567 break;
8568 }
8569 }
8570
8571 if (found)
8572 continue;
8573
8574 if ((pcl.pcl_list[i] >=
8575 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
8576 (pcl.pcl_list[i] <=
8577 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
8578 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
8579 return pcl.pcl_list[i];
8580 }
8581 }
8582
8583 return INVALID_CHANNEL_ID;
8584}
8585
8586#else
8587/**
8588 * hdd_set_thermal_level_cb() - set thermal level callback function
8589 * @hdd_handle: opaque handle for the hdd context
8590 * @level: thermal level
8591 *
8592 * Change IPA data path to SW path when the thermal throttle level greater
8593 * than 0, and restore the original data path when throttle level is 0
8594 *
8595 * Return: none
8596 */
8597static void hdd_set_thermal_level_cb(hdd_handle_t hdd_handle, u_int8_t level)
8598{
8599}
8600
8601/**
8602 * hdd_get_safe_channel() - Get safe channel from current regulatory
8603 * @hdd_ctx: pointer to hdd context
8604 * @adapter: pointer to softap adapter
8605 *
8606 * This function is used to get safe channel from current regulatory valid
8607 * channels to restart SAP if failed to get safe channel from PCL.
8608 *
8609 * Return: Channel number to restart SAP in case of success. In case of any
8610 * failure, the channel number returned is zero.
8611 */
8612static uint8_t
8613hdd_get_safe_channel(struct hdd_context *hdd_ctx,
8614 struct hdd_adapter *adapter)
8615{
8616 return 0;
8617}
8618#endif
8619
8620/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308621 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
8622 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05308623 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008624 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308625 * Get a safe channel to restart SAP. PCL already takes into account the
8626 * unsafe channels. So, the PCL is validated with the ACS range to provide
8627 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008628 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308629 * Return: Channel number to restart SAP in case of success. In case of any
8630 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008631 */
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308632static uint8_t
8633hdd_get_safe_channel_from_pcl_and_acs_range(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008634{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308635 struct sir_pcl_list pcl;
8636 QDF_STATUS status;
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308637 uint32_t i;
Jeff Johnson16528362018-06-14 12:34:16 -07008638 mac_handle_t mac_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008639 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008640
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308641 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8642 if (!hdd_ctx) {
8643 hdd_err("invalid HDD context");
8644 return INVALID_CHANNEL_ID;
8645 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008646
Jeff Johnson16528362018-06-14 12:34:16 -07008647 mac_handle = hdd_ctx->mac_handle;
8648 if (!mac_handle) {
8649 hdd_err("invalid MAC handle");
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05308650 return INVALID_CHANNEL_ID;
8651 }
8652
Dustin Brown1dbefe62018-09-11 16:32:03 -07008653 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008654 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08008655 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
8656 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308657 if (QDF_IS_STATUS_ERROR(status)) {
8658 hdd_err("Get PCL failed");
8659 return INVALID_CHANNEL_ID;
8660 }
8661
Frank Liudc2cefb2017-06-21 15:38:18 +08008662 /*
8663 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
8664 * channel is unsafe channel, the pcl may be empty, instead of return,
8665 * try to choose a safe channel from acs range.
8666 */
8667 if (!pcl.pcl_len)
8668 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308669
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008670 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07008671 adapter->session.ap.sap_config.acs_cfg.start_ch,
8672 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308673
8674 /* PCL already takes unsafe channel into account */
8675 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008676 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308677 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008678 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308679 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008680 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008681 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308682 return pcl.pcl_list[i];
8683 }
8684 }
8685
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008686 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308687
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308688 return hdd_get_safe_channel(hdd_ctx, adapter);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308689}
8690
8691/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008692 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308693 * @adapter: AP adapter
8694 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08008695 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308696 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008697 * Moves the SAP interface by invoking the function which
8698 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308699 *
8700 * Return: None
8701 */
Min Liu2fef5792018-01-19 17:59:42 +08008702void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
8703 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308704{
Jeff Johnson87251032017-08-29 13:31:11 -07008705 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008706 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07008707 mac_handle_t mac_handle;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308708
8709 if (!adapter) {
8710 hdd_err("invalid adapter");
8711 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008712 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308713
8714 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
8715
Jeff Johnson16528362018-06-14 12:34:16 -07008716 mac_handle = hdd_adapter_get_mac_handle(adapter);
8717 if (!mac_handle) {
8718 hdd_err("invalid MAC handle");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308719 return;
8720 }
8721
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008722 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8723
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008724 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07008725 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308726
Dustin Brown1dbefe62018-09-11 16:32:03 -07008727 policy_mgr_change_sap_channel_with_csa(hdd_ctx->psoc,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08008728 adapter->vdev_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08008729 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008730}
Kapil Gupta8878ad92017-02-13 11:56:04 +05308731
Jeff Johnson9d295242017-08-29 14:39:48 -07008732int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05308733{
8734 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308735 int status;
8736 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308737
8738 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8739
8740 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07008741 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05308742 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07008743 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308744 }
8745 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07008746 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308747 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308748 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07008749 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308750 WLAN_VENDOR_ACS_WAIT_TIME);
8751 if (qdf_status != QDF_STATUS_SUCCESS) {
8752 hdd_err("failed to start external acs timer");
8753 return -ENOSPC;
8754 }
8755 /* Update config to application */
8756 status = hdd_cfg80211_update_acs_config(adapter, reason);
Dustin Brown5e89ef82018-03-14 11:50:23 -07008757 hdd_info("Updated ACS config to nl with reason %d", reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308758
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308759 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308760}
8761
Nirav Shaheb017be2018-02-15 11:20:58 +05308762#if defined(FEATURE_WLAN_CH_AVOID)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308763/**
8764 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
8765 * @hdd_ctx: hdd context pointer
8766 *
8767 * hdd_unsafe_channel_restart_sap check all unsafe channel list
8768 * and if ACS is enabled, driver will ask userspace to restart the
8769 * sap. User space on LTE coex indication restart driver.
8770 *
8771 * Return - none
8772 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008773void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308774{
Dustin Brown920397d2017-12-13 16:27:50 -08008775 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308776 uint32_t i;
8777 bool found = false;
8778 uint8_t restart_chan;
Krunal Sonidf29bc42018-11-15 13:26:29 -08008779 uint8_t scc_on_lte_coex = 0;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05308780 bool value;
Harprit Chhabada1eeeb8d2018-09-14 15:16:56 -07008781 QDF_STATUS status;
8782 bool is_acs_support_for_dfs_ltecoex = cfg_default(CFG_USER_ACS_DFS_LTE);
8783 bool is_vendor_acs_support =
8784 cfg_default(CFG_USER_AUTO_CHANNEL_SELECTION);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008785
Dustin Brown920397d2017-12-13 16:27:50 -08008786 hdd_for_each_adapter(hdd_ctxt, adapter) {
8787 if (!(adapter->device_mode == QDF_SAP_MODE &&
8788 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008789 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08008790 adapter->device_mode,
8791 adapter->session.ap.sap_config.
8792 acs_cfg.acs_mode);
8793 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308794 }
8795
8796 found = false;
Krunal Sonidf29bc42018-11-15 13:26:29 -08008797 status =
8798 ucfg_policy_mgr_get_sta_sap_scc_lte_coex_chnl(hdd_ctxt->psoc,
8799 &scc_on_lte_coex);
8800 if (!QDF_IS_STATUS_SUCCESS(status))
8801 hdd_err("can't get scc on lte coex chnl, use def");
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008802 /*
8803 * If STA+SAP is doing SCC & g_sta_sap_scc_on_lte_coex_chan
8804 * is set, no need to move SAP.
8805 */
Manikandan Mohan956b69e2019-02-14 13:08:14 -08008806 if ((policy_mgr_is_sta_sap_scc(
8807 hdd_ctxt->psoc,
8808 adapter->session.ap.operating_channel) &&
8809 scc_on_lte_coex) ||
8810 policy_mgr_nan_sap_scc_on_unsafe_ch_chk(
8811 hdd_ctxt->psoc,
8812 adapter->session.ap.operating_channel)) {
8813 hdd_debug("SAP allowed in unsafe SCC channel");
8814 } else {
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008815 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
8816 if (adapter->session.ap.operating_channel ==
8817 hdd_ctxt->unsafe_channel_list[i]) {
8818 found = true;
8819 hdd_debug("operating ch:%d is unsafe",
8820 adapter->session.ap.operating_channel);
8821 break;
8822 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308823 }
8824 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308825 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008826 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08008827 adapter->session.ap.operating_channel);
8828 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308829 }
8830
Harprit Chhabada1eeeb8d2018-09-14 15:16:56 -07008831 status = ucfg_mlme_get_acs_support_for_dfs_ltecoex(
8832 hdd_ctxt->psoc,
8833 &is_acs_support_for_dfs_ltecoex);
8834 if (!QDF_IS_STATUS_SUCCESS(status))
8835 hdd_err("get_acs_support_for_dfs_ltecoex failed,set def");
8836
8837 status = ucfg_mlme_get_vendor_acs_support(
8838 hdd_ctxt->psoc,
8839 &is_vendor_acs_support);
8840 if (!QDF_IS_STATUS_SUCCESS(status))
8841 hdd_err("get_vendor_acs_support failed, set default");
8842
8843 if (is_vendor_acs_support && is_acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08008844 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05308845 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08008846 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308847 } else
8848 restart_chan =
8849 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08008850 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308851 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008852 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308853 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008854 /*
8855 * SAP restart due to unsafe channel. While
8856 * restarting the SAP, make sure to clear
8857 * acs_channel, channel to reset to
8858 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308859 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008860 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308861 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008862 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308863 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
8864 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Dustin Brown05d81302018-09-11 16:49:22 -07008865 ucfg_mlme_get_sap_internal_restart(hdd_ctxt->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05308866 &value);
8867 hdd_debug("driver to start sap: %d", value);
8868 if (value)
Min Liu2fef5792018-01-19 17:59:42 +08008869 hdd_switch_sap_channel(adapter, restart_chan,
8870 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04008871 else
8872 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308873 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308874 }
8875}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05308876
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008877/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008878 * hdd_init_channel_avoidance() - Initialize channel avoidance
8879 * @hdd_ctx: HDD global context
8880 *
8881 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07008882 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008883 * down to the lower layers. Then subscribe to subsequent channel
8884 * avoidance events.
8885 *
8886 * Return: None
8887 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008888static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008889{
8890 uint16_t unsafe_channel_count;
8891 int index;
8892
Yuanyuan Liu13738502016-04-06 17:41:37 -07008893 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
8894 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008895 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08008896 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008897
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008898 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008899 hdd_ctx->unsafe_channel_count);
8900
Anurag Chouhan6d760662016-02-20 16:05:43 +05308901 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08008902 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008903
8904 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008905 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008906 hdd_ctx->unsafe_channel_list[index]);
8907
8908 }
8909
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008910}
Dustin Brown676a2322017-08-15 13:16:13 -07008911
Jeff Johnson9d295242017-08-29 14:39:48 -07008912static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008913 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008914{
8915 uint8_t restart_chan;
8916
8917 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
8918 if (!restart_chan) {
8919 hdd_alert("fail to restart SAP");
8920 return;
8921 }
8922
8923 /* SAP restart due to unsafe channel. While restarting
8924 * the SAP, make sure to clear acs_channel, channel to
8925 * reset to 0. Otherwise these settings will override
8926 * the ACS while restart.
8927 */
8928 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07008929
8930 hdd_debug("sending coex indication");
8931
8932 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
8933 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08008934 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07008935}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008936
8937int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
8938 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
8939{
8940 uint32_t size;
8941 uint16_t *unsafe_list;
8942 uint16_t chan_count;
8943
8944 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
8945 return -EINVAL;
8946
8947 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
8948 NUM_CHANNELS);
8949 if (chan_count) {
8950 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
8951 unsafe_list = qdf_mem_malloc(size);
Min Liu74a1a502018-10-10 19:59:07 +08008952 if (!unsafe_list)
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008953 return -ENOMEM;
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008954 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
8955 } else {
8956 unsafe_list = NULL;
8957 }
8958
8959 *local_unsafe_list = unsafe_list;
8960 *local_unsafe_list_count = chan_count;
8961
8962 return 0;
8963}
8964
8965bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
8966 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
8967{
8968 int i, j;
8969
8970 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
8971 return true;
8972 if (local_unsafe_list_count == 0)
8973 return false;
8974 for (i = 0; i < local_unsafe_list_count; i++) {
8975 for (j = 0; j < local_unsafe_list_count; j++)
8976 if (local_unsafe_list[i] ==
8977 hdd_ctx->unsafe_channel_list[j])
8978 break;
8979 if (j >= local_unsafe_list_count)
8980 break;
8981 }
8982 if (i >= local_unsafe_list_count) {
8983 hdd_info("unsafe chan list same");
8984 return false;
8985 }
8986
8987 return true;
8988}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008989#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008990static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008991{
8992}
Dustin Brown676a2322017-08-15 13:16:13 -07008993
Jeff Johnson9d295242017-08-29 14:39:48 -07008994static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008995 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008996{
8997 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
8998}
Yuanyuan Liu13738502016-04-06 17:41:37 -07008999#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009000
9001/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08009002 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
9003 * user space
9004 * @frame_ind: Management frame data to be informed.
9005 *
9006 * This function is used to indicate management frame to
9007 * user space
9008 *
9009 * Return: None
9010 *
9011 */
9012void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
9013{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009014 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07009015 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08009016 int i;
Pragaspathi Thilagaraj28ffc042018-07-18 15:19:36 +05309017 struct ieee80211_mgmt *mgmt =
9018 (struct ieee80211_mgmt *)frame_ind->frameBuf;
Rajeev Kumard004abc2016-02-17 12:09:56 -08009019
Dustin Browne7e71d32018-05-11 16:00:08 -07009020 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9021 if (wlan_hdd_validate_context(hdd_ctx))
Rajeev Kumard004abc2016-02-17 12:09:56 -08009022 return;
9023
Pragaspathi Thilagaraj28ffc042018-07-18 15:19:36 +05309024 if (frame_ind->frame_len < ieee80211_hdrlen(mgmt->frame_control)) {
9025 hdd_err(" Invalid frame length");
9026 return;
9027 }
9028
Rajeev Kumard004abc2016-02-17 12:09:56 -08009029 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
Dustin Brownad06be62019-02-04 14:52:56 -08009030 for (i = 0; i < WLAN_MAX_VDEVS; i++) {
Rajeev Kumard004abc2016-02-17 12:09:56 -08009031 adapter =
Jeff Johnson55d2ab42019-03-06 11:43:49 -08009032 hdd_get_adapter_by_vdev(hdd_ctx, i);
Rajeev Kumard004abc2016-02-17 12:09:56 -08009033 if (adapter)
9034 break;
9035 }
Wu Gaoa0230a62018-01-04 20:56:57 +08009036 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
9037 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnsond36fa332019-03-18 13:42:25 -07009038 if ((adapter) &&
Wu Gaoa0230a62018-01-04 20:56:57 +08009039 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
9040 __hdd_indicate_mgmt_frame(adapter,
9041 frame_ind->frame_len,
9042 frame_ind->frameBuf,
9043 frame_ind->frameType,
9044 frame_ind->rxChan,
Srinivas Dasariea1c1332019-02-18 12:43:23 +05309045 frame_ind->rxRssi,
9046 frame_ind->rx_flags);
Wu Gaoa0230a62018-01-04 20:56:57 +08009047 }
9048 }
9049 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08009050 } else {
Jeff Johnson55d2ab42019-03-06 11:43:49 -08009051 adapter = hdd_get_adapter_by_vdev(hdd_ctx,
9052 frame_ind->sessionId);
Rajeev Kumard004abc2016-02-17 12:09:56 -08009053 }
9054
Jeff Johnsond36fa332019-03-18 13:42:25 -07009055 if ((adapter) &&
Rajeev Kumard004abc2016-02-17 12:09:56 -08009056 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
9057 __hdd_indicate_mgmt_frame(adapter,
9058 frame_ind->frame_len,
9059 frame_ind->frameBuf,
9060 frame_ind->frameType,
9061 frame_ind->rxChan,
Srinivas Dasariea1c1332019-02-18 12:43:23 +05309062 frame_ind->rxRssi,
9063 frame_ind->rx_flags);
Rajeev Kumard004abc2016-02-17 12:09:56 -08009064}
9065
Kapil Gupta8878ad92017-02-13 11:56:04 +05309066void hdd_acs_response_timeout_handler(void *context)
9067{
9068 struct hdd_external_acs_timer_context *timer_context =
9069 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07009070 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009071 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05309072 uint8_t reason;
9073
Dustin Brown491d54b2018-03-14 12:39:11 -07009074 hdd_enter();
Kapil Gupta8878ad92017-02-13 11:56:04 +05309075 if (!timer_context) {
9076 hdd_err("invlaid timer context");
9077 return;
9078 }
9079 adapter = timer_context->adapter;
9080 reason = timer_context->reason;
9081
9082
9083 if ((!adapter) ||
9084 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
9085 hdd_err("invalid adapter or adapter has invalid magic");
9086 return;
9087 }
9088 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
9089 if (wlan_hdd_validate_context(hdd_ctx))
9090 return;
9091
9092 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
9093 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
9094 else
9095 return;
9096
9097 hdd_err("ACS timeout happened for %s reason %d",
9098 adapter->dev->name, reason);
Jeff Johnson16528362018-06-14 12:34:16 -07009099
Kapil Gupta8878ad92017-02-13 11:56:04 +05309100 switch (reason) {
9101 /* SAP init case */
9102 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
9103 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
9104 false);
9105 wlan_hdd_cfg80211_start_acs(adapter);
9106 break;
9107 /* DFS detected on current channel */
9108 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
9109 wlan_sap_update_next_channel(
9110 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
Jeff Johnson16528362018-06-14 12:34:16 -07009111 sme_update_new_channel_event(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08009112 adapter->vdev_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05309113 break;
9114 /* LTE coex event on current channel */
9115 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
9116 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
9117 break;
9118 default:
9119 hdd_info("invalid reason for timer invoke");
9120
9121 }
9122}
9123
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009124/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009125 * hdd_override_ini_config - Override INI config
9126 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009127 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009128 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009129 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009130 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009131 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009132static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009133{
Abhinav Kumard4d6eb72018-12-04 20:30:37 +05309134 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009135
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009136 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
gaurank kathpalia97c070b2019-01-07 17:23:06 +05309137 ucfg_scan_cfg_set_dfs_chan_scan_allowed(hdd_ctx->psoc,
9138 enable_dfs_chan_scan);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009139 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009140 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009141 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009142 if (0 == enable_11d || 1 == enable_11d) {
Abhinav Kumard4d6eb72018-12-04 20:30:37 +05309143 status = ucfg_mlme_set_11d_enabled(hdd_ctx->psoc, enable_11d);
9144 if (!QDF_IS_STATUS_SUCCESS(status))
9145 hdd_err("Failed to set 11d_enable flag");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009146 }
Leo Chang11545d62016-10-17 14:53:50 -07009147
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +05309148 if (hdd_ctx->config->action_oui_enable && !ucfg_action_oui_enabled()) {
9149 hdd_ctx->config->action_oui_enable = 0;
Sourav Mohapatra58841062018-11-19 16:33:27 +05309150 hdd_err("Ignore action oui ini, since no action_oui component");
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +05309151 }
Will Huang14b120f2019-01-14 17:26:14 +08009152
9153 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
9154 hdd_override_all_ps(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009155}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009156
Ashish Kumar Dhanotiya12f68212018-09-04 22:00:14 +05309157#ifdef ENABLE_MTRACE_LOG
9158static void hdd_set_mtrace_for_each(struct hdd_context *hdd_ctx)
9159{
9160 uint8_t module_id = 0;
9161 int qdf_print_idx = -1;
9162
9163 qdf_print_idx = qdf_get_pidx();
9164 for (module_id = 0; module_id < QDF_MODULE_ID_MAX; module_id++)
9165 qdf_print_set_category_verbose(
9166 qdf_print_idx,
9167 module_id, QDF_TRACE_LEVEL_TRACE,
9168 hdd_ctx->config->enable_mtrace);
9169}
9170#else
9171static void hdd_set_mtrace_for_each(struct hdd_context *hdd_ctx)
9172{
9173}
9174
9175#endif
9176
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009177/**
9178 * hdd_set_trace_level_for_each - Set trace level for each INI config
9179 * @hdd_ctx - HDD context
9180 *
9181 * Set trace level for each module based on INI config.
9182 *
9183 * Return: None
9184 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009185static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009186{
Wu Gaobc6eaa12018-11-30 14:17:45 +08009187 hdd_qdf_trace_enable(QDF_MODULE_ID_DP, 0x7f);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05309188 hdd_qdf_trace_enable(QDF_MODULE_ID_MLME, 0xffff);
Sourav Mohapatra113685f2018-08-29 14:21:55 +05309189 hdd_qdf_trace_enable(QDF_MODULE_ID_FWOL, 0xffff);
Kiran Kumar Lokere4ce40482018-08-30 16:31:00 -07009190 hdd_qdf_trace_enable(QDF_MODULE_ID_CRYPTO, 0xffff);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07009191
Ashish Kumar Dhanotiya12f68212018-09-04 22:00:14 +05309192 hdd_set_mtrace_for_each(hdd_ctx);
9193
Nirav Shah5c083da2018-08-03 13:46:02 +05309194 hdd_cfg_print_global_config(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009195}
9196
9197/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009198 * hdd_context_init() - Initialize HDD context
9199 * @hdd_ctx: HDD context.
9200 *
9201 * Initialize HDD context along with all the feature specific contexts.
9202 *
9203 * return: 0 on success and errno on failure.
9204 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009205static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009206{
9207 int ret;
9208
9209 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
Dustin Brownad06be62019-02-04 14:52:56 -08009210 hdd_ctx->max_intf_count = WLAN_MAX_VDEVS;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009211
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009212 init_completion(&hdd_ctx->mc_sus_event_var);
9213 init_completion(&hdd_ctx->ready_to_suspend);
9214
9215 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009216 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05309217
Dustin Brownbee82832018-07-23 10:10:51 -07009218 qdf_list_create(&hdd_ctx->hdd_adapters, 0);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009219
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009220 ret = hdd_scan_context_init(hdd_ctx);
9221 if (ret)
9222 goto list_destroy;
9223
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009224 hdd_rx_wake_lock_create(hdd_ctx);
9225
9226 ret = hdd_sap_context_init(hdd_ctx);
9227 if (ret)
9228 goto scan_destroy;
9229
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009230 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
9231
9232 hdd_init_offloaded_packets_ctx(hdd_ctx);
9233
9234 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
9235 hdd_ctx->config);
9236 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08009237 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009238
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05309239 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
9240 "monitor_mode_wakelock");
9241
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009242 return 0;
9243
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009244sap_destroy:
9245 hdd_sap_context_destroy(hdd_ctx);
9246
9247scan_destroy:
9248 hdd_scan_context_destroy(hdd_ctx);
9249 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009250list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07009251 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08009252
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009253 return ret;
9254}
9255
Dustin Brown4c663222018-10-23 14:19:36 -07009256void hdd_psoc_idle_timer_start(struct hdd_context *hdd_ctx)
9257{
9258 uint32_t timeout_ms = hdd_ctx->config->iface_change_wait_time;
9259 enum wake_lock_reason reason =
9260 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER;
9261
Rajeev Kumar7b7bb3f2018-12-20 12:09:54 -08009262 if (!timeout_ms) {
9263 hdd_info("psoc idle timer is disabled");
9264 return;
9265 }
9266
Dustin Brown4c663222018-10-23 14:19:36 -07009267 hdd_debug("Starting psoc idle timer");
Dustin Brown8d8ab302019-03-05 16:19:36 -08009268 qdf_delayed_work_start(&hdd_ctx->psoc_idle_timeout_work, timeout_ms);
Dustin Brown4c663222018-10-23 14:19:36 -07009269 hdd_prevent_suspend_timeout(timeout_ms, reason);
9270}
9271
9272void hdd_psoc_idle_timer_stop(struct hdd_context *hdd_ctx)
9273{
Dustin Brown8d8ab302019-03-05 16:19:36 -08009274 qdf_delayed_work_stop_sync(&hdd_ctx->psoc_idle_timeout_work);
Dustin Brown4c663222018-10-23 14:19:36 -07009275 hdd_debug("Stopped psoc idle timer");
9276}
9277
Sourav Mohapatra698d6f62019-01-29 14:49:52 +05309278/*
9279 * enum hdd_block_shutdown - Control if driver allows modem shutdown
9280 * @HDD_UNBLOCK_MODEM_SHUTDOWN: Unblock shutdown
9281 * @HDD_BLOCK_MODEM_SHUTDOWN: Block shutdown
9282 *
9283 * On calling pld_block_shutdown API with the given values, modem
9284 * graceful shutdown is blocked/unblocked.
9285 */
9286enum hdd_block_shutdown {
9287 HDD_UNBLOCK_MODEM_SHUTDOWN,
9288 HDD_BLOCK_MODEM_SHUTDOWN,
9289};
9290
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009291/**
Dustin Brown3ecc8782018-09-19 16:37:13 -07009292 * hdd_psoc_idle_shutdown() - perform an idle shutdown on the given psoc
9293 * @hdd_ctx: the hdd context which should be shutdown
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309294 *
Dustin Brown3ecc8782018-09-19 16:37:13 -07009295 * When no interfaces are "up" on a psoc, an idle shutdown timer is started.
9296 * If no interfaces are brought up before the timer expires, we do an
9297 * "idle shutdown," cutting power to the physical SoC to save power. This is
9298 * done completely transparently from the perspective of userspace.
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309299 *
Dustin Brown3ecc8782018-09-19 16:37:13 -07009300 * Return: None
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309301 */
Dustin Brown3ecc8782018-09-19 16:37:13 -07009302static void hdd_psoc_idle_shutdown(struct hdd_context *hdd_ctx)
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309303{
Dustin Brown363b4792019-02-05 16:11:55 -08009304 struct osif_psoc_sync *psoc_sync;
Dustin Browncfcb5762019-01-31 15:43:45 -08009305 int errno;
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309306
Dustin Brown491d54b2018-03-14 12:39:11 -07009307 hdd_enter();
Dustin Brown3ecc8782018-09-19 16:37:13 -07009308
Dustin Brown363b4792019-02-05 16:11:55 -08009309 errno = osif_psoc_sync_trans_start(hdd_ctx->parent_dev, &psoc_sync);
Dustin Browncfcb5762019-01-31 15:43:45 -08009310 if (errno) {
9311 hdd_info("psoc busy, abort idle shutdown; errno:%d", errno);
9312 goto exit;
Dustin Brown3ecc8782018-09-19 16:37:13 -07009313 }
Sourav Mohapatra698d6f62019-01-29 14:49:52 +05309314 /* Block the modem graceful shutdown till stop modules is completed */
9315 pld_block_shutdown(hdd_ctx->parent_dev, HDD_BLOCK_MODEM_SHUTDOWN);
Dustin Brown3ecc8782018-09-19 16:37:13 -07009316
Dustin Brown363b4792019-02-05 16:11:55 -08009317 osif_psoc_sync_wait_for_ops(psoc_sync);
Dustin Browncfcb5762019-01-31 15:43:45 -08009318
Dustin Brown3ecc8782018-09-19 16:37:13 -07009319 QDF_BUG(!hdd_wlan_stop_modules(hdd_ctx, false));
9320
Dustin Brown363b4792019-02-05 16:11:55 -08009321 osif_psoc_sync_trans_stop(psoc_sync);
Dustin Brown3ecc8782018-09-19 16:37:13 -07009322
Sourav Mohapatra698d6f62019-01-29 14:49:52 +05309323 pld_block_shutdown(hdd_ctx->parent_dev, HDD_UNBLOCK_MODEM_SHUTDOWN);
9324
Dustin Browncfcb5762019-01-31 15:43:45 -08009325exit:
Dustin Browne74003f2018-03-14 12:51:58 -07009326 hdd_exit();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309327}
9328
Dustin Brown3ecc8782018-09-19 16:37:13 -07009329int hdd_psoc_idle_restart(struct hdd_context *hdd_ctx)
9330{
Dustin Brown693b5352019-01-17 10:00:31 -08009331 QDF_BUG(rtnl_is_locked());
Dustin Brown3ecc8782018-09-19 16:37:13 -07009332
Dustin Browncfcb5762019-01-31 15:43:45 -08009333 return hdd_wlan_start_modules(hdd_ctx, false);
Dustin Brown3ecc8782018-09-19 16:37:13 -07009334}
9335
9336/**
9337 * hdd_psoc_idle_timeout_callback() - Handler for psoc idle timeout
9338 * @priv: pointer to hdd context
9339 *
9340 * Return: None
9341 */
9342static void hdd_psoc_idle_timeout_callback(void *priv)
9343{
9344 struct hdd_context *hdd_ctx = priv;
9345
9346 if (wlan_hdd_validate_context(hdd_ctx))
9347 return;
9348
9349 hdd_debug("Psoc idle timeout elapsed; starting psoc shutdown");
9350 hdd_psoc_idle_shutdown(hdd_ctx);
9351}
9352
Nirav Shaheb017be2018-02-15 11:20:58 +05309353#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9354static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
9355{
9356 wlan_logging_set_log_to_console(hdd_ctx->config->
9357 wlan_logging_to_console);
9358 wlan_logging_set_active(hdd_ctx->config->wlan_logging_enable);
9359}
9360#else
9361static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
9362{ }
9363#endif
9364
Dundi Raviteja8e338282018-09-25 17:16:04 +05309365#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9366static void hdd_init_wlan_logging_params(struct hdd_config *config,
9367 struct wlan_objmgr_psoc *psoc)
9368{
9369 config->wlan_logging_enable = cfg_get(psoc, CFG_WLAN_LOGGING_SUPPORT);
9370
9371 config->wlan_logging_to_console =
9372 cfg_get(psoc, CFG_WLAN_LOGGING_CONSOLE_SUPPORT);
9373}
9374#else
9375static void hdd_init_wlan_logging_params(struct hdd_config *config,
9376 struct wlan_objmgr_psoc *psoc)
9377{
9378}
9379#endif
9380
9381#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9382static void hdd_init_wlan_auto_shutdown(struct hdd_config *config,
9383 struct wlan_objmgr_psoc *psoc)
9384{
9385 config->wlan_auto_shutdown = cfg_get(psoc, CFG_WLAN_AUTO_SHUTDOWN);
9386}
9387#else
9388static void hdd_init_wlan_auto_shutdown(struct hdd_config *config,
9389 struct wlan_objmgr_psoc *psoc)
9390{
9391}
9392#endif
9393
9394#ifndef REMOVE_PKT_LOG
9395static void hdd_init_packet_log(struct hdd_config *config,
9396 struct wlan_objmgr_psoc *psoc)
9397{
9398 config->enable_packet_log = cfg_get(psoc, CFG_ENABLE_PACKET_LOG);
9399}
9400#else
9401static void hdd_init_packet_log(struct hdd_config *config,
9402 struct wlan_objmgr_psoc *psoc)
9403{
9404}
9405#endif
9406
Sandeep Puligilla43b6d1a2018-12-03 09:16:13 -08009407#ifdef ENABLE_MTRACE_LOG
9408static void hdd_init_mtrace_log(struct hdd_config *config,
9409 struct wlan_objmgr_psoc *psoc)
9410{
9411 config->enable_mtrace = cfg_get(psoc, CFG_ENABLE_MTRACE);
9412}
9413#else
9414static void hdd_init_mtrace_log(struct hdd_config *config,
9415 struct wlan_objmgr_psoc *psoc)
9416{
9417}
9418#endif
9419
Sourav Mohapatra0dfe5552018-11-16 11:29:54 +05309420#ifdef FEATURE_RUNTIME_PM
9421static void hdd_init_runtime_pm(struct hdd_config *config,
9422 struct wlan_objmgr_psoc *psoc)
9423{
9424 config->runtime_pm = cfg_get(psoc, CFG_ENABLE_RUNTIME_PM);
9425}
9426#else
9427static void hdd_init_runtime_pm(struct hdd_config *config,
9428 struct wlan_objmgr_psoc *psoc)
9429
9430{
9431}
9432#endif
9433
9434#ifdef FEATURE_WLAN_DYNAMIC_CVM
9435static void hdd_init_vc_mode_cfg_bitmap(struct hdd_config *config,
9436 struct wlan_objmgr_psoc *psoc)
9437{
9438 config->vc_mode_cfg_bitmap = cfg_get(psoc, CFG_VC_MODE_BITMAP);
9439}
9440#else
9441static void hdd_init_vc_mode_cfg_bitmap(struct hdd_config *config,
9442 struct wlan_objmgr_psoc *psoc)
9443{
9444}
9445#endif
9446
gaurank kathpalia566c81b2019-02-20 14:31:45 +05309447#ifdef DHCP_SERVER_OFFLOAD
9448static void
9449hdd_init_dhcp_server_ip(struct hdd_context *hdd_ctx)
9450{
9451 uint8_t num_entries;
9452
9453 hdd_ctx->config->dhcp_server_ip.is_dhcp_server_ip_valid = true;
9454 hdd_string_to_u8_array(cfg_get(hdd_ctx->psoc, CFG_DHCP_SERVER_IP_NAME),
9455 hdd_ctx->config->dhcp_server_ip.dhcp_server_ip,
9456 &num_entries, IPADDR_NUM_ENTRIES);
9457
9458 if (num_entries != IPADDR_NUM_ENTRIES) {
9459 hdd_err("Incorrect IP address (%s) assigned for DHCP server!",
9460 cfg_get(hdd_ctx->psoc, CFG_DHCP_SERVER_IP_NAME));
9461 hdd_config->dhcp_server_ip.is_dhcp_server_ip_valid = false;
9462 }
9463}
9464#else
9465static void
9466hdd_init_dhcp_server_ip(struct hdd_context *hdd_ctx)
9467{
9468}
9469#endif
9470
Dundi Raviteja8e338282018-09-25 17:16:04 +05309471/**
9472 * hdd_cfg_params_init() - Initialize hdd params in hdd_config strucuture
9473 * @hdd_ctx - Pointer to HDD context
9474 *
9475 * Return: None
9476 */
9477static void hdd_cfg_params_init(struct hdd_context *hdd_ctx)
9478{
9479 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
9480 struct hdd_config *config = hdd_ctx->config;
9481
9482 if (!psoc) {
9483 hdd_err("Invalid psoc");
9484 return;
9485 }
9486
9487 if (!config) {
9488 hdd_err("Invalid hdd config");
9489 return;
9490 }
9491
gaurank kathpalia43c52622019-02-11 12:30:05 +05309492 config->dot11Mode = cfg_get(psoc, CFG_HDD_DOT11_MODE);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309493 config->bug_on_reinit_failure = cfg_get(psoc,
9494 CFG_BUG_ON_REINIT_FAILURE);
9495
9496 config->is_ramdump_enabled = cfg_get(psoc,
9497 CFG_ENABLE_RAMDUMP_COLLECTION);
9498
9499 config->iface_change_wait_time = cfg_get(psoc,
9500 CFG_INTERFACE_CHANGE_WAIT);
9501
9502 config->multicast_host_fw_msgs = cfg_get(psoc,
9503 CFG_MULTICAST_HOST_FW_MSGS);
9504
9505 config->private_wext_control = cfg_get(psoc, CFG_PRIVATE_WEXT_CONTROL);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309506 config->enablefwprint = cfg_get(psoc, CFG_ENABLE_FW_UART_PRINT);
9507 config->enable_fw_log = cfg_get(psoc, CFG_ENABLE_FW_LOG);
Vignesh Viswanathana0358ff2018-11-27 09:53:07 +05309508 config->operating_channel = cfg_get(psoc, CFG_OPERATING_CHANNEL);
9509 config->num_vdevs = cfg_get(psoc, CFG_NUM_VDEV_ENABLE);
Vignesh Viswanathana0358ff2018-11-27 09:53:07 +05309510 qdf_str_lcopy(config->enable_concurrent_sta,
9511 cfg_get(psoc, CFG_ENABLE_CONCURRENT_STA),
9512 CFG_CONCURRENT_IFACE_MAX_LEN);
9513 qdf_str_lcopy(config->dbs_scan_selection,
9514 cfg_get(psoc, CFG_DBS_SCAN_SELECTION),
9515 CFG_DBS_SCAN_PARAM_LENGTH);
Sourav Mohapatra0dfe5552018-11-16 11:29:54 +05309516 config->inform_bss_rssi_raw = cfg_get(psoc, CFG_INFORM_BSS_RSSI_RAW);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05309517 config->mac_provision = cfg_get(psoc, CFG_ENABLE_MAC_PROVISION);
9518 config->provisioned_intf_pool =
9519 cfg_get(psoc, CFG_PROVISION_INTERFACE_POOL);
9520 config->derived_intf_pool = cfg_get(psoc, CFG_DERIVED_INTERFACE_POOL);
Sourav Mohapatra58841062018-11-19 16:33:27 +05309521 config->action_oui_enable = cfg_get(psoc, CFG_ENABLE_ACTION_OUI);
Jeff Johnson15a88ac2019-03-11 14:35:25 -07009522 config->advertise_concurrent_operation =
Sandeep Puligilladc6d68a2019-01-04 16:57:12 -08009523 cfg_get(psoc,
9524 CFG_ADVERTISE_CONCURRENT_OPERATION);
Sourav Mohapatra58841062018-11-19 16:33:27 +05309525 qdf_str_lcopy(config->action_oui_str[0],
9526 cfg_get(psoc, CFG_ACTION_OUI_CONNECT_1X1),
9527 ACTION_OUI_MAX_STR_LEN);
9528 qdf_str_lcopy(config->action_oui_str[1],
9529 cfg_get(psoc, CFG_ACTION_OUI_ITO_EXTENSION),
9530 ACTION_OUI_MAX_STR_LEN);
9531 qdf_str_lcopy(config->action_oui_str[2],
9532 cfg_get(psoc, CFG_ACTION_OUI_CCKM_1X1),
9533 ACTION_OUI_MAX_STR_LEN);
9534 qdf_str_lcopy(config->action_oui_str[3],
9535 cfg_get(psoc, CFG_ACTION_OUI_ITO_ALTERNATE),
9536 ACTION_OUI_MAX_STR_LEN);
9537 qdf_str_lcopy(config->action_oui_str[4],
9538 cfg_get(psoc, CFG_ACTION_OUI_SWITCH_TO_11N_MODE),
9539 ACTION_OUI_MAX_STR_LEN);
9540 qdf_str_lcopy(config->action_oui_str[5],
9541 cfg_get(psoc,
9542 CFG_ACTION_OUI_CONNECT_1X1_WITH_1_CHAIN),
9543 ACTION_OUI_MAX_STR_LEN);
Rajeev Kumar Sirasanagandlad7987f12018-12-08 23:24:04 +05309544 qdf_str_lcopy(config->action_oui_str[6],
9545 cfg_get(psoc,
9546 CFG_ACTION_OUI_DISABLE_AGGRESSIVE_TX),
9547 ACTION_OUI_MAX_STR_LEN);
Sourav Mohapatra9e014cf2018-12-11 09:39:33 +05309548 config->enable_rtt_support = cfg_get(psoc, CFG_ENABLE_RTT_SUPPORT);
Sandeep Puligillaefeb4a92019-01-08 00:06:51 -08009549 config->is_unit_test_framework_enabled =
9550 cfg_get(psoc, CFG_ENABLE_UNIT_TEST_FRAMEWORK);
Ashish Kumar Dhanotiyad63d6862019-03-14 18:54:10 +05309551 config->disable_channel = cfg_get(psoc, CFG_ENABLE_DISABLE_CHANNEL);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309552
Sourav Mohapatra0dfe5552018-11-16 11:29:54 +05309553 hdd_init_vc_mode_cfg_bitmap(config, psoc);
9554 hdd_init_runtime_pm(config, psoc);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309555 hdd_init_wlan_auto_shutdown(config, psoc);
9556 hdd_init_wlan_logging_params(config, psoc);
9557 hdd_init_packet_log(config, psoc);
Sandeep Puligilla43b6d1a2018-12-03 09:16:13 -08009558 hdd_init_mtrace_log(config, psoc);
gaurank kathpalia566c81b2019-02-20 14:31:45 +05309559 hdd_init_dhcp_server_ip(hdd_ctx);
jitiphil869b9f72018-09-25 17:14:01 +05309560 hdd_dp_cfg_update(psoc, hdd_ctx);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309561}
9562
Dustin Brown623e7e32018-09-05 14:27:50 -07009563struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009564{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309565 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009566 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009567 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009568
Dustin Brown491d54b2018-03-14 12:39:11 -07009569 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009570
Dustin Brown92bd8382018-10-31 15:49:46 -07009571 hdd_ctx = hdd_cfg80211_wiphy_alloc();
9572 if (!hdd_ctx) {
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009573 ret = -ENOMEM;
9574 goto err_out;
9575 }
9576
Dustin Brown8d8ab302019-03-05 16:19:36 -08009577 status = qdf_delayed_work_create(&hdd_ctx->psoc_idle_timeout_work,
9578 hdd_psoc_idle_timeout_callback,
9579 hdd_ctx);
9580 if (QDF_IS_STATUS_ERROR(status)) {
9581 ret = qdf_status_to_os_return(status);
9582 goto wiphy_dealloc;
9583 }
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309584
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009585 hdd_ctx->parent_dev = dev;
Jeff Johnson995fd512019-03-06 08:45:10 -08009586 hdd_ctx->last_scan_reject_vdev_id = WLAN_UMAC_VDEV_ID_MAX;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009587
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309588 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Min Liu74a1a502018-10-10 19:59:07 +08009589 if (!hdd_ctx->config) {
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009590 ret = -ENOMEM;
9591 goto err_free_hdd_context;
9592 }
9593
9594 /* Read and parse the qcom_cfg.ini file */
9595 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309596 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309597 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009598 WLAN_INI_FILE);
9599 ret = -EINVAL;
9600 goto err_free_config;
9601 }
9602
Dustin Brown84f46ea2018-02-15 11:57:36 -08009603 status = cfg_parse(WLAN_INI_FILE);
9604 if (QDF_IS_STATUS_ERROR(status))
9605 hdd_err("Failed to parse cfg %s; status:%d\n",
9606 WLAN_INI_FILE, status);
9607
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309608 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx, DEFAULT_PSOC_ID);
9609 if (ret) {
Dundi Raviteja8e338282018-09-25 17:16:04 +05309610 QDF_DEBUG_PANIC("Psoc creation fails!");
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309611 goto err_free_config;
9612 }
9613
Dundi Raviteja8e338282018-09-25 17:16:04 +05309614 hdd_cfg_params_init(hdd_ctx);
9615
Dustin Brown4bbd5462019-03-22 11:18:13 -07009616 /* apply multiplier config, if not already set via module parameter */
9617 if (qdf_timer_get_multiplier() == 1)
9618 qdf_timer_set_multiplier(cfg_get(hdd_ctx->psoc,
9619 CFG_TIMER_MULTIPLIER));
Dustin Browna9a84522019-02-04 12:25:40 -08009620 hdd_debug("set timer multiplier: %u", qdf_timer_get_multiplier());
Dustin Brown7f939932017-05-18 15:02:17 -07009621
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309622 cds_set_fatal_event(cfg_get(hdd_ctx->psoc,
9623 CFG_ENABLE_FATAL_EVENT_TRIGGER));
Abhishek Singh5ea86532016-04-27 14:10:53 +05309624
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009625 hdd_override_ini_config(hdd_ctx);
9626
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009627 ret = hdd_context_init(hdd_ctx);
9628
9629 if (ret)
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309630 goto err_hdd_objmgr_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009631
Nirav Shah6aeecf92019-02-13 14:05:03 +05309632 if (hdd_get_conparam() == QDF_GLOBAL_FTM_MODE ||
9633 hdd_get_conparam() == QDF_GLOBAL_EPPING_MODE)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009634 goto skip_multicast_logging;
9635
9636 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
9637
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07009638 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
9639 if (ret)
9640 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05309641
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009642 ret = hdd_init_netlink_services(hdd_ctx);
9643 if (ret)
9644 goto err_deinit_txrx_histogram;
9645
Nirav Shaheb017be2018-02-15 11:20:58 +05309646 hdd_set_wlan_logging(hdd_ctx);
Nirav Shahed34b212016-04-25 10:59:16 +05309647
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009648skip_multicast_logging:
9649 hdd_set_trace_level_for_each(hdd_ctx);
9650
Rajeev Kumar493a31b2017-09-29 14:01:24 -07009651 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
9652
Dustin Browne74003f2018-03-14 12:51:58 -07009653 hdd_exit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07009654
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009655 return hdd_ctx;
9656
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009657err_deinit_txrx_histogram:
9658 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
9659
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07009660err_deinit_hdd_context:
9661 hdd_context_deinit(hdd_ctx);
9662
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309663err_hdd_objmgr_destroy:
9664 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9665
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009666err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309667 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009668
9669err_free_hdd_context:
Dustin Brown8d8ab302019-03-05 16:19:36 -08009670 qdf_delayed_work_destroy(&hdd_ctx->psoc_idle_timeout_work);
9671
9672wiphy_dealloc:
Rajeev Kumarfa55a692018-01-09 14:12:41 -08009673 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009674
9675err_out:
9676 return ERR_PTR(ret);
9677}
9678
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009679/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309680 * hdd_start_station_adapter()- Start the Station Adapter
9681 * @adapter: HDD adapter
9682 *
9683 * This function initializes the adapter for the station mode.
9684 *
9685 * Return: 0 on success or errno on failure.
9686 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009687int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309688{
9689 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08009690 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309691
Dustin Brownfdf17c12018-03-14 12:55:34 -07009692 hdd_enter_dev(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08009693 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9694 hdd_err("session is already opened, %d",
Jeff Johnson5a6fc962019-02-04 14:20:25 -08009695 adapter->vdev_id);
Krunal Sonib51eec72017-11-20 21:53:01 -08009696 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9697 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309698
Krunal Sonib51eec72017-11-20 21:53:01 -08009699 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
9700 if (ret) {
9701 hdd_err("failed to create vdev: %d", ret);
9702 return ret;
9703 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309704 status = hdd_init_station_mode(adapter);
9705
9706 if (QDF_STATUS_SUCCESS != status) {
9707 hdd_err("Error Initializing station 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_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009713 hdd_tx_resume_cb,
9714 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309715
Visweswara Tanukub5a61242019-03-26 12:24:13 +05309716 hdd_register_hl_netdev_fc_timer(adapter,
9717 hdd_tx_resume_timer_expired_handler);
9718
Dustin Browne74003f2018-03-14 12:51:58 -07009719 hdd_exit();
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05309720
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309721 return 0;
9722}
9723
9724/**
9725 * hdd_start_ap_adapter()- Start AP Adapter
9726 * @adapter: HDD adapter
9727 *
9728 * This function initializes the adapter for the AP mode.
9729 *
9730 * Return: 0 on success errno on failure.
9731 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009732int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309733{
9734 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009735 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08009736 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08009737 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arif Hussainbd5194c2018-11-27 19:01:15 -08009738 uint32_t fine_time_meas_cap = 0;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309739
Dustin Brown491d54b2018-03-14 12:39:11 -07009740 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309741
Krunal Sonib51eec72017-11-20 21:53:01 -08009742 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9743 hdd_err("session is already opened, %d",
Jeff Johnson5a6fc962019-02-04 14:20:25 -08009744 adapter->vdev_id);
Krunal Sonib51eec72017-11-20 21:53:01 -08009745 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9746 }
9747 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009748 * In SSR case no need to create new sap context.
9749 * Otherwise create sap context first and then create
9750 * vdev as while creating the vdev, driver needs to
9751 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08009752 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009753 if (adapter->session.ap.sap_context) {
9754 is_ssr = true;
9755 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08009756 hdd_err("sap creation failed");
9757 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
9758 }
9759
9760 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
9761 adapter->session.ap.sap_context);
9762 if (ret) {
9763 hdd_err("failed to create vdev, status:%d", ret);
9764 hdd_sap_destroy_ctx(adapter);
9765 return ret;
9766 }
Naveen Rawat1af09392018-01-03 17:28:21 -08009767
Arif Hussainbd5194c2018-11-27 19:01:15 -08009768 if (adapter->device_mode == QDF_SAP_MODE) {
9769 ucfg_mlme_get_fine_time_meas_cap(hdd_ctx->psoc,
9770 &fine_time_meas_cap);
Jeff Johnson5a6fc962019-02-04 14:20:25 -08009771 sme_cli_set_command(adapter->vdev_id,
Naveen Rawat1af09392018-01-03 17:28:21 -08009772 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
Arif Hussainbd5194c2018-11-27 19:01:15 -08009773 (bool)(fine_time_meas_cap & WMI_FW_AP_RTT_RESPR),
Naveen Rawat1af09392018-01-03 17:28:21 -08009774 VDEV_CMD);
Arif Hussainbd5194c2018-11-27 19:01:15 -08009775 }
Naveen Rawat1af09392018-01-03 17:28:21 -08009776
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009777 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309778
9779 if (QDF_STATUS_SUCCESS != status) {
9780 hdd_err("Error Initializing the AP mode: %d", status);
9781 return qdf_status_to_os_return(status);
9782 }
9783
Arun Khandavallifae92942016-08-01 13:31:08 +05309784 hdd_register_tx_flow_control(adapter,
9785 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009786 hdd_softap_tx_resume_cb,
9787 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309788
Visweswara Tanukub5a61242019-03-26 12:24:13 +05309789 hdd_register_hl_netdev_fc_timer(adapter,
9790 hdd_tx_resume_timer_expired_handler);
9791
Dustin Browne74003f2018-03-14 12:51:58 -07009792 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309793 return 0;
9794}
9795
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309796#ifdef QCA_LL_TX_FLOW_CONTROL_V2
9797/**
9798 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
9799 * @cds_cfg: CDS Configuration
9800 * @hdd_ctx: Pointer to hdd context
9801 *
9802 * Return: none
9803 */
9804static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9805 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009806 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309807{
9808 cds_cfg->tx_flow_stop_queue_th =
jitiphil47c3d9a2018-11-08 18:30:55 +05309809 cfg_get(hdd_ctx->psoc, CFG_DP_TX_FLOW_STOP_QUEUE_TH);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309810 cds_cfg->tx_flow_start_queue_offset =
jitiphil47c3d9a2018-11-08 18:30:55 +05309811 cfg_get(hdd_ctx->psoc, CFG_DP_TX_FLOW_START_QUEUE_OFFSET);
Mohit Khanna70322002018-05-15 19:21:32 -07009812 /* configuration for DP RX Threads */
9813 cds_cfg->enable_dp_rx_threads = hdd_ctx->enable_dp_rx_threads;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309814}
9815#else
9816static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9817 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009818 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309819{
9820}
9821#endif
9822
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309823/**
9824 * hdd_update_cds_config() - API to update cds configuration parameters
9825 * @hdd_ctx: HDD Context
9826 *
9827 * Return: 0 for Success, errno on failure
9828 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009829static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309830{
9831 struct cds_config_info *cds_cfg;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309832 int value;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309833 uint8_t band_capability;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309834 uint8_t ito_repeat_count;
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309835 bool crash_inject;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309836 bool self_recovery;
9837 bool fw_timeout_crash;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309838 QDF_STATUS status;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309839
Min Liu74a1a502018-10-10 19:59:07 +08009840 cds_cfg = qdf_mem_malloc(sizeof(*cds_cfg));
9841 if (!cds_cfg)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309842 return -ENOMEM;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309843
Srinivas Girigowda35b00312017-06-27 21:52:03 -07009844 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Bala Venkatesh46e29032018-11-14 18:24:55 +05309845 ucfg_mlme_get_sap_max_modulated_dtim(hdd_ctx->psoc,
9846 &cds_cfg->sta_maxlimod_dtim);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309847
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309848 status = ucfg_mlme_get_crash_inject(hdd_ctx->psoc, &crash_inject);
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309849 if (QDF_IS_STATUS_ERROR(status)) {
9850 hdd_err("Failed to get crash inject ini config");
9851 goto exit;
9852 }
9853
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309854 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
9855 if (QDF_IS_STATUS_ERROR(status)) {
9856 hdd_err("Failed to get self recovery ini config");
9857 goto exit;
9858 }
9859
9860 status = ucfg_mlme_get_fw_timeout_crash(hdd_ctx->psoc,
9861 &fw_timeout_crash);
9862 if (QDF_IS_STATUS_ERROR(status)) {
9863 hdd_err("Failed to get fw timeout crash ini config");
9864 goto exit;
9865 }
9866
9867 status = ucfg_mlme_get_ito_repeat_count(hdd_ctx->psoc,
9868 &ito_repeat_count);
9869 if (QDF_IS_STATUS_ERROR(status)) {
9870 hdd_err("Failed to get ITO repeat count ini config");
9871 goto exit;
9872 }
9873
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309874 cds_cfg->force_target_assert_enabled = crash_inject;
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05309875
Dustin Brown05d81302018-09-11 16:49:22 -07009876 ucfg_mlme_get_sap_max_offload_peers(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309877 cds_cfg->ap_maxoffload_peers = value;
Dustin Brown05d81302018-09-11 16:49:22 -07009878 ucfg_mlme_get_sap_max_offload_reorder_buffs(hdd_ctx->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309879 &value);
9880 cds_cfg->ap_maxoffload_reorderbuffs = value;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309881
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309882 cds_cfg->reorder_offload =
jitiphil47c3d9a2018-11-08 18:30:55 +05309883 cfg_get(hdd_ctx->psoc, CFG_DP_REORDER_OFFLOAD_SUPPORT);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309884
9885 /* IPA micro controller data path offload resource config item */
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05309886 cds_cfg->uc_offload_enabled = ucfg_ipa_uc_is_enabled();
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309887
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07009888 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Dustin Brown05d81302018-09-11 16:49:22 -07009889 ucfg_mlme_get_sap_max_peers(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309890 cds_cfg->max_station = value;
Naveen Rawat64e477e2016-05-20 10:34:56 -07009891 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07009892 cds_cfg->max_msdus_per_rxinorderind =
jitiphil8e15ea62018-11-16 18:05:34 +05309893 cfg_get(hdd_ctx->psoc, CFG_DP_MAX_MSDUS_PER_RXIND);
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309894 cds_cfg->self_recovery_enabled = self_recovery;
9895 cds_cfg->fw_timeout_crash = fw_timeout_crash;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309896
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309897 cds_cfg->ito_repeat_count = ito_repeat_count;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309898
9899 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
9900 if (QDF_IS_STATUS_ERROR(status))
9901 goto exit;
9902
9903 cds_cfg->bandcapability = band_capability;
Rachit Kankane0106e382018-05-16 18:59:28 +05309904 cds_cfg->num_vdevs = hdd_ctx->config->num_vdevs;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309905
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309906 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07009907 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309908 cds_init_ini_config(cds_cfg);
9909 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309910
9911exit:
9912 qdf_mem_free(cds_cfg);
9913 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309914}
9915
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009916/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009917 * hdd_update_user_config() - API to update user configuration
9918 * parameters to obj mgr which are used by multiple components
9919 * @hdd_ctx: HDD Context
9920 *
9921 * Return: 0 for Success, errno on failure
9922 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009923static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009924{
9925 struct wlan_objmgr_psoc_user_config *user_config;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309926 uint8_t band_capability;
9927 QDF_STATUS status;
Abhinav Kumard4d6eb72018-12-04 20:30:37 +05309928 bool value = false;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309929
9930 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
9931 if (QDF_IS_STATUS_ERROR(status))
9932 return -EIO;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009933
9934 user_config = qdf_mem_malloc(sizeof(*user_config));
Min Liu74a1a502018-10-10 19:59:07 +08009935 if (!user_config)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009936 return -ENOMEM;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009937
9938 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
Abhinav Kumard4d6eb72018-12-04 20:30:37 +05309939 status = ucfg_mlme_is_11d_enabled(hdd_ctx->psoc, &value);
9940 if (!QDF_IS_STATUS_SUCCESS(status))
9941 hdd_err("Invalid 11d_enable flag");
9942 user_config->is_11d_support_enabled = value;
9943
9944 value = false;
9945 status = ucfg_mlme_is_11h_enabled(hdd_ctx->psoc, &value);
9946 if (!QDF_IS_STATUS_SUCCESS(status))
9947 hdd_err("Invalid 11h_enable flag");
9948 user_config->is_11h_support_enabled = value;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309949 user_config->band_capability = band_capability;
Dustin Brown1dbefe62018-09-11 16:32:03 -07009950 wlan_objmgr_psoc_set_user_config(hdd_ctx->psoc, user_config);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009951
9952 qdf_mem_free(user_config);
9953 return 0;
9954}
9955
9956/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009957 * hdd_init_thermal_info - Initialize thermal level
9958 * @hdd_ctx: HDD context
9959 *
9960 * Initialize thermal level at SME layer and set the thermal level callback
9961 * which would be called when a configured thermal threshold is hit.
9962 *
9963 * Return: 0 on success and errno on failure
9964 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009965static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009966{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309967 QDF_STATUS status;
Manikandan Mohan9045e2e2018-11-26 16:44:19 -08009968 mac_handle_t mac_handle = hdd_ctx->mac_handle;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009969
Manikandan Mohan9045e2e2018-11-26 16:44:19 -08009970 status = sme_init_thermal_info(mac_handle);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009971
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309972 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05309973 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009974
Jeff Johnson16528362018-06-14 12:34:16 -07009975 sme_add_set_thermal_level_callback(mac_handle,
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009976 hdd_set_thermal_level_cb);
9977
9978 return 0;
9979
9980}
9981
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009982#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
9983/**
9984 * hdd_hold_rtnl_lock - Hold RTNL lock
9985 *
9986 * Hold RTNL lock
9987 *
9988 * Return: True if held and false otherwise
9989 */
9990static inline bool hdd_hold_rtnl_lock(void)
9991{
9992 rtnl_lock();
9993 return true;
9994}
9995
9996/**
9997 * hdd_release_rtnl_lock - Release RTNL lock
9998 *
9999 * Release RTNL lock
10000 *
10001 * Return: None
10002 */
10003static inline void hdd_release_rtnl_lock(void)
10004{
10005 rtnl_unlock();
10006}
10007#else
10008static inline bool hdd_hold_rtnl_lock(void) { return false; }
10009static inline void hdd_release_rtnl_lock(void) { }
10010#endif
10011
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010012#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010013
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010014/* MAX iwpriv command support */
10015#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010016#define PKTLOG_CLEAR_BUFF 4
Venkata Sharath Chandra Manchala27e44902019-01-28 11:29:18 -080010017/* Set Maximum pktlog file size to 64MB */
10018#define MAX_PKTLOG_SIZE 64
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010019
10020/**
10021 * hdd_pktlog_set_buff_size() - set pktlog buffer size
10022 * @hdd_ctx: hdd context
10023 * @set_value2: pktlog buffer size value
10024 *
10025 *
10026 * Return: 0 for success or error.
10027 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010028static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010029{
10030 struct sir_wifi_start_log start_log = { 0 };
10031 QDF_STATUS status;
10032
10033 start_log.ring_id = RING_ID_PER_PACKET_STATS;
10034 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
10035 start_log.ini_triggered = cds_is_packet_log_enabled();
10036 start_log.user_triggered = 1;
10037 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010038 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010039
Jeff Johnson16528362018-06-14 12:34:16 -070010040 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010041 if (!QDF_IS_STATUS_SUCCESS(status)) {
10042 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -070010043 hdd_exit();
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010044 return -EINVAL;
10045 }
10046
10047 return 0;
10048}
10049
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010050/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010051 * hdd_pktlog_clear_buff() - clear pktlog buffer
10052 * @hdd_ctx: hdd context
10053 *
10054 * Return: 0 for success or error.
10055 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010056static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010057{
10058 struct sir_wifi_start_log start_log;
10059 QDF_STATUS status;
10060
10061 start_log.ring_id = RING_ID_PER_PACKET_STATS;
10062 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
10063 start_log.ini_triggered = cds_is_packet_log_enabled();
10064 start_log.user_triggered = 1;
10065 start_log.size = 0;
10066 start_log.is_pktlog_buff_clear = true;
10067
Jeff Johnson16528362018-06-14 12:34:16 -070010068 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010069 if (!QDF_IS_STATUS_SUCCESS(status)) {
10070 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -070010071 hdd_exit();
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010072 return -EINVAL;
10073 }
10074
10075 return 0;
10076}
10077
10078
10079/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010080 * hdd_process_pktlog_command() - process pktlog command
10081 * @hdd_ctx: hdd context
10082 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010083 * @set_value2: pktlog buffer size value
10084 *
10085 * This function process pktlog command.
10086 * set_value2 only matters when set_value is 3 (set buff size)
10087 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010088 *
10089 * Return: 0 for success or error.
10090 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010091int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010092 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010093{
10094 int ret;
10095 bool enable;
10096 uint8_t user_triggered = 0;
10097
10098 ret = wlan_hdd_validate_context(hdd_ctx);
10099 if (0 != ret)
10100 return ret;
10101
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010102 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010103
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010104 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010105 hdd_err("invalid pktlog value %d", set_value);
10106 return -EINVAL;
10107 }
10108
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010109 if (set_value == PKTLOG_SET_BUFF_SIZE) {
10110 if (set_value2 <= 0) {
10111 hdd_err("invalid pktlog size %d", set_value2);
10112 return -EINVAL;
10113 } else if (set_value2 > MAX_PKTLOG_SIZE) {
Venkata Sharath Chandra Manchala27e44902019-01-28 11:29:18 -080010114 hdd_err_rl("Pktlog size is large. max value is %uMB.",
10115 MAX_PKTLOG_SIZE);
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010116 return -EINVAL;
10117 }
10118 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010119 } else if (set_value == PKTLOG_CLEAR_BUFF) {
10120 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010121 }
10122
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010123 /*
10124 * set_value = 0 then disable packetlog
10125 * set_value = 1 enable packetlog forcefully
10126 * set_vlaue = 2 then disable packetlog if disabled through ini or
10127 * enable packetlog with AUTO type.
10128 */
10129 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
10130 true : false;
10131
10132 if (1 == set_value) {
10133 enable = true;
10134 user_triggered = 1;
10135 }
10136
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010137 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010138}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010139
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010140/**
10141 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
10142 * @hdd_ctx: HDD context
10143 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010144 * @user_triggered: triggered through iwpriv
10145 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010146 *
10147 * Return: 0 on success; error number otherwise
10148 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010149int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010150 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010151{
10152 struct sir_wifi_start_log start_log;
10153 QDF_STATUS status;
10154
10155 start_log.ring_id = RING_ID_PER_PACKET_STATS;
10156 start_log.verbose_level =
10157 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010158 start_log.ini_triggered = cds_is_packet_log_enabled();
10159 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010160 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010161 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +053010162 /*
10163 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
10164 * commands. Host uses this flag to decide whether to send pktlog
10165 * disable command to fw without sending pktlog enable command
10166 * previously. For eg, If vendor sends pktlog disable command without
10167 * sending pktlog enable command, then host discards the packet
10168 * but for iwpriv command, host will send it to fw.
10169 */
10170 start_log.is_iwpriv_command = 1;
Jeff Johnson16528362018-06-14 12:34:16 -070010171 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010172 if (!QDF_IS_STATUS_SUCCESS(status)) {
10173 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -070010174 hdd_exit();
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010175 return -EINVAL;
10176 }
10177
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010178 if (enable == true)
10179 hdd_ctx->is_pktlog_enabled = 1;
10180 else
10181 hdd_ctx->is_pktlog_enabled = 0;
10182
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010183 return 0;
10184}
10185#endif /* REMOVE_PKT_LOG */
10186
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010187void hdd_free_mac_address_lists(struct hdd_context *hdd_ctx)
10188{
10189 hdd_debug("Resetting MAC address lists");
hangtian127c9532019-01-12 13:29:07 +080010190 qdf_mem_zero(hdd_ctx->provisioned_mac_addr,
10191 sizeof(hdd_ctx->provisioned_mac_addr));
10192 qdf_mem_zero(hdd_ctx->derived_mac_addr,
10193 sizeof(hdd_ctx->derived_mac_addr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010194 hdd_ctx->num_provisioned_addr = 0;
10195 hdd_ctx->num_derived_addr = 0;
10196 hdd_ctx->provisioned_intf_addr_mask = 0;
10197 hdd_ctx->derived_intf_addr_mask = 0;
10198}
10199
Komal Seelam92fff912016-03-24 11:51:41 +053010200/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010201 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
10202 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +053010203 * @dev: Device Pointer
10204 * @num: Number of Valid Mac address
10205 *
10206 * Return: Pointer to MAC address buffer
10207 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010208static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
10209 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +053010210{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010211 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +053010212}
Komal Seelam92fff912016-03-24 11:51:41 +053010213
10214/**
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010215 * hdd_get_platform_wlan_derived_mac_buff() - API to query platform driver
10216 * for derived MAC address
10217 * @dev: Device Pointer
10218 * @num: Number of Valid Mac address
10219 *
10220 * Return: Pointer to MAC address buffer
10221 */
10222static uint8_t *hdd_get_platform_wlan_derived_mac_buff(struct device *dev,
10223 uint32_t *num)
10224{
10225 return pld_get_wlan_derived_mac_address(dev, num);
10226}
10227
10228/**
Komal Seelam92fff912016-03-24 11:51:41 +053010229 * hdd_populate_random_mac_addr() - API to populate random mac addresses
10230 * @hdd_ctx: HDD Context
10231 * @num: Number of random mac addresses needed
10232 *
10233 * Generate random addresses using bit manipulation on the base mac address
10234 *
10235 * Return: None
10236 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010237void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +053010238{
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010239 uint32_t idx = hdd_ctx->num_derived_addr;
Komal Seelam92fff912016-03-24 11:51:41 +053010240 uint32_t iter;
Komal Seelam92fff912016-03-24 11:51:41 +053010241 uint8_t *buf = NULL;
10242 uint8_t macaddr_b3, tmp_br3;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010243 /*
10244 * Consider first provisioned mac address as source address to derive
10245 * remaining addresses
10246 */
Komal Seelam92fff912016-03-24 11:51:41 +053010247
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010248 uint8_t *src = hdd_ctx->provisioned_mac_addr[0].bytes;
10249
10250 for (iter = 0; iter < num; ++iter, ++idx) {
10251 buf = hdd_ctx->derived_mac_addr[idx].bytes;
Komal Seelam92fff912016-03-24 11:51:41 +053010252 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
10253 macaddr_b3 = buf[3];
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010254 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + idx) &
Komal Seelam92fff912016-03-24 11:51:41 +053010255 INTF_MACADDR_MASK;
10256 macaddr_b3 += tmp_br3;
10257 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
10258 buf[0] |= 0x02;
10259 buf[3] = macaddr_b3;
Srinivas Girigowda34fbba02019-04-08 12:07:44 -070010260 hdd_debug(MAC_ADDRESS_STR, QDF_MAC_ADDR_ARRAY(buf));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010261 hdd_ctx->num_derived_addr++;
Komal Seelam92fff912016-03-24 11:51:41 +053010262 }
10263}
10264
10265/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010266 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +053010267 * @hdd_ctx: HDD Context
10268 *
10269 * API to get mac addresses from platform driver and update the driver
10270 * structures and configure FW with the base mac address.
10271 * Return: int
10272 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010273static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +053010274{
10275 uint32_t no_of_mac_addr, iter;
10276 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
10277 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
10278 uint8_t *addr, *buf;
10279 struct device *dev = hdd_ctx->parent_dev;
Komal Seelam92fff912016-03-24 11:51:41 +053010280 tSirMacAddr mac_addr;
10281 QDF_STATUS status;
10282
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010283 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +053010284
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010285 if (no_of_mac_addr == 0 || !addr) {
10286 hdd_debug("No mac configured from platform driver");
Komal Seelam92fff912016-03-24 11:51:41 +053010287 return -EINVAL;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010288 }
10289
10290 hdd_free_mac_address_lists(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +053010291
10292 if (no_of_mac_addr > max_mac_addr)
10293 no_of_mac_addr = max_mac_addr;
10294
10295 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
10296
10297 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010298 buf = hdd_ctx->provisioned_mac_addr[iter].bytes;
Komal Seelam92fff912016-03-24 11:51:41 +053010299 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010300 hdd_info("provisioned MAC Addr [%d]" MAC_ADDRESS_STR, iter,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -070010301 QDF_MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +053010302 }
10303
Komal Seelam92fff912016-03-24 11:51:41 +053010304
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010305 hdd_ctx->num_provisioned_addr = no_of_mac_addr;
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010306
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010307 if (hdd_ctx->config->mac_provision) {
10308 addr = hdd_get_platform_wlan_derived_mac_buff(dev,
10309 &no_of_mac_addr);
10310
10311 if (no_of_mac_addr == 0 || !addr)
10312 hdd_warn("No derived address from platform driver");
10313 else if (no_of_mac_addr >
10314 (max_mac_addr - hdd_ctx->num_provisioned_addr))
10315 no_of_mac_addr = (max_mac_addr -
10316 hdd_ctx->num_provisioned_addr);
10317
10318 for (iter = 0; iter < no_of_mac_addr; ++iter,
10319 addr += mac_addr_size) {
10320 buf = hdd_ctx->derived_mac_addr[iter].bytes;
10321 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
10322 hdd_debug("derived MAC Addr [%d]" MAC_ADDRESS_STR, iter,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -070010323 QDF_MAC_ADDR_ARRAY(buf));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010324 }
10325 hdd_ctx->num_derived_addr = no_of_mac_addr;
10326 }
10327
10328 no_of_mac_addr = hdd_ctx->num_provisioned_addr +
10329 hdd_ctx->num_derived_addr;
Komal Seelam92fff912016-03-24 11:51:41 +053010330 if (no_of_mac_addr < max_mac_addr)
10331 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
10332 no_of_mac_addr);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010333
10334 status = sme_set_custom_mac_addr(mac_addr);
10335 if (!QDF_IS_STATUS_SUCCESS(status))
10336 return -EAGAIN;
10337
Komal Seelam92fff912016-03-24 11:51:41 +053010338 return 0;
10339}
10340
10341/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010342 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
10343 * @hdd_ctx: HDD Context
10344 *
10345 * Update MAC address to FW. If MAC address passed by FW is invalid, host
10346 * will generate its own MAC and update it to FW.
10347 *
10348 * Return: 0 for success
10349 * Non-zero error code for failure
10350 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010351static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010352{
Jeff Johnson374c0852019-03-10 19:02:07 -070010353 tSirMacAddr custom_mac_addr;
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010354 QDF_STATUS status;
10355
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010356 if (hdd_ctx->num_provisioned_addr)
Jeff Johnson374c0852019-03-10 19:02:07 -070010357 qdf_mem_copy(&custom_mac_addr,
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010358 &hdd_ctx->provisioned_mac_addr[0].bytes[0],
10359 sizeof(tSirMacAddr));
10360 else
Jeff Johnson374c0852019-03-10 19:02:07 -070010361 qdf_mem_copy(&custom_mac_addr,
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010362 &hdd_ctx->derived_mac_addr[0].bytes[0],
10363 sizeof(tSirMacAddr));
Jeff Johnson374c0852019-03-10 19:02:07 -070010364 status = sme_set_custom_mac_addr(custom_mac_addr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010365 if (!QDF_IS_STATUS_SUCCESS(status))
10366 return -EAGAIN;
10367 return 0;
10368}
10369
10370/**
Komal Seelam92fff912016-03-24 11:51:41 +053010371 * hdd_initialize_mac_address() - API to get wlan mac addresses
10372 * @hdd_ctx: HDD Context
10373 *
10374 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
10375 * is provisioned with mac addresses, driver uses it, else it will use
10376 * wlan_mac.bin to update HW MAC addresses.
10377 *
10378 * Return: None
10379 */
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010380static int hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +053010381{
10382 QDF_STATUS status;
10383 int ret;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010384 bool update_mac_addr_to_fw = true;
Komal Seelam92fff912016-03-24 11:51:41 +053010385
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010386 ret = hdd_platform_wlan_mac(hdd_ctx);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010387 if (hdd_ctx->config->mac_provision || !ret) {
Dustin Brown7e761c72018-07-31 13:50:17 -070010388 hdd_info("using MAC address from platform driver");
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010389 return ret;
Dustin Brown7e761c72018-07-31 13:50:17 -070010390 }
Komal Seelam92fff912016-03-24 11:51:41 +053010391
10392 status = hdd_update_mac_config(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010393 if (QDF_IS_STATUS_SUCCESS(status)) {
10394 hdd_info("using MAC address from wlan_mac.bin");
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010395 return 0;
Dustin Brown7e761c72018-07-31 13:50:17 -070010396 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010397
Dustin Brown7e761c72018-07-31 13:50:17 -070010398 hdd_info("using default MAC address");
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010399
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010400 /* Use fw provided MAC */
10401 if (!qdf_is_macaddr_zero(&hdd_ctx->hw_macaddr)) {
10402 hdd_update_macaddr(hdd_ctx, hdd_ctx->hw_macaddr, false);
10403 update_mac_addr_to_fw = false;
10404 return 0;
10405 } else if (hdd_generate_macaddr_auto(hdd_ctx) != 0) {
10406 struct qdf_mac_addr mac_addr;
10407
10408 hdd_err("MAC failure from device serial no.");
Jeff Johnson51a80522018-12-11 20:19:44 -080010409 qdf_get_random_bytes(&mac_addr, sizeof(mac_addr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010410 /*
10411 * Reset multicast bit (bit-0) and set
10412 * locally-administered bit
10413 */
10414 mac_addr.bytes[0] = 0x2;
10415 hdd_update_macaddr(hdd_ctx, mac_addr, true);
10416 }
10417
10418 if (update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010419 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010420 if (ret)
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -080010421 hdd_err("MAC address out-of-sync, ret:%d", ret);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010422 }
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010423 return ret;
Komal Seelam92fff912016-03-24 11:51:41 +053010424}
10425
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010426static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010427{
10428 int vdev_id = 0;
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053010429 QDF_STATUS status;
10430 bool smart_chainmask_enabled;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010431 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010432 int vpdev = PDEV_CMD;
10433 int ret;
10434
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053010435 status = ucfg_get_smart_chainmask_enabled(hdd_ctx->psoc,
10436 &smart_chainmask_enabled);
10437 if (QDF_IS_STATUS_ERROR(status))
10438 return -EINVAL;
10439
10440 ret = sme_cli_set_command(vdev_id, param_id,
10441 (int)smart_chainmask_enabled, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010442 if (ret)
10443 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
10444
10445 return ret;
10446}
10447
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010448static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010449{
10450 int vdev_id = 0;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010451 QDF_STATUS status;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010452 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010453 bool alternative_chainmask_enabled;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010454 int vpdev = PDEV_CMD;
10455 int ret;
10456
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010457 status = ucfg_get_alternative_chainmask_enabled(
10458 hdd_ctx->psoc,
10459 &alternative_chainmask_enabled);
10460 if (QDF_IS_STATUS_ERROR(status))
10461 return -EINVAL;
10462
10463 ret = sme_cli_set_command(vdev_id, param_id,
10464 (int)alternative_chainmask_enabled, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010465 if (ret)
10466 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
10467 ret);
10468
10469 return ret;
10470}
10471
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010472static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -070010473{
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010474 QDF_STATUS status;
Jeff Johnson12a744b2017-04-04 08:19:37 -070010475 int vdev_id = 0;
10476 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010477 bool value;
Jeff Johnson12a744b2017-04-04 08:19:37 -070010478 int vpdev = PDEV_CMD;
10479 int ret;
10480
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010481 status = ucfg_fwol_get_ani_enabled(hdd_ctx->psoc, &value);
10482 if (QDF_IS_STATUS_ERROR(status))
10483 return -EINVAL;
10484
10485 ret = sme_cli_set_command(vdev_id, param_id, (int)value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -070010486 if (ret)
10487 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
10488
10489 return ret;
10490}
10491
Jeff Johnson89c66ff2016-04-22 15:21:37 -070010492/**
Prashanth Bhatta07998752016-04-28 12:35:33 -070010493 * hdd_pre_enable_configure() - Configurations prior to cds_enable
10494 * @hdd_ctx: HDD context
10495 *
10496 * Pre configurations to be done at lower layer before calling cds enable.
10497 *
10498 * Return: 0 on success and errno on failure.
10499 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010500static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -070010501{
10502 int ret;
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010503 uint8_t val = 0;
Prashanth Bhatta07998752016-04-28 12:35:33 -070010504 QDF_STATUS status;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010505 uint32_t arp_ac_category;
Leo Changfdb45c32016-10-28 11:09:23 -070010506 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010507
Leo Changfdb45c32016-10-28 11:09:23 -070010508 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Ajit Pal Singh5d269612018-04-19 16:29:12 +053010509 /* Register HL netdev flow control callback */
10510 cdp_hl_fc_register(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010511
10512 /*
10513 * Note that the cds_pre_enable() sequence triggers the cfg download.
10514 * The cfg download must occur before we update the SME config
10515 * since the SME config operation must access the cfg database
10516 */
10517 status = hdd_set_sme_config(hdd_ctx);
10518
10519 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010520 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010521 ret = qdf_status_to_os_return(status);
10522 goto out;
10523 }
10524
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -070010525 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
10526 if (QDF_STATUS_SUCCESS != status) {
10527 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
10528 ret = qdf_status_to_os_return(status);
10529 goto out;
10530 }
10531
Dustin Brown1dbefe62018-09-11 16:32:03 -070010532 status = ucfg_mlme_get_tx_chainmask_1ss(hdd_ctx->psoc, &val);
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010533 if (QDF_STATUS_SUCCESS != status) {
10534 hdd_err("Get tx_chainmask_1ss from mlme failed");
10535 ret = qdf_status_to_os_return(status);
10536 goto out;
10537 }
10538 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS, val,
Prashanth Bhatta07998752016-04-28 12:35:33 -070010539 PDEV_CMD);
10540 if (0 != ret) {
10541 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
10542 goto out;
10543 }
10544
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010545 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
10546 if (ret)
10547 goto out;
10548
10549 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
10550 if (ret)
10551 goto out;
10552
Jeff Johnson12a744b2017-04-04 08:19:37 -070010553 ret = hdd_set_ani_enabled(hdd_ctx);
10554 if (ret)
10555 goto out;
10556
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010557 status = ucfg_get_arp_ac_category(hdd_ctx->psoc, &arp_ac_category);
10558
10559 if (QDF_IS_STATUS_ERROR(status))
10560 return -EINVAL;
10561
Naveen Rawat247a8682017-06-05 15:00:31 -070010562 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010563 arp_ac_category,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -080010564 PDEV_CMD);
10565 if (0 != ret) {
10566 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010567 arp_ac_category, ret);
Srinivas Girigowda70e169a2017-03-07 23:55:57 -080010568 goto out;
10569 }
10570
Prashanth Bhatta07998752016-04-28 12:35:33 -070010571 status = hdd_set_sme_chan_list(hdd_ctx);
10572 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010573 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010574 ret = qdf_status_to_os_return(status);
10575 goto out;
10576 }
10577
10578 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -070010579 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010580 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -070010581 ret = -EINVAL;
10582 goto out;
10583 }
10584
Prashanth Bhatta07998752016-04-28 12:35:33 -070010585
10586 hdd_init_channel_avoidance(hdd_ctx);
10587
10588out:
10589 return ret;
10590}
10591
Rachit Kankane026e77a2018-07-31 16:21:09 +053010592#ifdef FEATURE_P2P_LISTEN_OFFLOAD
Prashanth Bhatta07998752016-04-28 12:35:33 -070010593/**
Peng Xu8fdaa492016-06-22 10:20:47 -070010594 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010595 * @context: context registered with sme_register_p2p_lo_event(). HDD
10596 * always registers a hdd context pointer
10597 * @evt:event structure pointer
Peng Xu8fdaa492016-06-22 10:20:47 -070010598 *
10599 * This is the p2p listen offload stop event handler, it sends vendor
10600 * event back to supplicant to notify the stop reason.
10601 *
10602 * Return: None
10603 */
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010604static void wlan_hdd_p2p_lo_event_callback(void *context,
10605 struct sir_p2p_lo_event *evt)
Peng Xu8fdaa492016-06-22 10:20:47 -070010606{
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010607 struct hdd_context *hdd_ctx = context;
Peng Xu8fdaa492016-06-22 10:20:47 -070010608 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -070010609 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -070010610
Dustin Brown491d54b2018-03-14 12:39:11 -070010611 hdd_enter();
Peng Xu8fdaa492016-06-22 10:20:47 -070010612
Jeff Johnsond36fa332019-03-18 13:42:25 -070010613 if (!hdd_ctx) {
Peng Xu8fdaa492016-06-22 10:20:47 -070010614 hdd_err("Invalid HDD context pointer");
10615 return;
10616 }
10617
Peng Xu5c682812017-08-06 07:39:13 -070010618 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
10619 if (!adapter) {
10620 hdd_err("Cannot find adapter by vdev_id = %d",
10621 evt->vdev_id);
10622 return;
10623 }
10624
Peng Xu8fdaa492016-06-22 10:20:47 -070010625 vendor_event =
10626 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -070010627 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -070010628 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
10629 GFP_KERNEL);
10630
10631 if (!vendor_event) {
10632 hdd_err("cfg80211_vendor_event_alloc failed");
10633 return;
10634 }
10635
10636 if (nla_put_u32(vendor_event,
10637 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
10638 evt->reason_code)) {
10639 hdd_err("nla put failed");
10640 kfree_skb(vendor_event);
10641 return;
10642 }
10643
10644 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -070010645 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
10646 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -070010647}
Rachit Kankane026e77a2018-07-31 16:21:09 +053010648#else
10649static void wlan_hdd_p2p_lo_event_callback(void *context,
10650 struct sir_p2p_lo_event *evt)
10651{
10652}
10653#endif
Peng Xu8fdaa492016-06-22 10:20:47 -070010654
Rachit Kankanef6834c42018-08-02 18:47:50 +053010655#ifdef FEATURE_WLAN_DYNAMIC_CVM
10656static inline int hdd_set_vc_mode_config(struct hdd_context *hdd_ctx)
10657{
10658 return sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap);
10659}
10660#else
10661static inline int hdd_set_vc_mode_config(struct hdd_context *hdd_ctx)
10662{
10663 return QDF_STATUS_SUCCESS;
10664}
10665#endif
10666
Peng Xu8fdaa492016-06-22 10:20:47 -070010667/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010668 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
10669 * @hdd_ctx: HDD context
10670 *
10671 * This function sends the adaptive dwell time config configuration to the
10672 * firmware via WMA
10673 *
10674 * Return: 0 - success, < 0 - failure
10675 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010676static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010677{
10678 QDF_STATUS status;
10679 struct adaptive_dwelltime_params dwelltime_params;
10680
Harprit Chhabadad59ae762019-01-08 16:40:43 -080010681 status = ucfg_fwol_get_all_adaptive_dwelltime_params(hdd_ctx->psoc,
10682 &dwelltime_params);
10683 status = ucfg_fwol_set_adaptive_dwelltime_config(&dwelltime_params);
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010684
10685 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
10686 if (!QDF_IS_STATUS_SUCCESS(status)) {
10687 hdd_err("Failed to send Adaptive Dwelltime configuration!");
10688 return -EAGAIN;
10689 }
10690 return 0;
10691}
10692
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010693int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010694{
10695 QDF_STATUS status;
10696 struct wmi_dbs_scan_sel_params dbs_scan_params;
10697 uint32_t i = 0;
10698 uint8_t count = 0, numentries = 0;
Krunal Sonidf29bc42018-11-15 13:26:29 -080010699 uint8_t dual_mac_feature;
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010700 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
10701 * CDS_DBS_SCAN_CLIENTS_MAX];
10702
Krunal Sonidf29bc42018-11-15 13:26:29 -080010703 status = ucfg_policy_mgr_get_dual_mac_feature(hdd_ctx->psoc,
10704 &dual_mac_feature);
10705
10706 if (status != QDF_STATUS_SUCCESS) {
10707 hdd_err("can't get dual mac feature flag");
10708 return -EINVAL;
10709 }
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010710 /* check if DBS is enabled or supported */
Krunal Sonidf29bc42018-11-15 13:26:29 -080010711 if ((dual_mac_feature == DISABLE_DBS_CXN_AND_SCAN) ||
10712 (dual_mac_feature == ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN))
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010713 return -EINVAL;
10714
10715 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
10716 dbs_scan_config, &numentries,
10717 (CDS_DBS_SCAN_PARAM_PER_CLIENT
10718 * CDS_DBS_SCAN_CLIENTS_MAX));
10719
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010720 if (!numentries) {
Dustin Brown6a8d39b2018-08-14 15:27:26 -070010721 hdd_debug("Do not send scan_selection_config");
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010722 return 0;
10723 }
10724
10725 /* hdd_set_fw_log_params */
10726 dbs_scan_params.num_clients = 0;
10727 while (count < (numentries - 2)) {
10728 dbs_scan_params.module_id[i] = dbs_scan_config[count];
10729 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
10730 dbs_scan_params.num_non_dbs_scans[i] =
10731 dbs_scan_config[count + 2];
10732 dbs_scan_params.num_clients++;
10733 hdd_debug("module:%d NDS:%d NNDS:%d",
10734 dbs_scan_params.module_id[i],
10735 dbs_scan_params.num_dbs_scans[i],
10736 dbs_scan_params.num_non_dbs_scans[i]);
10737 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
10738 i++;
10739 }
10740
10741 dbs_scan_params.pdev_id = 0;
10742
10743 hdd_debug("clients:%d pdev:%d",
10744 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
10745
Jeff Johnson16528362018-06-14 12:34:16 -070010746 status = sme_set_dbs_scan_selection_config(hdd_ctx->mac_handle,
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010747 &dbs_scan_params);
10748 hdd_debug("Sending DBS Scan Selection Configuration to fw");
10749 if (!QDF_IS_STATUS_SUCCESS(status)) {
10750 hdd_err("Failed to send DBS Scan selection configuration!");
10751 return -EAGAIN;
10752 }
10753 return 0;
10754}
10755
Arun Khandavallid4349a92016-07-25 11:10:43 +053010756#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10757/**
10758 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
10759 * @hdd_ctx: HDD context
10760 *
10761 * Set auto shutdown callback to get indications from firmware to indicate
10762 * userspace to shutdown WLAN after a configured amount of inactivity.
10763 *
10764 * Return: 0 on success and errno on failure.
10765 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010766static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010767{
10768 QDF_STATUS status;
10769
Dundi Raviteja8e338282018-09-25 17:16:04 +053010770 if (!hdd_ctx->config->wlan_auto_shutdown)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010771 return 0;
10772
Jeff Johnson16528362018-06-14 12:34:16 -070010773 status = sme_set_auto_shutdown_cb(hdd_ctx->mac_handle,
Arun Khandavallid4349a92016-07-25 11:10:43 +053010774 wlan_hdd_auto_shutdown_cb);
10775 if (status != QDF_STATUS_SUCCESS)
10776 hdd_err("Auto shutdown feature could not be enabled: %d",
10777 status);
10778
10779 return qdf_status_to_os_return(status);
10780}
10781#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010782static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010783{
10784 return 0;
10785}
10786#endif
10787
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010788#ifdef MWS_COEX
10789/**
10790 * hdd_set_mws_coex() - Set MWS coex configurations
10791 * @hdd_ctx: HDD context
10792 *
10793 * This function sends MWS-COEX 4G quick FTDM and
10794 * MWS-COEX 5G-NR power limit to FW
10795 *
10796 * Return: 0 on success and errno on failure.
10797 */
10798static int hdd_init_mws_coex(struct hdd_context *hdd_ctx)
10799{
10800 int ret = 0;
lifengdb340e72018-11-20 00:50:20 +080010801 uint32_t mws_coex_4g_quick_tdm = 0, mws_coex_5g_nr_pwr_limit = 0;
10802
10803 ucfg_mlme_get_mws_coex_4g_quick_tdm(hdd_ctx->psoc,
10804 &mws_coex_4g_quick_tdm);
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010805
10806 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_MWSCOEX_4G_ALLOW_QUICK_FTDM,
lifengdb340e72018-11-20 00:50:20 +080010807 mws_coex_4g_quick_tdm,
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010808 PDEV_CMD);
10809 if (ret) {
10810 hdd_warn("Unable to send MWS-COEX 4G quick FTDM policy");
10811 return ret;
10812 }
10813
lifengdb340e72018-11-20 00:50:20 +080010814 ucfg_mlme_get_mws_coex_5g_nr_pwr_limit(hdd_ctx->psoc,
10815 &mws_coex_5g_nr_pwr_limit);
10816
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010817 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_MWSCOEX_SET_5GNR_PWR_LIMIT,
lifengdb340e72018-11-20 00:50:20 +080010818 mws_coex_5g_nr_pwr_limit,
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010819 PDEV_CMD);
10820 if (ret) {
10821 hdd_warn("Unable to send MWS-COEX 4G quick FTDM policy");
10822 return ret;
10823 }
lifengdb340e72018-11-20 00:50:20 +080010824
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010825 return ret;
10826}
10827#else
10828static int hdd_init_mws_coex(struct hdd_context *hdd_ctx)
10829{
10830 return 0;
10831}
10832#endif
10833
Arun Khandavallid4349a92016-07-25 11:10:43 +053010834/**
10835 * hdd_features_init() - Init features
10836 * @hdd_ctx: HDD context
Arun Khandavallid4349a92016-07-25 11:10:43 +053010837 *
10838 * Initialize features and their feature context after WLAN firmware is up.
10839 *
10840 * Return: 0 on success and errno on failure.
10841 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010842static int hdd_features_init(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010843{
Jeff Johnson19ce8d02019-02-08 22:56:23 -080010844 struct tx_power_limit hddtxlimit;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010845 QDF_STATUS status;
10846 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070010847 mac_handle_t mac_handle;
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010848 struct hdd_config *cfg;
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +053010849 bool b_cts2self, is_imps_enabled;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010850
Dustin Brown491d54b2018-03-14 12:39:11 -070010851 hdd_enter();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010852
Dustin Brownad698ae2018-09-05 17:19:30 -070010853 ret = hdd_update_country_code(hdd_ctx);
10854 if (ret) {
10855 hdd_err("Failed to update country code; errno:%d", ret);
10856 return -EINVAL;
10857 }
10858
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010859 ret = hdd_init_mws_coex(hdd_ctx);
10860 if (ret)
10861 hdd_warn("Error initializing mws-coex");
10862
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010863 cfg = hdd_ctx->config;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010864 /* FW capabilities received, Set the Dot11 mode */
Jeff Johnson16528362018-06-14 12:34:16 -070010865 mac_handle = hdd_ctx->mac_handle;
10866 sme_setdef_dot11mode(mac_handle);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010867
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +053010868 ucfg_mlme_is_imps_enabled(hdd_ctx->psoc, &is_imps_enabled);
10869 hdd_set_idle_ps_config(hdd_ctx, is_imps_enabled);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010870
Poddar, Siddarth37033032017-10-11 15:47:40 +053010871 /* Send Enable/Disable data stall detection cmd to FW */
10872 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
jitiphil377bcc12018-10-05 19:46:08 +053010873 cdp_cfg_get(cds_get_context(QDF_MODULE_ID_SOC),
10874 cfg_dp_enable_data_stall), PDEV_CMD);
Poddar, Siddarth37033032017-10-11 15:47:40 +053010875
Dustin Brown1dbefe62018-09-11 16:32:03 -070010876 ucfg_mlme_get_go_cts2self_for_sta(hdd_ctx->psoc, &b_cts2self);
Wu Gao93816212018-08-31 16:49:54 +080010877 if (b_cts2self)
Jeff Johnson16528362018-06-14 12:34:16 -070010878 sme_set_cts2self_for_p2p_go(mac_handle);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010879
Rachit Kankanef6834c42018-08-02 18:47:50 +053010880 if (hdd_set_vc_mode_config(hdd_ctx))
Nachiket Kukade8983cf62017-10-12 18:14:48 +053010881 hdd_warn("Error in setting Voltage Corner mode config to FW");
10882
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010883 if (hdd_rx_ol_init(hdd_ctx))
10884 hdd_err("Unable to initialize Rx LRO/GRO in fw");
Arun Khandavallid4349a92016-07-25 11:10:43 +053010885
10886 if (hdd_adaptive_dwelltime_init(hdd_ctx))
10887 hdd_err("Unable to send adaptive dwelltime setting to FW");
10888
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010889 if (hdd_dbs_scan_selection_init(hdd_ctx))
10890 hdd_err("Unable to send DBS scan selection setting to FW");
10891
Arun Khandavallid4349a92016-07-25 11:10:43 +053010892 ret = hdd_init_thermal_info(hdd_ctx);
10893 if (ret) {
10894 hdd_err("Error while initializing thermal information");
Dustin Browne7e71d32018-05-11 16:00:08 -070010895 return ret;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010896 }
10897
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010898 /**
10899 * In case of SSR/PDR, if pktlog was enabled manually before
Rakshith Suresh Patkar6d955262019-03-13 16:51:50 +053010900 * SSR/PDR, then enable it again automatically after Wlan
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010901 * device up.
Rakshith Suresh Patkar6d955262019-03-13 16:51:50 +053010902 * During SSR/PDR, pktlog will be disabled as part of
10903 * hdd_features_deinit if pktlog is enabled in ini.
10904 * Re-enable pktlog in SSR case, if pktlog is enabled in ini.
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010905 */
Rakshith Suresh Patkar6d955262019-03-13 16:51:50 +053010906 if (cds_is_packet_log_enabled() ||
10907 (cds_is_driver_recovering() && hdd_ctx->is_pktlog_enabled))
Alok Kumar5a75b9d2018-08-31 10:55:43 +053010908 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Poddar, Siddarth66a46592017-02-22 11:44:44 +053010909
gaurank kathpalia3d2e3852018-10-03 22:03:23 +053010910 hddtxlimit.txPower2g = ucfg_get_tx_power(hdd_ctx->psoc, BAND_2G);
10911 hddtxlimit.txPower5g = ucfg_get_tx_power(hdd_ctx->psoc, BAND_5G);
Jeff Johnson16528362018-06-14 12:34:16 -070010912 status = sme_txpower_limit(mac_handle, &hddtxlimit);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010913 if (!QDF_IS_STATUS_SUCCESS(status))
10914 hdd_err("Error setting txlimit in sme: %d", status);
10915
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010916 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010917
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053010918 status = sme_enable_disable_chanavoidind_event(mac_handle, 0);
10919 if (QDF_IS_STATUS_ERROR(status) && (status != QDF_STATUS_E_NOSUPPORT)) {
10920 hdd_err("Failed to disable Chan Avoidance Indication");
Sourav Mohapatra674925f2018-04-16 11:16:58 +053010921 return -EINVAL;
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +053010922 }
Arun Khandavallid4349a92016-07-25 11:10:43 +053010923
10924 /* register P2P Listen Offload event callback */
10925 if (wma_is_p2p_lo_capable())
Jeff Johnson16528362018-06-14 12:34:16 -070010926 sme_register_p2p_lo_event(mac_handle, hdd_ctx,
10927 wlan_hdd_p2p_lo_event_callback);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010928
10929 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
10930
10931 if (ret)
Sourav Mohapatra674925f2018-04-16 11:16:58 +053010932 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010933
Dustin Brown11638b72018-01-25 17:37:25 +053010934 wlan_hdd_init_chan_info(hdd_ctx);
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010935 wlan_hdd_twt_init(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010936
Dustin Browne74003f2018-03-14 12:51:58 -070010937 hdd_exit();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010938 return 0;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010939}
10940
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010941/**
10942 * hdd_features_deinit() - Deinit features
10943 * @hdd_ctx: HDD context
10944 *
10945 * De-Initialize features and their feature context.
10946 *
10947 * Return: none.
10948 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010949static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010950{
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010951 wlan_hdd_twt_deinit(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010952 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010953 wlan_hdd_tsf_deinit(hdd_ctx);
jitiphil4e3bef42018-11-14 14:31:13 +053010954 if (cds_is_packet_log_enabled())
10955 hdd_pktlog_enable_disable(hdd_ctx, false, 0, 0);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010956}
10957
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010958/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010959 * hdd_register_bcn_cb() - register scan beacon callback
10960 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010961 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010962 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010963 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010964static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010965{
10966 QDF_STATUS status;
10967
Dustin Brown1dbefe62018-09-11 16:32:03 -070010968 status = ucfg_scan_register_bcn_cb(hdd_ctx->psoc,
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010969 wlan_cfg80211_inform_bss_frame,
10970 SCAN_CB_TYPE_INFORM_BCN);
10971 if (!QDF_IS_STATUS_SUCCESS(status)) {
Abhishek Singh5ffe9de2019-03-05 15:42:43 +053010972 hdd_err("failed to register SCAN_CB_TYPE_INFORM_BCN with status code %08d [x%08x]",
10973 status, status);
10974 return status;
10975 }
10976
10977 status = ucfg_scan_register_bcn_cb(hdd_ctx->psoc,
10978 wlan_cfg80211_unlink_bss_list,
10979 SCAN_CB_TYPE_UNLINK_BSS);
10980 if (!QDF_IS_STATUS_SUCCESS(status)) {
10981 hdd_err("failed to refister SCAN_CB_TYPE_FLUSH_BSS with status code %08d [x%08x]",
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010982 status, status);
10983 return status;
10984 }
10985
10986 return QDF_STATUS_SUCCESS;
10987}
Arun Khandavallid4349a92016-07-25 11:10:43 +053010988
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010989/**
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070010990 * hdd_v2_flow_pool_map() - Flow pool create callback when vdev is active
10991 * @vdev_id: vdev_id, corresponds to flow_pool
10992 *
10993 * Return: none.
10994 */
10995static void hdd_v2_flow_pool_map(int vdev_id)
10996{
10997 QDF_STATUS status;
10998
10999 status = cdp_flow_pool_map(cds_get_context(QDF_MODULE_ID_SOC),
11000 cds_get_context(QDF_MODULE_ID_TXRX),
11001 vdev_id);
11002 /*
11003 * For Adrastea flow control v2 is based on FW MAP events,
11004 * so this above callback is not implemented.
11005 * Hence this is not actual failure. Dont return failure
11006 */
11007 if ((status != QDF_STATUS_SUCCESS) &&
11008 (status != QDF_STATUS_E_INVAL)) {
11009 hdd_err("vdev_id: %d, failed to create flow pool status %d",
11010 vdev_id, status);
11011 }
11012}
11013
11014/**
11015 * hdd_v2_flow_pool_unmap() - Flow pool create callback when vdev is not active
11016 * @vdev_id: vdev_id, corresponds to flow_pool
11017 *
11018 * Return: none.
11019 */
11020static void hdd_v2_flow_pool_unmap(int vdev_id)
11021{
11022 cdp_flow_pool_unmap(cds_get_context(QDF_MODULE_ID_SOC),
11023 cds_get_context(QDF_MODULE_ID_TXRX), vdev_id);
11024}
11025
11026/**
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011027 * hdd_action_oui_config() - Configure action_oui strings
11028 * @hdd_ctx: pointer to hdd context
11029 *
11030 * This is a HDD wrapper function which invokes ucfg api
11031 * of action_oui component to parse action oui strings.
11032 *
11033 * Return: None
11034 */
11035static void hdd_action_oui_config(struct hdd_context *hdd_ctx)
11036{
11037 QDF_STATUS status;
11038 uint32_t id;
11039 uint8_t *str;
11040
11041 if (!hdd_ctx->config->action_oui_enable)
11042 return;
11043
11044 for (id = 0; id < ACTION_OUI_MAXIMUM_ID; id++) {
11045 str = hdd_ctx->config->action_oui_str[id];
11046 if (!qdf_str_len(str))
11047 continue;
11048
Dustin Brown1dbefe62018-09-11 16:32:03 -070011049 status = ucfg_action_oui_parse(hdd_ctx->psoc, str, id);
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011050 if (!QDF_IS_STATUS_SUCCESS(status))
11051 hdd_err("Failed to parse action_oui str: %u", id);
11052 }
11053}
11054
11055/**
11056 * hdd_action_oui_send() - Send action_oui extensions to firmware
11057 * @hdd_ctx: pointer to hdd context
11058 *
11059 * This is a HDD wrapper function which invokes ucfg api
11060 * of action_oui component to send action oui extensions to firmware.
11061 *
11062 * Return: None
11063 */
11064static void hdd_action_oui_send(struct hdd_context *hdd_ctx)
11065{
11066 QDF_STATUS status;
11067
11068 if (!hdd_ctx->config->action_oui_enable)
11069 return;
11070
Dustin Brown1dbefe62018-09-11 16:32:03 -070011071 status = ucfg_action_oui_send(hdd_ctx->psoc);
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011072 if (!QDF_IS_STATUS_SUCCESS(status))
11073 hdd_err("Failed to send one or all action_ouis");
11074}
11075
Jeff Johnson0187c622019-01-04 06:39:44 -080011076static void hdd_hastings_bt_war_initialize(struct hdd_context *hdd_ctx)
11077{
11078 if (hdd_ctx->config->iface_change_wait_time)
11079 hdd_hastings_bt_war_disable_fw(hdd_ctx);
11080 else
11081 hdd_hastings_bt_war_enable_fw(hdd_ctx);
11082}
11083
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011084/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011085 * hdd_configure_cds() - Configure cds modules
11086 * @hdd_ctx: HDD context
11087 * @adapter: Primary adapter context
11088 *
11089 * Enable Cds modules after WLAN firmware is up.
11090 *
11091 * Return: 0 on success and errno on failure.
11092 */
Dustin Browne7e71d32018-05-11 16:00:08 -070011093int hdd_configure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053011094{
11095 int ret;
11096 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011097 int set_value;
Jeff Johnson16528362018-06-14 12:34:16 -070011098 mac_handle_t mac_handle;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011099 bool enable_rts_sifsbursting;
11100 uint8_t enable_phy_reg_retention;
Krunal Sonidf29bc42018-11-15 13:26:29 -080011101 uint8_t max_mpdus_inampdu, is_force_1x1 = 0;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011102 uint32_t num_abg_tx_chains = 0;
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053011103 uint16_t num_11b_tx_chains = 0;
11104 uint16_t num_11ag_tx_chains = 0;
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070011105 struct policy_mgr_dp_cbacks dp_cbs = {0};
Bala Venkatesh2fde2c62018-09-11 20:33:24 +053011106 bool value;
Wu Gao66454f12018-09-26 19:55:41 +080011107 enum pmo_auto_pwr_detect_failure_mode auto_power_fail_mode;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053011108 bool bval = false;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011109
Jeff Johnson16528362018-06-14 12:34:16 -070011110 mac_handle = hdd_ctx->mac_handle;
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011111
11112 hdd_action_oui_send(hdd_ctx);
Krunal Sonidf29bc42018-11-15 13:26:29 -080011113 status = ucfg_policy_mgr_get_force_1x1(hdd_ctx->psoc, &is_force_1x1);
11114 if (status != QDF_STATUS_SUCCESS) {
11115 hdd_err("Failed to get force 1x1 value");
11116 goto out;
11117 }
11118 if (is_force_1x1)
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011119 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
11120 1, PDEV_CMD);
11121 /* set chip power save failure detected callback */
Jeff Johnson16528362018-06-14 12:34:16 -070011122 sme_set_chip_pwr_save_fail_cb(mac_handle,
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011123 hdd_chip_pwr_save_fail_detected_cb);
11124
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011125 status = ucfg_get_max_mpdus_inampdu(hdd_ctx->psoc,
11126 &max_mpdus_inampdu);
Krunal Sonidf29bc42018-11-15 13:26:29 -080011127 if (status) {
11128 hdd_err("Failed to get max mpdus in ampdu value");
11129 goto out;
11130 }
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011131
11132 if (max_mpdus_inampdu) {
11133 set_value = max_mpdus_inampdu;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011134 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
11135 set_value, PDEV_CMD);
11136 }
11137
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011138 status = ucfg_get_enable_rts_sifsbursting(hdd_ctx->psoc,
11139 &enable_rts_sifsbursting);
Krunal Sonidf29bc42018-11-15 13:26:29 -080011140 if (status) {
11141 hdd_err("Failed to get rts sifs bursting value");
11142 goto out;
11143 }
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011144
11145 if (enable_rts_sifsbursting) {
11146 set_value = enable_rts_sifsbursting;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011147 sme_cli_set_command(0,
11148 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
11149 set_value, PDEV_CMD);
11150 }
11151
Dustin Brown05d81302018-09-11 16:49:22 -070011152 ucfg_mlme_get_sap_get_peer_info(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +053011153 if (value) {
11154 set_value = value;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011155 sme_cli_set_command(0,
11156 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
11157 set_value, PDEV_CMD);
11158 }
11159
Dustin Brown1dbefe62018-09-11 16:32:03 -070011160 status = ucfg_mlme_get_num_11b_tx_chains(hdd_ctx->psoc,
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053011161 &num_11b_tx_chains);
11162 if (status != QDF_STATUS_SUCCESS) {
11163 hdd_err("Failed to get num_11b_tx_chains");
11164 goto out;
11165 }
11166
Dustin Brown1dbefe62018-09-11 16:32:03 -070011167 status = ucfg_mlme_get_num_11ag_tx_chains(hdd_ctx->psoc,
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053011168 &num_11ag_tx_chains);
11169 if (status != QDF_STATUS_SUCCESS) {
11170 hdd_err("Failed to get num_11ag_tx_chains");
11171 goto out;
11172 }
11173
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053011174 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
11175 if (!QDF_IS_STATUS_SUCCESS(status))
11176 hdd_err("unable to get vht_enable2x2");
11177
11178 if (!bval) {
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011179 if (num_11b_tx_chains > 1)
11180 num_11b_tx_chains = 1;
11181 if (num_11ag_tx_chains > 1)
11182 num_11ag_tx_chains = 1;
11183 }
11184 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
11185 num_11b_tx_chains);
11186 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
11187 num_11ag_tx_chains);
11188 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
11189 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +053011190
Paul Zhang02526cd2018-09-20 17:47:46 +080011191 if (!ucfg_reg_is_regdb_offloaded(hdd_ctx->psoc))
11192 ucfg_reg_program_default_cc(hdd_ctx->pdev,
11193 hdd_ctx->reg.reg_domain);
11194
Arun Khandavallifae92942016-08-01 13:31:08 +053011195 ret = hdd_pre_enable_configure(hdd_ctx);
11196 if (ret) {
11197 hdd_err("Failed to pre-configure cds");
11198 goto out;
11199 }
11200
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080011201 /* Always get latest IPA resources allocated from cds_open and configure
11202 * IPA module before configuring them to FW. Sequence required as crash
11203 * observed otherwise.
11204 */
Dustin Brown07901ec2018-09-07 11:02:41 -070011205 if (ucfg_ipa_uc_ol_init(hdd_ctx->pdev,
11206 cds_get_context(QDF_MODULE_ID_QDF_DEVICE))) {
Manikandan Mohan2e803a02017-02-14 14:57:53 -080011207 hdd_err("Failed to setup pipes");
11208 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080011209 }
11210
Arun Khandavallifae92942016-08-01 13:31:08 +053011211 /*
11212 * Start CDS which starts up the SME/MAC/HAL modules and everything
11213 * else
11214 */
Dustin Brown1dbefe62018-09-11 16:32:03 -070011215 status = cds_enable(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053011216
11217 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011218 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053011219 goto out;
11220 }
11221
11222 status = hdd_post_cds_enable_config(hdd_ctx);
11223 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011224 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011225 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053011226 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +053011227 status = hdd_register_bcn_cb(hdd_ctx);
11228 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +080011229 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +053011230 goto cds_disable;
11231 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011232
Dustin Browne7e71d32018-05-11 16:00:08 -070011233 ret = hdd_features_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053011234 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011235 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053011236
Mohit Khanna81418772018-10-30 14:14:46 -070011237 /* Donot disable rx offload on concurrency for lithium based targets */
11238 if (!(hdd_ctx->target_type == TARGET_TYPE_QCA6290 ||
11239 hdd_ctx->target_type == TARGET_TYPE_QCA6390))
11240 if (hdd_ctx->ol_enable)
11241 dp_cbs.hdd_disable_rx_ol_in_concurrency =
11242 hdd_disable_rx_ol_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -070011243 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
jiadbb47e132018-03-30 16:28:30 +080011244 dp_cbs.hdd_ipa_set_mcc_mode_cb = hdd_ipa_set_mcc_mode;
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070011245 dp_cbs.hdd_v2_flow_pool_map = hdd_v2_flow_pool_map;
11246 dp_cbs.hdd_v2_flow_pool_unmap = hdd_v2_flow_pool_unmap;
Dustin Brown1dbefe62018-09-11 16:32:03 -070011247 status = policy_mgr_register_dp_cb(hdd_ctx->psoc, &dp_cbs);
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070011248 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -070011249 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070011250 goto cds_disable;
11251 }
Dustin Brown1dbefe62018-09-11 16:32:03 -070011252 status = policy_mgr_register_mode_change_cb(hdd_ctx->psoc,
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053011253 wlan_hdd_send_mode_change_event);
11254 if (!QDF_IS_STATUS_SUCCESS(status)) {
11255 hdd_debug("Failed to register mode change cb with Policy Manager");
11256 goto cds_disable;
11257 }
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070011258
Jeff Johnson8bb61112018-03-31 13:33:54 -070011259 if (hdd_green_ap_enable_egap(hdd_ctx))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +053011260 hdd_debug("enhance green ap is not enabled");
11261
Nachiket Kukadedd302662017-07-13 17:31:44 +053011262 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
11263 hdd_debug("Failed to set wow pulse");
11264
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053011265 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
Manikandan Mohan66df7fc2019-01-08 17:57:05 -080011266 ucfg_fwol_get_gcmp_enable(hdd_ctx->psoc), PDEV_CMD);
Wu Gao66454f12018-09-26 19:55:41 +080011267
11268 auto_power_fail_mode =
11269 ucfg_pmo_get_auto_power_fail_mode(hdd_ctx->psoc);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053011270 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
Wu Gao66454f12018-09-26 19:55:41 +080011271 auto_power_fail_mode, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053011272
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011273 status = ucfg_get_enable_phy_reg_retention(hdd_ctx->psoc,
11274 &enable_phy_reg_retention);
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053011275
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011276 if (QDF_IS_STATUS_ERROR(status))
11277 return -EINVAL;
11278
11279 if (enable_phy_reg_retention)
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053011280 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011281 enable_phy_reg_retention, PDEV_CMD);
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053011282
Jeff Johnson0187c622019-01-04 06:39:44 -080011283 hdd_hastings_bt_war_initialize(hdd_ctx);
11284
Arun Khandavallifae92942016-08-01 13:31:08 +053011285 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011286
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011287cds_disable:
Dustin Brown1dbefe62018-09-11 16:32:03 -070011288 cds_disable(hdd_ctx->psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011289
Arun Khandavallifae92942016-08-01 13:31:08 +053011290out:
11291 return -EINVAL;
11292}
11293
11294/**
11295 * hdd_deconfigure_cds() -De-Configure cds
11296 * @hdd_ctx: HDD context
11297 *
11298 * Deconfigure Cds modules before WLAN firmware is down.
11299 *
11300 * Return: 0 on success and errno on failure.
11301 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011302static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053011303{
11304 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070011305 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011306
Dustin Brown491d54b2018-03-14 12:39:11 -070011307 hdd_enter();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080011308
11309 /* De-init features */
11310 hdd_features_deinit(hdd_ctx);
11311
Dustin Brown1dbefe62018-09-11 16:32:03 -070011312 qdf_status = policy_mgr_deregister_mode_change_cb(hdd_ctx->psoc);
Srinivas Girigowdad2412882018-09-07 15:42:04 -070011313 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053011314 hdd_debug("Failed to deregister mode change cb with Policy Manager");
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053011315
Dustin Brown1dbefe62018-09-11 16:32:03 -070011316 qdf_status = cds_disable(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053011317 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11318 hdd_err("Failed to Disable the CDS Modules! :%d",
11319 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070011320 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011321 }
11322
Dustin Brown07901ec2018-09-07 11:02:41 -070011323 if (ucfg_ipa_uc_ol_deinit(hdd_ctx->pdev) != QDF_STATUS_SUCCESS) {
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053011324 hdd_err("Failed to disconnect pipes");
11325 ret = -EINVAL;
11326 }
11327
Dustin Browne74003f2018-03-14 12:51:58 -070011328 hdd_exit();
Houston Hoffman6640cf32016-10-10 16:44:29 -070011329 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053011330}
11331
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070011332#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
11333static void hdd_deregister_policy_manager_callback(
11334 struct wlan_objmgr_psoc *psoc)
11335{
11336 if (QDF_STATUS_SUCCESS !=
11337 policy_mgr_deregister_hdd_cb(psoc)) {
11338 hdd_err("HDD callback deregister with policy manager failed");
11339 }
11340}
11341#else
11342static void hdd_deregister_policy_manager_callback(
11343 struct wlan_objmgr_psoc *psoc)
11344{
11345}
11346#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053011347
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011348int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053011349{
11350 void *hif_ctx;
11351 qdf_device_t qdf_ctx;
11352 QDF_STATUS qdf_status;
Dustin Brown4bc0a622017-12-06 15:56:50 -080011353 bool is_recovery_stop = cds_is_driver_recovering();
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053011354 int ret = 0;
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053011355 int debugfs_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053011356 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053011357
Dustin Brown491d54b2018-03-14 12:39:11 -070011358 hdd_enter();
Arun Khandavallifae92942016-08-01 13:31:08 +053011359
Dustin Brown1dbefe62018-09-11 16:32:03 -070011360 hdd_deregister_policy_manager_callback(hdd_ctx->psoc);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070011361
Arun Khandavallifae92942016-08-01 13:31:08 +053011362 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11363 if (!qdf_ctx) {
11364 hdd_err("QDF device context NULL");
11365 return -EINVAL;
11366 }
11367
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011368 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011369
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053011370 debugfs_threads = hdd_return_debugfs_threads_count();
Dustin Brown70111822017-03-30 15:31:40 -070011371
Dustin Brown3fdaaf62019-03-18 14:00:16 -070011372 if (debugfs_threads > 0 || hdd_ctx->is_wiphy_suspended) {
11373 hdd_warn("Debugfs threads %d, wiphy suspend %d",
11374 debugfs_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -070011375
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053011376 if (IS_IDLE_STOP && !ftm_mode) {
Dustin Brown4c663222018-10-23 14:19:36 -070011377 hdd_psoc_idle_timer_start(hdd_ctx);
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011378 cds_set_module_stop_in_progress(false);
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011379
Dustin Brown70111822017-03-30 15:31:40 -070011380 return 0;
11381 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070011382 }
11383
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080011384 /* free user wowl patterns */
11385 hdd_free_user_wowl_ptrns();
11386
Arun Khandavallifae92942016-08-01 13:31:08 +053011387 switch (hdd_ctx->driver_status) {
11388 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011389 hdd_debug("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011390 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011391 case DRIVER_MODULES_CLOSED:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011392 hdd_debug("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011393 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011394 case DRIVER_MODULES_ENABLED:
Dustin Brown1a20b082018-08-03 17:27:15 -070011395 hdd_info("Wlan transitioning (CLOSED <- ENABLED)");
11396
Nirav Shah6aeecf92019-02-13 14:05:03 +053011397 if (hdd_get_conparam() == QDF_GLOBAL_FTM_MODE ||
11398 hdd_get_conparam() == QDF_GLOBAL_EPPING_MODE)
Dustin Brown1a20b082018-08-03 17:27:15 -070011399 break;
Dustin Brown550f6d22017-12-14 15:44:01 -080011400
Komal Seelamf2136bb2016-09-28 18:30:44 +053011401 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053011402 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011403 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053011404 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011405 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011406 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011407 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080011408
Arun Khandavallifae92942016-08-01 13:31:08 +053011409 break;
11410 default:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011411 QDF_DEBUG_PANIC("Unknown driver state:%d",
Arun Khandavallifae92942016-08-01 13:31:08 +053011412 hdd_ctx->driver_status);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011413 ret = -EINVAL;
11414 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011415 }
11416
Arunk Khandavalli890f6d92018-10-30 20:18:28 +053011417 hdd_sysfs_destroy_powerstats_interface();
Amar Singhal18081642018-01-26 16:04:13 -080011418 hdd_sysfs_destroy_version_interface();
Arunk Khandavalli890f6d92018-10-30 20:18:28 +053011419 hdd_sysfs_destroy_driver_root_obj();
Dustin Brown550f6d22017-12-14 15:44:01 -080011420 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080011421
Nirav Shah6aeecf92019-02-13 14:05:03 +053011422 if (hdd_get_conparam() != QDF_GLOBAL_EPPING_MODE) {
11423 qdf_status = cds_post_disable();
11424 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11425 hdd_err("Failed to process post CDS disable! :%d",
11426 qdf_status);
11427 ret = -EINVAL;
11428 QDF_ASSERT(0);
11429 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011430
Nirav Shah6aeecf92019-02-13 14:05:03 +053011431 /* De-register the SME callbacks */
11432 hdd_deregister_cb(hdd_ctx);
Sourav Mohapatra674925f2018-04-16 11:16:58 +053011433
Nirav Shah6aeecf92019-02-13 14:05:03 +053011434 hdd_runtime_suspend_context_deinit(hdd_ctx);
psimhadeea0a12017-12-18 14:50:02 -080011435
Nirav Shah6aeecf92019-02-13 14:05:03 +053011436 qdf_status = cds_dp_close(hdd_ctx->psoc);
11437 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11438 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
11439 ret = -EINVAL;
11440 QDF_ASSERT(0);
11441 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011442
Nirav Shah6aeecf92019-02-13 14:05:03 +053011443 qdf_status = cds_close(hdd_ctx->psoc);
11444 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11445 hdd_warn("Failed to stop CDS: %d", qdf_status);
11446 ret = -EINVAL;
11447 QDF_ASSERT(0);
11448 }
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053011449
Nirav Shah6aeecf92019-02-13 14:05:03 +053011450 qdf_status = wbuff_module_deinit();
11451 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
11452 hdd_err("WBUFF de-init unsuccessful; status: %d",
11453 qdf_status);
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053011454
Nirav Shah6aeecf92019-02-13 14:05:03 +053011455 hdd_component_pdev_close(hdd_ctx->pdev);
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053011456
Nirav Shah6aeecf92019-02-13 14:05:03 +053011457 hdd_component_psoc_close(hdd_ctx->psoc);
11458 dispatcher_pdev_close(hdd_ctx->pdev);
11459 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
11460 if (ret) {
11461 hdd_err("Failed to destroy pdev; errno:%d", ret);
11462 QDF_ASSERT(0);
11463 }
Liangwei Dong50a64a72018-01-11 01:17:00 -050011464 }
11465
11466 /*
11467 * Reset total mac phy during module stop such that during
11468 * next module start same psoc is used to populate new service
11469 * ready data
11470 */
Dustin Brown1dbefe62018-09-11 16:32:03 -070011471 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->psoc);
Arunk Khandavallia6305a32018-01-25 11:19:18 +053011472 if (tgt_hdl)
11473 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
11474
Liangwei Dong50a64a72018-01-11 01:17:00 -050011475
Arun Khandavallifae92942016-08-01 13:31:08 +053011476 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
11477 if (!hif_ctx) {
11478 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011479 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011480 }
11481
Arunk Khandavalli4b404332017-09-26 12:46:00 +053011482 if (hdd_ctx->target_hw_name) {
11483 qdf_mem_free(hdd_ctx->target_hw_name);
11484 hdd_ctx->target_hw_name = NULL;
11485 }
11486
Visweswara Tanukuc949ad22019-03-20 13:00:30 +053011487 if (hdd_get_conparam() != QDF_GLOBAL_EPPING_MODE) {
11488 epping_disable();
11489 epping_close();
11490 }
11491
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053011492 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053011493
11494 ol_cds_free();
11495
Dustin Brownc2a156e2018-10-25 16:56:27 -070011496 if (IS_IDLE_STOP) {
Arun Khandavallifae92942016-08-01 13:31:08 +053011497 ret = pld_power_off(qdf_ctx->dev);
11498 if (ret)
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011499 hdd_err("Failed to power down device; errno:%d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053011500 }
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011501
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011502 /* Free the cache channels of the command SET_DISABLE_CHANNEL_LIST */
11503 wlan_hdd_free_cache_channels(hdd_ctx);
Arunk Khandavalli847969d2017-09-25 15:15:36 +053011504
Jingxiang Ge3de02752019-01-29 15:47:03 +080011505 hdd_sap_destroy_ctx_all(hdd_ctx, is_recovery_stop);
11506
Dustin Brown29533f22018-07-24 13:11:56 -070011507 hdd_check_for_leaks(hdd_ctx, is_recovery_stop);
Dustin Brown26b3d042017-12-21 11:13:27 -080011508 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080011509
Arunk Khandavalli847969d2017-09-25 15:15:36 +053011510 /* Once the firmware sequence is completed reset this flag */
11511 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053011512 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080011513 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053011514
Kai Liueabb1df2018-11-08 14:58:54 +080011515 pld_request_bus_bandwidth(hdd_ctx->parent_dev, PLD_BUS_WIDTH_NONE);
11516
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011517done:
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011518 cds_set_module_stop_in_progress(false);
Dustin Brown4bc0a622017-12-06 15:56:50 -080011519
Dustin Browne74003f2018-03-14 12:51:58 -070011520 hdd_exit();
Arun Khandavallifae92942016-08-01 13:31:08 +053011521
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011522 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053011523}
11524
Wen Gong3f003382018-05-14 14:26:37 +080011525#ifdef WLAN_FEATURE_MEMDUMP_ENABLE
Arun Khandavallifae92942016-08-01 13:31:08 +053011526/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011527 * hdd_state_info_dump() - prints state information of hdd layer
11528 * @buf: buffer pointer
11529 * @size: size of buffer to be filled
11530 *
11531 * This function is used to dump state information of hdd layer
11532 *
11533 * Return: None
11534 */
11535static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
11536{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011537 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070011538 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070011539 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011540 uint16_t len = 0;
11541 char *buf = *buf_ptr;
11542
11543 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11544 if (!hdd_ctx) {
11545 hdd_err("Failed to get hdd context ");
11546 return;
11547 }
11548
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011549 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011550
11551 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070011552 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011553 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080011554 "\n is_scheduler_suspended %d",
11555 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011556
Dustin Brown920397d2017-12-13 16:27:50 -080011557 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011558 if (adapter->dev)
11559 len += scnprintf(buf + len, *size - len,
11560 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080011561 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011562 "\n device_mode: %d", adapter->device_mode);
11563 switch (adapter->device_mode) {
11564 case QDF_STA_MODE:
11565 case QDF_P2P_CLIENT_MODE:
11566 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11567 len += scnprintf(buf + len, *size - len,
Jeff Johnsone7951512019-02-27 10:02:51 -080011568 "\n conn_state: %d",
11569 hdd_sta_ctx->conn_info.conn_state);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011570 break;
11571
11572 default:
11573 break;
11574 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011575 }
11576
11577 *size -= len;
11578 *buf_ptr += len;
11579}
11580
11581/**
11582 * hdd_register_debug_callback() - registration function for hdd layer
11583 * to print hdd state information
11584 *
11585 * Return: None
11586 */
11587static void hdd_register_debug_callback(void)
11588{
11589 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
11590}
Wen Gong3f003382018-05-14 14:26:37 +080011591#else /* WLAN_FEATURE_MEMDUMP_ENABLE */
Wen Gongaa6d55d2018-04-26 16:33:21 +080011592static void hdd_register_debug_callback(void)
11593{
11594}
Wen Gong3f003382018-05-14 14:26:37 +080011595#endif /* WLAN_FEATURE_MEMDUMP_ENABLE */
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011596
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053011597/*
11598 * wlan_init_bug_report_lock() - Initialize bug report lock
11599 *
11600 * This function is used to create bug report lock
11601 *
11602 * Return: None
11603 */
11604static void wlan_init_bug_report_lock(void)
11605{
Jeff Johnson2b6982c2018-05-29 14:56:11 -070011606 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053011607
11608 p_cds_context = cds_get_global_context();
11609 if (!p_cds_context) {
11610 hdd_err("cds context is NULL");
11611 return;
11612 }
11613
11614 qdf_spinlock_create(&p_cds_context->bug_report_lock);
11615}
11616
Nirav Shahd21a2e32018-04-20 16:34:43 +053011617#ifdef CONFIG_DP_TRACE
Mohit Khannaf8f96822017-05-17 17:11:59 -070011618void hdd_dp_trace_init(struct hdd_config *config)
11619{
Mohit Khannaf8f96822017-05-17 17:11:59 -070011620 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
11621 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
11622 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
11623 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
11624 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
11625 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
11626 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080011627 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070011628
Nirav Shahd21a2e32018-04-20 16:34:43 +053011629 if (!config->enable_dp_trace) {
11630 hdd_err("dp trace is disabled from ini");
11631 return;
11632 }
11633
Mohit Khannaf8f96822017-05-17 17:11:59 -070011634 hdd_string_to_u8_array(config->dp_trace_config, config_params,
11635 &num_entries, sizeof(config_params));
11636
11637 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080011638 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080011639 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080011640 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080011641 else if (bw_compute_interval > 1000) {
11642 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
11643 thresh_time_limit = 1;
11644 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070011645 hdd_err("busBandwidthComputeInterval is 0, using defaults");
11646
11647 switch (num_entries) {
11648 case 4:
11649 proto_bitmap = config_params[3];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011650 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011651 case 3:
11652 verbosity = config_params[2];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011653 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011654 case 2:
11655 thresh = config_params[1];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011656 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011657 case 1:
11658 live_mode = config_params[0];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011659 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011660 default:
Dustin Browna7bb6ae2018-08-16 16:51:50 -070011661 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
11662 live_mode, thresh, thresh_time_limit,
11663 verbosity, proto_bitmap);
Mohit Khannaf8f96822017-05-17 17:11:59 -070011664 };
11665
11666 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
11667 verbosity, proto_bitmap);
11668
11669}
Nirav Shahd21a2e32018-04-20 16:34:43 +053011670#endif
11671
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011672#ifdef DISABLE_CHANNEL_LIST
Dustin Brown623e7e32018-09-05 14:27:50 -070011673static QDF_STATUS wlan_hdd_cache_chann_mutex_create(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011674{
11675 return qdf_mutex_create(&hdd_ctx->cache_channel_lock);
11676}
11677#else
Dustin Brown623e7e32018-09-05 14:27:50 -070011678static QDF_STATUS wlan_hdd_cache_chann_mutex_create(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011679{
Dustin Brown623e7e32018-09-05 14:27:50 -070011680 return QDF_STATUS_SUCCESS;
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011681}
11682#endif
11683
Dustin Brown693b5352019-01-17 10:00:31 -080011684static QDF_STATUS hdd_open_adapter_no_trans(struct hdd_context *hdd_ctx,
11685 enum QDF_OPMODE op_mode,
11686 const char *iface_name,
11687 uint8_t *mac_addr_bytes)
11688{
Dustin Brown2c5e0482019-02-05 16:14:43 -080011689 struct osif_vdev_sync *vdev_sync;
Dustin Brown693b5352019-01-17 10:00:31 -080011690 struct hdd_adapter *adapter;
11691 QDF_STATUS status;
11692 int errno;
11693
11694 QDF_BUG(rtnl_is_locked());
Dustin Brown693b5352019-01-17 10:00:31 -080011695
Dustin Brown2c5e0482019-02-05 16:14:43 -080011696 errno = osif_vdev_sync_create(hdd_ctx->parent_dev, &vdev_sync);
Dustin Brown693b5352019-01-17 10:00:31 -080011697 if (errno)
11698 return qdf_status_from_os_return(errno);
11699
11700 adapter = hdd_open_adapter(hdd_ctx, op_mode, iface_name,
11701 mac_addr_bytes, NET_NAME_UNKNOWN, true);
11702 if (!adapter) {
11703 status = QDF_STATUS_E_INVAL;
11704 goto destroy_sync;
11705 }
11706
Dustin Brown2c5e0482019-02-05 16:14:43 -080011707 osif_vdev_sync_register(adapter->dev, vdev_sync);
Dustin Brown693b5352019-01-17 10:00:31 -080011708
11709 return QDF_STATUS_SUCCESS;
11710
11711destroy_sync:
Dustin Brown2c5e0482019-02-05 16:14:43 -080011712 osif_vdev_sync_destroy(vdev_sync);
Dustin Brown693b5352019-01-17 10:00:31 -080011713
11714 return status;
11715}
11716
11717#ifdef WLAN_OPEN_P2P_INTERFACE
11718/**
11719 * hdd_open_p2p_interface - Open P2P interface
11720 * @hdd_ctx: HDD context
11721 *
11722 * Return: QDF_STATUS
11723 */
11724static QDF_STATUS hdd_open_p2p_interface(struct hdd_context *hdd_ctx)
11725{
11726 QDF_STATUS status;
11727 bool p2p_dev_addr_admin;
11728 bool is_p2p_locally_administered = false;
11729
11730 cfg_p2p_get_device_addr_admin(hdd_ctx->psoc, &p2p_dev_addr_admin);
11731
11732 if (p2p_dev_addr_admin) {
11733 if (hdd_ctx->num_provisioned_addr &&
11734 !(hdd_ctx->provisioned_mac_addr[0].bytes[0] & 0x02)) {
11735 hdd_ctx->p2p_device_address =
11736 hdd_ctx->provisioned_mac_addr[0];
11737
11738 /*
11739 * Generate the P2P Device Address. This consists of
11740 * the device's primary MAC address with the locally
11741 * administered bit set.
11742 */
11743
11744 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
11745 is_p2p_locally_administered = true;
11746 } else if (!(hdd_ctx->derived_mac_addr[0].bytes[0] & 0x02)) {
11747 hdd_ctx->p2p_device_address =
11748 hdd_ctx->derived_mac_addr[0];
11749 /*
11750 * Generate the P2P Device Address. This consists of
11751 * the device's primary MAC address with the locally
11752 * administered bit set.
11753 */
11754 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
11755 is_p2p_locally_administered = true;
11756 }
11757 }
11758 if (!is_p2p_locally_administered) {
11759 uint8_t *p2p_dev_addr;
11760
11761 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx,
11762 QDF_P2P_DEVICE_MODE);
11763 if (!p2p_dev_addr) {
11764 hdd_err("Failed to get MAC address for new p2p device");
11765 return QDF_STATUS_E_INVAL;
11766 }
11767
11768 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
11769 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
11770 }
11771
11772 status = hdd_open_adapter_no_trans(hdd_ctx, QDF_P2P_DEVICE_MODE,
11773 "p2p%d",
11774 hdd_ctx->p2p_device_address.bytes);
11775 if (QDF_IS_STATUS_ERROR(status)) {
11776 hdd_err("Failed to open p2p interface");
11777 return QDF_STATUS_E_INVAL;
11778 }
11779
11780 return QDF_STATUS_SUCCESS;
11781}
11782#else
11783static inline QDF_STATUS hdd_open_p2p_interface(struct hdd_context *hdd_ctx)
11784{
11785 return QDF_STATUS_SUCCESS;
11786}
11787#endif
11788
11789static QDF_STATUS hdd_open_ocb_interface(struct hdd_context *hdd_ctx)
11790{
11791 QDF_STATUS status;
11792 uint8_t *mac_addr;
11793
11794 mac_addr = wlan_hdd_get_intf_addr(hdd_ctx, QDF_OCB_MODE);
11795 status = hdd_open_adapter_no_trans(hdd_ctx, QDF_OCB_MODE,
11796 "wlanocb%d", mac_addr);
11797 if (QDF_IS_STATUS_ERROR(status))
11798 hdd_err("Failed to open 802.11p interface");
11799
11800 return status;
11801}
11802
11803static QDF_STATUS hdd_open_concurrent_interface(struct hdd_context *hdd_ctx)
11804{
11805 QDF_STATUS status;
11806 const char *iface_name;
11807 uint8_t *mac_addr;
11808
11809 if (qdf_str_eq(hdd_ctx->config->enable_concurrent_sta, ""))
11810 return QDF_STATUS_SUCCESS;
11811
11812 iface_name = hdd_ctx->config->enable_concurrent_sta;
11813 mac_addr = wlan_hdd_get_intf_addr(hdd_ctx, QDF_STA_MODE);
11814 status = hdd_open_adapter_no_trans(hdd_ctx, QDF_STA_MODE,
11815 iface_name, mac_addr);
11816 if (QDF_IS_STATUS_ERROR(status))
11817 hdd_err("Failed to open concurrent station interface");
11818
11819 return status;
11820}
11821
Dustin Brown61cc3932018-10-18 16:12:13 -070011822static QDF_STATUS
11823hdd_open_adapters_for_mission_mode(struct hdd_context *hdd_ctx)
Dustin Browna2deeb72018-10-18 14:19:27 -070011824{
Dustin Browna2deeb72018-10-18 14:19:27 -070011825 enum dot11p_mode dot11p_mode;
Dustin Brown61cc3932018-10-18 16:12:13 -070011826 QDF_STATUS status;
Dustin Brown693b5352019-01-17 10:00:31 -080011827 uint8_t *mac_addr;
Dustin Browna2deeb72018-10-18 14:19:27 -070011828
11829 ucfg_mlme_get_dot11p_mode(hdd_ctx->psoc, &dot11p_mode);
11830
11831 /* Create only 802.11p interface? */
11832 if (dot11p_mode == CFG_11P_STANDALONE)
Dustin Brown61cc3932018-10-18 16:12:13 -070011833 return hdd_open_ocb_interface(hdd_ctx);
Dustin Browna2deeb72018-10-18 14:19:27 -070011834
Dustin Brown693b5352019-01-17 10:00:31 -080011835 mac_addr = wlan_hdd_get_intf_addr(hdd_ctx, QDF_STA_MODE);
11836 status = hdd_open_adapter_no_trans(hdd_ctx, QDF_STA_MODE,
11837 "wlan%d", mac_addr);
11838 if (QDF_IS_STATUS_ERROR(status))
11839 return status;
Dustin Browna2deeb72018-10-18 14:19:27 -070011840
Dustin Brown61cc3932018-10-18 16:12:13 -070011841 /* opening concurrent STA is best effort, continue on error */
11842 hdd_open_concurrent_interface(hdd_ctx);
Dustin Browna2deeb72018-10-18 14:19:27 -070011843
Dustin Brown61cc3932018-10-18 16:12:13 -070011844 status = hdd_open_p2p_interface(hdd_ctx);
11845 if (status)
Dustin Browna2deeb72018-10-18 14:19:27 -070011846 goto err_close_adapters;
11847
11848 /* Open 802.11p Interface */
11849 if (dot11p_mode == CFG_11P_CONCURRENT) {
Dustin Brown61cc3932018-10-18 16:12:13 -070011850 status = hdd_open_ocb_interface(hdd_ctx);
11851 if (QDF_IS_STATUS_ERROR(status))
Dustin Browna2deeb72018-10-18 14:19:27 -070011852 goto err_close_adapters;
11853 }
11854
Dustin Brown61cc3932018-10-18 16:12:13 -070011855 return QDF_STATUS_SUCCESS;
Dustin Browna2deeb72018-10-18 14:19:27 -070011856
11857err_close_adapters:
11858 hdd_close_all_adapters(hdd_ctx, true);
11859
Dustin Brown61cc3932018-10-18 16:12:13 -070011860 return status;
Dustin Browna2deeb72018-10-18 14:19:27 -070011861}
11862
Dustin Brown61cc3932018-10-18 16:12:13 -070011863static QDF_STATUS hdd_open_adapters_for_ftm_mode(struct hdd_context *hdd_ctx)
Dustin Browna2deeb72018-10-18 14:19:27 -070011864{
Dustin Brown693b5352019-01-17 10:00:31 -080011865 uint8_t *mac_addr = wlan_hdd_get_intf_addr(hdd_ctx, QDF_FTM_MODE);
Dustin Brown61cc3932018-10-18 16:12:13 -070011866
Dustin Brown693b5352019-01-17 10:00:31 -080011867 return hdd_open_adapter_no_trans(hdd_ctx, QDF_FTM_MODE,
11868 "wlan%d", mac_addr);
Dustin Brown61cc3932018-10-18 16:12:13 -070011869}
11870
11871static QDF_STATUS
11872hdd_open_adapters_for_monitor_mode(struct hdd_context *hdd_ctx)
11873{
Dustin Brown693b5352019-01-17 10:00:31 -080011874 uint8_t *mac_addr = wlan_hdd_get_intf_addr(hdd_ctx, QDF_MONITOR_MODE);
Dustin Brown61cc3932018-10-18 16:12:13 -070011875
Dustin Brown693b5352019-01-17 10:00:31 -080011876 return hdd_open_adapter_no_trans(hdd_ctx, QDF_MONITOR_MODE,
11877 "wlan%d", mac_addr);
Dustin Brown61cc3932018-10-18 16:12:13 -070011878}
11879
11880static QDF_STATUS hdd_open_adapters_for_epping_mode(struct hdd_context *hdd_ctx)
11881{
Nirav Shah6aeecf92019-02-13 14:05:03 +053011882 epping_enable_adapter();
Dustin Brown61cc3932018-10-18 16:12:13 -070011883 return QDF_STATUS_SUCCESS;
Dustin Brown61cc3932018-10-18 16:12:13 -070011884}
11885
11886typedef QDF_STATUS (*hdd_open_mode_handler)(struct hdd_context *hdd_ctx);
11887
11888static const hdd_open_mode_handler
11889hdd_open_mode_handlers[QDF_GLOBAL_MAX_MODE] = {
11890 [QDF_GLOBAL_MISSION_MODE] = hdd_open_adapters_for_mission_mode,
11891 [QDF_GLOBAL_FTM_MODE] = hdd_open_adapters_for_ftm_mode,
11892 [QDF_GLOBAL_MONITOR_MODE] = hdd_open_adapters_for_monitor_mode,
11893 [QDF_GLOBAL_EPPING_MODE] = hdd_open_adapters_for_epping_mode,
11894};
11895
Dustin Brown92bd8382018-10-31 15:49:46 -070011896static QDF_STATUS hdd_open_adapters_for_mode(struct hdd_context *hdd_ctx,
11897 enum QDF_GLOBAL_MODE driver_mode)
Dustin Brown61cc3932018-10-18 16:12:13 -070011898{
11899 QDF_STATUS status;
11900
11901 if (driver_mode < 0 ||
11902 driver_mode >= QDF_GLOBAL_MAX_MODE ||
11903 !hdd_open_mode_handlers[driver_mode]) {
11904 hdd_err("Driver mode %d not supported", driver_mode);
11905 return -ENOTSUPP;
11906 }
Dustin Browna2deeb72018-10-18 14:19:27 -070011907
11908 hdd_hold_rtnl_lock();
Dustin Brown61cc3932018-10-18 16:12:13 -070011909 status = hdd_open_mode_handlers[driver_mode](hdd_ctx);
Dustin Browna2deeb72018-10-18 14:19:27 -070011910 hdd_release_rtnl_lock();
11911
Dustin Brown92bd8382018-10-31 15:49:46 -070011912 return status;
Dustin Browna2deeb72018-10-18 14:19:27 -070011913}
11914
Dustin Brown623e7e32018-09-05 14:27:50 -070011915int hdd_wlan_startup(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011916{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011917 QDF_STATUS status;
Dustin Brown623e7e32018-09-05 14:27:50 -070011918 int errno;
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +053011919 bool is_imps_enabled;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011920
Dustin Brown491d54b2018-03-14 12:39:11 -070011921 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011922
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011923 hdd_action_oui_config(hdd_ctx);
11924
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053011925 qdf_nbuf_init_replenish_timer();
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011926
Dustin Brown623e7e32018-09-05 14:27:50 -070011927 status = wlan_hdd_cache_chann_mutex_create(hdd_ctx);
11928 if (QDF_IS_STATUS_ERROR(status))
11929 return qdf_status_to_os_return(status);
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011930
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053011931#ifdef FEATURE_WLAN_CH_AVOID
11932 mutex_init(&hdd_ctx->avoid_freq_lock);
11933#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053011934
Naveen Rawate02f8f52018-04-05 11:58:04 -070011935 osif_request_manager_init();
Dustin Brown021cecd2017-12-11 13:56:43 -080011936 hdd_driver_memdump_init();
Dustin Brown86d196b2018-08-02 11:51:49 -070011937 hdd_bus_bandwidth_init(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -080011938
Arunk Khandavalli5ff0375472019-01-11 17:26:47 +053011939#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
11940 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
11941 QDF_TIMER_TYPE_SW,
11942 hdd_skip_acs_scan_timer_handler,
11943 hdd_ctx);
11944 if (QDF_IS_STATUS_ERROR(status))
11945 hdd_err("Failed to init ACS Skip timer");
11946 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
11947#endif
11948
Dustin Brown623e7e32018-09-05 14:27:50 -070011949 errno = hdd_wlan_start_modules(hdd_ctx, false);
11950 if (errno) {
11951 hdd_err("Failed to start modules; errno:%d", errno);
11952 goto memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011953 }
11954
Nirav Shah6aeecf92019-02-13 14:05:03 +053011955 if (hdd_get_conparam() == QDF_GLOBAL_EPPING_MODE)
11956 return 0;
11957
Yingying Tang80e15f32016-09-27 18:23:01 +080011958 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011959
Dustin Brown623e7e32018-09-05 14:27:50 -070011960 hdd_ctx->mac_handle = cds_get_context(QDF_MODULE_ID_SME);
11961 if (!hdd_ctx->mac_handle) {
Jeff Johnson16528362018-06-14 12:34:16 -070011962 hdd_err("Mac Handle is null");
Dustin Brown623e7e32018-09-05 14:27:50 -070011963 goto stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011964 }
11965
Dustin Brown623e7e32018-09-05 14:27:50 -070011966 errno = hdd_wiphy_init(hdd_ctx);
11967 if (errno) {
11968 hdd_err("Failed to initialize wiphy; errno:%d", errno);
11969 goto stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011970 }
11971
Nirav Shahd21a2e32018-04-20 16:34:43 +053011972 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053011973
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053011974 errno = hdd_initialize_mac_address(hdd_ctx);
11975 if (errno) {
11976 hdd_err("MAC initializtion failed: %d", errno);
11977 goto unregister_wiphy;
11978 }
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080011979
Dustin Brown623e7e32018-09-05 14:27:50 -070011980 errno = register_netdevice_notifier(&hdd_netdev_notifier);
11981 if (errno) {
11982 hdd_err("register_netdevice_notifier failed; errno:%d", errno);
11983 goto unregister_wiphy;
Paul Zhangfb02f452017-12-22 11:58:43 +080011984 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053011985
Dustin Brown623e7e32018-09-05 14:27:50 -070011986 errno = register_reboot_notifier(&system_reboot_notifier);
11987 if (errno) {
11988 hdd_err("Failed to register reboot notifier; errno:%d", errno);
11989 goto unregister_netdev;
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011990 }
11991
Sandeep Puligilla34618782019-01-04 17:42:42 -080011992 wlan_hdd_update_11n_mode(hdd_ctx);
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080011993
Arunk Khandavalli40943af2017-05-15 19:25:34 +053011994 hdd_lpass_notify_wlan_version(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011995
Dustin Brown623e7e32018-09-05 14:27:50 -070011996 errno = hdd_register_notifiers(hdd_ctx);
11997 if (errno)
11998 goto unregister_reboot;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070011999
Paul Zhangfb02f452017-12-22 11:58:43 +080012000 status = wlansap_global_init();
Dustin Brown92bd8382018-10-31 15:49:46 -070012001 if (QDF_IS_STATUS_ERROR(status))
12002 goto unregister_notifiers;
Paul Zhangfb02f452017-12-22 11:58:43 +080012003
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +053012004 ucfg_mlme_is_imps_enabled(hdd_ctx->psoc, &is_imps_enabled);
12005 hdd_set_idle_ps_config(hdd_ctx, is_imps_enabled);
Arun Kumar Khandavallideda5a82019-03-11 15:32:19 +053012006 hdd_debugfs_mws_coex_info_init(hdd_ctx);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012007
Dustin Brown92bd8382018-10-31 15:49:46 -070012008 hdd_exit();
12009
12010 return 0;
12011
12012unregister_notifiers:
12013 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012014
Dustin Brown623e7e32018-09-05 14:27:50 -070012015unregister_reboot:
Arunk Khandavalli830c9692018-03-22 12:17:40 +053012016 unregister_reboot_notifier(&system_reboot_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012017
Dustin Brown623e7e32018-09-05 14:27:50 -070012018unregister_netdev:
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053012019 unregister_netdevice_notifier(&hdd_netdev_notifier);
12020
Dustin Brown623e7e32018-09-05 14:27:50 -070012021unregister_wiphy:
Rachit Kankane30807332018-06-27 18:39:36 +053012022 qdf_dp_trace_deinit();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080012023 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012024
Dustin Brown623e7e32018-09-05 14:27:50 -070012025stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070012026 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053012027
Dustin Brown623e7e32018-09-05 14:27:50 -070012028memdump_deinit:
Dustin Brown86d196b2018-08-02 11:51:49 -070012029 hdd_bus_bandwidth_deinit(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -080012030 hdd_driver_memdump_deinit();
Naveen Rawate02f8f52018-04-05 11:58:04 -070012031 osif_request_manager_deinit();
Dustin Brown623e7e32018-09-05 14:27:50 -070012032 qdf_nbuf_deinit_replenish_timer();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070012033
Nachiket Kukade8003d252017-03-30 15:55:58 +053012034 if (cds_is_fw_down())
12035 hdd_err("Not setting the complete event as fw is down");
12036 else
Dustin Brown623e7e32018-09-05 14:27:50 -070012037 hdd_start_complete(errno);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012038
Dustin Browne74003f2018-03-14 12:51:58 -070012039 hdd_exit();
Dustin Brown92bd8382018-10-31 15:49:46 -070012040
Dustin Brown623e7e32018-09-05 14:27:50 -070012041 return errno;
Dustin Brown92bd8382018-10-31 15:49:46 -070012042}
12043
12044QDF_STATUS hdd_psoc_create_vdevs(struct hdd_context *hdd_ctx)
12045{
12046 enum QDF_GLOBAL_MODE driver_mode = hdd_get_conparam();
12047 QDF_STATUS status;
12048
12049 status = hdd_open_adapters_for_mode(hdd_ctx, driver_mode);
12050 if (QDF_IS_STATUS_ERROR(status)) {
12051 hdd_err("Failed to create vdevs; status:%d", status);
12052 return status;
12053 }
12054
12055 if (hdd_ctx->rps)
12056 hdd_set_rps_cpu_mask(hdd_ctx);
12057
12058 if (driver_mode != QDF_GLOBAL_FTM_MODE)
12059 hdd_psoc_idle_timer_start(hdd_ctx);
12060
12061 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012062}
12063
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012064/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012065 * hdd_wlan_update_target_info() - update target type info
12066 * @hdd_ctx: HDD context
12067 * @context: hif context
12068 *
12069 * Update target info received from firmware in hdd context
12070 * Return:None
12071 */
12072
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012073void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053012074{
12075 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
12076
12077 if (!tgt_info) {
12078 hdd_err("Target info is Null");
12079 return;
12080 }
12081
12082 hdd_ctx->target_type = tgt_info->target_type;
12083}
12084
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053012085void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp, void *context)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012086{
12087 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012088 int status;
12089 struct hdd_adapter *adapter = NULL;
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070012090 struct osif_request *request = NULL;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012091
Dustin Brown491d54b2018-03-14 12:39:11 -070012092 hdd_enter();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012093
12094 if (!rsp) {
12095 hdd_err("data is null");
12096 return;
12097 }
12098
12099 status = wlan_hdd_validate_context(hdd_ctx);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053012100 if (status != 0)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012101 return;
12102
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070012103 request = osif_request_get(context);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053012104 if (!request) {
12105 hdd_err("obselete request");
12106 return;
12107 }
12108
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012109 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
Jeff Johnsond36fa332019-03-18 13:42:25 -070012110 if ((!adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012111 hdd_err("Invalid adapter or adapter has invalid magic");
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070012112 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012113 return;
12114 }
12115
Alok Kumarce2c29a2018-10-12 15:44:02 +053012116 hdd_debug("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
12117 hdd_debug("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
12118 hdd_debug("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
12119 hdd_debug("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
12120 hdd_debug("rsp->out_of_order_arp_rsp_drop_cnt :%x",
12121 rsp->out_of_order_arp_rsp_drop_cnt);
12122 hdd_debug("rsp->dad_detected :%x", rsp->dad_detected);
12123 hdd_debug("rsp->connect_status :%x", rsp->connect_status);
12124 hdd_debug("rsp->ba_session_establishment_status :%x",
12125 rsp->ba_session_establishment_status);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012126
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012127 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012128 adapter->dad |= rsp->dad_detected;
12129 adapter->con_status = rsp->connect_status;
12130
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053012131 /* Flag true indicates connectivity check stats present. */
12132 if (rsp->connect_stats_present) {
Alok Kumarce2c29a2018-10-12 15:44:02 +053012133 hdd_debug("rsp->tcp_ack_recvd :%x", rsp->tcp_ack_recvd);
12134 hdd_debug("rsp->icmpv4_rsp_recvd :%x", rsp->icmpv4_rsp_recvd);
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053012135 adapter->hdd_stats.hdd_tcp_stats.rx_fw_cnt = rsp->tcp_ack_recvd;
12136 adapter->hdd_stats.hdd_icmpv4_stats.rx_fw_cnt =
12137 rsp->icmpv4_rsp_recvd;
12138 }
12139
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070012140 osif_request_complete(request);
12141 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012142
Dustin Browne74003f2018-03-14 12:51:58 -070012143 hdd_exit();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012144}
12145
Visweswara Tanuku633976b2019-01-07 16:13:12 +053012146#ifdef WLAN_FEATURE_MOTION_DETECTION
12147/**
12148 * hdd_md_host_evt_cb - Callback for Motion Detection Event
12149 * @ctx: HDD context
12150 * @event: motion detect event
12151 *
12152 * Callback for Motion Detection Event. Re-enables Motion
12153 * Detection again upon event
12154 *
12155 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and
12156 * QDF_STATUS_E_FAILURE on failure
12157 */
12158QDF_STATUS hdd_md_host_evt_cb(void *ctx, struct sir_md_evt *event)
12159{
12160 struct hdd_adapter *adapter = NULL;
12161 struct hdd_context *hdd_ctx;
12162 QDF_STATUS status;
12163 struct sme_motion_det_en motion_det;
12164
12165 if (!ctx || !event)
12166 return QDF_STATUS_E_INVAL;
12167
12168 hdd_ctx = (struct hdd_context *)ctx;
12169 status = wlan_hdd_validate_context(hdd_ctx);
12170 if (0 != status)
12171 return QDF_STATUS_E_INVAL;
12172
12173 adapter = hdd_get_adapter_by_vdev(hdd_ctx, event->vdev_id);
12174 if (!adapter || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
12175 hdd_err("Invalid adapter or adapter has invalid magic");
12176 return QDF_STATUS_E_INVAL;
12177 }
12178
12179 hdd_debug("Motion Detection CB vdev_id=%u, status=%u",
12180 event->vdev_id, event->status);
12181
12182 if (adapter->motion_detection_mode) {
12183 motion_det.vdev_id = event->vdev_id;
12184 motion_det.enable = 1;
12185 hdd_debug("Motion Detect CB -> Enable Motion Detection again");
12186 sme_motion_det_enable(hdd_ctx->mac_handle, &motion_det);
12187 }
12188
12189 return QDF_STATUS_SUCCESS;
12190}
12191#endif /* WLAN_FEATURE_MOTION_DETECTION */
12192
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012193/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012194 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012195 * @hdd_ctx: HDD context
12196 *
12197 * Register the HDD callbacks to CDS/SME.
12198 *
12199 * Return: 0 for success or Error code for failure
12200 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012201int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012202{
12203 QDF_STATUS status;
12204 int ret = 0;
Jeff Johnson16528362018-06-14 12:34:16 -070012205 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012206
Dustin Brown491d54b2018-03-14 12:39:11 -070012207 hdd_enter();
Sourav Mohapatra674925f2018-04-16 11:16:58 +053012208 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
12209 hdd_err("in ftm mode, no need to register callbacks");
12210 return ret;
12211 }
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012212
Jeff Johnson16528362018-06-14 12:34:16 -070012213 mac_handle = hdd_ctx->mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012214
Jeff Johnson16528362018-06-14 12:34:16 -070012215 sme_register_oem_data_rsp_callback(mac_handle,
12216 hdd_send_oem_data_rsp_msg);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012217
Jeff Johnson16528362018-06-14 12:34:16 -070012218 sme_register_mgmt_frame_ind_callback(mac_handle,
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053012219 hdd_indicate_mgmt_frame);
Jeff Johnson16528362018-06-14 12:34:16 -070012220 sme_set_tsfcb(mac_handle, hdd_get_tsf_cb, hdd_ctx);
Jeff Johnson16528362018-06-14 12:34:16 -070012221 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012222 wlan_hdd_cfg80211_stats_ext_callback);
12223
Jeff Johnson16528362018-06-14 12:34:16 -070012224 sme_ext_scan_register_callback(mac_handle,
12225 wlan_hdd_cfg80211_extscan_callback);
12226 sme_stats_ext2_register_callback(mac_handle,
lifeng66831662017-05-19 16:01:35 +080012227 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012228
Jeff Johnson16528362018-06-14 12:34:16 -070012229 sme_set_rssi_threshold_breached_cb(mac_handle,
12230 hdd_rssi_threshold_breached);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012231
Jeff Johnson16528362018-06-14 12:34:16 -070012232 sme_set_link_layer_stats_ind_cb(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012233 wlan_hdd_cfg80211_link_layer_stats_callback);
12234
Jeff Johnson16528362018-06-14 12:34:16 -070012235 sme_rso_cmd_status_cb(mac_handle, wlan_hdd_rso_cmd_status_cb);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053012236
Jeff Johnson16528362018-06-14 12:34:16 -070012237 sme_set_link_layer_ext_cb(mac_handle,
Zhang Qianca38fb12016-12-23 11:10:48 +080012238 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
Abhinav Kumar338e57d2019-02-04 17:30:10 +053012239 sme_update_hidden_ssid_status_cb(mac_handle,
12240 hdd_hidden_ssid_enable_roaming);
Zhang Qianca38fb12016-12-23 11:10:48 +080012241
Jeff Johnson16528362018-06-14 12:34:16 -070012242 status = sme_set_lost_link_info_cb(mac_handle,
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053012243 hdd_lost_link_info_cb);
12244 /* print error and not block the startup process */
12245 if (!QDF_IS_STATUS_SUCCESS(status))
12246 hdd_err("set lost link info callback failed");
12247
Poddar, Siddarth34872782017-08-10 14:08:51 +053012248 ret = hdd_register_data_stall_detect_cb();
12249 if (ret) {
12250 hdd_err("Register data stall detect detect callback failed.");
12251 return ret;
12252 }
12253
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012254 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
12255
Jeff Johnson16528362018-06-14 12:34:16 -070012256 sme_register_set_connection_info_cb(mac_handle,
12257 hdd_set_connection_in_progress,
12258 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053012259
Jeff Johnson16528362018-06-14 12:34:16 -070012260 status = sme_congestion_register_callback(mac_handle,
12261 hdd_update_cca_info_cb);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053012262 if (!QDF_IS_STATUS_SUCCESS(status))
12263 hdd_err("set congestion callback failed");
12264
Jeff Johnson16528362018-06-14 12:34:16 -070012265 status = sme_set_bt_activity_info_cb(mac_handle,
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053012266 hdd_bt_activity_cb);
12267 if (!QDF_IS_STATUS_SUCCESS(status))
12268 hdd_err("set bt activity info callback failed");
12269
Jeff Johnson16528362018-06-14 12:34:16 -070012270 status = sme_register_tx_queue_cb(mac_handle,
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080012271 hdd_tx_queue_cb);
12272 if (!QDF_IS_STATUS_SUCCESS(status))
12273 hdd_err("Register tx queue callback failed");
12274
Visweswara Tanuku633976b2019-01-07 16:13:12 +053012275#ifdef WLAN_FEATURE_MOTION_DETECTION
12276 sme_set_md_host_evt_cb(mac_handle, hdd_md_host_evt_cb, (void *)hdd_ctx);
12277#endif /* WLAN_FEATURE_MOTION_DETECTION */
12278
Dustin Browne74003f2018-03-14 12:51:58 -070012279 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012280
12281 return ret;
12282}
12283
12284/**
12285 * hdd_deregister_cb() - De-Register HDD callbacks.
12286 * @hdd_ctx: HDD context
12287 *
12288 * De-Register the HDD callbacks to CDS/SME.
12289 *
12290 * Return: void
12291 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012292void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012293{
12294 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053012295 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070012296 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012297
Dustin Brown491d54b2018-03-14 12:39:11 -070012298 hdd_enter();
Sourav Mohapatra674925f2018-04-16 11:16:58 +053012299 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
12300 hdd_err("in ftm mode, no need to deregister callbacks");
12301 return;
12302 }
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012303
Jeff Johnson16528362018-06-14 12:34:16 -070012304 mac_handle = hdd_ctx->mac_handle;
12305 sme_deregister_tx_queue_cb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012306
Jeff Johnson16528362018-06-14 12:34:16 -070012307 sme_reset_link_layer_stats_ind_cb(mac_handle);
12308 sme_reset_rssi_threshold_breached_cb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012309
Jeff Johnson16528362018-06-14 12:34:16 -070012310 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012311 wlan_hdd_cfg80211_stats_ext_callback);
12312
Jeff Johnson16528362018-06-14 12:34:16 -070012313 status = sme_reset_tsfcb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012314 if (!QDF_IS_STATUS_SUCCESS(status))
12315 hdd_err("Failed to de-register tsfcb the callback:%d",
12316 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012317
Poddar, Siddarth34872782017-08-10 14:08:51 +053012318 ret = hdd_deregister_data_stall_detect_cb();
12319 if (ret)
12320 hdd_err("Failed to de-register data stall detect event callback");
12321
Jeff Johnson16528362018-06-14 12:34:16 -070012322 sme_deregister_oem_data_rsp_callback(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012323
Dustin Browne74003f2018-03-14 12:51:58 -070012324 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012325}
12326
12327/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012328 * hdd_softap_sta_deauth() - handle deauth req from HDD
Jeff Johnson50e37e92019-03-08 11:32:25 -080012329 * @adapter: Pointer to the HDD adapter
12330 * @param: Params to the operation
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012331 *
12332 * This to take counter measure to handle deauth req from HDD
12333 *
12334 * Return: None
12335 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012336QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnson50e37e92019-03-08 11:32:25 -080012337 struct csr_del_sta_params *param)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012338{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012339 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012340
Dustin Brown491d54b2018-03-14 12:39:11 -070012341 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012342
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012343 /* Ignore request to deauth bcmc station */
Jeff Johnson50e37e92019-03-08 11:32:25 -080012344 if (param->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012345 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012346
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012347 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012348 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Jeff Johnson50e37e92019-03-08 11:32:25 -080012349 param);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012350
Dustin Browne74003f2018-03-14 12:51:58 -070012351 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012352 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012353}
12354
12355/**
12356 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
Jeff Johnson50e37e92019-03-08 11:32:25 -080012357 * @adapter: Pointer to the HDD
12358 * @param: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012359 *
12360 * This to take counter measure to handle deauth req from HDD
12361 *
12362 * Return: None
12363 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012364void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnson50e37e92019-03-08 11:32:25 -080012365 struct csr_del_sta_params *param)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012366{
Dustin Brown491d54b2018-03-14 12:39:11 -070012367 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012368
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012369 /* Ignore request to disassoc bcmc station */
Jeff Johnson50e37e92019-03-08 11:32:25 -080012370 if (param->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012371 return;
12372
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012373 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Jeff Johnson50e37e92019-03-08 11:32:25 -080012374 param);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012375}
12376
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012377void wlan_hdd_disable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012378{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012379 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
12380 struct hdd_adapter *adapter = NULL;
12381 struct csr_roam_profile *roam_profile;
12382 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012383
Dustin Brown1dbefe62018-09-11 16:32:03 -070012384 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->psoc)) {
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012385 hdd_debug("No active sta session");
12386 return;
12387 }
12388
12389 hdd_for_each_adapter(hdd_ctx, adapter) {
12390 roam_profile = hdd_roam_profile(adapter);
12391 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12392
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012393 if (cur_adapter->vdev_id != adapter->vdev_id &&
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012394 adapter->device_mode == QDF_STA_MODE &&
12395 hdd_conn_is_connected(sta_ctx)) {
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012396 hdd_debug("%d Disable roaming", adapter->vdev_id);
Jeff Johnson16528362018-06-14 12:34:16 -070012397 sme_stop_roaming(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012398 adapter->vdev_id,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012399 ecsr_driver_disabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012400 }
12401 }
12402}
12403
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012404void wlan_hdd_enable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012405{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012406 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
12407 struct hdd_adapter *adapter = NULL;
12408 struct csr_roam_profile *roam_profile;
12409 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012410
Dustin Brown1dbefe62018-09-11 16:32:03 -070012411 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->psoc)) {
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012412 hdd_debug("No active sta session");
12413 return;
12414 }
12415
12416 hdd_for_each_adapter(hdd_ctx, adapter) {
12417 roam_profile = hdd_roam_profile(adapter);
12418 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12419
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012420 if (cur_adapter->vdev_id != adapter->vdev_id &&
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012421 adapter->device_mode == QDF_STA_MODE &&
12422 hdd_conn_is_connected(sta_ctx)) {
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012423 hdd_debug("%d Enable roaming", adapter->vdev_id);
Jeff Johnson16528362018-06-14 12:34:16 -070012424 sme_start_roaming(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012425 adapter->vdev_id,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012426 REASON_DRIVER_ENABLED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012427 }
12428 }
12429}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012430
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053012431/**
12432 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
12433 * @skb: sk buffer pointer
12434 *
12435 * Sends the bcast message to SVC multicast group with generic nl socket
12436 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
12437 *
12438 * Return: None
12439 */
12440static void nl_srv_bcast_svc(struct sk_buff *skb)
12441{
12442#ifdef CNSS_GENL
12443 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
12444#else
12445 nl_srv_bcast(skb);
12446#endif
12447}
12448
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012449void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012450{
12451 struct sk_buff *skb;
12452 struct nlmsghdr *nlh;
12453 tAniMsgHdr *ani_hdr;
12454 void *nl_data = NULL;
12455 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012456 struct radio_index_tlv *radio_info;
12457 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012458
12459 if (in_interrupt() || irqs_disabled() || in_atomic())
12460 flags = GFP_ATOMIC;
12461
12462 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
12463
Jeff Johnsond36fa332019-03-18 13:42:25 -070012464 if (!skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012465 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012466
12467 nlh = (struct nlmsghdr *)skb->data;
12468 nlh->nlmsg_pid = 0; /* from kernel */
12469 nlh->nlmsg_flags = 0;
12470 nlh->nlmsg_seq = 0;
12471 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
12472
12473 ani_hdr = NLMSG_DATA(nlh);
12474 ani_hdr->type = type;
12475
12476 switch (type) {
12477 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053012478 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012479 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012480 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070012481 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012482 ani_hdr->length = 0;
12483 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012484 break;
12485 case WLAN_SVC_WLAN_STATUS_IND:
12486 case WLAN_SVC_WLAN_VERSION_IND:
12487 case WLAN_SVC_DFS_CAC_START_IND:
12488 case WLAN_SVC_DFS_CAC_END_IND:
12489 case WLAN_SVC_DFS_RADAR_DETECT_IND:
12490 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
12491 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080012492 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053012493 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080012494 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012495 ani_hdr->length = len;
12496 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
12497 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
12498 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012499 break;
12500
12501 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070012502 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012503 type);
12504 kfree_skb(skb);
12505 return;
12506 }
12507
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012508 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080012509 * Add radio index at the end of the svc event in TLV format
12510 * to maintain the backward compatibility with userspace
12511 * applications.
12512 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012513
12514 tlv_len = 0;
12515
12516 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
12517 < WLAN_NL_MAX_PAYLOAD) {
12518 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
12519 sizeof(*ani_hdr) + len);
12520 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
12521 radio_info->length = (unsigned short) sizeof(radio_info->radio);
12522 radio_info->radio = radio;
12523 tlv_len = sizeof(*radio_info);
Dustin Browna2868622018-03-20 11:38:14 -070012524 hdd_debug("Added radio index tlv - radio index %d",
12525 radio_info->radio);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012526 }
12527
12528 nlh->nlmsg_len += tlv_len;
12529 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
12530
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053012531 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012532}
12533
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012534#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
12535void wlan_hdd_auto_shutdown_cb(void)
12536{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012537 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012538
12539 if (!hdd_ctx)
12540 return;
12541
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012542 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012543 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
12544 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012545}
12546
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012547void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012548{
Jeff Johnson9d295242017-08-29 14:39:48 -070012549 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012550 bool ap_connected = false, sta_connected = false;
Jeff Johnson16528362018-06-14 12:34:16 -070012551 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012552
Jeff Johnson16528362018-06-14 12:34:16 -070012553 mac_handle = hdd_ctx->mac_handle;
12554 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012555 return;
12556
Dundi Raviteja8e338282018-09-25 17:16:04 +053012557 if (hdd_ctx->config->wlan_auto_shutdown == 0)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012558 return;
12559
12560 if (enable == false) {
Jeff Johnson16528362018-06-14 12:34:16 -070012561 if (sme_set_auto_shutdown_timer(mac_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012562 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012563 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012564 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012565 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070012566 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012567 return;
12568 }
12569
12570 /* To enable shutdown timer check conncurrency */
Dustin Brown1dbefe62018-09-11 16:32:03 -070012571 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->psoc)) {
Dustin Brown920397d2017-12-13 16:27:50 -080012572 hdd_for_each_adapter(hdd_ctx, adapter) {
12573 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012574 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
Jeff Johnsone7951512019-02-27 10:02:51 -080012575 conn_info.conn_state ==
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012576 eConnectionState_Associated) {
12577 sta_connected = true;
12578 break;
12579 }
12580 }
Dustin Brown920397d2017-12-13 16:27:50 -080012581
12582 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012583 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070012584 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012585 ap_connected = true;
12586 break;
12587 }
12588 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012589 }
12590 }
12591
12592 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012593 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012594 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012595 }
Jeff Johnson68755312017-02-10 11:46:55 -080012596
Jeff Johnson16528362018-06-14 12:34:16 -070012597 if (sme_set_auto_shutdown_timer(mac_handle,
Dundi Raviteja8e338282018-09-25 17:16:04 +053012598 hdd_ctx->config->wlan_auto_shutdown)
Jeff Johnson68755312017-02-10 11:46:55 -080012599 != QDF_STATUS_SUCCESS)
12600 hdd_err("Failed to start wlan auto shutdown timer");
12601 else
Dustin Brown5e89ef82018-03-14 11:50:23 -070012602 hdd_info("Auto Shutdown timer for %d seconds enabled",
Dundi Raviteja8e338282018-09-25 17:16:04 +053012603 hdd_ctx->config->wlan_auto_shutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012604}
12605#endif
12606
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070012607struct hdd_adapter *
12608hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
12609 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012610{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012611 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070012612 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012613
12614 con_sap_adapter = NULL;
12615
Dustin Brown920397d2017-12-13 16:27:50 -080012616 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012617 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
12618 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012619 adapter != this_sap_adapter) {
12620 if (check_start_bss) {
12621 if (test_bit(SOFTAP_BSS_STARTED,
12622 &adapter->event_flags)) {
12623 con_sap_adapter = adapter;
12624 break;
12625 }
12626 } else {
12627 con_sap_adapter = adapter;
12628 break;
12629 }
12630 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012631 }
12632
12633 return con_sap_adapter;
12634}
12635
Tiger Yu8b119e92019-04-09 13:55:07 +080012636#ifdef WLAN_FEATURE_DP_BUS_BANDWIDTH
Jeff Johnson9d295242017-08-29 14:39:48 -070012637static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012638{
Dustin Brown5ec6b552017-03-31 12:11:40 -070012639 return adapter->device_mode == QDF_STA_MODE ||
12640 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012641}
12642
Jeff Johnson9d295242017-08-29 14:39:48 -070012643static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012644{
Dustin Brown5ec6b552017-03-31 12:11:40 -070012645 return adapter->device_mode == QDF_SAP_MODE ||
12646 adapter->device_mode == QDF_P2P_GO_MODE;
12647}
12648
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012649static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012650{
Dustin Brown920397d2017-12-13 16:27:50 -080012651 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070012652
Dustin Brown920397d2017-12-13 16:27:50 -080012653 hdd_for_each_adapter(hdd_ctx, adapter) {
12654 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070012655 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
Jeff Johnsone7951512019-02-27 10:02:51 -080012656 conn_info.conn_state == eConnectionState_Associated) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070012657 return true;
12658 }
12659
Dustin Brown920397d2017-12-13 16:27:50 -080012660 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070012661 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070012662 return true;
12663 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070012664 }
12665
12666 return false;
12667}
12668
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012669static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012670{
Dustin Browna20bad52019-03-05 12:03:30 -080012671 qdf_periodic_work_start(&hdd_ctx->bus_bw_work,
12672 hdd_ctx->config->bus_bw_compute_interval);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012673}
12674
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012675void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012676{
Dustin Brown491d54b2018-03-14 12:39:11 -070012677 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012678
Dustin Brown5ec6b552017-03-31 12:11:40 -070012679 __hdd_bus_bw_compute_timer_start(hdd_ctx);
12680
Dustin Browne74003f2018-03-14 12:51:58 -070012681 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012682}
12683
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012684void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012685{
Dustin Brown491d54b2018-03-14 12:39:11 -070012686 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012687
Dustin Brown5ec6b552017-03-31 12:11:40 -070012688 if (hdd_any_adapter_is_assoc(hdd_ctx))
12689 __hdd_bus_bw_compute_timer_start(hdd_ctx);
12690
Dustin Browne74003f2018-03-14 12:51:58 -070012691 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012692}
12693
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012694static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012695{
Dustin Browna20bad52019-03-05 12:03:30 -080012696 if (!qdf_periodic_work_stop_sync(&hdd_ctx->bus_bw_work))
12697 return;
12698
Dustin Brown07901ec2018-09-07 11:02:41 -070012699 ucfg_ipa_set_perf_level(hdd_ctx->pdev, 0, 0);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012700 hdd_reset_tcp_delack(hdd_ctx);
12701}
12702
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012703void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012704{
Dustin Brown491d54b2018-03-14 12:39:11 -070012705 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012706
Dustin Brown5ec6b552017-03-31 12:11:40 -070012707 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
12708
Dustin Browne74003f2018-03-14 12:51:58 -070012709 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012710}
12711
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012712void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012713{
Dustin Brown491d54b2018-03-14 12:39:11 -070012714 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012715
Dustin Brown5ec6b552017-03-31 12:11:40 -070012716 if (!hdd_any_adapter_is_assoc(hdd_ctx))
12717 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
12718
Dustin Browne74003f2018-03-14 12:51:58 -070012719 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012720}
Tiger Yu8b119e92019-04-09 13:55:07 +080012721#endif /*WLAN_FEATURE_DP_BUS_BANDWIDTH*/
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012722
12723/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012724 * wlan_hdd_stop_sap() - This function stops bss of SAP.
12725 * @ap_adapter: SAP adapter
12726 *
12727 * This function will process the stopping of sap adapter.
12728 *
12729 * Return: None
12730 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012731void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012732{
Jeff Johnson87251032017-08-29 13:31:11 -070012733 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012734 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053012735 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012736 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012737
Jeff Johnsond36fa332019-03-18 13:42:25 -070012738 if (!ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012739 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012740 return;
12741 }
12742
12743 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12744 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012745 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012746 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012747
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012748 mutex_lock(&hdd_ctx->sap_lock);
12749 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080012750 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012751 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012752 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053012753 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012754 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012755 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053012756 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080012757 qdf_stop_bss_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +053012758 SME_CMD_STOP_BSS_TIMEOUT);
Anurag Chouhance0dc992016-02-16 18:18:03 +053012759 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012760 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070012761 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012762 return;
12763 }
12764 }
12765 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -070012766 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012767 ap_adapter->device_mode,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012768 ap_adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012769 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012770 false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012771 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012772 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012773 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012774 }
12775 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012776}
12777
12778/**
12779 * wlan_hdd_start_sap() - this function starts bss of SAP.
12780 * @ap_adapter: SAP adapter
12781 *
12782 * This function will process the starting of sap adapter.
12783 *
12784 * Return: None
12785 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012786void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012787{
Jeff Johnson87251032017-08-29 13:31:11 -070012788 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012789 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053012790 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012791 struct hdd_context *hdd_ctx;
Jeff Johnson8f8ceb92019-03-24 08:16:55 -070012792 struct sap_config *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012793
Jeff Johnsond36fa332019-03-18 13:42:25 -070012794 if (!ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012795 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012796 return;
12797 }
12798
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012799 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070012800 hdd_err("SoftAp role has not been enabled");
12801 return;
12802 }
12803
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012804 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
12805 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12806 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070012807 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012808
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012809 mutex_lock(&hdd_ctx->sap_lock);
12810 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
12811 goto end;
12812
12813 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012814 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012815 goto end;
12816 }
Dustin Brown07901ec2018-09-07 11:02:41 -070012817 wlan_reg_set_channel_params(hdd_ctx->pdev,
Abhinav Kumar6f694482018-09-04 16:07:39 +053012818 hdd_ap_ctx->sap_config.channel, 0,
12819 &hdd_ap_ctx->sap_config.ch_params);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012820
Wei Song2f76f642016-11-18 16:32:53 +080012821 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012822 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070012823 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012824 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012825 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012826 goto end;
12827
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012828 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053012829 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +053012830 SME_CMD_START_BSS_TIMEOUT);
Anurag Chouhance0dc992016-02-16 18:18:03 +053012831 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012832 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012833 goto end;
12834 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070012835 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012836 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012837 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012838 if (hostapd_state->bss_state == BSS_START) {
Dustin Brown1dbefe62018-09-11 16:32:03 -070012839 policy_mgr_incr_active_session(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012840 ap_adapter->device_mode,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012841 ap_adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012842 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012843 true);
12844 }
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053012845 mutex_unlock(&hdd_ctx->sap_lock);
12846
12847 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012848end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012849 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012850 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070012851 /* SAP context and beacon cleanup will happen during driver unload
12852 * in hdd_stop_adapter
12853 */
12854 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
12855
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012856}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012857
12858/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012859 * hdd_get_fw_version() - Get FW version
12860 * @hdd_ctx: pointer to HDD context.
12861 * @major_spid: FW version - major spid.
12862 * @minor_spid: FW version - minor spid
12863 * @ssid: FW version - ssid
12864 * @crmid: FW version - crmid
12865 *
12866 * This function is called to get the firmware build version stored
12867 * as part of the HDD context
12868 *
12869 * Return: None
12870 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012871void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012872 uint32_t *major_spid, uint32_t *minor_spid,
12873 uint32_t *siid, uint32_t *crmid)
12874{
12875 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
12876 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
12877 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
12878 *crmid = hdd_ctx->target_fw_version & 0x7fff;
12879}
12880
12881#ifdef QCA_CONFIG_SMP
12882/**
12883 * wlan_hdd_get_cpu() - get cpu_index
12884 *
12885 * Return: cpu_index
12886 */
12887int wlan_hdd_get_cpu(void)
12888{
12889 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012890
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012891 put_cpu();
12892 return cpu_index;
12893}
12894#endif
12895
12896/**
12897 * hdd_get_fwpath() - get framework path
12898 *
12899 * This function is used to get the string written by
12900 * userspace to start the wlan driver
12901 *
12902 * Return: string
12903 */
12904const char *hdd_get_fwpath(void)
12905{
12906 return fwpath.string;
12907}
12908
Dustin Brown94ce20f2018-09-04 13:11:38 -070012909static inline int hdd_state_query_cb(void)
12910{
12911 return !!wlan_hdd_validate_context(cds_get_context(QDF_MODULE_ID_HDD));
12912}
12913
Dustin Brown265e82b2019-03-18 11:07:32 -070012914static int __hdd_op_protect_cb(void **out_sync, const char *func)
12915{
12916 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12917
12918 if (!hdd_ctx)
12919 return -EAGAIN;
12920
12921 return __osif_psoc_sync_op_start(hdd_ctx->parent_dev,
12922 (struct osif_psoc_sync **)out_sync,
12923 func);
12924}
12925
12926static void __hdd_op_unprotect_cb(void *sync, const char *func)
12927{
12928 __osif_psoc_sync_op_stop(sync, func);
12929}
12930
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012931/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012932 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012933 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012934 * This function initilizes CDS global context with the help of cds_init. This
12935 * has to be the first function called after probe to get a valid global
12936 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012937 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012938 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012939 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012940int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012941{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012942 QDF_STATUS status;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012943
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012944 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080012945 if (QDF_IS_STATUS_ERROR(status)) {
12946 hdd_err("Failed to allocate CDS context");
Dustin Brownc1d81af2019-03-01 13:43:43 -080012947 return -ENOMEM;
wadesongae4ffd12017-10-24 16:45:54 +080012948 }
Dustin Brownc1d81af2019-03-01 13:43:43 -080012949
Dustin Brown265e82b2019-03-18 11:07:32 -070012950 qdf_op_callbacks_register(__hdd_op_protect_cb, __hdd_op_unprotect_cb);
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053012951
12952 wlan_init_bug_report_lock();
12953
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012954#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12955 wlan_logging_sock_init_svc();
12956#endif
12957
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012958 hdd_trace_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053012959 hdd_register_debug_callback();
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012960 wlan_roam_debug_init();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012961
Dustin Brownfe50cef2018-12-10 10:42:37 -080012962 return 0;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012963}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012964
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012965/**
12966 * hdd_deinit() - Deinitialize Driver
12967 *
12968 * This function frees CDS global context with the help of cds_deinit. This
12969 * has to be the last function call in remove callback to free the global
12970 * context.
12971 */
12972void hdd_deinit(void)
12973{
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012974 wlan_roam_debug_deinit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012975
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012976#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12977 wlan_logging_sock_deinit_svc();
12978#endif
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012979
12980 wlan_destroy_bug_report_lock();
Dustin Brown265e82b2019-03-18 11:07:32 -070012981 qdf_op_callbacks_register(NULL, NULL);
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012982 cds_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 Browna2a39dc2018-09-17 15:29:59 -070013318static QDF_STATUS hdd_qdf_print_init(void)
13319{
13320 QDF_STATUS status;
13321 int qdf_print_idx;
13322
13323 status = qdf_print_setup();
13324 if (QDF_IS_STATUS_ERROR(status)) {
13325 pr_err("Failed qdf_print_setup; status:%u\n", status);
13326 return status;
13327 }
13328
13329 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
13330 if (qdf_print_idx < 0) {
13331 pr_err("Failed to register for qdf_print_ctrl\n");
13332 return QDF_STATUS_E_FAILURE;
13333 }
13334
13335 qdf_set_pidx(qdf_print_idx);
13336
13337 return QDF_STATUS_SUCCESS;
13338}
13339
13340static void hdd_qdf_print_deinit(void)
13341{
13342 int qdf_pidx = qdf_get_pidx();
13343
13344 qdf_set_pidx(-1);
13345 qdf_print_ctrl_cleanup(qdf_pidx);
13346
13347 /* currently, no qdf print 'un-setup'*/
13348}
13349
13350static QDF_STATUS hdd_qdf_init(void)
13351{
13352 QDF_STATUS status;
13353
13354 status = hdd_qdf_print_init();
13355 if (QDF_IS_STATUS_ERROR(status))
13356 goto exit;
13357
13358 status = qdf_debugfs_init();
13359 if (QDF_IS_STATUS_ERROR(status)) {
13360 hdd_err("Failed to init debugfs; status:%u", status);
13361 goto print_deinit;
13362 }
13363
13364 qdf_lock_stats_init();
13365 qdf_mem_init();
Dustin Brownc2796312019-03-13 16:43:36 -070013366 qdf_delayed_work_feature_init();
Dustin Brown4a93bb52019-03-13 11:46:34 -070013367 qdf_periodic_work_feature_init();
Dustin Browna2a39dc2018-09-17 15:29:59 -070013368 qdf_mc_timer_manager_init();
13369 qdf_event_list_init();
13370
Dustin Brownd315c452018-11-27 11:28:48 -080013371 status = qdf_talloc_feature_init();
13372 if (QDF_IS_STATUS_ERROR(status)) {
13373 hdd_err("Failed to init talloc; status:%u", status);
13374 goto event_deinit;
13375 }
13376
Dustin Browna2a39dc2018-09-17 15:29:59 -070013377 status = qdf_cpuhp_init();
13378 if (QDF_IS_STATUS_ERROR(status)) {
13379 hdd_err("Failed to init cpuhp; status:%u", status);
Dustin Brownd315c452018-11-27 11:28:48 -080013380 goto talloc_deinit;
Dustin Browna2a39dc2018-09-17 15:29:59 -070013381 }
13382
13383 status = qdf_trace_spin_lock_init();
13384 if (QDF_IS_STATUS_ERROR(status)) {
13385 hdd_err("Failed to init spinlock; status:%u", status);
13386 goto cpuhp_deinit;
13387 }
13388
13389 qdf_trace_init();
13390 qdf_register_debugcb_init();
13391
13392 return QDF_STATUS_SUCCESS;
13393
13394cpuhp_deinit:
13395 qdf_cpuhp_deinit();
Dustin Brownd315c452018-11-27 11:28:48 -080013396talloc_deinit:
13397 qdf_talloc_feature_deinit();
Dustin Browna2a39dc2018-09-17 15:29:59 -070013398event_deinit:
13399 qdf_event_list_destroy();
13400 qdf_mc_timer_manager_exit();
Dustin Brown4a93bb52019-03-13 11:46:34 -070013401 qdf_periodic_work_feature_deinit();
Dustin Brownc2796312019-03-13 16:43:36 -070013402 qdf_delayed_work_feature_deinit();
Dustin Browna2a39dc2018-09-17 15:29:59 -070013403 qdf_mem_exit();
13404 qdf_lock_stats_deinit();
13405 qdf_debugfs_exit();
13406print_deinit:
13407 hdd_qdf_print_deinit();
13408
13409exit:
13410 return status;
13411}
13412
13413static void hdd_qdf_deinit(void)
13414{
13415 /* currently, no debugcb deinit */
13416
13417 qdf_trace_deinit();
13418
13419 /* currently, no trace spinlock deinit */
13420
13421 qdf_cpuhp_deinit();
Dustin Brownd315c452018-11-27 11:28:48 -080013422 qdf_talloc_feature_deinit();
Dustin Browna2a39dc2018-09-17 15:29:59 -070013423 qdf_event_list_destroy();
13424 qdf_mc_timer_manager_exit();
Dustin Brown4a93bb52019-03-13 11:46:34 -070013425 qdf_periodic_work_feature_deinit();
Dustin Brownc2796312019-03-13 16:43:36 -070013426 qdf_delayed_work_feature_deinit();
Dustin Browna2a39dc2018-09-17 15:29:59 -070013427 qdf_mem_exit();
13428 qdf_lock_stats_deinit();
13429 qdf_debugfs_exit();
13430 hdd_qdf_print_deinit();
13431}
Dustin Brownf0f70562018-09-14 10:29:38 -070013432
Dustin Brown26afe8f2019-03-01 12:37:24 -080013433#ifdef FEATURE_MONITOR_MODE_SUPPORT
13434static bool is_monitor_mode_supported(void)
13435{
13436 return true;
13437}
13438#else
13439static bool is_monitor_mode_supported(void)
13440{
13441 pr_err("Monitor mode not supported!");
13442 return false;
13443}
13444#endif
13445
13446#ifdef WLAN_FEATURE_EPPING
13447static bool is_epping_mode_supported(void)
13448{
13449 return true;
13450}
13451#else
13452static bool is_epping_mode_supported(void)
13453{
13454 pr_err("Epping mode not supported!");
13455 return false;
13456}
13457#endif
13458
13459#ifdef QCA_WIFI_FTM
13460static bool is_ftm_mode_supported(void)
13461{
13462 return true;
13463}
13464#else
13465static bool is_ftm_mode_supported(void)
13466{
13467 pr_err("FTM mode not supported!");
13468 return false;
13469}
13470#endif
13471
13472/**
13473 * is_con_mode_valid() check con mode is valid or not
13474 * @mode: global con mode
13475 *
13476 * Return: TRUE on success FALSE on failure
13477 */
13478static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
13479{
13480 switch (mode) {
13481 case QDF_GLOBAL_MONITOR_MODE:
13482 return is_monitor_mode_supported();
13483 case QDF_GLOBAL_EPPING_MODE:
13484 return is_epping_mode_supported();
13485 case QDF_GLOBAL_FTM_MODE:
13486 return is_ftm_mode_supported();
13487 case QDF_GLOBAL_MISSION_MODE:
13488 return true;
13489 default:
13490 return false;
13491 }
13492}
13493
13494static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
13495 enum QDF_GLOBAL_MODE curr_mode)
13496{
13497 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
13498 return;
13499
13500 switch (curr_mode) {
13501 case QDF_GLOBAL_MONITOR_MODE:
13502 hdd_info("Release wakelock for monitor mode!");
13503 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
13504 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
13505 /* fallthrough */
13506 case QDF_GLOBAL_MISSION_MODE:
13507 case QDF_GLOBAL_FTM_MODE:
13508 hdd_abort_mac_scan_all_adapters(hdd_ctx);
13509 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, NULL);
13510 hdd_stop_all_adapters(hdd_ctx);
13511 hdd_deinit_all_adapters(hdd_ctx, false);
13512
13513 break;
13514 default:
13515 break;
13516 }
13517}
13518
13519static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
13520 enum QDF_GLOBAL_MODE curr_mode)
13521{
13522 int driver_status;
13523
13524 driver_status = hdd_ctx->driver_status;
13525
13526 switch (curr_mode) {
13527 case QDF_GLOBAL_MISSION_MODE:
13528 case QDF_GLOBAL_MONITOR_MODE:
13529 case QDF_GLOBAL_FTM_MODE:
13530 hdd_close_all_adapters(hdd_ctx, false);
13531 break;
13532 case QDF_GLOBAL_EPPING_MODE:
13533 epping_disable();
13534 epping_close();
13535 break;
13536 default:
13537 return;
13538 }
13539}
13540
13541static int
13542hdd_parse_driver_mode(const char *mode_str, enum QDF_GLOBAL_MODE *out_mode)
13543{
13544 QDF_STATUS status;
13545 uint32_t mode;
13546
13547 *out_mode = QDF_GLOBAL_MAX_MODE;
13548
13549 status = qdf_uint32_parse(mode_str, &mode);
13550 if (QDF_IS_STATUS_ERROR(status))
13551 return qdf_status_to_os_return(status);
13552
13553 if (mode >= QDF_GLOBAL_MAX_MODE)
13554 return -ERANGE;
13555
13556 *out_mode = (enum QDF_GLOBAL_MODE)mode;
13557
13558 return 0;
13559}
13560
13561/**
13562 * __hdd_driver_mode_change() - Handles a driver mode change
13563 * @hdd_ctx: Pointer to the global HDD context
13564 * @next_mode: the driver mode to transition to
13565 *
13566 * This function is invoked when user updates con_mode using sys entry,
13567 * to initialize and bring-up driver in that specific mode.
13568 *
13569 * Return: Errno
13570 */
13571static int __hdd_driver_mode_change(struct hdd_context *hdd_ctx,
13572 enum QDF_GLOBAL_MODE next_mode)
13573{
13574 enum QDF_GLOBAL_MODE curr_mode;
13575 int errno;
13576
13577 hdd_info("Driver mode changing to %d", next_mode);
13578
13579 errno = wlan_hdd_validate_context(hdd_ctx);
13580 if (errno)
13581 return errno;
13582
13583 if (!is_con_mode_valid(next_mode)) {
13584 hdd_err_rl("Requested driver mode is invalid");
13585 return -EINVAL;
13586 }
13587
Dustin Brown26afe8f2019-03-01 12:37:24 -080013588 curr_mode = hdd_get_conparam();
13589 if (curr_mode == next_mode) {
13590 hdd_err_rl("Driver is already in the requested mode");
Dustin Browne0a77272019-03-19 16:28:06 -070013591 return 0;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013592 }
13593
13594 /* ensure adapters are stopped */
13595 hdd_stop_present_mode(hdd_ctx, curr_mode);
13596
13597 errno = hdd_wlan_stop_modules(hdd_ctx, true);
13598 if (errno) {
13599 hdd_err("Stop wlan modules failed");
Dustin Browne0a77272019-03-19 16:28:06 -070013600 return errno;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013601 }
13602
13603 /* Cleanup present mode before switching to new mode */
13604 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
13605
13606 hdd_set_conparam(next_mode);
13607
13608 errno = hdd_wlan_start_modules(hdd_ctx, false);
13609 if (errno) {
13610 hdd_err("Start wlan modules failed: %d", errno);
Dustin Browne0a77272019-03-19 16:28:06 -070013611 return errno;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013612 }
13613
13614 errno = hdd_open_adapters_for_mode(hdd_ctx, next_mode);
13615 if (errno) {
13616 hdd_err("Failed to open adapters");
Dustin Browne0a77272019-03-19 16:28:06 -070013617 return errno;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013618 }
13619
13620 if (next_mode == QDF_GLOBAL_MONITOR_MODE) {
13621 struct hdd_adapter *adapter =
13622 hdd_get_adapter(hdd_ctx, QDF_MONITOR_MODE);
13623
13624 QDF_BUG(adapter);
13625 if (!adapter) {
13626 hdd_err("Failed to get monitor adapter");
Dustin Browne0a77272019-03-19 16:28:06 -070013627 return -EINVAL;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013628 }
13629
13630 errno = hdd_start_adapter(adapter);
13631 if (errno) {
13632 hdd_err("Failed to start monitor adapter");
Dustin Browne0a77272019-03-19 16:28:06 -070013633 return errno;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013634 }
13635
13636 hdd_info("Acquire wakelock for monitor mode");
13637 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
13638 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
13639 }
13640
13641 /* con_mode is a global module parameter */
13642 con_mode = next_mode;
13643 hdd_info("Driver mode successfully changed to %d", next_mode);
13644
Dustin Browne0a77272019-03-19 16:28:06 -070013645 return 0;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013646}
13647
13648static int hdd_driver_mode_change(enum QDF_GLOBAL_MODE mode)
13649{
Dustin Brownc1d81af2019-03-01 13:43:43 -080013650 struct osif_driver_sync *driver_sync;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013651 struct hdd_context *hdd_ctx;
13652 QDF_STATUS status;
13653 int errno;
13654
13655 hdd_enter();
13656
Dustin Brownc1d81af2019-03-01 13:43:43 -080013657 status = osif_driver_sync_trans_start_wait(&driver_sync);
Dustin Brown26afe8f2019-03-01 12:37:24 -080013658 if (QDF_IS_STATUS_ERROR(status)) {
13659 hdd_err("Failed to start 'mode change'; status:%u", status);
13660 errno = qdf_status_to_os_return(status);
13661 goto exit;
13662 }
13663
Dustin Brownc1d81af2019-03-01 13:43:43 -080013664 osif_driver_sync_wait_for_ops(driver_sync);
Dustin Brown26afe8f2019-03-01 12:37:24 -080013665
13666 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13667 errno = wlan_hdd_validate_context(hdd_ctx);
13668 if (errno)
13669 goto trans_stop;
13670
Dustin Brown26afe8f2019-03-01 12:37:24 -080013671 errno = __hdd_driver_mode_change(hdd_ctx, mode);
Dustin Brown26afe8f2019-03-01 12:37:24 -080013672
13673trans_stop:
Dustin Brownc1d81af2019-03-01 13:43:43 -080013674 osif_driver_sync_trans_stop(driver_sync);
Dustin Brown26afe8f2019-03-01 12:37:24 -080013675
13676exit:
13677 hdd_exit();
13678
13679 return errno;
13680}
13681
13682static int hdd_set_con_mode(enum QDF_GLOBAL_MODE mode)
13683{
13684 con_mode = mode;
13685
13686 return 0;
13687}
13688
13689static int (*hdd_set_con_mode_cb)(enum QDF_GLOBAL_MODE mode) = hdd_set_con_mode;
13690
13691static void hdd_driver_mode_change_register(void)
13692{
13693 hdd_set_con_mode_cb = hdd_driver_mode_change;
13694}
13695
13696static void hdd_driver_mode_change_unregister(void)
13697{
13698 hdd_set_con_mode_cb = hdd_set_con_mode;
13699}
13700
13701static int con_mode_handler(const char *kmessage, const struct kernel_param *kp)
13702{
13703 enum QDF_GLOBAL_MODE mode;
13704 int errno;
13705
13706 errno = hdd_parse_driver_mode(kmessage, &mode);
13707 if (errno) {
13708 hdd_err_rl("Failed to parse driver mode '%s'", kmessage);
13709 return errno;
13710 }
13711
13712 return hdd_set_con_mode_cb(mode);
13713}
Dustin Brown95ff00b2019-02-28 13:41:13 -080013714
Dustin Brownf0f70562018-09-14 10:29:38 -070013715/**
13716 * hdd_driver_load() - Perform the driver-level load operation
13717 *
13718 * Note: this is used in both static and DLKM driver builds
13719 *
13720 * Return: Errno
13721 */
13722static int hdd_driver_load(void)
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013723{
Dustin Brownc1d81af2019-03-01 13:43:43 -080013724 struct osif_driver_sync *driver_sync;
Dustin Brownd585cb32018-09-12 17:12:23 -070013725 QDF_STATUS status;
Dustin Brownf0f70562018-09-14 10:29:38 -070013726 int errno;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013727
Dustin Brownc1d81af2019-03-01 13:43:43 -080013728 pr_err("%s: Loading driver v%s\n", WLAN_MODULE_NAME,
Rajeev Kumare555e2d2018-09-17 11:52:37 -070013729 g_wlan_driver_version);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013730
Dustin Browna2a39dc2018-09-17 15:29:59 -070013731 status = hdd_qdf_init();
13732 if (QDF_IS_STATUS_ERROR(status)) {
13733 errno = qdf_status_to_os_return(status);
13734 goto exit;
13735 }
13736
Dustin Brownc1d81af2019-03-01 13:43:43 -080013737 osif_sync_init();
Dustin Brown21a1d462018-07-31 15:13:06 -070013738
Dustin Brownc1d81af2019-03-01 13:43:43 -080013739 status = osif_driver_sync_create_and_trans(&driver_sync);
Dustin Brown21a1d462018-07-31 15:13:06 -070013740 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Brownc1d81af2019-03-01 13:43:43 -080013741 hdd_err("Failed to init driver sync; status:%u", status);
Dustin Brown21a1d462018-07-31 15:13:06 -070013742 errno = qdf_status_to_os_return(status);
Dustin Brownc1d81af2019-03-01 13:43:43 -080013743 goto sync_deinit;
Dustin Brown21a1d462018-07-31 15:13:06 -070013744 }
13745
Dustin Brownf0f70562018-09-14 10:29:38 -070013746 errno = hdd_init();
13747 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013748 hdd_err("Failed to init HDD; errno:%d", errno);
Dustin Brown21a1d462018-07-31 15:13:06 -070013749 goto trans_stop;
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013750 }
13751
Dustin Brownd585cb32018-09-12 17:12:23 -070013752 status = hdd_component_init();
13753 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013754 hdd_err("Failed to init components; status:%u", status);
Dustin Brownf0f70562018-09-14 10:29:38 -070013755 errno = qdf_status_to_os_return(status);
Dustin Brownd585cb32018-09-12 17:12:23 -070013756 goto hdd_deinit;
13757 }
Mukul Sharmad75a6672017-06-22 15:40:53 +053013758
Dustin Brownf0f70562018-09-14 10:29:38 -070013759 status = qdf_wake_lock_create(&wlan_wake_lock, "wlan");
13760 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013761 hdd_err("Failed to create wake lock; status:%u", status);
Dustin Brownf0f70562018-09-14 10:29:38 -070013762 errno = qdf_status_to_os_return(status);
13763 goto comp_deinit;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013764 }
13765
Dustin Brownf0f70562018-09-14 10:29:38 -070013766 hdd_set_conparam(con_mode);
13767
Dustin Brownf0f70562018-09-14 10:29:38 -070013768 errno = wlan_hdd_state_ctrl_param_create();
13769 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013770 hdd_err("Failed to create ctrl param; errno:%d", errno);
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013771 goto wakelock_destroy;
13772 }
13773
Dustin Brown25843ad2018-09-17 14:54:33 -070013774 errno = pld_init();
13775 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013776 hdd_err("Failed to init PLD; errno:%d", errno);
Dustin Brown25843ad2018-09-17 14:54:33 -070013777 goto param_destroy;
13778 }
13779
Dustin Brown95ff00b2019-02-28 13:41:13 -080013780 hdd_driver_mode_change_register();
Dustin Brownc1d81af2019-03-01 13:43:43 -080013781
13782 osif_driver_sync_register(driver_sync);
13783 osif_driver_sync_trans_stop(driver_sync);
Dustin Brown21a1d462018-07-31 15:13:06 -070013784
13785 /* psoc probe can happen in registration; do after 'load' transition */
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013786 errno = wlan_hdd_register_driver();
13787 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013788 hdd_err("Failed to register driver; errno:%d", errno);
Dustin Brown25843ad2018-09-17 14:54:33 -070013789 goto pld_deinit;
Sachin Ahuja16904db2017-12-13 19:56:57 +053013790 }
13791
Dustin Browna2a39dc2018-09-17 15:29:59 -070013792 hdd_debug("%s: driver loaded", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013793
13794 return 0;
Dustin Brownd585cb32018-09-12 17:12:23 -070013795
Dustin Brown25843ad2018-09-17 14:54:33 -070013796pld_deinit:
Dustin Brownc1d81af2019-03-01 13:43:43 -080013797 status = osif_driver_sync_trans_start(&driver_sync);
Dustin Brown21a1d462018-07-31 15:13:06 -070013798 QDF_BUG(QDF_IS_STATUS_SUCCESS(status));
13799
Dustin Brownc1d81af2019-03-01 13:43:43 -080013800 osif_driver_sync_unregister();
13801 osif_driver_sync_wait_for_ops(driver_sync);
13802
Dustin Brown95ff00b2019-02-28 13:41:13 -080013803 hdd_driver_mode_change_unregister();
Dustin Brown25843ad2018-09-17 14:54:33 -070013804 pld_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013805
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013806param_destroy:
13807 wlan_hdd_state_ctrl_param_destroy();
Dustin Brownf0f70562018-09-14 10:29:38 -070013808wakelock_destroy:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053013809 qdf_wake_lock_destroy(&wlan_wake_lock);
Dustin Brownf0f70562018-09-14 10:29:38 -070013810comp_deinit:
Dustin Brownd585cb32018-09-12 17:12:23 -070013811 hdd_component_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013812hdd_deinit:
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013813 hdd_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013814trans_stop:
Dustin Brownc1d81af2019-03-01 13:43:43 -080013815 osif_driver_sync_trans_stop(driver_sync);
13816 osif_driver_sync_destroy(driver_sync);
13817sync_deinit:
13818 osif_sync_deinit();
Dustin Browna2a39dc2018-09-17 15:29:59 -070013819 hdd_qdf_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013820
Dustin Brown25843ad2018-09-17 14:54:33 -070013821exit:
Dustin Brownf0f70562018-09-14 10:29:38 -070013822 return errno;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013823}
13824
13825/**
Dustin Brownf0f70562018-09-14 10:29:38 -070013826 * hdd_driver_unload() - Performs the driver-level unload operation
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013827 *
Dustin Brownf0f70562018-09-14 10:29:38 -070013828 * Note: this is used in both static and DLKM driver builds
13829 *
13830 * Return: None
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013831 */
Dustin Brownf0f70562018-09-14 10:29:38 -070013832static void hdd_driver_unload(void)
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013833{
Dustin Brownc1d81af2019-03-01 13:43:43 -080013834 struct osif_driver_sync *driver_sync;
Will Huang36049722018-04-13 11:48:51 +080013835 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Dustin Brown21a1d462018-07-31 15:13:06 -070013836 QDF_STATUS status;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053013837
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013838 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
13839 QWLAN_VERSIONSTR);
13840
Dustin Brown8c0b5e32019-01-18 13:56:02 -080013841 if (g_is_system_reboot_triggered) {
13842 hdd_info("System rebooting; Skipping unload");
13843 return;
13844 }
13845
13846 if (hdd_ctx)
13847 hdd_psoc_idle_timer_stop(hdd_ctx);
13848
13849 /* trigger SoC remove */
13850 wlan_hdd_unregister_driver();
13851
Dustin Brownc1d81af2019-03-01 13:43:43 -080013852 status = osif_driver_sync_trans_start_wait(&driver_sync);
Dustin Brown21a1d462018-07-31 15:13:06 -070013853 QDF_BUG(QDF_IS_STATUS_SUCCESS(status));
13854 if (QDF_IS_STATUS_ERROR(status)) {
13855 hdd_err("Unable to unload wlan; status:%u", status);
Arunk Khandavalli830c9692018-03-22 12:17:40 +053013856 return;
Dustin Brown21a1d462018-07-31 15:13:06 -070013857 }
13858
Dustin Brownc1d81af2019-03-01 13:43:43 -080013859 osif_driver_sync_unregister();
13860 osif_driver_sync_wait_for_ops(driver_sync);
Dustin Brown21a1d462018-07-31 15:13:06 -070013861
Will Huangba035ec2018-07-05 11:13:30 +080013862 cds_set_driver_loaded(false);
13863 cds_set_unload_in_progress(true);
13864
Dustin Brown95ff00b2019-02-28 13:41:13 -080013865 hdd_driver_mode_change_unregister();
Dustin Brown25843ad2018-09-17 14:54:33 -070013866 pld_deinit();
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013867 wlan_hdd_state_ctrl_param_destroy();
Dustin Brownf0f70562018-09-14 10:29:38 -070013868 hdd_set_conparam(0);
Anurag Chouhana37b5b72016-02-21 14:53:42 +053013869 qdf_wake_lock_destroy(&wlan_wake_lock);
Dustin Brownd585cb32018-09-12 17:12:23 -070013870 hdd_component_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013871 hdd_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013872
Dustin Brownc1d81af2019-03-01 13:43:43 -080013873 osif_driver_sync_trans_stop(driver_sync);
13874 osif_driver_sync_destroy(driver_sync);
Dustin Brown623e7e32018-09-05 14:27:50 -070013875
Dustin Brownc1d81af2019-03-01 13:43:43 -080013876 osif_sync_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013877
Dustin Browna2a39dc2018-09-17 15:29:59 -070013878 hdd_qdf_deinit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013879}
13880
Arun Khandavallifae92942016-08-01 13:31:08 +053013881#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013882/**
Arun Khandavallifae92942016-08-01 13:31:08 +053013883 * wlan_boot_cb() - Wlan boot callback
13884 * @kobj: object whose directory we're creating the link in.
13885 * @attr: attribute the user is interacting with
13886 * @buff: the buffer containing the user data
13887 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013888 *
Arun Khandavallifae92942016-08-01 13:31:08 +053013889 * This callback is invoked when the fs is ready to start the
13890 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013891 *
Arun Khandavallifae92942016-08-01 13:31:08 +053013892 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013893 */
Arun Khandavallifae92942016-08-01 13:31:08 +053013894static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013895 struct kobj_attribute *attr,
13896 const char *buf,
13897 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013898{
Arun Khandavallifae92942016-08-01 13:31:08 +053013899
Arun Khandavallifae92942016-08-01 13:31:08 +053013900 if (wlan_loader->loaded_state) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013901 hdd_err("wlan driver already initialized");
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013902 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053013903 }
13904
Dustin Brownf0f70562018-09-14 10:29:38 -070013905 if (hdd_driver_load())
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013906 return -EIO;
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013907
13908 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053013909
13910 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013911}
Arun Khandavallifae92942016-08-01 13:31:08 +053013912
13913/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013914 * hdd_sysfs_cleanup() - cleanup sysfs
13915 *
13916 * Return: None
13917 *
13918 */
13919static void hdd_sysfs_cleanup(void)
13920{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013921 /* remove from group */
13922 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
13923 sysfs_remove_group(wlan_loader->boot_wlan_obj,
13924 wlan_loader->attr_group);
13925
13926 /* unlink the object from parent */
13927 kobject_del(wlan_loader->boot_wlan_obj);
13928
13929 /* free the object */
13930 kobject_put(wlan_loader->boot_wlan_obj);
13931
13932 kfree(wlan_loader->attr_group);
13933 kfree(wlan_loader);
13934
13935 wlan_loader = NULL;
13936}
13937
13938/**
Arun Khandavallifae92942016-08-01 13:31:08 +053013939 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
13940 * ready
13941 *
13942 * This is creates the syfs entry boot_wlan. Which shall be invoked
13943 * when the filesystem is ready.
13944 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013945 * QDF API cannot be used here since this function is called even before
13946 * initializing WLAN driver.
13947 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070013948 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053013949 */
13950static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013951{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013952 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053013953
13954 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013955 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013956 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053013957
13958 wlan_loader->boot_wlan_obj = NULL;
13959 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
13960 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013961 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053013962 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053013963
13964 wlan_loader->loaded_state = 0;
13965 wlan_loader->attr_group->attrs = attrs;
13966
Qun Zhang4a83a462018-09-11 16:28:51 +080013967 wlan_loader->boot_wlan_obj = kobject_create_and_add(WLAN_LOADER_NAME,
Arun Khandavallifae92942016-08-01 13:31:08 +053013968 kernel_kobj);
13969 if (!wlan_loader->boot_wlan_obj) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013970 hdd_err("sysfs create and add failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053013971 goto error_return;
13972 }
13973
13974 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
13975 wlan_loader->attr_group);
13976 if (ret) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013977 hdd_err("sysfs create group failed; errno:%d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053013978 goto error_return;
13979 }
13980
13981 return 0;
13982
13983error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013984 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053013985
13986 return ret;
13987}
13988
13989/**
13990 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
13991 *
13992 * Return: 0 on success or errno on failure
13993 */
13994static int wlan_deinit_sysfs(void)
13995{
Arun Khandavallifae92942016-08-01 13:31:08 +053013996 if (!wlan_loader) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013997 hdd_err("wlan_loader is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053013998 return -EINVAL;
13999 }
14000
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070014001 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014002 return 0;
14003}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014004
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070014005#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053014006
14007#ifdef MODULE
14008/**
Dustin Brownf0f70562018-09-14 10:29:38 -070014009 * hdd_module_init() - Module init helper
Arun Khandavallifae92942016-08-01 13:31:08 +053014010 *
14011 * Module init helper function used by both module and static driver.
14012 *
14013 * Return: 0 for success, errno on failure
14014 */
14015static int hdd_module_init(void)
14016{
Dustin Brownf0f70562018-09-14 10:29:38 -070014017 if (hdd_driver_load())
Dustin Brownab482ac2017-06-09 17:00:44 -070014018 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053014019
Dustin Brownab482ac2017-06-09 17:00:44 -070014020 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053014021}
14022#else
14023static int __init hdd_module_init(void)
14024{
14025 int ret = -EINVAL;
14026
14027 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070014028 if (ret)
Dustin Browna2a39dc2018-09-17 15:29:59 -070014029 hdd_err("Failed to create sysfs entry");
Arun Khandavallifae92942016-08-01 13:31:08 +053014030
14031 return ret;
14032}
14033#endif
14034
14035
14036#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014037/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014038 * hdd_module_exit() - Exit function
14039 *
14040 * This is the driver exit point (invoked when module is unloaded using rmmod)
14041 *
14042 * Return: None
14043 */
14044static void __exit hdd_module_exit(void)
14045{
Dustin Brownf0f70562018-09-14 10:29:38 -070014046 hdd_driver_unload();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014047}
Arun Khandavallifae92942016-08-01 13:31:08 +053014048#else
14049static void __exit hdd_module_exit(void)
14050{
Dustin Brownf0f70562018-09-14 10:29:38 -070014051 hdd_driver_unload();
Arun Khandavallifae92942016-08-01 13:31:08 +053014052 wlan_deinit_sysfs();
14053}
14054#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014055
Srinivas Girigowda841da292018-02-21 16:33:00 -080014056static int fwpath_changed_handler(const char *kmessage,
14057 const struct kernel_param *kp)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014058{
14059 return param_set_copystring(kmessage, kp);
14060}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080014061
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053014062static int con_mode_handler_ftm(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080014063 const struct kernel_param *kp)
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053014064{
14065 int ret;
14066
14067 ret = param_set_int(kmessage, kp);
14068
14069 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
14070 pr_err("Only FTM mode supported!");
14071 return -ENOTSUPP;
14072 }
14073
14074 hdd_set_conparam(con_mode_ftm);
14075 con_mode = con_mode_ftm;
14076
14077 return ret;
14078}
14079
Nirav Shah6aeecf92019-02-13 14:05:03 +053014080#ifdef WLAN_FEATURE_EPPING
14081static int con_mode_handler_epping(const char *kmessage,
14082 const struct kernel_param *kp)
14083{
14084 int ret;
14085
14086 ret = param_set_int(kmessage, kp);
14087
14088 if (con_mode_epping != QDF_GLOBAL_EPPING_MODE) {
14089 pr_err("Only EPPING mode supported!");
14090 return -ENOTSUPP;
14091 }
14092
14093 hdd_set_conparam(con_mode_epping);
14094 con_mode = con_mode_epping;
14095
14096 return ret;
14097}
14098#endif
14099
Nirav Shah73713f72018-05-17 14:50:41 +053014100#ifdef FEATURE_MONITOR_MODE_SUPPORT
Ravi Joshia307f632017-07-17 23:41:41 -070014101static int con_mode_handler_monitor(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080014102 const struct kernel_param *kp)
Ravi Joshia307f632017-07-17 23:41:41 -070014103{
14104 int ret;
14105
14106 ret = param_set_int(kmessage, kp);
14107
14108 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
14109 pr_err("Only Monitor mode supported!");
14110 return -ENOTSUPP;
14111 }
14112
14113 hdd_set_conparam(con_mode_monitor);
14114 con_mode = con_mode_monitor;
14115
14116 return ret;
14117}
Nirav Shah73713f72018-05-17 14:50:41 +053014118#endif
Ravi Joshia307f632017-07-17 23:41:41 -070014119
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014120/**
14121 * hdd_get_conparam() - driver exit point
14122 *
14123 * This is the driver exit point (invoked when module is unloaded using rmmod)
14124 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080014125 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014126 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080014127enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014128{
Jeff Johnson876c1a62017-12-12 10:43:07 -080014129 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014130}
14131
Dustin Brownf0f70562018-09-14 10:29:38 -070014132void hdd_set_conparam(int32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014133{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080014134 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014135}
14136
Komal Seelamc11bb222016-01-27 18:57:10 +053014137/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014138 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
14139 * @hdd_ctx: HDD context
14140 *
14141 * Cleans up the pre cac interface, if it exists
14142 *
14143 * Return: None
14144 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014145void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014146{
Jeff Johnson55d2ab42019-03-06 11:43:49 -080014147 uint8_t vdev_id;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014148 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070014149 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014150
Jeff Johnson55d2ab42019-03-06 11:43:49 -080014151 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->mac_handle, &vdev_id);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014152 if (QDF_IS_STATUS_ERROR(status)) {
14153 hdd_err("failed to get pre cac vdev id");
14154 return;
14155 }
14156
Jeff Johnson55d2ab42019-03-06 11:43:49 -080014157 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014158 if (!precac_adapter) {
Jeff Johnsondd2f1fc2018-05-06 11:22:52 -070014159 hdd_err("invalid pre cac adapter");
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014160 return;
14161 }
14162
14163 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
14164 wlan_hdd_sap_pre_cac_failure,
14165 (void *)precac_adapter);
14166 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
14167
14168}
14169
14170/**
Komal Seelamec702b02016-02-24 18:42:16 +053014171 * hdd_update_ol_config - API to update ol configuration parameters
14172 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053014173 *
Komal Seelamc11bb222016-01-27 18:57:10 +053014174 * Return: void
14175 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014176static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053014177{
Abhishek Singh98278ce2018-12-27 11:41:03 +053014178 struct ol_config_info cfg = {0};
Anurag Chouhandf2b2682016-02-29 14:15:27 +053014179 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014180 bool self_recovery = false;
14181 QDF_STATUS status;
Komal Seelamc11bb222016-01-27 18:57:10 +053014182
Komal Seelamec702b02016-02-24 18:42:16 +053014183 if (!ol_ctx)
14184 return;
14185
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014186 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
14187 if (QDF_IS_STATUS_ERROR(status))
14188 hdd_err("Failed to get self recovery ini config");
14189
14190 cfg.enable_self_recovery = self_recovery;
Komal Seelamec702b02016-02-24 18:42:16 +053014191 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
14192 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
14193 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070014194 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053014195
14196 ol_init_ini_config(ol_ctx, &cfg);
14197}
14198
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014199#ifdef FEATURE_RUNTIME_PM
14200/**
14201 * hdd_populate_runtime_cfg() - populate runtime configuration
14202 * @hdd_ctx: hdd context
14203 * @cfg: pointer to the configuration memory being populated
14204 *
14205 * Return: void
14206 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014207static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014208 struct hif_config_info *cfg)
14209{
14210 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
Wu Gao66454f12018-09-26 19:55:41 +080014211 cfg->runtime_pm_delay =
14212 ucfg_pmo_get_runtime_pm_delay(hdd_ctx->psoc);
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014213}
14214#else
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}
14219#endif
14220
Komal Seelamec702b02016-02-24 18:42:16 +053014221/**
14222 * hdd_update_hif_config - API to update HIF configuration parameters
14223 * @hdd_ctx: HDD Context
14224 *
14225 * Return: void
14226 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014227static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053014228{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053014229 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Abhishek Singh98278ce2018-12-27 11:41:03 +053014230 struct hif_config_info cfg = {0};
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014231 bool prevent_link_down = false;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014232 bool self_recovery = false;
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014233 QDF_STATUS status;
Komal Seelamec702b02016-02-24 18:42:16 +053014234
14235 if (!scn)
14236 return;
14237
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014238 status = ucfg_mlme_get_prevent_link_down(hdd_ctx->psoc,
14239 &prevent_link_down);
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014240 if (QDF_IS_STATUS_ERROR(status))
14241 hdd_err("Failed to get prevent_link_down config");
14242
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014243 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
14244 if (QDF_IS_STATUS_ERROR(status))
14245 hdd_err("Failed to get self recovery ini config");
14246
14247 cfg.enable_self_recovery = self_recovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014248 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053014249 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070014250
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014251 if (prevent_link_down)
Dustin Brownee3e0592017-09-07 13:50:11 -070014252 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053014253}
14254
14255/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014256 * hdd_update_dp_config() - Propagate config parameters to Lithium
14257 * datapath
14258 * @hdd_ctx: HDD Context
14259 *
14260 * Return: 0 for success/errno for failure
14261 */
14262static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
14263{
Abhishek Singh98278ce2018-12-27 11:41:03 +053014264 struct cdp_config_params params = {0};
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014265 QDF_STATUS status;
jitiphil377bcc12018-10-05 19:46:08 +053014266 void *soc;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014267
jitiphil377bcc12018-10-05 19:46:08 +053014268 soc = cds_get_context(QDF_MODULE_ID_SOC);
14269 params.tso_enable = cfg_get(hdd_ctx->psoc, CFG_DP_TSO);
14270 params.lro_enable = cfg_get(hdd_ctx->psoc, CFG_DP_LRO);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014271#ifdef QCA_LL_TX_FLOW_CONTROL_V2
14272 params.tx_flow_stop_queue_threshold =
jitiphil47c3d9a2018-11-08 18:30:55 +053014273 cfg_get(hdd_ctx->psoc, CFG_DP_TX_FLOW_STOP_QUEUE_TH);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014274 params.tx_flow_start_queue_offset =
jitiphil47c3d9a2018-11-08 18:30:55 +053014275 cfg_get(hdd_ctx->psoc,
14276 CFG_DP_TX_FLOW_START_QUEUE_OFFSET);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014277#endif
jitiphil377bcc12018-10-05 19:46:08 +053014278 params.flow_steering_enable =
14279 cfg_get(hdd_ctx->psoc, CFG_DP_FLOW_STEERING_ENABLED);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014280 params.napi_enable = hdd_ctx->napi_enable;
14281 params.tcp_udp_checksumoffload =
jitiphil377bcc12018-10-05 19:46:08 +053014282 cfg_get(hdd_ctx->psoc,
14283 CFG_DP_TCP_UDP_CKSUM_OFFLOAD);
Sravan Kumar Kairam0af1ee52018-12-12 20:37:51 +053014284 params.ipa_enable = ucfg_ipa_is_enabled();
Mohit Khanna81418772018-10-30 14:14:46 -070014285 params.gro_enable = cfg_get(hdd_ctx->psoc, CFG_DP_GRO);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014286
jitiphil377bcc12018-10-05 19:46:08 +053014287 status = cdp_update_config_parameters(soc, &params);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014288 if (status) {
Dustin Browna2868622018-03-20 11:38:14 -070014289 hdd_err("Failed to attach config parameters");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014290 return status;
14291 }
14292
14293 return 0;
14294}
14295
14296/**
Komal Seelamec702b02016-02-24 18:42:16 +053014297 * hdd_update_config() - Initialize driver per module ini parameters
14298 * @hdd_ctx: HDD Context
14299 *
14300 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053014301 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053014302 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014303int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053014304{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053014305 int ret;
14306
Wu Gao66454f12018-09-26 19:55:41 +080014307 if (ucfg_pmo_is_ns_offloaded(hdd_ctx->psoc))
14308 hdd_ctx->ns_offload_enable = true;
14309
Komal Seelamec702b02016-02-24 18:42:16 +053014310 hdd_update_ol_config(hdd_ctx);
14311 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053014312 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
14313 ret = hdd_update_cds_config_ftm(hdd_ctx);
14314 else
14315 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080014316 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053014317
14318 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053014319}
14320
Mukul Sharma9d797a02017-01-05 20:26:03 +053014321/**
14322 * hdd_update_pmo_config - API to update pmo configuration parameters
14323 * @hdd_ctx: HDD context
14324 *
14325 * Return: void
14326 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014327static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053014328{
Abhishek Singh98278ce2018-12-27 11:41:03 +053014329 struct pmo_psoc_cfg psoc_cfg = {0};
Mukul Sharma9d797a02017-01-05 20:26:03 +053014330 QDF_STATUS status;
Wu Gao66454f12018-09-26 19:55:41 +080014331 enum pmo_wow_enable_type wow_enable;
14332
14333 ucfg_pmo_get_psoc_config(hdd_ctx->psoc, &psoc_cfg);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014334
14335 /*
14336 * Value of hdd_ctx->wowEnable can be,
14337 * 0 - Disable both magic pattern match and pattern byte match.
14338 * 1 - Enable magic pattern match on all interfaces.
14339 * 2 - Enable pattern byte match on all interfaces.
14340 * 3 - Enable both magic patter and pattern byte match on
14341 * all interfaces.
14342 */
Wu Gao66454f12018-09-26 19:55:41 +080014343 wow_enable = ucfg_pmo_get_wow_enable(hdd_ctx->psoc);
14344 psoc_cfg.magic_ptrn_enable = (wow_enable & 0x01) ? true : false;
Mukul Sharma9d797a02017-01-05 20:26:03 +053014345 psoc_cfg.ptrn_match_enable_all_vdev =
Wu Gao66454f12018-09-26 19:55:41 +080014346 (wow_enable & 0x02) ? true : false;
Mukul Sharma9d797a02017-01-05 20:26:03 +053014347 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080014348 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Bala Venkatesh46e29032018-11-14 18:24:55 +053014349 ucfg_mlme_get_sap_max_modulated_dtim(hdd_ctx->psoc,
14350 &psoc_cfg.sta_max_li_mod_dtim);
14351
Mukul Sharma9d797a02017-01-05 20:26:03 +053014352
Mukul Sharma9223f232017-03-08 18:42:27 +053014353 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014354
Dustin Brown1dbefe62018-09-11 16:32:03 -070014355 status = ucfg_pmo_update_psoc_config(hdd_ctx->psoc, &psoc_cfg);
Dustin Brownb9987af2018-03-01 17:15:11 -080014356 if (QDF_IS_STATUS_ERROR(status))
14357 hdd_err("failed pmo psoc configuration; status:%d", status);
14358
14359 return qdf_status_to_os_return(status);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014360}
14361
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014362void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014363 struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014364{
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014365 struct wlan_fwol_ie_whitelist whitelist = {0};
14366 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014367 QDF_STATUS status;
14368 bool is_ie_whitelist_enable = false;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014369 uint8_t i = 0;
14370
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014371 status = ucfg_fwol_get_ie_whitelist(psoc, &is_ie_whitelist_enable);
14372 if (QDF_IS_STATUS_ERROR(status)) {
14373 hdd_err("Unable to get IE whitelist param");
14374 return;
14375 }
14376
14377 ie_whitelist->white_list = is_ie_whitelist_enable;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014378 if (!ie_whitelist->white_list)
14379 return;
14380
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014381 status = ucfg_fwol_get_all_whitelist_params(psoc, &whitelist);
14382 if (QDF_IS_STATUS_ERROR(status)) {
14383 hdd_err("Unable to get all whitelist params");
14384 return;
14385 }
14386
14387 ie_whitelist->ie_bitmap[0] = whitelist.ie_bitmap_0;
14388 ie_whitelist->ie_bitmap[1] = whitelist.ie_bitmap_1;
14389 ie_whitelist->ie_bitmap[2] = whitelist.ie_bitmap_2;
14390 ie_whitelist->ie_bitmap[3] = whitelist.ie_bitmap_3;
14391 ie_whitelist->ie_bitmap[4] = whitelist.ie_bitmap_4;
14392 ie_whitelist->ie_bitmap[5] = whitelist.ie_bitmap_5;
14393 ie_whitelist->ie_bitmap[6] = whitelist.ie_bitmap_6;
14394 ie_whitelist->ie_bitmap[7] = whitelist.ie_bitmap_7;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014395
Dundi Raviteja9ab4e7b2018-09-28 14:18:28 +053014396 ie_whitelist->num_vendor_oui = whitelist.no_of_probe_req_ouis;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014397 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
Dundi Raviteja9ab4e7b2018-09-28 14:18:28 +053014398 ie_whitelist->voui[i] = whitelist.probe_req_voui[i];
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014399}
14400
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014401uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
14402{
14403 uint8_t i, score;
14404
14405 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
14406 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
14407 if (score > MAX_INDEX_SCORE)
14408 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
14409 MAX_INDEX_SCORE, i);
14410 }
14411
14412 return per_index_score;
14413}
14414
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014415QDF_STATUS hdd_update_score_config(
14416 struct scoring_config *score_config, struct hdd_context *hdd_ctx)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014417{
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014418 struct hdd_config *cfg = hdd_ctx->config;
gaurank kathpaliaae52c982018-10-04 01:35:18 +053014419 QDF_STATUS status;
gaurank kathpalia651abcd2018-11-12 22:41:23 +053014420 struct wlan_mlme_nss_chains vdev_ini_cfg;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014421 bool bval = false;
Wu Gaoed616a12019-01-16 15:19:21 +080014422 uint32_t channel_bonding_mode;
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014423
Abhishek Singh98278ce2018-12-27 11:41:03 +053014424 qdf_mem_zero(&vdev_ini_cfg, sizeof(struct wlan_mlme_nss_chains));
gaurank kathpalia651abcd2018-11-12 22:41:23 +053014425 /* Populate the nss chain params from ini for this vdev type */
14426 sme_populate_nss_chain_params(hdd_ctx->mac_handle, &vdev_ini_cfg,
14427 QDF_STA_MODE,
14428 hdd_ctx->num_rf_chains);
14429
14430 score_config->vdev_nss_24g = vdev_ini_cfg.rx_nss[NSS_CHAINS_BAND_2GHZ];
14431 score_config->vdev_nss_24g = vdev_ini_cfg.rx_nss[NSS_CHAINS_BAND_5GHZ];
14432
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014433 sme_update_score_config(hdd_ctx->mac_handle, score_config);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014434
Wu Gaoed616a12019-01-16 15:19:21 +080014435 ucfg_mlme_get_channel_bonding_24ghz(hdd_ctx->psoc,
14436 &channel_bonding_mode);
14437 score_config->cb_mode_24G = channel_bonding_mode;
14438 ucfg_mlme_get_channel_bonding_5ghz(hdd_ctx->psoc,
14439 &channel_bonding_mode);
14440 score_config->cb_mode_5G = channel_bonding_mode;
gaurank kathpaliaae52c982018-10-04 01:35:18 +053014441
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014442 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
14443 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
14444 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
14445 score_config->he_cap = 1;
14446
14447 if (score_config->he_cap ||
14448 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
14449 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
14450 score_config->vht_cap = 1;
14451
14452 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
14453 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
14454 score_config->ht_cap = 1;
14455
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014456 status = ucfg_mlme_get_vht_for_24ghz(hdd_ctx->psoc, &bval);
14457 if (!QDF_IS_STATUS_SUCCESS(status))
14458 hdd_err("Failed to get vht_for_24ghz");
14459 if (score_config->vht_cap && bval)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014460 score_config->vht_24G_cap = 1;
14461
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014462 status = ucfg_mlme_get_vht_enable_tx_bf(hdd_ctx->psoc,
14463 &bval);
14464 if (!QDF_IS_STATUS_SUCCESS(status))
14465 hdd_err("unable to get vht_enable_tx_bf");
14466
14467 if (bval)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014468 score_config->beamformee_cap = 1;
14469
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014470 return QDF_STATUS_SUCCESS;
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014471}
14472
Abhishek Singh257a9482017-03-06 16:52:39 +053014473/**
bings81fe50a2017-11-27 14:33:26 +080014474 * hdd_update_dfs_config() - API to update dfs configuration parameters.
14475 * @hdd_ctx: HDD context
14476 *
14477 * Return: 0 if success else err
14478 */
14479static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
14480{
Dustin Brown1dbefe62018-09-11 16:32:03 -070014481 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Abhishek Singh98278ce2018-12-27 11:41:03 +053014482 struct dfs_user_config dfs_cfg = {0};
bings81fe50a2017-11-27 14:33:26 +080014483 QDF_STATUS status;
14484
Arif Hussain224d3812018-11-16 17:58:38 -080014485 ucfg_mlme_get_dfs_filter_offload(hdd_ctx->psoc,
14486 &dfs_cfg.dfs_is_phyerr_filter_offload);
bings81fe50a2017-11-27 14:33:26 +080014487 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
14488 if (QDF_IS_STATUS_ERROR(status)) {
14489 hdd_err("failed dfs psoc configuration");
14490 return -EINVAL;
14491 }
14492
14493 return 0;
14494}
14495
14496/**
Abhishek Singh257a9482017-03-06 16:52:39 +053014497 * hdd_update_scan_config - API to update scan configuration parameters
14498 * @hdd_ctx: HDD context
14499 *
14500 * Return: 0 if success else err
14501 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014502static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053014503{
Dustin Brown1dbefe62018-09-11 16:32:03 -070014504 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Sandeep Puligillad7887022019-02-26 00:48:52 -080014505 struct scan_user_cfg scan_cfg;
Abhishek Singh257a9482017-03-06 16:52:39 +053014506 QDF_STATUS status;
Krunal Sonid2c33e12018-12-06 15:02:37 -080014507 uint32_t mcast_mcc_rest_time = 0;
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014508
Sandeep Puligillad7887022019-02-26 00:48:52 -080014509 qdf_mem_zero(&scan_cfg, sizeof(scan_cfg));
Krunal Sonid2c33e12018-12-06 15:02:37 -080014510 status = ucfg_mlme_get_sta_miracast_mcc_rest_time(hdd_ctx->psoc,
14511 &mcast_mcc_rest_time);
14512 if (!QDF_IS_STATUS_SUCCESS(status)) {
14513 hdd_err("ucfg_mlme_get_sta_miracast_mcc_rest_time, use def");
14514 return -EIO;
14515 }
14516 scan_cfg.sta_miracast_mcc_rest_time = mcast_mcc_rest_time;
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014517 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, hdd_ctx);
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014518
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014519 status = hdd_update_score_config(&scan_cfg.score_config, hdd_ctx);
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014520 if (QDF_IS_STATUS_ERROR(status)) {
14521 hdd_err("Failed to update scoring config");
14522 return -EINVAL;
14523 }
Abhishek Singhb20db962017-03-03 21:28:46 +053014524
Abhishek Singh257a9482017-03-06 16:52:39 +053014525 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
14526 if (status != QDF_STATUS_SUCCESS) {
14527 hdd_err("failed pmo psoc configuration");
14528 return -EINVAL;
14529 }
14530
14531 return 0;
14532}
Abhishek Singh257a9482017-03-06 16:52:39 +053014533
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014534int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053014535{
14536 int ret;
14537
14538 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053014539 if (ret)
14540 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014541
Abhishek Singh257a9482017-03-06 16:52:39 +053014542 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080014543 if (ret)
14544 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014545
Frank Liud4b2fa02017-03-29 11:46:48 +080014546 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014547 if (ret)
14548 return ret;
14549
14550 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080014551 if (ret)
14552 return ret;
14553
14554 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014555
14556 return ret;
14557}
14558
Agrawal Ashish65634612016-08-18 13:24:32 +053014559/**
14560 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
14561 * @mode : cfg80211 DFS mode
14562 *
14563 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
14564 */
14565enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
14566{
14567 switch (mode) {
14568 case DFS_MODE_ENABLE:
14569 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014570 case DFS_MODE_DISABLE:
14571 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014572 case DFS_MODE_DEPRIORITIZE:
14573 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014574 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080014575 hdd_debug("ACS dfs mode is NONE");
14576 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014577 }
14578}
14579
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014580/**
14581 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
14582 * @hddctx: pointer to hdd context
14583 * @set_value: enable/disable
14584 *
14585 * When Host sends vendor command enable, FW will send *ONE* CA ind to
14586 * Host(even though it is duplicate). When Host send vendor command
14587 * disable,FW doesn't perform any action. Whenever any change in
14588 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
14589 *
14590 * return - 0 on success, appropriate error values on failure.
14591 */
Jeff Johnson16528362018-06-14 12:34:16 -070014592int hdd_enable_disable_ca_event(struct hdd_context *hdd_ctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014593{
14594 QDF_STATUS status;
14595
Jeff Johnson16528362018-06-14 12:34:16 -070014596 if (0 != wlan_hdd_validate_context(hdd_ctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014597 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014598
Jeff Johnson16528362018-06-14 12:34:16 -070014599 status = sme_enable_disable_chanavoidind_event(hdd_ctx->mac_handle,
14600 set_value);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014601 if (!QDF_IS_STATUS_SUCCESS(status)) {
14602 hdd_err("Failed to send chan avoid command to SME");
14603 return -EINVAL;
14604 }
14605 return 0;
14606}
Agrawal Ashish65634612016-08-18 13:24:32 +053014607
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014608/**
14609 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
14610 * @value: value to set
14611 *
14612 * This function will set the passed value to roaming in progress flag.
14613 *
14614 * Return: None
14615 */
14616void hdd_set_roaming_in_progress(bool value)
14617{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014618 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014619
14620 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14621 if (!hdd_ctx) {
14622 hdd_err("HDD context is NULL");
14623 return;
14624 }
14625
14626 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080014627 hdd_debug("Roaming in Progress set to %d", value);
Abhinav Kumar2b431b62019-03-18 20:23:58 +053014628 if (!hdd_ctx->roaming_in_progress) {
14629 /* Reset scan reject params on successful roam complete */
14630 hdd_debug("Reset scan reject params");
14631 hdd_init_scan_reject_params(hdd_ctx);
14632 }
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014633}
14634
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014635bool hdd_is_roaming_in_progress(struct hdd_context *hdd_ctx)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014636{
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014637 if (!hdd_ctx) {
14638 hdd_err("HDD context is NULL");
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014639 return false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014640 }
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080014641
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014642 hdd_debug("roaming_in_progress = %d", hdd_ctx->roaming_in_progress);
14643
14644 return hdd_ctx->roaming_in_progress;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014645}
14646
Jeff Johnsona2ac4e72019-03-06 08:35:29 -080014647bool hdd_is_connection_in_progress(uint8_t *out_vdev_id,
14648 enum scan_reject_states *out_reason)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014649{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070014650 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070014651 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014652 uint8_t sta_id = 0;
14653 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014654 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -070014655 mac_handle_t mac_handle;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014656
14657 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14658 if (!hdd_ctx) {
14659 hdd_err("HDD context is NULL");
14660 return false;
14661 }
14662
Jeff Johnson16528362018-06-14 12:34:16 -070014663 mac_handle = hdd_ctx->mac_handle;
14664
Dustin Brown920397d2017-12-13 16:27:50 -080014665 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya929afa42018-06-01 15:04:44 -070014666 hdd_debug("Adapter with device mode %s(%d) exists",
Dustin Brown458027c2018-10-19 12:26:27 -070014667 qdf_opmode_str(adapter->device_mode),
14668 adapter->device_mode);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014669 if (((QDF_STA_MODE == adapter->device_mode)
14670 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
14671 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
14672 && (eConnectionState_Connecting ==
14673 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
Jeff Johnsone7951512019-02-27 10:02:51 -080014674 conn_info.conn_state)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014675 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014676 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014677 adapter->vdev_id);
Jeff Johnsona2ac4e72019-03-06 08:35:29 -080014678 if (out_vdev_id && out_reason) {
14679 *out_vdev_id = adapter->vdev_id;
14680 *out_reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014681 }
14682 return true;
14683 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070014684 /*
14685 * sme_neighbor_middle_of_roaming is for LFR2
14686 * hdd_is_roaming_in_progress is for LFR3
14687 */
14688 if (((QDF_STA_MODE == adapter->device_mode) &&
14689 sme_neighbor_middle_of_roaming(
Jeff Johnson16528362018-06-14 12:34:16 -070014690 mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014691 adapter->vdev_id)) ||
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014692 hdd_is_roaming_in_progress(hdd_ctx)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014693 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014694 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014695 adapter->vdev_id);
Jeff Johnsona2ac4e72019-03-06 08:35:29 -080014696 if (out_vdev_id && out_reason) {
14697 *out_vdev_id = adapter->vdev_id;
14698 *out_reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014699 }
14700 return true;
14701 }
14702 if ((QDF_STA_MODE == adapter->device_mode) ||
14703 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
14704 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
14705 hdd_sta_ctx =
14706 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
14707 if ((eConnectionState_Associated ==
Jeff Johnsone7951512019-02-27 10:02:51 -080014708 hdd_sta_ctx->conn_info.conn_state)
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053014709 && sme_is_sta_key_exchange_in_progress(
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014710 mac_handle, adapter->vdev_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014711 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070014712 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014713 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014714 " is in middle of WPS/EAPOL exchange.",
Srinivas Girigowda34fbba02019-04-08 12:07:44 -070014715 QDF_MAC_ADDR_ARRAY(sta_mac));
Jeff Johnsona2ac4e72019-03-06 08:35:29 -080014716 if (out_vdev_id && out_reason) {
14717 *out_vdev_id = adapter->vdev_id;
14718 *out_reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014719 }
14720 return true;
14721 }
14722 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
14723 (QDF_P2P_GO_MODE == adapter->device_mode)) {
14724 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
14725 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014726 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014727 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014728 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014729 continue;
14730
14731 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014732 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070014733 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014734 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014735 " of SAP/GO is in middle of WPS/EAPOL exchange",
Srinivas Girigowda34fbba02019-04-08 12:07:44 -070014736 QDF_MAC_ADDR_ARRAY(sta_mac));
Jeff Johnsona2ac4e72019-03-06 08:35:29 -080014737 if (out_vdev_id && out_reason) {
14738 *out_vdev_id = adapter->vdev_id;
14739 *out_reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014740 }
14741 return true;
14742 }
14743 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014744 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014745 return true;
14746 }
14747 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014748 }
Dustin Brown920397d2017-12-13 16:27:50 -080014749
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014750 return false;
14751}
14752
14753/**
14754 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070014755 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014756 *
14757 * Return: None
14758 */
Jeff Johnson9d295242017-08-29 14:39:48 -070014759void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014760{
Jeff Johnson87251032017-08-29 13:31:11 -070014761 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070014762 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014763 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014764 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Jeff Johnson8f8ceb92019-03-24 08:16:55 -070014765 struct sap_config *sap_config;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014766 void *sap_ctx;
14767
14768 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070014769 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070014770 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014771
14772 mutex_lock(&hdd_ctx->sap_lock);
14773 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
14774 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014775 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
14776 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
14777 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
14778 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053014779 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014780 qdf_stop_bss_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +053014781 SME_CMD_STOP_BSS_TIMEOUT);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014782
14783 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014784 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014785 goto end;
14786 }
14787 }
14788 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -070014789 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014790 ap_adapter->device_mode, ap_adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070014791 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014792 false);
Jeff Johnson6867ec32017-09-29 20:30:20 -070014793 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014794
14795 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014796 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014797 wlansap_reset_sap_config_add_ie(sap_config,
14798 eUPDATE_IE_ALL);
14799 goto end;
14800 }
14801
14802 qdf_event_reset(&hostapd_state->qdf_event);
14803 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
14804 sap_config,
14805 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014806 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014807 wlansap_reset_sap_config_add_ie(sap_config,
14808 eUPDATE_IE_ALL);
14809 goto end;
14810 }
14811
Jeff Johnson6867ec32017-09-29 20:30:20 -070014812 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014813 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053014814 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +053014815 SME_CMD_START_BSS_TIMEOUT);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014816 wlansap_reset_sap_config_add_ie(sap_config,
14817 eUPDATE_IE_ALL);
14818 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014819 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014820 goto end;
14821 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070014822 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014823 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014824 if (hostapd_state->bss_state == BSS_START) {
Dustin Brown1dbefe62018-09-11 16:32:03 -070014825 policy_mgr_incr_active_session(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014826 ap_adapter->device_mode,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014827 ap_adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070014828 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014829 ap_adapter->device_mode,
14830 true);
14831 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014832 }
14833end:
14834 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014835}
14836
14837/**
14838 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
14839 * with non dfs acs
14840 *
14841 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
14842 *
14843 * Return: None
14844 */
14845void hdd_check_and_restart_sap_with_non_dfs_acs(void)
14846{
Jeff Johnson9d295242017-08-29 14:39:48 -070014847 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014848 struct hdd_context *hdd_ctx;
Jeff Johnson2b6982c2018-05-29 14:56:11 -070014849 struct cds_context *cds_ctx;
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014850 uint8_t restart_chan;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014851
14852 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14853 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014854 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014855 return;
14856 }
14857
14858 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
14859 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014860 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014861 return;
14862 }
14863
Dustin Brown1dbefe62018-09-11 16:32:03 -070014864 if (policy_mgr_get_concurrency_mode(hdd_ctx->psoc)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014865 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Dustin Brown7e761c72018-07-31 13:50:17 -070014866 hdd_debug("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014867 return;
14868 }
14869
14870 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Dustin Brown07901ec2018-09-07 11:02:41 -070014871 if (ap_adapter &&
14872 test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags) &&
14873 wlan_reg_is_dfs_ch(hdd_ctx->pdev,
14874 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014875
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014876 hdd_warn("STA-AP Mode DFS not supported, Switch SAP channel to Non DFS");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014877
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014878 restart_chan =
14879 hdd_get_safe_channel_from_pcl_and_acs_range(ap_adapter);
14880 if (!restart_chan ||
Dustin Brown07901ec2018-09-07 11:02:41 -070014881 wlan_reg_is_dfs_ch(hdd_ctx->pdev, restart_chan))
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014882 restart_chan = SAP_DEFAULT_5GHZ_CHANNEL;
14883
14884 hdd_switch_sap_channel(ap_adapter, restart_chan, true);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014885 }
14886}
14887
14888/**
14889 * hdd_set_connection_in_progress() - to set the connection in
14890 * progress flag
14891 * @value: value to set
14892 *
14893 * This function will set the passed value to connection in progress flag.
14894 * If value is previously being set to true then no need to set it again.
14895 *
14896 * Return: true if value is being set correctly and false otherwise.
14897 */
14898bool hdd_set_connection_in_progress(bool value)
14899{
14900 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014901 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014902
14903 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14904 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014905 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014906 return false;
14907 }
14908
14909 qdf_spin_lock(&hdd_ctx->connection_status_lock);
14910 /*
14911 * if the value is set to true previously and if someone is
14912 * trying to make it true again then it could be some race
14913 * condition being triggered. Avoid this situation by returning
14914 * false
14915 */
14916 if (hdd_ctx->connection_in_progress && value)
14917 status = false;
14918 else
14919 hdd_ctx->connection_in_progress = value;
14920 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
14921 return status;
14922}
14923
Jeff Johnson9d295242017-08-29 14:39:48 -070014924int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014925{
14926 if (!adapter) {
14927 hdd_err("Invalid adapter");
14928 return -EINVAL;
14929 }
14930 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014931 sme_cli_set_command(adapter->vdev_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014932 WMA_VDEV_MCC_SET_TIME_QUOTA,
14933 set_value, VDEV_CMD);
14934 return 0;
14935
14936}
14937
Jeff Johnson9d295242017-08-29 14:39:48 -070014938int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014939{
14940 if (!adapter) {
14941 hdd_err("Invalid adapter");
14942 return -EINVAL;
14943 }
14944
14945 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014946 sme_cli_set_command(adapter->vdev_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014947 WMA_VDEV_MCC_SET_TIME_LATENCY,
14948 set_value, VDEV_CMD);
14949 return 0;
14950}
14951
Jeff Johnson9d295242017-08-29 14:39:48 -070014952struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070014953 *psoc, uint8_t vdev_id)
14954{
Jeff Johnson9d295242017-08-29 14:39:48 -070014955 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014956 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070014957
14958 /*
14959 * Currently PSOC is not being used. But this logic will
14960 * change once we have the converged implementation of
14961 * HDD context per PSOC in place. This would break if
14962 * multiple vdev objects reuse the vdev id.
14963 */
14964 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
14965 if (!adapter)
14966 hdd_err("Get adapter by vdev id failed");
14967
14968 return adapter;
14969}
14970
Jeff Johnson9d295242017-08-29 14:39:48 -070014971int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014972 int8_t *rssi, int8_t *snr)
14973{
14974 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -070014975 mac_handle_t mac_handle;
Jeff Johnson025618c2018-03-18 14:41:00 -070014976 struct csr_roam_profile *roam_profile;
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014977
Jeff Johnson025618c2018-03-18 14:41:00 -070014978 roam_profile = hdd_roam_profile(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -070014979 mac_handle = hdd_adapter_get_mac_handle(adapter);
14980 status = sme_get_rssi_snr_by_bssid(mac_handle,
Jeff Johnson025618c2018-03-18 14:41:00 -070014981 roam_profile, bssid, rssi, snr);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014982 if (QDF_STATUS_SUCCESS != status) {
14983 hdd_warn("sme_get_rssi_snr_by_bssid failed");
14984 return -EINVAL;
14985 }
14986
14987 return 0;
14988}
14989
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014990/**
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014991 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
14992 * @adapter - HDD adapter
14993 *
14994 * Return: 0 on success and non zero value on failure
14995 */
14996int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
14997{
14998 struct hdd_context *hdd_ctx;
14999 int ret;
15000 QDF_STATUS status;
Krunal Sonie71838d2018-09-27 10:45:05 -070015001 uint8_t sys_pref = 0;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053015002
15003 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
15004 ret = wlan_hdd_validate_context(hdd_ctx);
15005 if (ret < 0)
15006 return ret;
15007
Krunal Sonie71838d2018-09-27 10:45:05 -070015008 ucfg_policy_mgr_get_sys_pref(hdd_ctx->psoc,
15009 &sys_pref);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053015010 /* set the system preferece to default */
Krunal Sonie71838d2018-09-27 10:45:05 -070015011 policy_mgr_set_cur_conc_system_pref(hdd_ctx->psoc, sys_pref);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053015012
15013 /* clear the bitmap */
15014 adapter->active_ac = 0;
15015
15016 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson5a6fc962019-02-04 14:20:25 -080015017 adapter->vdev_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053015018
Jeff Johnson16528362018-06-14 12:34:16 -070015019 status = sme_send_limit_off_channel_params(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080015020 adapter->vdev_id,
Jeff Johnson16528362018-06-14 12:34:16 -070015021 false, 0, 0, false);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053015022 if (!QDF_IS_STATUS_SUCCESS(status)) {
15023 hdd_err("failed to reset limit off chan params");
15024 ret = -EINVAL;
15025 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053015026
15027 return ret;
15028}
15029
Yun Parkff6a16a2017-09-26 16:38:18 -070015030void hdd_set_rx_mode_rps(bool enable)
15031{
15032 struct cds_config_info *cds_cfg = cds_get_ini_config();
Ryan Hsu0e878fa2018-05-04 15:22:09 -070015033 struct hdd_context *hdd_ctx;
15034 struct hdd_adapter *adapter;
Yun Parkff6a16a2017-09-26 16:38:18 -070015035
Ryan Hsu0e878fa2018-05-04 15:22:09 -070015036 if (!cds_cfg)
15037 return;
15038
15039 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
15040 if (!hdd_ctx)
15041 return;
15042
15043 adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
15044 if (!adapter)
15045 return;
15046
15047 if (!hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
Yun Parkff6a16a2017-09-26 16:38:18 -070015048 if (enable && !cds_cfg->rps_enabled)
15049 hdd_send_rps_ind(adapter);
15050 else if (!enable && cds_cfg->rps_enabled)
15051 hdd_send_rps_disable_ind(adapter);
15052 }
15053}
15054
Abhinav Kumar338e57d2019-02-04 17:30:10 +053015055void hdd_hidden_ssid_enable_roaming(hdd_handle_t hdd_handle, uint8_t vdev_id)
15056{
15057 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
15058 struct hdd_adapter *adapter;
15059
15060 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
15061
15062 if (!adapter) {
15063 hdd_err("Adapter is null");
15064 return;
15065 }
15066 /* enable roaming on all adapters once hdd get hidden ssid rsp */
15067 wlan_hdd_enable_roaming(adapter);
15068}
15069
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015070/* Register the module init/exit functions */
15071module_init(hdd_module_init);
15072module_exit(hdd_module_exit);
15073
15074MODULE_LICENSE("Dual BSD/GPL");
15075MODULE_AUTHOR("Qualcomm Atheros, Inc.");
15076MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
15077
Srinivas Girigowda841da292018-02-21 16:33:00 -080015078static const struct kernel_param_ops con_mode_ops = {
15079 .set = con_mode_handler,
15080 .get = param_get_int,
15081};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015082
Srinivas Girigowda841da292018-02-21 16:33:00 -080015083static const struct kernel_param_ops con_mode_ftm_ops = {
15084 .set = con_mode_handler_ftm,
15085 .get = param_get_int,
15086};
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053015087
Nirav Shah6aeecf92019-02-13 14:05:03 +053015088#ifdef WLAN_FEATURE_EPPING
15089static const struct kernel_param_ops con_mode_epping_ops = {
15090 .set = con_mode_handler_epping,
15091 .get = param_get_int,
15092};
15093#endif
15094
Nirav Shah73713f72018-05-17 14:50:41 +053015095#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080015096static const struct kernel_param_ops con_mode_monitor_ops = {
15097 .set = con_mode_handler_monitor,
15098 .get = param_get_int,
15099};
Nirav Shah73713f72018-05-17 14:50:41 +053015100#endif
Ravi Joshia307f632017-07-17 23:41:41 -070015101
Srinivas Girigowda841da292018-02-21 16:33:00 -080015102static const struct kernel_param_ops fwpath_ops = {
15103 .set = fwpath_changed_handler,
15104 .get = param_get_string,
15105};
15106
15107module_param_cb(con_mode, &con_mode_ops, &con_mode,
15108 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
15109
15110module_param_cb(con_mode_ftm, &con_mode_ftm_ops, &con_mode_ftm,
15111 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
15112
Nirav Shah6aeecf92019-02-13 14:05:03 +053015113#ifdef WLAN_FEATURE_EPPING
15114module_param_cb(con_mode_epping, &con_mode_epping_ops,
15115 &con_mode_epping, 0644);
15116#endif
15117
Nirav Shah73713f72018-05-17 14:50:41 +053015118#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080015119module_param_cb(con_mode_monitor, &con_mode_monitor_ops, &con_mode_monitor,
15120 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Nirav Shah73713f72018-05-17 14:50:41 +053015121#endif
Srinivas Girigowda841da292018-02-21 16:33:00 -080015122
15123module_param_cb(fwpath, &fwpath_ops, &fwpath,
15124 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015125
15126module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
15127
15128module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
15129
15130module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);
Dustin Brown4bbd5462019-03-22 11:18:13 -070015131
15132static int timer_multiplier_get_handler(char *buffer,
15133 const struct kernel_param *kp)
15134{
15135 return scnprintf(buffer, PAGE_SIZE, "%u", qdf_timer_get_multiplier());
15136}
15137
15138static int timer_multiplier_set_handler(const char *kmessage,
15139 const struct kernel_param *kp)
15140{
15141 QDF_STATUS status;
15142 uint32_t scalar;
15143
15144 status = qdf_uint32_parse(kmessage, &scalar);
15145 if (QDF_IS_STATUS_ERROR(status))
15146 return qdf_status_to_os_return(status);
15147
15148 if (!cfg_in_range(CFG_TIMER_MULTIPLIER, scalar))
15149 return -ERANGE;
15150
15151 qdf_timer_set_multiplier(scalar);
15152
15153 return 0;
15154}
15155
15156static const struct kernel_param_ops timer_multiplier_ops = {
15157 .get = timer_multiplier_get_handler,
15158 .set = timer_multiplier_set_handler,
15159};
15160
15161module_param_cb(timer_multiplier, &timer_multiplier_ops, NULL, 0644);
15162