blob: a295be7be746c2f96d7a699c42e4b6a2c50c4914 [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>
Subrat Dash5f36fbe2019-02-12 16:28:14 +053081#include <linux/ethtool.h>
Tiger Yu8b119e92019-04-09 13:55:07 +080082
83#ifdef WLAN_FEATURE_DP_BUS_BANDWIDTH
84#include "qdf_periodic_work.h"
85#endif
86
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080087#ifdef MSM_PLATFORM
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080088#include <soc/qcom/subsystem_restart.h>
89#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080090#include <wlan_hdd_hostapd.h>
91#include <wlan_hdd_softap_tx_rx.h>
Jeff Johnson8bb61112018-03-31 13:33:54 -070092#include <wlan_hdd_green_ap.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080093#include "qwlan_version.h"
94#include "wma_types.h"
95#include "wlan_hdd_tdls.h"
96#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053097#include "cds_regdomain.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080098#endif /* FEATURE_WLAN_CH_AVOID */
Dustin Brownce46d1d2017-08-15 13:34:24 -070099#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -0700100#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -0800101#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800102#include "wlan_hdd_nan.h"
103#include "wlan_hdd_debugfs.h"
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +0530104#include "wlan_hdd_debugfs_csr.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800105#include "wlan_hdd_driver_ops.h"
106#include "epping_main.h"
Poddar, Siddarth34872782017-08-10 14:08:51 +0530107#include "wlan_hdd_data_stall_detection.h"
stonezc9936cb2019-03-11 16:41:22 +0800108#include "wlan_hdd_mpta_helper.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800109
110#include <wlan_hdd_ipa.h>
111#include "hif.h"
112#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800113#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700114#include "wlan_hdd_tsf.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530115#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700116#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700117#include "wlan_hdd_lpass.h"
Nachiket Kukade63bb63d2018-11-21 14:42:14 +0530118#include "wlan_nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700119#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530120#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800121#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800122#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530123#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800124#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800125#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530126#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530127#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800128#include "os_if_wifi_pos.h"
129#include "wifi_pos_api.h"
130#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800131#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700132#include "os_if_nan.h"
133#include "nan_public_structs.h"
Nachiket Kukade85aa3782018-11-02 20:12:34 +0530134#include "nan_ucfg_api.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700135#include "wlan_reg_ucfg_api.h"
bings81fe50a2017-11-27 14:33:26 +0800136#include "wlan_dfs_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700137#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530138#include "sme_power_save_api.h"
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +0530139#include "enet.h"
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700140#include <cdp_txrx_cmn_struct.h>
Mohit Khanna70322002018-05-15 19:21:32 -0700141#include <dp_txrx.h>
Amar Singhal0928b192017-12-01 10:50:54 -0800142#include "wlan_hdd_sysfs.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530143#include "wlan_disa_ucfg_api.h"
Wu Gao52084c12018-05-17 20:47:11 +0800144#include "wlan_disa_obj_mgmt_api.h"
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +0530145#include "wlan_action_oui_ucfg_api.h"
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +0530146#include "wlan_ipa_ucfg_api.h"
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530147#include <target_if.h>
Alok Kumarb64650c2018-03-23 17:05:11 +0530148#include "wlan_hdd_nud_tracking.h"
Nachiket Kukaded0dd62e2018-05-21 18:39:22 +0530149#include "wlan_hdd_apf.h"
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -0700150#include "wlan_hdd_twt.h"
Rachit Kankane0dc3e852018-05-07 17:33:42 +0530151#include "qc_sap_ioctl.h"
Sandeep Puligillac5609d52018-05-17 19:23:41 -0700152#include "wlan_mlme_main.h"
Wu Gaoe5689792018-07-05 19:20:13 +0800153#include "wlan_p2p_cfg_api.h"
Wu Gao637d58a2018-12-08 10:37:34 +0800154#include "wlan_cfg80211_p2p.h"
Paul Zhang37185672019-05-14 11:20:14 +0800155#include "wlan_cfg80211_interop_issues_ap.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>
Paul Zhang37185672019-05-14 11:20:14 +0800169#include <wlan_interop_issues_ap_ucfg_api.h>
Mohit Khanna81418772018-10-30 14:14:46 -0700170#include <target_type.h>
Arun Kumar Khandavallideda5a82019-03-11 15:32:19 +0530171#include <wlan_hdd_debugfs_coex.h>
Liangwei Dong3abfe8f2018-09-20 02:25:44 -0400172
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800173#ifdef MODULE
174#define WLAN_MODULE_NAME module_name(THIS_MODULE)
175#else
176#define WLAN_MODULE_NAME "wlan"
177#endif
178
179#ifdef TIMER_MANAGER
180#define TIMER_MANAGER_STR " +TIMER_MANAGER"
181#else
182#define TIMER_MANAGER_STR ""
183#endif
184
185#ifdef MEMORY_DEBUG
186#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
187#else
188#define MEMORY_DEBUG_STR ""
189#endif
190
Dustin Brownc1034df2018-02-07 14:51:32 -0800191#ifdef PANIC_ON_BUG
192#define PANIC_ON_BUG_STR " +PANIC_ON_BUG"
193#else
194#define PANIC_ON_BUG_STR ""
195#endif
196
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},
Paul Zhang37185672019-05-14 11:20:14 +0800324 [QDF_MODULE_ID_INTEROP_ISSUES_AP] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700325};
326
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530327struct notifier_block hdd_netdev_notifier;
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
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530691 return 0;
692}
693
Will Huang79af29f2019-04-11 15:46:26 +0800694uint8_t hdd_get_adapter_home_channel(struct hdd_adapter *adapter)
695{
696 uint8_t home_channel = 0;
697
698 if ((adapter->device_mode == QDF_SAP_MODE ||
699 adapter->device_mode == QDF_P2P_GO_MODE) &&
700 test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
701 home_channel = adapter->session.ap.operating_channel;
702 } else if ((adapter->device_mode == QDF_STA_MODE ||
703 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
704 adapter->session.station.conn_info.conn_state ==
705 eConnectionState_Associated) {
706 home_channel =
707 adapter->session.station.conn_info.channel;
708 }
709
710 return home_channel;
711}
712
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800713#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
Dustin Brown98f7c822019-03-06 12:25:49 -0800714static inline struct net_device *hdd_net_dev_from_notifier(void *context)
715{
716 struct netdev_notifier_info *info = context;
717
718 return info->dev;
719}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800720#else
Dustin Brown98f7c822019-03-06 12:25:49 -0800721static inline struct net_device *hdd_net_dev_from_notifier(void *context)
722{
723 return context;
724}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800725#endif
Dustin Brown98f7c822019-03-06 12:25:49 -0800726
727static int __hdd_netdev_notifier_call(struct net_device *net_dev,
728 unsigned long state)
729{
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530730 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700731 struct hdd_context *hdd_ctx;
Min Liu8c5d99e2018-09-10 17:18:44 +0800732 struct wlan_objmgr_vdev *vdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800733
Dustin Brown98f7c822019-03-06 12:25:49 -0800734 hdd_enter_dev(net_dev);
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800735
Dustin Brown98f7c822019-03-06 12:25:49 -0800736 if (!net_dev->ieee80211_ptr) {
Dustin Brownaeb55642018-07-30 17:20:32 -0700737 hdd_debug("ieee80211_ptr is null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800738 return NOTIFY_DONE;
739 }
740
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530741 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
742 if (!hdd_ctx) {
743 hdd_err("HDD Context is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800744 return NOTIFY_DONE;
745 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800746
747 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -0700748 hdd_debug("%s: Driver module is closed", __func__);
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800749 return NOTIFY_DONE;
750 }
751
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530752 /* Make sure that this callback corresponds to our device. */
Dustin Brown98f7c822019-03-06 12:25:49 -0800753 adapter = hdd_get_adapter_by_iface_name(hdd_ctx, net_dev->name);
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530754 if (!adapter) {
Dustin Brown98f7c822019-03-06 12:25:49 -0800755 hdd_debug("failed to look up adapter for '%s'", net_dev->name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800756 return NOTIFY_DONE;
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530757 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800758
Dustin Brown98f7c822019-03-06 12:25:49 -0800759 if (adapter != WLAN_HDD_GET_PRIV_PTR(net_dev)) {
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530760 hdd_err("HDD adapter mismatch!");
761 return NOTIFY_DONE;
762 }
763
Dustin Brownaeb55642018-07-30 17:20:32 -0700764 if (cds_is_driver_recovering()) {
765 hdd_debug("Driver is recovering");
766 return NOTIFY_DONE;
767 }
768
769 if (cds_is_driver_in_bad_state()) {
770 hdd_debug("Driver is in failed recovery state");
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530771 return NOTIFY_DONE;
772 }
773
Dustin Brown98f7c822019-03-06 12:25:49 -0800774 hdd_debug("%s New Net Device State = %lu", net_dev->name, state);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800775
776 switch (state) {
777 case NETDEV_REGISTER:
778 break;
779
780 case NETDEV_UNREGISTER:
781 break;
782
783 case NETDEV_UP:
Jeff Johnson16528362018-06-14 12:34:16 -0700784 sme_ch_avoid_update_req(hdd_ctx->mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800785 break;
786
787 case NETDEV_DOWN:
788 break;
789
790 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700791 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800792 complete(&adapter->linkup_event_var);
793 break;
794
795 case NETDEV_GOING_DOWN:
Min Liu8c5d99e2018-09-10 17:18:44 +0800796 vdev = hdd_objmgr_get_vdev(adapter);
797 if (!vdev)
798 break;
799 if (ucfg_scan_get_vdev_status(vdev) !=
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700800 SCAN_NOT_IN_PROGRESS) {
Dustin Brown07901ec2018-09-07 11:02:41 -0700801 wlan_abort_scan(hdd_ctx->pdev, INVAL_PDEV_ID,
Jeff Johnson5a6fc962019-02-04 14:20:25 -0800802 adapter->vdev_id, INVALID_SCAN_ID,
Dustin Brown07901ec2018-09-07 11:02:41 -0700803 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800804 }
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +0530805 hdd_objmgr_put_vdev(vdev);
Min Liu9be5d4a2018-05-17 11:51:53 +0800806 cds_flush_work(&adapter->scan_block_work);
807 /* Need to clean up blocked scan request */
Dustin Brown96b98dd2019-03-06 12:39:37 -0800808 wlan_hdd_cfg80211_scan_block(adapter);
Min Liu9be5d4a2018-05-17 11:51:53 +0800809 hdd_debug("Scan is not Pending from user");
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530810 /*
811 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
812 * of return status of hdd_stop call, kernel resets the IFF_UP
813 * flag after which driver does not send the cfg80211_scan_done.
814 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
815 */
Dustin Brown98f7c822019-03-06 12:25:49 -0800816 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, net_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800817 break;
818
819 default:
820 break;
821 }
822
823 return NOTIFY_DONE;
824}
825
826/**
827 * hdd_netdev_notifier_call() - netdev notifier callback function
828 * @nb: pointer to notifier block
829 * @state: state
Dustin Brown98f7c822019-03-06 12:25:49 -0800830 * @context: notifier callback context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800831 *
832 * Return: 0 on success, error number otherwise.
833 */
834static int hdd_netdev_notifier_call(struct notifier_block *nb,
835 unsigned long state,
Dustin Brown98f7c822019-03-06 12:25:49 -0800836 void *context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800837{
Dustin Brown98f7c822019-03-06 12:25:49 -0800838 struct net_device *net_dev = hdd_net_dev_from_notifier(context);
839 struct osif_vdev_sync *vdev_sync;
840 int errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800841
Dustin Brown98f7c822019-03-06 12:25:49 -0800842 errno = osif_vdev_sync_op_start(net_dev, &vdev_sync);
843 if (errno)
844 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800845
Dustin Brown98f7c822019-03-06 12:25:49 -0800846 errno = __hdd_netdev_notifier_call(net_dev, state);
847
848 osif_vdev_sync_op_stop(vdev_sync);
849
850 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800851}
852
853struct notifier_block hdd_netdev_notifier = {
854 .notifier_call = hdd_netdev_notifier_call,
855};
856
857/* variable to hold the insmod parameters */
858static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800859
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530860static int con_mode_ftm;
Nirav Shah6aeecf92019-02-13 14:05:03 +0530861int con_mode_epping;
Ravi Joshia307f632017-07-17 23:41:41 -0700862int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530863
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800864/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800865static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800866
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530867/**
868 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
869 * @ch_width: NL channel width
870 *
871 * Converts the NL channel width to the driver's internal representation
872 *
873 * Return: Converted channel width. In case of non matching NL channel width,
874 * CH_WIDTH_MAX will be returned.
875 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800876enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530877{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800878 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700879
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800880 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530881 switch (ch_width) {
882 case NL80211_CHAN_WIDTH_20_NOHT:
883 case NL80211_CHAN_WIDTH_20:
884 return CH_WIDTH_20MHZ;
885 case NL80211_CHAN_WIDTH_40:
886 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530887 case NL80211_CHAN_WIDTH_80:
888 return CH_WIDTH_80MHZ;
889 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800890 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
891 return CH_WIDTH_80P80MHZ;
892 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
893 return CH_WIDTH_160MHZ;
894 else
895 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530896 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800897 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
898 return CH_WIDTH_160MHZ;
899 else
900 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530901 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800902 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530903 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800904 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530905 default:
906 hdd_err("Invalid channel width %d, setting to default",
907 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800908 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530909 }
910}
911
Dustin Brown56377e12018-10-10 17:04:04 -0700912QDF_STATUS hdd_nl_to_qdf_iface_type(enum nl80211_iftype nl_type,
913 enum QDF_OPMODE *out_qdf_type)
914{
915 switch (nl_type) {
916 case NL80211_IFTYPE_ADHOC:
917 *out_qdf_type = QDF_IBSS_MODE;
918 break;
919 case NL80211_IFTYPE_AP:
920 *out_qdf_type = QDF_SAP_MODE;
921 break;
922 case NL80211_IFTYPE_MONITOR:
923 *out_qdf_type = QDF_MONITOR_MODE;
924 break;
925 case NL80211_IFTYPE_OCB:
926 *out_qdf_type = QDF_OCB_MODE;
927 break;
928 case NL80211_IFTYPE_P2P_CLIENT:
929 *out_qdf_type = QDF_P2P_CLIENT_MODE;
930 break;
931 case NL80211_IFTYPE_P2P_DEVICE:
932 *out_qdf_type = QDF_P2P_DEVICE_MODE;
933 break;
934 case NL80211_IFTYPE_P2P_GO:
935 *out_qdf_type = QDF_P2P_GO_MODE;
936 break;
937 case NL80211_IFTYPE_STATION:
938 *out_qdf_type = QDF_STA_MODE;
939 break;
940 case NL80211_IFTYPE_WDS:
941 *out_qdf_type = QDF_WDS_MODE;
942 break;
943 default:
944 hdd_err("Invalid nl80211 interface type %d", nl_type);
945 return QDF_STATUS_E_INVAL;
946 }
947
948 return QDF_STATUS_SUCCESS;
949}
950
Jeff Johnson16528362018-06-14 12:34:16 -0700951uint8_t wlan_hdd_find_opclass(mac_handle_t mac_handle, uint8_t channel,
952 uint8_t bw_offset)
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530953{
954 uint8_t opclass = 0;
955
Jeff Johnson16528362018-06-14 12:34:16 -0700956 sme_get_opclass(mac_handle, channel, bw_offset, &opclass);
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530957 return opclass;
958}
959
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800960/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530961 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530962 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800963 * @bitmask: Bitmask of log levels to be enabled
964 *
965 * Called immediately after the cfg.ini is read in order to configure
966 * the desired trace levels.
967 *
968 * Return: None
969 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530970int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800971{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530972 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530973 int qdf_print_idx = -1;
974 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800975 /*
976 * if the bitmask is the default value, then a bitmask was not
977 * specified in cfg.ini, so leave the logging level alone (it
978 * will remain at the "compiled in" default value)
979 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700980 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530981 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800982
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530983 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800984
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530985 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530986 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530987 QDF_TRACE_LEVEL_NONE, 0);
988
989 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530990 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800991 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530992 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800993 while (0 != bitmask) {
994 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530995 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530996 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530997 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530998 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800999 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001000
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001001 level++;
1002 bitmask >>= 1;
1003 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +05301004 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001005}
1006
Dustin Brownda351e32018-07-23 15:48:22 -07001007int __wlan_hdd_validate_context(struct hdd_context *hdd_ctx, const char *func)
Chris Guo1751acf2017-07-03 14:09:01 +08001008{
Dustin Brownda351e32018-07-23 15:48:22 -07001009 if (!hdd_ctx) {
1010 hdd_err("HDD context is null (via %s)", func);
1011 return -ENODEV;
1012 }
1013
1014 if (!hdd_ctx->config) {
1015 hdd_err("HDD config is null (via %s)", func);
Chris Guo1751acf2017-07-03 14:09:01 +08001016 return -ENODEV;
1017 }
1018
1019 if (cds_is_driver_recovering()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001020 hdd_debug("Recovery in progress (via %s); state:0x%x",
1021 func, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001022 return -EAGAIN;
1023 }
1024
Yue Ma9f275d92017-09-14 16:58:41 -07001025 if (cds_is_load_or_unload_in_progress()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001026 hdd_debug("Load/unload in progress (via %s); state:0x%x",
1027 func, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001028 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -07001029 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +05301030
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301031 if (cds_is_driver_in_bad_state()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001032 hdd_debug("Driver in bad state (via %s); state:0x%x",
1033 func, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +05301034 return -EAGAIN;
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301035 }
1036
Arunk Khandavalli2859fa12018-02-14 10:46:26 +05301037 if (cds_is_fw_down()) {
Dustin Brownda351e32018-07-23 15:48:22 -07001038 hdd_debug("FW is down (via %s); state:0x%x",
1039 func, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +05301040 return -EAGAIN;
Arunk Khandavalli2859fa12018-02-14 10:46:26 +05301041 }
1042
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001043 return 0;
1044}
1045
Dustin Browna8700cc2018-08-07 12:04:47 -07001046int __hdd_validate_adapter(struct hdd_adapter *adapter, const char *func)
Dustin Brownf13b8c32017-05-19 17:23:08 -07001047{
1048 if (!adapter) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001049 hdd_err("adapter is null (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001050 return -EINVAL;
1051 }
1052
1053 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001054 hdd_err("bad adapter magic (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001055 return -EINVAL;
1056 }
1057
1058 if (!adapter->dev) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001059 hdd_err("adapter net_device is null (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001060 return -EINVAL;
1061 }
1062
1063 if (!(adapter->dev->flags & IFF_UP)) {
Dustin Browna8700cc2018-08-07 12:04:47 -07001064 hdd_debug_rl("adapter '%s' is not up (via %s)",
1065 adapter->dev->name, func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001066 return -EAGAIN;
1067 }
1068
Jeff Johnson7eb6e842019-02-23 14:33:34 -08001069 return __wlan_hdd_validate_vdev_id(adapter->vdev_id, func);
Dustin Brownf13b8c32017-05-19 17:23:08 -07001070}
1071
Jeff Johnson7eb6e842019-02-23 14:33:34 -08001072int __wlan_hdd_validate_vdev_id(uint8_t vdev_id, const char *func)
Dustin Brown63500612018-08-07 11:36:09 -07001073{
Srinivas Girigowdad8697d42019-03-08 15:34:39 -08001074 if (vdev_id == WLAN_UMAC_VDEV_ID_MAX) {
Dustin Brown63500612018-08-07 11:36:09 -07001075 hdd_debug_rl("adapter is not up (via %s)", func);
1076 return -EINVAL;
1077 }
1078
Jeff Johnson7eb6e842019-02-23 14:33:34 -08001079 if (vdev_id >= WLAN_MAX_VDEVS) {
1080 hdd_err("bad vdev Id:%u (via %s)", vdev_id, func);
Dustin Brown63500612018-08-07 11:36:09 -07001081 return -EINVAL;
1082 }
1083
1084 return 0;
1085}
1086
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05301087QDF_STATUS __wlan_hdd_validate_mac_address(struct qdf_mac_addr *mac_addr,
1088 const char *func)
1089{
1090 if (!mac_addr) {
1091 hdd_err("Received NULL mac address (via %s)", func);
1092 return QDF_STATUS_E_INVAL;
1093 }
1094
1095 if (qdf_is_macaddr_zero(mac_addr)) {
1096 hdd_err("MAC is all zero (via %s)", func);
1097 return QDF_STATUS_E_INVAL;
1098 }
1099
1100 if (qdf_is_macaddr_broadcast(mac_addr)) {
1101 hdd_err("MAC is Broadcast (via %s)", func);
1102 return QDF_STATUS_E_INVAL;
1103 }
1104
1105 if (QDF_NET_IS_MAC_MULTICAST(mac_addr->bytes)) {
1106 hdd_err("MAC is Multicast (via %s)", func);
1107 return QDF_STATUS_E_INVAL;
1108 }
1109
1110 return QDF_STATUS_SUCCESS;
1111}
1112
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001113/**
Arun Khandavallica892f62017-05-26 14:25:50 +05301114 * wlan_hdd_validate_modules_state() - Check modules status
1115 * @hdd_ctx: HDD context pointer
1116 *
1117 * Check's the driver module's state and returns true if the
1118 * modules are enabled returns false if modules are closed.
1119 *
1120 * Return: True if modules are enabled or false.
1121 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001122bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +05301123{
Arun Khandavallica892f62017-05-26 14:25:50 +05301124 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
Dustin Brown5e89ef82018-03-14 11:50:23 -07001125 hdd_info("Modules not enabled, Present status: %d",
1126 hdd_ctx->driver_status);
Arun Khandavallica892f62017-05-26 14:25:50 +05301127 return false;
1128 }
Dustin Brownf688ea12019-03-19 17:02:32 -07001129
Arun Khandavallica892f62017-05-26 14:25:50 +05301130 return true;
1131}
1132
1133/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001134 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -07001135 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001136 *
1137 * This function sets the IBSS power save config parameters to WMA
1138 * which will send it to firmware if FW supports IBSS power save
1139 * before vdev start.
1140 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301141 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001142 * on failure.
1143 */
Jeff Johnson9d295242017-08-29 14:39:48 -07001144QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001145{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001146 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001147
Jeff Johnsond36fa332019-03-18 13:42:25 -07001148 if (!hdd_ctx) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001149 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301150 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001151 }
1152
Manikandan Mohan2bd09772018-11-28 18:27:32 -08001153 return ucfg_mlme_ibss_power_save_setup(hdd_ctx->psoc,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08001154 adapter->vdev_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001155}
1156
Yue Macd359b72017-10-03 15:21:00 -07001157#ifdef FEATURE_RUNTIME_PM
1158/**
1159 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
1160 * @hdd_ctx: HDD context
1161 *
1162 * Return: None
1163 */
1164static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
1165{
1166 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1167
Yue Macd359b72017-10-03 15:21:00 -07001168 qdf_runtime_lock_init(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001169 qdf_runtime_lock_init(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001170
Dustin Brown07901ec2018-09-07 11:02:41 -07001171 wlan_scan_runtime_pm_init(hdd_ctx->pdev);
Yue Macd359b72017-10-03 15:21:00 -07001172}
1173
1174/**
1175 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1176 * @hdd_ctx: HDD Context
1177 *
1178 * Return: None
1179 */
1180static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1181{
1182 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1183
Yue Macd359b72017-10-03 15:21:00 -07001184 qdf_runtime_lock_deinit(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001185 qdf_runtime_lock_deinit(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001186
Dustin Brown07901ec2018-09-07 11:02:41 -07001187 wlan_scan_runtime_pm_deinit(hdd_ctx->pdev);
Yue Macd359b72017-10-03 15:21:00 -07001188}
1189
Yue Macd359b72017-10-03 15:21:00 -07001190#else /* FEATURE_RUNTIME_PM */
1191static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1192static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Yue Macd359b72017-10-03 15:21:00 -07001193#endif /* FEATURE_RUNTIME_PM */
1194
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001195#define INTF_MACADDR_MASK 0x7
1196
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301197void hdd_update_macaddr(struct hdd_context *hdd_ctx,
1198 struct qdf_mac_addr hw_macaddr, bool generate_mac_auto)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001199{
1200 int8_t i;
1201 uint8_t macaddr_b3, tmp_br3;
1202
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301203 /*
1204 * If "generate_mac_auto" is true, it indicates that all the
1205 * addresses are derived addresses, else the first addresses
1206 * is not derived address (It is provided by fw).
1207 */
1208 if (!generate_mac_auto) {
1209 qdf_mem_copy(hdd_ctx->provisioned_mac_addr[0].bytes,
1210 hw_macaddr.bytes, QDF_MAC_ADDR_SIZE);
1211 hdd_ctx->num_provisioned_addr++;
1212 hdd_info("hdd_ctx->provisioned_mac_addr[0]: "
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07001213 QDF_MAC_ADDR_STR,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07001214 QDF_MAC_ADDR_ARRAY(hdd_ctx->
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301215 provisioned_mac_addr[0].bytes));
1216 } else {
1217 qdf_mem_copy(hdd_ctx->derived_mac_addr[0].bytes,
1218 hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301219 QDF_MAC_ADDR_SIZE);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301220 hdd_ctx->num_derived_addr++;
1221 hdd_info("hdd_ctx->derived_mac_addr[0]: "
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07001222 QDF_MAC_ADDR_STR,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07001223 QDF_MAC_ADDR_ARRAY(hdd_ctx->derived_mac_addr[0].bytes));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301224 }
1225 for (i = hdd_ctx->num_derived_addr; i < (QDF_MAX_CONCURRENCY_PERSONA -
1226 hdd_ctx->num_provisioned_addr);
1227 i++) {
1228 qdf_mem_copy(hdd_ctx->derived_mac_addr[i].bytes,
1229 hw_macaddr.bytes,
1230 QDF_MAC_ADDR_SIZE);
1231 macaddr_b3 = hdd_ctx->derived_mac_addr[i].bytes[3];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001232 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1233 INTF_MACADDR_MASK;
1234 macaddr_b3 += tmp_br3;
1235
1236 /* XOR-ing bit-24 of the mac address. This will give enough
1237 * mac address range before collision
1238 */
1239 macaddr_b3 ^= (1 << 7);
1240
1241 /* Set locally administered bit */
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301242 hdd_ctx->derived_mac_addr[i].bytes[0] |= 0x02;
1243 hdd_ctx->derived_mac_addr[i].bytes[3] = macaddr_b3;
1244 hdd_info("hdd_ctx->derived_mac_addr[%d]: "
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07001245 QDF_MAC_ADDR_STR, i,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07001246 QDF_MAC_ADDR_ARRAY(hdd_ctx->derived_mac_addr[i].bytes));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301247 hdd_ctx->num_derived_addr++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001248 }
1249}
1250
Jeff Johnson2de58792019-02-08 07:49:17 -08001251#ifdef FEATURE_WLAN_TDLS
Kabilan Kannan44a58372017-12-06 18:16:11 -08001252static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1253{
Dustin Brown1dbefe62018-09-11 16:32:03 -07001254 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001255 struct tdls_start_params tdls_cfg;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001256 QDF_STATUS status;
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301257 struct wlan_mlme_nss_chains vdev_ini_cfg;
1258
1259 /* Populate the nss chain params from ini for this vdev type */
1260 sme_populate_nss_chain_params(hdd_ctx->mac_handle, &vdev_ini_cfg,
1261 QDF_TDLS_MODE,
1262 hdd_ctx->num_rf_chains);
Kabilan Kannan44a58372017-12-06 18:16:11 -08001263
Dustin Brown1dbefe62018-09-11 16:32:03 -07001264 cfg_tdls_set_vdev_nss_2g(hdd_ctx->psoc,
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301265 vdev_ini_cfg.rx_nss[NSS_CHAINS_BAND_2GHZ]);
Dustin Brown1dbefe62018-09-11 16:32:03 -07001266 cfg_tdls_set_vdev_nss_5g(hdd_ctx->psoc,
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301267 vdev_ini_cfg.rx_nss[NSS_CHAINS_BAND_5GHZ]);
jiad7b8a5e02018-11-26 16:37:57 +08001268 hdd_init_tdls_config(&tdls_cfg);
Kabilan Kannan44a58372017-12-06 18:16:11 -08001269 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1270 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1271 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1272 tdls_cfg.tdls_evt_cb_data = psoc;
Jeff Johnson1d40f5b2018-03-02 08:35:53 -08001273 tdls_cfg.tdls_peer_context = hdd_ctx;
1274 tdls_cfg.tdls_reg_peer = hdd_tdls_register_peer;
1275 tdls_cfg.tdls_dereg_peer = hdd_tdls_deregister_peer;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001276 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1277 tdls_cfg.tdls_wmm_cb_data = psoc;
1278 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1279 tdls_cfg.tdls_rx_cb_data = psoc;
1280 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
Arun Kumar Khandavalli43fdd252019-04-24 18:34:18 +05301281 tdls_cfg.tdls_osif_init_cb = wlan_cfg80211_tdls_osif_priv_init;
1282 tdls_cfg.tdls_osif_deinit_cb = wlan_cfg80211_tdls_osif_priv_deinit;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001283
1284 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1285 if (status != QDF_STATUS_SUCCESS) {
1286 hdd_err("failed pmo psoc configuration");
1287 return -EINVAL;
1288 }
1289
1290 hdd_ctx->tdls_umac_comp_active = true;
1291 /* enable napier specific tdls data path */
1292 hdd_ctx->tdls_nap_active = true;
1293
1294 return 0;
1295}
Jeff Johnson74c6bb22019-02-15 10:15:07 -08001296#else
1297static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1298{
1299 return 0;
1300}
1301#endif
Kabilan Kannan44a58372017-12-06 18:16:11 -08001302
Wu Gaoca416ff2018-09-17 11:05:07 +08001303#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1304static void hdd_update_roam_offload(struct hdd_context *hdd_ctx,
1305 struct wma_tgt_services *cfg)
1306{
1307 bool roam_offload_enable;
1308
Dustin Brown1dbefe62018-09-11 16:32:03 -07001309 ucfg_mlme_get_roaming_offload(hdd_ctx->psoc, &roam_offload_enable);
1310 ucfg_mlme_set_roaming_offload(hdd_ctx->psoc,
Wu Gaoca416ff2018-09-17 11:05:07 +08001311 roam_offload_enable &
1312 cfg->en_roam_offload);
1313}
1314#else
1315static inline void hdd_update_roam_offload(struct hdd_context *hdd_ctx,
1316 struct wma_tgt_services *cfg)
1317{
1318}
1319#endif
1320
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001321static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001322 struct wma_tgt_services *cfg)
1323{
1324 struct hdd_config *config = hdd_ctx->config;
Wu Gao66454f12018-09-26 19:55:41 +08001325 bool arp_offload_enable;
Wu Gao1ab05582018-11-08 16:22:49 +08001326 bool mawc_enabled;
Wu Gaobdb7f272018-07-05 19:33:26 +08001327#ifdef FEATURE_WLAN_TDLS
1328 bool tdls_support;
1329 bool tdls_off_channel;
1330 bool tdls_buffer_sta;
1331 uint32_t tdls_uapsd_mask;
1332#endif
Will Huangb9cb1242019-04-02 14:52:17 +08001333 bool get_peer_info_enable;
jiad7b8a5e02018-11-26 16:37:57 +08001334
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001335 /* Set up UAPSD */
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05301336 ucfg_mlme_set_sap_uapsd_flag(hdd_ctx->psoc, cfg->uapsd);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001337
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001338 /* 11AX mode support */
1339 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1340 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1341 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1342
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001343 /* 11AC mode support */
1344 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1345 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1346 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001347
1348 /* ARP offload: override user setting if invalid */
Wu Gao66454f12018-09-26 19:55:41 +08001349 arp_offload_enable =
1350 ucfg_pmo_is_arp_offload_enabled(hdd_ctx->psoc);
1351 ucfg_pmo_set_arp_offload_enabled(hdd_ctx->psoc,
1352 arp_offload_enable & cfg->arp_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001353#ifdef FEATURE_WLAN_SCAN_PNO
1354 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001355 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001356 if (cfg->pno_offload)
Pragaspathi Thilagaraj24789d32018-12-10 22:28:03 +05301357 ucfg_scan_set_pno_offload(hdd_ctx->psoc, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001358#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001359#ifdef FEATURE_WLAN_TDLS
Dustin Brown1dbefe62018-09-11 16:32:03 -07001360 cfg_tdls_get_support_enable(hdd_ctx->psoc, &tdls_support);
1361 cfg_tdls_set_support_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001362 tdls_support & cfg->en_tdls);
1363
Dustin Brown1dbefe62018-09-11 16:32:03 -07001364 cfg_tdls_get_off_channel_enable(hdd_ctx->psoc, &tdls_off_channel);
1365 cfg_tdls_set_off_channel_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001366 tdls_off_channel &&
1367 cfg->en_tdls_offchan);
1368
Dustin Brown1dbefe62018-09-11 16:32:03 -07001369 cfg_tdls_get_buffer_sta_enable(hdd_ctx->psoc, &tdls_buffer_sta);
1370 cfg_tdls_set_buffer_sta_enable(hdd_ctx->psoc,
Wu Gaobdb7f272018-07-05 19:33:26 +08001371 tdls_buffer_sta &&
1372 cfg->en_tdls_uapsd_buf_sta);
1373
Dustin Brown1dbefe62018-09-11 16:32:03 -07001374 cfg_tdls_get_uapsd_mask(hdd_ctx->psoc, &tdls_uapsd_mask);
Wu Gaobdb7f272018-07-05 19:33:26 +08001375 if (tdls_uapsd_mask && cfg->en_tdls_uapsd_sleep_sta)
Dustin Brown1dbefe62018-09-11 16:32:03 -07001376 cfg_tdls_set_sleep_sta_enable(hdd_ctx->psoc, true);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001377 else
Dustin Brown1dbefe62018-09-11 16:32:03 -07001378 cfg_tdls_set_sleep_sta_enable(hdd_ctx->psoc, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001379#endif
Wu Gaoca416ff2018-09-17 11:05:07 +08001380 hdd_update_roam_offload(hdd_ctx, cfg);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05301381
Will Huangb9cb1242019-04-02 14:52:17 +08001382 if (ucfg_mlme_get_sap_get_peer_info(
1383 hdd_ctx->psoc, &get_peer_info_enable) == QDF_STATUS_SUCCESS) {
1384 get_peer_info_enable &= cfg->get_peer_info_enabled;
1385 ucfg_mlme_set_sap_get_peer_info(hdd_ctx->psoc,
1386 get_peer_info_enable);
1387 }
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05301388
Wu Gao1ab05582018-11-08 16:22:49 +08001389 ucfg_mlme_is_mawc_enabled(hdd_ctx->psoc, &mawc_enabled);
1390 ucfg_mlme_set_mawc_enabled(hdd_ctx->psoc,
1391 mawc_enabled & cfg->is_fw_mawc_capable);
Kabilan Kannan44a58372017-12-06 18:16:11 -08001392 hdd_update_tdls_config(hdd_ctx);
Jeff Johnson16528362018-06-14 12:34:16 -07001393 sme_update_tgt_services(hdd_ctx->mac_handle, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001394}
1395
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001396/**
1397 * hdd_update_vdev_nss() - sets the vdev nss
1398 * @hdd_ctx: HDD context
1399 *
1400 * Sets the Nss per vdev type based on INI
1401 *
1402 * Return: None
1403 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001404static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001405{
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001406 uint8_t max_supp_nss = 1;
Jeff Johnson16528362018-06-14 12:34:16 -07001407 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301408 QDF_STATUS status;
1409 bool bval;
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001410
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301411 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
1412 if (!QDF_IS_STATUS_SUCCESS(status))
1413 hdd_err("unable to get vht_enable2x2");
1414
1415 if (bval && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001416 max_supp_nss = 2;
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301417
1418 hdd_debug("max nss %d", max_supp_nss);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001419
Jeff Johnson16528362018-06-14 12:34:16 -07001420 mac_handle = hdd_ctx->mac_handle;
1421 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301422 NSS_CHAINS_BAND_2GHZ);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001423
Jeff Johnson16528362018-06-14 12:34:16 -07001424 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
gaurank kathpalia651abcd2018-11-12 22:41:23 +05301425 NSS_CHAINS_BAND_5GHZ);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001426}
1427
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301428/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301429 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1430 * @hdd_ctx: HDD context
1431 *
1432 * Updates wiphy vhtcap fields
1433 *
1434 * Return: None
1435 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001436static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301437{
1438 struct ieee80211_supported_band *band_5g =
1439 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301440 QDF_STATUS status;
1441 uint8_t value = 0, value1 = 0;
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301442
1443 if (!band_5g) {
1444 hdd_debug("5GHz band disabled, skipping capability population");
1445 return;
1446 }
1447
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301448 status = ucfg_mlme_cfg_get_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
1449 &value);
1450 if (!QDF_IS_STATUS_SUCCESS(status))
1451 hdd_err("unable to get tx_bfee_ant_supp");
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301452
Abhinav Kumare057b412018-10-09 17:28:16 +05301453 band_5g->vht_cap.cap |=
1454 (value << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301455
1456 value1 = NUM_OF_SOUNDING_DIMENSIONS;
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301457 band_5g->vht_cap.cap |=
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301458 (value1 << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301459
Dustin Brown7e761c72018-07-31 13:50:17 -07001460 hdd_debug("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301461 band_5g->vht_cap.cap, value, value1);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301462}
1463
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001464static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001465 struct wma_tgt_ht_cap *cfg)
1466{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301467 QDF_STATUS status;
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301468 qdf_size_t value_len;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301469 uint32_t value;
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05301470 uint8_t mpdu_density;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301471 struct mlme_ht_capabilities_info ht_cap_info;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001472 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301473 bool b_enable1x1;
Jeff Johnson16528362018-06-14 12:34:16 -07001474
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001475 /* get the MPDU density */
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05301476 status = ucfg_mlme_get_ht_mpdu_density(hdd_ctx->psoc, &mpdu_density);
1477 if (QDF_IS_STATUS_ERROR(status)) {
1478 hdd_err("could not get HT MPDU Density");
1479 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001480 }
1481
1482 /*
1483 * MPDU density:
1484 * override user's setting if value is larger
1485 * than the one supported by target
1486 */
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05301487 if (mpdu_density > cfg->mpdu_density) {
1488 status = ucfg_mlme_set_ht_mpdu_density(hdd_ctx->psoc,
1489 cfg->mpdu_density);
1490 if (QDF_IS_STATUS_ERROR(status))
1491 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001492 }
1493
1494 /* get the HT capability info */
Dustin Brown1dbefe62018-09-11 16:32:03 -07001495 status = ucfg_mlme_get_ht_cap_info(hdd_ctx->psoc, &ht_cap_info);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301496 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001497 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001498 return;
1499 }
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301500
1501 /* check and update RX STBC */
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301502 if (ht_cap_info.rx_stbc && !cfg->ht_rx_stbc)
1503 ht_cap_info.rx_stbc = cfg->ht_rx_stbc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001504
1505 /* Set the LDPC capability */
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301506 ht_cap_info.adv_coding_cap = cfg->ht_rx_ldpc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001507
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301508 if (ht_cap_info.short_gi_20_mhz && !cfg->ht_sgi_20)
1509 ht_cap_info.short_gi_20_mhz = cfg->ht_sgi_20;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001510
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301511 if (ht_cap_info.short_gi_40_mhz && !cfg->ht_sgi_40)
1512 ht_cap_info.short_gi_40_mhz = cfg->ht_sgi_40;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001513
1514 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1515 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1516
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301517 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &b_enable1x1);
1518 if (!QDF_IS_STATUS_SUCCESS(status))
1519 hdd_err("unable to get vht_enable2x2");
1520
1521 b_enable1x1 = b_enable1x1 && (cfg->num_rf_chains == 2);
1522
1523 status = ucfg_mlme_set_vht_enable2x2(hdd_ctx->psoc, b_enable1x1);
1524 if (!QDF_IS_STATUS_SUCCESS(status))
1525 hdd_err("unable to set vht_enable2x2");
1526
Abhinav Kumare057b412018-10-09 17:28:16 +05301527 if (!b_enable1x1) {
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301528 ht_cap_info.tx_stbc = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001529
1530 /* 1x1 */
1531 /* Update Rx Highest Long GI data Rate */
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301532 status = ucfg_mlme_cfg_set_vht_rx_supp_data_rate(
1533 hdd_ctx->psoc,
1534 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1);
1535 if (!QDF_IS_STATUS_SUCCESS(status))
1536 hdd_err("Failed to set rx_supp_data_rate");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001537 /* Update Tx Highest Long GI data Rate */
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301538 status = ucfg_mlme_cfg_set_vht_tx_supp_data_rate(
1539 hdd_ctx->psoc,
1540 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1);
1541 if (!QDF_IS_STATUS_SUCCESS(status))
1542 hdd_err("Failed to set tx_supp_data_rate");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001543 }
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301544 if (!(cfg->ht_tx_stbc && b_enable1x1))
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301545 ht_cap_info.tx_stbc = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001546
Dustin Brown1dbefe62018-09-11 16:32:03 -07001547 status = ucfg_mlme_set_ht_cap_info(hdd_ctx->psoc, ht_cap_info);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301548 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001549 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001550#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301551 value_len = SIZE_OF_SUPPORTED_MCS_SET;
1552 if (ucfg_mlme_get_supported_mcs_set(
1553 hdd_ctx->psoc, mcs_set,
1554 &value_len) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001555 hdd_debug("Read MCS rate set");
gaurank kathpalia18b49362018-04-15 23:12:03 +05301556 if (cfg->num_rf_chains > SIZE_OF_SUPPORTED_MCS_SET)
1557 cfg->num_rf_chains = SIZE_OF_SUPPORTED_MCS_SET;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301558
1559 if (b_enable1x1) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001560 for (value = 0; value < cfg->num_rf_chains; value++)
1561 mcs_set[value] =
1562 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1563
Karthik Kantamnenie3bbd7f2018-09-19 20:27:32 +05301564 status = ucfg_mlme_set_supported_mcs_set(
1565 hdd_ctx->psoc,
1566 mcs_set,
1567 (qdf_size_t)SIZE_OF_SUPPORTED_MCS_SET);
1568 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001569 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001570 }
1571 }
1572#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1573}
1574
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001575static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001576 struct wma_tgt_vht_cap *cfg)
1577{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301578 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001579 struct wiphy *wiphy = hdd_ctx->wiphy;
1580 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001581 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001582 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001583 struct wma_caps_per_phy caps_per_phy;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301584 uint8_t val = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001585
Dustin Brown5e06bd32016-10-04 12:49:10 -07001586 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001587 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001588 return;
1589 }
1590
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301591 status = ucfg_mlme_update_vht_cap(hdd_ctx->psoc, cfg);
1592 if (QDF_IS_STATUS_ERROR(status))
1593 hdd_err("could not update vht capabilities");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001594
1595 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1596 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1597 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1598 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1599 else
1600 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1601
1602
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001603 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
Abhinav Kumare057b412018-10-09 17:28:16 +05301604 status = ucfg_mlme_set_vht_ch_width(hdd_ctx->psoc,
1605 VHT_CAP_160_AND_80P80_SUPP);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301606 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001607 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001608 band_5g->vht_cap.cap |=
1609 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001610 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1611 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
Abhinav Kumare057b412018-10-09 17:28:16 +05301612 status = ucfg_mlme_set_vht_ch_width(hdd_ctx->psoc,
1613 VHT_CAP_160_SUPP);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301614 if (QDF_IS_STATUS_ERROR(status))
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001615 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001616 band_5g->vht_cap.cap |=
1617 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001618 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1619 }
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001620
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301621 status =
1622 ucfg_mlme_cfg_get_vht_chan_width(hdd_ctx->psoc, &val);
1623 if (QDF_IS_STATUS_ERROR(status))
1624 hdd_err("could not get channel_width");
1625
1626 val = QDF_MIN(val, ch_width);
Abhinav Kumare057b412018-10-09 17:28:16 +05301627 status = ucfg_mlme_set_vht_ch_width(hdd_ctx->psoc, val);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301628 if (QDF_IS_STATUS_ERROR(status))
1629 hdd_err("could not set the channel width");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001630
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001631 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001632 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001633 hdd_debug("VHT RxLDPC capability is set");
1634 } else {
1635 /*
1636 * Get the RX LDPC capability for the NON DBS
1637 * hardware mode for 5G band
1638 */
1639 status = wma_get_caps_for_phyidx_hwmode(&caps_per_phy,
1640 HW_MODE_DBS_NONE, CDS_BAND_5GHZ);
1641 if ((QDF_IS_STATUS_SUCCESS(status)) &&
1642 (caps_per_phy.vht_5g & WMI_VHT_CAP_RX_LDPC)) {
1643 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1644 hdd_debug("VHT RX LDPC capability is set");
1645 }
1646 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001647
1648 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1649 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1650 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1651 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1652
1653 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1654 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1655
1656 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1657 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1658 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1659 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1660 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1661 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1662
1663 band_5g->vht_cap.cap |=
1664 (cfg->vht_max_ampdu_len_exp <<
1665 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1666
1667 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1668 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1669 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1670 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1671 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1672 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1673 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1674 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1675
1676 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1677 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1678
1679}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001680
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001681/**
1682 * hdd_generate_macaddr_auto() - Auto-generate mac address
1683 * @hdd_ctx: Pointer to the HDD context
1684 *
1685 * Auto-generate mac address using device serial number.
1686 * Keep the first 3 bytes of OUI as before and replace
1687 * the last 3 bytes with the lower 3 bytes of serial number.
1688 *
1689 * Return: 0 for success
1690 * Non zero failure code for errors
1691 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001692static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001693{
1694 unsigned int serialno = 0;
1695 struct qdf_mac_addr mac_addr = {
1696 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1697 };
1698
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001699 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001700 if (serialno == 0)
1701 return -EINVAL;
1702
1703 serialno &= 0x00ffffff;
1704
1705 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1706 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1707 mac_addr.bytes[5] = serialno & 0xff;
1708
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301709 hdd_update_macaddr(hdd_ctx, mac_addr, true);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001710 return 0;
1711}
1712
Jeff Johnsonf9176382018-07-17 19:15:58 -07001713static void hdd_sar_target_config(struct hdd_context *hdd_ctx,
1714 struct wma_tgt_cfg *cfg)
1715{
1716 hdd_ctx->sar_version = cfg->sar_version;
1717}
1718
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001719static void hdd_update_vhtcap_2g(struct hdd_context *hdd_ctx)
1720{
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001721 uint32_t chip_mode = 0;
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001722 QDF_STATUS status;
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001723 bool b2g_vht_cfg = false;
1724 bool b2g_vht_target = false;
1725 struct wma_caps_per_phy caps_per_phy;
1726 struct wmi_unified *wmi_handle;
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001727
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001728 wmi_handle = get_wmi_unified_hdl_from_psoc(hdd_ctx->psoc);
1729 if (!wmi_handle) {
1730 hdd_err("wmi handle is NULL");
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001731 return;
1732 }
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001733
1734 status = ucfg_mlme_get_vht_for_24ghz(hdd_ctx->psoc, &b2g_vht_cfg);
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001735 if (QDF_IS_STATUS_ERROR(status)) {
1736 hdd_err("Failed to get 2g vht mode");
1737 return;
1738 }
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001739 if (wmi_service_enabled(wmi_handle, wmi_service_ext_msg)) {
1740 status = wma_get_caps_for_phyidx_hwmode(&caps_per_phy,
1741 HW_MODE_DBS_NONE,
1742 CDS_BAND_ALL);
1743 if (QDF_IS_STATUS_ERROR(status)) {
1744 hdd_err("Failed to get phy caps");
1745 return;
1746 }
1747 if (caps_per_phy.vht_2g)
1748 b2g_vht_target = true;
1749 } else {
1750 status = wlan_reg_get_chip_mode(hdd_ctx->pdev, &chip_mode);
1751 if (QDF_IS_STATUS_ERROR(status)) {
1752 hdd_err("Failed to get chip mode");
1753 return;
1754 }
1755 b2g_vht_target =
1756 (chip_mode & WMI_HOST_REGDMN_MODE_11AC_VHT20_2G) ?
1757 true : false;
1758 }
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001759
Jianmin Zhu2f9e7532019-01-21 15:39:50 +08001760 b2g_vht_cfg = b2g_vht_cfg && b2g_vht_target;
1761 hdd_debug("vht 2g target: %d, cfg: %d", b2g_vht_target, b2g_vht_cfg);
1762 status = ucfg_mlme_set_vht_for_24ghz(hdd_ctx->psoc, b2g_vht_cfg);
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001763 if (QDF_IS_STATUS_ERROR(status)) {
1764 hdd_err("Failed to update 2g vht mode");
1765 return;
1766 }
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08001767}
1768
Arun Kumar Khandavallia4234582019-03-20 16:16:05 +05301769int hdd_update_tgt_cfg(hdd_handle_t hdd_handle, struct wma_tgt_cfg *cfg)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001770{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001771 int ret;
Jeff Johnsonea70b942018-07-02 09:42:31 -07001772 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301773 uint8_t temp_band_cap, band_capability;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001774 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301775 uint8_t antenna_mode;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301776 uint8_t sub_20_chan_width;
Arif Hussainee10f902017-12-27 16:30:17 -08001777 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -07001778 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301779 bool bval = false;
1780 uint8_t value = 0;
Arif Hussainbd5194c2018-11-27 19:01:15 -08001781 uint32_t fine_time_meas_cap = 0;
gaurank kathpaliafa7ad0a2019-03-12 19:17:56 +05301782 enum nss_chains_band_info band;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301783
gaurank kathpalia843f7c32018-07-02 18:04:14 +05301784 if (!hdd_ctx) {
1785 hdd_err("HDD context is NULL");
Arun Kumar Khandavallia4234582019-03-20 16:16:05 +05301786 return -EINVAL;
gaurank kathpalia843f7c32018-07-02 18:04:14 +05301787 }
Dustin Brownbd68fe12017-11-21 15:28:52 -08001788 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1789 if (ret) {
Dustin Brown64204d22018-08-15 16:35:19 -07001790 QDF_DEBUG_PANIC("Failed to create pdev; errno:%d", ret);
Arun Kumar Khandavallia4234582019-03-20 16:16:05 +05301791 return -EINVAL;
Dustin Brown64204d22018-08-15 16:35:19 -07001792 }
1793
1794 hdd_debug("New pdev has been created with pdev_id = %u",
Dustin Brown07901ec2018-09-07 11:02:41 -07001795 hdd_ctx->pdev->pdev_objmgr.wlan_pdev_id);
Dustin Brown64204d22018-08-15 16:35:19 -07001796
Dustin Brown07901ec2018-09-07 11:02:41 -07001797 status = dispatcher_pdev_open(hdd_ctx->pdev);
Dustin Brown64204d22018-08-15 16:35:19 -07001798 if (QDF_IS_STATUS_ERROR(status)) {
1799 QDF_DEBUG_PANIC("dispatcher pdev open failed; status:%d",
1800 status);
Arun Kumar Khandavallia4234582019-03-20 16:16:05 +05301801 ret = qdf_status_to_os_return(status);
1802 goto exit;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301803 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001804
Sandeep Puligillab7beb472018-08-13 22:54:20 -07001805 status = hdd_component_pdev_open(hdd_ctx->pdev);
1806 if (QDF_IS_STATUS_ERROR(status)) {
1807 QDF_DEBUG_PANIC("hdd component pdev open failed; status:%d",
1808 status);
Arun Kumar Khandavallia4234582019-03-20 16:16:05 +05301809 ret = qdf_status_to_os_return(status);
1810 goto dispatcher_close;
Sandeep Puligillab7beb472018-08-13 22:54:20 -07001811 }
Arun Kumar Khandavallia4234582019-03-20 16:16:05 +05301812
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301813 cdp_pdev_set_ctrl_pdev(cds_get_context(QDF_MODULE_ID_SOC),
1814 cds_get_context(QDF_MODULE_ID_TXRX),
Dustin Brown07901ec2018-09-07 11:02:41 -07001815 (struct cdp_ctrl_objmgr_pdev *)hdd_ctx->pdev);
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301816
Dustin Brown07901ec2018-09-07 11:02:41 -07001817 wlan_pdev_set_dp_handle(hdd_ctx->pdev,
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301818 cds_get_context(QDF_MODULE_ID_TXRX));
1819
Will Huang07244172018-05-14 14:23:30 +08001820 hdd_objmgr_update_tgt_max_vdev_psoc(hdd_ctx, cfg->max_intf_count);
1821
Dustin Brown1dbefe62018-09-11 16:32:03 -07001822 ucfg_ipa_set_dp_handle(hdd_ctx->psoc,
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301823 cds_get_context(QDF_MODULE_ID_SOC));
Dustin Brown1dbefe62018-09-11 16:32:03 -07001824 ucfg_ipa_set_txrx_handle(hdd_ctx->psoc,
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301825 cds_get_context(QDF_MODULE_ID_TXRX));
Dustin Brown07901ec2018-09-07 11:02:41 -07001826 ucfg_ipa_reg_sap_xmit_cb(hdd_ctx->pdev,
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301827 hdd_softap_hard_start_xmit);
Dustin Brown07901ec2018-09-07 11:02:41 -07001828 ucfg_ipa_reg_send_to_nw_cb(hdd_ctx->pdev,
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301829 hdd_ipa_send_skb_to_network);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301830
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301831 status = ucfg_mlme_get_sub_20_chan_width(hdd_ctx->psoc,
1832 &sub_20_chan_width);
1833 if (QDF_IS_STATUS_ERROR(status)) {
1834 hdd_err("Failed to get sub_20_chan_width config");
Arun Kumar Khandavallia4234582019-03-20 16:16:05 +05301835 ret = qdf_status_to_os_return(status);
1836 goto pdev_close;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301837 }
1838
Naveen Rawat64e477e2016-05-20 10:34:56 -07001839 if (cds_cfg) {
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301840 if (sub_20_chan_width !=
1841 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
Naveen Rawat64e477e2016-05-20 10:34:56 -07001842 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1843 cds_cfg->sub_20_channel_width =
1844 WLAN_SUB_20_CH_WIDTH_NONE;
1845 } else {
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05301846 cds_cfg->sub_20_channel_width = sub_20_chan_width;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001847 }
1848 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001849
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301850 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
1851 if (QDF_IS_STATUS_ERROR(status)) {
1852 hdd_err("Failed to get MLME band capability");
Arun Kumar Khandavallia4234582019-03-20 16:16:05 +05301853 ret = qdf_status_to_os_return(status);
1854 goto pdev_close;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301855 }
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");
Arun Kumar Khandavallia4234582019-03-20 16:16:05 +05301883 ret = qdf_status_to_os_return(status);
1884 goto pdev_close;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05301885 }
1886
1887 hdd_ctx->curr_band = band_capability;
Amar Singhal58b45ef2017-08-01 13:43:54 -07001888
Qun Zhang043635a2019-02-27 15:19:29 +08001889 status = wlan_hdd_update_wiphy_supported_band(hdd_ctx);
1890 if (QDF_IS_STATUS_ERROR(status)) {
1891 hdd_err("Failed to update wiphy band info");
Arun Kumar Khandavallia4234582019-03-20 16:16:05 +05301892 goto pdev_close;
Qun Zhang043635a2019-02-27 15:19:29 +08001893 }
1894
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301895 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001896 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1897 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1898 }
1899
1900 /* This can be extended to other configurations like ht, vht cap... */
1901
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05301902 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr))
1903 qdf_mem_copy(&hdd_ctx->hw_macaddr, &cfg->hw_macaddr,
1904 QDF_MAC_ADDR_SIZE);
1905 else
1906 hdd_info("hw_mac is zero");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001907
1908 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001909 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001910
Ryan Hsuc6918552018-05-16 13:29:59 -07001911 hdd_ctx->hw_bd_id = cfg->hw_bd_id;
1912 qdf_mem_copy(&hdd_ctx->hw_bd_info, &cfg->hw_bd_info,
1913 sizeof(cfg->hw_bd_info));
1914
Dustin Brownad06be62019-02-04 14:52:56 -08001915 if (cfg->max_intf_count > WLAN_MAX_VDEVS) {
Dustin Brownbee82832018-07-23 10:10:51 -07001916 hdd_err("fw max vdevs (%u) > host max vdevs (%u); using %u",
Dustin Brownad06be62019-02-04 14:52:56 -08001917 cfg->max_intf_count, WLAN_MAX_VDEVS, WLAN_MAX_VDEVS);
1918 hdd_ctx->max_intf_count = WLAN_MAX_VDEVS;
Dustin Brownbee82832018-07-23 10:10:51 -07001919 } else {
1920 hdd_ctx->max_intf_count = cfg->max_intf_count;
1921 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001922
Jeff Johnsonf9176382018-07-17 19:15:58 -07001923 hdd_sar_target_config(hdd_ctx, cfg);
Jeff Johnsonc875e242016-09-23 18:12:34 -07001924 hdd_lpass_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001925
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001926 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
Pragaspathi Thilagarajeb367282019-02-19 00:42:28 +05301927 status = ucfg_mlme_set_fw_supported_roaming_akm(
1928 hdd_ctx->psoc,
1929 cfg->ft_akm_service_bitmap);
1930 if (QDF_IS_STATUS_ERROR(status))
1931 hdd_err("Failed to set ft akm suites bitmap");
1932
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001933 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1934
1935 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1936
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001937 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001938 if (cfg->services.en_11ax) {
1939 hdd_info("11AX: 11ax is enabled - update HDD config");
1940 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1941 }
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -07001942 hdd_update_tgt_twt_cap(hdd_ctx, cfg);
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001943
gaurank kathpaliafa7ad0a2019-03-12 19:17:56 +05301944 for (band = NSS_CHAINS_BAND_2GHZ; band < NSS_CHAINS_BAND_MAX; band++) {
1945 sme_modify_nss_chains_tgt_cfg(hdd_ctx->mac_handle,
1946 QDF_STA_MODE, band);
1947 sme_modify_nss_chains_tgt_cfg(hdd_ctx->mac_handle,
1948 QDF_SAP_MODE, band);
1949 sme_modify_nss_chains_tgt_cfg(hdd_ctx->mac_handle,
1950 QDF_TDLS_MODE, band);
1951 sme_modify_nss_chains_tgt_cfg(hdd_ctx->mac_handle,
1952 QDF_P2P_DEVICE_MODE,
1953 band);
1954 sme_modify_nss_chains_tgt_cfg(hdd_ctx->mac_handle,
1955 QDF_OCB_MODE, band);
1956 sme_modify_nss_chains_tgt_cfg(hdd_ctx->mac_handle,
1957 QDF_TDLS_MODE, band);
1958 }
1959
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001960 hdd_update_vdev_nss(hdd_ctx);
1961
gaurank kathpalia5fcefa92018-10-24 15:03:15 +05301962 hdd_ctx->dynamic_nss_chains_support =
1963 cfg->dynamic_nss_chains_support;
Arif Hussainbd5194c2018-11-27 19:01:15 -08001964 ucfg_mlme_get_fine_time_meas_cap(hdd_ctx->psoc, &fine_time_meas_cap);
1965 fine_time_meas_cap &= cfg->fine_time_measurement_cap;
1966 status = ucfg_mlme_set_fine_time_meas_cap(hdd_ctx->psoc,
1967 fine_time_meas_cap);
1968 if (QDF_IS_STATUS_ERROR(status)) {
1969 hdd_err("failed to set fine_time_meas_cap, 0x%x, ox%x",
1970 fine_time_meas_cap, cfg->fine_time_measurement_cap);
1971 ucfg_mlme_get_fine_time_meas_cap(hdd_ctx->psoc,
1972 &fine_time_meas_cap);
1973 }
1974
Krunal Sonie3531942016-04-12 17:43:53 -07001975 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Arif Hussainbd5194c2018-11-27 19:01:15 -08001976 hdd_debug("fine_time_meas_cap: 0x%x", fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001977
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301978 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
1979 if (!QDF_IS_STATUS_SUCCESS(status))
1980 hdd_err("unable to get vht_enable2x2");
1981
1982 antenna_mode = (bval == 0x01) ?
Nitesh Shahe50711f2017-04-26 16:30:45 +05301983 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1984 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001985 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08001986 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001987
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05301988 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301989
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301990 status = ucfg_mlme_cfg_get_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
Abhinav Kumare057b412018-10-09 17:28:16 +05301991 &value);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301992 if (QDF_IS_STATUS_ERROR(status)) {
1993 status = false;
1994 hdd_err("set tx_bfee_ant_supp failed");
1995 }
1996
1997 if ((value >
Arif Hussainee10f902017-12-27 16:30:17 -08001998 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05301999 !cfg->tx_bfee_8ss_enabled) {
2000 status =
2001 ucfg_mlme_cfg_set_vht_tx_bfee_ant_supp(hdd_ctx->psoc,
2002 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF);
2003 if (QDF_IS_STATUS_ERROR(status)) {
2004 status = false;
2005 hdd_err("set tx_bfee_ant_supp failed");
2006 }
2007 }
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302008
Jeff Johnson16528362018-06-14 12:34:16 -07002009 mac_handle = hdd_ctx->mac_handle;
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302010
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05302011 hdd_debug("txBFCsnValue %d", value);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05302012
2013 /*
2014 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
2015 */
2016 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05302017
Jianmin Zhuc8bfffb2019-01-15 12:40:03 +08002018 hdd_update_vhtcap_2g(hdd_ctx);
2019
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05302020 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
2021
Ashish Kumar Dhanotiya908925d2019-03-01 17:35:30 +05302022 wlan_config_sched_scan_plans_to_wiphy(hdd_ctx->wiphy, hdd_ctx->psoc);
Yue Macd359b72017-10-03 15:21:00 -07002023 /*
2024 * This needs to be done after HDD pdev is created and stored since
2025 * it will access the HDD pdev object lock.
2026 */
2027 hdd_runtime_suspend_context_init(hdd_ctx);
2028
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07002029 /* Configure NAN datapath features */
2030 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Nachiket Kukade85aa3782018-11-02 20:12:34 +05302031 ucfg_nan_set_tgt_caps(hdd_ctx->psoc, &cfg->nan_caps);
Arif Hussain759a0232017-03-20 13:17:18 -07002032 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08002033 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Liangwei Dong0da14262018-07-03 03:30:23 -04002034 hdd_ctx->obss_scan_offload = cfg->services.obss_scan_offload;
Wu Gao5f764082019-01-04 15:54:38 +08002035 status = ucfg_mlme_set_obss_detection_offload_enabled(
2036 hdd_ctx->psoc, cfg->obss_detection_offloaded);
Arif Hussainee10f902017-12-27 16:30:17 -08002037 if (QDF_IS_STATUS_ERROR(status))
2038 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Arif Hussain05fb4872018-01-03 16:02:55 -08002039
Wu Gao5f764082019-01-04 15:54:38 +08002040 status = ucfg_mlme_set_obss_color_collision_offload_enabled(
2041 hdd_ctx->psoc, cfg->obss_color_collision_offloaded);
Arif Hussain05fb4872018-01-03 16:02:55 -08002042 if (QDF_IS_STATUS_ERROR(status))
2043 hdd_err("Failed to set WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD");
Arif Hussain50689082019-03-26 12:07:58 -07002044
2045 ucfg_mlme_get_bcast_twt(hdd_ctx->psoc, &bval);
2046 if (bval)
2047 ucfg_mlme_set_bcast_twt(hdd_ctx->psoc, cfg->bcast_twt_support);
2048 else
2049 hdd_debug("bcast twt is disable in ini, fw cap %d",
2050 cfg->bcast_twt_support);
Arun Kumar Khandavallia4234582019-03-20 16:16:05 +05302051 return 0;
2052
2053dispatcher_close:
2054 dispatcher_pdev_close(hdd_ctx->pdev);
2055pdev_close:
2056 hdd_component_pdev_close(hdd_ctx->pdev);
2057exit:
2058 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
2059
2060 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002061}
2062
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002063bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002064{
Jeff Johnson9d295242017-08-29 14:39:48 -07002065 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002066 struct hdd_ap_ctx *ap_ctx;
Arif Hussain224d3812018-11-16 17:58:38 -08002067 bool dfs_disable_channel_switch = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002068
Jiachao Wuf610d912018-01-23 17:47:32 +08002069 if (!hdd_ctx) {
2070 hdd_info("Couldn't get hdd_ctx");
2071 return true;
2072 }
2073
Arif Hussain224d3812018-11-16 17:58:38 -08002074 ucfg_mlme_get_dfs_disable_channel_switch(hdd_ctx->psoc,
2075 &dfs_disable_channel_switch);
2076 if (dfs_disable_channel_switch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002077 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussain224d3812018-11-16 17:58:38 -08002078 hdd_ctx, dfs_disable_channel_switch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302079 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002080 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002081
Dustin Brown920397d2017-12-13 16:27:50 -08002082 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002083 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2084
2085 if ((QDF_SAP_MODE == adapter->device_mode ||
2086 QDF_P2P_GO_MODE == adapter->device_mode) &&
Dustin Brown07901ec2018-09-07 11:02:41 -07002087 (wlan_reg_is_passive_or_disable_ch(hdd_ctx->pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002088 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002089 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2090 true;
Jeff Johnson7eb6e842019-02-23 14:33:34 -08002091 hdd_info("tx blocked for vdev: %d",
Jeff Johnson5a6fc962019-02-04 14:20:25 -08002092 adapter->vdev_id);
bings6fb9bf62018-07-05 14:01:53 +08002093 if (adapter->txrx_vdev)
2094 cdp_fc_vdev_flush(
2095 cds_get_context(QDF_MODULE_ID_SOC),
bings0e03a982018-05-09 08:40:59 +08002096 adapter->txrx_vdev);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302097 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002098 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302099
2100 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002101}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002102
Jeff Johnson030cd902018-11-11 10:19:40 -08002103bool hdd_is_valid_mac_address(const uint8_t *mac_addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002104{
2105 int xdigit = 0;
2106 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002107
Jeff Johnson030cd902018-11-11 10:19:40 -08002108 while (*mac_addr) {
2109 if (isxdigit(*mac_addr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002110 xdigit++;
Jeff Johnson030cd902018-11-11 10:19:40 -08002111 } else if (':' == *mac_addr) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002112 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2113 break;
2114
2115 ++separator;
2116 } else {
2117 /* Invalid MAC found */
Jeff Johnson030cd902018-11-11 10:19:40 -08002118 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002119 }
Jeff Johnson030cd902018-11-11 10:19:40 -08002120 ++mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002121 }
2122 return xdigit == 12 && (separator == 5 || separator == 0);
2123}
2124
2125/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302126 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2127 * @dev: Handle to struct net_device to be updated.
2128 *
2129 * Return: None
2130 */
2131static void hdd_mon_mode_ether_setup(struct net_device *dev)
2132{
2133 dev->header_ops = NULL;
2134 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2135 dev->hard_header_len = ETH_HLEN;
2136 dev->mtu = ETH_DATA_LEN;
2137 dev->addr_len = ETH_ALEN;
2138 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2139 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2140 dev->priv_flags |= IFF_TX_SKB_SHARING;
2141
2142 memset(dev->broadcast, 0xFF, ETH_ALEN);
2143}
2144
Nirav Shah73713f72018-05-17 14:50:41 +05302145#ifdef FEATURE_MONITOR_MODE_SUPPORT
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302146/**
chenguo71303962018-10-24 19:44:34 +08002147 * hdd_mon_turn_off_ps_and_wow() - Update monitor mode struct net_device.
2148 * @hdd_ctx: Pointer to HDD context.
2149 *
2150 * Return: None
2151 */
2152static void hdd_mon_turn_off_ps_and_wow(struct hdd_context *hdd_ctx)
2153{
2154 ucfg_pmo_set_power_save_mode(hdd_ctx->psoc, PS_NOT_SUPPORTED);
2155 ucfg_pmo_set_wow_enable(hdd_ctx->psoc, PMO_WOW_DISABLE_BOTH);
2156}
2157
2158/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002159 * __hdd__mon_open() - HDD Open function
2160 * @dev: Pointer to net_device structure
2161 *
2162 * This is called in response to ifconfig up
2163 *
2164 * Return: 0 for success; non-zero for failure
2165 */
2166static int __hdd_mon_open(struct net_device *dev)
2167{
2168 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002169 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2170 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002171
Dustin Brownfdf17c12018-03-14 12:55:34 -07002172 hdd_enter_dev(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002173
2174 ret = wlan_hdd_validate_context(hdd_ctx);
2175 if (ret)
2176 return ret;
2177
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302178 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002179
2180 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
Rajeev Kumar473f9af2019-04-05 14:25:56 -07002181 ret = hdd_trigger_psoc_idle_restart(hdd_ctx);
Ravi Joshia307f632017-07-17 23:41:41 -07002182 if (ret) {
2183 hdd_err("Failed to start WLAN modules return");
2184 return ret;
2185 }
2186 hdd_err("hdd_wlan_start_modules() successful !");
2187
2188 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2189 ret = hdd_start_adapter(adapter);
2190 if (ret) {
2191 hdd_err("Failed to start adapter :%d",
2192 adapter->device_mode);
2193 return ret;
2194 }
2195 hdd_err("hdd_start_adapters() successful !");
2196 }
chenguo71303962018-10-24 19:44:34 +08002197 hdd_mon_turn_off_ps_and_wow(hdd_ctx);
Ravi Joshia307f632017-07-17 23:41:41 -07002198 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2199 }
2200
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002201 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002202
2203 if (!ret)
2204 ret = hdd_enable_monitor_mode(dev);
2205
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002206 return ret;
2207}
2208
2209/**
2210 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2211 * @dev: Pointer to net_device structure
2212 *
2213 * This is called in response to ifconfig up
2214 *
2215 * Return: 0 for success; non-zero for failure
2216 */
Dustin Brown0e1e1622019-01-17 11:00:22 -08002217static int hdd_mon_open(struct net_device *net_dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002218{
Dustin Brown0e1e1622019-01-17 11:00:22 -08002219 int errno;
2220 struct osif_vdev_sync *vdev_sync;
2221
2222 errno = osif_vdev_sync_trans_start(net_dev, &vdev_sync);
2223 if (errno)
2224 return errno;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002225
Dustin Brown0e1e1622019-01-17 11:00:22 -08002226 errno = __hdd_mon_open(net_dev);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002227
Dustin Brown0e1e1622019-01-17 11:00:22 -08002228 osif_vdev_sync_trans_stop(vdev_sync);
2229
2230 return errno;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002231}
Nirav Shah73713f72018-05-17 14:50:41 +05302232#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002233
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002234static QDF_STATUS
2235wlan_hdd_update_dbs_scan_and_fw_mode_config(void)
2236{
2237 struct policy_mgr_dual_mac_config cfg = {0};
2238 QDF_STATUS status;
Krunal Sonie64b17e2018-12-13 16:00:02 -08002239 uint32_t chnl_sel_logic_conc = 0;
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002240 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Krunal Sonidf29bc42018-11-15 13:26:29 -08002241 uint8_t dual_mac_feature = DISABLE_DBS_CXN_AND_SCAN;
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002242
2243 if (!hdd_ctx) {
2244 hdd_err("HDD context is NULL");
2245 return QDF_STATUS_E_FAILURE;
2246 }
2247
Krunal Sonie64b17e2018-12-13 16:00:02 -08002248 /*
2249 * ROME platform doesn't support any DBS related commands in FW,
2250 * so if driver sends wmi command with dual_mac_config with all set to
2251 * 0 then FW wouldn't respond back and driver would timeout on waiting
2252 * for response. Check if FW supports DBS to eliminate ROME vs
2253 * NON-ROME platform.
2254 */
2255 if (!policy_mgr_find_if_fw_supports_dbs(hdd_ctx->psoc))
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002256 return QDF_STATUS_SUCCESS;
2257
2258 cfg.scan_config = 0;
2259 cfg.fw_mode_config = 0;
2260 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
Krunal Sonie64b17e2018-12-13 16:00:02 -08002261 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->psoc)) {
2262 status =
2263 ucfg_policy_mgr_get_chnl_select_plcy(hdd_ctx->psoc,
2264 &chnl_sel_logic_conc);
2265 if (status != QDF_STATUS_SUCCESS) {
2266 hdd_err("can't get chnl sel policy, use def");
2267 return status;
2268 }
Krunal Sonidf29bc42018-11-15 13:26:29 -08002269 }
2270 status =
2271 ucfg_policy_mgr_get_dual_mac_feature(hdd_ctx->psoc,
2272 &dual_mac_feature);
2273 if (status != QDF_STATUS_SUCCESS) {
2274 hdd_err("ucfg_policy_mgr_get_dual_mac_feature failed, use def");
2275 return status;
2276 }
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002277
Krunal Sonidf29bc42018-11-15 13:26:29 -08002278 if (dual_mac_feature != DISABLE_DBS_CXN_AND_SCAN) {
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002279 status = policy_mgr_get_updated_scan_and_fw_mode_config(
Dustin Brown1dbefe62018-09-11 16:32:03 -07002280 hdd_ctx->psoc, &cfg.scan_config,
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002281 &cfg.fw_mode_config,
Krunal Sonidf29bc42018-11-15 13:26:29 -08002282 dual_mac_feature,
Krunal Sonie64b17e2018-12-13 16:00:02 -08002283 chnl_sel_logic_conc);
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002284
2285 if (status != QDF_STATUS_SUCCESS) {
2286 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
2287 status);
2288 return status;
2289 }
2290 }
2291
2292 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
2293 cfg.scan_config, cfg.fw_mode_config);
2294
2295 status = sme_soc_set_dual_mac_config(cfg);
2296 if (status != QDF_STATUS_SUCCESS) {
2297 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
2298 return status;
2299 }
2300
2301 return QDF_STATUS_SUCCESS;
2302}
2303
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002304/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302305 * hdd_start_adapter() - Wrapper function for device specific adapter
2306 * @adapter: pointer to HDD adapter
2307 *
2308 * This function is called to start the device specific adapter for
2309 * the mode passed in the adapter's device_mode.
2310 *
2311 * Return: 0 for success; non-zero for failure
2312 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002313int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302314{
2315
2316 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002317 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302318
Dustin Brownfdf17c12018-03-14 12:55:34 -07002319 hdd_enter_dev(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002320 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302321
2322 switch (device_mode) {
2323 case QDF_P2P_CLIENT_MODE:
2324 case QDF_P2P_DEVICE_MODE:
2325 case QDF_OCB_MODE:
2326 case QDF_STA_MODE:
2327 case QDF_MONITOR_MODE:
2328 ret = hdd_start_station_adapter(adapter);
2329 if (ret)
2330 goto err_start_adapter;
Alok Kumar81e1d732018-09-04 11:10:36 +05302331
2332 hdd_nud_ignore_tracking(adapter, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05302333 break;
2334 case QDF_P2P_GO_MODE:
2335 case QDF_SAP_MODE:
2336 ret = hdd_start_ap_adapter(adapter);
2337 if (ret)
2338 goto err_start_adapter;
2339 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302340 case QDF_IBSS_MODE:
2341 /*
2342 * For IBSS interface is initialized as part of
2343 * hdd_init_station_mode()
2344 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002345 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302346 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002347 /* vdevs are dynamically managed by firmware in FTM */
Arun Kumar Khandavallif573e062019-04-16 17:17:40 +05302348 hdd_register_wext(adapter->dev);
Dustin Browndb2a8be2017-12-20 11:49:56 -08002349 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302350 default:
2351 hdd_err("Invalid session type %d", device_mode);
2352 QDF_ASSERT(0);
2353 goto err_start_adapter;
2354 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002355
Arun Khandavallifae92942016-08-01 13:31:08 +05302356 if (hdd_set_fw_params(adapter))
2357 hdd_err("Failed to set the FW params for the adapter!");
2358
Jeff Johnson912b1bb2019-03-06 10:12:36 -08002359 if (adapter->vdev_id != WLAN_UMAC_VDEV_ID_MAX) {
Dustin Browne7e71d32018-05-11 16:00:08 -07002360 ret = wlan_hdd_cfg80211_register_frames(adapter);
2361 if (ret < 0) {
2362 hdd_err("Failed to register frames - ret %d", ret);
2363 goto err_start_adapter;
2364 }
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302365 }
Dustin Browne7e71d32018-05-11 16:00:08 -07002366
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002367 wlan_hdd_update_dbs_scan_and_fw_mode_config();
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302368
Dustin Browndb2a8be2017-12-20 11:49:56 -08002369exit_with_success:
Dustin Browne74003f2018-03-14 12:51:58 -07002370 hdd_exit();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002371
Arun Khandavallifae92942016-08-01 13:31:08 +05302372 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002373
Arun Khandavallifae92942016-08-01 13:31:08 +05302374err_start_adapter:
2375 return -EINVAL;
2376}
2377
2378/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302379 * hdd_enable_power_management() - API to Enable Power Management
2380 *
2381 * API invokes Bus Interface Layer power management functionality
2382 *
2383 * Return: None
2384 */
2385static void hdd_enable_power_management(void)
2386{
2387 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2388
2389 if (!hif_ctx) {
2390 hdd_err("Bus Interface Context is Invalid");
2391 return;
2392 }
2393
2394 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2395}
2396
2397/**
2398 * hdd_disable_power_management() - API to disable Power Management
2399 *
2400 * API disable Bus Interface Layer Power management functionality
2401 *
2402 * Return: None
2403 */
2404static void hdd_disable_power_management(void)
2405{
2406 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2407
2408 if (!hif_ctx) {
2409 hdd_err("Bus Interface Context is Invalid");
2410 return;
2411 }
2412
2413 hif_disable_power_management(hif_ctx);
2414}
2415
Ryan Hsuaadba072018-04-20 13:01:53 -07002416void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302417{
2418 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002419 size_t target_hw_name_len;
2420 const char *target_hw_name;
Ryan Hsuaadba072018-04-20 13:01:53 -07002421 uint8_t *buf;
2422 uint32_t buf_len;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302423
2424 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2425 if (!hif_sc) {
2426 hdd_err("HIF context is NULL");
2427 return;
2428 }
2429
Ryan Hsuaadba072018-04-20 13:01:53 -07002430 hif_get_hw_info(hif_sc, &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302431 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002432 &target_hw_name);
2433
2434 if (hdd_ctx->target_hw_name)
2435 qdf_mem_free(hdd_ctx->target_hw_name);
2436
2437 target_hw_name_len = strlen(target_hw_name) + 1;
2438 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2439 if (hdd_ctx->target_hw_name)
2440 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2441 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302442
Ryan Hsuaadba072018-04-20 13:01:53 -07002443 buf = qdf_mem_malloc(WE_MAX_STR_LEN);
2444 if (buf) {
2445 buf_len = hdd_wlan_get_version(hdd_ctx, WE_MAX_STR_LEN, buf);
2446 hdd_info("%s", buf);
2447 qdf_mem_free(buf);
2448 }
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302449}
2450
2451/**
gbian62edd7e2017-03-07 13:12:13 +08002452 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2453 * @hdd_ctx: Pointer to hdd context
2454 *
2455 * Return: none
2456 */
2457static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002458hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002459{
jitiphil8e15ea62018-11-16 18:05:34 +05302460 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM] = {0};
2461 qdf_size_t out_size = 0;
gbian62edd7e2017-03-07 13:12:13 +08002462 int i;
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002463 struct cds_context *cds_ctx;
gbian62edd7e2017-03-07 13:12:13 +08002464
Jeff Johnsond36fa332019-03-18 13:42:25 -07002465 if (!hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002466 return;
2467
Jeff Johnsond36fa332019-03-18 13:42:25 -07002468 if (!hdd_ctx->config) {
gbian62edd7e2017-03-07 13:12:13 +08002469 /* Do nothing if hdd_ctx is invalid */
2470 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2471 return;
2472 }
2473
2474 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2475
2476 if (!cds_ctx) {
2477 hdd_err("Invalid CDS Context");
2478 return;
2479 }
2480
Srinivas Girigowdad462f3b2019-03-25 14:05:33 -07002481 for (i = 0; i < QCA_WLAN_AC_ALL; i++) {
gbian62edd7e2017-03-07 13:12:13 +08002482 switch (i) {
Srinivas Girigowdad462f3b2019-03-25 14:05:33 -07002483 case QCA_WLAN_AC_BE:
jitiphil8e15ea62018-11-16 18:05:34 +05302484 qdf_uint8_array_parse(
2485 cfg_get(hdd_ctx->psoc,
2486 CFG_DP_ENABLE_TX_SCHED_WRR_BE),
2487 tx_sched_wrr_param,
2488 sizeof(tx_sched_wrr_param),
2489 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002490 break;
Srinivas Girigowdad462f3b2019-03-25 14:05:33 -07002491 case QCA_WLAN_AC_BK:
jitiphil8e15ea62018-11-16 18:05:34 +05302492 qdf_uint8_array_parse(
2493 cfg_get(hdd_ctx->psoc,
2494 CFG_DP_ENABLE_TX_SCHED_WRR_BK),
2495 tx_sched_wrr_param,
2496 sizeof(tx_sched_wrr_param),
2497 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002498 break;
Srinivas Girigowdad462f3b2019-03-25 14:05:33 -07002499 case QCA_WLAN_AC_VI:
jitiphil8e15ea62018-11-16 18:05:34 +05302500 qdf_uint8_array_parse(
2501 cfg_get(hdd_ctx->psoc,
2502 CFG_DP_ENABLE_TX_SCHED_WRR_VI),
2503 tx_sched_wrr_param,
2504 sizeof(tx_sched_wrr_param),
2505 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002506 break;
Srinivas Girigowdad462f3b2019-03-25 14:05:33 -07002507 case QCA_WLAN_AC_VO:
jitiphil8e15ea62018-11-16 18:05:34 +05302508 qdf_uint8_array_parse(
2509 cfg_get(hdd_ctx->psoc,
2510 CFG_DP_ENABLE_TX_SCHED_WRR_VO),
2511 tx_sched_wrr_param,
2512 sizeof(tx_sched_wrr_param),
2513 &out_size);
gbian62edd7e2017-03-07 13:12:13 +08002514 break;
2515 default:
gbian62edd7e2017-03-07 13:12:13 +08002516 break;
2517 }
2518
jitiphil8e15ea62018-11-16 18:05:34 +05302519 if (out_size == TX_SCHED_WRR_PARAMS_NUM) {
gbian62edd7e2017-03-07 13:12:13 +08002520 cds_ctx->ac_specs[i].wrr_skip_weight =
2521 tx_sched_wrr_param[0];
2522 cds_ctx->ac_specs[i].credit_threshold =
2523 tx_sched_wrr_param[1];
2524 cds_ctx->ac_specs[i].send_limit =
2525 tx_sched_wrr_param[2];
2526 cds_ctx->ac_specs[i].credit_reserve =
2527 tx_sched_wrr_param[3];
2528 cds_ctx->ac_specs[i].discard_weight =
2529 tx_sched_wrr_param[4];
2530 }
2531
jitiphil8e15ea62018-11-16 18:05:34 +05302532 out_size = 0;
gbian62edd7e2017-03-07 13:12:13 +08002533 }
2534}
2535
Ryan Hsuaadba072018-04-20 13:01:53 -07002536uint32_t hdd_wlan_get_version(struct hdd_context *hdd_ctx,
2537 const size_t version_len, uint8_t *version)
2538{
2539 uint32_t size;
2540 uint32_t msp_id = 0, mspid = 0, siid = 0, crmid = 0, sub_id = 0;
2541
2542 if (!hdd_ctx) {
2543 hdd_err("Invalid context, HDD context is null");
2544 return 0;
2545 }
2546
Ashish Kumar Dhanotiya7353f882018-05-15 12:50:19 +05302547 if (!version || version_len == 0) {
Ryan Hsuaadba072018-04-20 13:01:53 -07002548 hdd_err("Invalid buffer pointr or buffer len\n");
2549 return 0;
2550 }
2551
2552 msp_id = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
2553 mspid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
2554 siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
2555 crmid = hdd_ctx->target_fw_version & 0x7fff;
2556 sub_id = (hdd_ctx->target_fw_vers_ext & 0xf0000000) >> 28;
2557
2558 size = scnprintf(version, version_len,
Ryan Hsuc6918552018-05-16 13:29:59 -07002559 "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 -07002560 QWLAN_VERSIONSTR,
2561 msp_id, mspid, siid, crmid, sub_id,
Ryan Hsuc6918552018-05-16 13:29:59 -07002562 hdd_ctx->target_hw_name,
2563 hdd_ctx->hw_bd_info.bdf_version,
2564 hdd_ctx->hw_bd_info.ref_design_id,
2565 hdd_ctx->hw_bd_info.customer_id,
2566 hdd_ctx->hw_bd_info.project_id,
2567 hdd_ctx->hw_bd_info.board_data_rev);
Ryan Hsuaadba072018-04-20 13:01:53 -07002568
2569 return size;
2570}
2571
Rachit Kankane0dc3e852018-05-07 17:33:42 +05302572int hdd_set_11ax_rate(struct hdd_adapter *adapter, int set_value,
2573 struct sap_config *sap_config)
2574{
2575 uint8_t preamble = 0, nss = 0, rix = 0;
2576 int ret;
2577 mac_handle_t mac_handle = adapter->hdd_ctx->mac_handle;
2578
2579 if (!sap_config) {
2580 if (!sme_is_feature_supported_by_fw(DOT11AX)) {
2581 hdd_err("Target does not support 11ax");
2582 return -EIO;
2583 }
2584 } else if (sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax &&
2585 sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax_ONLY) {
2586 hdd_err("Invalid hw mode, SAP hw_mode= 0x%x, ch = %d",
2587 sap_config->SapHw_mode, sap_config->channel);
2588 return -EIO;
2589 }
2590
2591 if (set_value != 0xff) {
2592 rix = RC_2_RATE_IDX_11AX(set_value);
2593 preamble = WMI_RATE_PREAMBLE_HE;
2594 nss = HT_RC_2_STREAMS_11AX(set_value);
2595
2596 set_value = hdd_assemble_rate_code(preamble, nss, rix);
2597 } else {
Jeff Johnson5a6fc962019-02-04 14:20:25 -08002598 ret = sme_set_auto_rate_he_ltf(mac_handle, adapter->vdev_id,
Rachit Kankane0dc3e852018-05-07 17:33:42 +05302599 QCA_WLAN_HE_LTF_AUTO);
2600 }
2601
2602 hdd_info("SET_11AX_RATE val %d rix %d preamble %x nss %d",
2603 set_value, rix, preamble, nss);
2604
Jeff Johnson5a6fc962019-02-04 14:20:25 -08002605 ret = wma_cli_set_command(adapter->vdev_id,
Rachit Kankane0dc3e852018-05-07 17:33:42 +05302606 WMI_VDEV_PARAM_FIXED_RATE,
2607 set_value, VDEV_CMD);
2608
2609 return ret;
2610}
2611
2612int hdd_assemble_rate_code(uint8_t preamble, uint8_t nss, uint8_t rate)
2613{
2614 int set_value;
2615
2616 if (sme_is_feature_supported_by_fw(DOT11AX))
2617 set_value = WMI_ASSEMBLE_RATECODE_V1(rate, nss, preamble);
2618 else
2619 set_value = (preamble << 6) | (nss << 4) | rate;
2620
2621 return set_value;
2622}
2623
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002624#ifdef FEATURE_WLAN_WAPI
2625/**
2626 * hdd_wapi_security_sta_exist() - return wapi security sta exist or not
2627 *
2628 * This API returns the wapi security station exist or not
2629 *
2630 * Return: true - wapi security station exist
2631 */
2632static bool hdd_wapi_security_sta_exist(void)
2633{
2634 struct hdd_adapter *adapter = NULL;
2635 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2636
2637 hdd_for_each_adapter(hdd_ctx, adapter) {
2638 if ((adapter->device_mode == QDF_STA_MODE) &&
2639 adapter->wapi_info.wapi_mode &&
2640 (adapter->wapi_info.wapi_auth_mode != WAPI_AUTH_MODE_OPEN))
2641 return true;
2642 }
2643 return false;
2644}
2645#else
2646static bool hdd_wapi_security_sta_exist(void)
2647{
2648 return false;
2649}
2650#endif
2651
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002652#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002653static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2654 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2655{
Jeff Johnson9d295242017-08-29 14:39:48 -07002656 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002657 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002658
2659 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2660 if (!adapter) {
2661 hdd_err("Adapter is NULL");
2662 return PM_MAX_NUM_OF_MODE;
2663 }
2664
2665 return policy_mgr_convert_device_mode_to_qdf_type(
2666 adapter->device_mode);
2667}
2668
Abhishek Singh3bbf6cb2019-03-28 14:05:43 +05302669/**
2670 * hdd_is_chan_switch_in_progress() - Check if any adapter has channel switch in
2671 * progress
2672 *
2673 * Return: true, if any adapter has channel switch in
2674 * progress else false
2675 */
2676static bool hdd_is_chan_switch_in_progress(void)
2677{
2678 struct hdd_adapter *adapter = NULL;
2679 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2680
2681 hdd_for_each_adapter(hdd_ctx, adapter) {
2682 if ((adapter->device_mode == QDF_SAP_MODE ||
2683 adapter->device_mode == QDF_P2P_GO_MODE) &&
2684 qdf_atomic_read(&adapter->ch_switch_in_progress)) {
2685 hdd_debug("channel switch progress for vdev_id %d",
2686 adapter->vdev_id);
2687 return true;
2688 }
2689 }
2690
2691 return false;
2692}
2693
2694
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002695static void hdd_register_policy_manager_callback(
2696 struct wlan_objmgr_psoc *psoc)
2697{
2698 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002699
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002700 qdf_mem_zero(&hdd_cbacks, sizeof(hdd_cbacks));
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002701 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002702 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002703 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2704 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002705 hdd_cbacks.get_mode_for_non_connected_vdev =
2706 wlan_hdd_get_mode_for_non_connected_vdev;
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05302707 hdd_cbacks.hdd_get_device_mode = hdd_get_device_mode;
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002708 hdd_cbacks.hdd_wapi_security_sta_exist =
2709 hdd_wapi_security_sta_exist;
Abhishek Singh3bbf6cb2019-03-28 14:05:43 +05302710 hdd_cbacks.hdd_is_chan_switch_in_progress =
2711 hdd_is_chan_switch_in_progress;
2712
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002713 if (QDF_STATUS_SUCCESS !=
2714 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2715 hdd_err("HDD callback registration with policy manager failed");
2716 }
2717}
2718#else
2719static void hdd_register_policy_manager_callback(
2720 struct wlan_objmgr_psoc *psoc)
2721{
2722}
2723#endif
2724
Nachiket Kukade2fb1fdb2019-01-08 15:35:27 +05302725#ifdef WLAN_FEATURE_NAN
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002726static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002727{
2728 struct nan_callbacks cb_obj = {0};
2729
2730 cb_obj.ndi_open = hdd_ndi_open;
2731 cb_obj.ndi_close = hdd_ndi_close;
2732 cb_obj.ndi_start = hdd_ndi_start;
2733 cb_obj.ndi_delete = hdd_ndi_delete;
2734 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2735 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2736
Naveen Rawat37f62c82017-03-26 22:24:43 -07002737 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002738 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002739
Dustin Brown1dbefe62018-09-11 16:32:03 -07002740 os_if_nan_register_hdd_callbacks(hdd_ctx->psoc, &cb_obj);
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002741}
jiadff1ac132018-11-26 16:27:48 +08002742#else
2743static inline void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
2744{
2745}
2746#endif
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002747
Dustin Brown26b3d042017-12-21 11:13:27 -08002748#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002749/**
2750 * hdd_check_for_leaks() - Perform runtime memory leak checks
Dustin Browna6246dd2018-05-24 14:35:58 -07002751 * @hdd_ctx: the global HDD context
Dustin Brown29533f22018-07-24 13:11:56 -07002752 * @is_ssr: true if SSR is in progress
Dustin Brown4c5b9902017-12-19 11:17:19 -08002753 *
2754 * This API triggers runtime memory leak detection. This feature enforces the
2755 * policy that any memory allocated at runtime must also be released at runtime.
2756 *
2757 * Allocating memory at runtime and releasing it at unload is effectively a
2758 * memory leak for configurations which never unload (e.g. LONU, statically
2759 * compiled driver). Such memory leaks are NOT false positives, and must be
2760 * fixed.
2761 *
2762 * Return: None
2763 */
Dustin Brown29533f22018-07-24 13:11:56 -07002764static void hdd_check_for_leaks(struct hdd_context *hdd_ctx, bool is_ssr)
Dustin Brown4bc0a622017-12-06 15:56:50 -08002765{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002766 /* DO NOT REMOVE these checks; for false positives, read above first */
2767
Dustin Brown1dbefe62018-09-11 16:32:03 -07002768 wlan_objmgr_psoc_check_for_peer_leaks(hdd_ctx->psoc);
2769 wlan_objmgr_psoc_check_for_vdev_leaks(hdd_ctx->psoc);
2770 wlan_objmgr_psoc_check_for_pdev_leaks(hdd_ctx->psoc);
Dustin Brown29533f22018-07-24 13:11:56 -07002771
2772 /* many adapter resources are not freed by design during SSR */
2773 if (is_ssr)
2774 return;
2775
Dustin Brownc2796312019-03-13 16:43:36 -07002776 qdf_delayed_work_check_for_leaks();
Dustin Brown677e0862017-10-10 16:30:09 -07002777 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002778 qdf_nbuf_map_check_for_leaks();
Dustin Brown4a93bb52019-03-13 11:46:34 -07002779 qdf_periodic_work_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002780 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002781}
2782
Dustin Brown26b3d042017-12-21 11:13:27 -08002783#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2784#else
Dustin Brown29533f22018-07-24 13:11:56 -07002785static inline void hdd_check_for_leaks(struct hdd_context *hdd_ctx, bool is_ssr)
2786{ }
Dustin Brown26b3d042017-12-21 11:13:27 -08002787
2788#define hdd_debug_domain_set(domain)
2789#endif /* CONFIG_LEAK_DETECTION */
2790
gbian62edd7e2017-03-07 13:12:13 +08002791/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002792 * hdd_update_country_code - Update country code
2793 * @hdd_ctx: HDD context
2794 *
2795 * Update country code based on module parameter country_code
2796 *
2797 * Return: 0 on success and errno on failure
2798 */
2799static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2800{
2801 if (!country_code)
2802 return 0;
2803
2804 return hdd_reg_set_country(hdd_ctx, country_code);
2805}
2806
Dustin Browne7e71d32018-05-11 16:00:08 -07002807int hdd_wlan_start_modules(struct hdd_context *hdd_ctx, bool reinit)
Arun Khandavallifae92942016-08-01 13:31:08 +05302808{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002809 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302810 qdf_device_t qdf_dev;
2811 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302812 bool unint = false;
2813 void *hif_ctx;
Jingxiang Ge95912f82018-04-19 12:01:26 +08002814 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +05302815
Arun Khandavallifae92942016-08-01 13:31:08 +05302816 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2817 if (!qdf_dev) {
2818 hdd_err("QDF Device Context is Invalid return");
2819 return -EINVAL;
2820 }
2821
Dustin Brown4c663222018-10-23 14:19:36 -07002822 hdd_psoc_idle_timer_stop(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302823
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302824 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002825 hdd_debug("Driver modules already Enabled");
Dustin Browne74003f2018-03-14 12:51:58 -07002826 hdd_exit();
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302827 return 0;
2828 }
2829
Arun Khandavallifae92942016-08-01 13:31:08 +05302830 switch (hdd_ctx->driver_status) {
2831 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002832 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302833 unint = true;
2834 /* Fall through dont add break here */
2835 case DRIVER_MODULES_CLOSED:
Dustin Brown1a20b082018-08-03 17:27:15 -07002836 hdd_info("Wlan transitioning (CLOSED -> ENABLED)");
Dustin Brown550f6d22017-12-14 15:44:01 -08002837
Dustin Brown26b3d042017-12-21 11:13:27 -08002838 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002839
Arun Khandavallifae92942016-08-01 13:31:08 +05302840 if (!reinit && !unint) {
2841 ret = pld_power_on(qdf_dev->dev);
2842 if (ret) {
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002843 hdd_err("Failed to power up device; errno:%d",
Dustin Browndca39692017-11-09 15:30:25 -08002844 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302845 goto release_lock;
2846 }
2847 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002848
2849 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2850 hdd_ctx->config->enable_fw_log);
Arun Khandavallifae92942016-08-01 13:31:08 +05302851 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2852 qdf_dev->bus_type,
2853 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2854 HIF_ENABLE_TYPE_PROBE);
2855 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002856 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302857 goto power_down;
2858 }
2859
2860 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302861 if (!hif_ctx) {
2862 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002863 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302864 goto power_down;
2865 }
2866
Arun Khandavallifae92942016-08-01 13:31:08 +05302867 status = ol_cds_init(qdf_dev, hif_ctx);
2868 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002869 hdd_err("No Memory to Create BMI Context; status: %d",
2870 status);
2871 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302872 goto hif_close;
2873 }
2874
Nirav Shah6aeecf92019-02-13 14:05:03 +05302875 if (hdd_get_conparam() == QDF_GLOBAL_EPPING_MODE) {
2876 status = epping_open();
2877 if (status) {
2878 hdd_err("Failed to open in epping mode: %d",
2879 status);
2880 ret = -EINVAL;
2881 goto cds_free;
2882 }
2883
2884 status = epping_enable(qdf_dev->dev, false);
2885 if (status) {
2886 hdd_err("Failed to enable in epping mode : %d",
2887 status);
2888 epping_close();
2889 goto cds_free;
2890 }
2891
2892 hdd_info("epping mode enabled");
2893 break;
2894 }
2895
jitiphil4c256a32018-09-07 08:51:52 +05302896 ucfg_ipa_component_config_update(hdd_ctx->psoc);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302897
gbian62edd7e2017-03-07 13:12:13 +08002898 hdd_update_cds_ac_specs_params(hdd_ctx);
2899
Dustin Brown1dbefe62018-09-11 16:32:03 -07002900 status = hdd_component_psoc_open(hdd_ctx->psoc);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05302901 if (QDF_IS_STATUS_ERROR(status)) {
2902 hdd_err("Failed to Open legacy components; status: %d",
2903 status);
2904 ret = qdf_status_to_os_return(status);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05302905 goto cds_free;
2906 }
2907
2908 ret = hdd_update_config(hdd_ctx);
2909 if (ret) {
2910 hdd_err("Failed to update configuration; errno: %d",
2911 ret);
2912 goto cds_free;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05302913 }
2914
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +05302915 status = wbuff_module_init();
2916 if (QDF_IS_STATUS_ERROR(status))
2917 hdd_err("WBUFF init unsuccessful; status: %d", status);
2918
Dustin Brown1dbefe62018-09-11 16:32:03 -07002919 status = cds_open(hdd_ctx->psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002920 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002921 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002922 ret = qdf_status_to_os_return(status);
Krunal Sonie71838d2018-09-27 10:45:05 -07002923 goto psoc_close;
Arun Khandavallifae92942016-08-01 13:31:08 +05302924 }
2925
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +05302926 hdd_ctx->mac_handle = cds_get_context(QDF_MODULE_ID_SME);
2927
Manjunathappa Prakashb6b4ff12018-06-04 12:32:33 -07002928 if (hdd_ctx->config->rx_thread_affinity_mask)
2929 cds_set_rx_thread_cpu_mask(
2930 hdd_ctx->config->rx_thread_affinity_mask);
2931
2932 /* initialize components configurations after psoc open */
Mukul Sharma9d797a02017-01-05 20:26:03 +05302933 ret = hdd_update_components_config(hdd_ctx);
2934 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002935 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302936 ret);
2937 goto close;
2938 }
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302939
Dustin Brown1dbefe62018-09-11 16:32:03 -07002940 status = cds_dp_open(hdd_ctx->psoc);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002941 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002942 hdd_err("Failed to Open cds post open; status: %d",
2943 status);
2944 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002945 goto close;
2946 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302947
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302948 ret = hdd_register_cb(hdd_ctx);
2949 if (ret) {
2950 hdd_err("Failed to register HDD callbacks!");
2951 goto cds_txrx_free;
2952 }
2953
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002954 /*
2955 * NAN compoenet requires certian operations like, open adapter,
2956 * close adapter, etc. to be initiated by HDD, for those
2957 * register HDD callbacks with UMAC's NAN componenet.
2958 */
2959 hdd_nan_register_callbacks(hdd_ctx);
2960
Jeff Johnson3a280122017-09-13 07:42:00 -07002961 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302962 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002963 hdd_err("Failed to pre-enable CDS; status: %d", status);
2964 ret = qdf_status_to_os_return(status);
Sourav Mohapatra674925f2018-04-16 11:16:58 +05302965 goto deregister_cb;
Arun Khandavallifae92942016-08-01 13:31:08 +05302966 }
2967
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002968 hdd_register_policy_manager_callback(
Dustin Brown1dbefe62018-09-11 16:32:03 -07002969 hdd_ctx->psoc);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002970
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302971 hdd_sysfs_create_driver_root_obj();
Dustin Brown1dbefe62018-09-11 16:32:03 -07002972 hdd_sysfs_create_version_interface(hdd_ctx->psoc);
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302973 hdd_sysfs_create_powerstats_interface();
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302974 hdd_update_hw_sw_info(hdd_ctx);
Dustin Brown550f6d22017-12-14 15:44:01 -08002975
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302976 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2977 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002978 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302979 break;
2980 }
Dustin Browndca39692017-11-09 15:30:25 -08002981
Dustin Browne7e71d32018-05-11 16:00:08 -07002982 ret = hdd_configure_cds(hdd_ctx);
Dustin Browndca39692017-11-09 15:30:25 -08002983 if (ret) {
2984 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05302985 goto destroy_driver_sysfs;
Arun Khandavallifae92942016-08-01 13:31:08 +05302986 }
Dustin Browndca39692017-11-09 15:30:25 -08002987
Komal Seelamf2136bb2016-09-28 18:30:44 +05302988 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002989
Arun Khandavallifae92942016-08-01 13:31:08 +05302990 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002991
Arun Khandavallifae92942016-08-01 13:31:08 +05302992 default:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002993 QDF_DEBUG_PANIC("Unknown driver state:%d",
Arun Khandavallifae92942016-08-01 13:31:08 +05302994 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002995 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302996 goto release_lock;
2997 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002998
Dustin Brown1a20b082018-08-03 17:27:15 -07002999 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
3000 hdd_info("Wlan transitioned (now ENABLED)");
3001
Dustin Browne74003f2018-03-14 12:51:58 -07003002 hdd_exit();
Dustin Brown550f6d22017-12-14 15:44:01 -08003003
Arun Khandavallifae92942016-08-01 13:31:08 +05303004 return 0;
3005
Arunk Khandavalli890f6d92018-10-30 20:18:28 +05303006destroy_driver_sysfs:
3007 hdd_sysfs_destroy_powerstats_interface();
3008 hdd_sysfs_destroy_version_interface();
3009 hdd_sysfs_destroy_driver_root_obj();
Rajeev Kumarbe021242017-02-16 16:12:23 -08003010 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08003011
Sourav Mohapatra674925f2018-04-16 11:16:58 +05303012deregister_cb:
3013 hdd_deregister_cb(hdd_ctx);
3014
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07003015cds_txrx_free:
Dustin Brown1dbefe62018-09-11 16:32:03 -07003016 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->psoc);
Jingxiang Ge95912f82018-04-19 12:01:26 +08003017
3018 if (tgt_hdl && target_psoc_get_wmi_ready(tgt_hdl)) {
3019 hdd_runtime_suspend_context_deinit(hdd_ctx);
Dustin Brown07901ec2018-09-07 11:02:41 -07003020 dispatcher_pdev_close(hdd_ctx->pdev);
Jingxiang Ge95912f82018-04-19 12:01:26 +08003021 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
3022 }
3023
Dustin Brown1dbefe62018-09-11 16:32:03 -07003024 cds_dp_close(hdd_ctx->psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08003025
Arun Khandavallifae92942016-08-01 13:31:08 +05303026close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08003027 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08003028 hdd_info("Wlan transition aborted (now CLOSED)");
3029
Dustin Brown1dbefe62018-09-11 16:32:03 -07003030 cds_close(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05303031
Krunal Sonie71838d2018-09-27 10:45:05 -07003032psoc_close:
Dustin Brown1dbefe62018-09-11 16:32:03 -07003033 hdd_component_psoc_close(hdd_ctx->psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07003034 cds_deinit_ini_config();
3035
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07003036cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05303037 ol_cds_free();
3038
3039hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07003040 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
3041 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05303042power_down:
3043 if (!reinit && !unint)
3044 pld_power_off(qdf_dev->dev);
3045release_lock:
Abhinav Kumar7ae9b7b2017-12-19 15:11:54 +05303046 if (hdd_ctx->target_hw_name) {
3047 qdf_mem_free(hdd_ctx->target_hw_name);
3048 hdd_ctx->target_hw_name = NULL;
3049 }
Dustin Brown29533f22018-07-24 13:11:56 -07003050
3051 hdd_check_for_leaks(hdd_ctx, reinit);
Dustin Brown26b3d042017-12-21 11:13:27 -08003052 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08003053
Dustin Browne74003f2018-03-14 12:51:58 -07003054 hdd_exit();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08003055
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07003056 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05303057}
3058
Naveen Rawat910726a2017-03-06 11:42:51 -08003059#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003060static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003061{
3062 int ret = os_if_wifi_pos_register_nl();
3063
3064 if (ret)
3065 hdd_err("os_if_wifi_pos_register_nl failed");
3066
3067 return ret;
3068}
3069
3070static int hdd_deactivate_wifi_pos(void)
3071{
3072 int ret = os_if_wifi_pos_deregister_nl();
3073
3074 if (ret)
3075 hdd_err("os_if_wifi_pos_deregister_nl failed");
3076
3077 return ret;
3078}
3079
3080/**
3081 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
3082 * @hdd_ctx: hdd context
3083 *
3084 * Return: status of operation
3085 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003086static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003087{
Dustin Brown1dbefe62018-09-11 16:32:03 -07003088 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Wu Gao1ab05582018-11-08 16:22:49 +08003089 uint16_t neighbor_scan_max_chan_time;
3090 uint16_t neighbor_scan_min_chan_time;
Naveen Rawat910726a2017-03-06 11:42:51 -08003091
3092 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
3093 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
3094 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
3095 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
3096 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
3097 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
Wu Gao1ab05582018-11-08 16:22:49 +08003098 ucfg_mlme_get_neighbor_scan_max_chan_time(psoc,
3099 &neighbor_scan_max_chan_time);
3100 ucfg_mlme_get_neighbor_scan_min_chan_time(psoc,
3101 &neighbor_scan_min_chan_time);
3102 wifi_pos_set_dwell_time_min(psoc, neighbor_scan_min_chan_time);
3103 wifi_pos_set_dwell_time_max(psoc, neighbor_scan_max_chan_time);
Naveen Rawat910726a2017-03-06 11:42:51 -08003104}
3105#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003106static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003107{
3108 return oem_activate_service(hdd_ctx);
3109}
3110
3111static int hdd_deactivate_wifi_pos(void)
3112{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05303113 return oem_deactivate_service();
Naveen Rawat910726a2017-03-06 11:42:51 -08003114}
3115
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003116static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003117{
3118}
3119#endif
3120
Arun Khandavallifae92942016-08-01 13:31:08 +05303121/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003122 * __hdd_open() - HDD Open function
3123 * @dev: Pointer to net_device structure
3124 *
3125 * This is called in response to ifconfig up
3126 *
3127 * Return: 0 for success; non-zero for failure
3128 */
3129static int __hdd_open(struct net_device *dev)
3130{
Jeff Johnson9d295242017-08-29 14:39:48 -07003131 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003132 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003133 int ret;
3134
Dustin Brownfdf17c12018-03-14 12:55:34 -07003135 hdd_enter_dev(dev);
Ashish Kumar Dhanotiyaf10aa5f2018-12-28 21:29:56 +05303136
3137 qdf_mtrace(QDF_MODULE_ID_HDD, QDF_MODULE_ID_HDD,
3138 TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08003139 adapter->vdev_id, adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003140
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05303141 /* Nothing to be done if device is unloading */
3142 if (cds_is_driver_unloading()) {
3143 hdd_err("Driver is unloading can not open the hdd");
3144 return -EBUSY;
3145 }
3146
Dustin Brown01847752017-10-25 13:56:27 -07003147 if (cds_is_driver_recovering()) {
3148 hdd_err("WLAN is currently recovering; Please try again.");
3149 return -EBUSY;
3150 }
3151
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303152 /*
3153 * This scenario can be hit in cases where in the wlan driver after
3154 * registering the netdevices and there is a failure in driver
3155 * initialization. So return error gracefully because the netdevices
3156 * will be de-registered as part of the load failure.
3157 */
3158
3159 if (!cds_is_driver_loaded()) {
3160 hdd_err("Failed to start the wlan driver!!");
Dustin Brown3da3a832019-03-19 15:51:54 -07003161 return -EIO;
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303162 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303163
Rajeev Kumar473f9af2019-04-05 14:25:56 -07003164 ret = hdd_trigger_psoc_idle_restart(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05303165 if (ret) {
3166 hdd_err("Failed to start WLAN modules return");
Dustin Brown3da3a832019-03-19 15:51:54 -07003167 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05303168 }
3169
Arun Khandavallifae92942016-08-01 13:31:08 +05303170 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3171 ret = hdd_start_adapter(adapter);
3172 if (ret) {
3173 hdd_err("Failed to start adapter :%d",
3174 adapter->device_mode);
Dustin Brown3da3a832019-03-19 15:51:54 -07003175 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05303176 }
3177 }
3178
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003179 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3180 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003181 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003182 /* Enable TX queues only when we are connected */
3183 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05303184 WLAN_START_ALL_NETIF_QUEUE,
3185 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003186 }
3187
Naveen Rawat286def52016-09-23 15:38:02 -07003188 /* Enable carrier and transmit queues for NDI */
3189 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003190 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07003191 wlan_hdd_netif_queue_control(adapter,
3192 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
3193 WLAN_CONTROL_PATH);
3194 }
3195
Naveen Rawat910726a2017-03-06 11:42:51 -08003196 hdd_populate_wifi_pos_cfg(hdd_ctx);
Arunk Khandavalli40943af2017-05-15 19:25:34 +05303197 hdd_lpass_notify_start(hdd_ctx, adapter);
Naveen Rawat910726a2017-03-06 11:42:51 -08003198
Dustin Brown3da3a832019-03-19 15:51:54 -07003199 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003200}
3201
3202/**
3203 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
Dustin Brown98f7c822019-03-06 12:25:49 -08003204 * @net_dev: Pointer to net_device structure
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003205 *
3206 * This is called in response to ifconfig up
3207 *
3208 * Return: 0 for success; non-zero for failure
3209 */
Dustin Brown0e1e1622019-01-17 11:00:22 -08003210static int hdd_open(struct net_device *net_dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003211{
Dustin Brown0e1e1622019-01-17 11:00:22 -08003212 int errno;
3213 struct osif_vdev_sync *vdev_sync;
3214
3215 errno = osif_vdev_sync_trans_start(net_dev, &vdev_sync);
3216 if (errno)
3217 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003218
Dustin Brown0e1e1622019-01-17 11:00:22 -08003219 errno = __hdd_open(net_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003220
Dustin Brown0e1e1622019-01-17 11:00:22 -08003221 osif_vdev_sync_trans_stop(vdev_sync);
3222
3223 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003224}
3225
3226/**
3227 * __hdd_stop() - HDD stop function
3228 * @dev: Pointer to net_device structure
3229 *
3230 * This is called in response to ifconfig down
3231 *
3232 * Return: 0 for success; non-zero for failure
3233 */
3234static int __hdd_stop(struct net_device *dev)
3235{
Jeff Johnson9d295242017-08-29 14:39:48 -07003236 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003237 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003238 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -07003239 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003240
Dustin Brownfdf17c12018-03-14 12:55:34 -07003241 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003242
Ashish Kumar Dhanotiyaf10aa5f2018-12-28 21:29:56 +05303243 qdf_mtrace(QDF_MODULE_ID_HDD, QDF_MODULE_ID_HDD,
3244 TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08003245 adapter->vdev_id, adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003246
3247 ret = wlan_hdd_validate_context(hdd_ctx);
Arunk Khandavalli987c8d52018-06-21 17:40:31 +05303248 if (ret) {
3249 set_bit(DOWN_DURING_SSR, &adapter->event_flags);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003250 return ret;
Arunk Khandavalli987c8d52018-06-21 17:40:31 +05303251 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003252
3253 /* Nothing to be done if the interface is not opened */
3254 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003255 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003256 return -ENODEV;
3257 }
3258
3259 /* Make sure the interface is marked as closed */
3260 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303261
Jeff Johnson16528362018-06-14 12:34:16 -07003262 mac_handle = hdd_ctx->mac_handle;
3263
Mukul Sharmad16c2022017-07-25 18:56:12 +05303264 hdd_debug("Disabling Auto Power save timer");
3265 sme_ps_disable_auto_ps_timer(
Jeff Johnson16528362018-06-14 12:34:16 -07003266 mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08003267 adapter->vdev_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303268
3269 /*
3270 * Disable TX on the interface, after this hard_start_xmit() will not
3271 * be called on that interface
3272 */
Dustin Browna7bb6ae2018-08-16 16:51:50 -07003273 hdd_debug("Disabling queues, adapter device mode: %s(%d)",
Dustin Brown458027c2018-10-19 12:26:27 -07003274 qdf_opmode_str(adapter->device_mode), adapter->device_mode);
Kabilan Kannan8dac3502017-10-30 12:40:27 -07003275
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303276 wlan_hdd_netif_queue_control(adapter,
3277 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3278 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003279
Arunk Khandavalli40943af2017-05-15 19:25:34 +05303280 if (adapter->device_mode == QDF_STA_MODE)
3281 hdd_lpass_notify_stop(hdd_ctx);
3282
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003283 /*
Naveen Rawat286def52016-09-23 15:38:02 -07003284 * NAN data interface is different in some sense. The traffic on NDI is
3285 * bursty in nature and depends on the need to transfer. The service
3286 * layer may down the interface after the usage and up again when
3287 * required. In some sense, the NDI is expected to be available
3288 * (like SAP) iface until NDI delete request is issued by the service
3289 * layer. Skip BSS termination and adapter deletion for NAN Data
3290 * interface (NDI).
3291 */
3292 if (WLAN_HDD_IS_NDI(adapter))
3293 return 0;
3294
3295 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003296 * The interface is marked as down for outside world (aka kernel)
3297 * But the driver is pretty much alive inside. The driver needs to
3298 * tear down the existing connection on the netdev (session)
3299 * cleanup the data pipes and wait until the control plane is stabilized
3300 * for this interface. The call also needs to wait until the above
3301 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003302 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003303 * That is intentional to be able to scan if it is a STA/P2P interface
3304 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08003305 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003306
3307 /* DeInit the adapter. This ensures datapath cleanup as well */
3308 hdd_deinit_adapter(hdd_ctx, adapter, true);
3309
Dustin Brown4c663222018-10-23 14:19:36 -07003310 if (!hdd_is_any_interface_open(hdd_ctx))
3311 hdd_psoc_idle_timer_start(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05303312
Dustin Browne74003f2018-03-14 12:51:58 -07003313 hdd_exit();
Dustin Brown4c663222018-10-23 14:19:36 -07003314
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003315 return 0;
3316}
3317
3318/**
3319 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3320 * @dev: pointer to net_device structure
3321 *
3322 * This is called in response to ifconfig down
3323 *
3324 * Return: 0 for success and error number for failure
3325 */
Dustin Brown0e1e1622019-01-17 11:00:22 -08003326static int hdd_stop(struct net_device *net_dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003327{
Dustin Brown0e1e1622019-01-17 11:00:22 -08003328 int errno;
3329 struct osif_vdev_sync *vdev_sync;
3330
3331 errno = osif_vdev_sync_trans_start(net_dev, &vdev_sync);
3332 if (errno)
3333 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003334
Dustin Brown0e1e1622019-01-17 11:00:22 -08003335 errno = __hdd_stop(net_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003336
Dustin Brown0e1e1622019-01-17 11:00:22 -08003337 osif_vdev_sync_trans_stop(vdev_sync);
3338
3339 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003340}
3341
3342/**
Dustin Brown96b98dd2019-03-06 12:39:37 -08003343 * hdd_uninit() - HDD uninit function
3344 * @dev: Pointer to net_device structure
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003345 *
3346 * This is called during the netdev unregister to uninitialize all data
3347 * associated with the device
3348 *
Dustin Brown96b98dd2019-03-06 12:39:37 -08003349 * This function must be protected by a transition
3350 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003351 * Return: None
3352 */
Dustin Brown96b98dd2019-03-06 12:39:37 -08003353static void hdd_uninit(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003354{
Jeff Johnson9d295242017-08-29 14:39:48 -07003355 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003356 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003357
Dustin Brownfdf17c12018-03-14 12:55:34 -07003358 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003359
Dustin Brown96b98dd2019-03-06 12:39:37 -08003360 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
3361 hdd_err("Invalid magic");
3362 goto exit;
3363 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003364
Dustin Brown96b98dd2019-03-06 12:39:37 -08003365 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3366 if (!hdd_ctx) {
3367 hdd_err("NULL hdd_ctx");
3368 goto exit;
3369 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003370
Dustin Brown96b98dd2019-03-06 12:39:37 -08003371 if (dev != adapter->dev)
3372 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003373
Dustin Brown96b98dd2019-03-06 12:39:37 -08003374 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003375
Dustin Brown96b98dd2019-03-06 12:39:37 -08003376 /* after uninit our adapter structure will no longer be valid */
3377 adapter->dev = NULL;
3378 adapter->magic = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003379
Dustin Brown96b98dd2019-03-06 12:39:37 -08003380exit:
Dustin Browne74003f2018-03-14 12:51:58 -07003381 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003382}
3383
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003384static int hdd_open_cesium_nl_sock(void)
3385{
3386#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3387 struct netlink_kernel_cfg cfg = {
3388 .groups = WLAN_NLINK_MCAST_GRP_ID,
3389 .input = NULL
3390 };
3391#endif
3392 int ret = 0;
3393
3394#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3395 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3396#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3397 THIS_MODULE,
3398#endif
3399 &cfg);
3400#else
3401 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3402 WLAN_NLINK_MCAST_GRP_ID,
3403 NULL, NULL, THIS_MODULE);
3404#endif
3405
Jeff Johnsond36fa332019-03-18 13:42:25 -07003406 if (!cesium_nl_srv_sock) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003407 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003408 ret = -ECONNREFUSED;
3409 }
3410
3411 return ret;
3412}
3413
3414static void hdd_close_cesium_nl_sock(void)
3415{
Jeff Johnsond36fa332019-03-18 13:42:25 -07003416 if (cesium_nl_srv_sock) {
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003417 netlink_kernel_release(cesium_nl_srv_sock);
3418 cesium_nl_srv_sock = NULL;
3419 }
3420}
3421
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303422void hdd_update_dynamic_mac(struct hdd_context *hdd_ctx,
3423 struct qdf_mac_addr *curr_mac_addr,
3424 struct qdf_mac_addr *new_mac_addr)
3425{
3426 uint8_t i;
3427
3428 hdd_enter();
3429
3430 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303431 if (!qdf_mem_cmp(
3432 curr_mac_addr->bytes,
3433 &hdd_ctx->dynamic_mac_list[i].dynamic_mac.bytes[0],
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303434 sizeof(struct qdf_mac_addr))) {
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303435 qdf_mem_copy(&hdd_ctx->dynamic_mac_list[i].dynamic_mac,
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303436 new_mac_addr->bytes,
3437 sizeof(struct qdf_mac_addr));
3438 break;
3439 }
3440 }
3441
3442 hdd_exit();
3443}
3444
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003445/**
3446 * __hdd_set_mac_address() - set the user specified mac address
3447 * @dev: Pointer to the net device.
3448 * @addr: Pointer to the sockaddr.
3449 *
3450 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003451 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003452 *
3453 * Return: 0 for success, non zero for failure
3454 */
3455static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3456{
Jeff Johnson9d295242017-08-29 14:39:48 -07003457 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303458 struct hdd_adapter *adapter_temp;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003459 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003460 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303461 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003462 int ret;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303463 struct qdf_mac_addr mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003464
Dustin Brownfdf17c12018-03-14 12:55:34 -07003465 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003466
Hanumanth Reddy Pothula5c7a7812018-03-09 12:55:32 +05303467 if (netif_running(dev)) {
3468 hdd_err("On iface up, set mac address change isn't supported");
3469 return -EBUSY;
3470 }
3471
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003472 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3473 ret = wlan_hdd_validate_context(hdd_ctx);
3474 if (0 != ret)
3475 return ret;
3476
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303477 qdf_mem_copy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303478 adapter_temp = hdd_get_adapter_by_macaddr(hdd_ctx, mac_addr.bytes);
3479 if (adapter_temp) {
3480 if (!qdf_str_cmp(adapter_temp->dev->name, dev->name))
3481 return 0;
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07003482 hdd_err("%s adapter exist with same address " QDF_MAC_ADDR_STR,
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303483 adapter_temp->dev->name,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07003484 QDF_MAC_ADDR_ARRAY(mac_addr.bytes));
Ashish Kumar Dhanotiyaf974f332018-04-19 16:03:15 +05303485 return -EINVAL;
3486 }
3487
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05303488 qdf_ret_status = wlan_hdd_validate_mac_address(&mac_addr);
3489 if (QDF_IS_STATUS_ERROR(qdf_ret_status))
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303490 return -EINVAL;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303491
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07003492 hdd_info("Changing MAC to " QDF_MAC_ADDR_STR " of the interface %s ",
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07003493 QDF_MAC_ADDR_ARRAY(mac_addr.bytes), dev->name);
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303494
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303495 hdd_update_dynamic_mac(hdd_ctx, &adapter->mac_addr, &mac_addr);
Jeff Johnson1e851a12017-10-28 14:36:12 -07003496 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003497 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3498
Dustin Browne74003f2018-03-14 12:51:58 -07003499 hdd_exit();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303500 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003501}
3502
3503/**
3504 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
Dustin Brown98f7c822019-03-06 12:25:49 -08003505 * function from SSR
3506 * @net_dev: pointer to net_device structure
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003507 * @addr: Pointer to the sockaddr
3508 *
3509 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003510 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003511 *
3512 * Return: 0 for success.
3513 */
Dustin Brown98f7c822019-03-06 12:25:49 -08003514static int hdd_set_mac_address(struct net_device *net_dev, void *addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003515{
Dustin Brown98f7c822019-03-06 12:25:49 -08003516 struct osif_vdev_sync *vdev_sync;
3517 int errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003518
Dustin Brown98f7c822019-03-06 12:25:49 -08003519 errno = osif_vdev_sync_op_start(net_dev, &vdev_sync);
3520 if (errno)
3521 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003522
Dustin Brown98f7c822019-03-06 12:25:49 -08003523 errno = __hdd_set_mac_address(net_dev, addr);
3524
3525 osif_vdev_sync_op_stop(vdev_sync);
3526
3527 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003528}
3529
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303530static uint8_t *wlan_hdd_get_derived_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003531{
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303532 int i, j;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003533
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303534 i = qdf_ffz(hdd_ctx->derived_intf_addr_mask);
3535 if (i < 0 || i >= hdd_ctx->num_derived_addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003536 return NULL;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303537 qdf_atomic_set_bit(i, &hdd_ctx->derived_intf_addr_mask);
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07003538 hdd_info("Assigning MAC from derived list" QDF_MAC_ADDR_STR,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07003539 QDF_MAC_ADDR_ARRAY(hdd_ctx->derived_mac_addr[i].bytes));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003540
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303541 /* Copy the mac in dynamic mac list at first free position */
3542 for (j = 0; j < QDF_MAX_CONCURRENCY_PERSONA; j++) {
3543 if (qdf_is_macaddr_zero(&hdd_ctx->
3544 dynamic_mac_list[j].dynamic_mac))
3545 break;
3546 }
3547 if (j == QDF_MAX_CONCURRENCY_PERSONA) {
3548 hdd_err("Max interfaces are up");
3549 return NULL;
3550 }
Dustin Brown61cc3932018-10-18 16:12:13 -07003551
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303552 qdf_mem_copy(&hdd_ctx->dynamic_mac_list[j].dynamic_mac.bytes,
3553 &hdd_ctx->derived_mac_addr[i].bytes,
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05303554 sizeof(struct qdf_mac_addr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303555 hdd_ctx->dynamic_mac_list[j].is_provisioned_mac = false;
3556 hdd_ctx->dynamic_mac_list[j].bit_position = i;
3557
3558 return hdd_ctx->derived_mac_addr[i].bytes;
3559}
3560
3561static uint8_t *wlan_hdd_get_provisioned_intf_addr(struct hdd_context *hdd_ctx)
3562{
3563 int i, j;
3564
3565 i = qdf_ffz(hdd_ctx->provisioned_intf_addr_mask);
3566 if (i < 0 || i >= hdd_ctx->num_provisioned_addr)
3567 return NULL;
3568 qdf_atomic_set_bit(i, &hdd_ctx->provisioned_intf_addr_mask);
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07003569 hdd_info("Assigning MAC from provisioned list" QDF_MAC_ADDR_STR,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07003570 QDF_MAC_ADDR_ARRAY(hdd_ctx->provisioned_mac_addr[i].bytes));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303571
3572 /* Copy the mac in dynamic mac list at first free position */
3573 for (j = 0; j < QDF_MAX_CONCURRENCY_PERSONA; j++) {
3574 if (qdf_is_macaddr_zero(&hdd_ctx->
3575 dynamic_mac_list[j].dynamic_mac))
3576 break;
3577 }
3578 if (j == QDF_MAX_CONCURRENCY_PERSONA) {
3579 hdd_err("Max interfaces are up");
3580 return NULL;
3581 }
3582
3583 qdf_mem_copy(&hdd_ctx->dynamic_mac_list[j].dynamic_mac.bytes,
3584 &hdd_ctx->provisioned_mac_addr[i].bytes,
3585 sizeof(struct qdf_mac_addr));
3586 hdd_ctx->dynamic_mac_list[j].is_provisioned_mac = true;
3587 hdd_ctx->dynamic_mac_list[j].bit_position = i;
3588 return hdd_ctx->provisioned_mac_addr[i].bytes;
3589}
3590
3591uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx,
3592 enum QDF_OPMODE interface_type)
3593{
3594 uint8_t *mac_addr = NULL;
3595
3596 if (qdf_atomic_test_bit(interface_type,
3597 (unsigned long *)
3598 (&hdd_ctx->config->provisioned_intf_pool)))
3599 mac_addr = wlan_hdd_get_provisioned_intf_addr(hdd_ctx);
3600
3601 if ((!mac_addr) &&
3602 (qdf_atomic_test_bit(interface_type,
3603 (unsigned long *)
3604 (&hdd_ctx->config->derived_intf_pool))))
3605 mac_addr = wlan_hdd_get_derived_intf_addr(hdd_ctx);
3606
3607 if (!mac_addr)
3608 hdd_err("MAC is not available in both the lists");
3609 return mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003610}
3611
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003612void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3613 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003614{
3615 int i;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303616 int mac_pos_in_mask;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003617
Anurag Chouhan6d760662016-02-20 16:05:43 +05303618 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003619 if (!memcmp(releaseAddr,
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303620 hdd_ctx->dynamic_mac_list[i].dynamic_mac.bytes,
3621 QDF_MAC_ADDR_SIZE)) {
3622 mac_pos_in_mask =
3623 hdd_ctx->dynamic_mac_list[i].bit_position;
3624 if (hdd_ctx->dynamic_mac_list[i].is_provisioned_mac) {
3625 qdf_atomic_clear_bit(
3626 mac_pos_in_mask,
3627 &hdd_ctx->
3628 provisioned_intf_addr_mask);
3629 hdd_info("Releasing MAC from provisioned list");
3630 hdd_info(
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07003631 QDF_MAC_ADDR_STR,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07003632 QDF_MAC_ADDR_ARRAY(releaseAddr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303633 } else {
3634 qdf_atomic_clear_bit(
3635 mac_pos_in_mask, &hdd_ctx->
3636 derived_intf_addr_mask);
3637 hdd_info("Releasing MAC from derived list");
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07003638 hdd_info(QDF_MAC_ADDR_STR,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07003639 QDF_MAC_ADDR_ARRAY(releaseAddr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303640 }
3641 qdf_zero_macaddr(&hdd_ctx->
3642 dynamic_mac_list[i].dynamic_mac);
3643 hdd_ctx->dynamic_mac_list[i].is_provisioned_mac =
3644 false;
3645 hdd_ctx->dynamic_mac_list[i].bit_position = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003646 break;
3647 }
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303648
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003649 }
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05303650 if (i == QDF_MAX_CONCURRENCY_PERSONA)
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07003651 hdd_err("Releasing non existing MAC" QDF_MAC_ADDR_STR,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07003652 QDF_MAC_ADDR_ARRAY(releaseAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003653}
3654
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003655/**
3656 * __hdd_set_multicast_list() - set the multicast address list
3657 * @dev: Pointer to the WLAN device.
3658 * @skb: Pointer to OS packet (sk_buff).
3659 *
3660 * This funciton sets the multicast address list.
3661 *
3662 * Return: None
3663 */
3664static void __hdd_set_multicast_list(struct net_device *dev)
3665{
Jeff Johnson9d295242017-08-29 14:39:48 -07003666 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Dustin Brown0f874482018-06-13 14:39:22 -07003667 int i = 0, errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003668 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003669 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303670 struct pmo_mc_addr_list_params *mc_list_request = NULL;
Dustin Brown1dbefe62018-09-11 16:32:03 -07003671 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303672 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003673
Dustin Brownfdf17c12018-03-14 12:55:34 -07003674 hdd_enter_dev(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303675 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303676 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303677
Dustin Brown0f874482018-06-13 14:39:22 -07003678 errno = wlan_hdd_validate_context(hdd_ctx);
3679 if (errno)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303680 goto out;
3681
Dustin Brown0f874482018-06-13 14:39:22 -07003682 errno = hdd_validate_adapter(adapter);
3683 if (errno)
Dustin Brownc788acb2017-08-01 17:43:51 -07003684 goto out;
3685
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303686 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3687 hdd_err("%s: Driver module is closed", __func__);
Dustin Brown0f874482018-06-13 14:39:22 -07003688 goto out;
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303689 }
3690
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303691 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
Min Liu74a1a502018-10-10 19:59:07 +08003692 if (!mc_list_request)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303693 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003694
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303695 /* Delete already configured multicast address list */
3696 if (adapter->mc_addr_list.mc_cnt > 0) {
Dustin Brown0f874482018-06-13 14:39:22 -07003697 hdd_debug("clear previously configured MC address list");
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303698 hdd_disable_and_flush_mc_addr_list(adapter,
3699 pmo_mc_list_change_notify);
3700 }
3701
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003702 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003703 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303704 hdd_disable_and_flush_mc_addr_list(adapter,
3705 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003706 } else {
3707 mc_count = netdev_mc_count(dev);
Wu Gaod7dd6e42018-10-16 17:22:56 +08003708 if (mc_count > ucfg_pmo_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003709 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Wu Gaod7dd6e42018-10-16 17:22:56 +08003710 ucfg_pmo_max_mc_addr_supported(psoc));
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303711 hdd_disable_and_flush_mc_addr_list(adapter,
3712 pmo_mc_list_change_notify);
stonezdf2bdfd2018-11-20 14:45:06 +08003713 adapter->mc_addr_list.mc_cnt = 0;
Dustin Brown0f874482018-06-13 14:39:22 -07003714 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003715 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003716 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07003717 hdd_debug("ha_addr[%d] "QDF_MAC_ADDR_STR,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07003718 i, QDF_MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003719 if (i == mc_count)
3720 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303721 memset(&(mc_list_request->mc_addr[i].bytes),
3722 0, ETH_ALEN);
3723 memcpy(&(mc_list_request->mc_addr[i].bytes),
3724 ha->addr, ETH_ALEN);
Dustin Brown0f874482018-06-13 14:39:22 -07003725 hdd_debug("mlist[%d] = %pM", i,
3726 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003727 i++;
3728 }
3729 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303730
stonezdf2bdfd2018-11-20 14:45:06 +08003731 adapter->mc_addr_list.mc_cnt = mc_count;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303732 mc_list_request->psoc = psoc;
Jeff Johnson5a6fc962019-02-04 14:20:25 -08003733 mc_list_request->vdev_id = adapter->vdev_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303734 mc_list_request->count = mc_count;
Dustin Brown0f874482018-06-13 14:39:22 -07003735
3736 errno = hdd_cache_mc_addr_list(mc_list_request);
3737 if (errno) {
3738 hdd_err("Failed to cache MC address list for vdev %u; errno:%d",
Jeff Johnson5a6fc962019-02-04 14:20:25 -08003739 adapter->vdev_id, errno);
Dustin Brown0f874482018-06-13 14:39:22 -07003740 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003741 }
Dustin Brown0f874482018-06-13 14:39:22 -07003742
3743 hdd_enable_mc_addr_filtering(adapter, pmo_mc_list_change_notify);
3744
3745free_req:
3746 qdf_mem_free(mc_list_request);
3747
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303748out:
Dustin Browne74003f2018-03-14 12:51:58 -07003749 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003750}
3751
3752/**
3753 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
Dustin Brown98f7c822019-03-06 12:25:49 -08003754 * @net_dev: pointer to net_device
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003755 *
3756 * Return: none
3757 */
Dustin Brown98f7c822019-03-06 12:25:49 -08003758static void hdd_set_multicast_list(struct net_device *net_dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003759{
Dustin Brown98f7c822019-03-06 12:25:49 -08003760 struct osif_vdev_sync *vdev_sync;
3761
3762 if (osif_vdev_sync_op_start(net_dev, &vdev_sync))
3763 return;
3764
3765 __hdd_set_multicast_list(net_dev);
3766
3767 osif_vdev_sync_op_stop(vdev_sync);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003768}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003769
Subrat Dash5f36fbe2019-02-12 16:28:14 +05303770#ifdef WLAN_FEATURE_TSF_PTP
3771static const struct ethtool_ops wlan_ethtool_ops = {
3772 .get_ts_info = wlan_get_ts_info,
3773};
3774#endif
3775
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003776static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003777 .ndo_open = hdd_open,
3778 .ndo_stop = hdd_stop,
3779 .ndo_uninit = hdd_uninit,
3780 .ndo_start_xmit = hdd_hard_start_xmit,
3781 .ndo_tx_timeout = hdd_tx_timeout,
3782 .ndo_get_stats = hdd_get_stats,
3783 .ndo_do_ioctl = hdd_ioctl,
3784 .ndo_set_mac_address = hdd_set_mac_address,
3785 .ndo_select_queue = hdd_select_queue,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003786 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003787};
3788
Nirav Shah73713f72018-05-17 14:50:41 +05303789#ifdef FEATURE_MONITOR_MODE_SUPPORT
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003790/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003791static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003792 .ndo_open = hdd_mon_open,
3793 .ndo_stop = hdd_stop,
3794 .ndo_get_stats = hdd_get_stats,
3795};
3796
Subrat Dash5f36fbe2019-02-12 16:28:14 +05303797#ifdef WLAN_FEATURE_TSF_PTP
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003798/**
3799 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003800 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003801 * Return: None
3802 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003803void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003804{
Subrat Dash5f36fbe2019-02-12 16:28:14 +05303805 if (cds_get_conparam() == QDF_GLOBAL_MONITOR_MODE) {
3806 dev->netdev_ops = &wlan_mon_drv_ops;
3807 } else {
3808 dev->netdev_ops = &wlan_drv_ops;
3809 dev->ethtool_ops = &wlan_ethtool_ops;
3810 }
3811}
3812#else
3813void hdd_set_station_ops(struct net_device *dev)
3814{
3815 if (cds_get_conparam() == QDF_GLOBAL_MONITOR_MODE)
Jeff Johnson5505db82017-11-02 21:19:23 -07003816 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003817 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003818 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003819}
Subrat Dash5f36fbe2019-02-12 16:28:14 +05303820
3821#endif
3822#else
3823#ifdef WLAN_FEATURE_TSF_PTP
3824void hdd_set_station_ops(struct net_device *dev)
3825{
3826 dev->netdev_ops = &wlan_drv_ops;
3827 dev->ethtool_ops = &wlan_ethtool_ops;
3828}
Nirav Shah73713f72018-05-17 14:50:41 +05303829#else
3830void hdd_set_station_ops(struct net_device *dev)
3831{
3832 dev->netdev_ops = &wlan_drv_ops;
3833}
3834#endif
Subrat Dash5f36fbe2019-02-12 16:28:14 +05303835#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003836
3837/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003838 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3839 * @hdd_ctx: global hdd context
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003840 * @mac_addr: mac address to assign to the interface
Ryan Hsu07495ea2016-01-21 15:25:39 -08003841 * @name: User-visible name of the interface
3842 *
3843 * hdd adapter pointer would point to the netdev->priv space, this function
Jeff Johnson62018292018-05-06 16:18:35 -07003844 * would retrieve the pointer, and setup the hdd adapter configuration.
Ryan Hsu07495ea2016-01-21 15:25:39 -08003845 *
3846 * Return: the pointer to hdd adapter, otherwise NULL
3847 */
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003848static struct hdd_adapter *
3849hdd_alloc_station_adapter(struct hdd_context *hdd_ctx, tSirMacAddr mac_addr,
3850 unsigned char name_assign_type, const char *name)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003851{
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003852 struct net_device *dev;
3853 struct hdd_adapter *adapter;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003854 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303855 QDF_STATUS qdf_status;
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003856
3857 /* cfg80211 initialization and registration */
3858 dev = alloc_netdev_mq(sizeof(*adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003859#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003860 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003861#endif
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003862 (cds_get_conparam() == QDF_GLOBAL_MONITOR_MODE ?
3863 hdd_mon_mode_ether_setup : ether_setup),
3864 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003865
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003866 if (!dev) {
3867 hdd_err("Failed to allocate new net_device '%s'", name);
3868 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003869 }
3870
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003871 adapter = netdev_priv(dev);
3872
3873 qdf_mem_zero(adapter, sizeof(*adapter));
3874 sta_ctx = &adapter->session.station;
Jeff Johnson0a082d92019-03-04 12:25:49 -08003875 qdf_mem_set(sta_ctx->conn_info.sta_id,
3876 sizeof(sta_ctx->conn_info.sta_id),
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003877 HDD_WLAN_INVALID_STA_ID);
3878 adapter->dev = dev;
3879 adapter->hdd_ctx = hdd_ctx;
3880 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson912b1bb2019-03-06 10:12:36 -08003881 adapter->vdev_id = WLAN_UMAC_VDEV_ID_MAX;
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003882
3883 qdf_status = qdf_event_create(&adapter->qdf_session_open_event);
3884 if (QDF_IS_STATUS_ERROR(qdf_status))
3885 goto free_net_dev;
3886
3887 qdf_status = qdf_event_create(&adapter->qdf_session_close_event);
3888 if (QDF_IS_STATUS_ERROR(qdf_status))
3889 goto free_net_dev;
3890
3891 adapter->offloads_configured = false;
3892 adapter->is_link_up_service_needed = false;
3893 adapter->disconnection_in_progress = false;
3894 adapter->send_mode_change = true;
3895
3896 /* Init the net_device structure */
3897 strlcpy(dev->name, name, IFNAMSIZ);
3898
3899 qdf_mem_copy(dev->dev_addr, mac_addr, sizeof(tSirMacAddr));
3900 qdf_mem_copy(adapter->mac_addr.bytes, mac_addr, sizeof(tSirMacAddr));
3901 dev->watchdog_timeo = HDD_TX_TIMEOUT;
3902
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003903 hdd_set_station_ops(adapter->dev);
3904
3905 hdd_dev_setup_destructor(dev);
3906 dev->ieee80211_ptr = &adapter->wdev;
3907 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
3908 adapter->wdev.wiphy = hdd_ctx->wiphy;
3909 adapter->wdev.netdev = dev;
3910
3911 /* set dev's parent to underlying device */
3912 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
3913 hdd_wmm_init(adapter);
3914 spin_lock_init(&adapter->pause_map_lock);
3915 adapter->start_time = qdf_system_ticks();
3916 adapter->last_time = adapter->start_time;
3917
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003918 return adapter;
Dustin Brownef5fc2d2018-09-11 11:02:00 -07003919
3920free_net_dev:
3921 free_netdev(adapter->dev);
3922
3923 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003924}
3925
Jeff Johnson9d295242017-08-29 14:39:48 -07003926static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003927{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003928 struct net_device *dev = adapter->dev;
3929 int ret;
3930
Dustin Brown491d54b2018-03-14 12:39:11 -07003931 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003932
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003933 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003934 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3935
3936 ret = dev_alloc_name(dev, dev->name);
3937 if (ret < 0) {
3938 hdd_err(
3939 "unable to get dev name: %s, err = 0x%x",
3940 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303941 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003942 }
3943 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003944
3945 ret = register_netdevice(dev);
3946 if (ret) {
3947 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3948 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303949 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003950 }
3951 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003952 ret = register_netdev(dev);
3953 if (ret) {
3954 hdd_err("register_netdev(%s) failed, err = 0x%x",
3955 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303956 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003957 }
3958 }
3959 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3960
Dustin Browne74003f2018-03-14 12:51:58 -07003961 hdd_exit();
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003962
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303963 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003964}
3965
Jeff Johnson55d2ab42019-03-06 11:43:49 -08003966QDF_STATUS hdd_sme_open_session_callback(uint8_t vdev_id,
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05303967 QDF_STATUS qdf_status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003968{
Krunal Sonib51eec72017-11-20 21:53:01 -08003969 struct hdd_adapter *adapter;
3970 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003971
Krunal Sonib51eec72017-11-20 21:53:01 -08003972 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3973 if (!hdd_ctx) {
3974 hdd_err("Invalid HDD_CTX");
3975 return QDF_STATUS_E_FAILURE;
3976 }
3977
Jeff Johnson55d2ab42019-03-06 11:43:49 -08003978 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Jeff Johnsond36fa332019-03-18 13:42:25 -07003979 if (!adapter) {
Jeff Johnson55d2ab42019-03-06 11:43:49 -08003980 hdd_err("NULL adapter for %d", vdev_id);
Krunal Sonib51eec72017-11-20 21:53:01 -08003981 return QDF_STATUS_E_INVAL;
3982 }
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05303983
3984 if (qdf_status == QDF_STATUS_SUCCESS)
3985 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3986
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303987 qdf_event_set(&adapter->qdf_session_open_event);
Jeff Johnson5a6fc962019-02-04 14:20:25 -08003988 hdd_debug("session %d opened", adapter->vdev_id);
Krunal Sonib51eec72017-11-20 21:53:01 -08003989
3990 return QDF_STATUS_SUCCESS;
3991}
3992
Jeff Johnson55d2ab42019-03-06 11:43:49 -08003993QDF_STATUS hdd_sme_close_session_callback(uint8_t vdev_id)
Krunal Sonib51eec72017-11-20 21:53:01 -08003994{
3995 struct hdd_adapter *adapter;
3996 struct hdd_context *hdd_ctx;
3997
3998 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3999 if (!hdd_ctx) {
4000 hdd_err("Invalid HDD_CTX");
4001 return QDF_STATUS_E_FAILURE;
4002 }
4003
Jeff Johnson55d2ab42019-03-06 11:43:49 -08004004 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Jeff Johnsond36fa332019-03-18 13:42:25 -07004005 if (!adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004006 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304007 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004008 }
4009
4010 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004011 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304012 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004013 }
4014
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004015 /*
4016 * For NAN Data interface, the close session results in the final
4017 * indication to the userspace
4018 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07004019 if (adapter->device_mode == QDF_NDI_MODE)
4020 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004021
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004022 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
4023
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004024 /*
4025 * We can be blocked while waiting for scheduled work to be
4026 * flushed, and the adapter structure can potentially be freed, in
4027 * which case the magic will have been reset. So make sure the
4028 * magic is still good, and hence the adapter structure is still
4029 * valid, before signaling completion
4030 */
4031 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304032 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004033
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304034 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004035}
4036
Jeff Johnson9d295242017-08-29 14:39:48 -07004037int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004038{
Min Liu8c5d99e2018-09-10 17:18:44 +08004039 struct wlan_objmgr_vdev *vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07004040 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004041
Min Liu8c5d99e2018-09-10 17:18:44 +08004042 vdev = hdd_objmgr_get_vdev(adapter);
4043 if (!vdev)
4044 return -EINVAL;
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07004045
Min Liu8c5d99e2018-09-10 17:18:44 +08004046 status = pmo_vdev_ready(vdev);
4047 if (QDF_IS_STATUS_ERROR(status)) {
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05304048 hdd_objmgr_put_vdev(vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07004049 return qdf_status_to_os_return(status);
Min Liu8c5d99e2018-09-10 17:18:44 +08004050 }
4051
4052 status = ucfg_reg_11d_vdev_created_update(vdev);
4053 if (QDF_IS_STATUS_ERROR(status)) {
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05304054 hdd_objmgr_put_vdev(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08004055 return qdf_status_to_os_return(status);
4056 }
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07004057
4058 if (wma_capability_enhanced_mcast_filter())
Min Liu8c5d99e2018-09-10 17:18:44 +08004059 status = ucfg_pmo_enhanced_mc_filter_enable(vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07004060 else
Min Liu8c5d99e2018-09-10 17:18:44 +08004061 status = ucfg_pmo_enhanced_mc_filter_disable(vdev);
4062
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05304063 hdd_objmgr_put_vdev(vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07004064
4065 return qdf_status_to_os_return(status);
4066}
4067
Jeff Johnson9d295242017-08-29 14:39:48 -07004068int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07004069{
4070 QDF_STATUS status;
Dustin Brown2da29eb2018-07-13 14:23:12 -07004071 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004072 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004073 uint8_t vdev_id;
Min Liu8c5d99e2018-09-10 17:18:44 +08004074 struct wlan_objmgr_vdev *vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07004075
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004076 vdev_id = adapter->vdev_id;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004077 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004078
4079 /* vdev created sanity check */
4080 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Dustin Brown2da29eb2018-07-13 14:23:12 -07004081 hdd_err("vdev %u does not exist", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004082 return -EINVAL;
4083 }
Dustin Brown2da29eb2018-07-13 14:23:12 -07004084
Abhishek Singh628bb6f2019-03-26 14:52:40 +05304085 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4086
4087 /*
4088 * if this is the last active connection check & stop the
4089 * opportunistic timer first
4090 */
4091 if ((policy_mgr_get_connection_count(hdd_ctx->psoc) == 1 &&
4092 policy_mgr_mode_specific_connection_count(hdd_ctx->psoc,
4093 policy_mgr_convert_device_mode_to_qdf_type(
4094 adapter->device_mode), NULL) == 1) ||
4095 !policy_mgr_get_connection_count(hdd_ctx->psoc))
4096 policy_mgr_check_and_stop_opportunistic_timer(hdd_ctx->psoc,
4097 adapter->vdev_id);
4098
Min Liu8c5d99e2018-09-10 17:18:44 +08004099 vdev = hdd_objmgr_get_vdev(adapter);
4100 if (!vdev)
4101 return -EINVAL;
Ashish Kumar Dhanotiya68ee2e42018-11-19 21:15:14 +05304102
4103 ucfg_pmo_del_wow_pattern(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08004104 status = ucfg_reg_11d_vdev_delete_update(vdev);
Abhishek Singh935e4772018-11-21 14:14:10 +05304105 ucfg_scan_vdev_set_disable(vdev, REASON_VDEV_DOWN);
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05304106 hdd_objmgr_put_vdev(vdev);
Yue Maf9782842017-05-08 12:49:49 -07004107
Dustin Brownd28772b2017-03-17 14:16:07 -07004108 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304109 qdf_event_reset(&adapter->qdf_session_close_event);
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004110 status = sme_close_session(hdd_ctx->mac_handle, adapter->vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004111 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Brown2da29eb2018-07-13 14:23:12 -07004112 hdd_err("failed to close sme session; status:%d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08004113 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07004114 }
4115
4116 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304117 status = qdf_wait_for_event_completion(
4118 &adapter->qdf_session_close_event,
Abhishek Singh13bf0ce2018-10-24 14:26:14 +05304119 SME_CMD_VDEV_CREATE_DELETE_TIMEOUT);
Dustin Brown2da29eb2018-07-13 14:23:12 -07004120
4121 if (QDF_IS_STATUS_ERROR(status)) {
4122 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
4123
Dustin Brownd28772b2017-03-17 14:16:07 -07004124 if (adapter->device_mode == QDF_NDI_MODE)
4125 hdd_ndp_session_end_handler(adapter);
Dustin Brown2da29eb2018-07-13 14:23:12 -07004126
4127 if (status == QDF_STATUS_E_TIMEOUT)
4128 hdd_err("timed out waiting for sme close session");
4129 else if (adapter->qdf_session_close_event.force_set)
4130 hdd_info("SSR occurred during sme close session");
4131 else
4132 hdd_err("failed to wait for sme close session; status:%u",
4133 status);
Dustin Brownd28772b2017-03-17 14:16:07 -07004134 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08004135
Yue Maf9782842017-05-08 12:49:49 -07004136release_vdev:
Jiachao Wu2c42c222018-01-15 18:13:19 +08004137
Sandeep Puligillaef415362017-08-30 16:37:13 -07004138 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08004139 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07004140 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08004141 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07004142 return errno;
4143 }
4144
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004145 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004146
4147 return 0;
4148}
4149
Krunal Sonib51eec72017-11-20 21:53:01 -08004150static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
4151 struct sme_session_params *session_param,
Jeff Johnson6a18c962018-07-01 09:09:37 -07004152 csr_roam_complete_cb callback,
Krunal Sonib51eec72017-11-20 21:53:01 -08004153 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07004154{
Dustin Brownd28772b2017-03-17 14:16:07 -07004155 uint32_t type;
4156 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08004157 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07004158
4159 /* determine vdev (sub)type */
4160 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304161 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07004162 hdd_err("failed to get vdev type: %d", status);
4163 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004164 }
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004165 session_param->sme_session_id = adapter->vdev_id;
Krunal Sonib51eec72017-11-20 21:53:01 -08004166 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
4167 session_param->type_of_persona = type;
4168 session_param->subtype_of_persona = sub_type;
4169 session_param->session_open_cb = hdd_sme_open_session_callback;
4170 session_param->session_close_cb = hdd_sme_close_session_callback;
4171 session_param->callback = callback;
4172 session_param->callback_ctx = callback_ctx;
4173
4174 return 0;
4175}
4176
gaurank kathpalia6c4b50c2019-02-28 14:07:48 +05304177void
gaurank kathpalia78af1932018-10-27 20:33:10 +05304178hdd_store_nss_chains_cfg_in_vdev(struct hdd_adapter *adapter)
4179{
4180 struct wlan_mlme_nss_chains vdev_ini_cfg;
4181 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4182
gaurank kathpaliab414bce2018-11-09 18:44:46 +05304183 /* Populate the nss chain params from ini for this vdev type */
gaurank kathpalia78af1932018-10-27 20:33:10 +05304184 sme_populate_nss_chain_params(hdd_ctx->mac_handle, &vdev_ini_cfg,
4185 adapter->device_mode,
4186 hdd_ctx->num_rf_chains);
gaurank kathpaliab414bce2018-11-09 18:44:46 +05304187
4188 /* Store the nss chain config into the vdev */
4189 sme_store_nss_chains_cfg_in_vdev(adapter->vdev, &vdev_ini_cfg);
gaurank kathpalia78af1932018-10-27 20:33:10 +05304190}
gaurank kathpalia6982d472018-10-31 21:54:15 +05304191
4192bool hdd_is_vdev_in_conn_state(struct hdd_adapter *adapter)
4193{
4194 switch (adapter->device_mode) {
4195 case QDF_STA_MODE:
4196 case QDF_P2P_CLIENT_MODE:
4197 case QDF_P2P_DEVICE_MODE:
4198 return hdd_conn_is_connected(
4199 WLAN_HDD_GET_STATION_CTX_PTR(adapter));
4200 case QDF_SAP_MODE:
4201 case QDF_P2P_GO_MODE:
4202 return (test_bit(SOFTAP_BSS_STARTED,
4203 &adapter->event_flags));
4204 default:
4205 hdd_err("Device mode %d invalid", adapter->device_mode);
4206 return 0;
4207 }
4208
4209 return 0;
4210}
4211
Krunal Sonib51eec72017-11-20 21:53:01 -08004212int hdd_vdev_create(struct hdd_adapter *adapter,
Jeff Johnson6a18c962018-07-01 09:09:37 -07004213 csr_roam_complete_cb callback, void *ctx)
Krunal Sonib51eec72017-11-20 21:53:01 -08004214{
4215 QDF_STATUS status;
4216 int errno;
Karthik Kantamneni9180c752018-11-14 12:14:17 +05304217 bool bval;
Krunal Sonib51eec72017-11-20 21:53:01 -08004218 struct hdd_context *hdd_ctx;
4219 struct sme_session_params sme_session_params = {0};
Min Liu8c5d99e2018-09-10 17:18:44 +08004220 struct wlan_objmgr_vdev *vdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004221
4222 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07004223
4224 /* do vdev create via objmgr */
4225 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown07901ec2018-09-07 11:02:41 -07004226 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07004227 if (errno) {
4228 hdd_err("failed to create objmgr vdev: %d", errno);
4229 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004230 }
Dustin Brownd28772b2017-03-17 14:16:07 -07004231
4232 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304233 status = qdf_event_reset(&adapter->qdf_session_open_event);
4234 if (QDF_STATUS_SUCCESS != status) {
4235 hdd_err("failed to reinit session open event");
4236 return -EINVAL;
4237 }
Krunal Sonib51eec72017-11-20 21:53:01 -08004238 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
4239 callback, ctx);
4240 if (errno) {
4241 hdd_err("failed to populating SME params");
4242 goto objmgr_vdev_destroy_procedure;
4243 }
Jeff Johnson16528362018-06-14 12:34:16 -07004244 status = sme_open_session(hdd_ctx->mac_handle, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07004245 if (QDF_IS_STATUS_ERROR(status)) {
4246 hdd_err("failed to open sme session: %d", status);
4247 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07004248 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004249 }
4250
4251 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304252 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
Abhishek Singh13bf0ce2018-10-24 14:26:14 +05304253 SME_CMD_VDEV_CREATE_DELETE_TIMEOUT);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304254 if (QDF_STATUS_SUCCESS != status) {
4255 if (adapter->qdf_session_open_event.force_set) {
4256 /*
4257 * SSR/PDR has caused shutdown, which has forcefully
4258 * set the event. Return without the closing session.
4259 */
Jeff Johnson912b1bb2019-03-06 10:12:36 -08004260 adapter->vdev_id = WLAN_UMAC_VDEV_ID_MAX;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304261 hdd_err("Session open event forcefully set");
4262 return -EINVAL;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304263 }
Jeff Johnsonc66d3102018-02-28 11:58:26 -08004264
4265 if (QDF_STATUS_E_TIMEOUT == status)
4266 hdd_err("Session failed to open within timeout period");
4267 else
4268 hdd_err("Failed to wait for session open event(status-%d)",
4269 status);
4270 errno = -ETIMEDOUT;
4271 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
4272 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004273 }
4274
Pragaspathi Thilagaraj3551caa2018-09-26 15:52:56 +05304275 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
4276 hdd_err("Session failed to open due to vdev create failure");
4277 errno = -EINVAL;
4278 goto objmgr_vdev_destroy_procedure;
4279 }
4280
Dustin Brownd28772b2017-03-17 14:16:07 -07004281 /* firmware ready for component communication, raise vdev_ready event */
4282 errno = hdd_vdev_ready(adapter);
4283 if (errno) {
4284 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07004285 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004286 }
4287
Naveen Rawat2b430892018-03-13 13:58:18 -07004288 if (adapter->device_mode == QDF_STA_MODE) {
Karthik Kantamneni9180c752018-11-14 12:14:17 +05304289 bval = false;
4290 status = ucfg_mlme_get_rtt_mac_randomization(hdd_ctx->psoc,
4291 &bval);
4292 if (QDF_IS_STATUS_ERROR(status))
4293 hdd_err("unable to get RTT MAC randomization value");
4294
4295 hdd_debug("setting RTT mac randomization param: %d", bval);
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004296 errno = sme_cli_set_command(adapter->vdev_id,
Naveen Rawat2b430892018-03-13 13:58:18 -07004297 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_INITIATOR_RANDOM_MAC,
Karthik Kantamneni9180c752018-11-14 12:14:17 +05304298 bval,
Naveen Rawat2b430892018-03-13 13:58:18 -07004299 VDEV_CMD);
4300 if (0 != errno)
4301 hdd_err("RTT mac randomization param set failed %d",
4302 errno);
4303 }
4304
Bala Venkatesh110b03e2018-07-10 16:02:08 +05304305 if (adapter->device_mode == QDF_STA_MODE ||
Min Liu8c5d99e2018-09-10 17:18:44 +08004306 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
4307 vdev = hdd_objmgr_get_vdev(adapter);
4308 if (!vdev)
4309 goto hdd_vdev_destroy_procedure;
4310 wlan_vdev_set_max_peer_count(vdev, HDD_MAX_VDEV_PEER_COUNT);
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05304311 hdd_objmgr_put_vdev(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08004312 }
Bala Venkatesh110b03e2018-07-10 16:02:08 +05304313
gaurank kathpalia78af1932018-10-27 20:33:10 +05304314 hdd_store_nss_chains_cfg_in_vdev(adapter);
4315
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004316 hdd_info("vdev %d created successfully", adapter->vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004317
4318 return 0;
4319
4320 /*
4321 * Due to legacy constraints, we need to destroy in the same order as
4322 * create. So, split error handling into 2 cases to accommodate.
4323 */
4324
Krunal Soni4a020c72017-10-30 20:58:40 -07004325objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07004326 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07004327
4328 return errno;
4329
Krunal Soni4a020c72017-10-30 20:58:40 -07004330hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07004331 QDF_BUG(!hdd_vdev_destroy(adapter));
4332
4333 return errno;
4334}
4335
Jeff Johnson9d295242017-08-29 14:39:48 -07004336QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07004337{
Jeff Johnsonb9424862017-10-30 08:49:35 -07004338 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004339 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07004340 QDF_STATUS status;
4341 int ret_val;
Jeff Johnson16528362018-06-14 12:34:16 -07004342 mac_handle_t mac_handle;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304343 bool bval = false;
Dustin Brownd28772b2017-03-17 14:16:07 -07004344
Dustin Brownd28772b2017-03-17 14:16:07 -07004345 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -07004346 mac_handle = hdd_ctx->mac_handle;
4347 sme_set_curr_device_mode(mac_handle, adapter->device_mode);
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304348 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
4349 if (!QDF_IS_STATUS_SUCCESS(status))
4350 hdd_err("unable to get vht_enable2x2");
4351 sme_set_pdev_ht_vht_ies(mac_handle, bval);
4352
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004353 sme_set_vdev_ies_per_band(mac_handle, adapter->vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004354
Jeff Johnson7f2c5912018-03-23 11:42:28 -07004355 hdd_roam_profile_init(adapter);
4356 hdd_register_wext(adapter->dev);
4357
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07004358 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004359
Jeff Johnson0a082d92019-03-04 12:25:49 -08004360 qdf_mem_set(sta_ctx->conn_info.sta_id,
4361 sizeof(sta_ctx->conn_info.sta_id),
4362 HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05304363
Deepak Dhamdherea2785822016-11-17 01:17:45 -08004364 /* set fast roaming capability in sme session */
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004365 status = sme_config_fast_roaming(mac_handle, adapter->vdev_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05304366 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004367 /* Set the default operation channel */
Jeff Johnson8626e932019-02-27 18:35:22 -08004368 sta_ctx->conn_info.channel =
Vignesh Viswanathana0358ff2018-11-27 09:53:07 +05304369 hdd_ctx->config->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004370
4371 /* Make the default Auth Type as OPEN */
Jeff Johnson96e33512019-02-27 15:10:21 -08004372 sta_ctx->conn_info.auth_type = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004373
4374 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304375 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004376 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004377 status, status);
4378 goto error_init_txrx;
4379 }
4380
4381 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4382
4383 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304384 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004385 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004386 status, status);
4387 goto error_wmm_init;
4388 }
4389
4390 set_bit(WMM_INIT_DONE, &adapter->event_flags);
4391
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004392 ret_val = sme_cli_set_command(adapter->vdev_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004393 WMI_PDEV_PARAM_BURST_ENABLE,
Dundi Raviteja3aa01be2018-05-21 18:58:59 +05304394 HDD_ENABLE_SIFS_BURST_DEFAULT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004395 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07004396 if (ret_val)
4397 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004398
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05304399 /*
4400 * In case of USB tethering, LRO is disabled. If SSR happened
4401 * during that time, then as part of SSR init, do not enable
4402 * the LRO again. Keep the LRO state same as before SSR.
4403 */
jitiphil377bcc12018-10-05 19:46:08 +05304404 if (cdp_cfg_get(cds_get_context(QDF_MODULE_ID_SOC),
4405 cfg_dp_lro_enable) &&
4406 !(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07004407 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05304408
Rakshith Suresh Patkar9f5c5862019-02-04 16:23:02 +05304409 if (cdp_cfg_get(cds_get_context(QDF_MODULE_ID_SOC),
4410 cfg_dp_enable_ip_tcp_udp_checksum_offload))
4411 adapter->dev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
4412 adapter->dev->features |= NETIF_F_RXCSUM;
4413
4414 hdd_set_tso_flags(hdd_ctx, adapter->dev);
4415
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05304416 /* rcpi info initialization */
4417 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
4418
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304419 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004420
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004421error_wmm_init:
4422 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4423 hdd_deinit_tx_rx(adapter);
4424error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07004425 hdd_unregister_wext(adapter->dev);
Dustin Brownd28772b2017-03-17 14:16:07 -07004426 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004427
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004428 return status;
4429}
4430
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304431/**
Krunal Soni4a020c72017-10-30 20:58:40 -07004432 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304433 * @hdd_ctx: global hdd context
4434 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07004435 * @rtnl_held: Used to indicate whether or not the caller is holding
4436 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304437 *
4438 * This function De-initializes the STA/P2P/OCB adapter.
4439 *
4440 * Return: None.
4441 */
Krunal Soni4a020c72017-10-30 20:58:40 -07004442static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004443 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004444 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304445{
Dustin Brownfdf17c12018-03-14 12:55:34 -07004446 hdd_enter_dev(adapter->dev);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304447
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05304448 if (adapter->dev) {
4449 if (rtnl_held)
4450 adapter->dev->wireless_handlers = NULL;
4451 else {
4452 rtnl_lock();
4453 adapter->dev->wireless_handlers = NULL;
4454 rtnl_unlock();
4455 }
4456 }
4457
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304458 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
4459 hdd_deinit_tx_rx(adapter);
4460 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4461 }
4462
4463 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4464 hdd_wmm_adapter_close(adapter);
4465 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4466 }
4467
Krunal Sonib51eec72017-11-20 21:53:01 -08004468
Dustin Browne74003f2018-03-14 12:51:58 -07004469 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304470}
4471
Krunal Sonib51eec72017-11-20 21:53:01 -08004472void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
4473 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004474 bool rtnl_held)
4475{
Dustin Brown491d54b2018-03-14 12:39:11 -07004476 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304477
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004478 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004479 case QDF_STA_MODE:
4480 case QDF_P2P_CLIENT_MODE:
4481 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08004482 case QDF_IBSS_MODE:
4483 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004484 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004485 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004486 break;
4487 }
4488
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004489 case QDF_SAP_MODE:
4490 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004491 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004492 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004493 break;
4494 }
4495
4496 default:
4497 break;
4498 }
4499
Dustin Browne74003f2018-03-14 12:51:58 -07004500 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004501}
4502
Min Liu8c5d99e2018-09-10 17:18:44 +08004503static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx,
4504 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004505 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004506{
Jeff Johnson5505db82017-11-02 21:19:23 -07004507 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004508
4509 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07004510 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004511 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004512 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004513 return;
4514 }
4515
Alok Kumarb64650c2018-03-23 17:05:11 +05304516 hdd_nud_deinit_tracking(adapter);
4517 qdf_mutex_destroy(&adapter->disconnection_status_lock);
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05304518 hdd_apf_context_destroy(adapter);
Min Liu8c5d99e2018-09-10 17:18:44 +08004519 qdf_spinlock_destroy(&adapter->vdev_lock);
Alok Kumarb64650c2018-03-23 17:05:11 +05304520
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05304521 wlan_hdd_debugfs_csr_deinit(adapter);
Arunk Khandavallica56d4b2018-11-29 15:46:00 +05304522 if (adapter->device_mode == QDF_STA_MODE)
4523 hdd_sysfs_destroy_adapter_root_obj(adapter);
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05304524
Rajeev Kumardca5f812016-02-04 17:28:06 -08004525 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05304526
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004527 /*
4528 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
4529 * the driver is almost closed and cannot handle either control
4530 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004531 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
4532 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004533 * is not right. Setting this flag helps hdd_stop() to recognize that
4534 * the interface is closed and restricts any operations on that
4535 */
4536 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
4537
4538 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004539 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07004540 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004541 else
Jeff Johnson5505db82017-11-02 21:19:23 -07004542 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004543 /*
4544 * Note that the adapter is no longer valid at this point
4545 * since the memory has been reclaimed
4546 */
4547 }
4548}
4549
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004550static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07004551 tSirMacAddr mac_addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004552{
Jeff Johnson9d295242017-08-29 14:39:48 -07004553 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004554
Dustin Brown920397d2017-12-13 16:27:50 -08004555 hdd_for_each_adapter(hdd_ctx, adapter) {
4556 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07004557 mac_addr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304558 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004559 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004560 }
Dustin Brown920397d2017-12-13 16:27:50 -08004561
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304562 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004563}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004564
Arun Khandavalli2358d522016-05-16 18:05:37 +05304565#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4566/**
4567 * hdd_set_fw_log_params() - Set log parameters to FW
4568 * @hdd_ctx: HDD Context
4569 * @adapter: HDD Adapter
4570 *
4571 * This function set the FW Debug log level based on the INI.
4572 *
4573 * Return: None
4574 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004575static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004576 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304577{
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304578 QDF_STATUS status;
4579 uint16_t enable_fw_log_level, enable_fw_log_type;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304580 int ret;
4581
Arun Khandavallifae92942016-08-01 13:31:08 +05304582 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4583 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004584 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304585 return;
4586 }
4587
Arun Khandavallifae92942016-08-01 13:31:08 +05304588 /* Enable FW logs based on INI configuration */
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304589 status = ucfg_fwol_get_enable_fw_log_type(hdd_ctx->psoc,
4590 &enable_fw_log_type);
4591 if (QDF_IS_STATUS_ERROR(status))
4592 return;
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004593 ret = sme_cli_set_command(adapter->vdev_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304594 WMI_DBGLOG_TYPE,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304595 enable_fw_log_type,
Arun Khandavallifae92942016-08-01 13:31:08 +05304596 DBG_CMD);
4597 if (ret != 0)
4598 hdd_err("Failed to enable FW log type ret %d",
4599 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304600
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304601 status = ucfg_fwol_get_enable_fw_log_level(hdd_ctx->psoc,
4602 &enable_fw_log_level);
4603 if (QDF_IS_STATUS_ERROR(status))
4604 return;
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004605 ret = sme_cli_set_command(adapter->vdev_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304606 WMI_DBGLOG_LOG_LEVEL,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304607 enable_fw_log_level,
Arun Khandavallifae92942016-08-01 13:31:08 +05304608 DBG_CMD);
4609 if (ret != 0)
4610 hdd_err("Failed to enable FW log level ret %d",
4611 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304612
lifengfaa83cb2018-11-24 01:53:56 +08004613 sme_enable_fw_module_log_level(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004614 adapter->vdev_id);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304615}
4616#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004617static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004618 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304619{
4620}
4621
4622#endif
4623
4624/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004625 * hdd_configure_chain_mask() - programs chain mask to firmware
4626 * @adapter: HDD adapter
4627 *
4628 * Return: 0 on success or errno on failure
4629 */
4630static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4631{
Naveen Rawat98322472018-03-06 10:29:42 -08004632 QDF_STATUS status;
4633 struct wma_caps_per_phy non_dbs_phy_cap;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004634 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304635 bool enable2x2 = false, enable_bt_chain_sep = false;
Krunal Sonidf29bc42018-11-15 13:26:29 -08004636 uint8_t dual_mac_feature = DISABLE_DBS_CXN_AND_SCAN;
4637
4638 status = ucfg_policy_mgr_get_dual_mac_feature(hdd_ctx->psoc,
4639 &dual_mac_feature);
4640 if (!QDF_IS_STATUS_SUCCESS(status))
4641 hdd_err("unable to get dual mac feature");
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304642
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304643 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &enable2x2);
4644 if (QDF_IS_STATUS_ERROR(status))
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304645 hdd_err("unable to get vht_enable2x2");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004646
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304647 status = ucfg_mlme_get_bt_chain_separation_flag(hdd_ctx->psoc,
4648 &enable_bt_chain_sep);
4649 if (QDF_IS_STATUS_ERROR(status))
4650 hdd_debug("unable to get BT chain separation. using default");
4651
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304652 hdd_debug("enable2x2: %d, lte_coex: %d, disable_DBS: %d",
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304653 enable2x2, hdd_ctx->lte_coex_ant_share,
Krunal Sonidf29bc42018-11-15 13:26:29 -08004654 dual_mac_feature);
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304655 hdd_debug("enable_bt_chain_separation %d", enable_bt_chain_sep);
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004656
Naveen Rawat98322472018-03-06 10:29:42 -08004657 status = wma_get_caps_for_phyidx_hwmode(&non_dbs_phy_cap,
4658 HW_MODE_DBS_NONE,
4659 CDS_BAND_ALL);
4660 if (QDF_IS_STATUS_ERROR(status)) {
4661 hdd_err("couldn't get phy caps. skip chain mask programming");
4662 return qdf_status_to_os_return(status);
4663 }
4664
4665 if (non_dbs_phy_cap.tx_chain_mask_2G < 3 ||
4666 non_dbs_phy_cap.rx_chain_mask_2G < 3 ||
4667 non_dbs_phy_cap.tx_chain_mask_5G < 3 ||
4668 non_dbs_phy_cap.rx_chain_mask_5G < 3) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004669 hdd_debug("firmware not capable. skip chain mask programming");
Naveen Rawat98322472018-03-06 10:29:42 -08004670 return 0;
4671 }
4672
Pragaspathi Thilagaraj4b5c0602018-11-14 22:35:23 +05304673 if (enable2x2 && !enable_bt_chain_sep) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004674 hdd_debug("2x2 enabled. skip chain mask programming");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004675 return 0;
4676 }
4677
Krunal Sonidf29bc42018-11-15 13:26:29 -08004678 if (dual_mac_feature != DISABLE_DBS_CXN_AND_SCAN) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004679 hdd_debug("DBS enabled(%d). skip chain mask programming",
Krunal Sonidf29bc42018-11-15 13:26:29 -08004680 dual_mac_feature);
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004681 return 0;
4682 }
4683
Naveen Rawatdacb5032018-02-08 15:23:24 -08004684 if (hdd_ctx->lte_coex_ant_share) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004685 hdd_debug("lte ant sharing enabled. skip chainmask programming");
Naveen Rawatdacb5032018-02-08 15:23:24 -08004686 return 0;
4687 }
4688
Dustin Brown1dbefe62018-09-11 16:32:03 -07004689 status = ucfg_mlme_configure_chain_mask(hdd_ctx->psoc,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004690 adapter->vdev_id);
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304691 if (status != QDF_STATUS_SUCCESS)
4692 goto error;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004693
4694 return 0;
4695
4696error:
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +05304697 hdd_err("WMI PDEV set param failed");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004698 return -EINVAL;
4699}
4700
4701/**
Dundi Raviteja3b637092018-09-12 13:42:50 +05304702 * hdd_send_coex_config_params() - Send coex config params to FW
4703 * @hdd_ctx: HDD context
4704 * @adapter: Primary adapter context
4705 *
4706 * This function is used to send all coex config related params to FW
4707 *
4708 * Return: 0 on success and -EINVAL on failure
4709 */
4710static int hdd_send_coex_config_params(struct hdd_context *hdd_ctx,
4711 struct hdd_adapter *adapter)
4712{
4713 struct coex_config_params coex_cfg_params = {0};
4714 struct wlan_fwol_coex_config config = {0};
Dustin Brown05d81302018-09-11 16:49:22 -07004715 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Dundi Raviteja3b637092018-09-12 13:42:50 +05304716 QDF_STATUS status;
4717
4718 if (!hdd_ctx) {
4719 hdd_err("hdd_ctx is invalid");
4720 goto err;
4721 }
4722
4723 if (!adapter) {
4724 hdd_err("adapter is invalid");
4725 goto err;
4726 }
4727
4728 if (!psoc) {
4729 hdd_err("HDD psoc is invalid");
4730 goto err;
4731 }
4732
4733 status = ucfg_fwol_get_coex_config_params(psoc, &config);
4734 if (QDF_IS_STATUS_ERROR(status)) {
4735 hdd_err("Unable to get coex config params");
4736 goto err;
4737 }
4738
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004739 coex_cfg_params.vdev_id = adapter->vdev_id;
Dundi Raviteja3b637092018-09-12 13:42:50 +05304740 coex_cfg_params.config_type = WMI_COEX_CONFIG_TX_POWER;
4741 coex_cfg_params.config_arg1 = config.max_tx_power_for_btc;
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 Tx power");
4746 goto err;
4747 }
4748
4749 coex_cfg_params.config_type = WMI_COEX_CONFIG_HANDOVER_RSSI;
4750 coex_cfg_params.config_arg1 = config.wlan_low_rssi_threshold;
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 handover RSSI");
4755 goto err;
4756 }
4757
4758 coex_cfg_params.config_type = WMI_COEX_CONFIG_BTC_MODE;
4759 coex_cfg_params.config_arg1 = config.btc_mode;
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 BTC mode");
4764 goto err;
4765 }
4766
4767 coex_cfg_params.config_type = WMI_COEX_CONFIG_ANTENNA_ISOLATION;
4768 coex_cfg_params.config_arg1 = config.antenna_isolation;
4769
4770 status = sme_send_coex_config_cmd(&coex_cfg_params);
4771 if (QDF_IS_STATUS_ERROR(status)) {
4772 hdd_err("Failed to send coex antenna isolation");
4773 goto err;
4774 }
4775
4776 coex_cfg_params.config_type = WMI_COEX_CONFIG_BT_LOW_RSSI_THRESHOLD;
4777 coex_cfg_params.config_arg1 = config.bt_low_rssi_threshold;
4778
4779 status = sme_send_coex_config_cmd(&coex_cfg_params);
4780 if (QDF_IS_STATUS_ERROR(status)) {
4781 hdd_err("Failed to send coex BT low RSSI threshold");
4782 goto err;
4783 }
4784
4785 coex_cfg_params.config_type = WMI_COEX_CONFIG_BT_INTERFERENCE_LEVEL;
4786 coex_cfg_params.config_arg1 = config.bt_interference_low_ll;
4787 coex_cfg_params.config_arg2 = config.bt_interference_low_ul;
4788 coex_cfg_params.config_arg3 = config.bt_interference_medium_ll;
4789 coex_cfg_params.config_arg4 = config.bt_interference_medium_ul;
4790 coex_cfg_params.config_arg5 = config.bt_interference_high_ll;
4791 coex_cfg_params.config_arg6 = config.bt_interference_high_ul;
4792
4793 status = sme_send_coex_config_cmd(&coex_cfg_params);
4794 if (QDF_IS_STATUS_ERROR(status)) {
4795 hdd_err("Failed to send coex BT interference level");
4796 goto err;
4797 }
stonezc9936cb2019-03-11 16:41:22 +08004798
4799 if (wlan_hdd_mpta_helper_enable(&coex_cfg_params, &config))
4800 goto err;
4801
Dundi Raviteja3b637092018-09-12 13:42:50 +05304802 return 0;
4803err:
4804 return -EINVAL;
4805}
4806
4807/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304808 * hdd_set_fw_params() - Set parameters to firmware
4809 * @adapter: HDD adapter
4810 *
4811 * This function Sets various parameters to fw once the
4812 * adapter is started.
4813 *
4814 * Return: 0 on success or errno on failure
4815 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004816int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304817{
4818 int ret;
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304819 uint16_t upper_brssi_thresh, lower_brssi_thresh, rts_profile;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304820 bool enable_dtim_1chrx;
4821 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004822 struct hdd_context *hdd_ctx;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304823 bool bval = false;
Manikandan Mohand350c192018-11-29 14:01:12 -08004824 uint8_t max_amsdu_len, enable_tx_sch_delay;
4825 uint32_t dtim_sel_diversity, enable_secondary_rate;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304826
Dustin Brownfdf17c12018-03-14 12:55:34 -07004827 hdd_enter_dev(adapter->dev);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304828
4829 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4830 if (!hdd_ctx)
4831 return -EINVAL;
4832
Dustin Brown732ab9c2017-06-15 13:24:09 -07004833 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4834 hdd_debug("FTM Mode is active; nothing to do");
4835 return 0;
4836 }
4837
Manikandan Mohand350c192018-11-29 14:01:12 -08004838 ret = -1;
4839 if (QDF_IS_STATUS_SUCCESS(ucfg_fwol_get_lprx_enable(hdd_ctx->psoc,
4840 &bval))) {
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004841 ret = sme_cli_set_command(adapter->vdev_id,
Manikandan Mohand350c192018-11-29 14:01:12 -08004842 WMI_PDEV_PARAM_DTIM_SYNTH,
4843 bval, PDEV_CMD);
4844 }
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304845 if (ret) {
4846 hdd_err("Failed to set LPRx");
4847 goto error;
4848 }
4849
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +05304850 ucfg_mlme_get_dtim_selection_diversity(hdd_ctx->psoc,
4851 &dtim_sel_diversity);
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304852
4853 ret = sme_cli_set_command(
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004854 adapter->vdev_id,
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304855 WMI_PDEV_PARAM_1CH_DTIM_OPTIMIZED_CHAIN_SELECTION,
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +05304856 dtim_sel_diversity, PDEV_CMD);
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304857 if (ret) {
4858 hdd_err("Failed to set DTIM_OPTIMIZED_CHAIN_SELECTION");
4859 goto error;
4860 }
4861
Manikandan Mohand350c192018-11-29 14:01:12 -08004862 ret = -1;
4863 if (QDF_IS_STATUS_SUCCESS(ucfg_fwol_get_enable_tx_sch_delay(
4864 hdd_ctx->psoc, &enable_tx_sch_delay))) {
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004865 ret = sme_cli_set_command(adapter->vdev_id,
Manikandan Mohand350c192018-11-29 14:01:12 -08004866 WMI_PDEV_PARAM_TX_SCH_DELAY,
4867 enable_tx_sch_delay, PDEV_CMD);
4868 }
Ashish Kumar Dhanotiya48dac7d2018-03-28 14:59:50 +05304869 if (ret) {
4870 hdd_err("Failed to set WMI_PDEV_PARAM_TX_SCH_DELAY");
4871 goto error;
4872 }
4873
Manikandan Mohand350c192018-11-29 14:01:12 -08004874 ret = -1;
4875 if (QDF_IS_STATUS_SUCCESS(ucfg_fwol_get_enable_secondary_rate(
4876 hdd_ctx->psoc, &enable_secondary_rate))) {
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004877 ret = sme_cli_set_command(adapter->vdev_id,
Manikandan Mohand350c192018-11-29 14:01:12 -08004878 WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE,
4879 enable_secondary_rate, PDEV_CMD);
4880 }
Ashish Kumar Dhanotiya959b38c2018-04-06 21:07:57 +05304881 if (ret) {
4882 hdd_err("Failed to set WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE");
4883 goto error;
4884 }
4885
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304886 if (adapter->device_mode == QDF_STA_MODE) {
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304887 status = ucfg_get_upper_brssi_thresh(hdd_ctx->psoc,
4888 &upper_brssi_thresh);
4889 if (QDF_IS_STATUS_ERROR(status))
4890 return -EINVAL;
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304891
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_UPPER_BRSSI_THRESH,
4894 upper_brssi_thresh);
4895
4896 status = ucfg_get_lower_brssi_thresh(hdd_ctx->psoc,
4897 &lower_brssi_thresh);
4898 if (QDF_IS_STATUS_ERROR(status))
4899 return -EINVAL;
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304900
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004901 sme_set_smps_cfg(adapter->vdev_id,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304902 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4903 lower_brssi_thresh);
4904
4905 status = ucfg_get_enable_dtim_1chrx(hdd_ctx->psoc,
4906 &enable_dtim_1chrx);
4907 if (QDF_IS_STATUS_ERROR(status))
4908 return -EINVAL;
4909
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004910 sme_set_smps_cfg(adapter->vdev_id,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +05304911 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4912 enable_dtim_1chrx);
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304913 }
4914
Abhinav Kumarb074f2f2018-09-15 15:32:11 +05304915 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
4916 if (!QDF_IS_STATUS_SUCCESS(status))
4917 hdd_err("unable to get vht_enable2x2");
4918
4919 if (bval) {
Dustin Brown732ab9c2017-06-15 13:24:09 -07004920 hdd_debug("configuring 2x2 mode fw params");
4921
Vignesh Viswanathana851d752018-10-03 19:44:38 +05304922 ret = sme_set_cck_tx_fir_override(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004923 adapter->vdev_id);
Dustin Brown732ab9c2017-06-15 13:24:09 -07004924 if (ret) {
4925 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4926 ret);
4927 goto error;
4928 }
Liangwei Dong22810e82018-03-15 03:42:12 -04004929
4930 if (hdd_configure_chain_mask(adapter))
4931 goto error;
Dustin Brown732ab9c2017-06-15 13:24:09 -07004932 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304933#define HDD_DTIM_1CHAIN_RX_ID 0x5
4934#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004935 hdd_debug("configuring 1x1 mode fw params");
4936
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004937 /*
4938 * Disable DTIM 1 chain Rx when in 1x1,
4939 * we are passing two value
4940 * as param_id << 29 | param_value.
4941 * Below param_value = 0(disable)
4942 */
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004943 ret = sme_cli_set_command(adapter->vdev_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004944 WMI_STA_SMPS_PARAM_CMDID,
4945 HDD_DTIM_1CHAIN_RX_ID <<
4946 HDD_SMPS_PARAM_VALUE_S,
4947 VDEV_CMD);
4948 if (ret) {
4949 hdd_err("DTIM 1 chain set failed %d", ret);
4950 goto error;
4951 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304952
Arun Khandavalli2358d522016-05-16 18:05:37 +05304953#undef HDD_DTIM_1CHAIN_RX_ID
4954#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004955
4956 if (hdd_configure_chain_mask(adapter))
4957 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004958 }
4959
Vignesh Viswanathana851d752018-10-03 19:44:38 +05304960 ret = sme_set_enable_mem_deep_sleep(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004961 adapter->vdev_id);
Dustin Brown732ab9c2017-06-15 13:24:09 -07004962 if (ret) {
4963 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4964 goto error;
4965 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304966
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304967 status = ucfg_fwol_get_rts_profile(hdd_ctx->psoc, &rts_profile);
4968 if (QDF_IS_STATUS_ERROR(status))
4969 return -EINVAL;
4970
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004971 ret = sme_cli_set_command(adapter->vdev_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004972 WMI_VDEV_PARAM_ENABLE_RTSCTS,
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +05304973 rts_profile,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004974 VDEV_CMD);
4975 if (ret) {
4976 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4977 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304978 }
4979
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05304980 status = ucfg_mlme_get_max_amsdu_num(hdd_ctx->psoc, &max_amsdu_len);
4981 if (QDF_IS_STATUS_ERROR(status)) {
4982 hdd_err("Failed to get Max AMSDU Num");
4983 goto error;
4984 }
4985
4986 hdd_debug("SET AMSDU num %d", max_amsdu_len);
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004987
Jeff Johnson5a6fc962019-02-04 14:20:25 -08004988 ret = wma_cli_set_command(adapter->vdev_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004989 GEN_VDEV_PARAM_AMSDU,
Vignesh Viswanathanddc89e52018-11-02 18:43:42 +05304990 max_amsdu_len,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004991 GEN_CMD);
4992 if (ret != 0) {
4993 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4994 goto error;
4995 }
4996
Arun Khandavalli2358d522016-05-16 18:05:37 +05304997 hdd_set_fw_log_params(hdd_ctx, adapter);
Dundi Raviteja3b637092018-09-12 13:42:50 +05304998
4999 ret = hdd_send_coex_config_params(hdd_ctx, adapter);
5000 if (ret) {
5001 hdd_warn("Error initializing coex config params");
5002 goto error;
5003 }
5004
Dustin Browne74003f2018-03-14 12:51:58 -07005005 hdd_exit();
Dustin Brown732ab9c2017-06-15 13:24:09 -07005006
Arun Khandavalli2358d522016-05-16 18:05:37 +05305007 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05305008
Arun Khandavalli2358d522016-05-16 18:05:37 +05305009error:
5010 return -EINVAL;
5011}
5012
Ryan Hsu07495ea2016-01-21 15:25:39 -08005013/**
Abhinav Kumarcc959f12018-08-09 13:58:30 +05305014 * hdd_init_completion() - Initialize Completion Variables
5015 * @adapter: HDD adapter
5016 *
5017 * This function Initialize the completion variables for
5018 * a particular adapter
5019 *
5020 * Return: None
5021 */
5022static void hdd_init_completion(struct hdd_adapter *adapter)
5023{
5024 init_completion(&adapter->disconnect_comp_var);
5025 init_completion(&adapter->roaming_comp_var);
5026 init_completion(&adapter->linkup_event_var);
Abhinav Kumarcc959f12018-08-09 13:58:30 +05305027 init_completion(&adapter->sta_authorized_event);
5028 init_completion(&adapter->offchannel_tx_event);
5029 init_completion(&adapter->tx_action_cnf_event);
5030 init_completion(&adapter->ibss_peer_info_comp);
5031 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
5032}
5033
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05305034static void hdd_reset_locally_admin_bit(struct hdd_context *hdd_ctx,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005035 tSirMacAddr mac_addr)
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05305036{
5037 int i;
5038 /*
5039 * Reset locally administered bit for dynamic_mac_list
5040 * also as while releasing the MAC address for any
5041 * interface mac will be compared with dynamic mac list
5042 */
5043 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
5044 if (!qdf_mem_cmp(
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005045 mac_addr,
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05305046 &hdd_ctx->
5047 dynamic_mac_list[i].dynamic_mac.bytes[0],
5048 sizeof(struct qdf_mac_addr))) {
5049 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(
5050 hdd_ctx->
5051 dynamic_mac_list[i].dynamic_mac.bytes);
5052 break;
5053 }
5054 }
5055 /*
5056 * Reset locally administered bit if the device mode is
5057 * STA
5058 */
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005059 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(mac_addr);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05305060 hdd_debug("locally administered bit reset in sta mode: "
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07005061 QDF_MAC_ADDR_STR, QDF_MAC_ADDR_ARRAY(mac_addr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05305062}
5063
Dustin Brown96b98dd2019-03-06 12:39:37 -08005064static void wlan_hdd_cfg80211_scan_block_cb(struct work_struct *work)
5065{
5066 struct hdd_adapter *adapter =
5067 container_of(work, struct hdd_adapter, scan_block_work);
5068 struct osif_vdev_sync *vdev_sync;
5069
5070 if (osif_vdev_sync_op_start(adapter->dev, &vdev_sync))
5071 return;
5072
5073 wlan_hdd_cfg80211_scan_block(adapter);
5074
5075 osif_vdev_sync_op_stop(vdev_sync);
5076}
5077
Abhinav Kumarcc959f12018-08-09 13:58:30 +05305078/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08005079 * hdd_open_adapter() - open and setup the hdd adatper
5080 * @hdd_ctx: global hdd context
5081 * @session_type: type of the interface to be created
5082 * @iface_name: User-visible name of the interface
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005083 * @mac_addr: MAC address to assign to the interface
Ryan Hsu07495ea2016-01-21 15:25:39 -08005084 * @name_assign_type: the name of assign type of the netdev
5085 * @rtnl_held: the rtnl lock hold flag
5086 *
5087 * This function open and setup the hdd adpater according to the device
5088 * type request, assign the name, the mac address assigned, and then prepared
5089 * the hdd related parameters, queue, lock and ready to start.
5090 *
5091 * Return: the pointer of hdd adapter, otherwise NULL.
5092 */
Jeff Johnson9d295242017-08-29 14:39:48 -07005093struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005094 const char *iface_name, tSirMacAddr mac_addr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08005095 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08005096 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005097{
Madhvapathi Sriram8b056652019-03-27 17:38:12 +05305098 struct net_device *ndev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07005099 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305100 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005101
5102 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
5103 /*
5104 * Max limit reached on the number of vdevs configured by the
5105 * host. Return error
5106 */
Arun Khandavallifae92942016-08-01 13:31:08 +05305107 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
5108 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005109 return NULL;
5110 }
5111
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005112 status = wlan_hdd_validate_mac_address((struct qdf_mac_addr *)mac_addr);
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05305113 if (QDF_IS_STATUS_ERROR(status)) {
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005114 /* Not received valid mac_addr */
Arun Khandavallifae92942016-08-01 13:31:08 +05305115 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005116 return NULL;
5117 }
Pragaspathi Thilagaraj84b72842018-09-19 22:06:57 +05305118
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005119 status = hdd_check_for_existing_macaddr(hdd_ctx, mac_addr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305120 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07005121 hdd_err("Duplicate MAC addr: " QDF_MAC_ADDR_STR
Arun Khandavallifae92942016-08-01 13:31:08 +05305122 " already exists",
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07005123 QDF_MAC_ADDR_ARRAY(mac_addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005124 return NULL;
5125 }
5126
5127 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005128 case QDF_STA_MODE:
Ashish Kumar Dhanotiya01485192018-12-24 12:44:06 +05305129 if (!hdd_ctx->config->mac_provision) {
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005130 hdd_reset_locally_admin_bit(hdd_ctx, mac_addr);
Ashish Kumar Dhanotiya01485192018-12-24 12:44:06 +05305131 /*
5132 * After resetting locally administered bit
5133 * again check if the new mac address is already
5134 * exists.
5135 */
5136 status = hdd_check_for_existing_macaddr(hdd_ctx,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005137 mac_addr);
Ashish Kumar Dhanotiya01485192018-12-24 12:44:06 +05305138 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -07005139 hdd_err("Duplicate MAC addr: " QDF_MAC_ADDR_STR
Ashish Kumar Dhanotiya01485192018-12-24 12:44:06 +05305140 " already exists",
Srinivas Girigowda34fbba02019-04-08 12:07:44 -07005141 QDF_MAC_ADDR_ARRAY(mac_addr));
Ashish Kumar Dhanotiya01485192018-12-24 12:44:06 +05305142 return NULL;
5143 }
5144 }
Ashish Kumar Dhanotiya6784b502018-10-17 12:51:10 +05305145
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005146 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005147 case QDF_P2P_CLIENT_MODE:
5148 case QDF_P2P_DEVICE_MODE:
5149 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07005150 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305151 case QDF_MONITOR_MODE:
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005152 adapter = hdd_alloc_station_adapter(hdd_ctx, mac_addr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08005153 name_assign_type,
5154 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005155
Jeff Johnsond36fa332019-03-18 13:42:25 -07005156 if (!adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305157 hdd_err("failed to allocate adapter for session %d",
5158 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005159 return NULL;
5160 }
5161
Madhvapathi Sriram8b056652019-03-27 17:38:12 +05305162 ndev = adapter->dev;
5163
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005164 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005165 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005166 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005167 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305168 else if (QDF_MONITOR_MODE == session_type)
5169 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005170 else
5171 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
5172
5173 adapter->device_mode = session_type;
5174
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005175
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005176 /*
5177 * Workqueue which gets scheduled in IPv4 notification
5178 * callback
5179 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005180 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005181 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005182
5183#ifdef WLAN_NS_OFFLOAD
5184 /*
5185 * Workqueue which gets scheduled in IPv6
5186 * notification callback.
5187 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005188 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005189 hdd_ipv6_notifier_work_queue);
5190#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005191 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08005192 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08005193 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005194
5195 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005196 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005197 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305198 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5199 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05305200
Alok Kumarb64650c2018-03-23 17:05:11 +05305201 hdd_nud_init_tracking(adapter);
Arunk Khandavallica56d4b2018-11-29 15:46:00 +05305202 if (adapter->device_mode == QDF_STA_MODE ||
5203 adapter->device_mode == QDF_P2P_DEVICE_MODE)
5204 hdd_sysfs_create_adapter_root_obj(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05305205 qdf_mutex_create(&adapter->disconnection_status_lock);
5206
Ravi Joshi1a292562017-05-18 16:28:54 -07005207 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005208
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005209 case QDF_P2P_GO_MODE:
5210 case QDF_SAP_MODE:
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005211 adapter = hdd_wlan_create_ap_dev(hdd_ctx, mac_addr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08005212 name_assign_type,
5213 (uint8_t *) iface_name);
Jeff Johnsond36fa332019-03-18 13:42:25 -07005214 if (!adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005215 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05305216 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005217 return NULL;
5218 }
5219
Madhvapathi Sriram8b056652019-03-27 17:38:12 +05305220 ndev = adapter->dev;
5221
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005222 adapter->wdev.iftype =
5223 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005224 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005225 NL80211_IFTYPE_P2P_GO;
5226 adapter->device_mode = session_type;
5227
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07005228 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08005229 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005230 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08005231
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005232 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005233 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305234 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5235 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305236
5237 /*
5238 * Workqueue which gets scheduled in IPv4 notification
5239 * callback
5240 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005241 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305242 hdd_ipv4_notifier_work_queue);
5243
5244#ifdef WLAN_NS_OFFLOAD
5245 /*
5246 * Workqueue which gets scheduled in IPv6
5247 * notification callback.
5248 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005249 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305250 hdd_ipv6_notifier_work_queue);
5251#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005252 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305253 case QDF_FTM_MODE:
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07005254 adapter = hdd_alloc_station_adapter(hdd_ctx, mac_addr,
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305255 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08005256 iface_name);
Jeff Johnsond36fa332019-03-18 13:42:25 -07005257 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305258 hdd_err("Failed to allocate adapter for FTM mode");
5259 return NULL;
5260 }
Madhvapathi Sriram8b056652019-03-27 17:38:12 +05305261
5262 ndev = adapter->dev;
5263
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305264 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
5265 adapter->device_mode = session_type;
5266 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08005267 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08005268 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08005269
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305270 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005271 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305272 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305273 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5274 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305275 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005276 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005277 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305278 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005279 return NULL;
5280 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005281
Min Liu8c5d99e2018-09-10 17:18:44 +08005282 qdf_spinlock_create(&adapter->vdev_lock);
5283
Abhinav Kumarcc959f12018-08-09 13:58:30 +05305284 hdd_init_completion(adapter);
hqueaa33ee2017-05-04 17:56:35 +08005285 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
Min Liu9be5d4a2018-05-17 11:51:53 +08005286 qdf_list_create(&adapter->blocked_scan_request_q, WLAN_MAX_SCAN_COUNT);
5287 qdf_mutex_create(&adapter->blocked_scan_request_q_lock);
hqueaa33ee2017-05-04 17:56:35 +08005288
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305289 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005290 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08005291 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005292 }
5293
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305294 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsond36fa332019-03-18 13:42:25 -07005295 if (adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005296 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
5297 adapter = NULL;
5298 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005299
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005300 return NULL;
5301 }
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05305302 hdd_apf_context_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005303
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305304 if (QDF_STATUS_SUCCESS == status) {
Dustin Brown1dbefe62018-09-11 16:32:03 -07005305 policy_mgr_set_concurrency_mode(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005306 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005307
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005308 /* Adapter successfully added. Increment the vdev count */
5309 hdd_ctx->current_intf_count++;
5310
Jeff Johnson5880d792016-08-15 13:32:30 -07005311 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005312 hdd_ctx->current_intf_count);
5313
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08005314 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005315 }
5316
Rajeev Kumardca5f812016-02-04 17:28:06 -08005317 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07005318 hdd_err("Interface %s wow debug_fs init failed",
5319 netdev_name(adapter->dev));
5320
5321 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
5322 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005323
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05305324 if (adapter->device_mode == QDF_STA_MODE)
5325 wlan_hdd_debugfs_csr_init(adapter);
5326
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005327 return adapter;
5328
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005329err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07005330 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Madhvapathi Sriram8b056652019-03-27 17:38:12 +05305331
5332 if (ndev)
5333 free_netdev(ndev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005334
5335 return NULL;
5336}
5337
Dustin Brown728d65a2018-10-02 16:27:52 -07005338static void __hdd_close_adapter(struct hdd_context *hdd_ctx,
5339 struct hdd_adapter *adapter,
5340 bool rtnl_held)
5341{
5342 qdf_list_destroy(&adapter->blocked_scan_request_q);
5343 qdf_mutex_destroy(&adapter->blocked_scan_request_q_lock);
5344 policy_mgr_clear_concurrency_mode(hdd_ctx->psoc, adapter->device_mode);
5345
5346 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
5347
5348 if (hdd_ctx->current_intf_count != 0)
5349 hdd_ctx->current_intf_count--;
5350}
5351
5352void hdd_close_adapter(struct hdd_context *hdd_ctx,
5353 struct hdd_adapter *adapter,
5354 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005355{
Dustin Brown920397d2017-12-13 16:27:50 -08005356 /*
Dustin Brown728d65a2018-10-02 16:27:52 -07005357 * Stop the global bus bandwidth timer while touching the adapter list
5358 * to avoid bad memory access by the timer handler.
Dustin Brown920397d2017-12-13 16:27:50 -08005359 */
Dustin Brown920397d2017-12-13 16:27:50 -08005360 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005361
Dustin Brown920397d2017-12-13 16:27:50 -08005362 hdd_remove_adapter(hdd_ctx, adapter);
Dustin Brown728d65a2018-10-02 16:27:52 -07005363 __hdd_close_adapter(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005364
Dustin Brown920397d2017-12-13 16:27:50 -08005365 /* conditionally restart the bw timer */
5366 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005367}
5368
Dustin Brown728d65a2018-10-02 16:27:52 -07005369void hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005370{
Dustin Brown920397d2017-12-13 16:27:50 -08005371 struct hdd_adapter *adapter;
Dustin Brown2c5e0482019-02-05 16:14:43 -08005372 struct osif_vdev_sync *vdev_sync;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005373
Dustin Brown491d54b2018-03-14 12:39:11 -07005374 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005375
Dustin Brown728d65a2018-10-02 16:27:52 -07005376 while (QDF_IS_STATUS_SUCCESS(hdd_remove_front_adapter(hdd_ctx,
5377 &adapter))) {
Dustin Brown2c5e0482019-02-05 16:14:43 -08005378 vdev_sync = osif_vdev_sync_unregister(adapter->dev);
Dustin Brown693b5352019-01-17 10:00:31 -08005379 if (vdev_sync)
Dustin Brown2c5e0482019-02-05 16:14:43 -08005380 osif_vdev_sync_wait_for_ops(vdev_sync);
Dustin Brown693b5352019-01-17 10:00:31 -08005381
Dustin Brown728d65a2018-10-02 16:27:52 -07005382 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
5383 __hdd_close_adapter(hdd_ctx, adapter, rtnl_held);
Dustin Brown693b5352019-01-17 10:00:31 -08005384
5385 if (vdev_sync)
Dustin Brown2c5e0482019-02-05 16:14:43 -08005386 osif_vdev_sync_destroy(vdev_sync);
Dustin Brown728d65a2018-10-02 16:27:52 -07005387 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005388
Dustin Browne74003f2018-03-14 12:51:58 -07005389 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005390}
5391
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005392void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005393{
Anurag Chouhan6d760662016-02-20 16:05:43 +05305394 struct qdf_mac_addr *bssid = NULL;
Jeff Johnsonc565af12019-03-10 21:09:47 -07005395 tSirUpdateIE update_ie;
Jeff Johnson16528362018-06-14 12:34:16 -07005396 mac_handle_t mac_handle;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005397
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005398 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005399 case QDF_STA_MODE:
5400 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005401 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005402 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005403 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsone04b6992019-02-27 14:06:55 -08005404 bssid = &sta_ctx->conn_info.bssid;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005405 break;
5406 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005407 case QDF_SAP_MODE:
5408 case QDF_P2P_GO_MODE:
5409 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005410 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07005411 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005412 break;
5413 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005414 case QDF_FTM_MODE:
5415 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005416 default:
5417 /*
5418 * wlan_hdd_reset_prob_rspies should not have been called
5419 * for these kind of devices
5420 */
Jeff Johnson5880d792016-08-15 13:32:30 -07005421 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005422 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005423 return;
5424 }
5425
Jeff Johnsonc565af12019-03-10 21:09:47 -07005426 qdf_copy_macaddr(&update_ie.bssid, bssid);
5427 update_ie.smeSessionId = adapter->vdev_id;
5428 update_ie.ieBufferlength = 0;
5429 update_ie.pAdditionIEBuffer = NULL;
5430 update_ie.append = true;
5431 update_ie.notify = false;
Jeff Johnson16528362018-06-14 12:34:16 -07005432 mac_handle = hdd_adapter_get_mac_handle(adapter);
5433 if (sme_update_add_ie(mac_handle,
Jeff Johnsonc565af12019-03-10 21:09:47 -07005434 &update_ie,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305435 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005436 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005437 }
5438}
5439
Dustin Browndb2a8be2017-12-20 11:49:56 -08005440QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
5441 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005442{
Dustin Brownd747ecd2018-10-26 16:32:22 -07005443 QDF_STATUS status = QDF_STATUS_SUCCESS;
5444 struct hdd_station_ctx *sta_ctx;
Dustin Brownb4260d52019-01-24 11:53:08 -08005445 struct sap_context *sap_ctx;
Jeff Johnson025618c2018-03-18 14:41:00 -07005446 struct csr_roam_profile *roam_profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005447 union iwreq_data wrqu;
Jeff Johnsonc565af12019-03-10 21:09:47 -07005448 tSirUpdateIE update_ie;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005449 unsigned long rc;
Jeff Johnson8f8ceb92019-03-24 08:16:55 -07005450 struct sap_config *sap_config;
Jeff Johnson16528362018-06-14 12:34:16 -07005451 mac_handle_t mac_handle;
Min Liu8c5d99e2018-09-10 17:18:44 +08005452 struct wlan_objmgr_vdev *vdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005453
Dustin Brown491d54b2018-03-14 12:39:11 -07005454 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005455
Jeff Johnson912b1bb2019-03-06 10:12:36 -08005456 if (adapter->vdev_id != WLAN_UMAC_VDEV_ID_MAX)
Dustin Browne7e71d32018-05-11 16:00:08 -07005457 wlan_hdd_cfg80211_deregister_frames(adapter);
5458
Alok Kumarb64650c2018-03-23 17:05:11 +05305459 hdd_nud_ignore_tracking(adapter, true);
5460 hdd_nud_reset_tracking(adapter);
Alok Kumar016a1ac2018-09-16 09:55:50 +05305461 hdd_nud_flush_work(adapter);
hangtian9c47aaf2018-11-26 17:59:39 +08005462 hdd_stop_tsf_sync(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05305463
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005464 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305465 wlan_hdd_netif_queue_control(adapter,
5466 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5467 WLAN_CONTROL_PATH);
Jeff Johnson16528362018-06-14 12:34:16 -07005468
5469 mac_handle = hdd_ctx->mac_handle;
5470
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005471 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005472 case QDF_STA_MODE:
5473 case QDF_P2P_CLIENT_MODE:
5474 case QDF_IBSS_MODE:
5475 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005476 case QDF_NDI_MODE:
Dustin Brownd747ecd2018-10-26 16:32:22 -07005477 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
5478
5479 if (adapter->device_mode == QDF_NDI_MODE ||
5480 hdd_conn_is_connected(sta_ctx) ||
5481 hdd_is_connecting(sta_ctx)) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005482 INIT_COMPLETION(adapter->disconnect_comp_var);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005483
Jeff Johnson025618c2018-03-18 14:41:00 -07005484 roam_profile = hdd_roam_profile(adapter);
5485 /* For NDI do not use roam_profile */
Dustin Brownd747ecd2018-10-26 16:32:22 -07005486 if (adapter->device_mode == QDF_NDI_MODE)
5487 status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005488 mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08005489 adapter->vdev_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005490 eCSR_DISCONNECT_REASON_NDI_DELETE);
Jeff Johnson025618c2018-03-18 14:41:00 -07005491 else if (roam_profile->BSSType ==
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005492 eCSR_BSS_TYPE_START_IBSS)
Dustin Brownd747ecd2018-10-26 16:32:22 -07005493 status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005494 mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08005495 adapter->vdev_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005496 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Abhinav Kumar19a7a402018-07-12 17:36:57 +05305497 else if (adapter->device_mode == QDF_STA_MODE)
5498 wlan_hdd_disconnect(adapter,
5499 eCSR_DISCONNECT_REASON_DEAUTH);
5500 else
Dustin Brownd747ecd2018-10-26 16:32:22 -07005501 status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005502 mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08005503 adapter->vdev_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005504 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005505 /* success implies disconnect is queued */
5506 if (QDF_IS_STATUS_SUCCESS(status) &&
5507 adapter->device_mode != QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005508 rc = wait_for_completion_timeout(
5509 &adapter->disconnect_comp_var,
5510 msecs_to_jiffies
Abhishek Singhd1f21c72019-01-21 15:16:34 +05305511 (SME_DISCONNECT_TIMEOUT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005512 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005513 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005514 }
Dustin Brownd747ecd2018-10-26 16:32:22 -07005515 if (QDF_IS_STATUS_ERROR(status))
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005516 hdd_warn("failed to post disconnect");
Dustin Brownd747ecd2018-10-26 16:32:22 -07005517
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005518 memset(&wrqu, '\0', sizeof(wrqu));
5519 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5520 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5521 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
5522 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05305523 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005524
Dustin Brownd747ecd2018-10-26 16:32:22 -07005525 wlan_hdd_scan_abort(adapter);
Wu Gao4a1ec8c2018-07-23 19:18:40 +08005526 wlan_hdd_cleanup_actionframe(adapter);
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05305527 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05305528 hdd_clear_fils_connection_info(adapter);
Ashish Kumar Dhanotiya36510832019-02-20 22:13:25 +05305529
Liangwei Donga44d55b2019-03-20 03:22:08 -04005530 status = wlan_hdd_flush_pmksa_cache(adapter);
Ashish Kumar Dhanotiya36510832019-02-20 22:13:25 +05305531 if (QDF_IS_STATUS_ERROR(status))
5532 hdd_err("Cannot flush PMKIDCache");
5533
Visweswara Tanukub5a61242019-03-26 12:24:13 +05305534 hdd_deregister_hl_netdev_fc_timer(adapter);
5535
Dustin Brownd747ecd2018-10-26 16:32:22 -07005536 hdd_deregister_tx_flow_control(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005537
5538#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005539 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005540#ifdef WLAN_NS_OFFLOAD
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005541 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005542#endif
5543#endif
5544
Min Liu8c5d99e2018-09-10 17:18:44 +08005545 if (adapter->device_mode == QDF_STA_MODE) {
5546 struct wlan_objmgr_vdev *vdev;
5547
5548 vdev = hdd_objmgr_get_vdev(adapter);
5549 if (vdev) {
5550 wlan_cfg80211_sched_scan_stop(vdev);
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05305551 hdd_objmgr_put_vdev(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08005552 }
5553 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08005554
Pragaspathi Thilagaraje6f37e02019-01-04 12:24:33 +05305555 /*
5556 * During vdev destroy, if any STA is in connecting state the
5557 * roam command will be in active queue and thus vdev destroy is
5558 * queued in pending queue. In case STA tries to connect to
5559 * multiple BSSID and fails to connect, due to auth/assoc
5560 * timeouts it may take more than vdev destroy time to get
5561 * completed. On vdev destroy timeout vdev is moved to logically
5562 * deleted state. Once connection is completed, vdev destroy is
5563 * activated and to release the self-peer ref count it try to
5564 * get the ref of the vdev, which fails as vdev is logically
5565 * deleted and this leads to peer ref leak. So before vdev
5566 * destroy is queued abort any STA ongoing connection to avoid
5567 * vdev destroy timeout.
5568 */
5569 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags))
5570 hdd_abort_ongoing_sta_connection(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08005571
Himanshu Agarwalb229a142017-12-21 10:16:45 +05305572 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005573 break;
5574
Rajeev Kumar3b906202018-02-01 10:55:14 -08005575 case QDF_MONITOR_MODE:
5576 wlan_hdd_scan_abort(adapter);
Visweswara Tanukub5a61242019-03-26 12:24:13 +05305577 hdd_deregister_hl_netdev_fc_timer(adapter);
Rajeev Kumar3b906202018-02-01 10:55:14 -08005578 hdd_deregister_tx_flow_control(adapter);
5579 hdd_vdev_destroy(adapter);
5580 break;
5581
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005582 case QDF_SAP_MODE:
Will Huang7049bae2018-08-13 17:25:02 +08005583 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
5584 cds_flush_delayed_work(&adapter->acs_pending_work);
5585 clear_bit(ACS_PENDING, &adapter->event_flags);
5586 }
Dustin Brownd747ecd2018-10-26 16:32:22 -07005587
wadesongf9b15ed2017-12-14 14:12:32 +08005588 wlan_hdd_scan_abort(adapter);
gaurank kathpaliab7a9f702019-02-15 18:09:58 +05305589 /* Diassociate with all the peers before stop ap post */
5590 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags))
5591 wlan_hdd_del_station(adapter);
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05305592 sap_config = &adapter->session.ap.sap_config;
Dustin Brownd747ecd2018-10-26 16:32:22 -07005593 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
5594
Dustin Brown07901ec2018-09-07 11:02:41 -07005595 ucfg_ipa_flush(hdd_ctx->pdev);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005596
Dustin Brownb4260d52019-01-24 11:53:08 -08005597 /* don't flush pre-cac destroy if we are destroying pre-cac */
5598 sap_ctx = WLAN_HDD_GET_SAP_CTX_PTR(adapter);
5599 if (!wlan_sap_is_pre_cac_context(sap_ctx))
Liangwei Dongad89c762018-06-01 01:56:23 -04005600 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Dustin Brownb4260d52019-01-24 11:53:08 -08005601
Jeff Johnson46807cd2018-04-29 21:32:22 -07005602 /* fallthrough */
Dustin Browna5cf8e02017-10-19 16:04:19 -07005603
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005604 case QDF_P2P_GO_MODE:
Krunal Soni22208392017-09-29 18:10:34 -07005605 cds_flush_work(&adapter->sap_stop_bss_work);
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305606 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005607 wlan_hdd_undo_acs(adapter);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005608
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005609 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005610 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5611
Visweswara Tanukub5a61242019-03-26 12:24:13 +05305612 hdd_deregister_hl_netdev_fc_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005613 hdd_deregister_tx_flow_control(adapter);
Kapil Guptac1224bf2017-06-22 21:22:40 +05305614 hdd_destroy_acs_timer(adapter);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005615
Pragaspathi Thilagaraje6f37e02019-01-04 12:24:33 +05305616 /**
5617 * During vdev destroy, If any STA is in connecting state the
5618 * roam command will be in active queue and thus vdev destroy is
5619 * queued in pending queue. In case STA is tries to connected to
5620 * multiple BSSID and fails to connect, due to auth/assoc
5621 * timeouts it may take more than vdev destroy time to get
5622 * completes. If vdev destroy timeout vdev is moved to logically
5623 * deleted state. Once connection is completed, vdev destroy is
5624 * activated and to release the self-peer ref count it try to
5625 * get the ref of the vdev, which fails as vdev is logically
5626 * deleted and this leads to peer ref leak. So before vdev
5627 * destroy is queued abort any STA ongoing connection to avoid
5628 * vdev destroy timeout.
5629 */
5630 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags))
5631 hdd_abort_ongoing_sta_connection(hdd_ctx);
5632
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005633 mutex_lock(&hdd_ctx->sap_lock);
5634 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005635 status = wlansap_stop_bss(
5636 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005637
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305638 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07005639 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005640 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305641 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305642 qdf_stop_bss_event);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005643 status = qdf_wait_for_event_completion(
Nachiket Kukade0396b732017-11-14 16:35:16 +05305644 &hostapd_state->qdf_stop_bss_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +05305645 SME_CMD_STOP_BSS_TIMEOUT);
Dustin Brownd747ecd2018-10-26 16:32:22 -07005646 if (QDF_IS_STATUS_ERROR(status))
Jeff Johnson5880d792016-08-15 13:32:30 -07005647 hdd_err("failure waiting for wlansap_stop_bss %d",
Dustin Brownd747ecd2018-10-26 16:32:22 -07005648 status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005649 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07005650 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005651 }
Dustin Brownd747ecd2018-10-26 16:32:22 -07005652
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005653 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -07005654 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005655 adapter->device_mode,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08005656 adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005657 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305658 adapter->device_mode,
5659 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005660
Jeff Johnsonc565af12019-03-10 21:09:47 -07005661 qdf_copy_macaddr(&update_ie.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07005662 &adapter->mac_addr);
Jeff Johnsonc565af12019-03-10 21:09:47 -07005663 update_ie.smeSessionId = adapter->vdev_id;
5664 update_ie.ieBufferlength = 0;
5665 update_ie.pAdditionIEBuffer = NULL;
5666 update_ie.append = false;
5667 update_ie.notify = false;
Dustin Brownd747ecd2018-10-26 16:32:22 -07005668
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005669 /* Probe bcn reset */
Jeff Johnsonc565af12019-03-10 21:09:47 -07005670 status = sme_update_add_ie(mac_handle, &update_ie,
Dustin Brownd747ecd2018-10-26 16:32:22 -07005671 eUPDATE_IE_PROBE_BCN);
5672 if (status == QDF_STATUS_E_FAILURE)
5673 hdd_err("Could not pass PROBE_RSP_BCN to PE");
5674
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005675 /* Assoc resp reset */
Jeff Johnsonc565af12019-03-10 21:09:47 -07005676 status = sme_update_add_ie(mac_handle, &update_ie,
Dustin Brownd747ecd2018-10-26 16:32:22 -07005677 eUPDATE_IE_ASSOC_RESP);
5678 if (status == QDF_STATUS_E_FAILURE)
5679 hdd_err("Could not pass ASSOC_RSP to PE");
5680
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005681 /* Reset WNI_CFG_PROBE_RSP Flags */
5682 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005683 }
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005684 clear_bit(SOFTAP_INIT_DONE, &adapter->event_flags);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005685 qdf_mem_free(adapter->session.ap.beacon);
5686 adapter->session.ap.beacon = NULL;
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005687
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305688 /*
5689 * If Do_Not_Break_Stream was enabled clear avoid channel list.
5690 */
Min Liu8c5d99e2018-09-10 17:18:44 +08005691 vdev = hdd_objmgr_get_vdev(adapter);
5692 if (vdev) {
5693 if (policy_mgr_is_dnsc_set(vdev))
5694 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05305695 hdd_objmgr_put_vdev(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08005696 }
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305697
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305698#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005699 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305700#ifdef WLAN_NS_OFFLOAD
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005701 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305702#endif
5703#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08005704
5705 hdd_vdev_destroy(adapter);
5706
Krunal Sonib51eec72017-11-20 21:53:01 -08005707 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005708 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005709 case QDF_OCB_MODE:
Dustin Brownd747ecd2018-10-26 16:32:22 -07005710 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08005711 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Dustin Brownd747ecd2018-10-26 16:32:22 -07005712 cds_get_context(QDF_MODULE_ID_TXRX),
Jeff Johnson0a082d92019-03-04 12:25:49 -08005713 sta_ctx->conn_info.sta_id[0]);
Visweswara Tanukub5a61242019-03-26 12:24:13 +05305714 hdd_deregister_hl_netdev_fc_timer(adapter);
Zhang Qian79d0d132018-02-05 13:40:16 +08005715 hdd_deregister_tx_flow_control(adapter);
5716 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005717 break;
5718 default:
5719 break;
5720 }
5721
Dustin Brown04348372017-12-14 16:13:39 -08005722 if (adapter->scan_info.default_scan_ies) {
5723 qdf_mem_free(adapter->scan_info.default_scan_ies);
5724 adapter->scan_info.default_scan_ies = NULL;
5725 }
5726
Dustin Browne74003f2018-03-14 12:51:58 -07005727 hdd_exit();
Dustin Brownd747ecd2018-10-26 16:32:22 -07005728
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305729 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005730}
5731
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305732/**
5733 * hdd_deinit_all_adapters - deinit all adapters
5734 * @hdd_ctx: HDD context
5735 * @rtnl_held: True if RTNL lock held
5736 *
5737 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005738void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305739{
Jeff Johnson9d295242017-08-29 14:39:48 -07005740 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305741
Dustin Brown491d54b2018-03-14 12:39:11 -07005742 hdd_enter();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305743
Dustin Brown920397d2017-12-13 16:27:50 -08005744 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305745 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305746
Dustin Browne74003f2018-03-14 12:51:58 -07005747 hdd_exit();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305748}
5749
Dustin Browndb2a8be2017-12-20 11:49:56 -08005750QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005751{
Jeff Johnson9d295242017-08-29 14:39:48 -07005752 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005753
Dustin Brown491d54b2018-03-14 12:39:11 -07005754 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005755
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305756 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5757
Dustin Brown920397d2017-12-13 16:27:50 -08005758 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08005759 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005760
Dustin Browne74003f2018-03-14 12:51:58 -07005761 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005762
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305763 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005764}
5765
Paul Zhang84fa9382017-11-10 21:18:21 +08005766static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
5767 struct hdd_adapter *adapter)
5768{
5769 switch (adapter->device_mode) {
5770 case QDF_STA_MODE:
5771 case QDF_P2P_CLIENT_MODE:
5772 case QDF_IBSS_MODE:
5773 case QDF_P2P_DEVICE_MODE:
5774 case QDF_NDI_MODE:
5775 wlan_hdd_scan_abort(adapter);
5776 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Min Liu8c5d99e2018-09-10 17:18:44 +08005777 if (adapter->device_mode == QDF_STA_MODE) {
5778 struct wlan_objmgr_vdev *vdev;
5779
5780 vdev = hdd_objmgr_get_vdev(adapter);
5781 if (vdev) {
5782 wlan_cfg80211_sched_scan_stop(vdev);
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05305783 hdd_objmgr_put_vdev(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08005784 }
5785 }
Paul Zhang84fa9382017-11-10 21:18:21 +08005786 break;
5787 case QDF_P2P_GO_MODE:
5788 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5789 break;
5790 case QDF_SAP_MODE:
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305791 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Paul Zhang84fa9382017-11-10 21:18:21 +08005792 wlan_hdd_undo_acs(adapter);
5793 break;
5794 default:
5795 break;
5796 }
5797}
5798
Ke Huangc067b8d2018-05-21 15:50:13 +08005799#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
5800/**
5801 * hdd_adapter_abort_tx_flow() - Abort the tx flow control
5802 * @pAdapter: pointer to hdd_adapter_t
5803 *
5804 * Resume tx and stop the tx flow control timer if the tx is paused
5805 * and the flow control timer is running. This function is called by
5806 * SSR to avoid the inconsistency of tx status before and after SSR.
5807 *
5808 * Return: void
5809 */
5810static void hdd_adapter_abort_tx_flow(struct hdd_adapter *adapter)
5811{
5812 if (adapter->hdd_stats.tx_rx_stats.is_txflow_paused &&
5813 QDF_TIMER_STATE_RUNNING ==
5814 qdf_mc_timer_get_current_state(
5815 &adapter->tx_flow_control_timer)) {
5816 hdd_tx_resume_timer_expired_handler(adapter);
5817 qdf_mc_timer_stop(&adapter->tx_flow_control_timer);
5818 }
5819}
5820#endif
5821
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005822QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005823{
Jeff Johnson9d295242017-08-29 14:39:48 -07005824 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07005825 struct hdd_station_ctx *sta_ctx;
Jeff Johnson2d044612019-02-26 20:08:43 -08005826 struct qdf_mac_addr peer_macaddr;
Yue Ma42654682018-01-11 16:55:24 -08005827 int sta_id;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05305828 bool value;
Min Liu8c5d99e2018-09-10 17:18:44 +08005829 struct wlan_objmgr_vdev *vdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005830
Dustin Brown491d54b2018-03-14 12:39:11 -07005831 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005832
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305833 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5834
Dustin Brown920397d2017-12-13 16:27:50 -08005835 hdd_for_each_adapter(hdd_ctx, adapter) {
Dustin Brown5e89ef82018-03-14 11:50:23 -07005836 hdd_info("[SSR] reset adapter with device mode %s(%d)",
Dustin Brown458027c2018-10-19 12:26:27 -07005837 qdf_opmode_str(adapter->device_mode),
Dustin Brown5e89ef82018-03-14 11:50:23 -07005838 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305839
Ke Huangc067b8d2018-05-21 15:50:13 +08005840#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
5841 hdd_adapter_abort_tx_flow(adapter);
5842#endif
5843
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305844 if ((adapter->device_mode == QDF_STA_MODE) ||
Paul Zhang679025e2018-03-08 22:39:44 +08005845 (adapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305846 /* Stop tdls timers */
Min Liu8c5d99e2018-09-10 17:18:44 +08005847 vdev = hdd_objmgr_get_vdev(adapter);
5848 if (vdev) {
5849 hdd_notify_tdls_reset_adapter(vdev);
Rajeev Kumar Sirasanagandla25bdfad2019-02-15 19:15:49 +05305850 hdd_objmgr_put_vdev(vdev);
Min Liu8c5d99e2018-09-10 17:18:44 +08005851 }
Paul Zhang679025e2018-03-08 22:39:44 +08005852 adapter->session.station.hdd_reassoc_scenario = false;
5853 }
Dustin Brown05d81302018-09-11 16:49:22 -07005854 ucfg_mlme_get_sap_internal_restart(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05305855 if (value &&
Arun Khandavallicc544b32017-01-30 19:52:16 +05305856 adapter->device_mode == QDF_SAP_MODE) {
5857 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305858 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05305859 WLAN_CONTROL_PATH);
Ashish Kumar Dhanotiyadc3900f2019-01-11 20:42:04 +05305860 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
5861 cds_flush_delayed_work(
5862 &adapter->acs_pending_work);
5863 clear_bit(ACS_PENDING, &adapter->event_flags);
5864 }
5865
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005866 if (test_bit(SOFTAP_BSS_STARTED,
Ashish Kumar Dhanotiyadc3900f2019-01-11 20:42:04 +05305867 &adapter->event_flags)) {
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005868 hdd_sap_indicate_disconnect_for_sta(adapter);
Ashish Kumar Dhanotiyadc3900f2019-01-11 20:42:04 +05305869 clear_bit(SOFTAP_BSS_STARTED,
5870 &adapter->event_flags);
5871 }
5872
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005873 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305874 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305875 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005876 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005877 }
Nijun Gong104ccc72018-08-07 10:43:56 +08005878 /*
5879 * Clear fc flag if it was set before SSR to avoid TX queues
5880 * permanently stopped after SSR.
5881 * Here WLAN_START_ALL_NETIF_QUEUE will actually not start any
5882 * queue since it's blocked by reason WLAN_CONTROL_PATH.
5883 */
5884 if (adapter->pause_map & (1 << WLAN_DATA_FLOW_CONTROL))
5885 wlan_hdd_netif_queue_control(adapter,
5886 WLAN_START_ALL_NETIF_QUEUE,
5887 WLAN_DATA_FLOW_CONTROL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005888
Paul Zhang84fa9382017-11-10 21:18:21 +08005889 hdd_reset_scan_operation(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005890
5891 hdd_deinit_tx_rx(adapter);
Dustin Brown1dbefe62018-09-11 16:32:03 -07005892 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08005893 adapter->device_mode, adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005894 hdd_green_ap_start_state_mc(hdd_ctx, adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305895 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005896 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5897 hdd_wmm_adapter_close(adapter);
5898 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5899 }
5900
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305901 if (adapter->device_mode == QDF_STA_MODE)
5902 hdd_clear_fils_connection_info(adapter);
5903
Wu Gao3545e642017-07-14 19:24:41 +08005904 if (adapter->device_mode == QDF_SAP_MODE) {
Jingxiang Geec113592018-08-09 15:40:39 +08005905 wlansap_cleanup_cac_timer(
5906 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Wu Gao3545e642017-07-14 19:24:41 +08005907 /*
5908 * If adapter is SAP, set session ID to invalid
5909 * since SAP session will be cleanup during SSR.
5910 */
Wu Gao36717432016-11-21 15:09:48 +08005911 wlansap_set_invalid_session(
5912 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Wu Gao3545e642017-07-14 19:24:41 +08005913 }
5914
Abhishek Singh8f4aa182019-03-06 10:29:24 +05305915 /* Release vdev ref count to avoid vdev object leak */
5916 if (adapter->device_mode == QDF_P2P_GO_MODE ||
5917 adapter->device_mode == QDF_SAP_MODE)
5918 wlansap_release_vdev_ref(
5919 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5920
Yue Ma42654682018-01-11 16:55:24 -08005921 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005922 if (adapter->device_mode == QDF_STA_MODE ||
5923 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005924 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnson2d044612019-02-26 20:08:43 -08005925 qdf_copy_macaddr(&peer_macaddr,
Jeff Johnsone04b6992019-02-27 14:06:55 -08005926 &sta_ctx->conn_info.bssid);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005927
Yue Ma42654682018-01-11 16:55:24 -08005928 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
Wu Gao6b81fc52018-05-24 19:27:27 +08005929 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Yue Ma42654682018-01-11 16:55:24 -08005930 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5931 if (adapter->sta_info[sta_id].in_use) {
5932 hdd_debug("[SSR] deregister STA with ID %d",
5933 sta_id);
5934 hdd_softap_deregister_sta(adapter,
5935 sta_id);
5936 adapter->sta_info[sta_id].in_use = 0;
5937 }
5938 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005939 }
5940
Alok Kumarb64650c2018-03-23 17:05:11 +05305941 hdd_nud_ignore_tracking(adapter, true);
Alok Kumar016a1ac2018-09-16 09:55:50 +05305942 hdd_nud_reset_tracking(adapter);
5943 hdd_nud_flush_work(adapter);
Ashish Kumar Dhanotiyadc3900f2019-01-11 20:42:04 +05305944
5945 if (adapter->device_mode != QDF_SAP_MODE &&
5946 adapter->device_mode != QDF_P2P_GO_MODE &&
5947 adapter->device_mode != QDF_FTM_MODE)
5948 hdd_set_disconnect_status(adapter, false);
5949
hangtian9c47aaf2018-11-26 17:59:39 +08005950 hdd_stop_tsf_sync(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05305951
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005952 hdd_softap_deinit_tx_rx(adapter);
Visweswara Tanukub5a61242019-03-26 12:24:13 +05305953 hdd_deregister_hl_netdev_fc_timer(adapter);
Tiger Yu8c387702018-07-06 16:56:42 +08005954 hdd_deregister_tx_flow_control(adapter);
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005955
Yue Maf9782842017-05-08 12:49:49 -07005956 /* Destroy vdev which will be recreated during reinit. */
5957 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005958 }
5959
Dustin Browne74003f2018-03-14 12:51:58 -07005960 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005961
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305962 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005963}
5964
Dustin Brown4c663222018-10-23 14:19:36 -07005965bool hdd_is_any_interface_open(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305966{
Dustin Brown920397d2017-12-13 16:27:50 -08005967 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305968
Dustin Brown4c663222018-10-23 14:19:36 -07005969 if (hdd_get_conparam() == QDF_GLOBAL_FTM_MODE) {
Arun Khandavalliba479c42017-07-26 21:29:40 +05305970 hdd_info("FTM mode, don't close the module");
Dustin Brown4c663222018-10-23 14:19:36 -07005971 return true;
Arun Khandavalliba479c42017-07-26 21:29:40 +05305972 }
5973
Dustin Brown920397d2017-12-13 16:27:50 -08005974 hdd_for_each_adapter(hdd_ctx, adapter) {
5975 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
Dustin Brown4c663222018-10-23 14:19:36 -07005976 test_bit(SME_SESSION_OPENED, &adapter->event_flags))
5977 return true;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305978 }
5979
Dustin Brown4c663222018-10-23 14:19:36 -07005980 return false;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305981}
5982
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305983bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305984{
5985 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5986 return true;
5987 else
5988 return false;
5989}
5990
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305991#if defined CFG80211_CONNECT_BSS || \
5992 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305993#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305994 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305995/**
5996 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5997 * @timeout_reason: reason for connect timeout
5998 *
5999 * This function is used to convert host timeout
6000 * reason enum to kernel specific enum.
6001 *
6002 * Return: nl timeout enum
6003 */
6004static enum nl80211_timeout_reason hdd_convert_timeout_reason(
6005 tSirResultCodes timeout_reason)
6006{
6007 switch (timeout_reason) {
6008 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
6009 return NL80211_TIMEOUT_SCAN;
6010 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
6011 return NL80211_TIMEOUT_AUTH;
6012 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
6013 return NL80211_TIMEOUT_ASSOC;
6014 default:
6015 return NL80211_TIMEOUT_UNSPECIFIED;
6016 }
6017}
6018
6019/**
6020 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
6021 * @dev: network device
6022 * @bssid: bssid to which we want to associate
6023 * @timeout_reason: reason for connect timeout
6024 *
6025 * This API is used to send connection timeout reason to supplicant
6026 *
6027 * Return: void
6028 */
6029static void hdd_cfg80211_connect_timeout(struct net_device *dev,
6030 const u8 *bssid,
6031 tSirResultCodes timeout_reason)
6032{
6033 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006034
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306035 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
6036
6037 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
6038 nl_timeout_reason);
6039}
6040
6041/**
6042 * __hdd_connect_bss() - API to send connection status to supplicant
6043 * @dev: network device
6044 * @bssid: bssid to which we want to associate
6045 * @req_ie: Request Information Element
6046 * @req_ie_len: len of the req IE
6047 * @resp_ie: Response IE
6048 * @resp_ie_len: len of ht response IE
6049 * @status: status
6050 * @gfp: Kernel Flag
6051 * @timeout_reason: reason for connect timeout
6052 *
6053 * Return: void
6054 */
6055static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
6056 struct cfg80211_bss *bss, const u8 *req_ie,
6057 size_t req_ie_len, const u8 *resp_ie,
6058 size_t resp_ie_len, int status, gfp_t gfp,
6059 tSirResultCodes timeout_reason)
6060{
6061 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006062
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306063 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
6064
6065 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
6066 resp_ie, resp_ie_len, status, gfp,
6067 nl_timeout_reason);
6068}
6069#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306070#if defined CFG80211_CONNECT_TIMEOUT || \
6071 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306072static void hdd_cfg80211_connect_timeout(struct net_device *dev,
6073 const u8 *bssid,
6074 tSirResultCodes timeout_reason)
6075{
6076 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
6077}
6078#endif
6079
6080static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
6081 struct cfg80211_bss *bss, const u8 *req_ie,
6082 size_t req_ie_len, const u8 *resp_ie,
6083 size_t resp_ie_len, int status, gfp_t gfp,
6084 tSirResultCodes timeout_reason)
6085{
6086 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
6087 resp_ie, resp_ie_len, status, gfp);
6088}
6089#endif
6090
Abhishek Singha84d3952016-09-13 13:45:05 +05306091/**
6092 * hdd_connect_bss() - API to send connection status to supplicant
6093 * @dev: network device
6094 * @bssid: bssid to which we want to associate
6095 * @req_ie: Request Information Element
6096 * @req_ie_len: len of the req IE
6097 * @resp_ie: Response IE
6098 * @resp_ie_len: len of ht response IE
6099 * @status: status
6100 * @gfp: Kernel Flag
6101 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306102 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05306103 *
6104 * The API is a wrapper to send connection status to supplicant
6105 *
6106 * Return: Void
6107 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306108#if defined CFG80211_CONNECT_TIMEOUT || \
6109 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05306110static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
6111 struct cfg80211_bss *bss, const u8 *req_ie,
6112 size_t req_ie_len, const u8 *resp_ie,
6113 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306114 bool connect_timeout,
6115 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05306116{
6117 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306118 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05306119 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306120 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
6121 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05306122}
6123#else
6124static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
6125 struct cfg80211_bss *bss, const u8 *req_ie,
6126 size_t req_ie_len, const u8 *resp_ie,
6127 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306128 bool connect_timeout,
6129 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05306130{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306131 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
6132 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05306133}
6134#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05306135
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306136#if defined(WLAN_FEATURE_FILS_SK)
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306137#if (defined(CFG80211_CONNECT_DONE) || \
6138 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))) && \
6139 (LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0))
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306140#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
6141 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306142/**
6143 * hdd_populate_fils_params() - Populate FILS keys to connect response
6144 * @fils_params: connect response to supplicant
6145 * @fils_kek: FILS kek
6146 * @fils_kek_len: FILS kek length
6147 * @pmk: FILS PMK
6148 * @pmk_len: FILS PMK length
6149 * @pmkid: PMKID
6150 * @fils_seq_num: FILS Seq number
6151 *
6152 * Return: None
6153 */
6154static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
6155 *fils_params, const uint8_t *fils_kek,
6156 size_t fils_kek_len, const uint8_t *pmk,
6157 size_t pmk_len, const uint8_t *pmkid,
6158 uint16_t fils_seq_num)
6159{
6160 /* Increament seq number to be used for next FILS */
6161 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
6162 fils_params->update_erp_next_seq_num = true;
6163 fils_params->fils_kek = fils_kek;
6164 fils_params->fils_kek_len = fils_kek_len;
6165 fils_params->pmk = pmk;
6166 fils_params->pmk_len = pmk_len;
6167 fils_params->pmkid = pmkid;
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306168 hdd_debug("FILS erp_next_seq_num:%d",
6169 fils_params->fils_erp_next_seq_num);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306170}
6171#else
6172static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
6173 *fils_params, const uint8_t
6174 *fils_kek, size_t fils_kek_len,
6175 const uint8_t *pmk, size_t pmk_len,
6176 const uint8_t *pmkid,
6177 uint16_t fils_seq_num)
6178{ }
6179#endif
6180
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306181#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0))
6182/**
6183 * hdd_populate_fils_params() - Populate FILS keys to connect response
6184 * @fils_params: connect response to supplicant
6185 * @fils_kek: FILS kek
6186 * @fils_kek_len: FILS kek length
6187 * @pmk: FILS PMK
6188 * @pmk_len: FILS PMK length
6189 * @pmkid: PMKID
6190 * @fils_seq_num: FILS Seq number
6191 *
6192 * Return: None
6193 */
6194static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
6195 *fils_params, const uint8_t *fils_kek,
6196 size_t fils_kek_len, const uint8_t *pmk,
6197 size_t pmk_len, const uint8_t *pmkid,
6198 uint16_t fils_seq_num)
6199{
6200 /* Increament seq number to be used for next FILS */
6201 fils_params->fils.erp_next_seq_num = fils_seq_num + 1;
6202 fils_params->fils.update_erp_next_seq_num = true;
6203 fils_params->fils.kek = fils_kek;
6204 fils_params->fils.kek_len = fils_kek_len;
6205 fils_params->fils.pmk = pmk;
6206 fils_params->fils.pmk_len = pmk_len;
6207 fils_params->fils.pmkid = pmkid;
6208 hdd_debug("FILS erp_next_seq_num:%d",
6209 fils_params->fils.erp_next_seq_num);
6210}
6211#endif /* CFG80211_CONNECT_DONE */
6212
6213#if defined(CFG80211_CONNECT_DONE) || \
6214 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
6215
Jeff Johnson172237b2017-11-07 15:32:59 -08006216void hdd_update_hlp_info(struct net_device *dev,
6217 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306218{
6219 struct sk_buff *skb;
6220 uint16_t skb_len;
6221 struct llc_snap_hdr_t *llc_hdr;
6222 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306223 uint8_t *hlp_data;
6224 uint16_t hlp_data_len;
6225 struct fils_join_rsp_params *roam_fils_params
6226 = roam_info->fils_join_rsp;
Jeff Johnsona1382382019-03-31 11:08:27 -07006227 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306228
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306229 if (!roam_fils_params) {
6230 hdd_err("FILS Roam Param NULL");
6231 return;
6232 }
6233
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08006234 if (!roam_fils_params->hlp_data_len) {
Jianmin Zhucc6b3d02019-03-07 14:19:34 +08006235 hdd_debug("FILS HLP Data NULL, len %d",
6236 roam_fils_params->hlp_data_len);
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306237 return;
6238 }
6239
6240 hlp_data = roam_fils_params->hlp_data;
6241 hlp_data_len = roam_fils_params->hlp_data_len;
6242
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306243 /* Calculate skb length */
6244 skb_len = (2 * ETH_ALEN) + hlp_data_len;
6245 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
Jeff Johnsond36fa332019-03-18 13:42:25 -07006246 if (!skb) {
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306247 hdd_err("HLP packet nbuf alloc fails");
6248 return;
6249 }
6250
6251 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
6252 QDF_MAC_ADDR_SIZE);
6253 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
6254 QDF_MAC_ADDR_SIZE);
6255
6256 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
6257 if (IS_SNAP(llc_hdr)) {
6258 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
6259 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
6260 }
6261
6262 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
6263
6264 /*
6265 * This HLP packet is formed from HLP info encapsulated
6266 * in assoc response frame which is AEAD encrypted.
6267 * Hence, this checksum validation can be set unnecessary.
6268 * i.e. network layer need not worry about checksum.
6269 */
6270 skb->ip_summed = CHECKSUM_UNNECESSARY;
6271
Jeff Johnsona1382382019-03-31 11:08:27 -07006272 status = hdd_rx_packet_cbk(adapter, skb);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306273 if (QDF_IS_STATUS_ERROR(status)) {
6274 hdd_err("Sending HLP packet fails");
6275 return;
6276 }
6277 hdd_debug("send HLP packet to netif successfully");
6278}
6279
6280/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306281 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
6282 * @dev: network device
6283 * @bssid: bssid to which we want to associate
6284 * @bss: cfg80211 bss info
6285 * @roam_info: information about connected bss
6286 * @req_ie: Request Information Element
6287 * @req_ie_len: len of the req IE
6288 * @resp_ie: Response IE
6289 * @resp_ie_len: len of ht response IE
6290 * @status: status
6291 * @gfp: allocation flags
6292 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
6293 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306294 *
6295 * This API is used as wrapper to send FILS key/sequence number
6296 * params etc. to supplicant in case of FILS connection
6297 *
6298 * Return: None
6299 */
6300static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006301 struct cfg80211_bss *bss,
6302 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306303 const u8 *req_ie, size_t req_ie_len,
6304 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006305 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306306 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306307{
6308 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306309 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
6310 struct fils_join_rsp_params *roam_fils_params =
6311 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006312
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306313 qdf_mem_zero(&fils_params, sizeof(fils_params));
6314
6315 if (!roam_fils_params) {
6316 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
6317 } else {
6318 fils_params.status = status;
6319 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08006320 fils_params.timeout_reason =
6321 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306322 fils_params.req_ie = req_ie;
6323 fils_params.req_ie_len = req_ie_len;
6324 fils_params.resp_ie = resp_ie;
6325 fils_params.resp_ie_len = resp_ie_len;
6326 fils_params.bss = bss;
6327 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
6328 roam_fils_params->kek_len,
6329 roam_fils_params->fils_pmk,
6330 roam_fils_params->fils_pmk_len,
6331 roam_fils_params->fils_pmkid,
6332 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05306333 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306334 }
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306335 hdd_debug("FILS indicate connect status %d", fils_params.status);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306336
6337 cfg80211_connect_done(dev, &fils_params, gfp);
6338
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306339 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306340 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306341
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306342 /* Clear all the FILS key info */
6343 if (roam_fils_params && roam_fils_params->fils_pmk)
6344 qdf_mem_free(roam_fils_params->fils_pmk);
6345 if (roam_fils_params)
6346 qdf_mem_free(roam_fils_params);
6347 roam_info->fils_join_rsp = NULL;
6348}
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306349#else /* CFG80211_CONNECT_DONE */
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006350static inline void
6351hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006352 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07006353 const u8 *req_ie, size_t req_ie_len,
6354 const u8 *resp_ie, size_t resp_ie_len, u16 status,
6355 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306356 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05306357{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306358#endif
Pragaspathi Thilagaraj9e619082019-01-24 15:15:45 +05306359#endif /* WLAN_FEATURE_FILS_SK */
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306360
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05306361#if defined(WLAN_FEATURE_FILS_SK) && \
6362 (defined(CFG80211_CONNECT_DONE) || \
6363 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306364/**
6365 * hdd_fils_update_connect_results() - API to send fils connection status to
6366 * supplicant.
6367 * @dev: network device
6368 * @bssid: bssid to which we want to associate
6369 * @bss: cfg80211 bss info
6370 * @roam_info: information about connected bss
6371 * @req_ie: Request Information Element
6372 * @req_ie_len: len of the req IE
6373 * @resp_ie: Response IE
6374 * @resp_ie_len: len of ht response IE
6375 * @status: status
6376 * @gfp: allocation flags
6377 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
6378 * @timeout_reason: reason for connect timeout
6379 *
6380 * The API is a wrapper to send connection status to supplicant
6381 *
6382 * Return: 0 if success else failure
6383 */
6384static int hdd_fils_update_connect_results(struct net_device *dev,
6385 const u8 *bssid,
6386 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08006387 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306388 size_t req_ie_len, const u8 *resp_ie,
6389 size_t resp_ie_len, u16 status, gfp_t gfp,
6390 bool connect_timeout,
6391 tSirResultCodes timeout_reason)
6392{
Dustin Brown491d54b2018-03-14 12:39:11 -07006393 hdd_enter();
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306394 if (!roam_info || !roam_info->is_fils_connection)
6395 return -EINVAL;
6396
6397 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
6398 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05306399 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306400 return 0;
6401}
6402#else
6403static inline int hdd_fils_update_connect_results(struct net_device *dev,
6404 const u8 *bssid,
6405 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08006406 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306407 size_t req_ie_len, const u8 *resp_ie,
6408 size_t resp_ie_len, u16 status, gfp_t gfp,
6409 bool connect_timeout,
6410 tSirResultCodes timeout_reason)
6411{
6412 return -EINVAL;
6413}
6414#endif
6415
Anurag Chouhanc4092922016-09-08 15:56:11 +05306416/**
6417 * hdd_connect_result() - API to send connection status to supplicant
6418 * @dev: network device
6419 * @bssid: bssid to which we want to associate
6420 * @roam_info: information about connected bss
6421 * @req_ie: Request Information Element
6422 * @req_ie_len: len of the req IE
6423 * @resp_ie: Response IE
6424 * @resp_ie_len: len of ht response IE
6425 * @status: status
6426 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05306427 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306428 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05306429 *
6430 * The API is a wrapper to send connection status to supplicant
6431 * and allow runtime suspend
6432 *
6433 * Return: Void
6434 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306435void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006436 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05306437 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05306438 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306439 bool connect_timeout,
6440 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05306441{
Jeff Johnsona1382382019-03-31 11:08:27 -07006442 struct hdd_adapter *adapter = netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306443 struct cfg80211_bss *bss = NULL;
Jeff Johnsona1382382019-03-31 11:08:27 -07006444 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306445
6446 if (WLAN_STATUS_SUCCESS == status) {
6447 struct ieee80211_channel *chan;
6448 int freq;
6449 int chan_no = roam_info->pBssDesc->channelId;
6450
6451 if (chan_no <= 14)
6452 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07006453 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306454 else
6455 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07006456 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306457
Jeff Johnsona1382382019-03-31 11:08:27 -07006458 chan = ieee80211_get_channel(adapter->wdev.wiphy, freq);
6459 bss = wlan_cfg80211_get_bss(adapter->wdev.wiphy, chan, bssid,
Anurag Chouhanc4092922016-09-08 15:56:11 +05306460 roam_info->u.pConnectedProfile->SSID.ssId,
6461 roam_info->u.pConnectedProfile->SSID.length);
6462 }
Komal Seelama89be8d2016-09-29 11:09:26 +05306463
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306464 if (hdd_fils_update_connect_results(dev, bssid, bss,
6465 roam_info, req_ie, req_ie_len, resp_ie,
6466 resp_ie_len, status, gfp, connect_timeout,
6467 timeout_reason) != 0) {
6468 hdd_connect_bss(dev, bssid, bss, req_ie,
6469 req_ie_len, resp_ie, resp_ie_len,
6470 status, gfp, connect_timeout, timeout_reason);
6471 }
Komal Seelama89be8d2016-09-29 11:09:26 +05306472
Jingxiang Geb49aa302018-01-17 20:54:15 +08006473 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07006474 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306475}
6476#else
6477void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006478 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05306479 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05306480 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306481 bool connect_timeout,
6482 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05306483{
Jeff Johnsona1382382019-03-31 11:08:27 -07006484 struct hdd_adapter *adapter = netdev_priv(dev);
6485 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05306486
Anurag Chouhanc4092922016-09-08 15:56:11 +05306487 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
6488 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08006489
Jingxiang Geb49aa302018-01-17 20:54:15 +08006490 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07006491 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306492}
6493#endif
6494
Nirav Shah73713f72018-05-17 14:50:41 +05306495#ifdef FEATURE_MONITOR_MODE_SUPPORT
Jeff Johnsond9952752018-04-18 12:15:35 -07006496int wlan_hdd_set_mon_chan(struct hdd_adapter *adapter, uint32_t chan,
6497 uint32_t bandwidth)
6498{
6499 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6500 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
6501 struct hdd_mon_set_ch_info *ch_info = &sta_ctx->ch_info;
6502 QDF_STATUS status;
Jeff Johnson43837af2018-10-17 12:44:05 -07006503 mac_handle_t mac_handle = hdd_ctx->mac_handle;
Jeff Johnsond9952752018-04-18 12:15:35 -07006504 struct qdf_mac_addr bssid;
6505 struct csr_roam_profile roam_profile;
6506 struct ch_params ch_params;
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006507 eConnectionState connstate;
Jeff Johnsond9952752018-04-18 12:15:35 -07006508
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006509 if (hdd_get_conparam() != QDF_GLOBAL_MONITOR_MODE &&
6510 adapter->device_mode != QDF_STA_MODE) {
6511 hdd_err("Not supported, device is not in monitor mode or sta mission mode");
Jeff Johnsond9952752018-04-18 12:15:35 -07006512 return -EINVAL;
6513 }
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006514 if (adapter->device_mode == QDF_STA_MODE &&
Pragaspathi Thilagaraja8893752019-02-06 19:58:59 +05306515 ucfg_mlme_is_change_channel_bandwidth_enabled(hdd_ctx->psoc)) {
Jeff Johnsone7951512019-02-27 10:02:51 -08006516 connstate = sta_ctx->conn_info.conn_state;
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006517 if (eConnectionState_Associated == connstate ||
6518 eConnectionState_Connecting == connstate) {
6519 return -EINVAL;
6520 }
6521 }
Jeff Johnsond9952752018-04-18 12:15:35 -07006522
Visweswara Tanuku006313a2018-04-12 12:26:34 +05306523 /* Validate Channel */
6524 if (!WLAN_REG_IS_24GHZ_CH(chan) && !WLAN_REG_IS_5GHZ_CH(chan)) {
6525 hdd_err("Channel %d Not supported", chan);
6526 return -EINVAL;
6527 }
6528
6529 if (WLAN_REG_IS_24GHZ_CH(chan)) {
6530 if (bandwidth == CH_WIDTH_80MHZ) {
6531 hdd_err("BW80 not possible in 2.4GHz band");
6532 return -EINVAL;
6533 }
6534 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 14) &&
6535 (bandwidth != CH_WIDTH_MAX)) {
6536 hdd_err("Only BW20 possible on channel 14");
6537 return -EINVAL;
6538 }
6539 }
6540
6541 if (WLAN_REG_IS_5GHZ_CH(chan)) {
6542 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 165) &&
6543 (bandwidth != CH_WIDTH_MAX)) {
6544 hdd_err("Only BW20 possible on channel 165");
6545 return -EINVAL;
6546 }
6547 }
6548
Jeff Johnsond9952752018-04-18 12:15:35 -07006549 hdd_debug("Set monitor mode Channel %d", chan);
6550 qdf_mem_zero(&roam_profile, sizeof(roam_profile));
6551 roam_profile.ChannelInfo.ChannelList = &ch_info->channel;
6552 roam_profile.ChannelInfo.numOfChannels = 1;
6553 roam_profile.phyMode = ch_info->phy_mode;
6554 roam_profile.ch_params.ch_width = bandwidth;
6555 hdd_select_cbmode(adapter, chan, &roam_profile.ch_params);
Pragaspathi Thilagaraja8893752019-02-06 19:58:59 +05306556 if (ucfg_mlme_is_change_channel_bandwidth_enabled(hdd_ctx->psoc) &&
Jeff Johnson43837af2018-10-17 12:44:05 -07006557 (!sme_find_session_by_bssid(mac_handle, adapter->mac_addr.bytes))) {
6558 status = sme_create_mon_session(mac_handle,
Rajeev Kumar Sirasanagandlae3b59912018-08-24 15:53:31 +05306559 adapter->mac_addr.bytes,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08006560 adapter->vdev_id);
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006561 if (status != QDF_STATUS_SUCCESS) {
6562 hdd_err("Status: %d Failed to create session.",
6563 status);
6564 return qdf_status_to_os_return(status);
6565 }
6566 }
Jeff Johnsond9952752018-04-18 12:15:35 -07006567 qdf_mem_copy(bssid.bytes, adapter->mac_addr.bytes,
6568 QDF_MAC_ADDR_SIZE);
6569
6570 ch_params.ch_width = bandwidth;
Dustin Brown07901ec2018-09-07 11:02:41 -07006571 wlan_reg_set_channel_params(hdd_ctx->pdev, chan, 0, &ch_params);
Jeff Johnsond9952752018-04-18 12:15:35 -07006572 if (ch_params.ch_width == CH_WIDTH_INVALID) {
6573 hdd_err("Invalid capture channel or bandwidth for a country");
6574 return -EINVAL;
6575 }
6576 if (wlan_hdd_change_hw_mode_for_given_chnl(adapter, chan,
6577 POLICY_MGR_UPDATE_REASON_SET_OPER_CHAN)) {
6578 hdd_err("Failed to change hw mode");
6579 return -EINVAL;
6580 }
6581
Jeff Johnson16528362018-06-14 12:34:16 -07006582 status = sme_roam_channel_change_req(hdd_ctx->mac_handle,
6583 bssid, &ch_params,
Jeff Johnsond9952752018-04-18 12:15:35 -07006584 &roam_profile);
6585 if (status) {
6586 hdd_err("Status: %d Failed to set sme_roam Channel for monitor mode",
6587 status);
6588 }
6589
6590 adapter->mon_chan = chan;
6591 adapter->mon_bandwidth = bandwidth;
6592 return qdf_status_to_os_return(status);
6593}
Nirav Shah73713f72018-05-17 14:50:41 +05306594#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05306595
Wu Gaodf929f12018-05-25 18:12:25 +08006596#ifdef MSM_PLATFORM
6597/**
6598 * hdd_stop_p2p_go() - call cfg80211 API to stop P2P GO
6599 * @adapter: pointer to adapter
6600 *
6601 * This function calls cfg80211 API to stop P2P GO
6602 *
6603 * Return: None
6604 */
6605static void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6606{
6607 hdd_debug("[SSR] send stop ap to supplicant");
6608 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
6609}
6610
6611static inline void hdd_delete_sta(struct hdd_adapter *adapter)
6612{
6613}
6614#else
6615static inline void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6616{
6617}
6618
6619/**
6620 * hdd_delete_sta() - call cfg80211 API to delete STA
6621 * @adapter: pointer to adapter
6622 *
6623 * This function calls cfg80211 API to delete STA
6624 *
6625 * Return: None
6626 */
6627static void hdd_delete_sta(struct hdd_adapter *adapter)
6628{
6629 struct qdf_mac_addr bcast_mac = QDF_MAC_ADDR_BCAST_INIT;
6630
6631 hdd_debug("[SSR] send restart supplicant");
6632 /* event supplicant to restart */
6633 cfg80211_del_sta(adapter->dev,
6634 (const u8 *)&bcast_mac.bytes[0],
6635 GFP_KERNEL);
6636}
6637#endif
6638
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006639QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006640{
Jeff Johnson9d295242017-08-29 14:39:48 -07006641 struct hdd_adapter *adapter;
Jeff Johnsone7951512019-02-27 10:02:51 -08006642 eConnectionState conn_state;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05306643 bool value;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006644
Dustin Brown491d54b2018-03-14 12:39:11 -07006645 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006646
Dustin Brown920397d2017-12-13 16:27:50 -08006647 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05306648 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08006649 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05306650
Yue Ma42654682018-01-11 16:55:24 -08006651 hdd_debug("[SSR] start adapter with device mode %s(%d)",
Dustin Brown458027c2018-10-19 12:26:27 -07006652 qdf_opmode_str(adapter->device_mode),
Yue Ma42654682018-01-11 16:55:24 -08006653 adapter->device_mode);
6654
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006655 hdd_wmm_init(adapter);
6656
6657 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006658 case QDF_STA_MODE:
6659 case QDF_P2P_CLIENT_MODE:
6660 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006661
Jeff Johnsone7951512019-02-27 10:02:51 -08006662 conn_state = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
6663 ->conn_info.conn_state;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006664
Krunal Sonib51eec72017-11-20 21:53:01 -08006665 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006666 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07006667 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006668
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006669 /* Indicate disconnect event to supplicant
6670 * if associated previously
6671 */
Jeff Johnsone7951512019-02-27 10:02:51 -08006672 if (eConnectionState_Associated == conn_state ||
6673 eConnectionState_IbssConnected == conn_state ||
6674 eConnectionState_NotConnected == conn_state ||
6675 eConnectionState_IbssDisconnected == conn_state ||
6676 eConnectionState_Disconnecting == conn_state) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006677 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006678
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006679 memset(&wrqu, '\0', sizeof(wrqu));
6680 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
6681 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
6682 wireless_send_event(adapter->dev, SIOCGIWAP,
6683 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07006684 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07006685 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006686
6687 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05306688 wlan_hdd_cfg80211_indicate_disconnect(
6689 adapter->dev, false,
6690 WLAN_REASON_UNSPECIFIED);
Jeff Johnsone7951512019-02-27 10:02:51 -08006691 } else if (eConnectionState_Connecting == conn_state) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006692 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006693 * Indicate connect failure to supplicant if we
6694 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006695 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306696 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306697 NULL, 0, NULL, 0,
6698 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006699 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006700 }
6701
6702 hdd_register_tx_flow_control(adapter,
6703 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08006704 hdd_tx_resume_cb,
6705 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006706
Visweswara Tanukub5a61242019-03-26 12:24:13 +05306707 hdd_register_hl_netdev_fc_timer(
6708 adapter,
6709 hdd_tx_resume_timer_expired_handler);
6710
Arunk Khandavalli40943af2017-05-15 19:25:34 +05306711 hdd_lpass_notify_start(hdd_ctx, adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05306712 hdd_nud_ignore_tracking(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006713 break;
6714
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006715 case QDF_SAP_MODE:
Dustin Brown05d81302018-09-11 16:49:22 -07006716 ucfg_mlme_get_sap_internal_restart(hdd_ctx->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05306717 &value);
6718 if (value)
Krunal Sonib51eec72017-11-20 21:53:01 -08006719 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05306720
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006721 break;
6722
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006723 case QDF_P2P_GO_MODE:
Wu Gaodf929f12018-05-25 18:12:25 +08006724 hdd_delete_sta(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006725 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306726 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08006727 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306728 hdd_set_mon_rx_cb(adapter->dev);
6729 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
6730 adapter->mon_bandwidth);
6731 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006732 default:
6733 break;
6734 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07006735 /*
6736 * Action frame registered in one adapter which will
6737 * applicable to all interfaces
6738 */
6739 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006740 }
6741
Wu Gaodf929f12018-05-25 18:12:25 +08006742 hdd_for_each_adapter(hdd_ctx, adapter) {
6743 if (!hdd_is_interface_up(adapter))
6744 continue;
6745
6746 if (adapter->device_mode == QDF_P2P_GO_MODE)
6747 hdd_stop_p2p_go(adapter);
6748 }
6749
Dustin Browne74003f2018-03-14 12:51:58 -07006750 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006751
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306752 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006753}
6754
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006755QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006756 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006757{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306758 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006759 qdf_list_node_t *node;
6760
6761 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006762
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006763 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006764 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006765 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006766
6767 if (QDF_IS_STATUS_ERROR(status))
6768 return status;
6769
6770 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6771
6772 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006773}
6774
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006775QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006776 struct hdd_adapter *current_adapter,
6777 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006778{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306779 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006780 qdf_list_node_t *node;
6781
6782 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006783
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006784 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006785 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08006786 &current_adapter->node,
6787 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006788 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006789
6790 if (QDF_IS_STATUS_ERROR(status))
6791 return status;
6792
6793 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6794
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006795 return status;
6796}
6797
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006798QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006799 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006800{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306801 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006802
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006803 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006804 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006805 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006806
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006807 return status;
6808}
6809
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006810QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006811 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006812{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306813 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006814 qdf_list_node_t *node;
6815
6816 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006817
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006818 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006819 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006820 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006821
6822 if (QDF_IS_STATUS_ERROR(status))
6823 return status;
6824
6825 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6826
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006827 return status;
6828}
6829
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006830QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006831 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006832{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306833 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006834
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006835 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006836 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006837 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006838
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006839 return status;
6840}
6841
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006842QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006843 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006844{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306845 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006846
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006847 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006848 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006849 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006850
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006851 return status;
6852}
6853
Liangwei Dong3abfe8f2018-09-20 02:25:44 -04006854struct hdd_adapter *hdd_get_adapter_by_rand_macaddr(
6855 struct hdd_context *hdd_ctx, tSirMacAddr mac_addr)
6856{
6857 struct hdd_adapter *adapter;
6858
6859 hdd_for_each_adapter(hdd_ctx, adapter) {
6860 if ((adapter->device_mode == QDF_STA_MODE ||
6861 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6862 adapter->device_mode == QDF_P2P_DEVICE_MODE) &&
6863 ucfg_p2p_check_random_mac(hdd_ctx->psoc,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08006864 adapter->vdev_id, mac_addr))
Liangwei Dong3abfe8f2018-09-20 02:25:44 -04006865 return adapter;
6866 }
6867
6868 return NULL;
6869}
6870
Jeff Johnson9d295242017-08-29 14:39:48 -07006871struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07006872 tSirMacAddr mac_addr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006873{
Jeff Johnson9d295242017-08-29 14:39:48 -07006874 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006875
Dustin Brown920397d2017-12-13 16:27:50 -08006876 hdd_for_each_adapter(hdd_ctx, adapter) {
6877 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
Jeff Johnsonaa6cbb82019-03-10 19:31:35 -07006878 mac_addr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006879 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006880 }
6881
6882 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006883}
6884
Jeff Johnson9d295242017-08-29 14:39:48 -07006885struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Jeff Johnson55d2ab42019-03-06 11:43:49 -08006886 uint32_t vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006887{
Jeff Johnson9d295242017-08-29 14:39:48 -07006888 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006889
Dustin Brown920397d2017-12-13 16:27:50 -08006890 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson5a6fc962019-02-04 14:20:25 -08006891 if (adapter->vdev_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006892 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006893 }
6894
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006895 return NULL;
6896}
6897
Jeff Johnson9d295242017-08-29 14:39:48 -07006898struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07006899 const char *iface_name)
6900{
Jeff Johnson9d295242017-08-29 14:39:48 -07006901 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006902
Dustin Brown920397d2017-12-13 16:27:50 -08006903 hdd_for_each_adapter(hdd_ctx, adapter) {
6904 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07006905 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006906 }
Dustin Brown920397d2017-12-13 16:27:50 -08006907
Naveen Rawat4edb6822017-04-12 10:09:17 -07006908 return NULL;
6909}
6910
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006911/**
6912 * hdd_get_adapter() - to get adapter matching the mode
6913 * @hdd_ctx: hdd context
6914 * @mode: adapter mode
6915 *
6916 * This routine will return the pointer to adapter matching
6917 * with the passed mode.
6918 *
6919 * Return: pointer to adapter or null
6920 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006921struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006922 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006923{
Jeff Johnson9d295242017-08-29 14:39:48 -07006924 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006925
Dustin Brown920397d2017-12-13 16:27:50 -08006926 hdd_for_each_adapter(hdd_ctx, adapter) {
6927 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006928 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006929 }
6930
6931 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006932}
6933
Jeff Johnson55d2ab42019-03-06 11:43:49 -08006934enum QDF_OPMODE hdd_get_device_mode(uint32_t vdev_id)
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306935{
6936 struct hdd_context *hdd_ctx;
6937 struct hdd_adapter *adapter;
6938
6939 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
6940 if (!hdd_ctx) {
6941 hdd_err("Invalid HDD context");
6942 return QDF_MAX_NO_OF_MODE;
6943 }
6944
Jeff Johnson55d2ab42019-03-06 11:43:49 -08006945 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306946 if (!adapter) {
6947 hdd_err("Invalid HDD adapter");
6948 return QDF_MAX_NO_OF_MODE;
6949 }
6950
6951 return adapter->device_mode;
6952}
6953
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006954/**
6955 * hdd_get_operating_channel() - return operating channel of the device mode
6956 * @hdd_ctx: Pointer to the HDD context.
6957 * @mode: Device mode for which operating channel is required.
Jeff Johnson77f89bb2018-05-06 16:21:36 -07006958 * Supported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006959 * QDF_STA_MODE,
6960 * QDF_P2P_CLIENT_MODE,
6961 * QDF_SAP_MODE,
6962 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006963 *
6964 * This API returns the operating channel of the requested device mode
6965 *
6966 * Return: channel number. "0" id the requested device is not found OR it is
6967 * not connected.
6968 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006969uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006970 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006971{
Jeff Johnson9d295242017-08-29 14:39:48 -07006972 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006973 uint8_t operatingChannel = 0;
6974
Dustin Brown920397d2017-12-13 16:27:50 -08006975 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006976 if (mode == adapter->device_mode) {
6977 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006978 case QDF_STA_MODE:
6979 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006980 if (hdd_conn_is_connected
6981 (WLAN_HDD_GET_STATION_CTX_PTR
6982 (adapter))) {
6983 operatingChannel =
6984 (WLAN_HDD_GET_STATION_CTX_PTR
6985 (adapter))->conn_info.
Jeff Johnson8626e932019-02-27 18:35:22 -08006986 channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006987 }
6988 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006989 case QDF_SAP_MODE:
6990 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006991 /* softap connection info */
6992 if (test_bit
6993 (SOFTAP_BSS_STARTED,
6994 &adapter->event_flags))
6995 operatingChannel =
6996 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07006997 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006998 break;
6999 default:
7000 break;
7001 }
7002
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007003 /* Found the device of interest. break the loop */
7004 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007005 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007006 }
Dustin Brown920397d2017-12-13 16:27:50 -08007007
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007008 return operatingChannel;
7009}
7010
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007011static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007012 hdd_ctx)
7013{
Jeff Johnson9d295242017-08-29 14:39:48 -07007014 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007015
Dustin Brown491d54b2018-03-14 12:39:11 -07007016 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007017
Dustin Brown920397d2017-12-13 16:27:50 -08007018 hdd_for_each_adapter(hdd_ctx, adapter) {
7019 if (adapter->device_mode == QDF_STA_MODE ||
7020 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
7021 adapter->device_mode == QDF_IBSS_MODE ||
7022 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
7023 adapter->device_mode == QDF_SAP_MODE ||
7024 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007025 hdd_unregister_wext(adapter->dev);
7026 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007027 }
7028
Dustin Browne74003f2018-03-14 12:51:58 -07007029 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007030
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307031 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007032}
7033
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007034QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007035{
Jeff Johnson9d295242017-08-29 14:39:48 -07007036 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007037
Dustin Brown491d54b2018-03-14 12:39:11 -07007038 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007039
Dustin Brown920397d2017-12-13 16:27:50 -08007040 hdd_for_each_adapter(hdd_ctx, adapter) {
7041 if (adapter->device_mode == QDF_STA_MODE ||
7042 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
7043 adapter->device_mode == QDF_IBSS_MODE ||
7044 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
7045 adapter->device_mode == QDF_SAP_MODE ||
7046 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brown07901ec2018-09-07 11:02:41 -07007047 wlan_abort_scan(hdd_ctx->pdev, INVAL_PDEV_ID,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08007048 adapter->vdev_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05307049 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007050 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007051 }
7052
Dustin Browne74003f2018-03-14 12:51:58 -07007053 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007054
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307055 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007056}
7057
Dustin Brownf27bce82016-11-03 12:52:27 -07007058/**
7059 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
7060 * adapters
7061 * @hdd_ctx: The HDD context containing the adapters to operate on
7062 *
7063 * return: QDF_STATUS_SUCCESS
7064 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007065static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07007066{
Jeff Johnson9d295242017-08-29 14:39:48 -07007067 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07007068 int err;
7069
Dustin Brown491d54b2018-03-14 12:39:11 -07007070 hdd_enter();
Dustin Brownf27bce82016-11-03 12:52:27 -07007071
Dustin Brown920397d2017-12-13 16:27:50 -08007072 hdd_for_each_adapter(hdd_ctx, adapter) {
7073 if (adapter->device_mode == QDF_STA_MODE ||
7074 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
7075 adapter->device_mode == QDF_IBSS_MODE ||
7076 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
7077 adapter->device_mode == QDF_SAP_MODE ||
7078 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07007079 err = wlan_hdd_sched_scan_stop(adapter->dev);
7080 if (err)
7081 hdd_err("Unable to stop scheduled scan");
7082 }
Dustin Brownf27bce82016-11-03 12:52:27 -07007083 }
7084
Dustin Browne74003f2018-03-14 12:51:58 -07007085 hdd_exit();
Dustin Brownf27bce82016-11-03 12:52:27 -07007086
7087 return QDF_STATUS_SUCCESS;
7088}
7089
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007090#ifdef WLAN_NS_OFFLOAD
7091/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007092 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007093 * @hdd_ctx: Pointer to hdd context
7094 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007095 * Unregister for IPv6 address change notifications.
7096 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007097 * Return: None
7098 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007099static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007100{
7101 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007102}
7103
7104/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007105 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007106 * @hdd_ctx: Pointer to hdd context
7107 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007108 * Register for IPv6 address change notifications.
7109 *
7110 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007111 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007112static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007113{
7114 int ret;
7115
7116 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
7117 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007118 if (ret) {
7119 hdd_err("Failed to register IPv6 notifier: %d", ret);
7120 goto out;
7121 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007122
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007123 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007124out:
7125 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007126}
7127#else
7128/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007129 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007130 * @hdd_ctx: Pointer to hdd context
7131 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007132 * Unregister for IPv6 address change notifications.
7133 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007134 * Return: None
7135 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007136static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007137{
7138}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007139
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007140/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007141 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007142 * @hdd_ctx: Pointer to hdd context
7143 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007144 * Register for IPv6 address change notifications.
7145 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007146 * Return: None
7147 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007148static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007149{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007150 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007151}
7152#endif
7153
Alok Kumarb64650c2018-03-23 17:05:11 +05307154void hdd_set_disconnect_status(struct hdd_adapter *adapter, bool status)
7155{
7156 qdf_mutex_acquire(&adapter->disconnection_status_lock);
7157 adapter->disconnection_in_progress = status;
7158 qdf_mutex_release(&adapter->disconnection_status_lock);
7159 hdd_debug("setting disconnection status: %d", status);
7160}
7161
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007162/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007163 * hdd_register_notifiers - Register netdev notifiers.
7164 * @hdd_ctx: HDD context
7165 *
7166 * Register netdev notifiers like IPv4 and IPv6.
7167 *
7168 * Return: 0 on success and errno on failure
7169 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007170static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007171{
7172 int ret;
7173
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007174 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
7175 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05307176 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007177
7178 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
7179 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
7180 if (ret) {
7181 hdd_err("Failed to register IPv4 notifier: %d", ret);
7182 goto unregister_ip6_notifier;
7183 }
7184
Alok Kumarb64650c2018-03-23 17:05:11 +05307185 ret = hdd_nud_register_netevent_notifier(hdd_ctx);
7186 if (ret) {
7187 hdd_err("Failed to register netevent notifier: %d",
7188 ret);
7189 goto unregister_inetaddr_notifier;
7190 }
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007191 return 0;
7192
Alok Kumarb64650c2018-03-23 17:05:11 +05307193unregister_inetaddr_notifier:
7194 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007195unregister_ip6_notifier:
7196 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007197out:
7198 return ret;
7199
7200}
7201
7202/**
7203 * hdd_unregister_notifiers - Unregister netdev notifiers.
7204 * @hdd_ctx: HDD context
7205 *
7206 * Unregister netdev notifiers like IPv4 and IPv6.
7207 *
7208 * Return: None.
7209 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007210void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007211{
Alok Kumarb64650c2018-03-23 17:05:11 +05307212 hdd_nud_unregister_netevent_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007213 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
7214
7215 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07007216}
7217
7218/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007219 * hdd_exit_netlink_services - Exit netlink services
7220 * @hdd_ctx: HDD context
7221 *
7222 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
7223 * nl service.
7224 *
7225 * Return: None.
7226 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007227static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007228{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307229 spectral_scan_deactivate_service();
7230 cnss_diag_deactivate_service();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007231 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007232 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307233 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007234
7235 nl_srv_exit();
7236}
7237
7238/**
7239 * hdd_init_netlink_services- Init netlink services
7240 * @hdd_ctx: HDD context
7241 *
7242 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
7243 * nl service.
7244 *
7245 * Return: 0 on success and errno on failure.
7246 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007247static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007248{
7249 int ret;
7250
Ryan Hsuceddceb2016-04-28 10:20:14 -07007251 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007252 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007253 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007254 goto out;
7255 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07007256 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007257
Naveen Rawat910726a2017-03-06 11:42:51 -08007258 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007259 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007260 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007261 goto err_nl_srv;
7262 }
7263
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307264 ptt_sock_activate_svc();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007265
7266 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07007267 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007268 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007269
7270 ret = cnss_diag_activate_service();
7271 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007272 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007273 goto err_close_cesium;
7274 }
7275
Dustin Brown01520852019-02-27 12:14:16 -08007276 spectral_scan_activate_service(hdd_ctx);
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08007277
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007278 return 0;
7279
7280err_close_cesium:
7281 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007282 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05307283 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007284err_nl_srv:
7285 nl_srv_exit();
7286out:
7287 return ret;
7288}
7289
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007290/**
7291 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
7292 * @hdd_ctx: HDD context.
7293 *
7294 * Destroy RX wakelock.
7295 *
7296 * Return: None.
7297 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007298static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007299{
7300 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
7301}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08007302
7303/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007304 * hdd_rx_wake_lock_create() - Create RX wakelock
7305 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007306 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007307 * Create RX wakelock.
7308 *
7309 * Return: None.
7310 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007311static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007312{
7313 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
7314}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007315
7316/**
Houston Hoffman160db392016-10-10 17:37:51 -07007317 * hdd_context_deinit() - Deinitialize HDD context
7318 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007319 *
Houston Hoffman160db392016-10-10 17:37:51 -07007320 * Deinitialize HDD context along with all the feature specific contexts but
7321 * do not free hdd context itself. Caller of this API is supposed to free
7322 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007323 *
Houston Hoffman160db392016-10-10 17:37:51 -07007324 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007325 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007326static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007327{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05307328 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
7329
Houston Hoffman160db392016-10-10 17:37:51 -07007330 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007331
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007332 hdd_sap_context_destroy(hdd_ctx);
7333
7334 hdd_rx_wake_lock_destroy(hdd_ctx);
7335
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007336 hdd_scan_context_destroy(hdd_ctx);
7337
Jeff Johnson19fc8e42017-10-30 19:53:49 -07007338 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007339
Houston Hoffman160db392016-10-10 17:37:51 -07007340 return 0;
7341}
7342
Dustin Brown623e7e32018-09-05 14:27:50 -07007343void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07007344{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07007345 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05307346
Dustin Brown623e7e32018-09-05 14:27:50 -07007347 hdd_exit_netlink_services(hdd_ctx);
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05307348 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
7349
Houston Hoffman160db392016-10-10 17:37:51 -07007350 hdd_context_deinit(hdd_ctx);
7351
Dustin Browndb2df2e2018-10-31 15:29:24 -07007352 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
7353
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307354 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007355 hdd_ctx->config = NULL;
Dustin Brown84f46ea2018-02-15 11:57:36 -08007356 cfg_release();
7357
Min Liu47104042019-04-09 17:49:21 +08007358 qdf_delayed_work_destroy(&hdd_ctx->psoc_idle_timeout_work);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08007359 wiphy_free(hdd_ctx->wiphy);
7360}
7361
7362/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05307363 * wlan_destroy_bug_report_lock() - Destroy bug report lock
7364 *
7365 * This function is used to destroy bug report lock
7366 *
7367 * Return: None
7368 */
7369static void wlan_destroy_bug_report_lock(void)
7370{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07007371 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05307372
7373 p_cds_context = cds_get_global_context();
7374 if (!p_cds_context) {
7375 hdd_err("cds context is NULL");
7376 return;
7377 }
7378
7379 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
7380}
7381
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05307382#ifdef DISABLE_CHANNEL_LIST
7383static void wlan_hdd_cache_chann_mutex_destroy(struct hdd_context *hdd_ctx)
7384{
7385 qdf_mutex_destroy(&hdd_ctx->cache_channel_lock);
7386}
7387#else
7388static void wlan_hdd_cache_chann_mutex_destroy(struct hdd_context *hdd_ctx)
7389{
7390}
7391#endif
7392
Dustin Brown92bd8382018-10-31 15:49:46 -07007393void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007394{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007395 struct wiphy *wiphy = hdd_ctx->wiphy;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007396
Dustin Brown491d54b2018-03-14 12:39:11 -07007397 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007398
Arun Kumar Khandavallideda5a82019-03-11 15:32:19 +05307399 hdd_debugfs_mws_coex_info_deinit(hdd_ctx);
Dustin Brown4c663222018-10-23 14:19:36 -07007400 hdd_psoc_idle_timer_stop(hdd_ctx);
Dustin Brown6470aba2018-09-05 09:49:58 -07007401
Arun Khandavallifae92942016-08-01 13:31:08 +05307402 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007403
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007404#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05307405 if (QDF_TIMER_STATE_RUNNING ==
7406 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
7407 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007408 }
7409
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307410 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05307411 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07007412 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007413 }
Liangwei Dongaef84342016-10-21 05:28:00 -04007414 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
7415 qdf_mem_free(hdd_ctx->last_acs_channel_list);
7416 hdd_ctx->last_acs_channel_list = NULL;
7417 hdd_ctx->num_of_channels = 0;
7418 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007419#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007420
7421 /*
7422 * Powersave Offload Case
7423 * Disable Idle Power Save Mode
7424 */
7425 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07007426 /* clear the scan queue in all the scenarios */
Dustin Brown07901ec2018-09-07 11:02:41 -07007427 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007428
Dustin Brownf688ea12019-03-19 17:02:32 -07007429 if (hdd_ctx->driver_status != DRIVER_MODULES_CLOSED) {
Arun Khandavallifae92942016-08-01 13:31:08 +05307430 hdd_unregister_wext_all_adapters(hdd_ctx);
7431 /*
7432 * Cancel any outstanding scan requests. We are about to close
7433 * all of our adapters, but an adapter structure is what SME
7434 * passes back to our callback function. Hence if there
7435 * are any outstanding scan requests then there is a
7436 * race condition between when the adapter is closed and
7437 * when the callback is invoked. We try to resolve that
7438 * race condition here by canceling any outstanding scans
7439 * before we close the adapters.
7440 * Note that the scans may be cancelled in an asynchronous
7441 * manner, so ideally there needs to be some kind of
7442 * synchronization. Rather than introduce a new
7443 * synchronization here, we will utilize the fact that we are
7444 * about to Request Full Power, and since that is synchronized,
7445 * the expectation is that by the time Request Full Power has
7446 * completed, all scans will be cancelled
7447 */
7448 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07007449 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08007450 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08007451 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007452 }
7453
Arun Khandavalli08479ba2017-08-07 19:56:23 +05307454 unregister_netdevice_notifier(&hdd_netdev_notifier);
7455
Rachit Kankane30807332018-06-27 18:39:36 +05307456 qdf_dp_trace_deinit();
7457
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07007458 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05307459
Visweswara Tanukuc029a202018-11-27 10:42:10 +05307460 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Dustin Brown86d196b2018-08-02 11:51:49 -07007461 hdd_bus_bandwidth_deinit(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -08007462 hdd_driver_memdump_deinit();
7463
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05307464 qdf_nbuf_deinit_replenish_timer();
7465
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05307466 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
7467 hdd_info("Release wakelock for monitor mode!");
7468 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
7469 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
7470 }
7471
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307472 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307473 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05307474 wlan_hdd_cache_chann_mutex_destroy(hdd_ctx);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307475
Naveen Rawate02f8f52018-04-05 11:58:04 -07007476 osif_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007477
Dustin Brownd005ad82018-01-19 10:32:13 -08007478 hdd_close_all_adapters(hdd_ctx, false);
7479
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05307480 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307481 /*
7482 * If there is re_init failure wiphy would have already de-registered
7483 * check the wiphy status before un-registering again
7484 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05307485 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307486 wiphy_unregister(wiphy);
7487 wlan_hdd_cfg80211_deinit(wiphy);
7488 hdd_lpass_notify_stop(hdd_ctx);
7489 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07007490
Arun Khandavallifae92942016-08-01 13:31:08 +05307491 hdd_exit_netlink_services(hdd_ctx);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307492#ifdef FEATURE_WLAN_CH_AVOID
7493 mutex_destroy(&hdd_ctx->avoid_freq_lock);
7494#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007495}
7496
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007497#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04007498/**
7499 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007500 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04007501 *
7502 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
7503 * Then new ACS request will do a fresh scan without reusing the cached
7504 * scan information.
7505 *
7506 * Return: void
7507 */
Tang Yingying523322d2017-01-17 23:28:43 +08007508static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007509{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007510 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Jeff Johnson16528362018-06-14 12:34:16 -07007511 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007512
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007513 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007514 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04007515 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
7516 qdf_mem_free(hdd_ctx->last_acs_channel_list);
7517 hdd_ctx->last_acs_channel_list = NULL;
7518 hdd_ctx->num_of_channels = 0;
7519 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007520
Jeff Johnson16528362018-06-14 12:34:16 -07007521 mac_handle = hdd_ctx->mac_handle;
7522 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007523 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007524}
7525#endif
7526
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007527/**
7528 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
7529 * @state: state
7530 *
7531 * This function notifies FW with modem power status
7532 *
7533 * Return: 0 if successful, error number otherwise
7534 */
7535int hdd_wlan_notify_modem_power_state(int state)
7536{
7537 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307538 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007539 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07007540 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007541
Anurag Chouhan6d760662016-02-20 16:05:43 +05307542 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007543 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307544 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007545 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307546
Jeff Johnson16528362018-06-14 12:34:16 -07007547 mac_handle = hdd_ctx->mac_handle;
7548 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007549 return -EINVAL;
7550
Jeff Johnson16528362018-06-14 12:34:16 -07007551 qdf_status = sme_notify_modem_power_state(mac_handle, state);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307552 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007553 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007554 state);
7555 return -EINVAL;
7556 }
7557 return 0;
7558}
7559
7560/**
7561 *
7562 * hdd_post_cds_enable_config() - HDD post cds start config helper
7563 * @adapter - Pointer to the HDD
7564 *
7565 * Return: None
7566 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007567QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007568{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307569 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007570
7571 /*
7572 * Send ready indication to the HDD. This will kick off the MAC
7573 * into a 'running' state and should kick off an initial scan.
7574 */
Jeff Johnson16528362018-06-14 12:34:16 -07007575 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->mac_handle);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307576 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007577 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
7578 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307579 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007580 }
7581
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307582 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007583}
7584
Sourav Mohapatra92ea8d62018-02-05 10:03:10 +05307585struct hdd_adapter *hdd_get_first_valid_adapter(struct hdd_context *hdd_ctx)
7586{
7587 struct hdd_adapter *adapter;
7588
7589 hdd_for_each_adapter(hdd_ctx, adapter) {
7590 if (adapter && adapter->magic == WLAN_HDD_ADAPTER_MAGIC)
7591 return adapter;
7592 }
7593
7594 return NULL;
7595}
7596
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007597/* wake lock APIs for HDD */
7598void hdd_prevent_suspend(uint32_t reason)
7599{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307600 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007601}
7602
7603void hdd_allow_suspend(uint32_t reason)
7604{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307605 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007606}
7607
7608void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
7609{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05307610 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
7611 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007612}
7613
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007614/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007615QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007616{
Jeff Johnson16528362018-06-14 12:34:16 -07007617 return sme_init_chan_list(hdd_ctx->mac_handle,
Amar Singhal6f8592b2017-04-26 14:31:58 -07007618 hdd_ctx->reg.alpha2,
7619 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007620}
7621
7622/**
7623 * hdd_is_5g_supported() - check if hardware supports 5GHz
7624 * @hdd_ctx: Pointer to the hdd context
7625 *
7626 * HDD function to know if hardware supports 5GHz
7627 *
7628 * Return: true if hardware supports 5GHz
7629 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007630bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007631{
Amar Singhal58b45ef2017-08-01 13:43:54 -07007632 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08007633 return true;
7634
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08007635 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08007636 return true;
7637 else
7638 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007639}
7640
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007641static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007642{
7643 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07007644 int ret_val;
Wu Gaoed616a12019-01-16 15:19:21 +08007645 uint32_t channel_bonding_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007646
7647 wiphy = hdd_ctx->wiphy;
7648
7649 /*
7650 * The channel information in
7651 * wiphy needs to be initialized before wiphy registration
7652 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007653 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
7654 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007655 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07007656 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007657 }
7658
7659#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
7660 wiphy->wowlan = &wowlan_support_reg_init;
7661#else
7662 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
7663 WIPHY_WOWLAN_MAGIC_PKT |
7664 WIPHY_WOWLAN_DISCONNECT |
7665 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
7666 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
7667 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
7668 WIPHY_WOWLAN_4WAY_HANDSHAKE |
7669 WIPHY_WOWLAN_RFKILL_RELEASE;
7670
7671 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
7672 WOW_MAX_FILTERS_PER_LIST);
7673 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
7674 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
7675#endif
Wu Gaoed616a12019-01-16 15:19:21 +08007676 ucfg_mlme_get_channel_bonding_24ghz(hdd_ctx->psoc,
7677 &channel_bonding_mode);
Liangwei Dong0da14262018-07-03 03:30:23 -04007678 if (hdd_ctx->obss_scan_offload) {
7679 hdd_debug("wmi_service_obss_scan supported");
Wu Gaoed616a12019-01-16 15:19:21 +08007680 } else if (channel_bonding_mode) {
Liangwei Dong0da14262018-07-03 03:30:23 -04007681 hdd_debug("enable wpa_supp obss_scan");
7682 wiphy->features |= NL80211_FEATURE_NEED_OBSS_SCAN;
7683 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007684
7685 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007686 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307687 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07007688 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307689 return ret_val;
7690 }
Amar Singhalac26de22018-06-22 12:53:06 -07007691
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007692 /* Check the kernel version for upstream commit aced43ce780dc5 that
7693 * has support for processing user cell_base hints when wiphy is
7694 * self managed or check the backport flag for the same.
7695 */
Amar Singhalac26de22018-06-22 12:53:06 -07007696#if defined CFG80211_USER_HINT_CELL_BASE_SELF_MANAGED || \
7697 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0))
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007698 hdd_send_wiphy_regd_sync_event(hdd_ctx);
7699#endif
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307700
Amar Singhal2d812012018-02-03 15:06:47 +08007701 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007702
Amar Singhale4f28ee2015-10-21 14:36:56 -07007703 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007704}
7705
Tiger Yu8b119e92019-04-09 13:55:07 +08007706#ifdef WLAN_FEATURE_DP_BUS_BANDWIDTH
Mohit Khannaca4173b2017-09-12 21:52:19 -07007707/**
7708 * hdd_display_periodic_stats() - Function to display periodic stats
7709 * @hdd_ctx - handle to hdd context
7710 * @bool data_in_interval - true, if data detected in bw time interval
7711 *
7712 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
7713 * Stats show up in wlan driver logs.
7714 *
7715 * Returns: None
7716 */
Mohit Khanna70322002018-05-15 19:21:32 -07007717static void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
7718 bool data_in_interval)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007719{
Mohit Khanna70322002018-05-15 19:21:32 -07007720 static uint32_t counter;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007721 static bool data_in_time_period;
7722 ol_txrx_pdev_handle pdev;
Mohit Khanna81418772018-10-30 14:14:46 -07007723 ol_txrx_soc_handle soc;
Arif Hussaincca60432018-12-03 19:45:12 -08007724 uint32_t periodic_stats_disp_time = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007725
Arif Hussaincca60432018-12-03 19:45:12 -08007726 ucfg_mlme_stats_get_periodic_display_time(hdd_ctx->psoc,
7727 &periodic_stats_disp_time);
7728 if (!periodic_stats_disp_time)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007729 return;
7730
Mohit Khanna81418772018-10-30 14:14:46 -07007731 soc = cds_get_context(QDF_MODULE_ID_SOC);
7732 if (!soc) {
7733 hdd_err("soc is NULL");
7734 return;
7735 }
7736
Mohit Khannaca4173b2017-09-12 21:52:19 -07007737 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
7738 if (!pdev) {
7739 hdd_err("pdev is NULL");
7740 return;
7741 }
7742
7743 counter++;
7744 if (data_in_interval)
7745 data_in_time_period = data_in_interval;
7746
jitiphil869b9f72018-09-25 17:14:01 +05307747 if (counter * hdd_ctx->config->bus_bw_compute_interval >=
Arif Hussaincca60432018-12-03 19:45:12 -08007748 periodic_stats_disp_time * 1000) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007749 if (data_in_time_period) {
Mohit Khanna70322002018-05-15 19:21:32 -07007750 wlan_hdd_display_txrx_stats(hdd_ctx);
Mohit Khannac9649652018-11-28 18:10:28 -08007751 dp_txrx_ext_dump_stats(soc, CDP_DP_RX_THREAD_STATS);
Mohit Khanna81418772018-10-30 14:14:46 -07007752 cdp_display_stats(soc,
Mohit Khanna70322002018-05-15 19:21:32 -07007753 CDP_RX_RING_STATS,
7754 QDF_STATS_VERBOSITY_LEVEL_LOW);
Mohit Khanna81418772018-10-30 14:14:46 -07007755 cdp_display_stats(soc,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007756 CDP_TXRX_PATH_STATS,
7757 QDF_STATS_VERBOSITY_LEVEL_LOW);
7758 wlan_hdd_display_netif_queue_history
7759 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
7760 qdf_dp_trace_dump_stats();
7761 }
7762 counter = 0;
7763 data_in_time_period = false;
7764 }
7765}
7766
Ravi Joshie2331e82015-07-01 18:18:54 -07007767/**
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007768 * hdd_clear_rps_cpu_mask - clear RPS CPU mask for interfaces
7769 * @hdd_ctx: pointer to struct hdd_context
7770 *
7771 * Return: none
7772 */
7773static void hdd_clear_rps_cpu_mask(struct hdd_context *hdd_ctx)
7774{
7775 struct hdd_adapter *adapter;
7776
7777 hdd_for_each_adapter(hdd_ctx, adapter)
7778 hdd_send_rps_disable_ind(adapter);
7779}
7780
7781/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07007782 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07007783 * @hdd_ctx - handle to hdd context
7784 * @tx_packets - transmit packet count
7785 * @rx_packets - receive packet count
7786 *
7787 * The function controls the bus bandwidth and dynamic control of
7788 * tcp delayed ack configuration
7789 *
7790 * Returns: None
7791 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007792
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007793static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07007794 const uint64_t tx_packets,
7795 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007796{
Mohit Khannaca4173b2017-09-12 21:52:19 -07007797 u64 total_pkts = tx_packets + rx_packets;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007798 uint64_t temp_tx = 0, avg_rx = 0;
7799 uint64_t no_rx_offload_pkts = 0, avg_no_rx_offload_pkts = 0;
7800 uint64_t rx_offload_pkts = 0, avg_rx_offload_pkts = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007801 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08007802 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08007803 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007804 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007805 uint16_t index = 0;
7806 bool vote_level_change = false;
7807 bool rx_level_change = false;
7808 bool tx_level_change = false;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007809 bool rxthread_high_tput_req = false;
Mohit Khannaf7562c32018-07-05 17:42:36 -07007810 bool dptrace_high_tput_req;
Srinivas Girigowda50335342018-09-07 15:21:01 -07007811
jitiphil869b9f72018-09-25 17:14:01 +05307812 if (total_pkts > hdd_ctx->config->bus_bw_high_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007813 next_vote_level = PLD_BUS_WIDTH_HIGH;
jitiphil869b9f72018-09-25 17:14:01 +05307814 else if (total_pkts > hdd_ctx->config->bus_bw_medium_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007815 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
jitiphil869b9f72018-09-25 17:14:01 +05307816 else if (total_pkts > hdd_ctx->config->bus_bw_low_threshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007817 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07007818 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07007819 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007820
Mohit Khannaf7562c32018-07-05 17:42:36 -07007821 dptrace_high_tput_req =
7822 next_vote_level > PLD_BUS_WIDTH_NONE ? true : false;
7823
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007824 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07007825 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
7826 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007827 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007828 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007829 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007830 if ((next_vote_level == PLD_BUS_WIDTH_LOW) ||
7831 (next_vote_level == PLD_BUS_WIDTH_NONE)) {
Nirav Shahffc6a092016-06-09 16:09:08 +05307832 if (hdd_ctx->hbw_requested) {
7833 pld_remove_pm_qos(hdd_ctx->parent_dev);
7834 hdd_ctx->hbw_requested = false;
7835 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007836 if (hdd_ctx->dynamic_rps)
7837 hdd_clear_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007838 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05307839 if (!hdd_ctx->hbw_requested) {
7840 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
7841 hdd_ctx->hbw_requested = true;
7842 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007843 if (hdd_ctx->dynamic_rps)
7844 hdd_set_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007845 }
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007846
Manjunathappa Prakashcb6df762018-05-29 18:54:58 -07007847 if (hdd_ctx->config->napi_cpu_affinity_mask)
7848 hdd_napi_apply_throughput_policy(hdd_ctx,
7849 tx_packets,
7850 rx_packets);
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007851
jitiphil869b9f72018-09-25 17:14:01 +05307852 if (rx_packets < hdd_ctx->config->bus_bw_low_threshold)
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007853 hdd_disable_rx_ol_for_low_tput(hdd_ctx, true);
7854 else
7855 hdd_disable_rx_ol_for_low_tput(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007856 }
Mohit Khannae71e2262015-11-10 09:37:24 -08007857
Mohit Khannaf7562c32018-07-05 17:42:36 -07007858 qdf_dp_trace_apply_tput_policy(dptrace_high_tput_req);
7859
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007860 /*
7861 * Includes tcp+udp, if perf core is required for tcp, then
7862 * perf core is also required for udp.
7863 */
7864 no_rx_offload_pkts = hdd_ctx->no_rx_offload_pkt_cnt;
7865 hdd_ctx->no_rx_offload_pkt_cnt = 0;
7866 rx_offload_pkts = rx_packets - no_rx_offload_pkts;
Mohit Khannae71e2262015-11-10 09:37:24 -08007867
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007868 avg_no_rx_offload_pkts = (no_rx_offload_pkts +
7869 hdd_ctx->prev_no_rx_offload_pkts) / 2;
7870 hdd_ctx->prev_no_rx_offload_pkts = no_rx_offload_pkts;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08007871
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007872 avg_rx_offload_pkts = (rx_offload_pkts +
7873 hdd_ctx->prev_rx_offload_pkts) / 2;
7874 hdd_ctx->prev_rx_offload_pkts = rx_offload_pkts;
7875
7876 avg_rx = avg_no_rx_offload_pkts + avg_rx_offload_pkts;
7877 /*
7878 * Takes care to set Rx_thread affinity for below case
7879 * 1)LRO/GRO not supported ROME case
7880 * 2)when rx_ol is disabled in cases like concurrency etc
7881 * 3)For UDP cases
7882 */
7883 if (avg_no_rx_offload_pkts >
jitiphil869b9f72018-09-25 17:14:01 +05307884 hdd_ctx->config->bus_bw_high_threshold)
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007885 rxthread_high_tput_req = true;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307886 else
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007887 rxthread_high_tput_req = false;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307888
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007889 if (cds_sched_handle_throughput_req(rxthread_high_tput_req))
7890 hdd_warn("Rx thread high_tput(%d) affinity request failed",
7891 rxthread_high_tput_req);
7892
7893 /* fine-tuning parameters for RX Flows */
jitiphil869b9f72018-09-25 17:14:01 +05307894 if (avg_rx > hdd_ctx->config->tcp_delack_thres_high) {
Ravi Joshifed83572016-10-07 16:20:37 -07007895 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
7896 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
7897 next_rx_level = WLAN_SVC_TP_HIGH;
7898 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07007899 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07007900 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08007901 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007902 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007903
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007904 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007905 struct wlan_rx_tp_data rx_tp_data = {0};
7906
Ravi Joshie2331e82015-07-01 18:18:54 -07007907 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Jeff Johnsonb9feee42018-07-08 10:34:48 -07007908 next_rx_level, avg_rx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007909 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007910 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07007911 /* Send throughput indication only if it is enabled.
7912 * Disabling tcp_del_ack will revert the tcp stack behavior
7913 * to default delayed ack. Note that this will disable the
7914 * dynamic delayed ack mechanism across the system
7915 */
Manjunathappa Prakashbfd12762018-04-29 22:44:52 -07007916 if (hdd_ctx->en_tcp_delack_no_lro)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007917 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
7918
Mohit Khanna6272fb682017-04-13 09:34:36 -07007919 if (hdd_ctx->config->enable_tcp_adv_win_scale)
7920 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
7921
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007922 rx_tp_data.level = next_rx_level;
Alok Kumar2fad6442018-11-08 19:19:28 +05307923 wlan_hdd_update_tcp_rx_param(hdd_ctx, &rx_tp_data);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007924 }
7925
Mohit Khannae71e2262015-11-10 09:37:24 -08007926 /* fine-tuning parameters for TX Flows */
7927 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
7928 hdd_ctx->prev_tx = tx_packets;
7929 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
7930 next_tx_level = WLAN_SVC_TP_HIGH;
7931 else
7932 next_tx_level = WLAN_SVC_TP_LOW;
7933
Prakash Manjunathappae73e3b52018-02-27 18:56:22 -08007934 if ((hdd_ctx->config->enable_tcp_limit_output) &&
7935 (hdd_ctx->cur_tx_level != next_tx_level)) {
Alok Kumar2fad6442018-11-08 19:19:28 +05307936 struct wlan_tx_tp_data tx_tp_data = {0};
7937
Mohit Khannae71e2262015-11-10 09:37:24 -08007938 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
7939 next_tx_level, temp_tx);
7940 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007941 tx_level_change = true;
Alok Kumar2fad6442018-11-08 19:19:28 +05307942 tx_tp_data.level = next_tx_level;
7943 tx_tp_data.tcp_limit_output = true;
7944 wlan_hdd_update_tcp_tx_param(hdd_ctx, &tx_tp_data);
Mohit Khannae71e2262015-11-10 09:37:24 -08007945 }
7946
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007947 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007948 if (vote_level_change || tx_level_change || rx_level_change) {
7949 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
7950 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
7951 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
7952 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
7953 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
7954 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
7955 hdd_ctx->hdd_txrx_hist_idx++;
7956 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
7957 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07007958
7959 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007960}
7961
7962#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Dustin Browna20bad52019-03-05 12:03:30 -08007963static void __hdd_bus_bw_work_handler(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007964{
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307965 struct hdd_adapter *adapter = NULL, *con_sap_adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307966 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05307967 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
7968 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007969 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307970 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007971 bool connected = false;
7972 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
7973
Prashanth Bhattaab004382016-10-11 16:08:11 -07007974 if (wlan_hdd_validate_context(hdd_ctx))
Dustin Browna20bad52019-03-05 12:03:30 -08007975 goto stop_work;
Prashanth Bhattaab004382016-10-11 16:08:11 -07007976
Jeff Johnson214671b2017-10-30 19:45:23 -07007977 if (hdd_ctx->is_wiphy_suspended)
Dustin Browna20bad52019-03-05 12:03:30 -08007978 return;
Jingxiang Gec64e1932017-08-22 14:38:59 +08007979
Dustin Brown920397d2017-12-13 16:27:50 -08007980 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05307981 /*
7982 * Validate magic so we don't end up accessing
7983 * an invalid adapter.
7984 */
7985 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
7986 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007987
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007988 if ((adapter->device_mode == QDF_STA_MODE ||
7989 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Jeff Johnsone7951512019-02-27 10:02:51 -08007990 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.conn_state
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007991 != eConnectionState_Associated) {
7992
7993 continue;
7994 }
7995
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007996 if ((adapter->device_mode == QDF_SAP_MODE ||
7997 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07007998 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007999
8000 continue;
8001 }
8002
8003 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
8004 adapter->prev_tx_packets);
8005 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
8006 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05308007
8008 if (adapter->device_mode == QDF_SAP_MODE ||
8009 adapter->device_mode == QDF_P2P_GO_MODE ||
8010 adapter->device_mode == QDF_IBSS_MODE) {
8011
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08008012 ret = cdp_get_intra_bss_fwd_pkts_count(
8013 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson5a6fc962019-02-04 14:20:25 -08008014 adapter->vdev_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05308015 &fwd_tx_packets, &fwd_rx_packets);
8016 if (ret == A_OK) {
8017 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
8018 fwd_tx_packets,
8019 adapter->prev_fwd_tx_packets);
8020 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
8021 fwd_tx_packets,
8022 adapter->prev_fwd_rx_packets);
8023 }
8024 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008025
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05308026 if (adapter->device_mode == QDF_SAP_MODE)
8027 con_sap_adapter = adapter;
8028
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008029 total_rx += adapter->stats.rx_packets;
8030 total_tx += adapter->stats.tx_packets;
8031
8032 spin_lock_bh(&hdd_ctx->bus_bw_lock);
8033 adapter->prev_tx_packets = adapter->stats.tx_packets;
8034 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05308035 adapter->prev_fwd_tx_packets = fwd_tx_packets;
8036 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008037 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
8038 connected = true;
8039 }
8040
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008041 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07008042 hdd_err("bus bandwidth timer running in disconnected state");
Dustin Browna20bad52019-03-05 12:03:30 -08008043 goto stop_work;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008044 }
8045
Yun Parka29974a2018-04-09 12:05:49 -07008046 /* add intra bss forwarded tx and rx packets */
8047 tx_packets += fwd_tx_packets_diff;
8048 rx_packets += fwd_rx_packets_diff;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008049
Dustin Brown07901ec2018-09-07 11:02:41 -07008050 if (ucfg_ipa_is_fw_wdi_activated(hdd_ctx->pdev)) {
8051 ucfg_ipa_uc_stat_query(hdd_ctx->pdev, &ipa_tx_packets,
8052 &ipa_rx_packets);
Yun Parka29974a2018-04-09 12:05:49 -07008053 tx_packets += (uint64_t)ipa_tx_packets;
8054 rx_packets += (uint64_t)ipa_rx_packets;
8055
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05308056 if (con_sap_adapter) {
8057 con_sap_adapter->stats.tx_packets += ipa_tx_packets;
8058 con_sap_adapter->stats.rx_packets += ipa_rx_packets;
8059 }
8060
Dustin Brown07901ec2018-09-07 11:02:41 -07008061 ucfg_ipa_set_perf_level(hdd_ctx->pdev, tx_packets, rx_packets);
8062 ucfg_ipa_uc_stat_request(hdd_ctx->pdev, 2);
Yun Parka29974a2018-04-09 12:05:49 -07008063 }
8064
8065 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008066
Dustin Browna20bad52019-03-05 12:03:30 -08008067 return;
8068
8069stop_work:
8070 qdf_periodic_work_stop_async(&hdd_ctx->bus_bw_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008071}
Prashanth Bhattaab004382016-10-11 16:08:11 -07008072
Dustin Browna20bad52019-03-05 12:03:30 -08008073static void hdd_bus_bw_work_handler(void *context)
Rajeev Kumarb2b5e692018-08-31 15:12:40 -07008074{
Dustin Brown3fdaaf62019-03-18 14:00:16 -07008075 struct hdd_context *hdd_ctx = context;
8076 struct qdf_op_sync *op_sync;
Dustin Browna20bad52019-03-05 12:03:30 -08008077
Dustin Brown3fdaaf62019-03-18 14:00:16 -07008078 if (qdf_op_protect(&op_sync))
8079 return;
8080
8081 __hdd_bus_bw_work_handler(hdd_ctx);
8082
8083 qdf_op_unprotect(op_sync);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05308084}
8085
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008086int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07008087{
Dustin Browna20bad52019-03-05 12:03:30 -08008088 QDF_STATUS status;
8089
Dustin Brown35008ba2018-08-23 14:34:21 -07008090 hdd_enter();
8091
Prashanth Bhattaab004382016-10-11 16:08:11 -07008092 spin_lock_init(&hdd_ctx->bus_bw_lock);
Dustin Browna20bad52019-03-05 12:03:30 -08008093 status = qdf_periodic_work_create(&hdd_ctx->bus_bw_work,
8094 hdd_bus_bw_work_handler,
Dustin Brown3fdaaf62019-03-18 14:00:16 -07008095 hdd_ctx);
Dustin Brown35008ba2018-08-23 14:34:21 -07008096
8097 hdd_exit();
Prashanth Bhattaab004382016-10-11 16:08:11 -07008098
Dustin Browna20bad52019-03-05 12:03:30 -08008099 return qdf_status_to_os_return(status);
Prashanth Bhattaab004382016-10-11 16:08:11 -07008100}
8101
Dustin Brown86d196b2018-08-02 11:51:49 -07008102void hdd_bus_bandwidth_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07008103{
Dustin Brown35008ba2018-08-23 14:34:21 -07008104 hdd_enter();
Prashanth Bhattaab004382016-10-11 16:08:11 -07008105
Dustin Browna20bad52019-03-05 12:03:30 -08008106 QDF_BUG(!qdf_periodic_work_stop_sync(&hdd_ctx->bus_bw_work));
8107 qdf_periodic_work_destroy(&hdd_ctx->bus_bw_work);
Dustin Brown35008ba2018-08-23 14:34:21 -07008108
8109 hdd_exit();
Prashanth Bhattaab004382016-10-11 16:08:11 -07008110}
Tiger Yu8b119e92019-04-09 13:55:07 +08008111#endif /*WLAN_FEATURE_DP_BUS_BANDWIDTH*/
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008112
8113/**
Nirav Shahed34b212016-04-25 10:59:16 +05308114 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
8115 * @hdd_ctx: hdd context
8116 *
8117 * Return: 0 for success or error code
8118 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008119static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05308120{
8121 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
8122 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Min Liu74a1a502018-10-10 19:59:07 +08008123 if (!hdd_ctx->hdd_txrx_hist)
Nirav Shahed34b212016-04-25 10:59:16 +05308124 return -ENOMEM;
Nirav Shahed34b212016-04-25 10:59:16 +05308125 return 0;
8126}
8127
8128/**
8129 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
8130 * @hdd_ctx: hdd context
8131 *
8132 * Return: none
8133 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008134void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05308135{
Jeff Johnsond36fa332019-03-18 13:42:25 -07008136 if (!hdd_ctx || !hdd_ctx->hdd_txrx_hist)
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05308137 return;
8138
8139 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
8140 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05308141}
8142
Nirav Shahda008342016-05-17 18:50:40 +05308143static uint8_t *convert_level_to_string(uint32_t level)
8144{
8145 switch (level) {
8146 /* initialize the wlan sub system */
8147 case WLAN_SVC_TP_NONE:
8148 return "NONE";
8149 case WLAN_SVC_TP_LOW:
8150 return "LOW";
8151 case WLAN_SVC_TP_MEDIUM:
8152 return "MED";
8153 case WLAN_SVC_TP_HIGH:
8154 return "HIGH";
8155 default:
8156 return "INVAL";
8157 }
8158}
8159
Nirav Shahed34b212016-04-25 10:59:16 +05308160
8161/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008162 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
8163 * @hdd_ctx: hdd context
8164 *
8165 * Return: none
8166 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008167void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008168{
8169 int i;
8170
Tiger Yu8b119e92019-04-09 13:55:07 +08008171#ifdef WLAN_FEATURE_DP_BUS_BANDWIDTH
Nirav Shahe6194ac2018-07-13 11:04:41 +05308172 hdd_nofl_info("BW compute Interval: %dms",
jitiphil869b9f72018-09-25 17:14:01 +05308173 hdd_ctx->config->bus_bw_compute_interval);
Nirav Shahe6194ac2018-07-13 11:04:41 +05308174 hdd_nofl_info("BW High TH: %d BW Med TH: %d BW Low TH: %d",
jitiphil869b9f72018-09-25 17:14:01 +05308175 hdd_ctx->config->bus_bw_high_threshold,
8176 hdd_ctx->config->bus_bw_medium_threshold,
8177 hdd_ctx->config->bus_bw_low_threshold);
Nirav Shahe6194ac2018-07-13 11:04:41 +05308178 hdd_nofl_info("Enable TCP DEL ACK: %d",
8179 hdd_ctx->en_tcp_delack_no_lro);
8180 hdd_nofl_info("TCP DEL High TH: %d TCP DEL Low TH: %d",
jitiphil869b9f72018-09-25 17:14:01 +05308181 hdd_ctx->config->tcp_delack_thres_high,
8182 hdd_ctx->config->tcp_delack_thres_low);
Nirav Shahe6194ac2018-07-13 11:04:41 +05308183 hdd_nofl_info("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
8184 hdd_ctx->config->tcp_tx_high_tput_thres);
Tiger Yu8b119e92019-04-09 13:55:07 +08008185#endif /*WLAN_FEATURE_DP_BUS_BANDWIDTH*/
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008186
Nirav Shahe6194ac2018-07-13 11:04:41 +05308187 hdd_nofl_info("Total entries: %d Current index: %d",
8188 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
Nirav Shahda008342016-05-17 18:50:40 +05308189
Nirav Shahe6194ac2018-07-13 11:04:41 +05308190 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 -08008191
8192 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008193 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08008194 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Nirav Shahe6194ac2018-07-13 11:04:41 +05308195 hdd_nofl_info("[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
8196 i, hdd_ctx->hdd_txrx_hist[i].qtime,
8197 hdd_ctx->hdd_txrx_hist[i].interval_rx,
8198 hdd_ctx->hdd_txrx_hist[i].interval_tx,
8199 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008200 hdd_ctx->hdd_txrx_hist[i].
8201 next_vote_level),
Nirav Shahe6194ac2018-07-13 11:04:41 +05308202 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008203 hdd_ctx->hdd_txrx_hist[i].
8204 next_rx_level),
Nirav Shahe6194ac2018-07-13 11:04:41 +05308205 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008206 hdd_ctx->hdd_txrx_hist[i].
8207 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008208 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008209}
8210
8211/**
8212 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
8213 * @hdd_ctx: hdd context
8214 *
8215 * Return: none
8216 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008217void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008218{
8219 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05308220 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
8221 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008222}
8223
Mohit Khannaca4173b2017-09-12 21:52:19 -07008224/* length of the netif queue log needed per adapter */
8225#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
8226
8227/**
8228 *
8229 * hdd_display_netif_queue_history_compact() - display compact netifq history
8230 * @hdd_ctx: hdd context
8231 *
8232 * Return: none
8233 */
8234static void
8235hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
8236{
8237 int adapter_num = 0;
8238 int i;
8239 int bytes_written;
8240 u32 tbytes;
8241 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008242 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08008243 char *comb_log_str;
8244 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008245 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008246
Dustin Brownad06be62019-02-04 14:52:56 -08008247 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * WLAN_MAX_VDEVS) + 1;
jiadbdefb252018-01-03 14:27:06 +08008248 comb_log_str = qdf_mem_malloc(comb_log_str_size);
Min Liu74a1a502018-10-10 19:59:07 +08008249 if (!comb_log_str)
jiadbdefb252018-01-03 14:27:06 +08008250 return;
jiadbdefb252018-01-03 14:27:06 +08008251
Mohit Khannaca4173b2017-09-12 21:52:19 -07008252 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07008253
Dustin Brown920397d2017-12-13 16:27:50 -08008254 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07008255 curr_time = qdf_system_ticks();
8256 total = curr_time - adapter->start_time;
8257 delta = curr_time - adapter->last_time;
8258
8259 if (adapter->pause_map) {
8260 pause = adapter->total_pause_time + delta;
8261 unpause = adapter->total_unpause_time;
8262 } else {
8263 unpause = adapter->total_unpause_time + delta;
8264 pause = adapter->total_pause_time;
8265 }
8266
8267 tbytes = 0;
hangtian127c9532019-01-12 13:29:07 +08008268 qdf_mem_zero(temp_str, sizeof(temp_str));
Mohit Khannaca4173b2017-09-12 21:52:19 -07008269 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
8270 if (adapter->queue_oper_stats[i].pause_count == 0)
8271 continue;
8272 tbytes +=
8273 snprintf(
8274 &temp_str[tbytes],
8275 (tbytes >= sizeof(temp_str) ?
8276 0 : sizeof(temp_str) - tbytes),
8277 "%d(%d,%d) ",
8278 i,
8279 adapter->queue_oper_stats[i].
8280 pause_count,
8281 adapter->queue_oper_stats[i].
8282 unpause_count);
8283 }
8284 if (tbytes >= sizeof(temp_str))
8285 hdd_warn("log truncated");
8286
8287 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08008288 bytes_written >= comb_log_str_size ? 0 :
8289 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07008290 "[%d %d] (%d) %u/%ums %s|",
Jeff Johnson5a6fc962019-02-04 14:20:25 -08008291 adapter->vdev_id, adapter->device_mode,
Mohit Khannaca4173b2017-09-12 21:52:19 -07008292 adapter->pause_map,
8293 qdf_system_ticks_to_msecs(pause),
8294 qdf_system_ticks_to_msecs(total),
8295 temp_str);
8296
Mohit Khannaca4173b2017-09-12 21:52:19 -07008297 adapter_num++;
8298 }
8299
8300 /* using QDF_TRACE to avoid printing function name */
8301 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
8302 "STATS |%s", comb_log_str);
8303
jiadbdefb252018-01-03 14:27:06 +08008304 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07008305 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08008306
8307 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07008308}
8309
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008310/* Max size of a single netdev tx queue state string. e.g. "1: 0x1" */
8311#define HDD_NETDEV_TX_Q_STATE_STRLEN 15
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008312/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07008313 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07008314 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008315 *
8316 * Return: none
8317 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07008318void
8319wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
8320 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008321{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008322 int i;
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008323 struct hdd_adapter *adapter = NULL;
Nirav Shahda008342016-05-17 18:50:40 +05308324 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008325 struct hdd_netif_queue_history *q_hist_ptr;
8326 char q_status_buf[NUM_TX_QUEUES * HDD_NETDEV_TX_Q_STATE_STRLEN] = {0};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008327
Mohit Khannaca4173b2017-09-12 21:52:19 -07008328 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
8329 hdd_display_netif_queue_history_compact(hdd_ctx);
8330 return;
8331 }
8332
Dustin Brown920397d2017-12-13 16:27:50 -08008333 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008334 if (adapter->vdev_id == CDP_INVALID_VDEV_ID)
8335 continue;
Nirav Shahe6194ac2018-07-13 11:04:41 +05308336 hdd_nofl_info("Netif queue operation statistics:");
Jeff Johnson55d2ab42019-03-06 11:43:49 -08008337 hdd_nofl_info("vdev_id %d device mode %d",
Jeff Johnson5a6fc962019-02-04 14:20:25 -08008338 adapter->vdev_id, adapter->device_mode);
Nirav Shahe6194ac2018-07-13 11:04:41 +05308339 hdd_nofl_info("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05308340 curr_time = qdf_system_ticks();
8341 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05308342 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05308343 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05308344 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05308345 unpause = adapter->total_unpause_time;
8346 } else {
Nirav Shahda008342016-05-17 18:50:40 +05308347 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05308348 pause = adapter->total_pause_time;
8349 }
Nirav Shahe6194ac2018-07-13 11:04:41 +05308350 hdd_nofl_info("Total: %ums Pause: %ums Unpause: %ums",
8351 qdf_system_ticks_to_msecs(total),
8352 qdf_system_ticks_to_msecs(pause),
8353 qdf_system_ticks_to_msecs(unpause));
8354 hdd_nofl_info("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008355
Nirav Shahda008342016-05-17 18:50:40 +05308356 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
8357 qdf_time_t pause_delta = 0;
8358
8359 if (adapter->pause_map & (1 << i))
8360 pause_delta = delta;
8361
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008362 /* using hdd_log to avoid printing function name */
Nirav Shahe6194ac2018-07-13 11:04:41 +05308363 hdd_nofl_info("%s: %d: %d: %ums",
8364 hdd_reason_type_to_string(i),
8365 adapter->queue_oper_stats[i].pause_count,
8366 adapter->queue_oper_stats[i].
8367 unpause_count,
8368 qdf_system_ticks_to_msecs(
8369 adapter->queue_oper_stats[i].
8370 total_pause_time + pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008371 }
8372
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008373 hdd_nofl_info("Netif queue operation history: Total entries: %d current index %d(-1) time %u",
Nirav Shahe6194ac2018-07-13 11:04:41 +05308374 WLAN_HDD_MAX_HISTORY_ENTRY,
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008375 adapter->history_index,
8376 qdf_system_ticks_to_msecs(qdf_system_ticks()));
Nirav Shahda008342016-05-17 18:50:40 +05308377
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008378 hdd_nofl_info("%2s%20s%50s%30s%10s %s",
8379 "#", "time(ms)", "action_type", "reason_type",
8380 "pause_map", "netdev-queue-status");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008381
8382 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008383 /* using hdd_log to avoid printing function name */
8384 if (adapter->queue_oper_history[i].time == 0)
8385 continue;
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008386 q_hist_ptr = &adapter->queue_oper_history[i];
8387 wlan_hdd_dump_queue_history_state(q_hist_ptr,
8388 q_status_buf,
8389 sizeof(q_status_buf));
8390 hdd_nofl_info("%2d%20u%50s%30s%10x %s",
Nirav Shahe6194ac2018-07-13 11:04:41 +05308391 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008392 adapter->queue_oper_history[i].time),
Nirav Shahe6194ac2018-07-13 11:04:41 +05308393 hdd_action_type_to_string(
8394 adapter->queue_oper_history[i].
8395 netif_action),
8396 hdd_reason_type_to_string(
8397 adapter->queue_oper_history[i].
8398 netif_reason),
Mohit Khannaf7e7b342019-04-08 11:54:21 -07008399 adapter->queue_oper_history[i].pause_map,
8400 q_status_buf);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008401 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008402 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008403}
8404
8405/**
8406 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
8407 * @hdd_ctx: hdd context
8408 *
8409 * Return: none
8410 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008411void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008412{
Jeff Johnson9d295242017-08-29 14:39:48 -07008413 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008414
Dustin Brown920397d2017-12-13 16:27:50 -08008415 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308416 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008417 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308418 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008419 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05308420 adapter->history_index = 0;
8421 adapter->start_time = adapter->last_time = qdf_system_ticks();
8422 adapter->total_pause_time = 0;
8423 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008424 }
8425}
8426
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008427#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
8428/**
8429 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
8430 * @hdd_ctx: hdd global context
8431 *
8432 * Return: none
8433 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008434static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008435{
8436 uint8_t i;
8437
8438 mutex_init(&hdd_ctx->op_ctx.op_lock);
8439 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
8440 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
8441 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
8442 }
8443}
8444#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008445static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008446{
8447}
8448#endif
8449
Yingying Tang95409972016-10-20 15:16:15 +08008450#ifdef WLAN_FEATURE_WOW_PULSE
8451/**
8452 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsonfd7d1ef2019-03-31 10:41:37 -07008453 * @hdd_ctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08008454 * @enable: enable or disable this behaviour
8455 *
8456 * Return: int
8457 */
Jeff Johnsonfd7d1ef2019-03-31 10:41:37 -07008458static int wlan_hdd_set_wow_pulse(struct hdd_context *hdd_ctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008459{
Yingying Tang95409972016-10-20 15:16:15 +08008460 struct wow_pulse_mode wow_pulse_set_info;
8461 QDF_STATUS status;
8462
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008463 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08008464
Jeff Johnsonfd7d1ef2019-03-31 10:41:37 -07008465 if (!ucfg_pmo_is_wow_pulse_enabled(hdd_ctx->psoc))
Yingying Tang95409972016-10-20 15:16:15 +08008466 return 0;
8467
8468 /* prepare the request to send to SME */
8469 if (enable == true) {
8470 wow_pulse_set_info.wow_pulse_enable = true;
8471 wow_pulse_set_info.wow_pulse_pin =
Jeff Johnsonfd7d1ef2019-03-31 10:41:37 -07008472 ucfg_pmo_get_wow_pulse_pin(hdd_ctx->psoc);
Wu Gao66454f12018-09-26 19:55:41 +08008473
Yingying Tang95409972016-10-20 15:16:15 +08008474 wow_pulse_set_info.wow_pulse_interval_high =
Jeff Johnsonfd7d1ef2019-03-31 10:41:37 -07008475 ucfg_pmo_get_wow_pulse_interval_high(hdd_ctx->psoc);
Wu Gao66454f12018-09-26 19:55:41 +08008476
8477 wow_pulse_set_info.wow_pulse_interval_low =
Jeff Johnsonfd7d1ef2019-03-31 10:41:37 -07008478 ucfg_pmo_get_wow_pulse_interval_low(hdd_ctx->psoc);
Yingying Tang95409972016-10-20 15:16:15 +08008479 } else {
8480 wow_pulse_set_info.wow_pulse_enable = false;
8481 wow_pulse_set_info.wow_pulse_pin = 0;
8482 wow_pulse_set_info.wow_pulse_interval_low = 0;
8483 wow_pulse_set_info.wow_pulse_interval_high = 0;
8484 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008485 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08008486 wow_pulse_set_info.wow_pulse_enable,
8487 wow_pulse_set_info.wow_pulse_pin,
8488 wow_pulse_set_info.wow_pulse_interval_low,
8489 wow_pulse_set_info.wow_pulse_interval_high);
8490
8491 status = sme_set_wow_pulse(&wow_pulse_set_info);
8492 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008493 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08008494 return -EIO;
8495 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008496 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08008497 return 0;
8498}
8499#else
Jeff Johnsonfd7d1ef2019-03-31 10:41:37 -07008500static inline int wlan_hdd_set_wow_pulse(struct hdd_context *hdd_ctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008501{
8502 return 0;
8503}
8504#endif
8505
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008506#ifdef WLAN_FEATURE_FASTPATH
jitiphil377bcc12018-10-05 19:46:08 +05308507
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008508/**
8509 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
8510 * @hdd_cfg: hdd config
8511 * @context: lower layer context
8512 *
8513 * Return: none
8514 */
jitiphil377bcc12018-10-05 19:46:08 +05308515void hdd_enable_fastpath(struct hdd_context *hdd_ctx,
8516 void *context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008517{
jitiphil377bcc12018-10-05 19:46:08 +05308518 if (cfg_get(hdd_ctx->psoc, CFG_DP_ENABLE_FASTPATH))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008519 hif_enable_fastpath(context);
8520}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008521#endif
8522
Yuanyuan Liu13738502016-04-06 17:41:37 -07008523#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008524/**
8525 * hdd_set_thermal_level_cb() - set thermal level callback function
Jeff Johnson0e963082018-07-04 19:39:20 -07008526 * @hdd_handle: opaque handle for the hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008527 * @level: thermal level
8528 *
8529 * Change IPA data path to SW path when the thermal throttle level greater
8530 * than 0, and restore the original data path when throttle level is 0
8531 *
8532 * Return: none
8533 */
Jeff Johnson0e963082018-07-04 19:39:20 -07008534static void hdd_set_thermal_level_cb(hdd_handle_t hdd_handle, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008535{
Jeff Johnson0e963082018-07-04 19:39:20 -07008536 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008537
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008538 /* Change IPA to SW path when throttle level greater than 0 */
8539 if (level > THROTTLE_LEVEL_0)
Dustin Brown07901ec2018-09-07 11:02:41 -07008540 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->pdev, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008541 else
8542 /* restore original concurrency mode */
Dustin Brown07901ec2018-09-07 11:02:41 -07008543 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->pdev, hdd_ctx->mcc_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008544}
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308545#else
8546/**
8547 * hdd_set_thermal_level_cb() - set thermal level callback function
8548 * @hdd_handle: opaque handle for the hdd context
8549 * @level: thermal level
8550 *
8551 * Change IPA data path to SW path when the thermal throttle level greater
8552 * than 0, and restore the original data path when throttle level is 0
8553 *
8554 * Return: none
8555 */
8556static void hdd_set_thermal_level_cb(hdd_handle_t hdd_handle, u_int8_t level)
8557{
8558}
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308559#endif
8560
8561/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008562 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308563 * @adapter: AP adapter
8564 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08008565 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308566 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008567 * Moves the SAP interface by invoking the function which
8568 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308569 *
8570 * Return: None
8571 */
Min Liu2fef5792018-01-19 17:59:42 +08008572void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
8573 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308574{
Jeff Johnson87251032017-08-29 13:31:11 -07008575 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008576 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07008577 mac_handle_t mac_handle;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308578
8579 if (!adapter) {
8580 hdd_err("invalid adapter");
8581 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008582 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308583
8584 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
8585
Jeff Johnson16528362018-06-14 12:34:16 -07008586 mac_handle = hdd_adapter_get_mac_handle(adapter);
8587 if (!mac_handle) {
8588 hdd_err("invalid MAC handle");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308589 return;
8590 }
8591
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008592 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8593
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008594 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07008595 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308596
Dustin Brown1dbefe62018-09-11 16:32:03 -07008597 policy_mgr_change_sap_channel_with_csa(hdd_ctx->psoc,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08008598 adapter->vdev_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08008599 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008600}
Kapil Gupta8878ad92017-02-13 11:56:04 +05308601
Jeff Johnson9d295242017-08-29 14:39:48 -07008602int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05308603{
8604 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308605 int status;
8606 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308607
8608 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8609
8610 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07008611 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05308612 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07008613 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308614 }
8615 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07008616 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308617 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308618 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07008619 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308620 WLAN_VENDOR_ACS_WAIT_TIME);
8621 if (qdf_status != QDF_STATUS_SUCCESS) {
8622 hdd_err("failed to start external acs timer");
8623 return -ENOSPC;
8624 }
8625 /* Update config to application */
8626 status = hdd_cfg80211_update_acs_config(adapter, reason);
Dustin Brown5e89ef82018-03-14 11:50:23 -07008627 hdd_info("Updated ACS config to nl with reason %d", reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308628
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308629 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308630}
8631
Nirav Shaheb017be2018-02-15 11:20:58 +05308632#if defined(FEATURE_WLAN_CH_AVOID)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308633/**
8634 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
8635 * @hdd_ctx: hdd context pointer
8636 *
8637 * hdd_unsafe_channel_restart_sap check all unsafe channel list
8638 * and if ACS is enabled, driver will ask userspace to restart the
8639 * sap. User space on LTE coex indication restart driver.
8640 *
8641 * Return - none
8642 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008643void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308644{
Dustin Brown920397d2017-12-13 16:27:50 -08008645 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308646 uint32_t i;
8647 bool found = false;
8648 uint8_t restart_chan;
Krunal Sonidf29bc42018-11-15 13:26:29 -08008649 uint8_t scc_on_lte_coex = 0;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05308650 bool value;
Harprit Chhabada1eeeb8d2018-09-14 15:16:56 -07008651 QDF_STATUS status;
8652 bool is_acs_support_for_dfs_ltecoex = cfg_default(CFG_USER_ACS_DFS_LTE);
8653 bool is_vendor_acs_support =
8654 cfg_default(CFG_USER_AUTO_CHANNEL_SELECTION);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008655
Dustin Brown920397d2017-12-13 16:27:50 -08008656 hdd_for_each_adapter(hdd_ctxt, adapter) {
8657 if (!(adapter->device_mode == QDF_SAP_MODE &&
8658 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008659 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08008660 adapter->device_mode,
8661 adapter->session.ap.sap_config.
8662 acs_cfg.acs_mode);
8663 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308664 }
8665
8666 found = false;
Krunal Sonidf29bc42018-11-15 13:26:29 -08008667 status =
8668 ucfg_policy_mgr_get_sta_sap_scc_lte_coex_chnl(hdd_ctxt->psoc,
8669 &scc_on_lte_coex);
8670 if (!QDF_IS_STATUS_SUCCESS(status))
8671 hdd_err("can't get scc on lte coex chnl, use def");
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008672 /*
8673 * If STA+SAP is doing SCC & g_sta_sap_scc_on_lte_coex_chan
8674 * is set, no need to move SAP.
8675 */
Manikandan Mohan956b69e2019-02-14 13:08:14 -08008676 if ((policy_mgr_is_sta_sap_scc(
8677 hdd_ctxt->psoc,
8678 adapter->session.ap.operating_channel) &&
8679 scc_on_lte_coex) ||
8680 policy_mgr_nan_sap_scc_on_unsafe_ch_chk(
8681 hdd_ctxt->psoc,
8682 adapter->session.ap.operating_channel)) {
8683 hdd_debug("SAP allowed in unsafe SCC channel");
8684 } else {
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008685 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
8686 if (adapter->session.ap.operating_channel ==
8687 hdd_ctxt->unsafe_channel_list[i]) {
8688 found = true;
8689 hdd_debug("operating ch:%d is unsafe",
8690 adapter->session.ap.operating_channel);
8691 break;
8692 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308693 }
8694 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308695 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008696 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08008697 adapter->session.ap.operating_channel);
8698 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308699 }
8700
Harprit Chhabada1eeeb8d2018-09-14 15:16:56 -07008701 status = ucfg_mlme_get_acs_support_for_dfs_ltecoex(
8702 hdd_ctxt->psoc,
8703 &is_acs_support_for_dfs_ltecoex);
8704 if (!QDF_IS_STATUS_SUCCESS(status))
8705 hdd_err("get_acs_support_for_dfs_ltecoex failed,set def");
8706
8707 status = ucfg_mlme_get_vendor_acs_support(
8708 hdd_ctxt->psoc,
8709 &is_vendor_acs_support);
8710 if (!QDF_IS_STATUS_SUCCESS(status))
8711 hdd_err("get_vendor_acs_support failed, set default");
8712
8713 if (is_vendor_acs_support && is_acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08008714 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05308715 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08008716 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308717 } else
8718 restart_chan =
bings6c4672b2019-03-19 16:00:19 +08008719 wlansap_get_safe_channel_from_pcl_and_acs_range(
8720 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Agrawal Ashish467dde42016-09-08 18:44:22 +05308721 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008722 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308723 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008724 /*
8725 * SAP restart due to unsafe channel. While
8726 * restarting the SAP, make sure to clear
8727 * acs_channel, channel to reset to
8728 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308729 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008730 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308731 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008732 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308733 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
8734 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Dustin Brown05d81302018-09-11 16:49:22 -07008735 ucfg_mlme_get_sap_internal_restart(hdd_ctxt->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05308736 &value);
8737 hdd_debug("driver to start sap: %d", value);
8738 if (value)
Min Liu2fef5792018-01-19 17:59:42 +08008739 hdd_switch_sap_channel(adapter, restart_chan,
8740 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04008741 else
8742 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308743 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308744 }
8745}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05308746
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008747/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008748 * hdd_init_channel_avoidance() - Initialize channel avoidance
8749 * @hdd_ctx: HDD global context
8750 *
8751 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07008752 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008753 * down to the lower layers. Then subscribe to subsequent channel
8754 * avoidance events.
8755 *
8756 * Return: None
8757 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008758static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008759{
8760 uint16_t unsafe_channel_count;
8761 int index;
8762
Yuanyuan Liu13738502016-04-06 17:41:37 -07008763 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
8764 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008765 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08008766 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008767
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008768 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008769 hdd_ctx->unsafe_channel_count);
8770
Anurag Chouhan6d760662016-02-20 16:05:43 +05308771 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08008772 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008773
8774 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008775 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008776 hdd_ctx->unsafe_channel_list[index]);
8777
8778 }
8779
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008780}
Dustin Brown676a2322017-08-15 13:16:13 -07008781
Jeff Johnson9d295242017-08-29 14:39:48 -07008782static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008783 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008784{
8785 uint8_t restart_chan;
8786
bings6c4672b2019-03-19 16:00:19 +08008787 restart_chan = wlansap_get_safe_channel_from_pcl_and_acs_range(
8788 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Dustin Brown676a2322017-08-15 13:16:13 -07008789 if (!restart_chan) {
8790 hdd_alert("fail to restart SAP");
8791 return;
8792 }
8793
8794 /* SAP restart due to unsafe channel. While restarting
8795 * the SAP, make sure to clear acs_channel, channel to
8796 * reset to 0. Otherwise these settings will override
8797 * the ACS while restart.
8798 */
8799 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07008800
8801 hdd_debug("sending coex indication");
8802
8803 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
8804 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08008805 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07008806}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008807
8808int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
8809 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
8810{
8811 uint32_t size;
8812 uint16_t *unsafe_list;
8813 uint16_t chan_count;
8814
8815 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
8816 return -EINVAL;
8817
8818 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
8819 NUM_CHANNELS);
8820 if (chan_count) {
8821 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
8822 unsafe_list = qdf_mem_malloc(size);
Min Liu74a1a502018-10-10 19:59:07 +08008823 if (!unsafe_list)
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008824 return -ENOMEM;
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008825 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
8826 } else {
8827 unsafe_list = NULL;
8828 }
8829
8830 *local_unsafe_list = unsafe_list;
8831 *local_unsafe_list_count = chan_count;
8832
8833 return 0;
8834}
8835
8836bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
8837 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
8838{
8839 int i, j;
8840
8841 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
8842 return true;
8843 if (local_unsafe_list_count == 0)
8844 return false;
8845 for (i = 0; i < local_unsafe_list_count; i++) {
8846 for (j = 0; j < local_unsafe_list_count; j++)
8847 if (local_unsafe_list[i] ==
8848 hdd_ctx->unsafe_channel_list[j])
8849 break;
8850 if (j >= local_unsafe_list_count)
8851 break;
8852 }
8853 if (i >= local_unsafe_list_count) {
8854 hdd_info("unsafe chan list same");
8855 return false;
8856 }
8857
8858 return true;
8859}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008860#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008861static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008862{
8863}
Dustin Brown676a2322017-08-15 13:16:13 -07008864
Jeff Johnson9d295242017-08-29 14:39:48 -07008865static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008866 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008867{
8868 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
8869}
Yuanyuan Liu13738502016-04-06 17:41:37 -07008870#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008871
8872/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08008873 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
8874 * user space
8875 * @frame_ind: Management frame data to be informed.
8876 *
8877 * This function is used to indicate management frame to
8878 * user space
8879 *
8880 * Return: None
8881 *
8882 */
8883void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
8884{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008885 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07008886 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008887 int i;
Pragaspathi Thilagaraj28ffc042018-07-18 15:19:36 +05308888 struct ieee80211_mgmt *mgmt =
8889 (struct ieee80211_mgmt *)frame_ind->frameBuf;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008890
Dustin Browne7e71d32018-05-11 16:00:08 -07008891 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
8892 if (wlan_hdd_validate_context(hdd_ctx))
Rajeev Kumard004abc2016-02-17 12:09:56 -08008893 return;
8894
Pragaspathi Thilagaraj28ffc042018-07-18 15:19:36 +05308895 if (frame_ind->frame_len < ieee80211_hdrlen(mgmt->frame_control)) {
8896 hdd_err(" Invalid frame length");
8897 return;
8898 }
8899
Rajeev Kumard004abc2016-02-17 12:09:56 -08008900 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
Dustin Brownad06be62019-02-04 14:52:56 -08008901 for (i = 0; i < WLAN_MAX_VDEVS; i++) {
Rajeev Kumard004abc2016-02-17 12:09:56 -08008902 adapter =
Jeff Johnson55d2ab42019-03-06 11:43:49 -08008903 hdd_get_adapter_by_vdev(hdd_ctx, i);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008904 if (adapter)
8905 break;
8906 }
Wu Gaoa0230a62018-01-04 20:56:57 +08008907 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
8908 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnsond36fa332019-03-18 13:42:25 -07008909 if ((adapter) &&
Wu Gaoa0230a62018-01-04 20:56:57 +08008910 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
8911 __hdd_indicate_mgmt_frame(adapter,
8912 frame_ind->frame_len,
8913 frame_ind->frameBuf,
8914 frame_ind->frameType,
8915 frame_ind->rxChan,
Srinivas Dasariea1c1332019-02-18 12:43:23 +05308916 frame_ind->rxRssi,
8917 frame_ind->rx_flags);
Wu Gaoa0230a62018-01-04 20:56:57 +08008918 }
8919 }
8920 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008921 } else {
Jeff Johnson55d2ab42019-03-06 11:43:49 -08008922 adapter = hdd_get_adapter_by_vdev(hdd_ctx,
8923 frame_ind->sessionId);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008924 }
8925
Jeff Johnsond36fa332019-03-18 13:42:25 -07008926 if ((adapter) &&
Rajeev Kumard004abc2016-02-17 12:09:56 -08008927 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
8928 __hdd_indicate_mgmt_frame(adapter,
8929 frame_ind->frame_len,
8930 frame_ind->frameBuf,
8931 frame_ind->frameType,
8932 frame_ind->rxChan,
Srinivas Dasariea1c1332019-02-18 12:43:23 +05308933 frame_ind->rxRssi,
8934 frame_ind->rx_flags);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008935}
8936
Kapil Gupta8878ad92017-02-13 11:56:04 +05308937void hdd_acs_response_timeout_handler(void *context)
8938{
8939 struct hdd_external_acs_timer_context *timer_context =
8940 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07008941 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008942 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308943 uint8_t reason;
8944
Dustin Brown491d54b2018-03-14 12:39:11 -07008945 hdd_enter();
Kapil Gupta8878ad92017-02-13 11:56:04 +05308946 if (!timer_context) {
8947 hdd_err("invlaid timer context");
8948 return;
8949 }
8950 adapter = timer_context->adapter;
8951 reason = timer_context->reason;
8952
8953
8954 if ((!adapter) ||
8955 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
8956 hdd_err("invalid adapter or adapter has invalid magic");
8957 return;
8958 }
8959 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8960 if (wlan_hdd_validate_context(hdd_ctx))
8961 return;
8962
8963 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
8964 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8965 else
8966 return;
8967
8968 hdd_err("ACS timeout happened for %s reason %d",
8969 adapter->dev->name, reason);
Jeff Johnson16528362018-06-14 12:34:16 -07008970
Kapil Gupta8878ad92017-02-13 11:56:04 +05308971 switch (reason) {
8972 /* SAP init case */
8973 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
8974 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
8975 false);
8976 wlan_hdd_cfg80211_start_acs(adapter);
8977 break;
8978 /* DFS detected on current channel */
8979 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
8980 wlan_sap_update_next_channel(
8981 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
Jeff Johnson16528362018-06-14 12:34:16 -07008982 sme_update_new_channel_event(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -08008983 adapter->vdev_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308984 break;
8985 /* LTE coex event on current channel */
8986 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
8987 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
8988 break;
8989 default:
8990 hdd_info("invalid reason for timer invoke");
8991
8992 }
8993}
8994
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008995/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008996 * hdd_override_ini_config - Override INI config
8997 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008998 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008999 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009000 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009001 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009002 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009003static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009004{
Abhinav Kumard4d6eb72018-12-04 20:30:37 +05309005 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009006
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009007 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
gaurank kathpalia97c070b2019-01-07 17:23:06 +05309008 ucfg_scan_cfg_set_dfs_chan_scan_allowed(hdd_ctx->psoc,
9009 enable_dfs_chan_scan);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009010 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009011 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009012 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009013 if (0 == enable_11d || 1 == enable_11d) {
Abhinav Kumard4d6eb72018-12-04 20:30:37 +05309014 status = ucfg_mlme_set_11d_enabled(hdd_ctx->psoc, enable_11d);
9015 if (!QDF_IS_STATUS_SUCCESS(status))
9016 hdd_err("Failed to set 11d_enable flag");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009017 }
Leo Chang11545d62016-10-17 14:53:50 -07009018
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +05309019 if (hdd_ctx->config->action_oui_enable && !ucfg_action_oui_enabled()) {
9020 hdd_ctx->config->action_oui_enable = 0;
Sourav Mohapatra58841062018-11-19 16:33:27 +05309021 hdd_err("Ignore action oui ini, since no action_oui component");
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +05309022 }
Will Huang14b120f2019-01-14 17:26:14 +08009023
9024 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
9025 hdd_override_all_ps(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009026}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08009027
Ashish Kumar Dhanotiya12f68212018-09-04 22:00:14 +05309028#ifdef ENABLE_MTRACE_LOG
9029static void hdd_set_mtrace_for_each(struct hdd_context *hdd_ctx)
9030{
9031 uint8_t module_id = 0;
9032 int qdf_print_idx = -1;
9033
9034 qdf_print_idx = qdf_get_pidx();
9035 for (module_id = 0; module_id < QDF_MODULE_ID_MAX; module_id++)
9036 qdf_print_set_category_verbose(
9037 qdf_print_idx,
9038 module_id, QDF_TRACE_LEVEL_TRACE,
9039 hdd_ctx->config->enable_mtrace);
9040}
9041#else
9042static void hdd_set_mtrace_for_each(struct hdd_context *hdd_ctx)
9043{
9044}
9045
9046#endif
9047
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009048/**
Wu Gao8dd9f502019-04-26 15:04:28 +08009049 * hdd_log_level_to_bitmask() - user space log level to host log bitmask
9050 * @user_log_level: user space log level
9051 *
9052 * Convert log level from user space to host log level bitmask.
9053 *
9054 * Return: Bitmask of log levels to be enabled
9055 */
9056static uint32_t hdd_log_level_to_bitmask(enum host_log_level user_log_level)
9057{
9058 QDF_TRACE_LEVEL host_trace_level;
9059 uint32_t bitmask;
9060
9061 switch (user_log_level) {
9062 case HOST_LOG_LEVEL_NONE:
9063 host_trace_level = QDF_TRACE_LEVEL_NONE;
9064 break;
9065 case HOST_LOG_LEVEL_FATAL:
9066 host_trace_level = QDF_TRACE_LEVEL_FATAL;
9067 break;
9068 case HOST_LOG_LEVEL_ERROR:
9069 host_trace_level = QDF_TRACE_LEVEL_ERROR;
9070 break;
9071 case HOST_LOG_LEVEL_WARN:
9072 host_trace_level = QDF_TRACE_LEVEL_WARN;
9073 break;
9074 case HOST_LOG_LEVEL_INFO:
9075 host_trace_level = QDF_TRACE_LEVEL_INFO_LOW;
9076 break;
9077 case HOST_LOG_LEVEL_DEBUG:
9078 host_trace_level = QDF_TRACE_LEVEL_DEBUG;
9079 break;
9080 case HOST_LOG_LEVEL_TRACE:
9081 host_trace_level = QDF_TRACE_LEVEL_TRACE;
9082 break;
9083 default:
9084 host_trace_level = QDF_TRACE_LEVEL_TRACE;
9085 break;
9086 }
9087
9088 bitmask = (1 << (host_trace_level + 1)) - 1;
9089
9090 return bitmask;
9091}
9092
9093/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009094 * hdd_set_trace_level_for_each - Set trace level for each INI config
9095 * @hdd_ctx - HDD context
9096 *
9097 * Set trace level for each module based on INI config.
9098 *
9099 * Return: None
9100 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009101static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009102{
Wu Gao8dd9f502019-04-26 15:04:28 +08009103 uint8_t host_module_log[QDF_MODULE_ID_MAX * 2];
9104 qdf_size_t host_module_log_num = 0;
9105 QDF_MODULE_ID module_id;
9106 uint32_t bitmask;
9107 uint32_t i;
9108
Wu Gaobc6eaa12018-11-30 14:17:45 +08009109 hdd_qdf_trace_enable(QDF_MODULE_ID_DP, 0x7f);
Wu Gao8dd9f502019-04-26 15:04:28 +08009110
9111 qdf_uint8_array_parse(cfg_get(hdd_ctx->psoc,
9112 CFG_ENABLE_HOST_MODULE_LOG_LEVEL),
9113 host_module_log,
9114 QDF_MODULE_ID_MAX * 2,
9115 &host_module_log_num);
9116
9117 for (i = 0; i + 1 < host_module_log_num; i += 2) {
9118 module_id = host_module_log[i];
9119 bitmask = hdd_log_level_to_bitmask(host_module_log[i + 1]);
9120 if (module_id < QDF_MODULE_ID_MAX &&
9121 module_id >= QDF_MODULE_ID_MIN)
9122 hdd_qdf_trace_enable(module_id, bitmask);
9123 }
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07009124
Ashish Kumar Dhanotiya12f68212018-09-04 22:00:14 +05309125 hdd_set_mtrace_for_each(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009126}
9127
9128/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009129 * hdd_context_init() - Initialize HDD context
9130 * @hdd_ctx: HDD context.
9131 *
9132 * Initialize HDD context along with all the feature specific contexts.
9133 *
9134 * return: 0 on success and errno on failure.
9135 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009136static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009137{
9138 int ret;
9139
9140 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
Dustin Brownad06be62019-02-04 14:52:56 -08009141 hdd_ctx->max_intf_count = WLAN_MAX_VDEVS;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009142
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009143 init_completion(&hdd_ctx->mc_sus_event_var);
9144 init_completion(&hdd_ctx->ready_to_suspend);
9145
9146 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009147 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05309148
Dustin Brownbee82832018-07-23 10:10:51 -07009149 qdf_list_create(&hdd_ctx->hdd_adapters, 0);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009150
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009151 ret = hdd_scan_context_init(hdd_ctx);
9152 if (ret)
9153 goto list_destroy;
9154
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009155 hdd_rx_wake_lock_create(hdd_ctx);
9156
9157 ret = hdd_sap_context_init(hdd_ctx);
9158 if (ret)
9159 goto scan_destroy;
9160
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009161 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
9162
9163 hdd_init_offloaded_packets_ctx(hdd_ctx);
9164
9165 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
9166 hdd_ctx->config);
9167 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08009168 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009169
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05309170 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
9171 "monitor_mode_wakelock");
9172
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009173 return 0;
9174
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009175sap_destroy:
9176 hdd_sap_context_destroy(hdd_ctx);
9177
9178scan_destroy:
9179 hdd_scan_context_destroy(hdd_ctx);
9180 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009181list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07009182 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08009183
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009184 return ret;
9185}
9186
Dustin Brown4c663222018-10-23 14:19:36 -07009187void hdd_psoc_idle_timer_start(struct hdd_context *hdd_ctx)
9188{
9189 uint32_t timeout_ms = hdd_ctx->config->iface_change_wait_time;
9190 enum wake_lock_reason reason =
9191 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER;
9192
Rajeev Kumar7b7bb3f2018-12-20 12:09:54 -08009193 if (!timeout_ms) {
9194 hdd_info("psoc idle timer is disabled");
9195 return;
9196 }
9197
Dustin Brown4c663222018-10-23 14:19:36 -07009198 hdd_debug("Starting psoc idle timer");
Dustin Brown8d8ab302019-03-05 16:19:36 -08009199 qdf_delayed_work_start(&hdd_ctx->psoc_idle_timeout_work, timeout_ms);
Dustin Brown4c663222018-10-23 14:19:36 -07009200 hdd_prevent_suspend_timeout(timeout_ms, reason);
9201}
9202
9203void hdd_psoc_idle_timer_stop(struct hdd_context *hdd_ctx)
9204{
Dustin Brown8d8ab302019-03-05 16:19:36 -08009205 qdf_delayed_work_stop_sync(&hdd_ctx->psoc_idle_timeout_work);
Dustin Brown4c663222018-10-23 14:19:36 -07009206 hdd_debug("Stopped psoc idle timer");
9207}
9208
Sourav Mohapatra698d6f62019-01-29 14:49:52 +05309209/*
9210 * enum hdd_block_shutdown - Control if driver allows modem shutdown
9211 * @HDD_UNBLOCK_MODEM_SHUTDOWN: Unblock shutdown
9212 * @HDD_BLOCK_MODEM_SHUTDOWN: Block shutdown
9213 *
9214 * On calling pld_block_shutdown API with the given values, modem
9215 * graceful shutdown is blocked/unblocked.
9216 */
9217enum hdd_block_shutdown {
9218 HDD_UNBLOCK_MODEM_SHUTDOWN,
9219 HDD_BLOCK_MODEM_SHUTDOWN,
9220};
9221
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009222/**
Rajeev Kumar473f9af2019-04-05 14:25:56 -07009223 * __hdd_psoc_idle_shutdown() - perform an idle shutdown on the given psoc
Dustin Brown3ecc8782018-09-19 16:37:13 -07009224 * @hdd_ctx: the hdd context which should be shutdown
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309225 *
Dustin Brown3ecc8782018-09-19 16:37:13 -07009226 * When no interfaces are "up" on a psoc, an idle shutdown timer is started.
9227 * If no interfaces are brought up before the timer expires, we do an
9228 * "idle shutdown," cutting power to the physical SoC to save power. This is
9229 * done completely transparently from the perspective of userspace.
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309230 *
Dustin Brown3ecc8782018-09-19 16:37:13 -07009231 * Return: None
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309232 */
Rajeev Kumar473f9af2019-04-05 14:25:56 -07009233static int __hdd_psoc_idle_shutdown(struct hdd_context *hdd_ctx)
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309234{
Dustin Brown363b4792019-02-05 16:11:55 -08009235 struct osif_psoc_sync *psoc_sync;
Dustin Browncfcb5762019-01-31 15:43:45 -08009236 int errno;
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309237
Dustin Brown491d54b2018-03-14 12:39:11 -07009238 hdd_enter();
Dustin Brown3ecc8782018-09-19 16:37:13 -07009239
Dustin Brown363b4792019-02-05 16:11:55 -08009240 errno = osif_psoc_sync_trans_start(hdd_ctx->parent_dev, &psoc_sync);
Dustin Browncfcb5762019-01-31 15:43:45 -08009241 if (errno) {
9242 hdd_info("psoc busy, abort idle shutdown; errno:%d", errno);
9243 goto exit;
Dustin Brown3ecc8782018-09-19 16:37:13 -07009244 }
Sourav Mohapatra698d6f62019-01-29 14:49:52 +05309245 /* Block the modem graceful shutdown till stop modules is completed */
9246 pld_block_shutdown(hdd_ctx->parent_dev, HDD_BLOCK_MODEM_SHUTDOWN);
Dustin Brown3ecc8782018-09-19 16:37:13 -07009247
Dustin Brown363b4792019-02-05 16:11:55 -08009248 osif_psoc_sync_wait_for_ops(psoc_sync);
Dustin Browncfcb5762019-01-31 15:43:45 -08009249
Dustin Brown3ecc8782018-09-19 16:37:13 -07009250 QDF_BUG(!hdd_wlan_stop_modules(hdd_ctx, false));
9251
Dustin Brown363b4792019-02-05 16:11:55 -08009252 osif_psoc_sync_trans_stop(psoc_sync);
Dustin Brown3ecc8782018-09-19 16:37:13 -07009253
Sourav Mohapatra698d6f62019-01-29 14:49:52 +05309254 pld_block_shutdown(hdd_ctx->parent_dev, HDD_UNBLOCK_MODEM_SHUTDOWN);
9255
Dustin Browncfcb5762019-01-31 15:43:45 -08009256exit:
Dustin Browne74003f2018-03-14 12:51:58 -07009257 hdd_exit();
Rajeev Kumar473f9af2019-04-05 14:25:56 -07009258 return errno;
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309259}
9260
Rajeev Kumar473f9af2019-04-05 14:25:56 -07009261int hdd_psoc_idle_shutdown(struct device *dev)
9262{
9263 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9264
9265 return __hdd_psoc_idle_shutdown(hdd_ctx);
9266}
9267
9268static int __hdd_psoc_idle_restart(struct hdd_context *hdd_ctx)
9269{
9270 return hdd_wlan_start_modules(hdd_ctx, false);
9271}
9272
9273int hdd_psoc_idle_restart(struct device *dev)
9274{
9275 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
9276
9277 return __hdd_psoc_idle_restart(hdd_ctx);
9278}
9279
9280int hdd_trigger_psoc_idle_restart(struct hdd_context *hdd_ctx)
Dustin Brown3ecc8782018-09-19 16:37:13 -07009281{
Dustin Brown693b5352019-01-17 10:00:31 -08009282 QDF_BUG(rtnl_is_locked());
Dustin Brown3ecc8782018-09-19 16:37:13 -07009283
Rajeev Kumar473f9af2019-04-05 14:25:56 -07009284 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
9285 hdd_psoc_idle_timer_stop(hdd_ctx);
9286 hdd_info("Driver modules already Enabled");
9287 return 0;
9288 }
9289
9290 pld_idle_restart(hdd_ctx->parent_dev, hdd_psoc_idle_restart);
9291
9292 return 0;
Dustin Brown3ecc8782018-09-19 16:37:13 -07009293}
9294
9295/**
9296 * hdd_psoc_idle_timeout_callback() - Handler for psoc idle timeout
9297 * @priv: pointer to hdd context
9298 *
9299 * Return: None
9300 */
9301static void hdd_psoc_idle_timeout_callback(void *priv)
9302{
9303 struct hdd_context *hdd_ctx = priv;
9304
9305 if (wlan_hdd_validate_context(hdd_ctx))
9306 return;
9307
Rajeev Kumar473f9af2019-04-05 14:25:56 -07009308 hdd_info("Psoc idle timeout elapsed; starting psoc shutdown");
9309
9310 pld_idle_shutdown(hdd_ctx->parent_dev, hdd_psoc_idle_shutdown);
Dustin Brown3ecc8782018-09-19 16:37:13 -07009311}
9312
Nirav Shaheb017be2018-02-15 11:20:58 +05309313#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9314static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
9315{
9316 wlan_logging_set_log_to_console(hdd_ctx->config->
9317 wlan_logging_to_console);
9318 wlan_logging_set_active(hdd_ctx->config->wlan_logging_enable);
9319}
9320#else
9321static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
9322{ }
9323#endif
9324
Dundi Raviteja8e338282018-09-25 17:16:04 +05309325#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9326static void hdd_init_wlan_logging_params(struct hdd_config *config,
9327 struct wlan_objmgr_psoc *psoc)
9328{
9329 config->wlan_logging_enable = cfg_get(psoc, CFG_WLAN_LOGGING_SUPPORT);
9330
9331 config->wlan_logging_to_console =
9332 cfg_get(psoc, CFG_WLAN_LOGGING_CONSOLE_SUPPORT);
9333}
9334#else
9335static void hdd_init_wlan_logging_params(struct hdd_config *config,
9336 struct wlan_objmgr_psoc *psoc)
9337{
9338}
9339#endif
9340
9341#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9342static void hdd_init_wlan_auto_shutdown(struct hdd_config *config,
9343 struct wlan_objmgr_psoc *psoc)
9344{
9345 config->wlan_auto_shutdown = cfg_get(psoc, CFG_WLAN_AUTO_SHUTDOWN);
9346}
9347#else
9348static void hdd_init_wlan_auto_shutdown(struct hdd_config *config,
9349 struct wlan_objmgr_psoc *psoc)
9350{
9351}
9352#endif
9353
9354#ifndef REMOVE_PKT_LOG
9355static void hdd_init_packet_log(struct hdd_config *config,
9356 struct wlan_objmgr_psoc *psoc)
9357{
9358 config->enable_packet_log = cfg_get(psoc, CFG_ENABLE_PACKET_LOG);
9359}
9360#else
9361static void hdd_init_packet_log(struct hdd_config *config,
9362 struct wlan_objmgr_psoc *psoc)
9363{
9364}
9365#endif
9366
Sandeep Puligilla43b6d1a2018-12-03 09:16:13 -08009367#ifdef ENABLE_MTRACE_LOG
9368static void hdd_init_mtrace_log(struct hdd_config *config,
9369 struct wlan_objmgr_psoc *psoc)
9370{
9371 config->enable_mtrace = cfg_get(psoc, CFG_ENABLE_MTRACE);
9372}
9373#else
9374static void hdd_init_mtrace_log(struct hdd_config *config,
9375 struct wlan_objmgr_psoc *psoc)
9376{
9377}
9378#endif
9379
Sourav Mohapatra0dfe5552018-11-16 11:29:54 +05309380#ifdef FEATURE_RUNTIME_PM
9381static void hdd_init_runtime_pm(struct hdd_config *config,
9382 struct wlan_objmgr_psoc *psoc)
9383{
9384 config->runtime_pm = cfg_get(psoc, CFG_ENABLE_RUNTIME_PM);
9385}
9386#else
9387static void hdd_init_runtime_pm(struct hdd_config *config,
9388 struct wlan_objmgr_psoc *psoc)
9389
9390{
9391}
9392#endif
9393
9394#ifdef FEATURE_WLAN_DYNAMIC_CVM
9395static void hdd_init_vc_mode_cfg_bitmap(struct hdd_config *config,
9396 struct wlan_objmgr_psoc *psoc)
9397{
9398 config->vc_mode_cfg_bitmap = cfg_get(psoc, CFG_VC_MODE_BITMAP);
9399}
9400#else
9401static void hdd_init_vc_mode_cfg_bitmap(struct hdd_config *config,
9402 struct wlan_objmgr_psoc *psoc)
9403{
9404}
9405#endif
9406
gaurank kathpalia566c81b2019-02-20 14:31:45 +05309407#ifdef DHCP_SERVER_OFFLOAD
9408static void
9409hdd_init_dhcp_server_ip(struct hdd_context *hdd_ctx)
9410{
9411 uint8_t num_entries;
9412
9413 hdd_ctx->config->dhcp_server_ip.is_dhcp_server_ip_valid = true;
9414 hdd_string_to_u8_array(cfg_get(hdd_ctx->psoc, CFG_DHCP_SERVER_IP_NAME),
9415 hdd_ctx->config->dhcp_server_ip.dhcp_server_ip,
9416 &num_entries, IPADDR_NUM_ENTRIES);
9417
9418 if (num_entries != IPADDR_NUM_ENTRIES) {
9419 hdd_err("Incorrect IP address (%s) assigned for DHCP server!",
9420 cfg_get(hdd_ctx->psoc, CFG_DHCP_SERVER_IP_NAME));
9421 hdd_config->dhcp_server_ip.is_dhcp_server_ip_valid = false;
9422 }
9423}
9424#else
9425static void
9426hdd_init_dhcp_server_ip(struct hdd_context *hdd_ctx)
9427{
9428}
9429#endif
9430
Dundi Raviteja8e338282018-09-25 17:16:04 +05309431/**
9432 * hdd_cfg_params_init() - Initialize hdd params in hdd_config strucuture
9433 * @hdd_ctx - Pointer to HDD context
9434 *
9435 * Return: None
9436 */
9437static void hdd_cfg_params_init(struct hdd_context *hdd_ctx)
9438{
9439 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
9440 struct hdd_config *config = hdd_ctx->config;
9441
9442 if (!psoc) {
9443 hdd_err("Invalid psoc");
9444 return;
9445 }
9446
9447 if (!config) {
9448 hdd_err("Invalid hdd config");
9449 return;
9450 }
9451
gaurank kathpalia43c52622019-02-11 12:30:05 +05309452 config->dot11Mode = cfg_get(psoc, CFG_HDD_DOT11_MODE);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309453 config->bug_on_reinit_failure = cfg_get(psoc,
9454 CFG_BUG_ON_REINIT_FAILURE);
9455
9456 config->is_ramdump_enabled = cfg_get(psoc,
9457 CFG_ENABLE_RAMDUMP_COLLECTION);
9458
9459 config->iface_change_wait_time = cfg_get(psoc,
9460 CFG_INTERFACE_CHANGE_WAIT);
9461
9462 config->multicast_host_fw_msgs = cfg_get(psoc,
9463 CFG_MULTICAST_HOST_FW_MSGS);
9464
9465 config->private_wext_control = cfg_get(psoc, CFG_PRIVATE_WEXT_CONTROL);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309466 config->enablefwprint = cfg_get(psoc, CFG_ENABLE_FW_UART_PRINT);
9467 config->enable_fw_log = cfg_get(psoc, CFG_ENABLE_FW_LOG);
Vignesh Viswanathana0358ff2018-11-27 09:53:07 +05309468 config->operating_channel = cfg_get(psoc, CFG_OPERATING_CHANNEL);
9469 config->num_vdevs = cfg_get(psoc, CFG_NUM_VDEV_ENABLE);
Vignesh Viswanathana0358ff2018-11-27 09:53:07 +05309470 qdf_str_lcopy(config->enable_concurrent_sta,
9471 cfg_get(psoc, CFG_ENABLE_CONCURRENT_STA),
9472 CFG_CONCURRENT_IFACE_MAX_LEN);
9473 qdf_str_lcopy(config->dbs_scan_selection,
9474 cfg_get(psoc, CFG_DBS_SCAN_SELECTION),
9475 CFG_DBS_SCAN_PARAM_LENGTH);
Sourav Mohapatra0dfe5552018-11-16 11:29:54 +05309476 config->inform_bss_rssi_raw = cfg_get(psoc, CFG_INFORM_BSS_RSSI_RAW);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +05309477 config->mac_provision = cfg_get(psoc, CFG_ENABLE_MAC_PROVISION);
9478 config->provisioned_intf_pool =
9479 cfg_get(psoc, CFG_PROVISION_INTERFACE_POOL);
9480 config->derived_intf_pool = cfg_get(psoc, CFG_DERIVED_INTERFACE_POOL);
Sourav Mohapatra58841062018-11-19 16:33:27 +05309481 config->action_oui_enable = cfg_get(psoc, CFG_ENABLE_ACTION_OUI);
Jeff Johnson15a88ac2019-03-11 14:35:25 -07009482 config->advertise_concurrent_operation =
Sandeep Puligilladc6d68a2019-01-04 16:57:12 -08009483 cfg_get(psoc,
9484 CFG_ADVERTISE_CONCURRENT_OPERATION);
Sourav Mohapatra58841062018-11-19 16:33:27 +05309485 qdf_str_lcopy(config->action_oui_str[0],
9486 cfg_get(psoc, CFG_ACTION_OUI_CONNECT_1X1),
9487 ACTION_OUI_MAX_STR_LEN);
9488 qdf_str_lcopy(config->action_oui_str[1],
9489 cfg_get(psoc, CFG_ACTION_OUI_ITO_EXTENSION),
9490 ACTION_OUI_MAX_STR_LEN);
9491 qdf_str_lcopy(config->action_oui_str[2],
9492 cfg_get(psoc, CFG_ACTION_OUI_CCKM_1X1),
9493 ACTION_OUI_MAX_STR_LEN);
9494 qdf_str_lcopy(config->action_oui_str[3],
9495 cfg_get(psoc, CFG_ACTION_OUI_ITO_ALTERNATE),
9496 ACTION_OUI_MAX_STR_LEN);
9497 qdf_str_lcopy(config->action_oui_str[4],
9498 cfg_get(psoc, CFG_ACTION_OUI_SWITCH_TO_11N_MODE),
9499 ACTION_OUI_MAX_STR_LEN);
9500 qdf_str_lcopy(config->action_oui_str[5],
9501 cfg_get(psoc,
9502 CFG_ACTION_OUI_CONNECT_1X1_WITH_1_CHAIN),
9503 ACTION_OUI_MAX_STR_LEN);
Rajeev Kumar Sirasanagandlad7987f12018-12-08 23:24:04 +05309504 qdf_str_lcopy(config->action_oui_str[6],
9505 cfg_get(psoc,
9506 CFG_ACTION_OUI_DISABLE_AGGRESSIVE_TX),
9507 ACTION_OUI_MAX_STR_LEN);
Sourav Mohapatra9e014cf2018-12-11 09:39:33 +05309508 config->enable_rtt_support = cfg_get(psoc, CFG_ENABLE_RTT_SUPPORT);
Sandeep Puligillaefeb4a92019-01-08 00:06:51 -08009509 config->is_unit_test_framework_enabled =
9510 cfg_get(psoc, CFG_ENABLE_UNIT_TEST_FRAMEWORK);
Ashish Kumar Dhanotiyad63d6862019-03-14 18:54:10 +05309511 config->disable_channel = cfg_get(psoc, CFG_ENABLE_DISABLE_CHANNEL);
Ashish Kumar Dhanotiya95498182019-04-29 13:59:20 +05309512 config->sar_version = cfg_get(psoc, CFG_SAR_VERSION);
Rajeev Kumar3a7c3402019-05-02 16:02:20 -07009513 config->is_wow_disabled = cfg_get(psoc, CFG_WOW_DISABLE);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309514
Sourav Mohapatra0dfe5552018-11-16 11:29:54 +05309515 hdd_init_vc_mode_cfg_bitmap(config, psoc);
9516 hdd_init_runtime_pm(config, psoc);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309517 hdd_init_wlan_auto_shutdown(config, psoc);
9518 hdd_init_wlan_logging_params(config, psoc);
9519 hdd_init_packet_log(config, psoc);
Sandeep Puligilla43b6d1a2018-12-03 09:16:13 -08009520 hdd_init_mtrace_log(config, psoc);
gaurank kathpalia566c81b2019-02-20 14:31:45 +05309521 hdd_init_dhcp_server_ip(hdd_ctx);
jitiphil869b9f72018-09-25 17:14:01 +05309522 hdd_dp_cfg_update(psoc, hdd_ctx);
Dundi Raviteja8e338282018-09-25 17:16:04 +05309523}
9524
Dustin Brown623e7e32018-09-05 14:27:50 -07009525struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009526{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309527 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009528 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009529 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009530
Dustin Brown491d54b2018-03-14 12:39:11 -07009531 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009532
Dustin Brown92bd8382018-10-31 15:49:46 -07009533 hdd_ctx = hdd_cfg80211_wiphy_alloc();
9534 if (!hdd_ctx) {
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009535 ret = -ENOMEM;
9536 goto err_out;
9537 }
9538
Dustin Brown8d8ab302019-03-05 16:19:36 -08009539 status = qdf_delayed_work_create(&hdd_ctx->psoc_idle_timeout_work,
9540 hdd_psoc_idle_timeout_callback,
9541 hdd_ctx);
9542 if (QDF_IS_STATUS_ERROR(status)) {
9543 ret = qdf_status_to_os_return(status);
9544 goto wiphy_dealloc;
9545 }
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309546
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009547 hdd_ctx->parent_dev = dev;
Jeff Johnson995fd512019-03-06 08:45:10 -08009548 hdd_ctx->last_scan_reject_vdev_id = WLAN_UMAC_VDEV_ID_MAX;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009549
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309550 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Min Liu74a1a502018-10-10 19:59:07 +08009551 if (!hdd_ctx->config) {
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009552 ret = -ENOMEM;
9553 goto err_free_hdd_context;
9554 }
9555
Dustin Brown84f46ea2018-02-15 11:57:36 -08009556 status = cfg_parse(WLAN_INI_FILE);
9557 if (QDF_IS_STATUS_ERROR(status))
9558 hdd_err("Failed to parse cfg %s; status:%d\n",
9559 WLAN_INI_FILE, status);
9560
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309561 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx, DEFAULT_PSOC_ID);
9562 if (ret) {
Dundi Raviteja8e338282018-09-25 17:16:04 +05309563 QDF_DEBUG_PANIC("Psoc creation fails!");
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309564 goto err_free_config;
9565 }
9566
Dundi Raviteja8e338282018-09-25 17:16:04 +05309567 hdd_cfg_params_init(hdd_ctx);
9568
Dustin Brown4bbd5462019-03-22 11:18:13 -07009569 /* apply multiplier config, if not already set via module parameter */
9570 if (qdf_timer_get_multiplier() == 1)
9571 qdf_timer_set_multiplier(cfg_get(hdd_ctx->psoc,
9572 CFG_TIMER_MULTIPLIER));
Dustin Browna9a84522019-02-04 12:25:40 -08009573 hdd_debug("set timer multiplier: %u", qdf_timer_get_multiplier());
Dustin Brown7f939932017-05-18 15:02:17 -07009574
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309575 cds_set_fatal_event(cfg_get(hdd_ctx->psoc,
9576 CFG_ENABLE_FATAL_EVENT_TRIGGER));
Abhishek Singh5ea86532016-04-27 14:10:53 +05309577
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009578 hdd_override_ini_config(hdd_ctx);
9579
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009580 ret = hdd_context_init(hdd_ctx);
9581
9582 if (ret)
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309583 goto err_hdd_objmgr_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009584
Nirav Shah6aeecf92019-02-13 14:05:03 +05309585 if (hdd_get_conparam() == QDF_GLOBAL_FTM_MODE ||
9586 hdd_get_conparam() == QDF_GLOBAL_EPPING_MODE)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009587 goto skip_multicast_logging;
9588
9589 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
9590
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07009591 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
9592 if (ret)
9593 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05309594
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009595 ret = hdd_init_netlink_services(hdd_ctx);
9596 if (ret)
9597 goto err_deinit_txrx_histogram;
9598
Nirav Shaheb017be2018-02-15 11:20:58 +05309599 hdd_set_wlan_logging(hdd_ctx);
Nirav Shahed34b212016-04-25 10:59:16 +05309600
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009601skip_multicast_logging:
9602 hdd_set_trace_level_for_each(hdd_ctx);
9603
Rajeev Kumar493a31b2017-09-29 14:01:24 -07009604 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
9605
Dustin Browne74003f2018-03-14 12:51:58 -07009606 hdd_exit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07009607
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009608 return hdd_ctx;
9609
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009610err_deinit_txrx_histogram:
9611 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
9612
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07009613err_deinit_hdd_context:
9614 hdd_context_deinit(hdd_ctx);
9615
Dundi Ravitejafb9357a2018-09-25 12:16:03 +05309616err_hdd_objmgr_destroy:
9617 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
9618
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009619err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309620 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009621
9622err_free_hdd_context:
Dustin Brown8d8ab302019-03-05 16:19:36 -08009623 qdf_delayed_work_destroy(&hdd_ctx->psoc_idle_timeout_work);
9624
9625wiphy_dealloc:
Rajeev Kumarfa55a692018-01-09 14:12:41 -08009626 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009627
9628err_out:
9629 return ERR_PTR(ret);
9630}
9631
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009632/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309633 * hdd_start_station_adapter()- Start the Station Adapter
9634 * @adapter: HDD adapter
9635 *
9636 * This function initializes the adapter for the station mode.
9637 *
9638 * Return: 0 on success or errno on failure.
9639 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009640int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309641{
9642 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08009643 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309644
Dustin Brownfdf17c12018-03-14 12:55:34 -07009645 hdd_enter_dev(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08009646 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9647 hdd_err("session is already opened, %d",
Jeff Johnson5a6fc962019-02-04 14:20:25 -08009648 adapter->vdev_id);
Krunal Sonib51eec72017-11-20 21:53:01 -08009649 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9650 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309651
Krunal Sonib51eec72017-11-20 21:53:01 -08009652 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
9653 if (ret) {
9654 hdd_err("failed to create vdev: %d", ret);
9655 return ret;
9656 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309657 status = hdd_init_station_mode(adapter);
9658
9659 if (QDF_STATUS_SUCCESS != status) {
9660 hdd_err("Error Initializing station mode: %d", status);
9661 return qdf_status_to_os_return(status);
9662 }
9663
Arun Khandavallifae92942016-08-01 13:31:08 +05309664 hdd_register_tx_flow_control(adapter,
9665 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009666 hdd_tx_resume_cb,
9667 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309668
Visweswara Tanukub5a61242019-03-26 12:24:13 +05309669 hdd_register_hl_netdev_fc_timer(adapter,
9670 hdd_tx_resume_timer_expired_handler);
9671
Dustin Browne74003f2018-03-14 12:51:58 -07009672 hdd_exit();
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05309673
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309674 return 0;
9675}
9676
9677/**
9678 * hdd_start_ap_adapter()- Start AP Adapter
9679 * @adapter: HDD adapter
9680 *
9681 * This function initializes the adapter for the AP mode.
9682 *
9683 * Return: 0 on success errno on failure.
9684 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009685int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309686{
9687 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009688 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08009689 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08009690 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arif Hussainbd5194c2018-11-27 19:01:15 -08009691 uint32_t fine_time_meas_cap = 0;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309692
Dustin Brown491d54b2018-03-14 12:39:11 -07009693 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309694
Krunal Sonib51eec72017-11-20 21:53:01 -08009695 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9696 hdd_err("session is already opened, %d",
Jeff Johnson5a6fc962019-02-04 14:20:25 -08009697 adapter->vdev_id);
Krunal Sonib51eec72017-11-20 21:53:01 -08009698 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9699 }
9700 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009701 * In SSR case no need to create new sap context.
9702 * Otherwise create sap context first and then create
9703 * vdev as while creating the vdev, driver needs to
9704 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08009705 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009706 if (adapter->session.ap.sap_context) {
9707 is_ssr = true;
9708 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08009709 hdd_err("sap creation failed");
9710 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
9711 }
9712
9713 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
9714 adapter->session.ap.sap_context);
9715 if (ret) {
9716 hdd_err("failed to create vdev, status:%d", ret);
9717 hdd_sap_destroy_ctx(adapter);
9718 return ret;
9719 }
Naveen Rawat1af09392018-01-03 17:28:21 -08009720
Arif Hussainbd5194c2018-11-27 19:01:15 -08009721 if (adapter->device_mode == QDF_SAP_MODE) {
9722 ucfg_mlme_get_fine_time_meas_cap(hdd_ctx->psoc,
9723 &fine_time_meas_cap);
Jeff Johnson5a6fc962019-02-04 14:20:25 -08009724 sme_cli_set_command(adapter->vdev_id,
Naveen Rawat1af09392018-01-03 17:28:21 -08009725 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
Arif Hussainbd5194c2018-11-27 19:01:15 -08009726 (bool)(fine_time_meas_cap & WMI_FW_AP_RTT_RESPR),
Naveen Rawat1af09392018-01-03 17:28:21 -08009727 VDEV_CMD);
Arif Hussainbd5194c2018-11-27 19:01:15 -08009728 }
Naveen Rawat1af09392018-01-03 17:28:21 -08009729
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009730 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309731
9732 if (QDF_STATUS_SUCCESS != status) {
9733 hdd_err("Error Initializing the AP mode: %d", status);
9734 return qdf_status_to_os_return(status);
9735 }
9736
Arun Khandavallifae92942016-08-01 13:31:08 +05309737 hdd_register_tx_flow_control(adapter,
9738 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009739 hdd_softap_tx_resume_cb,
9740 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309741
Visweswara Tanukub5a61242019-03-26 12:24:13 +05309742 hdd_register_hl_netdev_fc_timer(adapter,
9743 hdd_tx_resume_timer_expired_handler);
9744
Dustin Browne74003f2018-03-14 12:51:58 -07009745 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309746 return 0;
9747}
9748
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309749/**
9750 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
9751 * @cds_cfg: CDS Configuration
9752 * @hdd_ctx: Pointer to hdd context
9753 *
9754 * Return: none
9755 */
9756static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9757 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009758 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309759{
9760 cds_cfg->tx_flow_stop_queue_th =
jitiphil47c3d9a2018-11-08 18:30:55 +05309761 cfg_get(hdd_ctx->psoc, CFG_DP_TX_FLOW_STOP_QUEUE_TH);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309762 cds_cfg->tx_flow_start_queue_offset =
jitiphil47c3d9a2018-11-08 18:30:55 +05309763 cfg_get(hdd_ctx->psoc, CFG_DP_TX_FLOW_START_QUEUE_OFFSET);
Mohit Khanna70322002018-05-15 19:21:32 -07009764 /* configuration for DP RX Threads */
9765 cds_cfg->enable_dp_rx_threads = hdd_ctx->enable_dp_rx_threads;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309766}
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309767
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309768/**
9769 * hdd_update_cds_config() - API to update cds configuration parameters
9770 * @hdd_ctx: HDD Context
9771 *
9772 * Return: 0 for Success, errno on failure
9773 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009774static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309775{
9776 struct cds_config_info *cds_cfg;
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309777 int value;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309778 uint8_t band_capability;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309779 uint8_t ito_repeat_count;
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309780 bool crash_inject;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309781 bool self_recovery;
9782 bool fw_timeout_crash;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309783 QDF_STATUS status;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309784
Min Liu74a1a502018-10-10 19:59:07 +08009785 cds_cfg = qdf_mem_malloc(sizeof(*cds_cfg));
9786 if (!cds_cfg)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309787 return -ENOMEM;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309788
Srinivas Girigowda35b00312017-06-27 21:52:03 -07009789 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Bala Venkatesh46e29032018-11-14 18:24:55 +05309790 ucfg_mlme_get_sap_max_modulated_dtim(hdd_ctx->psoc,
9791 &cds_cfg->sta_maxlimod_dtim);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309792
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309793 status = ucfg_mlme_get_crash_inject(hdd_ctx->psoc, &crash_inject);
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309794 if (QDF_IS_STATUS_ERROR(status)) {
9795 hdd_err("Failed to get crash inject ini config");
9796 goto exit;
9797 }
9798
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309799 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
9800 if (QDF_IS_STATUS_ERROR(status)) {
9801 hdd_err("Failed to get self recovery ini config");
9802 goto exit;
9803 }
9804
9805 status = ucfg_mlme_get_fw_timeout_crash(hdd_ctx->psoc,
9806 &fw_timeout_crash);
9807 if (QDF_IS_STATUS_ERROR(status)) {
9808 hdd_err("Failed to get fw timeout crash ini config");
9809 goto exit;
9810 }
9811
9812 status = ucfg_mlme_get_ito_repeat_count(hdd_ctx->psoc,
9813 &ito_repeat_count);
9814 if (QDF_IS_STATUS_ERROR(status)) {
9815 hdd_err("Failed to get ITO repeat count ini config");
9816 goto exit;
9817 }
9818
Vignesh Viswanathana851d752018-10-03 19:44:38 +05309819 cds_cfg->force_target_assert_enabled = crash_inject;
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05309820
Dustin Brown05d81302018-09-11 16:49:22 -07009821 ucfg_mlme_get_sap_max_offload_peers(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309822 cds_cfg->ap_maxoffload_peers = value;
Dustin Brown05d81302018-09-11 16:49:22 -07009823 ucfg_mlme_get_sap_max_offload_reorder_buffs(hdd_ctx->psoc,
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309824 &value);
9825 cds_cfg->ap_maxoffload_reorderbuffs = value;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309826
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309827 cds_cfg->reorder_offload =
jitiphil47c3d9a2018-11-08 18:30:55 +05309828 cfg_get(hdd_ctx->psoc, CFG_DP_REORDER_OFFLOAD_SUPPORT);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309829
9830 /* IPA micro controller data path offload resource config item */
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05309831 cds_cfg->uc_offload_enabled = ucfg_ipa_uc_is_enabled();
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309832
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07009833 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Dustin Brown05d81302018-09-11 16:49:22 -07009834 ucfg_mlme_get_sap_max_peers(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +05309835 cds_cfg->max_station = value;
Naveen Rawat64e477e2016-05-20 10:34:56 -07009836 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07009837 cds_cfg->max_msdus_per_rxinorderind =
jitiphil8e15ea62018-11-16 18:05:34 +05309838 cfg_get(hdd_ctx->psoc, CFG_DP_MAX_MSDUS_PER_RXIND);
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309839 cds_cfg->self_recovery_enabled = self_recovery;
9840 cds_cfg->fw_timeout_crash = fw_timeout_crash;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309841
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +05309842 cds_cfg->ito_repeat_count = ito_repeat_count;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309843
9844 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
9845 if (QDF_IS_STATUS_ERROR(status))
9846 goto exit;
9847
9848 cds_cfg->bandcapability = band_capability;
Rachit Kankane0106e382018-05-16 18:59:28 +05309849 cds_cfg->num_vdevs = hdd_ctx->config->num_vdevs;
Jiani Liu6d3b6a12019-05-08 15:15:06 +08009850 cds_cfg->enable_tx_compl_tsf64 =
9851 hdd_tsf_is_tsf64_tx_set(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309852 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07009853 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309854 cds_init_ini_config(cds_cfg);
9855 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309856
9857exit:
9858 qdf_mem_free(cds_cfg);
9859 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309860}
9861
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009862/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009863 * hdd_update_user_config() - API to update user configuration
9864 * parameters to obj mgr which are used by multiple components
9865 * @hdd_ctx: HDD Context
9866 *
9867 * Return: 0 for Success, errno on failure
9868 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009869static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009870{
9871 struct wlan_objmgr_psoc_user_config *user_config;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309872 uint8_t band_capability;
9873 QDF_STATUS status;
Abhinav Kumard4d6eb72018-12-04 20:30:37 +05309874 bool value = false;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309875
9876 status = ucfg_mlme_get_band_capability(hdd_ctx->psoc, &band_capability);
9877 if (QDF_IS_STATUS_ERROR(status))
9878 return -EIO;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009879
9880 user_config = qdf_mem_malloc(sizeof(*user_config));
Min Liu74a1a502018-10-10 19:59:07 +08009881 if (!user_config)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009882 return -ENOMEM;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009883
9884 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
Abhinav Kumard4d6eb72018-12-04 20:30:37 +05309885 status = ucfg_mlme_is_11d_enabled(hdd_ctx->psoc, &value);
9886 if (!QDF_IS_STATUS_SUCCESS(status))
9887 hdd_err("Invalid 11d_enable flag");
9888 user_config->is_11d_support_enabled = value;
9889
9890 value = false;
9891 status = ucfg_mlme_is_11h_enabled(hdd_ctx->psoc, &value);
9892 if (!QDF_IS_STATUS_SUCCESS(status))
9893 hdd_err("Invalid 11h_enable flag");
9894 user_config->is_11h_support_enabled = value;
Vignesh Viswanathanf97cc112018-10-03 19:17:07 +05309895 user_config->band_capability = band_capability;
Dustin Brown1dbefe62018-09-11 16:32:03 -07009896 wlan_objmgr_psoc_set_user_config(hdd_ctx->psoc, user_config);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009897
9898 qdf_mem_free(user_config);
9899 return 0;
9900}
9901
9902/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009903 * hdd_init_thermal_info - Initialize thermal level
9904 * @hdd_ctx: HDD context
9905 *
9906 * Initialize thermal level at SME layer and set the thermal level callback
9907 * which would be called when a configured thermal threshold is hit.
9908 *
9909 * Return: 0 on success and errno on failure
9910 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009911static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009912{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309913 QDF_STATUS status;
Manikandan Mohan9045e2e2018-11-26 16:44:19 -08009914 mac_handle_t mac_handle = hdd_ctx->mac_handle;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009915
Manikandan Mohan9045e2e2018-11-26 16:44:19 -08009916 status = sme_init_thermal_info(mac_handle);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009917
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309918 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05309919 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009920
Jeff Johnson16528362018-06-14 12:34:16 -07009921 sme_add_set_thermal_level_callback(mac_handle,
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009922 hdd_set_thermal_level_cb);
9923
9924 return 0;
9925
9926}
9927
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009928#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
9929/**
9930 * hdd_hold_rtnl_lock - Hold RTNL lock
9931 *
9932 * Hold RTNL lock
9933 *
9934 * Return: True if held and false otherwise
9935 */
9936static inline bool hdd_hold_rtnl_lock(void)
9937{
9938 rtnl_lock();
9939 return true;
9940}
9941
9942/**
9943 * hdd_release_rtnl_lock - Release RTNL lock
9944 *
9945 * Release RTNL lock
9946 *
9947 * Return: None
9948 */
9949static inline void hdd_release_rtnl_lock(void)
9950{
9951 rtnl_unlock();
9952}
9953#else
9954static inline bool hdd_hold_rtnl_lock(void) { return false; }
9955static inline void hdd_release_rtnl_lock(void) { }
9956#endif
9957
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009958#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009959
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309960/* MAX iwpriv command support */
9961#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309962#define PKTLOG_CLEAR_BUFF 4
Venkata Sharath Chandra Manchala27e44902019-01-28 11:29:18 -08009963/* Set Maximum pktlog file size to 64MB */
9964#define MAX_PKTLOG_SIZE 64
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309965
9966/**
9967 * hdd_pktlog_set_buff_size() - set pktlog buffer size
9968 * @hdd_ctx: hdd context
9969 * @set_value2: pktlog buffer size value
9970 *
9971 *
9972 * Return: 0 for success or error.
9973 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009974static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309975{
9976 struct sir_wifi_start_log start_log = { 0 };
9977 QDF_STATUS status;
9978
9979 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9980 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9981 start_log.ini_triggered = cds_is_packet_log_enabled();
9982 start_log.user_triggered = 1;
9983 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309984 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309985
Jeff Johnson16528362018-06-14 12:34:16 -07009986 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309987 if (!QDF_IS_STATUS_SUCCESS(status)) {
9988 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009989 hdd_exit();
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309990 return -EINVAL;
9991 }
9992
9993 return 0;
9994}
9995
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009996/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309997 * hdd_pktlog_clear_buff() - clear pktlog buffer
9998 * @hdd_ctx: hdd context
9999 *
10000 * Return: 0 for success or error.
10001 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010002static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010003{
10004 struct sir_wifi_start_log start_log;
10005 QDF_STATUS status;
10006
10007 start_log.ring_id = RING_ID_PER_PACKET_STATS;
10008 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
10009 start_log.ini_triggered = cds_is_packet_log_enabled();
10010 start_log.user_triggered = 1;
10011 start_log.size = 0;
10012 start_log.is_pktlog_buff_clear = true;
10013
Jeff Johnson16528362018-06-14 12:34:16 -070010014 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010015 if (!QDF_IS_STATUS_SUCCESS(status)) {
10016 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -070010017 hdd_exit();
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010018 return -EINVAL;
10019 }
10020
10021 return 0;
10022}
10023
10024
10025/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010026 * hdd_process_pktlog_command() - process pktlog command
10027 * @hdd_ctx: hdd context
10028 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010029 * @set_value2: pktlog buffer size value
10030 *
10031 * This function process pktlog command.
10032 * set_value2 only matters when set_value is 3 (set buff size)
10033 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010034 *
10035 * Return: 0 for success or error.
10036 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010037int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010038 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010039{
10040 int ret;
10041 bool enable;
10042 uint8_t user_triggered = 0;
10043
10044 ret = wlan_hdd_validate_context(hdd_ctx);
10045 if (0 != ret)
10046 return ret;
10047
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010048 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010049
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010050 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010051 hdd_err("invalid pktlog value %d", set_value);
10052 return -EINVAL;
10053 }
10054
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010055 if (set_value == PKTLOG_SET_BUFF_SIZE) {
10056 if (set_value2 <= 0) {
10057 hdd_err("invalid pktlog size %d", set_value2);
10058 return -EINVAL;
10059 } else if (set_value2 > MAX_PKTLOG_SIZE) {
Venkata Sharath Chandra Manchala27e44902019-01-28 11:29:18 -080010060 hdd_err_rl("Pktlog size is large. max value is %uMB.",
10061 MAX_PKTLOG_SIZE);
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010062 return -EINVAL;
10063 }
10064 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010065 } else if (set_value == PKTLOG_CLEAR_BUFF) {
10066 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010067 }
10068
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010069 /*
10070 * set_value = 0 then disable packetlog
10071 * set_value = 1 enable packetlog forcefully
10072 * set_vlaue = 2 then disable packetlog if disabled through ini or
10073 * enable packetlog with AUTO type.
10074 */
10075 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
10076 true : false;
10077
10078 if (1 == set_value) {
10079 enable = true;
10080 user_triggered = 1;
10081 }
10082
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010083 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010084}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070010085
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010086/**
10087 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
10088 * @hdd_ctx: HDD context
10089 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010090 * @user_triggered: triggered through iwpriv
10091 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010092 *
10093 * Return: 0 on success; error number otherwise
10094 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010095int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010096 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010097{
10098 struct sir_wifi_start_log start_log;
10099 QDF_STATUS status;
10100
10101 start_log.ring_id = RING_ID_PER_PACKET_STATS;
10102 start_log.verbose_level =
10103 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -080010104 start_log.ini_triggered = cds_is_packet_log_enabled();
10105 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +053010106 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +053010107 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +053010108 /*
10109 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
10110 * commands. Host uses this flag to decide whether to send pktlog
10111 * disable command to fw without sending pktlog enable command
10112 * previously. For eg, If vendor sends pktlog disable command without
10113 * sending pktlog enable command, then host discards the packet
10114 * but for iwpriv command, host will send it to fw.
10115 */
10116 start_log.is_iwpriv_command = 1;
Jeff Johnson16528362018-06-14 12:34:16 -070010117 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010118 if (!QDF_IS_STATUS_SUCCESS(status)) {
10119 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -070010120 hdd_exit();
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010121 return -EINVAL;
10122 }
10123
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010124 if (enable == true)
10125 hdd_ctx->is_pktlog_enabled = 1;
10126 else
10127 hdd_ctx->is_pktlog_enabled = 0;
10128
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -080010129 return 0;
10130}
10131#endif /* REMOVE_PKT_LOG */
10132
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010133void hdd_free_mac_address_lists(struct hdd_context *hdd_ctx)
10134{
10135 hdd_debug("Resetting MAC address lists");
hangtian127c9532019-01-12 13:29:07 +080010136 qdf_mem_zero(hdd_ctx->provisioned_mac_addr,
10137 sizeof(hdd_ctx->provisioned_mac_addr));
10138 qdf_mem_zero(hdd_ctx->derived_mac_addr,
10139 sizeof(hdd_ctx->derived_mac_addr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010140 hdd_ctx->num_provisioned_addr = 0;
10141 hdd_ctx->num_derived_addr = 0;
10142 hdd_ctx->provisioned_intf_addr_mask = 0;
10143 hdd_ctx->derived_intf_addr_mask = 0;
10144}
10145
Komal Seelam92fff912016-03-24 11:51:41 +053010146/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010147 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
10148 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +053010149 * @dev: Device Pointer
10150 * @num: Number of Valid Mac address
10151 *
10152 * Return: Pointer to MAC address buffer
10153 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010154static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
10155 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +053010156{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010157 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +053010158}
Komal Seelam92fff912016-03-24 11:51:41 +053010159
10160/**
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010161 * hdd_get_platform_wlan_derived_mac_buff() - API to query platform driver
10162 * for derived MAC address
10163 * @dev: Device Pointer
10164 * @num: Number of Valid Mac address
10165 *
10166 * Return: Pointer to MAC address buffer
10167 */
10168static uint8_t *hdd_get_platform_wlan_derived_mac_buff(struct device *dev,
10169 uint32_t *num)
10170{
10171 return pld_get_wlan_derived_mac_address(dev, num);
10172}
10173
10174/**
Komal Seelam92fff912016-03-24 11:51:41 +053010175 * hdd_populate_random_mac_addr() - API to populate random mac addresses
10176 * @hdd_ctx: HDD Context
10177 * @num: Number of random mac addresses needed
10178 *
10179 * Generate random addresses using bit manipulation on the base mac address
10180 *
10181 * Return: None
10182 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010183void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +053010184{
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010185 uint32_t idx = hdd_ctx->num_derived_addr;
Komal Seelam92fff912016-03-24 11:51:41 +053010186 uint32_t iter;
Komal Seelam92fff912016-03-24 11:51:41 +053010187 uint8_t *buf = NULL;
10188 uint8_t macaddr_b3, tmp_br3;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010189 /*
10190 * Consider first provisioned mac address as source address to derive
10191 * remaining addresses
10192 */
Komal Seelam92fff912016-03-24 11:51:41 +053010193
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010194 uint8_t *src = hdd_ctx->provisioned_mac_addr[0].bytes;
10195
10196 for (iter = 0; iter < num; ++iter, ++idx) {
10197 buf = hdd_ctx->derived_mac_addr[idx].bytes;
Komal Seelam92fff912016-03-24 11:51:41 +053010198 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
10199 macaddr_b3 = buf[3];
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010200 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + idx) &
Komal Seelam92fff912016-03-24 11:51:41 +053010201 INTF_MACADDR_MASK;
10202 macaddr_b3 += tmp_br3;
10203 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
10204 buf[0] |= 0x02;
10205 buf[3] = macaddr_b3;
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -070010206 hdd_debug(QDF_MAC_ADDR_STR, QDF_MAC_ADDR_ARRAY(buf));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010207 hdd_ctx->num_derived_addr++;
Komal Seelam92fff912016-03-24 11:51:41 +053010208 }
10209}
10210
10211/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010212 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +053010213 * @hdd_ctx: HDD Context
10214 *
10215 * API to get mac addresses from platform driver and update the driver
10216 * structures and configure FW with the base mac address.
10217 * Return: int
10218 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010219static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +053010220{
10221 uint32_t no_of_mac_addr, iter;
10222 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
10223 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
10224 uint8_t *addr, *buf;
10225 struct device *dev = hdd_ctx->parent_dev;
Komal Seelam92fff912016-03-24 11:51:41 +053010226 tSirMacAddr mac_addr;
10227 QDF_STATUS status;
10228
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010229 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +053010230
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010231 if (no_of_mac_addr == 0 || !addr) {
10232 hdd_debug("No mac configured from platform driver");
Komal Seelam92fff912016-03-24 11:51:41 +053010233 return -EINVAL;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010234 }
10235
10236 hdd_free_mac_address_lists(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +053010237
10238 if (no_of_mac_addr > max_mac_addr)
10239 no_of_mac_addr = max_mac_addr;
10240
10241 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
10242
10243 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010244 buf = hdd_ctx->provisioned_mac_addr[iter].bytes;
Komal Seelam92fff912016-03-24 11:51:41 +053010245 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -070010246 hdd_info("provisioned MAC Addr [%d]" QDF_MAC_ADDR_STR, iter,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -070010247 QDF_MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +053010248 }
10249
Komal Seelam92fff912016-03-24 11:51:41 +053010250
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010251 hdd_ctx->num_provisioned_addr = no_of_mac_addr;
Srinivas Girigowdab841da72017-03-25 18:04:39 -070010252
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010253 if (hdd_ctx->config->mac_provision) {
10254 addr = hdd_get_platform_wlan_derived_mac_buff(dev,
10255 &no_of_mac_addr);
10256
10257 if (no_of_mac_addr == 0 || !addr)
10258 hdd_warn("No derived address from platform driver");
10259 else if (no_of_mac_addr >
10260 (max_mac_addr - hdd_ctx->num_provisioned_addr))
10261 no_of_mac_addr = (max_mac_addr -
10262 hdd_ctx->num_provisioned_addr);
10263
10264 for (iter = 0; iter < no_of_mac_addr; ++iter,
10265 addr += mac_addr_size) {
10266 buf = hdd_ctx->derived_mac_addr[iter].bytes;
10267 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -070010268 hdd_debug("derived MAC Addr [%d]" QDF_MAC_ADDR_STR, iter,
Srinivas Girigowda34fbba02019-04-08 12:07:44 -070010269 QDF_MAC_ADDR_ARRAY(buf));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010270 }
10271 hdd_ctx->num_derived_addr = no_of_mac_addr;
10272 }
10273
10274 no_of_mac_addr = hdd_ctx->num_provisioned_addr +
10275 hdd_ctx->num_derived_addr;
Komal Seelam92fff912016-03-24 11:51:41 +053010276 if (no_of_mac_addr < max_mac_addr)
10277 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
10278 no_of_mac_addr);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010279
10280 status = sme_set_custom_mac_addr(mac_addr);
10281 if (!QDF_IS_STATUS_SUCCESS(status))
10282 return -EAGAIN;
10283
Komal Seelam92fff912016-03-24 11:51:41 +053010284 return 0;
10285}
10286
10287/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010288 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
10289 * @hdd_ctx: HDD Context
10290 *
10291 * Update MAC address to FW. If MAC address passed by FW is invalid, host
10292 * will generate its own MAC and update it to FW.
10293 *
10294 * Return: 0 for success
10295 * Non-zero error code for failure
10296 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010297static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010298{
Jeff Johnson374c0852019-03-10 19:02:07 -070010299 tSirMacAddr custom_mac_addr;
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010300 QDF_STATUS status;
10301
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010302 if (hdd_ctx->num_provisioned_addr)
Jeff Johnson374c0852019-03-10 19:02:07 -070010303 qdf_mem_copy(&custom_mac_addr,
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010304 &hdd_ctx->provisioned_mac_addr[0].bytes[0],
10305 sizeof(tSirMacAddr));
10306 else
Jeff Johnson374c0852019-03-10 19:02:07 -070010307 qdf_mem_copy(&custom_mac_addr,
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010308 &hdd_ctx->derived_mac_addr[0].bytes[0],
10309 sizeof(tSirMacAddr));
Jeff Johnson374c0852019-03-10 19:02:07 -070010310 status = sme_set_custom_mac_addr(custom_mac_addr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010311 if (!QDF_IS_STATUS_SUCCESS(status))
10312 return -EAGAIN;
10313 return 0;
10314}
10315
10316/**
Komal Seelam92fff912016-03-24 11:51:41 +053010317 * hdd_initialize_mac_address() - API to get wlan mac addresses
10318 * @hdd_ctx: HDD Context
10319 *
10320 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
10321 * is provisioned with mac addresses, driver uses it, else it will use
10322 * wlan_mac.bin to update HW MAC addresses.
10323 *
10324 * Return: None
10325 */
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010326static int hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +053010327{
10328 QDF_STATUS status;
10329 int ret;
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010330 bool update_mac_addr_to_fw = true;
Komal Seelam92fff912016-03-24 11:51:41 +053010331
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010332 ret = hdd_platform_wlan_mac(hdd_ctx);
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010333 if (hdd_ctx->config->mac_provision || !ret) {
Dustin Brown7e761c72018-07-31 13:50:17 -070010334 hdd_info("using MAC address from platform driver");
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010335 return ret;
Dustin Brown7e761c72018-07-31 13:50:17 -070010336 }
Komal Seelam92fff912016-03-24 11:51:41 +053010337
10338 status = hdd_update_mac_config(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010339 if (QDF_IS_STATUS_SUCCESS(status)) {
10340 hdd_info("using MAC address from wlan_mac.bin");
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010341 return 0;
Dustin Brown7e761c72018-07-31 13:50:17 -070010342 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010343
Dustin Brown7e761c72018-07-31 13:50:17 -070010344 hdd_info("using default MAC address");
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010345
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010346 /* Use fw provided MAC */
10347 if (!qdf_is_macaddr_zero(&hdd_ctx->hw_macaddr)) {
10348 hdd_update_macaddr(hdd_ctx, hdd_ctx->hw_macaddr, false);
10349 update_mac_addr_to_fw = false;
10350 return 0;
10351 } else if (hdd_generate_macaddr_auto(hdd_ctx) != 0) {
10352 struct qdf_mac_addr mac_addr;
10353
10354 hdd_err("MAC failure from device serial no.");
Jeff Johnson51a80522018-12-11 20:19:44 -080010355 qdf_get_random_bytes(&mac_addr, sizeof(mac_addr));
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010356 /*
10357 * Reset multicast bit (bit-0) and set
10358 * locally-administered bit
10359 */
10360 mac_addr.bytes[0] = 0x2;
10361 hdd_update_macaddr(hdd_ctx, mac_addr, true);
10362 }
10363
10364 if (update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010365 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010366 if (ret)
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -080010367 hdd_err("MAC address out-of-sync, ret:%d", ret);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010368 }
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053010369 return ret;
Komal Seelam92fff912016-03-24 11:51:41 +053010370}
10371
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010372static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010373{
10374 int vdev_id = 0;
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053010375 QDF_STATUS status;
10376 bool smart_chainmask_enabled;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010377 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010378 int vpdev = PDEV_CMD;
10379 int ret;
10380
Sourav Mohapatra0f3b8572018-09-12 10:03:51 +053010381 status = ucfg_get_smart_chainmask_enabled(hdd_ctx->psoc,
10382 &smart_chainmask_enabled);
10383 if (QDF_IS_STATUS_ERROR(status))
10384 return -EINVAL;
10385
10386 ret = sme_cli_set_command(vdev_id, param_id,
10387 (int)smart_chainmask_enabled, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010388 if (ret)
10389 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
10390
10391 return ret;
10392}
10393
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010394static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010395{
10396 int vdev_id = 0;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010397 QDF_STATUS status;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010398 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010399 bool alternative_chainmask_enabled;
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010400 int vpdev = PDEV_CMD;
10401 int ret;
10402
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010403 status = ucfg_get_alternative_chainmask_enabled(
10404 hdd_ctx->psoc,
10405 &alternative_chainmask_enabled);
10406 if (QDF_IS_STATUS_ERROR(status))
10407 return -EINVAL;
10408
10409 ret = sme_cli_set_command(vdev_id, param_id,
10410 (int)alternative_chainmask_enabled, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010411 if (ret)
10412 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
10413 ret);
10414
10415 return ret;
10416}
10417
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010418static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -070010419{
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010420 QDF_STATUS status;
Jeff Johnson12a744b2017-04-04 08:19:37 -070010421 int vdev_id = 0;
10422 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010423 bool value;
Jeff Johnson12a744b2017-04-04 08:19:37 -070010424 int vpdev = PDEV_CMD;
10425 int ret;
10426
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010427 status = ucfg_fwol_get_ani_enabled(hdd_ctx->psoc, &value);
10428 if (QDF_IS_STATUS_ERROR(status))
10429 return -EINVAL;
10430
10431 ret = sme_cli_set_command(vdev_id, param_id, (int)value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -070010432 if (ret)
10433 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
10434
10435 return ret;
10436}
10437
Jeff Johnson89c66ff2016-04-22 15:21:37 -070010438/**
Prashanth Bhatta07998752016-04-28 12:35:33 -070010439 * hdd_pre_enable_configure() - Configurations prior to cds_enable
10440 * @hdd_ctx: HDD context
10441 *
10442 * Pre configurations to be done at lower layer before calling cds enable.
10443 *
10444 * Return: 0 on success and errno on failure.
10445 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010446static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -070010447{
10448 int ret;
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010449 uint8_t val = 0;
Prashanth Bhatta07998752016-04-28 12:35:33 -070010450 QDF_STATUS status;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010451 uint32_t arp_ac_category;
Leo Changfdb45c32016-10-28 11:09:23 -070010452 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010453
Leo Changfdb45c32016-10-28 11:09:23 -070010454 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Ajit Pal Singh5d269612018-04-19 16:29:12 +053010455 /* Register HL netdev flow control callback */
10456 cdp_hl_fc_register(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010457
10458 /*
10459 * Note that the cds_pre_enable() sequence triggers the cfg download.
10460 * The cfg download must occur before we update the SME config
10461 * since the SME config operation must access the cfg database
10462 */
10463 status = hdd_set_sme_config(hdd_ctx);
10464
10465 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010466 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010467 ret = qdf_status_to_os_return(status);
10468 goto out;
10469 }
10470
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -070010471 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
10472 if (QDF_STATUS_SUCCESS != status) {
10473 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
10474 ret = qdf_status_to_os_return(status);
10475 goto out;
10476 }
10477
Dustin Brown1dbefe62018-09-11 16:32:03 -070010478 status = ucfg_mlme_get_tx_chainmask_1ss(hdd_ctx->psoc, &val);
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053010479 if (QDF_STATUS_SUCCESS != status) {
10480 hdd_err("Get tx_chainmask_1ss from mlme failed");
10481 ret = qdf_status_to_os_return(status);
10482 goto out;
10483 }
10484 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS, val,
Prashanth Bhatta07998752016-04-28 12:35:33 -070010485 PDEV_CMD);
10486 if (0 != ret) {
10487 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
10488 goto out;
10489 }
10490
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010491 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
10492 if (ret)
10493 goto out;
10494
10495 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
10496 if (ret)
10497 goto out;
10498
Jeff Johnson12a744b2017-04-04 08:19:37 -070010499 ret = hdd_set_ani_enabled(hdd_ctx);
10500 if (ret)
10501 goto out;
10502
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010503 status = ucfg_get_arp_ac_category(hdd_ctx->psoc, &arp_ac_category);
10504
10505 if (QDF_IS_STATUS_ERROR(status))
10506 return -EINVAL;
10507
Naveen Rawat247a8682017-06-05 15:00:31 -070010508 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010509 arp_ac_category,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -080010510 PDEV_CMD);
10511 if (0 != ret) {
10512 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053010513 arp_ac_category, ret);
Srinivas Girigowda70e169a2017-03-07 23:55:57 -080010514 goto out;
10515 }
10516
Prashanth Bhatta07998752016-04-28 12:35:33 -070010517 status = hdd_set_sme_chan_list(hdd_ctx);
10518 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010519 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010520 ret = qdf_status_to_os_return(status);
10521 goto out;
10522 }
10523
Krunal Sonidf0f8742016-09-26 14:56:31 -070010524 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010525 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -070010526 ret = -EINVAL;
10527 goto out;
10528 }
Prashanth Bhatta07998752016-04-28 12:35:33 -070010529 hdd_init_channel_avoidance(hdd_ctx);
10530
10531out:
10532 return ret;
10533}
10534
Rachit Kankane026e77a2018-07-31 16:21:09 +053010535#ifdef FEATURE_P2P_LISTEN_OFFLOAD
Prashanth Bhatta07998752016-04-28 12:35:33 -070010536/**
Peng Xu8fdaa492016-06-22 10:20:47 -070010537 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010538 * @context: context registered with sme_register_p2p_lo_event(). HDD
10539 * always registers a hdd context pointer
10540 * @evt:event structure pointer
Peng Xu8fdaa492016-06-22 10:20:47 -070010541 *
10542 * This is the p2p listen offload stop event handler, it sends vendor
10543 * event back to supplicant to notify the stop reason.
10544 *
10545 * Return: None
10546 */
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010547static void wlan_hdd_p2p_lo_event_callback(void *context,
10548 struct sir_p2p_lo_event *evt)
Peng Xu8fdaa492016-06-22 10:20:47 -070010549{
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010550 struct hdd_context *hdd_ctx = context;
Peng Xu8fdaa492016-06-22 10:20:47 -070010551 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -070010552 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -070010553
Dustin Brown491d54b2018-03-14 12:39:11 -070010554 hdd_enter();
Peng Xu8fdaa492016-06-22 10:20:47 -070010555
Jeff Johnsond36fa332019-03-18 13:42:25 -070010556 if (!hdd_ctx) {
Peng Xu8fdaa492016-06-22 10:20:47 -070010557 hdd_err("Invalid HDD context pointer");
10558 return;
10559 }
10560
Peng Xu5c682812017-08-06 07:39:13 -070010561 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
10562 if (!adapter) {
10563 hdd_err("Cannot find adapter by vdev_id = %d",
10564 evt->vdev_id);
10565 return;
10566 }
10567
Peng Xu8fdaa492016-06-22 10:20:47 -070010568 vendor_event =
10569 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -070010570 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -070010571 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
10572 GFP_KERNEL);
10573
10574 if (!vendor_event) {
10575 hdd_err("cfg80211_vendor_event_alloc failed");
10576 return;
10577 }
10578
10579 if (nla_put_u32(vendor_event,
10580 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
10581 evt->reason_code)) {
10582 hdd_err("nla put failed");
10583 kfree_skb(vendor_event);
10584 return;
10585 }
10586
10587 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -070010588 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
10589 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -070010590}
Rachit Kankane026e77a2018-07-31 16:21:09 +053010591#else
10592static void wlan_hdd_p2p_lo_event_callback(void *context,
10593 struct sir_p2p_lo_event *evt)
10594{
10595}
10596#endif
Peng Xu8fdaa492016-06-22 10:20:47 -070010597
Rachit Kankanef6834c42018-08-02 18:47:50 +053010598#ifdef FEATURE_WLAN_DYNAMIC_CVM
10599static inline int hdd_set_vc_mode_config(struct hdd_context *hdd_ctx)
10600{
10601 return sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap);
10602}
10603#else
10604static inline int hdd_set_vc_mode_config(struct hdd_context *hdd_ctx)
10605{
10606 return QDF_STATUS_SUCCESS;
10607}
10608#endif
10609
Peng Xu8fdaa492016-06-22 10:20:47 -070010610/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010611 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
10612 * @hdd_ctx: HDD context
10613 *
10614 * This function sends the adaptive dwell time config configuration to the
10615 * firmware via WMA
10616 *
10617 * Return: 0 - success, < 0 - failure
10618 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010619static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010620{
10621 QDF_STATUS status;
10622 struct adaptive_dwelltime_params dwelltime_params;
10623
Harprit Chhabadad59ae762019-01-08 16:40:43 -080010624 status = ucfg_fwol_get_all_adaptive_dwelltime_params(hdd_ctx->psoc,
10625 &dwelltime_params);
10626 status = ucfg_fwol_set_adaptive_dwelltime_config(&dwelltime_params);
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010627
10628 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
10629 if (!QDF_IS_STATUS_SUCCESS(status)) {
10630 hdd_err("Failed to send Adaptive Dwelltime configuration!");
10631 return -EAGAIN;
10632 }
10633 return 0;
10634}
10635
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010636int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010637{
10638 QDF_STATUS status;
10639 struct wmi_dbs_scan_sel_params dbs_scan_params;
10640 uint32_t i = 0;
10641 uint8_t count = 0, numentries = 0;
Krunal Sonidf29bc42018-11-15 13:26:29 -080010642 uint8_t dual_mac_feature;
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010643 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
10644 * CDS_DBS_SCAN_CLIENTS_MAX];
10645
Krunal Sonidf29bc42018-11-15 13:26:29 -080010646 status = ucfg_policy_mgr_get_dual_mac_feature(hdd_ctx->psoc,
10647 &dual_mac_feature);
10648
10649 if (status != QDF_STATUS_SUCCESS) {
10650 hdd_err("can't get dual mac feature flag");
10651 return -EINVAL;
10652 }
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010653 /* check if DBS is enabled or supported */
Krunal Sonidf29bc42018-11-15 13:26:29 -080010654 if ((dual_mac_feature == DISABLE_DBS_CXN_AND_SCAN) ||
10655 (dual_mac_feature == ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN))
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010656 return -EINVAL;
10657
10658 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
10659 dbs_scan_config, &numentries,
10660 (CDS_DBS_SCAN_PARAM_PER_CLIENT
10661 * CDS_DBS_SCAN_CLIENTS_MAX));
10662
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010663 if (!numentries) {
Dustin Brown6a8d39b2018-08-14 15:27:26 -070010664 hdd_debug("Do not send scan_selection_config");
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010665 return 0;
10666 }
10667
10668 /* hdd_set_fw_log_params */
10669 dbs_scan_params.num_clients = 0;
10670 while (count < (numentries - 2)) {
10671 dbs_scan_params.module_id[i] = dbs_scan_config[count];
10672 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
10673 dbs_scan_params.num_non_dbs_scans[i] =
10674 dbs_scan_config[count + 2];
10675 dbs_scan_params.num_clients++;
10676 hdd_debug("module:%d NDS:%d NNDS:%d",
10677 dbs_scan_params.module_id[i],
10678 dbs_scan_params.num_dbs_scans[i],
10679 dbs_scan_params.num_non_dbs_scans[i]);
10680 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
10681 i++;
10682 }
10683
10684 dbs_scan_params.pdev_id = 0;
10685
10686 hdd_debug("clients:%d pdev:%d",
10687 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
10688
Jeff Johnson16528362018-06-14 12:34:16 -070010689 status = sme_set_dbs_scan_selection_config(hdd_ctx->mac_handle,
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010690 &dbs_scan_params);
10691 hdd_debug("Sending DBS Scan Selection Configuration to fw");
10692 if (!QDF_IS_STATUS_SUCCESS(status)) {
10693 hdd_err("Failed to send DBS Scan selection configuration!");
10694 return -EAGAIN;
10695 }
10696 return 0;
10697}
10698
Arun Khandavallid4349a92016-07-25 11:10:43 +053010699#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10700/**
10701 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
10702 * @hdd_ctx: HDD context
10703 *
10704 * Set auto shutdown callback to get indications from firmware to indicate
10705 * userspace to shutdown WLAN after a configured amount of inactivity.
10706 *
10707 * Return: 0 on success and errno on failure.
10708 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010709static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010710{
10711 QDF_STATUS status;
10712
Dundi Raviteja8e338282018-09-25 17:16:04 +053010713 if (!hdd_ctx->config->wlan_auto_shutdown)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010714 return 0;
10715
Jeff Johnson16528362018-06-14 12:34:16 -070010716 status = sme_set_auto_shutdown_cb(hdd_ctx->mac_handle,
Arun Khandavallid4349a92016-07-25 11:10:43 +053010717 wlan_hdd_auto_shutdown_cb);
10718 if (status != QDF_STATUS_SUCCESS)
10719 hdd_err("Auto shutdown feature could not be enabled: %d",
10720 status);
10721
10722 return qdf_status_to_os_return(status);
10723}
10724#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010725static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010726{
10727 return 0;
10728}
10729#endif
10730
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010731#ifdef MWS_COEX
10732/**
10733 * hdd_set_mws_coex() - Set MWS coex configurations
10734 * @hdd_ctx: HDD context
10735 *
10736 * This function sends MWS-COEX 4G quick FTDM and
10737 * MWS-COEX 5G-NR power limit to FW
10738 *
10739 * Return: 0 on success and errno on failure.
10740 */
10741static int hdd_init_mws_coex(struct hdd_context *hdd_ctx)
10742{
10743 int ret = 0;
lifengdb340e72018-11-20 00:50:20 +080010744 uint32_t mws_coex_4g_quick_tdm = 0, mws_coex_5g_nr_pwr_limit = 0;
10745
10746 ucfg_mlme_get_mws_coex_4g_quick_tdm(hdd_ctx->psoc,
10747 &mws_coex_4g_quick_tdm);
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010748
10749 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_MWSCOEX_4G_ALLOW_QUICK_FTDM,
lifengdb340e72018-11-20 00:50:20 +080010750 mws_coex_4g_quick_tdm,
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010751 PDEV_CMD);
10752 if (ret) {
10753 hdd_warn("Unable to send MWS-COEX 4G quick FTDM policy");
10754 return ret;
10755 }
10756
lifengdb340e72018-11-20 00:50:20 +080010757 ucfg_mlme_get_mws_coex_5g_nr_pwr_limit(hdd_ctx->psoc,
10758 &mws_coex_5g_nr_pwr_limit);
10759
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010760 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_MWSCOEX_SET_5GNR_PWR_LIMIT,
lifengdb340e72018-11-20 00:50:20 +080010761 mws_coex_5g_nr_pwr_limit,
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010762 PDEV_CMD);
10763 if (ret) {
10764 hdd_warn("Unable to send MWS-COEX 4G quick FTDM policy");
10765 return ret;
10766 }
lifengdb340e72018-11-20 00:50:20 +080010767
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010768 return ret;
10769}
10770#else
10771static int hdd_init_mws_coex(struct hdd_context *hdd_ctx)
10772{
10773 return 0;
10774}
10775#endif
10776
Arun Khandavallid4349a92016-07-25 11:10:43 +053010777/**
10778 * hdd_features_init() - Init features
10779 * @hdd_ctx: HDD context
Arun Khandavallid4349a92016-07-25 11:10:43 +053010780 *
10781 * Initialize features and their feature context after WLAN firmware is up.
10782 *
10783 * Return: 0 on success and errno on failure.
10784 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010785static int hdd_features_init(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010786{
Jeff Johnson19ce8d02019-02-08 22:56:23 -080010787 struct tx_power_limit hddtxlimit;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010788 QDF_STATUS status;
10789 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070010790 mac_handle_t mac_handle;
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010791 struct hdd_config *cfg;
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +053010792 bool b_cts2self, is_imps_enabled;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010793
Dustin Brown491d54b2018-03-14 12:39:11 -070010794 hdd_enter();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010795
Dustin Brownad698ae2018-09-05 17:19:30 -070010796 ret = hdd_update_country_code(hdd_ctx);
10797 if (ret) {
10798 hdd_err("Failed to update country code; errno:%d", ret);
10799 return -EINVAL;
10800 }
10801
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010802 ret = hdd_init_mws_coex(hdd_ctx);
10803 if (ret)
10804 hdd_warn("Error initializing mws-coex");
10805
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010806 cfg = hdd_ctx->config;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010807 /* FW capabilities received, Set the Dot11 mode */
Jeff Johnson16528362018-06-14 12:34:16 -070010808 mac_handle = hdd_ctx->mac_handle;
10809 sme_setdef_dot11mode(mac_handle);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010810
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +053010811 ucfg_mlme_is_imps_enabled(hdd_ctx->psoc, &is_imps_enabled);
10812 hdd_set_idle_ps_config(hdd_ctx, is_imps_enabled);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010813
Poddar, Siddarth37033032017-10-11 15:47:40 +053010814 /* Send Enable/Disable data stall detection cmd to FW */
10815 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
jitiphil377bcc12018-10-05 19:46:08 +053010816 cdp_cfg_get(cds_get_context(QDF_MODULE_ID_SOC),
10817 cfg_dp_enable_data_stall), PDEV_CMD);
Poddar, Siddarth37033032017-10-11 15:47:40 +053010818
Dustin Brown1dbefe62018-09-11 16:32:03 -070010819 ucfg_mlme_get_go_cts2self_for_sta(hdd_ctx->psoc, &b_cts2self);
Wu Gao93816212018-08-31 16:49:54 +080010820 if (b_cts2self)
Jeff Johnson16528362018-06-14 12:34:16 -070010821 sme_set_cts2self_for_p2p_go(mac_handle);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010822
Rachit Kankanef6834c42018-08-02 18:47:50 +053010823 if (hdd_set_vc_mode_config(hdd_ctx))
Nachiket Kukade8983cf62017-10-12 18:14:48 +053010824 hdd_warn("Error in setting Voltage Corner mode config to FW");
10825
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010826 if (hdd_rx_ol_init(hdd_ctx))
10827 hdd_err("Unable to initialize Rx LRO/GRO in fw");
Arun Khandavallid4349a92016-07-25 11:10:43 +053010828
10829 if (hdd_adaptive_dwelltime_init(hdd_ctx))
10830 hdd_err("Unable to send adaptive dwelltime setting to FW");
10831
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010832 if (hdd_dbs_scan_selection_init(hdd_ctx))
10833 hdd_err("Unable to send DBS scan selection setting to FW");
10834
Arun Khandavallid4349a92016-07-25 11:10:43 +053010835 ret = hdd_init_thermal_info(hdd_ctx);
10836 if (ret) {
10837 hdd_err("Error while initializing thermal information");
Dustin Browne7e71d32018-05-11 16:00:08 -070010838 return ret;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010839 }
10840
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010841 /**
10842 * In case of SSR/PDR, if pktlog was enabled manually before
Rakshith Suresh Patkar6d955262019-03-13 16:51:50 +053010843 * SSR/PDR, then enable it again automatically after Wlan
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010844 * device up.
Rakshith Suresh Patkar6d955262019-03-13 16:51:50 +053010845 * During SSR/PDR, pktlog will be disabled as part of
10846 * hdd_features_deinit if pktlog is enabled in ini.
10847 * Re-enable pktlog in SSR case, if pktlog is enabled in ini.
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010848 */
Rakshith Suresh Patkar6d955262019-03-13 16:51:50 +053010849 if (cds_is_packet_log_enabled() ||
10850 (cds_is_driver_recovering() && hdd_ctx->is_pktlog_enabled))
Alok Kumar5a75b9d2018-08-31 10:55:43 +053010851 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Poddar, Siddarth66a46592017-02-22 11:44:44 +053010852
gaurank kathpalia3d2e3852018-10-03 22:03:23 +053010853 hddtxlimit.txPower2g = ucfg_get_tx_power(hdd_ctx->psoc, BAND_2G);
10854 hddtxlimit.txPower5g = ucfg_get_tx_power(hdd_ctx->psoc, BAND_5G);
Jeff Johnson16528362018-06-14 12:34:16 -070010855 status = sme_txpower_limit(mac_handle, &hddtxlimit);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010856 if (!QDF_IS_STATUS_SUCCESS(status))
10857 hdd_err("Error setting txlimit in sme: %d", status);
10858
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010859 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010860
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053010861 status = sme_enable_disable_chanavoidind_event(mac_handle, 0);
10862 if (QDF_IS_STATUS_ERROR(status) && (status != QDF_STATUS_E_NOSUPPORT)) {
10863 hdd_err("Failed to disable Chan Avoidance Indication");
Sourav Mohapatra674925f2018-04-16 11:16:58 +053010864 return -EINVAL;
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +053010865 }
Arun Khandavallid4349a92016-07-25 11:10:43 +053010866
10867 /* register P2P Listen Offload event callback */
10868 if (wma_is_p2p_lo_capable())
Jeff Johnson16528362018-06-14 12:34:16 -070010869 sme_register_p2p_lo_event(mac_handle, hdd_ctx,
10870 wlan_hdd_p2p_lo_event_callback);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010871
10872 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
10873
10874 if (ret)
Sourav Mohapatra674925f2018-04-16 11:16:58 +053010875 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010876
Dustin Brown11638b72018-01-25 17:37:25 +053010877 wlan_hdd_init_chan_info(hdd_ctx);
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010878 wlan_hdd_twt_init(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010879
Dustin Browne74003f2018-03-14 12:51:58 -070010880 hdd_exit();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010881 return 0;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010882}
10883
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010884/**
10885 * hdd_features_deinit() - Deinit features
10886 * @hdd_ctx: HDD context
10887 *
10888 * De-Initialize features and their feature context.
10889 *
10890 * Return: none.
10891 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010892static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010893{
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010894 wlan_hdd_twt_deinit(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010895 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010896 wlan_hdd_tsf_deinit(hdd_ctx);
jitiphil4e3bef42018-11-14 14:31:13 +053010897 if (cds_is_packet_log_enabled())
10898 hdd_pktlog_enable_disable(hdd_ctx, false, 0, 0);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010899}
10900
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010901/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010902 * hdd_register_bcn_cb() - register scan beacon callback
10903 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010904 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010905 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010906 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010907static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010908{
10909 QDF_STATUS status;
10910
Dustin Brown1dbefe62018-09-11 16:32:03 -070010911 status = ucfg_scan_register_bcn_cb(hdd_ctx->psoc,
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010912 wlan_cfg80211_inform_bss_frame,
10913 SCAN_CB_TYPE_INFORM_BCN);
10914 if (!QDF_IS_STATUS_SUCCESS(status)) {
Abhishek Singh5ffe9de2019-03-05 15:42:43 +053010915 hdd_err("failed to register SCAN_CB_TYPE_INFORM_BCN with status code %08d [x%08x]",
10916 status, status);
10917 return status;
10918 }
10919
10920 status = ucfg_scan_register_bcn_cb(hdd_ctx->psoc,
10921 wlan_cfg80211_unlink_bss_list,
10922 SCAN_CB_TYPE_UNLINK_BSS);
10923 if (!QDF_IS_STATUS_SUCCESS(status)) {
10924 hdd_err("failed to refister SCAN_CB_TYPE_FLUSH_BSS with status code %08d [x%08x]",
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010925 status, status);
10926 return status;
10927 }
10928
10929 return QDF_STATUS_SUCCESS;
10930}
Arun Khandavallid4349a92016-07-25 11:10:43 +053010931
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010932/**
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070010933 * hdd_v2_flow_pool_map() - Flow pool create callback when vdev is active
10934 * @vdev_id: vdev_id, corresponds to flow_pool
10935 *
10936 * Return: none.
10937 */
10938static void hdd_v2_flow_pool_map(int vdev_id)
10939{
10940 QDF_STATUS status;
10941
10942 status = cdp_flow_pool_map(cds_get_context(QDF_MODULE_ID_SOC),
10943 cds_get_context(QDF_MODULE_ID_TXRX),
10944 vdev_id);
10945 /*
10946 * For Adrastea flow control v2 is based on FW MAP events,
10947 * so this above callback is not implemented.
10948 * Hence this is not actual failure. Dont return failure
10949 */
10950 if ((status != QDF_STATUS_SUCCESS) &&
10951 (status != QDF_STATUS_E_INVAL)) {
10952 hdd_err("vdev_id: %d, failed to create flow pool status %d",
10953 vdev_id, status);
10954 }
10955}
10956
10957/**
10958 * hdd_v2_flow_pool_unmap() - Flow pool create callback when vdev is not active
10959 * @vdev_id: vdev_id, corresponds to flow_pool
10960 *
10961 * Return: none.
10962 */
10963static void hdd_v2_flow_pool_unmap(int vdev_id)
10964{
10965 cdp_flow_pool_unmap(cds_get_context(QDF_MODULE_ID_SOC),
10966 cds_get_context(QDF_MODULE_ID_TXRX), vdev_id);
10967}
10968
10969/**
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010970 * hdd_action_oui_config() - Configure action_oui strings
10971 * @hdd_ctx: pointer to hdd context
10972 *
10973 * This is a HDD wrapper function which invokes ucfg api
10974 * of action_oui component to parse action oui strings.
10975 *
10976 * Return: None
10977 */
10978static void hdd_action_oui_config(struct hdd_context *hdd_ctx)
10979{
10980 QDF_STATUS status;
10981 uint32_t id;
10982 uint8_t *str;
10983
10984 if (!hdd_ctx->config->action_oui_enable)
10985 return;
10986
10987 for (id = 0; id < ACTION_OUI_MAXIMUM_ID; id++) {
10988 str = hdd_ctx->config->action_oui_str[id];
10989 if (!qdf_str_len(str))
10990 continue;
10991
Dustin Brown1dbefe62018-09-11 16:32:03 -070010992 status = ucfg_action_oui_parse(hdd_ctx->psoc, str, id);
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010993 if (!QDF_IS_STATUS_SUCCESS(status))
10994 hdd_err("Failed to parse action_oui str: %u", id);
10995 }
10996}
10997
10998/**
10999 * hdd_action_oui_send() - Send action_oui extensions to firmware
11000 * @hdd_ctx: pointer to hdd context
11001 *
11002 * This is a HDD wrapper function which invokes ucfg api
11003 * of action_oui component to send action oui extensions to firmware.
11004 *
11005 * Return: None
11006 */
11007static void hdd_action_oui_send(struct hdd_context *hdd_ctx)
11008{
11009 QDF_STATUS status;
11010
11011 if (!hdd_ctx->config->action_oui_enable)
11012 return;
11013
Dustin Brown1dbefe62018-09-11 16:32:03 -070011014 status = ucfg_action_oui_send(hdd_ctx->psoc);
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011015 if (!QDF_IS_STATUS_SUCCESS(status))
11016 hdd_err("Failed to send one or all action_ouis");
11017}
11018
Jeff Johnson0187c622019-01-04 06:39:44 -080011019static void hdd_hastings_bt_war_initialize(struct hdd_context *hdd_ctx)
11020{
11021 if (hdd_ctx->config->iface_change_wait_time)
11022 hdd_hastings_bt_war_disable_fw(hdd_ctx);
11023 else
11024 hdd_hastings_bt_war_enable_fw(hdd_ctx);
11025}
11026
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011027/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011028 * hdd_configure_cds() - Configure cds modules
11029 * @hdd_ctx: HDD context
11030 * @adapter: Primary adapter context
11031 *
11032 * Enable Cds modules after WLAN firmware is up.
11033 *
11034 * Return: 0 on success and errno on failure.
11035 */
Dustin Browne7e71d32018-05-11 16:00:08 -070011036int hdd_configure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053011037{
11038 int ret;
11039 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011040 int set_value;
Jeff Johnson16528362018-06-14 12:34:16 -070011041 mac_handle_t mac_handle;
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011042 bool enable_rts_sifsbursting;
11043 uint8_t enable_phy_reg_retention;
Krunal Sonidf29bc42018-11-15 13:26:29 -080011044 uint8_t max_mpdus_inampdu, is_force_1x1 = 0;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011045 uint32_t num_abg_tx_chains = 0;
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053011046 uint16_t num_11b_tx_chains = 0;
11047 uint16_t num_11ag_tx_chains = 0;
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070011048 struct policy_mgr_dp_cbacks dp_cbs = {0};
Bala Venkatesh2fde2c62018-09-11 20:33:24 +053011049 bool value;
Wu Gao66454f12018-09-26 19:55:41 +080011050 enum pmo_auto_pwr_detect_failure_mode auto_power_fail_mode;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053011051 bool bval = false;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011052
Jeff Johnson16528362018-06-14 12:34:16 -070011053 mac_handle = hdd_ctx->mac_handle;
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011054
11055 hdd_action_oui_send(hdd_ctx);
Krunal Sonidf29bc42018-11-15 13:26:29 -080011056 status = ucfg_policy_mgr_get_force_1x1(hdd_ctx->psoc, &is_force_1x1);
11057 if (status != QDF_STATUS_SUCCESS) {
11058 hdd_err("Failed to get force 1x1 value");
11059 goto out;
11060 }
11061 if (is_force_1x1)
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011062 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
11063 1, PDEV_CMD);
11064 /* set chip power save failure detected callback */
Jeff Johnson16528362018-06-14 12:34:16 -070011065 sme_set_chip_pwr_save_fail_cb(mac_handle,
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011066 hdd_chip_pwr_save_fail_detected_cb);
11067
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011068 status = ucfg_get_max_mpdus_inampdu(hdd_ctx->psoc,
11069 &max_mpdus_inampdu);
Krunal Sonidf29bc42018-11-15 13:26:29 -080011070 if (status) {
11071 hdd_err("Failed to get max mpdus in ampdu value");
11072 goto out;
11073 }
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011074
11075 if (max_mpdus_inampdu) {
11076 set_value = max_mpdus_inampdu;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011077 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
11078 set_value, PDEV_CMD);
11079 }
11080
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011081 status = ucfg_get_enable_rts_sifsbursting(hdd_ctx->psoc,
11082 &enable_rts_sifsbursting);
Krunal Sonidf29bc42018-11-15 13:26:29 -080011083 if (status) {
11084 hdd_err("Failed to get rts sifs bursting value");
11085 goto out;
11086 }
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011087
11088 if (enable_rts_sifsbursting) {
11089 set_value = enable_rts_sifsbursting;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011090 sme_cli_set_command(0,
11091 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
11092 set_value, PDEV_CMD);
11093 }
11094
Dustin Brown05d81302018-09-11 16:49:22 -070011095 ucfg_mlme_get_sap_get_peer_info(hdd_ctx->psoc, &value);
Bala Venkatesh2fde2c62018-09-11 20:33:24 +053011096 if (value) {
11097 set_value = value;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011098 sme_cli_set_command(0,
11099 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
11100 set_value, PDEV_CMD);
11101 }
11102
Dustin Brown1dbefe62018-09-11 16:32:03 -070011103 status = ucfg_mlme_get_num_11b_tx_chains(hdd_ctx->psoc,
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053011104 &num_11b_tx_chains);
11105 if (status != QDF_STATUS_SUCCESS) {
11106 hdd_err("Failed to get num_11b_tx_chains");
11107 goto out;
11108 }
11109
Dustin Brown1dbefe62018-09-11 16:32:03 -070011110 status = ucfg_mlme_get_num_11ag_tx_chains(hdd_ctx->psoc,
Pragaspathi Thilagaraj00bd8bc2018-08-18 01:23:01 +053011111 &num_11ag_tx_chains);
11112 if (status != QDF_STATUS_SUCCESS) {
11113 hdd_err("Failed to get num_11ag_tx_chains");
11114 goto out;
11115 }
11116
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053011117 status = ucfg_mlme_get_vht_enable2x2(hdd_ctx->psoc, &bval);
11118 if (!QDF_IS_STATUS_SUCCESS(status))
11119 hdd_err("unable to get vht_enable2x2");
11120
11121 if (!bval) {
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011122 if (num_11b_tx_chains > 1)
11123 num_11b_tx_chains = 1;
11124 if (num_11ag_tx_chains > 1)
11125 num_11ag_tx_chains = 1;
11126 }
11127 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
11128 num_11b_tx_chains);
11129 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
11130 num_11ag_tx_chains);
11131 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
11132 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +053011133
Paul Zhang02526cd2018-09-20 17:47:46 +080011134 if (!ucfg_reg_is_regdb_offloaded(hdd_ctx->psoc))
11135 ucfg_reg_program_default_cc(hdd_ctx->pdev,
11136 hdd_ctx->reg.reg_domain);
11137
Arun Khandavallifae92942016-08-01 13:31:08 +053011138 ret = hdd_pre_enable_configure(hdd_ctx);
11139 if (ret) {
11140 hdd_err("Failed to pre-configure cds");
11141 goto out;
11142 }
11143
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080011144 /* Always get latest IPA resources allocated from cds_open and configure
11145 * IPA module before configuring them to FW. Sequence required as crash
11146 * observed otherwise.
11147 */
Dustin Brown07901ec2018-09-07 11:02:41 -070011148 if (ucfg_ipa_uc_ol_init(hdd_ctx->pdev,
11149 cds_get_context(QDF_MODULE_ID_QDF_DEVICE))) {
Manikandan Mohan2e803a02017-02-14 14:57:53 -080011150 hdd_err("Failed to setup pipes");
11151 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080011152 }
11153
Arun Khandavallifae92942016-08-01 13:31:08 +053011154 /*
11155 * Start CDS which starts up the SME/MAC/HAL modules and everything
11156 * else
11157 */
Dustin Brown1dbefe62018-09-11 16:32:03 -070011158 status = cds_enable(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053011159
11160 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011161 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053011162 goto out;
11163 }
11164
11165 status = hdd_post_cds_enable_config(hdd_ctx);
11166 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011167 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011168 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053011169 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +053011170 status = hdd_register_bcn_cb(hdd_ctx);
11171 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +080011172 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +053011173 goto cds_disable;
11174 }
Arun Khandavallifae92942016-08-01 13:31:08 +053011175
Dustin Browne7e71d32018-05-11 16:00:08 -070011176 ret = hdd_features_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053011177 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011178 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053011179
Mohit Khanna81418772018-10-30 14:14:46 -070011180 /* Donot disable rx offload on concurrency for lithium based targets */
11181 if (!(hdd_ctx->target_type == TARGET_TYPE_QCA6290 ||
11182 hdd_ctx->target_type == TARGET_TYPE_QCA6390))
11183 if (hdd_ctx->ol_enable)
11184 dp_cbs.hdd_disable_rx_ol_in_concurrency =
11185 hdd_disable_rx_ol_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -070011186 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
jiadbb47e132018-03-30 16:28:30 +080011187 dp_cbs.hdd_ipa_set_mcc_mode_cb = hdd_ipa_set_mcc_mode;
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070011188 dp_cbs.hdd_v2_flow_pool_map = hdd_v2_flow_pool_map;
11189 dp_cbs.hdd_v2_flow_pool_unmap = hdd_v2_flow_pool_unmap;
Dustin Brown1dbefe62018-09-11 16:32:03 -070011190 status = policy_mgr_register_dp_cb(hdd_ctx->psoc, &dp_cbs);
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070011191 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -070011192 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070011193 goto cds_disable;
11194 }
Dustin Brown1dbefe62018-09-11 16:32:03 -070011195 status = policy_mgr_register_mode_change_cb(hdd_ctx->psoc,
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053011196 wlan_hdd_send_mode_change_event);
11197 if (!QDF_IS_STATUS_SUCCESS(status)) {
11198 hdd_debug("Failed to register mode change cb with Policy Manager");
11199 goto cds_disable;
11200 }
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070011201
Jeff Johnson8bb61112018-03-31 13:33:54 -070011202 if (hdd_green_ap_enable_egap(hdd_ctx))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +053011203 hdd_debug("enhance green ap is not enabled");
11204
Nachiket Kukadedd302662017-07-13 17:31:44 +053011205 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
11206 hdd_debug("Failed to set wow pulse");
11207
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053011208 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
Manikandan Mohan66df7fc2019-01-08 17:57:05 -080011209 ucfg_fwol_get_gcmp_enable(hdd_ctx->psoc), PDEV_CMD);
Wu Gao66454f12018-09-26 19:55:41 +080011210
11211 auto_power_fail_mode =
11212 ucfg_pmo_get_auto_power_fail_mode(hdd_ctx->psoc);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053011213 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
Wu Gao66454f12018-09-26 19:55:41 +080011214 auto_power_fail_mode, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053011215
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011216 status = ucfg_get_enable_phy_reg_retention(hdd_ctx->psoc,
11217 &enable_phy_reg_retention);
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053011218
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011219 if (QDF_IS_STATUS_ERROR(status))
11220 return -EINVAL;
11221
11222 if (enable_phy_reg_retention)
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053011223 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
Sourav Mohapatrad9387d82018-09-07 12:28:52 +053011224 enable_phy_reg_retention, PDEV_CMD);
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053011225
Jeff Johnson0187c622019-01-04 06:39:44 -080011226 hdd_hastings_bt_war_initialize(hdd_ctx);
11227
Arun Khandavallifae92942016-08-01 13:31:08 +053011228 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011229
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011230cds_disable:
Dustin Brown1dbefe62018-09-11 16:32:03 -070011231 cds_disable(hdd_ctx->psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070011232
Arun Khandavallifae92942016-08-01 13:31:08 +053011233out:
11234 return -EINVAL;
11235}
11236
11237/**
11238 * hdd_deconfigure_cds() -De-Configure cds
11239 * @hdd_ctx: HDD context
11240 *
11241 * Deconfigure Cds modules before WLAN firmware is down.
11242 *
11243 * Return: 0 on success and errno on failure.
11244 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011245static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053011246{
11247 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070011248 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053011249
Dustin Brown491d54b2018-03-14 12:39:11 -070011250 hdd_enter();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080011251
11252 /* De-init features */
11253 hdd_features_deinit(hdd_ctx);
11254
Dustin Brown1dbefe62018-09-11 16:32:03 -070011255 qdf_status = policy_mgr_deregister_mode_change_cb(hdd_ctx->psoc);
Srinivas Girigowdad2412882018-09-07 15:42:04 -070011256 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053011257 hdd_debug("Failed to deregister mode change cb with Policy Manager");
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053011258
Dustin Brown1dbefe62018-09-11 16:32:03 -070011259 qdf_status = cds_disable(hdd_ctx->psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053011260 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11261 hdd_err("Failed to Disable the CDS Modules! :%d",
11262 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070011263 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011264 }
11265
Dustin Brown07901ec2018-09-07 11:02:41 -070011266 if (ucfg_ipa_uc_ol_deinit(hdd_ctx->pdev) != QDF_STATUS_SUCCESS) {
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053011267 hdd_err("Failed to disconnect pipes");
11268 ret = -EINVAL;
11269 }
11270
Dustin Browne74003f2018-03-14 12:51:58 -070011271 hdd_exit();
Houston Hoffman6640cf32016-10-10 16:44:29 -070011272 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053011273}
11274
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070011275#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
11276static void hdd_deregister_policy_manager_callback(
11277 struct wlan_objmgr_psoc *psoc)
11278{
11279 if (QDF_STATUS_SUCCESS !=
11280 policy_mgr_deregister_hdd_cb(psoc)) {
11281 hdd_err("HDD callback deregister with policy manager failed");
11282 }
11283}
11284#else
11285static void hdd_deregister_policy_manager_callback(
11286 struct wlan_objmgr_psoc *psoc)
11287{
11288}
11289#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053011290
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011291int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053011292{
11293 void *hif_ctx;
11294 qdf_device_t qdf_ctx;
11295 QDF_STATUS qdf_status;
Dustin Brown4bc0a622017-12-06 15:56:50 -080011296 bool is_recovery_stop = cds_is_driver_recovering();
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053011297 int ret = 0;
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053011298 int debugfs_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053011299 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053011300
Dustin Brown491d54b2018-03-14 12:39:11 -070011301 hdd_enter();
Arun Khandavallifae92942016-08-01 13:31:08 +053011302 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
11303 if (!qdf_ctx) {
11304 hdd_err("QDF device context NULL");
11305 return -EINVAL;
11306 }
11307
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011308 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053011309
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053011310 debugfs_threads = hdd_return_debugfs_threads_count();
Dustin Brown70111822017-03-30 15:31:40 -070011311
Dustin Brown3fdaaf62019-03-18 14:00:16 -070011312 if (debugfs_threads > 0 || hdd_ctx->is_wiphy_suspended) {
11313 hdd_warn("Debugfs threads %d, wiphy suspend %d",
11314 debugfs_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -070011315
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053011316 if (IS_IDLE_STOP && !ftm_mode) {
Dustin Brown4c663222018-10-23 14:19:36 -070011317 hdd_psoc_idle_timer_start(hdd_ctx);
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011318 cds_set_module_stop_in_progress(false);
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011319
Dustin Brown70111822017-03-30 15:31:40 -070011320 return 0;
11321 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070011322 }
11323
Liangwei Dong857cb842019-04-28 04:55:17 -040011324 hdd_deregister_policy_manager_callback(hdd_ctx->psoc);
11325
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080011326 /* free user wowl patterns */
11327 hdd_free_user_wowl_ptrns();
11328
Arun Khandavallifae92942016-08-01 13:31:08 +053011329 switch (hdd_ctx->driver_status) {
11330 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011331 hdd_debug("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011332 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011333 case DRIVER_MODULES_CLOSED:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011334 hdd_debug("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011335 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011336 case DRIVER_MODULES_ENABLED:
Dustin Brown1a20b082018-08-03 17:27:15 -070011337 hdd_info("Wlan transitioning (CLOSED <- ENABLED)");
11338
Nirav Shah6aeecf92019-02-13 14:05:03 +053011339 if (hdd_get_conparam() == QDF_GLOBAL_FTM_MODE ||
11340 hdd_get_conparam() == QDF_GLOBAL_EPPING_MODE)
Dustin Brown1a20b082018-08-03 17:27:15 -070011341 break;
Dustin Brown550f6d22017-12-14 15:44:01 -080011342
Komal Seelamf2136bb2016-09-28 18:30:44 +053011343 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053011344 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011345 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053011346 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011347 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011348 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011349 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080011350
Arun Khandavallifae92942016-08-01 13:31:08 +053011351 break;
11352 default:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011353 QDF_DEBUG_PANIC("Unknown driver state:%d",
Arun Khandavallifae92942016-08-01 13:31:08 +053011354 hdd_ctx->driver_status);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011355 ret = -EINVAL;
11356 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011357 }
11358
Arunk Khandavalli890f6d92018-10-30 20:18:28 +053011359 hdd_sysfs_destroy_powerstats_interface();
Amar Singhal18081642018-01-26 16:04:13 -080011360 hdd_sysfs_destroy_version_interface();
Arunk Khandavalli890f6d92018-10-30 20:18:28 +053011361 hdd_sysfs_destroy_driver_root_obj();
Dustin Brown550f6d22017-12-14 15:44:01 -080011362 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080011363
Nirav Shah6aeecf92019-02-13 14:05:03 +053011364 if (hdd_get_conparam() != QDF_GLOBAL_EPPING_MODE) {
11365 qdf_status = cds_post_disable();
11366 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11367 hdd_err("Failed to process post CDS disable! :%d",
11368 qdf_status);
11369 ret = -EINVAL;
11370 QDF_ASSERT(0);
11371 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011372
Nirav Shah6aeecf92019-02-13 14:05:03 +053011373 /* De-register the SME callbacks */
11374 hdd_deregister_cb(hdd_ctx);
Sourav Mohapatra674925f2018-04-16 11:16:58 +053011375
Nirav Shah6aeecf92019-02-13 14:05:03 +053011376 hdd_runtime_suspend_context_deinit(hdd_ctx);
psimhadeea0a12017-12-18 14:50:02 -080011377
Nirav Shah6aeecf92019-02-13 14:05:03 +053011378 qdf_status = cds_dp_close(hdd_ctx->psoc);
11379 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11380 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
11381 ret = -EINVAL;
11382 QDF_ASSERT(0);
11383 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011384
Nirav Shah6aeecf92019-02-13 14:05:03 +053011385 qdf_status = cds_close(hdd_ctx->psoc);
11386 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11387 hdd_warn("Failed to stop CDS: %d", qdf_status);
11388 ret = -EINVAL;
11389 QDF_ASSERT(0);
11390 }
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053011391
Nirav Shah6aeecf92019-02-13 14:05:03 +053011392 qdf_status = wbuff_module_deinit();
11393 if (!QDF_IS_STATUS_SUCCESS(qdf_status))
11394 hdd_err("WBUFF de-init unsuccessful; status: %d",
11395 qdf_status);
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053011396
Nirav Shah6aeecf92019-02-13 14:05:03 +053011397 hdd_component_pdev_close(hdd_ctx->pdev);
Rakshith Suresh Patkard9f4e612018-09-12 12:10:38 +053011398
Nirav Shah6aeecf92019-02-13 14:05:03 +053011399 hdd_component_psoc_close(hdd_ctx->psoc);
11400 dispatcher_pdev_close(hdd_ctx->pdev);
11401 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
11402 if (ret) {
11403 hdd_err("Failed to destroy pdev; errno:%d", ret);
11404 QDF_ASSERT(0);
11405 }
Liangwei Dong50a64a72018-01-11 01:17:00 -050011406 }
11407
11408 /*
11409 * Reset total mac phy during module stop such that during
11410 * next module start same psoc is used to populate new service
11411 * ready data
11412 */
Dustin Brown1dbefe62018-09-11 16:32:03 -070011413 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->psoc);
Arunk Khandavallia6305a32018-01-25 11:19:18 +053011414 if (tgt_hdl)
11415 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
11416
Liangwei Dong50a64a72018-01-11 01:17:00 -050011417
Arun Khandavallifae92942016-08-01 13:31:08 +053011418 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
11419 if (!hif_ctx) {
11420 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011421 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011422 }
11423
Arunk Khandavalli4b404332017-09-26 12:46:00 +053011424 if (hdd_ctx->target_hw_name) {
11425 qdf_mem_free(hdd_ctx->target_hw_name);
11426 hdd_ctx->target_hw_name = NULL;
11427 }
11428
Lin Bai7bae1032019-04-30 12:29:36 +080011429 if (hdd_get_conparam() == QDF_GLOBAL_EPPING_MODE) {
Visweswara Tanukuc949ad22019-03-20 13:00:30 +053011430 epping_disable();
11431 epping_close();
11432 }
11433
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053011434 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053011435
11436 ol_cds_free();
11437
Dustin Brownc2a156e2018-10-25 16:56:27 -070011438 if (IS_IDLE_STOP) {
Arun Khandavallifae92942016-08-01 13:31:08 +053011439 ret = pld_power_off(qdf_ctx->dev);
11440 if (ret)
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011441 hdd_err("Failed to power down device; errno:%d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053011442 }
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011443
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011444 /* Free the cache channels of the command SET_DISABLE_CHANNEL_LIST */
11445 wlan_hdd_free_cache_channels(hdd_ctx);
Arunk Khandavalli847969d2017-09-25 15:15:36 +053011446
Sourav Mohapatra9036f652019-04-02 15:02:59 +053011447 /* Free the resources allocated while storing SAR config. These needs
11448 * to be freed only in the case when it is not SSR. As in the case of
11449 * SSR, the values needs to be intact so that it can be restored during
11450 * reinit path.
11451 */
11452 if (!is_recovery_stop)
11453 wlan_hdd_free_sar_config(hdd_ctx);
11454
Jingxiang Ge3de02752019-01-29 15:47:03 +080011455 hdd_sap_destroy_ctx_all(hdd_ctx, is_recovery_stop);
11456
Dustin Brown29533f22018-07-24 13:11:56 -070011457 hdd_check_for_leaks(hdd_ctx, is_recovery_stop);
Dustin Brown26b3d042017-12-21 11:13:27 -080011458 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080011459
Arunk Khandavalli847969d2017-09-25 15:15:36 +053011460 /* Once the firmware sequence is completed reset this flag */
11461 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053011462 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080011463 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053011464
Kai Liueabb1df2018-11-08 14:58:54 +080011465 pld_request_bus_bandwidth(hdd_ctx->parent_dev, PLD_BUS_WIDTH_NONE);
11466
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011467done:
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011468 cds_set_module_stop_in_progress(false);
Dustin Brown4bc0a622017-12-06 15:56:50 -080011469
Dustin Browne74003f2018-03-14 12:51:58 -070011470 hdd_exit();
Arun Khandavallifae92942016-08-01 13:31:08 +053011471
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011472 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053011473}
11474
Wen Gong3f003382018-05-14 14:26:37 +080011475#ifdef WLAN_FEATURE_MEMDUMP_ENABLE
Arun Khandavallifae92942016-08-01 13:31:08 +053011476/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011477 * hdd_state_info_dump() - prints state information of hdd layer
11478 * @buf: buffer pointer
11479 * @size: size of buffer to be filled
11480 *
11481 * This function is used to dump state information of hdd layer
11482 *
11483 * Return: None
11484 */
11485static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
11486{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011487 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070011488 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070011489 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011490 uint16_t len = 0;
11491 char *buf = *buf_ptr;
11492
11493 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11494 if (!hdd_ctx) {
11495 hdd_err("Failed to get hdd context ");
11496 return;
11497 }
11498
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011499 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011500
11501 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070011502 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011503 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080011504 "\n is_scheduler_suspended %d",
11505 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011506
Dustin Brown920397d2017-12-13 16:27:50 -080011507 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011508 if (adapter->dev)
11509 len += scnprintf(buf + len, *size - len,
11510 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080011511 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011512 "\n device_mode: %d", adapter->device_mode);
11513 switch (adapter->device_mode) {
11514 case QDF_STA_MODE:
11515 case QDF_P2P_CLIENT_MODE:
11516 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11517 len += scnprintf(buf + len, *size - len,
Jeff Johnsone7951512019-02-27 10:02:51 -080011518 "\n conn_state: %d",
11519 hdd_sta_ctx->conn_info.conn_state);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011520 break;
11521
11522 default:
11523 break;
11524 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011525 }
11526
11527 *size -= len;
11528 *buf_ptr += len;
11529}
11530
11531/**
11532 * hdd_register_debug_callback() - registration function for hdd layer
11533 * to print hdd state information
11534 *
11535 * Return: None
11536 */
11537static void hdd_register_debug_callback(void)
11538{
11539 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
11540}
Wen Gong3f003382018-05-14 14:26:37 +080011541#else /* WLAN_FEATURE_MEMDUMP_ENABLE */
Wen Gongaa6d55d2018-04-26 16:33:21 +080011542static void hdd_register_debug_callback(void)
11543{
11544}
Wen Gong3f003382018-05-14 14:26:37 +080011545#endif /* WLAN_FEATURE_MEMDUMP_ENABLE */
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011546
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053011547/*
11548 * wlan_init_bug_report_lock() - Initialize bug report lock
11549 *
11550 * This function is used to create bug report lock
11551 *
11552 * Return: None
11553 */
11554static void wlan_init_bug_report_lock(void)
11555{
Jeff Johnson2b6982c2018-05-29 14:56:11 -070011556 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053011557
11558 p_cds_context = cds_get_global_context();
11559 if (!p_cds_context) {
11560 hdd_err("cds context is NULL");
11561 return;
11562 }
11563
11564 qdf_spinlock_create(&p_cds_context->bug_report_lock);
11565}
11566
Nirav Shahd21a2e32018-04-20 16:34:43 +053011567#ifdef CONFIG_DP_TRACE
Mohit Khannaf8f96822017-05-17 17:11:59 -070011568void hdd_dp_trace_init(struct hdd_config *config)
11569{
Mohit Khannaf8f96822017-05-17 17:11:59 -070011570 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
11571 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
11572 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
11573 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
11574 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
11575 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
11576 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080011577 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070011578
Nirav Shahd21a2e32018-04-20 16:34:43 +053011579 if (!config->enable_dp_trace) {
11580 hdd_err("dp trace is disabled from ini");
11581 return;
11582 }
11583
Mohit Khannaf8f96822017-05-17 17:11:59 -070011584 hdd_string_to_u8_array(config->dp_trace_config, config_params,
11585 &num_entries, sizeof(config_params));
11586
11587 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080011588 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080011589 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080011590 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080011591 else if (bw_compute_interval > 1000) {
11592 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
11593 thresh_time_limit = 1;
11594 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070011595 hdd_err("busBandwidthComputeInterval is 0, using defaults");
11596
11597 switch (num_entries) {
11598 case 4:
11599 proto_bitmap = config_params[3];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011600 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011601 case 3:
11602 verbosity = config_params[2];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011603 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011604 case 2:
11605 thresh = config_params[1];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011606 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011607 case 1:
11608 live_mode = config_params[0];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011609 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011610 default:
Dustin Browna7bb6ae2018-08-16 16:51:50 -070011611 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
11612 live_mode, thresh, thresh_time_limit,
11613 verbosity, proto_bitmap);
Mohit Khannaf8f96822017-05-17 17:11:59 -070011614 };
11615
11616 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
11617 verbosity, proto_bitmap);
11618
11619}
Nirav Shahd21a2e32018-04-20 16:34:43 +053011620#endif
11621
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011622#ifdef DISABLE_CHANNEL_LIST
Dustin Brown623e7e32018-09-05 14:27:50 -070011623static QDF_STATUS wlan_hdd_cache_chann_mutex_create(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011624{
11625 return qdf_mutex_create(&hdd_ctx->cache_channel_lock);
11626}
11627#else
Dustin Brown623e7e32018-09-05 14:27:50 -070011628static QDF_STATUS wlan_hdd_cache_chann_mutex_create(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011629{
Dustin Brown623e7e32018-09-05 14:27:50 -070011630 return QDF_STATUS_SUCCESS;
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011631}
11632#endif
11633
Dustin Brown693b5352019-01-17 10:00:31 -080011634static QDF_STATUS hdd_open_adapter_no_trans(struct hdd_context *hdd_ctx,
11635 enum QDF_OPMODE op_mode,
11636 const char *iface_name,
11637 uint8_t *mac_addr_bytes)
11638{
Dustin Brown2c5e0482019-02-05 16:14:43 -080011639 struct osif_vdev_sync *vdev_sync;
Dustin Brown693b5352019-01-17 10:00:31 -080011640 struct hdd_adapter *adapter;
11641 QDF_STATUS status;
11642 int errno;
11643
11644 QDF_BUG(rtnl_is_locked());
Dustin Brown693b5352019-01-17 10:00:31 -080011645
Dustin Brown2c5e0482019-02-05 16:14:43 -080011646 errno = osif_vdev_sync_create(hdd_ctx->parent_dev, &vdev_sync);
Dustin Brown693b5352019-01-17 10:00:31 -080011647 if (errno)
11648 return qdf_status_from_os_return(errno);
11649
11650 adapter = hdd_open_adapter(hdd_ctx, op_mode, iface_name,
11651 mac_addr_bytes, NET_NAME_UNKNOWN, true);
11652 if (!adapter) {
11653 status = QDF_STATUS_E_INVAL;
11654 goto destroy_sync;
11655 }
11656
Dustin Brown2c5e0482019-02-05 16:14:43 -080011657 osif_vdev_sync_register(adapter->dev, vdev_sync);
Dustin Brown693b5352019-01-17 10:00:31 -080011658
11659 return QDF_STATUS_SUCCESS;
11660
11661destroy_sync:
Dustin Brown2c5e0482019-02-05 16:14:43 -080011662 osif_vdev_sync_destroy(vdev_sync);
Dustin Brown693b5352019-01-17 10:00:31 -080011663
11664 return status;
11665}
11666
11667#ifdef WLAN_OPEN_P2P_INTERFACE
11668/**
11669 * hdd_open_p2p_interface - Open P2P interface
11670 * @hdd_ctx: HDD context
11671 *
11672 * Return: QDF_STATUS
11673 */
11674static QDF_STATUS hdd_open_p2p_interface(struct hdd_context *hdd_ctx)
11675{
11676 QDF_STATUS status;
11677 bool p2p_dev_addr_admin;
11678 bool is_p2p_locally_administered = false;
11679
11680 cfg_p2p_get_device_addr_admin(hdd_ctx->psoc, &p2p_dev_addr_admin);
11681
11682 if (p2p_dev_addr_admin) {
11683 if (hdd_ctx->num_provisioned_addr &&
11684 !(hdd_ctx->provisioned_mac_addr[0].bytes[0] & 0x02)) {
11685 hdd_ctx->p2p_device_address =
11686 hdd_ctx->provisioned_mac_addr[0];
11687
11688 /*
11689 * Generate the P2P Device Address. This consists of
11690 * the device's primary MAC address with the locally
11691 * administered bit set.
11692 */
11693
11694 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
11695 is_p2p_locally_administered = true;
11696 } else if (!(hdd_ctx->derived_mac_addr[0].bytes[0] & 0x02)) {
11697 hdd_ctx->p2p_device_address =
11698 hdd_ctx->derived_mac_addr[0];
11699 /*
11700 * Generate the P2P Device Address. This consists of
11701 * the device's primary MAC address with the locally
11702 * administered bit set.
11703 */
11704 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
11705 is_p2p_locally_administered = true;
11706 }
11707 }
11708 if (!is_p2p_locally_administered) {
11709 uint8_t *p2p_dev_addr;
11710
11711 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx,
11712 QDF_P2P_DEVICE_MODE);
11713 if (!p2p_dev_addr) {
11714 hdd_err("Failed to get MAC address for new p2p device");
11715 return QDF_STATUS_E_INVAL;
11716 }
11717
11718 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
11719 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
11720 }
11721
11722 status = hdd_open_adapter_no_trans(hdd_ctx, QDF_P2P_DEVICE_MODE,
11723 "p2p%d",
11724 hdd_ctx->p2p_device_address.bytes);
11725 if (QDF_IS_STATUS_ERROR(status)) {
11726 hdd_err("Failed to open p2p interface");
11727 return QDF_STATUS_E_INVAL;
11728 }
11729
11730 return QDF_STATUS_SUCCESS;
11731}
11732#else
11733static inline QDF_STATUS hdd_open_p2p_interface(struct hdd_context *hdd_ctx)
11734{
11735 return QDF_STATUS_SUCCESS;
11736}
11737#endif
11738
11739static QDF_STATUS hdd_open_ocb_interface(struct hdd_context *hdd_ctx)
11740{
11741 QDF_STATUS status;
11742 uint8_t *mac_addr;
11743
11744 mac_addr = wlan_hdd_get_intf_addr(hdd_ctx, QDF_OCB_MODE);
11745 status = hdd_open_adapter_no_trans(hdd_ctx, QDF_OCB_MODE,
11746 "wlanocb%d", mac_addr);
11747 if (QDF_IS_STATUS_ERROR(status))
11748 hdd_err("Failed to open 802.11p interface");
11749
11750 return status;
11751}
11752
11753static QDF_STATUS hdd_open_concurrent_interface(struct hdd_context *hdd_ctx)
11754{
11755 QDF_STATUS status;
11756 const char *iface_name;
11757 uint8_t *mac_addr;
11758
11759 if (qdf_str_eq(hdd_ctx->config->enable_concurrent_sta, ""))
11760 return QDF_STATUS_SUCCESS;
11761
11762 iface_name = hdd_ctx->config->enable_concurrent_sta;
11763 mac_addr = wlan_hdd_get_intf_addr(hdd_ctx, QDF_STA_MODE);
11764 status = hdd_open_adapter_no_trans(hdd_ctx, QDF_STA_MODE,
11765 iface_name, mac_addr);
11766 if (QDF_IS_STATUS_ERROR(status))
11767 hdd_err("Failed to open concurrent station interface");
11768
11769 return status;
11770}
11771
Dustin Brown61cc3932018-10-18 16:12:13 -070011772static QDF_STATUS
11773hdd_open_adapters_for_mission_mode(struct hdd_context *hdd_ctx)
Dustin Browna2deeb72018-10-18 14:19:27 -070011774{
Dustin Browna2deeb72018-10-18 14:19:27 -070011775 enum dot11p_mode dot11p_mode;
Dustin Brown61cc3932018-10-18 16:12:13 -070011776 QDF_STATUS status;
Dustin Brown693b5352019-01-17 10:00:31 -080011777 uint8_t *mac_addr;
Dustin Browna2deeb72018-10-18 14:19:27 -070011778
11779 ucfg_mlme_get_dot11p_mode(hdd_ctx->psoc, &dot11p_mode);
11780
11781 /* Create only 802.11p interface? */
11782 if (dot11p_mode == CFG_11P_STANDALONE)
Dustin Brown61cc3932018-10-18 16:12:13 -070011783 return hdd_open_ocb_interface(hdd_ctx);
Dustin Browna2deeb72018-10-18 14:19:27 -070011784
Dustin Brown693b5352019-01-17 10:00:31 -080011785 mac_addr = wlan_hdd_get_intf_addr(hdd_ctx, QDF_STA_MODE);
11786 status = hdd_open_adapter_no_trans(hdd_ctx, QDF_STA_MODE,
11787 "wlan%d", mac_addr);
11788 if (QDF_IS_STATUS_ERROR(status))
11789 return status;
Dustin Browna2deeb72018-10-18 14:19:27 -070011790
Dustin Brown61cc3932018-10-18 16:12:13 -070011791 /* opening concurrent STA is best effort, continue on error */
11792 hdd_open_concurrent_interface(hdd_ctx);
Dustin Browna2deeb72018-10-18 14:19:27 -070011793
Dustin Brown61cc3932018-10-18 16:12:13 -070011794 status = hdd_open_p2p_interface(hdd_ctx);
11795 if (status)
Dustin Browna2deeb72018-10-18 14:19:27 -070011796 goto err_close_adapters;
11797
11798 /* Open 802.11p Interface */
11799 if (dot11p_mode == CFG_11P_CONCURRENT) {
Dustin Brown61cc3932018-10-18 16:12:13 -070011800 status = hdd_open_ocb_interface(hdd_ctx);
11801 if (QDF_IS_STATUS_ERROR(status))
Dustin Browna2deeb72018-10-18 14:19:27 -070011802 goto err_close_adapters;
11803 }
11804
Dustin Brown61cc3932018-10-18 16:12:13 -070011805 return QDF_STATUS_SUCCESS;
Dustin Browna2deeb72018-10-18 14:19:27 -070011806
11807err_close_adapters:
11808 hdd_close_all_adapters(hdd_ctx, true);
11809
Dustin Brown61cc3932018-10-18 16:12:13 -070011810 return status;
Dustin Browna2deeb72018-10-18 14:19:27 -070011811}
11812
Dustin Brown61cc3932018-10-18 16:12:13 -070011813static QDF_STATUS hdd_open_adapters_for_ftm_mode(struct hdd_context *hdd_ctx)
Dustin Browna2deeb72018-10-18 14:19:27 -070011814{
Dustin Brown693b5352019-01-17 10:00:31 -080011815 uint8_t *mac_addr = wlan_hdd_get_intf_addr(hdd_ctx, QDF_FTM_MODE);
Dustin Brown61cc3932018-10-18 16:12:13 -070011816
Dustin Brown693b5352019-01-17 10:00:31 -080011817 return hdd_open_adapter_no_trans(hdd_ctx, QDF_FTM_MODE,
11818 "wlan%d", mac_addr);
Dustin Brown61cc3932018-10-18 16:12:13 -070011819}
11820
11821static QDF_STATUS
11822hdd_open_adapters_for_monitor_mode(struct hdd_context *hdd_ctx)
11823{
Dustin Brown693b5352019-01-17 10:00:31 -080011824 uint8_t *mac_addr = wlan_hdd_get_intf_addr(hdd_ctx, QDF_MONITOR_MODE);
Dustin Brown61cc3932018-10-18 16:12:13 -070011825
Dustin Brown693b5352019-01-17 10:00:31 -080011826 return hdd_open_adapter_no_trans(hdd_ctx, QDF_MONITOR_MODE,
11827 "wlan%d", mac_addr);
Dustin Brown61cc3932018-10-18 16:12:13 -070011828}
11829
11830static QDF_STATUS hdd_open_adapters_for_epping_mode(struct hdd_context *hdd_ctx)
11831{
Nirav Shah6aeecf92019-02-13 14:05:03 +053011832 epping_enable_adapter();
Dustin Brown61cc3932018-10-18 16:12:13 -070011833 return QDF_STATUS_SUCCESS;
Dustin Brown61cc3932018-10-18 16:12:13 -070011834}
11835
11836typedef QDF_STATUS (*hdd_open_mode_handler)(struct hdd_context *hdd_ctx);
11837
11838static const hdd_open_mode_handler
11839hdd_open_mode_handlers[QDF_GLOBAL_MAX_MODE] = {
11840 [QDF_GLOBAL_MISSION_MODE] = hdd_open_adapters_for_mission_mode,
11841 [QDF_GLOBAL_FTM_MODE] = hdd_open_adapters_for_ftm_mode,
11842 [QDF_GLOBAL_MONITOR_MODE] = hdd_open_adapters_for_monitor_mode,
11843 [QDF_GLOBAL_EPPING_MODE] = hdd_open_adapters_for_epping_mode,
11844};
11845
Dustin Brown92bd8382018-10-31 15:49:46 -070011846static QDF_STATUS hdd_open_adapters_for_mode(struct hdd_context *hdd_ctx,
11847 enum QDF_GLOBAL_MODE driver_mode)
Dustin Brown61cc3932018-10-18 16:12:13 -070011848{
11849 QDF_STATUS status;
11850
11851 if (driver_mode < 0 ||
11852 driver_mode >= QDF_GLOBAL_MAX_MODE ||
11853 !hdd_open_mode_handlers[driver_mode]) {
11854 hdd_err("Driver mode %d not supported", driver_mode);
11855 return -ENOTSUPP;
11856 }
Dustin Browna2deeb72018-10-18 14:19:27 -070011857
11858 hdd_hold_rtnl_lock();
Dustin Brown61cc3932018-10-18 16:12:13 -070011859 status = hdd_open_mode_handlers[driver_mode](hdd_ctx);
Dustin Browna2deeb72018-10-18 14:19:27 -070011860 hdd_release_rtnl_lock();
11861
Dustin Brown92bd8382018-10-31 15:49:46 -070011862 return status;
Dustin Browna2deeb72018-10-18 14:19:27 -070011863}
11864
Dustin Brown623e7e32018-09-05 14:27:50 -070011865int hdd_wlan_startup(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011866{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011867 QDF_STATUS status;
Dustin Brown623e7e32018-09-05 14:27:50 -070011868 int errno;
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +053011869 bool is_imps_enabled;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011870
Dustin Brown491d54b2018-03-14 12:39:11 -070011871 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011872
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011873 hdd_action_oui_config(hdd_ctx);
11874
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053011875 qdf_nbuf_init_replenish_timer();
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011876
Dustin Brown623e7e32018-09-05 14:27:50 -070011877 status = wlan_hdd_cache_chann_mutex_create(hdd_ctx);
11878 if (QDF_IS_STATUS_ERROR(status))
11879 return qdf_status_to_os_return(status);
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011880
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053011881#ifdef FEATURE_WLAN_CH_AVOID
11882 mutex_init(&hdd_ctx->avoid_freq_lock);
11883#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053011884
Naveen Rawate02f8f52018-04-05 11:58:04 -070011885 osif_request_manager_init();
Dustin Brown021cecd2017-12-11 13:56:43 -080011886 hdd_driver_memdump_init();
Dustin Brown86d196b2018-08-02 11:51:49 -070011887 hdd_bus_bandwidth_init(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -080011888
Arunk Khandavalli5ff0375472019-01-11 17:26:47 +053011889#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
11890 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
11891 QDF_TIMER_TYPE_SW,
11892 hdd_skip_acs_scan_timer_handler,
11893 hdd_ctx);
11894 if (QDF_IS_STATUS_ERROR(status))
11895 hdd_err("Failed to init ACS Skip timer");
11896 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
11897#endif
11898
Dustin Brown623e7e32018-09-05 14:27:50 -070011899 errno = hdd_wlan_start_modules(hdd_ctx, false);
11900 if (errno) {
11901 hdd_err("Failed to start modules; errno:%d", errno);
11902 goto memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011903 }
11904
Nirav Shah6aeecf92019-02-13 14:05:03 +053011905 if (hdd_get_conparam() == QDF_GLOBAL_EPPING_MODE)
11906 return 0;
11907
Yingying Tang80e15f32016-09-27 18:23:01 +080011908 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011909
Dustin Brown623e7e32018-09-05 14:27:50 -070011910 hdd_ctx->mac_handle = cds_get_context(QDF_MODULE_ID_SME);
11911 if (!hdd_ctx->mac_handle) {
Jeff Johnson16528362018-06-14 12:34:16 -070011912 hdd_err("Mac Handle is null");
Dustin Brown623e7e32018-09-05 14:27:50 -070011913 goto stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011914 }
11915
Dustin Brown623e7e32018-09-05 14:27:50 -070011916 errno = hdd_wiphy_init(hdd_ctx);
11917 if (errno) {
11918 hdd_err("Failed to initialize wiphy; errno:%d", errno);
11919 goto stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011920 }
11921
Nirav Shahd21a2e32018-04-20 16:34:43 +053011922 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053011923
Ashish Kumar Dhanotiya7a11e272018-11-28 13:16:55 +053011924 errno = hdd_initialize_mac_address(hdd_ctx);
11925 if (errno) {
11926 hdd_err("MAC initializtion failed: %d", errno);
11927 goto unregister_wiphy;
11928 }
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080011929
Dustin Brown623e7e32018-09-05 14:27:50 -070011930 errno = register_netdevice_notifier(&hdd_netdev_notifier);
11931 if (errno) {
11932 hdd_err("register_netdevice_notifier failed; errno:%d", errno);
11933 goto unregister_wiphy;
Paul Zhangfb02f452017-12-22 11:58:43 +080011934 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053011935
Sandeep Puligilla34618782019-01-04 17:42:42 -080011936 wlan_hdd_update_11n_mode(hdd_ctx);
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080011937
Arunk Khandavalli40943af2017-05-15 19:25:34 +053011938 hdd_lpass_notify_wlan_version(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011939
Dustin Brown623e7e32018-09-05 14:27:50 -070011940 errno = hdd_register_notifiers(hdd_ctx);
11941 if (errno)
Arun Kumar Khandavalli4b6e2182019-04-29 18:32:09 +053011942 goto unregister_netdev;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070011943
Paul Zhangfb02f452017-12-22 11:58:43 +080011944 status = wlansap_global_init();
Dustin Brown92bd8382018-10-31 15:49:46 -070011945 if (QDF_IS_STATUS_ERROR(status))
11946 goto unregister_notifiers;
Paul Zhangfb02f452017-12-22 11:58:43 +080011947
Pragaspathi Thilagaraj784c4922018-12-02 22:47:29 +053011948 ucfg_mlme_is_imps_enabled(hdd_ctx->psoc, &is_imps_enabled);
11949 hdd_set_idle_ps_config(hdd_ctx, is_imps_enabled);
Arun Kumar Khandavallideda5a82019-03-11 15:32:19 +053011950 hdd_debugfs_mws_coex_info_init(hdd_ctx);
Paul Zhang37185672019-05-14 11:20:14 +080011951 wlan_cfg80211_init_interop_issues_ap(hdd_ctx->pdev);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011952
Dustin Brown92bd8382018-10-31 15:49:46 -070011953 hdd_exit();
11954
11955 return 0;
11956
11957unregister_notifiers:
11958 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011959
Dustin Brown623e7e32018-09-05 14:27:50 -070011960unregister_netdev:
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011961 unregister_netdevice_notifier(&hdd_netdev_notifier);
11962
Dustin Brown623e7e32018-09-05 14:27:50 -070011963unregister_wiphy:
Rachit Kankane30807332018-06-27 18:39:36 +053011964 qdf_dp_trace_deinit();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011965 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011966
Dustin Brown623e7e32018-09-05 14:27:50 -070011967stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011968 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053011969
Dustin Brown623e7e32018-09-05 14:27:50 -070011970memdump_deinit:
Dustin Brown86d196b2018-08-02 11:51:49 -070011971 hdd_bus_bandwidth_deinit(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -080011972 hdd_driver_memdump_deinit();
Naveen Rawate02f8f52018-04-05 11:58:04 -070011973 osif_request_manager_deinit();
Dustin Brown623e7e32018-09-05 14:27:50 -070011974 qdf_nbuf_deinit_replenish_timer();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070011975
Nachiket Kukade8003d252017-03-30 15:55:58 +053011976 if (cds_is_fw_down())
11977 hdd_err("Not setting the complete event as fw is down");
11978 else
Dustin Brown623e7e32018-09-05 14:27:50 -070011979 hdd_start_complete(errno);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011980
Dustin Browne74003f2018-03-14 12:51:58 -070011981 hdd_exit();
Dustin Brown92bd8382018-10-31 15:49:46 -070011982
Dustin Brown623e7e32018-09-05 14:27:50 -070011983 return errno;
Dustin Brown92bd8382018-10-31 15:49:46 -070011984}
11985
11986QDF_STATUS hdd_psoc_create_vdevs(struct hdd_context *hdd_ctx)
11987{
11988 enum QDF_GLOBAL_MODE driver_mode = hdd_get_conparam();
11989 QDF_STATUS status;
11990
11991 status = hdd_open_adapters_for_mode(hdd_ctx, driver_mode);
11992 if (QDF_IS_STATUS_ERROR(status)) {
11993 hdd_err("Failed to create vdevs; status:%d", status);
11994 return status;
11995 }
11996
11997 if (hdd_ctx->rps)
11998 hdd_set_rps_cpu_mask(hdd_ctx);
11999
12000 if (driver_mode != QDF_GLOBAL_FTM_MODE)
12001 hdd_psoc_idle_timer_start(hdd_ctx);
12002
12003 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012004}
12005
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012006/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012007 * hdd_wlan_update_target_info() - update target type info
12008 * @hdd_ctx: HDD context
12009 * @context: hif context
12010 *
12011 * Update target info received from firmware in hdd context
12012 * Return:None
12013 */
12014
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012015void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053012016{
12017 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
12018
12019 if (!tgt_info) {
12020 hdd_err("Target info is Null");
12021 return;
12022 }
12023
12024 hdd_ctx->target_type = tgt_info->target_type;
12025}
12026
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053012027void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp, void *context)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012028{
12029 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012030 int status;
12031 struct hdd_adapter *adapter = NULL;
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070012032 struct osif_request *request = NULL;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012033
Dustin Brown491d54b2018-03-14 12:39:11 -070012034 hdd_enter();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012035
12036 if (!rsp) {
12037 hdd_err("data is null");
12038 return;
12039 }
12040
12041 status = wlan_hdd_validate_context(hdd_ctx);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053012042 if (status != 0)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012043 return;
12044
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070012045 request = osif_request_get(context);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053012046 if (!request) {
12047 hdd_err("obselete request");
12048 return;
12049 }
12050
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012051 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
Jeff Johnsond36fa332019-03-18 13:42:25 -070012052 if ((!adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012053 hdd_err("Invalid adapter or adapter has invalid magic");
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070012054 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012055 return;
12056 }
12057
Alok Kumarce2c29a2018-10-12 15:44:02 +053012058 hdd_debug("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
12059 hdd_debug("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
12060 hdd_debug("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
12061 hdd_debug("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
12062 hdd_debug("rsp->out_of_order_arp_rsp_drop_cnt :%x",
12063 rsp->out_of_order_arp_rsp_drop_cnt);
12064 hdd_debug("rsp->dad_detected :%x", rsp->dad_detected);
12065 hdd_debug("rsp->connect_status :%x", rsp->connect_status);
12066 hdd_debug("rsp->ba_session_establishment_status :%x",
12067 rsp->ba_session_establishment_status);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012068
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012069 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012070 adapter->dad |= rsp->dad_detected;
12071 adapter->con_status = rsp->connect_status;
12072
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053012073 /* Flag true indicates connectivity check stats present. */
12074 if (rsp->connect_stats_present) {
Alok Kumarce2c29a2018-10-12 15:44:02 +053012075 hdd_debug("rsp->tcp_ack_recvd :%x", rsp->tcp_ack_recvd);
12076 hdd_debug("rsp->icmpv4_rsp_recvd :%x", rsp->icmpv4_rsp_recvd);
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053012077 adapter->hdd_stats.hdd_tcp_stats.rx_fw_cnt = rsp->tcp_ack_recvd;
12078 adapter->hdd_stats.hdd_icmpv4_stats.rx_fw_cnt =
12079 rsp->icmpv4_rsp_recvd;
12080 }
12081
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070012082 osif_request_complete(request);
12083 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012084
Dustin Browne74003f2018-03-14 12:51:58 -070012085 hdd_exit();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012086}
12087
Visweswara Tanuku633976b2019-01-07 16:13:12 +053012088#ifdef WLAN_FEATURE_MOTION_DETECTION
12089/**
12090 * hdd_md_host_evt_cb - Callback for Motion Detection Event
12091 * @ctx: HDD context
12092 * @event: motion detect event
12093 *
12094 * Callback for Motion Detection Event. Re-enables Motion
12095 * Detection again upon event
12096 *
12097 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and
12098 * QDF_STATUS_E_FAILURE on failure
12099 */
12100QDF_STATUS hdd_md_host_evt_cb(void *ctx, struct sir_md_evt *event)
12101{
12102 struct hdd_adapter *adapter = NULL;
12103 struct hdd_context *hdd_ctx;
12104 QDF_STATUS status;
12105 struct sme_motion_det_en motion_det;
12106
12107 if (!ctx || !event)
12108 return QDF_STATUS_E_INVAL;
12109
12110 hdd_ctx = (struct hdd_context *)ctx;
12111 status = wlan_hdd_validate_context(hdd_ctx);
12112 if (0 != status)
12113 return QDF_STATUS_E_INVAL;
12114
12115 adapter = hdd_get_adapter_by_vdev(hdd_ctx, event->vdev_id);
12116 if (!adapter || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
12117 hdd_err("Invalid adapter or adapter has invalid magic");
12118 return QDF_STATUS_E_INVAL;
12119 }
12120
12121 hdd_debug("Motion Detection CB vdev_id=%u, status=%u",
12122 event->vdev_id, event->status);
12123
12124 if (adapter->motion_detection_mode) {
12125 motion_det.vdev_id = event->vdev_id;
12126 motion_det.enable = 1;
12127 hdd_debug("Motion Detect CB -> Enable Motion Detection again");
12128 sme_motion_det_enable(hdd_ctx->mac_handle, &motion_det);
12129 }
12130
12131 return QDF_STATUS_SUCCESS;
12132}
12133#endif /* WLAN_FEATURE_MOTION_DETECTION */
12134
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053012135/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012136 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012137 * @hdd_ctx: HDD context
12138 *
12139 * Register the HDD callbacks to CDS/SME.
12140 *
12141 * Return: 0 for success or Error code for failure
12142 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012143int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012144{
12145 QDF_STATUS status;
12146 int ret = 0;
Jeff Johnson16528362018-06-14 12:34:16 -070012147 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012148
Dustin Brown491d54b2018-03-14 12:39:11 -070012149 hdd_enter();
Sourav Mohapatra674925f2018-04-16 11:16:58 +053012150 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
12151 hdd_err("in ftm mode, no need to register callbacks");
12152 return ret;
12153 }
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012154
Jeff Johnson16528362018-06-14 12:34:16 -070012155 mac_handle = hdd_ctx->mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012156
Jeff Johnson16528362018-06-14 12:34:16 -070012157 sme_register_oem_data_rsp_callback(mac_handle,
12158 hdd_send_oem_data_rsp_msg);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012159
Jeff Johnson16528362018-06-14 12:34:16 -070012160 sme_register_mgmt_frame_ind_callback(mac_handle,
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053012161 hdd_indicate_mgmt_frame);
Jeff Johnson16528362018-06-14 12:34:16 -070012162 sme_set_tsfcb(mac_handle, hdd_get_tsf_cb, hdd_ctx);
Jeff Johnson16528362018-06-14 12:34:16 -070012163 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012164 wlan_hdd_cfg80211_stats_ext_callback);
12165
Jeff Johnson16528362018-06-14 12:34:16 -070012166 sme_ext_scan_register_callback(mac_handle,
12167 wlan_hdd_cfg80211_extscan_callback);
12168 sme_stats_ext2_register_callback(mac_handle,
lifeng66831662017-05-19 16:01:35 +080012169 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012170
Jeff Johnson16528362018-06-14 12:34:16 -070012171 sme_set_rssi_threshold_breached_cb(mac_handle,
12172 hdd_rssi_threshold_breached);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012173
Jeff Johnson16528362018-06-14 12:34:16 -070012174 sme_set_link_layer_stats_ind_cb(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012175 wlan_hdd_cfg80211_link_layer_stats_callback);
12176
Jeff Johnson16528362018-06-14 12:34:16 -070012177 sme_rso_cmd_status_cb(mac_handle, wlan_hdd_rso_cmd_status_cb);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053012178
Jeff Johnson16528362018-06-14 12:34:16 -070012179 sme_set_link_layer_ext_cb(mac_handle,
Zhang Qianca38fb12016-12-23 11:10:48 +080012180 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
Abhinav Kumar338e57d2019-02-04 17:30:10 +053012181 sme_update_hidden_ssid_status_cb(mac_handle,
12182 hdd_hidden_ssid_enable_roaming);
Zhang Qianca38fb12016-12-23 11:10:48 +080012183
Jeff Johnson16528362018-06-14 12:34:16 -070012184 status = sme_set_lost_link_info_cb(mac_handle,
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053012185 hdd_lost_link_info_cb);
12186 /* print error and not block the startup process */
12187 if (!QDF_IS_STATUS_SUCCESS(status))
12188 hdd_err("set lost link info callback failed");
12189
Poddar, Siddarth34872782017-08-10 14:08:51 +053012190 ret = hdd_register_data_stall_detect_cb();
12191 if (ret) {
12192 hdd_err("Register data stall detect detect callback failed.");
12193 return ret;
12194 }
12195
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012196 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
12197
Jeff Johnson16528362018-06-14 12:34:16 -070012198 sme_register_set_connection_info_cb(mac_handle,
12199 hdd_set_connection_in_progress,
12200 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053012201
Jeff Johnson16528362018-06-14 12:34:16 -070012202 status = sme_congestion_register_callback(mac_handle,
12203 hdd_update_cca_info_cb);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053012204 if (!QDF_IS_STATUS_SUCCESS(status))
12205 hdd_err("set congestion callback failed");
12206
Jeff Johnson16528362018-06-14 12:34:16 -070012207 status = sme_set_bt_activity_info_cb(mac_handle,
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053012208 hdd_bt_activity_cb);
12209 if (!QDF_IS_STATUS_SUCCESS(status))
12210 hdd_err("set bt activity info callback failed");
12211
Jeff Johnson16528362018-06-14 12:34:16 -070012212 status = sme_register_tx_queue_cb(mac_handle,
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080012213 hdd_tx_queue_cb);
12214 if (!QDF_IS_STATUS_SUCCESS(status))
12215 hdd_err("Register tx queue callback failed");
12216
Visweswara Tanuku633976b2019-01-07 16:13:12 +053012217#ifdef WLAN_FEATURE_MOTION_DETECTION
12218 sme_set_md_host_evt_cb(mac_handle, hdd_md_host_evt_cb, (void *)hdd_ctx);
12219#endif /* WLAN_FEATURE_MOTION_DETECTION */
12220
Dustin Browne74003f2018-03-14 12:51:58 -070012221 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012222
12223 return ret;
12224}
12225
12226/**
12227 * hdd_deregister_cb() - De-Register HDD callbacks.
12228 * @hdd_ctx: HDD context
12229 *
12230 * De-Register the HDD callbacks to CDS/SME.
12231 *
12232 * Return: void
12233 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012234void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012235{
12236 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053012237 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070012238 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012239
Dustin Brown491d54b2018-03-14 12:39:11 -070012240 hdd_enter();
Sourav Mohapatra674925f2018-04-16 11:16:58 +053012241 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
12242 hdd_err("in ftm mode, no need to deregister callbacks");
12243 return;
12244 }
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012245
Jeff Johnson16528362018-06-14 12:34:16 -070012246 mac_handle = hdd_ctx->mac_handle;
12247 sme_deregister_tx_queue_cb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012248
Jeff Johnson16528362018-06-14 12:34:16 -070012249 sme_reset_link_layer_stats_ind_cb(mac_handle);
12250 sme_reset_rssi_threshold_breached_cb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012251
Min Liud35ae312019-05-08 15:43:13 +080012252 sme_stats_ext_deregister_callback(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012253
Jeff Johnson16528362018-06-14 12:34:16 -070012254 status = sme_reset_tsfcb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012255 if (!QDF_IS_STATUS_SUCCESS(status))
12256 hdd_err("Failed to de-register tsfcb the callback:%d",
12257 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012258
Poddar, Siddarth34872782017-08-10 14:08:51 +053012259 ret = hdd_deregister_data_stall_detect_cb();
12260 if (ret)
12261 hdd_err("Failed to de-register data stall detect event callback");
12262
Jeff Johnson16528362018-06-14 12:34:16 -070012263 sme_deregister_oem_data_rsp_callback(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012264
Dustin Browne74003f2018-03-14 12:51:58 -070012265 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053012266}
12267
12268/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012269 * hdd_softap_sta_deauth() - handle deauth req from HDD
Jeff Johnson50e37e92019-03-08 11:32:25 -080012270 * @adapter: Pointer to the HDD adapter
12271 * @param: Params to the operation
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012272 *
12273 * This to take counter measure to handle deauth req from HDD
12274 *
12275 * Return: None
12276 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012277QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnson50e37e92019-03-08 11:32:25 -080012278 struct csr_del_sta_params *param)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012279{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012280 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012281
Dustin Brown491d54b2018-03-14 12:39:11 -070012282 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012283
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012284 /* Ignore request to deauth bcmc station */
Jeff Johnson50e37e92019-03-08 11:32:25 -080012285 if (param->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012286 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012287
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012288 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012289 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Jeff Johnson50e37e92019-03-08 11:32:25 -080012290 param);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012291
Dustin Browne74003f2018-03-14 12:51:58 -070012292 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012293 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012294}
12295
12296/**
12297 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
Jeff Johnson50e37e92019-03-08 11:32:25 -080012298 * @adapter: Pointer to the HDD
12299 * @param: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012300 *
12301 * This to take counter measure to handle deauth req from HDD
12302 *
12303 * Return: None
12304 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012305void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnson50e37e92019-03-08 11:32:25 -080012306 struct csr_del_sta_params *param)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012307{
Dustin Brown491d54b2018-03-14 12:39:11 -070012308 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012309
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012310 /* Ignore request to disassoc bcmc station */
Jeff Johnson50e37e92019-03-08 11:32:25 -080012311 if (param->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012312 return;
12313
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012314 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Jeff Johnson50e37e92019-03-08 11:32:25 -080012315 param);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012316}
12317
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012318void wlan_hdd_disable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012319{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012320 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
12321 struct hdd_adapter *adapter = NULL;
12322 struct csr_roam_profile *roam_profile;
12323 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012324
Dustin Brown1dbefe62018-09-11 16:32:03 -070012325 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->psoc)) {
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012326 hdd_debug("No active sta session");
12327 return;
12328 }
12329
12330 hdd_for_each_adapter(hdd_ctx, adapter) {
12331 roam_profile = hdd_roam_profile(adapter);
12332 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12333
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012334 if (cur_adapter->vdev_id != adapter->vdev_id &&
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012335 adapter->device_mode == QDF_STA_MODE &&
12336 hdd_conn_is_connected(sta_ctx)) {
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012337 hdd_debug("%d Disable roaming", adapter->vdev_id);
Jeff Johnson16528362018-06-14 12:34:16 -070012338 sme_stop_roaming(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012339 adapter->vdev_id,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012340 ecsr_driver_disabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012341 }
12342 }
12343}
12344
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012345void wlan_hdd_enable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012346{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012347 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
12348 struct hdd_adapter *adapter = NULL;
12349 struct csr_roam_profile *roam_profile;
12350 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012351
Dustin Brown1dbefe62018-09-11 16:32:03 -070012352 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->psoc)) {
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012353 hdd_debug("No active sta session");
12354 return;
12355 }
12356
12357 hdd_for_each_adapter(hdd_ctx, adapter) {
12358 roam_profile = hdd_roam_profile(adapter);
12359 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
12360
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012361 if (cur_adapter->vdev_id != adapter->vdev_id &&
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012362 adapter->device_mode == QDF_STA_MODE &&
12363 hdd_conn_is_connected(sta_ctx)) {
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012364 hdd_debug("%d Enable roaming", adapter->vdev_id);
Jeff Johnson16528362018-06-14 12:34:16 -070012365 sme_start_roaming(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012366 adapter->vdev_id,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053012367 REASON_DRIVER_ENABLED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012368 }
12369 }
12370}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012371
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053012372/**
12373 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
12374 * @skb: sk buffer pointer
12375 *
12376 * Sends the bcast message to SVC multicast group with generic nl socket
12377 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
12378 *
12379 * Return: None
12380 */
12381static void nl_srv_bcast_svc(struct sk_buff *skb)
12382{
12383#ifdef CNSS_GENL
12384 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
12385#else
12386 nl_srv_bcast(skb);
12387#endif
12388}
12389
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012390void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012391{
12392 struct sk_buff *skb;
12393 struct nlmsghdr *nlh;
12394 tAniMsgHdr *ani_hdr;
12395 void *nl_data = NULL;
12396 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012397 struct radio_index_tlv *radio_info;
12398 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012399
12400 if (in_interrupt() || irqs_disabled() || in_atomic())
12401 flags = GFP_ATOMIC;
12402
12403 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
12404
Jeff Johnsond36fa332019-03-18 13:42:25 -070012405 if (!skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012406 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012407
12408 nlh = (struct nlmsghdr *)skb->data;
12409 nlh->nlmsg_pid = 0; /* from kernel */
12410 nlh->nlmsg_flags = 0;
12411 nlh->nlmsg_seq = 0;
12412 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
12413
12414 ani_hdr = NLMSG_DATA(nlh);
12415 ani_hdr->type = type;
12416
12417 switch (type) {
12418 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053012419 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012420 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012421 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070012422 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012423 ani_hdr->length = 0;
12424 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012425 break;
12426 case WLAN_SVC_WLAN_STATUS_IND:
12427 case WLAN_SVC_WLAN_VERSION_IND:
12428 case WLAN_SVC_DFS_CAC_START_IND:
12429 case WLAN_SVC_DFS_CAC_END_IND:
12430 case WLAN_SVC_DFS_RADAR_DETECT_IND:
12431 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
12432 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080012433 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053012434 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080012435 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012436 ani_hdr->length = len;
12437 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
12438 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
12439 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012440 break;
12441
12442 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070012443 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012444 type);
12445 kfree_skb(skb);
12446 return;
12447 }
12448
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012449 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080012450 * Add radio index at the end of the svc event in TLV format
12451 * to maintain the backward compatibility with userspace
12452 * applications.
12453 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012454
12455 tlv_len = 0;
12456
12457 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
12458 < WLAN_NL_MAX_PAYLOAD) {
12459 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
12460 sizeof(*ani_hdr) + len);
12461 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
12462 radio_info->length = (unsigned short) sizeof(radio_info->radio);
12463 radio_info->radio = radio;
12464 tlv_len = sizeof(*radio_info);
Dustin Browna2868622018-03-20 11:38:14 -070012465 hdd_debug("Added radio index tlv - radio index %d",
12466 radio_info->radio);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012467 }
12468
12469 nlh->nlmsg_len += tlv_len;
12470 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
12471
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053012472 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012473}
12474
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012475#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
12476void wlan_hdd_auto_shutdown_cb(void)
12477{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012478 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012479
12480 if (!hdd_ctx)
12481 return;
12482
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012483 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012484 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
12485 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012486}
12487
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012488void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012489{
Jeff Johnson9d295242017-08-29 14:39:48 -070012490 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012491 bool ap_connected = false, sta_connected = false;
Jeff Johnson16528362018-06-14 12:34:16 -070012492 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012493
Jeff Johnson16528362018-06-14 12:34:16 -070012494 mac_handle = hdd_ctx->mac_handle;
12495 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012496 return;
12497
Dundi Raviteja8e338282018-09-25 17:16:04 +053012498 if (hdd_ctx->config->wlan_auto_shutdown == 0)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012499 return;
12500
12501 if (enable == false) {
Jeff Johnson16528362018-06-14 12:34:16 -070012502 if (sme_set_auto_shutdown_timer(mac_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012503 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012504 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012505 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053012506 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070012507 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012508 return;
12509 }
12510
12511 /* To enable shutdown timer check conncurrency */
Dustin Brown1dbefe62018-09-11 16:32:03 -070012512 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->psoc)) {
Dustin Brown920397d2017-12-13 16:27:50 -080012513 hdd_for_each_adapter(hdd_ctx, adapter) {
12514 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012515 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
Jeff Johnsone7951512019-02-27 10:02:51 -080012516 conn_info.conn_state ==
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012517 eConnectionState_Associated) {
12518 sta_connected = true;
12519 break;
12520 }
12521 }
Dustin Brown920397d2017-12-13 16:27:50 -080012522
12523 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012524 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070012525 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012526 ap_connected = true;
12527 break;
12528 }
12529 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012530 }
12531 }
12532
12533 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012534 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012535 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012536 }
Jeff Johnson68755312017-02-10 11:46:55 -080012537
Jeff Johnson16528362018-06-14 12:34:16 -070012538 if (sme_set_auto_shutdown_timer(mac_handle,
Dundi Raviteja8e338282018-09-25 17:16:04 +053012539 hdd_ctx->config->wlan_auto_shutdown)
Jeff Johnson68755312017-02-10 11:46:55 -080012540 != QDF_STATUS_SUCCESS)
12541 hdd_err("Failed to start wlan auto shutdown timer");
12542 else
Dustin Brown5e89ef82018-03-14 11:50:23 -070012543 hdd_info("Auto Shutdown timer for %d seconds enabled",
Dundi Raviteja8e338282018-09-25 17:16:04 +053012544 hdd_ctx->config->wlan_auto_shutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012545}
12546#endif
12547
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070012548struct hdd_adapter *
12549hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
12550 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012551{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012552 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070012553 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012554
12555 con_sap_adapter = NULL;
12556
Dustin Brown920397d2017-12-13 16:27:50 -080012557 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012558 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
12559 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012560 adapter != this_sap_adapter) {
12561 if (check_start_bss) {
12562 if (test_bit(SOFTAP_BSS_STARTED,
12563 &adapter->event_flags)) {
12564 con_sap_adapter = adapter;
12565 break;
12566 }
12567 } else {
12568 con_sap_adapter = adapter;
12569 break;
12570 }
12571 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012572 }
12573
12574 return con_sap_adapter;
12575}
12576
Tiger Yu8b119e92019-04-09 13:55:07 +080012577#ifdef WLAN_FEATURE_DP_BUS_BANDWIDTH
Jeff Johnson9d295242017-08-29 14:39:48 -070012578static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012579{
Dustin Brown5ec6b552017-03-31 12:11:40 -070012580 return adapter->device_mode == QDF_STA_MODE ||
12581 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012582}
12583
Jeff Johnson9d295242017-08-29 14:39:48 -070012584static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012585{
Dustin Brown5ec6b552017-03-31 12:11:40 -070012586 return adapter->device_mode == QDF_SAP_MODE ||
12587 adapter->device_mode == QDF_P2P_GO_MODE;
12588}
12589
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012590static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012591{
Dustin Brown920397d2017-12-13 16:27:50 -080012592 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070012593
Dustin Brown920397d2017-12-13 16:27:50 -080012594 hdd_for_each_adapter(hdd_ctx, adapter) {
12595 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070012596 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
Jeff Johnsone7951512019-02-27 10:02:51 -080012597 conn_info.conn_state == eConnectionState_Associated) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070012598 return true;
12599 }
12600
Dustin Brown920397d2017-12-13 16:27:50 -080012601 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070012602 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070012603 return true;
12604 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070012605 }
12606
12607 return false;
12608}
12609
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012610static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012611{
Dustin Browna20bad52019-03-05 12:03:30 -080012612 qdf_periodic_work_start(&hdd_ctx->bus_bw_work,
12613 hdd_ctx->config->bus_bw_compute_interval);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012614}
12615
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012616void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012617{
Dustin Brown491d54b2018-03-14 12:39:11 -070012618 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012619
Dustin Brown5ec6b552017-03-31 12:11:40 -070012620 __hdd_bus_bw_compute_timer_start(hdd_ctx);
12621
Dustin Browne74003f2018-03-14 12:51:58 -070012622 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012623}
12624
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012625void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012626{
Dustin Brown491d54b2018-03-14 12:39:11 -070012627 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012628
Dustin Brown5ec6b552017-03-31 12:11:40 -070012629 if (hdd_any_adapter_is_assoc(hdd_ctx))
12630 __hdd_bus_bw_compute_timer_start(hdd_ctx);
12631
Dustin Browne74003f2018-03-14 12:51:58 -070012632 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012633}
12634
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012635static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012636{
Dustin Browna20bad52019-03-05 12:03:30 -080012637 if (!qdf_periodic_work_stop_sync(&hdd_ctx->bus_bw_work))
12638 return;
12639
Dustin Brown07901ec2018-09-07 11:02:41 -070012640 ucfg_ipa_set_perf_level(hdd_ctx->pdev, 0, 0);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012641 hdd_reset_tcp_delack(hdd_ctx);
12642}
12643
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012644void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012645{
Dustin Brown491d54b2018-03-14 12:39:11 -070012646 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012647
Dustin Brown5ec6b552017-03-31 12:11:40 -070012648 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
12649
Dustin Browne74003f2018-03-14 12:51:58 -070012650 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012651}
12652
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012653void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012654{
Dustin Brown491d54b2018-03-14 12:39:11 -070012655 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012656
Dustin Brown5ec6b552017-03-31 12:11:40 -070012657 if (!hdd_any_adapter_is_assoc(hdd_ctx))
12658 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
12659
Dustin Browne74003f2018-03-14 12:51:58 -070012660 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012661}
Tiger Yu8b119e92019-04-09 13:55:07 +080012662#endif /*WLAN_FEATURE_DP_BUS_BANDWIDTH*/
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012663
12664/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012665 * wlan_hdd_stop_sap() - This function stops bss of SAP.
12666 * @ap_adapter: SAP adapter
12667 *
12668 * This function will process the stopping of sap adapter.
12669 *
12670 * Return: None
12671 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012672void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012673{
Jeff Johnson87251032017-08-29 13:31:11 -070012674 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012675 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053012676 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012677 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012678
Jeff Johnsond36fa332019-03-18 13:42:25 -070012679 if (!ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012680 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012681 return;
12682 }
12683
12684 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12685 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012686 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012687 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012688
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012689 mutex_lock(&hdd_ctx->sap_lock);
12690 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080012691 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012692 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012693 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053012694 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012695 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012696 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053012697 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080012698 qdf_stop_bss_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +053012699 SME_CMD_STOP_BSS_TIMEOUT);
Anurag Chouhance0dc992016-02-16 18:18:03 +053012700 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012701 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070012702 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012703 return;
12704 }
12705 }
12706 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -070012707 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012708 ap_adapter->device_mode,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012709 ap_adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012710 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012711 false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012712 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012713 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012714 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012715 }
12716 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012717}
12718
12719/**
12720 * wlan_hdd_start_sap() - this function starts bss of SAP.
12721 * @ap_adapter: SAP adapter
12722 *
12723 * This function will process the starting of sap adapter.
12724 *
12725 * Return: None
12726 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012727void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012728{
Jeff Johnson87251032017-08-29 13:31:11 -070012729 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012730 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053012731 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012732 struct hdd_context *hdd_ctx;
Jeff Johnson8f8ceb92019-03-24 08:16:55 -070012733 struct sap_config *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012734
Jeff Johnsond36fa332019-03-18 13:42:25 -070012735 if (!ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012736 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012737 return;
12738 }
12739
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012740 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070012741 hdd_err("SoftAp role has not been enabled");
12742 return;
12743 }
12744
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012745 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
12746 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12747 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070012748 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012749
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012750 mutex_lock(&hdd_ctx->sap_lock);
12751 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
12752 goto end;
12753
12754 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012755 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012756 goto end;
12757 }
Dustin Brown07901ec2018-09-07 11:02:41 -070012758 wlan_reg_set_channel_params(hdd_ctx->pdev,
Abhinav Kumar6f694482018-09-04 16:07:39 +053012759 hdd_ap_ctx->sap_config.channel, 0,
12760 &hdd_ap_ctx->sap_config.ch_params);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012761
Wei Song2f76f642016-11-18 16:32:53 +080012762 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012763 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070012764 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012765 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012766 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012767 goto end;
12768
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012769 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053012770 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +053012771 SME_CMD_START_BSS_TIMEOUT);
Anurag Chouhance0dc992016-02-16 18:18:03 +053012772 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012773 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012774 goto end;
12775 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070012776 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012777 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012778 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012779 if (hostapd_state->bss_state == BSS_START) {
Dustin Brown1dbefe62018-09-11 16:32:03 -070012780 policy_mgr_incr_active_session(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012781 ap_adapter->device_mode,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080012782 ap_adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012783 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012784 true);
12785 }
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053012786 mutex_unlock(&hdd_ctx->sap_lock);
12787
12788 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012789end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012790 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012791 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070012792 /* SAP context and beacon cleanup will happen during driver unload
12793 * in hdd_stop_adapter
12794 */
12795 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
12796
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012797}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012798
12799/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012800 * hdd_get_fw_version() - Get FW version
12801 * @hdd_ctx: pointer to HDD context.
12802 * @major_spid: FW version - major spid.
12803 * @minor_spid: FW version - minor spid
12804 * @ssid: FW version - ssid
12805 * @crmid: FW version - crmid
12806 *
12807 * This function is called to get the firmware build version stored
12808 * as part of the HDD context
12809 *
12810 * Return: None
12811 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012812void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012813 uint32_t *major_spid, uint32_t *minor_spid,
12814 uint32_t *siid, uint32_t *crmid)
12815{
12816 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
12817 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
12818 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
12819 *crmid = hdd_ctx->target_fw_version & 0x7fff;
12820}
12821
12822#ifdef QCA_CONFIG_SMP
12823/**
12824 * wlan_hdd_get_cpu() - get cpu_index
12825 *
12826 * Return: cpu_index
12827 */
12828int wlan_hdd_get_cpu(void)
12829{
12830 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012831
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012832 put_cpu();
12833 return cpu_index;
12834}
12835#endif
12836
12837/**
12838 * hdd_get_fwpath() - get framework path
12839 *
12840 * This function is used to get the string written by
12841 * userspace to start the wlan driver
12842 *
12843 * Return: string
12844 */
12845const char *hdd_get_fwpath(void)
12846{
12847 return fwpath.string;
12848}
12849
Dustin Brown94ce20f2018-09-04 13:11:38 -070012850static inline int hdd_state_query_cb(void)
12851{
12852 return !!wlan_hdd_validate_context(cds_get_context(QDF_MODULE_ID_HDD));
12853}
12854
Dustin Brown265e82b2019-03-18 11:07:32 -070012855static int __hdd_op_protect_cb(void **out_sync, const char *func)
12856{
12857 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12858
12859 if (!hdd_ctx)
12860 return -EAGAIN;
12861
12862 return __osif_psoc_sync_op_start(hdd_ctx->parent_dev,
12863 (struct osif_psoc_sync **)out_sync,
12864 func);
12865}
12866
12867static void __hdd_op_unprotect_cb(void *sync, const char *func)
12868{
12869 __osif_psoc_sync_op_stop(sync, func);
12870}
12871
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012872/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012873 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012874 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012875 * This function initilizes CDS global context with the help of cds_init. This
12876 * has to be the first function called after probe to get a valid global
12877 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012878 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012879 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012880 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012881int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012882{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012883 QDF_STATUS status;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012884
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012885 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080012886 if (QDF_IS_STATUS_ERROR(status)) {
12887 hdd_err("Failed to allocate CDS context");
Dustin Brownc1d81af2019-03-01 13:43:43 -080012888 return -ENOMEM;
wadesongae4ffd12017-10-24 16:45:54 +080012889 }
Dustin Brownc1d81af2019-03-01 13:43:43 -080012890
Dustin Brown265e82b2019-03-18 11:07:32 -070012891 qdf_op_callbacks_register(__hdd_op_protect_cb, __hdd_op_unprotect_cb);
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053012892
12893 wlan_init_bug_report_lock();
12894
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012895#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12896 wlan_logging_sock_init_svc();
12897#endif
12898
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012899 hdd_trace_init();
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053012900 hdd_register_debug_callback();
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012901 wlan_roam_debug_init();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012902
Dustin Brownfe50cef2018-12-10 10:42:37 -080012903 return 0;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012904}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012905
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012906/**
12907 * hdd_deinit() - Deinitialize Driver
12908 *
12909 * This function frees CDS global context with the help of cds_deinit. This
12910 * has to be the last function call in remove callback to free the global
12911 * context.
12912 */
12913void hdd_deinit(void)
12914{
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012915 wlan_roam_debug_deinit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012916
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012917#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12918 wlan_logging_sock_deinit_svc();
12919#endif
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012920
12921 wlan_destroy_bug_report_lock();
Dustin Brown265e82b2019-03-18 11:07:32 -070012922 qdf_op_callbacks_register(NULL, NULL);
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012923 cds_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012924}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012925
Yue Ma6e7b1a02017-04-03 14:17:46 -070012926#ifdef QCA_WIFI_NAPIER_EMULATION
12927#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
12928#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012929#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070012930#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012931
Sachin Ahujadddd2632017-03-07 19:07:24 +053012932static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
12933 struct file *file)
12934{
12935 return 0;
12936}
12937
12938static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
12939 const char __user *user_buf,
12940 size_t count,
12941 loff_t *f_pos)
12942{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012943 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053012944 static const char wlan_off_str[] = "OFF";
12945 static const char wlan_on_str[] = "ON";
12946 int ret;
12947 unsigned long rc;
12948
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012949 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012950 pr_err("Failed to read buffer\n");
12951 return -EINVAL;
12952 }
12953
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012954 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012955 pr_debug("Wifi turning off from UI\n");
12956 goto exit;
12957 }
12958
Srinivas Girigowdad2412882018-09-07 15:42:04 -070012959 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) == 0)
Sachin Ahuja16904db2017-12-13 19:56:57 +053012960 pr_info("Wifi Turning On from UI\n");
Sachin Ahuja16904db2017-12-13 19:56:57 +053012961
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012962 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012963 pr_err("Invalid value received from framework");
12964 goto exit;
12965 }
12966
12967 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053012968 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053012969 rc = wait_for_completion_timeout(&wlan_start_comp,
12970 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
12971 if (!rc) {
Srinivas Girigowda09625b02018-09-10 15:28:09 -070012972 hdd_alert("Timed-out!!");
Sachin Ahujadddd2632017-03-07 19:07:24 +053012973 ret = -EINVAL;
Sachin Ahujadddd2632017-03-07 19:07:24 +053012974 return ret;
12975 }
12976
12977 hdd_start_complete(0);
12978 }
12979
12980exit:
12981 return count;
12982}
12983
12984
12985const struct file_operations wlan_hdd_state_fops = {
12986 .owner = THIS_MODULE,
12987 .open = wlan_hdd_state_ctrl_param_open,
12988 .write = wlan_hdd_state_ctrl_param_write,
12989};
12990
12991static int wlan_hdd_state_ctrl_param_create(void)
12992{
12993 unsigned int wlan_hdd_state_major = 0;
12994 int ret;
12995 struct device *dev;
12996
12997 device = MKDEV(wlan_hdd_state_major, 0);
12998
12999 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
13000 if (ret) {
13001 pr_err("Failed to register qcwlanstate");
13002 goto dev_alloc_err;
13003 }
13004 wlan_hdd_state_major = MAJOR(device);
13005
13006 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
13007 if (IS_ERR(class)) {
13008 pr_err("wlan_hdd_state class_create error");
13009 goto class_err;
13010 }
13011
13012 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
13013 if (IS_ERR(dev)) {
13014 pr_err("wlan_hdd_statedevice_create error");
13015 goto err_class_destroy;
13016 }
13017
13018 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
13019 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
13020 if (ret) {
13021 pr_err("Failed to add cdev error");
13022 goto cdev_add_err;
13023 }
13024
13025 pr_info("wlan_hdd_state %s major(%d) initialized",
13026 WLAN_MODULE_NAME, wlan_hdd_state_major);
13027
13028 return 0;
13029
13030cdev_add_err:
13031 device_destroy(class, device);
13032err_class_destroy:
13033 class_destroy(class);
13034class_err:
13035 unregister_chrdev_region(device, dev_num);
13036dev_alloc_err:
13037 return -ENODEV;
13038}
13039
13040static void wlan_hdd_state_ctrl_param_destroy(void)
13041{
13042 cdev_del(&wlan_hdd_state_cdev);
13043 device_destroy(class, device);
13044 class_destroy(class);
13045 unregister_chrdev_region(device, dev_num);
13046
13047 pr_info("Device node unregistered");
13048}
13049
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013050/**
Dustin Brownd585cb32018-09-12 17:12:23 -070013051 * hdd_component_init() - Initialize all components
Mukul Sharmad75a6672017-06-22 15:40:53 +053013052 *
Dustin Brownd585cb32018-09-12 17:12:23 -070013053 * Return: QDF_STATUS
Mukul Sharmad75a6672017-06-22 15:40:53 +053013054 */
Dustin Brownd585cb32018-09-12 17:12:23 -070013055static QDF_STATUS hdd_component_init(void)
Mukul Sharmad75a6672017-06-22 15:40:53 +053013056{
Dustin Brownd585cb32018-09-12 17:12:23 -070013057 QDF_STATUS status;
13058
13059 /* initialize converged components */
Arif Hussain49698112018-07-31 00:32:50 -070013060 status = target_if_init(wma_get_psoc_from_scn_handle);
Dustin Brownd585cb32018-09-12 17:12:23 -070013061 if (QDF_IS_STATUS_ERROR(status))
13062 return status;
13063
Abhishek Singhd5cf22d2019-01-08 19:51:09 +053013064 status = ucfg_mlme_global_init();
Arif Hussain49698112018-07-31 00:32:50 -070013065 if (QDF_IS_STATUS_ERROR(status))
13066 goto target_if_deinit;
13067
Abhishek Singhd5cf22d2019-01-08 19:51:09 +053013068 status = dispatcher_init();
13069 if (QDF_IS_STATUS_ERROR(status))
13070 goto mlme_global_deinit;
13071
Dustin Brownd585cb32018-09-12 17:12:23 -070013072 /* initialize non-converged components */
13073 status = ucfg_mlme_init();
13074 if (QDF_IS_STATUS_ERROR(status))
13075 goto dispatcher_deinit;
13076
13077 status = ucfg_fwol_init();
13078 if (QDF_IS_STATUS_ERROR(status))
13079 goto mlme_deinit;
13080
13081 status = disa_init();
13082 if (QDF_IS_STATUS_ERROR(status))
13083 goto fwol_deinit;
13084
13085 status = pmo_init();
13086 if (QDF_IS_STATUS_ERROR(status))
13087 goto disa_deinit;
13088
13089 status = ucfg_ocb_init();
13090 if (QDF_IS_STATUS_ERROR(status))
13091 goto pmo_deinit;
13092
13093 status = ipa_init();
13094 if (QDF_IS_STATUS_ERROR(status))
13095 goto ocb_deinit;
13096
13097 status = ucfg_action_oui_init();
13098 if (QDF_IS_STATUS_ERROR(status))
13099 goto ipa_deinit;
13100
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013101 status = nan_init();
13102 if (QDF_IS_STATUS_ERROR(status))
13103 goto action_oui_deinit;
13104
Wu Gao637d58a2018-12-08 10:37:34 +080013105 status = ucfg_p2p_init();
13106 if (QDF_IS_STATUS_ERROR(status))
13107 goto nan_deinit;
13108
Paul Zhang37185672019-05-14 11:20:14 +080013109 status = ucfg_interop_issues_ap_init();
Wu Gaod6b5e402018-12-03 22:09:24 +080013110 if (QDF_IS_STATUS_ERROR(status))
13111 goto p2p_deinit;
13112
Paul Zhang37185672019-05-14 11:20:14 +080013113 status = policy_mgr_init();
13114 if (QDF_IS_STATUS_ERROR(status))
13115 goto interop_issues_ap_deinit;
13116
Wu Gao5f793402018-12-08 11:04:00 +080013117 status = ucfg_tdls_init();
13118 if (QDF_IS_STATUS_ERROR(status))
13119 goto policy_deinit;
13120
Dustin Brownd585cb32018-09-12 17:12:23 -070013121 return QDF_STATUS_SUCCESS;
13122
Wu Gao5f793402018-12-08 11:04:00 +080013123policy_deinit:
13124 policy_mgr_deinit();
Paul Zhang37185672019-05-14 11:20:14 +080013125interop_issues_ap_deinit:
13126 ucfg_interop_issues_ap_deinit();
Wu Gaod6b5e402018-12-03 22:09:24 +080013127p2p_deinit:
13128 ucfg_p2p_deinit();
Wu Gao637d58a2018-12-08 10:37:34 +080013129nan_deinit:
13130 nan_deinit();
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013131action_oui_deinit:
13132 ucfg_action_oui_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013133ipa_deinit:
13134 ipa_deinit();
13135ocb_deinit:
13136 ucfg_ocb_deinit();
13137pmo_deinit:
13138 pmo_deinit();
13139disa_deinit:
13140 disa_deinit();
13141fwol_deinit:
13142 ucfg_fwol_deinit();
13143mlme_deinit:
13144 ucfg_mlme_deinit();
13145dispatcher_deinit:
13146 dispatcher_deinit();
Abhishek Singhd5cf22d2019-01-08 19:51:09 +053013147mlme_global_deinit:
13148 ucfg_mlme_global_deinit();
Arif Hussain49698112018-07-31 00:32:50 -070013149target_if_deinit:
13150 target_if_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013151
13152 return status;
Mukul Sharmad75a6672017-06-22 15:40:53 +053013153}
13154
13155/**
Dustin Brownd585cb32018-09-12 17:12:23 -070013156 * hdd_component_deinit() - Deinitialize all components
Mukul Sharmad75a6672017-06-22 15:40:53 +053013157 *
13158 * Return: None
13159 */
Dustin Brownd585cb32018-09-12 17:12:23 -070013160static void hdd_component_deinit(void)
Mukul Sharmad75a6672017-06-22 15:40:53 +053013161{
Dustin Brownd585cb32018-09-12 17:12:23 -070013162 /* deinitialize non-converged components */
Wu Gao5f793402018-12-08 11:04:00 +080013163 ucfg_tdls_deinit();
Wu Gaod6b5e402018-12-03 22:09:24 +080013164 policy_mgr_deinit();
Paul Zhang37185672019-05-14 11:20:14 +080013165 ucfg_interop_issues_ap_deinit();
Wu Gao637d58a2018-12-08 10:37:34 +080013166 ucfg_p2p_deinit();
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013167 nan_deinit();
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053013168 ucfg_action_oui_deinit();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053013169 ipa_deinit();
Zhang Qian47e22ce2018-01-04 15:38:38 +080013170 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053013171 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013172 disa_deinit();
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013173 ucfg_fwol_deinit();
Vignesh Viswanathana0921c42018-09-04 19:03:35 +053013174 ucfg_mlme_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013175
13176 /* deinitialize converged components */
13177 dispatcher_deinit();
Abhishek Singhd5cf22d2019-01-08 19:51:09 +053013178 ucfg_mlme_global_deinit();
Arif Hussain49698112018-07-31 00:32:50 -070013179 target_if_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013180}
13181
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053013182QDF_STATUS hdd_component_psoc_open(struct wlan_objmgr_psoc *psoc)
13183{
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013184 QDF_STATUS status;
13185
13186 status = ucfg_mlme_psoc_open(psoc);
13187 if (QDF_IS_STATUS_ERROR(status))
13188 return status;
13189
13190 status = ucfg_fwol_psoc_open(psoc);
13191 if (QDF_IS_STATUS_ERROR(status))
Wu Gao66454f12018-09-26 19:55:41 +080013192 goto err_fwol;
13193
13194 status = ucfg_pmo_psoc_open(psoc);
13195 if (QDF_IS_STATUS_ERROR(status))
13196 goto err_pmo;
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013197
Krunal Sonie9c12f52018-10-04 11:45:42 -070013198 status = ucfg_policy_mgr_psoc_open(psoc);
13199 if (QDF_IS_STATUS_ERROR(status))
13200 goto err_plcy_mgr;
13201
Wu Gao637d58a2018-12-08 10:37:34 +080013202 status = ucfg_p2p_psoc_open(psoc);
13203 if (QDF_IS_STATUS_ERROR(status))
13204 goto err_p2p;
Wu Gao5f793402018-12-08 11:04:00 +080013205
13206 status = ucfg_tdls_psoc_open(psoc);
13207 if (QDF_IS_STATUS_ERROR(status))
13208 goto err_tdls;
13209
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013210 return status;
13211
Wu Gao5f793402018-12-08 11:04:00 +080013212err_tdls:
13213 ucfg_tdls_psoc_close(psoc);
Wu Gao637d58a2018-12-08 10:37:34 +080013214err_p2p:
13215 ucfg_p2p_psoc_close(psoc);
Krunal Sonie9c12f52018-10-04 11:45:42 -070013216err_plcy_mgr:
13217 ucfg_pmo_psoc_close(psoc);
Wu Gao66454f12018-09-26 19:55:41 +080013218err_pmo:
13219 ucfg_fwol_psoc_close(psoc);
13220err_fwol:
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013221 ucfg_mlme_psoc_close(psoc);
Krunal Sonie9c12f52018-10-04 11:45:42 -070013222
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013223 return status;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053013224}
13225
13226void hdd_component_psoc_close(struct wlan_objmgr_psoc *psoc)
13227{
Wu Gao5f793402018-12-08 11:04:00 +080013228 ucfg_tdls_psoc_close(psoc);
Wu Gao637d58a2018-12-08 10:37:34 +080013229 ucfg_p2p_psoc_close(psoc);
Krunal Sonie9c12f52018-10-04 11:45:42 -070013230 ucfg_policy_mgr_psoc_close(psoc);
Wu Gao66454f12018-09-26 19:55:41 +080013231 ucfg_pmo_psoc_close(psoc);
Sourav Mohapatra113685f2018-08-29 14:21:55 +053013232 ucfg_fwol_psoc_close(psoc);
Vignesh Viswanathana0921c42018-09-04 19:03:35 +053013233 ucfg_mlme_psoc_close(psoc);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053013234}
13235
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013236void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
13237{
Zhang Qian47e22ce2018-01-04 15:38:38 +080013238 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013239 disa_psoc_enable(psoc);
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013240 nan_psoc_enable(psoc);
Wu Gao637d58a2018-12-08 10:37:34 +080013241 p2p_psoc_enable(psoc);
Paul Zhang37185672019-05-14 11:20:14 +080013242 ucfg_interop_issues_ap_psoc_enable(psoc);
Wu Gaod6b5e402018-12-03 22:09:24 +080013243 policy_mgr_psoc_enable(psoc);
Wu Gaoa67c3802018-12-27 12:07:52 +080013244 ucfg_tdls_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013245}
13246
13247void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
13248{
Wu Gaoa67c3802018-12-27 12:07:52 +080013249 ucfg_tdls_psoc_disable(psoc);
Wu Gaod6b5e402018-12-03 22:09:24 +080013250 policy_mgr_psoc_disable(psoc);
Paul Zhang37185672019-05-14 11:20:14 +080013251 ucfg_interop_issues_ap_psoc_disable(psoc);
Wu Gao637d58a2018-12-08 10:37:34 +080013252 p2p_psoc_disable(psoc);
Nachiket Kukade63bb63d2018-11-21 14:42:14 +053013253 nan_psoc_disable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053013254 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080013255 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053013256}
13257
Sandeep Puligillab7beb472018-08-13 22:54:20 -070013258QDF_STATUS hdd_component_pdev_open(struct wlan_objmgr_pdev *pdev)
13259{
13260 return ucfg_mlme_pdev_open(pdev);
13261}
13262
13263void hdd_component_pdev_close(struct wlan_objmgr_pdev *pdev)
13264{
13265 ucfg_mlme_pdev_close(pdev);
13266}
13267
Dustin Browna2a39dc2018-09-17 15:29:59 -070013268static QDF_STATUS hdd_qdf_print_init(void)
13269{
13270 QDF_STATUS status;
13271 int qdf_print_idx;
13272
13273 status = qdf_print_setup();
13274 if (QDF_IS_STATUS_ERROR(status)) {
13275 pr_err("Failed qdf_print_setup; status:%u\n", status);
13276 return status;
13277 }
13278
13279 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
13280 if (qdf_print_idx < 0) {
13281 pr_err("Failed to register for qdf_print_ctrl\n");
13282 return QDF_STATUS_E_FAILURE;
13283 }
13284
13285 qdf_set_pidx(qdf_print_idx);
13286
13287 return QDF_STATUS_SUCCESS;
13288}
13289
13290static void hdd_qdf_print_deinit(void)
13291{
13292 int qdf_pidx = qdf_get_pidx();
13293
13294 qdf_set_pidx(-1);
13295 qdf_print_ctrl_cleanup(qdf_pidx);
13296
13297 /* currently, no qdf print 'un-setup'*/
13298}
13299
13300static QDF_STATUS hdd_qdf_init(void)
13301{
13302 QDF_STATUS status;
13303
13304 status = hdd_qdf_print_init();
13305 if (QDF_IS_STATUS_ERROR(status))
13306 goto exit;
13307
13308 status = qdf_debugfs_init();
13309 if (QDF_IS_STATUS_ERROR(status)) {
13310 hdd_err("Failed to init debugfs; status:%u", status);
13311 goto print_deinit;
13312 }
13313
13314 qdf_lock_stats_init();
13315 qdf_mem_init();
Dustin Brownc2796312019-03-13 16:43:36 -070013316 qdf_delayed_work_feature_init();
Dustin Brown4a93bb52019-03-13 11:46:34 -070013317 qdf_periodic_work_feature_init();
Dustin Browna2a39dc2018-09-17 15:29:59 -070013318 qdf_mc_timer_manager_init();
13319 qdf_event_list_init();
13320
Dustin Brownd315c452018-11-27 11:28:48 -080013321 status = qdf_talloc_feature_init();
13322 if (QDF_IS_STATUS_ERROR(status)) {
13323 hdd_err("Failed to init talloc; status:%u", status);
13324 goto event_deinit;
13325 }
13326
Dustin Browna2a39dc2018-09-17 15:29:59 -070013327 status = qdf_cpuhp_init();
13328 if (QDF_IS_STATUS_ERROR(status)) {
13329 hdd_err("Failed to init cpuhp; status:%u", status);
Dustin Brownd315c452018-11-27 11:28:48 -080013330 goto talloc_deinit;
Dustin Browna2a39dc2018-09-17 15:29:59 -070013331 }
13332
13333 status = qdf_trace_spin_lock_init();
13334 if (QDF_IS_STATUS_ERROR(status)) {
13335 hdd_err("Failed to init spinlock; status:%u", status);
13336 goto cpuhp_deinit;
13337 }
13338
13339 qdf_trace_init();
13340 qdf_register_debugcb_init();
13341
13342 return QDF_STATUS_SUCCESS;
13343
13344cpuhp_deinit:
13345 qdf_cpuhp_deinit();
Dustin Brownd315c452018-11-27 11:28:48 -080013346talloc_deinit:
13347 qdf_talloc_feature_deinit();
Dustin Browna2a39dc2018-09-17 15:29:59 -070013348event_deinit:
13349 qdf_event_list_destroy();
13350 qdf_mc_timer_manager_exit();
Dustin Brown4a93bb52019-03-13 11:46:34 -070013351 qdf_periodic_work_feature_deinit();
Dustin Brownc2796312019-03-13 16:43:36 -070013352 qdf_delayed_work_feature_deinit();
Dustin Browna2a39dc2018-09-17 15:29:59 -070013353 qdf_mem_exit();
13354 qdf_lock_stats_deinit();
13355 qdf_debugfs_exit();
13356print_deinit:
13357 hdd_qdf_print_deinit();
13358
13359exit:
13360 return status;
13361}
13362
13363static void hdd_qdf_deinit(void)
13364{
13365 /* currently, no debugcb deinit */
13366
13367 qdf_trace_deinit();
13368
13369 /* currently, no trace spinlock deinit */
13370
13371 qdf_cpuhp_deinit();
Dustin Brownd315c452018-11-27 11:28:48 -080013372 qdf_talloc_feature_deinit();
Dustin Browna2a39dc2018-09-17 15:29:59 -070013373 qdf_event_list_destroy();
13374 qdf_mc_timer_manager_exit();
Dustin Brown4a93bb52019-03-13 11:46:34 -070013375 qdf_periodic_work_feature_deinit();
Dustin Brownc2796312019-03-13 16:43:36 -070013376 qdf_delayed_work_feature_deinit();
Dustin Browna2a39dc2018-09-17 15:29:59 -070013377 qdf_mem_exit();
13378 qdf_lock_stats_deinit();
13379 qdf_debugfs_exit();
13380 hdd_qdf_print_deinit();
13381}
Dustin Brownf0f70562018-09-14 10:29:38 -070013382
Dustin Brown26afe8f2019-03-01 12:37:24 -080013383#ifdef FEATURE_MONITOR_MODE_SUPPORT
13384static bool is_monitor_mode_supported(void)
13385{
13386 return true;
13387}
13388#else
13389static bool is_monitor_mode_supported(void)
13390{
13391 pr_err("Monitor mode not supported!");
13392 return false;
13393}
13394#endif
13395
13396#ifdef WLAN_FEATURE_EPPING
13397static bool is_epping_mode_supported(void)
13398{
13399 return true;
13400}
13401#else
13402static bool is_epping_mode_supported(void)
13403{
13404 pr_err("Epping mode not supported!");
13405 return false;
13406}
13407#endif
13408
13409#ifdef QCA_WIFI_FTM
13410static bool is_ftm_mode_supported(void)
13411{
13412 return true;
13413}
13414#else
13415static bool is_ftm_mode_supported(void)
13416{
13417 pr_err("FTM mode not supported!");
13418 return false;
13419}
13420#endif
13421
13422/**
13423 * is_con_mode_valid() check con mode is valid or not
13424 * @mode: global con mode
13425 *
13426 * Return: TRUE on success FALSE on failure
13427 */
13428static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
13429{
13430 switch (mode) {
13431 case QDF_GLOBAL_MONITOR_MODE:
13432 return is_monitor_mode_supported();
13433 case QDF_GLOBAL_EPPING_MODE:
13434 return is_epping_mode_supported();
13435 case QDF_GLOBAL_FTM_MODE:
13436 return is_ftm_mode_supported();
13437 case QDF_GLOBAL_MISSION_MODE:
13438 return true;
13439 default:
13440 return false;
13441 }
13442}
13443
13444static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
13445 enum QDF_GLOBAL_MODE curr_mode)
13446{
13447 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
13448 return;
13449
13450 switch (curr_mode) {
13451 case QDF_GLOBAL_MONITOR_MODE:
13452 hdd_info("Release wakelock for monitor mode!");
13453 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
13454 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
13455 /* fallthrough */
13456 case QDF_GLOBAL_MISSION_MODE:
13457 case QDF_GLOBAL_FTM_MODE:
13458 hdd_abort_mac_scan_all_adapters(hdd_ctx);
13459 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->pdev, NULL);
13460 hdd_stop_all_adapters(hdd_ctx);
13461 hdd_deinit_all_adapters(hdd_ctx, false);
13462
13463 break;
13464 default:
13465 break;
13466 }
13467}
13468
13469static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
13470 enum QDF_GLOBAL_MODE curr_mode)
13471{
13472 int driver_status;
13473
13474 driver_status = hdd_ctx->driver_status;
13475
13476 switch (curr_mode) {
13477 case QDF_GLOBAL_MISSION_MODE:
13478 case QDF_GLOBAL_MONITOR_MODE:
13479 case QDF_GLOBAL_FTM_MODE:
13480 hdd_close_all_adapters(hdd_ctx, false);
13481 break;
13482 case QDF_GLOBAL_EPPING_MODE:
13483 epping_disable();
13484 epping_close();
13485 break;
13486 default:
13487 return;
13488 }
13489}
13490
13491static int
13492hdd_parse_driver_mode(const char *mode_str, enum QDF_GLOBAL_MODE *out_mode)
13493{
13494 QDF_STATUS status;
13495 uint32_t mode;
13496
13497 *out_mode = QDF_GLOBAL_MAX_MODE;
13498
13499 status = qdf_uint32_parse(mode_str, &mode);
13500 if (QDF_IS_STATUS_ERROR(status))
13501 return qdf_status_to_os_return(status);
13502
13503 if (mode >= QDF_GLOBAL_MAX_MODE)
13504 return -ERANGE;
13505
13506 *out_mode = (enum QDF_GLOBAL_MODE)mode;
13507
13508 return 0;
13509}
13510
13511/**
13512 * __hdd_driver_mode_change() - Handles a driver mode change
13513 * @hdd_ctx: Pointer to the global HDD context
13514 * @next_mode: the driver mode to transition to
13515 *
13516 * This function is invoked when user updates con_mode using sys entry,
13517 * to initialize and bring-up driver in that specific mode.
13518 *
13519 * Return: Errno
13520 */
13521static int __hdd_driver_mode_change(struct hdd_context *hdd_ctx,
13522 enum QDF_GLOBAL_MODE next_mode)
13523{
13524 enum QDF_GLOBAL_MODE curr_mode;
13525 int errno;
13526
13527 hdd_info("Driver mode changing to %d", next_mode);
13528
13529 errno = wlan_hdd_validate_context(hdd_ctx);
13530 if (errno)
13531 return errno;
13532
13533 if (!is_con_mode_valid(next_mode)) {
13534 hdd_err_rl("Requested driver mode is invalid");
13535 return -EINVAL;
13536 }
13537
Dustin Brown26afe8f2019-03-01 12:37:24 -080013538 curr_mode = hdd_get_conparam();
13539 if (curr_mode == next_mode) {
13540 hdd_err_rl("Driver is already in the requested mode");
Dustin Browne0a77272019-03-19 16:28:06 -070013541 return 0;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013542 }
13543
13544 /* ensure adapters are stopped */
13545 hdd_stop_present_mode(hdd_ctx, curr_mode);
13546
13547 errno = hdd_wlan_stop_modules(hdd_ctx, true);
13548 if (errno) {
13549 hdd_err("Stop wlan modules failed");
Dustin Browne0a77272019-03-19 16:28:06 -070013550 return errno;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013551 }
13552
13553 /* Cleanup present mode before switching to new mode */
13554 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
13555
13556 hdd_set_conparam(next_mode);
13557
13558 errno = hdd_wlan_start_modules(hdd_ctx, false);
13559 if (errno) {
13560 hdd_err("Start wlan modules failed: %d", errno);
Dustin Browne0a77272019-03-19 16:28:06 -070013561 return errno;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013562 }
13563
13564 errno = hdd_open_adapters_for_mode(hdd_ctx, next_mode);
13565 if (errno) {
13566 hdd_err("Failed to open adapters");
Dustin Browne0a77272019-03-19 16:28:06 -070013567 return errno;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013568 }
13569
13570 if (next_mode == QDF_GLOBAL_MONITOR_MODE) {
13571 struct hdd_adapter *adapter =
13572 hdd_get_adapter(hdd_ctx, QDF_MONITOR_MODE);
13573
13574 QDF_BUG(adapter);
13575 if (!adapter) {
13576 hdd_err("Failed to get monitor adapter");
Dustin Browne0a77272019-03-19 16:28:06 -070013577 return -EINVAL;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013578 }
13579
13580 errno = hdd_start_adapter(adapter);
13581 if (errno) {
13582 hdd_err("Failed to start monitor adapter");
Dustin Browne0a77272019-03-19 16:28:06 -070013583 return errno;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013584 }
13585
13586 hdd_info("Acquire wakelock for monitor mode");
13587 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
13588 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
13589 }
13590
13591 /* con_mode is a global module parameter */
13592 con_mode = next_mode;
13593 hdd_info("Driver mode successfully changed to %d", next_mode);
13594
Dustin Browne0a77272019-03-19 16:28:06 -070013595 return 0;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013596}
13597
13598static int hdd_driver_mode_change(enum QDF_GLOBAL_MODE mode)
13599{
Dustin Brownc1d81af2019-03-01 13:43:43 -080013600 struct osif_driver_sync *driver_sync;
Dustin Brown26afe8f2019-03-01 12:37:24 -080013601 struct hdd_context *hdd_ctx;
13602 QDF_STATUS status;
13603 int errno;
13604
13605 hdd_enter();
13606
Dustin Brownc1d81af2019-03-01 13:43:43 -080013607 status = osif_driver_sync_trans_start_wait(&driver_sync);
Dustin Brown26afe8f2019-03-01 12:37:24 -080013608 if (QDF_IS_STATUS_ERROR(status)) {
13609 hdd_err("Failed to start 'mode change'; status:%u", status);
13610 errno = qdf_status_to_os_return(status);
13611 goto exit;
13612 }
13613
Dustin Brownc1d81af2019-03-01 13:43:43 -080013614 osif_driver_sync_wait_for_ops(driver_sync);
Dustin Brown26afe8f2019-03-01 12:37:24 -080013615
13616 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13617 errno = wlan_hdd_validate_context(hdd_ctx);
13618 if (errno)
13619 goto trans_stop;
13620
Dustin Brown26afe8f2019-03-01 12:37:24 -080013621 errno = __hdd_driver_mode_change(hdd_ctx, mode);
Dustin Brown26afe8f2019-03-01 12:37:24 -080013622
13623trans_stop:
Dustin Brownc1d81af2019-03-01 13:43:43 -080013624 osif_driver_sync_trans_stop(driver_sync);
Dustin Brown26afe8f2019-03-01 12:37:24 -080013625
13626exit:
13627 hdd_exit();
13628
13629 return errno;
13630}
13631
13632static int hdd_set_con_mode(enum QDF_GLOBAL_MODE mode)
13633{
13634 con_mode = mode;
13635
13636 return 0;
13637}
13638
13639static int (*hdd_set_con_mode_cb)(enum QDF_GLOBAL_MODE mode) = hdd_set_con_mode;
13640
13641static void hdd_driver_mode_change_register(void)
13642{
13643 hdd_set_con_mode_cb = hdd_driver_mode_change;
13644}
13645
13646static void hdd_driver_mode_change_unregister(void)
13647{
13648 hdd_set_con_mode_cb = hdd_set_con_mode;
13649}
13650
13651static int con_mode_handler(const char *kmessage, const struct kernel_param *kp)
13652{
13653 enum QDF_GLOBAL_MODE mode;
13654 int errno;
13655
13656 errno = hdd_parse_driver_mode(kmessage, &mode);
13657 if (errno) {
13658 hdd_err_rl("Failed to parse driver mode '%s'", kmessage);
13659 return errno;
13660 }
13661
13662 return hdd_set_con_mode_cb(mode);
13663}
Dustin Brown95ff00b2019-02-28 13:41:13 -080013664
Dustin Brownf0f70562018-09-14 10:29:38 -070013665/**
13666 * hdd_driver_load() - Perform the driver-level load operation
13667 *
13668 * Note: this is used in both static and DLKM driver builds
13669 *
13670 * Return: Errno
13671 */
13672static int hdd_driver_load(void)
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013673{
Dustin Brownc1d81af2019-03-01 13:43:43 -080013674 struct osif_driver_sync *driver_sync;
Dustin Brownd585cb32018-09-12 17:12:23 -070013675 QDF_STATUS status;
Dustin Brownf0f70562018-09-14 10:29:38 -070013676 int errno;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013677
Dustin Brownc1d81af2019-03-01 13:43:43 -080013678 pr_err("%s: Loading driver v%s\n", WLAN_MODULE_NAME,
Rajeev Kumare555e2d2018-09-17 11:52:37 -070013679 g_wlan_driver_version);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013680
Dustin Browna2a39dc2018-09-17 15:29:59 -070013681 status = hdd_qdf_init();
13682 if (QDF_IS_STATUS_ERROR(status)) {
13683 errno = qdf_status_to_os_return(status);
13684 goto exit;
13685 }
13686
Dustin Brownc1d81af2019-03-01 13:43:43 -080013687 osif_sync_init();
Dustin Brown21a1d462018-07-31 15:13:06 -070013688
Dustin Brownc1d81af2019-03-01 13:43:43 -080013689 status = osif_driver_sync_create_and_trans(&driver_sync);
Dustin Brown21a1d462018-07-31 15:13:06 -070013690 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Brownc1d81af2019-03-01 13:43:43 -080013691 hdd_err("Failed to init driver sync; status:%u", status);
Dustin Brown21a1d462018-07-31 15:13:06 -070013692 errno = qdf_status_to_os_return(status);
Dustin Brownc1d81af2019-03-01 13:43:43 -080013693 goto sync_deinit;
Dustin Brown21a1d462018-07-31 15:13:06 -070013694 }
13695
Dustin Brownf0f70562018-09-14 10:29:38 -070013696 errno = hdd_init();
13697 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013698 hdd_err("Failed to init HDD; errno:%d", errno);
Dustin Brown21a1d462018-07-31 15:13:06 -070013699 goto trans_stop;
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013700 }
13701
Dustin Brownd585cb32018-09-12 17:12:23 -070013702 status = hdd_component_init();
13703 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013704 hdd_err("Failed to init components; status:%u", status);
Dustin Brownf0f70562018-09-14 10:29:38 -070013705 errno = qdf_status_to_os_return(status);
Dustin Brownd585cb32018-09-12 17:12:23 -070013706 goto hdd_deinit;
13707 }
Mukul Sharmad75a6672017-06-22 15:40:53 +053013708
Dustin Brownf0f70562018-09-14 10:29:38 -070013709 status = qdf_wake_lock_create(&wlan_wake_lock, "wlan");
13710 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013711 hdd_err("Failed to create wake lock; status:%u", status);
Dustin Brownf0f70562018-09-14 10:29:38 -070013712 errno = qdf_status_to_os_return(status);
13713 goto comp_deinit;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013714 }
13715
Dustin Brownf0f70562018-09-14 10:29:38 -070013716 hdd_set_conparam(con_mode);
13717
Dustin Brownf0f70562018-09-14 10:29:38 -070013718 errno = wlan_hdd_state_ctrl_param_create();
13719 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013720 hdd_err("Failed to create ctrl param; errno:%d", errno);
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013721 goto wakelock_destroy;
13722 }
13723
Dustin Brown25843ad2018-09-17 14:54:33 -070013724 errno = pld_init();
13725 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013726 hdd_err("Failed to init PLD; errno:%d", errno);
Dustin Brown25843ad2018-09-17 14:54:33 -070013727 goto param_destroy;
13728 }
13729
Dustin Brown95ff00b2019-02-28 13:41:13 -080013730 hdd_driver_mode_change_register();
Dustin Brownc1d81af2019-03-01 13:43:43 -080013731
13732 osif_driver_sync_register(driver_sync);
13733 osif_driver_sync_trans_stop(driver_sync);
Dustin Brown21a1d462018-07-31 15:13:06 -070013734
13735 /* psoc probe can happen in registration; do after 'load' transition */
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013736 errno = wlan_hdd_register_driver();
13737 if (errno) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013738 hdd_err("Failed to register driver; errno:%d", errno);
Dustin Brown25843ad2018-09-17 14:54:33 -070013739 goto pld_deinit;
Sachin Ahuja16904db2017-12-13 19:56:57 +053013740 }
13741
Dustin Browna2a39dc2018-09-17 15:29:59 -070013742 hdd_debug("%s: driver loaded", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013743
13744 return 0;
Dustin Brownd585cb32018-09-12 17:12:23 -070013745
Dustin Brown25843ad2018-09-17 14:54:33 -070013746pld_deinit:
Dustin Brownc1d81af2019-03-01 13:43:43 -080013747 status = osif_driver_sync_trans_start(&driver_sync);
Dustin Brown21a1d462018-07-31 15:13:06 -070013748 QDF_BUG(QDF_IS_STATUS_SUCCESS(status));
13749
Dustin Brownc1d81af2019-03-01 13:43:43 -080013750 osif_driver_sync_unregister();
13751 osif_driver_sync_wait_for_ops(driver_sync);
13752
Dustin Brown95ff00b2019-02-28 13:41:13 -080013753 hdd_driver_mode_change_unregister();
Dustin Brown25843ad2018-09-17 14:54:33 -070013754 pld_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013755
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013756param_destroy:
13757 wlan_hdd_state_ctrl_param_destroy();
Dustin Brownf0f70562018-09-14 10:29:38 -070013758wakelock_destroy:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053013759 qdf_wake_lock_destroy(&wlan_wake_lock);
Dustin Brownf0f70562018-09-14 10:29:38 -070013760comp_deinit:
Dustin Brownd585cb32018-09-12 17:12:23 -070013761 hdd_component_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013762hdd_deinit:
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013763 hdd_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013764trans_stop:
Dustin Brownc1d81af2019-03-01 13:43:43 -080013765 osif_driver_sync_trans_stop(driver_sync);
13766 osif_driver_sync_destroy(driver_sync);
13767sync_deinit:
13768 osif_sync_deinit();
Dustin Browna2a39dc2018-09-17 15:29:59 -070013769 hdd_qdf_deinit();
Dustin Brownd585cb32018-09-12 17:12:23 -070013770
Dustin Brown25843ad2018-09-17 14:54:33 -070013771exit:
Dustin Brownf0f70562018-09-14 10:29:38 -070013772 return errno;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013773}
13774
13775/**
Dustin Brownf0f70562018-09-14 10:29:38 -070013776 * hdd_driver_unload() - Performs the driver-level unload operation
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013777 *
Dustin Brownf0f70562018-09-14 10:29:38 -070013778 * Note: this is used in both static and DLKM driver builds
13779 *
13780 * Return: None
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013781 */
Dustin Brownf0f70562018-09-14 10:29:38 -070013782static void hdd_driver_unload(void)
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013783{
Dustin Brownc1d81af2019-03-01 13:43:43 -080013784 struct osif_driver_sync *driver_sync;
Will Huang36049722018-04-13 11:48:51 +080013785 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Dustin Brown21a1d462018-07-31 15:13:06 -070013786 QDF_STATUS status;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053013787
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080013788 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
13789 QWLAN_VERSIONSTR);
13790
Dustin Brown8c0b5e32019-01-18 13:56:02 -080013791 if (hdd_ctx)
13792 hdd_psoc_idle_timer_stop(hdd_ctx);
13793
13794 /* trigger SoC remove */
13795 wlan_hdd_unregister_driver();
13796
Dustin Brownc1d81af2019-03-01 13:43:43 -080013797 status = osif_driver_sync_trans_start_wait(&driver_sync);
Dustin Brown21a1d462018-07-31 15:13:06 -070013798 QDF_BUG(QDF_IS_STATUS_SUCCESS(status));
13799 if (QDF_IS_STATUS_ERROR(status)) {
13800 hdd_err("Unable to unload wlan; status:%u", status);
Arunk Khandavalli830c9692018-03-22 12:17:40 +053013801 return;
Dustin Brown21a1d462018-07-31 15:13:06 -070013802 }
13803
Dustin Brownc1d81af2019-03-01 13:43:43 -080013804 osif_driver_sync_unregister();
13805 osif_driver_sync_wait_for_ops(driver_sync);
Dustin Brown21a1d462018-07-31 15:13:06 -070013806
Will Huangba035ec2018-07-05 11:13:30 +080013807 cds_set_driver_loaded(false);
13808 cds_set_unload_in_progress(true);
13809
Dustin Brown95ff00b2019-02-28 13:41:13 -080013810 hdd_driver_mode_change_unregister();
Dustin Brown25843ad2018-09-17 14:54:33 -070013811 pld_deinit();
Dustin Brown4b9dbe62018-09-14 15:41:11 -070013812 wlan_hdd_state_ctrl_param_destroy();
Dustin Brownf0f70562018-09-14 10:29:38 -070013813 hdd_set_conparam(0);
Anurag Chouhana37b5b72016-02-21 14:53:42 +053013814 qdf_wake_lock_destroy(&wlan_wake_lock);
Dustin Brownd585cb32018-09-12 17:12:23 -070013815 hdd_component_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013816 hdd_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013817
Dustin Brownc1d81af2019-03-01 13:43:43 -080013818 osif_driver_sync_trans_stop(driver_sync);
13819 osif_driver_sync_destroy(driver_sync);
Dustin Brown623e7e32018-09-05 14:27:50 -070013820
Dustin Brownc1d81af2019-03-01 13:43:43 -080013821 osif_sync_deinit();
Dustin Brown21a1d462018-07-31 15:13:06 -070013822
Dustin Browna2a39dc2018-09-17 15:29:59 -070013823 hdd_qdf_deinit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013824}
13825
Arun Khandavallifae92942016-08-01 13:31:08 +053013826#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013827/**
Arun Khandavallifae92942016-08-01 13:31:08 +053013828 * wlan_boot_cb() - Wlan boot callback
13829 * @kobj: object whose directory we're creating the link in.
13830 * @attr: attribute the user is interacting with
13831 * @buff: the buffer containing the user data
13832 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013833 *
Arun Khandavallifae92942016-08-01 13:31:08 +053013834 * This callback is invoked when the fs is ready to start the
13835 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013836 *
Arun Khandavallifae92942016-08-01 13:31:08 +053013837 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013838 */
Arun Khandavallifae92942016-08-01 13:31:08 +053013839static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013840 struct kobj_attribute *attr,
13841 const char *buf,
13842 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013843{
Arun Khandavallifae92942016-08-01 13:31:08 +053013844
Arun Khandavallifae92942016-08-01 13:31:08 +053013845 if (wlan_loader->loaded_state) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013846 hdd_err("wlan driver already initialized");
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013847 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053013848 }
13849
Dustin Brownf0f70562018-09-14 10:29:38 -070013850 if (hdd_driver_load())
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013851 return -EIO;
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013852
13853 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053013854
13855 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013856}
Arun Khandavallifae92942016-08-01 13:31:08 +053013857
13858/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013859 * hdd_sysfs_cleanup() - cleanup sysfs
13860 *
13861 * Return: None
13862 *
13863 */
13864static void hdd_sysfs_cleanup(void)
13865{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013866 /* remove from group */
13867 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
13868 sysfs_remove_group(wlan_loader->boot_wlan_obj,
13869 wlan_loader->attr_group);
13870
13871 /* unlink the object from parent */
13872 kobject_del(wlan_loader->boot_wlan_obj);
13873
13874 /* free the object */
13875 kobject_put(wlan_loader->boot_wlan_obj);
13876
13877 kfree(wlan_loader->attr_group);
13878 kfree(wlan_loader);
13879
13880 wlan_loader = NULL;
13881}
13882
13883/**
Arun Khandavallifae92942016-08-01 13:31:08 +053013884 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
13885 * ready
13886 *
13887 * This is creates the syfs entry boot_wlan. Which shall be invoked
13888 * when the filesystem is ready.
13889 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013890 * QDF API cannot be used here since this function is called even before
13891 * initializing WLAN driver.
13892 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070013893 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053013894 */
13895static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013896{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013897 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053013898
13899 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013900 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013901 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053013902
13903 wlan_loader->boot_wlan_obj = NULL;
13904 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
13905 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013906 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053013907 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053013908
13909 wlan_loader->loaded_state = 0;
13910 wlan_loader->attr_group->attrs = attrs;
13911
Qun Zhang4a83a462018-09-11 16:28:51 +080013912 wlan_loader->boot_wlan_obj = kobject_create_and_add(WLAN_LOADER_NAME,
Arun Khandavallifae92942016-08-01 13:31:08 +053013913 kernel_kobj);
13914 if (!wlan_loader->boot_wlan_obj) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013915 hdd_err("sysfs create and add failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053013916 goto error_return;
13917 }
13918
13919 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
13920 wlan_loader->attr_group);
13921 if (ret) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013922 hdd_err("sysfs create group failed; errno:%d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053013923 goto error_return;
13924 }
13925
13926 return 0;
13927
13928error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013929 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053013930
13931 return ret;
13932}
13933
13934/**
13935 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
13936 *
13937 * Return: 0 on success or errno on failure
13938 */
13939static int wlan_deinit_sysfs(void)
13940{
Arun Khandavallifae92942016-08-01 13:31:08 +053013941 if (!wlan_loader) {
Dustin Browna2a39dc2018-09-17 15:29:59 -070013942 hdd_err("wlan_loader is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053013943 return -EINVAL;
13944 }
13945
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013946 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013947 return 0;
13948}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013949
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070013950#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053013951
13952#ifdef MODULE
13953/**
Dustin Brownf0f70562018-09-14 10:29:38 -070013954 * hdd_module_init() - Module init helper
Arun Khandavallifae92942016-08-01 13:31:08 +053013955 *
13956 * Module init helper function used by both module and static driver.
13957 *
13958 * Return: 0 for success, errno on failure
13959 */
13960static int hdd_module_init(void)
13961{
Dustin Brownf0f70562018-09-14 10:29:38 -070013962 if (hdd_driver_load())
Dustin Brownab482ac2017-06-09 17:00:44 -070013963 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053013964
Dustin Brownab482ac2017-06-09 17:00:44 -070013965 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053013966}
13967#else
13968static int __init hdd_module_init(void)
13969{
13970 int ret = -EINVAL;
13971
13972 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070013973 if (ret)
Dustin Browna2a39dc2018-09-17 15:29:59 -070013974 hdd_err("Failed to create sysfs entry");
Arun Khandavallifae92942016-08-01 13:31:08 +053013975
13976 return ret;
13977}
13978#endif
13979
13980
13981#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013982/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013983 * hdd_module_exit() - Exit function
13984 *
13985 * This is the driver exit point (invoked when module is unloaded using rmmod)
13986 *
13987 * Return: None
13988 */
13989static void __exit hdd_module_exit(void)
13990{
Dustin Brownf0f70562018-09-14 10:29:38 -070013991 hdd_driver_unload();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013992}
Arun Khandavallifae92942016-08-01 13:31:08 +053013993#else
13994static void __exit hdd_module_exit(void)
13995{
Dustin Brownf0f70562018-09-14 10:29:38 -070013996 hdd_driver_unload();
Arun Khandavallifae92942016-08-01 13:31:08 +053013997 wlan_deinit_sysfs();
13998}
13999#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014000
Srinivas Girigowda841da292018-02-21 16:33:00 -080014001static int fwpath_changed_handler(const char *kmessage,
14002 const struct kernel_param *kp)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014003{
14004 return param_set_copystring(kmessage, kp);
14005}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080014006
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053014007static int con_mode_handler_ftm(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080014008 const struct kernel_param *kp)
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053014009{
14010 int ret;
14011
14012 ret = param_set_int(kmessage, kp);
14013
14014 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
14015 pr_err("Only FTM mode supported!");
14016 return -ENOTSUPP;
14017 }
14018
14019 hdd_set_conparam(con_mode_ftm);
14020 con_mode = con_mode_ftm;
14021
14022 return ret;
14023}
14024
Nirav Shah6aeecf92019-02-13 14:05:03 +053014025#ifdef WLAN_FEATURE_EPPING
14026static int con_mode_handler_epping(const char *kmessage,
14027 const struct kernel_param *kp)
14028{
14029 int ret;
14030
14031 ret = param_set_int(kmessage, kp);
14032
14033 if (con_mode_epping != QDF_GLOBAL_EPPING_MODE) {
14034 pr_err("Only EPPING mode supported!");
14035 return -ENOTSUPP;
14036 }
14037
14038 hdd_set_conparam(con_mode_epping);
14039 con_mode = con_mode_epping;
14040
14041 return ret;
14042}
14043#endif
14044
Nirav Shah73713f72018-05-17 14:50:41 +053014045#ifdef FEATURE_MONITOR_MODE_SUPPORT
Ravi Joshia307f632017-07-17 23:41:41 -070014046static int con_mode_handler_monitor(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080014047 const struct kernel_param *kp)
Ravi Joshia307f632017-07-17 23:41:41 -070014048{
14049 int ret;
14050
14051 ret = param_set_int(kmessage, kp);
14052
14053 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
14054 pr_err("Only Monitor mode supported!");
14055 return -ENOTSUPP;
14056 }
14057
14058 hdd_set_conparam(con_mode_monitor);
14059 con_mode = con_mode_monitor;
14060
14061 return ret;
14062}
Nirav Shah73713f72018-05-17 14:50:41 +053014063#endif
Ravi Joshia307f632017-07-17 23:41:41 -070014064
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014065/**
14066 * hdd_get_conparam() - driver exit point
14067 *
14068 * This is the driver exit point (invoked when module is unloaded using rmmod)
14069 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080014070 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014071 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080014072enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014073{
Jeff Johnson876c1a62017-12-12 10:43:07 -080014074 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014075}
14076
Dustin Brownf0f70562018-09-14 10:29:38 -070014077void hdd_set_conparam(int32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014078{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080014079 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080014080}
14081
Komal Seelamc11bb222016-01-27 18:57:10 +053014082/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014083 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
14084 * @hdd_ctx: HDD context
14085 *
14086 * Cleans up the pre cac interface, if it exists
14087 *
14088 * Return: None
14089 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014090void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014091{
Jeff Johnson55d2ab42019-03-06 11:43:49 -080014092 uint8_t vdev_id;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014093 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070014094 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014095
Jeff Johnson55d2ab42019-03-06 11:43:49 -080014096 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->mac_handle, &vdev_id);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014097 if (QDF_IS_STATUS_ERROR(status)) {
14098 hdd_err("failed to get pre cac vdev id");
14099 return;
14100 }
14101
Jeff Johnson55d2ab42019-03-06 11:43:49 -080014102 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014103 if (!precac_adapter) {
Jeff Johnsondd2f1fc2018-05-06 11:22:52 -070014104 hdd_err("invalid pre cac adapter");
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053014105 return;
14106 }
14107
14108 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
14109 wlan_hdd_sap_pre_cac_failure,
14110 (void *)precac_adapter);
14111 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
14112
14113}
14114
14115/**
Komal Seelamec702b02016-02-24 18:42:16 +053014116 * hdd_update_ol_config - API to update ol configuration parameters
14117 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053014118 *
Komal Seelamc11bb222016-01-27 18:57:10 +053014119 * Return: void
14120 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014121static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053014122{
Abhishek Singh98278ce2018-12-27 11:41:03 +053014123 struct ol_config_info cfg = {0};
Anurag Chouhandf2b2682016-02-29 14:15:27 +053014124 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014125 bool self_recovery = false;
14126 QDF_STATUS status;
Komal Seelamc11bb222016-01-27 18:57:10 +053014127
Komal Seelamec702b02016-02-24 18:42:16 +053014128 if (!ol_ctx)
14129 return;
14130
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014131 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
14132 if (QDF_IS_STATUS_ERROR(status))
14133 hdd_err("Failed to get self recovery ini config");
14134
14135 cfg.enable_self_recovery = self_recovery;
Komal Seelamec702b02016-02-24 18:42:16 +053014136 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
14137 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
14138 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070014139 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053014140
14141 ol_init_ini_config(ol_ctx, &cfg);
14142}
14143
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014144#ifdef FEATURE_RUNTIME_PM
14145/**
14146 * hdd_populate_runtime_cfg() - populate runtime configuration
14147 * @hdd_ctx: hdd context
14148 * @cfg: pointer to the configuration memory being populated
14149 *
14150 * Return: void
14151 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014152static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014153 struct hif_config_info *cfg)
14154{
14155 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
Wu Gao66454f12018-09-26 19:55:41 +080014156 cfg->runtime_pm_delay =
14157 ucfg_pmo_get_runtime_pm_delay(hdd_ctx->psoc);
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014158}
14159#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014160static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014161 struct hif_config_info *cfg)
14162{
14163}
14164#endif
14165
Komal Seelamec702b02016-02-24 18:42:16 +053014166/**
14167 * hdd_update_hif_config - API to update HIF configuration parameters
14168 * @hdd_ctx: HDD Context
14169 *
14170 * Return: void
14171 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014172static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053014173{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053014174 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Abhishek Singh98278ce2018-12-27 11:41:03 +053014175 struct hif_config_info cfg = {0};
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014176 bool prevent_link_down = false;
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014177 bool self_recovery = false;
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014178 QDF_STATUS status;
Komal Seelamec702b02016-02-24 18:42:16 +053014179
14180 if (!scn)
14181 return;
14182
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014183 status = ucfg_mlme_get_prevent_link_down(hdd_ctx->psoc,
14184 &prevent_link_down);
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014185 if (QDF_IS_STATUS_ERROR(status))
14186 hdd_err("Failed to get prevent_link_down config");
14187
Vignesh Viswanathana1f3a1a2018-10-04 13:10:46 +053014188 status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
14189 if (QDF_IS_STATUS_ERROR(status))
14190 hdd_err("Failed to get self recovery ini config");
14191
14192 cfg.enable_self_recovery = self_recovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070014193 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Mohit Khannaa8c9f562019-03-25 22:17:02 -070014194 cfg.rx_softirq_max_yield_duration_ns =
14195 cfg_get(hdd_ctx->psoc,
14196 CFG_DP_RX_SOFTIRQ_MAX_YIELD_TIME_NS);
14197
Komal Seelamec702b02016-02-24 18:42:16 +053014198 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070014199
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014200 if (prevent_link_down)
Dustin Brownee3e0592017-09-07 13:50:11 -070014201 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053014202}
14203
Mohit Khannaa8c9f562019-03-25 22:17:02 -070014204#ifdef WLAN_FEATURE_RX_SOFTIRQ_TIME_LIMIT
14205/**
14206 * hdd_update_dp_config_rx_softirq_limits() - Update DP rx softirq limit config
14207 * datapath
14208 * @hdd_ctx: HDD Context
14209 * @params: pointer to cdp_config_params to be updated
14210 *
14211 * Void
14212 */
14213static
14214void hdd_update_dp_config_rx_softirq_limits(struct hdd_context *hdd_ctx,
14215 struct cdp_config_params *params)
14216{
14217 params->tx_comp_loop_pkt_limit = cfg_get(hdd_ctx->psoc,
14218 CFG_DP_TX_COMP_LOOP_PKT_LIMIT);
14219 params->rx_reap_loop_pkt_limit = cfg_get(hdd_ctx->psoc,
14220 CFG_DP_RX_REAP_LOOP_PKT_LIMIT);
14221 params->rx_hp_oos_update_limit = cfg_get(hdd_ctx->psoc,
14222 CFG_DP_RX_HP_OOS_UPDATE_LIMIT);
14223}
14224#else
14225static
14226void hdd_update_dp_config_rx_softirq_limits(struct hdd_context *hdd_ctx,
14227 struct cdp_config_params *params)
14228{
14229}
14230#endif /* WLAN_FEATURE_RX_SOFTIRQ_TIME_LIMIT */
14231
Komal Seelamec702b02016-02-24 18:42:16 +053014232/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014233 * hdd_update_dp_config() - Propagate config parameters to Lithium
14234 * datapath
14235 * @hdd_ctx: HDD Context
14236 *
14237 * Return: 0 for success/errno for failure
14238 */
14239static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
14240{
Abhishek Singh98278ce2018-12-27 11:41:03 +053014241 struct cdp_config_params params = {0};
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014242 QDF_STATUS status;
jitiphil377bcc12018-10-05 19:46:08 +053014243 void *soc;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014244
jitiphil377bcc12018-10-05 19:46:08 +053014245 soc = cds_get_context(QDF_MODULE_ID_SOC);
14246 params.tso_enable = cfg_get(hdd_ctx->psoc, CFG_DP_TSO);
14247 params.lro_enable = cfg_get(hdd_ctx->psoc, CFG_DP_LRO);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014248 params.tx_flow_stop_queue_threshold =
jitiphil47c3d9a2018-11-08 18:30:55 +053014249 cfg_get(hdd_ctx->psoc, CFG_DP_TX_FLOW_STOP_QUEUE_TH);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014250 params.tx_flow_start_queue_offset =
jitiphil47c3d9a2018-11-08 18:30:55 +053014251 cfg_get(hdd_ctx->psoc,
14252 CFG_DP_TX_FLOW_START_QUEUE_OFFSET);
jitiphil377bcc12018-10-05 19:46:08 +053014253 params.flow_steering_enable =
14254 cfg_get(hdd_ctx->psoc, CFG_DP_FLOW_STEERING_ENABLED);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014255 params.napi_enable = hdd_ctx->napi_enable;
14256 params.tcp_udp_checksumoffload =
jitiphil377bcc12018-10-05 19:46:08 +053014257 cfg_get(hdd_ctx->psoc,
14258 CFG_DP_TCP_UDP_CKSUM_OFFLOAD);
Sravan Kumar Kairam0af1ee52018-12-12 20:37:51 +053014259 params.ipa_enable = ucfg_ipa_is_enabled();
Mohit Khanna81418772018-10-30 14:14:46 -070014260 params.gro_enable = cfg_get(hdd_ctx->psoc, CFG_DP_GRO);
Mohit Khannaa8c9f562019-03-25 22:17:02 -070014261 params.tx_comp_loop_pkt_limit = cfg_get(hdd_ctx->psoc,
14262 CFG_DP_TX_COMP_LOOP_PKT_LIMIT);
14263 params.rx_reap_loop_pkt_limit = cfg_get(hdd_ctx->psoc,
14264 CFG_DP_RX_REAP_LOOP_PKT_LIMIT);
14265 params.rx_hp_oos_update_limit = cfg_get(hdd_ctx->psoc,
14266 CFG_DP_RX_HP_OOS_UPDATE_LIMIT);
14267 hdd_update_dp_config_rx_softirq_limits(hdd_ctx, &params);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014268
jitiphil377bcc12018-10-05 19:46:08 +053014269 status = cdp_update_config_parameters(soc, &params);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014270 if (status) {
Dustin Browna2868622018-03-20 11:38:14 -070014271 hdd_err("Failed to attach config parameters");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014272 return status;
14273 }
14274
14275 return 0;
14276}
14277
14278/**
Komal Seelamec702b02016-02-24 18:42:16 +053014279 * hdd_update_config() - Initialize driver per module ini parameters
14280 * @hdd_ctx: HDD Context
14281 *
14282 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053014283 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053014284 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014285int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053014286{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053014287 int ret;
14288
Wu Gao66454f12018-09-26 19:55:41 +080014289 if (ucfg_pmo_is_ns_offloaded(hdd_ctx->psoc))
14290 hdd_ctx->ns_offload_enable = true;
14291
Komal Seelamec702b02016-02-24 18:42:16 +053014292 hdd_update_ol_config(hdd_ctx);
14293 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053014294 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
14295 ret = hdd_update_cds_config_ftm(hdd_ctx);
14296 else
14297 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080014298 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053014299
14300 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053014301}
14302
Mukul Sharma9d797a02017-01-05 20:26:03 +053014303/**
14304 * hdd_update_pmo_config - API to update pmo configuration parameters
14305 * @hdd_ctx: HDD context
14306 *
14307 * Return: void
14308 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014309static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053014310{
Abhishek Singh98278ce2018-12-27 11:41:03 +053014311 struct pmo_psoc_cfg psoc_cfg = {0};
Mukul Sharma9d797a02017-01-05 20:26:03 +053014312 QDF_STATUS status;
Wu Gao66454f12018-09-26 19:55:41 +080014313 enum pmo_wow_enable_type wow_enable;
14314
14315 ucfg_pmo_get_psoc_config(hdd_ctx->psoc, &psoc_cfg);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014316
14317 /*
14318 * Value of hdd_ctx->wowEnable can be,
14319 * 0 - Disable both magic pattern match and pattern byte match.
14320 * 1 - Enable magic pattern match on all interfaces.
14321 * 2 - Enable pattern byte match on all interfaces.
14322 * 3 - Enable both magic patter and pattern byte match on
14323 * all interfaces.
14324 */
Wu Gao66454f12018-09-26 19:55:41 +080014325 wow_enable = ucfg_pmo_get_wow_enable(hdd_ctx->psoc);
14326 psoc_cfg.magic_ptrn_enable = (wow_enable & 0x01) ? true : false;
Mukul Sharma9d797a02017-01-05 20:26:03 +053014327 psoc_cfg.ptrn_match_enable_all_vdev =
Wu Gao66454f12018-09-26 19:55:41 +080014328 (wow_enable & 0x02) ? true : false;
Mukul Sharma9d797a02017-01-05 20:26:03 +053014329 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080014330 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Bala Venkatesh46e29032018-11-14 18:24:55 +053014331 ucfg_mlme_get_sap_max_modulated_dtim(hdd_ctx->psoc,
14332 &psoc_cfg.sta_max_li_mod_dtim);
14333
Mukul Sharma9d797a02017-01-05 20:26:03 +053014334
Mukul Sharma9223f232017-03-08 18:42:27 +053014335 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014336
Dustin Brown1dbefe62018-09-11 16:32:03 -070014337 status = ucfg_pmo_update_psoc_config(hdd_ctx->psoc, &psoc_cfg);
Dustin Brownb9987af2018-03-01 17:15:11 -080014338 if (QDF_IS_STATUS_ERROR(status))
14339 hdd_err("failed pmo psoc configuration; status:%d", status);
14340
14341 return qdf_status_to_os_return(status);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014342}
14343
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014344void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014345 struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014346{
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014347 struct wlan_fwol_ie_whitelist whitelist = {0};
14348 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014349 QDF_STATUS status;
14350 bool is_ie_whitelist_enable = false;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014351 uint8_t i = 0;
14352
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014353 status = ucfg_fwol_get_ie_whitelist(psoc, &is_ie_whitelist_enable);
14354 if (QDF_IS_STATUS_ERROR(status)) {
14355 hdd_err("Unable to get IE whitelist param");
14356 return;
14357 }
14358
14359 ie_whitelist->white_list = is_ie_whitelist_enable;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014360 if (!ie_whitelist->white_list)
14361 return;
14362
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014363 status = ucfg_fwol_get_all_whitelist_params(psoc, &whitelist);
14364 if (QDF_IS_STATUS_ERROR(status)) {
14365 hdd_err("Unable to get all whitelist params");
14366 return;
14367 }
14368
14369 ie_whitelist->ie_bitmap[0] = whitelist.ie_bitmap_0;
14370 ie_whitelist->ie_bitmap[1] = whitelist.ie_bitmap_1;
14371 ie_whitelist->ie_bitmap[2] = whitelist.ie_bitmap_2;
14372 ie_whitelist->ie_bitmap[3] = whitelist.ie_bitmap_3;
14373 ie_whitelist->ie_bitmap[4] = whitelist.ie_bitmap_4;
14374 ie_whitelist->ie_bitmap[5] = whitelist.ie_bitmap_5;
14375 ie_whitelist->ie_bitmap[6] = whitelist.ie_bitmap_6;
14376 ie_whitelist->ie_bitmap[7] = whitelist.ie_bitmap_7;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014377
Dundi Raviteja9ab4e7b2018-09-28 14:18:28 +053014378 ie_whitelist->num_vendor_oui = whitelist.no_of_probe_req_ouis;
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014379 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
Dundi Raviteja9ab4e7b2018-09-28 14:18:28 +053014380 ie_whitelist->voui[i] = whitelist.probe_req_voui[i];
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053014381}
14382
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014383uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
14384{
14385 uint8_t i, score;
14386
14387 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
14388 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
14389 if (score > MAX_INDEX_SCORE)
14390 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
14391 MAX_INDEX_SCORE, i);
14392 }
14393
14394 return per_index_score;
14395}
14396
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014397QDF_STATUS hdd_update_score_config(
14398 struct scoring_config *score_config, struct hdd_context *hdd_ctx)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014399{
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014400 struct hdd_config *cfg = hdd_ctx->config;
gaurank kathpaliaae52c982018-10-04 01:35:18 +053014401 QDF_STATUS status;
gaurank kathpalia651abcd2018-11-12 22:41:23 +053014402 struct wlan_mlme_nss_chains vdev_ini_cfg;
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014403 bool bval = false;
Wu Gaoed616a12019-01-16 15:19:21 +080014404 uint32_t channel_bonding_mode;
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014405
Abhishek Singh98278ce2018-12-27 11:41:03 +053014406 qdf_mem_zero(&vdev_ini_cfg, sizeof(struct wlan_mlme_nss_chains));
gaurank kathpalia651abcd2018-11-12 22:41:23 +053014407 /* Populate the nss chain params from ini for this vdev type */
14408 sme_populate_nss_chain_params(hdd_ctx->mac_handle, &vdev_ini_cfg,
14409 QDF_STA_MODE,
14410 hdd_ctx->num_rf_chains);
14411
14412 score_config->vdev_nss_24g = vdev_ini_cfg.rx_nss[NSS_CHAINS_BAND_2GHZ];
14413 score_config->vdev_nss_24g = vdev_ini_cfg.rx_nss[NSS_CHAINS_BAND_5GHZ];
14414
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014415 sme_update_score_config(hdd_ctx->mac_handle, score_config);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014416
Wu Gaoed616a12019-01-16 15:19:21 +080014417 ucfg_mlme_get_channel_bonding_24ghz(hdd_ctx->psoc,
14418 &channel_bonding_mode);
14419 score_config->cb_mode_24G = channel_bonding_mode;
14420 ucfg_mlme_get_channel_bonding_5ghz(hdd_ctx->psoc,
14421 &channel_bonding_mode);
14422 score_config->cb_mode_5G = channel_bonding_mode;
gaurank kathpaliaae52c982018-10-04 01:35:18 +053014423
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014424 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
14425 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
14426 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
14427 score_config->he_cap = 1;
14428
14429 if (score_config->he_cap ||
14430 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
14431 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
14432 score_config->vht_cap = 1;
14433
14434 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
14435 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
14436 score_config->ht_cap = 1;
14437
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014438 status = ucfg_mlme_get_vht_for_24ghz(hdd_ctx->psoc, &bval);
14439 if (!QDF_IS_STATUS_SUCCESS(status))
14440 hdd_err("Failed to get vht_for_24ghz");
14441 if (score_config->vht_cap && bval)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014442 score_config->vht_24G_cap = 1;
14443
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014444 status = ucfg_mlme_get_vht_enable_tx_bf(hdd_ctx->psoc,
14445 &bval);
14446 if (!QDF_IS_STATUS_SUCCESS(status))
14447 hdd_err("unable to get vht_enable_tx_bf");
14448
14449 if (bval)
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014450 score_config->beamformee_cap = 1;
14451
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014452 return QDF_STATUS_SUCCESS;
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053014453}
14454
Abhishek Singh257a9482017-03-06 16:52:39 +053014455/**
bings81fe50a2017-11-27 14:33:26 +080014456 * hdd_update_dfs_config() - API to update dfs configuration parameters.
14457 * @hdd_ctx: HDD context
14458 *
14459 * Return: 0 if success else err
14460 */
14461static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
14462{
Dustin Brown1dbefe62018-09-11 16:32:03 -070014463 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Abhishek Singh98278ce2018-12-27 11:41:03 +053014464 struct dfs_user_config dfs_cfg = {0};
bings81fe50a2017-11-27 14:33:26 +080014465 QDF_STATUS status;
14466
Arif Hussain224d3812018-11-16 17:58:38 -080014467 ucfg_mlme_get_dfs_filter_offload(hdd_ctx->psoc,
14468 &dfs_cfg.dfs_is_phyerr_filter_offload);
bings81fe50a2017-11-27 14:33:26 +080014469 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
14470 if (QDF_IS_STATUS_ERROR(status)) {
14471 hdd_err("failed dfs psoc configuration");
14472 return -EINVAL;
14473 }
14474
14475 return 0;
14476}
14477
14478/**
Abhishek Singh257a9482017-03-06 16:52:39 +053014479 * hdd_update_scan_config - API to update scan configuration parameters
14480 * @hdd_ctx: HDD context
14481 *
14482 * Return: 0 if success else err
14483 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014484static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053014485{
Dustin Brown1dbefe62018-09-11 16:32:03 -070014486 struct wlan_objmgr_psoc *psoc = hdd_ctx->psoc;
Sandeep Puligillad7887022019-02-26 00:48:52 -080014487 struct scan_user_cfg scan_cfg;
Abhishek Singh257a9482017-03-06 16:52:39 +053014488 QDF_STATUS status;
Krunal Sonid2c33e12018-12-06 15:02:37 -080014489 uint32_t mcast_mcc_rest_time = 0;
Vignesh Viswanathana851d752018-10-03 19:44:38 +053014490
Sandeep Puligillad7887022019-02-26 00:48:52 -080014491 qdf_mem_zero(&scan_cfg, sizeof(scan_cfg));
Krunal Sonid2c33e12018-12-06 15:02:37 -080014492 status = ucfg_mlme_get_sta_miracast_mcc_rest_time(hdd_ctx->psoc,
14493 &mcast_mcc_rest_time);
14494 if (!QDF_IS_STATUS_SUCCESS(status)) {
14495 hdd_err("ucfg_mlme_get_sta_miracast_mcc_rest_time, use def");
14496 return -EIO;
14497 }
14498 scan_cfg.sta_miracast_mcc_rest_time = mcast_mcc_rest_time;
Dundi Raviteja85a240a2018-09-10 15:03:07 +053014499 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, hdd_ctx);
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014500
Abhinav Kumarb074f2f2018-09-15 15:32:11 +053014501 status = hdd_update_score_config(&scan_cfg.score_config, hdd_ctx);
Vignesh Viswanathan987f0bb2018-09-17 17:00:29 +053014502 if (QDF_IS_STATUS_ERROR(status)) {
14503 hdd_err("Failed to update scoring config");
14504 return -EINVAL;
14505 }
Abhishek Singhb20db962017-03-03 21:28:46 +053014506
Abhishek Singh257a9482017-03-06 16:52:39 +053014507 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
14508 if (status != QDF_STATUS_SUCCESS) {
14509 hdd_err("failed pmo psoc configuration");
14510 return -EINVAL;
14511 }
14512
14513 return 0;
14514}
Abhishek Singh257a9482017-03-06 16:52:39 +053014515
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014516int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053014517{
14518 int ret;
14519
14520 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053014521 if (ret)
14522 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014523
Abhishek Singh257a9482017-03-06 16:52:39 +053014524 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080014525 if (ret)
14526 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014527
Frank Liud4b2fa02017-03-29 11:46:48 +080014528 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070014529 if (ret)
14530 return ret;
14531
14532 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080014533 if (ret)
14534 return ret;
14535
14536 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053014537
14538 return ret;
14539}
14540
Agrawal Ashish65634612016-08-18 13:24:32 +053014541/**
14542 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
14543 * @mode : cfg80211 DFS mode
14544 *
14545 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
14546 */
14547enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
14548{
14549 switch (mode) {
14550 case DFS_MODE_ENABLE:
14551 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014552 case DFS_MODE_DISABLE:
14553 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014554 case DFS_MODE_DEPRIORITIZE:
14555 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014556 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080014557 hdd_debug("ACS dfs mode is NONE");
14558 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053014559 }
14560}
14561
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014562/**
14563 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
14564 * @hddctx: pointer to hdd context
14565 * @set_value: enable/disable
14566 *
14567 * When Host sends vendor command enable, FW will send *ONE* CA ind to
14568 * Host(even though it is duplicate). When Host send vendor command
14569 * disable,FW doesn't perform any action. Whenever any change in
14570 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
14571 *
14572 * return - 0 on success, appropriate error values on failure.
14573 */
Jeff Johnson16528362018-06-14 12:34:16 -070014574int hdd_enable_disable_ca_event(struct hdd_context *hdd_ctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014575{
14576 QDF_STATUS status;
14577
Jeff Johnson16528362018-06-14 12:34:16 -070014578 if (0 != wlan_hdd_validate_context(hdd_ctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014579 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014580
Jeff Johnson16528362018-06-14 12:34:16 -070014581 status = sme_enable_disable_chanavoidind_event(hdd_ctx->mac_handle,
14582 set_value);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053014583 if (!QDF_IS_STATUS_SUCCESS(status)) {
14584 hdd_err("Failed to send chan avoid command to SME");
14585 return -EINVAL;
14586 }
14587 return 0;
14588}
Agrawal Ashish65634612016-08-18 13:24:32 +053014589
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014590/**
14591 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
14592 * @value: value to set
14593 *
14594 * This function will set the passed value to roaming in progress flag.
14595 *
14596 * Return: None
14597 */
14598void hdd_set_roaming_in_progress(bool value)
14599{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014600 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014601
14602 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14603 if (!hdd_ctx) {
14604 hdd_err("HDD context is NULL");
14605 return;
14606 }
14607
14608 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080014609 hdd_debug("Roaming in Progress set to %d", value);
Abhinav Kumar2b431b62019-03-18 20:23:58 +053014610 if (!hdd_ctx->roaming_in_progress) {
14611 /* Reset scan reject params on successful roam complete */
14612 hdd_debug("Reset scan reject params");
14613 hdd_init_scan_reject_params(hdd_ctx);
14614 }
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014615}
14616
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014617bool hdd_is_roaming_in_progress(struct hdd_context *hdd_ctx)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014618{
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014619 if (!hdd_ctx) {
14620 hdd_err("HDD context is NULL");
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014621 return false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014622 }
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080014623
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014624 hdd_debug("roaming_in_progress = %d", hdd_ctx->roaming_in_progress);
14625
14626 return hdd_ctx->roaming_in_progress;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080014627}
14628
Jeff Johnsona2ac4e72019-03-06 08:35:29 -080014629bool hdd_is_connection_in_progress(uint8_t *out_vdev_id,
14630 enum scan_reject_states *out_reason)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014631{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070014632 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070014633 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014634 uint8_t sta_id = 0;
14635 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014636 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -070014637 mac_handle_t mac_handle;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014638
14639 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14640 if (!hdd_ctx) {
14641 hdd_err("HDD context is NULL");
14642 return false;
14643 }
14644
Jeff Johnson16528362018-06-14 12:34:16 -070014645 mac_handle = hdd_ctx->mac_handle;
14646
Dustin Brown920397d2017-12-13 16:27:50 -080014647 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya929afa42018-06-01 15:04:44 -070014648 hdd_debug("Adapter with device mode %s(%d) exists",
Dustin Brown458027c2018-10-19 12:26:27 -070014649 qdf_opmode_str(adapter->device_mode),
14650 adapter->device_mode);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014651 if (((QDF_STA_MODE == adapter->device_mode)
14652 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
14653 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
14654 && (eConnectionState_Connecting ==
14655 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
Jeff Johnsone7951512019-02-27 10:02:51 -080014656 conn_info.conn_state)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014657 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014658 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014659 adapter->vdev_id);
Jeff Johnsona2ac4e72019-03-06 08:35:29 -080014660 if (out_vdev_id && out_reason) {
14661 *out_vdev_id = adapter->vdev_id;
14662 *out_reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014663 }
14664 return true;
14665 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070014666 /*
14667 * sme_neighbor_middle_of_roaming is for LFR2
14668 * hdd_is_roaming_in_progress is for LFR3
14669 */
14670 if (((QDF_STA_MODE == adapter->device_mode) &&
14671 sme_neighbor_middle_of_roaming(
Jeff Johnson16528362018-06-14 12:34:16 -070014672 mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014673 adapter->vdev_id)) ||
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053014674 hdd_is_roaming_in_progress(hdd_ctx)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014675 hdd_debug("%pK(%d) Reassociation 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 = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014681 }
14682 return true;
14683 }
14684 if ((QDF_STA_MODE == adapter->device_mode) ||
14685 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
14686 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
14687 hdd_sta_ctx =
14688 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
14689 if ((eConnectionState_Associated ==
Jeff Johnsone7951512019-02-27 10:02:51 -080014690 hdd_sta_ctx->conn_info.conn_state)
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053014691 && sme_is_sta_key_exchange_in_progress(
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014692 mac_handle, adapter->vdev_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014693 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070014694 &(adapter->mac_addr.bytes[0]);
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -070014695 hdd_debug("client " QDF_MAC_ADDR_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014696 " is in middle of WPS/EAPOL exchange.",
Srinivas Girigowda34fbba02019-04-08 12:07:44 -070014697 QDF_MAC_ADDR_ARRAY(sta_mac));
Jeff Johnsona2ac4e72019-03-06 08:35:29 -080014698 if (out_vdev_id && out_reason) {
14699 *out_vdev_id = adapter->vdev_id;
14700 *out_reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014701 }
14702 return true;
14703 }
14704 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
14705 (QDF_P2P_GO_MODE == adapter->device_mode)) {
14706 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
14707 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014708 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014709 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014710 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014711 continue;
14712
14713 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014714 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070014715 sta_mac.bytes[0]);
Srinivas Girigowdacb7b8b82019-04-10 14:27:47 -070014716 hdd_debug("client " QDF_MAC_ADDR_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014717 " of SAP/GO is in middle of WPS/EAPOL exchange",
Srinivas Girigowda34fbba02019-04-08 12:07:44 -070014718 QDF_MAC_ADDR_ARRAY(sta_mac));
Jeff Johnsona2ac4e72019-03-06 08:35:29 -080014719 if (out_vdev_id && out_reason) {
14720 *out_vdev_id = adapter->vdev_id;
14721 *out_reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014722 }
14723 return true;
14724 }
14725 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014726 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014727 return true;
14728 }
14729 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014730 }
Dustin Brown920397d2017-12-13 16:27:50 -080014731
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014732 return false;
14733}
14734
14735/**
14736 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070014737 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014738 *
14739 * Return: None
14740 */
Jeff Johnson9d295242017-08-29 14:39:48 -070014741void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014742{
Jeff Johnson87251032017-08-29 13:31:11 -070014743 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070014744 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014745 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014746 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Jeff Johnson8f8ceb92019-03-24 08:16:55 -070014747 struct sap_config *sap_config;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014748 void *sap_ctx;
14749
14750 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070014751 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070014752 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014753
14754 mutex_lock(&hdd_ctx->sap_lock);
14755 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
14756 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014757 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
14758 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
14759 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
14760 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053014761 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014762 qdf_stop_bss_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +053014763 SME_CMD_STOP_BSS_TIMEOUT);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014764
14765 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014766 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014767 goto end;
14768 }
14769 }
14770 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Dustin Brown1dbefe62018-09-11 16:32:03 -070014771 policy_mgr_decr_session_set_pcl(hdd_ctx->psoc,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014772 ap_adapter->device_mode, ap_adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070014773 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014774 false);
Jeff Johnson6867ec32017-09-29 20:30:20 -070014775 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014776
14777 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014778 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014779 wlansap_reset_sap_config_add_ie(sap_config,
14780 eUPDATE_IE_ALL);
14781 goto end;
14782 }
14783
14784 qdf_event_reset(&hostapd_state->qdf_event);
14785 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
14786 sap_config,
14787 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014788 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014789 wlansap_reset_sap_config_add_ie(sap_config,
14790 eUPDATE_IE_ALL);
14791 goto end;
14792 }
14793
Jeff Johnson6867ec32017-09-29 20:30:20 -070014794 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014795 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053014796 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Abhishek Singhd1f21c72019-01-21 15:16:34 +053014797 SME_CMD_START_BSS_TIMEOUT);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014798 wlansap_reset_sap_config_add_ie(sap_config,
14799 eUPDATE_IE_ALL);
14800 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014801 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014802 goto end;
14803 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070014804 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014805 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014806 if (hostapd_state->bss_state == BSS_START) {
Dustin Brown1dbefe62018-09-11 16:32:03 -070014807 policy_mgr_incr_active_session(hdd_ctx->psoc,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014808 ap_adapter->device_mode,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014809 ap_adapter->vdev_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070014810 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014811 ap_adapter->device_mode,
14812 true);
14813 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014814 }
14815end:
14816 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014817}
14818
14819/**
14820 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
14821 * with non dfs acs
14822 *
14823 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
14824 *
14825 * Return: None
14826 */
14827void hdd_check_and_restart_sap_with_non_dfs_acs(void)
14828{
Jeff Johnson9d295242017-08-29 14:39:48 -070014829 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014830 struct hdd_context *hdd_ctx;
Jeff Johnson2b6982c2018-05-29 14:56:11 -070014831 struct cds_context *cds_ctx;
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014832 uint8_t restart_chan;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014833
14834 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14835 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014836 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014837 return;
14838 }
14839
14840 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
14841 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014842 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014843 return;
14844 }
14845
Dustin Brown1dbefe62018-09-11 16:32:03 -070014846 if (policy_mgr_get_concurrency_mode(hdd_ctx->psoc)
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014847 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Dustin Brown7e761c72018-07-31 13:50:17 -070014848 hdd_debug("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014849 return;
14850 }
14851
14852 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Dustin Brown07901ec2018-09-07 11:02:41 -070014853 if (ap_adapter &&
14854 test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags) &&
14855 wlan_reg_is_dfs_ch(hdd_ctx->pdev,
14856 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014857
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014858 hdd_warn("STA-AP Mode DFS not supported, Switch SAP channel to Non DFS");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014859
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014860 restart_chan =
bings6c4672b2019-03-19 16:00:19 +080014861 wlansap_get_safe_channel_from_pcl_and_acs_range(
14862 WLAN_HDD_GET_SAP_CTX_PTR(ap_adapter));
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014863 if (!restart_chan ||
Dustin Brown07901ec2018-09-07 11:02:41 -070014864 wlan_reg_is_dfs_ch(hdd_ctx->pdev, restart_chan))
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014865 restart_chan = SAP_DEFAULT_5GHZ_CHANNEL;
14866
14867 hdd_switch_sap_channel(ap_adapter, restart_chan, true);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014868 }
14869}
14870
14871/**
14872 * hdd_set_connection_in_progress() - to set the connection in
14873 * progress flag
14874 * @value: value to set
14875 *
14876 * This function will set the passed value to connection in progress flag.
14877 * If value is previously being set to true then no need to set it again.
14878 *
14879 * Return: true if value is being set correctly and false otherwise.
14880 */
14881bool hdd_set_connection_in_progress(bool value)
14882{
14883 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014884 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014885
14886 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14887 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014888 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014889 return false;
14890 }
14891
14892 qdf_spin_lock(&hdd_ctx->connection_status_lock);
14893 /*
14894 * if the value is set to true previously and if someone is
14895 * trying to make it true again then it could be some race
14896 * condition being triggered. Avoid this situation by returning
14897 * false
14898 */
14899 if (hdd_ctx->connection_in_progress && value)
14900 status = false;
14901 else
14902 hdd_ctx->connection_in_progress = value;
14903 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
14904 return status;
14905}
14906
Jeff Johnson9d295242017-08-29 14:39:48 -070014907int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014908{
14909 if (!adapter) {
14910 hdd_err("Invalid adapter");
14911 return -EINVAL;
14912 }
14913 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014914 sme_cli_set_command(adapter->vdev_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014915 WMA_VDEV_MCC_SET_TIME_QUOTA,
14916 set_value, VDEV_CMD);
14917 return 0;
14918
14919}
14920
Jeff Johnson9d295242017-08-29 14:39:48 -070014921int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014922{
14923 if (!adapter) {
14924 hdd_err("Invalid adapter");
14925 return -EINVAL;
14926 }
14927
14928 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson5a6fc962019-02-04 14:20:25 -080014929 sme_cli_set_command(adapter->vdev_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014930 WMA_VDEV_MCC_SET_TIME_LATENCY,
14931 set_value, VDEV_CMD);
14932 return 0;
14933}
14934
Jeff Johnson9d295242017-08-29 14:39:48 -070014935struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070014936 *psoc, uint8_t vdev_id)
14937{
Jeff Johnson9d295242017-08-29 14:39:48 -070014938 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014939 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070014940
14941 /*
14942 * Currently PSOC is not being used. But this logic will
14943 * change once we have the converged implementation of
14944 * HDD context per PSOC in place. This would break if
14945 * multiple vdev objects reuse the vdev id.
14946 */
14947 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
14948 if (!adapter)
14949 hdd_err("Get adapter by vdev id failed");
14950
14951 return adapter;
14952}
14953
Jeff Johnson9d295242017-08-29 14:39:48 -070014954int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014955 int8_t *rssi, int8_t *snr)
14956{
14957 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -070014958 mac_handle_t mac_handle;
Jeff Johnson025618c2018-03-18 14:41:00 -070014959 struct csr_roam_profile *roam_profile;
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014960
Jeff Johnson025618c2018-03-18 14:41:00 -070014961 roam_profile = hdd_roam_profile(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -070014962 mac_handle = hdd_adapter_get_mac_handle(adapter);
14963 status = sme_get_rssi_snr_by_bssid(mac_handle,
Jeff Johnson025618c2018-03-18 14:41:00 -070014964 roam_profile, bssid, rssi, snr);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014965 if (QDF_STATUS_SUCCESS != status) {
14966 hdd_warn("sme_get_rssi_snr_by_bssid failed");
14967 return -EINVAL;
14968 }
14969
14970 return 0;
14971}
14972
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014973/**
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014974 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
14975 * @adapter - HDD adapter
14976 *
14977 * Return: 0 on success and non zero value on failure
14978 */
14979int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
14980{
14981 struct hdd_context *hdd_ctx;
14982 int ret;
14983 QDF_STATUS status;
Krunal Sonie71838d2018-09-27 10:45:05 -070014984 uint8_t sys_pref = 0;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014985
14986 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
14987 ret = wlan_hdd_validate_context(hdd_ctx);
14988 if (ret < 0)
14989 return ret;
14990
Krunal Sonie71838d2018-09-27 10:45:05 -070014991 ucfg_policy_mgr_get_sys_pref(hdd_ctx->psoc,
14992 &sys_pref);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014993 /* set the system preferece to default */
Krunal Sonie71838d2018-09-27 10:45:05 -070014994 policy_mgr_set_cur_conc_system_pref(hdd_ctx->psoc, sys_pref);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014995
14996 /* clear the bitmap */
14997 adapter->active_ac = 0;
14998
14999 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson5a6fc962019-02-04 14:20:25 -080015000 adapter->vdev_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053015001
Jeff Johnson16528362018-06-14 12:34:16 -070015002 status = sme_send_limit_off_channel_params(hdd_ctx->mac_handle,
Jeff Johnson5a6fc962019-02-04 14:20:25 -080015003 adapter->vdev_id,
Jeff Johnson16528362018-06-14 12:34:16 -070015004 false, 0, 0, false);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053015005 if (!QDF_IS_STATUS_SUCCESS(status)) {
15006 hdd_err("failed to reset limit off chan params");
15007 ret = -EINVAL;
15008 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053015009
15010 return ret;
15011}
15012
Yun Parkff6a16a2017-09-26 16:38:18 -070015013void hdd_set_rx_mode_rps(bool enable)
15014{
15015 struct cds_config_info *cds_cfg = cds_get_ini_config();
Ryan Hsu0e878fa2018-05-04 15:22:09 -070015016 struct hdd_context *hdd_ctx;
15017 struct hdd_adapter *adapter;
Yun Parkff6a16a2017-09-26 16:38:18 -070015018
Ryan Hsu0e878fa2018-05-04 15:22:09 -070015019 if (!cds_cfg)
15020 return;
15021
15022 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
15023 if (!hdd_ctx)
15024 return;
15025
15026 adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
15027 if (!adapter)
15028 return;
15029
15030 if (!hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
Yun Parkff6a16a2017-09-26 16:38:18 -070015031 if (enable && !cds_cfg->rps_enabled)
15032 hdd_send_rps_ind(adapter);
15033 else if (!enable && cds_cfg->rps_enabled)
15034 hdd_send_rps_disable_ind(adapter);
15035 }
15036}
15037
Abhinav Kumar338e57d2019-02-04 17:30:10 +053015038void hdd_hidden_ssid_enable_roaming(hdd_handle_t hdd_handle, uint8_t vdev_id)
15039{
15040 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
15041 struct hdd_adapter *adapter;
15042
15043 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
15044
15045 if (!adapter) {
15046 hdd_err("Adapter is null");
15047 return;
15048 }
15049 /* enable roaming on all adapters once hdd get hidden ssid rsp */
15050 wlan_hdd_enable_roaming(adapter);
15051}
15052
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015053/* Register the module init/exit functions */
15054module_init(hdd_module_init);
15055module_exit(hdd_module_exit);
15056
15057MODULE_LICENSE("Dual BSD/GPL");
15058MODULE_AUTHOR("Qualcomm Atheros, Inc.");
15059MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
15060
Srinivas Girigowda841da292018-02-21 16:33:00 -080015061static const struct kernel_param_ops con_mode_ops = {
15062 .set = con_mode_handler,
15063 .get = param_get_int,
15064};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015065
Srinivas Girigowda841da292018-02-21 16:33:00 -080015066static const struct kernel_param_ops con_mode_ftm_ops = {
15067 .set = con_mode_handler_ftm,
15068 .get = param_get_int,
15069};
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053015070
Nirav Shah6aeecf92019-02-13 14:05:03 +053015071#ifdef WLAN_FEATURE_EPPING
15072static const struct kernel_param_ops con_mode_epping_ops = {
15073 .set = con_mode_handler_epping,
15074 .get = param_get_int,
15075};
15076#endif
15077
Nirav Shah73713f72018-05-17 14:50:41 +053015078#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080015079static const struct kernel_param_ops con_mode_monitor_ops = {
15080 .set = con_mode_handler_monitor,
15081 .get = param_get_int,
15082};
Nirav Shah73713f72018-05-17 14:50:41 +053015083#endif
Ravi Joshia307f632017-07-17 23:41:41 -070015084
Srinivas Girigowda841da292018-02-21 16:33:00 -080015085static const struct kernel_param_ops fwpath_ops = {
15086 .set = fwpath_changed_handler,
15087 .get = param_get_string,
15088};
15089
15090module_param_cb(con_mode, &con_mode_ops, &con_mode,
15091 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
15092
15093module_param_cb(con_mode_ftm, &con_mode_ftm_ops, &con_mode_ftm,
15094 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
15095
Nirav Shah6aeecf92019-02-13 14:05:03 +053015096#ifdef WLAN_FEATURE_EPPING
15097module_param_cb(con_mode_epping, &con_mode_epping_ops,
15098 &con_mode_epping, 0644);
15099#endif
15100
Nirav Shah73713f72018-05-17 14:50:41 +053015101#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080015102module_param_cb(con_mode_monitor, &con_mode_monitor_ops, &con_mode_monitor,
15103 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Nirav Shah73713f72018-05-17 14:50:41 +053015104#endif
Srinivas Girigowda841da292018-02-21 16:33:00 -080015105
15106module_param_cb(fwpath, &fwpath_ops, &fwpath,
15107 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080015108
15109module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
15110
15111module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
15112
15113module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);
Dustin Brown4bbd5462019-03-22 11:18:13 -070015114
15115static int timer_multiplier_get_handler(char *buffer,
15116 const struct kernel_param *kp)
15117{
15118 return scnprintf(buffer, PAGE_SIZE, "%u", qdf_timer_get_multiplier());
15119}
15120
15121static int timer_multiplier_set_handler(const char *kmessage,
15122 const struct kernel_param *kp)
15123{
15124 QDF_STATUS status;
15125 uint32_t scalar;
15126
15127 status = qdf_uint32_parse(kmessage, &scalar);
15128 if (QDF_IS_STATUS_ERROR(status))
15129 return qdf_status_to_os_return(status);
15130
15131 if (!cfg_in_range(CFG_TIMER_MULTIPLIER, scalar))
15132 return -ERANGE;
15133
15134 qdf_timer_set_multiplier(scalar);
15135
15136 return 0;
15137}
15138
15139static const struct kernel_param_ops timer_multiplier_ops = {
15140 .get = timer_multiplier_get_handler,
15141 .set = timer_multiplier_set_handler,
15142};
15143
15144module_param_cb(timer_multiplier, &timer_multiplier_ops, NULL, 0644);
15145