blob: c63884c4af2be3a4a59410b81579d768aa9475f6 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Dustin Browndb2a8be2017-12-20 11:49:56 -08002 * Copyright (c) 2012-2018 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
7 * copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080019/**
20 * DOC: wlan_hdd_main.c
21 *
22 * WLAN Host Device Driver implementation
23 *
24 */
25
26/* Include Files */
Dustin Brown84f46ea2018-02-15 11:57:36 -080027#include "cfg_ucfg_api.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080028#include <wlan_hdd_includes.h>
29#include <cds_api.h>
30#include <cds_sched.h>
Arun Khandavallifae92942016-08-01 13:31:08 +053031#include <linux/cpu.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080032#include <linux/etherdevice.h>
33#include <linux/firmware.h>
34#include <wlan_hdd_tx_rx.h>
35#include <wni_api.h>
36#include <wlan_hdd_cfg.h>
37#include <wlan_ptt_sock_svc.h>
38#include <dbglog_host.h>
39#include <wlan_logging_sock_svc.h>
Qiwei Caiad9b01c2018-07-09 17:21:31 +080040#include <wlan_roam_debug.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080041#include <wlan_hdd_wowl.h>
42#include <wlan_hdd_misc.h>
43#include <wlan_hdd_wext.h>
44#include "wlan_hdd_trace.h"
45#include "wlan_hdd_ioctl.h"
46#include "wlan_hdd_ftm.h"
47#include "wlan_hdd_power.h"
48#include "wlan_hdd_stats.h"
Prashanth Bhatta527fd752016-04-28 12:35:23 -070049#include "wlan_hdd_scan.h"
Naveen Rawate02f8f52018-04-05 11:58:04 -070050#include <wlan_osif_request_manager.h>
Dustin Brown26b3d042017-12-21 11:13:27 -080051#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4bc0a622017-12-06 15:56:50 -080052#include "qdf_debug_domain.h"
Dustin Brown26b3d042017-12-21 11:13:27 -080053#endif
Dustin Brownd4241942018-02-26 12:51:37 -080054#include "qdf_str.h"
55#include "qdf_trace.h"
56#include "qdf_types.h"
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070057#include <cdp_txrx_peer_ops.h>
Dhanashri Atrea8f82f22017-01-23 12:58:24 -080058#include <cdp_txrx_misc.h>
Mohit Khannaca4173b2017-09-12 21:52:19 -070059#include <cdp_txrx_stats.h>
bings0e03a982018-05-09 08:40:59 +080060#include "cdp_txrx_flow_ctrl_legacy.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080061
62#include <net/addrconf.h>
63#include <linux/wireless.h>
64#include <net/cfg80211.h>
65#include <linux/inetdevice.h>
66#include <net/addrconf.h>
67#include "wlan_hdd_cfg80211.h"
68#include "wlan_hdd_ext_scan.h"
69#include "wlan_hdd_p2p.h"
70#include <linux/rtnetlink.h>
71#include "sap_api.h"
72#include <linux/semaphore.h>
73#include <linux/ctype.h>
74#include <linux/compat.h>
Arunk Khandavalli830c9692018-03-22 12:17:40 +053075#include <linux/reboot.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080076#ifdef MSM_PLATFORM
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080077#include <soc/qcom/subsystem_restart.h>
78#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080079#include <wlan_hdd_hostapd.h>
80#include <wlan_hdd_softap_tx_rx.h>
Jeff Johnson8bb61112018-03-31 13:33:54 -070081#include <wlan_hdd_green_ap.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080082#include "cfg_api.h"
83#include "qwlan_version.h"
84#include "wma_types.h"
85#include "wlan_hdd_tdls.h"
86#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053087#include "cds_regdomain.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080088#endif /* FEATURE_WLAN_CH_AVOID */
Dustin Brownce46d1d2017-08-15 13:34:24 -070089#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070090#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -080091#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080092#include "wlan_hdd_nan.h"
93#include "wlan_hdd_debugfs.h"
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053094#include "wlan_hdd_debugfs_csr.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080095#include "wlan_hdd_driver_ops.h"
96#include "epping_main.h"
Poddar, Siddarth34872782017-08-10 14:08:51 +053097#include "wlan_hdd_data_stall_detection.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080098
99#include <wlan_hdd_ipa.h>
100#include "hif.h"
101#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800102#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700103#include "wlan_hdd_tsf.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530104#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700105#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700106#include "wlan_hdd_lpass.h"
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530107#include "nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700108#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530109#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800110#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800111#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530112#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800113#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800114#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530115#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530116#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800117#include "os_if_wifi_pos.h"
118#include "wifi_pos_api.h"
119#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800120#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700121#include "os_if_nan.h"
122#include "nan_public_structs.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700123#include "wlan_reg_ucfg_api.h"
bings81fe50a2017-11-27 14:33:26 +0800124#include "wlan_dfs_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700125#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530126#include "sme_power_save_api.h"
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +0530127#include "enet.h"
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700128#include <cdp_txrx_cmn_struct.h>
Mohit Khanna70322002018-05-15 19:21:32 -0700129#include <dp_txrx.h>
Amar Singhal0928b192017-12-01 10:50:54 -0800130#include "wlan_hdd_sysfs.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530131#include "wlan_disa_ucfg_api.h"
Wu Gao52084c12018-05-17 20:47:11 +0800132#include "wlan_disa_obj_mgmt_api.h"
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +0530133#include "wlan_action_oui_ucfg_api.h"
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +0530134#include "wlan_ipa_ucfg_api.h"
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530135#include <target_if.h>
Alok Kumarb64650c2018-03-23 17:05:11 +0530136#include "wlan_hdd_nud_tracking.h"
Nachiket Kukaded0dd62e2018-05-21 18:39:22 +0530137#include "wlan_hdd_apf.h"
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -0700138#include "wlan_hdd_twt.h"
Rachit Kankane0dc3e852018-05-07 17:33:42 +0530139#include "qc_sap_ioctl.h"
Sandeep Puligillac5609d52018-05-17 19:23:41 -0700140#include "wlan_mlme_main.h"
Wu Gaoe5689792018-07-05 19:20:13 +0800141#include "wlan_p2p_cfg_api.h"
Wu Gaobdb7f272018-07-05 19:33:26 +0800142#include "wlan_tdls_cfg_api.h"
Qiwei Caie689a262018-07-26 15:50:22 +0800143#include <wlan_hdd_rssi_monitor.h>
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +0530144#include "wlan_mlme_ucfg_api.h"
145#include "wlan_mlme_public_struct.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530146#ifdef CNSS_GENL
147#include <net/cnss_nl.h>
148#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800149#include "wlan_reg_ucfg_api.h"
Zhang Qian47e22ce2018-01-04 15:38:38 +0800150#include "wlan_ocb_ucfg_api.h"
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -0800151#include <wlan_hdd_spectralscan.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800152#ifdef MODULE
153#define WLAN_MODULE_NAME module_name(THIS_MODULE)
154#else
155#define WLAN_MODULE_NAME "wlan"
156#endif
157
158#ifdef TIMER_MANAGER
159#define TIMER_MANAGER_STR " +TIMER_MANAGER"
160#else
161#define TIMER_MANAGER_STR ""
162#endif
163
164#ifdef MEMORY_DEBUG
165#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
166#else
167#define MEMORY_DEBUG_STR ""
168#endif
169
Dustin Brownc1034df2018-02-07 14:51:32 -0800170#ifdef PANIC_ON_BUG
171#define PANIC_ON_BUG_STR " +PANIC_ON_BUG"
172#else
173#define PANIC_ON_BUG_STR ""
174#endif
175
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530176bool g_is_system_reboot_triggered;
Sachin Ahujadddd2632017-03-07 19:07:24 +0530177int wlan_start_ret_val;
178static DECLARE_COMPLETION(wlan_start_comp);
179static unsigned int dev_num = 1;
180static struct cdev wlan_hdd_state_cdev;
181static struct class *class;
182static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530183#ifndef MODULE
184static struct gwlan_loader *wlan_loader;
185static ssize_t wlan_boot_cb(struct kobject *kobj,
186 struct kobj_attribute *attr,
187 const char *buf, size_t count);
188struct gwlan_loader {
189 bool loaded_state;
190 struct kobject *boot_wlan_obj;
191 struct attribute_group *attr_group;
192};
193
194static struct kobj_attribute wlan_boot_attribute =
195 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
196
197static struct attribute *attrs[] = {
198 &wlan_boot_attribute.attr,
199 NULL,
200};
201
202#define MODULE_INITIALIZED 1
203#endif
204
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530205#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
206#define MAX_OPS_NAME_STRING_SIZE 20
Rajeev Kumar6d0b2ea2017-12-26 17:55:33 -0800207#define RATE_LIMIT_ERROR_LOG (256)
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530208
209static qdf_timer_t hdd_drv_ops_inactivity_timer;
Dustin Brown45ed4bb2017-12-18 12:00:13 -0800210static struct task_struct *hdd_drv_ops_task;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530211static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
212
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800213/* the Android framework expects this param even though we don't use it */
214#define BUF_LEN 20
215static char fwpath_buffer[BUF_LEN];
216static struct kparam_string fwpath = {
217 .string = fwpath_buffer,
218 .maxlen = BUF_LEN,
219};
220
221static char *country_code;
222static int enable_11d = -1;
223static int enable_dfs_chan_scan = -1;
224
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800225/*
226 * spinlock for synchronizing asynchronous request/response
227 * (full description of use in wlan_hdd_main.h)
228 */
229DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530230DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800231
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800232#define WLAN_NLINK_CESIUM 30
233
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530234static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800235
236#define WOW_MAX_FILTER_LISTS 1
237#define WOW_MAX_FILTERS_PER_LIST 4
238#define WOW_MIN_PATTERN_SIZE 6
239#define WOW_MAX_PATTERN_SIZE 64
240
Bala Venkatesh110b03e2018-07-10 16:02:08 +0530241/* max peer can be tdls peers + self peer + bss peer */
242#define HDD_MAX_VDEV_PEER_COUNT (HDD_MAX_NUM_TDLS_STA + 2)
Sourav Mohapatra808e3d42018-07-04 09:34:23 +0530243#define IS_IDLE_STOP (!cds_is_driver_unloading() && \
244 !cds_is_driver_recovering() && !cds_is_driver_loading())
Bala Venkatesh110b03e2018-07-10 16:02:08 +0530245
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800246#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
247static const struct wiphy_wowlan_support wowlan_support_reg_init = {
248 .flags = WIPHY_WOWLAN_ANY |
249 WIPHY_WOWLAN_MAGIC_PKT |
250 WIPHY_WOWLAN_DISCONNECT |
251 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
252 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
253 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
254 WIPHY_WOWLAN_4WAY_HANDSHAKE |
255 WIPHY_WOWLAN_RFKILL_RELEASE,
256 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
257 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
258 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
259};
260#endif
261
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700262static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
263 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
264 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
265 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
266 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
267 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
268 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
269 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
270 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
271 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
272 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
273 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
274 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
275 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
276 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
277 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
278 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
279 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
280 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
281 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
282 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
283 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
284 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
285 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
286 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
287 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
288 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
289 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
290 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
291 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
292 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
293 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
294 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
295 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
296 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700297 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700298 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700299 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530300 [QDF_MODULE_ID_GREEN_AP] = {QDF_TRACE_LEVEL_ALL},
Zhang Qian47e22ce2018-01-04 15:38:38 +0800301 [QDF_MODULE_ID_OCB] = {QDF_TRACE_LEVEL_ALL},
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530302 [QDF_MODULE_ID_IPA] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +0530303 [QDF_MODULE_ID_ACTION_OUI] = {QDF_TRACE_LEVEL_ALL},
Dustin Brown84f46ea2018-02-15 11:57:36 -0800304 [QDF_MODULE_ID_CONFIG] = {QDF_TRACE_LEVEL_ALL},
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +0530305 [QDF_MODULE_ID_MLME] = {QDF_TRACE_LEVEL_ALL},
Ashish Kumar Dhanotiya8d039c82018-07-11 20:41:14 +0530306 [QDF_MODULE_ID_TARGET] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700307};
308
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530309struct notifier_block hdd_netdev_notifier;
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530310struct notifier_block system_reboot_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800311
312struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800313#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700314static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800315#endif
316
Sachin Ahujadddd2632017-03-07 19:07:24 +0530317void hdd_start_complete(int ret)
318{
319 wlan_start_ret_val = ret;
320
321 complete(&wlan_start_comp);
322}
323
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800324/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530325 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700326 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530327 *
328 * Return: none
329 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700330static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530331{
Jeff Johnson9d295242017-08-29 14:39:48 -0700332 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530333
Dustin Brown920397d2017-12-13 16:27:50 -0800334 hdd_for_each_adapter(hdd_ctx, adapter)
335 hdd_send_rps_ind(adapter);
Nirav Shahbd36b062016-07-18 11:12:59 +0530336}
337
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530338#ifdef QCA_HL_NETDEV_FLOW_CONTROL
339void wlan_hdd_mod_fc_timer(struct hdd_adapter *adapter,
340 enum netif_action_type action)
341{
342 if (!adapter->tx_flow_timer_initialized)
343 return;
344
345 if (action == WLAN_WAKE_NON_PRIORITY_QUEUE) {
346 qdf_mc_timer_stop(&adapter->tx_flow_control_timer);
347 } else if (action == WLAN_STOP_NON_PRIORITY_QUEUE) {
348 QDF_STATUS status =
349 qdf_mc_timer_start(&adapter->tx_flow_control_timer,
350 WLAN_HDD_TX_FLOW_CONTROL_OS_Q_BLOCK_TIME);
351
352 if (!QDF_IS_STATUS_SUCCESS(status))
353 hdd_err("Failed to start tx_flow_control_timer");
354 else
355 adapter->
356 hdd_stats.tx_rx_stats.txflow_timer_cnt++;
357
358 adapter->hdd_stats.tx_rx_stats.txflow_pause_cnt++;
359 adapter->hdd_stats.tx_rx_stats.is_txflow_paused = true;
360 }
361}
362#endif /* QCA_HL_NETDEV_FLOW_CONTROL */
363
Nirav Shahbd36b062016-07-18 11:12:59 +0530364/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800365 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
366 * @vdev_id: vdev_id
367 * @action: action type
368 * @reason: reason type
369 *
370 * Return: none
371 */
372void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
373 enum netif_action_type action, enum netif_reason_type reason)
374{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700375 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700376 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800377
378 if (!hdd_ctx) {
379 hdd_err("hdd ctx is NULL");
380 return;
381 }
382 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530383 wlan_hdd_mod_fc_timer(adapter, action);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800384 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800385}
386
387/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700388 * Store WLAN driver version and timestamp info in global variables such that
389 * crash debugger can extract them from driver debug symbol and crashdump for
390 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800391 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800392#ifdef BUILD_TAG
393uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR "; " BUILD_TAG;
394#else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800395uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700396#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800397
398/**
399 * hdd_device_mode_to_string() - return string conversion of device mode
400 * @device_mode: device mode
401 *
402 * This utility function helps log string conversion of device mode.
403 *
404 * Return: string conversion of device mode, if match found;
405 * "Unknown" otherwise.
406 */
407const char *hdd_device_mode_to_string(uint8_t device_mode)
408{
409 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800410 CASE_RETURN_STRING(QDF_STA_MODE);
411 CASE_RETURN_STRING(QDF_SAP_MODE);
412 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
413 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
414 CASE_RETURN_STRING(QDF_FTM_MODE);
415 CASE_RETURN_STRING(QDF_IBSS_MODE);
416 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
417 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700418 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800419 default:
420 return "Unknown";
421 }
422}
423
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530424/**
Liangwei Dong17bf2662018-01-05 02:02:05 -0500425 * hdd_get_valid_chan() - return current chan list from regulatory.
426 * @hdd_ctx: HDD context
427 * @chan_list: buf hold returned chan list
428 * @chan_num: input buf size and output returned chan num
429 *
430 * This function helps get current available chan list from regulatory
431 * module. It excludes the "disabled" and "invalid" channels.
432 *
433 * Return: 0 for success.
434 */
435static int hdd_get_valid_chan(struct hdd_context *hdd_ctx,
436 uint8_t *chan_list,
437 uint32_t *chan_num)
438{
439 int i = 0, j = 0;
440 struct regulatory_channel *cur_chan_list;
441 struct wlan_objmgr_pdev *pdev;
442
443 if (!hdd_ctx || !hdd_ctx->hdd_pdev || !chan_list || !chan_num)
444 return -EINVAL;
445
446 pdev = hdd_ctx->hdd_pdev;
447 cur_chan_list = qdf_mem_malloc(NUM_CHANNELS *
448 sizeof(struct regulatory_channel));
449 if (!cur_chan_list)
450 return -ENOMEM;
451
452 if (wlan_reg_get_current_chan_list(pdev, cur_chan_list) !=
453 QDF_STATUS_SUCCESS) {
454 qdf_mem_free(cur_chan_list);
455 return -EINVAL;
456 }
457
458 for (i = 0; i < NUM_CHANNELS; i++) {
459 uint32_t ch = cur_chan_list[i].chan_num;
460 enum channel_state state = wlan_reg_get_channel_state(pdev,
461 ch);
462
463 if (state != CHANNEL_STATE_DISABLE &&
464 state != CHANNEL_STATE_INVALID &&
465 j < *chan_num) {
466 chan_list[j] = (uint8_t)ch;
467 j++;
468 }
469 }
470 *chan_num = j;
471 qdf_mem_free(cur_chan_list);
472 return 0;
473}
474
475/**
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530476 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
477 * @adapter: HDD adapter
478 * @chan_number: Channel number
479 * @chan_bw: Bandwidth
480 *
481 * Checks if the given bandwidth is valid for the given channel number.
482 *
483 * Return: 0 for success, non-zero for failure
484 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700485int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530486 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800487 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530488{
Liangwei Dong17bf2662018-01-05 02:02:05 -0500489 uint8_t chan[NUM_CHANNELS];
490 uint32_t len = NUM_CHANNELS, i;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530491 bool found = false;
Jeff Johnson16528362018-06-14 12:34:16 -0700492 mac_handle_t mac_handle;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500493 int ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530494
Jeff Johnson16528362018-06-14 12:34:16 -0700495 mac_handle = hdd_adapter_get_mac_handle(adapter);
496 if (!mac_handle) {
497 hdd_err("Invalid MAC handle");
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530498 return -EINVAL;
499 }
500
Liangwei Dong17bf2662018-01-05 02:02:05 -0500501 ret = hdd_get_valid_chan(adapter->hdd_ctx, chan,
502 &len);
503 if (ret) {
504 hdd_err("error %d in getting valid channel list", ret);
505 return ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530506 }
507
508 for (i = 0; i < len; i++) {
509 if (chan[i] == chan_number) {
510 found = true;
511 break;
512 }
513 }
514
515 if (found == false) {
516 hdd_err("Channel not in driver's valid channel list");
517 return -EOPNOTSUPP;
518 }
519
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700520 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
521 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530522 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
523 return -EINVAL;
524 }
525
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700526 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530527 if (chan_bw == CH_WIDTH_80MHZ) {
528 hdd_err("BW80 not possible in 2.4GHz band");
529 return -EINVAL;
530 }
531 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
532 (chan_bw != CH_WIDTH_MAX)) {
533 hdd_err("Only BW20 possible on channel 14");
534 return -EINVAL;
535 }
536 }
537
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700538 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530539 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
540 (chan_bw != CH_WIDTH_MAX)) {
541 hdd_err("Only BW20 possible on channel 165");
542 return -EINVAL;
543 }
544 }
545
546 return 0;
547}
548
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530549/**
550 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
551 *
552 * Block the unloading of the driver (or) interface up until the
553 * cds recovery is completed
554 *
555 * Return: true for recovery completion else false
556 */
557static bool hdd_wait_for_recovery_completion(void)
558{
559 int retry = 0;
560
561 /* Wait for recovery to complete */
562 while (cds_is_driver_recovering()) {
563 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
564 hdd_err("Recovery in progress; wait here!!!");
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530565
566 if (g_is_system_reboot_triggered) {
567 hdd_info("System Reboot happening ignore unload!!");
568 return false;
569 }
570
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530571 msleep(1000);
572 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
573 hdd_err("SSR never completed, error");
574 /*
575 * Trigger the bug_on in the internal builds, in the
576 * customer builds self-recovery will be enabled
577 * in those cases just return error.
578 */
579 if (cds_is_self_recovery_enabled())
580 return false;
581 QDF_BUG(0);
582 }
583 }
584
585 hdd_info("Recovery completed successfully!");
586 return true;
587}
588
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530589
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800590static int __hdd_netdev_notifier_call(struct notifier_block *nb,
591 unsigned long state, void *data)
592{
593#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
594 struct netdev_notifier_info *dev_notif_info = data;
595 struct net_device *dev = dev_notif_info->dev;
596#else
597 struct net_device *dev = data;
598#endif
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530599 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700600 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800601
Dustin Brownfdf17c12018-03-14 12:55:34 -0700602 hdd_enter_dev(dev);
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800603
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800604 if (!dev->ieee80211_ptr) {
Dustin Brownaeb55642018-07-30 17:20:32 -0700605 hdd_debug("ieee80211_ptr is null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800606 return NOTIFY_DONE;
607 }
608
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530609 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
610 if (!hdd_ctx) {
611 hdd_err("HDD Context is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800612 return NOTIFY_DONE;
613 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800614
615 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -0700616 hdd_debug("%s: Driver module is closed", __func__);
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800617 return NOTIFY_DONE;
618 }
619
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530620 /* Make sure that this callback corresponds to our device. */
621 adapter = hdd_get_adapter_by_iface_name(hdd_ctx, dev->name);
622 if (!adapter) {
Dustin Brownaeb55642018-07-30 17:20:32 -0700623 hdd_debug("failed to look up adapter for '%s'", dev->name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800624 return NOTIFY_DONE;
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530625 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800626
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530627 if (adapter != WLAN_HDD_GET_PRIV_PTR(dev)) {
628 hdd_err("HDD adapter mismatch!");
629 return NOTIFY_DONE;
630 }
631
Dustin Brownaeb55642018-07-30 17:20:32 -0700632 if (cds_is_driver_recovering()) {
633 hdd_debug("Driver is recovering");
634 return NOTIFY_DONE;
635 }
636
637 if (cds_is_driver_in_bad_state()) {
638 hdd_debug("Driver is in failed recovery state");
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530639 return NOTIFY_DONE;
640 }
641
642 hdd_debug("%s New Net Device State = %lu", dev->name, state);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800643
644 switch (state) {
645 case NETDEV_REGISTER:
646 break;
647
648 case NETDEV_UNREGISTER:
649 break;
650
651 case NETDEV_UP:
Jeff Johnson16528362018-06-14 12:34:16 -0700652 sme_ch_avoid_update_req(hdd_ctx->mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800653 break;
654
655 case NETDEV_DOWN:
656 break;
657
658 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700659 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800660 complete(&adapter->linkup_event_var);
661 break;
662
663 case NETDEV_GOING_DOWN:
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700664 if (ucfg_scan_get_vdev_status(adapter->hdd_vdev) !=
665 SCAN_NOT_IN_PROGRESS) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530666 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -0700667 adapter->session_id, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800668 }
Min Liu9be5d4a2018-05-17 11:51:53 +0800669 cds_flush_work(&adapter->scan_block_work);
670 /* Need to clean up blocked scan request */
671 wlan_hdd_cfg80211_scan_block_cb(&adapter->scan_block_work);
Min Liu9be5d4a2018-05-17 11:51:53 +0800672 hdd_debug("Scan is not Pending from user");
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530673 /*
674 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
675 * of return status of hdd_stop call, kernel resets the IFF_UP
676 * flag after which driver does not send the cfg80211_scan_done.
677 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
678 */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +0530679 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800680 break;
681
682 default:
683 break;
684 }
685
686 return NOTIFY_DONE;
687}
688
689/**
690 * hdd_netdev_notifier_call() - netdev notifier callback function
691 * @nb: pointer to notifier block
692 * @state: state
693 * @ndev: ndev pointer
694 *
695 * Return: 0 on success, error number otherwise.
696 */
697static int hdd_netdev_notifier_call(struct notifier_block *nb,
698 unsigned long state,
699 void *ndev)
700{
701 int ret;
702
703 cds_ssr_protect(__func__);
704 ret = __hdd_netdev_notifier_call(nb, state, ndev);
705 cds_ssr_unprotect(__func__);
706
707 return ret;
708}
709
710struct notifier_block hdd_netdev_notifier = {
711 .notifier_call = hdd_netdev_notifier_call,
712};
713
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530714static int system_reboot_notifier_call(struct notifier_block *nb,
715 unsigned long msg_type, void *_unused)
716{
717 switch (msg_type) {
718 case SYS_DOWN:
719 case SYS_HALT:
720 case SYS_POWER_OFF:
721 g_is_system_reboot_triggered = true;
722 hdd_info("reboot, reason: %ld", msg_type);
723 break;
724 default:
725 break;
726 }
727
728 return NOTIFY_OK;
729}
730
731struct notifier_block system_reboot_notifier = {
732 .notifier_call = system_reboot_notifier_call,
733};
734
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800735/* variable to hold the insmod parameters */
736static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800737
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530738static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700739int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530740
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800741/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800742static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800743
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530744/**
745 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
746 * @ch_width: NL channel width
747 *
748 * Converts the NL channel width to the driver's internal representation
749 *
750 * Return: Converted channel width. In case of non matching NL channel width,
751 * CH_WIDTH_MAX will be returned.
752 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800753enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530754{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800755 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700756
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800757 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530758 switch (ch_width) {
759 case NL80211_CHAN_WIDTH_20_NOHT:
760 case NL80211_CHAN_WIDTH_20:
761 return CH_WIDTH_20MHZ;
762 case NL80211_CHAN_WIDTH_40:
763 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530764 case NL80211_CHAN_WIDTH_80:
765 return CH_WIDTH_80MHZ;
766 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800767 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
768 return CH_WIDTH_80P80MHZ;
769 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
770 return CH_WIDTH_160MHZ;
771 else
772 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530773 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800774 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
775 return CH_WIDTH_160MHZ;
776 else
777 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530778 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800779 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530780 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800781 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530782 default:
783 hdd_err("Invalid channel width %d, setting to default",
784 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800785 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530786 }
787}
788
Jeff Johnson16528362018-06-14 12:34:16 -0700789uint8_t wlan_hdd_find_opclass(mac_handle_t mac_handle, uint8_t channel,
790 uint8_t bw_offset)
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530791{
792 uint8_t opclass = 0;
793
Jeff Johnson16528362018-06-14 12:34:16 -0700794 sme_get_opclass(mac_handle, channel, bw_offset, &opclass);
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530795 return opclass;
796}
797
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800798/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530799 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530800 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800801 * @bitmask: Bitmask of log levels to be enabled
802 *
803 * Called immediately after the cfg.ini is read in order to configure
804 * the desired trace levels.
805 *
806 * Return: None
807 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530808int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800809{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530810 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530811 int qdf_print_idx = -1;
812 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800813 /*
814 * if the bitmask is the default value, then a bitmask was not
815 * specified in cfg.ini, so leave the logging level alone (it
816 * will remain at the "compiled in" default value)
817 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700818 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530819 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800820
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530821 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800822
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530823 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530824 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530825 QDF_TRACE_LEVEL_NONE, 0);
826
827 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530828 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800829 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530830 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800831 while (0 != bitmask) {
832 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530833 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530834 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530835 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530836 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800837 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700838
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800839 level++;
840 bitmask >>= 1;
841 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530842 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800843}
844
Dustin Brownda351e32018-07-23 15:48:22 -0700845int __wlan_hdd_validate_context(struct hdd_context *hdd_ctx, const char *func)
Chris Guo1751acf2017-07-03 14:09:01 +0800846{
Dustin Brownda351e32018-07-23 15:48:22 -0700847 if (!hdd_ctx) {
848 hdd_err("HDD context is null (via %s)", func);
849 return -ENODEV;
850 }
851
852 if (!hdd_ctx->config) {
853 hdd_err("HDD config is null (via %s)", func);
Chris Guo1751acf2017-07-03 14:09:01 +0800854 return -ENODEV;
855 }
856
857 if (cds_is_driver_recovering()) {
Dustin Brownda351e32018-07-23 15:48:22 -0700858 hdd_debug("Recovery in progress (via %s); state:0x%x",
859 func, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800860 return -EAGAIN;
861 }
862
Yue Ma9f275d92017-09-14 16:58:41 -0700863 if (cds_is_load_or_unload_in_progress()) {
Dustin Brownda351e32018-07-23 15:48:22 -0700864 hdd_debug("Load/unload in progress (via %s); state:0x%x",
865 func, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800866 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -0700867 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530868
Dustin Brownda351e32018-07-23 15:48:22 -0700869 if (hdd_ctx->start_modules_in_progress) {
870 hdd_debug("Start modules in progress (via %s)", func);
871 return -EAGAIN;
872 }
873
874 if (hdd_ctx->stop_modules_in_progress) {
875 hdd_debug("Stop modules in progress (via %s)", func);
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530876 return -EAGAIN;
877 }
878
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530879 if (cds_is_driver_in_bad_state()) {
Dustin Brownda351e32018-07-23 15:48:22 -0700880 hdd_debug("Driver in bad state (via %s); state:0x%x",
881 func, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +0530882 return -EAGAIN;
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530883 }
884
Arunk Khandavalli2859fa12018-02-14 10:46:26 +0530885 if (cds_is_fw_down()) {
Dustin Brownda351e32018-07-23 15:48:22 -0700886 hdd_debug("FW is down (via %s); state:0x%x",
887 func, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +0530888 return -EAGAIN;
Arunk Khandavalli2859fa12018-02-14 10:46:26 +0530889 }
890
Liangwei Dong858feb12018-05-21 01:52:46 -0400891 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
Dustin Brownda351e32018-07-23 15:48:22 -0700892 hdd_debug("Driver mode change in progress (via %s)", func);
Liangwei Dong858feb12018-05-21 01:52:46 -0400893 return -EAGAIN;
894 }
895
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800896 return 0;
897}
898
Dustin Browna8700cc2018-08-07 12:04:47 -0700899int __hdd_validate_adapter(struct hdd_adapter *adapter, const char *func)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700900{
901 if (!adapter) {
Dustin Browna8700cc2018-08-07 12:04:47 -0700902 hdd_err("adapter is null (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700903 return -EINVAL;
904 }
905
906 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Dustin Browna8700cc2018-08-07 12:04:47 -0700907 hdd_err("bad adapter magic (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700908 return -EINVAL;
909 }
910
911 if (!adapter->dev) {
Dustin Browna8700cc2018-08-07 12:04:47 -0700912 hdd_err("adapter net_device is null (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700913 return -EINVAL;
914 }
915
916 if (!(adapter->dev->flags & IFF_UP)) {
Dustin Browna8700cc2018-08-07 12:04:47 -0700917 hdd_debug_rl("adapter '%s' is not up (via %s)",
918 adapter->dev->name, func);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700919 return -EAGAIN;
920 }
921
Dustin Browna8700cc2018-08-07 12:04:47 -0700922 return __wlan_hdd_validate_session_id(adapter->session_id, func);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700923}
924
Dustin Brown63500612018-08-07 11:36:09 -0700925int __wlan_hdd_validate_session_id(uint8_t session_id, const char *func)
926{
927 if (session_id == CSR_SESSION_ID_INVALID) {
928 hdd_debug_rl("adapter is not up (via %s)", func);
929 return -EINVAL;
930 }
931
932 if (session_id >= CSR_ROAM_SESSION_MAX) {
933 hdd_err("bad session Id:%u (via %s)", session_id, func);
934 return -EINVAL;
935 }
936
937 return 0;
938}
939
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800940/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530941 * wlan_hdd_validate_modules_state() - Check modules status
942 * @hdd_ctx: HDD context pointer
943 *
944 * Check's the driver module's state and returns true if the
945 * modules are enabled returns false if modules are closed.
946 *
947 * Return: True if modules are enabled or false.
948 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700949bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530950{
951 mutex_lock(&hdd_ctx->iface_change_lock);
952 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
953 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown5e89ef82018-03-14 11:50:23 -0700954 hdd_info("Modules not enabled, Present status: %d",
955 hdd_ctx->driver_status);
Arun Khandavallica892f62017-05-26 14:25:50 +0530956 return false;
957 }
958 mutex_unlock(&hdd_ctx->iface_change_lock);
959 return true;
960}
961
962/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800963 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700964 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800965 *
966 * This function sets the IBSS power save config parameters to WMA
967 * which will send it to firmware if FW supports IBSS power save
968 * before vdev start.
969 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530970 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800971 * on failure.
972 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700973QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800974{
975 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700976 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800977
978 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700979 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530980 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800981 }
982
Jeff Johnson1b780e42017-10-31 14:11:45 -0700983 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800984 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
985 hdd_ctx->config->ibssATIMWinSize,
986 VDEV_CMD);
987 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -0700988 hdd_err("atim window set failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530989 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800990 }
991
Jeff Johnson1b780e42017-10-31 14:11:45 -0700992 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800993 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
994 hdd_ctx->config->isIbssPowerSaveAllowed,
995 VDEV_CMD);
996 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -0700997 hdd_err("power save allow failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700998 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530999 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001000 }
1001
Jeff Johnson1b780e42017-10-31 14:11:45 -07001002 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001003 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
1004 hdd_ctx->config->
1005 isIbssPowerCollapseAllowed, VDEV_CMD);
1006 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001007 hdd_err("power collapse allow failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001008 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301009 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001010 }
1011
Jeff Johnson1b780e42017-10-31 14:11:45 -07001012 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001013 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
1014 hdd_ctx->config->isIbssAwakeOnTxRx,
1015 VDEV_CMD);
1016 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001017 hdd_err("set awake on tx/rx failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301018 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001019 }
1020
Jeff Johnson1b780e42017-10-31 14:11:45 -07001021 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001022 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
1023 hdd_ctx->config->ibssInactivityCount,
1024 VDEV_CMD);
1025 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001026 hdd_err("set inactivity time failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301027 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001028 }
1029
Jeff Johnson1b780e42017-10-31 14:11:45 -07001030 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001031 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
1032 hdd_ctx->config->ibssTxSpEndInactivityTime,
1033 VDEV_CMD);
1034 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001035 hdd_err("set txsp end failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001036 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301037 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001038 }
1039
Jeff Johnson1b780e42017-10-31 14:11:45 -07001040 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001041 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
1042 hdd_ctx->config->ibssPsWarmupTime,
1043 VDEV_CMD);
1044 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001045 hdd_err("set ps warmup failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001046 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301047 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001048 }
1049
Jeff Johnson1b780e42017-10-31 14:11:45 -07001050 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001051 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
1052 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
1053 VDEV_CMD);
1054 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001055 hdd_err("set 1rx chain atim failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001056 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301057 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001058 }
1059
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301060 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001061}
1062
Yue Macd359b72017-10-03 15:21:00 -07001063#ifdef FEATURE_RUNTIME_PM
1064/**
1065 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
1066 * @hdd_ctx: HDD context
1067 *
1068 * Return: None
1069 */
1070static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
1071{
1072 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1073
Yue Macd359b72017-10-03 15:21:00 -07001074 qdf_runtime_lock_init(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001075 qdf_runtime_lock_init(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001076
1077 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
1078}
1079
1080/**
1081 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1082 * @hdd_ctx: HDD Context
1083 *
1084 * Return: None
1085 */
1086static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1087{
1088 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1089
Yue Macd359b72017-10-03 15:21:00 -07001090 qdf_runtime_lock_deinit(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001091 qdf_runtime_lock_deinit(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001092
1093 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
1094}
1095
Yue Macd359b72017-10-03 15:21:00 -07001096#else /* FEATURE_RUNTIME_PM */
1097static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1098static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Yue Macd359b72017-10-03 15:21:00 -07001099#endif /* FEATURE_RUNTIME_PM */
1100
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001101#define INTF_MACADDR_MASK 0x7
1102
1103/**
1104 * hdd_update_macaddr() - update mac address
1105 * @config: hdd configuration
1106 * @hw_macaddr: mac address
1107 *
1108 * Mac address for multiple virtual interface is found as following
1109 * i) The mac address of the first interface is just the actual hw mac address.
1110 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
1111 * define the mac address for the remaining interfaces and locally
1112 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1113 * supported virtual interfaces, right now this is 0x07 (meaning 8
1114 * interface).
1115 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1116 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1117 *
1118 * Return: None
1119 */
1120void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301121 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001122{
1123 int8_t i;
1124 uint8_t macaddr_b3, tmp_br3;
1125
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301126 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301127 QDF_MAC_ADDR_SIZE);
1128 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301129 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301130 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001131 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1132 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1133 INTF_MACADDR_MASK;
1134 macaddr_b3 += tmp_br3;
1135
1136 /* XOR-ing bit-24 of the mac address. This will give enough
1137 * mac address range before collision
1138 */
1139 macaddr_b3 ^= (1 << 7);
1140
1141 /* Set locally administered bit */
1142 config->intfMacAddr[i].bytes[0] |= 0x02;
1143 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001144 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001145 MAC_ADDRESS_STR, i,
1146 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1147 }
1148}
1149
Kabilan Kannan44a58372017-12-06 18:16:11 -08001150static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1151{
1152 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
1153 struct tdls_start_params tdls_cfg;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001154 struct hdd_config *cfg = hdd_ctx->config;
1155 QDF_STATUS status;
1156
Wu Gaobdb7f272018-07-05 19:33:26 +08001157 cfg_tdls_set_vdev_nss_2g(hdd_ctx->hdd_psoc,
1158 CFG_TDLS_NSS(cfg->vdev_type_nss_2g));
1159 cfg_tdls_set_vdev_nss_5g(hdd_ctx->hdd_psoc,
1160 CFG_TDLS_NSS(cfg->vdev_type_nss_5g));
Kabilan Kannan44a58372017-12-06 18:16:11 -08001161 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
1162 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
1163 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
1164 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
1165 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1166 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1167 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1168 tdls_cfg.tdls_evt_cb_data = psoc;
Jeff Johnson1d40f5b2018-03-02 08:35:53 -08001169 tdls_cfg.tdls_peer_context = hdd_ctx;
1170 tdls_cfg.tdls_reg_peer = hdd_tdls_register_peer;
1171 tdls_cfg.tdls_dereg_peer = hdd_tdls_deregister_peer;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001172 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1173 tdls_cfg.tdls_wmm_cb_data = psoc;
1174 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1175 tdls_cfg.tdls_rx_cb_data = psoc;
1176 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1177
1178 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1179 if (status != QDF_STATUS_SUCCESS) {
1180 hdd_err("failed pmo psoc configuration");
1181 return -EINVAL;
1182 }
1183
1184 hdd_ctx->tdls_umac_comp_active = true;
1185 /* enable napier specific tdls data path */
1186 hdd_ctx->tdls_nap_active = true;
1187
1188 return 0;
1189}
1190
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001191static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001192 struct wma_tgt_services *cfg)
1193{
1194 struct hdd_config *config = hdd_ctx->config;
Wu Gaobdb7f272018-07-05 19:33:26 +08001195#ifdef FEATURE_WLAN_TDLS
1196 bool tdls_support;
1197 bool tdls_off_channel;
1198 bool tdls_buffer_sta;
1199 uint32_t tdls_uapsd_mask;
1200#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001201 /* Set up UAPSD */
1202 config->apUapsdEnabled &= cfg->uapsd;
1203
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001204 /* 11AX mode support */
1205 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1206 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1207 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1208
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001209 /* 11AC mode support */
1210 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1211 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1212 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001213
1214 /* ARP offload: override user setting if invalid */
1215 config->fhostArpOffload &= cfg->arp_offload;
1216
1217#ifdef FEATURE_WLAN_SCAN_PNO
1218 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001219 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001220 if (cfg->pno_offload)
1221 config->PnoOffload = true;
1222#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001223#ifdef FEATURE_WLAN_TDLS
Wu Gaobdb7f272018-07-05 19:33:26 +08001224 cfg_tdls_get_support_enable(hdd_ctx->hdd_psoc, &tdls_support);
1225 cfg_tdls_set_support_enable(hdd_ctx->hdd_psoc,
1226 tdls_support & cfg->en_tdls);
1227
1228 cfg_tdls_get_off_channel_enable(hdd_ctx->hdd_psoc, &tdls_off_channel);
1229 cfg_tdls_set_off_channel_enable(hdd_ctx->hdd_psoc,
1230 tdls_off_channel &&
1231 cfg->en_tdls_offchan);
1232
1233 cfg_tdls_get_buffer_sta_enable(hdd_ctx->hdd_psoc, &tdls_buffer_sta);
1234 cfg_tdls_set_buffer_sta_enable(hdd_ctx->hdd_psoc,
1235 tdls_buffer_sta &&
1236 cfg->en_tdls_uapsd_buf_sta);
1237
1238 cfg_tdls_get_uapsd_mask(hdd_ctx->hdd_psoc, &tdls_uapsd_mask);
1239 if (tdls_uapsd_mask && cfg->en_tdls_uapsd_sleep_sta)
1240 cfg_tdls_set_sleep_sta_enable(hdd_ctx->hdd_psoc, true);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001241 else
Wu Gaobdb7f272018-07-05 19:33:26 +08001242 cfg_tdls_set_sleep_sta_enable(hdd_ctx->hdd_psoc, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001243#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001244#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1245 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1246#endif
Will Huang496b36c2017-07-11 16:38:50 +08001247 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001248 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001249 hdd_update_tdls_config(hdd_ctx);
Jeff Johnson16528362018-06-14 12:34:16 -07001250 sme_update_tgt_services(hdd_ctx->mac_handle, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001251
1252}
1253
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001254/**
1255 * hdd_update_vdev_nss() - sets the vdev nss
1256 * @hdd_ctx: HDD context
1257 *
1258 * Sets the Nss per vdev type based on INI
1259 *
1260 * Return: None
1261 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001262static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001263{
1264 struct hdd_config *cfg_ini = hdd_ctx->config;
1265 uint8_t max_supp_nss = 1;
Jeff Johnson16528362018-06-14 12:34:16 -07001266 mac_handle_t mac_handle;
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001267
Naveen Rawat10b1c152017-01-18 11:16:06 -08001268 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001269 max_supp_nss = 2;
Liangwei Dong22810e82018-03-15 03:42:12 -04001270 hdd_debug("max nss %d vdev_type_nss_2g %x vdev_type_nss_5g %x",
1271 max_supp_nss, cfg_ini->vdev_type_nss_2g,
1272 cfg_ini->vdev_type_nss_5g);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001273
Jeff Johnson16528362018-06-14 12:34:16 -07001274 mac_handle = hdd_ctx->mac_handle;
1275 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
1276 cfg_ini->vdev_type_nss_2g, BAND_2G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001277
Jeff Johnson16528362018-06-14 12:34:16 -07001278 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
1279 cfg_ini->vdev_type_nss_5g, BAND_5G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001280}
1281
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301282/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301283 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1284 * @hdd_ctx: HDD context
1285 *
1286 * Updates wiphy vhtcap fields
1287 *
1288 * Return: None
1289 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001290static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301291{
1292 struct ieee80211_supported_band *band_5g =
1293 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1294 uint32_t val;
1295
1296 if (!band_5g) {
1297 hdd_debug("5GHz band disabled, skipping capability population");
1298 return;
1299 }
1300
1301 val = hdd_ctx->config->txBFCsnValue;
1302 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1303
1304 val = NUM_OF_SOUNDING_DIMENSIONS;
1305 band_5g->vht_cap.cap |=
1306 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1307
Dustin Brown7e761c72018-07-31 13:50:17 -07001308 hdd_debug("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1309 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301310}
1311
1312/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301313 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1314 * @hdd_ctx: HDD context
1315 *
1316 * Sets the DBS capability as per INI and firmware capability
1317 *
1318 * Return: None
1319 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001320static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301321{
1322 struct hdd_config *cfg_ini = hdd_ctx->config;
1323 uint8_t hw_dbs_capable = 0;
1324
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001325 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1326 ((cfg_ini->dual_mac_feature_disable ==
1327 ENABLE_DBS_CXN_AND_SCAN) ||
1328 (cfg_ini->dual_mac_feature_disable ==
Tushnim Bhattacharyyaaececb22018-08-06 14:27:46 -07001329 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF) ||
1330 (cfg_ini->dual_mac_feature_disable ==
1331 ENABLE_DBS_CXN_AND_DISABLE_SIMULTANEOUS_SCAN)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301332 hw_dbs_capable = 1;
1333
Jeff Johnson16528362018-06-14 12:34:16 -07001334 sme_update_hw_dbs_capable(hdd_ctx->mac_handle, hw_dbs_capable);
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301335}
1336
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001337static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001338 struct wma_tgt_ht_cap *cfg)
1339{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301340 QDF_STATUS status;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301341 uint32_t value;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001342 struct hdd_config *pconfig = hdd_ctx->config;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301343 struct mlme_ht_capabilities_info ht_cap_info;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001344 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301345 mac_handle_t mac_handle = hdd_ctx->mac_handle;
Jeff Johnson16528362018-06-14 12:34:16 -07001346
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001347 /* get the MPDU density */
Jeff Johnson16528362018-06-14 12:34:16 -07001348 status = sme_cfg_get_int(mac_handle, WNI_CFG_MPDU_DENSITY, &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001349
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301350 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001351 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001352 value = 0;
1353 }
1354
1355 /*
1356 * MPDU density:
1357 * override user's setting if value is larger
1358 * than the one supported by target
1359 */
1360 if (value > cfg->mpdu_density) {
Jeff Johnson16528362018-06-14 12:34:16 -07001361 status = sme_cfg_set_int(mac_handle, WNI_CFG_MPDU_DENSITY,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001362 cfg->mpdu_density);
1363
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301364 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001365 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001366 }
1367
1368 /* get the HT capability info */
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301369 status = ucfg_mlme_get_ht_cap_info(hdd_ctx->hdd_psoc, &ht_cap_info);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301370 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001371 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001372 return;
1373 }
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301374
1375 /* check and update RX STBC */
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301376 if (ht_cap_info.rx_stbc && !cfg->ht_rx_stbc)
1377 ht_cap_info.rx_stbc = cfg->ht_rx_stbc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001378
1379 /* Set the LDPC capability */
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301380 ht_cap_info.adv_coding_cap = cfg->ht_rx_ldpc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001381
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301382 if (ht_cap_info.short_gi_20_mhz && !cfg->ht_sgi_20)
1383 ht_cap_info.short_gi_20_mhz = cfg->ht_sgi_20;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001384
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301385 if (ht_cap_info.short_gi_40_mhz && !cfg->ht_sgi_40)
1386 ht_cap_info.short_gi_40_mhz = cfg->ht_sgi_40;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001387
1388 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1389 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1390
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001391 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1392 pconfig->enable2x2 = 1;
1393 } else {
1394 pconfig->enable2x2 = 0;
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301395 ht_cap_info.tx_stbc = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001396
1397 /* 1x1 */
1398 /* Update Rx Highest Long GI data Rate */
Jeff Johnson16528362018-06-14 12:34:16 -07001399 if (sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001400 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001401 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301402 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001403 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001404 }
1405
1406 /* Update Tx Highest Long GI data Rate */
1407 if (sme_cfg_set_int
Jeff Johnson16528362018-06-14 12:34:16 -07001408 (mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001409 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001410 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301411 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001412 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001413 }
1414 }
1415 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301416 ht_cap_info.tx_stbc = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001417
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301418 status = ucfg_mlme_set_ht_cap_info(hdd_ctx->hdd_psoc, ht_cap_info);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301419 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001420 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001421#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1422 value = SIZE_OF_SUPPORTED_MCS_SET;
Jeff Johnson16528362018-06-14 12:34:16 -07001423 if (sme_cfg_get_str(mac_handle, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301424 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001425 hdd_debug("Read MCS rate set");
gaurank kathpalia18b49362018-04-15 23:12:03 +05301426 if (cfg->num_rf_chains > SIZE_OF_SUPPORTED_MCS_SET)
1427 cfg->num_rf_chains = SIZE_OF_SUPPORTED_MCS_SET;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001428 if (pconfig->enable2x2) {
1429 for (value = 0; value < cfg->num_rf_chains; value++)
1430 mcs_set[value] =
1431 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1432
1433 status =
Jeff Johnson16528362018-06-14 12:34:16 -07001434 sme_cfg_set_str(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001435 WNI_CFG_SUPPORTED_MCS_SET,
1436 mcs_set,
1437 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301438 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001439 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001440 }
1441 }
1442#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1443}
1444
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001445static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001446 struct wma_tgt_vht_cap *cfg)
1447{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301448 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001449 uint32_t value = 0;
1450 struct hdd_config *pconfig = hdd_ctx->config;
1451 struct wiphy *wiphy = hdd_ctx->wiphy;
1452 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001453 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001454 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001455 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001456 uint32_t hw_rx_ldpc_enabled;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001457 struct wma_caps_per_phy caps_per_phy;
Jeff Johnson16528362018-06-14 12:34:16 -07001458 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001459
Dustin Brown5e06bd32016-10-04 12:49:10 -07001460 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001461 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001462 return;
1463 }
1464
Jeff Johnson16528362018-06-14 12:34:16 -07001465 mac_handle = hdd_ctx->mac_handle;
1466
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001467 /* Get the current MPDU length */
1468 status =
Jeff Johnson16528362018-06-14 12:34:16 -07001469 sme_cfg_get_int(mac_handle, WNI_CFG_VHT_MAX_MPDU_LENGTH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001470 &value);
1471
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301472 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001473 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001474 value = 0;
1475 }
1476
1477 /*
1478 * VHT max MPDU length:
1479 * override if user configured value is too high
1480 * that the target cannot support
1481 */
1482 if (value > cfg->vht_max_mpdu) {
Jeff Johnson16528362018-06-14 12:34:16 -07001483 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001484 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1485 cfg->vht_max_mpdu);
1486
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001487 if (status == QDF_STATUS_E_FAILURE)
1488 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001489 }
1490
Jeff Johnson16528362018-06-14 12:34:16 -07001491 sme_cfg_get_int(mac_handle, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001492 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1493
1494 if (pconfig->enable2x2)
1495 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1496
Jeff Johnson16528362018-06-14 12:34:16 -07001497 if (sme_cfg_set_int(mac_handle, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001498 QDF_STATUS_E_FAILURE) {
1499 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1500 }
1501
Jeff Johnson16528362018-06-14 12:34:16 -07001502 sme_cfg_get_int(mac_handle, WNI_CFG_VHT_RX_MCS_MAP, &temp);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001503 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1504 if (pconfig->enable2x2)
1505 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1506
Jeff Johnson16528362018-06-14 12:34:16 -07001507 if (sme_cfg_set_int(mac_handle, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001508 QDF_STATUS_E_FAILURE) {
1509 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1510 }
1511
Jeff Johnson16528362018-06-14 12:34:16 -07001512 sme_cfg_get_int(mac_handle, WNI_CFG_VHT_TX_MCS_MAP, &temp);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001513 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1514 if (pconfig->enable2x2)
1515 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1516
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001517 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001518 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1519
Jeff Johnson16528362018-06-14 12:34:16 -07001520 if (sme_cfg_set_int(mac_handle, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001521 QDF_STATUS_E_FAILURE) {
1522 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1523 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001524 /* Get the current RX LDPC setting */
Jeff Johnson16528362018-06-14 12:34:16 -07001525 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_LDPC_CODING_CAP,
1526 &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001527
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301528 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001529 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001530 value = 0;
1531 }
1532
jiad4a7a33c2017-08-08 15:32:24 +08001533 /* Set HW RX LDPC capability */
1534 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1535 if (hw_rx_ldpc_enabled != value) {
Jeff Johnson16528362018-06-14 12:34:16 -07001536 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001537 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001538 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001539
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001540 if (status == QDF_STATUS_E_FAILURE)
1541 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001542 }
1543
1544 /* Get current GI 80 value */
Jeff Johnson16528362018-06-14 12:34:16 -07001545 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_SHORT_GI_80MHZ,
1546 &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001547
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301548 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001549 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001550 value = 0;
1551 }
1552
1553 /* set the Guard interval 80MHz */
1554 if (value && !cfg->vht_short_gi_80) {
Jeff Johnson16528362018-06-14 12:34:16 -07001555 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001556 WNI_CFG_VHT_SHORT_GI_80MHZ,
1557 cfg->vht_short_gi_80);
1558
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001559 if (status == QDF_STATUS_E_FAILURE)
1560 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001561 }
1562
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001563 /* Get VHT TX STBC cap */
Jeff Johnson16528362018-06-14 12:34:16 -07001564 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_TXSTBC, &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001565
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301566 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001567 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001568 value = 0;
1569 }
1570
1571 /* VHT TX STBC cap */
1572 if (value && !cfg->vht_tx_stbc) {
Jeff Johnson16528362018-06-14 12:34:16 -07001573 status = sme_cfg_set_int(mac_handle, WNI_CFG_VHT_TXSTBC,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001574 cfg->vht_tx_stbc);
1575
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001576 if (status == QDF_STATUS_E_FAILURE)
1577 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001578 }
1579
1580 /* Get VHT RX STBC cap */
Jeff Johnson16528362018-06-14 12:34:16 -07001581 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_RXSTBC, &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001582
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301583 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001584 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001585 value = 0;
1586 }
1587
1588 /* VHT RX STBC cap */
1589 if (value && !cfg->vht_rx_stbc) {
Jeff Johnson16528362018-06-14 12:34:16 -07001590 status = sme_cfg_set_int(mac_handle, WNI_CFG_VHT_RXSTBC,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001591 cfg->vht_rx_stbc);
1592
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001593 if (status == QDF_STATUS_E_FAILURE)
1594 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001595 }
1596
1597 /* Get VHT SU Beamformer cap */
Jeff Johnson16528362018-06-14 12:34:16 -07001598 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001599 &value);
1600
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301601 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001602 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001603 value = 0;
1604 }
1605
1606 /* set VHT SU Beamformer cap */
1607 if (value && !cfg->vht_su_bformer) {
Jeff Johnson16528362018-06-14 12:34:16 -07001608 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001609 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1610 cfg->vht_su_bformer);
1611
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001612 if (status == QDF_STATUS_E_FAILURE)
1613 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001614 }
1615
1616 /* check and update SU BEAMFORMEE capabality */
1617 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1618 pconfig->enableTxBF = cfg->vht_su_bformee;
1619
Jeff Johnson16528362018-06-14 12:34:16 -07001620 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001621 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1622 pconfig->enableTxBF);
1623
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001624 if (status == QDF_STATUS_E_FAILURE)
1625 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001626
1627 /* Get VHT MU Beamformer cap */
Jeff Johnson16528362018-06-14 12:34:16 -07001628 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001629 &value);
1630
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301631 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001632 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001633 value = 0;
1634 }
1635
1636 /* set VHT MU Beamformer cap */
1637 if (value && !cfg->vht_mu_bformer) {
Jeff Johnson16528362018-06-14 12:34:16 -07001638 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001639 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1640 cfg->vht_mu_bformer);
1641
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001642 if (status == QDF_STATUS_E_FAILURE)
1643 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001644 }
1645
1646 /* Get VHT MU Beamformee cap */
Jeff Johnson16528362018-06-14 12:34:16 -07001647 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001648 &value);
1649
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301650 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001651 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001652 value = 0;
1653 }
1654
1655 /* set VHT MU Beamformee cap */
1656 if (value && !cfg->vht_mu_bformee) {
Jeff Johnson16528362018-06-14 12:34:16 -07001657 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001658 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1659 cfg->vht_mu_bformee);
1660
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001661 if (status == QDF_STATUS_E_FAILURE)
1662 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001663 }
1664
1665 /* Get VHT MAX AMPDU Len exp */
Jeff Johnson16528362018-06-14 12:34:16 -07001666 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001667 &value);
1668
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301669 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001670 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001671 value = 0;
1672 }
1673
1674 /*
1675 * VHT max AMPDU len exp:
1676 * override if user configured value is too high
1677 * that the target cannot support.
1678 * Even though Rome publish ampdu_len=7, it can
1679 * only support 4 because of some h/w bug.
1680 */
1681
1682 if (value > cfg->vht_max_ampdu_len_exp) {
Jeff Johnson16528362018-06-14 12:34:16 -07001683 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001684 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1685 cfg->vht_max_ampdu_len_exp);
1686
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001687 if (status == QDF_STATUS_E_FAILURE)
1688 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001689 }
1690
1691 /* Get VHT TXOP PS CAP */
Jeff Johnson16528362018-06-14 12:34:16 -07001692 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_TXOP_PS, &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001693
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301694 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001695 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001696 value = 0;
1697 }
1698
1699 /* set VHT TXOP PS cap */
1700 if (value && !cfg->vht_txop_ps) {
Jeff Johnson16528362018-06-14 12:34:16 -07001701 status = sme_cfg_set_int(mac_handle, WNI_CFG_VHT_TXOP_PS,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001702 cfg->vht_txop_ps);
1703
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001704 if (status == QDF_STATUS_E_FAILURE)
1705 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001706 }
1707
1708 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1709 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1710 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1711 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1712 else
1713 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1714
1715
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001716 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
Jeff Johnson16528362018-06-14 12:34:16 -07001717 status = sme_cfg_set_int(mac_handle,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001718 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1719 VHT_CAP_160_AND_80P80_SUPP);
1720 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001721 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001722 band_5g->vht_cap.cap |=
1723 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001724 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1725 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
Jeff Johnson16528362018-06-14 12:34:16 -07001726 status = sme_cfg_set_int(mac_handle,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001727 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1728 VHT_CAP_160_SUPP);
1729 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001730 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001731 band_5g->vht_cap.cap |=
1732 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001733 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1734 }
1735 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1736 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301737 /* Get the current GI 160 value */
Jeff Johnson16528362018-06-14 12:34:16 -07001738 status = sme_cfg_get_int(mac_handle,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301739 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001740 &value);
1741 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301742 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001743 value = 0;
1744 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301745 /* set the Guard interval 160MHz */
1746 if (value && !cfg->vht_short_gi_160) {
Jeff Johnson16528362018-06-14 12:34:16 -07001747 status = sme_cfg_set_int(mac_handle,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301748 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1749 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001750
1751 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301752 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001753 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001754
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001755 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001756 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001757 hdd_debug("VHT RxLDPC capability is set");
1758 } else {
1759 /*
1760 * Get the RX LDPC capability for the NON DBS
1761 * hardware mode for 5G band
1762 */
1763 status = wma_get_caps_for_phyidx_hwmode(&caps_per_phy,
1764 HW_MODE_DBS_NONE, CDS_BAND_5GHZ);
1765 if ((QDF_IS_STATUS_SUCCESS(status)) &&
1766 (caps_per_phy.vht_5g & WMI_VHT_CAP_RX_LDPC)) {
1767 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1768 hdd_debug("VHT RX LDPC capability is set");
1769 }
1770 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001771
1772 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1773 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1774 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1775 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1776
1777 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1778 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1779
1780 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1781 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1782 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1783 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1784 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1785 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1786
1787 band_5g->vht_cap.cap |=
1788 (cfg->vht_max_ampdu_len_exp <<
1789 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1790
1791 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1792 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1793 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1794 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1795 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1796 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1797 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1798 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1799
1800 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1801 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1802
1803}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001804
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001805/**
1806 * hdd_generate_macaddr_auto() - Auto-generate mac address
1807 * @hdd_ctx: Pointer to the HDD context
1808 *
1809 * Auto-generate mac address using device serial number.
1810 * Keep the first 3 bytes of OUI as before and replace
1811 * the last 3 bytes with the lower 3 bytes of serial number.
1812 *
1813 * Return: 0 for success
1814 * Non zero failure code for errors
1815 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001816static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001817{
1818 unsigned int serialno = 0;
1819 struct qdf_mac_addr mac_addr = {
1820 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1821 };
1822
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001823 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001824 if (serialno == 0)
1825 return -EINVAL;
1826
1827 serialno &= 0x00ffffff;
1828
1829 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1830 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1831 mac_addr.bytes[5] = serialno & 0xff;
1832
1833 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1834 return 0;
1835}
1836
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05301837#ifdef FEATURE_WLAN_APF
1838/**
1839 * hdd_update_apf_support() - Update APF supported flag in hdd context
1840 * @hdd_ctx: Pointer to hdd_ctx
1841 * @cfg: target configuration
1842 *
1843 * Update the APF support flag in HDD Context using INI and target config.
1844 *
1845 * Return: None
1846 */
1847static void hdd_update_apf_support(struct hdd_context *hdd_ctx,
1848 struct wma_tgt_cfg *cfg)
1849{
1850 hdd_ctx->apf_supported = (cfg->apf_enabled &&
1851 hdd_ctx->config->apf_packet_filter_enable);
1852}
1853#else
1854static void hdd_update_apf_support(struct hdd_context *hdd_ctx,
1855 struct wma_tgt_cfg *cfg)
1856{
1857}
1858#endif
1859
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301860/**
1861 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1862 * configuration to cfg_ini in HDD
1863 * @hdd_ctx: Pointer to hdd_ctx
1864 * @cfg: target configuration
1865 *
1866 * Return: None
1867 */
1868#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001869static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301870 struct wma_tgt_cfg *cfg)
1871{
1872 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1873}
1874#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001875static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301876 struct wma_tgt_cfg *cfg)
1877{
1878}
1879#endif
1880
Jeff Johnsonf9176382018-07-17 19:15:58 -07001881static void hdd_sar_target_config(struct hdd_context *hdd_ctx,
1882 struct wma_tgt_cfg *cfg)
1883{
1884 hdd_ctx->sar_version = cfg->sar_version;
1885}
1886
Jeff Johnson8abc5932018-06-02 22:51:37 -07001887void hdd_update_tgt_cfg(hdd_handle_t hdd_handle, struct wma_tgt_cfg *cfg)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001888{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001889 int ret;
Jeff Johnsonea70b942018-07-02 09:42:31 -07001890 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001891 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001892 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301893 uint8_t antenna_mode;
Arif Hussainee10f902017-12-27 16:30:17 -08001894 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -07001895 mac_handle_t mac_handle;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301896
gaurank kathpalia843f7c32018-07-02 18:04:14 +05301897 if (!hdd_ctx) {
1898 hdd_err("HDD context is NULL");
1899 return;
1900 }
Dustin Brownbd68fe12017-11-21 15:28:52 -08001901 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1902 if (ret) {
Dustin Brown64204d22018-08-15 16:35:19 -07001903 QDF_DEBUG_PANIC("Failed to create pdev; errno:%d", ret);
1904 return;
1905 }
1906
1907 hdd_debug("New pdev has been created with pdev_id = %u",
1908 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
1909
1910 status = dispatcher_pdev_open(hdd_ctx->hdd_pdev);
1911 if (QDF_IS_STATUS_ERROR(status)) {
1912 QDF_DEBUG_PANIC("dispatcher pdev open failed; status:%d",
1913 status);
1914 return;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301915 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001916
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301917 cdp_pdev_set_ctrl_pdev(cds_get_context(QDF_MODULE_ID_SOC),
1918 cds_get_context(QDF_MODULE_ID_TXRX),
1919 (struct cdp_ctrl_objmgr_pdev *)hdd_ctx->hdd_pdev);
1920
1921 wlan_pdev_set_dp_handle(hdd_ctx->hdd_pdev,
1922 cds_get_context(QDF_MODULE_ID_TXRX));
1923
Will Huang07244172018-05-14 14:23:30 +08001924 hdd_objmgr_update_tgt_max_vdev_psoc(hdd_ctx, cfg->max_intf_count);
1925
Jeff Johnsone8846ab2018-03-31 11:54:45 -07001926 ret = hdd_green_ap_update_config(hdd_ctx);
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301927
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301928 ucfg_ipa_set_dp_handle(hdd_ctx->hdd_psoc,
1929 cds_get_context(QDF_MODULE_ID_SOC));
1930 ucfg_ipa_set_txrx_handle(hdd_ctx->hdd_psoc,
1931 cds_get_context(QDF_MODULE_ID_TXRX));
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301932 ucfg_ipa_reg_sap_xmit_cb(hdd_ctx->hdd_pdev,
1933 hdd_softap_hard_start_xmit);
1934 ucfg_ipa_reg_send_to_nw_cb(hdd_ctx->hdd_pdev,
1935 hdd_ipa_send_skb_to_network);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301936
Naveen Rawat64e477e2016-05-20 10:34:56 -07001937 if (cds_cfg) {
1938 if (hdd_ctx->config->enable_sub_20_channel_width !=
1939 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1940 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1941 cds_cfg->sub_20_channel_width =
1942 WLAN_SUB_20_CH_WIDTH_NONE;
1943 } else {
1944 cds_cfg->sub_20_channel_width =
1945 hdd_ctx->config->enable_sub_20_channel_width;
1946 }
1947 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001948
1949 /* first store the INI band capability */
1950 temp_band_cap = hdd_ctx->config->nBandCapability;
1951
1952 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301953 hdd_ctx->is_fils_roaming_supported =
1954 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001955
Vignesh Viswanathan694e28e2018-01-18 20:53:57 +05301956 hdd_ctx->config->is_11k_offload_supported =
1957 cfg->services.is_11k_offload_supported;
1958
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001959 /*
1960 * now overwrite the target band capability with INI
1961 * setting if INI setting is a subset
1962 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001963
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001964 if ((hdd_ctx->config->nBandCapability == BAND_ALL) &&
1965 (temp_band_cap != BAND_ALL))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001966 hdd_ctx->config->nBandCapability = temp_band_cap;
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001967 else if ((hdd_ctx->config->nBandCapability != BAND_ALL) &&
1968 (temp_band_cap != BAND_ALL) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001969 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001970 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001971 }
1972
Amar Singhal58b45ef2017-08-01 13:43:54 -07001973 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1974
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301975 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001976 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1977 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1978 }
1979
1980 /* This can be extended to other configurations like ht, vht cap... */
1981
Anurag Chouhanc5548422016-02-24 18:33:27 +05301982 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001983 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001984 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001985 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001986 static struct qdf_mac_addr default_mac_addr = {
1987 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1988 };
1989 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1990 &default_mac_addr)) {
1991 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1992 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1993 MAC_ADDRESS_STR,
1994 MAC_ADDR_ARRAY(hdd_ctx->config->
1995 intfMacAddr[0].bytes));
1996 } else {
1997 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1998 MAC_ADDRESS_STR,
1999 MAC_ADDR_ARRAY(hdd_ctx->config->
2000 intfMacAddr[0].bytes));
2001 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07002002 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002003 }
2004
2005 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07002006 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002007
Ryan Hsuc6918552018-05-16 13:29:59 -07002008 hdd_ctx->hw_bd_id = cfg->hw_bd_id;
2009 qdf_mem_copy(&hdd_ctx->hw_bd_info, &cfg->hw_bd_info,
2010 sizeof(cfg->hw_bd_info));
2011
Dustin Brownbee82832018-07-23 10:10:51 -07002012 if (cfg->max_intf_count > CSR_ROAM_SESSION_MAX) {
2013 hdd_err("fw max vdevs (%u) > host max vdevs (%u); using %u",
2014 cfg->max_intf_count, CSR_ROAM_SESSION_MAX,
2015 CSR_ROAM_SESSION_MAX);
2016 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
2017 } else {
2018 hdd_ctx->max_intf_count = cfg->max_intf_count;
2019 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002020
Jeff Johnsonf9176382018-07-17 19:15:58 -07002021 hdd_sar_target_config(hdd_ctx, cfg);
Jeff Johnsonc875e242016-09-23 18:12:34 -07002022 hdd_lpass_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08002023
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002024 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
2025 hdd_update_tgt_services(hdd_ctx, &cfg->services);
2026
2027 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
2028
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002029 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07002030 if (cfg->services.en_11ax) {
2031 hdd_info("11AX: 11ax is enabled - update HDD config");
2032 hdd_update_tgt_he_cap(hdd_ctx, cfg);
2033 }
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -07002034 hdd_update_tgt_twt_cap(hdd_ctx, cfg);
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07002035
2036 hdd_update_vdev_nss(hdd_ctx);
2037
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05302038 hdd_update_hw_dbs_capable(hdd_ctx);
2039
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08002040 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07002041 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002042 hdd_debug("fine_time_meas_cap: 0x%x",
Arif Hussainee10f902017-12-27 16:30:17 -08002043 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08002044
Nitesh Shahe50711f2017-04-26 16:30:45 +05302045 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
2046 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
2047 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002048 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08002049 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08002050
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05302051 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05302052 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05302053
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302054 if ((hdd_ctx->config->txBFCsnValue >
Arif Hussainee10f902017-12-27 16:30:17 -08002055 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
2056 !cfg->tx_bfee_8ss_enabled)
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302057 hdd_ctx->config->txBFCsnValue =
2058 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
2059
Jeff Johnson16528362018-06-14 12:34:16 -07002060 mac_handle = hdd_ctx->mac_handle;
2061 status = sme_cfg_set_int(mac_handle,
Arif Hussainee10f902017-12-27 16:30:17 -08002062 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
2063 hdd_ctx->config->txBFCsnValue);
2064 if (QDF_IS_STATUS_ERROR(status))
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302065 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
2066
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05302067 hdd_update_apf_support(hdd_ctx, cfg);
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302068
Nachiket Kukadee547a482018-05-22 16:43:30 +05302069 hdd_debug("Target APF %d Host APF %d 8ss fw support %d txBFCsnValue %d",
2070 cfg->apf_enabled, hdd_ctx->config->apf_packet_filter_enable,
Arif Hussainee10f902017-12-27 16:30:17 -08002071 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05302072
2073 /*
2074 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
2075 */
2076 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05302077
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05302078 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
2079
Yue Macd359b72017-10-03 15:21:00 -07002080 /*
2081 * This needs to be done after HDD pdev is created and stored since
2082 * it will access the HDD pdev object lock.
2083 */
2084 hdd_runtime_suspend_context_init(hdd_ctx);
2085
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07002086 /* Configure NAN datapath features */
2087 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07002088 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08002089 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Liangwei Dong0da14262018-07-03 03:30:23 -04002090 hdd_ctx->obss_scan_offload = cfg->services.obss_scan_offload;
Jeff Johnson16528362018-06-14 12:34:16 -07002091 status = sme_cfg_set_int(mac_handle, WNI_CFG_OBSS_DETECTION_OFFLOAD,
Arif Hussainee10f902017-12-27 16:30:17 -08002092 cfg->obss_detection_offloaded);
2093 if (QDF_IS_STATUS_ERROR(status))
2094 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Arif Hussain05fb4872018-01-03 16:02:55 -08002095
Jeff Johnson16528362018-06-14 12:34:16 -07002096 status = sme_cfg_set_int(mac_handle,
Arif Hussain05fb4872018-01-03 16:02:55 -08002097 WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD,
2098 cfg->obss_color_collision_offloaded);
2099 if (QDF_IS_STATUS_ERROR(status))
2100 hdd_err("Failed to set WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002101}
2102
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002103bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002104{
Jeff Johnson9d295242017-08-29 14:39:48 -07002105 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002106 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002107
Jiachao Wuf610d912018-01-23 17:47:32 +08002108 if (!hdd_ctx) {
2109 hdd_info("Couldn't get hdd_ctx");
2110 return true;
2111 }
2112
2113 if (hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002114 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08002115 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302116 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002117 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002118
Dustin Brown920397d2017-12-13 16:27:50 -08002119 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002120 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2121
2122 if ((QDF_SAP_MODE == adapter->device_mode ||
2123 QDF_P2P_GO_MODE == adapter->device_mode) &&
bings0e03a982018-05-09 08:40:59 +08002124 (wlan_reg_is_passive_or_disable_ch(hdd_ctx->hdd_pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002125 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002126 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2127 true;
2128 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07002129 adapter->session_id);
bings6fb9bf62018-07-05 14:01:53 +08002130 if (adapter->txrx_vdev)
2131 cdp_fc_vdev_flush(
2132 cds_get_context(QDF_MODULE_ID_SOC),
bings0e03a982018-05-09 08:40:59 +08002133 adapter->txrx_vdev);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302134 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002135 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302136
2137 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002138}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002139
2140/**
2141 * hdd_is_valid_mac_address() - validate MAC address
2142 * @pMacAddr: Pointer to the input MAC address
2143 *
2144 * This function validates whether the given MAC address is valid or not
2145 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
2146 * where X is the hexa decimal digit character and separated by ':'
2147 * This algorithm works even if MAC address is not separated by ':'
2148 *
2149 * This code checks given input string mac contains exactly 12 hexadecimal
2150 * digits and a separator colon : appears in the input string only after
2151 * an even number of hex digits.
2152 *
2153 * Return: 1 for valid and 0 for invalid
2154 */
2155bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
2156{
2157 int xdigit = 0;
2158 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002159
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002160 while (*pMacAddr) {
2161 if (isxdigit(*pMacAddr)) {
2162 xdigit++;
2163 } else if (':' == *pMacAddr) {
2164 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2165 break;
2166
2167 ++separator;
2168 } else {
2169 /* Invalid MAC found */
2170 return 0;
2171 }
2172 ++pMacAddr;
2173 }
2174 return xdigit == 12 && (separator == 5 || separator == 0);
2175}
2176
2177/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302178 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2179 * @dev: Handle to struct net_device to be updated.
2180 *
2181 * Return: None
2182 */
2183static void hdd_mon_mode_ether_setup(struct net_device *dev)
2184{
2185 dev->header_ops = NULL;
2186 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2187 dev->hard_header_len = ETH_HLEN;
2188 dev->mtu = ETH_DATA_LEN;
2189 dev->addr_len = ETH_ALEN;
2190 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2191 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2192 dev->priv_flags |= IFF_TX_SKB_SHARING;
2193
2194 memset(dev->broadcast, 0xFF, ETH_ALEN);
2195}
2196
Nirav Shah73713f72018-05-17 14:50:41 +05302197#ifdef FEATURE_MONITOR_MODE_SUPPORT
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302198/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002199 * __hdd__mon_open() - HDD Open function
2200 * @dev: Pointer to net_device structure
2201 *
2202 * This is called in response to ifconfig up
2203 *
2204 * Return: 0 for success; non-zero for failure
2205 */
2206static int __hdd_mon_open(struct net_device *dev)
2207{
2208 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002209 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2210 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002211
Dustin Brownfdf17c12018-03-14 12:55:34 -07002212 hdd_enter_dev(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002213
2214 ret = wlan_hdd_validate_context(hdd_ctx);
2215 if (ret)
2216 return ret;
2217
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302218 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002219
2220 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Browne7e71d32018-05-11 16:00:08 -07002221 ret = hdd_wlan_start_modules(hdd_ctx, false);
Ravi Joshia307f632017-07-17 23:41:41 -07002222 if (ret) {
2223 hdd_err("Failed to start WLAN modules return");
2224 return ret;
2225 }
2226 hdd_err("hdd_wlan_start_modules() successful !");
2227
2228 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2229 ret = hdd_start_adapter(adapter);
2230 if (ret) {
2231 hdd_err("Failed to start adapter :%d",
2232 adapter->device_mode);
2233 return ret;
2234 }
2235 hdd_err("hdd_start_adapters() successful !");
2236 }
2237 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2238 }
2239
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002240 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002241
2242 if (!ret)
2243 ret = hdd_enable_monitor_mode(dev);
2244
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002245 return ret;
2246}
2247
2248/**
2249 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2250 * @dev: Pointer to net_device structure
2251 *
2252 * This is called in response to ifconfig up
2253 *
2254 * Return: 0 for success; non-zero for failure
2255 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002256static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002257{
2258 int ret;
2259
2260 cds_ssr_protect(__func__);
2261 ret = __hdd_mon_open(dev);
2262 cds_ssr_unprotect(__func__);
2263
2264 return ret;
2265}
Nirav Shah73713f72018-05-17 14:50:41 +05302266#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002267
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002268static QDF_STATUS
2269wlan_hdd_update_dbs_scan_and_fw_mode_config(void)
2270{
2271 struct policy_mgr_dual_mac_config cfg = {0};
2272 QDF_STATUS status;
2273 uint32_t channel_select_logic_conc;
2274 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2275
2276 if (!hdd_ctx) {
2277 hdd_err("HDD context is NULL");
2278 return QDF_STATUS_E_FAILURE;
2279 }
2280
2281
2282 if (!policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc))
2283 return QDF_STATUS_SUCCESS;
2284
2285 cfg.scan_config = 0;
2286 cfg.fw_mode_config = 0;
2287 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
2288
2289 channel_select_logic_conc = hdd_ctx->config->
2290 channel_select_logic_conc;
2291
2292 if (hdd_ctx->config->dual_mac_feature_disable !=
2293 DISABLE_DBS_CXN_AND_SCAN) {
2294 status = policy_mgr_get_updated_scan_and_fw_mode_config(
2295 hdd_ctx->hdd_psoc, &cfg.scan_config,
2296 &cfg.fw_mode_config,
2297 hdd_ctx->config->dual_mac_feature_disable,
2298 channel_select_logic_conc);
2299
2300 if (status != QDF_STATUS_SUCCESS) {
2301 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
2302 status);
2303 return status;
2304 }
2305 }
2306
2307 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
2308 cfg.scan_config, cfg.fw_mode_config);
2309
2310 status = sme_soc_set_dual_mac_config(cfg);
2311 if (status != QDF_STATUS_SUCCESS) {
2312 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
2313 return status;
2314 }
2315
2316 return QDF_STATUS_SUCCESS;
2317}
2318
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002319/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302320 * hdd_start_adapter() - Wrapper function for device specific adapter
2321 * @adapter: pointer to HDD adapter
2322 *
2323 * This function is called to start the device specific adapter for
2324 * the mode passed in the adapter's device_mode.
2325 *
2326 * Return: 0 for success; non-zero for failure
2327 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002328int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302329{
2330
2331 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002332 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302333
Dustin Brownfdf17c12018-03-14 12:55:34 -07002334 hdd_enter_dev(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002335 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302336
2337 switch (device_mode) {
2338 case QDF_P2P_CLIENT_MODE:
2339 case QDF_P2P_DEVICE_MODE:
2340 case QDF_OCB_MODE:
2341 case QDF_STA_MODE:
2342 case QDF_MONITOR_MODE:
2343 ret = hdd_start_station_adapter(adapter);
2344 if (ret)
2345 goto err_start_adapter;
Alok Kumar81e1d732018-09-04 11:10:36 +05302346
2347 hdd_nud_ignore_tracking(adapter, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05302348 break;
2349 case QDF_P2P_GO_MODE:
2350 case QDF_SAP_MODE:
2351 ret = hdd_start_ap_adapter(adapter);
2352 if (ret)
2353 goto err_start_adapter;
2354 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302355 case QDF_IBSS_MODE:
2356 /*
2357 * For IBSS interface is initialized as part of
2358 * hdd_init_station_mode()
2359 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002360 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302361 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002362 /* vdevs are dynamically managed by firmware in FTM */
2363 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302364 default:
2365 hdd_err("Invalid session type %d", device_mode);
2366 QDF_ASSERT(0);
2367 goto err_start_adapter;
2368 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002369
Arun Khandavallifae92942016-08-01 13:31:08 +05302370 if (hdd_set_fw_params(adapter))
2371 hdd_err("Failed to set the FW params for the adapter!");
2372
Dustin Browne7e71d32018-05-11 16:00:08 -07002373 if (adapter->session_id != HDD_SESSION_ID_INVALID) {
2374 ret = wlan_hdd_cfg80211_register_frames(adapter);
2375 if (ret < 0) {
2376 hdd_err("Failed to register frames - ret %d", ret);
2377 goto err_start_adapter;
2378 }
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302379 }
Dustin Browne7e71d32018-05-11 16:00:08 -07002380
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002381 wlan_hdd_update_dbs_scan_and_fw_mode_config();
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302382
Dustin Browndb2a8be2017-12-20 11:49:56 -08002383exit_with_success:
Dustin Browne74003f2018-03-14 12:51:58 -07002384 hdd_exit();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002385
Arun Khandavallifae92942016-08-01 13:31:08 +05302386 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002387
Arun Khandavallifae92942016-08-01 13:31:08 +05302388err_start_adapter:
2389 return -EINVAL;
2390}
2391
2392/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302393 * hdd_enable_power_management() - API to Enable Power Management
2394 *
2395 * API invokes Bus Interface Layer power management functionality
2396 *
2397 * Return: None
2398 */
2399static void hdd_enable_power_management(void)
2400{
2401 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2402
2403 if (!hif_ctx) {
2404 hdd_err("Bus Interface Context is Invalid");
2405 return;
2406 }
2407
2408 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2409}
2410
2411/**
2412 * hdd_disable_power_management() - API to disable Power Management
2413 *
2414 * API disable Bus Interface Layer Power management functionality
2415 *
2416 * Return: None
2417 */
2418static void hdd_disable_power_management(void)
2419{
2420 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2421
2422 if (!hif_ctx) {
2423 hdd_err("Bus Interface Context is Invalid");
2424 return;
2425 }
2426
2427 hif_disable_power_management(hif_ctx);
2428}
2429
Ryan Hsuaadba072018-04-20 13:01:53 -07002430void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302431{
2432 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002433 size_t target_hw_name_len;
2434 const char *target_hw_name;
Ryan Hsuaadba072018-04-20 13:01:53 -07002435 uint8_t *buf;
2436 uint32_t buf_len;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302437
2438 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2439 if (!hif_sc) {
2440 hdd_err("HIF context is NULL");
2441 return;
2442 }
2443
Ryan Hsuaadba072018-04-20 13:01:53 -07002444 hif_get_hw_info(hif_sc, &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302445 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002446 &target_hw_name);
2447
2448 if (hdd_ctx->target_hw_name)
2449 qdf_mem_free(hdd_ctx->target_hw_name);
2450
2451 target_hw_name_len = strlen(target_hw_name) + 1;
2452 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2453 if (hdd_ctx->target_hw_name)
2454 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2455 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302456
Ryan Hsuaadba072018-04-20 13:01:53 -07002457 buf = qdf_mem_malloc(WE_MAX_STR_LEN);
2458 if (buf) {
2459 buf_len = hdd_wlan_get_version(hdd_ctx, WE_MAX_STR_LEN, buf);
2460 hdd_info("%s", buf);
2461 qdf_mem_free(buf);
2462 }
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302463}
2464
2465/**
gbian62edd7e2017-03-07 13:12:13 +08002466 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2467 * @hdd_ctx: Pointer to hdd context
2468 *
2469 * Return: none
2470 */
2471static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002472hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002473{
2474 uint8_t num_entries = 0;
2475 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2476 uint8_t *tx_sched_wrr_ac;
2477 int i;
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002478 struct cds_context *cds_ctx;
gbian62edd7e2017-03-07 13:12:13 +08002479
2480 if (NULL == hdd_ctx)
2481 return;
2482
2483 if (NULL == hdd_ctx->config) {
2484 /* Do nothing if hdd_ctx is invalid */
2485 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2486 return;
2487 }
2488
2489 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2490
2491 if (!cds_ctx) {
2492 hdd_err("Invalid CDS Context");
2493 return;
2494 }
2495
2496 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2497 switch (i) {
2498 case OL_TX_WMM_AC_BE:
2499 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2500 break;
2501 case OL_TX_WMM_AC_BK:
2502 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2503 break;
2504 case OL_TX_WMM_AC_VI:
2505 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2506 break;
2507 case OL_TX_WMM_AC_VO:
2508 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2509 break;
2510 default:
2511 tx_sched_wrr_ac = NULL;
2512 break;
2513 }
2514
2515 hdd_string_to_u8_array(tx_sched_wrr_ac,
2516 tx_sched_wrr_param,
2517 &num_entries,
2518 sizeof(tx_sched_wrr_param));
2519
2520 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2521 cds_ctx->ac_specs[i].wrr_skip_weight =
2522 tx_sched_wrr_param[0];
2523 cds_ctx->ac_specs[i].credit_threshold =
2524 tx_sched_wrr_param[1];
2525 cds_ctx->ac_specs[i].send_limit =
2526 tx_sched_wrr_param[2];
2527 cds_ctx->ac_specs[i].credit_reserve =
2528 tx_sched_wrr_param[3];
2529 cds_ctx->ac_specs[i].discard_weight =
2530 tx_sched_wrr_param[4];
2531 }
2532
2533 num_entries = 0;
2534 }
2535}
2536
Ryan Hsuaadba072018-04-20 13:01:53 -07002537uint32_t hdd_wlan_get_version(struct hdd_context *hdd_ctx,
2538 const size_t version_len, uint8_t *version)
2539{
2540 uint32_t size;
2541 uint32_t msp_id = 0, mspid = 0, siid = 0, crmid = 0, sub_id = 0;
2542
2543 if (!hdd_ctx) {
2544 hdd_err("Invalid context, HDD context is null");
2545 return 0;
2546 }
2547
Ashish Kumar Dhanotiya7353f882018-05-15 12:50:19 +05302548 if (!version || version_len == 0) {
Ryan Hsuaadba072018-04-20 13:01:53 -07002549 hdd_err("Invalid buffer pointr or buffer len\n");
2550 return 0;
2551 }
2552
2553 msp_id = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
2554 mspid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
2555 siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
2556 crmid = hdd_ctx->target_fw_version & 0x7fff;
2557 sub_id = (hdd_ctx->target_fw_vers_ext & 0xf0000000) >> 28;
2558
2559 size = scnprintf(version, version_len,
Ryan Hsuc6918552018-05-16 13:29:59 -07002560 "Host SW:%s, FW:%d.%d.%d.%d.%d, HW:%s, Board ver: %x Ref design id: %x, Customer id: %x, Project id: %x, Board Data Rev: %x",
Ryan Hsuaadba072018-04-20 13:01:53 -07002561 QWLAN_VERSIONSTR,
2562 msp_id, mspid, siid, crmid, sub_id,
Ryan Hsuc6918552018-05-16 13:29:59 -07002563 hdd_ctx->target_hw_name,
2564 hdd_ctx->hw_bd_info.bdf_version,
2565 hdd_ctx->hw_bd_info.ref_design_id,
2566 hdd_ctx->hw_bd_info.customer_id,
2567 hdd_ctx->hw_bd_info.project_id,
2568 hdd_ctx->hw_bd_info.board_data_rev);
Ryan Hsuaadba072018-04-20 13:01:53 -07002569
2570 return size;
2571}
2572
Rachit Kankane0dc3e852018-05-07 17:33:42 +05302573int hdd_set_11ax_rate(struct hdd_adapter *adapter, int set_value,
2574 struct sap_config *sap_config)
2575{
2576 uint8_t preamble = 0, nss = 0, rix = 0;
2577 int ret;
2578 mac_handle_t mac_handle = adapter->hdd_ctx->mac_handle;
2579
2580 if (!sap_config) {
2581 if (!sme_is_feature_supported_by_fw(DOT11AX)) {
2582 hdd_err("Target does not support 11ax");
2583 return -EIO;
2584 }
2585 } else if (sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax &&
2586 sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax_ONLY) {
2587 hdd_err("Invalid hw mode, SAP hw_mode= 0x%x, ch = %d",
2588 sap_config->SapHw_mode, sap_config->channel);
2589 return -EIO;
2590 }
2591
2592 if (set_value != 0xff) {
2593 rix = RC_2_RATE_IDX_11AX(set_value);
2594 preamble = WMI_RATE_PREAMBLE_HE;
2595 nss = HT_RC_2_STREAMS_11AX(set_value);
2596
2597 set_value = hdd_assemble_rate_code(preamble, nss, rix);
2598 } else {
2599 ret = sme_set_auto_rate_he_ltf(mac_handle, adapter->session_id,
2600 QCA_WLAN_HE_LTF_AUTO);
2601 }
2602
2603 hdd_info("SET_11AX_RATE val %d rix %d preamble %x nss %d",
2604 set_value, rix, preamble, nss);
2605
2606 ret = wma_cli_set_command(adapter->session_id,
2607 WMI_VDEV_PARAM_FIXED_RATE,
2608 set_value, VDEV_CMD);
2609
2610 return ret;
2611}
2612
2613int hdd_assemble_rate_code(uint8_t preamble, uint8_t nss, uint8_t rate)
2614{
2615 int set_value;
2616
2617 if (sme_is_feature_supported_by_fw(DOT11AX))
2618 set_value = WMI_ASSEMBLE_RATECODE_V1(rate, nss, preamble);
2619 else
2620 set_value = (preamble << 6) | (nss << 4) | rate;
2621
2622 return set_value;
2623}
2624
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302625#ifdef IPA_OFFLOAD
2626/**
2627 * hdd_update_ipa_component_config() - update ipa config
2628 * @hdd_ctx: Pointer to hdd context
2629 *
2630 * Return: none
2631 */
2632static void hdd_update_ipa_component_config(struct hdd_context *hdd_ctx)
2633{
2634 struct hdd_config *cfg = hdd_ctx->config;
2635 struct wlan_ipa_config ipa_cfg;
2636
2637 ipa_cfg.ipa_config = cfg->IpaConfig;
2638 ipa_cfg.desc_size = cfg->IpaDescSize;
2639 ipa_cfg.txbuf_count = cfg->IpaUcTxBufCount;
2640 ipa_cfg.bus_bw_high = cfg->busBandwidthHighThreshold;
2641 ipa_cfg.bus_bw_medium = cfg->busBandwidthMediumThreshold;
2642 ipa_cfg.bus_bw_low = cfg->busBandwidthLowThreshold;
2643 ipa_cfg.ipa_bw_high = cfg->IpaHighBandwidthMbps;
2644 ipa_cfg.ipa_bw_medium = cfg->IpaMediumBandwidthMbps;
2645 ipa_cfg.ipa_bw_low = cfg->IpaLowBandwidthMbps;
2646
2647 ucfg_ipa_update_config(&ipa_cfg);
2648}
2649#else
2650static void hdd_update_ipa_component_config(struct hdd_context *hdd_ctx)
2651{
2652}
2653#endif
2654
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002655#ifdef FEATURE_WLAN_WAPI
2656/**
2657 * hdd_wapi_security_sta_exist() - return wapi security sta exist or not
2658 *
2659 * This API returns the wapi security station exist or not
2660 *
2661 * Return: true - wapi security station exist
2662 */
2663static bool hdd_wapi_security_sta_exist(void)
2664{
2665 struct hdd_adapter *adapter = NULL;
2666 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2667
2668 hdd_for_each_adapter(hdd_ctx, adapter) {
2669 if ((adapter->device_mode == QDF_STA_MODE) &&
2670 adapter->wapi_info.wapi_mode &&
2671 (adapter->wapi_info.wapi_auth_mode != WAPI_AUTH_MODE_OPEN))
2672 return true;
2673 }
2674 return false;
2675}
2676#else
2677static bool hdd_wapi_security_sta_exist(void)
2678{
2679 return false;
2680}
2681#endif
2682
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002683#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002684static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2685 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2686{
Jeff Johnson9d295242017-08-29 14:39:48 -07002687 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002688 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002689
2690 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2691 if (!adapter) {
2692 hdd_err("Adapter is NULL");
2693 return PM_MAX_NUM_OF_MODE;
2694 }
2695
2696 return policy_mgr_convert_device_mode_to_qdf_type(
2697 adapter->device_mode);
2698}
2699
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002700static void hdd_register_policy_manager_callback(
2701 struct wlan_objmgr_psoc *psoc)
2702{
2703 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002704
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002705 qdf_mem_zero(&hdd_cbacks, sizeof(hdd_cbacks));
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002706 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002707 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002708 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2709 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002710 hdd_cbacks.get_mode_for_non_connected_vdev =
2711 wlan_hdd_get_mode_for_non_connected_vdev;
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05302712 hdd_cbacks.hdd_get_device_mode = hdd_get_device_mode;
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002713 hdd_cbacks.hdd_wapi_security_sta_exist =
2714 hdd_wapi_security_sta_exist;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002715 if (QDF_STATUS_SUCCESS !=
2716 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2717 hdd_err("HDD callback registration with policy manager failed");
2718 }
2719}
2720#else
2721static void hdd_register_policy_manager_callback(
2722 struct wlan_objmgr_psoc *psoc)
2723{
2724}
2725#endif
2726
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002727static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002728{
2729 struct nan_callbacks cb_obj = {0};
2730
2731 cb_obj.ndi_open = hdd_ndi_open;
2732 cb_obj.ndi_close = hdd_ndi_close;
2733 cb_obj.ndi_start = hdd_ndi_start;
2734 cb_obj.ndi_delete = hdd_ndi_delete;
2735 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2736 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2737
Naveen Rawat37f62c82017-03-26 22:24:43 -07002738 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2739 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002740 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002741
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002742 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2743}
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002744
Dustin Brown26b3d042017-12-21 11:13:27 -08002745#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002746/**
2747 * hdd_check_for_leaks() - Perform runtime memory leak checks
Dustin Browna6246dd2018-05-24 14:35:58 -07002748 * @hdd_ctx: the global HDD context
Dustin Brown29533f22018-07-24 13:11:56 -07002749 * @is_ssr: true if SSR is in progress
Dustin Brown4c5b9902017-12-19 11:17:19 -08002750 *
2751 * This API triggers runtime memory leak detection. This feature enforces the
2752 * policy that any memory allocated at runtime must also be released at runtime.
2753 *
2754 * Allocating memory at runtime and releasing it at unload is effectively a
2755 * memory leak for configurations which never unload (e.g. LONU, statically
2756 * compiled driver). Such memory leaks are NOT false positives, and must be
2757 * fixed.
2758 *
2759 * Return: None
2760 */
Dustin Brown29533f22018-07-24 13:11:56 -07002761static void hdd_check_for_leaks(struct hdd_context *hdd_ctx, bool is_ssr)
Dustin Brown4bc0a622017-12-06 15:56:50 -08002762{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002763 /* DO NOT REMOVE these checks; for false positives, read above first */
2764
Dustin Brown3cfe0d42018-07-25 14:13:47 -07002765 wlan_objmgr_psoc_check_for_peer_leaks(hdd_ctx->hdd_psoc);
Dustin Browna6246dd2018-05-24 14:35:58 -07002766 wlan_objmgr_psoc_check_for_vdev_leaks(hdd_ctx->hdd_psoc);
Dustin Brown29462962018-06-18 14:02:00 -07002767 wlan_objmgr_psoc_check_for_pdev_leaks(hdd_ctx->hdd_psoc);
Dustin Brown29533f22018-07-24 13:11:56 -07002768
2769 /* many adapter resources are not freed by design during SSR */
2770 if (is_ssr)
2771 return;
2772
Dustin Brown677e0862017-10-10 16:30:09 -07002773 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002774 qdf_nbuf_map_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002775 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002776}
2777
Dustin Brown26b3d042017-12-21 11:13:27 -08002778#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2779#else
Dustin Brown29533f22018-07-24 13:11:56 -07002780static inline void hdd_check_for_leaks(struct hdd_context *hdd_ctx, bool is_ssr)
2781{ }
Dustin Brown26b3d042017-12-21 11:13:27 -08002782
2783#define hdd_debug_domain_set(domain)
2784#endif /* CONFIG_LEAK_DETECTION */
2785
gbian62edd7e2017-03-07 13:12:13 +08002786/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002787 * hdd_update_country_code - Update country code
2788 * @hdd_ctx: HDD context
2789 *
2790 * Update country code based on module parameter country_code
2791 *
2792 * Return: 0 on success and errno on failure
2793 */
2794static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2795{
2796 if (!country_code)
2797 return 0;
2798
2799 return hdd_reg_set_country(hdd_ctx, country_code);
2800}
2801
2802/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302803 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2804 * @hdd_ctx: HDD context
Arun Khandavallifae92942016-08-01 13:31:08 +05302805 * @reinit: flag to indicate from SSR or normal path
2806 *
2807 * This function maintains the driver state machine it will be invoked from
2808 * startup, reinit and change interface. Depending on the driver state shall
2809 * perform the opening of the modules.
2810 *
2811 * Return: 0 for success; non-zero for failure
2812 */
Dustin Browne7e71d32018-05-11 16:00:08 -07002813int hdd_wlan_start_modules(struct hdd_context *hdd_ctx, bool reinit)
Arun Khandavallifae92942016-08-01 13:31:08 +05302814{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002815 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302816 qdf_device_t qdf_dev;
2817 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302818 bool unint = false;
2819 void *hif_ctx;
Jingxiang Ge95912f82018-04-19 12:01:26 +08002820 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +05302821
Arun Khandavallifae92942016-08-01 13:31:08 +05302822 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2823 if (!qdf_dev) {
2824 hdd_err("QDF Device Context is Invalid return");
2825 return -EINVAL;
2826 }
2827
Dustin Brown6f427922017-09-19 12:19:00 -07002828 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05302829
Dustin Brown1fe30a82017-10-03 16:13:36 -07002830 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302831 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2832 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002833 hdd_debug("Driver modules already Enabled");
Dustin Browne74003f2018-03-14 12:51:58 -07002834 hdd_exit();
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302835 return 0;
2836 }
2837
Dustin Brown1fe30a82017-10-03 16:13:36 -07002838 hdd_ctx->start_modules_in_progress = true;
2839
Arun Khandavallifae92942016-08-01 13:31:08 +05302840 switch (hdd_ctx->driver_status) {
2841 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002842 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302843 unint = true;
2844 /* Fall through dont add break here */
2845 case DRIVER_MODULES_CLOSED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002846 hdd_info("Wlan transitioning (CLOSED -> OPENED)");
2847
Dustin Brown26b3d042017-12-21 11:13:27 -08002848 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002849
Arun Khandavallifae92942016-08-01 13:31:08 +05302850 if (!reinit && !unint) {
2851 ret = pld_power_on(qdf_dev->dev);
2852 if (ret) {
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002853 hdd_err("Failed to power up device; errno:%d",
Dustin Browndca39692017-11-09 15:30:25 -08002854 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302855 goto release_lock;
2856 }
2857 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002858
2859 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2860 hdd_ctx->config->enable_fw_log);
Arun Khandavallifae92942016-08-01 13:31:08 +05302861 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2862 qdf_dev->bus_type,
2863 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2864 HIF_ENABLE_TYPE_PROBE);
2865 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002866 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302867 goto power_down;
2868 }
2869
2870 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302871 if (!hif_ctx) {
2872 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002873 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302874 goto power_down;
2875 }
2876
Arun Khandavallifae92942016-08-01 13:31:08 +05302877 status = ol_cds_init(qdf_dev, hif_ctx);
2878 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002879 hdd_err("No Memory to Create BMI Context; status: %d",
2880 status);
2881 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302882 goto hif_close;
2883 }
2884
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302885 hdd_update_ipa_component_config(hdd_ctx);
2886
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002887 ret = hdd_update_config(hdd_ctx);
2888 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002889 hdd_err("Failed to update configuration; errno: %d",
2890 ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002891 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002892 }
2893
gbian62edd7e2017-03-07 13:12:13 +08002894 hdd_update_cds_ac_specs_params(hdd_ctx);
2895
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05302896 status = hdd_component_psoc_open(hdd_ctx->hdd_psoc);
2897 if (QDF_IS_STATUS_ERROR(status)) {
2898 hdd_err("Failed to Open legacy components; status: %d",
2899 status);
2900 ret = qdf_status_to_os_return(status);
2901 goto deinit_config;
2902 }
2903
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302904 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002905 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002906 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002907 ret = qdf_status_to_os_return(status);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05302908 goto hdd_psoc_close;
Arun Khandavallifae92942016-08-01 13:31:08 +05302909 }
2910
Manjunathappa Prakashb6b4ff12018-06-04 12:32:33 -07002911 if (hdd_ctx->config->rx_thread_affinity_mask)
2912 cds_set_rx_thread_cpu_mask(
2913 hdd_ctx->config->rx_thread_affinity_mask);
2914
2915 /* initialize components configurations after psoc open */
Mukul Sharma9d797a02017-01-05 20:26:03 +05302916 ret = hdd_update_components_config(hdd_ctx);
2917 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002918 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302919 ret);
2920 goto close;
2921 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002922 status = cds_dp_open(hdd_ctx->hdd_psoc);
2923 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002924 hdd_err("Failed to Open cds post open; status: %d",
2925 status);
2926 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002927 goto close;
2928 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302929
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002930 /*
2931 * NAN compoenet requires certian operations like, open adapter,
2932 * close adapter, etc. to be initiated by HDD, for those
2933 * register HDD callbacks with UMAC's NAN componenet.
2934 */
2935 hdd_nan_register_callbacks(hdd_ctx);
2936
Jeff Johnson16528362018-06-14 12:34:16 -07002937 hdd_ctx->mac_handle = cds_get_context(QDF_MODULE_ID_SME);
Arun Khandavallifae92942016-08-01 13:31:08 +05302938
Jeff Johnson3a280122017-09-13 07:42:00 -07002939 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302940 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002941 hdd_err("Failed to pre-enable CDS; status: %d", status);
2942 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002943 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302944 }
2945
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002946 hdd_register_policy_manager_callback(
2947 hdd_ctx->hdd_psoc);
2948
Amar Singhal0928b192017-12-01 10:50:54 -08002949 hdd_sysfs_create_version_interface(hdd_ctx->hdd_psoc);
2950
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302951 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302952 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002953 hdd_info("Wlan transitioned (now OPENED)");
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302954
Arun Khandavallifae92942016-08-01 13:31:08 +05302955 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002956 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302957 break;
2958 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302959
Arun Khandavallifae92942016-08-01 13:31:08 +05302960 /* Fall through dont add break here */
2961 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002962 hdd_info("Wlan transitioning (OPENED -> ENABLED)");
2963
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302964 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2965 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002966 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302967 break;
2968 }
Dustin Browndca39692017-11-09 15:30:25 -08002969
Dustin Browne7e71d32018-05-11 16:00:08 -07002970 ret = hdd_configure_cds(hdd_ctx);
Dustin Browndca39692017-11-09 15:30:25 -08002971 if (ret) {
2972 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002973 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302974 }
Dustin Browndca39692017-11-09 15:30:25 -08002975
Komal Seelamf2136bb2016-09-28 18:30:44 +05302976 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002977
Arun Khandavallifae92942016-08-01 13:31:08 +05302978 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002979 hdd_info("Wlan transitioned (now ENABLED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302980 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002981
Arun Khandavallifae92942016-08-01 13:31:08 +05302982 default:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002983 QDF_DEBUG_PANIC("Unknown driver state:%d",
Arun Khandavallifae92942016-08-01 13:31:08 +05302984 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002985 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302986 goto release_lock;
2987 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002988
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302989 hdd_ctx->start_modules_in_progress = false;
Paul Zhange03cf4c2018-01-19 18:33:22 +08002990 if (DRIVER_MODULES_ENABLED == hdd_ctx->driver_status) {
2991 ret = hdd_update_country_code(hdd_ctx);
2992 if (ret)
2993 hdd_err("Failed to update command line country code!");
2994 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302995 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002996
Dustin Browne74003f2018-03-14 12:51:58 -07002997 hdd_exit();
Dustin Brown550f6d22017-12-14 15:44:01 -08002998
Arun Khandavallifae92942016-08-01 13:31:08 +05302999 return 0;
3000
Rajeev Kumara3f672f2017-02-16 13:59:37 -08003001post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08003002 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08003003
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07003004cds_txrx_free:
Jingxiang Ge95912f82018-04-19 12:01:26 +08003005 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
3006
3007 if (tgt_hdl && target_psoc_get_wmi_ready(tgt_hdl)) {
3008 hdd_runtime_suspend_context_deinit(hdd_ctx);
3009 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
3010 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
3011 }
3012
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07003013 cds_dp_close(hdd_ctx->hdd_psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08003014
Arun Khandavallifae92942016-08-01 13:31:08 +05303015close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08003016 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08003017 hdd_info("Wlan transition aborted (now CLOSED)");
3018
Jeff Johnsone4b14592017-09-13 14:23:33 -07003019 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05303020
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05303021hdd_psoc_close:
3022 hdd_component_psoc_close(hdd_ctx->hdd_psoc);
3023
Dustin Brown28b17892017-10-10 13:29:38 -07003024deinit_config:
3025 cds_deinit_ini_config();
3026
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07003027cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05303028 ol_cds_free();
3029
3030hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07003031 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
3032 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05303033power_down:
3034 if (!reinit && !unint)
3035 pld_power_off(qdf_dev->dev);
3036release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05303037 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05303038 mutex_unlock(&hdd_ctx->iface_change_lock);
Abhinav Kumar7ae9b7b2017-12-19 15:11:54 +05303039 if (hdd_ctx->target_hw_name) {
3040 qdf_mem_free(hdd_ctx->target_hw_name);
3041 hdd_ctx->target_hw_name = NULL;
3042 }
Dustin Brown29533f22018-07-24 13:11:56 -07003043
3044 hdd_check_for_leaks(hdd_ctx, reinit);
Dustin Brown26b3d042017-12-21 11:13:27 -08003045 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08003046
Dustin Browne74003f2018-03-14 12:51:58 -07003047 hdd_exit();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08003048
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07003049 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05303050}
3051
Naveen Rawat910726a2017-03-06 11:42:51 -08003052#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003053static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003054{
3055 int ret = os_if_wifi_pos_register_nl();
3056
3057 if (ret)
3058 hdd_err("os_if_wifi_pos_register_nl failed");
3059
3060 return ret;
3061}
3062
3063static int hdd_deactivate_wifi_pos(void)
3064{
3065 int ret = os_if_wifi_pos_deregister_nl();
3066
3067 if (ret)
3068 hdd_err("os_if_wifi_pos_deregister_nl failed");
3069
3070 return ret;
3071}
3072
3073/**
3074 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
3075 * @hdd_ctx: hdd context
3076 *
3077 * Return: status of operation
3078 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003079static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003080{
3081 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3082 struct hdd_config *cfg = hdd_ctx->config;
3083
3084 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
3085 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
3086 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
3087 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
3088 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
3089 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
3090 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
3091 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
3092}
3093#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003094static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003095{
3096 return oem_activate_service(hdd_ctx);
3097}
3098
3099static int hdd_deactivate_wifi_pos(void)
3100{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05303101 return oem_deactivate_service();
Naveen Rawat910726a2017-03-06 11:42:51 -08003102}
3103
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003104static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003105{
3106}
3107#endif
3108
Arun Khandavallifae92942016-08-01 13:31:08 +05303109/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003110 * __hdd_open() - HDD Open function
3111 * @dev: Pointer to net_device structure
3112 *
3113 * This is called in response to ifconfig up
3114 *
3115 * Return: 0 for success; non-zero for failure
3116 */
3117static int __hdd_open(struct net_device *dev)
3118{
Jeff Johnson9d295242017-08-29 14:39:48 -07003119 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003120 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003121 int ret;
3122
Dustin Brownfdf17c12018-03-14 12:55:34 -07003123 hdd_enter_dev(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303124 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003125 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003126
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05303127 /* Nothing to be done if device is unloading */
3128 if (cds_is_driver_unloading()) {
3129 hdd_err("Driver is unloading can not open the hdd");
3130 return -EBUSY;
3131 }
3132
Dustin Brown01847752017-10-25 13:56:27 -07003133 if (cds_is_driver_recovering()) {
3134 hdd_err("WLAN is currently recovering; Please try again.");
3135 return -EBUSY;
3136 }
3137
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05303138 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
3139 hdd_err("con_mode_handler is in progress; Please try again.");
3140 return -EBUSY;
3141 }
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303142
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05303143 mutex_lock(&hdd_init_deinit_lock);
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05303144 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
3145
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303146 /*
3147 * This scenario can be hit in cases where in the wlan driver after
3148 * registering the netdevices and there is a failure in driver
3149 * initialization. So return error gracefully because the netdevices
3150 * will be de-registered as part of the load failure.
3151 */
3152
3153 if (!cds_is_driver_loaded()) {
3154 hdd_err("Failed to start the wlan driver!!");
3155 ret = -EIO;
3156 goto err_hdd_hdd_init_deinit_lock;
3157 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303158
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003159
Dustin Browne7e71d32018-05-11 16:00:08 -07003160 ret = hdd_wlan_start_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05303161 if (ret) {
3162 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303163 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05303164 }
3165
3166
3167 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3168 ret = hdd_start_adapter(adapter);
3169 if (ret) {
3170 hdd_err("Failed to start adapter :%d",
3171 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303172 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05303173 }
3174 }
3175
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003176 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3177 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003178 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003179 /* Enable TX queues only when we are connected */
3180 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05303181 WLAN_START_ALL_NETIF_QUEUE,
3182 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003183 }
3184
Naveen Rawat286def52016-09-23 15:38:02 -07003185 /* Enable carrier and transmit queues for NDI */
3186 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003187 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07003188 wlan_hdd_netif_queue_control(adapter,
3189 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
3190 WLAN_CONTROL_PATH);
3191 }
3192
Naveen Rawat910726a2017-03-06 11:42:51 -08003193 hdd_populate_wifi_pos_cfg(hdd_ctx);
Arunk Khandavalli40943af2017-05-15 19:25:34 +05303194 hdd_lpass_notify_start(hdd_ctx, adapter);
Naveen Rawat910726a2017-03-06 11:42:51 -08003195
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303196err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05303197 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303198 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003199 return ret;
3200}
3201
Arun Khandavallifae92942016-08-01 13:31:08 +05303202
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003203/**
3204 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
3205 * @dev: Pointer to net_device structure
3206 *
3207 * This is called in response to ifconfig up
3208 *
3209 * Return: 0 for success; non-zero for failure
3210 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003211static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003212{
3213 int ret;
3214
3215 cds_ssr_protect(__func__);
3216 ret = __hdd_open(dev);
3217 cds_ssr_unprotect(__func__);
3218
3219 return ret;
3220}
3221
3222/**
3223 * __hdd_stop() - HDD stop function
3224 * @dev: Pointer to net_device structure
3225 *
3226 * This is called in response to ifconfig down
3227 *
3228 * Return: 0 for success; non-zero for failure
3229 */
3230static int __hdd_stop(struct net_device *dev)
3231{
Jeff Johnson9d295242017-08-29 14:39:48 -07003232 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003233 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003234 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -07003235 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003236
Dustin Brownfdf17c12018-03-14 12:55:34 -07003237 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003238
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303239 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003240 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003241
3242 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303243 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003244 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003245
3246 /* Nothing to be done if the interface is not opened */
3247 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003248 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003249 return -ENODEV;
3250 }
3251
3252 /* Make sure the interface is marked as closed */
3253 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303254
Jeff Johnson16528362018-06-14 12:34:16 -07003255 mac_handle = hdd_ctx->mac_handle;
3256
Mukul Sharmad16c2022017-07-25 18:56:12 +05303257 hdd_debug("Disabling Auto Power save timer");
3258 sme_ps_disable_auto_ps_timer(
Jeff Johnson16528362018-06-14 12:34:16 -07003259 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003260 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303261
3262 /*
3263 * Disable TX on the interface, after this hard_start_xmit() will not
3264 * be called on that interface
3265 */
Dustin Browna7bb6ae2018-08-16 16:51:50 -07003266 hdd_debug("Disabling queues, adapter device mode: %s(%d)",
3267 hdd_device_mode_to_string(adapter->device_mode),
3268 adapter->device_mode);
Kabilan Kannan8dac3502017-10-30 12:40:27 -07003269
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303270 wlan_hdd_netif_queue_control(adapter,
3271 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3272 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003273
Arunk Khandavalli40943af2017-05-15 19:25:34 +05303274 if (adapter->device_mode == QDF_STA_MODE)
3275 hdd_lpass_notify_stop(hdd_ctx);
3276
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003277 /*
Naveen Rawat286def52016-09-23 15:38:02 -07003278 * NAN data interface is different in some sense. The traffic on NDI is
3279 * bursty in nature and depends on the need to transfer. The service
3280 * layer may down the interface after the usage and up again when
3281 * required. In some sense, the NDI is expected to be available
3282 * (like SAP) iface until NDI delete request is issued by the service
3283 * layer. Skip BSS termination and adapter deletion for NAN Data
3284 * interface (NDI).
3285 */
3286 if (WLAN_HDD_IS_NDI(adapter))
3287 return 0;
3288
3289 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003290 * The interface is marked as down for outside world (aka kernel)
3291 * But the driver is pretty much alive inside. The driver needs to
3292 * tear down the existing connection on the netdev (session)
3293 * cleanup the data pipes and wait until the control plane is stabilized
3294 * for this interface. The call also needs to wait until the above
3295 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003296 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003297 * That is intentional to be able to scan if it is a STA/P2P interface
3298 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08003299 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003300
3301 /* DeInit the adapter. This ensures datapath cleanup as well */
3302 hdd_deinit_adapter(hdd_ctx, adapter, true);
3303
Arun Khandavallifae92942016-08-01 13:31:08 +05303304
3305 /*
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +05303306 * Upon wifi turn off, DUT has to flush the scan results so if
3307 * this is the last cli iface, flush the scan database.
3308 */
3309 if (!hdd_is_cli_iface_up(hdd_ctx))
Jeff Johnson16528362018-06-14 12:34:16 -07003310 sme_scan_flush_result(mac_handle);
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +05303311
3312 /*
Arun Khandavallifae92942016-08-01 13:31:08 +05303313 * Find if any iface is up. If any iface is up then can't put device to
3314 * sleep/power save mode
3315 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05303316 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003317 hdd_debug("Closing all modules from the hdd_stop");
Dustin Brown6f427922017-09-19 12:19:00 -07003318 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
3319 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05303320 hdd_prevent_suspend_timeout(
3321 hdd_ctx->config->iface_change_wait_time,
3322 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05303323 }
3324
Dustin Browne74003f2018-03-14 12:51:58 -07003325 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003326 return 0;
3327}
3328
3329/**
3330 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3331 * @dev: pointer to net_device structure
3332 *
3333 * This is called in response to ifconfig down
3334 *
3335 * Return: 0 for success and error number for failure
3336 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003337static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003338{
3339 int ret;
3340
3341 cds_ssr_protect(__func__);
3342 ret = __hdd_stop(dev);
3343 cds_ssr_unprotect(__func__);
3344
3345 return ret;
3346}
3347
3348/**
3349 * __hdd_uninit() - HDD uninit function
3350 * @dev: Pointer to net_device structure
3351 *
3352 * This is called during the netdev unregister to uninitialize all data
3353 * associated with the device
3354 *
3355 * Return: None
3356 */
3357static void __hdd_uninit(struct net_device *dev)
3358{
Jeff Johnson9d295242017-08-29 14:39:48 -07003359 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003360 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003361
Dustin Brownfdf17c12018-03-14 12:55:34 -07003362 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003363
3364 do {
3365 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003366 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003367 break;
3368 }
3369
Jeff Johnson399c6272017-08-30 10:51:00 -07003370 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3371 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003372 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003373 break;
3374 }
3375
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003376 if (dev != adapter->dev)
3377 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003378
Jeff Johnson399c6272017-08-30 10:51:00 -07003379 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003380
3381 /* after uninit our adapter structure will no longer be valid */
3382 adapter->dev = NULL;
3383 adapter->magic = 0;
3384 } while (0);
3385
Dustin Browne74003f2018-03-14 12:51:58 -07003386 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003387}
3388
3389/**
3390 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
3391 * @dev: pointer to net_device structure
3392 *
3393 * This is called during the netdev unregister to uninitialize all data
3394 * associated with the device
3395 *
3396 * Return: none
3397 */
3398static void hdd_uninit(struct net_device *dev)
3399{
3400 cds_ssr_protect(__func__);
3401 __hdd_uninit(dev);
3402 cds_ssr_unprotect(__func__);
3403}
3404
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003405static int hdd_open_cesium_nl_sock(void)
3406{
3407#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3408 struct netlink_kernel_cfg cfg = {
3409 .groups = WLAN_NLINK_MCAST_GRP_ID,
3410 .input = NULL
3411 };
3412#endif
3413 int ret = 0;
3414
3415#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3416 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3417#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3418 THIS_MODULE,
3419#endif
3420 &cfg);
3421#else
3422 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3423 WLAN_NLINK_MCAST_GRP_ID,
3424 NULL, NULL, THIS_MODULE);
3425#endif
3426
3427 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003428 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003429 ret = -ECONNREFUSED;
3430 }
3431
3432 return ret;
3433}
3434
3435static void hdd_close_cesium_nl_sock(void)
3436{
3437 if (NULL != cesium_nl_srv_sock) {
3438 netlink_kernel_release(cesium_nl_srv_sock);
3439 cesium_nl_srv_sock = NULL;
3440 }
3441}
3442
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003443/**
3444 * __hdd_set_mac_address() - set the user specified mac address
3445 * @dev: Pointer to the net device.
3446 * @addr: Pointer to the sockaddr.
3447 *
3448 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003449 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003450 *
3451 * Return: 0 for success, non zero for failure
3452 */
3453static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3454{
Jeff Johnson9d295242017-08-29 14:39:48 -07003455 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303456 struct hdd_adapter *adapter_temp;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003457 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003458 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303459 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003460 int ret;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303461 struct qdf_mac_addr mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003462
Dustin Brownfdf17c12018-03-14 12:55:34 -07003463 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003464
Hanumanth Reddy Pothula5c7a7812018-03-09 12:55:32 +05303465 if (netif_running(dev)) {
3466 hdd_err("On iface up, set mac address change isn't supported");
3467 return -EBUSY;
3468 }
3469
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003470 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3471 ret = wlan_hdd_validate_context(hdd_ctx);
3472 if (0 != ret)
3473 return ret;
3474
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303475 qdf_mem_copy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303476 adapter_temp = hdd_get_adapter_by_macaddr(hdd_ctx, mac_addr.bytes);
3477 if (adapter_temp) {
3478 if (!qdf_str_cmp(adapter_temp->dev->name, dev->name))
3479 return 0;
3480 hdd_err("%s adapter exist with same address " MAC_ADDRESS_STR,
3481 adapter_temp->dev->name,
Ashish Kumar Dhanotiyaf974f332018-04-19 16:03:15 +05303482 MAC_ADDR_ARRAY(mac_addr.bytes));
3483 return -EINVAL;
3484 }
3485
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303486 if (qdf_is_macaddr_zero(&mac_addr)) {
3487 hdd_err("MAC is all zero");
3488 return -EINVAL;
3489 }
3490
3491 if (qdf_is_macaddr_broadcast(&mac_addr)) {
3492 hdd_err("MAC is Broadcast");
3493 return -EINVAL;
3494 }
3495
3496 if (ETHER_IS_MULTICAST(psta_mac_addr->sa_data)) {
3497 hdd_err("MAC is Multicast");
3498 return -EINVAL;
3499 }
Ashish Kumar Dhanotiya8bfef122018-04-18 16:48:27 +05303500 hdd_info("Changing MAC to " MAC_ADDRESS_STR " of the interface %s ",
3501 MAC_ADDR_ARRAY(mac_addr.bytes), dev->name);
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303502
Jeff Johnson1e851a12017-10-28 14:36:12 -07003503 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003504 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3505
Dustin Browne74003f2018-03-14 12:51:58 -07003506 hdd_exit();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303507 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003508}
3509
3510/**
3511 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3512 * function from SSR
3513 * @dev: pointer to net_device structure
3514 * @addr: Pointer to the sockaddr
3515 *
3516 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003517 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003518 *
3519 * Return: 0 for success.
3520 */
3521static int hdd_set_mac_address(struct net_device *dev, void *addr)
3522{
3523 int ret;
3524
3525 cds_ssr_protect(__func__);
3526 ret = __hdd_set_mac_address(dev, addr);
3527 cds_ssr_unprotect(__func__);
3528
3529 return ret;
3530}
3531
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003532uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003533{
3534 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003535
Anurag Chouhan6d760662016-02-20 16:05:43 +05303536 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003537 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
3538 break;
3539 }
3540
Anurag Chouhan6d760662016-02-20 16:05:43 +05303541 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003542 return NULL;
3543
3544 hdd_ctx->config->intfAddrMask |= (1 << i);
3545 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
3546}
3547
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003548void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3549 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003550{
3551 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003552
Anurag Chouhan6d760662016-02-20 16:05:43 +05303553 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003554 if (!memcmp(releaseAddr,
3555 &hdd_ctx->config->intfMacAddr[i].bytes[0],
3556 6)) {
3557 hdd_ctx->config->intfAddrMask &= ~(1 << i);
3558 break;
3559 }
3560 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003561}
3562
3563#ifdef WLAN_FEATURE_PACKET_FILTERING
3564/**
3565 * __hdd_set_multicast_list() - set the multicast address list
3566 * @dev: Pointer to the WLAN device.
3567 * @skb: Pointer to OS packet (sk_buff).
3568 *
3569 * This funciton sets the multicast address list.
3570 *
3571 * Return: None
3572 */
3573static void __hdd_set_multicast_list(struct net_device *dev)
3574{
Jeff Johnson9d295242017-08-29 14:39:48 -07003575 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Dustin Brown0f874482018-06-13 14:39:22 -07003576 int i = 0, errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003577 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003578 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303579 struct pmo_mc_addr_list_params *mc_list_request = NULL;
3580 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3581 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003582
Dustin Brownfdf17c12018-03-14 12:55:34 -07003583 hdd_enter_dev(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303584 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303585 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303586
Dustin Brown0f874482018-06-13 14:39:22 -07003587 errno = wlan_hdd_validate_context(hdd_ctx);
3588 if (errno)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303589 goto out;
3590
Dustin Brown0f874482018-06-13 14:39:22 -07003591 errno = hdd_validate_adapter(adapter);
3592 if (errno)
Dustin Brownc788acb2017-08-01 17:43:51 -07003593 goto out;
3594
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303595 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3596 hdd_err("%s: Driver module is closed", __func__);
Dustin Brown0f874482018-06-13 14:39:22 -07003597 goto out;
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303598 }
3599
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303600 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
3601 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003602 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303603 goto out;
3604 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003605
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303606 /* Delete already configured multicast address list */
3607 if (adapter->mc_addr_list.mc_cnt > 0) {
Dustin Brown0f874482018-06-13 14:39:22 -07003608 hdd_debug("clear previously configured MC address list");
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303609 hdd_disable_and_flush_mc_addr_list(adapter,
3610 pmo_mc_list_change_notify);
3611 }
3612
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003613 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003614 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303615 hdd_disable_and_flush_mc_addr_list(adapter,
3616 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003617 } else {
3618 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303619 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003620 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Dustin Brown0f874482018-06-13 14:39:22 -07003621 pmo_ucfg_max_mc_addr_supported(psoc));
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303622 hdd_disable_and_flush_mc_addr_list(adapter,
3623 pmo_mc_list_change_notify);
Dustin Brown0f874482018-06-13 14:39:22 -07003624 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003625 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003626 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003627 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303628 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003629 if (i == mc_count)
3630 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303631 memset(&(mc_list_request->mc_addr[i].bytes),
3632 0, ETH_ALEN);
3633 memcpy(&(mc_list_request->mc_addr[i].bytes),
3634 ha->addr, ETH_ALEN);
Dustin Brown0f874482018-06-13 14:39:22 -07003635 hdd_debug("mlist[%d] = %pM", i,
3636 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003637 i++;
3638 }
3639 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303640
3641 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003642 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303643 mc_list_request->count = mc_count;
Dustin Brown0f874482018-06-13 14:39:22 -07003644
3645 errno = hdd_cache_mc_addr_list(mc_list_request);
3646 if (errno) {
3647 hdd_err("Failed to cache MC address list for vdev %u; errno:%d",
3648 adapter->session_id, errno);
3649 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003650 }
Dustin Brown0f874482018-06-13 14:39:22 -07003651
3652 hdd_enable_mc_addr_filtering(adapter, pmo_mc_list_change_notify);
3653
3654free_req:
3655 qdf_mem_free(mc_list_request);
3656
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303657out:
Dustin Browne74003f2018-03-14 12:51:58 -07003658 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003659}
3660
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303661
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003662/**
3663 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3664 * @dev: pointer to net_device
3665 *
3666 * Return: none
3667 */
3668static void hdd_set_multicast_list(struct net_device *dev)
3669{
3670 cds_ssr_protect(__func__);
3671 __hdd_set_multicast_list(dev);
3672 cds_ssr_unprotect(__func__);
3673}
3674#endif
3675
3676/**
3677 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3678 * @dev: Pointer to the WLAN device.
3679 * @skb: Pointer to OS packet (sk_buff).
3680 *
3681 * This function is registered with the Linux OS for network
3682 * core to decide which queue to use first.
3683 *
3684 * Return: ac, Queue Index/access category corresponding to UP in IP header
3685 */
3686static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3687#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3688 , void *accel_priv
3689#endif
3690#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3691 , select_queue_fallback_t fallback
3692#endif
3693)
3694{
3695 return hdd_wmm_select_queue(dev, skb);
3696}
3697
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003698static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003699 .ndo_open = hdd_open,
3700 .ndo_stop = hdd_stop,
3701 .ndo_uninit = hdd_uninit,
3702 .ndo_start_xmit = hdd_hard_start_xmit,
3703 .ndo_tx_timeout = hdd_tx_timeout,
3704 .ndo_get_stats = hdd_get_stats,
3705 .ndo_do_ioctl = hdd_ioctl,
3706 .ndo_set_mac_address = hdd_set_mac_address,
3707 .ndo_select_queue = hdd_select_queue,
3708#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003709 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003710#endif
3711};
3712
Nirav Shah73713f72018-05-17 14:50:41 +05303713#ifdef FEATURE_MONITOR_MODE_SUPPORT
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003714/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003715static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003716 .ndo_open = hdd_mon_open,
3717 .ndo_stop = hdd_stop,
3718 .ndo_get_stats = hdd_get_stats,
3719};
3720
3721/**
3722 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003723 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003724 * Return: None
3725 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003726void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003727{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003728 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003729 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003730 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003731 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003732}
Nirav Shah73713f72018-05-17 14:50:41 +05303733#else
3734void hdd_set_station_ops(struct net_device *dev)
3735{
3736 dev->netdev_ops = &wlan_drv_ops;
3737}
3738#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003739
3740/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003741 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3742 * @hdd_ctx: global hdd context
3743 * @macAddr: mac address to assign to the interface
3744 * @name: User-visible name of the interface
3745 *
3746 * hdd adapter pointer would point to the netdev->priv space, this function
Jeff Johnson62018292018-05-06 16:18:35 -07003747 * would retrieve the pointer, and setup the hdd adapter configuration.
Ryan Hsu07495ea2016-01-21 15:25:39 -08003748 *
3749 * Return: the pointer to hdd adapter, otherwise NULL
3750 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003751static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003752 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003753 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003754 const char *name)
3755{
Jeff Johnson5505db82017-11-02 21:19:23 -07003756 struct net_device *dev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003757 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003758 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303759 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003760 /*
3761 * cfg80211 initialization and registration....
3762 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003763 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003764#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3765 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003766#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003767 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3768 hdd_mon_mode_ether_setup : ether_setup),
3769 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003770
Jeff Johnson5505db82017-11-02 21:19:23 -07003771 if (dev != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003772
3773 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson5505db82017-11-02 21:19:23 -07003774 adapter = (struct hdd_adapter *) netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003775
Jeff Johnson9d295242017-08-29 14:39:48 -07003776 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Jeff Johnsonb9424862017-10-30 08:49:35 -07003777 sta_ctx = &adapter->session.station;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303778 qdf_mem_set(sta_ctx->conn_info.staId,
3779 sizeof(sta_ctx->conn_info.staId),
3780 HDD_WLAN_INVALID_STA_ID);
Jeff Johnson5505db82017-11-02 21:19:23 -07003781 adapter->dev = dev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003782 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003783 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003784 adapter->session_id = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003785
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303786 qdf_status = qdf_event_create(
3787 &adapter->qdf_session_open_event);
3788 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3789 hdd_err("Session open QDF event init failed!");
3790 free_netdev(adapter->dev);
3791 return NULL;
3792 }
3793
3794 qdf_status = qdf_event_create(
3795 &adapter->qdf_session_close_event);
3796 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3797 hdd_err("Session close QDF event init failed!");
3798 free_netdev(adapter->dev);
3799 return NULL;
3800 }
3801
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003802 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003803 adapter->is_link_up_service_needed = false;
Alok Kumarb64650c2018-03-23 17:05:11 +05303804 adapter->disconnection_in_progress = false;
Yeshwanth Sriram Guntuka4fe30bd2018-06-13 11:41:42 +05303805 adapter->send_mode_change = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003806 /* Init the net_device structure */
Jeff Johnson5505db82017-11-02 21:19:23 -07003807 strlcpy(dev->name, name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003808
Jeff Johnson5505db82017-11-02 21:19:23 -07003809 qdf_mem_copy(dev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003810 sizeof(tSirMacAddr));
Jeff Johnson1e851a12017-10-28 14:36:12 -07003811 qdf_mem_copy(adapter->mac_addr.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003812 sizeof(tSirMacAddr));
Jeff Johnson5505db82017-11-02 21:19:23 -07003813 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003814
3815 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
Jeff Johnson5505db82017-11-02 21:19:23 -07003816 dev->features |=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003817 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Jeff Johnson5505db82017-11-02 21:19:23 -07003818 dev->features |= NETIF_F_RXCSUM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003819
Jeff Johnson5505db82017-11-02 21:19:23 -07003820 hdd_set_tso_flags(hdd_ctx, dev);
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003821
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003822 hdd_set_station_ops(adapter->dev);
3823
Jeff Johnson5505db82017-11-02 21:19:23 -07003824 hdd_dev_setup_destructor(dev);
3825 dev->ieee80211_ptr = &adapter->wdev;
3826 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003827 adapter->wdev.wiphy = hdd_ctx->wiphy;
Jeff Johnson5505db82017-11-02 21:19:23 -07003828 adapter->wdev.netdev = dev;
3829 /* set dev's parent to underlying device */
3830 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003831 hdd_wmm_init(adapter);
3832 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303833 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003834 }
3835
3836 return adapter;
3837}
3838
Jeff Johnson9d295242017-08-29 14:39:48 -07003839static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003840{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003841 struct net_device *dev = adapter->dev;
3842 int ret;
3843
Dustin Brown491d54b2018-03-14 12:39:11 -07003844 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003845
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003846 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003847 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3848
3849 ret = dev_alloc_name(dev, dev->name);
3850 if (ret < 0) {
3851 hdd_err(
3852 "unable to get dev name: %s, err = 0x%x",
3853 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303854 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003855 }
3856 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003857
3858 ret = register_netdevice(dev);
3859 if (ret) {
3860 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3861 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303862 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003863 }
3864 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003865 ret = register_netdev(dev);
3866 if (ret) {
3867 hdd_err("register_netdev(%s) failed, err = 0x%x",
3868 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303869 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003870 }
3871 }
3872 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3873
Dustin Browne74003f2018-03-14 12:51:58 -07003874 hdd_exit();
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003875
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303876 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003877}
3878
Krunal Sonib51eec72017-11-20 21:53:01 -08003879QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003880{
Krunal Sonib51eec72017-11-20 21:53:01 -08003881 struct hdd_adapter *adapter;
3882 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003883
Krunal Sonib51eec72017-11-20 21:53:01 -08003884 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3885 if (!hdd_ctx) {
3886 hdd_err("Invalid HDD_CTX");
3887 return QDF_STATUS_E_FAILURE;
3888 }
3889
3890 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3891 if (NULL == adapter) {
Naveen Rawat23a3b912018-05-30 17:45:52 -07003892 hdd_err("NULL adapter for %d", session_id);
Krunal Sonib51eec72017-11-20 21:53:01 -08003893 return QDF_STATUS_E_INVAL;
3894 }
3895 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303896 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003897 hdd_debug("session %d opened", adapter->session_id);
3898
3899 return QDF_STATUS_SUCCESS;
3900}
3901
3902QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3903{
3904 struct hdd_adapter *adapter;
3905 struct hdd_context *hdd_ctx;
3906
3907 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3908 if (!hdd_ctx) {
3909 hdd_err("Invalid HDD_CTX");
3910 return QDF_STATUS_E_FAILURE;
3911 }
3912
3913 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003914 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003915 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303916 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003917 }
3918
3919 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003920 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303921 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003922 }
3923
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003924 /*
3925 * For NAN Data interface, the close session results in the final
3926 * indication to the userspace
3927 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003928 if (adapter->device_mode == QDF_NDI_MODE)
3929 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003930
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003931 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3932
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003933 /*
3934 * We can be blocked while waiting for scheduled work to be
3935 * flushed, and the adapter structure can potentially be freed, in
3936 * which case the magic will have been reset. So make sure the
3937 * magic is still good, and hence the adapter structure is still
3938 * valid, before signaling completion
3939 */
3940 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303941 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003942
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303943 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003944}
3945
Jeff Johnson9d295242017-08-29 14:39:48 -07003946int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003947{
Dustin Brownd28772b2017-03-17 14:16:07 -07003948 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003949
Dustin Brownd28772b2017-03-17 14:16:07 -07003950 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003951 if (QDF_IS_STATUS_ERROR(status))
3952 return qdf_status_to_os_return(status);
3953
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003954 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003955 if (QDF_IS_STATUS_ERROR(status))
3956 return qdf_status_to_os_return(status);
3957
3958 if (wma_capability_enhanced_mcast_filter())
3959 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3960 else
3961 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003962
3963 return qdf_status_to_os_return(status);
3964}
3965
Jeff Johnson9d295242017-08-29 14:39:48 -07003966int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003967{
3968 QDF_STATUS status;
Dustin Brown2da29eb2018-07-13 14:23:12 -07003969 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003970 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003971 uint8_t vdev_id;
Dustin Brownd28772b2017-03-17 14:16:07 -07003972
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003973 vdev_id = adapter->session_id;
3974 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003975
3976 /* vdev created sanity check */
3977 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Dustin Brown2da29eb2018-07-13 14:23:12 -07003978 hdd_err("vdev %u does not exist", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003979 return -EINVAL;
3980 }
Dustin Brown2da29eb2018-07-13 14:23:12 -07003981
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003982 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Krunal Soni8a06d832018-06-20 16:41:17 -07003983 ucfg_scan_set_vdev_del_in_progress(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003984
Dustin Brownd28772b2017-03-17 14:16:07 -07003985 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303986 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07003987 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -07003988 status = sme_close_session(hdd_ctx->mac_handle, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003989 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Brown2da29eb2018-07-13 14:23:12 -07003990 hdd_err("failed to close sme session; status:%d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003991 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07003992 }
3993
3994 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303995 status = qdf_wait_for_event_completion(
3996 &adapter->qdf_session_close_event,
3997 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
Dustin Brown2da29eb2018-07-13 14:23:12 -07003998
3999 if (QDF_IS_STATUS_ERROR(status)) {
4000 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
4001
Dustin Brownd28772b2017-03-17 14:16:07 -07004002 if (adapter->device_mode == QDF_NDI_MODE)
4003 hdd_ndp_session_end_handler(adapter);
Dustin Brown2da29eb2018-07-13 14:23:12 -07004004
4005 if (status == QDF_STATUS_E_TIMEOUT)
4006 hdd_err("timed out waiting for sme close session");
4007 else if (adapter->qdf_session_close_event.force_set)
4008 hdd_info("SSR occurred during sme close session");
4009 else
4010 hdd_err("failed to wait for sme close session; status:%u",
4011 status);
Dustin Brownd28772b2017-03-17 14:16:07 -07004012 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08004013
Yue Maf9782842017-05-08 12:49:49 -07004014release_vdev:
Krunal Soni8a06d832018-06-20 16:41:17 -07004015 ucfg_scan_clear_vdev_del_in_progress(adapter->hdd_vdev);
Jiachao Wu2c42c222018-01-15 18:13:19 +08004016
Sandeep Puligillaef415362017-08-30 16:37:13 -07004017 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08004018 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07004019 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08004020 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07004021 return errno;
4022 }
4023
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004024 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004025
4026 return 0;
4027}
4028
Krunal Sonib51eec72017-11-20 21:53:01 -08004029static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
4030 struct sme_session_params *session_param,
Jeff Johnson6a18c962018-07-01 09:09:37 -07004031 csr_roam_complete_cb callback,
Krunal Sonib51eec72017-11-20 21:53:01 -08004032 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07004033{
Dustin Brownd28772b2017-03-17 14:16:07 -07004034 uint32_t type;
4035 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08004036 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07004037
4038 /* determine vdev (sub)type */
4039 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304040 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07004041 hdd_err("failed to get vdev type: %d", status);
4042 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004043 }
Krunal Sonib51eec72017-11-20 21:53:01 -08004044 session_param->sme_session_id = adapter->session_id;
4045 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
4046 session_param->type_of_persona = type;
4047 session_param->subtype_of_persona = sub_type;
4048 session_param->session_open_cb = hdd_sme_open_session_callback;
4049 session_param->session_close_cb = hdd_sme_close_session_callback;
4050 session_param->callback = callback;
4051 session_param->callback_ctx = callback_ctx;
4052
4053 return 0;
4054}
4055
4056int hdd_vdev_create(struct hdd_adapter *adapter,
Jeff Johnson6a18c962018-07-01 09:09:37 -07004057 csr_roam_complete_cb callback, void *ctx)
Krunal Sonib51eec72017-11-20 21:53:01 -08004058{
4059 QDF_STATUS status;
4060 int errno;
4061 struct hdd_context *hdd_ctx;
4062 struct sme_session_params sme_session_params = {0};
Krunal Sonib51eec72017-11-20 21:53:01 -08004063
4064 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07004065
4066 /* do vdev create via objmgr */
4067 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07004068 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07004069 if (errno) {
4070 hdd_err("failed to create objmgr vdev: %d", errno);
4071 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004072 }
Dustin Brownd28772b2017-03-17 14:16:07 -07004073
4074 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304075 status = qdf_event_reset(&adapter->qdf_session_open_event);
4076 if (QDF_STATUS_SUCCESS != status) {
4077 hdd_err("failed to reinit session open event");
4078 return -EINVAL;
4079 }
Krunal Sonib51eec72017-11-20 21:53:01 -08004080 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
4081 callback, ctx);
4082 if (errno) {
4083 hdd_err("failed to populating SME params");
4084 goto objmgr_vdev_destroy_procedure;
4085 }
4086
Jeff Johnson16528362018-06-14 12:34:16 -07004087 status = sme_open_session(hdd_ctx->mac_handle, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07004088 if (QDF_IS_STATUS_ERROR(status)) {
4089 hdd_err("failed to open sme session: %d", status);
4090 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07004091 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004092 }
4093
4094 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304095 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
4096 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
4097 if (QDF_STATUS_SUCCESS != status) {
4098 if (adapter->qdf_session_open_event.force_set) {
4099 /*
4100 * SSR/PDR has caused shutdown, which has forcefully
4101 * set the event. Return without the closing session.
4102 */
4103 adapter->session_id = HDD_SESSION_ID_INVALID;
4104 hdd_err("Session open event forcefully set");
4105 return -EINVAL;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304106 }
Jeff Johnsonc66d3102018-02-28 11:58:26 -08004107
4108 if (QDF_STATUS_E_TIMEOUT == status)
4109 hdd_err("Session failed to open within timeout period");
4110 else
4111 hdd_err("Failed to wait for session open event(status-%d)",
4112 status);
4113 errno = -ETIMEDOUT;
4114 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
4115 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004116 }
4117
4118 /* firmware ready for component communication, raise vdev_ready event */
4119 errno = hdd_vdev_ready(adapter);
4120 if (errno) {
4121 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07004122 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004123 }
4124
Naveen Rawat2b430892018-03-13 13:58:18 -07004125 if (adapter->device_mode == QDF_STA_MODE) {
4126 hdd_debug("setting RTT mac randomization param: %d",
4127 hdd_ctx->config->enable_rtt_mac_randomization);
4128 errno = sme_cli_set_command(adapter->session_id,
4129 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_INITIATOR_RANDOM_MAC,
4130 hdd_ctx->config->enable_rtt_mac_randomization,
4131 VDEV_CMD);
4132 if (0 != errno)
4133 hdd_err("RTT mac randomization param set failed %d",
4134 errno);
4135 }
4136
Bala Venkatesh110b03e2018-07-10 16:02:08 +05304137 if (adapter->device_mode == QDF_STA_MODE ||
4138 adapter->device_mode == QDF_P2P_CLIENT_MODE)
4139 wlan_vdev_set_max_peer_count(adapter->hdd_vdev,
4140 HDD_MAX_VDEV_PEER_COUNT);
4141
Jeff Johnson1b780e42017-10-31 14:11:45 -07004142 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004143
4144 return 0;
4145
4146 /*
4147 * Due to legacy constraints, we need to destroy in the same order as
4148 * create. So, split error handling into 2 cases to accommodate.
4149 */
4150
Krunal Soni4a020c72017-10-30 20:58:40 -07004151objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07004152 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07004153
4154 return errno;
4155
Krunal Soni4a020c72017-10-30 20:58:40 -07004156hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07004157 QDF_BUG(!hdd_vdev_destroy(adapter));
4158
4159 return errno;
4160}
4161
Jeff Johnson9d295242017-08-29 14:39:48 -07004162QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07004163{
Jeff Johnsonb9424862017-10-30 08:49:35 -07004164 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004165 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07004166 QDF_STATUS status;
4167 int ret_val;
Jeff Johnson16528362018-06-14 12:34:16 -07004168 mac_handle_t mac_handle;
Dustin Brownd28772b2017-03-17 14:16:07 -07004169
Dustin Brownd28772b2017-03-17 14:16:07 -07004170 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -07004171 mac_handle = hdd_ctx->mac_handle;
4172 sme_set_curr_device_mode(mac_handle, adapter->device_mode);
4173 sme_set_pdev_ht_vht_ies(mac_handle, hdd_ctx->config->enable2x2);
4174 sme_set_vdev_ies_per_band(mac_handle, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004175
Jeff Johnson7f2c5912018-03-23 11:42:28 -07004176 hdd_roam_profile_init(adapter);
4177 hdd_register_wext(adapter->dev);
4178
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07004179 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004180
Jeff Johnsond377dce2017-10-04 10:32:42 -07004181 qdf_mem_set(sta_ctx->conn_info.staId,
4182 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05304183
Deepak Dhamdherea2785822016-11-17 01:17:45 -08004184 /* set fast roaming capability in sme session */
Jeff Johnson16528362018-06-14 12:34:16 -07004185 status = sme_config_fast_roaming(mac_handle, adapter->session_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05304186 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004187 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004188 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004189 hdd_ctx->config->OperatingChannel;
4190
4191 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004192 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004193
4194 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304195 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004196 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004197 status, status);
4198 goto error_init_txrx;
4199 }
4200
4201 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4202
4203 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304204 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004205 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004206 status, status);
4207 goto error_wmm_init;
4208 }
4209
4210 set_bit(WMM_INIT_DONE, &adapter->event_flags);
4211
Jeff Johnson1b780e42017-10-31 14:11:45 -07004212 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004213 WMI_PDEV_PARAM_BURST_ENABLE,
Dundi Raviteja3aa01be2018-05-21 18:58:59 +05304214 HDD_ENABLE_SIFS_BURST_DEFAULT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004215 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07004216 if (ret_val)
4217 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004218
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05304219 /*
4220 * In case of USB tethering, LRO is disabled. If SSR happened
4221 * during that time, then as part of SSR init, do not enable
4222 * the LRO again. Keep the LRO state same as before SSR.
4223 */
Alok Kumar90a73092018-08-03 13:55:09 +05304224 if (hdd_ctx->config->lro_enable &&
4225 !(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07004226 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05304227
4228 /* rcpi info initialization */
4229 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
4230
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304231 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004232
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004233error_wmm_init:
4234 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4235 hdd_deinit_tx_rx(adapter);
4236error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07004237 hdd_unregister_wext(adapter->dev);
Dustin Brownd28772b2017-03-17 14:16:07 -07004238 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004239
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004240 return status;
4241}
4242
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304243/**
Krunal Soni4a020c72017-10-30 20:58:40 -07004244 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304245 * @hdd_ctx: global hdd context
4246 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07004247 * @rtnl_held: Used to indicate whether or not the caller is holding
4248 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304249 *
4250 * This function De-initializes the STA/P2P/OCB adapter.
4251 *
4252 * Return: None.
4253 */
Krunal Soni4a020c72017-10-30 20:58:40 -07004254static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004255 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004256 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304257{
Dustin Brownfdf17c12018-03-14 12:55:34 -07004258 hdd_enter_dev(adapter->dev);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304259
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05304260 if (adapter->dev) {
4261 if (rtnl_held)
4262 adapter->dev->wireless_handlers = NULL;
4263 else {
4264 rtnl_lock();
4265 adapter->dev->wireless_handlers = NULL;
4266 rtnl_unlock();
4267 }
4268 }
4269
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304270 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
4271 hdd_deinit_tx_rx(adapter);
4272 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4273 }
4274
4275 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4276 hdd_wmm_adapter_close(adapter);
4277 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4278 }
4279
Krunal Sonib51eec72017-11-20 21:53:01 -08004280
Dustin Browne74003f2018-03-14 12:51:58 -07004281 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304282}
4283
Krunal Sonib51eec72017-11-20 21:53:01 -08004284void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
4285 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004286 bool rtnl_held)
4287{
Dustin Brown491d54b2018-03-14 12:39:11 -07004288 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304289
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004290 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004291 case QDF_STA_MODE:
4292 case QDF_P2P_CLIENT_MODE:
4293 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08004294 case QDF_IBSS_MODE:
4295 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004296 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004297 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004298 break;
4299 }
4300
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004301 case QDF_SAP_MODE:
4302 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004303 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004304 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004305 break;
4306 }
4307
4308 default:
4309 break;
4310 }
4311
Dustin Browne74003f2018-03-14 12:51:58 -07004312 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004313}
4314
Jeff Johnson9d295242017-08-29 14:39:48 -07004315static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004316 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004317{
Jeff Johnson5505db82017-11-02 21:19:23 -07004318 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004319
4320 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07004321 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004322 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004323 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004324 return;
4325 }
4326
Alok Kumarb64650c2018-03-23 17:05:11 +05304327 hdd_nud_deinit_tracking(adapter);
4328 qdf_mutex_destroy(&adapter->disconnection_status_lock);
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05304329 hdd_apf_context_destroy(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05304330
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05304331 wlan_hdd_debugfs_csr_deinit(adapter);
4332
Rajeev Kumardca5f812016-02-04 17:28:06 -08004333 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05304334
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004335 /*
4336 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
4337 * the driver is almost closed and cannot handle either control
4338 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004339 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
4340 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004341 * is not right. Setting this flag helps hdd_stop() to recognize that
4342 * the interface is closed and restricts any operations on that
4343 */
4344 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
4345
4346 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004347 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07004348 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004349 else
Jeff Johnson5505db82017-11-02 21:19:23 -07004350 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004351 /*
4352 * Note that the adapter is no longer valid at this point
4353 * since the memory has been reclaimed
4354 */
4355 }
4356}
4357
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004358static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07004359 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004360{
Jeff Johnson9d295242017-08-29 14:39:48 -07004361 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004362
Dustin Brown920397d2017-12-13 16:27:50 -08004363 hdd_for_each_adapter(hdd_ctx, adapter) {
4364 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
4365 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304366 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004367 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004368 }
Dustin Brown920397d2017-12-13 16:27:50 -08004369
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304370 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004371}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004372
Arun Khandavalli2358d522016-05-16 18:05:37 +05304373#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4374/**
4375 * hdd_set_fw_log_params() - Set log parameters to FW
4376 * @hdd_ctx: HDD Context
4377 * @adapter: HDD Adapter
4378 *
4379 * This function set the FW Debug log level based on the INI.
4380 *
4381 * Return: None
4382 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004383static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004384 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304385{
4386 uint8_t count = 0, numentries = 0,
4387 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
4388 uint32_t value = 0;
4389 int ret;
4390
Arun Khandavallifae92942016-08-01 13:31:08 +05304391 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4392 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004393 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304394 return;
4395 }
4396
Arun Khandavallifae92942016-08-01 13:31:08 +05304397 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05304398 hdd_ctx->fw_log_settings.dl_type =
4399 hdd_ctx->config->enableFwLogType;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004400 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304401 WMI_DBGLOG_TYPE,
4402 hdd_ctx->config->enableFwLogType,
4403 DBG_CMD);
4404 if (ret != 0)
4405 hdd_err("Failed to enable FW log type ret %d",
4406 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304407
4408 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05304409 hdd_ctx->config->enableFwLogLevel;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004410 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304411 WMI_DBGLOG_LOG_LEVEL,
4412 hdd_ctx->config->enableFwLogLevel,
4413 DBG_CMD);
4414 if (ret != 0)
4415 hdd_err("Failed to enable FW log level ret %d",
4416 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304417
4418 hdd_string_to_u8_array(
4419 hdd_ctx->config->enableFwModuleLogLevel,
4420 moduleloglevel,
4421 &numentries,
4422 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
4423
4424 while (count < numentries) {
4425 /*
4426 * FW module log level input string looks like
4427 * below:
4428 * gFwDebugModuleLoglevel=<FW Module ID>,
4429 * <Log Level>,...
4430 * For example:
4431 * gFwDebugModuleLoglevel=
4432 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
4433 * Above input string means :
4434 * For FW module ID 1 enable log level 0
4435 * For FW module ID 2 enable log level 1
4436 * For FW module ID 3 enable log level 2
4437 * For FW module ID 4 enable log level 3
4438 * For FW module ID 5 enable log level 4
4439 * For FW module ID 6 enable log level 5
4440 * For FW module ID 7 enable log level 6
4441 */
4442
Nishank Aggarwale239d962017-03-03 12:26:02 +05304443 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
4444 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
4445 hdd_err("Module id %d and dbglog level %d input length is more than max",
4446 moduleloglevel[count],
4447 moduleloglevel[count + 1]);
4448 return;
4449 }
4450
4451 value = moduleloglevel[count] << 16;
4452 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07004453 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304454 WMI_DBGLOG_MOD_LOG_LEVEL,
4455 value, DBG_CMD);
4456 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304457 hdd_err("Failed to enable FW module log level %d ret %d",
4458 value, ret);
4459
4460 count += 2;
4461 }
Arun Khandavallifae92942016-08-01 13:31:08 +05304462
Arun Khandavalli2358d522016-05-16 18:05:37 +05304463}
4464#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004465static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004466 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304467{
4468}
4469
4470#endif
4471
4472/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004473 * hdd_configure_chain_mask() - programs chain mask to firmware
4474 * @adapter: HDD adapter
4475 *
4476 * Return: 0 on success or errno on failure
4477 */
4478static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4479{
4480 int ret_val;
Naveen Rawat98322472018-03-06 10:29:42 -08004481 QDF_STATUS status;
4482 struct wma_caps_per_phy non_dbs_phy_cap;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004483 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4484
4485 hdd_debug("enable2x2: %d, lte_coex: %d, ChainMask1x1: tx: %d rx: %d",
4486 hdd_ctx->config->enable2x2, hdd_ctx->lte_coex_ant_share,
4487 hdd_ctx->config->txchainmask1x1,
4488 hdd_ctx->config->rxchainmask1x1);
4489 hdd_debug("disable_DBS: %d, tx_chain_mask_2g: %d, rx_chain_mask_2g: %d",
4490 hdd_ctx->config->dual_mac_feature_disable,
4491 hdd_ctx->config->tx_chain_mask_2g,
4492 hdd_ctx->config->rx_chain_mask_2g);
4493 hdd_debug("tx_chain_mask_5g: %d, rx_chain_mask_5g: %d",
4494 hdd_ctx->config->tx_chain_mask_5g,
4495 hdd_ctx->config->rx_chain_mask_5g);
Liangwei Dong22810e82018-03-15 03:42:12 -04004496 hdd_debug("enable_bt_chain_separation %d",
4497 hdd_ctx->config->enable_bt_chain_separation);
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004498
Naveen Rawat98322472018-03-06 10:29:42 -08004499 status = wma_get_caps_for_phyidx_hwmode(&non_dbs_phy_cap,
4500 HW_MODE_DBS_NONE,
4501 CDS_BAND_ALL);
4502 if (QDF_IS_STATUS_ERROR(status)) {
4503 hdd_err("couldn't get phy caps. skip chain mask programming");
4504 return qdf_status_to_os_return(status);
4505 }
4506
4507 if (non_dbs_phy_cap.tx_chain_mask_2G < 3 ||
4508 non_dbs_phy_cap.rx_chain_mask_2G < 3 ||
4509 non_dbs_phy_cap.tx_chain_mask_5G < 3 ||
4510 non_dbs_phy_cap.rx_chain_mask_5G < 3) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004511 hdd_debug("firmware not capable. skip chain mask programming");
Naveen Rawat98322472018-03-06 10:29:42 -08004512 return 0;
4513 }
4514
Liangwei Dong22810e82018-03-15 03:42:12 -04004515 if (hdd_ctx->config->enable2x2 &&
4516 !hdd_ctx->config->enable_bt_chain_separation) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004517 hdd_debug("2x2 enabled. skip chain mask programming");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004518 return 0;
4519 }
4520
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004521 if (hdd_ctx->config->dual_mac_feature_disable !=
4522 DISABLE_DBS_CXN_AND_SCAN) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004523 hdd_debug("DBS enabled(%d). skip chain mask programming",
4524 hdd_ctx->config->dual_mac_feature_disable);
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004525 return 0;
4526 }
4527
Naveen Rawatdacb5032018-02-08 15:23:24 -08004528 if (hdd_ctx->lte_coex_ant_share) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004529 hdd_debug("lte ant sharing enabled. skip chainmask programming");
Naveen Rawatdacb5032018-02-08 15:23:24 -08004530 return 0;
4531 }
4532
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004533 if (hdd_ctx->config->txchainmask1x1) {
4534 ret_val = sme_cli_set_command(adapter->session_id,
4535 WMI_PDEV_PARAM_TX_CHAIN_MASK,
4536 hdd_ctx->config->txchainmask1x1,
4537 PDEV_CMD);
4538 if (ret_val)
4539 goto error;
4540 }
4541
4542 if (hdd_ctx->config->rxchainmask1x1) {
4543 ret_val = sme_cli_set_command(adapter->session_id,
4544 WMI_PDEV_PARAM_RX_CHAIN_MASK,
4545 hdd_ctx->config->rxchainmask1x1,
4546 PDEV_CMD);
4547 if (ret_val)
4548 goto error;
4549 }
4550
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004551 if (hdd_ctx->config->txchainmask1x1 ||
4552 hdd_ctx->config->rxchainmask1x1) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004553 hdd_debug("band agnostic tx/rx chain mask set. skip per band chain mask");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004554 return 0;
4555 }
4556
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004557 if (hdd_ctx->config->tx_chain_mask_2g) {
4558 ret_val = sme_cli_set_command(adapter->session_id,
4559 WMI_PDEV_PARAM_TX_CHAIN_MASK_2G,
4560 hdd_ctx->config->tx_chain_mask_2g, PDEV_CMD);
4561 if (0 != ret_val)
4562 goto error;
4563 }
4564
4565 if (hdd_ctx->config->rx_chain_mask_2g) {
4566 ret_val = sme_cli_set_command(adapter->session_id,
4567 WMI_PDEV_PARAM_RX_CHAIN_MASK_2G,
4568 hdd_ctx->config->rx_chain_mask_2g, PDEV_CMD);
4569 if (0 != ret_val)
4570 goto error;
4571 }
4572
4573 if (hdd_ctx->config->tx_chain_mask_5g) {
4574 ret_val = sme_cli_set_command(adapter->session_id,
4575 WMI_PDEV_PARAM_TX_CHAIN_MASK_5G,
4576 hdd_ctx->config->tx_chain_mask_5g, PDEV_CMD);
4577 if (0 != ret_val)
4578 goto error;
4579 }
4580
4581 if (hdd_ctx->config->rx_chain_mask_5g) {
4582 ret_val = sme_cli_set_command(adapter->session_id,
4583 WMI_PDEV_PARAM_RX_CHAIN_MASK_5G,
4584 hdd_ctx->config->rx_chain_mask_5g, PDEV_CMD);
4585 if (0 != ret_val)
4586 goto error;
4587 }
4588
4589 return 0;
4590
4591error:
4592 hdd_err("WMI PDEV set param failed %d", ret_val);
4593 return -EINVAL;
4594}
4595
4596/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304597 * hdd_set_fw_params() - Set parameters to firmware
4598 * @adapter: HDD adapter
4599 *
4600 * This function Sets various parameters to fw once the
4601 * adapter is started.
4602 *
4603 * Return: 0 on success or errno on failure
4604 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004605int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304606{
4607 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004608 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304609
Dustin Brownfdf17c12018-03-14 12:55:34 -07004610 hdd_enter_dev(adapter->dev);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304611
4612 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4613 if (!hdd_ctx)
4614 return -EINVAL;
4615
Dustin Brown732ab9c2017-06-15 13:24:09 -07004616 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4617 hdd_debug("FTM Mode is active; nothing to do");
4618 return 0;
4619 }
4620
Jeff Johnson1b780e42017-10-31 14:11:45 -07004621 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304622 WMI_PDEV_PARAM_DTIM_SYNTH,
4623 hdd_ctx->config->enable_lprx, PDEV_CMD);
4624 if (ret) {
4625 hdd_err("Failed to set LPRx");
4626 goto error;
4627 }
4628
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304629
4630 ret = sme_cli_set_command(
4631 adapter->session_id,
4632 WMI_PDEV_PARAM_1CH_DTIM_OPTIMIZED_CHAIN_SELECTION,
4633 hdd_ctx->config->enable_dtim_selection_diversity,
4634 PDEV_CMD);
4635 if (ret) {
4636 hdd_err("Failed to set DTIM_OPTIMIZED_CHAIN_SELECTION");
4637 goto error;
4638 }
4639
Ashish Kumar Dhanotiya48dac7d2018-03-28 14:59:50 +05304640 ret = sme_cli_set_command(
4641 adapter->session_id,
4642 WMI_PDEV_PARAM_TX_SCH_DELAY,
4643 hdd_ctx->config->enable_tx_sch_delay,
4644 PDEV_CMD);
4645 if (ret) {
4646 hdd_err("Failed to set WMI_PDEV_PARAM_TX_SCH_DELAY");
4647 goto error;
4648 }
4649
Ashish Kumar Dhanotiya959b38c2018-04-06 21:07:57 +05304650 ret = sme_cli_set_command(
4651 adapter->session_id,
4652 WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE,
4653 hdd_ctx->config->enable_secondary_rate,
4654 PDEV_CMD);
4655 if (ret) {
4656 hdd_err("Failed to set WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE");
4657 goto error;
4658 }
4659
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304660 if (adapter->device_mode == QDF_STA_MODE) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07004661 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304662 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4663 hdd_ctx->config->upper_brssi_thresh);
4664
Jeff Johnson1b780e42017-10-31 14:11:45 -07004665 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304666 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4667 hdd_ctx->config->lower_brssi_thresh);
4668
Jeff Johnson1b780e42017-10-31 14:11:45 -07004669 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304670 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4671 hdd_ctx->config->enable_dtim_1chrx);
4672 }
4673
Dustin Brown732ab9c2017-06-15 13:24:09 -07004674 if (hdd_ctx->config->enable2x2) {
4675 hdd_debug("configuring 2x2 mode fw params");
4676
Jeff Johnson1b780e42017-10-31 14:11:45 -07004677 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004678 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
4679 hdd_ctx->config->enable_cck_tx_fir_override,
4680 PDEV_CMD);
4681 if (ret) {
4682 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4683 ret);
4684 goto error;
4685 }
Liangwei Dong22810e82018-03-15 03:42:12 -04004686
4687 if (hdd_configure_chain_mask(adapter))
4688 goto error;
Dustin Brown732ab9c2017-06-15 13:24:09 -07004689 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304690#define HDD_DTIM_1CHAIN_RX_ID 0x5
4691#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004692 hdd_debug("configuring 1x1 mode fw params");
4693
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004694 /*
4695 * Disable DTIM 1 chain Rx when in 1x1,
4696 * we are passing two value
4697 * as param_id << 29 | param_value.
4698 * Below param_value = 0(disable)
4699 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004700 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004701 WMI_STA_SMPS_PARAM_CMDID,
4702 HDD_DTIM_1CHAIN_RX_ID <<
4703 HDD_SMPS_PARAM_VALUE_S,
4704 VDEV_CMD);
4705 if (ret) {
4706 hdd_err("DTIM 1 chain set failed %d", ret);
4707 goto error;
4708 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304709
Arun Khandavalli2358d522016-05-16 18:05:37 +05304710#undef HDD_DTIM_1CHAIN_RX_ID
4711#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004712
4713 if (hdd_configure_chain_mask(adapter))
4714 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004715 }
4716
Jeff Johnson1b780e42017-10-31 14:11:45 -07004717 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004718 WMI_PDEV_PARAM_HYST_EN,
4719 hdd_ctx->config->enableMemDeepSleep,
4720 PDEV_CMD);
4721 if (ret) {
4722 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4723 goto error;
4724 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304725
Jeff Johnson1b780e42017-10-31 14:11:45 -07004726 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004727 WMI_VDEV_PARAM_ENABLE_RTSCTS,
4728 hdd_ctx->config->rts_profile,
4729 VDEV_CMD);
4730 if (ret) {
4731 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4732 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304733 }
4734
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004735 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
4736
Jeff Johnson1b780e42017-10-31 14:11:45 -07004737 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004738 GEN_VDEV_PARAM_AMSDU,
4739 hdd_ctx->config->max_amsdu_num,
4740 GEN_CMD);
4741 if (ret != 0) {
4742 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4743 goto error;
4744 }
4745
Arun Khandavalli2358d522016-05-16 18:05:37 +05304746 hdd_set_fw_log_params(hdd_ctx, adapter);
Dustin Browne74003f2018-03-14 12:51:58 -07004747 hdd_exit();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004748
Arun Khandavalli2358d522016-05-16 18:05:37 +05304749 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304750
Arun Khandavalli2358d522016-05-16 18:05:37 +05304751error:
4752 return -EINVAL;
4753}
4754
Ryan Hsu07495ea2016-01-21 15:25:39 -08004755/**
Abhinav Kumarcc959f12018-08-09 13:58:30 +05304756 * hdd_init_completion() - Initialize Completion Variables
4757 * @adapter: HDD adapter
4758 *
4759 * This function Initialize the completion variables for
4760 * a particular adapter
4761 *
4762 * Return: None
4763 */
4764static void hdd_init_completion(struct hdd_adapter *adapter)
4765{
4766 init_completion(&adapter->disconnect_comp_var);
4767 init_completion(&adapter->roaming_comp_var);
4768 init_completion(&adapter->linkup_event_var);
4769 init_completion(&adapter->cancel_rem_on_chan_var);
4770 init_completion(&adapter->rem_on_chan_ready_event);
4771 init_completion(&adapter->sta_authorized_event);
4772 init_completion(&adapter->offchannel_tx_event);
4773 init_completion(&adapter->tx_action_cnf_event);
4774 init_completion(&adapter->ibss_peer_info_comp);
4775 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
4776}
4777
4778/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08004779 * hdd_open_adapter() - open and setup the hdd adatper
4780 * @hdd_ctx: global hdd context
4781 * @session_type: type of the interface to be created
4782 * @iface_name: User-visible name of the interface
4783 * @macAddr: MAC address to assign to the interface
4784 * @name_assign_type: the name of assign type of the netdev
4785 * @rtnl_held: the rtnl lock hold flag
4786 *
4787 * This function open and setup the hdd adpater according to the device
4788 * type request, assign the name, the mac address assigned, and then prepared
4789 * the hdd related parameters, queue, lock and ready to start.
4790 *
4791 * Return: the pointer of hdd adapter, otherwise NULL.
4792 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004793struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004794 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08004795 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004796 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004797{
Jeff Johnson9d295242017-08-29 14:39:48 -07004798 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304799 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004800
4801 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4802 /*
4803 * Max limit reached on the number of vdevs configured by the
4804 * host. Return error
4805 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304806 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4807 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004808 return NULL;
4809 }
4810
4811 if (macAddr == NULL) {
4812 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304813 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004814 return NULL;
4815 }
4816 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304817 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304818 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4819 " already exists",
4820 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004821 return NULL;
4822 }
4823
4824 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004825 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004826 /* Reset locally administered bit if the device mode is STA */
4827 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Dustin Brown7e761c72018-07-31 13:50:17 -07004828 hdd_debug("locally administered bit reset in sta mode: "
4829 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004830 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004831 case QDF_P2P_CLIENT_MODE:
4832 case QDF_P2P_DEVICE_MODE:
4833 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07004834 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304835 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004836 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4837 name_assign_type,
4838 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004839
4840 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304841 hdd_err("failed to allocate adapter for session %d",
4842 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004843 return NULL;
4844 }
4845
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004846 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004847 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004848 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004849 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304850 else if (QDF_MONITOR_MODE == session_type)
4851 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004852 else
4853 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4854
4855 adapter->device_mode = session_type;
4856
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004857
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004858 /*
4859 * Workqueue which gets scheduled in IPv4 notification
4860 * callback
4861 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004862 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004863 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004864
4865#ifdef WLAN_NS_OFFLOAD
4866 /*
4867 * Workqueue which gets scheduled in IPv6
4868 * notification callback.
4869 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004870 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004871 hdd_ipv6_notifier_work_queue);
4872#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004873 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004874 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004875 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004876
4877 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004878 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004879 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304880 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4881 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304882
Alok Kumarb64650c2018-03-23 17:05:11 +05304883 hdd_nud_init_tracking(adapter);
4884
4885 qdf_mutex_create(&adapter->disconnection_status_lock);
4886
Ravi Joshi1a292562017-05-18 16:28:54 -07004887 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004888
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004889 case QDF_P2P_GO_MODE:
4890 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004891 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4892 name_assign_type,
4893 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004894 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004895 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304896 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004897 return NULL;
4898 }
4899
4900 adapter->wdev.iftype =
4901 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004902 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004903 NL80211_IFTYPE_P2P_GO;
4904 adapter->device_mode = session_type;
4905
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004906 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004907 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004908 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004909
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004910 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004911 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304912 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4913 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304914
4915 /*
4916 * Workqueue which gets scheduled in IPv4 notification
4917 * callback
4918 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004919 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304920 hdd_ipv4_notifier_work_queue);
4921
4922#ifdef WLAN_NS_OFFLOAD
4923 /*
4924 * Workqueue which gets scheduled in IPv6
4925 * notification callback.
4926 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004927 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304928 hdd_ipv6_notifier_work_queue);
4929#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004930 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304931 case QDF_FTM_MODE:
4932 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4933 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08004934 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304935 if (NULL == adapter) {
4936 hdd_err("Failed to allocate adapter for FTM mode");
4937 return NULL;
4938 }
4939 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4940 adapter->device_mode = session_type;
4941 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004942 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004943 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004944
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304945 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004946 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304947 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304948 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4949 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304950 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004951 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004952 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304953 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004954 return NULL;
4955 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004956
Abhinav Kumarcc959f12018-08-09 13:58:30 +05304957 hdd_init_completion(adapter);
hqueaa33ee2017-05-04 17:56:35 +08004958 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
Min Liu9be5d4a2018-05-17 11:51:53 +08004959 qdf_list_create(&adapter->blocked_scan_request_q, WLAN_MAX_SCAN_COUNT);
4960 qdf_mutex_create(&adapter->blocked_scan_request_q_lock);
hqueaa33ee2017-05-04 17:56:35 +08004961
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304962 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004963 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08004964 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004965 }
4966
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304967 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004968 if (NULL != adapter) {
4969 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4970 adapter = NULL;
4971 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004972
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004973 return NULL;
4974 }
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05304975 hdd_apf_context_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004976
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304977 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004978 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4979 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004980
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004981 /* Adapter successfully added. Increment the vdev count */
4982 hdd_ctx->current_intf_count++;
4983
Jeff Johnson5880d792016-08-15 13:32:30 -07004984 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004985 hdd_ctx->current_intf_count);
4986
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004987 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004988 }
4989
Rajeev Kumardca5f812016-02-04 17:28:06 -08004990 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004991 hdd_err("Interface %s wow debug_fs init failed",
4992 netdev_name(adapter->dev));
4993
Ajit Pal Singh106c1412018-04-18 18:08:49 +05304994 hdd_register_hl_netdev_fc_timer(adapter,
4995 hdd_tx_resume_timer_expired_handler);
4996
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004997 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4998 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004999
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05305000 if (adapter->device_mode == QDF_STA_MODE)
5001 wlan_hdd_debugfs_csr_init(adapter);
5002
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005003 return adapter;
5004
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005005err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07005006 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05305007 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005008
5009 return NULL;
5010}
5011
Jeff Johnson9d295242017-08-29 14:39:48 -07005012QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08005013 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005014{
Dustin Brown920397d2017-12-13 16:27:50 -08005015 /*
5016 * Here we are stopping global bus_bw timer & work per adapter.
5017 *
5018 * The reason is to fix one race condition between
5019 * bus bandwidth work and cleaning up an adapter.
5020 * Under some conditions, it is possible for the bus bandwidth
5021 * work to access a particularly destroyed adapter, leading to
5022 * use-after-free.
5023 */
Dustin Brown920397d2017-12-13 16:27:50 -08005024 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005025
Min Liuef92ef52018-06-25 18:08:54 +08005026 qdf_list_destroy(&adapter->blocked_scan_request_q);
5027 qdf_mutex_destroy(&adapter->blocked_scan_request_q_lock);
5028
Dustin Brown920397d2017-12-13 16:27:50 -08005029 /* cleanup adapter */
5030 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
5031 adapter->device_mode);
Dustin Brown920397d2017-12-13 16:27:50 -08005032 hdd_remove_adapter(hdd_ctx, adapter);
Liangwei Dongad89c762018-06-01 01:56:23 -04005033 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005034
Dustin Brown920397d2017-12-13 16:27:50 -08005035 /* conditionally restart the bw timer */
5036 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005037
Dustin Brown920397d2017-12-13 16:27:50 -08005038 /* Adapter removed. Decrement vdev count */
5039 if (hdd_ctx->current_intf_count != 0)
5040 hdd_ctx->current_intf_count--;
Dustin Brown5ec6b552017-03-31 12:11:40 -07005041
Dustin Brown920397d2017-12-13 16:27:50 -08005042 /* Fw will take care incase of concurrency */
5043 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005044}
5045
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08005046/**
5047 * hdd_close_all_adapters - Close all open adapters
5048 * @hdd_ctx: Hdd context
5049 * rtnl_held: True if RTNL lock held
5050 *
5051 * Close all open adapters.
5052 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305053 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08005054 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005055QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005056{
Dustin Brown920397d2017-12-13 16:27:50 -08005057 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305058 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005059
Dustin Brown491d54b2018-03-14 12:39:11 -07005060 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005061
5062 do {
Dustin Brown920397d2017-12-13 16:27:50 -08005063 status = hdd_remove_front_adapter(hdd_ctx, &adapter);
5064 if (QDF_IS_STATUS_SUCCESS(status)) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305065 wlan_hdd_release_intf_addr(hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005066 adapter->mac_addr.bytes);
5067 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
5068
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305069 /* Adapter removed. Decrement vdev count */
5070 if (hdd_ctx->current_intf_count != 0)
5071 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005072 }
Dustin Brown920397d2017-12-13 16:27:50 -08005073 } while (QDF_IS_STATUS_SUCCESS(status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005074
Dustin Browne74003f2018-03-14 12:51:58 -07005075 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005076
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305077 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005078}
5079
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005080void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005081{
Anurag Chouhan6d760662016-02-20 16:05:43 +05305082 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005083 tSirUpdateIE updateIE;
Jeff Johnson16528362018-06-14 12:34:16 -07005084 mac_handle_t mac_handle;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005085
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005086 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005087 case QDF_STA_MODE:
5088 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005089 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005090 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005091 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07005092 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005093 break;
5094 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005095 case QDF_SAP_MODE:
5096 case QDF_P2P_GO_MODE:
5097 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005098 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07005099 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005100 break;
5101 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005102 case QDF_FTM_MODE:
5103 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005104 default:
5105 /*
5106 * wlan_hdd_reset_prob_rspies should not have been called
5107 * for these kind of devices
5108 */
Jeff Johnson5880d792016-08-15 13:32:30 -07005109 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005110 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005111 return;
5112 }
5113
Anurag Chouhanc5548422016-02-24 18:33:27 +05305114 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005115 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005116 updateIE.ieBufferlength = 0;
5117 updateIE.pAdditionIEBuffer = NULL;
5118 updateIE.append = true;
5119 updateIE.notify = false;
Jeff Johnson16528362018-06-14 12:34:16 -07005120 mac_handle = hdd_adapter_get_mac_handle(adapter);
5121 if (sme_update_add_ie(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005122 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305123 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005124 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005125 }
5126}
5127
Dustin Browndb2a8be2017-12-20 11:49:56 -08005128QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
5129 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005130{
Liangwei Dongad89c762018-06-01 01:56:23 -04005131 return hdd_stop_adapter_ext(hdd_ctx, adapter, 0);
5132}
5133
5134QDF_STATUS hdd_stop_adapter_ext(struct hdd_context *hdd_ctx,
5135 struct hdd_adapter *adapter,
5136 enum hdd_adapter_stop_flag_t flag)
5137{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305138 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson025618c2018-03-18 14:41:00 -07005139 struct csr_roam_profile *roam_profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005140 union iwreq_data wrqu;
5141 tSirUpdateIE updateIE;
5142 unsigned long rc;
Jeff Johnsone4c11db2018-05-05 23:22:32 -07005143 tsap_config_t *sap_config;
Jeff Johnson16528362018-06-14 12:34:16 -07005144 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005145
Dustin Brown491d54b2018-03-14 12:39:11 -07005146 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005147
Dustin Browne7e71d32018-05-11 16:00:08 -07005148 if (adapter->session_id != HDD_SESSION_ID_INVALID)
5149 wlan_hdd_cfg80211_deregister_frames(adapter);
5150
Alok Kumarb64650c2018-03-23 17:05:11 +05305151 hdd_nud_ignore_tracking(adapter, true);
5152 hdd_nud_reset_tracking(adapter);
5153
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005154 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305155 wlan_hdd_netif_queue_control(adapter,
5156 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5157 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08005158 /*
5159 * if this is the last active connection check & stop the
5160 * opportunistic timer first
5161 */
5162 if (((policy_mgr_get_connection_count(hdd_ctx->hdd_psoc) == 1) &&
5163 (policy_mgr_mode_specific_connection_count(hdd_ctx->hdd_psoc,
5164 policy_mgr_convert_device_mode_to_qdf_type(
5165 adapter->device_mode), NULL) == 1)) ||
5166 !policy_mgr_get_connection_count(hdd_ctx->hdd_psoc))
5167 policy_mgr_check_and_stop_opportunistic_timer(
5168 hdd_ctx->hdd_psoc, adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -07005169
5170 mac_handle = hdd_ctx->mac_handle;
5171
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005172 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005173 case QDF_STA_MODE:
5174 case QDF_P2P_CLIENT_MODE:
5175 case QDF_IBSS_MODE:
5176 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005177 case QDF_NDI_MODE:
5178 if ((QDF_NDI_MODE == adapter->device_mode) ||
5179 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005180 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
5181 hdd_is_connecting(
5182 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005183 INIT_COMPLETION(adapter->disconnect_comp_var);
Jeff Johnson025618c2018-03-18 14:41:00 -07005184 roam_profile = hdd_roam_profile(adapter);
5185 /* For NDI do not use roam_profile */
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005186 if (QDF_NDI_MODE == adapter->device_mode)
5187 qdf_ret_status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005188 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005189 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005190 eCSR_DISCONNECT_REASON_NDI_DELETE);
Jeff Johnson025618c2018-03-18 14:41:00 -07005191 else if (roam_profile->BSSType ==
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005192 eCSR_BSS_TYPE_START_IBSS)
5193 qdf_ret_status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005194 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005195 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005196 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Abhinav Kumar19a7a402018-07-12 17:36:57 +05305197 else if (adapter->device_mode == QDF_STA_MODE)
5198 wlan_hdd_disconnect(adapter,
5199 eCSR_DISCONNECT_REASON_DEAUTH);
5200 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005201 qdf_ret_status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005202 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005203 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005204 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005205 /* success implies disconnect command got
5206 * queued up successfully
5207 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005208 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
5209 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005210 rc = wait_for_completion_timeout(
5211 &adapter->disconnect_comp_var,
5212 msecs_to_jiffies
5213 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005214 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005215 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005216 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005217 if (qdf_ret_status != QDF_STATUS_SUCCESS)
5218 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005219 memset(&wrqu, '\0', sizeof(wrqu));
5220 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5221 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5222 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
5223 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05305224 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08005225 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005226
Wu Gao4a1ec8c2018-07-23 19:18:40 +08005227 wlan_hdd_cleanup_actionframe(adapter);
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05305228 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05305229 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005230
5231#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005232 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005233#endif
5234
5235 hdd_deregister_tx_flow_control(adapter);
5236
5237#ifdef WLAN_NS_OFFLOAD
5238#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005239 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005240#endif
5241#endif
5242
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05305243 if (adapter->device_mode == QDF_STA_MODE)
5244 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
5245 adapter->dev);
Dustin Browndb2a8be2017-12-20 11:49:56 -08005246
5247 if (wlan_hdd_try_disconnect(adapter)) {
5248 hdd_err("Error: Can't disconnect adapter");
5249 return QDF_STATUS_E_FAILURE;
Krunal Soni985b8132017-02-10 18:49:08 -08005250 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08005251
Himanshu Agarwalb229a142017-12-21 10:16:45 +05305252 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005253 break;
5254
Rajeev Kumar3b906202018-02-01 10:55:14 -08005255 case QDF_MONITOR_MODE:
5256 wlan_hdd_scan_abort(adapter);
5257 hdd_deregister_tx_flow_control(adapter);
5258 hdd_vdev_destroy(adapter);
5259 break;
5260
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005261 case QDF_SAP_MODE:
Will Huang7049bae2018-08-13 17:25:02 +08005262 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
5263 cds_flush_delayed_work(&adapter->acs_pending_work);
5264 clear_bit(ACS_PENDING, &adapter->event_flags);
5265 }
wadesongf9b15ed2017-12-14 14:12:32 +08005266 wlan_hdd_scan_abort(adapter);
Govind Singh1dab23b2017-08-12 13:31:00 +05305267 /* Flush IPA exception path packets */
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05305268 sap_config = &adapter->session.ap.sap_config;
5269 if (sap_config)
5270 wlansap_reset_sap_config_add_ie(sap_config,
5271 eUPDATE_IE_ALL);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05305272 ucfg_ipa_flush(hdd_ctx->hdd_pdev);
Liangwei Dongad89c762018-06-01 01:56:23 -04005273 if (!(flag & HDD_IN_CAC_WORK_TH_CONTEXT))
5274 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Jeff Johnson46807cd2018-04-29 21:32:22 -07005275 /* fallthrough */
Dustin Browna5cf8e02017-10-19 16:04:19 -07005276
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005277 case QDF_P2P_GO_MODE:
Krunal Soni22208392017-09-29 18:10:34 -07005278 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005279
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005280 /* Any softap specific cleanup here... */
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305281 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005282 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005283 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005284 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5285
5286 hdd_deregister_tx_flow_control(adapter);
5287
Kapil Guptac1224bf2017-06-22 21:22:40 +05305288 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005289 mutex_lock(&hdd_ctx->sap_lock);
5290 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305291 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05305292 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005293
5294 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005295 status = wlansap_stop_bss(
5296 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005297
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305298 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07005299 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005300 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305301 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305302 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305303 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +05305304 qdf_wait_for_event_completion(
5305 &hostapd_state->qdf_stop_bss_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -08005306 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005307
Anurag Chouhance0dc992016-02-16 18:18:03 +05305308 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005309 hdd_err("failure waiting for wlansap_stop_bss %d",
5310 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005311 }
5312 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07005313 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005314 }
5315 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005316 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
5317 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005318 adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005319 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305320 adapter->device_mode,
5321 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005322
Anurag Chouhanc5548422016-02-24 18:33:27 +05305323 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07005324 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005325 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005326 updateIE.ieBufferlength = 0;
5327 updateIE.pAdditionIEBuffer = NULL;
5328 updateIE.append = false;
5329 updateIE.notify = false;
5330 /* Probe bcn reset */
Jeff Johnson16528362018-06-14 12:34:16 -07005331 if (sme_update_add_ie(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005332 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305333 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005334 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005335 }
5336 /* Assoc resp reset */
Jeff Johnson16528362018-06-14 12:34:16 -07005337 if (sme_update_add_ie(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005338 &updateIE,
5339 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305340 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005341 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005342 }
5343 /* Reset WNI_CFG_PROBE_RSP Flags */
5344 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005345 }
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005346 clear_bit(SOFTAP_INIT_DONE, &adapter->event_flags);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005347 qdf_mem_free(adapter->session.ap.beacon);
5348 adapter->session.ap.beacon = NULL;
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005349
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305350 /*
5351 * If Do_Not_Break_Stream was enabled clear avoid channel list.
5352 */
5353 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
5354 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
5355
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305356#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005357 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305358#endif
5359
5360#ifdef WLAN_NS_OFFLOAD
5361#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005362 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305363#endif
5364#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08005365
5366 hdd_vdev_destroy(adapter);
5367
Krunal Sonib51eec72017-11-20 21:53:01 -08005368 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005369 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005370 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08005371 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08005372 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07005373 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Zhang Qian79d0d132018-02-05 13:40:16 +08005374 hdd_deregister_tx_flow_control(adapter);
5375 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005376 break;
5377 default:
5378 break;
5379 }
5380
Ajit Pal Singh106c1412018-04-18 18:08:49 +05305381 hdd_deregister_hl_netdev_fc_timer(adapter);
5382
Dustin Brown04348372017-12-14 16:13:39 -08005383 if (adapter->scan_info.default_scan_ies) {
5384 qdf_mem_free(adapter->scan_info.default_scan_ies);
5385 adapter->scan_info.default_scan_ies = NULL;
5386 }
5387
Dustin Browne74003f2018-03-14 12:51:58 -07005388 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305389 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005390}
5391
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305392/**
5393 * hdd_deinit_all_adapters - deinit all adapters
5394 * @hdd_ctx: HDD context
5395 * @rtnl_held: True if RTNL lock held
5396 *
5397 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005398void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305399{
Jeff Johnson9d295242017-08-29 14:39:48 -07005400 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305401
Dustin Brown491d54b2018-03-14 12:39:11 -07005402 hdd_enter();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305403
Dustin Brown920397d2017-12-13 16:27:50 -08005404 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305405 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305406
Dustin Browne74003f2018-03-14 12:51:58 -07005407 hdd_exit();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305408}
5409
Dustin Browndb2a8be2017-12-20 11:49:56 -08005410QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005411{
Jeff Johnson9d295242017-08-29 14:39:48 -07005412 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005413
Dustin Brown491d54b2018-03-14 12:39:11 -07005414 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005415
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305416 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5417
Dustin Brown920397d2017-12-13 16:27:50 -08005418 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08005419 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005420
Dustin Browne74003f2018-03-14 12:51:58 -07005421 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005422
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305423 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005424}
5425
Paul Zhang84fa9382017-11-10 21:18:21 +08005426static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
5427 struct hdd_adapter *adapter)
5428{
5429 switch (adapter->device_mode) {
5430 case QDF_STA_MODE:
5431 case QDF_P2P_CLIENT_MODE:
5432 case QDF_IBSS_MODE:
5433 case QDF_P2P_DEVICE_MODE:
5434 case QDF_NDI_MODE:
5435 wlan_hdd_scan_abort(adapter);
5436 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5437 if (adapter->device_mode == QDF_STA_MODE)
5438 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
5439 adapter->dev);
5440 break;
5441 case QDF_P2P_GO_MODE:
5442 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5443 break;
5444 case QDF_SAP_MODE:
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305445 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Paul Zhang84fa9382017-11-10 21:18:21 +08005446 wlan_hdd_undo_acs(adapter);
5447 break;
5448 default:
5449 break;
5450 }
5451}
5452
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005453QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005454{
Jeff Johnson9d295242017-08-29 14:39:48 -07005455 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07005456 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07005457 struct qdf_mac_addr peerMacAddr;
Yue Ma42654682018-01-11 16:55:24 -08005458 int sta_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005459
Dustin Brown491d54b2018-03-14 12:39:11 -07005460 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005461
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305462 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5463
Dustin Brown920397d2017-12-13 16:27:50 -08005464 hdd_for_each_adapter(hdd_ctx, adapter) {
Dustin Brown5e89ef82018-03-14 11:50:23 -07005465 hdd_info("[SSR] reset adapter with device mode %s(%d)",
5466 hdd_device_mode_to_string(adapter->device_mode),
5467 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305468
5469 if ((adapter->device_mode == QDF_STA_MODE) ||
Paul Zhang679025e2018-03-08 22:39:44 +08005470 (adapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305471 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07005472 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Paul Zhang679025e2018-03-08 22:39:44 +08005473 adapter->session.station.hdd_reassoc_scenario = false;
5474 }
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305475
Arun Khandavallicc544b32017-01-30 19:52:16 +05305476 if (hdd_ctx->config->sap_internal_restart &&
5477 adapter->device_mode == QDF_SAP_MODE) {
5478 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305479 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05305480 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005481 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08005482 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005483 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005484 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
5485 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305486 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305487 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005488 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005489 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005490
Paul Zhang84fa9382017-11-10 21:18:21 +08005491 hdd_reset_scan_operation(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005492
5493 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005494 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005495 adapter->device_mode, adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005496 hdd_green_ap_start_state_mc(hdd_ctx, adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305497 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005498 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5499 hdd_wmm_adapter_close(adapter);
5500 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5501 }
5502
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305503 if (adapter->device_mode == QDF_STA_MODE)
5504 hdd_clear_fils_connection_info(adapter);
5505
Wu Gao3545e642017-07-14 19:24:41 +08005506 if (adapter->device_mode == QDF_SAP_MODE) {
Jingxiang Geec113592018-08-09 15:40:39 +08005507 wlansap_cleanup_cac_timer(
5508 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Wu Gao3545e642017-07-14 19:24:41 +08005509 /*
5510 * If adapter is SAP, set session ID to invalid
5511 * since SAP session will be cleanup during SSR.
5512 */
Wu Gao36717432016-11-21 15:09:48 +08005513 wlansap_set_invalid_session(
5514 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Wu Gao3545e642017-07-14 19:24:41 +08005515 }
5516
Yue Ma42654682018-01-11 16:55:24 -08005517 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005518 if (adapter->device_mode == QDF_STA_MODE ||
5519 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005520 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005521 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07005522 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005523
Yue Ma42654682018-01-11 16:55:24 -08005524 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
Wu Gao6b81fc52018-05-24 19:27:27 +08005525 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Yue Ma42654682018-01-11 16:55:24 -08005526 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5527 if (adapter->sta_info[sta_id].in_use) {
5528 hdd_debug("[SSR] deregister STA with ID %d",
5529 sta_id);
5530 hdd_softap_deregister_sta(adapter,
5531 sta_id);
5532 adapter->sta_info[sta_id].in_use = 0;
5533 }
5534 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005535 }
5536
Alok Kumarb64650c2018-03-23 17:05:11 +05305537 hdd_nud_reset_tracking(adapter);
5538 hdd_nud_ignore_tracking(adapter, true);
5539 hdd_set_disconnect_status(adapter, false);
5540
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005541 hdd_softap_deinit_tx_rx(adapter);
Tiger Yu8c387702018-07-06 16:56:42 +08005542 hdd_deregister_tx_flow_control(adapter);
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005543
Yue Maf9782842017-05-08 12:49:49 -07005544 /* Destroy vdev which will be recreated during reinit. */
5545 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005546 }
5547
Dustin Browne74003f2018-03-14 12:51:58 -07005548 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005549
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305550 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005551}
5552
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005553bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305554{
Dustin Brown920397d2017-12-13 16:27:50 -08005555 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305556 bool close_modules = true;
5557
Arun Khandavalliba479c42017-07-26 21:29:40 +05305558 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
5559 hdd_info("FTM mode, don't close the module");
5560 return false;
5561 }
5562
Dustin Brown920397d2017-12-13 16:27:50 -08005563 hdd_for_each_adapter(hdd_ctx, adapter) {
5564 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
5565 test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005566 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305567 close_modules = false;
5568 break;
5569 }
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305570 }
5571
5572 return close_modules;
5573}
5574
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305575bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305576{
5577 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5578 return true;
5579 else
5580 return false;
5581}
5582
Anurag Chouhanc4092922016-09-08 15:56:11 +05305583#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08005584 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305585struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5586 struct ieee80211_channel *channel,
5587 const u8 *bssid, const u8 *ssid,
5588 size_t ssid_len)
5589{
5590 return cfg80211_get_bss(wiphy, channel, bssid,
5591 ssid, ssid_len,
5592 WLAN_CAPABILITY_ESS,
5593 WLAN_CAPABILITY_ESS);
5594}
5595#else
5596struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5597 struct ieee80211_channel *channel,
5598 const u8 *bssid, const u8 *ssid,
5599 size_t ssid_len)
5600{
5601 return cfg80211_get_bss(wiphy, channel, bssid,
5602 ssid, ssid_len,
5603 IEEE80211_BSS_TYPE_ESS,
5604 IEEE80211_PRIVACY_ANY);
5605}
5606#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305607
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305608#if defined CFG80211_CONNECT_BSS || \
5609 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305610#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305611 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305612/**
5613 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5614 * @timeout_reason: reason for connect timeout
5615 *
5616 * This function is used to convert host timeout
5617 * reason enum to kernel specific enum.
5618 *
5619 * Return: nl timeout enum
5620 */
5621static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5622 tSirResultCodes timeout_reason)
5623{
5624 switch (timeout_reason) {
5625 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5626 return NL80211_TIMEOUT_SCAN;
5627 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5628 return NL80211_TIMEOUT_AUTH;
5629 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5630 return NL80211_TIMEOUT_ASSOC;
5631 default:
5632 return NL80211_TIMEOUT_UNSPECIFIED;
5633 }
5634}
5635
5636/**
5637 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5638 * @dev: network device
5639 * @bssid: bssid to which we want to associate
5640 * @timeout_reason: reason for connect timeout
5641 *
5642 * This API is used to send connection timeout reason to supplicant
5643 *
5644 * Return: void
5645 */
5646static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5647 const u8 *bssid,
5648 tSirResultCodes timeout_reason)
5649{
5650 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005651
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305652 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5653
5654 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5655 nl_timeout_reason);
5656}
5657
5658/**
5659 * __hdd_connect_bss() - API to send connection status to supplicant
5660 * @dev: network device
5661 * @bssid: bssid to which we want to associate
5662 * @req_ie: Request Information Element
5663 * @req_ie_len: len of the req IE
5664 * @resp_ie: Response IE
5665 * @resp_ie_len: len of ht response IE
5666 * @status: status
5667 * @gfp: Kernel Flag
5668 * @timeout_reason: reason for connect timeout
5669 *
5670 * Return: void
5671 */
5672static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5673 struct cfg80211_bss *bss, const u8 *req_ie,
5674 size_t req_ie_len, const u8 *resp_ie,
5675 size_t resp_ie_len, int status, gfp_t gfp,
5676 tSirResultCodes timeout_reason)
5677{
5678 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005679
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305680 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5681
5682 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5683 resp_ie, resp_ie_len, status, gfp,
5684 nl_timeout_reason);
5685}
5686#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305687#if defined CFG80211_CONNECT_TIMEOUT || \
5688 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305689static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5690 const u8 *bssid,
5691 tSirResultCodes timeout_reason)
5692{
5693 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5694}
5695#endif
5696
5697static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5698 struct cfg80211_bss *bss, const u8 *req_ie,
5699 size_t req_ie_len, const u8 *resp_ie,
5700 size_t resp_ie_len, int status, gfp_t gfp,
5701 tSirResultCodes timeout_reason)
5702{
5703 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5704 resp_ie, resp_ie_len, status, gfp);
5705}
5706#endif
5707
Abhishek Singha84d3952016-09-13 13:45:05 +05305708/**
5709 * hdd_connect_bss() - API to send connection status to supplicant
5710 * @dev: network device
5711 * @bssid: bssid to which we want to associate
5712 * @req_ie: Request Information Element
5713 * @req_ie_len: len of the req IE
5714 * @resp_ie: Response IE
5715 * @resp_ie_len: len of ht response IE
5716 * @status: status
5717 * @gfp: Kernel Flag
5718 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305719 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05305720 *
5721 * The API is a wrapper to send connection status to supplicant
5722 *
5723 * Return: Void
5724 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305725#if defined CFG80211_CONNECT_TIMEOUT || \
5726 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05305727static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5728 struct cfg80211_bss *bss, const u8 *req_ie,
5729 size_t req_ie_len, const u8 *resp_ie,
5730 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305731 bool connect_timeout,
5732 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305733{
5734 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305735 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305736 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305737 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5738 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305739}
5740#else
5741static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5742 struct cfg80211_bss *bss, const u8 *req_ie,
5743 size_t req_ie_len, const u8 *resp_ie,
5744 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305745 bool connect_timeout,
5746 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305747{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305748 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5749 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305750}
5751#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305752
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305753#if defined(WLAN_FEATURE_FILS_SK)
5754#if defined(CFG80211_CONNECT_DONE) || \
5755 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
5756#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
5757 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305758/**
5759 * hdd_populate_fils_params() - Populate FILS keys to connect response
5760 * @fils_params: connect response to supplicant
5761 * @fils_kek: FILS kek
5762 * @fils_kek_len: FILS kek length
5763 * @pmk: FILS PMK
5764 * @pmk_len: FILS PMK length
5765 * @pmkid: PMKID
5766 * @fils_seq_num: FILS Seq number
5767 *
5768 * Return: None
5769 */
5770static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5771 *fils_params, const uint8_t *fils_kek,
5772 size_t fils_kek_len, const uint8_t *pmk,
5773 size_t pmk_len, const uint8_t *pmkid,
5774 uint16_t fils_seq_num)
5775{
5776 /* Increament seq number to be used for next FILS */
5777 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
5778 fils_params->update_erp_next_seq_num = true;
5779 fils_params->fils_kek = fils_kek;
5780 fils_params->fils_kek_len = fils_kek_len;
5781 fils_params->pmk = pmk;
5782 fils_params->pmk_len = pmk_len;
5783 fils_params->pmkid = pmkid;
5784}
5785#else
5786static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5787 *fils_params, const uint8_t
5788 *fils_kek, size_t fils_kek_len,
5789 const uint8_t *pmk, size_t pmk_len,
5790 const uint8_t *pmkid,
5791 uint16_t fils_seq_num)
5792{ }
5793#endif
5794
Jeff Johnson172237b2017-11-07 15:32:59 -08005795void hdd_update_hlp_info(struct net_device *dev,
5796 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305797{
5798 struct sk_buff *skb;
5799 uint16_t skb_len;
5800 struct llc_snap_hdr_t *llc_hdr;
5801 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305802 uint8_t *hlp_data;
5803 uint16_t hlp_data_len;
5804 struct fils_join_rsp_params *roam_fils_params
5805 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305806 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
5807
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305808 if (!roam_fils_params) {
5809 hdd_err("FILS Roam Param NULL");
5810 return;
5811 }
5812
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08005813 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305814 hdd_err("FILS HLP Data NULL, len %d",
5815 roam_fils_params->hlp_data_len);
5816 return;
5817 }
5818
5819 hlp_data = roam_fils_params->hlp_data;
5820 hlp_data_len = roam_fils_params->hlp_data_len;
5821
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305822 /* Calculate skb length */
5823 skb_len = (2 * ETH_ALEN) + hlp_data_len;
5824 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
5825 if (skb == NULL) {
5826 hdd_err("HLP packet nbuf alloc fails");
5827 return;
5828 }
5829
5830 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
5831 QDF_MAC_ADDR_SIZE);
5832 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
5833 QDF_MAC_ADDR_SIZE);
5834
5835 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
5836 if (IS_SNAP(llc_hdr)) {
5837 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5838 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5839 }
5840
5841 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
5842
5843 /*
5844 * This HLP packet is formed from HLP info encapsulated
5845 * in assoc response frame which is AEAD encrypted.
5846 * Hence, this checksum validation can be set unnecessary.
5847 * i.e. network layer need not worry about checksum.
5848 */
5849 skb->ip_summed = CHECKSUM_UNNECESSARY;
5850
5851 status = hdd_rx_packet_cbk(padapter, skb);
5852 if (QDF_IS_STATUS_ERROR(status)) {
5853 hdd_err("Sending HLP packet fails");
5854 return;
5855 }
5856 hdd_debug("send HLP packet to netif successfully");
5857}
5858
5859/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305860 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
5861 * @dev: network device
5862 * @bssid: bssid to which we want to associate
5863 * @bss: cfg80211 bss info
5864 * @roam_info: information about connected bss
5865 * @req_ie: Request Information Element
5866 * @req_ie_len: len of the req IE
5867 * @resp_ie: Response IE
5868 * @resp_ie_len: len of ht response IE
5869 * @status: status
5870 * @gfp: allocation flags
5871 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5872 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305873 *
5874 * This API is used as wrapper to send FILS key/sequence number
5875 * params etc. to supplicant in case of FILS connection
5876 *
5877 * Return: None
5878 */
5879static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005880 struct cfg80211_bss *bss,
5881 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305882 const u8 *req_ie, size_t req_ie_len,
5883 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005884 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305885 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305886{
5887 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305888 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5889 struct fils_join_rsp_params *roam_fils_params =
5890 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005891
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305892 qdf_mem_zero(&fils_params, sizeof(fils_params));
5893
5894 if (!roam_fils_params) {
5895 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5896 } else {
5897 fils_params.status = status;
5898 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08005899 fils_params.timeout_reason =
5900 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305901 fils_params.req_ie = req_ie;
5902 fils_params.req_ie_len = req_ie_len;
5903 fils_params.resp_ie = resp_ie;
5904 fils_params.resp_ie_len = resp_ie_len;
5905 fils_params.bss = bss;
5906 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5907 roam_fils_params->kek_len,
5908 roam_fils_params->fils_pmk,
5909 roam_fils_params->fils_pmk_len,
5910 roam_fils_params->fils_pmkid,
5911 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305912 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305913 }
5914 hdd_debug("FILS indicate connect status %d seq no %d",
5915 fils_params.status,
5916 fils_params.fils_erp_next_seq_num);
5917
5918 cfg80211_connect_done(dev, &fils_params, gfp);
5919
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305920 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305921 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305922
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305923 /* Clear all the FILS key info */
5924 if (roam_fils_params && roam_fils_params->fils_pmk)
5925 qdf_mem_free(roam_fils_params->fils_pmk);
5926 if (roam_fils_params)
5927 qdf_mem_free(roam_fils_params);
5928 roam_info->fils_join_rsp = NULL;
5929}
5930#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005931static inline void
5932hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005933 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005934 const u8 *req_ie, size_t req_ie_len,
5935 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5936 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305937 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305938{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305939#endif
5940#endif
5941
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305942#if defined(WLAN_FEATURE_FILS_SK) && \
5943 (defined(CFG80211_CONNECT_DONE) || \
5944 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305945/**
5946 * hdd_fils_update_connect_results() - API to send fils connection status to
5947 * supplicant.
5948 * @dev: network device
5949 * @bssid: bssid to which we want to associate
5950 * @bss: cfg80211 bss info
5951 * @roam_info: information about connected bss
5952 * @req_ie: Request Information Element
5953 * @req_ie_len: len of the req IE
5954 * @resp_ie: Response IE
5955 * @resp_ie_len: len of ht response IE
5956 * @status: status
5957 * @gfp: allocation flags
5958 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5959 * @timeout_reason: reason for connect timeout
5960 *
5961 * The API is a wrapper to send connection status to supplicant
5962 *
5963 * Return: 0 if success else failure
5964 */
5965static int hdd_fils_update_connect_results(struct net_device *dev,
5966 const u8 *bssid,
5967 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005968 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305969 size_t req_ie_len, const u8 *resp_ie,
5970 size_t resp_ie_len, u16 status, gfp_t gfp,
5971 bool connect_timeout,
5972 tSirResultCodes timeout_reason)
5973{
Dustin Brown491d54b2018-03-14 12:39:11 -07005974 hdd_enter();
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305975 if (!roam_info || !roam_info->is_fils_connection)
5976 return -EINVAL;
5977
5978 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5979 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305980 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305981 return 0;
5982}
5983#else
5984static inline int hdd_fils_update_connect_results(struct net_device *dev,
5985 const u8 *bssid,
5986 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005987 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305988 size_t req_ie_len, const u8 *resp_ie,
5989 size_t resp_ie_len, u16 status, gfp_t gfp,
5990 bool connect_timeout,
5991 tSirResultCodes timeout_reason)
5992{
5993 return -EINVAL;
5994}
5995#endif
5996
Anurag Chouhanc4092922016-09-08 15:56:11 +05305997/**
5998 * hdd_connect_result() - API to send connection status to supplicant
5999 * @dev: network device
6000 * @bssid: bssid to which we want to associate
6001 * @roam_info: information about connected bss
6002 * @req_ie: Request Information Element
6003 * @req_ie_len: len of the req IE
6004 * @resp_ie: Response IE
6005 * @resp_ie_len: len of ht response IE
6006 * @status: status
6007 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05306008 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306009 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05306010 *
6011 * The API is a wrapper to send connection status to supplicant
6012 * and allow runtime suspend
6013 *
6014 * Return: Void
6015 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306016void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006017 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05306018 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05306019 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306020 bool connect_timeout,
6021 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05306022{
Jeff Johnson9d295242017-08-29 14:39:48 -07006023 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306024 struct cfg80211_bss *bss = NULL;
Jingxiang Ge929c7932018-01-24 14:01:12 +08006025 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306026
6027 if (WLAN_STATUS_SUCCESS == status) {
6028 struct ieee80211_channel *chan;
6029 int freq;
6030 int chan_no = roam_info->pBssDesc->channelId;
6031
6032 if (chan_no <= 14)
6033 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07006034 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306035 else
6036 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07006037 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306038
6039 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
6040 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
6041 roam_info->u.pConnectedProfile->SSID.ssId,
6042 roam_info->u.pConnectedProfile->SSID.length);
6043 }
Komal Seelama89be8d2016-09-29 11:09:26 +05306044
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306045 if (hdd_fils_update_connect_results(dev, bssid, bss,
6046 roam_info, req_ie, req_ie_len, resp_ie,
6047 resp_ie_len, status, gfp, connect_timeout,
6048 timeout_reason) != 0) {
6049 hdd_connect_bss(dev, bssid, bss, req_ie,
6050 req_ie_len, resp_ie, resp_ie_len,
6051 status, gfp, connect_timeout, timeout_reason);
6052 }
Komal Seelama89be8d2016-09-29 11:09:26 +05306053
Jingxiang Geb49aa302018-01-17 20:54:15 +08006054 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07006055 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306056}
6057#else
6058void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006059 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05306060 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05306061 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306062 bool connect_timeout,
6063 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05306064{
Jeff Johnson9d295242017-08-29 14:39:48 -07006065 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Jingxiang Ge929c7932018-01-24 14:01:12 +08006066 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05306067
Anurag Chouhanc4092922016-09-08 15:56:11 +05306068 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
6069 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08006070
Jingxiang Geb49aa302018-01-17 20:54:15 +08006071 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07006072 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306073}
6074#endif
6075
Nirav Shah73713f72018-05-17 14:50:41 +05306076#ifdef FEATURE_MONITOR_MODE_SUPPORT
Jeff Johnsond9952752018-04-18 12:15:35 -07006077int wlan_hdd_set_mon_chan(struct hdd_adapter *adapter, uint32_t chan,
6078 uint32_t bandwidth)
6079{
6080 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6081 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
6082 struct hdd_mon_set_ch_info *ch_info = &sta_ctx->ch_info;
6083 QDF_STATUS status;
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006084 tHalHandle hal_hdl = hdd_ctx->mac_handle;
Jeff Johnsond9952752018-04-18 12:15:35 -07006085 struct qdf_mac_addr bssid;
6086 struct csr_roam_profile roam_profile;
6087 struct ch_params ch_params;
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006088 eConnectionState connstate;
Jeff Johnsond9952752018-04-18 12:15:35 -07006089
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006090 if (hdd_get_conparam() != QDF_GLOBAL_MONITOR_MODE &&
6091 adapter->device_mode != QDF_STA_MODE) {
6092 hdd_err("Not supported, device is not in monitor mode or sta mission mode");
Jeff Johnsond9952752018-04-18 12:15:35 -07006093 return -EINVAL;
6094 }
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006095 if (adapter->device_mode == QDF_STA_MODE &&
6096 hdd_ctx->config->enable_change_channel_bandwidth) {
6097 connstate = sta_ctx->conn_info.connState;
6098 if (eConnectionState_Associated == connstate ||
6099 eConnectionState_Connecting == connstate) {
6100 return -EINVAL;
6101 }
6102 }
Jeff Johnsond9952752018-04-18 12:15:35 -07006103
Visweswara Tanuku006313a2018-04-12 12:26:34 +05306104 /* Validate Channel */
6105 if (!WLAN_REG_IS_24GHZ_CH(chan) && !WLAN_REG_IS_5GHZ_CH(chan)) {
6106 hdd_err("Channel %d Not supported", chan);
6107 return -EINVAL;
6108 }
6109
6110 if (WLAN_REG_IS_24GHZ_CH(chan)) {
6111 if (bandwidth == CH_WIDTH_80MHZ) {
6112 hdd_err("BW80 not possible in 2.4GHz band");
6113 return -EINVAL;
6114 }
6115 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 14) &&
6116 (bandwidth != CH_WIDTH_MAX)) {
6117 hdd_err("Only BW20 possible on channel 14");
6118 return -EINVAL;
6119 }
6120 }
6121
6122 if (WLAN_REG_IS_5GHZ_CH(chan)) {
6123 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 165) &&
6124 (bandwidth != CH_WIDTH_MAX)) {
6125 hdd_err("Only BW20 possible on channel 165");
6126 return -EINVAL;
6127 }
6128 }
6129
Jeff Johnsond9952752018-04-18 12:15:35 -07006130 hdd_debug("Set monitor mode Channel %d", chan);
6131 qdf_mem_zero(&roam_profile, sizeof(roam_profile));
6132 roam_profile.ChannelInfo.ChannelList = &ch_info->channel;
6133 roam_profile.ChannelInfo.numOfChannels = 1;
6134 roam_profile.phyMode = ch_info->phy_mode;
6135 roam_profile.ch_params.ch_width = bandwidth;
6136 hdd_select_cbmode(adapter, chan, &roam_profile.ch_params);
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006137 if (hdd_ctx->config->enable_change_channel_bandwidth &&
6138 (!sme_find_session_by_bssid(hal_hdl, adapter->mac_addr.bytes))) {
6139 status = sme_create_mon_session(hal_hdl,
Rajeev Kumar Sirasanagandlae3b59912018-08-24 15:53:31 +05306140 adapter->mac_addr.bytes,
6141 adapter->session_id);
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006142 if (status != QDF_STATUS_SUCCESS) {
6143 hdd_err("Status: %d Failed to create session.",
6144 status);
6145 return qdf_status_to_os_return(status);
6146 }
6147 }
Jeff Johnsond9952752018-04-18 12:15:35 -07006148 qdf_mem_copy(bssid.bytes, adapter->mac_addr.bytes,
6149 QDF_MAC_ADDR_SIZE);
6150
6151 ch_params.ch_width = bandwidth;
6152 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev, chan, 0, &ch_params);
6153 if (ch_params.ch_width == CH_WIDTH_INVALID) {
6154 hdd_err("Invalid capture channel or bandwidth for a country");
6155 return -EINVAL;
6156 }
6157 if (wlan_hdd_change_hw_mode_for_given_chnl(adapter, chan,
6158 POLICY_MGR_UPDATE_REASON_SET_OPER_CHAN)) {
6159 hdd_err("Failed to change hw mode");
6160 return -EINVAL;
6161 }
6162
Jeff Johnson16528362018-06-14 12:34:16 -07006163 status = sme_roam_channel_change_req(hdd_ctx->mac_handle,
6164 bssid, &ch_params,
Jeff Johnsond9952752018-04-18 12:15:35 -07006165 &roam_profile);
6166 if (status) {
6167 hdd_err("Status: %d Failed to set sme_roam Channel for monitor mode",
6168 status);
6169 }
6170
6171 adapter->mon_chan = chan;
6172 adapter->mon_bandwidth = bandwidth;
6173 return qdf_status_to_os_return(status);
6174}
Nirav Shah73713f72018-05-17 14:50:41 +05306175#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05306176
Wu Gaodf929f12018-05-25 18:12:25 +08006177#ifdef MSM_PLATFORM
6178/**
6179 * hdd_stop_p2p_go() - call cfg80211 API to stop P2P GO
6180 * @adapter: pointer to adapter
6181 *
6182 * This function calls cfg80211 API to stop P2P GO
6183 *
6184 * Return: None
6185 */
6186static void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6187{
6188 hdd_debug("[SSR] send stop ap to supplicant");
6189 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
6190}
6191
6192static inline void hdd_delete_sta(struct hdd_adapter *adapter)
6193{
6194}
6195#else
6196static inline void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6197{
6198}
6199
6200/**
6201 * hdd_delete_sta() - call cfg80211 API to delete STA
6202 * @adapter: pointer to adapter
6203 *
6204 * This function calls cfg80211 API to delete STA
6205 *
6206 * Return: None
6207 */
6208static void hdd_delete_sta(struct hdd_adapter *adapter)
6209{
6210 struct qdf_mac_addr bcast_mac = QDF_MAC_ADDR_BCAST_INIT;
6211
6212 hdd_debug("[SSR] send restart supplicant");
6213 /* event supplicant to restart */
6214 cfg80211_del_sta(adapter->dev,
6215 (const u8 *)&bcast_mac.bytes[0],
6216 GFP_KERNEL);
6217}
6218#endif
6219
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006220QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006221{
Jeff Johnson9d295242017-08-29 14:39:48 -07006222 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006223 eConnectionState connState;
6224
Dustin Brown491d54b2018-03-14 12:39:11 -07006225 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006226
Dustin Brown920397d2017-12-13 16:27:50 -08006227 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05306228 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08006229 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05306230
Yue Ma42654682018-01-11 16:55:24 -08006231 hdd_debug("[SSR] start adapter with device mode %s(%d)",
6232 hdd_device_mode_to_string(adapter->device_mode),
6233 adapter->device_mode);
6234
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006235 hdd_wmm_init(adapter);
6236
6237 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006238 case QDF_STA_MODE:
6239 case QDF_P2P_CLIENT_MODE:
6240 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006241
6242 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
6243 ->conn_info.connState;
6244
Krunal Sonib51eec72017-11-20 21:53:01 -08006245 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006246 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07006247 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006248
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006249 /* Indicate disconnect event to supplicant
6250 * if associated previously
6251 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006252 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07006253 eConnectionState_IbssConnected == connState ||
6254 eConnectionState_NotConnected == connState ||
6255 eConnectionState_IbssDisconnected == connState ||
6256 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006257 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006258
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006259 memset(&wrqu, '\0', sizeof(wrqu));
6260 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
6261 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
6262 wireless_send_event(adapter->dev, SIOCGIWAP,
6263 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07006264 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07006265 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006266
6267 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05306268 wlan_hdd_cfg80211_indicate_disconnect(
6269 adapter->dev, false,
6270 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006271 } else if (eConnectionState_Connecting == connState) {
6272 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006273 * Indicate connect failure to supplicant if we
6274 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006275 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306276 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306277 NULL, 0, NULL, 0,
6278 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006279 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006280 }
6281
6282 hdd_register_tx_flow_control(adapter,
6283 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08006284 hdd_tx_resume_cb,
6285 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006286
Arunk Khandavalli40943af2017-05-15 19:25:34 +05306287 hdd_lpass_notify_start(hdd_ctx, adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05306288 hdd_nud_ignore_tracking(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006289 break;
6290
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006291 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006292 if (hdd_ctx->config->sap_internal_restart)
Krunal Sonib51eec72017-11-20 21:53:01 -08006293 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05306294
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006295 break;
6296
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006297 case QDF_P2P_GO_MODE:
Wu Gaodf929f12018-05-25 18:12:25 +08006298 hdd_delete_sta(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006299 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306300 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08006301 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306302 hdd_set_mon_rx_cb(adapter->dev);
6303 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
6304 adapter->mon_bandwidth);
6305 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006306 default:
6307 break;
6308 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07006309 /*
6310 * Action frame registered in one adapter which will
6311 * applicable to all interfaces
6312 */
6313 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006314 }
6315
Wu Gaodf929f12018-05-25 18:12:25 +08006316 hdd_for_each_adapter(hdd_ctx, adapter) {
6317 if (!hdd_is_interface_up(adapter))
6318 continue;
6319
6320 if (adapter->device_mode == QDF_P2P_GO_MODE)
6321 hdd_stop_p2p_go(adapter);
6322 }
6323
Dustin Browne74003f2018-03-14 12:51:58 -07006324 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006325
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306326 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006327}
6328
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006329QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006330 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006331{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306332 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006333 qdf_list_node_t *node;
6334
6335 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006336
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006337 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006338 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006339 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006340
6341 if (QDF_IS_STATUS_ERROR(status))
6342 return status;
6343
6344 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6345
6346 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006347}
6348
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006349QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006350 struct hdd_adapter *current_adapter,
6351 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006352{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306353 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006354 qdf_list_node_t *node;
6355
6356 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006357
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006358 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006359 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08006360 &current_adapter->node,
6361 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006362 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006363
6364 if (QDF_IS_STATUS_ERROR(status))
6365 return status;
6366
6367 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6368
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006369 return status;
6370}
6371
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006372QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006373 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006374{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306375 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006376
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006377 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006378 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006379 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006380
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006381 return status;
6382}
6383
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006384QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006385 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006386{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306387 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006388 qdf_list_node_t *node;
6389
6390 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006391
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006392 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006393 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006394 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006395
6396 if (QDF_IS_STATUS_ERROR(status))
6397 return status;
6398
6399 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6400
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006401 return status;
6402}
6403
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006404QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006405 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006406{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306407 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006408
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006409 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006410 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006411 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006412
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006413 return status;
6414}
6415
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006416QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006417 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006418{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306419 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006420
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006421 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006422 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006423 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006424
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006425 return status;
6426}
6427
Jeff Johnson9d295242017-08-29 14:39:48 -07006428struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006429 tSirMacAddr macAddr)
6430{
Jeff Johnson9d295242017-08-29 14:39:48 -07006431 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006432
Dustin Brown920397d2017-12-13 16:27:50 -08006433 hdd_for_each_adapter(hdd_ctx, adapter) {
6434 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
6435 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006436 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006437 }
6438
6439 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006440}
6441
Jeff Johnson9d295242017-08-29 14:39:48 -07006442struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006443 uint32_t vdev_id)
6444{
Jeff Johnson9d295242017-08-29 14:39:48 -07006445 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006446
Dustin Brown920397d2017-12-13 16:27:50 -08006447 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07006448 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006449 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006450 }
6451
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006452 return NULL;
6453}
6454
Abhishek Singh7996eb72015-12-30 17:24:02 +05306455/**
6456 * hdd_get_adapter_by_sme_session_id() - Return adapter with
6457 * the sessionid
6458 * @hdd_ctx: hdd context.
6459 * @sme_session_id: sme session is for the adapter to get.
6460 *
6461 * This function is used to get the adapter with provided session id
6462 *
6463 * Return: adapter pointer if found
6464 *
6465 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07006466struct hdd_adapter *
6467hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
6468 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306469{
Jeff Johnson9d295242017-08-29 14:39:48 -07006470 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306471
Dustin Brown920397d2017-12-13 16:27:50 -08006472 hdd_for_each_adapter(hdd_ctx, adapter) {
6473 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306474 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306475 }
Dustin Brown920397d2017-12-13 16:27:50 -08006476
Abhishek Singh7996eb72015-12-30 17:24:02 +05306477 return NULL;
6478}
6479
Jeff Johnson9d295242017-08-29 14:39:48 -07006480struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07006481 const char *iface_name)
6482{
Jeff Johnson9d295242017-08-29 14:39:48 -07006483 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006484
Dustin Brown920397d2017-12-13 16:27:50 -08006485 hdd_for_each_adapter(hdd_ctx, adapter) {
6486 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07006487 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006488 }
Dustin Brown920397d2017-12-13 16:27:50 -08006489
Naveen Rawat4edb6822017-04-12 10:09:17 -07006490 return NULL;
6491}
6492
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006493/**
6494 * hdd_get_adapter() - to get adapter matching the mode
6495 * @hdd_ctx: hdd context
6496 * @mode: adapter mode
6497 *
6498 * This routine will return the pointer to adapter matching
6499 * with the passed mode.
6500 *
6501 * Return: pointer to adapter or null
6502 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006503struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006504 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006505{
Jeff Johnson9d295242017-08-29 14:39:48 -07006506 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006507
Dustin Brown920397d2017-12-13 16:27:50 -08006508 hdd_for_each_adapter(hdd_ctx, adapter) {
6509 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006510 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006511 }
6512
6513 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006514}
6515
Jeff Johnson36a0abf2018-05-20 11:24:25 -07006516enum QDF_OPMODE hdd_get_device_mode(uint32_t session_id)
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306517{
6518 struct hdd_context *hdd_ctx;
6519 struct hdd_adapter *adapter;
6520
6521 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
6522 if (!hdd_ctx) {
6523 hdd_err("Invalid HDD context");
6524 return QDF_MAX_NO_OF_MODE;
6525 }
6526
6527 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
6528 if (!adapter) {
6529 hdd_err("Invalid HDD adapter");
6530 return QDF_MAX_NO_OF_MODE;
6531 }
6532
6533 return adapter->device_mode;
6534}
6535
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006536/**
6537 * hdd_get_operating_channel() - return operating channel of the device mode
6538 * @hdd_ctx: Pointer to the HDD context.
6539 * @mode: Device mode for which operating channel is required.
Jeff Johnson77f89bb2018-05-06 16:21:36 -07006540 * Supported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006541 * QDF_STA_MODE,
6542 * QDF_P2P_CLIENT_MODE,
6543 * QDF_SAP_MODE,
6544 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006545 *
6546 * This API returns the operating channel of the requested device mode
6547 *
6548 * Return: channel number. "0" id the requested device is not found OR it is
6549 * not connected.
6550 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006551uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006552 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006553{
Jeff Johnson9d295242017-08-29 14:39:48 -07006554 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006555 uint8_t operatingChannel = 0;
6556
Dustin Brown920397d2017-12-13 16:27:50 -08006557 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006558 if (mode == adapter->device_mode) {
6559 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006560 case QDF_STA_MODE:
6561 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006562 if (hdd_conn_is_connected
6563 (WLAN_HDD_GET_STATION_CTX_PTR
6564 (adapter))) {
6565 operatingChannel =
6566 (WLAN_HDD_GET_STATION_CTX_PTR
6567 (adapter))->conn_info.
6568 operationChannel;
6569 }
6570 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006571 case QDF_SAP_MODE:
6572 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006573 /* softap connection info */
6574 if (test_bit
6575 (SOFTAP_BSS_STARTED,
6576 &adapter->event_flags))
6577 operatingChannel =
6578 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07006579 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006580 break;
6581 default:
6582 break;
6583 }
6584
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006585 /* Found the device of interest. break the loop */
6586 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006587 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006588 }
Dustin Brown920397d2017-12-13 16:27:50 -08006589
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006590 return operatingChannel;
6591}
6592
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006593static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006594 hdd_ctx)
6595{
Jeff Johnson9d295242017-08-29 14:39:48 -07006596 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006597
Dustin Brown491d54b2018-03-14 12:39:11 -07006598 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006599
Dustin Brown920397d2017-12-13 16:27:50 -08006600 hdd_for_each_adapter(hdd_ctx, adapter) {
6601 if (adapter->device_mode == QDF_STA_MODE ||
6602 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6603 adapter->device_mode == QDF_IBSS_MODE ||
6604 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6605 adapter->device_mode == QDF_SAP_MODE ||
6606 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006607 hdd_unregister_wext(adapter->dev);
6608 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006609 }
6610
Dustin Browne74003f2018-03-14 12:51:58 -07006611 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006612
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306613 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006614}
6615
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006616QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006617{
Jeff Johnson9d295242017-08-29 14:39:48 -07006618 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006619
Dustin Brown491d54b2018-03-14 12:39:11 -07006620 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006621
Dustin Brown920397d2017-12-13 16:27:50 -08006622 hdd_for_each_adapter(hdd_ctx, adapter) {
6623 if (adapter->device_mode == QDF_STA_MODE ||
6624 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6625 adapter->device_mode == QDF_IBSS_MODE ||
6626 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6627 adapter->device_mode == QDF_SAP_MODE ||
6628 adapter->device_mode == QDF_P2P_GO_MODE) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006629 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006630 adapter->session_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05306631 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006632 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006633 }
6634
Dustin Browne74003f2018-03-14 12:51:58 -07006635 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006636
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306637 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006638}
6639
Dustin Brownf27bce82016-11-03 12:52:27 -07006640/**
6641 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
6642 * adapters
6643 * @hdd_ctx: The HDD context containing the adapters to operate on
6644 *
6645 * return: QDF_STATUS_SUCCESS
6646 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006647static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07006648{
Jeff Johnson9d295242017-08-29 14:39:48 -07006649 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07006650 int err;
6651
Dustin Brown491d54b2018-03-14 12:39:11 -07006652 hdd_enter();
Dustin Brownf27bce82016-11-03 12:52:27 -07006653
Dustin Brown920397d2017-12-13 16:27:50 -08006654 hdd_for_each_adapter(hdd_ctx, adapter) {
6655 if (adapter->device_mode == QDF_STA_MODE ||
6656 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6657 adapter->device_mode == QDF_IBSS_MODE ||
6658 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6659 adapter->device_mode == QDF_SAP_MODE ||
6660 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07006661 err = wlan_hdd_sched_scan_stop(adapter->dev);
6662 if (err)
6663 hdd_err("Unable to stop scheduled scan");
6664 }
Dustin Brownf27bce82016-11-03 12:52:27 -07006665 }
6666
Dustin Browne74003f2018-03-14 12:51:58 -07006667 hdd_exit();
Dustin Brownf27bce82016-11-03 12:52:27 -07006668
6669 return QDF_STATUS_SUCCESS;
6670}
6671
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006672#ifdef WLAN_NS_OFFLOAD
6673/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006674 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006675 * @hdd_ctx: Pointer to hdd context
6676 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006677 * Unregister for IPv6 address change notifications.
6678 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006679 * Return: None
6680 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006681static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006682{
6683 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006684}
6685
6686/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006687 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006688 * @hdd_ctx: Pointer to hdd context
6689 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006690 * Register for IPv6 address change notifications.
6691 *
6692 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006693 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006694static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006695{
6696 int ret;
6697
6698 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
6699 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006700 if (ret) {
6701 hdd_err("Failed to register IPv6 notifier: %d", ret);
6702 goto out;
6703 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006704
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006705 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006706out:
6707 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006708}
6709#else
6710/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006711 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006712 * @hdd_ctx: Pointer to hdd context
6713 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006714 * Unregister for IPv6 address change notifications.
6715 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006716 * Return: None
6717 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006718static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006719{
6720}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006721
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006722/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006723 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006724 * @hdd_ctx: Pointer to hdd context
6725 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006726 * Register for IPv6 address change notifications.
6727 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006728 * Return: None
6729 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006730static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006731{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006732 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006733}
6734#endif
6735
Alok Kumarb64650c2018-03-23 17:05:11 +05306736void hdd_set_disconnect_status(struct hdd_adapter *adapter, bool status)
6737{
6738 qdf_mutex_acquire(&adapter->disconnection_status_lock);
6739 adapter->disconnection_in_progress = status;
6740 qdf_mutex_release(&adapter->disconnection_status_lock);
6741 hdd_debug("setting disconnection status: %d", status);
6742}
6743
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006744/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006745 * hdd_register_notifiers - Register netdev notifiers.
6746 * @hdd_ctx: HDD context
6747 *
6748 * Register netdev notifiers like IPv4 and IPv6.
6749 *
6750 * Return: 0 on success and errno on failure
6751 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006752static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006753{
6754 int ret;
6755
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006756 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
6757 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306758 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006759
6760 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
6761 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
6762 if (ret) {
6763 hdd_err("Failed to register IPv4 notifier: %d", ret);
6764 goto unregister_ip6_notifier;
6765 }
6766
Alok Kumarb64650c2018-03-23 17:05:11 +05306767 ret = hdd_nud_register_netevent_notifier(hdd_ctx);
6768 if (ret) {
6769 hdd_err("Failed to register netevent notifier: %d",
6770 ret);
6771 goto unregister_inetaddr_notifier;
6772 }
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006773 return 0;
6774
Alok Kumarb64650c2018-03-23 17:05:11 +05306775unregister_inetaddr_notifier:
6776 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006777unregister_ip6_notifier:
6778 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006779out:
6780 return ret;
6781
6782}
6783
6784/**
6785 * hdd_unregister_notifiers - Unregister netdev notifiers.
6786 * @hdd_ctx: HDD context
6787 *
6788 * Unregister netdev notifiers like IPv4 and IPv6.
6789 *
6790 * Return: None.
6791 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006792void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006793{
Alok Kumarb64650c2018-03-23 17:05:11 +05306794 hdd_nud_unregister_netevent_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006795 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
6796
6797 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006798}
6799
6800/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006801 * hdd_exit_netlink_services - Exit netlink services
6802 * @hdd_ctx: HDD context
6803 *
6804 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
6805 * nl service.
6806 *
6807 * Return: None.
6808 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006809static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006810{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306811 spectral_scan_deactivate_service();
6812 cnss_diag_deactivate_service();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006813 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006814 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306815 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006816
6817 nl_srv_exit();
6818}
6819
6820/**
6821 * hdd_init_netlink_services- Init netlink services
6822 * @hdd_ctx: HDD context
6823 *
6824 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
6825 * nl service.
6826 *
6827 * Return: 0 on success and errno on failure.
6828 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006829static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006830{
6831 int ret;
6832
Ryan Hsuceddceb2016-04-28 10:20:14 -07006833 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006834 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006835 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006836 goto out;
6837 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07006838 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006839
Naveen Rawat910726a2017-03-06 11:42:51 -08006840 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006841 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006842 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006843 goto err_nl_srv;
6844 }
6845
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306846 ptt_sock_activate_svc();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006847
6848 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07006849 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006850 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006851
6852 ret = cnss_diag_activate_service();
6853 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006854 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006855 goto err_close_cesium;
6856 }
6857
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306858 spectral_scan_activate_service();
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08006859
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006860 return 0;
6861
6862err_close_cesium:
6863 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006864 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306865 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006866err_nl_srv:
6867 nl_srv_exit();
6868out:
6869 return ret;
6870}
6871
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006872/**
6873 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
6874 * @hdd_ctx: HDD context.
6875 *
6876 * Destroy RX wakelock.
6877 *
6878 * Return: None.
6879 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006880static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006881{
6882 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
6883}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006884
6885/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006886 * hdd_rx_wake_lock_create() - Create RX wakelock
6887 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006888 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006889 * Create RX wakelock.
6890 *
6891 * Return: None.
6892 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006893static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006894{
6895 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
6896}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006897
6898/**
Houston Hoffman160db392016-10-10 17:37:51 -07006899 * hdd_context_deinit() - Deinitialize HDD context
6900 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006901 *
Houston Hoffman160db392016-10-10 17:37:51 -07006902 * Deinitialize HDD context along with all the feature specific contexts but
6903 * do not free hdd context itself. Caller of this API is supposed to free
6904 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006905 *
Houston Hoffman160db392016-10-10 17:37:51 -07006906 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006907 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006908static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006909{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306910 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
6911
Houston Hoffman160db392016-10-10 17:37:51 -07006912 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006913
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006914 hdd_sap_context_destroy(hdd_ctx);
6915
6916 hdd_rx_wake_lock_destroy(hdd_ctx);
6917
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006918 hdd_scan_context_destroy(hdd_ctx);
6919
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006920 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006921
Houston Hoffman160db392016-10-10 17:37:51 -07006922 return 0;
6923}
6924
6925/**
6926 * hdd_context_destroy() - Destroy HDD context
6927 * @hdd_ctx: HDD context to be destroyed.
6928 *
6929 * Free config and HDD context as well as destroy all the resources.
6930 *
6931 * Return: None
6932 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006933static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07006934{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07006935 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05306936
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05306937 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
6938
Houston Hoffman160db392016-10-10 17:37:51 -07006939 hdd_context_deinit(hdd_ctx);
6940
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306941 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006942 hdd_ctx->config = NULL;
6943
Dustin Brown84f46ea2018-02-15 11:57:36 -08006944 cfg_release();
6945
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006946 wiphy_free(hdd_ctx->wiphy);
6947}
6948
6949/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306950 * wlan_destroy_bug_report_lock() - Destroy bug report lock
6951 *
6952 * This function is used to destroy bug report lock
6953 *
6954 * Return: None
6955 */
6956static void wlan_destroy_bug_report_lock(void)
6957{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07006958 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306959
6960 p_cds_context = cds_get_global_context();
6961 if (!p_cds_context) {
6962 hdd_err("cds context is NULL");
6963 return;
6964 }
6965
6966 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6967}
6968
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05306969#ifdef DISABLE_CHANNEL_LIST
6970static void wlan_hdd_cache_chann_mutex_destroy(struct hdd_context *hdd_ctx)
6971{
6972 qdf_mutex_destroy(&hdd_ctx->cache_channel_lock);
6973}
6974#else
6975static void wlan_hdd_cache_chann_mutex_destroy(struct hdd_context *hdd_ctx)
6976{
6977}
6978#endif
6979
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306980/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006981 * hdd_wlan_exit() - HDD WLAN exit function
6982 * @hdd_ctx: Pointer to the HDD Context
6983 *
6984 * This is the driver exit point (invoked during rmmod)
6985 *
6986 * Return: None
6987 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006988static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006989{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006990 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306991 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006992
Dustin Brown491d54b2018-03-14 12:39:11 -07006993 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006994
Arun Khandavallifae92942016-08-01 13:31:08 +05306995 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006996
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006997#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306998 if (QDF_TIMER_STATE_RUNNING ==
6999 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
7000 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007001 }
7002
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307003 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05307004 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07007005 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007006 }
Liangwei Dongaef84342016-10-21 05:28:00 -04007007 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
7008 qdf_mem_free(hdd_ctx->last_acs_channel_list);
7009 hdd_ctx->last_acs_channel_list = NULL;
7010 hdd_ctx->num_of_channels = 0;
7011 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007012#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007013
Arun Khandavallifae92942016-08-01 13:31:08 +05307014 mutex_lock(&hdd_ctx->iface_change_lock);
7015 driver_status = hdd_ctx->driver_status;
7016 mutex_unlock(&hdd_ctx->iface_change_lock);
7017
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007018 /*
7019 * Powersave Offload Case
7020 * Disable Idle Power Save Mode
7021 */
7022 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07007023 /* clear the scan queue in all the scenarios */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +05307024 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007025
Arun Khandavallifae92942016-08-01 13:31:08 +05307026 if (driver_status != DRIVER_MODULES_CLOSED) {
7027 hdd_unregister_wext_all_adapters(hdd_ctx);
7028 /*
7029 * Cancel any outstanding scan requests. We are about to close
7030 * all of our adapters, but an adapter structure is what SME
7031 * passes back to our callback function. Hence if there
7032 * are any outstanding scan requests then there is a
7033 * race condition between when the adapter is closed and
7034 * when the callback is invoked. We try to resolve that
7035 * race condition here by canceling any outstanding scans
7036 * before we close the adapters.
7037 * Note that the scans may be cancelled in an asynchronous
7038 * manner, so ideally there needs to be some kind of
7039 * synchronization. Rather than introduce a new
7040 * synchronization here, we will utilize the fact that we are
7041 * about to Request Full Power, and since that is synchronized,
7042 * the expectation is that by the time Request Full Power has
7043 * completed, all scans will be cancelled
7044 */
7045 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07007046 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08007047 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08007048 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007049 }
7050
Arunk Khandavalli830c9692018-03-22 12:17:40 +05307051 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavalli08479ba2017-08-07 19:56:23 +05307052 unregister_netdevice_notifier(&hdd_netdev_notifier);
7053
Rachit Kankane30807332018-06-27 18:39:36 +05307054 qdf_dp_trace_deinit();
7055
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07007056 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05307057
Dustin Brown86d196b2018-08-02 11:51:49 -07007058 hdd_bus_bandwidth_deinit(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -08007059 hdd_driver_memdump_deinit();
7060
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05307061 qdf_nbuf_deinit_replenish_timer();
7062
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05307063 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
7064 hdd_info("Release wakelock for monitor mode!");
7065 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
7066 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
7067 }
7068
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307069 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
7070 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
7071 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05307072 wlan_hdd_cache_chann_mutex_destroy(hdd_ctx);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307073
Naveen Rawate02f8f52018-04-05 11:58:04 -07007074 osif_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007075
Dustin Brownd005ad82018-01-19 10:32:13 -08007076 hdd_close_all_adapters(hdd_ctx, false);
7077
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05307078 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307079 /*
7080 * If there is re_init failure wiphy would have already de-registered
7081 * check the wiphy status before un-registering again
7082 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05307083 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307084 wiphy_unregister(wiphy);
7085 wlan_hdd_cfg80211_deinit(wiphy);
7086 hdd_lpass_notify_stop(hdd_ctx);
7087 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07007088
Arun Khandavallifae92942016-08-01 13:31:08 +05307089 hdd_exit_netlink_services(hdd_ctx);
7090 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307091#ifdef FEATURE_WLAN_CH_AVOID
7092 mutex_destroy(&hdd_ctx->avoid_freq_lock);
7093#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05307094
Abhishek Singhe9068f12017-03-31 14:14:52 +05307095 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
7096 if (driver_status)
7097 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07007098
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007099 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007100}
7101
7102void __hdd_wlan_exit(void)
7103{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007104 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007105
Dustin Brown491d54b2018-03-14 12:39:11 -07007106 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007107
Anurag Chouhan6d760662016-02-20 16:05:43 +05307108 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007109 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007110 hdd_err("Invalid HDD Context");
Dustin Browne74003f2018-03-14 12:51:58 -07007111 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007112 return;
7113 }
7114
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007115 /* Do all the cleanup before deregistering the driver */
7116 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07007117
Dustin Browne74003f2018-03-14 12:51:58 -07007118 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007119}
7120
7121#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04007122/**
7123 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007124 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04007125 *
7126 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
7127 * Then new ACS request will do a fresh scan without reusing the cached
7128 * scan information.
7129 *
7130 * Return: void
7131 */
Tang Yingying523322d2017-01-17 23:28:43 +08007132static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007133{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007134 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Jeff Johnson16528362018-06-14 12:34:16 -07007135 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007136
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007137 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007138 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04007139 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
7140 qdf_mem_free(hdd_ctx->last_acs_channel_list);
7141 hdd_ctx->last_acs_channel_list = NULL;
7142 hdd_ctx->num_of_channels = 0;
7143 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007144
Jeff Johnson16528362018-06-14 12:34:16 -07007145 mac_handle = hdd_ctx->mac_handle;
7146 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007147 return;
Jeff Johnson16528362018-06-14 12:34:16 -07007148 sme_scan_flush_result(mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007149}
7150#endif
7151
7152#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07007153int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
7154 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007155{
7156 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307157 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07007158 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07007159 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007160
7161 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7162
7163 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307164 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007165 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307166
Jeff Johnson16528362018-06-14 12:34:16 -07007167 mac_handle = hdd_ctx->mac_handle;
7168 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007169 return -EINVAL;
7170
Jeff Johnson16528362018-06-14 12:34:16 -07007171 qdf_status = sme_notify_ht2040_mode(mac_handle, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007172 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307173 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007174 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007175 return -EINVAL;
7176 }
7177
7178 return 0;
7179}
7180#endif
7181
7182/**
7183 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
7184 * @state: state
7185 *
7186 * This function notifies FW with modem power status
7187 *
7188 * Return: 0 if successful, error number otherwise
7189 */
7190int hdd_wlan_notify_modem_power_state(int state)
7191{
7192 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307193 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007194 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07007195 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007196
Anurag Chouhan6d760662016-02-20 16:05:43 +05307197 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007198 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307199 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007200 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307201
Jeff Johnson16528362018-06-14 12:34:16 -07007202 mac_handle = hdd_ctx->mac_handle;
7203 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007204 return -EINVAL;
7205
Jeff Johnson16528362018-06-14 12:34:16 -07007206 qdf_status = sme_notify_modem_power_state(mac_handle, state);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307207 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007208 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007209 state);
7210 return -EINVAL;
7211 }
7212 return 0;
7213}
7214
7215/**
7216 *
7217 * hdd_post_cds_enable_config() - HDD post cds start config helper
7218 * @adapter - Pointer to the HDD
7219 *
7220 * Return: None
7221 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007222QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007223{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307224 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007225
7226 /*
7227 * Send ready indication to the HDD. This will kick off the MAC
7228 * into a 'running' state and should kick off an initial scan.
7229 */
Jeff Johnson16528362018-06-14 12:34:16 -07007230 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->mac_handle);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307231 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007232 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
7233 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307234 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007235 }
7236
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307237 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007238}
7239
Sourav Mohapatra92ea8d62018-02-05 10:03:10 +05307240struct hdd_adapter *hdd_get_first_valid_adapter(struct hdd_context *hdd_ctx)
7241{
7242 struct hdd_adapter *adapter;
7243
7244 hdd_for_each_adapter(hdd_ctx, adapter) {
7245 if (adapter && adapter->magic == WLAN_HDD_ADAPTER_MAGIC)
7246 return adapter;
7247 }
7248
7249 return NULL;
7250}
7251
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007252/* wake lock APIs for HDD */
7253void hdd_prevent_suspend(uint32_t reason)
7254{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307255 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007256}
7257
7258void hdd_allow_suspend(uint32_t reason)
7259{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307260 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007261}
7262
7263void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
7264{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05307265 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
7266 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007267}
7268
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007269/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007270QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007271{
Jeff Johnson16528362018-06-14 12:34:16 -07007272 return sme_init_chan_list(hdd_ctx->mac_handle,
Amar Singhal6f8592b2017-04-26 14:31:58 -07007273 hdd_ctx->reg.alpha2,
7274 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007275}
7276
7277/**
7278 * hdd_is_5g_supported() - check if hardware supports 5GHz
7279 * @hdd_ctx: Pointer to the hdd context
7280 *
7281 * HDD function to know if hardware supports 5GHz
7282 *
7283 * Return: true if hardware supports 5GHz
7284 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007285bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007286{
Amar Singhal58b45ef2017-08-01 13:43:54 -07007287 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08007288 return true;
7289
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08007290 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08007291 return true;
7292 else
7293 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007294}
7295
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007296static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007297{
7298 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07007299 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007300
7301 wiphy = hdd_ctx->wiphy;
7302
7303 /*
7304 * The channel information in
7305 * wiphy needs to be initialized before wiphy registration
7306 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007307 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
7308 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007309 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07007310 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007311 }
7312
7313#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
7314 wiphy->wowlan = &wowlan_support_reg_init;
7315#else
7316 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
7317 WIPHY_WOWLAN_MAGIC_PKT |
7318 WIPHY_WOWLAN_DISCONNECT |
7319 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
7320 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
7321 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
7322 WIPHY_WOWLAN_4WAY_HANDSHAKE |
7323 WIPHY_WOWLAN_RFKILL_RELEASE;
7324
7325 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
7326 WOW_MAX_FILTERS_PER_LIST);
7327 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
7328 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
7329#endif
Liangwei Dong0da14262018-07-03 03:30:23 -04007330 if (hdd_ctx->obss_scan_offload) {
7331 hdd_debug("wmi_service_obss_scan supported");
7332 } else if (hdd_ctx->config->nChannelBondingMode24GHz) {
7333 hdd_debug("enable wpa_supp obss_scan");
7334 wiphy->features |= NL80211_FEATURE_NEED_OBSS_SCAN;
7335 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007336
7337 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007338 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307339 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07007340 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307341 return ret_val;
7342 }
Amar Singhalac26de22018-06-22 12:53:06 -07007343
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007344 /* Check the kernel version for upstream commit aced43ce780dc5 that
7345 * has support for processing user cell_base hints when wiphy is
7346 * self managed or check the backport flag for the same.
7347 */
Amar Singhalac26de22018-06-22 12:53:06 -07007348#if defined CFG80211_USER_HINT_CELL_BASE_SELF_MANAGED || \
7349 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0))
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007350 hdd_send_wiphy_regd_sync_event(hdd_ctx);
7351#endif
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307352
Amar Singhal2d812012018-02-03 15:06:47 +08007353 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007354
Amar Singhale4f28ee2015-10-21 14:36:56 -07007355 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007356}
7357
Mohit Khannaca4173b2017-09-12 21:52:19 -07007358#ifdef MSM_PLATFORM
7359/**
7360 * hdd_display_periodic_stats() - Function to display periodic stats
7361 * @hdd_ctx - handle to hdd context
7362 * @bool data_in_interval - true, if data detected in bw time interval
7363 *
7364 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
7365 * Stats show up in wlan driver logs.
7366 *
7367 * Returns: None
7368 */
Mohit Khanna70322002018-05-15 19:21:32 -07007369static void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
7370 bool data_in_interval)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007371{
Mohit Khanna70322002018-05-15 19:21:32 -07007372 static uint32_t counter;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007373 static bool data_in_time_period;
7374 ol_txrx_pdev_handle pdev;
7375
7376 if (hdd_ctx->config->periodic_stats_disp_time == 0)
7377 return;
7378
7379 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
7380 if (!pdev) {
7381 hdd_err("pdev is NULL");
7382 return;
7383 }
7384
7385 counter++;
7386 if (data_in_interval)
7387 data_in_time_period = data_in_interval;
7388
7389 if (counter * hdd_ctx->config->busBandwidthComputeInterval >=
7390 hdd_ctx->config->periodic_stats_disp_time * 1000) {
7391 if (data_in_time_period) {
Mohit Khanna70322002018-05-15 19:21:32 -07007392 wlan_hdd_display_txrx_stats(hdd_ctx);
7393 dp_txrx_dump_stats(cds_get_context(QDF_MODULE_ID_SOC));
7394 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
7395 CDP_RX_RING_STATS,
7396 QDF_STATS_VERBOSITY_LEVEL_LOW);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007397 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
7398 CDP_TXRX_PATH_STATS,
7399 QDF_STATS_VERBOSITY_LEVEL_LOW);
7400 wlan_hdd_display_netif_queue_history
7401 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
7402 qdf_dp_trace_dump_stats();
7403 }
7404 counter = 0;
7405 data_in_time_period = false;
7406 }
7407}
7408
Ravi Joshie2331e82015-07-01 18:18:54 -07007409/**
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007410 * hdd_clear_rps_cpu_mask - clear RPS CPU mask for interfaces
7411 * @hdd_ctx: pointer to struct hdd_context
7412 *
7413 * Return: none
7414 */
7415static void hdd_clear_rps_cpu_mask(struct hdd_context *hdd_ctx)
7416{
7417 struct hdd_adapter *adapter;
7418
7419 hdd_for_each_adapter(hdd_ctx, adapter)
7420 hdd_send_rps_disable_ind(adapter);
7421}
7422
7423/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07007424 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07007425 * @hdd_ctx - handle to hdd context
7426 * @tx_packets - transmit packet count
7427 * @rx_packets - receive packet count
7428 *
7429 * The function controls the bus bandwidth and dynamic control of
7430 * tcp delayed ack configuration
7431 *
7432 * Returns: None
7433 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007434
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007435static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07007436 const uint64_t tx_packets,
7437 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007438{
Mohit Khannaca4173b2017-09-12 21:52:19 -07007439 u64 total_pkts = tx_packets + rx_packets;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007440 uint64_t temp_tx = 0, avg_rx = 0;
7441 uint64_t no_rx_offload_pkts = 0, avg_no_rx_offload_pkts = 0;
7442 uint64_t rx_offload_pkts = 0, avg_rx_offload_pkts = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007443 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08007444 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08007445 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007446 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007447 uint16_t index = 0;
7448 bool vote_level_change = false;
7449 bool rx_level_change = false;
7450 bool tx_level_change = false;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007451 bool rxthread_high_tput_req = false;
Mohit Khannaf7562c32018-07-05 17:42:36 -07007452 bool dptrace_high_tput_req;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007453 if (total_pkts > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007454 next_vote_level = PLD_BUS_WIDTH_HIGH;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007455 else if (total_pkts > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007456 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007457 else if (total_pkts > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007458 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07007459 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07007460 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007461
Mohit Khannaf7562c32018-07-05 17:42:36 -07007462 dptrace_high_tput_req =
7463 next_vote_level > PLD_BUS_WIDTH_NONE ? true : false;
7464
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007465 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07007466 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
7467 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007468 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007469 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007470 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007471 if ((next_vote_level == PLD_BUS_WIDTH_LOW) ||
7472 (next_vote_level == PLD_BUS_WIDTH_NONE)) {
Nirav Shahffc6a092016-06-09 16:09:08 +05307473 if (hdd_ctx->hbw_requested) {
7474 pld_remove_pm_qos(hdd_ctx->parent_dev);
7475 hdd_ctx->hbw_requested = false;
7476 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007477 if (hdd_ctx->dynamic_rps)
7478 hdd_clear_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007479 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05307480 if (!hdd_ctx->hbw_requested) {
7481 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
7482 hdd_ctx->hbw_requested = true;
7483 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007484 if (hdd_ctx->dynamic_rps)
7485 hdd_set_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007486 }
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007487
Manjunathappa Prakashcb6df762018-05-29 18:54:58 -07007488 if (hdd_ctx->config->napi_cpu_affinity_mask)
7489 hdd_napi_apply_throughput_policy(hdd_ctx,
7490 tx_packets,
7491 rx_packets);
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007492
7493 if (rx_packets < hdd_ctx->config->busBandwidthLowThreshold)
7494 hdd_disable_rx_ol_for_low_tput(hdd_ctx, true);
7495 else
7496 hdd_disable_rx_ol_for_low_tput(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007497 }
Mohit Khannae71e2262015-11-10 09:37:24 -08007498
Mohit Khannaf7562c32018-07-05 17:42:36 -07007499 qdf_dp_trace_apply_tput_policy(dptrace_high_tput_req);
7500
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007501 /*
7502 * Includes tcp+udp, if perf core is required for tcp, then
7503 * perf core is also required for udp.
7504 */
7505 no_rx_offload_pkts = hdd_ctx->no_rx_offload_pkt_cnt;
7506 hdd_ctx->no_rx_offload_pkt_cnt = 0;
7507 rx_offload_pkts = rx_packets - no_rx_offload_pkts;
Mohit Khannae71e2262015-11-10 09:37:24 -08007508
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007509 avg_no_rx_offload_pkts = (no_rx_offload_pkts +
7510 hdd_ctx->prev_no_rx_offload_pkts) / 2;
7511 hdd_ctx->prev_no_rx_offload_pkts = no_rx_offload_pkts;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08007512
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007513 avg_rx_offload_pkts = (rx_offload_pkts +
7514 hdd_ctx->prev_rx_offload_pkts) / 2;
7515 hdd_ctx->prev_rx_offload_pkts = rx_offload_pkts;
7516
7517 avg_rx = avg_no_rx_offload_pkts + avg_rx_offload_pkts;
7518 /*
7519 * Takes care to set Rx_thread affinity for below case
7520 * 1)LRO/GRO not supported ROME case
7521 * 2)when rx_ol is disabled in cases like concurrency etc
7522 * 3)For UDP cases
7523 */
7524 if (avg_no_rx_offload_pkts >
7525 hdd_ctx->config->busBandwidthHighThreshold)
7526 rxthread_high_tput_req = true;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307527 else
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007528 rxthread_high_tput_req = false;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307529
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007530 if (cds_sched_handle_throughput_req(rxthread_high_tput_req))
7531 hdd_warn("Rx thread high_tput(%d) affinity request failed",
7532 rxthread_high_tput_req);
7533
7534 /* fine-tuning parameters for RX Flows */
7535 if (avg_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
Ravi Joshifed83572016-10-07 16:20:37 -07007536 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
7537 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
7538 next_rx_level = WLAN_SVC_TP_HIGH;
7539 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07007540 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07007541 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08007542 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007543 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007544
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007545 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007546 struct wlan_rx_tp_data rx_tp_data = {0};
7547
Ravi Joshie2331e82015-07-01 18:18:54 -07007548 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Jeff Johnsonb9feee42018-07-08 10:34:48 -07007549 next_rx_level, avg_rx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007550 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007551 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07007552 /* Send throughput indication only if it is enabled.
7553 * Disabling tcp_del_ack will revert the tcp stack behavior
7554 * to default delayed ack. Note that this will disable the
7555 * dynamic delayed ack mechanism across the system
7556 */
Manjunathappa Prakashbfd12762018-04-29 22:44:52 -07007557 if (hdd_ctx->en_tcp_delack_no_lro)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007558 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
7559
Mohit Khanna6272fb682017-04-13 09:34:36 -07007560 if (hdd_ctx->config->enable_tcp_adv_win_scale)
7561 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
7562
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007563 rx_tp_data.level = next_rx_level;
7564 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7565 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
7566 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007567 }
7568
Mohit Khannae71e2262015-11-10 09:37:24 -08007569 /* fine-tuning parameters for TX Flows */
7570 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
7571 hdd_ctx->prev_tx = tx_packets;
7572 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
7573 next_tx_level = WLAN_SVC_TP_HIGH;
7574 else
7575 next_tx_level = WLAN_SVC_TP_LOW;
7576
Prakash Manjunathappae73e3b52018-02-27 18:56:22 -08007577 if ((hdd_ctx->config->enable_tcp_limit_output) &&
7578 (hdd_ctx->cur_tx_level != next_tx_level)) {
Mohit Khannae71e2262015-11-10 09:37:24 -08007579 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
7580 next_tx_level, temp_tx);
7581 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007582 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05307583 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7584 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08007585 &next_tx_level,
7586 sizeof(next_tx_level));
7587 }
7588
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007589 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007590 if (vote_level_change || tx_level_change || rx_level_change) {
7591 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
7592 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
7593 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
7594 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
7595 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
7596 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
7597 hdd_ctx->hdd_txrx_hist_idx++;
7598 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
7599 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07007600
7601 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007602}
7603
7604#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Rajeev Kumarb2b5e692018-08-31 15:12:40 -07007605static void __hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007606{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007607 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307608 bus_bw_work);
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307609 struct hdd_adapter *adapter = NULL, *con_sap_adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307610 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05307611 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
7612 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007613 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307614 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007615 bool connected = false;
7616 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
7617
Dustin Brown35008ba2018-08-23 14:34:21 -07007618 hdd_enter();
7619
Prashanth Bhattaab004382016-10-11 16:08:11 -07007620 if (wlan_hdd_validate_context(hdd_ctx))
7621 return;
7622
Jeff Johnson214671b2017-10-30 19:45:23 -07007623 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08007624 goto restart_timer;
7625
Dustin Brown920397d2017-12-13 16:27:50 -08007626 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05307627 /*
7628 * Validate magic so we don't end up accessing
7629 * an invalid adapter.
7630 */
7631 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
7632 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007633
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007634 if ((adapter->device_mode == QDF_STA_MODE ||
7635 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007636 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
7637 != eConnectionState_Associated) {
7638
7639 continue;
7640 }
7641
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007642 if ((adapter->device_mode == QDF_SAP_MODE ||
7643 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07007644 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007645
7646 continue;
7647 }
7648
7649 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
7650 adapter->prev_tx_packets);
7651 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
7652 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307653
7654 if (adapter->device_mode == QDF_SAP_MODE ||
7655 adapter->device_mode == QDF_P2P_GO_MODE ||
7656 adapter->device_mode == QDF_IBSS_MODE) {
7657
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08007658 ret = cdp_get_intra_bss_fwd_pkts_count(
7659 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007660 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307661 &fwd_tx_packets, &fwd_rx_packets);
7662 if (ret == A_OK) {
7663 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
7664 fwd_tx_packets,
7665 adapter->prev_fwd_tx_packets);
7666 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
7667 fwd_tx_packets,
7668 adapter->prev_fwd_rx_packets);
7669 }
7670 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007671
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307672 if (adapter->device_mode == QDF_SAP_MODE)
7673 con_sap_adapter = adapter;
7674
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007675 total_rx += adapter->stats.rx_packets;
7676 total_tx += adapter->stats.tx_packets;
7677
7678 spin_lock_bh(&hdd_ctx->bus_bw_lock);
7679 adapter->prev_tx_packets = adapter->stats.tx_packets;
7680 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307681 adapter->prev_fwd_tx_packets = fwd_tx_packets;
7682 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007683 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
7684 connected = true;
7685 }
7686
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007687 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007688 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007689 return;
7690 }
7691
Yun Parka29974a2018-04-09 12:05:49 -07007692 /* add intra bss forwarded tx and rx packets */
7693 tx_packets += fwd_tx_packets_diff;
7694 rx_packets += fwd_rx_packets_diff;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007695
Yun Parka29974a2018-04-09 12:05:49 -07007696 if (ucfg_ipa_is_fw_wdi_activated(hdd_ctx->hdd_pdev)) {
7697 ucfg_ipa_uc_stat_query(hdd_ctx->hdd_pdev, &ipa_tx_packets,
7698 &ipa_rx_packets);
7699 tx_packets += (uint64_t)ipa_tx_packets;
7700 rx_packets += (uint64_t)ipa_rx_packets;
7701
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307702 if (con_sap_adapter) {
7703 con_sap_adapter->stats.tx_packets += ipa_tx_packets;
7704 con_sap_adapter->stats.rx_packets += ipa_rx_packets;
7705 }
7706
Yun Parka29974a2018-04-09 12:05:49 -07007707 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, tx_packets, rx_packets);
7708 ucfg_ipa_uc_stat_request(hdd_ctx->hdd_pdev, 2);
7709 }
7710
7711 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007712
Jingxiang Gec64e1932017-08-22 14:38:59 +08007713restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08007714 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08007715 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08007716 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05307717 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08007718 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08007719 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07007720
7721 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007722}
Prashanth Bhattaab004382016-10-11 16:08:11 -07007723
Rajeev Kumarb2b5e692018-08-31 15:12:40 -07007724static void hdd_bus_bw_work_handler(struct work_struct *work)
7725{
7726 cds_ssr_protect(__func__);
7727 __hdd_bus_bw_work_handler(work);
7728 cds_ssr_unprotect(__func__);
7729}
7730
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307731/**
7732 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
7733 * @arg: Argument of timer function
7734 *
7735 * Schedule a workqueue in this function where all the processing is done.
7736 *
7737 * Return: None.
7738 */
7739static void __hdd_bus_bw_cbk(void *arg)
7740{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007741 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307742
7743 if (wlan_hdd_validate_context(hdd_ctx))
7744 return;
7745
7746 schedule_work(&hdd_ctx->bus_bw_work);
7747}
7748
7749/**
7750 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
7751 * @arg: Argument of timer function
7752 *
7753 * Return: None.
7754 */
7755static void hdd_bus_bw_cbk(void *arg)
7756{
7757 cds_ssr_protect(__func__);
7758 __hdd_bus_bw_cbk(arg);
7759 cds_ssr_unprotect(__func__);
7760}
7761
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007762int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007763{
Dustin Brown35008ba2018-08-23 14:34:21 -07007764 hdd_enter();
7765
Prashanth Bhattaab004382016-10-11 16:08:11 -07007766 spin_lock_init(&hdd_ctx->bus_bw_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07007767 INIT_WORK(&hdd_ctx->bus_bw_work, hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08007768 hdd_ctx->bus_bw_timer_running = false;
7769 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07007770 qdf_timer_init(NULL, &hdd_ctx->bus_bw_timer, hdd_bus_bw_cbk,
7771 (void *)hdd_ctx, QDF_TIMER_TYPE_SW);
7772
7773 hdd_exit();
Prashanth Bhattaab004382016-10-11 16:08:11 -07007774
7775 return 0;
7776}
7777
Dustin Brown86d196b2018-08-02 11:51:49 -07007778void hdd_bus_bandwidth_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007779{
Dustin Brown35008ba2018-08-23 14:34:21 -07007780 hdd_enter();
Prashanth Bhattaab004382016-10-11 16:08:11 -07007781
Rajeev Kumarc27efb62018-08-31 14:21:22 -07007782 QDF_BUG(!hdd_ctx->bus_bw_timer_running);
Dustin Brown35008ba2018-08-23 14:34:21 -07007783
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307784 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08007785 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07007786
7787 hdd_exit();
Prashanth Bhattaab004382016-10-11 16:08:11 -07007788}
Lin Baic5c06882017-09-21 13:58:43 +08007789
Dustin Brown35008ba2018-08-23 14:34:21 -07007790#endif /* MSM_PLATFORM */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007791
7792/**
Nirav Shahed34b212016-04-25 10:59:16 +05307793 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
7794 * @hdd_ctx: hdd context
7795 *
7796 * Return: 0 for success or error code
7797 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007798static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307799{
7800 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
7801 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
7802 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007803 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05307804 return -ENOMEM;
7805 }
7806 return 0;
7807}
7808
7809/**
7810 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
7811 * @hdd_ctx: hdd context
7812 *
7813 * Return: none
7814 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007815void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307816{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307817 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
7818 return;
7819
7820 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
7821 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05307822}
7823
Nirav Shahda008342016-05-17 18:50:40 +05307824static uint8_t *convert_level_to_string(uint32_t level)
7825{
7826 switch (level) {
7827 /* initialize the wlan sub system */
7828 case WLAN_SVC_TP_NONE:
7829 return "NONE";
7830 case WLAN_SVC_TP_LOW:
7831 return "LOW";
7832 case WLAN_SVC_TP_MEDIUM:
7833 return "MED";
7834 case WLAN_SVC_TP_HIGH:
7835 return "HIGH";
7836 default:
7837 return "INVAL";
7838 }
7839}
7840
Nirav Shahed34b212016-04-25 10:59:16 +05307841
7842/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007843 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
7844 * @hdd_ctx: hdd context
7845 *
7846 * Return: none
7847 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007848void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007849{
7850 int i;
7851
7852#ifdef MSM_PLATFORM
Nirav Shahe6194ac2018-07-13 11:04:41 +05307853 hdd_nofl_info("BW compute Interval: %dms",
7854 hdd_ctx->config->busBandwidthComputeInterval);
7855 hdd_nofl_info("BW High TH: %d BW Med TH: %d BW Low TH: %d",
7856 hdd_ctx->config->busBandwidthHighThreshold,
7857 hdd_ctx->config->busBandwidthMediumThreshold,
7858 hdd_ctx->config->busBandwidthLowThreshold);
7859 hdd_nofl_info("Enable TCP DEL ACK: %d",
7860 hdd_ctx->en_tcp_delack_no_lro);
7861 hdd_nofl_info("TCP DEL High TH: %d TCP DEL Low TH: %d",
7862 hdd_ctx->config->tcpDelackThresholdHigh,
7863 hdd_ctx->config->tcpDelackThresholdLow);
7864 hdd_nofl_info("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
7865 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007866#endif
7867
Nirav Shahe6194ac2018-07-13 11:04:41 +05307868 hdd_nofl_info("Total entries: %d Current index: %d",
7869 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
Nirav Shahda008342016-05-17 18:50:40 +05307870
Nirav Shahe6194ac2018-07-13 11:04:41 +05307871 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 -08007872
7873 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007874 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007875 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Nirav Shahe6194ac2018-07-13 11:04:41 +05307876 hdd_nofl_info("[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
7877 i, hdd_ctx->hdd_txrx_hist[i].qtime,
7878 hdd_ctx->hdd_txrx_hist[i].interval_rx,
7879 hdd_ctx->hdd_txrx_hist[i].interval_tx,
7880 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007881 hdd_ctx->hdd_txrx_hist[i].
7882 next_vote_level),
Nirav Shahe6194ac2018-07-13 11:04:41 +05307883 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007884 hdd_ctx->hdd_txrx_hist[i].
7885 next_rx_level),
Nirav Shahe6194ac2018-07-13 11:04:41 +05307886 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007887 hdd_ctx->hdd_txrx_hist[i].
7888 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007889 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007890}
7891
7892/**
7893 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
7894 * @hdd_ctx: hdd context
7895 *
7896 * Return: none
7897 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007898void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007899{
7900 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05307901 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
7902 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007903}
7904
Mohit Khannaca4173b2017-09-12 21:52:19 -07007905/* length of the netif queue log needed per adapter */
7906#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
7907
7908/**
7909 *
7910 * hdd_display_netif_queue_history_compact() - display compact netifq history
7911 * @hdd_ctx: hdd context
7912 *
7913 * Return: none
7914 */
7915static void
7916hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
7917{
7918 int adapter_num = 0;
7919 int i;
7920 int bytes_written;
7921 u32 tbytes;
7922 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007923 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08007924 char *comb_log_str;
7925 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007926 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007927
Dustin Brownbee82832018-07-23 10:10:51 -07007928 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * CSR_ROAM_SESSION_MAX) + 1;
jiadbdefb252018-01-03 14:27:06 +08007929 comb_log_str = qdf_mem_malloc(comb_log_str_size);
7930 if (!comb_log_str) {
7931 hdd_err("failed to alloc comb_log_str");
7932 return;
7933 }
7934
Mohit Khannaca4173b2017-09-12 21:52:19 -07007935 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007936
Dustin Brown920397d2017-12-13 16:27:50 -08007937 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007938 curr_time = qdf_system_ticks();
7939 total = curr_time - adapter->start_time;
7940 delta = curr_time - adapter->last_time;
7941
7942 if (adapter->pause_map) {
7943 pause = adapter->total_pause_time + delta;
7944 unpause = adapter->total_unpause_time;
7945 } else {
7946 unpause = adapter->total_unpause_time + delta;
7947 pause = adapter->total_pause_time;
7948 }
7949
7950 tbytes = 0;
7951 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7952 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7953 if (adapter->queue_oper_stats[i].pause_count == 0)
7954 continue;
7955 tbytes +=
7956 snprintf(
7957 &temp_str[tbytes],
7958 (tbytes >= sizeof(temp_str) ?
7959 0 : sizeof(temp_str) - tbytes),
7960 "%d(%d,%d) ",
7961 i,
7962 adapter->queue_oper_stats[i].
7963 pause_count,
7964 adapter->queue_oper_stats[i].
7965 unpause_count);
7966 }
7967 if (tbytes >= sizeof(temp_str))
7968 hdd_warn("log truncated");
7969
7970 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08007971 bytes_written >= comb_log_str_size ? 0 :
7972 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007973 "[%d %d] (%d) %u/%ums %s|",
7974 adapter->session_id, adapter->device_mode,
7975 adapter->pause_map,
7976 qdf_system_ticks_to_msecs(pause),
7977 qdf_system_ticks_to_msecs(total),
7978 temp_str);
7979
Mohit Khannaca4173b2017-09-12 21:52:19 -07007980 adapter_num++;
7981 }
7982
7983 /* using QDF_TRACE to avoid printing function name */
7984 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
7985 "STATS |%s", comb_log_str);
7986
jiadbdefb252018-01-03 14:27:06 +08007987 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007988 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08007989
7990 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007991}
7992
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007993/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007994 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07007995 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007996 *
7997 * Return: none
7998 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007999void
8000wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
8001 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008002{
8003
Jeff Johnson9d295242017-08-29 14:39:48 -07008004 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008005 int i;
Nirav Shahda008342016-05-17 18:50:40 +05308006 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008007
Mohit Khannaca4173b2017-09-12 21:52:19 -07008008 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
8009 hdd_display_netif_queue_history_compact(hdd_ctx);
8010 return;
8011 }
8012
Dustin Brown920397d2017-12-13 16:27:50 -08008013 hdd_for_each_adapter(hdd_ctx, adapter) {
Nirav Shahe6194ac2018-07-13 11:04:41 +05308014 hdd_nofl_info("Netif queue operation statistics:");
8015 hdd_nofl_info("Session_id %d device mode %d",
8016 adapter->session_id, adapter->device_mode);
8017 hdd_nofl_info("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05308018 curr_time = qdf_system_ticks();
8019 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05308020 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05308021 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05308022 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05308023 unpause = adapter->total_unpause_time;
8024 } else {
Nirav Shahda008342016-05-17 18:50:40 +05308025 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05308026 pause = adapter->total_pause_time;
8027 }
Nirav Shahe6194ac2018-07-13 11:04:41 +05308028 hdd_nofl_info("Total: %ums Pause: %ums Unpause: %ums",
8029 qdf_system_ticks_to_msecs(total),
8030 qdf_system_ticks_to_msecs(pause),
8031 qdf_system_ticks_to_msecs(unpause));
8032 hdd_nofl_info("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008033
Nirav Shahda008342016-05-17 18:50:40 +05308034 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
8035 qdf_time_t pause_delta = 0;
8036
8037 if (adapter->pause_map & (1 << i))
8038 pause_delta = delta;
8039
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008040 /* using hdd_log to avoid printing function name */
Nirav Shahe6194ac2018-07-13 11:04:41 +05308041 hdd_nofl_info("%s: %d: %d: %ums",
8042 hdd_reason_type_to_string(i),
8043 adapter->queue_oper_stats[i].pause_count,
8044 adapter->queue_oper_stats[i].
8045 unpause_count,
8046 qdf_system_ticks_to_msecs(
8047 adapter->queue_oper_stats[i].
8048 total_pause_time + pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008049 }
8050
Nirav Shahe6194ac2018-07-13 11:04:41 +05308051 hdd_nofl_info("Netif queue operation history:");
8052 hdd_nofl_info("Total entries: %d current index %d",
8053 WLAN_HDD_MAX_HISTORY_ENTRY,
8054 adapter->history_index);
Nirav Shahda008342016-05-17 18:50:40 +05308055
Nirav Shahe6194ac2018-07-13 11:04:41 +05308056 hdd_nofl_info("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008057
8058 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008059 /* using hdd_log to avoid printing function name */
8060 if (adapter->queue_oper_history[i].time == 0)
8061 continue;
Nirav Shahe6194ac2018-07-13 11:04:41 +05308062 hdd_nofl_info("%d: %u: %s: %s: %x",
8063 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008064 adapter->queue_oper_history[i].time),
Nirav Shahe6194ac2018-07-13 11:04:41 +05308065 hdd_action_type_to_string(
8066 adapter->queue_oper_history[i].
8067 netif_action),
8068 hdd_reason_type_to_string(
8069 adapter->queue_oper_history[i].
8070 netif_reason),
8071 adapter->queue_oper_history[i].pause_map);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008072 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008073 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008074}
8075
8076/**
8077 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
8078 * @hdd_ctx: hdd context
8079 *
8080 * Return: none
8081 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008082void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008083{
Jeff Johnson9d295242017-08-29 14:39:48 -07008084 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008085
Dustin Brown920397d2017-12-13 16:27:50 -08008086 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308087 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008088 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308089 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008090 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05308091 adapter->history_index = 0;
8092 adapter->start_time = adapter->last_time = qdf_system_ticks();
8093 adapter->total_pause_time = 0;
8094 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008095 }
8096}
8097
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008098#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
8099/**
8100 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
8101 * @hdd_ctx: hdd global context
8102 *
8103 * Return: none
8104 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008105static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008106{
8107 uint8_t i;
8108
8109 mutex_init(&hdd_ctx->op_ctx.op_lock);
8110 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
8111 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
8112 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
8113 }
8114}
8115#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008116static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008117{
8118}
8119#endif
8120
Yingying Tang95409972016-10-20 15:16:15 +08008121#ifdef WLAN_FEATURE_WOW_PULSE
8122/**
8123 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008124 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08008125 * @enable: enable or disable this behaviour
8126 *
8127 * Return: int
8128 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008129static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008130{
8131 struct hdd_config *pcfg_ini = phddctx->config;
8132 struct wow_pulse_mode wow_pulse_set_info;
8133 QDF_STATUS status;
8134
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008135 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08008136
8137 if (false == phddctx->config->wow_pulse_support)
8138 return 0;
8139
8140 /* prepare the request to send to SME */
8141 if (enable == true) {
8142 wow_pulse_set_info.wow_pulse_enable = true;
8143 wow_pulse_set_info.wow_pulse_pin =
8144 pcfg_ini->wow_pulse_pin;
8145 wow_pulse_set_info.wow_pulse_interval_low =
8146 pcfg_ini->wow_pulse_interval_low;
8147 wow_pulse_set_info.wow_pulse_interval_high =
8148 pcfg_ini->wow_pulse_interval_high;
8149 } else {
8150 wow_pulse_set_info.wow_pulse_enable = false;
8151 wow_pulse_set_info.wow_pulse_pin = 0;
8152 wow_pulse_set_info.wow_pulse_interval_low = 0;
8153 wow_pulse_set_info.wow_pulse_interval_high = 0;
8154 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008155 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08008156 wow_pulse_set_info.wow_pulse_enable,
8157 wow_pulse_set_info.wow_pulse_pin,
8158 wow_pulse_set_info.wow_pulse_interval_low,
8159 wow_pulse_set_info.wow_pulse_interval_high);
8160
8161 status = sme_set_wow_pulse(&wow_pulse_set_info);
8162 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008163 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08008164 return -EIO;
8165 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008166 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08008167 return 0;
8168}
8169#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008170static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008171{
8172 return 0;
8173}
8174#endif
8175
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008176#ifdef WLAN_FEATURE_FASTPATH
8177/**
8178 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
8179 * @hdd_cfg: hdd config
8180 * @context: lower layer context
8181 *
8182 * Return: none
8183 */
Arun Khandavallifae92942016-08-01 13:31:08 +05308184void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008185 void *context)
8186{
8187 if (hdd_cfg->fastpath_enable)
8188 hif_enable_fastpath(context);
8189}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008190#endif
8191
Yuanyuan Liu13738502016-04-06 17:41:37 -07008192#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008193/**
8194 * hdd_set_thermal_level_cb() - set thermal level callback function
Jeff Johnson0e963082018-07-04 19:39:20 -07008195 * @hdd_handle: opaque handle for the hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008196 * @level: thermal level
8197 *
8198 * Change IPA data path to SW path when the thermal throttle level greater
8199 * than 0, and restore the original data path when throttle level is 0
8200 *
8201 * Return: none
8202 */
Jeff Johnson0e963082018-07-04 19:39:20 -07008203static void hdd_set_thermal_level_cb(hdd_handle_t hdd_handle, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008204{
Jeff Johnson0e963082018-07-04 19:39:20 -07008205 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008206
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008207 /* Change IPA to SW path when throttle level greater than 0 */
8208 if (level > THROTTLE_LEVEL_0)
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308209 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008210 else
8211 /* restore original concurrency mode */
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308212 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, hdd_ctx->mcc_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008213}
8214
8215/**
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308216 * hdd_get_safe_channel() - Get safe channel from current regulatory
8217 * @hdd_ctx: pointer to hdd context
8218 * @adapter: pointer to softap adapter
8219 *
8220 * This function is used to get safe channel from current regulatory valid
8221 * channels to restart SAP if failed to get safe channel from PCL.
8222 *
8223 * Return: Channel number to restart SAP in case of success. In case of any
8224 * failure, the channel number returned is zero.
8225 */
8226static uint8_t
8227hdd_get_safe_channel(struct hdd_context *hdd_ctx,
8228 struct hdd_adapter *adapter)
8229{
8230 struct sir_pcl_list pcl = {0};
8231 uint32_t i, j;
8232 bool found = false;
8233 int ret;
8234
8235 /* Try for safe channel from all valid channel */
8236 pcl.pcl_len = MAX_NUM_CHAN;
8237 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
8238 &pcl.pcl_len);
8239 if (ret) {
8240 hdd_err("error %d in getting valid channel list", ret);
8241 return INVALID_CHANNEL_ID;
8242 }
8243
8244 for (i = 0; i < pcl.pcl_len; i++) {
8245 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
8246 found = false;
8247 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
8248 if (pcl.pcl_list[i] ==
8249 hdd_ctx->unsafe_channel_list[j]) {
8250 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
8251 found = true;
8252 break;
8253 }
8254 }
8255
8256 if (found)
8257 continue;
8258
8259 if ((pcl.pcl_list[i] >=
8260 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
8261 (pcl.pcl_list[i] <=
8262 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
8263 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
8264 return pcl.pcl_list[i];
8265 }
8266 }
8267
8268 return INVALID_CHANNEL_ID;
8269}
8270
8271#else
8272/**
8273 * hdd_set_thermal_level_cb() - set thermal level callback function
8274 * @hdd_handle: opaque handle for the hdd context
8275 * @level: thermal level
8276 *
8277 * Change IPA data path to SW path when the thermal throttle level greater
8278 * than 0, and restore the original data path when throttle level is 0
8279 *
8280 * Return: none
8281 */
8282static void hdd_set_thermal_level_cb(hdd_handle_t hdd_handle, u_int8_t level)
8283{
8284}
8285
8286/**
8287 * hdd_get_safe_channel() - Get safe channel from current regulatory
8288 * @hdd_ctx: pointer to hdd context
8289 * @adapter: pointer to softap adapter
8290 *
8291 * This function is used to get safe channel from current regulatory valid
8292 * channels to restart SAP if failed to get safe channel from PCL.
8293 *
8294 * Return: Channel number to restart SAP in case of success. In case of any
8295 * failure, the channel number returned is zero.
8296 */
8297static uint8_t
8298hdd_get_safe_channel(struct hdd_context *hdd_ctx,
8299 struct hdd_adapter *adapter)
8300{
8301 return 0;
8302}
8303#endif
8304
8305/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308306 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
8307 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05308308 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008309 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308310 * Get a safe channel to restart SAP. PCL already takes into account the
8311 * unsafe channels. So, the PCL is validated with the ACS range to provide
8312 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008313 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308314 * Return: Channel number to restart SAP in case of success. In case of any
8315 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008316 */
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308317static uint8_t
8318hdd_get_safe_channel_from_pcl_and_acs_range(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008319{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308320 struct sir_pcl_list pcl;
8321 QDF_STATUS status;
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308322 uint32_t i;
Jeff Johnson16528362018-06-14 12:34:16 -07008323 mac_handle_t mac_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008324 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008325
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308326 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8327 if (!hdd_ctx) {
8328 hdd_err("invalid HDD context");
8329 return INVALID_CHANNEL_ID;
8330 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008331
Jeff Johnson16528362018-06-14 12:34:16 -07008332 mac_handle = hdd_ctx->mac_handle;
8333 if (!mac_handle) {
8334 hdd_err("invalid MAC handle");
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05308335 return INVALID_CHANNEL_ID;
8336 }
8337
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008338 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
8339 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08008340 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
8341 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308342 if (QDF_IS_STATUS_ERROR(status)) {
8343 hdd_err("Get PCL failed");
8344 return INVALID_CHANNEL_ID;
8345 }
8346
Frank Liudc2cefb2017-06-21 15:38:18 +08008347 /*
8348 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
8349 * channel is unsafe channel, the pcl may be empty, instead of return,
8350 * try to choose a safe channel from acs range.
8351 */
8352 if (!pcl.pcl_len)
8353 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308354
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008355 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07008356 adapter->session.ap.sap_config.acs_cfg.start_ch,
8357 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308358
8359 /* PCL already takes unsafe channel into account */
8360 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008361 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308362 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008363 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308364 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008365 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008366 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308367 return pcl.pcl_list[i];
8368 }
8369 }
8370
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008371 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308372
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308373 return hdd_get_safe_channel(hdd_ctx, adapter);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308374}
8375
8376/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008377 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308378 * @adapter: AP adapter
8379 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08008380 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308381 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008382 * Moves the SAP interface by invoking the function which
8383 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308384 *
8385 * Return: None
8386 */
Min Liu2fef5792018-01-19 17:59:42 +08008387void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
8388 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308389{
Jeff Johnson87251032017-08-29 13:31:11 -07008390 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008391 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07008392 mac_handle_t mac_handle;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308393
8394 if (!adapter) {
8395 hdd_err("invalid adapter");
8396 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008397 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308398
8399 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
8400
Jeff Johnson16528362018-06-14 12:34:16 -07008401 mac_handle = hdd_adapter_get_mac_handle(adapter);
8402 if (!mac_handle) {
8403 hdd_err("invalid MAC handle");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308404 return;
8405 }
8406
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008407 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8408
Jeff Johnson91df29d2017-10-27 19:29:50 -07008409 hdd_ap_ctx->sap_config.channel = channel;
Himanshu Agarwalf5c5b102018-05-22 20:13:57 +05308410 hdd_ap_ctx->sap_config.ch_params.ch_width = CH_WIDTH_MAX;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308411
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008412 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07008413 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308414
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07008415 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07008416 hdd_ap_ctx->sap_config.channel,
8417 hdd_ap_ctx->sap_config.sec_ch,
8418 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308419
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008420 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07008421 adapter->session_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08008422 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008423}
Kapil Gupta8878ad92017-02-13 11:56:04 +05308424
Jeff Johnson9d295242017-08-29 14:39:48 -07008425int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05308426{
8427 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308428 int status;
8429 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308430
8431 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8432
8433 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07008434 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05308435 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07008436 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308437 }
8438 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07008439 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308440 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308441 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07008442 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308443 WLAN_VENDOR_ACS_WAIT_TIME);
8444 if (qdf_status != QDF_STATUS_SUCCESS) {
8445 hdd_err("failed to start external acs timer");
8446 return -ENOSPC;
8447 }
8448 /* Update config to application */
8449 status = hdd_cfg80211_update_acs_config(adapter, reason);
Dustin Brown5e89ef82018-03-14 11:50:23 -07008450 hdd_info("Updated ACS config to nl with reason %d", reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308451
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308452 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308453}
8454
Nirav Shaheb017be2018-02-15 11:20:58 +05308455#if defined(FEATURE_WLAN_CH_AVOID)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308456/**
8457 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
8458 * @hdd_ctx: hdd context pointer
8459 *
8460 * hdd_unsafe_channel_restart_sap check all unsafe channel list
8461 * and if ACS is enabled, driver will ask userspace to restart the
8462 * sap. User space on LTE coex indication restart driver.
8463 *
8464 * Return - none
8465 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008466void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308467{
Dustin Brown920397d2017-12-13 16:27:50 -08008468 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308469 uint32_t i;
8470 bool found = false;
8471 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008472
Dustin Brown920397d2017-12-13 16:27:50 -08008473 hdd_for_each_adapter(hdd_ctxt, adapter) {
8474 if (!(adapter->device_mode == QDF_SAP_MODE &&
8475 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008476 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08008477 adapter->device_mode,
8478 adapter->session.ap.sap_config.
8479 acs_cfg.acs_mode);
8480 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308481 }
8482
8483 found = false;
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008484 /*
8485 * If STA+SAP is doing SCC & g_sta_sap_scc_on_lte_coex_chan
8486 * is set, no need to move SAP.
8487 */
8488 if (policy_mgr_is_sta_sap_scc(hdd_ctxt->hdd_psoc,
8489 adapter->session.ap.operating_channel) &&
8490 hdd_ctxt->config->sta_sap_scc_on_lte_coex_chan)
8491 hdd_debug("SAP is allowed on SCC channel, no need to move SAP");
8492 else {
8493 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
8494 if (adapter->session.ap.operating_channel ==
8495 hdd_ctxt->unsafe_channel_list[i]) {
8496 found = true;
8497 hdd_debug("operating ch:%d is unsafe",
8498 adapter->session.ap.operating_channel);
8499 break;
8500 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308501 }
8502 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308503 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008504 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08008505 adapter->session.ap.operating_channel);
8506 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308507 }
8508
Kapil Gupta8878ad92017-02-13 11:56:04 +05308509 if (hdd_ctxt->config->vendor_acs_support &&
8510 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08008511 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05308512 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08008513 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308514 } else
8515 restart_chan =
8516 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08008517 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308518 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008519 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308520 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008521 /*
8522 * SAP restart due to unsafe channel. While
8523 * restarting the SAP, make sure to clear
8524 * acs_channel, channel to reset to
8525 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308526 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008527 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308528 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008529 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308530 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
8531 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04008532 hdd_debug("driver to start sap: %d",
8533 hdd_ctxt->config->sap_internal_restart);
8534 if (hdd_ctxt->config->sap_internal_restart)
Min Liu2fef5792018-01-19 17:59:42 +08008535 hdd_switch_sap_channel(adapter, restart_chan,
8536 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04008537 else
8538 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308539 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308540 }
8541}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05308542
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008543/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008544 * hdd_init_channel_avoidance() - Initialize channel avoidance
8545 * @hdd_ctx: HDD global context
8546 *
8547 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07008548 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008549 * down to the lower layers. Then subscribe to subsequent channel
8550 * avoidance events.
8551 *
8552 * Return: None
8553 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008554static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008555{
8556 uint16_t unsafe_channel_count;
8557 int index;
8558
Yuanyuan Liu13738502016-04-06 17:41:37 -07008559 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
8560 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008561 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08008562 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008563
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008564 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008565 hdd_ctx->unsafe_channel_count);
8566
Anurag Chouhan6d760662016-02-20 16:05:43 +05308567 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08008568 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008569
8570 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008571 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008572 hdd_ctx->unsafe_channel_list[index]);
8573
8574 }
8575
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008576}
Dustin Brown676a2322017-08-15 13:16:13 -07008577
Jeff Johnson9d295242017-08-29 14:39:48 -07008578static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008579 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008580{
8581 uint8_t restart_chan;
8582
8583 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
8584 if (!restart_chan) {
8585 hdd_alert("fail to restart SAP");
8586 return;
8587 }
8588
8589 /* SAP restart due to unsafe channel. While restarting
8590 * the SAP, make sure to clear acs_channel, channel to
8591 * reset to 0. Otherwise these settings will override
8592 * the ACS while restart.
8593 */
8594 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07008595
8596 hdd_debug("sending coex indication");
8597
8598 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
8599 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08008600 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07008601}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008602
8603int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
8604 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
8605{
8606 uint32_t size;
8607 uint16_t *unsafe_list;
8608 uint16_t chan_count;
8609
8610 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
8611 return -EINVAL;
8612
8613 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
8614 NUM_CHANNELS);
8615 if (chan_count) {
8616 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
8617 unsafe_list = qdf_mem_malloc(size);
8618 if (!unsafe_list) {
8619 hdd_err("No memory for unsafe chan list size%d",
8620 size);
8621 return -ENOMEM;
8622 }
8623 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
8624 } else {
8625 unsafe_list = NULL;
8626 }
8627
8628 *local_unsafe_list = unsafe_list;
8629 *local_unsafe_list_count = chan_count;
8630
8631 return 0;
8632}
8633
8634bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
8635 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
8636{
8637 int i, j;
8638
8639 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
8640 return true;
8641 if (local_unsafe_list_count == 0)
8642 return false;
8643 for (i = 0; i < local_unsafe_list_count; i++) {
8644 for (j = 0; j < local_unsafe_list_count; j++)
8645 if (local_unsafe_list[i] ==
8646 hdd_ctx->unsafe_channel_list[j])
8647 break;
8648 if (j >= local_unsafe_list_count)
8649 break;
8650 }
8651 if (i >= local_unsafe_list_count) {
8652 hdd_info("unsafe chan list same");
8653 return false;
8654 }
8655
8656 return true;
8657}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008658#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008659static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008660{
8661}
Dustin Brown676a2322017-08-15 13:16:13 -07008662
Jeff Johnson9d295242017-08-29 14:39:48 -07008663static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008664 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008665{
8666 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
8667}
Yuanyuan Liu13738502016-04-06 17:41:37 -07008668#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008669
8670/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08008671 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
8672 * user space
8673 * @frame_ind: Management frame data to be informed.
8674 *
8675 * This function is used to indicate management frame to
8676 * user space
8677 *
8678 * Return: None
8679 *
8680 */
8681void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
8682{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008683 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07008684 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008685 int i;
Pragaspathi Thilagaraj28ffc042018-07-18 15:19:36 +05308686 struct ieee80211_mgmt *mgmt =
8687 (struct ieee80211_mgmt *)frame_ind->frameBuf;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008688
Dustin Browne7e71d32018-05-11 16:00:08 -07008689 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
8690 if (wlan_hdd_validate_context(hdd_ctx))
Rajeev Kumard004abc2016-02-17 12:09:56 -08008691 return;
8692
Pragaspathi Thilagaraj28ffc042018-07-18 15:19:36 +05308693 if (frame_ind->frame_len < ieee80211_hdrlen(mgmt->frame_control)) {
8694 hdd_err(" Invalid frame length");
8695 return;
8696 }
8697
Rajeev Kumard004abc2016-02-17 12:09:56 -08008698 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
8699 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
8700 adapter =
8701 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
8702 if (adapter)
8703 break;
8704 }
Wu Gaoa0230a62018-01-04 20:56:57 +08008705 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
8706 hdd_for_each_adapter(hdd_ctx, adapter) {
8707 if ((NULL != adapter) &&
8708 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
8709 __hdd_indicate_mgmt_frame(adapter,
8710 frame_ind->frame_len,
8711 frame_ind->frameBuf,
8712 frame_ind->frameType,
8713 frame_ind->rxChan,
8714 frame_ind->rxRssi);
8715 }
8716 }
8717 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008718 } else {
8719 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
8720 frame_ind->sessionId);
8721 }
8722
8723 if ((NULL != adapter) &&
8724 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
8725 __hdd_indicate_mgmt_frame(adapter,
8726 frame_ind->frame_len,
8727 frame_ind->frameBuf,
8728 frame_ind->frameType,
8729 frame_ind->rxChan,
8730 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008731}
8732
Kapil Gupta8878ad92017-02-13 11:56:04 +05308733void hdd_acs_response_timeout_handler(void *context)
8734{
8735 struct hdd_external_acs_timer_context *timer_context =
8736 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07008737 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008738 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308739 uint8_t reason;
8740
Dustin Brown491d54b2018-03-14 12:39:11 -07008741 hdd_enter();
Kapil Gupta8878ad92017-02-13 11:56:04 +05308742 if (!timer_context) {
8743 hdd_err("invlaid timer context");
8744 return;
8745 }
8746 adapter = timer_context->adapter;
8747 reason = timer_context->reason;
8748
8749
8750 if ((!adapter) ||
8751 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
8752 hdd_err("invalid adapter or adapter has invalid magic");
8753 return;
8754 }
8755 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8756 if (wlan_hdd_validate_context(hdd_ctx))
8757 return;
8758
8759 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
8760 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8761 else
8762 return;
8763
8764 hdd_err("ACS timeout happened for %s reason %d",
8765 adapter->dev->name, reason);
Jeff Johnson16528362018-06-14 12:34:16 -07008766
Kapil Gupta8878ad92017-02-13 11:56:04 +05308767 switch (reason) {
8768 /* SAP init case */
8769 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
8770 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
8771 false);
8772 wlan_hdd_cfg80211_start_acs(adapter);
8773 break;
8774 /* DFS detected on current channel */
8775 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
8776 wlan_sap_update_next_channel(
8777 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
Jeff Johnson16528362018-06-14 12:34:16 -07008778 sme_update_new_channel_event(hdd_ctx->mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07008779 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308780 break;
8781 /* LTE coex event on current channel */
8782 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
8783 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
8784 break;
8785 default:
8786 hdd_info("invalid reason for timer invoke");
8787
8788 }
8789}
8790
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008791/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008792 * hdd_override_ini_config - Override INI config
8793 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008794 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008795 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008796 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008797 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008798 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008799static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008800{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008801
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008802 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
8803 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008804 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008805 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008806 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008807 if (0 == enable_11d || 1 == enable_11d) {
8808 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008809 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008810 }
Leo Chang11545d62016-10-17 14:53:50 -07008811
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308812 if (!ucfg_ipa_is_present()) {
Leo Chang11545d62016-10-17 14:53:50 -07008813 hdd_ctx->config->IpaConfig = 0;
Jingxiang Ge7a040dc2018-02-02 11:07:59 +08008814 hdd_debug("IpaConfig override to %d",
8815 hdd_ctx->config->IpaConfig);
8816 }
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05308817
8818 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
8819 !hdd_ctx->config->enable_bcast_probe_rsp) {
8820 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
8821 hdd_ctx->config->rssi_assoc_reject_enabled,
8822 hdd_ctx->config->enable_bcast_probe_rsp);
8823 hdd_ctx->config->oce_sta_enabled = 0;
8824 }
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +05308825
8826 if (hdd_ctx->config->action_oui_enable && !ucfg_action_oui_enabled()) {
8827 hdd_ctx->config->action_oui_enable = 0;
8828 hdd_err("Ignore ini: %s, since no action_oui component",
8829 CFG_ENABLE_ACTION_OUI);
8830 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008831}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008832
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008833/**
8834 * hdd_set_trace_level_for_each - Set trace level for each INI config
8835 * @hdd_ctx - HDD context
8836 *
8837 * Set trace level for each module based on INI config.
8838 *
8839 * Return: None
8840 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008841static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008842{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308843 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
8844 hdd_ctx->config->qdf_trace_enable_wdi);
8845 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
8846 hdd_ctx->config->qdf_trace_enable_hdd);
8847 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
8848 hdd_ctx->config->qdf_trace_enable_sme);
8849 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
8850 hdd_ctx->config->qdf_trace_enable_pe);
8851 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
8852 hdd_ctx->config->qdf_trace_enable_wma);
8853 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
8854 hdd_ctx->config->qdf_trace_enable_sys);
8855 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
8856 hdd_ctx->config->qdf_trace_enable_qdf);
8857 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
8858 hdd_ctx->config->qdf_trace_enable_sap);
8859 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
8860 hdd_ctx->config->qdf_trace_enable_hdd_sap);
8861 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
8862 hdd_ctx->config->qdf_trace_enable_bmi);
8863 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
8864 hdd_ctx->config->qdf_trace_enable_cfg);
8865 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
8866 hdd_ctx->config->qdf_trace_enable_epping);
8867 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
8868 hdd_ctx->config->qdf_trace_enable_qdf_devices);
8869 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07008870 hdd_ctx->config->qdf_trace_enable_txrx);
8871 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
8872 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308873 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
8874 hdd_ctx->config->qdf_trace_enable_htc);
8875 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
8876 hdd_ctx->config->qdf_trace_enable_hif);
8877 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
8878 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
8879 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
8880 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08008881 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
8882 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07008883 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
8884 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008885 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
8886 hdd_ctx->config->qdf_trace_enable_regulatory);
Naveen Rawat3cb779e2018-02-16 16:36:10 -08008887 hdd_qdf_trace_enable(QDF_MODULE_ID_CP_STATS,
8888 hdd_ctx->config->qdf_trace_enable_cp_stats);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05308889 hdd_qdf_trace_enable(QDF_MODULE_ID_MLME, 0xffff);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008890
Nirav Shah5c083da2018-08-03 13:46:02 +05308891 hdd_cfg_print_global_config(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008892}
8893
8894/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008895 * hdd_context_init() - Initialize HDD context
8896 * @hdd_ctx: HDD context.
8897 *
8898 * Initialize HDD context along with all the feature specific contexts.
8899 *
8900 * return: 0 on success and errno on failure.
8901 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008902static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008903{
8904 int ret;
8905
8906 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
8907 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
8908
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008909 init_completion(&hdd_ctx->mc_sus_event_var);
8910 init_completion(&hdd_ctx->ready_to_suspend);
8911
8912 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308913 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008914 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308915
Dustin Brownbee82832018-07-23 10:10:51 -07008916 qdf_list_create(&hdd_ctx->hdd_adapters, 0);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008917
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008918 ret = hdd_scan_context_init(hdd_ctx);
8919 if (ret)
8920 goto list_destroy;
8921
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008922 hdd_rx_wake_lock_create(hdd_ctx);
8923
8924 ret = hdd_sap_context_init(hdd_ctx);
8925 if (ret)
8926 goto scan_destroy;
8927
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008928 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8929
8930 hdd_init_offloaded_packets_ctx(hdd_ctx);
8931
8932 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8933 hdd_ctx->config);
8934 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08008935 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008936
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05308937 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
8938 "monitor_mode_wakelock");
8939
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008940 return 0;
8941
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008942sap_destroy:
8943 hdd_sap_context_destroy(hdd_ctx);
8944
8945scan_destroy:
8946 hdd_scan_context_destroy(hdd_ctx);
8947 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008948list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008949 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08008950
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008951 return ret;
8952}
8953
8954/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308955 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
8956 * @hdd_ctx: pointer to hdd context
8957 *
8958 * Return: status of initialization
8959 * 0 - success
8960 * negative value - failure
8961 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008962static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308963{
8964 int ret;
8965
8966 if (!hdd_ctx->config->probe_req_ie_whitelist)
8967 return 0;
8968
8969 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
8970 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
8971 hdd_ctx->config->probe_req_ie_whitelist = false;
8972 return -EINVAL;
8973 }
8974
8975 /* parse ini string probe req oui */
8976 ret = hdd_parse_probe_req_ouis(hdd_ctx);
8977 if (ret) {
8978 hdd_err("parsing error: disable ie whitelisting");
8979 hdd_ctx->config->probe_req_ie_whitelist = false;
8980 }
8981
8982 return ret;
8983}
8984
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308985/**
8986 * hdd_iface_change_callback() - Function invoked when stop modules expires
8987 * @priv: pointer to hdd context
8988 *
8989 * This function is invoked when the timer waiting for the interface change
8990 * expires, it shall cut-down the power to wlan and stop all the modules.
8991 *
8992 * Return: void
8993 */
8994static void hdd_iface_change_callback(void *priv)
8995{
8996 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
8997 int ret;
8998 int status = wlan_hdd_validate_context(hdd_ctx);
8999
9000 if (status)
9001 return;
9002
Dustin Brown491d54b2018-03-14 12:39:11 -07009003 hdd_enter();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309004 hdd_debug("Interface change timer expired close the modules!");
9005 ret = hdd_wlan_stop_modules(hdd_ctx, false);
9006 if (ret)
9007 hdd_err("Failed to stop modules");
Dustin Browne74003f2018-03-14 12:51:58 -07009008 hdd_exit();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309009}
9010
Nirav Shaheb017be2018-02-15 11:20:58 +05309011#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9012static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
9013{
9014 wlan_logging_set_log_to_console(hdd_ctx->config->
9015 wlan_logging_to_console);
9016 wlan_logging_set_active(hdd_ctx->config->wlan_logging_enable);
9017}
9018#else
9019static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
9020{ }
9021#endif
9022
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05309023/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009024 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05309025 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009026 *
9027 * Allocate and initialize HDD context. HDD context is allocated as part of
9028 * wiphy allocation and then context is initialized.
9029 *
9030 * Return: HDD context on success and ERR_PTR on failure
9031 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009032static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009033{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309034 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009035 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009036 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009037
Dustin Brown491d54b2018-03-14 12:39:11 -07009038 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009039
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009040 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009041 if (hdd_ctx == NULL) {
9042 ret = -ENOMEM;
9043 goto err_out;
9044 }
9045
Dustin Brown6f427922017-09-19 12:19:00 -07009046 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
9047 hdd_iface_change_callback,
9048 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309049
9050 mutex_init(&hdd_ctx->iface_change_lock);
9051
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009052 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05309053 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009054
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309055 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009056 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009057 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009058 ret = -ENOMEM;
9059 goto err_free_hdd_context;
9060 }
9061
9062 /* Read and parse the qcom_cfg.ini file */
9063 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309064 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309065 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009066 WLAN_INI_FILE);
9067 ret = -EINVAL;
9068 goto err_free_config;
9069 }
9070
Dustin Brown84f46ea2018-02-15 11:57:36 -08009071 status = cfg_parse(WLAN_INI_FILE);
9072 if (QDF_IS_STATUS_ERROR(status))
9073 hdd_err("Failed to parse cfg %s; status:%d\n",
9074 WLAN_INI_FILE, status);
9075
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05309076 ie_whitelist_attrs_init(hdd_ctx);
9077
Dustin Brown7f939932017-05-18 15:02:17 -07009078 hdd_debug("setting timer multiplier: %u",
9079 hdd_ctx->config->timer_multiplier);
9080 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
9081
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009082
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05309083 if (hdd_ctx->config->fhostNSOffload)
9084 hdd_ctx->ns_offload_enable = true;
9085
Abhishek Singh5ea86532016-04-27 14:10:53 +05309086 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
9087
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009088 hdd_override_ini_config(hdd_ctx);
9089
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009090 ret = hdd_context_init(hdd_ctx);
9091
9092 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009093 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009094
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009095 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05309096 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009097
Anurag Chouhan6d760662016-02-20 16:05:43 +05309098 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009099 goto skip_multicast_logging;
9100
9101 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
9102
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07009103 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
9104 if (ret)
9105 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05309106
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009107 ret = hdd_init_netlink_services(hdd_ctx);
9108 if (ret)
9109 goto err_deinit_txrx_histogram;
9110
Nirav Shaheb017be2018-02-15 11:20:58 +05309111 hdd_set_wlan_logging(hdd_ctx);
Nirav Shahed34b212016-04-25 10:59:16 +05309112
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009113skip_multicast_logging:
9114 hdd_set_trace_level_for_each(hdd_ctx);
9115
Rajeev Kumar493a31b2017-09-29 14:01:24 -07009116 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
9117
Dustin Browne74003f2018-03-14 12:51:58 -07009118 hdd_exit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07009119
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009120 return hdd_ctx;
9121
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009122err_deinit_txrx_histogram:
9123 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
9124
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07009125err_deinit_hdd_context:
9126 hdd_context_deinit(hdd_ctx);
9127
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009128err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309129 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009130
9131err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309132 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08009133 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009134
9135err_out:
9136 return ERR_PTR(ret);
9137}
9138
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009139#ifdef WLAN_OPEN_P2P_INTERFACE
9140/**
9141 * hdd_open_p2p_interface - Open P2P interface
9142 * @hdd_ctx: HDD context
9143 * @rtnl_held: True if RTNL lock held
9144 *
9145 * Open P2P interface during probe. This function called to open the P2P
9146 * interface at probe along with STA interface.
9147 *
9148 * Return: 0 on success and errno on failure
9149 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009150static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009151{
Jeff Johnson9d295242017-08-29 14:39:48 -07009152 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009153 uint8_t *p2p_dev_addr;
Wu Gaoe5689792018-07-05 19:20:13 +08009154 bool p2p_dev_addr_admin = false;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009155
Wu Gaoe5689792018-07-05 19:20:13 +08009156 cfg_p2p_get_device_addr_admin(hdd_ctx->hdd_psoc, &p2p_dev_addr_admin);
9157 if (p2p_dev_addr_admin &&
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009158 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009159 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009160 hdd_ctx->config->intfMacAddr[0].bytes,
9161 sizeof(tSirMacAddr));
9162
9163 /*
9164 * Generate the P2P Device Address. This consists of
9165 * the device's primary MAC address with the locally
9166 * administered bit set.
9167 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009168 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009169 } else {
9170 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
9171 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009172 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009173 return -ENOSPC;
9174 }
9175
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009176 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
9177 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009178 }
9179
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009180 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009181 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08009182 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009183
9184 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009185 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009186 return -ENOSPC;
9187 }
9188
9189 return 0;
9190}
9191#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009192static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009193 bool rtnl_held)
9194{
9195 return 0;
9196}
9197#endif
9198
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009199static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08009200{
Jeff Johnson9d295242017-08-29 14:39:48 -07009201 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08009202 int ret = 0;
9203
9204 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
9205 wlan_hdd_get_intf_addr(hdd_ctx),
9206 NET_NAME_UNKNOWN, rtnl_held);
9207 if (adapter == NULL) {
9208 hdd_err("Failed to open 802.11p interface");
9209 ret = -ENOSPC;
9210 }
9211
9212 return ret;
9213}
9214
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009215/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309216 * hdd_start_station_adapter()- Start the Station Adapter
9217 * @adapter: HDD adapter
9218 *
9219 * This function initializes the adapter for the station mode.
9220 *
9221 * Return: 0 on success or errno on failure.
9222 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009223int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309224{
9225 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08009226 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309227
Dustin Brownfdf17c12018-03-14 12:55:34 -07009228 hdd_enter_dev(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08009229 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9230 hdd_err("session is already opened, %d",
9231 adapter->session_id);
9232 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9233 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309234
Krunal Sonib51eec72017-11-20 21:53:01 -08009235 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
9236 if (ret) {
9237 hdd_err("failed to create vdev: %d", ret);
9238 return ret;
9239 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309240 status = hdd_init_station_mode(adapter);
9241
9242 if (QDF_STATUS_SUCCESS != status) {
9243 hdd_err("Error Initializing station mode: %d", status);
9244 return qdf_status_to_os_return(status);
9245 }
9246
Arun Khandavallifae92942016-08-01 13:31:08 +05309247 hdd_register_tx_flow_control(adapter,
9248 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009249 hdd_tx_resume_cb,
9250 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309251
Dustin Browne74003f2018-03-14 12:51:58 -07009252 hdd_exit();
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +05309253
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309254 return 0;
9255}
9256
9257/**
9258 * hdd_start_ap_adapter()- Start AP Adapter
9259 * @adapter: HDD adapter
9260 *
9261 * This function initializes the adapter for the AP mode.
9262 *
9263 * Return: 0 on success errno on failure.
9264 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009265int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309266{
9267 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009268 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08009269 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08009270 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309271
Dustin Brown491d54b2018-03-14 12:39:11 -07009272 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309273
Krunal Sonib51eec72017-11-20 21:53:01 -08009274 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9275 hdd_err("session is already opened, %d",
9276 adapter->session_id);
9277 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9278 }
9279 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009280 * In SSR case no need to create new sap context.
9281 * Otherwise create sap context first and then create
9282 * vdev as while creating the vdev, driver needs to
9283 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08009284 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009285 if (adapter->session.ap.sap_context) {
9286 is_ssr = true;
9287 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08009288 hdd_err("sap creation failed");
9289 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
9290 }
9291
9292 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
9293 adapter->session.ap.sap_context);
9294 if (ret) {
9295 hdd_err("failed to create vdev, status:%d", ret);
9296 hdd_sap_destroy_ctx(adapter);
9297 return ret;
9298 }
Naveen Rawat1af09392018-01-03 17:28:21 -08009299
9300 if (adapter->device_mode == QDF_SAP_MODE)
9301 sme_cli_set_command(adapter->session_id,
9302 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
9303 (bool)(hdd_ctx->config->fine_time_meas_cap &
9304 WMI_FW_AP_RTT_RESPR),
9305 VDEV_CMD);
9306
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009307 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309308
9309 if (QDF_STATUS_SUCCESS != status) {
9310 hdd_err("Error Initializing the AP mode: %d", status);
9311 return qdf_status_to_os_return(status);
9312 }
9313
Arun Khandavallifae92942016-08-01 13:31:08 +05309314 hdd_register_tx_flow_control(adapter,
9315 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009316 hdd_softap_tx_resume_cb,
9317 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309318
Dustin Browne74003f2018-03-14 12:51:58 -07009319 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309320 return 0;
9321}
9322
Sourav Mohapatra57006c72017-11-19 16:15:55 +05309323static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
9324 bool rtnl_held)
9325{
9326 struct hdd_adapter *adapter;
9327
9328 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
9329 hdd_ctx->config->enableConcurrentSTA,
9330 wlan_hdd_get_intf_addr(hdd_ctx),
9331 NET_NAME_UNKNOWN, rtnl_held);
9332
9333 if (!adapter)
9334 return -ENOSPC;
9335
9336 return 0;
9337}
9338
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309339/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009340 * hdd_open_interfaces - Open all required interfaces
9341 * hdd_ctx: HDD context
9342 * rtnl_held: True if RTNL lock is held
9343 *
9344 * Open all the interfaces like STA, P2P and OCB based on the configuration.
9345 *
Jeff Johnson957bc272017-02-02 08:54:48 -08009346 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009347 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009348static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009349{
Jeff Johnson9d295242017-08-29 14:39:48 -07009350 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009351 int ret;
9352
Ravi Joshia307f632017-07-17 23:41:41 -07009353 /* open monitor mode adapter if con_mode is monitor mode */
Lin Bai1c678482017-12-18 18:29:11 +08009354 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
9355 con_mode == QDF_GLOBAL_FTM_MODE) {
9356 uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
9357 QDF_MONITOR_MODE : QDF_FTM_MODE;
9358
9359 adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
9360 wlan_hdd_get_intf_addr(hdd_ctx),
9361 NET_NAME_UNKNOWN, rtnl_held);
Ravi Joshia307f632017-07-17 23:41:41 -07009362 if (!adapter) {
9363 hdd_err("open adapter failed");
9364 return -ENOSPC;
9365 }
Lin Bai1c678482017-12-18 18:29:11 +08009366
Ravi Joshia307f632017-07-17 23:41:41 -07009367 return 0;
9368 }
9369
Jeff Johnson957bc272017-02-02 08:54:48 -08009370 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05309371 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08009372 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009373
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009374 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009375 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08009376 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009377
9378 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08009379 return -ENOSPC;
9380
Sourav Mohapatra57006c72017-11-19 16:15:55 +05309381 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
9382 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
9383 if (ret)
9384 hdd_err("Cannot create concurrent STA interface");
9385 }
9386
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009387 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
9388 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08009389 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009390
9391 /* Open 802.11p Interface */
9392 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08009393 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
9394 if (ret)
9395 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009396 }
9397
Jeff Johnson957bc272017-02-02 08:54:48 -08009398 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009399
Jeff Johnson957bc272017-02-02 08:54:48 -08009400err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009401 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08009402 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009403}
9404
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009405
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309406#ifdef QCA_LL_TX_FLOW_CONTROL_V2
9407/**
9408 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
9409 * @cds_cfg: CDS Configuration
9410 * @hdd_ctx: Pointer to hdd context
9411 *
9412 * Return: none
9413 */
9414static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9415 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009416 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309417{
9418 cds_cfg->tx_flow_stop_queue_th =
9419 hdd_ctx->config->TxFlowStopQueueThreshold;
9420 cds_cfg->tx_flow_start_queue_offset =
9421 hdd_ctx->config->TxFlowStartQueueOffset;
Mohit Khanna70322002018-05-15 19:21:32 -07009422 /* configuration for DP RX Threads */
9423 cds_cfg->enable_dp_rx_threads = hdd_ctx->enable_dp_rx_threads;
9424 cds_cfg->num_dp_rx_threads = hdd_ctx->config->num_dp_rx_threads;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309425}
9426#else
9427static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9428 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009429 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309430{
9431}
9432#endif
9433
9434#ifdef FEATURE_WLAN_RA_FILTERING
9435/**
9436 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
9437 * @cds_cfg: CDS Configuration
9438 * @hdd_ctx: Pointer to hdd context
9439 *
9440 * Return: none
9441 */
Anand Kumar3b92a912016-12-05 12:01:26 +05309442static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009443 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309444{
9445 cds_cfg->ra_ratelimit_interval =
9446 hdd_ctx->config->RArateLimitInterval;
9447 cds_cfg->is_ra_ratelimit_enabled =
9448 hdd_ctx->config->IsRArateLimitEnabled;
9449}
9450#else
Anand Kumar3b92a912016-12-05 12:01:26 +05309451static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009452 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309453{
9454}
9455#endif
9456
9457/**
9458 * hdd_update_cds_config() - API to update cds configuration parameters
9459 * @hdd_ctx: HDD Context
9460 *
9461 * Return: 0 for Success, errno on failure
9462 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009463static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309464{
9465 struct cds_config_info *cds_cfg;
9466
9467 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
9468 if (!cds_cfg) {
9469 hdd_err("failed to allocate cds config");
9470 return -ENOMEM;
9471 }
9472
Srinivas Girigowda35b00312017-06-27 21:52:03 -07009473 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08009474 if (!hdd_ctx->config->nMaxPsPoll ||
9475 !hdd_ctx->config->enablePowersaveOffload) {
9476 cds_cfg->powersave_offload_enabled =
9477 hdd_ctx->config->enablePowersaveOffload;
9478 } else {
9479 if ((hdd_ctx->config->enablePowersaveOffload ==
9480 PS_QPOWER_NODEEPSLEEP) ||
9481 (hdd_ctx->config->enablePowersaveOffload ==
9482 PS_LEGACY_NODEEPSLEEP))
9483 cds_cfg->powersave_offload_enabled =
9484 PS_LEGACY_NODEEPSLEEP;
9485 else
9486 cds_cfg->powersave_offload_enabled =
9487 PS_LEGACY_DEEPSLEEP;
9488 hdd_info("Qpower disabled in cds config, %d",
9489 cds_cfg->powersave_offload_enabled);
9490 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309491 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
9492 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
9493 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
9494 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309495
9496 /*
9497 * Copy the DFS Phyerr Filtering Offload status.
9498 * This parameter reflects the value of the
9499 * dfs_phyerr_filter_offload flag as set in the ini.
9500 */
9501 cds_cfg->dfs_phyerr_filter_offload =
9502 hdd_ctx->config->fDfsPhyerrFilterOffload;
9503 if (hdd_ctx->config->ssdp)
9504 cds_cfg->ssdp = hdd_ctx->config->ssdp;
9505
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05309506 cds_cfg->force_target_assert_enabled =
9507 hdd_ctx->config->crash_inject_enabled;
9508
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309509 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
9510 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
9511
9512 cds_cfg->ap_maxoffload_reorderbuffs =
9513 hdd_ctx->config->apMaxOffloadReorderBuffs;
9514
9515 cds_cfg->ap_disable_intrabss_fwd =
9516 hdd_ctx->config->apDisableIntraBssFwd;
9517
9518 cds_cfg->dfs_pri_multiplier =
9519 hdd_ctx->config->dfsRadarPriMultiplier;
9520 cds_cfg->reorder_offload =
9521 hdd_ctx->config->reorderOffloadSupport;
9522
9523 /* IPA micro controller data path offload resource config item */
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05309524 cds_cfg->uc_offload_enabled = ucfg_ipa_uc_is_enabled();
Yun Parkde380782016-08-17 16:26:54 -07009525 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
9526 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009527 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009528 hdd_ctx->config->IpaUcTxBufCount);
9529 hdd_ctx->config->IpaUcTxBufCount =
9530 rounddown_pow_of_two(
9531 hdd_ctx->config->IpaUcTxBufCount);
9532 if (!hdd_ctx->config->IpaUcTxBufCount) {
9533 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309534 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07009535 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009536 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009537 hdd_ctx->config->IpaUcTxBufCount);
9538 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309539 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
9540 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07009541 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
9542 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009543 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009544 hdd_ctx->config->IpaUcRxIndRingCount);
9545 hdd_ctx->config->IpaUcRxIndRingCount =
9546 rounddown_pow_of_two(
9547 hdd_ctx->config->IpaUcRxIndRingCount);
9548 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
9549 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309550 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07009551 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009552 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009553 hdd_ctx->config->IpaUcRxIndRingCount);
9554 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309555 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07009556 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309557 cds_cfg->uc_tx_partition_base =
9558 hdd_ctx->config->IpaUcTxPartitionBase;
9559 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
9560
9561 cds_cfg->ip_tcp_udp_checksum_offload =
9562 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07009563 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309564 cds_cfg->ce_classify_enabled =
9565 hdd_ctx->config->ce_classify_enabled;
Nachiket Kukadee547a482018-05-22 16:43:30 +05309566 cds_cfg->apf_packet_filter_enable =
9567 hdd_ctx->config->apf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309568 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
9569 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
9570 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07009571 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07009572 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07009573 cds_cfg->max_msdus_per_rxinorderind =
9574 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07009575 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07009576 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Nachiket Kukadee547a482018-05-22 16:43:30 +05309577 cds_cfg->active_uc_apf_mode = hdd_ctx->config->active_uc_apf_mode;
9578 cds_cfg->active_mc_bc_apf_mode = hdd_ctx->config->active_mc_bc_apf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05309579 cds_cfg->auto_power_save_fail_mode =
9580 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309581
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309582 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07009583 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Zhu Jianmina2f8e8d2018-02-11 16:37:10 +08009584 cds_cfg->delay_before_vdev_stop =
9585 hdd_ctx->config->delay_before_vdev_stop;
Rachit Kankane0106e382018-05-16 18:59:28 +05309586 cds_cfg->num_vdevs = hdd_ctx->config->num_vdevs;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309587
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309588 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
9589 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07009590 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309591 cds_init_ini_config(cds_cfg);
9592 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309593
9594exit:
9595 qdf_mem_free(cds_cfg);
9596 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309597}
9598
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009599/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009600 * hdd_update_user_config() - API to update user configuration
9601 * parameters to obj mgr which are used by multiple components
9602 * @hdd_ctx: HDD Context
9603 *
9604 * Return: 0 for Success, errno on failure
9605 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009606static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009607{
9608 struct wlan_objmgr_psoc_user_config *user_config;
Wu Gaoe5689792018-07-05 19:20:13 +08009609 bool skip_dfs_in_p2p_search = false;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009610
9611 user_config = qdf_mem_malloc(sizeof(*user_config));
9612 if (user_config == NULL) {
9613 hdd_alert("Failed to alloc memory for user_config!");
9614 return -ENOMEM;
9615 }
9616
9617 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
9618 user_config->dual_mac_feature_disable =
9619 hdd_ctx->config->dual_mac_feature_disable;
9620 user_config->indoor_channel_support =
9621 hdd_ctx->config->indoor_channel_support;
9622 user_config->is_11d_support_enabled =
9623 hdd_ctx->config->Is11dSupportEnabled;
9624 user_config->is_11h_support_enabled =
9625 hdd_ctx->config->Is11hSupportEnabled;
9626 user_config->optimize_chan_avoid_event =
9627 hdd_ctx->config->goptimize_chan_avoid_event;
Wu Gaoe5689792018-07-05 19:20:13 +08009628 cfg_p2p_get_skip_dfs_channel_p2p_search(hdd_ctx->hdd_psoc,
9629 &skip_dfs_in_p2p_search);
9630 user_config->skip_dfs_chnl_in_p2p_search = skip_dfs_in_p2p_search;
Naveen Rawat222b2e92017-03-16 09:52:21 -07009631 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009632 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
9633
9634 qdf_mem_free(user_config);
9635 return 0;
9636}
9637
9638/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009639 * hdd_init_thermal_info - Initialize thermal level
9640 * @hdd_ctx: HDD context
9641 *
9642 * Initialize thermal level at SME layer and set the thermal level callback
9643 * which would be called when a configured thermal threshold is hit.
9644 *
9645 * Return: 0 on success and errno on failure
9646 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009647static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009648{
9649 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309650 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -07009651 mac_handle_t mac_handle;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009652
9653 thermal_param.smeThermalMgmtEnabled =
9654 hdd_ctx->config->thermalMitigationEnable;
9655 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
9656
Poddar, Siddarth83905022016-04-16 17:56:08 -07009657 thermal_param.sme_throttle_duty_cycle_tbl[0] =
9658 hdd_ctx->config->throttle_dutycycle_level0;
9659 thermal_param.sme_throttle_duty_cycle_tbl[1] =
9660 hdd_ctx->config->throttle_dutycycle_level1;
9661 thermal_param.sme_throttle_duty_cycle_tbl[2] =
9662 hdd_ctx->config->throttle_dutycycle_level2;
9663 thermal_param.sme_throttle_duty_cycle_tbl[3] =
9664 hdd_ctx->config->throttle_dutycycle_level3;
9665
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009666 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
9667 hdd_ctx->config->thermalTempMinLevel0;
9668 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
9669 hdd_ctx->config->thermalTempMaxLevel0;
9670 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
9671 hdd_ctx->config->thermalTempMinLevel1;
9672 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
9673 hdd_ctx->config->thermalTempMaxLevel1;
9674 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
9675 hdd_ctx->config->thermalTempMinLevel2;
9676 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
9677 hdd_ctx->config->thermalTempMaxLevel2;
9678 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
9679 hdd_ctx->config->thermalTempMinLevel3;
9680 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
9681 hdd_ctx->config->thermalTempMaxLevel3;
9682
Jeff Johnson16528362018-06-14 12:34:16 -07009683 mac_handle = hdd_ctx->mac_handle;
9684 status = sme_init_thermal_info(mac_handle, thermal_param);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009685
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309686 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05309687 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009688
Jeff Johnson16528362018-06-14 12:34:16 -07009689 sme_add_set_thermal_level_callback(mac_handle,
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009690 hdd_set_thermal_level_cb);
9691
9692 return 0;
9693
9694}
9695
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009696#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
9697/**
9698 * hdd_hold_rtnl_lock - Hold RTNL lock
9699 *
9700 * Hold RTNL lock
9701 *
9702 * Return: True if held and false otherwise
9703 */
9704static inline bool hdd_hold_rtnl_lock(void)
9705{
9706 rtnl_lock();
9707 return true;
9708}
9709
9710/**
9711 * hdd_release_rtnl_lock - Release RTNL lock
9712 *
9713 * Release RTNL lock
9714 *
9715 * Return: None
9716 */
9717static inline void hdd_release_rtnl_lock(void)
9718{
9719 rtnl_unlock();
9720}
9721#else
9722static inline bool hdd_hold_rtnl_lock(void) { return false; }
9723static inline void hdd_release_rtnl_lock(void) { }
9724#endif
9725
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009726#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009727
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309728/* MAX iwpriv command support */
9729#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309730#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309731#define MAX_PKTLOG_SIZE 16
9732
9733/**
9734 * hdd_pktlog_set_buff_size() - set pktlog buffer size
9735 * @hdd_ctx: hdd context
9736 * @set_value2: pktlog buffer size value
9737 *
9738 *
9739 * Return: 0 for success or error.
9740 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009741static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309742{
9743 struct sir_wifi_start_log start_log = { 0 };
9744 QDF_STATUS status;
9745
9746 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9747 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9748 start_log.ini_triggered = cds_is_packet_log_enabled();
9749 start_log.user_triggered = 1;
9750 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309751 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309752
Jeff Johnson16528362018-06-14 12:34:16 -07009753 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309754 if (!QDF_IS_STATUS_SUCCESS(status)) {
9755 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009756 hdd_exit();
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309757 return -EINVAL;
9758 }
9759
9760 return 0;
9761}
9762
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009763/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309764 * hdd_pktlog_clear_buff() - clear pktlog buffer
9765 * @hdd_ctx: hdd context
9766 *
9767 * Return: 0 for success or error.
9768 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009769static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309770{
9771 struct sir_wifi_start_log start_log;
9772 QDF_STATUS status;
9773
9774 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9775 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9776 start_log.ini_triggered = cds_is_packet_log_enabled();
9777 start_log.user_triggered = 1;
9778 start_log.size = 0;
9779 start_log.is_pktlog_buff_clear = true;
9780
Jeff Johnson16528362018-06-14 12:34:16 -07009781 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309782 if (!QDF_IS_STATUS_SUCCESS(status)) {
9783 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009784 hdd_exit();
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309785 return -EINVAL;
9786 }
9787
9788 return 0;
9789}
9790
9791
9792/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009793 * hdd_process_pktlog_command() - process pktlog command
9794 * @hdd_ctx: hdd context
9795 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309796 * @set_value2: pktlog buffer size value
9797 *
9798 * This function process pktlog command.
9799 * set_value2 only matters when set_value is 3 (set buff size)
9800 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009801 *
9802 * Return: 0 for success or error.
9803 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009804int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309805 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009806{
9807 int ret;
9808 bool enable;
9809 uint8_t user_triggered = 0;
9810
9811 ret = wlan_hdd_validate_context(hdd_ctx);
9812 if (0 != ret)
9813 return ret;
9814
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009815 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009816
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309817 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009818 hdd_err("invalid pktlog value %d", set_value);
9819 return -EINVAL;
9820 }
9821
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309822 if (set_value == PKTLOG_SET_BUFF_SIZE) {
9823 if (set_value2 <= 0) {
9824 hdd_err("invalid pktlog size %d", set_value2);
9825 return -EINVAL;
9826 } else if (set_value2 > MAX_PKTLOG_SIZE) {
9827 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
9828 return -EINVAL;
9829 }
9830 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309831 } else if (set_value == PKTLOG_CLEAR_BUFF) {
9832 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309833 }
9834
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009835 /*
9836 * set_value = 0 then disable packetlog
9837 * set_value = 1 enable packetlog forcefully
9838 * set_vlaue = 2 then disable packetlog if disabled through ini or
9839 * enable packetlog with AUTO type.
9840 */
9841 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
9842 true : false;
9843
9844 if (1 == set_value) {
9845 enable = true;
9846 user_triggered = 1;
9847 }
9848
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309849 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009850}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07009851
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009852/**
9853 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
9854 * @hdd_ctx: HDD context
9855 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309856 * @user_triggered: triggered through iwpriv
9857 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009858 *
9859 * Return: 0 on success; error number otherwise
9860 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009861int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309862 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009863{
9864 struct sir_wifi_start_log start_log;
9865 QDF_STATUS status;
9866
9867 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9868 start_log.verbose_level =
9869 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009870 start_log.ini_triggered = cds_is_packet_log_enabled();
9871 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309872 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309873 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05309874 /*
9875 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
9876 * commands. Host uses this flag to decide whether to send pktlog
9877 * disable command to fw without sending pktlog enable command
9878 * previously. For eg, If vendor sends pktlog disable command without
9879 * sending pktlog enable command, then host discards the packet
9880 * but for iwpriv command, host will send it to fw.
9881 */
9882 start_log.is_iwpriv_command = 1;
Jeff Johnson16528362018-06-14 12:34:16 -07009883 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009884 if (!QDF_IS_STATUS_SUCCESS(status)) {
9885 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009886 hdd_exit();
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009887 return -EINVAL;
9888 }
9889
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309890 if (enable == true)
9891 hdd_ctx->is_pktlog_enabled = 1;
9892 else
9893 hdd_ctx->is_pktlog_enabled = 0;
9894
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009895 return 0;
9896}
9897#endif /* REMOVE_PKT_LOG */
9898
Komal Seelam92fff912016-03-24 11:51:41 +05309899/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009900 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
9901 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05309902 * @dev: Device Pointer
9903 * @num: Number of Valid Mac address
9904 *
9905 * Return: Pointer to MAC address buffer
9906 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009907static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9908 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309909{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009910 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309911}
Komal Seelam92fff912016-03-24 11:51:41 +05309912
9913/**
9914 * hdd_populate_random_mac_addr() - API to populate random mac addresses
9915 * @hdd_ctx: HDD Context
9916 * @num: Number of random mac addresses needed
9917 *
9918 * Generate random addresses using bit manipulation on the base mac address
9919 *
9920 * Return: None
9921 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009922void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05309923{
9924 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
9925 uint32_t iter;
9926 struct hdd_config *ini = hdd_ctx->config;
9927 uint8_t *buf = NULL;
9928 uint8_t macaddr_b3, tmp_br3;
9929 uint8_t *src = ini->intfMacAddr[0].bytes;
9930
9931 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
9932 buf = ini->intfMacAddr[iter].bytes;
9933 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
9934 macaddr_b3 = buf[3];
9935 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
9936 INTF_MACADDR_MASK;
9937 macaddr_b3 += tmp_br3;
9938 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
9939 buf[0] |= 0x02;
9940 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009941 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309942 }
9943}
9944
9945/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009946 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05309947 * @hdd_ctx: HDD Context
9948 *
9949 * API to get mac addresses from platform driver and update the driver
9950 * structures and configure FW with the base mac address.
9951 * Return: int
9952 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009953static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309954{
9955 uint32_t no_of_mac_addr, iter;
9956 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
9957 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
9958 uint8_t *addr, *buf;
9959 struct device *dev = hdd_ctx->parent_dev;
9960 struct hdd_config *ini = hdd_ctx->config;
9961 tSirMacAddr mac_addr;
9962 QDF_STATUS status;
9963
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009964 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05309965
Dustin Brown7e761c72018-07-31 13:50:17 -07009966 if (no_of_mac_addr == 0 || !addr)
Komal Seelam92fff912016-03-24 11:51:41 +05309967 return -EINVAL;
Komal Seelam92fff912016-03-24 11:51:41 +05309968
9969 if (no_of_mac_addr > max_mac_addr)
9970 no_of_mac_addr = max_mac_addr;
9971
9972 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
9973
9974 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
9975 buf = ini->intfMacAddr[iter].bytes;
9976 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009977 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309978 }
9979
9980 status = sme_set_custom_mac_addr(mac_addr);
9981
9982 if (!QDF_IS_STATUS_SUCCESS(status))
9983 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009984
Komal Seelam92fff912016-03-24 11:51:41 +05309985 if (no_of_mac_addr < max_mac_addr)
9986 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
9987 no_of_mac_addr);
9988 return 0;
9989}
9990
9991/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009992 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
9993 * @hdd_ctx: HDD Context
9994 *
9995 * Update MAC address to FW. If MAC address passed by FW is invalid, host
9996 * will generate its own MAC and update it to FW.
9997 *
9998 * Return: 0 for success
9999 * Non-zero error code for failure
10000 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010001static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010002{
10003 tSirMacAddr customMacAddr;
10004 QDF_STATUS status;
10005
10006 qdf_mem_copy(&customMacAddr,
10007 &hdd_ctx->config->intfMacAddr[0].bytes[0],
10008 sizeof(tSirMacAddr));
10009 status = sme_set_custom_mac_addr(customMacAddr);
10010 if (!QDF_IS_STATUS_SUCCESS(status))
10011 return -EAGAIN;
10012 return 0;
10013}
10014
10015/**
Komal Seelam92fff912016-03-24 11:51:41 +053010016 * hdd_initialize_mac_address() - API to get wlan mac addresses
10017 * @hdd_ctx: HDD Context
10018 *
10019 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
10020 * is provisioned with mac addresses, driver uses it, else it will use
10021 * wlan_mac.bin to update HW MAC addresses.
10022 *
10023 * Return: None
10024 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010025static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +053010026{
10027 QDF_STATUS status;
10028 int ret;
10029
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010030 ret = hdd_platform_wlan_mac(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010031 if (!ret) {
10032 hdd_info("using MAC address from platform driver");
Komal Seelam92fff912016-03-24 11:51:41 +053010033 return;
Dustin Brown7e761c72018-07-31 13:50:17 -070010034 }
Komal Seelam92fff912016-03-24 11:51:41 +053010035
10036 status = hdd_update_mac_config(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010037 if (QDF_IS_STATUS_SUCCESS(status)) {
10038 hdd_info("using MAC address from wlan_mac.bin");
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010039 return;
Dustin Brown7e761c72018-07-31 13:50:17 -070010040 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010041
Dustin Brown7e761c72018-07-31 13:50:17 -070010042 hdd_info("using default MAC address");
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010043
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -080010044 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010045 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010046 if (ret)
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -080010047 hdd_err("MAC address out-of-sync, ret:%d", ret);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010048 }
Komal Seelam92fff912016-03-24 11:51:41 +053010049}
10050
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010051static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010052{
10053 int vdev_id = 0;
10054 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
10055 int value = hdd_ctx->config->smart_chainmask_enabled;
10056 int vpdev = PDEV_CMD;
10057 int ret;
10058
Naveen Rawat247a8682017-06-05 15:00:31 -070010059 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010060 if (ret)
10061 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
10062
10063 return ret;
10064}
10065
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010066static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010067{
10068 int vdev_id = 0;
10069 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
10070 int value = hdd_ctx->config->alternative_chainmask_enabled;
10071 int vpdev = PDEV_CMD;
10072 int ret;
10073
Naveen Rawat247a8682017-06-05 15:00:31 -070010074 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010075 if (ret)
10076 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
10077 ret);
10078
10079 return ret;
10080}
10081
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010082static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -070010083{
10084 int vdev_id = 0;
10085 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
10086 int value = hdd_ctx->config->ani_enabled;
10087 int vpdev = PDEV_CMD;
10088 int ret;
10089
Naveen Rawat247a8682017-06-05 15:00:31 -070010090 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -070010091 if (ret)
10092 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
10093
10094 return ret;
10095}
10096
Jeff Johnson89c66ff2016-04-22 15:21:37 -070010097/**
Prashanth Bhatta07998752016-04-28 12:35:33 -070010098 * hdd_pre_enable_configure() - Configurations prior to cds_enable
10099 * @hdd_ctx: HDD context
10100 *
10101 * Pre configurations to be done at lower layer before calling cds enable.
10102 *
10103 * Return: 0 on success and errno on failure.
10104 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010105static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -070010106{
10107 int ret;
10108 QDF_STATUS status;
Leo Changfdb45c32016-10-28 11:09:23 -070010109 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010110
Leo Changfdb45c32016-10-28 11:09:23 -070010111 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Ajit Pal Singh5d269612018-04-19 16:29:12 +053010112 /* Register HL netdev flow control callback */
10113 cdp_hl_fc_register(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010114 /*
10115 * Set 802.11p config
10116 * TODO-OCB: This has been temporarily added here to ensure this
10117 * parameter is set in CSR when we init the channel list. This should
10118 * be removed once the 5.9 GHz channels are added to the regulatory
10119 * domain.
10120 */
10121 hdd_set_dot11p_config(hdd_ctx);
10122
10123 /*
10124 * Note that the cds_pre_enable() sequence triggers the cfg download.
10125 * The cfg download must occur before we update the SME config
10126 * since the SME config operation must access the cfg database
10127 */
10128 status = hdd_set_sme_config(hdd_ctx);
10129
10130 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010131 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010132 ret = qdf_status_to_os_return(status);
10133 goto out;
10134 }
10135
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -070010136 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
10137 if (QDF_STATUS_SUCCESS != status) {
10138 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
10139 ret = qdf_status_to_os_return(status);
10140 goto out;
10141 }
10142
Naveen Rawat247a8682017-06-05 15:00:31 -070010143 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -070010144 hdd_ctx->config->tx_chain_mask_1ss,
10145 PDEV_CMD);
10146 if (0 != ret) {
10147 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
10148 goto out;
10149 }
10150
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010151 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
10152 if (ret)
10153 goto out;
10154
10155 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
10156 if (ret)
10157 goto out;
10158
Jeff Johnson12a744b2017-04-04 08:19:37 -070010159 ret = hdd_set_ani_enabled(hdd_ctx);
10160 if (ret)
10161 goto out;
10162
Naveen Rawat247a8682017-06-05 15:00:31 -070010163 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -080010164 hdd_ctx->config->arp_ac_category,
10165 PDEV_CMD);
10166 if (0 != ret) {
10167 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
10168 hdd_ctx->config->arp_ac_category, ret);
10169 goto out;
10170 }
10171
Prashanth Bhatta07998752016-04-28 12:35:33 -070010172 status = hdd_set_sme_chan_list(hdd_ctx);
10173 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010174 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010175 ret = qdf_status_to_os_return(status);
10176 goto out;
10177 }
10178
10179 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -070010180 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010181 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -070010182 ret = -EINVAL;
10183 goto out;
10184 }
10185
Prashanth Bhatta07998752016-04-28 12:35:33 -070010186 /*
10187 * Set the MAC Address Currently this is used by HAL to add self sta.
10188 * Remove this once self sta is added as part of session open.
10189 */
Jeff Johnson16528362018-06-14 12:34:16 -070010190 status = sme_cfg_set_str(hdd_ctx->mac_handle, WNI_CFG_STA_ID,
Jeff Johnsonbae59f92018-06-01 17:05:43 -070010191 hdd_ctx->config->intfMacAddr[0].bytes,
10192 sizeof(hdd_ctx->config->intfMacAddr[0]));
Prashanth Bhatta07998752016-04-28 12:35:33 -070010193
Jeff Johnsonbae59f92018-06-01 17:05:43 -070010194 if (QDF_IS_STATUS_ERROR(status)) {
10195 hdd_err("Failed to set MAC Address, status %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010196 ret = -EINVAL;
10197 goto out;
10198 }
10199
10200 hdd_init_channel_avoidance(hdd_ctx);
10201
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +053010202 /* update enable sap mandatory chan list */
10203 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
10204 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010205out:
10206 return ret;
10207}
10208
Rachit Kankane026e77a2018-07-31 16:21:09 +053010209#ifdef FEATURE_P2P_LISTEN_OFFLOAD
Prashanth Bhatta07998752016-04-28 12:35:33 -070010210/**
Peng Xu8fdaa492016-06-22 10:20:47 -070010211 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010212 * @context: context registered with sme_register_p2p_lo_event(). HDD
10213 * always registers a hdd context pointer
10214 * @evt:event structure pointer
Peng Xu8fdaa492016-06-22 10:20:47 -070010215 *
10216 * This is the p2p listen offload stop event handler, it sends vendor
10217 * event back to supplicant to notify the stop reason.
10218 *
10219 * Return: None
10220 */
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010221static void wlan_hdd_p2p_lo_event_callback(void *context,
10222 struct sir_p2p_lo_event *evt)
Peng Xu8fdaa492016-06-22 10:20:47 -070010223{
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010224 struct hdd_context *hdd_ctx = context;
Peng Xu8fdaa492016-06-22 10:20:47 -070010225 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -070010226 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -070010227
Dustin Brown491d54b2018-03-14 12:39:11 -070010228 hdd_enter();
Peng Xu8fdaa492016-06-22 10:20:47 -070010229
10230 if (hdd_ctx == NULL) {
10231 hdd_err("Invalid HDD context pointer");
10232 return;
10233 }
10234
Peng Xu5c682812017-08-06 07:39:13 -070010235 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
10236 if (!adapter) {
10237 hdd_err("Cannot find adapter by vdev_id = %d",
10238 evt->vdev_id);
10239 return;
10240 }
10241
Peng Xu8fdaa492016-06-22 10:20:47 -070010242 vendor_event =
10243 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -070010244 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -070010245 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
10246 GFP_KERNEL);
10247
10248 if (!vendor_event) {
10249 hdd_err("cfg80211_vendor_event_alloc failed");
10250 return;
10251 }
10252
10253 if (nla_put_u32(vendor_event,
10254 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
10255 evt->reason_code)) {
10256 hdd_err("nla put failed");
10257 kfree_skb(vendor_event);
10258 return;
10259 }
10260
10261 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -070010262 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
10263 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -070010264}
Rachit Kankane026e77a2018-07-31 16:21:09 +053010265#else
10266static void wlan_hdd_p2p_lo_event_callback(void *context,
10267 struct sir_p2p_lo_event *evt)
10268{
10269}
10270#endif
Peng Xu8fdaa492016-06-22 10:20:47 -070010271
Rachit Kankanef6834c42018-08-02 18:47:50 +053010272#ifdef FEATURE_WLAN_DYNAMIC_CVM
10273static inline int hdd_set_vc_mode_config(struct hdd_context *hdd_ctx)
10274{
10275 return sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap);
10276}
10277#else
10278static inline int hdd_set_vc_mode_config(struct hdd_context *hdd_ctx)
10279{
10280 return QDF_STATUS_SUCCESS;
10281}
10282#endif
10283
Peng Xu8fdaa492016-06-22 10:20:47 -070010284/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010285 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
10286 * @hdd_ctx: HDD context
10287 *
10288 * This function sends the adaptive dwell time config configuration to the
10289 * firmware via WMA
10290 *
10291 * Return: 0 - success, < 0 - failure
10292 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010293static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010294{
10295 QDF_STATUS status;
10296 struct adaptive_dwelltime_params dwelltime_params;
10297
10298 dwelltime_params.is_enabled =
10299 hdd_ctx->config->adaptive_dwell_mode_enabled;
10300 dwelltime_params.dwelltime_mode =
10301 hdd_ctx->config->global_adapt_dwelltime_mode;
10302 dwelltime_params.lpf_weight =
10303 hdd_ctx->config->adapt_dwell_lpf_weight;
10304 dwelltime_params.passive_mon_intval =
10305 hdd_ctx->config->adapt_dwell_passive_mon_intval;
10306 dwelltime_params.wifi_act_threshold =
10307 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
10308
Jeff Johnson16528362018-06-14 12:34:16 -070010309 status = sme_set_adaptive_dwelltime_config(hdd_ctx->mac_handle,
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010310 &dwelltime_params);
10311
10312 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
10313 if (!QDF_IS_STATUS_SUCCESS(status)) {
10314 hdd_err("Failed to send Adaptive Dwelltime configuration!");
10315 return -EAGAIN;
10316 }
10317 return 0;
10318}
10319
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010320int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010321{
10322 QDF_STATUS status;
10323 struct wmi_dbs_scan_sel_params dbs_scan_params;
10324 uint32_t i = 0;
10325 uint8_t count = 0, numentries = 0;
10326 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
10327 * CDS_DBS_SCAN_CLIENTS_MAX];
10328
10329 /* check if DBS is enabled or supported */
Bala Venkateshc8236ca2018-03-09 12:38:29 +053010330 if ((hdd_ctx->config->dual_mac_feature_disable ==
10331 DISABLE_DBS_CXN_AND_SCAN) ||
10332 (hdd_ctx->config->dual_mac_feature_disable ==
10333 ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN))
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010334 return -EINVAL;
10335
10336 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
10337 dbs_scan_config, &numentries,
10338 (CDS_DBS_SCAN_PARAM_PER_CLIENT
10339 * CDS_DBS_SCAN_CLIENTS_MAX));
10340
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010341 if (!numentries) {
Dustin Brown6a8d39b2018-08-14 15:27:26 -070010342 hdd_debug("Do not send scan_selection_config");
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010343 return 0;
10344 }
10345
10346 /* hdd_set_fw_log_params */
10347 dbs_scan_params.num_clients = 0;
10348 while (count < (numentries - 2)) {
10349 dbs_scan_params.module_id[i] = dbs_scan_config[count];
10350 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
10351 dbs_scan_params.num_non_dbs_scans[i] =
10352 dbs_scan_config[count + 2];
10353 dbs_scan_params.num_clients++;
10354 hdd_debug("module:%d NDS:%d NNDS:%d",
10355 dbs_scan_params.module_id[i],
10356 dbs_scan_params.num_dbs_scans[i],
10357 dbs_scan_params.num_non_dbs_scans[i]);
10358 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
10359 i++;
10360 }
10361
10362 dbs_scan_params.pdev_id = 0;
10363
10364 hdd_debug("clients:%d pdev:%d",
10365 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
10366
Jeff Johnson16528362018-06-14 12:34:16 -070010367 status = sme_set_dbs_scan_selection_config(hdd_ctx->mac_handle,
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010368 &dbs_scan_params);
10369 hdd_debug("Sending DBS Scan Selection Configuration to fw");
10370 if (!QDF_IS_STATUS_SUCCESS(status)) {
10371 hdd_err("Failed to send DBS Scan selection configuration!");
10372 return -EAGAIN;
10373 }
10374 return 0;
10375}
10376
Arun Khandavallid4349a92016-07-25 11:10:43 +053010377#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10378/**
10379 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
10380 * @hdd_ctx: HDD context
10381 *
10382 * Set auto shutdown callback to get indications from firmware to indicate
10383 * userspace to shutdown WLAN after a configured amount of inactivity.
10384 *
10385 * Return: 0 on success and errno on failure.
10386 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010387static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010388{
10389 QDF_STATUS status;
10390
10391 if (!hdd_ctx->config->WlanAutoShutdown)
10392 return 0;
10393
Jeff Johnson16528362018-06-14 12:34:16 -070010394 status = sme_set_auto_shutdown_cb(hdd_ctx->mac_handle,
Arun Khandavallid4349a92016-07-25 11:10:43 +053010395 wlan_hdd_auto_shutdown_cb);
10396 if (status != QDF_STATUS_SUCCESS)
10397 hdd_err("Auto shutdown feature could not be enabled: %d",
10398 status);
10399
10400 return qdf_status_to_os_return(status);
10401}
10402#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010403static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010404{
10405 return 0;
10406}
10407#endif
10408
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010409#ifdef MWS_COEX
10410/**
10411 * hdd_set_mws_coex() - Set MWS coex configurations
10412 * @hdd_ctx: HDD context
10413 *
10414 * This function sends MWS-COEX 4G quick FTDM and
10415 * MWS-COEX 5G-NR power limit to FW
10416 *
10417 * Return: 0 on success and errno on failure.
10418 */
10419static int hdd_init_mws_coex(struct hdd_context *hdd_ctx)
10420{
10421 int ret = 0;
10422
10423 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_MWSCOEX_4G_ALLOW_QUICK_FTDM,
10424 hdd_ctx->config->mws_coex_4g_quick_tdm,
10425 PDEV_CMD);
10426 if (ret) {
10427 hdd_warn("Unable to send MWS-COEX 4G quick FTDM policy");
10428 return ret;
10429 }
10430
10431 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_MWSCOEX_SET_5GNR_PWR_LIMIT,
10432 hdd_ctx->config->mws_coex_5g_nr_pwr_limit,
10433 PDEV_CMD);
10434 if (ret) {
10435 hdd_warn("Unable to send MWS-COEX 4G quick FTDM policy");
10436 return ret;
10437 }
10438 return ret;
10439}
10440#else
10441static int hdd_init_mws_coex(struct hdd_context *hdd_ctx)
10442{
10443 return 0;
10444}
10445#endif
10446
Arun Khandavallid4349a92016-07-25 11:10:43 +053010447/**
10448 * hdd_features_init() - Init features
10449 * @hdd_ctx: HDD context
Arun Khandavallid4349a92016-07-25 11:10:43 +053010450 *
10451 * Initialize features and their feature context after WLAN firmware is up.
10452 *
10453 * Return: 0 on success and errno on failure.
10454 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010455static int hdd_features_init(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010456{
10457 tSirTxPowerLimit hddtxlimit;
10458 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +053010459 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010460 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070010461 mac_handle_t mac_handle;
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010462 struct hdd_config *cfg;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010463
Dustin Brown491d54b2018-03-14 12:39:11 -070010464 hdd_enter();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010465
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010466 ret = hdd_init_mws_coex(hdd_ctx);
10467 if (ret)
10468 hdd_warn("Error initializing mws-coex");
10469
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010470 cfg = hdd_ctx->config;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010471 /* FW capabilities received, Set the Dot11 mode */
Jeff Johnson16528362018-06-14 12:34:16 -070010472 mac_handle = hdd_ctx->mac_handle;
10473 sme_setdef_dot11mode(mac_handle);
10474 sme_set_prefer_80MHz_over_160MHz(mac_handle,
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -070010475 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010476 sme_set_etsi13_srd_ch_in_master_mode(mac_handle,
10477 cfg->
10478 etsi13_srd_chan_in_master_mode);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010479
10480 if (hdd_ctx->config->fIsImpsEnabled)
10481 hdd_set_idle_ps_config(hdd_ctx, true);
10482 else
10483 hdd_set_idle_ps_config(hdd_ctx, false);
10484
Poddar, Siddarth37033032017-10-11 15:47:40 +053010485 /* Send Enable/Disable data stall detection cmd to FW */
10486 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
10487 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
10488
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010489 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Jeff Johnson16528362018-06-14 12:34:16 -070010490 sme_set_cts2self_for_p2p_go(mac_handle);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010491
Rachit Kankanef6834c42018-08-02 18:47:50 +053010492 if (hdd_set_vc_mode_config(hdd_ctx))
Nachiket Kukade8983cf62017-10-12 18:14:48 +053010493 hdd_warn("Error in setting Voltage Corner mode config to FW");
10494
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010495 if (hdd_rx_ol_init(hdd_ctx))
10496 hdd_err("Unable to initialize Rx LRO/GRO in fw");
Arun Khandavallid4349a92016-07-25 11:10:43 +053010497
10498 if (hdd_adaptive_dwelltime_init(hdd_ctx))
10499 hdd_err("Unable to send adaptive dwelltime setting to FW");
10500
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010501 if (hdd_dbs_scan_selection_init(hdd_ctx))
10502 hdd_err("Unable to send DBS scan selection setting to FW");
10503
Arun Khandavallid4349a92016-07-25 11:10:43 +053010504 ret = hdd_init_thermal_info(hdd_ctx);
10505 if (ret) {
10506 hdd_err("Error while initializing thermal information");
Dustin Browne7e71d32018-05-11 16:00:08 -070010507 return ret;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010508 }
10509
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010510 /**
10511 * In case of SSR/PDR, if pktlog was enabled manually before
10512 * SSR/PDR, Then enabled it again automatically after Wlan
10513 * device up.
10514 */
10515 if (cds_is_driver_recovering()) {
10516 if (hdd_ctx->is_pktlog_enabled)
10517 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Alok Kumar5a75b9d2018-08-31 10:55:43 +053010518 } else if (cds_is_packet_log_enabled())
10519 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Poddar, Siddarth66a46592017-02-22 11:44:44 +053010520
Arun Khandavallid4349a92016-07-25 11:10:43 +053010521 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
10522 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
Jeff Johnson16528362018-06-14 12:34:16 -070010523 status = sme_txpower_limit(mac_handle, &hddtxlimit);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010524 if (!QDF_IS_STATUS_SUCCESS(status))
10525 hdd_err("Error setting txlimit in sme: %d", status);
10526
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010527 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010528
Arun Khandavallid4349a92016-07-25 11:10:43 +053010529 ret = hdd_register_cb(hdd_ctx);
10530 if (ret) {
10531 hdd_err("Failed to register HDD callbacks!");
Dustin Browne7e71d32018-05-11 16:00:08 -070010532 return ret;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010533 }
10534
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +053010535 if (hdd_ctx->config->goptimize_chan_avoid_event) {
10536 status = sme_enable_disable_chanavoidind_event(
Jeff Johnson16528362018-06-14 12:34:16 -070010537 mac_handle, 0);
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +053010538 if (!QDF_IS_STATUS_SUCCESS(status)) {
10539 hdd_err("Failed to disable Chan Avoidance Indication");
10540 goto deregister_cb;
10541 }
10542 }
Arun Khandavallid4349a92016-07-25 11:10:43 +053010543
Manjeet Singha9cae432017-02-28 11:58:22 +053010544 if (hdd_ctx->config->enable_5g_band_pref) {
10545 band_pref_params.rssi_boost_threshold_5g =
10546 hdd_ctx->config->rssi_boost_threshold_5g;
10547 band_pref_params.rssi_boost_factor_5g =
10548 hdd_ctx->config->rssi_boost_factor_5g;
10549 band_pref_params.max_rssi_boost_5g =
10550 hdd_ctx->config->max_rssi_boost_5g;
10551 band_pref_params.rssi_penalize_threshold_5g =
10552 hdd_ctx->config->rssi_penalize_threshold_5g;
10553 band_pref_params.rssi_penalize_factor_5g =
10554 hdd_ctx->config->rssi_penalize_factor_5g;
10555 band_pref_params.max_rssi_penalize_5g =
10556 hdd_ctx->config->max_rssi_penalize_5g;
Jeff Johnson16528362018-06-14 12:34:16 -070010557 sme_set_5g_band_pref(mac_handle, &band_pref_params);
Manjeet Singha9cae432017-02-28 11:58:22 +053010558 }
10559
Arun Khandavallid4349a92016-07-25 11:10:43 +053010560 /* register P2P Listen Offload event callback */
10561 if (wma_is_p2p_lo_capable())
Jeff Johnson16528362018-06-14 12:34:16 -070010562 sme_register_p2p_lo_event(mac_handle, hdd_ctx,
10563 wlan_hdd_p2p_lo_event_callback);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010564
10565 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
10566
10567 if (ret)
10568 goto deregister_cb;
10569
Dustin Brown11638b72018-01-25 17:37:25 +053010570 wlan_hdd_init_chan_info(hdd_ctx);
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010571 wlan_hdd_twt_init(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010572
Dustin Browne74003f2018-03-14 12:51:58 -070010573 hdd_exit();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010574 return 0;
10575
10576deregister_cb:
10577 hdd_deregister_cb(hdd_ctx);
Dustin Browne7e71d32018-05-11 16:00:08 -070010578
Arun Khandavallid4349a92016-07-25 11:10:43 +053010579 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010580}
10581
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010582/**
10583 * hdd_features_deinit() - Deinit features
10584 * @hdd_ctx: HDD context
10585 *
10586 * De-Initialize features and their feature context.
10587 *
10588 * Return: none.
10589 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010590static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010591{
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010592 wlan_hdd_twt_deinit(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010593 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010594 wlan_hdd_tsf_deinit(hdd_ctx);
10595}
10596
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010597/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010598 * hdd_register_bcn_cb() - register scan beacon callback
10599 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010600 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010601 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010602 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010603static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010604{
10605 QDF_STATUS status;
10606
10607 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
10608 wlan_cfg80211_inform_bss_frame,
10609 SCAN_CB_TYPE_INFORM_BCN);
10610 if (!QDF_IS_STATUS_SUCCESS(status)) {
10611 hdd_err("failed with status code %08d [x%08x]",
10612 status, status);
10613 return status;
10614 }
10615
10616 return QDF_STATUS_SUCCESS;
10617}
Arun Khandavallid4349a92016-07-25 11:10:43 +053010618
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010619/**
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070010620 * hdd_v2_flow_pool_map() - Flow pool create callback when vdev is active
10621 * @vdev_id: vdev_id, corresponds to flow_pool
10622 *
10623 * Return: none.
10624 */
10625static void hdd_v2_flow_pool_map(int vdev_id)
10626{
10627 QDF_STATUS status;
10628
10629 status = cdp_flow_pool_map(cds_get_context(QDF_MODULE_ID_SOC),
10630 cds_get_context(QDF_MODULE_ID_TXRX),
10631 vdev_id);
10632 /*
10633 * For Adrastea flow control v2 is based on FW MAP events,
10634 * so this above callback is not implemented.
10635 * Hence this is not actual failure. Dont return failure
10636 */
10637 if ((status != QDF_STATUS_SUCCESS) &&
10638 (status != QDF_STATUS_E_INVAL)) {
10639 hdd_err("vdev_id: %d, failed to create flow pool status %d",
10640 vdev_id, status);
10641 }
10642}
10643
10644/**
10645 * hdd_v2_flow_pool_unmap() - Flow pool create callback when vdev is not active
10646 * @vdev_id: vdev_id, corresponds to flow_pool
10647 *
10648 * Return: none.
10649 */
10650static void hdd_v2_flow_pool_unmap(int vdev_id)
10651{
10652 cdp_flow_pool_unmap(cds_get_context(QDF_MODULE_ID_SOC),
10653 cds_get_context(QDF_MODULE_ID_TXRX), vdev_id);
10654}
10655
10656/**
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010657 * hdd_action_oui_config() - Configure action_oui strings
10658 * @hdd_ctx: pointer to hdd context
10659 *
10660 * This is a HDD wrapper function which invokes ucfg api
10661 * of action_oui component to parse action oui strings.
10662 *
10663 * Return: None
10664 */
10665static void hdd_action_oui_config(struct hdd_context *hdd_ctx)
10666{
10667 QDF_STATUS status;
10668 uint32_t id;
10669 uint8_t *str;
10670
10671 if (!hdd_ctx->config->action_oui_enable)
10672 return;
10673
10674 for (id = 0; id < ACTION_OUI_MAXIMUM_ID; id++) {
10675 str = hdd_ctx->config->action_oui_str[id];
10676 if (!qdf_str_len(str))
10677 continue;
10678
10679 status = ucfg_action_oui_parse(hdd_ctx->hdd_psoc, str, id);
10680 if (!QDF_IS_STATUS_SUCCESS(status))
10681 hdd_err("Failed to parse action_oui str: %u", id);
10682 }
10683}
10684
10685/**
10686 * hdd_action_oui_send() - Send action_oui extensions to firmware
10687 * @hdd_ctx: pointer to hdd context
10688 *
10689 * This is a HDD wrapper function which invokes ucfg api
10690 * of action_oui component to send action oui extensions to firmware.
10691 *
10692 * Return: None
10693 */
10694static void hdd_action_oui_send(struct hdd_context *hdd_ctx)
10695{
10696 QDF_STATUS status;
10697
10698 if (!hdd_ctx->config->action_oui_enable)
10699 return;
10700
10701 status = ucfg_action_oui_send(hdd_ctx->hdd_psoc);
10702 if (!QDF_IS_STATUS_SUCCESS(status))
10703 hdd_err("Failed to send one or all action_ouis");
10704}
10705
10706/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010707 * hdd_configure_cds() - Configure cds modules
10708 * @hdd_ctx: HDD context
10709 * @adapter: Primary adapter context
10710 *
10711 * Enable Cds modules after WLAN firmware is up.
10712 *
10713 * Return: 0 on success and errno on failure.
10714 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010715int hdd_configure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010716{
10717 int ret;
10718 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010719 int set_value;
Jeff Johnson16528362018-06-14 12:34:16 -070010720 mac_handle_t mac_handle;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010721 uint32_t num_abg_tx_chains = 0;
10722 uint32_t num_11b_tx_chains = 0;
10723 uint32_t num_11ag_tx_chains = 0;
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010724 struct policy_mgr_dp_cbacks dp_cbs = {0};
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010725
Jeff Johnson16528362018-06-14 12:34:16 -070010726 mac_handle = hdd_ctx->mac_handle;
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010727
10728 hdd_action_oui_send(hdd_ctx);
10729
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010730 if (hdd_ctx->config->is_force_1x1)
10731 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
10732 1, PDEV_CMD);
10733 /* set chip power save failure detected callback */
Jeff Johnson16528362018-06-14 12:34:16 -070010734 sme_set_chip_pwr_save_fail_cb(mac_handle,
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010735 hdd_chip_pwr_save_fail_detected_cb);
10736
10737 if (hdd_ctx->config->max_mpdus_inampdu) {
10738 set_value = hdd_ctx->config->max_mpdus_inampdu;
10739 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
10740 set_value, PDEV_CMD);
10741 }
10742
10743 if (hdd_ctx->config->enable_rts_sifsbursting) {
10744 set_value = hdd_ctx->config->enable_rts_sifsbursting;
10745 sme_cli_set_command(0,
10746 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
10747 set_value, PDEV_CMD);
10748 }
10749
10750 if (hdd_ctx->config->sap_get_peer_info) {
10751 set_value = hdd_ctx->config->sap_get_peer_info;
10752 sme_cli_set_command(0,
10753 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
10754 set_value, PDEV_CMD);
10755 }
10756
10757 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
10758 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
10759 if (!hdd_ctx->config->enable2x2) {
10760 if (num_11b_tx_chains > 1)
10761 num_11b_tx_chains = 1;
10762 if (num_11ag_tx_chains > 1)
10763 num_11ag_tx_chains = 1;
10764 }
10765 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
10766 num_11b_tx_chains);
10767 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
10768 num_11ag_tx_chains);
10769 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
10770 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +053010771
10772 ret = hdd_pre_enable_configure(hdd_ctx);
10773 if (ret) {
10774 hdd_err("Failed to pre-configure cds");
10775 goto out;
10776 }
10777
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010778 /* Always get latest IPA resources allocated from cds_open and configure
10779 * IPA module before configuring them to FW. Sequence required as crash
10780 * observed otherwise.
10781 */
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010782 if (ucfg_ipa_uc_ol_init(hdd_ctx->hdd_pdev,
10783 cds_get_context(QDF_MODULE_ID_QDF_DEVICE))) {
Manikandan Mohan2e803a02017-02-14 14:57:53 -080010784 hdd_err("Failed to setup pipes");
10785 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010786 }
10787
Arun Khandavallifae92942016-08-01 13:31:08 +053010788 /*
10789 * Start CDS which starts up the SME/MAC/HAL modules and everything
10790 * else
10791 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -070010792 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010793
10794 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010795 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053010796 goto out;
10797 }
10798
10799 status = hdd_post_cds_enable_config(hdd_ctx);
10800 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010801 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010802 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010803 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010804 status = hdd_register_bcn_cb(hdd_ctx);
10805 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +080010806 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010807 goto cds_disable;
10808 }
Arun Khandavallifae92942016-08-01 13:31:08 +053010809
Dustin Browne7e71d32018-05-11 16:00:08 -070010810 ret = hdd_features_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010811 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010812 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010813
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010814 if (hdd_ctx->ol_enable)
10815 dp_cbs.hdd_disable_rx_ol_in_concurrency =
10816 hdd_disable_rx_ol_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -070010817 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
jiadbb47e132018-03-30 16:28:30 +080010818 dp_cbs.hdd_ipa_set_mcc_mode_cb = hdd_ipa_set_mcc_mode;
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070010819 dp_cbs.hdd_v2_flow_pool_map = hdd_v2_flow_pool_map;
10820 dp_cbs.hdd_v2_flow_pool_unmap = hdd_v2_flow_pool_unmap;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010821 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
10822 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -070010823 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010824 goto cds_disable;
10825 }
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010826 status = policy_mgr_register_mode_change_cb(hdd_ctx->hdd_psoc,
10827 wlan_hdd_send_mode_change_event);
10828 if (!QDF_IS_STATUS_SUCCESS(status)) {
10829 hdd_debug("Failed to register mode change cb with Policy Manager");
10830 goto cds_disable;
10831 }
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010832
Jeff Johnson8bb61112018-03-31 13:33:54 -070010833 if (hdd_green_ap_enable_egap(hdd_ctx))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +053010834 hdd_debug("enhance green ap is not enabled");
10835
Nachiket Kukadedd302662017-07-13 17:31:44 +053010836 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
10837 hdd_debug("Failed to set wow pulse");
10838
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053010839 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
10840 hdd_ctx->config->gcmp_enabled, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053010841 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
10842 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
10843
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053010844
10845 if (hdd_ctx->config->enable_phy_reg_retention)
10846 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
10847 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
10848
Arun Khandavallifae92942016-08-01 13:31:08 +053010849 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010850
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010851cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010852 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010853
Arun Khandavallifae92942016-08-01 13:31:08 +053010854out:
10855 return -EINVAL;
10856}
10857
10858/**
10859 * hdd_deconfigure_cds() -De-Configure cds
10860 * @hdd_ctx: HDD context
10861 *
10862 * Deconfigure Cds modules before WLAN firmware is down.
10863 *
10864 * Return: 0 on success and errno on failure.
10865 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010866static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010867{
10868 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070010869 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053010870
Dustin Brown491d54b2018-03-14 12:39:11 -070010871 hdd_enter();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010872
10873 /* De-init features */
10874 hdd_features_deinit(hdd_ctx);
10875
Arun Khandavallifae92942016-08-01 13:31:08 +053010876 /* De-register the SME callbacks */
10877 hdd_deregister_cb(hdd_ctx);
10878
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010879 qdf_status = policy_mgr_deregister_mode_change_cb(hdd_ctx->hdd_psoc);
10880 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10881 hdd_debug("Failed to deregister mode change cb with Policy Manager");
10882 }
10883
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010884 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010885 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10886 hdd_err("Failed to Disable the CDS Modules! :%d",
10887 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070010888 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010889 }
10890
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010891 if (ucfg_ipa_uc_ol_deinit(hdd_ctx->hdd_pdev) != QDF_STATUS_SUCCESS) {
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053010892 hdd_err("Failed to disconnect pipes");
10893 ret = -EINVAL;
10894 }
10895
Dustin Browne74003f2018-03-14 12:51:58 -070010896 hdd_exit();
Houston Hoffman6640cf32016-10-10 16:44:29 -070010897 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010898}
10899
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010900#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
10901static void hdd_deregister_policy_manager_callback(
10902 struct wlan_objmgr_psoc *psoc)
10903{
10904 if (QDF_STATUS_SUCCESS !=
10905 policy_mgr_deregister_hdd_cb(psoc)) {
10906 hdd_err("HDD callback deregister with policy manager failed");
10907 }
10908}
10909#else
10910static void hdd_deregister_policy_manager_callback(
10911 struct wlan_objmgr_psoc *psoc)
10912{
10913}
10914#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010915
10916/**
10917 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
10918 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010919 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +053010920 *
10921 * This function maintains the driver state machine it will be invoked from
10922 * exit, shutdown and con_mode change handler. Depending on the driver state
10923 * shall perform the stopping/closing of the modules.
10924 *
10925 * Return: 0 for success; non-zero for failure
10926 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010927int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053010928{
10929 void *hif_ctx;
10930 qdf_device_t qdf_ctx;
10931 QDF_STATUS qdf_status;
Dustin Brown4bc0a622017-12-06 15:56:50 -080010932 bool is_recovery_stop = cds_is_driver_recovering();
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053010933 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -070010934 int active_threads;
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053010935 int debugfs_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010936 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053010937
Dustin Brown491d54b2018-03-14 12:39:11 -070010938 hdd_enter();
Arun Khandavallifae92942016-08-01 13:31:08 +053010939
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010940 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
10941
Arun Khandavallifae92942016-08-01 13:31:08 +053010942 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
10943 if (!qdf_ctx) {
10944 hdd_err("QDF device context NULL");
10945 return -EINVAL;
10946 }
10947
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010948 mutex_lock(&hdd_ctx->iface_change_lock);
10949 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010950 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053010951
Dustin Brown70111822017-03-30 15:31:40 -070010952 active_threads = cds_return_external_threads_count();
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053010953 debugfs_threads = hdd_return_debugfs_threads_count();
Dustin Brown70111822017-03-30 15:31:40 -070010954
Rajeev Kumar Sirasanagandla197d4172018-02-15 19:03:29 +053010955 if (active_threads > 0 || debugfs_threads > 0 ||
10956 hdd_ctx->is_wiphy_suspended) {
10957 hdd_warn("External threads %d, Debugfs threads %d, wiphy suspend %d",
10958 active_threads, debugfs_threads,
10959 hdd_ctx->is_wiphy_suspended);
10960
10961 if (active_threads)
10962 cds_print_external_threads();
Dustin Brown70111822017-03-30 15:31:40 -070010963
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053010964 if (IS_IDLE_STOP && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070010965 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -070010966 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10967 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010968 hdd_prevent_suspend_timeout(
10969 hdd_ctx->config->iface_change_wait_time,
10970 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010971 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010972 cds_set_module_stop_in_progress(false);
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070010973
Dustin Brown70111822017-03-30 15:31:40 -070010974 return 0;
10975 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070010976 }
10977
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080010978 /* free user wowl patterns */
10979 hdd_free_user_wowl_ptrns();
10980
Arun Khandavallifae92942016-08-01 13:31:08 +053010981 switch (hdd_ctx->driver_status) {
10982 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070010983 hdd_debug("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010984 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010985 case DRIVER_MODULES_CLOSED:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070010986 hdd_debug("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010987 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010988 case DRIVER_MODULES_ENABLED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010989 hdd_info("Wlan transitioning (OPENED <- ENABLED)");
10990
Komal Seelamf2136bb2016-09-28 18:30:44 +053010991 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053010992 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010993 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053010994 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010995 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010996 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010997 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080010998
Arun Khandavallifae92942016-08-01 13:31:08 +053010999 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -080011000 hdd_info("Wlan transitioned (now OPENED)");
11001
11002 /* fall through */
Arun Khandavallifae92942016-08-01 13:31:08 +053011003 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -080011004 hdd_info("Wlan transitioning (CLOSED <- OPENED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053011005 break;
11006 default:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011007 QDF_DEBUG_PANIC("Unknown driver state:%d",
Arun Khandavallifae92942016-08-01 13:31:08 +053011008 hdd_ctx->driver_status);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011009 ret = -EINVAL;
11010 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053011011 }
11012
Amar Singhal18081642018-01-26 16:04:13 -080011013 hdd_sysfs_destroy_version_interface();
Dustin Brown550f6d22017-12-14 15:44:01 -080011014 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080011015
Rajeev Kumarbe021242017-02-16 16:12:23 -080011016 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053011017 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11018 hdd_err("Failed to process post CDS disable Modules! :%d",
11019 qdf_status);
11020 ret = -EINVAL;
11021 QDF_ASSERT(0);
11022 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011023
psimhadeea0a12017-12-18 14:50:02 -080011024 hdd_runtime_suspend_context_deinit(hdd_ctx);
11025
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011026 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
11027 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11028 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
11029 ret = -EINVAL;
11030 QDF_ASSERT(0);
11031 }
11032
Jeff Johnsone4b14592017-09-13 14:23:33 -070011033 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053011034 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011035 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053011036 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011037 QDF_ASSERT(0);
11038 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -070011039
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053011040 hdd_component_psoc_close(hdd_ctx->hdd_psoc);
Amar Singhal410675c2018-01-10 12:14:21 -080011041 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Liangwei Dong50a64a72018-01-11 01:17:00 -050011042 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
11043 if (ret) {
11044 hdd_err("Failed to destroy pdev; errno:%d", ret);
11045 QDF_ASSERT(0);
11046 }
11047
11048 /*
11049 * Reset total mac phy during module stop such that during
11050 * next module start same psoc is used to populate new service
11051 * ready data
11052 */
Arunk Khandavallia6305a32018-01-25 11:19:18 +053011053 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
11054 if (tgt_hdl)
11055 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
11056
Liangwei Dong50a64a72018-01-11 01:17:00 -050011057
Arun Khandavallifae92942016-08-01 13:31:08 +053011058 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
11059 if (!hif_ctx) {
11060 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011061 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011062 }
11063
Arunk Khandavalli4b404332017-09-26 12:46:00 +053011064 if (hdd_ctx->target_hw_name) {
11065 qdf_mem_free(hdd_ctx->target_hw_name);
11066 hdd_ctx->target_hw_name = NULL;
11067 }
11068
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053011069 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053011070
11071 ol_cds_free();
11072
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053011073 if (IS_IDLE_STOP && cds_is_target_ready()) {
Arun Khandavallifae92942016-08-01 13:31:08 +053011074 ret = pld_power_off(qdf_ctx->dev);
11075 if (ret)
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011076 hdd_err("Failed to power down device; errno:%d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053011077 }
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011078
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011079 /* Free the cache channels of the command SET_DISABLE_CHANNEL_LIST */
11080 wlan_hdd_free_cache_channels(hdd_ctx);
Arunk Khandavalli847969d2017-09-25 15:15:36 +053011081
Dustin Brown29533f22018-07-24 13:11:56 -070011082 hdd_check_for_leaks(hdd_ctx, is_recovery_stop);
Dustin Brown26b3d042017-12-21 11:13:27 -080011083 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080011084
Arunk Khandavalli847969d2017-09-25 15:15:36 +053011085 /* Once the firmware sequence is completed reset this flag */
11086 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053011087 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080011088 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053011089
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011090done:
11091 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011092 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011093 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4bc0a622017-12-06 15:56:50 -080011094
Dustin Browne74003f2018-03-14 12:51:58 -070011095 hdd_exit();
Arun Khandavallifae92942016-08-01 13:31:08 +053011096
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011097 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053011098}
11099
Arun Khandavallifae92942016-08-01 13:31:08 +053011100
Wen Gong3f003382018-05-14 14:26:37 +080011101#ifdef WLAN_FEATURE_MEMDUMP_ENABLE
Arun Khandavallifae92942016-08-01 13:31:08 +053011102/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011103 * hdd_state_info_dump() - prints state information of hdd layer
11104 * @buf: buffer pointer
11105 * @size: size of buffer to be filled
11106 *
11107 * This function is used to dump state information of hdd layer
11108 *
11109 * Return: None
11110 */
11111static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
11112{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011113 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070011114 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070011115 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011116 uint16_t len = 0;
11117 char *buf = *buf_ptr;
11118
11119 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11120 if (!hdd_ctx) {
11121 hdd_err("Failed to get hdd context ");
11122 return;
11123 }
11124
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011125 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011126
11127 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070011128 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011129 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080011130 "\n is_scheduler_suspended %d",
11131 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011132
Dustin Brown920397d2017-12-13 16:27:50 -080011133 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011134 if (adapter->dev)
11135 len += scnprintf(buf + len, *size - len,
11136 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080011137 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011138 "\n device_mode: %d", adapter->device_mode);
11139 switch (adapter->device_mode) {
11140 case QDF_STA_MODE:
11141 case QDF_P2P_CLIENT_MODE:
11142 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11143 len += scnprintf(buf + len, *size - len,
11144 "\n connState: %d",
11145 hdd_sta_ctx->conn_info.connState);
11146 break;
11147
11148 default:
11149 break;
11150 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011151 }
11152
11153 *size -= len;
11154 *buf_ptr += len;
11155}
11156
11157/**
11158 * hdd_register_debug_callback() - registration function for hdd layer
11159 * to print hdd state information
11160 *
11161 * Return: None
11162 */
11163static void hdd_register_debug_callback(void)
11164{
11165 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
11166}
Wen Gong3f003382018-05-14 14:26:37 +080011167#else /* WLAN_FEATURE_MEMDUMP_ENABLE */
Wen Gongaa6d55d2018-04-26 16:33:21 +080011168static void hdd_register_debug_callback(void)
11169{
11170}
Wen Gong3f003382018-05-14 14:26:37 +080011171#endif /* WLAN_FEATURE_MEMDUMP_ENABLE */
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011172
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053011173/*
11174 * wlan_init_bug_report_lock() - Initialize bug report lock
11175 *
11176 * This function is used to create bug report lock
11177 *
11178 * Return: None
11179 */
11180static void wlan_init_bug_report_lock(void)
11181{
Jeff Johnson2b6982c2018-05-29 14:56:11 -070011182 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053011183
11184 p_cds_context = cds_get_global_context();
11185 if (!p_cds_context) {
11186 hdd_err("cds context is NULL");
11187 return;
11188 }
11189
11190 qdf_spinlock_create(&p_cds_context->bug_report_lock);
11191}
11192
Nirav Shahd21a2e32018-04-20 16:34:43 +053011193#ifdef CONFIG_DP_TRACE
Mohit Khannaf8f96822017-05-17 17:11:59 -070011194void hdd_dp_trace_init(struct hdd_config *config)
11195{
Mohit Khannaf8f96822017-05-17 17:11:59 -070011196 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
11197 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
11198 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
11199 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
11200 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
11201 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
11202 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080011203 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070011204
Nirav Shahd21a2e32018-04-20 16:34:43 +053011205 if (!config->enable_dp_trace) {
11206 hdd_err("dp trace is disabled from ini");
11207 return;
11208 }
11209
Mohit Khannaf8f96822017-05-17 17:11:59 -070011210 hdd_string_to_u8_array(config->dp_trace_config, config_params,
11211 &num_entries, sizeof(config_params));
11212
11213 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080011214 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080011215 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080011216 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080011217 else if (bw_compute_interval > 1000) {
11218 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
11219 thresh_time_limit = 1;
11220 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070011221 hdd_err("busBandwidthComputeInterval is 0, using defaults");
11222
11223 switch (num_entries) {
11224 case 4:
11225 proto_bitmap = config_params[3];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011226 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011227 case 3:
11228 verbosity = config_params[2];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011229 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011230 case 2:
11231 thresh = config_params[1];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011232 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011233 case 1:
11234 live_mode = config_params[0];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011235 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011236 default:
Dustin Browna7bb6ae2018-08-16 16:51:50 -070011237 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
11238 live_mode, thresh, thresh_time_limit,
11239 verbosity, proto_bitmap);
Mohit Khannaf8f96822017-05-17 17:11:59 -070011240 };
11241
11242 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
11243 verbosity, proto_bitmap);
11244
11245}
Nirav Shahd21a2e32018-04-20 16:34:43 +053011246#endif
11247
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011248#ifdef DISABLE_CHANNEL_LIST
11249static int wlan_hdd_cache_chann_mutex_create(struct hdd_context *hdd_ctx)
11250{
11251 return qdf_mutex_create(&hdd_ctx->cache_channel_lock);
11252}
11253#else
11254static int wlan_hdd_cache_chann_mutex_create(struct hdd_context *hdd_ctx)
11255{
11256 return 0;
11257}
11258#endif
11259
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011260/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011261 * hdd_wlan_startup() - HDD init function
11262 * @dev: Pointer to the underlying device
11263 *
11264 * This is the driver startup code executed once a WLAN device has been detected
11265 *
11266 * Return: 0 for success, < 0 for failure
11267 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011268int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011269{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011270 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011271 struct hdd_context *hdd_ctx;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053011272 struct wlan_objmgr_psoc *psoc;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011273 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080011274 bool rtnl_held;
Jeff Johnson16528362018-06-14 12:34:16 -070011275 mac_handle_t mac_handle;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011276
Dustin Brown491d54b2018-03-14 12:39:11 -070011277 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011278
Arun Khandavallifae92942016-08-01 13:31:08 +053011279 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011280
11281 if (IS_ERR(hdd_ctx))
11282 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011283
Abhishek Singhe9068f12017-03-31 14:14:52 +053011284 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
11285 DEFAULT_PSOC_ID);
11286 if (ret) {
11287 hdd_err("Psoc creation fails!");
11288 QDF_BUG(0);
11289 goto err_hdd_free_context;
11290 }
11291
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011292 hdd_action_oui_config(hdd_ctx);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053011293 psoc = hdd_ctx->hdd_psoc;
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011294
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053011295 qdf_nbuf_init_replenish_timer();
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011296
11297 ret = wlan_hdd_cache_chann_mutex_create(hdd_ctx);
11298 if (QDF_IS_STATUS_ERROR(ret))
11299 goto err_hdd_free_context;
11300
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053011301#ifdef FEATURE_WLAN_CH_AVOID
11302 mutex_init(&hdd_ctx->avoid_freq_lock);
11303#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053011304
Naveen Rawate02f8f52018-04-05 11:58:04 -070011305 osif_request_manager_init();
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053011306 qdf_atomic_init(&hdd_ctx->con_mode_flag);
Dustin Brown021cecd2017-12-11 13:56:43 -080011307 hdd_driver_memdump_init();
Dustin Brown86d196b2018-08-02 11:51:49 -070011308 hdd_bus_bandwidth_init(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -080011309
Dustin Browne7e71d32018-05-11 16:00:08 -070011310 ret = hdd_wlan_start_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053011311 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011312 hdd_err("Failed to start modules: %d", ret);
Dustin Brown021cecd2017-12-11 13:56:43 -080011313 goto err_memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011314 }
11315
Yingying Tang80e15f32016-09-27 18:23:01 +080011316 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011317
Jeff Johnson16528362018-06-14 12:34:16 -070011318 mac_handle = cds_get_context(QDF_MODULE_ID_SME);
11319 hdd_ctx->mac_handle = mac_handle;
11320 if (!mac_handle) {
11321 hdd_err("Mac Handle is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053011322 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011323 }
11324
Prashanth Bhatta07998752016-04-28 12:35:33 -070011325 ret = hdd_wiphy_init(hdd_ctx);
11326 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011327 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053011328 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011329 }
11330
Nirav Shahd21a2e32018-04-20 16:34:43 +053011331 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053011332
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070011333 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080011334
Paul Zhangfb02f452017-12-22 11:58:43 +080011335 ret = register_netdevice_notifier(&hdd_netdev_notifier);
11336 if (ret) {
11337 hdd_err("register_netdevice_notifier failed: %d", ret);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053011338 goto err_wiphy_unregister;
Paul Zhangfb02f452017-12-22 11:58:43 +080011339 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053011340
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011341 ret = register_reboot_notifier(&system_reboot_notifier);
11342 if (ret) {
11343 hdd_err("Failed to register reboot notifier: %d", ret);
11344 goto err_unregister_netdev;
11345 }
11346
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080011347 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011348
Jeff Johnson957bc272017-02-02 08:54:48 -080011349 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11350 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011351 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080011352 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011353 }
11354
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080011355 hdd_release_rtnl_lock();
11356 rtnl_held = false;
11357
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080011358 wlan_hdd_update_11n_mode(hdd_ctx->config);
11359
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011360#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053011361 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053011362 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011363 hdd_skip_acs_scan_timer_handler,
11364 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011365 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070011366 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040011367 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011368#endif
11369
Arunk Khandavalli40943af2017-05-15 19:25:34 +053011370 hdd_lpass_notify_wlan_version(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011371
Nirav Shahbd36b062016-07-18 11:12:59 +053011372 if (hdd_ctx->rps)
11373 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070011374
Paul Zhangfb02f452017-12-22 11:58:43 +080011375 ret = hdd_register_notifiers(hdd_ctx);
11376 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -080011377 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070011378
Paul Zhangfb02f452017-12-22 11:58:43 +080011379 status = wlansap_global_init();
11380 if (QDF_IS_STATUS_ERROR(status)) {
11381 hdd_unregister_notifiers(hdd_ctx);
11382 goto err_close_adapters;
11383 }
11384
Arun Khandavallifae92942016-08-01 13:31:08 +053011385 if (hdd_ctx->config->fIsImpsEnabled)
11386 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070011387 else
11388 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011389
Mukul Sharma07bd8752017-10-10 16:58:14 +053011390 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070011391 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
11392 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053011393 hdd_prevent_suspend_timeout(
11394 hdd_ctx->config->iface_change_wait_time,
11395 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
11396 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053011397
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011398 goto success;
11399
Jeff Johnson957bc272017-02-02 08:54:48 -080011400err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080011401 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011402
Jeff Johnson46bde382017-02-01 15:31:16 -080011403err_release_rtnl_lock:
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011404 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavallid4349a92016-07-25 11:10:43 +053011405 if (rtnl_held)
11406 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011407
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011408err_unregister_netdev:
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011409 unregister_netdevice_notifier(&hdd_netdev_notifier);
11410
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011411err_wiphy_unregister:
Rachit Kankane30807332018-06-27 18:39:36 +053011412 qdf_dp_trace_deinit();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011413 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011414
Arun Khandavallifae92942016-08-01 13:31:08 +053011415err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011416 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053011417
Dustin Brown021cecd2017-12-11 13:56:43 -080011418err_memdump_deinit:
Dustin Brown86d196b2018-08-02 11:51:49 -070011419 hdd_bus_bandwidth_deinit(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -080011420 hdd_driver_memdump_deinit();
Dustin Brown021cecd2017-12-11 13:56:43 -080011421
Naveen Rawate02f8f52018-04-05 11:58:04 -070011422 osif_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070011423 hdd_exit_netlink_services(hdd_ctx);
11424
Dustin Brown20912462017-06-07 13:48:25 -070011425 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
11426
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011427err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053011428 if (cds_is_fw_down())
11429 hdd_err("Not setting the complete event as fw is down");
11430 else
11431 hdd_start_complete(ret);
11432
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053011433 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070011434 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070011435 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011436
11437success:
Dustin Browne74003f2018-03-14 12:51:58 -070011438 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011439 return 0;
11440}
11441
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011442/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011443 * hdd_wlan_update_target_info() - update target type info
11444 * @hdd_ctx: HDD context
11445 * @context: hif context
11446 *
11447 * Update target info received from firmware in hdd context
11448 * Return:None
11449 */
11450
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011451void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053011452{
11453 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
11454
11455 if (!tgt_info) {
11456 hdd_err("Target info is Null");
11457 return;
11458 }
11459
11460 hdd_ctx->target_type = tgt_info->target_type;
11461}
11462
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011463void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp, void *context)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011464{
11465 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011466 int status;
11467 struct hdd_adapter *adapter = NULL;
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011468 struct osif_request *request = NULL;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011469
Dustin Brown491d54b2018-03-14 12:39:11 -070011470 hdd_enter();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011471
11472 if (!rsp) {
11473 hdd_err("data is null");
11474 return;
11475 }
11476
11477 status = wlan_hdd_validate_context(hdd_ctx);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011478 if (status != 0)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011479 return;
11480
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011481 request = osif_request_get(context);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011482 if (!request) {
11483 hdd_err("obselete request");
11484 return;
11485 }
11486
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011487 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
11488 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
11489 hdd_err("Invalid adapter or adapter has invalid magic");
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011490 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011491 return;
11492 }
11493
Dustin Brown5e89ef82018-03-14 11:50:23 -070011494 hdd_info("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
11495 hdd_info("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
11496 hdd_info("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
11497 hdd_info("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
11498 hdd_info("rsp->out_of_order_arp_rsp_drop_cnt :%x",
11499 rsp->out_of_order_arp_rsp_drop_cnt);
11500 hdd_info("rsp->dad_detected :%x", rsp->dad_detected);
11501 hdd_info("rsp->connect_status :%x", rsp->connect_status);
11502 hdd_info("rsp->ba_session_establishment_status :%x",
11503 rsp->ba_session_establishment_status);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011504
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011505 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011506 adapter->dad |= rsp->dad_detected;
11507 adapter->con_status = rsp->connect_status;
11508
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053011509 /* Flag true indicates connectivity check stats present. */
11510 if (rsp->connect_stats_present) {
11511 hdd_info("rsp->tcp_ack_recvd :%x", rsp->tcp_ack_recvd);
11512 hdd_info("rsp->icmpv4_rsp_recvd :%x", rsp->icmpv4_rsp_recvd);
11513 adapter->hdd_stats.hdd_tcp_stats.rx_fw_cnt = rsp->tcp_ack_recvd;
11514 adapter->hdd_stats.hdd_icmpv4_stats.rx_fw_cnt =
11515 rsp->icmpv4_rsp_recvd;
11516 }
11517
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011518 osif_request_complete(request);
11519 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011520
Dustin Browne74003f2018-03-14 12:51:58 -070011521 hdd_exit();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011522}
11523
11524/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011525 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011526 * @hdd_ctx: HDD context
11527 *
11528 * Register the HDD callbacks to CDS/SME.
11529 *
11530 * Return: 0 for success or Error code for failure
11531 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011532int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011533{
11534 QDF_STATUS status;
11535 int ret = 0;
Jeff Johnson16528362018-06-14 12:34:16 -070011536 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011537
Dustin Brown491d54b2018-03-14 12:39:11 -070011538 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011539
Jeff Johnson16528362018-06-14 12:34:16 -070011540 mac_handle = hdd_ctx->mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011541
Jeff Johnson16528362018-06-14 12:34:16 -070011542 sme_register_oem_data_rsp_callback(mac_handle,
11543 hdd_send_oem_data_rsp_msg);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011544
Jeff Johnson16528362018-06-14 12:34:16 -070011545 sme_register_mgmt_frame_ind_callback(mac_handle,
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053011546 hdd_indicate_mgmt_frame);
Jeff Johnson16528362018-06-14 12:34:16 -070011547 sme_set_tsfcb(mac_handle, hdd_get_tsf_cb, hdd_ctx);
11548 sme_nan_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011549 wlan_hdd_cfg80211_nan_callback);
Jeff Johnson16528362018-06-14 12:34:16 -070011550 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011551 wlan_hdd_cfg80211_stats_ext_callback);
11552
Jeff Johnson16528362018-06-14 12:34:16 -070011553 sme_ext_scan_register_callback(mac_handle,
11554 wlan_hdd_cfg80211_extscan_callback);
11555 sme_stats_ext2_register_callback(mac_handle,
lifeng66831662017-05-19 16:01:35 +080011556 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011557
Jeff Johnson16528362018-06-14 12:34:16 -070011558 sme_set_rssi_threshold_breached_cb(mac_handle,
11559 hdd_rssi_threshold_breached);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011560
Jeff Johnson16528362018-06-14 12:34:16 -070011561 sme_set_link_layer_stats_ind_cb(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011562 wlan_hdd_cfg80211_link_layer_stats_callback);
11563
Jeff Johnson16528362018-06-14 12:34:16 -070011564 sme_rso_cmd_status_cb(mac_handle, wlan_hdd_rso_cmd_status_cb);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053011565
Jeff Johnson16528362018-06-14 12:34:16 -070011566 sme_set_link_layer_ext_cb(mac_handle,
Zhang Qianca38fb12016-12-23 11:10:48 +080011567 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
11568
Jeff Johnson16528362018-06-14 12:34:16 -070011569 status = sme_set_lost_link_info_cb(mac_handle,
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053011570 hdd_lost_link_info_cb);
11571 /* print error and not block the startup process */
11572 if (!QDF_IS_STATUS_SUCCESS(status))
11573 hdd_err("set lost link info callback failed");
11574
Poddar, Siddarth34872782017-08-10 14:08:51 +053011575 ret = hdd_register_data_stall_detect_cb();
11576 if (ret) {
11577 hdd_err("Register data stall detect detect callback failed.");
11578 return ret;
11579 }
11580
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011581 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
11582
Jeff Johnson16528362018-06-14 12:34:16 -070011583 sme_register_set_connection_info_cb(mac_handle,
11584 hdd_set_connection_in_progress,
11585 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053011586
Jeff Johnson16528362018-06-14 12:34:16 -070011587 status = sme_congestion_register_callback(mac_handle,
11588 hdd_update_cca_info_cb);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053011589 if (!QDF_IS_STATUS_SUCCESS(status))
11590 hdd_err("set congestion callback failed");
11591
Jeff Johnson16528362018-06-14 12:34:16 -070011592 status = sme_set_bt_activity_info_cb(mac_handle,
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053011593 hdd_bt_activity_cb);
11594 if (!QDF_IS_STATUS_SUCCESS(status))
11595 hdd_err("set bt activity info callback failed");
11596
Jeff Johnson16528362018-06-14 12:34:16 -070011597 status = sme_register_tx_queue_cb(mac_handle,
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080011598 hdd_tx_queue_cb);
11599 if (!QDF_IS_STATUS_SUCCESS(status))
11600 hdd_err("Register tx queue callback failed");
11601
Dustin Browne74003f2018-03-14 12:51:58 -070011602 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011603
11604 return ret;
11605}
11606
11607/**
11608 * hdd_deregister_cb() - De-Register HDD callbacks.
11609 * @hdd_ctx: HDD context
11610 *
11611 * De-Register the HDD callbacks to CDS/SME.
11612 *
11613 * Return: void
11614 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011615void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011616{
11617 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053011618 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070011619 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011620
Dustin Brown491d54b2018-03-14 12:39:11 -070011621 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011622
Jeff Johnson16528362018-06-14 12:34:16 -070011623 mac_handle = hdd_ctx->mac_handle;
11624 sme_deregister_tx_queue_cb(mac_handle);
11625 status = sme_deregister_for_dcc_stats_event(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011626 if (!QDF_IS_STATUS_SUCCESS(status))
11627 hdd_err("De-register of dcc stats callback failed: %d",
11628 status);
11629
Jeff Johnson16528362018-06-14 12:34:16 -070011630 sme_reset_link_layer_stats_ind_cb(mac_handle);
11631 sme_reset_rssi_threshold_breached_cb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011632
Jeff Johnson16528362018-06-14 12:34:16 -070011633 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011634 wlan_hdd_cfg80211_stats_ext_callback);
11635
Jeff Johnson16528362018-06-14 12:34:16 -070011636 sme_nan_deregister_callback(mac_handle);
11637 status = sme_reset_tsfcb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011638 if (!QDF_IS_STATUS_SUCCESS(status))
11639 hdd_err("Failed to de-register tsfcb the callback:%d",
11640 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011641
Poddar, Siddarth34872782017-08-10 14:08:51 +053011642 ret = hdd_deregister_data_stall_detect_cb();
11643 if (ret)
11644 hdd_err("Failed to de-register data stall detect event callback");
11645
Jeff Johnson16528362018-06-14 12:34:16 -070011646 sme_deregister_oem_data_rsp_callback(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011647
Dustin Browne74003f2018-03-14 12:51:58 -070011648 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011649}
11650
11651/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011652 * hdd_softap_sta_deauth() - handle deauth req from HDD
11653 * @adapter: Pointer to the HDD
11654 * @enable: bool value
11655 *
11656 * This to take counter measure to handle deauth req from HDD
11657 *
11658 * Return: None
11659 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011660QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011661 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011662{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011663 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011664
Dustin Brown491d54b2018-03-14 12:39:11 -070011665 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011666
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011667 /* Ignore request to deauth bcmc station */
11668 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011669 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011670
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011671 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011672 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
11673 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011674
Dustin Browne74003f2018-03-14 12:51:58 -070011675 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011676 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011677}
11678
11679/**
11680 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
11681 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011682 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011683 *
11684 * This to take counter measure to handle deauth req from HDD
11685 *
11686 * Return: None
11687 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011688void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011689 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011690{
Dustin Brown491d54b2018-03-14 12:39:11 -070011691 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011692
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011693 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011694 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011695 return;
11696
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011697 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011698 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011699}
11700
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011701/**
11702 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
11703 * @hdd_ctx: HDD Context
11704 *
11705 * API to find if there is any STA or P2P-Client is connected
11706 *
11707 * Return: true if connected; false otherwise
11708 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011709QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011710{
Jeff Johnson16528362018-06-14 12:34:16 -070011711 return sme_is_sta_p2p_client_connected(hdd_ctx->mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011712}
11713
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011714void wlan_hdd_disable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011715{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011716 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
11717 struct hdd_adapter *adapter = NULL;
11718 struct csr_roam_profile *roam_profile;
11719 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011720
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011721 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->hdd_psoc)) {
11722 hdd_debug("No active sta session");
11723 return;
11724 }
11725
11726 hdd_for_each_adapter(hdd_ctx, adapter) {
11727 roam_profile = hdd_roam_profile(adapter);
11728 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11729
11730 if (cur_adapter->session_id != adapter->session_id &&
11731 adapter->device_mode == QDF_STA_MODE &&
11732 hdd_conn_is_connected(sta_ctx)) {
11733 hdd_debug("%d Disable roaming", adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -070011734 sme_stop_roaming(hdd_ctx->mac_handle,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011735 adapter->session_id,
11736 ecsr_driver_disabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011737 }
11738 }
11739}
11740
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011741void wlan_hdd_enable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011742{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011743 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
11744 struct hdd_adapter *adapter = NULL;
11745 struct csr_roam_profile *roam_profile;
11746 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011747
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011748 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->hdd_psoc)) {
11749 hdd_debug("No active sta session");
11750 return;
11751 }
11752
11753 hdd_for_each_adapter(hdd_ctx, adapter) {
11754 roam_profile = hdd_roam_profile(adapter);
11755 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11756
11757 if (cur_adapter->session_id != adapter->session_id &&
11758 adapter->device_mode == QDF_STA_MODE &&
11759 hdd_conn_is_connected(sta_ctx)) {
11760 hdd_debug("%d Enable roaming", adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -070011761 sme_start_roaming(hdd_ctx->mac_handle,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011762 adapter->session_id,
11763 REASON_DRIVER_ENABLED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011764 }
11765 }
11766}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011767
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011768/**
11769 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
11770 * @skb: sk buffer pointer
11771 *
11772 * Sends the bcast message to SVC multicast group with generic nl socket
11773 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
11774 *
11775 * Return: None
11776 */
11777static void nl_srv_bcast_svc(struct sk_buff *skb)
11778{
11779#ifdef CNSS_GENL
11780 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
11781#else
11782 nl_srv_bcast(skb);
11783#endif
11784}
11785
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011786void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011787{
11788 struct sk_buff *skb;
11789 struct nlmsghdr *nlh;
11790 tAniMsgHdr *ani_hdr;
11791 void *nl_data = NULL;
11792 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011793 struct radio_index_tlv *radio_info;
11794 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011795
11796 if (in_interrupt() || irqs_disabled() || in_atomic())
11797 flags = GFP_ATOMIC;
11798
11799 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
11800
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011801 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011802 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011803
11804 nlh = (struct nlmsghdr *)skb->data;
11805 nlh->nlmsg_pid = 0; /* from kernel */
11806 nlh->nlmsg_flags = 0;
11807 nlh->nlmsg_seq = 0;
11808 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
11809
11810 ani_hdr = NLMSG_DATA(nlh);
11811 ani_hdr->type = type;
11812
11813 switch (type) {
11814 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053011815 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011816 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011817 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011818 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011819 ani_hdr->length = 0;
11820 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011821 break;
11822 case WLAN_SVC_WLAN_STATUS_IND:
11823 case WLAN_SVC_WLAN_VERSION_IND:
11824 case WLAN_SVC_DFS_CAC_START_IND:
11825 case WLAN_SVC_DFS_CAC_END_IND:
11826 case WLAN_SVC_DFS_RADAR_DETECT_IND:
11827 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
11828 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080011829 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053011830 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080011831 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011832 ani_hdr->length = len;
11833 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
11834 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
11835 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011836 break;
11837
11838 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070011839 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011840 type);
11841 kfree_skb(skb);
11842 return;
11843 }
11844
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011845 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080011846 * Add radio index at the end of the svc event in TLV format
11847 * to maintain the backward compatibility with userspace
11848 * applications.
11849 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011850
11851 tlv_len = 0;
11852
11853 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
11854 < WLAN_NL_MAX_PAYLOAD) {
11855 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
11856 sizeof(*ani_hdr) + len);
11857 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
11858 radio_info->length = (unsigned short) sizeof(radio_info->radio);
11859 radio_info->radio = radio;
11860 tlv_len = sizeof(*radio_info);
Dustin Browna2868622018-03-20 11:38:14 -070011861 hdd_debug("Added radio index tlv - radio index %d",
11862 radio_info->radio);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011863 }
11864
11865 nlh->nlmsg_len += tlv_len;
11866 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
11867
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011868 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011869}
11870
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011871#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
11872void wlan_hdd_auto_shutdown_cb(void)
11873{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011874 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011875
11876 if (!hdd_ctx)
11877 return;
11878
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011879 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011880 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
11881 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011882}
11883
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011884void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011885{
Jeff Johnson9d295242017-08-29 14:39:48 -070011886 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011887 bool ap_connected = false, sta_connected = false;
Jeff Johnson16528362018-06-14 12:34:16 -070011888 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011889
Jeff Johnson16528362018-06-14 12:34:16 -070011890 mac_handle = hdd_ctx->mac_handle;
11891 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011892 return;
11893
11894 if (hdd_ctx->config->WlanAutoShutdown == 0)
11895 return;
11896
11897 if (enable == false) {
Jeff Johnson16528362018-06-14 12:34:16 -070011898 if (sme_set_auto_shutdown_timer(mac_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011899 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011900 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011901 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011902 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011903 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011904 return;
11905 }
11906
11907 /* To enable shutdown timer check conncurrency */
Dustin Brown920397d2017-12-13 16:27:50 -080011908 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->hdd_psoc)) {
11909 hdd_for_each_adapter(hdd_ctx, adapter) {
11910 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011911 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11912 conn_info.connState ==
11913 eConnectionState_Associated) {
11914 sta_connected = true;
11915 break;
11916 }
11917 }
Dustin Brown920397d2017-12-13 16:27:50 -080011918
11919 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011920 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070011921 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011922 ap_connected = true;
11923 break;
11924 }
11925 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011926 }
11927 }
11928
11929 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011930 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011931 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011932 }
Jeff Johnson68755312017-02-10 11:46:55 -080011933
Jeff Johnson16528362018-06-14 12:34:16 -070011934 if (sme_set_auto_shutdown_timer(mac_handle,
Jeff Johnson68755312017-02-10 11:46:55 -080011935 hdd_ctx->config->WlanAutoShutdown)
11936 != QDF_STATUS_SUCCESS)
11937 hdd_err("Failed to start wlan auto shutdown timer");
11938 else
Dustin Brown5e89ef82018-03-14 11:50:23 -070011939 hdd_info("Auto Shutdown timer for %d seconds enabled",
11940 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011941}
11942#endif
11943
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011944struct hdd_adapter *
11945hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
11946 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011947{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011948 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011949 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011950
11951 con_sap_adapter = NULL;
11952
Dustin Brown920397d2017-12-13 16:27:50 -080011953 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011954 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
11955 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011956 adapter != this_sap_adapter) {
11957 if (check_start_bss) {
11958 if (test_bit(SOFTAP_BSS_STARTED,
11959 &adapter->event_flags)) {
11960 con_sap_adapter = adapter;
11961 break;
11962 }
11963 } else {
11964 con_sap_adapter = adapter;
11965 break;
11966 }
11967 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011968 }
11969
11970 return con_sap_adapter;
11971}
11972
11973#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070011974static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011975{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011976 return adapter->device_mode == QDF_STA_MODE ||
11977 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011978}
11979
Jeff Johnson9d295242017-08-29 14:39:48 -070011980static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011981{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011982 return adapter->device_mode == QDF_SAP_MODE ||
11983 adapter->device_mode == QDF_P2P_GO_MODE;
11984}
11985
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011986static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011987{
Dustin Brown920397d2017-12-13 16:27:50 -080011988 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070011989
Dustin Brown920397d2017-12-13 16:27:50 -080011990 hdd_for_each_adapter(hdd_ctx, adapter) {
11991 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070011992 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11993 conn_info.connState == eConnectionState_Associated) {
11994 return true;
11995 }
11996
Dustin Brown920397d2017-12-13 16:27:50 -080011997 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070011998 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070011999 return true;
12000 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070012001 }
12002
12003 return false;
12004}
12005
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012006static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012007{
12008 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012009
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053012010 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012011 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053012012 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012013
Dustin Brown5ec6b552017-03-31 12:11:40 -070012014 return is_running;
12015}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012016
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012017static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012018{
12019 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
12020 hdd_ctx->bus_bw_timer_running = true;
12021 qdf_timer_start(&hdd_ctx->bus_bw_timer,
12022 hdd_ctx->config->busBandwidthComputeInterval);
12023 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
12024}
12025
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012026void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012027{
Dustin Brown491d54b2018-03-14 12:39:11 -070012028 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012029
12030 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12031 hdd_debug("Bandwidth compute timer already started");
12032 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012033 }
12034
Dustin Brown5ec6b552017-03-31 12:11:40 -070012035 __hdd_bus_bw_compute_timer_start(hdd_ctx);
12036
Dustin Browne74003f2018-03-14 12:51:58 -070012037 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012038}
12039
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012040void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012041{
Dustin Brown491d54b2018-03-14 12:39:11 -070012042 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012043
12044 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12045 hdd_debug("Bandwidth compute timer already started");
12046 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070012047 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070012048
12049 if (hdd_any_adapter_is_assoc(hdd_ctx))
12050 __hdd_bus_bw_compute_timer_start(hdd_ctx);
12051
Dustin Browne74003f2018-03-14 12:51:58 -070012052 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012053}
12054
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012055static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012056{
Sravan Kumar Kairam9e99e9a2018-03-12 19:09:45 +053012057 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, 0, 0);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012058
12059 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012060 hdd_ctx->bus_bw_timer_running = false;
Dustin Brown35008ba2018-08-23 14:34:21 -070012061 qdf_timer_sync_cancel(&hdd_ctx->bus_bw_timer);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012062 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
12063
Dustin Brown35008ba2018-08-23 14:34:21 -070012064 /* work callback is long running; flush outside of lock */
12065 cancel_work_sync(&hdd_ctx->bus_bw_work);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012066 hdd_reset_tcp_delack(hdd_ctx);
12067}
12068
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012069void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012070{
Dustin Brown491d54b2018-03-14 12:39:11 -070012071 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012072
12073 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12074 hdd_debug("Bandwidth compute timer already stopped");
12075 return;
12076 }
12077
12078 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
12079
Dustin Browne74003f2018-03-14 12:51:58 -070012080 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012081}
12082
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012083void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012084{
Dustin Brown491d54b2018-03-14 12:39:11 -070012085 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012086
12087 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12088 hdd_debug("Bandwidth compute timer already stopped");
12089 return;
12090 }
12091
12092 if (!hdd_any_adapter_is_assoc(hdd_ctx))
12093 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
12094
Dustin Browne74003f2018-03-14 12:51:58 -070012095 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012096}
12097#endif
12098
12099/**
12100 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
12101 * and sta's operating channel.
12102 * @sta_adapter: Describe the first argument to foobar.
12103 * @ap_adapter: Describe the second argument to foobar.
12104 * @roam_profile: Roam profile of AP to which STA wants to connect.
12105 * @concurrent_chnl_same: If both SAP and STA channels are same then
12106 * set this flag to true else false.
12107 *
12108 * This function checks the sap's operating channel and sta's operating channel.
12109 * if both are same then it will return false else it will restart the sap in
12110 * sta's channel and return true.
12111 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012112 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012113 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070012114QDF_STATUS
12115wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
12116 struct hdd_adapter *ap_adapter,
Jeff Johnson61b5e982018-03-15 11:33:31 -070012117 struct csr_roam_profile *roam_profile,
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070012118 tScanResultHandle *scan_cache,
12119 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012120{
Jeff Johnson87251032017-08-29 13:31:11 -070012121 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012122 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012123 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012124 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012125 *concurrent_chnl_same = true;
12126
12127 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12128 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070012129 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012130 scan_cache,
12131 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012132 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012133 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012134 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070012135 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012136 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012137 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012138 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012139 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012140 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070012141 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012142 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012143 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012144 }
12145 }
12146 } else {
12147 /*
12148 * Lets handle worst case scenario here, Scan cache lookup is
12149 * failed so we have to stop the SAP to avoid any channel
12150 * discrepancy between SAP's channel and STA's channel.
12151 * Return the status as failure so caller function could know
12152 * that scan look up is failed.
12153 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070012154 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012155 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012156 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012157 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012158}
12159
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012160/**
12161 * wlan_hdd_stop_sap() - This function stops bss of SAP.
12162 * @ap_adapter: SAP adapter
12163 *
12164 * This function will process the stopping of sap adapter.
12165 *
12166 * Return: None
12167 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012168void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012169{
Jeff Johnson87251032017-08-29 13:31:11 -070012170 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012171 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053012172 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012173 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012174
12175 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012176 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012177 return;
12178 }
12179
12180 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12181 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012182 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012183 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012184
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012185 mutex_lock(&hdd_ctx->sap_lock);
12186 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080012187 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012188 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012189 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053012190 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012191 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012192 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053012193 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080012194 qdf_stop_bss_event,
12195 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053012196 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012197 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070012198 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012199 return;
12200 }
12201 }
12202 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012203 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
12204 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012205 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012206 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012207 false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012208 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012209 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012210 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012211 }
12212 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012213}
12214
12215/**
12216 * wlan_hdd_start_sap() - this function starts bss of SAP.
12217 * @ap_adapter: SAP adapter
12218 *
12219 * This function will process the starting of sap adapter.
12220 *
12221 * Return: None
12222 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012223void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012224{
Jeff Johnson87251032017-08-29 13:31:11 -070012225 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012226 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053012227 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012228 struct hdd_context *hdd_ctx;
Jeff Johnsone4c11db2018-05-05 23:22:32 -070012229 tsap_config_t *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012230
12231 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012232 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012233 return;
12234 }
12235
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012236 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070012237 hdd_err("SoftAp role has not been enabled");
12238 return;
12239 }
12240
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012241 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
12242 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12243 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070012244 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012245
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012246 mutex_lock(&hdd_ctx->sap_lock);
12247 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
12248 goto end;
12249
12250 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012251 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012252 goto end;
12253 }
Abhinav Kumar6f694482018-09-04 16:07:39 +053012254 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
12255 hdd_ap_ctx->sap_config.channel, 0,
12256 &hdd_ap_ctx->sap_config.ch_params);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012257
Wei Song2f76f642016-11-18 16:32:53 +080012258 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012259 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070012260 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012261 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012262 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012263 goto end;
12264
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012265 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053012266 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080012267 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053012268 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012269 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012270 goto end;
12271 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070012272 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012273 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012274 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012275 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012276 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12277 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012278 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012279 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012280 true);
12281 }
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053012282 mutex_unlock(&hdd_ctx->sap_lock);
12283
12284 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012285end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012286 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012287 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070012288 /* SAP context and beacon cleanup will happen during driver unload
12289 * in hdd_stop_adapter
12290 */
12291 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
12292
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012293}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012294
12295/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012296 * hdd_get_fw_version() - Get FW version
12297 * @hdd_ctx: pointer to HDD context.
12298 * @major_spid: FW version - major spid.
12299 * @minor_spid: FW version - minor spid
12300 * @ssid: FW version - ssid
12301 * @crmid: FW version - crmid
12302 *
12303 * This function is called to get the firmware build version stored
12304 * as part of the HDD context
12305 *
12306 * Return: None
12307 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012308void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012309 uint32_t *major_spid, uint32_t *minor_spid,
12310 uint32_t *siid, uint32_t *crmid)
12311{
12312 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
12313 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
12314 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
12315 *crmid = hdd_ctx->target_fw_version & 0x7fff;
12316}
12317
12318#ifdef QCA_CONFIG_SMP
12319/**
12320 * wlan_hdd_get_cpu() - get cpu_index
12321 *
12322 * Return: cpu_index
12323 */
12324int wlan_hdd_get_cpu(void)
12325{
12326 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012327
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012328 put_cpu();
12329 return cpu_index;
12330}
12331#endif
12332
12333/**
12334 * hdd_get_fwpath() - get framework path
12335 *
12336 * This function is used to get the string written by
12337 * userspace to start the wlan driver
12338 *
12339 * Return: string
12340 */
12341const char *hdd_get_fwpath(void)
12342{
12343 return fwpath.string;
12344}
12345
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070012346static int hdd_qdf_print_init(void)
12347{
12348 int qdf_print_idx;
12349 QDF_STATUS status;
12350
12351 status = qdf_print_setup();
12352 if (status != QDF_STATUS_SUCCESS) {
12353 pr_err("qdf_print_setup failed\n");
12354 return -EINVAL;
12355 }
12356
12357 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
12358
12359 if (qdf_print_idx < 0) {
12360 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
12361 qdf_print_idx);
12362 return -EINVAL;
12363 }
12364
12365 qdf_set_pidx(qdf_print_idx);
12366
12367 return 0;
12368}
12369
12370static void hdd_qdf_print_deinit(void)
12371{
12372 int qdf_print_idx;
12373
12374 qdf_print_idx = qdf_get_pidx();
12375 qdf_print_ctrl_cleanup(qdf_print_idx);
12376}
12377
Dustin Brown94ce20f2018-09-04 13:11:38 -070012378static inline int hdd_state_query_cb(void)
12379{
12380 return !!wlan_hdd_validate_context(cds_get_context(QDF_MODULE_ID_HDD));
12381}
12382
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012383/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012384 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012385 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012386 * This function initilizes CDS global context with the help of cds_init. This
12387 * has to be the first function called after probe to get a valid global
12388 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012389 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012390 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012391 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012392int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012393{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012394 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012395 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012396
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012397 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080012398 if (QDF_IS_STATUS_ERROR(status)) {
12399 hdd_err("Failed to allocate CDS context");
12400 ret = -ENOMEM;
12401 goto err_out;
12402 }
Dustin Brown94ce20f2018-09-04 13:11:38 -070012403 qdf_register_module_state_query_callback(hdd_state_query_cb);
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053012404
12405 wlan_init_bug_report_lock();
12406
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012407#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12408 wlan_logging_sock_init_svc();
12409#endif
12410
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012411 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
12412 (void *)hdd_drv_ops_inactivity_handler, NULL,
12413 QDF_TIMER_TYPE_SW);
12414
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012415 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070012416 hdd_qdf_print_init();
12417
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053012418 hdd_register_debug_callback();
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012419 wlan_roam_debug_init();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012420
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012421err_out:
12422 return ret;
12423}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012424
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012425/**
12426 * hdd_deinit() - Deinitialize Driver
12427 *
12428 * This function frees CDS global context with the help of cds_deinit. This
12429 * has to be the last function call in remove callback to free the global
12430 * context.
12431 */
12432void hdd_deinit(void)
12433{
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012434 wlan_roam_debug_deinit();
12435 hdd_qdf_print_deinit();
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012436 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012437
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012438#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12439 wlan_logging_sock_deinit_svc();
12440#endif
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012441
12442 wlan_destroy_bug_report_lock();
12443 cds_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012444}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012445
Yue Ma6e7b1a02017-04-03 14:17:46 -070012446#ifdef QCA_WIFI_NAPIER_EMULATION
12447#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
12448#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012449#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070012450#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012451
Sachin Ahujadddd2632017-03-07 19:07:24 +053012452static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
12453 struct file *file)
12454{
12455 return 0;
12456}
12457
12458static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
12459 const char __user *user_buf,
12460 size_t count,
12461 loff_t *f_pos)
12462{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012463 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053012464 static const char wlan_off_str[] = "OFF";
12465 static const char wlan_on_str[] = "ON";
12466 int ret;
12467 unsigned long rc;
12468
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012469 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012470 pr_err("Failed to read buffer\n");
12471 return -EINVAL;
12472 }
12473
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012474 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012475 pr_debug("Wifi turning off from UI\n");
12476 goto exit;
12477 }
12478
Sachin Ahuja16904db2017-12-13 19:56:57 +053012479 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) == 0) {
12480 pr_info("Wifi Turning On from UI\n");
12481 }
12482
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012483 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012484 pr_err("Invalid value received from framework");
12485 goto exit;
12486 }
12487
12488 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053012489 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053012490 rc = wait_for_completion_timeout(&wlan_start_comp,
12491 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
12492 if (!rc) {
12493 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
12494 ret = -EINVAL;
Sachin Ahujadddd2632017-03-07 19:07:24 +053012495 return ret;
12496 }
12497
12498 hdd_start_complete(0);
12499 }
12500
12501exit:
12502 return count;
12503}
12504
12505
12506const struct file_operations wlan_hdd_state_fops = {
12507 .owner = THIS_MODULE,
12508 .open = wlan_hdd_state_ctrl_param_open,
12509 .write = wlan_hdd_state_ctrl_param_write,
12510};
12511
12512static int wlan_hdd_state_ctrl_param_create(void)
12513{
12514 unsigned int wlan_hdd_state_major = 0;
12515 int ret;
12516 struct device *dev;
12517
12518 device = MKDEV(wlan_hdd_state_major, 0);
12519
12520 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
12521 if (ret) {
12522 pr_err("Failed to register qcwlanstate");
12523 goto dev_alloc_err;
12524 }
12525 wlan_hdd_state_major = MAJOR(device);
12526
12527 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
12528 if (IS_ERR(class)) {
12529 pr_err("wlan_hdd_state class_create error");
12530 goto class_err;
12531 }
12532
12533 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
12534 if (IS_ERR(dev)) {
12535 pr_err("wlan_hdd_statedevice_create error");
12536 goto err_class_destroy;
12537 }
12538
12539 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
12540 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
12541 if (ret) {
12542 pr_err("Failed to add cdev error");
12543 goto cdev_add_err;
12544 }
12545
12546 pr_info("wlan_hdd_state %s major(%d) initialized",
12547 WLAN_MODULE_NAME, wlan_hdd_state_major);
12548
12549 return 0;
12550
12551cdev_add_err:
12552 device_destroy(class, device);
12553err_class_destroy:
12554 class_destroy(class);
12555class_err:
12556 unregister_chrdev_region(device, dev_num);
12557dev_alloc_err:
12558 return -ENODEV;
12559}
12560
12561static void wlan_hdd_state_ctrl_param_destroy(void)
12562{
12563 cdev_del(&wlan_hdd_state_cdev);
12564 device_destroy(class, device);
12565 class_destroy(class);
12566 unregister_chrdev_region(device, dev_num);
12567
12568 pr_info("Device node unregistered");
12569}
12570
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012571/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053012572 * component_init - API to init cld component's
12573 *
12574 * Return: None
12575 */
12576static void component_init(void)
12577{
Vignesh Viswanathana0921c42018-09-04 19:03:35 +053012578 ucfg_mlme_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053012579 pmo_init();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012580 disa_init();
Zhang Qian47e22ce2018-01-04 15:38:38 +080012581 ucfg_ocb_init();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053012582 ipa_init();
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053012583 ucfg_action_oui_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053012584}
12585
12586/**
12587 * component_deinit - API to deinit cld component's
12588 *
12589 * Return: None
12590 */
12591static void component_deinit(void)
12592{
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053012593 ucfg_action_oui_deinit();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053012594 ipa_deinit();
Zhang Qian47e22ce2018-01-04 15:38:38 +080012595 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053012596 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012597 disa_deinit();
Vignesh Viswanathana0921c42018-09-04 19:03:35 +053012598 ucfg_mlme_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012599}
12600
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053012601QDF_STATUS hdd_component_psoc_open(struct wlan_objmgr_psoc *psoc)
12602{
Vignesh Viswanathana0921c42018-09-04 19:03:35 +053012603 return ucfg_mlme_psoc_open(psoc);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053012604}
12605
12606void hdd_component_psoc_close(struct wlan_objmgr_psoc *psoc)
12607{
Vignesh Viswanathana0921c42018-09-04 19:03:35 +053012608 ucfg_mlme_psoc_close(psoc);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053012609}
12610
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012611void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
12612{
Zhang Qian47e22ce2018-01-04 15:38:38 +080012613 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012614 disa_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012615}
12616
12617void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
12618{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012619 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080012620 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053012621}
12622
12623/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012624 * __hdd_module_init - Module init helper
12625 *
12626 * Module init helper function used by both module and static driver.
12627 *
12628 * Return: 0 for success, errno on failure
12629 */
12630static int __hdd_module_init(void)
12631{
12632 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012633
Dustin Brown96cd9632017-11-13 12:45:04 -080012634 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070012635 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080012636 g_wlan_driver_version,
Dustin Brownc1034df2018-02-07 14:51:32 -080012637 TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012638
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012639 pld_init();
12640
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012641 ret = hdd_init();
12642 if (ret) {
12643 pr_err("hdd_init failed %x\n", ret);
12644 goto err_hdd_init;
12645 }
12646
Rajeev Kumar97767a02016-11-30 11:20:40 -080012647 dispatcher_init();
12648
Mukul Sharmad75a6672017-06-22 15:40:53 +053012649 /* Ensure to call post objmgr init */
12650 component_init();
12651
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012652 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012653
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012654 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012655
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012656 ret = wlan_hdd_register_driver();
12657 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070012658 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
12659 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012660 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012661 }
12662
Sachin Ahuja16904db2017-12-13 19:56:57 +053012663 ret = wlan_hdd_state_ctrl_param_create();
12664 if (ret) {
12665 pr_err("wlan_hdd_state_create:%x\n", ret);
12666 goto out;
12667 }
12668
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053012669 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012670
12671 return 0;
12672out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012673 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080012674 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080012675 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012676 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080012677
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012678err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012679 pld_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012680 return ret;
12681}
12682
12683/**
12684 * __hdd_module_exit - Module exit helper
12685 *
12686 * Module exit helper function used by both module and static driver.
12687 */
12688static void __hdd_module_exit(void)
12689{
Will Huang36049722018-04-13 11:48:51 +080012690 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053012691
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012692 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
12693 QWLAN_VERSIONSTR);
12694
Arunk Khandavalli830c9692018-03-22 12:17:40 +053012695 if (!hdd_wait_for_recovery_completion())
12696 return;
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053012697
Will Huangba035ec2018-07-05 11:13:30 +080012698 cds_set_driver_loaded(false);
12699 cds_set_unload_in_progress(true);
12700
12701 if (!cds_wait_for_external_threads_completion(__func__))
12702 hdd_warn("External threads are still active attempting "
12703 "driver unload anyway");
12704
Rajeev Kumar3505ae52018-05-10 18:44:45 -070012705 if (hdd_ctx)
12706 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Will Huang36049722018-04-13 11:48:51 +080012707
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012708 wlan_hdd_unregister_driver();
12709
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012710 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012711
Mukul Sharmad75a6672017-06-22 15:40:53 +053012712 /* Ensure to call prior to objmgr deinit */
12713 component_deinit();
12714
Rajeev Kumar97767a02016-11-30 11:20:40 -080012715 dispatcher_deinit();
Amar Singhal0928b192017-12-01 10:50:54 -080012716
12717 hdd_sysfs_destroy_version_interface();
12718
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012719 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012720 pld_deinit();
12721
Sachin Ahujadddd2632017-03-07 19:07:24 +053012722 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012723}
12724
Arun Khandavallifae92942016-08-01 13:31:08 +053012725#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012726/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012727 * wlan_boot_cb() - Wlan boot callback
12728 * @kobj: object whose directory we're creating the link in.
12729 * @attr: attribute the user is interacting with
12730 * @buff: the buffer containing the user data
12731 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012732 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012733 * This callback is invoked when the fs is ready to start the
12734 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012735 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012736 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012737 */
Arun Khandavallifae92942016-08-01 13:31:08 +053012738static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012739 struct kobj_attribute *attr,
12740 const char *buf,
12741 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012742{
Arun Khandavallifae92942016-08-01 13:31:08 +053012743
Arun Khandavallifae92942016-08-01 13:31:08 +053012744 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012745 pr_err("%s: wlan driver already initialized\n", __func__);
12746 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053012747 }
12748
Arun Khandavallifae92942016-08-01 13:31:08 +053012749 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012750 pr_err("%s: wlan driver initialization failed\n", __func__);
12751 return -EIO;
12752 }
12753
12754 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053012755
12756 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012757}
Arun Khandavallifae92942016-08-01 13:31:08 +053012758
12759/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012760 * hdd_sysfs_cleanup() - cleanup sysfs
12761 *
12762 * Return: None
12763 *
12764 */
12765static void hdd_sysfs_cleanup(void)
12766{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012767 /* remove from group */
12768 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
12769 sysfs_remove_group(wlan_loader->boot_wlan_obj,
12770 wlan_loader->attr_group);
12771
12772 /* unlink the object from parent */
12773 kobject_del(wlan_loader->boot_wlan_obj);
12774
12775 /* free the object */
12776 kobject_put(wlan_loader->boot_wlan_obj);
12777
12778 kfree(wlan_loader->attr_group);
12779 kfree(wlan_loader);
12780
12781 wlan_loader = NULL;
12782}
12783
12784/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012785 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
12786 * ready
12787 *
12788 * This is creates the syfs entry boot_wlan. Which shall be invoked
12789 * when the filesystem is ready.
12790 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012791 * QDF API cannot be used here since this function is called even before
12792 * initializing WLAN driver.
12793 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012794 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053012795 */
12796static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012797{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012798 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012799
12800 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012801 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012802 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012803
12804 wlan_loader->boot_wlan_obj = NULL;
12805 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
12806 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012807 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053012808 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053012809
12810 wlan_loader->loaded_state = 0;
12811 wlan_loader->attr_group->attrs = attrs;
12812
12813 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
12814 kernel_kobj);
12815 if (!wlan_loader->boot_wlan_obj) {
12816 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053012817 goto error_return;
12818 }
12819
12820 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
12821 wlan_loader->attr_group);
12822 if (ret) {
12823 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
12824 goto error_return;
12825 }
12826
12827 return 0;
12828
12829error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012830 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053012831
12832 return ret;
12833}
12834
12835/**
12836 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
12837 *
12838 * Return: 0 on success or errno on failure
12839 */
12840static int wlan_deinit_sysfs(void)
12841{
Arun Khandavallifae92942016-08-01 13:31:08 +053012842 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012843 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053012844 return -EINVAL;
12845 }
12846
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012847 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012848 return 0;
12849}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012850
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012851#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053012852
12853#ifdef MODULE
12854/**
12855 * __hdd_module_init - Module init helper
12856 *
12857 * Module init helper function used by both module and static driver.
12858 *
12859 * Return: 0 for success, errno on failure
12860 */
12861static int hdd_module_init(void)
12862{
Arun Khandavallifae92942016-08-01 13:31:08 +053012863 if (__hdd_module_init()) {
12864 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070012865 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053012866 }
12867
Dustin Brownab482ac2017-06-09 17:00:44 -070012868 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053012869}
12870#else
12871static int __init hdd_module_init(void)
12872{
12873 int ret = -EINVAL;
12874
12875 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012876 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053012877 pr_err("Failed to create sysfs entry for loading wlan");
12878
12879 return ret;
12880}
12881#endif
12882
12883
12884#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012885/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012886 * hdd_module_exit() - Exit function
12887 *
12888 * This is the driver exit point (invoked when module is unloaded using rmmod)
12889 *
12890 * Return: None
12891 */
12892static void __exit hdd_module_exit(void)
12893{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012894 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012895}
Arun Khandavallifae92942016-08-01 13:31:08 +053012896#else
12897static void __exit hdd_module_exit(void)
12898{
12899 __hdd_module_exit();
12900 wlan_deinit_sysfs();
12901}
12902#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012903
Srinivas Girigowda841da292018-02-21 16:33:00 -080012904static int fwpath_changed_handler(const char *kmessage,
12905 const struct kernel_param *kp)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012906{
12907 return param_set_copystring(kmessage, kp);
12908}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012909
Nirav Shah73713f72018-05-17 14:50:41 +053012910#ifdef FEATURE_MONITOR_MODE_SUPPORT
12911static bool is_monitor_mode_supported(void)
12912{
12913 return true;
12914}
12915#else
12916static bool is_monitor_mode_supported(void)
12917{
12918 pr_err("Monitor mode not supported!");
12919 return false;
12920}
12921#endif
12922
12923#ifdef WLAN_FEATURE_EPPING
12924static bool is_epping_mode_supported(void)
12925{
12926 return true;
12927}
12928#else
12929static bool is_epping_mode_supported(void)
12930{
12931 pr_err("Epping mode not supported!");
12932 return false;
12933}
12934#endif
12935
Ryan Hsu6e9db0b2018-06-01 10:45:51 -070012936#ifdef QCA_WIFI_FTM
12937static bool is_ftm_mode_supported(void)
12938{
12939 return true;
12940}
12941#else
12942static bool is_ftm_mode_supported(void)
12943{
12944 pr_err("FTM mode not supported!");
12945 return false;
12946}
12947#endif
12948
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012949/**
12950 * is_con_mode_valid() check con mode is valid or not
12951 * @mode: global con mode
12952 *
12953 * Return: TRUE on success FALSE on failure
12954 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012955static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012956{
12957 switch (mode) {
12958 case QDF_GLOBAL_MONITOR_MODE:
Nirav Shah73713f72018-05-17 14:50:41 +053012959 return is_monitor_mode_supported();
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012960 case QDF_GLOBAL_EPPING_MODE:
Nirav Shah73713f72018-05-17 14:50:41 +053012961 return is_epping_mode_supported();
12962 case QDF_GLOBAL_FTM_MODE:
Ryan Hsu6e9db0b2018-06-01 10:45:51 -070012963 return is_ftm_mode_supported();
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012964 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012965 return true;
12966 default:
12967 return false;
12968 }
12969}
12970
12971/**
12972 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
12973 * @mode: global con mode
12974 *
12975 * Return: adapter mode
12976 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012977static enum QDF_OPMODE hdd_get_adpter_mode(
Jeff Johnson876c1a62017-12-12 10:43:07 -080012978 enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012979{
12980
12981 switch (mode) {
12982 case QDF_GLOBAL_MISSION_MODE:
12983 return QDF_STA_MODE;
12984 case QDF_GLOBAL_MONITOR_MODE:
12985 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012986 case QDF_GLOBAL_EPPING_MODE:
12987 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012988 case QDF_GLOBAL_FTM_MODE:
12989 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012990 case QDF_GLOBAL_QVIT_MODE:
12991 return QDF_QVIT_MODE;
12992 default:
12993 return QDF_MAX_NO_OF_MODE;
12994 }
12995}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012996
Dustin Brown27cd9942017-09-27 16:11:44 -070012997static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012998 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070012999{
13000 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
13001 return;
13002
13003 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070013004 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053013005 hdd_info("Release wakelock for monitor mode!");
13006 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
13007 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
Dundi Raviteja0a2a65b2018-04-30 12:34:11 +053013008 /* fallthrough */
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053013009 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070013010 case QDF_GLOBAL_FTM_MODE:
13011 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +053013012 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Dustin Browndb2a8be2017-12-20 11:49:56 -080013013 hdd_stop_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -070013014
Dustin Brown27cd9942017-09-27 16:11:44 -070013015 break;
13016 default:
13017 break;
13018 }
13019}
13020
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013021static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080013022 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013023{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053013024 int driver_status;
13025
13026 driver_status = hdd_ctx->driver_status;
13027
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013028 switch (curr_mode) {
13029 case QDF_GLOBAL_MISSION_MODE:
13030 case QDF_GLOBAL_MONITOR_MODE:
13031 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013032 hdd_deinit_all_adapters(hdd_ctx, false);
13033 hdd_close_all_adapters(hdd_ctx, false);
13034 break;
13035 case QDF_GLOBAL_EPPING_MODE:
13036 epping_disable();
13037 epping_close();
13038 break;
13039 default:
13040 return;
13041 }
13042}
13043
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013044static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080013045 enum QDF_GLOBAL_MODE mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013046{
Jeff Johnson9d295242017-08-29 14:39:48 -070013047 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013048 int ret = 0;
13049 bool rtnl_held;
13050 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
13051 QDF_STATUS status;
13052
13053 if (!qdf_dev) {
13054 hdd_err("qdf device context is Null return!");
13055 return -EINVAL;
13056 }
13057
13058 rtnl_held = hdd_hold_rtnl_lock();
13059 switch (mode) {
13060 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080013061 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
13062 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013063 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013064 break;
13065 case QDF_GLOBAL_FTM_MODE:
13066 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
13067 wlan_hdd_get_intf_addr(hdd_ctx),
13068 NET_NAME_UNKNOWN, rtnl_held);
13069 if (adapter == NULL)
13070 ret = -EINVAL;
13071 break;
13072 case QDF_GLOBAL_MONITOR_MODE:
13073 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
13074 wlan_hdd_get_intf_addr(hdd_ctx),
13075 NET_NAME_UNKNOWN, rtnl_held);
13076 if (adapter == NULL)
13077 ret = -EINVAL;
13078 break;
13079 case QDF_GLOBAL_EPPING_MODE:
13080 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013081 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013082 hdd_err("Failed to open in eeping mode: %d", status);
13083 ret = -EINVAL;
13084 break;
13085 }
13086 ret = epping_enable(qdf_dev->dev);
13087 if (ret) {
13088 hdd_err("Failed to enable in epping mode : %d", ret);
13089 epping_close();
13090 }
13091 break;
13092 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013093 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013094 ret = -ENOTSUPP;
13095 break;
13096 }
13097 hdd_release_rtnl_lock();
13098 rtnl_held = false;
13099 return ret;
13100}
13101
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013102/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013103 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013104 * @kmessage: con mode name on which driver to be bring up
13105 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013106 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013107 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013108 * This function is invoked when user updates con mode using sys entry,
13109 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013110 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013111 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013112 */
Srinivas Girigowda841da292018-02-21 16:33:00 -080013113static int __con_mode_handler(const char *kmessage,
13114 const struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013115 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013116{
13117 int ret;
Jeff Johnson876c1a62017-12-12 10:43:07 -080013118 enum QDF_GLOBAL_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080013119 enum QDF_OPMODE adapter_mode;
Dustin Brown20024e32018-01-03 12:34:58 -080013120 int new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013121
Dustin Brownab6029b2017-05-24 13:04:19 -070013122 hdd_info("con_mode handler: %s", kmessage);
13123
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013124 ret = wlan_hdd_validate_context(hdd_ctx);
13125 if (ret)
13126 return ret;
13127
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013128 qdf_atomic_set(&hdd_ctx->con_mode_flag, 1);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013129
Dustin Brown20024e32018-01-03 12:34:58 -080013130 ret = kstrtoint(kmessage, 0, &new_con_mode);
13131 if (ret) {
13132 hdd_err("Failed to parse con_mode '%s'", kmessage);
13133 goto reset_flags;
13134 }
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013135 mutex_lock(&hdd_init_deinit_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +053013136
Dustin Brown20024e32018-01-03 12:34:58 -080013137 if (!is_con_mode_valid(new_con_mode)) {
13138 hdd_err("invalid con_mode %d", new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013139 ret = -EINVAL;
13140 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013141 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013142
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013143 curr_mode = hdd_get_conparam();
Dustin Brown20024e32018-01-03 12:34:58 -080013144 if (curr_mode == new_con_mode) {
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013145 hdd_err("curr mode: %d is same as user triggered mode %d",
Dustin Brown20024e32018-01-03 12:34:58 -080013146 curr_mode, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013147 ret = 0;
13148 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013149 }
13150
Dustin Brown27cd9942017-09-27 16:11:44 -070013151 /* ensure adapters are stopped */
13152 hdd_stop_present_mode(hdd_ctx, curr_mode);
13153
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070013154 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053013155 if (ret) {
13156 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013157 goto reset_flags;
13158 }
13159
Dustin Browndd4e50f2018-05-24 15:43:42 -070013160 /* Cleanup present mode before switching to new mode */
13161 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053013162
Dustin Brown20024e32018-01-03 12:34:58 -080013163 hdd_set_conparam(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013164
13165 /* Register for new con_mode & then kick_start modules again */
Dustin Brown20024e32018-01-03 12:34:58 -080013166 ret = hdd_register_req_mode(hdd_ctx, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013167 if (ret) {
13168 hdd_err("Failed to register for new mode");
13169 goto reset_flags;
13170 }
13171
Dustin Brown20024e32018-01-03 12:34:58 -080013172 adapter_mode = hdd_get_adpter_mode(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013173 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
13174 hdd_err("invalid adapter");
13175 ret = -EINVAL;
13176 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053013177 }
13178
Dustin Browne7e71d32018-05-11 16:00:08 -070013179 ret = hdd_wlan_start_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053013180 if (ret) {
13181 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013182 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053013183 }
13184
Dustin Brown20024e32018-01-03 12:34:58 -080013185 if (new_con_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Browne7e71d32018-05-11 16:00:08 -070013186 struct hdd_adapter *adapter =
13187 hdd_get_adapter(hdd_ctx, adapter_mode);
13188
13189 if (!adapter) {
13190 hdd_err("Failed to get adapter:%d", adapter_mode);
13191 goto reset_flags;
13192 }
13193
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013194 if (hdd_start_adapter(adapter)) {
13195 hdd_err("Failed to start %s adapter", kmessage);
13196 ret = -EINVAL;
13197 goto reset_flags;
13198 }
Arun Khandavallifae92942016-08-01 13:31:08 +053013199
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053013200 hdd_info("Acquire wakelock for monitor mode!");
13201 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
13202 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
13203 }
13204
Dustin Brown20024e32018-01-03 12:34:58 -080013205 /* con_mode is a global module parameter */
13206 con_mode = new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013207 hdd_info("Mode successfully changed to %s", kmessage);
13208 ret = 0;
13209
13210reset_flags:
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013211 mutex_unlock(&hdd_init_deinit_lock);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013212 qdf_atomic_set(&hdd_ctx->con_mode_flag, 0);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013213 return ret;
13214}
13215
13216
Srinivas Girigowda841da292018-02-21 16:33:00 -080013217static int con_mode_handler(const char *kmessage, const struct kernel_param *kp)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013218{
13219 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013220 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013221
13222 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13223 ret = wlan_hdd_validate_context(hdd_ctx);
13224 if (ret)
13225 return ret;
13226
Ashish Kumar Dhanotiya759b3272018-05-18 17:49:46 +053013227 if (!cds_wait_for_external_threads_completion(__func__)) {
13228 hdd_warn("External threads are still active, can not change mode");
13229 return -EAGAIN;
13230 }
13231
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013232 cds_ssr_protect(__func__);
13233 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
13234 cds_ssr_unprotect(__func__);
13235
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013236 return ret;
13237}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013238
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013239static int con_mode_handler_ftm(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080013240 const struct kernel_param *kp)
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013241{
13242 int ret;
13243
13244 ret = param_set_int(kmessage, kp);
13245
13246 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
13247 pr_err("Only FTM mode supported!");
13248 return -ENOTSUPP;
13249 }
13250
13251 hdd_set_conparam(con_mode_ftm);
13252 con_mode = con_mode_ftm;
13253
13254 return ret;
13255}
13256
Nirav Shah73713f72018-05-17 14:50:41 +053013257#ifdef FEATURE_MONITOR_MODE_SUPPORT
Ravi Joshia307f632017-07-17 23:41:41 -070013258static int con_mode_handler_monitor(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080013259 const struct kernel_param *kp)
Ravi Joshia307f632017-07-17 23:41:41 -070013260{
13261 int ret;
13262
13263 ret = param_set_int(kmessage, kp);
13264
13265 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
13266 pr_err("Only Monitor mode supported!");
13267 return -ENOTSUPP;
13268 }
13269
13270 hdd_set_conparam(con_mode_monitor);
13271 con_mode = con_mode_monitor;
13272
13273 return ret;
13274}
Nirav Shah73713f72018-05-17 14:50:41 +053013275#endif
Ravi Joshia307f632017-07-17 23:41:41 -070013276
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013277/**
13278 * hdd_get_conparam() - driver exit point
13279 *
13280 * This is the driver exit point (invoked when module is unloaded using rmmod)
13281 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080013282 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013283 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080013284enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013285{
Jeff Johnson876c1a62017-12-12 10:43:07 -080013286 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013287}
13288
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080013289void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013290{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080013291 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013292}
13293
Komal Seelamc11bb222016-01-27 18:57:10 +053013294/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013295 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
13296 * @hdd_ctx: HDD context
13297 *
13298 * Cleans up the pre cac interface, if it exists
13299 *
13300 * Return: None
13301 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013302void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013303{
13304 uint8_t session_id;
13305 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070013306 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013307
Jeff Johnson16528362018-06-14 12:34:16 -070013308 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->mac_handle, &session_id);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013309 if (QDF_IS_STATUS_ERROR(status)) {
13310 hdd_err("failed to get pre cac vdev id");
13311 return;
13312 }
13313
13314 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
13315 if (!precac_adapter) {
Jeff Johnsondd2f1fc2018-05-06 11:22:52 -070013316 hdd_err("invalid pre cac adapter");
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013317 return;
13318 }
13319
13320 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
13321 wlan_hdd_sap_pre_cac_failure,
13322 (void *)precac_adapter);
13323 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
13324
13325}
13326
13327/**
Komal Seelamec702b02016-02-24 18:42:16 +053013328 * hdd_update_ol_config - API to update ol configuration parameters
13329 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053013330 *
Komal Seelamc11bb222016-01-27 18:57:10 +053013331 * Return: void
13332 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013333static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053013334{
Komal Seelamec702b02016-02-24 18:42:16 +053013335 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053013336 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053013337
Komal Seelamec702b02016-02-24 18:42:16 +053013338 if (!ol_ctx)
13339 return;
13340
13341 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
13342 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
13343 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
13344 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070013345 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053013346
13347 ol_init_ini_config(ol_ctx, &cfg);
13348}
13349
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013350#ifdef FEATURE_RUNTIME_PM
13351/**
13352 * hdd_populate_runtime_cfg() - populate runtime configuration
13353 * @hdd_ctx: hdd context
13354 * @cfg: pointer to the configuration memory being populated
13355 *
13356 * Return: void
13357 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013358static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013359 struct hif_config_info *cfg)
13360{
13361 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
13362 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
13363}
13364#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013365static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013366 struct hif_config_info *cfg)
13367{
13368}
13369#endif
13370
Komal Seelamec702b02016-02-24 18:42:16 +053013371/**
13372 * hdd_update_hif_config - API to update HIF configuration parameters
13373 * @hdd_ctx: HDD Context
13374 *
13375 * Return: void
13376 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013377static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053013378{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053013379 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053013380 struct hif_config_info cfg;
13381
13382 if (!scn)
13383 return;
13384
13385 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013386 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053013387 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070013388
13389 if (hdd_ctx->config->prevent_link_down)
13390 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053013391}
13392
13393/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013394 * hdd_update_dp_config() - Propagate config parameters to Lithium
13395 * datapath
13396 * @hdd_ctx: HDD Context
13397 *
13398 * Return: 0 for success/errno for failure
13399 */
13400static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
13401{
13402 struct cdp_config_params params;
13403 QDF_STATUS status;
13404
13405 params.tso_enable = hdd_ctx->config->tso_enable;
13406 params.lro_enable = hdd_ctx->config->lro_enable;
13407#ifdef QCA_LL_TX_FLOW_CONTROL_V2
13408 params.tx_flow_stop_queue_threshold =
13409 hdd_ctx->config->TxFlowStopQueueThreshold;
13410 params.tx_flow_start_queue_offset =
13411 hdd_ctx->config->TxFlowStartQueueOffset;
13412#endif
13413 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
13414 params.napi_enable = hdd_ctx->napi_enable;
13415 params.tcp_udp_checksumoffload =
13416 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
13417
13418 status = cdp_update_config_parameters(
13419 cds_get_context(QDF_MODULE_ID_SOC),
13420 &params);
13421 if (status) {
Dustin Browna2868622018-03-20 11:38:14 -070013422 hdd_err("Failed to attach config parameters");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013423 return status;
13424 }
13425
13426 return 0;
13427}
13428
13429/**
Komal Seelamec702b02016-02-24 18:42:16 +053013430 * hdd_update_config() - Initialize driver per module ini parameters
13431 * @hdd_ctx: HDD Context
13432 *
13433 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013434 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053013435 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013436int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053013437{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013438 int ret;
13439
Komal Seelamec702b02016-02-24 18:42:16 +053013440 hdd_update_ol_config(hdd_ctx);
13441 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013442 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
13443 ret = hdd_update_cds_config_ftm(hdd_ctx);
13444 else
13445 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080013446 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013447
13448 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053013449}
13450
Mukul Sharma9d797a02017-01-05 20:26:03 +053013451#ifdef FEATURE_WLAN_RA_FILTERING
13452/**
13453 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
13454 * @psoc_cfg: pmo psoc Configuration
13455 * @hdd_ctx: Pointer to hdd context
13456 *
13457 * Return: none
13458 */
13459static inline void hdd_ra_populate_pmo_config(
13460 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013461 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013462{
13463 psoc_cfg->ra_ratelimit_interval =
13464 hdd_ctx->config->RArateLimitInterval;
13465 psoc_cfg->ra_ratelimit_enable =
13466 hdd_ctx->config->IsRArateLimitEnabled;
13467}
13468#else
13469static inline void hdd_ra_populate_pmo_config(
13470 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013471 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013472{
13473}
13474#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080013475
Mukul Sharma9d797a02017-01-05 20:26:03 +053013476/**
13477 * hdd_update_pmo_config - API to update pmo configuration parameters
13478 * @hdd_ctx: HDD context
13479 *
13480 * Return: void
13481 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013482static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013483{
Mukul Sharma9d797a02017-01-05 20:26:03 +053013484 struct pmo_psoc_cfg psoc_cfg;
13485 QDF_STATUS status;
13486
13487 /*
13488 * Value of hdd_ctx->wowEnable can be,
13489 * 0 - Disable both magic pattern match and pattern byte match.
13490 * 1 - Enable magic pattern match on all interfaces.
13491 * 2 - Enable pattern byte match on all interfaces.
13492 * 3 - Enable both magic patter and pattern byte match on
13493 * all interfaces.
13494 */
13495 psoc_cfg.magic_ptrn_enable =
13496 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
13497 psoc_cfg.ptrn_match_enable_all_vdev =
13498 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Nachiket Kukadee547a482018-05-22 16:43:30 +053013499 psoc_cfg.apf_enable = hdd_ctx->config->apf_packet_filter_enable;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013500 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Nachiket Kukadef0804072018-02-27 18:20:07 +053013501 psoc_cfg.hw_filter_mode_bitmap = hdd_ctx->config->hw_filter_mode_bitmap;
Dustin Brownb9987af2018-03-01 17:15:11 -080013502 psoc_cfg.ns_offload_enable_dynamic = hdd_ctx->config->fhostNSOffload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013503 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
Dustin Brownb9987af2018-03-01 17:15:11 -080013504 psoc_cfg.packet_filter_enabled = !hdd_ctx->config->disablePacketFilter;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013505 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
13506 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
Dustin Brownb9987af2018-03-01 17:15:11 -080013507 psoc_cfg.active_mode_offload = hdd_ctx->config->active_mode_offload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013508 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080013509 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9223f232017-03-08 18:42:27 +053013510 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
13511 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
13512 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
Dustin Brownb9987af2018-03-01 17:15:11 -080013513 psoc_cfg.power_save_mode = hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053013514 psoc_cfg.auto_power_save_fail_mode =
13515 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013516
13517 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053013518 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013519
Dustin Brownb9987af2018-03-01 17:15:11 -080013520 status = ucfg_pmo_update_psoc_config(hdd_ctx->hdd_psoc, &psoc_cfg);
13521 if (QDF_IS_STATUS_ERROR(status))
13522 hdd_err("failed pmo psoc configuration; status:%d", status);
13523
13524 return qdf_status_to_os_return(status);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013525}
13526
Abhishek Singhb20db962017-03-03 21:28:46 +053013527#ifdef FEATURE_WLAN_SCAN_PNO
13528static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
13529 struct hdd_config *cfg)
13530{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070013531 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
13532
Abhishek Singhb20db962017-03-03 21:28:46 +053013533 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
13534 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
13535 pno_cfg->stationary_thresh = cfg->stationary_thresh;
13536 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
13537 pno_cfg->channel_prediction_full_scan =
13538 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070013539 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
13540 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
13541 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
13542 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053013543}
13544#else
13545static inline void
13546hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070013547 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053013548{
Abhishek Singhb20db962017-03-03 21:28:46 +053013549}
13550#endif
13551
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013552void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
13553 struct hdd_config *cfg)
13554{
13555 uint8_t i = 0;
13556
13557 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
13558 if (!ie_whitelist->white_list)
13559 return;
13560
13561 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
13562 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
13563 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
13564 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
13565 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
13566 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
13567 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
13568 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
13569
13570 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
13571 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
13572 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
13573}
13574
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013575uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
13576{
13577 uint8_t i, score;
13578
13579 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
13580 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
13581 if (score > MAX_INDEX_SCORE)
13582 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
13583 MAX_INDEX_SCORE, i);
13584 }
13585
13586 return per_index_score;
13587}
13588
13589/**
13590 * hdd_update_score_config - API to update candidate scoring related params
13591 * configuration parameters
13592 * @score_config: score config to update
13593 * @cfg: config params
13594 *
13595 * Return: 0 if success else err
13596 */
13597static void hdd_update_score_config(
13598 struct scoring_config *score_config, struct hdd_config *cfg)
13599{
13600 int total_weight;
13601
13602 score_config->weight_cfg.rssi_weightage = cfg->rssi_weightage;
13603 score_config->weight_cfg.ht_caps_weightage = cfg->ht_caps_weightage;
13604 score_config->weight_cfg.vht_caps_weightage =
13605 cfg->vht_caps_weightage;
13606 score_config->weight_cfg.he_caps_weightage =
13607 cfg->he_caps_weightage;
13608 score_config->weight_cfg.chan_width_weightage =
13609 cfg->chan_width_weightage;
13610 score_config->weight_cfg.chan_band_weightage =
13611 cfg->chan_band_weightage;
13612 score_config->weight_cfg.nss_weightage = cfg->nss_weightage;
13613 score_config->weight_cfg.beamforming_cap_weightage =
13614 cfg->beamforming_cap_weightage;
13615 score_config->weight_cfg.pcl_weightage = cfg->pcl_weightage;
13616 score_config->weight_cfg.channel_congestion_weightage =
13617 cfg->channel_congestion_weightage;
13618 score_config->weight_cfg.oce_wan_weightage = cfg->oce_wan_weightage;
13619
13620 total_weight = score_config->weight_cfg.rssi_weightage +
13621 score_config->weight_cfg.ht_caps_weightage +
13622 score_config->weight_cfg.vht_caps_weightage +
13623 score_config->weight_cfg.he_caps_weightage +
13624 score_config->weight_cfg.chan_width_weightage +
13625 score_config->weight_cfg.chan_band_weightage +
13626 score_config->weight_cfg.nss_weightage +
13627 score_config->weight_cfg.beamforming_cap_weightage +
13628 score_config->weight_cfg.pcl_weightage +
13629 score_config->weight_cfg.channel_congestion_weightage +
13630 score_config->weight_cfg.oce_wan_weightage;
13631
13632 if (total_weight > BEST_CANDIDATE_MAX_WEIGHT) {
13633 hdd_err("total weight is greater than %d fallback to default values",
13634 BEST_CANDIDATE_MAX_WEIGHT);
13635
13636 score_config->weight_cfg.rssi_weightage = RSSI_WEIGHTAGE;
13637 score_config->weight_cfg.ht_caps_weightage =
13638 HT_CAPABILITY_WEIGHTAGE;
13639 score_config->weight_cfg.vht_caps_weightage = VHT_CAP_WEIGHTAGE;
13640 score_config->weight_cfg.he_caps_weightage = HE_CAP_WEIGHTAGE;
13641 score_config->weight_cfg.chan_width_weightage =
13642 CHAN_WIDTH_WEIGHTAGE;
13643 score_config->weight_cfg.chan_band_weightage =
13644 CHAN_BAND_WEIGHTAGE;
13645 score_config->weight_cfg.nss_weightage = NSS_WEIGHTAGE;
13646 score_config->weight_cfg.beamforming_cap_weightage =
13647 BEAMFORMING_CAP_WEIGHTAGE;
13648 score_config->weight_cfg.pcl_weightage = PCL_WEIGHT;
13649 score_config->weight_cfg.channel_congestion_weightage =
13650 CHANNEL_CONGESTION_WEIGHTAGE;
13651 score_config->weight_cfg.oce_wan_weightage = OCE_WAN_WEIGHTAGE;
13652 }
13653
13654 score_config->bandwidth_weight_per_index =
13655 hdd_limit_max_per_index_score(
13656 cfg->bandwidth_weight_per_index);
13657 score_config->nss_weight_per_index =
13658 hdd_limit_max_per_index_score(cfg->nss_weight_per_index);
13659 score_config->band_weight_per_index =
13660 hdd_limit_max_per_index_score(cfg->band_weight_per_index);
13661
13662 score_config->rssi_score.best_rssi_threshold =
13663 cfg->best_rssi_threshold;
13664 score_config->rssi_score.good_rssi_threshold =
13665 cfg->good_rssi_threshold;
13666 score_config->rssi_score.bad_rssi_threshold =
13667 cfg->bad_rssi_threshold;
13668 score_config->rssi_score.good_rssi_pcnt = cfg->good_rssi_pcnt;
13669 score_config->rssi_score.bad_rssi_pcnt = cfg->bad_rssi_pcnt;
13670 score_config->rssi_score.good_rssi_bucket_size =
13671 cfg->good_rssi_bucket_size;
13672 score_config->rssi_score.bad_rssi_bucket_size =
13673 cfg->bad_rssi_bucket_size;
13674 score_config->rssi_score.rssi_pref_5g_rssi_thresh =
13675 cfg->rssi_pref_5g_rssi_thresh;
13676
13677 score_config->esp_qbss_scoring.num_slot = cfg->num_esp_qbss_slots;
13678 score_config->esp_qbss_scoring.score_pcnt3_to_0 =
13679 hdd_limit_max_per_index_score(
13680 cfg->esp_qbss_score_slots3_to_0);
13681 score_config->esp_qbss_scoring.score_pcnt7_to_4 =
13682 hdd_limit_max_per_index_score(
13683 cfg->esp_qbss_score_slots7_to_4);
13684 score_config->esp_qbss_scoring.score_pcnt11_to_8 =
13685 hdd_limit_max_per_index_score(
13686 cfg->esp_qbss_score_slots11_to_8);
13687 score_config->esp_qbss_scoring.score_pcnt15_to_12 =
13688 hdd_limit_max_per_index_score(
13689 cfg->esp_qbss_score_slots15_to_12);
13690
13691 score_config->oce_wan_scoring.num_slot = cfg->num_oce_wan_slots;
13692 score_config->oce_wan_scoring.score_pcnt3_to_0 =
13693 hdd_limit_max_per_index_score(
13694 cfg->oce_wan_score_slots3_to_0);
13695 score_config->oce_wan_scoring.score_pcnt7_to_4 =
13696 hdd_limit_max_per_index_score(
13697 cfg->oce_wan_score_slots7_to_4);
13698 score_config->oce_wan_scoring.score_pcnt11_to_8 =
13699 hdd_limit_max_per_index_score(
13700 cfg->oce_wan_score_slots11_to_8);
13701 score_config->oce_wan_scoring.score_pcnt15_to_12 =
13702 hdd_limit_max_per_index_score(
13703 cfg->oce_wan_score_slots15_to_12);
13704
13705
13706 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
13707 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
13708 score_config->nss = cfg->enable2x2 ? 2 : 1;
13709
13710 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
13711 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
13712 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
13713 score_config->he_cap = 1;
13714
13715 if (score_config->he_cap ||
13716 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
13717 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
13718 score_config->vht_cap = 1;
13719
13720 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
13721 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
13722 score_config->ht_cap = 1;
13723
13724 if (score_config->vht_cap && cfg->enableVhtFor24GHzBand)
13725 score_config->vht_24G_cap = 1;
13726
13727 if (cfg->enableTxBF)
13728 score_config->beamformee_cap = 1;
13729
13730}
13731
Abhishek Singh257a9482017-03-06 16:52:39 +053013732/**
bings81fe50a2017-11-27 14:33:26 +080013733 * hdd_update_dfs_config() - API to update dfs configuration parameters.
13734 * @hdd_ctx: HDD context
13735 *
13736 * Return: 0 if success else err
13737 */
13738static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
13739{
13740 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13741 struct hdd_config *cfg = hdd_ctx->config;
13742 struct dfs_user_config dfs_cfg;
13743 QDF_STATUS status;
13744
13745 dfs_cfg.dfs_is_phyerr_filter_offload = !!cfg->fDfsPhyerrFilterOffload;
13746 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
13747 if (QDF_IS_STATUS_ERROR(status)) {
13748 hdd_err("failed dfs psoc configuration");
13749 return -EINVAL;
13750 }
13751
13752 return 0;
13753}
13754
13755/**
Abhishek Singh257a9482017-03-06 16:52:39 +053013756 * hdd_update_scan_config - API to update scan configuration parameters
13757 * @hdd_ctx: HDD context
13758 *
13759 * Return: 0 if success else err
13760 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013761static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053013762{
13763 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13764 struct scan_user_cfg scan_cfg;
13765 struct hdd_config *cfg = hdd_ctx->config;
13766 QDF_STATUS status;
13767
13768 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
13769 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
13770 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
13771 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
13772 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
13773 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
13774 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053013775 /* convert to ms */
13776 scan_cfg.scan_cache_aging_time =
13777 cfg->scanAgingTimeout * 1000;
13778 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
13779 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
13780 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
13781 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053013782 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053013783 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080013784 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
13785 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053013786 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070013787 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singhc87bb042018-01-30 17:10:42 +053013788 scan_cfg.sta_miracast_mcc_rest_time =
13789 cfg->sta_miracast_mcc_rest_time_val;
Abhishek Singh257a9482017-03-06 16:52:39 +053013790
Abhishek Singhb20db962017-03-03 21:28:46 +053013791 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013792 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013793 hdd_update_score_config(&scan_cfg.score_config, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053013794
Abhishek Singh257a9482017-03-06 16:52:39 +053013795 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
13796 if (status != QDF_STATUS_SUCCESS) {
13797 hdd_err("failed pmo psoc configuration");
13798 return -EINVAL;
13799 }
13800
13801 return 0;
13802}
Abhishek Singh257a9482017-03-06 16:52:39 +053013803
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013804int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013805{
13806 int ret;
13807
13808 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053013809 if (ret)
13810 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013811
Abhishek Singh257a9482017-03-06 16:52:39 +053013812 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080013813 if (ret)
13814 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013815
Frank Liud4b2fa02017-03-29 11:46:48 +080013816 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013817 if (ret)
13818 return ret;
13819
13820 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080013821 if (ret)
13822 return ret;
13823
13824 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013825
13826 return ret;
13827}
13828
Agrawal Ashish65634612016-08-18 13:24:32 +053013829/**
13830 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
13831 * @mode : cfg80211 DFS mode
13832 *
13833 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
13834 */
13835enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
13836{
13837 switch (mode) {
13838 case DFS_MODE_ENABLE:
13839 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013840 case DFS_MODE_DISABLE:
13841 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013842 case DFS_MODE_DEPRIORITIZE:
13843 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013844 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013845 hdd_debug("ACS dfs mode is NONE");
13846 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013847 }
13848}
13849
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013850/**
13851 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
13852 * @hddctx: pointer to hdd context
13853 * @set_value: enable/disable
13854 *
13855 * When Host sends vendor command enable, FW will send *ONE* CA ind to
13856 * Host(even though it is duplicate). When Host send vendor command
13857 * disable,FW doesn't perform any action. Whenever any change in
13858 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
13859 *
13860 * return - 0 on success, appropriate error values on failure.
13861 */
Jeff Johnson16528362018-06-14 12:34:16 -070013862int hdd_enable_disable_ca_event(struct hdd_context *hdd_ctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013863{
13864 QDF_STATUS status;
13865
Jeff Johnson16528362018-06-14 12:34:16 -070013866 if (0 != wlan_hdd_validate_context(hdd_ctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013867 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013868
Jeff Johnson16528362018-06-14 12:34:16 -070013869 if (!hdd_ctx->config->goptimize_chan_avoid_event) {
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013870 hdd_warn("goptimize_chan_avoid_event ini param disabled");
13871 return -EINVAL;
13872 }
13873
Jeff Johnson16528362018-06-14 12:34:16 -070013874 status = sme_enable_disable_chanavoidind_event(hdd_ctx->mac_handle,
13875 set_value);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013876 if (!QDF_IS_STATUS_SUCCESS(status)) {
13877 hdd_err("Failed to send chan avoid command to SME");
13878 return -EINVAL;
13879 }
13880 return 0;
13881}
Agrawal Ashish65634612016-08-18 13:24:32 +053013882
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013883/**
13884 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
13885 * @value: value to set
13886 *
13887 * This function will set the passed value to roaming in progress flag.
13888 *
13889 * Return: None
13890 */
13891void hdd_set_roaming_in_progress(bool value)
13892{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013893 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013894
13895 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13896 if (!hdd_ctx) {
13897 hdd_err("HDD context is NULL");
13898 return;
13899 }
13900
13901 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013902 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013903}
13904
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053013905bool hdd_is_roaming_in_progress(struct hdd_context *hdd_ctx)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013906{
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013907 if (!hdd_ctx) {
13908 hdd_err("HDD context is NULL");
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053013909 return false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013910 }
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013911
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053013912 hdd_debug("roaming_in_progress = %d", hdd_ctx->roaming_in_progress);
13913
13914 return hdd_ctx->roaming_in_progress;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013915}
13916
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013917/**
13918 * hdd_is_connection_in_progress() - check if connection is in
13919 * progress
13920 * @session_id: session id
13921 * @reason: scan reject reason
13922 *
13923 * Go through each adapter and check if Connection is in progress
13924 *
13925 * Return: true if connection is in progress else false
13926 */
13927bool hdd_is_connection_in_progress(uint8_t *session_id,
13928 enum scan_reject_states *reason)
13929{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070013930 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070013931 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013932 uint8_t sta_id = 0;
13933 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013934 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -070013935 mac_handle_t mac_handle;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013936
13937 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13938 if (!hdd_ctx) {
13939 hdd_err("HDD context is NULL");
13940 return false;
13941 }
13942
Jeff Johnson16528362018-06-14 12:34:16 -070013943 mac_handle = hdd_ctx->mac_handle;
13944
Dustin Brown920397d2017-12-13 16:27:50 -080013945 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya929afa42018-06-01 15:04:44 -070013946 hdd_debug("Adapter with device mode %s(%d) exists",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013947 hdd_device_mode_to_string(adapter->device_mode),
13948 adapter->device_mode);
13949 if (((QDF_STA_MODE == adapter->device_mode)
13950 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
13951 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
13952 && (eConnectionState_Connecting ==
13953 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
13954 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013955 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013956 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013957 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013958 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013959 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013960 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013961 }
13962 return true;
13963 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013964 /*
13965 * sme_neighbor_middle_of_roaming is for LFR2
13966 * hdd_is_roaming_in_progress is for LFR3
13967 */
13968 if (((QDF_STA_MODE == adapter->device_mode) &&
13969 sme_neighbor_middle_of_roaming(
Jeff Johnson16528362018-06-14 12:34:16 -070013970 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013971 adapter->session_id)) ||
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053013972 hdd_is_roaming_in_progress(hdd_ctx)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013973 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013974 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013975 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013976 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013977 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013978 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013979 }
13980 return true;
13981 }
13982 if ((QDF_STA_MODE == adapter->device_mode) ||
13983 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
13984 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
13985 hdd_sta_ctx =
13986 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
13987 if ((eConnectionState_Associated ==
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053013988 hdd_sta_ctx->conn_info.connState)
13989 && sme_is_sta_key_exchange_in_progress(
Jeff Johnson16528362018-06-14 12:34:16 -070013990 mac_handle, adapter->session_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013991 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070013992 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013993 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013994 " is in middle of WPS/EAPOL exchange.",
13995 MAC_ADDR_ARRAY(sta_mac));
13996 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013997 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013998 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013999 }
14000 return true;
14001 }
14002 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
14003 (QDF_P2P_GO_MODE == adapter->device_mode)) {
14004 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
14005 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014006 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014007 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014008 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014009 continue;
14010
14011 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070014012 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070014013 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014014 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014015 " of SAP/GO is in middle of WPS/EAPOL exchange",
14016 MAC_ADDR_ARRAY(sta_mac));
14017 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070014018 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014019 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014020 }
14021 return true;
14022 }
14023 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053014024 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014025 return true;
14026 }
14027 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014028 }
Dustin Brown920397d2017-12-13 16:27:50 -080014029
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014030 return false;
14031}
14032
14033/**
14034 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070014035 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014036 *
14037 * Return: None
14038 */
Jeff Johnson9d295242017-08-29 14:39:48 -070014039void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014040{
Jeff Johnson87251032017-08-29 13:31:11 -070014041 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070014042 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014043 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014044 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Jeff Johnsone4c11db2018-05-05 23:22:32 -070014045 tsap_config_t *sap_config;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014046 void *sap_ctx;
14047
14048 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070014049 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070014050 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014051
14052 mutex_lock(&hdd_ctx->sap_lock);
14053 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
14054 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014055 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
14056 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
14057 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
14058 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053014059 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014060 qdf_stop_bss_event,
14061 SME_CMD_TIMEOUT_VALUE);
14062
14063 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014064 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014065 goto end;
14066 }
14067 }
14068 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014069 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070014070 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070014071 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014072 false);
Jeff Johnson6867ec32017-09-29 20:30:20 -070014073 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014074
14075 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014076 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014077 wlansap_reset_sap_config_add_ie(sap_config,
14078 eUPDATE_IE_ALL);
14079 goto end;
14080 }
14081
14082 qdf_event_reset(&hostapd_state->qdf_event);
14083 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
14084 sap_config,
14085 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014086 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014087 wlansap_reset_sap_config_add_ie(sap_config,
14088 eUPDATE_IE_ALL);
14089 goto end;
14090 }
14091
Jeff Johnson6867ec32017-09-29 20:30:20 -070014092 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014093 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053014094 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014095 SME_CMD_TIMEOUT_VALUE);
14096 wlansap_reset_sap_config_add_ie(sap_config,
14097 eUPDATE_IE_ALL);
14098 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014099 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014100 goto end;
14101 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070014102 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014103 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014104 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014105 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
14106 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070014107 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070014108 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014109 ap_adapter->device_mode,
14110 true);
14111 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014112 }
14113end:
14114 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014115}
14116
14117/**
14118 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
14119 * with non dfs acs
14120 *
14121 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
14122 *
14123 * Return: None
14124 */
14125void hdd_check_and_restart_sap_with_non_dfs_acs(void)
14126{
Jeff Johnson9d295242017-08-29 14:39:48 -070014127 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014128 struct hdd_context *hdd_ctx;
Jeff Johnson2b6982c2018-05-29 14:56:11 -070014129 struct cds_context *cds_ctx;
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014130 uint8_t restart_chan;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014131
14132 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14133 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014134 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014135 return;
14136 }
14137
14138 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
14139 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014140 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014141 return;
14142 }
14143
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014144 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
14145 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Dustin Brown7e761c72018-07-31 13:50:17 -070014146 hdd_debug("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014147 return;
14148 }
14149
14150 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070014151 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
14152 &ap_adapter->event_flags) &&
14153 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070014154 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014155
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014156 hdd_warn("STA-AP Mode DFS not supported, Switch SAP channel to Non DFS");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014157
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014158 restart_chan =
14159 hdd_get_safe_channel_from_pcl_and_acs_range(ap_adapter);
14160 if (!restart_chan ||
14161 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev, restart_chan))
14162 restart_chan = SAP_DEFAULT_5GHZ_CHANNEL;
14163
14164 hdd_switch_sap_channel(ap_adapter, restart_chan, true);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014165 }
14166}
14167
14168/**
14169 * hdd_set_connection_in_progress() - to set the connection in
14170 * progress flag
14171 * @value: value to set
14172 *
14173 * This function will set the passed value to connection in progress flag.
14174 * If value is previously being set to true then no need to set it again.
14175 *
14176 * Return: true if value is being set correctly and false otherwise.
14177 */
14178bool hdd_set_connection_in_progress(bool value)
14179{
14180 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014181 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014182
14183 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14184 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014185 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014186 return false;
14187 }
14188
14189 qdf_spin_lock(&hdd_ctx->connection_status_lock);
14190 /*
14191 * if the value is set to true previously and if someone is
14192 * trying to make it true again then it could be some race
14193 * condition being triggered. Avoid this situation by returning
14194 * false
14195 */
14196 if (hdd_ctx->connection_in_progress && value)
14197 status = false;
14198 else
14199 hdd_ctx->connection_in_progress = value;
14200 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
14201 return status;
14202}
14203
Jeff Johnson9d295242017-08-29 14:39:48 -070014204int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014205{
14206 if (!adapter) {
14207 hdd_err("Invalid adapter");
14208 return -EINVAL;
14209 }
14210 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070014211 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014212 WMA_VDEV_MCC_SET_TIME_QUOTA,
14213 set_value, VDEV_CMD);
14214 return 0;
14215
14216}
14217
Jeff Johnson9d295242017-08-29 14:39:48 -070014218int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014219{
14220 if (!adapter) {
14221 hdd_err("Invalid adapter");
14222 return -EINVAL;
14223 }
14224
14225 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070014226 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014227 WMA_VDEV_MCC_SET_TIME_LATENCY,
14228 set_value, VDEV_CMD);
14229 return 0;
14230}
14231
Jeff Johnson9d295242017-08-29 14:39:48 -070014232struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070014233 *psoc, uint8_t vdev_id)
14234{
Jeff Johnson9d295242017-08-29 14:39:48 -070014235 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014236 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070014237
14238 /*
14239 * Currently PSOC is not being used. But this logic will
14240 * change once we have the converged implementation of
14241 * HDD context per PSOC in place. This would break if
14242 * multiple vdev objects reuse the vdev id.
14243 */
14244 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
14245 if (!adapter)
14246 hdd_err("Get adapter by vdev id failed");
14247
14248 return adapter;
14249}
14250
Jeff Johnson9d295242017-08-29 14:39:48 -070014251int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014252 int8_t *rssi, int8_t *snr)
14253{
14254 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -070014255 mac_handle_t mac_handle;
Jeff Johnson025618c2018-03-18 14:41:00 -070014256 struct csr_roam_profile *roam_profile;
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014257
Jeff Johnson025618c2018-03-18 14:41:00 -070014258 roam_profile = hdd_roam_profile(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -070014259 mac_handle = hdd_adapter_get_mac_handle(adapter);
14260 status = sme_get_rssi_snr_by_bssid(mac_handle,
Jeff Johnson025618c2018-03-18 14:41:00 -070014261 roam_profile, bssid, rssi, snr);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014262 if (QDF_STATUS_SUCCESS != status) {
14263 hdd_warn("sme_get_rssi_snr_by_bssid failed");
14264 return -EINVAL;
14265 }
14266
14267 return 0;
14268}
14269
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014270/**
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014271 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
14272 * @adapter - HDD adapter
14273 *
14274 * Return: 0 on success and non zero value on failure
14275 */
14276int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
14277{
14278 struct hdd_context *hdd_ctx;
14279 int ret;
14280 QDF_STATUS status;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014281
14282 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
14283 ret = wlan_hdd_validate_context(hdd_ctx);
14284 if (ret < 0)
14285 return ret;
14286
14287 /* set the system preferece to default */
14288 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
14289 hdd_ctx->config->conc_system_pref);
14290
14291 /* clear the bitmap */
14292 adapter->active_ac = 0;
14293
14294 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson16528362018-06-14 12:34:16 -070014295 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014296
Jeff Johnson16528362018-06-14 12:34:16 -070014297 status = sme_send_limit_off_channel_params(hdd_ctx->mac_handle,
14298 adapter->session_id,
14299 false, 0, 0, false);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014300 if (!QDF_IS_STATUS_SUCCESS(status)) {
14301 hdd_err("failed to reset limit off chan params");
14302 ret = -EINVAL;
14303 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014304
14305 return ret;
14306}
14307
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014308/**
14309 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
14310 * @drv_op: Enum indicating driver op
14311 *
14312 * Return: none
14313 */
14314void hdd_start_driver_ops_timer(int drv_op)
14315{
14316 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
14317 switch (drv_op) {
14318 case eHDD_DRV_OP_PROBE:
14319 memcpy(drv_ops_string, "probe", sizeof("probe"));
14320 break;
14321 case eHDD_DRV_OP_REMOVE:
14322 memcpy(drv_ops_string, "remove", sizeof("remove"));
14323 break;
14324 case eHDD_DRV_OP_SHUTDOWN:
14325 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
14326 break;
14327 case eHDD_DRV_OP_REINIT:
14328 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
14329 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053014330 case eHDD_DRV_OP_IFF_UP:
14331 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
14332 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014333 }
14334
Dustin Brown45ed4bb2017-12-18 12:00:13 -080014335 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014336 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
Dustin Browncfc54fe2018-06-18 16:17:41 -070014337 HDD_OPS_INACTIVITY_TIMEOUT * qdf_timer_get_multiplier());
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014338}
14339
14340/**
14341 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
14342 *
14343 * Return: none
14344 */
14345void hdd_stop_driver_ops_timer(void)
14346{
14347 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
14348}
14349
14350/**
14351 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
14352 * inactivity timer
14353 *
14354 * Return: None
14355 */
14356void hdd_drv_ops_inactivity_handler(void)
14357{
Rajeev Kumar4471f1b2018-06-08 14:18:28 -070014358 hdd_err("WLAN_BUG_RCA %s: %d Sec timer expired while in .%s",
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014359 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
14360
Dustin Brown45ed4bb2017-12-18 12:00:13 -080014361 if (hdd_drv_ops_task) {
14362 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
14363 qdf_print_thread_trace(hdd_drv_ops_task);
14364 } else {
14365 hdd_err("hdd_drv_ops_task is null");
14366 }
14367
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014368 /* Driver shutdown is stuck, no recovery possible at this point */
14369 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
14370 sizeof("shutdown")))
14371 QDF_BUG(0);
14372
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080014373 if (cds_is_fw_down()) {
14374 hdd_err("FW is down");
14375 return;
14376 }
14377
Dustin Brown83044c22018-08-13 15:00:44 -070014378 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014379}
14380
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053014381void hdd_pld_ipa_uc_shutdown_pipes(void)
14382{
14383 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14384
14385 if (!hdd_ctx)
14386 return;
14387
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +053014388 ucfg_ipa_uc_force_pipe_shutdown(hdd_ctx->hdd_pdev);
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053014389}
14390
Yun Parkff6a16a2017-09-26 16:38:18 -070014391/**
14392 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
14393 * @struct hdd_context *hdd_ctx
14394 * @struct hdd_adapter *padapter
14395 * @bool enble
14396 *
14397 * Return: none
14398 */
14399void hdd_set_rx_mode_rps(bool enable)
14400{
14401 struct cds_config_info *cds_cfg = cds_get_ini_config();
Ryan Hsu0e878fa2018-05-04 15:22:09 -070014402 struct hdd_context *hdd_ctx;
14403 struct hdd_adapter *adapter;
Yun Parkff6a16a2017-09-26 16:38:18 -070014404
Ryan Hsu0e878fa2018-05-04 15:22:09 -070014405 if (!cds_cfg)
14406 return;
14407
14408 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14409 if (!hdd_ctx)
14410 return;
14411
14412 adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
14413 if (!adapter)
14414 return;
14415
14416 if (!hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
Yun Parkff6a16a2017-09-26 16:38:18 -070014417 if (enable && !cds_cfg->rps_enabled)
14418 hdd_send_rps_ind(adapter);
14419 else if (!enable && cds_cfg->rps_enabled)
14420 hdd_send_rps_disable_ind(adapter);
14421 }
14422}
14423
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +053014424bool hdd_is_cli_iface_up(struct hdd_context *hdd_ctx)
14425{
14426 struct hdd_adapter *adapter = NULL;
14427
14428 hdd_for_each_adapter(hdd_ctx, adapter) {
14429 if ((adapter->device_mode == QDF_STA_MODE ||
14430 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
14431 qdf_atomic_test_bit(DEVICE_IFACE_OPENED,
14432 &adapter->event_flags)){
14433 return true;
14434 }
14435 }
14436
14437 return false;
14438}
14439
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014440/* Register the module init/exit functions */
14441module_init(hdd_module_init);
14442module_exit(hdd_module_exit);
14443
14444MODULE_LICENSE("Dual BSD/GPL");
14445MODULE_AUTHOR("Qualcomm Atheros, Inc.");
14446MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
14447
Srinivas Girigowda841da292018-02-21 16:33:00 -080014448static const struct kernel_param_ops con_mode_ops = {
14449 .set = con_mode_handler,
14450 .get = param_get_int,
14451};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014452
Srinivas Girigowda841da292018-02-21 16:33:00 -080014453static const struct kernel_param_ops con_mode_ftm_ops = {
14454 .set = con_mode_handler_ftm,
14455 .get = param_get_int,
14456};
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053014457
Nirav Shah73713f72018-05-17 14:50:41 +053014458#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080014459static const struct kernel_param_ops con_mode_monitor_ops = {
14460 .set = con_mode_handler_monitor,
14461 .get = param_get_int,
14462};
Nirav Shah73713f72018-05-17 14:50:41 +053014463#endif
Ravi Joshia307f632017-07-17 23:41:41 -070014464
Srinivas Girigowda841da292018-02-21 16:33:00 -080014465static const struct kernel_param_ops fwpath_ops = {
14466 .set = fwpath_changed_handler,
14467 .get = param_get_string,
14468};
14469
14470module_param_cb(con_mode, &con_mode_ops, &con_mode,
14471 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
14472
14473module_param_cb(con_mode_ftm, &con_mode_ftm_ops, &con_mode_ftm,
14474 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
14475
Nirav Shah73713f72018-05-17 14:50:41 +053014476#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080014477module_param_cb(con_mode_monitor, &con_mode_monitor_ops, &con_mode_monitor,
14478 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Nirav Shah73713f72018-05-17 14:50:41 +053014479#endif
Srinivas Girigowda841da292018-02-21 16:33:00 -080014480
14481module_param_cb(fwpath, &fwpath_ops, &fwpath,
14482 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014483
14484module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
14485
14486module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
14487
14488module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);