blob: b838c9f8f902a76deabc2a7b67578e19fa43e3a9 [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"
94#include "wlan_hdd_driver_ops.h"
95#include "epping_main.h"
Poddar, Siddarth34872782017-08-10 14:08:51 +053096#include "wlan_hdd_data_stall_detection.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080097
98#include <wlan_hdd_ipa.h>
99#include "hif.h"
100#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800101#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700102#include "wlan_hdd_tsf.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530103#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700104#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700105#include "wlan_hdd_lpass.h"
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530106#include "nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700107#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530108#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800109#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800110#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530111#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800112#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800113#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530114#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530115#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800116#include "os_if_wifi_pos.h"
117#include "wifi_pos_api.h"
118#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800119#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700120#include "os_if_nan.h"
121#include "nan_public_structs.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700122#include "wlan_reg_ucfg_api.h"
bings81fe50a2017-11-27 14:33:26 +0800123#include "wlan_dfs_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700124#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530125#include "sme_power_save_api.h"
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +0530126#include "enet.h"
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700127#include <cdp_txrx_cmn_struct.h>
Mohit Khanna70322002018-05-15 19:21:32 -0700128#include <dp_txrx.h>
Amar Singhal0928b192017-12-01 10:50:54 -0800129#include "wlan_hdd_sysfs.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530130#include "wlan_disa_ucfg_api.h"
Wu Gao52084c12018-05-17 20:47:11 +0800131#include "wlan_disa_obj_mgmt_api.h"
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +0530132#include "wlan_action_oui_ucfg_api.h"
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +0530133#include "wlan_ipa_ucfg_api.h"
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530134#include <target_if.h>
Alok Kumarb64650c2018-03-23 17:05:11 +0530135#include "wlan_hdd_nud_tracking.h"
Nachiket Kukaded0dd62e2018-05-21 18:39:22 +0530136#include "wlan_hdd_apf.h"
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -0700137#include "wlan_hdd_twt.h"
Rachit Kankane0dc3e852018-05-07 17:33:42 +0530138#include "qc_sap_ioctl.h"
Sandeep Puligillac5609d52018-05-17 19:23:41 -0700139#include "wlan_mlme_main.h"
Wu Gaoe5689792018-07-05 19:20:13 +0800140#include "wlan_p2p_cfg_api.h"
Wu Gaobdb7f272018-07-05 19:33:26 +0800141#include "wlan_tdls_cfg_api.h"
Qiwei Caie689a262018-07-26 15:50:22 +0800142#include <wlan_hdd_rssi_monitor.h>
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +0530143#include "wlan_mlme_ucfg_api.h"
144#include "wlan_mlme_public_struct.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530145#ifdef CNSS_GENL
146#include <net/cnss_nl.h>
147#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800148#include "wlan_reg_ucfg_api.h"
Zhang Qian47e22ce2018-01-04 15:38:38 +0800149#include "wlan_ocb_ucfg_api.h"
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -0800150#include <wlan_hdd_spectralscan.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800151#ifdef MODULE
152#define WLAN_MODULE_NAME module_name(THIS_MODULE)
153#else
154#define WLAN_MODULE_NAME "wlan"
155#endif
156
157#ifdef TIMER_MANAGER
158#define TIMER_MANAGER_STR " +TIMER_MANAGER"
159#else
160#define TIMER_MANAGER_STR ""
161#endif
162
163#ifdef MEMORY_DEBUG
164#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
165#else
166#define MEMORY_DEBUG_STR ""
167#endif
168
Dustin Brownc1034df2018-02-07 14:51:32 -0800169#ifdef PANIC_ON_BUG
170#define PANIC_ON_BUG_STR " +PANIC_ON_BUG"
171#else
172#define PANIC_ON_BUG_STR ""
173#endif
174
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530175bool g_is_system_reboot_triggered;
Sachin Ahujadddd2632017-03-07 19:07:24 +0530176int wlan_start_ret_val;
177static DECLARE_COMPLETION(wlan_start_comp);
178static unsigned int dev_num = 1;
179static struct cdev wlan_hdd_state_cdev;
180static struct class *class;
181static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530182#ifndef MODULE
183static struct gwlan_loader *wlan_loader;
184static ssize_t wlan_boot_cb(struct kobject *kobj,
185 struct kobj_attribute *attr,
186 const char *buf, size_t count);
187struct gwlan_loader {
188 bool loaded_state;
189 struct kobject *boot_wlan_obj;
190 struct attribute_group *attr_group;
191};
192
193static struct kobj_attribute wlan_boot_attribute =
194 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
195
196static struct attribute *attrs[] = {
197 &wlan_boot_attribute.attr,
198 NULL,
199};
200
201#define MODULE_INITIALIZED 1
202#endif
203
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530204#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
205#define MAX_OPS_NAME_STRING_SIZE 20
Rajeev Kumar6d0b2ea2017-12-26 17:55:33 -0800206#define RATE_LIMIT_ERROR_LOG (256)
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530207
208static qdf_timer_t hdd_drv_ops_inactivity_timer;
Dustin Brown45ed4bb2017-12-18 12:00:13 -0800209static struct task_struct *hdd_drv_ops_task;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530210static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
211
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800212/* the Android framework expects this param even though we don't use it */
213#define BUF_LEN 20
214static char fwpath_buffer[BUF_LEN];
215static struct kparam_string fwpath = {
216 .string = fwpath_buffer,
217 .maxlen = BUF_LEN,
218};
219
220static char *country_code;
221static int enable_11d = -1;
222static int enable_dfs_chan_scan = -1;
223
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800224/*
225 * spinlock for synchronizing asynchronous request/response
226 * (full description of use in wlan_hdd_main.h)
227 */
228DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530229DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800230
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800231#define WLAN_NLINK_CESIUM 30
232
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530233static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800234
235#define WOW_MAX_FILTER_LISTS 1
236#define WOW_MAX_FILTERS_PER_LIST 4
237#define WOW_MIN_PATTERN_SIZE 6
238#define WOW_MAX_PATTERN_SIZE 64
239
Bala Venkatesh110b03e2018-07-10 16:02:08 +0530240/* max peer can be tdls peers + self peer + bss peer */
241#define HDD_MAX_VDEV_PEER_COUNT (HDD_MAX_NUM_TDLS_STA + 2)
Sourav Mohapatra808e3d42018-07-04 09:34:23 +0530242#define IS_IDLE_STOP (!cds_is_driver_unloading() && \
243 !cds_is_driver_recovering() && !cds_is_driver_loading())
Bala Venkatesh110b03e2018-07-10 16:02:08 +0530244
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800245#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
246static const struct wiphy_wowlan_support wowlan_support_reg_init = {
247 .flags = WIPHY_WOWLAN_ANY |
248 WIPHY_WOWLAN_MAGIC_PKT |
249 WIPHY_WOWLAN_DISCONNECT |
250 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
251 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
252 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
253 WIPHY_WOWLAN_4WAY_HANDSHAKE |
254 WIPHY_WOWLAN_RFKILL_RELEASE,
255 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
256 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
257 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
258};
259#endif
260
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700261static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
262 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
263 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
264 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
265 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
266 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
267 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
268 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
269 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
270 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
271 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
272 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
273 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
274 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
275 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
276 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
277 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
278 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
279 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
280 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
281 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
282 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
283 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
284 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
285 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
286 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
287 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
288 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
289 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
290 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
291 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
292 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
293 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
294 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
295 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700296 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700297 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700298 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530299 [QDF_MODULE_ID_GREEN_AP] = {QDF_TRACE_LEVEL_ALL},
Zhang Qian47e22ce2018-01-04 15:38:38 +0800300 [QDF_MODULE_ID_OCB] = {QDF_TRACE_LEVEL_ALL},
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530301 [QDF_MODULE_ID_IPA] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +0530302 [QDF_MODULE_ID_ACTION_OUI] = {QDF_TRACE_LEVEL_ALL},
Dustin Brown84f46ea2018-02-15 11:57:36 -0800303 [QDF_MODULE_ID_CONFIG] = {QDF_TRACE_LEVEL_ALL},
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +0530304 [QDF_MODULE_ID_MLME] = {QDF_TRACE_LEVEL_ALL},
Ashish Kumar Dhanotiya8d039c82018-07-11 20:41:14 +0530305 [QDF_MODULE_ID_TARGET] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700306};
307
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530308struct notifier_block hdd_netdev_notifier;
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530309struct notifier_block system_reboot_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800310
311struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800312#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700313static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800314#endif
315
Sachin Ahujadddd2632017-03-07 19:07:24 +0530316void hdd_start_complete(int ret)
317{
318 wlan_start_ret_val = ret;
319
320 complete(&wlan_start_comp);
321}
322
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800323/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530324 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700325 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530326 *
327 * Return: none
328 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700329static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530330{
Jeff Johnson9d295242017-08-29 14:39:48 -0700331 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530332
Dustin Brown920397d2017-12-13 16:27:50 -0800333 hdd_for_each_adapter(hdd_ctx, adapter)
334 hdd_send_rps_ind(adapter);
Nirav Shahbd36b062016-07-18 11:12:59 +0530335}
336
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530337#ifdef QCA_HL_NETDEV_FLOW_CONTROL
338void wlan_hdd_mod_fc_timer(struct hdd_adapter *adapter,
339 enum netif_action_type action)
340{
341 if (!adapter->tx_flow_timer_initialized)
342 return;
343
344 if (action == WLAN_WAKE_NON_PRIORITY_QUEUE) {
345 qdf_mc_timer_stop(&adapter->tx_flow_control_timer);
346 } else if (action == WLAN_STOP_NON_PRIORITY_QUEUE) {
347 QDF_STATUS status =
348 qdf_mc_timer_start(&adapter->tx_flow_control_timer,
349 WLAN_HDD_TX_FLOW_CONTROL_OS_Q_BLOCK_TIME);
350
351 if (!QDF_IS_STATUS_SUCCESS(status))
352 hdd_err("Failed to start tx_flow_control_timer");
353 else
354 adapter->
355 hdd_stats.tx_rx_stats.txflow_timer_cnt++;
356
357 adapter->hdd_stats.tx_rx_stats.txflow_pause_cnt++;
358 adapter->hdd_stats.tx_rx_stats.is_txflow_paused = true;
359 }
360}
361#endif /* QCA_HL_NETDEV_FLOW_CONTROL */
362
Nirav Shahbd36b062016-07-18 11:12:59 +0530363/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800364 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
365 * @vdev_id: vdev_id
366 * @action: action type
367 * @reason: reason type
368 *
369 * Return: none
370 */
371void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
372 enum netif_action_type action, enum netif_reason_type reason)
373{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700374 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700375 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800376
377 if (!hdd_ctx) {
378 hdd_err("hdd ctx is NULL");
379 return;
380 }
381 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530382 wlan_hdd_mod_fc_timer(adapter, action);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800383 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800384}
385
386/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700387 * Store WLAN driver version and timestamp info in global variables such that
388 * crash debugger can extract them from driver debug symbol and crashdump for
389 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800390 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800391#ifdef BUILD_TAG
392uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR "; " BUILD_TAG;
393#else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800394uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700395#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800396
397/**
398 * hdd_device_mode_to_string() - return string conversion of device mode
399 * @device_mode: device mode
400 *
401 * This utility function helps log string conversion of device mode.
402 *
403 * Return: string conversion of device mode, if match found;
404 * "Unknown" otherwise.
405 */
406const char *hdd_device_mode_to_string(uint8_t device_mode)
407{
408 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800409 CASE_RETURN_STRING(QDF_STA_MODE);
410 CASE_RETURN_STRING(QDF_SAP_MODE);
411 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
412 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
413 CASE_RETURN_STRING(QDF_FTM_MODE);
414 CASE_RETURN_STRING(QDF_IBSS_MODE);
415 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
416 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700417 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800418 default:
419 return "Unknown";
420 }
421}
422
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530423/**
Liangwei Dong17bf2662018-01-05 02:02:05 -0500424 * hdd_get_valid_chan() - return current chan list from regulatory.
425 * @hdd_ctx: HDD context
426 * @chan_list: buf hold returned chan list
427 * @chan_num: input buf size and output returned chan num
428 *
429 * This function helps get current available chan list from regulatory
430 * module. It excludes the "disabled" and "invalid" channels.
431 *
432 * Return: 0 for success.
433 */
434static int hdd_get_valid_chan(struct hdd_context *hdd_ctx,
435 uint8_t *chan_list,
436 uint32_t *chan_num)
437{
438 int i = 0, j = 0;
439 struct regulatory_channel *cur_chan_list;
440 struct wlan_objmgr_pdev *pdev;
441
442 if (!hdd_ctx || !hdd_ctx->hdd_pdev || !chan_list || !chan_num)
443 return -EINVAL;
444
445 pdev = hdd_ctx->hdd_pdev;
446 cur_chan_list = qdf_mem_malloc(NUM_CHANNELS *
447 sizeof(struct regulatory_channel));
448 if (!cur_chan_list)
449 return -ENOMEM;
450
451 if (wlan_reg_get_current_chan_list(pdev, cur_chan_list) !=
452 QDF_STATUS_SUCCESS) {
453 qdf_mem_free(cur_chan_list);
454 return -EINVAL;
455 }
456
457 for (i = 0; i < NUM_CHANNELS; i++) {
458 uint32_t ch = cur_chan_list[i].chan_num;
459 enum channel_state state = wlan_reg_get_channel_state(pdev,
460 ch);
461
462 if (state != CHANNEL_STATE_DISABLE &&
463 state != CHANNEL_STATE_INVALID &&
464 j < *chan_num) {
465 chan_list[j] = (uint8_t)ch;
466 j++;
467 }
468 }
469 *chan_num = j;
470 qdf_mem_free(cur_chan_list);
471 return 0;
472}
473
474/**
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530475 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
476 * @adapter: HDD adapter
477 * @chan_number: Channel number
478 * @chan_bw: Bandwidth
479 *
480 * Checks if the given bandwidth is valid for the given channel number.
481 *
482 * Return: 0 for success, non-zero for failure
483 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700484int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530485 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800486 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530487{
Liangwei Dong17bf2662018-01-05 02:02:05 -0500488 uint8_t chan[NUM_CHANNELS];
489 uint32_t len = NUM_CHANNELS, i;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530490 bool found = false;
Jeff Johnson16528362018-06-14 12:34:16 -0700491 mac_handle_t mac_handle;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500492 int ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530493
Jeff Johnson16528362018-06-14 12:34:16 -0700494 mac_handle = hdd_adapter_get_mac_handle(adapter);
495 if (!mac_handle) {
496 hdd_err("Invalid MAC handle");
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530497 return -EINVAL;
498 }
499
Liangwei Dong17bf2662018-01-05 02:02:05 -0500500 ret = hdd_get_valid_chan(adapter->hdd_ctx, chan,
501 &len);
502 if (ret) {
503 hdd_err("error %d in getting valid channel list", ret);
504 return ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530505 }
506
507 for (i = 0; i < len; i++) {
508 if (chan[i] == chan_number) {
509 found = true;
510 break;
511 }
512 }
513
514 if (found == false) {
515 hdd_err("Channel not in driver's valid channel list");
516 return -EOPNOTSUPP;
517 }
518
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700519 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
520 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530521 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
522 return -EINVAL;
523 }
524
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700525 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530526 if (chan_bw == CH_WIDTH_80MHZ) {
527 hdd_err("BW80 not possible in 2.4GHz band");
528 return -EINVAL;
529 }
530 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
531 (chan_bw != CH_WIDTH_MAX)) {
532 hdd_err("Only BW20 possible on channel 14");
533 return -EINVAL;
534 }
535 }
536
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700537 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530538 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
539 (chan_bw != CH_WIDTH_MAX)) {
540 hdd_err("Only BW20 possible on channel 165");
541 return -EINVAL;
542 }
543 }
544
545 return 0;
546}
547
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530548/**
549 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
550 *
551 * Block the unloading of the driver (or) interface up until the
552 * cds recovery is completed
553 *
554 * Return: true for recovery completion else false
555 */
556static bool hdd_wait_for_recovery_completion(void)
557{
558 int retry = 0;
559
560 /* Wait for recovery to complete */
561 while (cds_is_driver_recovering()) {
562 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
563 hdd_err("Recovery in progress; wait here!!!");
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530564
565 if (g_is_system_reboot_triggered) {
566 hdd_info("System Reboot happening ignore unload!!");
567 return false;
568 }
569
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530570 msleep(1000);
571 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
572 hdd_err("SSR never completed, error");
573 /*
574 * Trigger the bug_on in the internal builds, in the
575 * customer builds self-recovery will be enabled
576 * in those cases just return error.
577 */
578 if (cds_is_self_recovery_enabled())
579 return false;
580 QDF_BUG(0);
581 }
582 }
583
584 hdd_info("Recovery completed successfully!");
585 return true;
586}
587
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530588
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800589static int __hdd_netdev_notifier_call(struct notifier_block *nb,
590 unsigned long state, void *data)
591{
592#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
593 struct netdev_notifier_info *dev_notif_info = data;
594 struct net_device *dev = dev_notif_info->dev;
595#else
596 struct net_device *dev = data;
597#endif
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530598 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700599 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800600
Dustin Brownfdf17c12018-03-14 12:55:34 -0700601 hdd_enter_dev(dev);
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800602
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800603 if (!dev->ieee80211_ptr) {
Dustin Brownaeb55642018-07-30 17:20:32 -0700604 hdd_debug("ieee80211_ptr is null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800605 return NOTIFY_DONE;
606 }
607
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530608 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
609 if (!hdd_ctx) {
610 hdd_err("HDD Context is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800611 return NOTIFY_DONE;
612 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800613
614 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -0700615 hdd_debug("%s: Driver module is closed", __func__);
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800616 return NOTIFY_DONE;
617 }
618
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530619 /* Make sure that this callback corresponds to our device. */
620 adapter = hdd_get_adapter_by_iface_name(hdd_ctx, dev->name);
621 if (!adapter) {
Dustin Brownaeb55642018-07-30 17:20:32 -0700622 hdd_debug("failed to look up adapter for '%s'", dev->name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800623 return NOTIFY_DONE;
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530624 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800625
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530626 if (adapter != WLAN_HDD_GET_PRIV_PTR(dev)) {
627 hdd_err("HDD adapter mismatch!");
628 return NOTIFY_DONE;
629 }
630
Dustin Brownaeb55642018-07-30 17:20:32 -0700631 if (cds_is_driver_recovering()) {
632 hdd_debug("Driver is recovering");
633 return NOTIFY_DONE;
634 }
635
636 if (cds_is_driver_in_bad_state()) {
637 hdd_debug("Driver is in failed recovery state");
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530638 return NOTIFY_DONE;
639 }
640
641 hdd_debug("%s New Net Device State = %lu", dev->name, state);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800642
643 switch (state) {
644 case NETDEV_REGISTER:
645 break;
646
647 case NETDEV_UNREGISTER:
648 break;
649
650 case NETDEV_UP:
Jeff Johnson16528362018-06-14 12:34:16 -0700651 sme_ch_avoid_update_req(hdd_ctx->mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800652 break;
653
654 case NETDEV_DOWN:
655 break;
656
657 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700658 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800659 complete(&adapter->linkup_event_var);
660 break;
661
662 case NETDEV_GOING_DOWN:
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700663 if (ucfg_scan_get_vdev_status(adapter->hdd_vdev) !=
664 SCAN_NOT_IN_PROGRESS) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530665 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -0700666 adapter->session_id, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800667 }
Min Liu9be5d4a2018-05-17 11:51:53 +0800668 cds_flush_work(&adapter->scan_block_work);
669 /* Need to clean up blocked scan request */
670 wlan_hdd_cfg80211_scan_block_cb(&adapter->scan_block_work);
Min Liu9be5d4a2018-05-17 11:51:53 +0800671 hdd_debug("Scan is not Pending from user");
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530672 /*
673 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
674 * of return status of hdd_stop call, kernel resets the IFF_UP
675 * flag after which driver does not send the cfg80211_scan_done.
676 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
677 */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +0530678 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800679 break;
680
681 default:
682 break;
683 }
684
685 return NOTIFY_DONE;
686}
687
688/**
689 * hdd_netdev_notifier_call() - netdev notifier callback function
690 * @nb: pointer to notifier block
691 * @state: state
692 * @ndev: ndev pointer
693 *
694 * Return: 0 on success, error number otherwise.
695 */
696static int hdd_netdev_notifier_call(struct notifier_block *nb,
697 unsigned long state,
698 void *ndev)
699{
700 int ret;
701
702 cds_ssr_protect(__func__);
703 ret = __hdd_netdev_notifier_call(nb, state, ndev);
704 cds_ssr_unprotect(__func__);
705
706 return ret;
707}
708
709struct notifier_block hdd_netdev_notifier = {
710 .notifier_call = hdd_netdev_notifier_call,
711};
712
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530713static int system_reboot_notifier_call(struct notifier_block *nb,
714 unsigned long msg_type, void *_unused)
715{
716 switch (msg_type) {
717 case SYS_DOWN:
718 case SYS_HALT:
719 case SYS_POWER_OFF:
720 g_is_system_reboot_triggered = true;
721 hdd_info("reboot, reason: %ld", msg_type);
722 break;
723 default:
724 break;
725 }
726
727 return NOTIFY_OK;
728}
729
730struct notifier_block system_reboot_notifier = {
731 .notifier_call = system_reboot_notifier_call,
732};
733
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800734/* variable to hold the insmod parameters */
735static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800736
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530737static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700738int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530739
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800740/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800741static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800742
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530743/**
744 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
745 * @ch_width: NL channel width
746 *
747 * Converts the NL channel width to the driver's internal representation
748 *
749 * Return: Converted channel width. In case of non matching NL channel width,
750 * CH_WIDTH_MAX will be returned.
751 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800752enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530753{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800754 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700755
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800756 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530757 switch (ch_width) {
758 case NL80211_CHAN_WIDTH_20_NOHT:
759 case NL80211_CHAN_WIDTH_20:
760 return CH_WIDTH_20MHZ;
761 case NL80211_CHAN_WIDTH_40:
762 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530763 case NL80211_CHAN_WIDTH_80:
764 return CH_WIDTH_80MHZ;
765 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800766 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
767 return CH_WIDTH_80P80MHZ;
768 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
769 return CH_WIDTH_160MHZ;
770 else
771 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530772 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800773 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
774 return CH_WIDTH_160MHZ;
775 else
776 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530777 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800778 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530779 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800780 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530781 default:
782 hdd_err("Invalid channel width %d, setting to default",
783 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800784 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530785 }
786}
787
Jeff Johnson16528362018-06-14 12:34:16 -0700788uint8_t wlan_hdd_find_opclass(mac_handle_t mac_handle, uint8_t channel,
789 uint8_t bw_offset)
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530790{
791 uint8_t opclass = 0;
792
Jeff Johnson16528362018-06-14 12:34:16 -0700793 sme_get_opclass(mac_handle, channel, bw_offset, &opclass);
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530794 return opclass;
795}
796
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800797/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530798 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530799 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800800 * @bitmask: Bitmask of log levels to be enabled
801 *
802 * Called immediately after the cfg.ini is read in order to configure
803 * the desired trace levels.
804 *
805 * Return: None
806 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530807int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800808{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530809 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530810 int qdf_print_idx = -1;
811 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800812 /*
813 * if the bitmask is the default value, then a bitmask was not
814 * specified in cfg.ini, so leave the logging level alone (it
815 * will remain at the "compiled in" default value)
816 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700817 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530818 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800819
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530820 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800821
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530822 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530823 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530824 QDF_TRACE_LEVEL_NONE, 0);
825
826 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530827 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800828 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530829 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800830 while (0 != bitmask) {
831 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530832 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530833 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530834 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530835 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800836 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700837
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800838 level++;
839 bitmask >>= 1;
840 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530841 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800842}
843
Dustin Brownda351e32018-07-23 15:48:22 -0700844int __wlan_hdd_validate_context(struct hdd_context *hdd_ctx, const char *func)
Chris Guo1751acf2017-07-03 14:09:01 +0800845{
Dustin Brownda351e32018-07-23 15:48:22 -0700846 if (!hdd_ctx) {
847 hdd_err("HDD context is null (via %s)", func);
848 return -ENODEV;
849 }
850
851 if (!hdd_ctx->config) {
852 hdd_err("HDD config is null (via %s)", func);
Chris Guo1751acf2017-07-03 14:09:01 +0800853 return -ENODEV;
854 }
855
856 if (cds_is_driver_recovering()) {
Dustin Brownda351e32018-07-23 15:48:22 -0700857 hdd_debug("Recovery in progress (via %s); state:0x%x",
858 func, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800859 return -EAGAIN;
860 }
861
Yue Ma9f275d92017-09-14 16:58:41 -0700862 if (cds_is_load_or_unload_in_progress()) {
Dustin Brownda351e32018-07-23 15:48:22 -0700863 hdd_debug("Load/unload in progress (via %s); state:0x%x",
864 func, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800865 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -0700866 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530867
Dustin Brownda351e32018-07-23 15:48:22 -0700868 if (hdd_ctx->start_modules_in_progress) {
869 hdd_debug("Start modules in progress (via %s)", func);
870 return -EAGAIN;
871 }
872
873 if (hdd_ctx->stop_modules_in_progress) {
874 hdd_debug("Stop modules in progress (via %s)", func);
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530875 return -EAGAIN;
876 }
877
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530878 if (cds_is_driver_in_bad_state()) {
Dustin Brownda351e32018-07-23 15:48:22 -0700879 hdd_debug("Driver in bad state (via %s); state:0x%x",
880 func, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +0530881 return -EAGAIN;
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530882 }
883
Arunk Khandavalli2859fa12018-02-14 10:46:26 +0530884 if (cds_is_fw_down()) {
Dustin Brownda351e32018-07-23 15:48:22 -0700885 hdd_debug("FW is down (via %s); state:0x%x",
886 func, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +0530887 return -EAGAIN;
Arunk Khandavalli2859fa12018-02-14 10:46:26 +0530888 }
889
Liangwei Dong858feb12018-05-21 01:52:46 -0400890 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
Dustin Brownda351e32018-07-23 15:48:22 -0700891 hdd_debug("Driver mode change in progress (via %s)", func);
Liangwei Dong858feb12018-05-21 01:52:46 -0400892 return -EAGAIN;
893 }
894
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800895 return 0;
896}
897
Dustin Browna8700cc2018-08-07 12:04:47 -0700898int __hdd_validate_adapter(struct hdd_adapter *adapter, const char *func)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700899{
900 if (!adapter) {
Dustin Browna8700cc2018-08-07 12:04:47 -0700901 hdd_err("adapter is null (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700902 return -EINVAL;
903 }
904
905 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Dustin Browna8700cc2018-08-07 12:04:47 -0700906 hdd_err("bad adapter magic (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700907 return -EINVAL;
908 }
909
910 if (!adapter->dev) {
Dustin Browna8700cc2018-08-07 12:04:47 -0700911 hdd_err("adapter net_device is null (via %s)", func);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700912 return -EINVAL;
913 }
914
915 if (!(adapter->dev->flags & IFF_UP)) {
Dustin Browna8700cc2018-08-07 12:04:47 -0700916 hdd_debug_rl("adapter '%s' is not up (via %s)",
917 adapter->dev->name, func);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700918 return -EAGAIN;
919 }
920
Dustin Browna8700cc2018-08-07 12:04:47 -0700921 return __wlan_hdd_validate_session_id(adapter->session_id, func);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700922}
923
Dustin Brown63500612018-08-07 11:36:09 -0700924int __wlan_hdd_validate_session_id(uint8_t session_id, const char *func)
925{
926 if (session_id == CSR_SESSION_ID_INVALID) {
927 hdd_debug_rl("adapter is not up (via %s)", func);
928 return -EINVAL;
929 }
930
931 if (session_id >= CSR_ROAM_SESSION_MAX) {
932 hdd_err("bad session Id:%u (via %s)", session_id, func);
933 return -EINVAL;
934 }
935
936 return 0;
937}
938
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800939/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530940 * wlan_hdd_validate_modules_state() - Check modules status
941 * @hdd_ctx: HDD context pointer
942 *
943 * Check's the driver module's state and returns true if the
944 * modules are enabled returns false if modules are closed.
945 *
946 * Return: True if modules are enabled or false.
947 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700948bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530949{
950 mutex_lock(&hdd_ctx->iface_change_lock);
951 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
952 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown5e89ef82018-03-14 11:50:23 -0700953 hdd_info("Modules not enabled, Present status: %d",
954 hdd_ctx->driver_status);
Arun Khandavallica892f62017-05-26 14:25:50 +0530955 return false;
956 }
957 mutex_unlock(&hdd_ctx->iface_change_lock);
958 return true;
959}
960
961/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800962 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700963 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800964 *
965 * This function sets the IBSS power save config parameters to WMA
966 * which will send it to firmware if FW supports IBSS power save
967 * before vdev start.
968 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530969 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800970 * on failure.
971 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700972QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800973{
974 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700975 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800976
977 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700978 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530979 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800980 }
981
Jeff Johnson1b780e42017-10-31 14:11:45 -0700982 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800983 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
984 hdd_ctx->config->ibssATIMWinSize,
985 VDEV_CMD);
986 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -0700987 hdd_err("atim window set failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530988 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800989 }
990
Jeff Johnson1b780e42017-10-31 14:11:45 -0700991 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800992 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
993 hdd_ctx->config->isIbssPowerSaveAllowed,
994 VDEV_CMD);
995 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -0700996 hdd_err("power save allow failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700997 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530998 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800999 }
1000
Jeff Johnson1b780e42017-10-31 14:11:45 -07001001 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001002 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
1003 hdd_ctx->config->
1004 isIbssPowerCollapseAllowed, VDEV_CMD);
1005 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001006 hdd_err("power collapse allow failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001007 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301008 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001009 }
1010
Jeff Johnson1b780e42017-10-31 14:11:45 -07001011 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001012 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
1013 hdd_ctx->config->isIbssAwakeOnTxRx,
1014 VDEV_CMD);
1015 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001016 hdd_err("set awake on tx/rx failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301017 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001018 }
1019
Jeff Johnson1b780e42017-10-31 14:11:45 -07001020 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001021 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
1022 hdd_ctx->config->ibssInactivityCount,
1023 VDEV_CMD);
1024 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001025 hdd_err("set inactivity time failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301026 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001027 }
1028
Jeff Johnson1b780e42017-10-31 14:11:45 -07001029 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001030 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
1031 hdd_ctx->config->ibssTxSpEndInactivityTime,
1032 VDEV_CMD);
1033 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001034 hdd_err("set txsp end failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001035 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301036 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001037 }
1038
Jeff Johnson1b780e42017-10-31 14:11:45 -07001039 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001040 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
1041 hdd_ctx->config->ibssPsWarmupTime,
1042 VDEV_CMD);
1043 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001044 hdd_err("set ps warmup failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001045 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301046 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001047 }
1048
Jeff Johnson1b780e42017-10-31 14:11:45 -07001049 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001050 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
1051 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
1052 VDEV_CMD);
1053 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001054 hdd_err("set 1rx chain atim failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001055 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301056 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001057 }
1058
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301059 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001060}
1061
Yue Macd359b72017-10-03 15:21:00 -07001062#ifdef FEATURE_RUNTIME_PM
1063/**
1064 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
1065 * @hdd_ctx: HDD context
1066 *
1067 * Return: None
1068 */
1069static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
1070{
1071 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1072
Yue Macd359b72017-10-03 15:21:00 -07001073 qdf_runtime_lock_init(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001074 qdf_runtime_lock_init(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001075
1076 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
1077}
1078
1079/**
1080 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1081 * @hdd_ctx: HDD Context
1082 *
1083 * Return: None
1084 */
1085static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1086{
1087 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1088
Yue Macd359b72017-10-03 15:21:00 -07001089 qdf_runtime_lock_deinit(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001090 qdf_runtime_lock_deinit(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001091
1092 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
1093}
1094
Yue Macd359b72017-10-03 15:21:00 -07001095#else /* FEATURE_RUNTIME_PM */
1096static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1097static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Yue Macd359b72017-10-03 15:21:00 -07001098#endif /* FEATURE_RUNTIME_PM */
1099
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001100#define INTF_MACADDR_MASK 0x7
1101
1102/**
1103 * hdd_update_macaddr() - update mac address
1104 * @config: hdd configuration
1105 * @hw_macaddr: mac address
1106 *
1107 * Mac address for multiple virtual interface is found as following
1108 * i) The mac address of the first interface is just the actual hw mac address.
1109 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
1110 * define the mac address for the remaining interfaces and locally
1111 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1112 * supported virtual interfaces, right now this is 0x07 (meaning 8
1113 * interface).
1114 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1115 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1116 *
1117 * Return: None
1118 */
1119void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301120 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001121{
1122 int8_t i;
1123 uint8_t macaddr_b3, tmp_br3;
1124
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301125 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301126 QDF_MAC_ADDR_SIZE);
1127 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301128 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301129 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001130 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1131 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1132 INTF_MACADDR_MASK;
1133 macaddr_b3 += tmp_br3;
1134
1135 /* XOR-ing bit-24 of the mac address. This will give enough
1136 * mac address range before collision
1137 */
1138 macaddr_b3 ^= (1 << 7);
1139
1140 /* Set locally administered bit */
1141 config->intfMacAddr[i].bytes[0] |= 0x02;
1142 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001143 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001144 MAC_ADDRESS_STR, i,
1145 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1146 }
1147}
1148
Kabilan Kannan44a58372017-12-06 18:16:11 -08001149static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1150{
1151 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
1152 struct tdls_start_params tdls_cfg;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001153 struct hdd_config *cfg = hdd_ctx->config;
1154 QDF_STATUS status;
1155
Wu Gaobdb7f272018-07-05 19:33:26 +08001156 cfg_tdls_set_vdev_nss_2g(hdd_ctx->hdd_psoc,
1157 CFG_TDLS_NSS(cfg->vdev_type_nss_2g));
1158 cfg_tdls_set_vdev_nss_5g(hdd_ctx->hdd_psoc,
1159 CFG_TDLS_NSS(cfg->vdev_type_nss_5g));
Kabilan Kannan44a58372017-12-06 18:16:11 -08001160 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
1161 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
1162 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
1163 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
1164 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1165 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1166 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1167 tdls_cfg.tdls_evt_cb_data = psoc;
Jeff Johnson1d40f5b2018-03-02 08:35:53 -08001168 tdls_cfg.tdls_peer_context = hdd_ctx;
1169 tdls_cfg.tdls_reg_peer = hdd_tdls_register_peer;
1170 tdls_cfg.tdls_dereg_peer = hdd_tdls_deregister_peer;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001171 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1172 tdls_cfg.tdls_wmm_cb_data = psoc;
1173 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1174 tdls_cfg.tdls_rx_cb_data = psoc;
1175 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1176
1177 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1178 if (status != QDF_STATUS_SUCCESS) {
1179 hdd_err("failed pmo psoc configuration");
1180 return -EINVAL;
1181 }
1182
1183 hdd_ctx->tdls_umac_comp_active = true;
1184 /* enable napier specific tdls data path */
1185 hdd_ctx->tdls_nap_active = true;
1186
1187 return 0;
1188}
1189
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001190static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001191 struct wma_tgt_services *cfg)
1192{
1193 struct hdd_config *config = hdd_ctx->config;
Wu Gaobdb7f272018-07-05 19:33:26 +08001194#ifdef FEATURE_WLAN_TDLS
1195 bool tdls_support;
1196 bool tdls_off_channel;
1197 bool tdls_buffer_sta;
1198 uint32_t tdls_uapsd_mask;
1199#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001200 /* Set up UAPSD */
1201 config->apUapsdEnabled &= cfg->uapsd;
1202
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001203 /* 11AX mode support */
1204 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1205 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1206 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1207
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001208 /* 11AC mode support */
1209 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1210 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1211 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001212
1213 /* ARP offload: override user setting if invalid */
1214 config->fhostArpOffload &= cfg->arp_offload;
1215
1216#ifdef FEATURE_WLAN_SCAN_PNO
1217 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001218 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001219 if (cfg->pno_offload)
1220 config->PnoOffload = true;
1221#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001222#ifdef FEATURE_WLAN_TDLS
Wu Gaobdb7f272018-07-05 19:33:26 +08001223 cfg_tdls_get_support_enable(hdd_ctx->hdd_psoc, &tdls_support);
1224 cfg_tdls_set_support_enable(hdd_ctx->hdd_psoc,
1225 tdls_support & cfg->en_tdls);
1226
1227 cfg_tdls_get_off_channel_enable(hdd_ctx->hdd_psoc, &tdls_off_channel);
1228 cfg_tdls_set_off_channel_enable(hdd_ctx->hdd_psoc,
1229 tdls_off_channel &&
1230 cfg->en_tdls_offchan);
1231
1232 cfg_tdls_get_buffer_sta_enable(hdd_ctx->hdd_psoc, &tdls_buffer_sta);
1233 cfg_tdls_set_buffer_sta_enable(hdd_ctx->hdd_psoc,
1234 tdls_buffer_sta &&
1235 cfg->en_tdls_uapsd_buf_sta);
1236
1237 cfg_tdls_get_uapsd_mask(hdd_ctx->hdd_psoc, &tdls_uapsd_mask);
1238 if (tdls_uapsd_mask && cfg->en_tdls_uapsd_sleep_sta)
1239 cfg_tdls_set_sleep_sta_enable(hdd_ctx->hdd_psoc, true);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001240 else
Wu Gaobdb7f272018-07-05 19:33:26 +08001241 cfg_tdls_set_sleep_sta_enable(hdd_ctx->hdd_psoc, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001242#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001243#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1244 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1245#endif
Will Huang496b36c2017-07-11 16:38:50 +08001246 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001247 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001248 hdd_update_tdls_config(hdd_ctx);
Jeff Johnson16528362018-06-14 12:34:16 -07001249 sme_update_tgt_services(hdd_ctx->mac_handle, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001250
1251}
1252
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001253/**
1254 * hdd_update_vdev_nss() - sets the vdev nss
1255 * @hdd_ctx: HDD context
1256 *
1257 * Sets the Nss per vdev type based on INI
1258 *
1259 * Return: None
1260 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001261static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001262{
1263 struct hdd_config *cfg_ini = hdd_ctx->config;
1264 uint8_t max_supp_nss = 1;
Jeff Johnson16528362018-06-14 12:34:16 -07001265 mac_handle_t mac_handle;
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001266
Naveen Rawat10b1c152017-01-18 11:16:06 -08001267 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001268 max_supp_nss = 2;
Liangwei Dong22810e82018-03-15 03:42:12 -04001269 hdd_debug("max nss %d vdev_type_nss_2g %x vdev_type_nss_5g %x",
1270 max_supp_nss, cfg_ini->vdev_type_nss_2g,
1271 cfg_ini->vdev_type_nss_5g);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001272
Jeff Johnson16528362018-06-14 12:34:16 -07001273 mac_handle = hdd_ctx->mac_handle;
1274 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
1275 cfg_ini->vdev_type_nss_2g, BAND_2G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001276
Jeff Johnson16528362018-06-14 12:34:16 -07001277 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
1278 cfg_ini->vdev_type_nss_5g, BAND_5G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001279}
1280
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301281/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301282 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1283 * @hdd_ctx: HDD context
1284 *
1285 * Updates wiphy vhtcap fields
1286 *
1287 * Return: None
1288 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001289static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301290{
1291 struct ieee80211_supported_band *band_5g =
1292 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1293 uint32_t val;
1294
1295 if (!band_5g) {
1296 hdd_debug("5GHz band disabled, skipping capability population");
1297 return;
1298 }
1299
1300 val = hdd_ctx->config->txBFCsnValue;
1301 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1302
1303 val = NUM_OF_SOUNDING_DIMENSIONS;
1304 band_5g->vht_cap.cap |=
1305 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1306
Dustin Brown7e761c72018-07-31 13:50:17 -07001307 hdd_debug("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1308 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301309}
1310
1311/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301312 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1313 * @hdd_ctx: HDD context
1314 *
1315 * Sets the DBS capability as per INI and firmware capability
1316 *
1317 * Return: None
1318 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001319static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301320{
1321 struct hdd_config *cfg_ini = hdd_ctx->config;
1322 uint8_t hw_dbs_capable = 0;
1323
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001324 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1325 ((cfg_ini->dual_mac_feature_disable ==
1326 ENABLE_DBS_CXN_AND_SCAN) ||
1327 (cfg_ini->dual_mac_feature_disable ==
Tushnim Bhattacharyyaaececb22018-08-06 14:27:46 -07001328 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF) ||
1329 (cfg_ini->dual_mac_feature_disable ==
1330 ENABLE_DBS_CXN_AND_DISABLE_SIMULTANEOUS_SCAN)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301331 hw_dbs_capable = 1;
1332
Jeff Johnson16528362018-06-14 12:34:16 -07001333 sme_update_hw_dbs_capable(hdd_ctx->mac_handle, hw_dbs_capable);
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301334}
1335
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001336static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001337 struct wma_tgt_ht_cap *cfg)
1338{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301339 QDF_STATUS status;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301340 uint32_t value;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001341 struct hdd_config *pconfig = hdd_ctx->config;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301342 struct mlme_ht_capabilities_info ht_cap_info;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001343 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301344 mac_handle_t mac_handle = hdd_ctx->mac_handle;
Jeff Johnson16528362018-06-14 12:34:16 -07001345
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001346 /* get the MPDU density */
Jeff Johnson16528362018-06-14 12:34:16 -07001347 status = sme_cfg_get_int(mac_handle, WNI_CFG_MPDU_DENSITY, &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001348
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301349 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001350 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001351 value = 0;
1352 }
1353
1354 /*
1355 * MPDU density:
1356 * override user's setting if value is larger
1357 * than the one supported by target
1358 */
1359 if (value > cfg->mpdu_density) {
Jeff Johnson16528362018-06-14 12:34:16 -07001360 status = sme_cfg_set_int(mac_handle, WNI_CFG_MPDU_DENSITY,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001361 cfg->mpdu_density);
1362
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301363 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001364 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001365 }
1366
1367 /* get the HT capability info */
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301368 status = ucfg_mlme_get_ht_cap_info(hdd_ctx->hdd_psoc, &ht_cap_info);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301369 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001370 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001371 return;
1372 }
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301373
1374 /* check and update RX STBC */
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301375 if (ht_cap_info.rx_stbc && !cfg->ht_rx_stbc)
1376 ht_cap_info.rx_stbc = cfg->ht_rx_stbc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001377
1378 /* Set the LDPC capability */
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301379 ht_cap_info.adv_coding_cap = cfg->ht_rx_ldpc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001380
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301381 if (ht_cap_info.short_gi_20_mhz && !cfg->ht_sgi_20)
1382 ht_cap_info.short_gi_20_mhz = cfg->ht_sgi_20;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001383
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301384 if (ht_cap_info.short_gi_40_mhz && !cfg->ht_sgi_40)
1385 ht_cap_info.short_gi_40_mhz = cfg->ht_sgi_40;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001386
1387 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1388 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1389
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001390 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1391 pconfig->enable2x2 = 1;
1392 } else {
1393 pconfig->enable2x2 = 0;
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301394 ht_cap_info.tx_stbc = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001395
1396 /* 1x1 */
1397 /* Update Rx Highest Long GI data Rate */
Jeff Johnson16528362018-06-14 12:34:16 -07001398 if (sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001399 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001400 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301401 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001402 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001403 }
1404
1405 /* Update Tx Highest Long GI data Rate */
1406 if (sme_cfg_set_int
Jeff Johnson16528362018-06-14 12:34:16 -07001407 (mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001408 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001409 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301410 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001411 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001412 }
1413 }
1414 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
Vignesh Viswanathan78182502018-08-06 15:13:30 +05301415 ht_cap_info.tx_stbc = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001416
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05301417 status = ucfg_mlme_set_ht_cap_info(hdd_ctx->hdd_psoc, ht_cap_info);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301418 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001419 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001420#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1421 value = SIZE_OF_SUPPORTED_MCS_SET;
Jeff Johnson16528362018-06-14 12:34:16 -07001422 if (sme_cfg_get_str(mac_handle, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301423 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001424 hdd_debug("Read MCS rate set");
gaurank kathpalia18b49362018-04-15 23:12:03 +05301425 if (cfg->num_rf_chains > SIZE_OF_SUPPORTED_MCS_SET)
1426 cfg->num_rf_chains = SIZE_OF_SUPPORTED_MCS_SET;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001427 if (pconfig->enable2x2) {
1428 for (value = 0; value < cfg->num_rf_chains; value++)
1429 mcs_set[value] =
1430 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1431
1432 status =
Jeff Johnson16528362018-06-14 12:34:16 -07001433 sme_cfg_set_str(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001434 WNI_CFG_SUPPORTED_MCS_SET,
1435 mcs_set,
1436 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301437 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001438 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001439 }
1440 }
1441#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1442}
1443
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001444static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001445 struct wma_tgt_vht_cap *cfg)
1446{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301447 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001448 uint32_t value = 0;
1449 struct hdd_config *pconfig = hdd_ctx->config;
1450 struct wiphy *wiphy = hdd_ctx->wiphy;
1451 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001452 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001453 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001454 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001455 uint32_t hw_rx_ldpc_enabled;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001456 struct wma_caps_per_phy caps_per_phy;
Jeff Johnson16528362018-06-14 12:34:16 -07001457 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001458
Dustin Brown5e06bd32016-10-04 12:49:10 -07001459 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001460 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001461 return;
1462 }
1463
Jeff Johnson16528362018-06-14 12:34:16 -07001464 mac_handle = hdd_ctx->mac_handle;
1465
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001466 /* Get the current MPDU length */
1467 status =
Jeff Johnson16528362018-06-14 12:34:16 -07001468 sme_cfg_get_int(mac_handle, WNI_CFG_VHT_MAX_MPDU_LENGTH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001469 &value);
1470
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301471 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001472 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001473 value = 0;
1474 }
1475
1476 /*
1477 * VHT max MPDU length:
1478 * override if user configured value is too high
1479 * that the target cannot support
1480 */
1481 if (value > cfg->vht_max_mpdu) {
Jeff Johnson16528362018-06-14 12:34:16 -07001482 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001483 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1484 cfg->vht_max_mpdu);
1485
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001486 if (status == QDF_STATUS_E_FAILURE)
1487 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001488 }
1489
Jeff Johnson16528362018-06-14 12:34:16 -07001490 sme_cfg_get_int(mac_handle, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001491 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1492
1493 if (pconfig->enable2x2)
1494 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1495
Jeff Johnson16528362018-06-14 12:34:16 -07001496 if (sme_cfg_set_int(mac_handle, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001497 QDF_STATUS_E_FAILURE) {
1498 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1499 }
1500
Jeff Johnson16528362018-06-14 12:34:16 -07001501 sme_cfg_get_int(mac_handle, WNI_CFG_VHT_RX_MCS_MAP, &temp);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001502 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1503 if (pconfig->enable2x2)
1504 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1505
Jeff Johnson16528362018-06-14 12:34:16 -07001506 if (sme_cfg_set_int(mac_handle, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001507 QDF_STATUS_E_FAILURE) {
1508 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1509 }
1510
Jeff Johnson16528362018-06-14 12:34:16 -07001511 sme_cfg_get_int(mac_handle, WNI_CFG_VHT_TX_MCS_MAP, &temp);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001512 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1513 if (pconfig->enable2x2)
1514 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1515
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001516 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001517 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1518
Jeff Johnson16528362018-06-14 12:34:16 -07001519 if (sme_cfg_set_int(mac_handle, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001520 QDF_STATUS_E_FAILURE) {
1521 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1522 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001523 /* Get the current RX LDPC setting */
Jeff Johnson16528362018-06-14 12:34:16 -07001524 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_LDPC_CODING_CAP,
1525 &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001526
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301527 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001528 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001529 value = 0;
1530 }
1531
jiad4a7a33c2017-08-08 15:32:24 +08001532 /* Set HW RX LDPC capability */
1533 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1534 if (hw_rx_ldpc_enabled != value) {
Jeff Johnson16528362018-06-14 12:34:16 -07001535 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001536 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001537 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001538
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001539 if (status == QDF_STATUS_E_FAILURE)
1540 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001541 }
1542
1543 /* Get current GI 80 value */
Jeff Johnson16528362018-06-14 12:34:16 -07001544 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_SHORT_GI_80MHZ,
1545 &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001546
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301547 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001548 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001549 value = 0;
1550 }
1551
1552 /* set the Guard interval 80MHz */
1553 if (value && !cfg->vht_short_gi_80) {
Jeff Johnson16528362018-06-14 12:34:16 -07001554 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001555 WNI_CFG_VHT_SHORT_GI_80MHZ,
1556 cfg->vht_short_gi_80);
1557
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001558 if (status == QDF_STATUS_E_FAILURE)
1559 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001560 }
1561
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001562 /* Get VHT TX STBC cap */
Jeff Johnson16528362018-06-14 12:34:16 -07001563 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_TXSTBC, &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001564
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301565 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001566 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001567 value = 0;
1568 }
1569
1570 /* VHT TX STBC cap */
1571 if (value && !cfg->vht_tx_stbc) {
Jeff Johnson16528362018-06-14 12:34:16 -07001572 status = sme_cfg_set_int(mac_handle, WNI_CFG_VHT_TXSTBC,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001573 cfg->vht_tx_stbc);
1574
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001575 if (status == QDF_STATUS_E_FAILURE)
1576 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001577 }
1578
1579 /* Get VHT RX STBC cap */
Jeff Johnson16528362018-06-14 12:34:16 -07001580 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_RXSTBC, &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001581
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301582 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001583 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001584 value = 0;
1585 }
1586
1587 /* VHT RX STBC cap */
1588 if (value && !cfg->vht_rx_stbc) {
Jeff Johnson16528362018-06-14 12:34:16 -07001589 status = sme_cfg_set_int(mac_handle, WNI_CFG_VHT_RXSTBC,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001590 cfg->vht_rx_stbc);
1591
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001592 if (status == QDF_STATUS_E_FAILURE)
1593 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001594 }
1595
1596 /* Get VHT SU Beamformer cap */
Jeff Johnson16528362018-06-14 12:34:16 -07001597 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001598 &value);
1599
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301600 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001601 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001602 value = 0;
1603 }
1604
1605 /* set VHT SU Beamformer cap */
1606 if (value && !cfg->vht_su_bformer) {
Jeff Johnson16528362018-06-14 12:34:16 -07001607 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001608 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1609 cfg->vht_su_bformer);
1610
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001611 if (status == QDF_STATUS_E_FAILURE)
1612 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001613 }
1614
1615 /* check and update SU BEAMFORMEE capabality */
1616 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1617 pconfig->enableTxBF = cfg->vht_su_bformee;
1618
Jeff Johnson16528362018-06-14 12:34:16 -07001619 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001620 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1621 pconfig->enableTxBF);
1622
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001623 if (status == QDF_STATUS_E_FAILURE)
1624 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001625
1626 /* Get VHT MU Beamformer cap */
Jeff Johnson16528362018-06-14 12:34:16 -07001627 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001628 &value);
1629
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301630 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001631 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001632 value = 0;
1633 }
1634
1635 /* set VHT MU Beamformer cap */
1636 if (value && !cfg->vht_mu_bformer) {
Jeff Johnson16528362018-06-14 12:34:16 -07001637 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001638 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1639 cfg->vht_mu_bformer);
1640
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001641 if (status == QDF_STATUS_E_FAILURE)
1642 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001643 }
1644
1645 /* Get VHT MU Beamformee cap */
Jeff Johnson16528362018-06-14 12:34:16 -07001646 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001647 &value);
1648
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301649 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001650 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001651 value = 0;
1652 }
1653
1654 /* set VHT MU Beamformee cap */
1655 if (value && !cfg->vht_mu_bformee) {
Jeff Johnson16528362018-06-14 12:34:16 -07001656 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001657 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1658 cfg->vht_mu_bformee);
1659
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001660 if (status == QDF_STATUS_E_FAILURE)
1661 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001662 }
1663
1664 /* Get VHT MAX AMPDU Len exp */
Jeff Johnson16528362018-06-14 12:34:16 -07001665 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001666 &value);
1667
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301668 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001669 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001670 value = 0;
1671 }
1672
1673 /*
1674 * VHT max AMPDU len exp:
1675 * override if user configured value is too high
1676 * that the target cannot support.
1677 * Even though Rome publish ampdu_len=7, it can
1678 * only support 4 because of some h/w bug.
1679 */
1680
1681 if (value > cfg->vht_max_ampdu_len_exp) {
Jeff Johnson16528362018-06-14 12:34:16 -07001682 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001683 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1684 cfg->vht_max_ampdu_len_exp);
1685
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001686 if (status == QDF_STATUS_E_FAILURE)
1687 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001688 }
1689
1690 /* Get VHT TXOP PS CAP */
Jeff Johnson16528362018-06-14 12:34:16 -07001691 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_TXOP_PS, &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001692
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301693 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001694 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001695 value = 0;
1696 }
1697
1698 /* set VHT TXOP PS cap */
1699 if (value && !cfg->vht_txop_ps) {
Jeff Johnson16528362018-06-14 12:34:16 -07001700 status = sme_cfg_set_int(mac_handle, WNI_CFG_VHT_TXOP_PS,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001701 cfg->vht_txop_ps);
1702
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001703 if (status == QDF_STATUS_E_FAILURE)
1704 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001705 }
1706
1707 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1708 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1709 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1710 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1711 else
1712 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1713
1714
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001715 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
Jeff Johnson16528362018-06-14 12:34:16 -07001716 status = sme_cfg_set_int(mac_handle,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001717 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1718 VHT_CAP_160_AND_80P80_SUPP);
1719 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001720 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001721 band_5g->vht_cap.cap |=
1722 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001723 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1724 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
Jeff Johnson16528362018-06-14 12:34:16 -07001725 status = sme_cfg_set_int(mac_handle,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001726 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1727 VHT_CAP_160_SUPP);
1728 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001729 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001730 band_5g->vht_cap.cap |=
1731 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001732 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1733 }
1734 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1735 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301736 /* Get the current GI 160 value */
Jeff Johnson16528362018-06-14 12:34:16 -07001737 status = sme_cfg_get_int(mac_handle,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301738 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001739 &value);
1740 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301741 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001742 value = 0;
1743 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301744 /* set the Guard interval 160MHz */
1745 if (value && !cfg->vht_short_gi_160) {
Jeff Johnson16528362018-06-14 12:34:16 -07001746 status = sme_cfg_set_int(mac_handle,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301747 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1748 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001749
1750 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301751 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001752 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001753
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001754 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001755 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001756 hdd_debug("VHT RxLDPC capability is set");
1757 } else {
1758 /*
1759 * Get the RX LDPC capability for the NON DBS
1760 * hardware mode for 5G band
1761 */
1762 status = wma_get_caps_for_phyidx_hwmode(&caps_per_phy,
1763 HW_MODE_DBS_NONE, CDS_BAND_5GHZ);
1764 if ((QDF_IS_STATUS_SUCCESS(status)) &&
1765 (caps_per_phy.vht_5g & WMI_VHT_CAP_RX_LDPC)) {
1766 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1767 hdd_debug("VHT RX LDPC capability is set");
1768 }
1769 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001770
1771 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1772 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1773 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1774 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1775
1776 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1777 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1778
1779 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1780 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1781 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1782 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1783 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1784 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1785
1786 band_5g->vht_cap.cap |=
1787 (cfg->vht_max_ampdu_len_exp <<
1788 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1789
1790 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1791 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1792 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1793 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1794 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1795 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1796 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1797 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1798
1799 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1800 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1801
1802}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001803
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001804/**
1805 * hdd_generate_macaddr_auto() - Auto-generate mac address
1806 * @hdd_ctx: Pointer to the HDD context
1807 *
1808 * Auto-generate mac address using device serial number.
1809 * Keep the first 3 bytes of OUI as before and replace
1810 * the last 3 bytes with the lower 3 bytes of serial number.
1811 *
1812 * Return: 0 for success
1813 * Non zero failure code for errors
1814 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001815static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001816{
1817 unsigned int serialno = 0;
1818 struct qdf_mac_addr mac_addr = {
1819 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1820 };
1821
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001822 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001823 if (serialno == 0)
1824 return -EINVAL;
1825
1826 serialno &= 0x00ffffff;
1827
1828 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1829 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1830 mac_addr.bytes[5] = serialno & 0xff;
1831
1832 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1833 return 0;
1834}
1835
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05301836#ifdef FEATURE_WLAN_APF
1837/**
1838 * hdd_update_apf_support() - Update APF supported flag in hdd context
1839 * @hdd_ctx: Pointer to hdd_ctx
1840 * @cfg: target configuration
1841 *
1842 * Update the APF support flag in HDD Context using INI and target config.
1843 *
1844 * Return: None
1845 */
1846static void hdd_update_apf_support(struct hdd_context *hdd_ctx,
1847 struct wma_tgt_cfg *cfg)
1848{
1849 hdd_ctx->apf_supported = (cfg->apf_enabled &&
1850 hdd_ctx->config->apf_packet_filter_enable);
1851}
1852#else
1853static void hdd_update_apf_support(struct hdd_context *hdd_ctx,
1854 struct wma_tgt_cfg *cfg)
1855{
1856}
1857#endif
1858
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301859/**
1860 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1861 * configuration to cfg_ini in HDD
1862 * @hdd_ctx: Pointer to hdd_ctx
1863 * @cfg: target configuration
1864 *
1865 * Return: None
1866 */
1867#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001868static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301869 struct wma_tgt_cfg *cfg)
1870{
1871 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1872}
1873#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001874static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301875 struct wma_tgt_cfg *cfg)
1876{
1877}
1878#endif
1879
Jeff Johnsonf9176382018-07-17 19:15:58 -07001880static void hdd_sar_target_config(struct hdd_context *hdd_ctx,
1881 struct wma_tgt_cfg *cfg)
1882{
1883 hdd_ctx->sar_version = cfg->sar_version;
1884}
1885
Jeff Johnson8abc5932018-06-02 22:51:37 -07001886void hdd_update_tgt_cfg(hdd_handle_t hdd_handle, struct wma_tgt_cfg *cfg)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001887{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001888 int ret;
Jeff Johnsonea70b942018-07-02 09:42:31 -07001889 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001890 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001891 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301892 uint8_t antenna_mode;
Arif Hussainee10f902017-12-27 16:30:17 -08001893 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -07001894 mac_handle_t mac_handle;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301895
gaurank kathpalia843f7c32018-07-02 18:04:14 +05301896 if (!hdd_ctx) {
1897 hdd_err("HDD context is NULL");
1898 return;
1899 }
Dustin Brownbd68fe12017-11-21 15:28:52 -08001900 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1901 if (ret) {
Dustin Brown64204d22018-08-15 16:35:19 -07001902 QDF_DEBUG_PANIC("Failed to create pdev; errno:%d", ret);
1903 return;
1904 }
1905
1906 hdd_debug("New pdev has been created with pdev_id = %u",
1907 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
1908
1909 status = dispatcher_pdev_open(hdd_ctx->hdd_pdev);
1910 if (QDF_IS_STATUS_ERROR(status)) {
1911 QDF_DEBUG_PANIC("dispatcher pdev open failed; status:%d",
1912 status);
1913 return;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301914 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001915
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301916 cdp_pdev_set_ctrl_pdev(cds_get_context(QDF_MODULE_ID_SOC),
1917 cds_get_context(QDF_MODULE_ID_TXRX),
1918 (struct cdp_ctrl_objmgr_pdev *)hdd_ctx->hdd_pdev);
1919
1920 wlan_pdev_set_dp_handle(hdd_ctx->hdd_pdev,
1921 cds_get_context(QDF_MODULE_ID_TXRX));
1922
Will Huang07244172018-05-14 14:23:30 +08001923 hdd_objmgr_update_tgt_max_vdev_psoc(hdd_ctx, cfg->max_intf_count);
1924
Jeff Johnsone8846ab2018-03-31 11:54:45 -07001925 ret = hdd_green_ap_update_config(hdd_ctx);
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301926
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301927 ucfg_ipa_set_dp_handle(hdd_ctx->hdd_psoc,
1928 cds_get_context(QDF_MODULE_ID_SOC));
1929 ucfg_ipa_set_txrx_handle(hdd_ctx->hdd_psoc,
1930 cds_get_context(QDF_MODULE_ID_TXRX));
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301931 ucfg_ipa_reg_sap_xmit_cb(hdd_ctx->hdd_pdev,
1932 hdd_softap_hard_start_xmit);
1933 ucfg_ipa_reg_send_to_nw_cb(hdd_ctx->hdd_pdev,
1934 hdd_ipa_send_skb_to_network);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301935
Naveen Rawat64e477e2016-05-20 10:34:56 -07001936 if (cds_cfg) {
1937 if (hdd_ctx->config->enable_sub_20_channel_width !=
1938 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1939 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1940 cds_cfg->sub_20_channel_width =
1941 WLAN_SUB_20_CH_WIDTH_NONE;
1942 } else {
1943 cds_cfg->sub_20_channel_width =
1944 hdd_ctx->config->enable_sub_20_channel_width;
1945 }
1946 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001947
1948 /* first store the INI band capability */
1949 temp_band_cap = hdd_ctx->config->nBandCapability;
1950
1951 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301952 hdd_ctx->is_fils_roaming_supported =
1953 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001954
Vignesh Viswanathan694e28e2018-01-18 20:53:57 +05301955 hdd_ctx->config->is_11k_offload_supported =
1956 cfg->services.is_11k_offload_supported;
1957
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001958 /*
1959 * now overwrite the target band capability with INI
1960 * setting if INI setting is a subset
1961 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001962
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001963 if ((hdd_ctx->config->nBandCapability == BAND_ALL) &&
1964 (temp_band_cap != BAND_ALL))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001965 hdd_ctx->config->nBandCapability = temp_band_cap;
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001966 else if ((hdd_ctx->config->nBandCapability != BAND_ALL) &&
1967 (temp_band_cap != BAND_ALL) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001968 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001969 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001970 }
1971
Amar Singhal58b45ef2017-08-01 13:43:54 -07001972 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1973
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301974 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001975 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1976 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1977 }
1978
1979 /* This can be extended to other configurations like ht, vht cap... */
1980
Anurag Chouhanc5548422016-02-24 18:33:27 +05301981 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001982 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001983 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001984 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001985 static struct qdf_mac_addr default_mac_addr = {
1986 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1987 };
1988 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1989 &default_mac_addr)) {
1990 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1991 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1992 MAC_ADDRESS_STR,
1993 MAC_ADDR_ARRAY(hdd_ctx->config->
1994 intfMacAddr[0].bytes));
1995 } else {
1996 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1997 MAC_ADDRESS_STR,
1998 MAC_ADDR_ARRAY(hdd_ctx->config->
1999 intfMacAddr[0].bytes));
2000 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07002001 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002002 }
2003
2004 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07002005 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002006
Ryan Hsuc6918552018-05-16 13:29:59 -07002007 hdd_ctx->hw_bd_id = cfg->hw_bd_id;
2008 qdf_mem_copy(&hdd_ctx->hw_bd_info, &cfg->hw_bd_info,
2009 sizeof(cfg->hw_bd_info));
2010
Dustin Brownbee82832018-07-23 10:10:51 -07002011 if (cfg->max_intf_count > CSR_ROAM_SESSION_MAX) {
2012 hdd_err("fw max vdevs (%u) > host max vdevs (%u); using %u",
2013 cfg->max_intf_count, CSR_ROAM_SESSION_MAX,
2014 CSR_ROAM_SESSION_MAX);
2015 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
2016 } else {
2017 hdd_ctx->max_intf_count = cfg->max_intf_count;
2018 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002019
Jeff Johnsonf9176382018-07-17 19:15:58 -07002020 hdd_sar_target_config(hdd_ctx, cfg);
Jeff Johnsonc875e242016-09-23 18:12:34 -07002021 hdd_lpass_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08002022
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002023 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
2024 hdd_update_tgt_services(hdd_ctx, &cfg->services);
2025
2026 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
2027
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002028 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07002029 if (cfg->services.en_11ax) {
2030 hdd_info("11AX: 11ax is enabled - update HDD config");
2031 hdd_update_tgt_he_cap(hdd_ctx, cfg);
2032 }
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -07002033 hdd_update_tgt_twt_cap(hdd_ctx, cfg);
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07002034
2035 hdd_update_vdev_nss(hdd_ctx);
2036
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05302037 hdd_update_hw_dbs_capable(hdd_ctx);
2038
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08002039 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07002040 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002041 hdd_debug("fine_time_meas_cap: 0x%x",
Arif Hussainee10f902017-12-27 16:30:17 -08002042 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08002043
Nitesh Shahe50711f2017-04-26 16:30:45 +05302044 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
2045 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
2046 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002047 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08002048 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08002049
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05302050 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05302051 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05302052
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302053 if ((hdd_ctx->config->txBFCsnValue >
Arif Hussainee10f902017-12-27 16:30:17 -08002054 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
2055 !cfg->tx_bfee_8ss_enabled)
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302056 hdd_ctx->config->txBFCsnValue =
2057 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
2058
Jeff Johnson16528362018-06-14 12:34:16 -07002059 mac_handle = hdd_ctx->mac_handle;
2060 status = sme_cfg_set_int(mac_handle,
Arif Hussainee10f902017-12-27 16:30:17 -08002061 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
2062 hdd_ctx->config->txBFCsnValue);
2063 if (QDF_IS_STATUS_ERROR(status))
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302064 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
2065
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05302066 hdd_update_apf_support(hdd_ctx, cfg);
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302067
Nachiket Kukadee547a482018-05-22 16:43:30 +05302068 hdd_debug("Target APF %d Host APF %d 8ss fw support %d txBFCsnValue %d",
2069 cfg->apf_enabled, hdd_ctx->config->apf_packet_filter_enable,
Arif Hussainee10f902017-12-27 16:30:17 -08002070 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05302071
2072 /*
2073 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
2074 */
2075 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05302076
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05302077 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
2078
Yue Macd359b72017-10-03 15:21:00 -07002079 /*
2080 * This needs to be done after HDD pdev is created and stored since
2081 * it will access the HDD pdev object lock.
2082 */
2083 hdd_runtime_suspend_context_init(hdd_ctx);
2084
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07002085 /* Configure NAN datapath features */
2086 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07002087 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08002088 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Liangwei Dong0da14262018-07-03 03:30:23 -04002089 hdd_ctx->obss_scan_offload = cfg->services.obss_scan_offload;
Jeff Johnson16528362018-06-14 12:34:16 -07002090 status = sme_cfg_set_int(mac_handle, WNI_CFG_OBSS_DETECTION_OFFLOAD,
Arif Hussainee10f902017-12-27 16:30:17 -08002091 cfg->obss_detection_offloaded);
2092 if (QDF_IS_STATUS_ERROR(status))
2093 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Arif Hussain05fb4872018-01-03 16:02:55 -08002094
Jeff Johnson16528362018-06-14 12:34:16 -07002095 status = sme_cfg_set_int(mac_handle,
Arif Hussain05fb4872018-01-03 16:02:55 -08002096 WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD,
2097 cfg->obss_color_collision_offloaded);
2098 if (QDF_IS_STATUS_ERROR(status))
2099 hdd_err("Failed to set WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002100}
2101
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002102bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002103{
Jeff Johnson9d295242017-08-29 14:39:48 -07002104 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002105 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002106
Jiachao Wuf610d912018-01-23 17:47:32 +08002107 if (!hdd_ctx) {
2108 hdd_info("Couldn't get hdd_ctx");
2109 return true;
2110 }
2111
2112 if (hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002113 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08002114 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302115 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002116 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002117
Dustin Brown920397d2017-12-13 16:27:50 -08002118 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002119 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2120
2121 if ((QDF_SAP_MODE == adapter->device_mode ||
2122 QDF_P2P_GO_MODE == adapter->device_mode) &&
bings0e03a982018-05-09 08:40:59 +08002123 (wlan_reg_is_passive_or_disable_ch(hdd_ctx->hdd_pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002124 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002125 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2126 true;
2127 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07002128 adapter->session_id);
bings6fb9bf62018-07-05 14:01:53 +08002129 if (adapter->txrx_vdev)
2130 cdp_fc_vdev_flush(
2131 cds_get_context(QDF_MODULE_ID_SOC),
bings0e03a982018-05-09 08:40:59 +08002132 adapter->txrx_vdev);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302133 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002134 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302135
2136 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002137}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002138
2139/**
2140 * hdd_is_valid_mac_address() - validate MAC address
2141 * @pMacAddr: Pointer to the input MAC address
2142 *
2143 * This function validates whether the given MAC address is valid or not
2144 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
2145 * where X is the hexa decimal digit character and separated by ':'
2146 * This algorithm works even if MAC address is not separated by ':'
2147 *
2148 * This code checks given input string mac contains exactly 12 hexadecimal
2149 * digits and a separator colon : appears in the input string only after
2150 * an even number of hex digits.
2151 *
2152 * Return: 1 for valid and 0 for invalid
2153 */
2154bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
2155{
2156 int xdigit = 0;
2157 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002158
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002159 while (*pMacAddr) {
2160 if (isxdigit(*pMacAddr)) {
2161 xdigit++;
2162 } else if (':' == *pMacAddr) {
2163 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2164 break;
2165
2166 ++separator;
2167 } else {
2168 /* Invalid MAC found */
2169 return 0;
2170 }
2171 ++pMacAddr;
2172 }
2173 return xdigit == 12 && (separator == 5 || separator == 0);
2174}
2175
2176/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302177 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2178 * @dev: Handle to struct net_device to be updated.
2179 *
2180 * Return: None
2181 */
2182static void hdd_mon_mode_ether_setup(struct net_device *dev)
2183{
2184 dev->header_ops = NULL;
2185 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2186 dev->hard_header_len = ETH_HLEN;
2187 dev->mtu = ETH_DATA_LEN;
2188 dev->addr_len = ETH_ALEN;
2189 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2190 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2191 dev->priv_flags |= IFF_TX_SKB_SHARING;
2192
2193 memset(dev->broadcast, 0xFF, ETH_ALEN);
2194}
2195
Nirav Shah73713f72018-05-17 14:50:41 +05302196#ifdef FEATURE_MONITOR_MODE_SUPPORT
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302197/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002198 * __hdd__mon_open() - HDD Open function
2199 * @dev: Pointer to net_device structure
2200 *
2201 * This is called in response to ifconfig up
2202 *
2203 * Return: 0 for success; non-zero for failure
2204 */
2205static int __hdd_mon_open(struct net_device *dev)
2206{
2207 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002208 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2209 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002210
Dustin Brownfdf17c12018-03-14 12:55:34 -07002211 hdd_enter_dev(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002212
2213 ret = wlan_hdd_validate_context(hdd_ctx);
2214 if (ret)
2215 return ret;
2216
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302217 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002218
2219 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Browne7e71d32018-05-11 16:00:08 -07002220 ret = hdd_wlan_start_modules(hdd_ctx, false);
Ravi Joshia307f632017-07-17 23:41:41 -07002221 if (ret) {
2222 hdd_err("Failed to start WLAN modules return");
2223 return ret;
2224 }
2225 hdd_err("hdd_wlan_start_modules() successful !");
2226
2227 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2228 ret = hdd_start_adapter(adapter);
2229 if (ret) {
2230 hdd_err("Failed to start adapter :%d",
2231 adapter->device_mode);
2232 return ret;
2233 }
2234 hdd_err("hdd_start_adapters() successful !");
2235 }
2236 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2237 }
2238
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002239 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002240
2241 if (!ret)
2242 ret = hdd_enable_monitor_mode(dev);
2243
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002244 return ret;
2245}
2246
2247/**
2248 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2249 * @dev: Pointer to net_device structure
2250 *
2251 * This is called in response to ifconfig up
2252 *
2253 * Return: 0 for success; non-zero for failure
2254 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002255static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002256{
2257 int ret;
2258
2259 cds_ssr_protect(__func__);
2260 ret = __hdd_mon_open(dev);
2261 cds_ssr_unprotect(__func__);
2262
2263 return ret;
2264}
Nirav Shah73713f72018-05-17 14:50:41 +05302265#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002266
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002267static QDF_STATUS
2268wlan_hdd_update_dbs_scan_and_fw_mode_config(void)
2269{
2270 struct policy_mgr_dual_mac_config cfg = {0};
2271 QDF_STATUS status;
2272 uint32_t channel_select_logic_conc;
2273 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2274
2275 if (!hdd_ctx) {
2276 hdd_err("HDD context is NULL");
2277 return QDF_STATUS_E_FAILURE;
2278 }
2279
2280
2281 if (!policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc))
2282 return QDF_STATUS_SUCCESS;
2283
2284 cfg.scan_config = 0;
2285 cfg.fw_mode_config = 0;
2286 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
2287
2288 channel_select_logic_conc = hdd_ctx->config->
2289 channel_select_logic_conc;
2290
2291 if (hdd_ctx->config->dual_mac_feature_disable !=
2292 DISABLE_DBS_CXN_AND_SCAN) {
2293 status = policy_mgr_get_updated_scan_and_fw_mode_config(
2294 hdd_ctx->hdd_psoc, &cfg.scan_config,
2295 &cfg.fw_mode_config,
2296 hdd_ctx->config->dual_mac_feature_disable,
2297 channel_select_logic_conc);
2298
2299 if (status != QDF_STATUS_SUCCESS) {
2300 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
2301 status);
2302 return status;
2303 }
2304 }
2305
2306 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
2307 cfg.scan_config, cfg.fw_mode_config);
2308
2309 status = sme_soc_set_dual_mac_config(cfg);
2310 if (status != QDF_STATUS_SUCCESS) {
2311 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
2312 return status;
2313 }
2314
2315 return QDF_STATUS_SUCCESS;
2316}
2317
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002318/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302319 * hdd_start_adapter() - Wrapper function for device specific adapter
2320 * @adapter: pointer to HDD adapter
2321 *
2322 * This function is called to start the device specific adapter for
2323 * the mode passed in the adapter's device_mode.
2324 *
2325 * Return: 0 for success; non-zero for failure
2326 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002327int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302328{
2329
2330 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002331 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302332
Dustin Brownfdf17c12018-03-14 12:55:34 -07002333 hdd_enter_dev(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002334 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302335
2336 switch (device_mode) {
2337 case QDF_P2P_CLIENT_MODE:
2338 case QDF_P2P_DEVICE_MODE:
2339 case QDF_OCB_MODE:
2340 case QDF_STA_MODE:
2341 case QDF_MONITOR_MODE:
2342 ret = hdd_start_station_adapter(adapter);
2343 if (ret)
2344 goto err_start_adapter;
Alok Kumar81e1d732018-09-04 11:10:36 +05302345
2346 hdd_nud_ignore_tracking(adapter, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05302347 break;
2348 case QDF_P2P_GO_MODE:
2349 case QDF_SAP_MODE:
2350 ret = hdd_start_ap_adapter(adapter);
2351 if (ret)
2352 goto err_start_adapter;
2353 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302354 case QDF_IBSS_MODE:
2355 /*
2356 * For IBSS interface is initialized as part of
2357 * hdd_init_station_mode()
2358 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002359 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302360 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002361 /* vdevs are dynamically managed by firmware in FTM */
2362 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302363 default:
2364 hdd_err("Invalid session type %d", device_mode);
2365 QDF_ASSERT(0);
2366 goto err_start_adapter;
2367 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002368
Arun Khandavallifae92942016-08-01 13:31:08 +05302369 if (hdd_set_fw_params(adapter))
2370 hdd_err("Failed to set the FW params for the adapter!");
2371
Dustin Browne7e71d32018-05-11 16:00:08 -07002372 if (adapter->session_id != HDD_SESSION_ID_INVALID) {
2373 ret = wlan_hdd_cfg80211_register_frames(adapter);
2374 if (ret < 0) {
2375 hdd_err("Failed to register frames - ret %d", ret);
2376 goto err_start_adapter;
2377 }
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302378 }
Dustin Browne7e71d32018-05-11 16:00:08 -07002379
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002380 wlan_hdd_update_dbs_scan_and_fw_mode_config();
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302381
Dustin Browndb2a8be2017-12-20 11:49:56 -08002382exit_with_success:
Dustin Browne74003f2018-03-14 12:51:58 -07002383 hdd_exit();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002384
Arun Khandavallifae92942016-08-01 13:31:08 +05302385 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002386
Arun Khandavallifae92942016-08-01 13:31:08 +05302387err_start_adapter:
2388 return -EINVAL;
2389}
2390
2391/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302392 * hdd_enable_power_management() - API to Enable Power Management
2393 *
2394 * API invokes Bus Interface Layer power management functionality
2395 *
2396 * Return: None
2397 */
2398static void hdd_enable_power_management(void)
2399{
2400 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2401
2402 if (!hif_ctx) {
2403 hdd_err("Bus Interface Context is Invalid");
2404 return;
2405 }
2406
2407 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2408}
2409
2410/**
2411 * hdd_disable_power_management() - API to disable Power Management
2412 *
2413 * API disable Bus Interface Layer Power management functionality
2414 *
2415 * Return: None
2416 */
2417static void hdd_disable_power_management(void)
2418{
2419 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2420
2421 if (!hif_ctx) {
2422 hdd_err("Bus Interface Context is Invalid");
2423 return;
2424 }
2425
2426 hif_disable_power_management(hif_ctx);
2427}
2428
Ryan Hsuaadba072018-04-20 13:01:53 -07002429void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302430{
2431 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002432 size_t target_hw_name_len;
2433 const char *target_hw_name;
Ryan Hsuaadba072018-04-20 13:01:53 -07002434 uint8_t *buf;
2435 uint32_t buf_len;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302436
2437 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2438 if (!hif_sc) {
2439 hdd_err("HIF context is NULL");
2440 return;
2441 }
2442
Ryan Hsuaadba072018-04-20 13:01:53 -07002443 hif_get_hw_info(hif_sc, &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302444 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002445 &target_hw_name);
2446
2447 if (hdd_ctx->target_hw_name)
2448 qdf_mem_free(hdd_ctx->target_hw_name);
2449
2450 target_hw_name_len = strlen(target_hw_name) + 1;
2451 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2452 if (hdd_ctx->target_hw_name)
2453 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2454 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302455
Ryan Hsuaadba072018-04-20 13:01:53 -07002456 buf = qdf_mem_malloc(WE_MAX_STR_LEN);
2457 if (buf) {
2458 buf_len = hdd_wlan_get_version(hdd_ctx, WE_MAX_STR_LEN, buf);
2459 hdd_info("%s", buf);
2460 qdf_mem_free(buf);
2461 }
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302462}
2463
2464/**
gbian62edd7e2017-03-07 13:12:13 +08002465 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2466 * @hdd_ctx: Pointer to hdd context
2467 *
2468 * Return: none
2469 */
2470static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002471hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002472{
2473 uint8_t num_entries = 0;
2474 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2475 uint8_t *tx_sched_wrr_ac;
2476 int i;
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002477 struct cds_context *cds_ctx;
gbian62edd7e2017-03-07 13:12:13 +08002478
2479 if (NULL == hdd_ctx)
2480 return;
2481
2482 if (NULL == hdd_ctx->config) {
2483 /* Do nothing if hdd_ctx is invalid */
2484 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2485 return;
2486 }
2487
2488 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2489
2490 if (!cds_ctx) {
2491 hdd_err("Invalid CDS Context");
2492 return;
2493 }
2494
2495 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2496 switch (i) {
2497 case OL_TX_WMM_AC_BE:
2498 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2499 break;
2500 case OL_TX_WMM_AC_BK:
2501 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2502 break;
2503 case OL_TX_WMM_AC_VI:
2504 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2505 break;
2506 case OL_TX_WMM_AC_VO:
2507 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2508 break;
2509 default:
2510 tx_sched_wrr_ac = NULL;
2511 break;
2512 }
2513
2514 hdd_string_to_u8_array(tx_sched_wrr_ac,
2515 tx_sched_wrr_param,
2516 &num_entries,
2517 sizeof(tx_sched_wrr_param));
2518
2519 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2520 cds_ctx->ac_specs[i].wrr_skip_weight =
2521 tx_sched_wrr_param[0];
2522 cds_ctx->ac_specs[i].credit_threshold =
2523 tx_sched_wrr_param[1];
2524 cds_ctx->ac_specs[i].send_limit =
2525 tx_sched_wrr_param[2];
2526 cds_ctx->ac_specs[i].credit_reserve =
2527 tx_sched_wrr_param[3];
2528 cds_ctx->ac_specs[i].discard_weight =
2529 tx_sched_wrr_param[4];
2530 }
2531
2532 num_entries = 0;
2533 }
2534}
2535
Ryan Hsuaadba072018-04-20 13:01:53 -07002536uint32_t hdd_wlan_get_version(struct hdd_context *hdd_ctx,
2537 const size_t version_len, uint8_t *version)
2538{
2539 uint32_t size;
2540 uint32_t msp_id = 0, mspid = 0, siid = 0, crmid = 0, sub_id = 0;
2541
2542 if (!hdd_ctx) {
2543 hdd_err("Invalid context, HDD context is null");
2544 return 0;
2545 }
2546
Ashish Kumar Dhanotiya7353f882018-05-15 12:50:19 +05302547 if (!version || version_len == 0) {
Ryan Hsuaadba072018-04-20 13:01:53 -07002548 hdd_err("Invalid buffer pointr or buffer len\n");
2549 return 0;
2550 }
2551
2552 msp_id = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
2553 mspid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
2554 siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
2555 crmid = hdd_ctx->target_fw_version & 0x7fff;
2556 sub_id = (hdd_ctx->target_fw_vers_ext & 0xf0000000) >> 28;
2557
2558 size = scnprintf(version, version_len,
Ryan Hsuc6918552018-05-16 13:29:59 -07002559 "Host SW:%s, FW:%d.%d.%d.%d.%d, HW:%s, Board ver: %x Ref design id: %x, Customer id: %x, Project id: %x, Board Data Rev: %x",
Ryan Hsuaadba072018-04-20 13:01:53 -07002560 QWLAN_VERSIONSTR,
2561 msp_id, mspid, siid, crmid, sub_id,
Ryan Hsuc6918552018-05-16 13:29:59 -07002562 hdd_ctx->target_hw_name,
2563 hdd_ctx->hw_bd_info.bdf_version,
2564 hdd_ctx->hw_bd_info.ref_design_id,
2565 hdd_ctx->hw_bd_info.customer_id,
2566 hdd_ctx->hw_bd_info.project_id,
2567 hdd_ctx->hw_bd_info.board_data_rev);
Ryan Hsuaadba072018-04-20 13:01:53 -07002568
2569 return size;
2570}
2571
Rachit Kankane0dc3e852018-05-07 17:33:42 +05302572int hdd_set_11ax_rate(struct hdd_adapter *adapter, int set_value,
2573 struct sap_config *sap_config)
2574{
2575 uint8_t preamble = 0, nss = 0, rix = 0;
2576 int ret;
2577 mac_handle_t mac_handle = adapter->hdd_ctx->mac_handle;
2578
2579 if (!sap_config) {
2580 if (!sme_is_feature_supported_by_fw(DOT11AX)) {
2581 hdd_err("Target does not support 11ax");
2582 return -EIO;
2583 }
2584 } else if (sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax &&
2585 sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax_ONLY) {
2586 hdd_err("Invalid hw mode, SAP hw_mode= 0x%x, ch = %d",
2587 sap_config->SapHw_mode, sap_config->channel);
2588 return -EIO;
2589 }
2590
2591 if (set_value != 0xff) {
2592 rix = RC_2_RATE_IDX_11AX(set_value);
2593 preamble = WMI_RATE_PREAMBLE_HE;
2594 nss = HT_RC_2_STREAMS_11AX(set_value);
2595
2596 set_value = hdd_assemble_rate_code(preamble, nss, rix);
2597 } else {
2598 ret = sme_set_auto_rate_he_ltf(mac_handle, adapter->session_id,
2599 QCA_WLAN_HE_LTF_AUTO);
2600 }
2601
2602 hdd_info("SET_11AX_RATE val %d rix %d preamble %x nss %d",
2603 set_value, rix, preamble, nss);
2604
2605 ret = wma_cli_set_command(adapter->session_id,
2606 WMI_VDEV_PARAM_FIXED_RATE,
2607 set_value, VDEV_CMD);
2608
2609 return ret;
2610}
2611
2612int hdd_assemble_rate_code(uint8_t preamble, uint8_t nss, uint8_t rate)
2613{
2614 int set_value;
2615
2616 if (sme_is_feature_supported_by_fw(DOT11AX))
2617 set_value = WMI_ASSEMBLE_RATECODE_V1(rate, nss, preamble);
2618 else
2619 set_value = (preamble << 6) | (nss << 4) | rate;
2620
2621 return set_value;
2622}
2623
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302624#ifdef IPA_OFFLOAD
2625/**
2626 * hdd_update_ipa_component_config() - update ipa config
2627 * @hdd_ctx: Pointer to hdd context
2628 *
2629 * Return: none
2630 */
2631static void hdd_update_ipa_component_config(struct hdd_context *hdd_ctx)
2632{
2633 struct hdd_config *cfg = hdd_ctx->config;
2634 struct wlan_ipa_config ipa_cfg;
2635
2636 ipa_cfg.ipa_config = cfg->IpaConfig;
2637 ipa_cfg.desc_size = cfg->IpaDescSize;
2638 ipa_cfg.txbuf_count = cfg->IpaUcTxBufCount;
2639 ipa_cfg.bus_bw_high = cfg->busBandwidthHighThreshold;
2640 ipa_cfg.bus_bw_medium = cfg->busBandwidthMediumThreshold;
2641 ipa_cfg.bus_bw_low = cfg->busBandwidthLowThreshold;
2642 ipa_cfg.ipa_bw_high = cfg->IpaHighBandwidthMbps;
2643 ipa_cfg.ipa_bw_medium = cfg->IpaMediumBandwidthMbps;
2644 ipa_cfg.ipa_bw_low = cfg->IpaLowBandwidthMbps;
2645
2646 ucfg_ipa_update_config(&ipa_cfg);
2647}
2648#else
2649static void hdd_update_ipa_component_config(struct hdd_context *hdd_ctx)
2650{
2651}
2652#endif
2653
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002654#ifdef FEATURE_WLAN_WAPI
2655/**
2656 * hdd_wapi_security_sta_exist() - return wapi security sta exist or not
2657 *
2658 * This API returns the wapi security station exist or not
2659 *
2660 * Return: true - wapi security station exist
2661 */
2662static bool hdd_wapi_security_sta_exist(void)
2663{
2664 struct hdd_adapter *adapter = NULL;
2665 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2666
2667 hdd_for_each_adapter(hdd_ctx, adapter) {
2668 if ((adapter->device_mode == QDF_STA_MODE) &&
2669 adapter->wapi_info.wapi_mode &&
2670 (adapter->wapi_info.wapi_auth_mode != WAPI_AUTH_MODE_OPEN))
2671 return true;
2672 }
2673 return false;
2674}
2675#else
2676static bool hdd_wapi_security_sta_exist(void)
2677{
2678 return false;
2679}
2680#endif
2681
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002682#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002683static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2684 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2685{
Jeff Johnson9d295242017-08-29 14:39:48 -07002686 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002687 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002688
2689 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2690 if (!adapter) {
2691 hdd_err("Adapter is NULL");
2692 return PM_MAX_NUM_OF_MODE;
2693 }
2694
2695 return policy_mgr_convert_device_mode_to_qdf_type(
2696 adapter->device_mode);
2697}
2698
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002699static void hdd_register_policy_manager_callback(
2700 struct wlan_objmgr_psoc *psoc)
2701{
2702 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002703
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002704 qdf_mem_zero(&hdd_cbacks, sizeof(hdd_cbacks));
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002705 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002706 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002707 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2708 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002709 hdd_cbacks.get_mode_for_non_connected_vdev =
2710 wlan_hdd_get_mode_for_non_connected_vdev;
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05302711 hdd_cbacks.hdd_get_device_mode = hdd_get_device_mode;
Liangwei Dong3fa5cba2018-07-16 06:41:55 -04002712 hdd_cbacks.hdd_wapi_security_sta_exist =
2713 hdd_wapi_security_sta_exist;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002714 if (QDF_STATUS_SUCCESS !=
2715 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2716 hdd_err("HDD callback registration with policy manager failed");
2717 }
2718}
2719#else
2720static void hdd_register_policy_manager_callback(
2721 struct wlan_objmgr_psoc *psoc)
2722{
2723}
2724#endif
2725
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002726static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002727{
2728 struct nan_callbacks cb_obj = {0};
2729
2730 cb_obj.ndi_open = hdd_ndi_open;
2731 cb_obj.ndi_close = hdd_ndi_close;
2732 cb_obj.ndi_start = hdd_ndi_start;
2733 cb_obj.ndi_delete = hdd_ndi_delete;
2734 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2735 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2736
Naveen Rawat37f62c82017-03-26 22:24:43 -07002737 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2738 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002739 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002740
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002741 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2742}
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002743
Dustin Brown26b3d042017-12-21 11:13:27 -08002744#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002745/**
2746 * hdd_check_for_leaks() - Perform runtime memory leak checks
Dustin Browna6246dd2018-05-24 14:35:58 -07002747 * @hdd_ctx: the global HDD context
Dustin Brown29533f22018-07-24 13:11:56 -07002748 * @is_ssr: true if SSR is in progress
Dustin Brown4c5b9902017-12-19 11:17:19 -08002749 *
2750 * This API triggers runtime memory leak detection. This feature enforces the
2751 * policy that any memory allocated at runtime must also be released at runtime.
2752 *
2753 * Allocating memory at runtime and releasing it at unload is effectively a
2754 * memory leak for configurations which never unload (e.g. LONU, statically
2755 * compiled driver). Such memory leaks are NOT false positives, and must be
2756 * fixed.
2757 *
2758 * Return: None
2759 */
Dustin Brown29533f22018-07-24 13:11:56 -07002760static void hdd_check_for_leaks(struct hdd_context *hdd_ctx, bool is_ssr)
Dustin Brown4bc0a622017-12-06 15:56:50 -08002761{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002762 /* DO NOT REMOVE these checks; for false positives, read above first */
2763
Dustin Brown3cfe0d42018-07-25 14:13:47 -07002764 wlan_objmgr_psoc_check_for_peer_leaks(hdd_ctx->hdd_psoc);
Dustin Browna6246dd2018-05-24 14:35:58 -07002765 wlan_objmgr_psoc_check_for_vdev_leaks(hdd_ctx->hdd_psoc);
Dustin Brown29462962018-06-18 14:02:00 -07002766 wlan_objmgr_psoc_check_for_pdev_leaks(hdd_ctx->hdd_psoc);
Dustin Brown29533f22018-07-24 13:11:56 -07002767
2768 /* many adapter resources are not freed by design during SSR */
2769 if (is_ssr)
2770 return;
2771
Dustin Brown677e0862017-10-10 16:30:09 -07002772 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002773 qdf_nbuf_map_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002774 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002775}
2776
Dustin Brown26b3d042017-12-21 11:13:27 -08002777#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2778#else
Dustin Brown29533f22018-07-24 13:11:56 -07002779static inline void hdd_check_for_leaks(struct hdd_context *hdd_ctx, bool is_ssr)
2780{ }
Dustin Brown26b3d042017-12-21 11:13:27 -08002781
2782#define hdd_debug_domain_set(domain)
2783#endif /* CONFIG_LEAK_DETECTION */
2784
gbian62edd7e2017-03-07 13:12:13 +08002785/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002786 * hdd_update_country_code - Update country code
2787 * @hdd_ctx: HDD context
2788 *
2789 * Update country code based on module parameter country_code
2790 *
2791 * Return: 0 on success and errno on failure
2792 */
2793static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2794{
2795 if (!country_code)
2796 return 0;
2797
2798 return hdd_reg_set_country(hdd_ctx, country_code);
2799}
2800
2801/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302802 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2803 * @hdd_ctx: HDD context
Arun Khandavallifae92942016-08-01 13:31:08 +05302804 * @reinit: flag to indicate from SSR or normal path
2805 *
2806 * This function maintains the driver state machine it will be invoked from
2807 * startup, reinit and change interface. Depending on the driver state shall
2808 * perform the opening of the modules.
2809 *
2810 * Return: 0 for success; non-zero for failure
2811 */
Dustin Browne7e71d32018-05-11 16:00:08 -07002812int hdd_wlan_start_modules(struct hdd_context *hdd_ctx, bool reinit)
Arun Khandavallifae92942016-08-01 13:31:08 +05302813{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002814 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302815 qdf_device_t qdf_dev;
2816 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302817 bool unint = false;
2818 void *hif_ctx;
Jingxiang Ge95912f82018-04-19 12:01:26 +08002819 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +05302820
Arun Khandavallifae92942016-08-01 13:31:08 +05302821 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2822 if (!qdf_dev) {
2823 hdd_err("QDF Device Context is Invalid return");
2824 return -EINVAL;
2825 }
2826
Dustin Brown6f427922017-09-19 12:19:00 -07002827 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05302828
Dustin Brown1fe30a82017-10-03 16:13:36 -07002829 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302830 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2831 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002832 hdd_debug("Driver modules already Enabled");
Dustin Browne74003f2018-03-14 12:51:58 -07002833 hdd_exit();
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302834 return 0;
2835 }
2836
Dustin Brown1fe30a82017-10-03 16:13:36 -07002837 hdd_ctx->start_modules_in_progress = true;
2838
Arun Khandavallifae92942016-08-01 13:31:08 +05302839 switch (hdd_ctx->driver_status) {
2840 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002841 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302842 unint = true;
2843 /* Fall through dont add break here */
2844 case DRIVER_MODULES_CLOSED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002845 hdd_info("Wlan transitioning (CLOSED -> OPENED)");
2846
Dustin Brown26b3d042017-12-21 11:13:27 -08002847 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002848
Arun Khandavallifae92942016-08-01 13:31:08 +05302849 if (!reinit && !unint) {
2850 ret = pld_power_on(qdf_dev->dev);
2851 if (ret) {
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002852 hdd_err("Failed to power up device; errno:%d",
Dustin Browndca39692017-11-09 15:30:25 -08002853 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302854 goto release_lock;
2855 }
2856 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002857
2858 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2859 hdd_ctx->config->enable_fw_log);
Arun Khandavallifae92942016-08-01 13:31:08 +05302860 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2861 qdf_dev->bus_type,
2862 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2863 HIF_ENABLE_TYPE_PROBE);
2864 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002865 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302866 goto power_down;
2867 }
2868
2869 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302870 if (!hif_ctx) {
2871 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002872 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302873 goto power_down;
2874 }
2875
Arun Khandavallifae92942016-08-01 13:31:08 +05302876 status = ol_cds_init(qdf_dev, hif_ctx);
2877 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002878 hdd_err("No Memory to Create BMI Context; status: %d",
2879 status);
2880 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302881 goto hif_close;
2882 }
2883
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302884 hdd_update_ipa_component_config(hdd_ctx);
2885
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002886 ret = hdd_update_config(hdd_ctx);
2887 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002888 hdd_err("Failed to update configuration; errno: %d",
2889 ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002890 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002891 }
2892
gbian62edd7e2017-03-07 13:12:13 +08002893 hdd_update_cds_ac_specs_params(hdd_ctx);
2894
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05302895 status = hdd_component_psoc_open(hdd_ctx->hdd_psoc);
2896 if (QDF_IS_STATUS_ERROR(status)) {
2897 hdd_err("Failed to Open legacy components; status: %d",
2898 status);
2899 ret = qdf_status_to_os_return(status);
2900 goto deinit_config;
2901 }
2902
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302903 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002904 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002905 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002906 ret = qdf_status_to_os_return(status);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05302907 goto hdd_psoc_close;
Arun Khandavallifae92942016-08-01 13:31:08 +05302908 }
2909
Manjunathappa Prakashb6b4ff12018-06-04 12:32:33 -07002910 if (hdd_ctx->config->rx_thread_affinity_mask)
2911 cds_set_rx_thread_cpu_mask(
2912 hdd_ctx->config->rx_thread_affinity_mask);
2913
2914 /* initialize components configurations after psoc open */
Mukul Sharma9d797a02017-01-05 20:26:03 +05302915 ret = hdd_update_components_config(hdd_ctx);
2916 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002917 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302918 ret);
2919 goto close;
2920 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002921 status = cds_dp_open(hdd_ctx->hdd_psoc);
2922 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002923 hdd_err("Failed to Open cds post open; status: %d",
2924 status);
2925 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002926 goto close;
2927 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302928
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002929 /*
2930 * NAN compoenet requires certian operations like, open adapter,
2931 * close adapter, etc. to be initiated by HDD, for those
2932 * register HDD callbacks with UMAC's NAN componenet.
2933 */
2934 hdd_nan_register_callbacks(hdd_ctx);
2935
Jeff Johnson16528362018-06-14 12:34:16 -07002936 hdd_ctx->mac_handle = cds_get_context(QDF_MODULE_ID_SME);
Arun Khandavallifae92942016-08-01 13:31:08 +05302937
Jeff Johnson3a280122017-09-13 07:42:00 -07002938 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302939 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002940 hdd_err("Failed to pre-enable CDS; status: %d", status);
2941 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002942 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302943 }
2944
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002945 hdd_register_policy_manager_callback(
2946 hdd_ctx->hdd_psoc);
2947
Amar Singhal0928b192017-12-01 10:50:54 -08002948 hdd_sysfs_create_version_interface(hdd_ctx->hdd_psoc);
2949
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302950 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302951 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002952 hdd_info("Wlan transitioned (now OPENED)");
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302953
Arun Khandavallifae92942016-08-01 13:31:08 +05302954 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002955 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302956 break;
2957 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302958
Arun Khandavallifae92942016-08-01 13:31:08 +05302959 /* Fall through dont add break here */
2960 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002961 hdd_info("Wlan transitioning (OPENED -> ENABLED)");
2962
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302963 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2964 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002965 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302966 break;
2967 }
Dustin Browndca39692017-11-09 15:30:25 -08002968
Dustin Browne7e71d32018-05-11 16:00:08 -07002969 ret = hdd_configure_cds(hdd_ctx);
Dustin Browndca39692017-11-09 15:30:25 -08002970 if (ret) {
2971 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002972 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302973 }
Dustin Browndca39692017-11-09 15:30:25 -08002974
Komal Seelamf2136bb2016-09-28 18:30:44 +05302975 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002976
Arun Khandavallifae92942016-08-01 13:31:08 +05302977 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002978 hdd_info("Wlan transitioned (now ENABLED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302979 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002980
Arun Khandavallifae92942016-08-01 13:31:08 +05302981 default:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -07002982 QDF_DEBUG_PANIC("Unknown driver state:%d",
Arun Khandavallifae92942016-08-01 13:31:08 +05302983 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002984 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302985 goto release_lock;
2986 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002987
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302988 hdd_ctx->start_modules_in_progress = false;
Paul Zhange03cf4c2018-01-19 18:33:22 +08002989 if (DRIVER_MODULES_ENABLED == hdd_ctx->driver_status) {
2990 ret = hdd_update_country_code(hdd_ctx);
2991 if (ret)
2992 hdd_err("Failed to update command line country code!");
2993 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302994 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002995
Dustin Browne74003f2018-03-14 12:51:58 -07002996 hdd_exit();
Dustin Brown550f6d22017-12-14 15:44:01 -08002997
Arun Khandavallifae92942016-08-01 13:31:08 +05302998 return 0;
2999
Rajeev Kumara3f672f2017-02-16 13:59:37 -08003000post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08003001 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08003002
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07003003cds_txrx_free:
Jingxiang Ge95912f82018-04-19 12:01:26 +08003004 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
3005
3006 if (tgt_hdl && target_psoc_get_wmi_ready(tgt_hdl)) {
3007 hdd_runtime_suspend_context_deinit(hdd_ctx);
3008 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
3009 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
3010 }
3011
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07003012 cds_dp_close(hdd_ctx->hdd_psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08003013
Arun Khandavallifae92942016-08-01 13:31:08 +05303014close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08003015 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08003016 hdd_info("Wlan transition aborted (now CLOSED)");
3017
Jeff Johnsone4b14592017-09-13 14:23:33 -07003018 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05303019
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05303020hdd_psoc_close:
3021 hdd_component_psoc_close(hdd_ctx->hdd_psoc);
3022
Dustin Brown28b17892017-10-10 13:29:38 -07003023deinit_config:
3024 cds_deinit_ini_config();
3025
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07003026cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05303027 ol_cds_free();
3028
3029hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07003030 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
3031 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05303032power_down:
3033 if (!reinit && !unint)
3034 pld_power_off(qdf_dev->dev);
3035release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05303036 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05303037 mutex_unlock(&hdd_ctx->iface_change_lock);
Abhinav Kumar7ae9b7b2017-12-19 15:11:54 +05303038 if (hdd_ctx->target_hw_name) {
3039 qdf_mem_free(hdd_ctx->target_hw_name);
3040 hdd_ctx->target_hw_name = NULL;
3041 }
Dustin Brown29533f22018-07-24 13:11:56 -07003042
3043 hdd_check_for_leaks(hdd_ctx, reinit);
Dustin Brown26b3d042017-12-21 11:13:27 -08003044 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08003045
Dustin Browne74003f2018-03-14 12:51:58 -07003046 hdd_exit();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08003047
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07003048 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05303049}
3050
Naveen Rawat910726a2017-03-06 11:42:51 -08003051#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003052static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003053{
3054 int ret = os_if_wifi_pos_register_nl();
3055
3056 if (ret)
3057 hdd_err("os_if_wifi_pos_register_nl failed");
3058
3059 return ret;
3060}
3061
3062static int hdd_deactivate_wifi_pos(void)
3063{
3064 int ret = os_if_wifi_pos_deregister_nl();
3065
3066 if (ret)
3067 hdd_err("os_if_wifi_pos_deregister_nl failed");
3068
3069 return ret;
3070}
3071
3072/**
3073 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
3074 * @hdd_ctx: hdd context
3075 *
3076 * Return: status of operation
3077 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003078static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003079{
3080 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3081 struct hdd_config *cfg = hdd_ctx->config;
3082
3083 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
3084 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
3085 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
3086 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
3087 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
3088 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
3089 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
3090 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
3091}
3092#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003093static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003094{
3095 return oem_activate_service(hdd_ctx);
3096}
3097
3098static int hdd_deactivate_wifi_pos(void)
3099{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05303100 return oem_deactivate_service();
Naveen Rawat910726a2017-03-06 11:42:51 -08003101}
3102
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003103static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003104{
3105}
3106#endif
3107
Arun Khandavallifae92942016-08-01 13:31:08 +05303108/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003109 * __hdd_open() - HDD Open function
3110 * @dev: Pointer to net_device structure
3111 *
3112 * This is called in response to ifconfig up
3113 *
3114 * Return: 0 for success; non-zero for failure
3115 */
3116static int __hdd_open(struct net_device *dev)
3117{
Jeff Johnson9d295242017-08-29 14:39:48 -07003118 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003119 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003120 int ret;
3121
Dustin Brownfdf17c12018-03-14 12:55:34 -07003122 hdd_enter_dev(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303123 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003124 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003125
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05303126 /* Nothing to be done if device is unloading */
3127 if (cds_is_driver_unloading()) {
3128 hdd_err("Driver is unloading can not open the hdd");
3129 return -EBUSY;
3130 }
3131
Dustin Brown01847752017-10-25 13:56:27 -07003132 if (cds_is_driver_recovering()) {
3133 hdd_err("WLAN is currently recovering; Please try again.");
3134 return -EBUSY;
3135 }
3136
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05303137 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
3138 hdd_err("con_mode_handler is in progress; Please try again.");
3139 return -EBUSY;
3140 }
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303141
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05303142 mutex_lock(&hdd_init_deinit_lock);
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05303143 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
3144
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303145 /*
3146 * This scenario can be hit in cases where in the wlan driver after
3147 * registering the netdevices and there is a failure in driver
3148 * initialization. So return error gracefully because the netdevices
3149 * will be de-registered as part of the load failure.
3150 */
3151
3152 if (!cds_is_driver_loaded()) {
3153 hdd_err("Failed to start the wlan driver!!");
3154 ret = -EIO;
3155 goto err_hdd_hdd_init_deinit_lock;
3156 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303157
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003158
Dustin Browne7e71d32018-05-11 16:00:08 -07003159 ret = hdd_wlan_start_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05303160 if (ret) {
3161 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303162 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05303163 }
3164
3165
3166 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3167 ret = hdd_start_adapter(adapter);
3168 if (ret) {
3169 hdd_err("Failed to start adapter :%d",
3170 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303171 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05303172 }
3173 }
3174
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003175 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3176 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003177 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003178 /* Enable TX queues only when we are connected */
3179 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05303180 WLAN_START_ALL_NETIF_QUEUE,
3181 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003182 }
3183
Naveen Rawat286def52016-09-23 15:38:02 -07003184 /* Enable carrier and transmit queues for NDI */
3185 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003186 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07003187 wlan_hdd_netif_queue_control(adapter,
3188 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
3189 WLAN_CONTROL_PATH);
3190 }
3191
Naveen Rawat910726a2017-03-06 11:42:51 -08003192 hdd_populate_wifi_pos_cfg(hdd_ctx);
Arunk Khandavalli40943af2017-05-15 19:25:34 +05303193 hdd_lpass_notify_start(hdd_ctx, adapter);
Naveen Rawat910726a2017-03-06 11:42:51 -08003194
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303195err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05303196 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303197 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003198 return ret;
3199}
3200
Arun Khandavallifae92942016-08-01 13:31:08 +05303201
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003202/**
3203 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
3204 * @dev: Pointer to net_device structure
3205 *
3206 * This is called in response to ifconfig up
3207 *
3208 * Return: 0 for success; non-zero for failure
3209 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003210static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003211{
3212 int ret;
3213
3214 cds_ssr_protect(__func__);
3215 ret = __hdd_open(dev);
3216 cds_ssr_unprotect(__func__);
3217
3218 return ret;
3219}
3220
3221/**
3222 * __hdd_stop() - HDD stop function
3223 * @dev: Pointer to net_device structure
3224 *
3225 * This is called in response to ifconfig down
3226 *
3227 * Return: 0 for success; non-zero for failure
3228 */
3229static int __hdd_stop(struct net_device *dev)
3230{
Jeff Johnson9d295242017-08-29 14:39:48 -07003231 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003232 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003233 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -07003234 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003235
Dustin Brownfdf17c12018-03-14 12:55:34 -07003236 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003237
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303238 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003239 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003240
3241 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303242 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003243 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003244
3245 /* Nothing to be done if the interface is not opened */
3246 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003247 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003248 return -ENODEV;
3249 }
3250
3251 /* Make sure the interface is marked as closed */
3252 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303253
Jeff Johnson16528362018-06-14 12:34:16 -07003254 mac_handle = hdd_ctx->mac_handle;
3255
Mukul Sharmad16c2022017-07-25 18:56:12 +05303256 hdd_debug("Disabling Auto Power save timer");
3257 sme_ps_disable_auto_ps_timer(
Jeff Johnson16528362018-06-14 12:34:16 -07003258 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003259 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303260
3261 /*
3262 * Disable TX on the interface, after this hard_start_xmit() will not
3263 * be called on that interface
3264 */
Dustin Browna7bb6ae2018-08-16 16:51:50 -07003265 hdd_debug("Disabling queues, adapter device mode: %s(%d)",
3266 hdd_device_mode_to_string(adapter->device_mode),
3267 adapter->device_mode);
Kabilan Kannan8dac3502017-10-30 12:40:27 -07003268
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303269 wlan_hdd_netif_queue_control(adapter,
3270 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3271 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003272
Arunk Khandavalli40943af2017-05-15 19:25:34 +05303273 if (adapter->device_mode == QDF_STA_MODE)
3274 hdd_lpass_notify_stop(hdd_ctx);
3275
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003276 /*
Naveen Rawat286def52016-09-23 15:38:02 -07003277 * NAN data interface is different in some sense. The traffic on NDI is
3278 * bursty in nature and depends on the need to transfer. The service
3279 * layer may down the interface after the usage and up again when
3280 * required. In some sense, the NDI is expected to be available
3281 * (like SAP) iface until NDI delete request is issued by the service
3282 * layer. Skip BSS termination and adapter deletion for NAN Data
3283 * interface (NDI).
3284 */
3285 if (WLAN_HDD_IS_NDI(adapter))
3286 return 0;
3287
3288 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003289 * The interface is marked as down for outside world (aka kernel)
3290 * But the driver is pretty much alive inside. The driver needs to
3291 * tear down the existing connection on the netdev (session)
3292 * cleanup the data pipes and wait until the control plane is stabilized
3293 * for this interface. The call also needs to wait until the above
3294 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003295 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003296 * That is intentional to be able to scan if it is a STA/P2P interface
3297 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08003298 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003299
3300 /* DeInit the adapter. This ensures datapath cleanup as well */
3301 hdd_deinit_adapter(hdd_ctx, adapter, true);
3302
Arun Khandavallifae92942016-08-01 13:31:08 +05303303
3304 /*
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +05303305 * Upon wifi turn off, DUT has to flush the scan results so if
3306 * this is the last cli iface, flush the scan database.
3307 */
3308 if (!hdd_is_cli_iface_up(hdd_ctx))
Jeff Johnson16528362018-06-14 12:34:16 -07003309 sme_scan_flush_result(mac_handle);
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +05303310
3311 /*
Arun Khandavallifae92942016-08-01 13:31:08 +05303312 * Find if any iface is up. If any iface is up then can't put device to
3313 * sleep/power save mode
3314 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05303315 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003316 hdd_debug("Closing all modules from the hdd_stop");
Dustin Brown6f427922017-09-19 12:19:00 -07003317 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
3318 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05303319 hdd_prevent_suspend_timeout(
3320 hdd_ctx->config->iface_change_wait_time,
3321 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05303322 }
3323
Dustin Browne74003f2018-03-14 12:51:58 -07003324 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003325 return 0;
3326}
3327
3328/**
3329 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3330 * @dev: pointer to net_device structure
3331 *
3332 * This is called in response to ifconfig down
3333 *
3334 * Return: 0 for success and error number for failure
3335 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003336static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003337{
3338 int ret;
3339
3340 cds_ssr_protect(__func__);
3341 ret = __hdd_stop(dev);
3342 cds_ssr_unprotect(__func__);
3343
3344 return ret;
3345}
3346
3347/**
3348 * __hdd_uninit() - HDD uninit function
3349 * @dev: Pointer to net_device structure
3350 *
3351 * This is called during the netdev unregister to uninitialize all data
3352 * associated with the device
3353 *
3354 * Return: None
3355 */
3356static void __hdd_uninit(struct net_device *dev)
3357{
Jeff Johnson9d295242017-08-29 14:39:48 -07003358 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003359 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003360
Dustin Brownfdf17c12018-03-14 12:55:34 -07003361 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003362
3363 do {
3364 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003365 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003366 break;
3367 }
3368
Jeff Johnson399c6272017-08-30 10:51:00 -07003369 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3370 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003371 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003372 break;
3373 }
3374
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003375 if (dev != adapter->dev)
3376 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003377
Jeff Johnson399c6272017-08-30 10:51:00 -07003378 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003379
3380 /* after uninit our adapter structure will no longer be valid */
3381 adapter->dev = NULL;
3382 adapter->magic = 0;
3383 } while (0);
3384
Dustin Browne74003f2018-03-14 12:51:58 -07003385 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003386}
3387
3388/**
3389 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
3390 * @dev: pointer to net_device structure
3391 *
3392 * This is called during the netdev unregister to uninitialize all data
3393 * associated with the device
3394 *
3395 * Return: none
3396 */
3397static void hdd_uninit(struct net_device *dev)
3398{
3399 cds_ssr_protect(__func__);
3400 __hdd_uninit(dev);
3401 cds_ssr_unprotect(__func__);
3402}
3403
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003404static int hdd_open_cesium_nl_sock(void)
3405{
3406#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3407 struct netlink_kernel_cfg cfg = {
3408 .groups = WLAN_NLINK_MCAST_GRP_ID,
3409 .input = NULL
3410 };
3411#endif
3412 int ret = 0;
3413
3414#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3415 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3416#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3417 THIS_MODULE,
3418#endif
3419 &cfg);
3420#else
3421 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3422 WLAN_NLINK_MCAST_GRP_ID,
3423 NULL, NULL, THIS_MODULE);
3424#endif
3425
3426 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003427 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003428 ret = -ECONNREFUSED;
3429 }
3430
3431 return ret;
3432}
3433
3434static void hdd_close_cesium_nl_sock(void)
3435{
3436 if (NULL != cesium_nl_srv_sock) {
3437 netlink_kernel_release(cesium_nl_srv_sock);
3438 cesium_nl_srv_sock = NULL;
3439 }
3440}
3441
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003442/**
3443 * __hdd_set_mac_address() - set the user specified mac address
3444 * @dev: Pointer to the net device.
3445 * @addr: Pointer to the sockaddr.
3446 *
3447 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003448 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003449 *
3450 * Return: 0 for success, non zero for failure
3451 */
3452static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3453{
Jeff Johnson9d295242017-08-29 14:39:48 -07003454 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303455 struct hdd_adapter *adapter_temp;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003456 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003457 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303458 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003459 int ret;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303460 struct qdf_mac_addr mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003461
Dustin Brownfdf17c12018-03-14 12:55:34 -07003462 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003463
Hanumanth Reddy Pothula5c7a7812018-03-09 12:55:32 +05303464 if (netif_running(dev)) {
3465 hdd_err("On iface up, set mac address change isn't supported");
3466 return -EBUSY;
3467 }
3468
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003469 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3470 ret = wlan_hdd_validate_context(hdd_ctx);
3471 if (0 != ret)
3472 return ret;
3473
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303474 qdf_mem_copy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303475 adapter_temp = hdd_get_adapter_by_macaddr(hdd_ctx, mac_addr.bytes);
3476 if (adapter_temp) {
3477 if (!qdf_str_cmp(adapter_temp->dev->name, dev->name))
3478 return 0;
3479 hdd_err("%s adapter exist with same address " MAC_ADDRESS_STR,
3480 adapter_temp->dev->name,
Ashish Kumar Dhanotiyaf974f332018-04-19 16:03:15 +05303481 MAC_ADDR_ARRAY(mac_addr.bytes));
3482 return -EINVAL;
3483 }
3484
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303485 if (qdf_is_macaddr_zero(&mac_addr)) {
3486 hdd_err("MAC is all zero");
3487 return -EINVAL;
3488 }
3489
3490 if (qdf_is_macaddr_broadcast(&mac_addr)) {
3491 hdd_err("MAC is Broadcast");
3492 return -EINVAL;
3493 }
3494
3495 if (ETHER_IS_MULTICAST(psta_mac_addr->sa_data)) {
3496 hdd_err("MAC is Multicast");
3497 return -EINVAL;
3498 }
Ashish Kumar Dhanotiya8bfef122018-04-18 16:48:27 +05303499 hdd_info("Changing MAC to " MAC_ADDRESS_STR " of the interface %s ",
3500 MAC_ADDR_ARRAY(mac_addr.bytes), dev->name);
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303501
Jeff Johnson1e851a12017-10-28 14:36:12 -07003502 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003503 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3504
Dustin Browne74003f2018-03-14 12:51:58 -07003505 hdd_exit();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303506 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003507}
3508
3509/**
3510 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3511 * function from SSR
3512 * @dev: pointer to net_device structure
3513 * @addr: Pointer to the sockaddr
3514 *
3515 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003516 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003517 *
3518 * Return: 0 for success.
3519 */
3520static int hdd_set_mac_address(struct net_device *dev, void *addr)
3521{
3522 int ret;
3523
3524 cds_ssr_protect(__func__);
3525 ret = __hdd_set_mac_address(dev, addr);
3526 cds_ssr_unprotect(__func__);
3527
3528 return ret;
3529}
3530
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003531uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003532{
3533 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003534
Anurag Chouhan6d760662016-02-20 16:05:43 +05303535 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003536 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
3537 break;
3538 }
3539
Anurag Chouhan6d760662016-02-20 16:05:43 +05303540 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003541 return NULL;
3542
3543 hdd_ctx->config->intfAddrMask |= (1 << i);
3544 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
3545}
3546
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003547void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3548 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003549{
3550 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003551
Anurag Chouhan6d760662016-02-20 16:05:43 +05303552 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003553 if (!memcmp(releaseAddr,
3554 &hdd_ctx->config->intfMacAddr[i].bytes[0],
3555 6)) {
3556 hdd_ctx->config->intfAddrMask &= ~(1 << i);
3557 break;
3558 }
3559 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003560}
3561
3562#ifdef WLAN_FEATURE_PACKET_FILTERING
3563/**
3564 * __hdd_set_multicast_list() - set the multicast address list
3565 * @dev: Pointer to the WLAN device.
3566 * @skb: Pointer to OS packet (sk_buff).
3567 *
3568 * This funciton sets the multicast address list.
3569 *
3570 * Return: None
3571 */
3572static void __hdd_set_multicast_list(struct net_device *dev)
3573{
Jeff Johnson9d295242017-08-29 14:39:48 -07003574 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Dustin Brown0f874482018-06-13 14:39:22 -07003575 int i = 0, errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003576 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003577 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303578 struct pmo_mc_addr_list_params *mc_list_request = NULL;
3579 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3580 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003581
Dustin Brownfdf17c12018-03-14 12:55:34 -07003582 hdd_enter_dev(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303583 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303584 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303585
Dustin Brown0f874482018-06-13 14:39:22 -07003586 errno = wlan_hdd_validate_context(hdd_ctx);
3587 if (errno)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303588 goto out;
3589
Dustin Brown0f874482018-06-13 14:39:22 -07003590 errno = hdd_validate_adapter(adapter);
3591 if (errno)
Dustin Brownc788acb2017-08-01 17:43:51 -07003592 goto out;
3593
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303594 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3595 hdd_err("%s: Driver module is closed", __func__);
Dustin Brown0f874482018-06-13 14:39:22 -07003596 goto out;
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303597 }
3598
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303599 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
3600 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003601 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303602 goto out;
3603 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003604
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303605 /* Delete already configured multicast address list */
3606 if (adapter->mc_addr_list.mc_cnt > 0) {
Dustin Brown0f874482018-06-13 14:39:22 -07003607 hdd_debug("clear previously configured MC address list");
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303608 hdd_disable_and_flush_mc_addr_list(adapter,
3609 pmo_mc_list_change_notify);
3610 }
3611
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003612 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003613 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303614 hdd_disable_and_flush_mc_addr_list(adapter,
3615 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003616 } else {
3617 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303618 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003619 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Dustin Brown0f874482018-06-13 14:39:22 -07003620 pmo_ucfg_max_mc_addr_supported(psoc));
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303621 hdd_disable_and_flush_mc_addr_list(adapter,
3622 pmo_mc_list_change_notify);
Dustin Brown0f874482018-06-13 14:39:22 -07003623 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003624 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003625 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003626 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303627 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003628 if (i == mc_count)
3629 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303630 memset(&(mc_list_request->mc_addr[i].bytes),
3631 0, ETH_ALEN);
3632 memcpy(&(mc_list_request->mc_addr[i].bytes),
3633 ha->addr, ETH_ALEN);
Dustin Brown0f874482018-06-13 14:39:22 -07003634 hdd_debug("mlist[%d] = %pM", i,
3635 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003636 i++;
3637 }
3638 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303639
3640 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003641 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303642 mc_list_request->count = mc_count;
Dustin Brown0f874482018-06-13 14:39:22 -07003643
3644 errno = hdd_cache_mc_addr_list(mc_list_request);
3645 if (errno) {
3646 hdd_err("Failed to cache MC address list for vdev %u; errno:%d",
3647 adapter->session_id, errno);
3648 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003649 }
Dustin Brown0f874482018-06-13 14:39:22 -07003650
3651 hdd_enable_mc_addr_filtering(adapter, pmo_mc_list_change_notify);
3652
3653free_req:
3654 qdf_mem_free(mc_list_request);
3655
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303656out:
Dustin Browne74003f2018-03-14 12:51:58 -07003657 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003658}
3659
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303660
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003661/**
3662 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3663 * @dev: pointer to net_device
3664 *
3665 * Return: none
3666 */
3667static void hdd_set_multicast_list(struct net_device *dev)
3668{
3669 cds_ssr_protect(__func__);
3670 __hdd_set_multicast_list(dev);
3671 cds_ssr_unprotect(__func__);
3672}
3673#endif
3674
3675/**
3676 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3677 * @dev: Pointer to the WLAN device.
3678 * @skb: Pointer to OS packet (sk_buff).
3679 *
3680 * This function is registered with the Linux OS for network
3681 * core to decide which queue to use first.
3682 *
3683 * Return: ac, Queue Index/access category corresponding to UP in IP header
3684 */
3685static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3686#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3687 , void *accel_priv
3688#endif
3689#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3690 , select_queue_fallback_t fallback
3691#endif
3692)
3693{
3694 return hdd_wmm_select_queue(dev, skb);
3695}
3696
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003697static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003698 .ndo_open = hdd_open,
3699 .ndo_stop = hdd_stop,
3700 .ndo_uninit = hdd_uninit,
3701 .ndo_start_xmit = hdd_hard_start_xmit,
3702 .ndo_tx_timeout = hdd_tx_timeout,
3703 .ndo_get_stats = hdd_get_stats,
3704 .ndo_do_ioctl = hdd_ioctl,
3705 .ndo_set_mac_address = hdd_set_mac_address,
3706 .ndo_select_queue = hdd_select_queue,
3707#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003708 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003709#endif
3710};
3711
Nirav Shah73713f72018-05-17 14:50:41 +05303712#ifdef FEATURE_MONITOR_MODE_SUPPORT
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003713/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003714static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003715 .ndo_open = hdd_mon_open,
3716 .ndo_stop = hdd_stop,
3717 .ndo_get_stats = hdd_get_stats,
3718};
3719
3720/**
3721 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003722 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003723 * Return: None
3724 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003725void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003726{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003727 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003728 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003729 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003730 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003731}
Nirav Shah73713f72018-05-17 14:50:41 +05303732#else
3733void hdd_set_station_ops(struct net_device *dev)
3734{
3735 dev->netdev_ops = &wlan_drv_ops;
3736}
3737#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003738
3739/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003740 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3741 * @hdd_ctx: global hdd context
3742 * @macAddr: mac address to assign to the interface
3743 * @name: User-visible name of the interface
3744 *
3745 * hdd adapter pointer would point to the netdev->priv space, this function
Jeff Johnson62018292018-05-06 16:18:35 -07003746 * would retrieve the pointer, and setup the hdd adapter configuration.
Ryan Hsu07495ea2016-01-21 15:25:39 -08003747 *
3748 * Return: the pointer to hdd adapter, otherwise NULL
3749 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003750static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003751 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003752 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003753 const char *name)
3754{
Jeff Johnson5505db82017-11-02 21:19:23 -07003755 struct net_device *dev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003756 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003757 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303758 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003759 /*
3760 * cfg80211 initialization and registration....
3761 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003762 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003763#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3764 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003765#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003766 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3767 hdd_mon_mode_ether_setup : ether_setup),
3768 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003769
Jeff Johnson5505db82017-11-02 21:19:23 -07003770 if (dev != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003771
3772 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson5505db82017-11-02 21:19:23 -07003773 adapter = (struct hdd_adapter *) netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003774
Jeff Johnson9d295242017-08-29 14:39:48 -07003775 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Jeff Johnsonb9424862017-10-30 08:49:35 -07003776 sta_ctx = &adapter->session.station;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303777 qdf_mem_set(sta_ctx->conn_info.staId,
3778 sizeof(sta_ctx->conn_info.staId),
3779 HDD_WLAN_INVALID_STA_ID);
Jeff Johnson5505db82017-11-02 21:19:23 -07003780 adapter->dev = dev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003781 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003782 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003783 adapter->session_id = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003784
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303785 qdf_status = qdf_event_create(
3786 &adapter->qdf_session_open_event);
3787 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3788 hdd_err("Session open QDF event init failed!");
3789 free_netdev(adapter->dev);
3790 return NULL;
3791 }
3792
3793 qdf_status = qdf_event_create(
3794 &adapter->qdf_session_close_event);
3795 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3796 hdd_err("Session close QDF event init failed!");
3797 free_netdev(adapter->dev);
3798 return NULL;
3799 }
3800
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003801 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003802 adapter->is_link_up_service_needed = false;
Alok Kumarb64650c2018-03-23 17:05:11 +05303803 adapter->disconnection_in_progress = false;
Yeshwanth Sriram Guntuka4fe30bd2018-06-13 11:41:42 +05303804 adapter->send_mode_change = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003805 /* Init the net_device structure */
Jeff Johnson5505db82017-11-02 21:19:23 -07003806 strlcpy(dev->name, name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003807
Jeff Johnson5505db82017-11-02 21:19:23 -07003808 qdf_mem_copy(dev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003809 sizeof(tSirMacAddr));
Jeff Johnson1e851a12017-10-28 14:36:12 -07003810 qdf_mem_copy(adapter->mac_addr.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003811 sizeof(tSirMacAddr));
Jeff Johnson5505db82017-11-02 21:19:23 -07003812 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003813
3814 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
Jeff Johnson5505db82017-11-02 21:19:23 -07003815 dev->features |=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003816 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Jeff Johnson5505db82017-11-02 21:19:23 -07003817 dev->features |= NETIF_F_RXCSUM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003818
Jeff Johnson5505db82017-11-02 21:19:23 -07003819 hdd_set_tso_flags(hdd_ctx, dev);
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003820
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003821 hdd_set_station_ops(adapter->dev);
3822
Jeff Johnson5505db82017-11-02 21:19:23 -07003823 hdd_dev_setup_destructor(dev);
3824 dev->ieee80211_ptr = &adapter->wdev;
3825 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003826 adapter->wdev.wiphy = hdd_ctx->wiphy;
Jeff Johnson5505db82017-11-02 21:19:23 -07003827 adapter->wdev.netdev = dev;
3828 /* set dev's parent to underlying device */
3829 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003830 hdd_wmm_init(adapter);
3831 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303832 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003833 }
3834
3835 return adapter;
3836}
3837
Jeff Johnson9d295242017-08-29 14:39:48 -07003838static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003839{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003840 struct net_device *dev = adapter->dev;
3841 int ret;
3842
Dustin Brown491d54b2018-03-14 12:39:11 -07003843 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003844
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003845 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003846 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3847
3848 ret = dev_alloc_name(dev, dev->name);
3849 if (ret < 0) {
3850 hdd_err(
3851 "unable to get dev name: %s, err = 0x%x",
3852 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303853 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003854 }
3855 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003856
3857 ret = register_netdevice(dev);
3858 if (ret) {
3859 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3860 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303861 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003862 }
3863 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003864 ret = register_netdev(dev);
3865 if (ret) {
3866 hdd_err("register_netdev(%s) failed, err = 0x%x",
3867 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303868 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003869 }
3870 }
3871 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3872
Dustin Browne74003f2018-03-14 12:51:58 -07003873 hdd_exit();
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003874
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303875 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003876}
3877
Krunal Sonib51eec72017-11-20 21:53:01 -08003878QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003879{
Krunal Sonib51eec72017-11-20 21:53:01 -08003880 struct hdd_adapter *adapter;
3881 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003882
Krunal Sonib51eec72017-11-20 21:53:01 -08003883 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3884 if (!hdd_ctx) {
3885 hdd_err("Invalid HDD_CTX");
3886 return QDF_STATUS_E_FAILURE;
3887 }
3888
3889 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3890 if (NULL == adapter) {
Naveen Rawat23a3b912018-05-30 17:45:52 -07003891 hdd_err("NULL adapter for %d", session_id);
Krunal Sonib51eec72017-11-20 21:53:01 -08003892 return QDF_STATUS_E_INVAL;
3893 }
3894 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303895 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003896 hdd_debug("session %d opened", adapter->session_id);
3897
3898 return QDF_STATUS_SUCCESS;
3899}
3900
3901QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3902{
3903 struct hdd_adapter *adapter;
3904 struct hdd_context *hdd_ctx;
3905
3906 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3907 if (!hdd_ctx) {
3908 hdd_err("Invalid HDD_CTX");
3909 return QDF_STATUS_E_FAILURE;
3910 }
3911
3912 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003913 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003914 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303915 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003916 }
3917
3918 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003919 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303920 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003921 }
3922
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003923 /*
3924 * For NAN Data interface, the close session results in the final
3925 * indication to the userspace
3926 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003927 if (adapter->device_mode == QDF_NDI_MODE)
3928 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003929
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003930 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3931
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003932 /*
3933 * We can be blocked while waiting for scheduled work to be
3934 * flushed, and the adapter structure can potentially be freed, in
3935 * which case the magic will have been reset. So make sure the
3936 * magic is still good, and hence the adapter structure is still
3937 * valid, before signaling completion
3938 */
3939 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303940 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003941
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303942 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003943}
3944
Jeff Johnson9d295242017-08-29 14:39:48 -07003945int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003946{
Dustin Brownd28772b2017-03-17 14:16:07 -07003947 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003948
Dustin Brownd28772b2017-03-17 14:16:07 -07003949 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003950 if (QDF_IS_STATUS_ERROR(status))
3951 return qdf_status_to_os_return(status);
3952
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003953 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003954 if (QDF_IS_STATUS_ERROR(status))
3955 return qdf_status_to_os_return(status);
3956
3957 if (wma_capability_enhanced_mcast_filter())
3958 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3959 else
3960 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003961
3962 return qdf_status_to_os_return(status);
3963}
3964
Jeff Johnson9d295242017-08-29 14:39:48 -07003965int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003966{
3967 QDF_STATUS status;
Dustin Brown2da29eb2018-07-13 14:23:12 -07003968 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003969 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003970 uint8_t vdev_id;
Dustin Brownd28772b2017-03-17 14:16:07 -07003971
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003972 vdev_id = adapter->session_id;
3973 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003974
3975 /* vdev created sanity check */
3976 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Dustin Brown2da29eb2018-07-13 14:23:12 -07003977 hdd_err("vdev %u does not exist", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003978 return -EINVAL;
3979 }
Dustin Brown2da29eb2018-07-13 14:23:12 -07003980
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003981 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Krunal Soni8a06d832018-06-20 16:41:17 -07003982 ucfg_scan_set_vdev_del_in_progress(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003983
Dustin Brownd28772b2017-03-17 14:16:07 -07003984 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303985 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07003986 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -07003987 status = sme_close_session(hdd_ctx->mac_handle, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003988 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Brown2da29eb2018-07-13 14:23:12 -07003989 hdd_err("failed to close sme session; status:%d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003990 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07003991 }
3992
3993 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303994 status = qdf_wait_for_event_completion(
3995 &adapter->qdf_session_close_event,
3996 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
Dustin Brown2da29eb2018-07-13 14:23:12 -07003997
3998 if (QDF_IS_STATUS_ERROR(status)) {
3999 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
4000
Dustin Brownd28772b2017-03-17 14:16:07 -07004001 if (adapter->device_mode == QDF_NDI_MODE)
4002 hdd_ndp_session_end_handler(adapter);
Dustin Brown2da29eb2018-07-13 14:23:12 -07004003
4004 if (status == QDF_STATUS_E_TIMEOUT)
4005 hdd_err("timed out waiting for sme close session");
4006 else if (adapter->qdf_session_close_event.force_set)
4007 hdd_info("SSR occurred during sme close session");
4008 else
4009 hdd_err("failed to wait for sme close session; status:%u",
4010 status);
Dustin Brownd28772b2017-03-17 14:16:07 -07004011 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08004012
Yue Maf9782842017-05-08 12:49:49 -07004013release_vdev:
Krunal Soni8a06d832018-06-20 16:41:17 -07004014 ucfg_scan_clear_vdev_del_in_progress(adapter->hdd_vdev);
Jiachao Wu2c42c222018-01-15 18:13:19 +08004015
Sandeep Puligillaef415362017-08-30 16:37:13 -07004016 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08004017 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07004018 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08004019 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07004020 return errno;
4021 }
4022
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004023 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004024
4025 return 0;
4026}
4027
Krunal Sonib51eec72017-11-20 21:53:01 -08004028static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
4029 struct sme_session_params *session_param,
Jeff Johnson6a18c962018-07-01 09:09:37 -07004030 csr_roam_complete_cb callback,
Krunal Sonib51eec72017-11-20 21:53:01 -08004031 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07004032{
Dustin Brownd28772b2017-03-17 14:16:07 -07004033 uint32_t type;
4034 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08004035 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07004036
4037 /* determine vdev (sub)type */
4038 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304039 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07004040 hdd_err("failed to get vdev type: %d", status);
4041 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004042 }
Krunal Sonib51eec72017-11-20 21:53:01 -08004043 session_param->sme_session_id = adapter->session_id;
4044 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
4045 session_param->type_of_persona = type;
4046 session_param->subtype_of_persona = sub_type;
4047 session_param->session_open_cb = hdd_sme_open_session_callback;
4048 session_param->session_close_cb = hdd_sme_close_session_callback;
4049 session_param->callback = callback;
4050 session_param->callback_ctx = callback_ctx;
4051
4052 return 0;
4053}
4054
4055int hdd_vdev_create(struct hdd_adapter *adapter,
Jeff Johnson6a18c962018-07-01 09:09:37 -07004056 csr_roam_complete_cb callback, void *ctx)
Krunal Sonib51eec72017-11-20 21:53:01 -08004057{
4058 QDF_STATUS status;
4059 int errno;
4060 struct hdd_context *hdd_ctx;
4061 struct sme_session_params sme_session_params = {0};
Krunal Sonib51eec72017-11-20 21:53:01 -08004062
4063 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07004064
4065 /* do vdev create via objmgr */
4066 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07004067 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07004068 if (errno) {
4069 hdd_err("failed to create objmgr vdev: %d", errno);
4070 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004071 }
Dustin Brownd28772b2017-03-17 14:16:07 -07004072
4073 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304074 status = qdf_event_reset(&adapter->qdf_session_open_event);
4075 if (QDF_STATUS_SUCCESS != status) {
4076 hdd_err("failed to reinit session open event");
4077 return -EINVAL;
4078 }
Krunal Sonib51eec72017-11-20 21:53:01 -08004079 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
4080 callback, ctx);
4081 if (errno) {
4082 hdd_err("failed to populating SME params");
4083 goto objmgr_vdev_destroy_procedure;
4084 }
4085
Jeff Johnson16528362018-06-14 12:34:16 -07004086 status = sme_open_session(hdd_ctx->mac_handle, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07004087 if (QDF_IS_STATUS_ERROR(status)) {
4088 hdd_err("failed to open sme session: %d", status);
4089 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07004090 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004091 }
4092
4093 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304094 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
4095 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
4096 if (QDF_STATUS_SUCCESS != status) {
4097 if (adapter->qdf_session_open_event.force_set) {
4098 /*
4099 * SSR/PDR has caused shutdown, which has forcefully
4100 * set the event. Return without the closing session.
4101 */
4102 adapter->session_id = HDD_SESSION_ID_INVALID;
4103 hdd_err("Session open event forcefully set");
4104 return -EINVAL;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304105 }
Jeff Johnsonc66d3102018-02-28 11:58:26 -08004106
4107 if (QDF_STATUS_E_TIMEOUT == status)
4108 hdd_err("Session failed to open within timeout period");
4109 else
4110 hdd_err("Failed to wait for session open event(status-%d)",
4111 status);
4112 errno = -ETIMEDOUT;
4113 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
4114 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004115 }
4116
4117 /* firmware ready for component communication, raise vdev_ready event */
4118 errno = hdd_vdev_ready(adapter);
4119 if (errno) {
4120 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07004121 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004122 }
4123
Naveen Rawat2b430892018-03-13 13:58:18 -07004124 if (adapter->device_mode == QDF_STA_MODE) {
4125 hdd_debug("setting RTT mac randomization param: %d",
4126 hdd_ctx->config->enable_rtt_mac_randomization);
4127 errno = sme_cli_set_command(adapter->session_id,
4128 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_INITIATOR_RANDOM_MAC,
4129 hdd_ctx->config->enable_rtt_mac_randomization,
4130 VDEV_CMD);
4131 if (0 != errno)
4132 hdd_err("RTT mac randomization param set failed %d",
4133 errno);
4134 }
4135
Bala Venkatesh110b03e2018-07-10 16:02:08 +05304136 if (adapter->device_mode == QDF_STA_MODE ||
4137 adapter->device_mode == QDF_P2P_CLIENT_MODE)
4138 wlan_vdev_set_max_peer_count(adapter->hdd_vdev,
4139 HDD_MAX_VDEV_PEER_COUNT);
4140
Jeff Johnson1b780e42017-10-31 14:11:45 -07004141 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004142
4143 return 0;
4144
4145 /*
4146 * Due to legacy constraints, we need to destroy in the same order as
4147 * create. So, split error handling into 2 cases to accommodate.
4148 */
4149
Krunal Soni4a020c72017-10-30 20:58:40 -07004150objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07004151 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07004152
4153 return errno;
4154
Krunal Soni4a020c72017-10-30 20:58:40 -07004155hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07004156 QDF_BUG(!hdd_vdev_destroy(adapter));
4157
4158 return errno;
4159}
4160
Jeff Johnson9d295242017-08-29 14:39:48 -07004161QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07004162{
Jeff Johnsonb9424862017-10-30 08:49:35 -07004163 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004164 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07004165 QDF_STATUS status;
4166 int ret_val;
Jeff Johnson16528362018-06-14 12:34:16 -07004167 mac_handle_t mac_handle;
Dustin Brownd28772b2017-03-17 14:16:07 -07004168
Dustin Brownd28772b2017-03-17 14:16:07 -07004169 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -07004170 mac_handle = hdd_ctx->mac_handle;
4171 sme_set_curr_device_mode(mac_handle, adapter->device_mode);
4172 sme_set_pdev_ht_vht_ies(mac_handle, hdd_ctx->config->enable2x2);
4173 sme_set_vdev_ies_per_band(mac_handle, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004174
Jeff Johnson7f2c5912018-03-23 11:42:28 -07004175 hdd_roam_profile_init(adapter);
4176 hdd_register_wext(adapter->dev);
4177
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07004178 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004179
Jeff Johnsond377dce2017-10-04 10:32:42 -07004180 qdf_mem_set(sta_ctx->conn_info.staId,
4181 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05304182
Deepak Dhamdherea2785822016-11-17 01:17:45 -08004183 /* set fast roaming capability in sme session */
Jeff Johnson16528362018-06-14 12:34:16 -07004184 status = sme_config_fast_roaming(mac_handle, adapter->session_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05304185 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004186 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004187 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004188 hdd_ctx->config->OperatingChannel;
4189
4190 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004191 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004192
4193 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304194 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004195 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004196 status, status);
4197 goto error_init_txrx;
4198 }
4199
4200 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4201
4202 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304203 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004204 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004205 status, status);
4206 goto error_wmm_init;
4207 }
4208
4209 set_bit(WMM_INIT_DONE, &adapter->event_flags);
4210
Jeff Johnson1b780e42017-10-31 14:11:45 -07004211 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004212 WMI_PDEV_PARAM_BURST_ENABLE,
Dundi Raviteja3aa01be2018-05-21 18:58:59 +05304213 HDD_ENABLE_SIFS_BURST_DEFAULT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004214 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07004215 if (ret_val)
4216 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004217
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05304218 /*
4219 * In case of USB tethering, LRO is disabled. If SSR happened
4220 * during that time, then as part of SSR init, do not enable
4221 * the LRO again. Keep the LRO state same as before SSR.
4222 */
Alok Kumar90a73092018-08-03 13:55:09 +05304223 if (hdd_ctx->config->lro_enable &&
4224 !(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07004225 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05304226
4227 /* rcpi info initialization */
4228 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
4229
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304230 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004231
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004232error_wmm_init:
4233 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4234 hdd_deinit_tx_rx(adapter);
4235error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07004236 hdd_unregister_wext(adapter->dev);
Dustin Brownd28772b2017-03-17 14:16:07 -07004237 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004238
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004239 return status;
4240}
4241
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304242/**
Krunal Soni4a020c72017-10-30 20:58:40 -07004243 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304244 * @hdd_ctx: global hdd context
4245 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07004246 * @rtnl_held: Used to indicate whether or not the caller is holding
4247 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304248 *
4249 * This function De-initializes the STA/P2P/OCB adapter.
4250 *
4251 * Return: None.
4252 */
Krunal Soni4a020c72017-10-30 20:58:40 -07004253static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004254 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004255 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304256{
Dustin Brownfdf17c12018-03-14 12:55:34 -07004257 hdd_enter_dev(adapter->dev);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304258
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05304259 if (adapter->dev) {
4260 if (rtnl_held)
4261 adapter->dev->wireless_handlers = NULL;
4262 else {
4263 rtnl_lock();
4264 adapter->dev->wireless_handlers = NULL;
4265 rtnl_unlock();
4266 }
4267 }
4268
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304269 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
4270 hdd_deinit_tx_rx(adapter);
4271 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4272 }
4273
4274 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4275 hdd_wmm_adapter_close(adapter);
4276 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4277 }
4278
Krunal Sonib51eec72017-11-20 21:53:01 -08004279
Dustin Browne74003f2018-03-14 12:51:58 -07004280 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304281}
4282
Krunal Sonib51eec72017-11-20 21:53:01 -08004283void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
4284 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004285 bool rtnl_held)
4286{
Dustin Brown491d54b2018-03-14 12:39:11 -07004287 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304288
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004289 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004290 case QDF_STA_MODE:
4291 case QDF_P2P_CLIENT_MODE:
4292 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08004293 case QDF_IBSS_MODE:
4294 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004295 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004296 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004297 break;
4298 }
4299
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004300 case QDF_SAP_MODE:
4301 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004302 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004303 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004304 break;
4305 }
4306
4307 default:
4308 break;
4309 }
4310
Dustin Browne74003f2018-03-14 12:51:58 -07004311 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004312}
4313
Jeff Johnson9d295242017-08-29 14:39:48 -07004314static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004315 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004316{
Jeff Johnson5505db82017-11-02 21:19:23 -07004317 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004318
4319 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07004320 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004321 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004322 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004323 return;
4324 }
4325
Alok Kumarb64650c2018-03-23 17:05:11 +05304326 hdd_nud_deinit_tracking(adapter);
4327 qdf_mutex_destroy(&adapter->disconnection_status_lock);
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05304328 hdd_apf_context_destroy(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05304329
Rajeev Kumardca5f812016-02-04 17:28:06 -08004330 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05304331
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004332 /*
4333 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
4334 * the driver is almost closed and cannot handle either control
4335 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004336 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
4337 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004338 * is not right. Setting this flag helps hdd_stop() to recognize that
4339 * the interface is closed and restricts any operations on that
4340 */
4341 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
4342
4343 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004344 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07004345 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004346 else
Jeff Johnson5505db82017-11-02 21:19:23 -07004347 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004348 /*
4349 * Note that the adapter is no longer valid at this point
4350 * since the memory has been reclaimed
4351 */
4352 }
4353}
4354
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004355static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07004356 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004357{
Jeff Johnson9d295242017-08-29 14:39:48 -07004358 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004359
Dustin Brown920397d2017-12-13 16:27:50 -08004360 hdd_for_each_adapter(hdd_ctx, adapter) {
4361 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
4362 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304363 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004364 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004365 }
Dustin Brown920397d2017-12-13 16:27:50 -08004366
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304367 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004368}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004369
Arun Khandavalli2358d522016-05-16 18:05:37 +05304370#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4371/**
4372 * hdd_set_fw_log_params() - Set log parameters to FW
4373 * @hdd_ctx: HDD Context
4374 * @adapter: HDD Adapter
4375 *
4376 * This function set the FW Debug log level based on the INI.
4377 *
4378 * Return: None
4379 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004380static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004381 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304382{
4383 uint8_t count = 0, numentries = 0,
4384 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
4385 uint32_t value = 0;
4386 int ret;
4387
Arun Khandavallifae92942016-08-01 13:31:08 +05304388 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4389 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004390 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304391 return;
4392 }
4393
Arun Khandavallifae92942016-08-01 13:31:08 +05304394 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05304395 hdd_ctx->fw_log_settings.dl_type =
4396 hdd_ctx->config->enableFwLogType;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004397 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304398 WMI_DBGLOG_TYPE,
4399 hdd_ctx->config->enableFwLogType,
4400 DBG_CMD);
4401 if (ret != 0)
4402 hdd_err("Failed to enable FW log type ret %d",
4403 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304404
4405 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05304406 hdd_ctx->config->enableFwLogLevel;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004407 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304408 WMI_DBGLOG_LOG_LEVEL,
4409 hdd_ctx->config->enableFwLogLevel,
4410 DBG_CMD);
4411 if (ret != 0)
4412 hdd_err("Failed to enable FW log level ret %d",
4413 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304414
4415 hdd_string_to_u8_array(
4416 hdd_ctx->config->enableFwModuleLogLevel,
4417 moduleloglevel,
4418 &numentries,
4419 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
4420
4421 while (count < numentries) {
4422 /*
4423 * FW module log level input string looks like
4424 * below:
4425 * gFwDebugModuleLoglevel=<FW Module ID>,
4426 * <Log Level>,...
4427 * For example:
4428 * gFwDebugModuleLoglevel=
4429 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
4430 * Above input string means :
4431 * For FW module ID 1 enable log level 0
4432 * For FW module ID 2 enable log level 1
4433 * For FW module ID 3 enable log level 2
4434 * For FW module ID 4 enable log level 3
4435 * For FW module ID 5 enable log level 4
4436 * For FW module ID 6 enable log level 5
4437 * For FW module ID 7 enable log level 6
4438 */
4439
Nishank Aggarwale239d962017-03-03 12:26:02 +05304440 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
4441 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
4442 hdd_err("Module id %d and dbglog level %d input length is more than max",
4443 moduleloglevel[count],
4444 moduleloglevel[count + 1]);
4445 return;
4446 }
4447
4448 value = moduleloglevel[count] << 16;
4449 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07004450 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304451 WMI_DBGLOG_MOD_LOG_LEVEL,
4452 value, DBG_CMD);
4453 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304454 hdd_err("Failed to enable FW module log level %d ret %d",
4455 value, ret);
4456
4457 count += 2;
4458 }
Arun Khandavallifae92942016-08-01 13:31:08 +05304459
Arun Khandavalli2358d522016-05-16 18:05:37 +05304460}
4461#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004462static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004463 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304464{
4465}
4466
4467#endif
4468
4469/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004470 * hdd_configure_chain_mask() - programs chain mask to firmware
4471 * @adapter: HDD adapter
4472 *
4473 * Return: 0 on success or errno on failure
4474 */
4475static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4476{
4477 int ret_val;
Naveen Rawat98322472018-03-06 10:29:42 -08004478 QDF_STATUS status;
4479 struct wma_caps_per_phy non_dbs_phy_cap;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004480 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4481
4482 hdd_debug("enable2x2: %d, lte_coex: %d, ChainMask1x1: tx: %d rx: %d",
4483 hdd_ctx->config->enable2x2, hdd_ctx->lte_coex_ant_share,
4484 hdd_ctx->config->txchainmask1x1,
4485 hdd_ctx->config->rxchainmask1x1);
4486 hdd_debug("disable_DBS: %d, tx_chain_mask_2g: %d, rx_chain_mask_2g: %d",
4487 hdd_ctx->config->dual_mac_feature_disable,
4488 hdd_ctx->config->tx_chain_mask_2g,
4489 hdd_ctx->config->rx_chain_mask_2g);
4490 hdd_debug("tx_chain_mask_5g: %d, rx_chain_mask_5g: %d",
4491 hdd_ctx->config->tx_chain_mask_5g,
4492 hdd_ctx->config->rx_chain_mask_5g);
Liangwei Dong22810e82018-03-15 03:42:12 -04004493 hdd_debug("enable_bt_chain_separation %d",
4494 hdd_ctx->config->enable_bt_chain_separation);
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004495
Naveen Rawat98322472018-03-06 10:29:42 -08004496 status = wma_get_caps_for_phyidx_hwmode(&non_dbs_phy_cap,
4497 HW_MODE_DBS_NONE,
4498 CDS_BAND_ALL);
4499 if (QDF_IS_STATUS_ERROR(status)) {
4500 hdd_err("couldn't get phy caps. skip chain mask programming");
4501 return qdf_status_to_os_return(status);
4502 }
4503
4504 if (non_dbs_phy_cap.tx_chain_mask_2G < 3 ||
4505 non_dbs_phy_cap.rx_chain_mask_2G < 3 ||
4506 non_dbs_phy_cap.tx_chain_mask_5G < 3 ||
4507 non_dbs_phy_cap.rx_chain_mask_5G < 3) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004508 hdd_debug("firmware not capable. skip chain mask programming");
Naveen Rawat98322472018-03-06 10:29:42 -08004509 return 0;
4510 }
4511
Liangwei Dong22810e82018-03-15 03:42:12 -04004512 if (hdd_ctx->config->enable2x2 &&
4513 !hdd_ctx->config->enable_bt_chain_separation) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004514 hdd_debug("2x2 enabled. skip chain mask programming");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004515 return 0;
4516 }
4517
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004518 if (hdd_ctx->config->dual_mac_feature_disable !=
4519 DISABLE_DBS_CXN_AND_SCAN) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004520 hdd_debug("DBS enabled(%d). skip chain mask programming",
4521 hdd_ctx->config->dual_mac_feature_disable);
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004522 return 0;
4523 }
4524
Naveen Rawatdacb5032018-02-08 15:23:24 -08004525 if (hdd_ctx->lte_coex_ant_share) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004526 hdd_debug("lte ant sharing enabled. skip chainmask programming");
Naveen Rawatdacb5032018-02-08 15:23:24 -08004527 return 0;
4528 }
4529
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004530 if (hdd_ctx->config->txchainmask1x1) {
4531 ret_val = sme_cli_set_command(adapter->session_id,
4532 WMI_PDEV_PARAM_TX_CHAIN_MASK,
4533 hdd_ctx->config->txchainmask1x1,
4534 PDEV_CMD);
4535 if (ret_val)
4536 goto error;
4537 }
4538
4539 if (hdd_ctx->config->rxchainmask1x1) {
4540 ret_val = sme_cli_set_command(adapter->session_id,
4541 WMI_PDEV_PARAM_RX_CHAIN_MASK,
4542 hdd_ctx->config->rxchainmask1x1,
4543 PDEV_CMD);
4544 if (ret_val)
4545 goto error;
4546 }
4547
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004548 if (hdd_ctx->config->txchainmask1x1 ||
4549 hdd_ctx->config->rxchainmask1x1) {
Dustin Browna7bb6ae2018-08-16 16:51:50 -07004550 hdd_debug("band agnostic tx/rx chain mask set. skip per band chain mask");
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004551 return 0;
4552 }
4553
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004554 if (hdd_ctx->config->tx_chain_mask_2g) {
4555 ret_val = sme_cli_set_command(adapter->session_id,
4556 WMI_PDEV_PARAM_TX_CHAIN_MASK_2G,
4557 hdd_ctx->config->tx_chain_mask_2g, PDEV_CMD);
4558 if (0 != ret_val)
4559 goto error;
4560 }
4561
4562 if (hdd_ctx->config->rx_chain_mask_2g) {
4563 ret_val = sme_cli_set_command(adapter->session_id,
4564 WMI_PDEV_PARAM_RX_CHAIN_MASK_2G,
4565 hdd_ctx->config->rx_chain_mask_2g, PDEV_CMD);
4566 if (0 != ret_val)
4567 goto error;
4568 }
4569
4570 if (hdd_ctx->config->tx_chain_mask_5g) {
4571 ret_val = sme_cli_set_command(adapter->session_id,
4572 WMI_PDEV_PARAM_TX_CHAIN_MASK_5G,
4573 hdd_ctx->config->tx_chain_mask_5g, PDEV_CMD);
4574 if (0 != ret_val)
4575 goto error;
4576 }
4577
4578 if (hdd_ctx->config->rx_chain_mask_5g) {
4579 ret_val = sme_cli_set_command(adapter->session_id,
4580 WMI_PDEV_PARAM_RX_CHAIN_MASK_5G,
4581 hdd_ctx->config->rx_chain_mask_5g, PDEV_CMD);
4582 if (0 != ret_val)
4583 goto error;
4584 }
4585
4586 return 0;
4587
4588error:
4589 hdd_err("WMI PDEV set param failed %d", ret_val);
4590 return -EINVAL;
4591}
4592
4593/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304594 * hdd_set_fw_params() - Set parameters to firmware
4595 * @adapter: HDD adapter
4596 *
4597 * This function Sets various parameters to fw once the
4598 * adapter is started.
4599 *
4600 * Return: 0 on success or errno on failure
4601 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004602int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304603{
4604 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004605 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304606
Dustin Brownfdf17c12018-03-14 12:55:34 -07004607 hdd_enter_dev(adapter->dev);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304608
4609 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4610 if (!hdd_ctx)
4611 return -EINVAL;
4612
Dustin Brown732ab9c2017-06-15 13:24:09 -07004613 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4614 hdd_debug("FTM Mode is active; nothing to do");
4615 return 0;
4616 }
4617
Jeff Johnson1b780e42017-10-31 14:11:45 -07004618 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304619 WMI_PDEV_PARAM_DTIM_SYNTH,
4620 hdd_ctx->config->enable_lprx, PDEV_CMD);
4621 if (ret) {
4622 hdd_err("Failed to set LPRx");
4623 goto error;
4624 }
4625
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304626
4627 ret = sme_cli_set_command(
4628 adapter->session_id,
4629 WMI_PDEV_PARAM_1CH_DTIM_OPTIMIZED_CHAIN_SELECTION,
4630 hdd_ctx->config->enable_dtim_selection_diversity,
4631 PDEV_CMD);
4632 if (ret) {
4633 hdd_err("Failed to set DTIM_OPTIMIZED_CHAIN_SELECTION");
4634 goto error;
4635 }
4636
Ashish Kumar Dhanotiya48dac7d2018-03-28 14:59:50 +05304637 ret = sme_cli_set_command(
4638 adapter->session_id,
4639 WMI_PDEV_PARAM_TX_SCH_DELAY,
4640 hdd_ctx->config->enable_tx_sch_delay,
4641 PDEV_CMD);
4642 if (ret) {
4643 hdd_err("Failed to set WMI_PDEV_PARAM_TX_SCH_DELAY");
4644 goto error;
4645 }
4646
Ashish Kumar Dhanotiya959b38c2018-04-06 21:07:57 +05304647 ret = sme_cli_set_command(
4648 adapter->session_id,
4649 WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE,
4650 hdd_ctx->config->enable_secondary_rate,
4651 PDEV_CMD);
4652 if (ret) {
4653 hdd_err("Failed to set WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE");
4654 goto error;
4655 }
4656
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304657 if (adapter->device_mode == QDF_STA_MODE) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07004658 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304659 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4660 hdd_ctx->config->upper_brssi_thresh);
4661
Jeff Johnson1b780e42017-10-31 14:11:45 -07004662 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304663 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4664 hdd_ctx->config->lower_brssi_thresh);
4665
Jeff Johnson1b780e42017-10-31 14:11:45 -07004666 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304667 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4668 hdd_ctx->config->enable_dtim_1chrx);
4669 }
4670
Dustin Brown732ab9c2017-06-15 13:24:09 -07004671 if (hdd_ctx->config->enable2x2) {
4672 hdd_debug("configuring 2x2 mode fw params");
4673
Jeff Johnson1b780e42017-10-31 14:11:45 -07004674 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004675 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
4676 hdd_ctx->config->enable_cck_tx_fir_override,
4677 PDEV_CMD);
4678 if (ret) {
4679 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4680 ret);
4681 goto error;
4682 }
Liangwei Dong22810e82018-03-15 03:42:12 -04004683
4684 if (hdd_configure_chain_mask(adapter))
4685 goto error;
Dustin Brown732ab9c2017-06-15 13:24:09 -07004686 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304687#define HDD_DTIM_1CHAIN_RX_ID 0x5
4688#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004689 hdd_debug("configuring 1x1 mode fw params");
4690
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004691 /*
4692 * Disable DTIM 1 chain Rx when in 1x1,
4693 * we are passing two value
4694 * as param_id << 29 | param_value.
4695 * Below param_value = 0(disable)
4696 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004697 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004698 WMI_STA_SMPS_PARAM_CMDID,
4699 HDD_DTIM_1CHAIN_RX_ID <<
4700 HDD_SMPS_PARAM_VALUE_S,
4701 VDEV_CMD);
4702 if (ret) {
4703 hdd_err("DTIM 1 chain set failed %d", ret);
4704 goto error;
4705 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304706
Arun Khandavalli2358d522016-05-16 18:05:37 +05304707#undef HDD_DTIM_1CHAIN_RX_ID
4708#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004709
4710 if (hdd_configure_chain_mask(adapter))
4711 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004712 }
4713
Jeff Johnson1b780e42017-10-31 14:11:45 -07004714 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004715 WMI_PDEV_PARAM_HYST_EN,
4716 hdd_ctx->config->enableMemDeepSleep,
4717 PDEV_CMD);
4718 if (ret) {
4719 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4720 goto error;
4721 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304722
Jeff Johnson1b780e42017-10-31 14:11:45 -07004723 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004724 WMI_VDEV_PARAM_ENABLE_RTSCTS,
4725 hdd_ctx->config->rts_profile,
4726 VDEV_CMD);
4727 if (ret) {
4728 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4729 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304730 }
4731
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004732 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
4733
Jeff Johnson1b780e42017-10-31 14:11:45 -07004734 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004735 GEN_VDEV_PARAM_AMSDU,
4736 hdd_ctx->config->max_amsdu_num,
4737 GEN_CMD);
4738 if (ret != 0) {
4739 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4740 goto error;
4741 }
4742
Arun Khandavalli2358d522016-05-16 18:05:37 +05304743 hdd_set_fw_log_params(hdd_ctx, adapter);
Dustin Browne74003f2018-03-14 12:51:58 -07004744 hdd_exit();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004745
Arun Khandavalli2358d522016-05-16 18:05:37 +05304746 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304747
Arun Khandavalli2358d522016-05-16 18:05:37 +05304748error:
4749 return -EINVAL;
4750}
4751
Ryan Hsu07495ea2016-01-21 15:25:39 -08004752/**
Abhinav Kumarcc959f12018-08-09 13:58:30 +05304753 * hdd_init_completion() - Initialize Completion Variables
4754 * @adapter: HDD adapter
4755 *
4756 * This function Initialize the completion variables for
4757 * a particular adapter
4758 *
4759 * Return: None
4760 */
4761static void hdd_init_completion(struct hdd_adapter *adapter)
4762{
4763 init_completion(&adapter->disconnect_comp_var);
4764 init_completion(&adapter->roaming_comp_var);
4765 init_completion(&adapter->linkup_event_var);
4766 init_completion(&adapter->cancel_rem_on_chan_var);
4767 init_completion(&adapter->rem_on_chan_ready_event);
4768 init_completion(&adapter->sta_authorized_event);
4769 init_completion(&adapter->offchannel_tx_event);
4770 init_completion(&adapter->tx_action_cnf_event);
4771 init_completion(&adapter->ibss_peer_info_comp);
4772 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
4773}
4774
4775/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08004776 * hdd_open_adapter() - open and setup the hdd adatper
4777 * @hdd_ctx: global hdd context
4778 * @session_type: type of the interface to be created
4779 * @iface_name: User-visible name of the interface
4780 * @macAddr: MAC address to assign to the interface
4781 * @name_assign_type: the name of assign type of the netdev
4782 * @rtnl_held: the rtnl lock hold flag
4783 *
4784 * This function open and setup the hdd adpater according to the device
4785 * type request, assign the name, the mac address assigned, and then prepared
4786 * the hdd related parameters, queue, lock and ready to start.
4787 *
4788 * Return: the pointer of hdd adapter, otherwise NULL.
4789 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004790struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004791 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08004792 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004793 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004794{
Jeff Johnson9d295242017-08-29 14:39:48 -07004795 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304796 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004797
4798 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4799 /*
4800 * Max limit reached on the number of vdevs configured by the
4801 * host. Return error
4802 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304803 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4804 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004805 return NULL;
4806 }
4807
4808 if (macAddr == NULL) {
4809 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304810 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004811 return NULL;
4812 }
4813 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304814 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304815 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4816 " already exists",
4817 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004818 return NULL;
4819 }
4820
4821 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004822 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004823 /* Reset locally administered bit if the device mode is STA */
4824 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Dustin Brown7e761c72018-07-31 13:50:17 -07004825 hdd_debug("locally administered bit reset in sta mode: "
4826 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004827 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004828 case QDF_P2P_CLIENT_MODE:
4829 case QDF_P2P_DEVICE_MODE:
4830 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07004831 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304832 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004833 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4834 name_assign_type,
4835 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004836
4837 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304838 hdd_err("failed to allocate adapter for session %d",
4839 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004840 return NULL;
4841 }
4842
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004843 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004844 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004845 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004846 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304847 else if (QDF_MONITOR_MODE == session_type)
4848 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004849 else
4850 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4851
4852 adapter->device_mode = session_type;
4853
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004854
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004855 /*
4856 * Workqueue which gets scheduled in IPv4 notification
4857 * callback
4858 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004859 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004860 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004861
4862#ifdef WLAN_NS_OFFLOAD
4863 /*
4864 * Workqueue which gets scheduled in IPv6
4865 * notification callback.
4866 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004867 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004868 hdd_ipv6_notifier_work_queue);
4869#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004870 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004871 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004872 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004873
4874 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004875 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004876 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304877 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4878 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304879
Alok Kumarb64650c2018-03-23 17:05:11 +05304880 hdd_nud_init_tracking(adapter);
4881
4882 qdf_mutex_create(&adapter->disconnection_status_lock);
4883
Ravi Joshi1a292562017-05-18 16:28:54 -07004884 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004885
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004886 case QDF_P2P_GO_MODE:
4887 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004888 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4889 name_assign_type,
4890 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004891 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004892 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304893 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004894 return NULL;
4895 }
4896
4897 adapter->wdev.iftype =
4898 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004899 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004900 NL80211_IFTYPE_P2P_GO;
4901 adapter->device_mode = session_type;
4902
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004903 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004904 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004905 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004906
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004907 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004908 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304909 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4910 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304911
4912 /*
4913 * Workqueue which gets scheduled in IPv4 notification
4914 * callback
4915 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004916 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304917 hdd_ipv4_notifier_work_queue);
4918
4919#ifdef WLAN_NS_OFFLOAD
4920 /*
4921 * Workqueue which gets scheduled in IPv6
4922 * notification callback.
4923 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004924 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304925 hdd_ipv6_notifier_work_queue);
4926#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004927 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304928 case QDF_FTM_MODE:
4929 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4930 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08004931 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304932 if (NULL == adapter) {
4933 hdd_err("Failed to allocate adapter for FTM mode");
4934 return NULL;
4935 }
4936 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4937 adapter->device_mode = session_type;
4938 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004939 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004940 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004941
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304942 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004943 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304944 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304945 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4946 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304947 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004948 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004949 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304950 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004951 return NULL;
4952 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004953
Abhinav Kumarcc959f12018-08-09 13:58:30 +05304954 hdd_init_completion(adapter);
hqueaa33ee2017-05-04 17:56:35 +08004955 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
Min Liu9be5d4a2018-05-17 11:51:53 +08004956 qdf_list_create(&adapter->blocked_scan_request_q, WLAN_MAX_SCAN_COUNT);
4957 qdf_mutex_create(&adapter->blocked_scan_request_q_lock);
hqueaa33ee2017-05-04 17:56:35 +08004958
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304959 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004960 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08004961 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004962 }
4963
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304964 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004965 if (NULL != adapter) {
4966 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4967 adapter = NULL;
4968 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004969
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004970 return NULL;
4971 }
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05304972 hdd_apf_context_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004973
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304974 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004975 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4976 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004977
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004978 /* Adapter successfully added. Increment the vdev count */
4979 hdd_ctx->current_intf_count++;
4980
Jeff Johnson5880d792016-08-15 13:32:30 -07004981 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004982 hdd_ctx->current_intf_count);
4983
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004984 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004985 }
4986
Rajeev Kumardca5f812016-02-04 17:28:06 -08004987 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004988 hdd_err("Interface %s wow debug_fs init failed",
4989 netdev_name(adapter->dev));
4990
Ajit Pal Singh106c1412018-04-18 18:08:49 +05304991 hdd_register_hl_netdev_fc_timer(adapter,
4992 hdd_tx_resume_timer_expired_handler);
4993
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004994 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4995 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004996
4997 return adapter;
4998
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004999err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07005000 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05305001 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005002
5003 return NULL;
5004}
5005
Jeff Johnson9d295242017-08-29 14:39:48 -07005006QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08005007 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005008{
Dustin Brown920397d2017-12-13 16:27:50 -08005009 /*
5010 * Here we are stopping global bus_bw timer & work per adapter.
5011 *
5012 * The reason is to fix one race condition between
5013 * bus bandwidth work and cleaning up an adapter.
5014 * Under some conditions, it is possible for the bus bandwidth
5015 * work to access a particularly destroyed adapter, leading to
5016 * use-after-free.
5017 */
Dustin Brown920397d2017-12-13 16:27:50 -08005018 hdd_bus_bw_compute_timer_stop(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005019
Min Liuef92ef52018-06-25 18:08:54 +08005020 qdf_list_destroy(&adapter->blocked_scan_request_q);
5021 qdf_mutex_destroy(&adapter->blocked_scan_request_q_lock);
5022
Dustin Brown920397d2017-12-13 16:27:50 -08005023 /* cleanup adapter */
5024 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
5025 adapter->device_mode);
Dustin Brown920397d2017-12-13 16:27:50 -08005026 hdd_remove_adapter(hdd_ctx, adapter);
Liangwei Dongad89c762018-06-01 01:56:23 -04005027 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005028
Dustin Brown920397d2017-12-13 16:27:50 -08005029 /* conditionally restart the bw timer */
5030 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005031
Dustin Brown920397d2017-12-13 16:27:50 -08005032 /* Adapter removed. Decrement vdev count */
5033 if (hdd_ctx->current_intf_count != 0)
5034 hdd_ctx->current_intf_count--;
Dustin Brown5ec6b552017-03-31 12:11:40 -07005035
Dustin Brown920397d2017-12-13 16:27:50 -08005036 /* Fw will take care incase of concurrency */
5037 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005038}
5039
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08005040/**
5041 * hdd_close_all_adapters - Close all open adapters
5042 * @hdd_ctx: Hdd context
5043 * rtnl_held: True if RTNL lock held
5044 *
5045 * Close all open adapters.
5046 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305047 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08005048 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005049QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005050{
Dustin Brown920397d2017-12-13 16:27:50 -08005051 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305052 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005053
Dustin Brown491d54b2018-03-14 12:39:11 -07005054 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005055
5056 do {
Dustin Brown920397d2017-12-13 16:27:50 -08005057 status = hdd_remove_front_adapter(hdd_ctx, &adapter);
5058 if (QDF_IS_STATUS_SUCCESS(status)) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305059 wlan_hdd_release_intf_addr(hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005060 adapter->mac_addr.bytes);
5061 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
5062
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305063 /* Adapter removed. Decrement vdev count */
5064 if (hdd_ctx->current_intf_count != 0)
5065 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005066 }
Dustin Brown920397d2017-12-13 16:27:50 -08005067 } while (QDF_IS_STATUS_SUCCESS(status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005068
Dustin Browne74003f2018-03-14 12:51:58 -07005069 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005070
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305071 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005072}
5073
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005074void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005075{
Anurag Chouhan6d760662016-02-20 16:05:43 +05305076 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005077 tSirUpdateIE updateIE;
Jeff Johnson16528362018-06-14 12:34:16 -07005078 mac_handle_t mac_handle;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005079
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005080 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005081 case QDF_STA_MODE:
5082 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005083 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005084 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005085 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07005086 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005087 break;
5088 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005089 case QDF_SAP_MODE:
5090 case QDF_P2P_GO_MODE:
5091 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005092 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07005093 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005094 break;
5095 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005096 case QDF_FTM_MODE:
5097 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005098 default:
5099 /*
5100 * wlan_hdd_reset_prob_rspies should not have been called
5101 * for these kind of devices
5102 */
Jeff Johnson5880d792016-08-15 13:32:30 -07005103 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005104 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005105 return;
5106 }
5107
Anurag Chouhanc5548422016-02-24 18:33:27 +05305108 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005109 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005110 updateIE.ieBufferlength = 0;
5111 updateIE.pAdditionIEBuffer = NULL;
5112 updateIE.append = true;
5113 updateIE.notify = false;
Jeff Johnson16528362018-06-14 12:34:16 -07005114 mac_handle = hdd_adapter_get_mac_handle(adapter);
5115 if (sme_update_add_ie(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005116 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305117 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005118 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005119 }
5120}
5121
Dustin Browndb2a8be2017-12-20 11:49:56 -08005122QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
5123 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005124{
Liangwei Dongad89c762018-06-01 01:56:23 -04005125 return hdd_stop_adapter_ext(hdd_ctx, adapter, 0);
5126}
5127
5128QDF_STATUS hdd_stop_adapter_ext(struct hdd_context *hdd_ctx,
5129 struct hdd_adapter *adapter,
5130 enum hdd_adapter_stop_flag_t flag)
5131{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305132 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson025618c2018-03-18 14:41:00 -07005133 struct csr_roam_profile *roam_profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005134 union iwreq_data wrqu;
5135 tSirUpdateIE updateIE;
5136 unsigned long rc;
Jeff Johnsone4c11db2018-05-05 23:22:32 -07005137 tsap_config_t *sap_config;
Jeff Johnson16528362018-06-14 12:34:16 -07005138 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005139
Dustin Brown491d54b2018-03-14 12:39:11 -07005140 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005141
Dustin Browne7e71d32018-05-11 16:00:08 -07005142 if (adapter->session_id != HDD_SESSION_ID_INVALID)
5143 wlan_hdd_cfg80211_deregister_frames(adapter);
5144
Alok Kumarb64650c2018-03-23 17:05:11 +05305145 hdd_nud_ignore_tracking(adapter, true);
5146 hdd_nud_reset_tracking(adapter);
5147
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005148 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305149 wlan_hdd_netif_queue_control(adapter,
5150 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5151 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08005152 /*
5153 * if this is the last active connection check & stop the
5154 * opportunistic timer first
5155 */
5156 if (((policy_mgr_get_connection_count(hdd_ctx->hdd_psoc) == 1) &&
5157 (policy_mgr_mode_specific_connection_count(hdd_ctx->hdd_psoc,
5158 policy_mgr_convert_device_mode_to_qdf_type(
5159 adapter->device_mode), NULL) == 1)) ||
5160 !policy_mgr_get_connection_count(hdd_ctx->hdd_psoc))
5161 policy_mgr_check_and_stop_opportunistic_timer(
5162 hdd_ctx->hdd_psoc, adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -07005163
5164 mac_handle = hdd_ctx->mac_handle;
5165
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005166 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005167 case QDF_STA_MODE:
5168 case QDF_P2P_CLIENT_MODE:
5169 case QDF_IBSS_MODE:
5170 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005171 case QDF_NDI_MODE:
5172 if ((QDF_NDI_MODE == adapter->device_mode) ||
5173 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005174 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
5175 hdd_is_connecting(
5176 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005177 INIT_COMPLETION(adapter->disconnect_comp_var);
Jeff Johnson025618c2018-03-18 14:41:00 -07005178 roam_profile = hdd_roam_profile(adapter);
5179 /* For NDI do not use roam_profile */
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005180 if (QDF_NDI_MODE == adapter->device_mode)
5181 qdf_ret_status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005182 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005183 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005184 eCSR_DISCONNECT_REASON_NDI_DELETE);
Jeff Johnson025618c2018-03-18 14:41:00 -07005185 else if (roam_profile->BSSType ==
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005186 eCSR_BSS_TYPE_START_IBSS)
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_IBSS_LEAVE);
Abhinav Kumar19a7a402018-07-12 17:36:57 +05305191 else if (adapter->device_mode == QDF_STA_MODE)
5192 wlan_hdd_disconnect(adapter,
5193 eCSR_DISCONNECT_REASON_DEAUTH);
5194 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005195 qdf_ret_status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005196 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005197 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005198 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005199 /* success implies disconnect command got
5200 * queued up successfully
5201 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005202 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
5203 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005204 rc = wait_for_completion_timeout(
5205 &adapter->disconnect_comp_var,
5206 msecs_to_jiffies
5207 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005208 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005209 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005210 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005211 if (qdf_ret_status != QDF_STATUS_SUCCESS)
5212 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005213 memset(&wrqu, '\0', sizeof(wrqu));
5214 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5215 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5216 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
5217 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05305218 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08005219 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005220
Wu Gao4a1ec8c2018-07-23 19:18:40 +08005221 wlan_hdd_cleanup_actionframe(adapter);
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05305222 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05305223 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005224
5225#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005226 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005227#endif
5228
5229 hdd_deregister_tx_flow_control(adapter);
5230
5231#ifdef WLAN_NS_OFFLOAD
5232#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005233 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005234#endif
5235#endif
5236
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05305237 if (adapter->device_mode == QDF_STA_MODE)
5238 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
5239 adapter->dev);
Dustin Browndb2a8be2017-12-20 11:49:56 -08005240
5241 if (wlan_hdd_try_disconnect(adapter)) {
5242 hdd_err("Error: Can't disconnect adapter");
5243 return QDF_STATUS_E_FAILURE;
Krunal Soni985b8132017-02-10 18:49:08 -08005244 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08005245
Himanshu Agarwalb229a142017-12-21 10:16:45 +05305246 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005247 break;
5248
Rajeev Kumar3b906202018-02-01 10:55:14 -08005249 case QDF_MONITOR_MODE:
5250 wlan_hdd_scan_abort(adapter);
5251 hdd_deregister_tx_flow_control(adapter);
5252 hdd_vdev_destroy(adapter);
5253 break;
5254
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005255 case QDF_SAP_MODE:
Will Huang7049bae2018-08-13 17:25:02 +08005256 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
5257 cds_flush_delayed_work(&adapter->acs_pending_work);
5258 clear_bit(ACS_PENDING, &adapter->event_flags);
5259 }
wadesongf9b15ed2017-12-14 14:12:32 +08005260 wlan_hdd_scan_abort(adapter);
Govind Singh1dab23b2017-08-12 13:31:00 +05305261 /* Flush IPA exception path packets */
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05305262 sap_config = &adapter->session.ap.sap_config;
5263 if (sap_config)
5264 wlansap_reset_sap_config_add_ie(sap_config,
5265 eUPDATE_IE_ALL);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05305266 ucfg_ipa_flush(hdd_ctx->hdd_pdev);
Liangwei Dongad89c762018-06-01 01:56:23 -04005267 if (!(flag & HDD_IN_CAC_WORK_TH_CONTEXT))
5268 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Jeff Johnson46807cd2018-04-29 21:32:22 -07005269 /* fallthrough */
Dustin Browna5cf8e02017-10-19 16:04:19 -07005270
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005271 case QDF_P2P_GO_MODE:
Krunal Soni22208392017-09-29 18:10:34 -07005272 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005273
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005274 /* Any softap specific cleanup here... */
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305275 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005276 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005277 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005278 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5279
5280 hdd_deregister_tx_flow_control(adapter);
5281
Kapil Guptac1224bf2017-06-22 21:22:40 +05305282 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005283 mutex_lock(&hdd_ctx->sap_lock);
5284 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305285 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05305286 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005287
5288 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005289 status = wlansap_stop_bss(
5290 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005291
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305292 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07005293 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005294 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305295 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305296 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305297 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +05305298 qdf_wait_for_event_completion(
5299 &hostapd_state->qdf_stop_bss_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -08005300 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005301
Anurag Chouhance0dc992016-02-16 18:18:03 +05305302 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005303 hdd_err("failure waiting for wlansap_stop_bss %d",
5304 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005305 }
5306 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07005307 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005308 }
5309 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005310 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
5311 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005312 adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005313 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305314 adapter->device_mode,
5315 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005316
Anurag Chouhanc5548422016-02-24 18:33:27 +05305317 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07005318 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005319 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005320 updateIE.ieBufferlength = 0;
5321 updateIE.pAdditionIEBuffer = NULL;
5322 updateIE.append = false;
5323 updateIE.notify = false;
5324 /* Probe bcn reset */
Jeff Johnson16528362018-06-14 12:34:16 -07005325 if (sme_update_add_ie(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005326 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305327 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005328 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005329 }
5330 /* Assoc resp 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,
5333 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305334 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005335 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005336 }
5337 /* Reset WNI_CFG_PROBE_RSP Flags */
5338 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005339 }
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005340 clear_bit(SOFTAP_INIT_DONE, &adapter->event_flags);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005341 qdf_mem_free(adapter->session.ap.beacon);
5342 adapter->session.ap.beacon = NULL;
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005343
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305344 /*
5345 * If Do_Not_Break_Stream was enabled clear avoid channel list.
5346 */
5347 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
5348 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
5349
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305350#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005351 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305352#endif
5353
5354#ifdef WLAN_NS_OFFLOAD
5355#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005356 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305357#endif
5358#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08005359
5360 hdd_vdev_destroy(adapter);
5361
Krunal Sonib51eec72017-11-20 21:53:01 -08005362 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005363 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005364 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08005365 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08005366 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07005367 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Zhang Qian79d0d132018-02-05 13:40:16 +08005368 hdd_deregister_tx_flow_control(adapter);
5369 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005370 break;
5371 default:
5372 break;
5373 }
5374
Ajit Pal Singh106c1412018-04-18 18:08:49 +05305375 hdd_deregister_hl_netdev_fc_timer(adapter);
5376
Dustin Brown04348372017-12-14 16:13:39 -08005377 if (adapter->scan_info.default_scan_ies) {
5378 qdf_mem_free(adapter->scan_info.default_scan_ies);
5379 adapter->scan_info.default_scan_ies = NULL;
5380 }
5381
Dustin Browne74003f2018-03-14 12:51:58 -07005382 hdd_exit();
Dustin Brown04348372017-12-14 16:13:39 -08005383
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305384 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005385}
5386
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305387/**
5388 * hdd_deinit_all_adapters - deinit all adapters
5389 * @hdd_ctx: HDD context
5390 * @rtnl_held: True if RTNL lock held
5391 *
5392 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005393void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305394{
Jeff Johnson9d295242017-08-29 14:39:48 -07005395 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305396
Dustin Brown491d54b2018-03-14 12:39:11 -07005397 hdd_enter();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305398
Dustin Brown920397d2017-12-13 16:27:50 -08005399 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305400 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305401
Dustin Browne74003f2018-03-14 12:51:58 -07005402 hdd_exit();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305403}
5404
Dustin Browndb2a8be2017-12-20 11:49:56 -08005405QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005406{
Jeff Johnson9d295242017-08-29 14:39:48 -07005407 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005408
Dustin Brown491d54b2018-03-14 12:39:11 -07005409 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005410
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305411 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5412
Dustin Brown920397d2017-12-13 16:27:50 -08005413 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08005414 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005415
Dustin Browne74003f2018-03-14 12:51:58 -07005416 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005417
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305418 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005419}
5420
Paul Zhang84fa9382017-11-10 21:18:21 +08005421static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
5422 struct hdd_adapter *adapter)
5423{
5424 switch (adapter->device_mode) {
5425 case QDF_STA_MODE:
5426 case QDF_P2P_CLIENT_MODE:
5427 case QDF_IBSS_MODE:
5428 case QDF_P2P_DEVICE_MODE:
5429 case QDF_NDI_MODE:
5430 wlan_hdd_scan_abort(adapter);
5431 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5432 if (adapter->device_mode == QDF_STA_MODE)
5433 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
5434 adapter->dev);
5435 break;
5436 case QDF_P2P_GO_MODE:
5437 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5438 break;
5439 case QDF_SAP_MODE:
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305440 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Paul Zhang84fa9382017-11-10 21:18:21 +08005441 wlan_hdd_undo_acs(adapter);
5442 break;
5443 default:
5444 break;
5445 }
5446}
5447
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005448QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005449{
Jeff Johnson9d295242017-08-29 14:39:48 -07005450 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07005451 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07005452 struct qdf_mac_addr peerMacAddr;
Yue Ma42654682018-01-11 16:55:24 -08005453 int sta_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005454
Dustin Brown491d54b2018-03-14 12:39:11 -07005455 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005456
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305457 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5458
Dustin Brown920397d2017-12-13 16:27:50 -08005459 hdd_for_each_adapter(hdd_ctx, adapter) {
Dustin Brown5e89ef82018-03-14 11:50:23 -07005460 hdd_info("[SSR] reset adapter with device mode %s(%d)",
5461 hdd_device_mode_to_string(adapter->device_mode),
5462 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305463
5464 if ((adapter->device_mode == QDF_STA_MODE) ||
Paul Zhang679025e2018-03-08 22:39:44 +08005465 (adapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305466 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07005467 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Paul Zhang679025e2018-03-08 22:39:44 +08005468 adapter->session.station.hdd_reassoc_scenario = false;
5469 }
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305470
Arun Khandavallicc544b32017-01-30 19:52:16 +05305471 if (hdd_ctx->config->sap_internal_restart &&
5472 adapter->device_mode == QDF_SAP_MODE) {
5473 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305474 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05305475 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005476 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08005477 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005478 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005479 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
5480 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305481 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305482 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005483 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005484 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005485
Paul Zhang84fa9382017-11-10 21:18:21 +08005486 hdd_reset_scan_operation(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005487
5488 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005489 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005490 adapter->device_mode, adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005491 hdd_green_ap_start_state_mc(hdd_ctx, adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305492 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005493 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5494 hdd_wmm_adapter_close(adapter);
5495 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5496 }
5497
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305498 if (adapter->device_mode == QDF_STA_MODE)
5499 hdd_clear_fils_connection_info(adapter);
5500
Wu Gao3545e642017-07-14 19:24:41 +08005501 if (adapter->device_mode == QDF_SAP_MODE) {
Jingxiang Geec113592018-08-09 15:40:39 +08005502 wlansap_cleanup_cac_timer(
5503 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Wu Gao3545e642017-07-14 19:24:41 +08005504 /*
5505 * If adapter is SAP, set session ID to invalid
5506 * since SAP session will be cleanup during SSR.
5507 */
Wu Gao36717432016-11-21 15:09:48 +08005508 wlansap_set_invalid_session(
5509 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Wu Gao3545e642017-07-14 19:24:41 +08005510 }
5511
Yue Ma42654682018-01-11 16:55:24 -08005512 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005513 if (adapter->device_mode == QDF_STA_MODE ||
5514 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005515 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005516 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07005517 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005518
Yue Ma42654682018-01-11 16:55:24 -08005519 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
Wu Gao6b81fc52018-05-24 19:27:27 +08005520 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Yue Ma42654682018-01-11 16:55:24 -08005521 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5522 if (adapter->sta_info[sta_id].in_use) {
5523 hdd_debug("[SSR] deregister STA with ID %d",
5524 sta_id);
5525 hdd_softap_deregister_sta(adapter,
5526 sta_id);
5527 adapter->sta_info[sta_id].in_use = 0;
5528 }
5529 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005530 }
5531
Alok Kumarb64650c2018-03-23 17:05:11 +05305532 hdd_nud_reset_tracking(adapter);
5533 hdd_nud_ignore_tracking(adapter, true);
5534 hdd_set_disconnect_status(adapter, false);
5535
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005536 hdd_softap_deinit_tx_rx(adapter);
Tiger Yu8c387702018-07-06 16:56:42 +08005537 hdd_deregister_tx_flow_control(adapter);
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005538
Yue Maf9782842017-05-08 12:49:49 -07005539 /* Destroy vdev which will be recreated during reinit. */
5540 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005541 }
5542
Dustin Browne74003f2018-03-14 12:51:58 -07005543 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005544
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305545 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005546}
5547
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005548bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305549{
Dustin Brown920397d2017-12-13 16:27:50 -08005550 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305551 bool close_modules = true;
5552
Arun Khandavalliba479c42017-07-26 21:29:40 +05305553 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
5554 hdd_info("FTM mode, don't close the module");
5555 return false;
5556 }
5557
Dustin Brown920397d2017-12-13 16:27:50 -08005558 hdd_for_each_adapter(hdd_ctx, adapter) {
5559 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
5560 test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005561 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305562 close_modules = false;
5563 break;
5564 }
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305565 }
5566
5567 return close_modules;
5568}
5569
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305570bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305571{
5572 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5573 return true;
5574 else
5575 return false;
5576}
5577
Anurag Chouhanc4092922016-09-08 15:56:11 +05305578#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08005579 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305580struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5581 struct ieee80211_channel *channel,
5582 const u8 *bssid, const u8 *ssid,
5583 size_t ssid_len)
5584{
5585 return cfg80211_get_bss(wiphy, channel, bssid,
5586 ssid, ssid_len,
5587 WLAN_CAPABILITY_ESS,
5588 WLAN_CAPABILITY_ESS);
5589}
5590#else
5591struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5592 struct ieee80211_channel *channel,
5593 const u8 *bssid, const u8 *ssid,
5594 size_t ssid_len)
5595{
5596 return cfg80211_get_bss(wiphy, channel, bssid,
5597 ssid, ssid_len,
5598 IEEE80211_BSS_TYPE_ESS,
5599 IEEE80211_PRIVACY_ANY);
5600}
5601#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305602
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305603#if defined CFG80211_CONNECT_BSS || \
5604 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305605#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305606 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305607/**
5608 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5609 * @timeout_reason: reason for connect timeout
5610 *
5611 * This function is used to convert host timeout
5612 * reason enum to kernel specific enum.
5613 *
5614 * Return: nl timeout enum
5615 */
5616static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5617 tSirResultCodes timeout_reason)
5618{
5619 switch (timeout_reason) {
5620 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5621 return NL80211_TIMEOUT_SCAN;
5622 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5623 return NL80211_TIMEOUT_AUTH;
5624 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5625 return NL80211_TIMEOUT_ASSOC;
5626 default:
5627 return NL80211_TIMEOUT_UNSPECIFIED;
5628 }
5629}
5630
5631/**
5632 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5633 * @dev: network device
5634 * @bssid: bssid to which we want to associate
5635 * @timeout_reason: reason for connect timeout
5636 *
5637 * This API is used to send connection timeout reason to supplicant
5638 *
5639 * Return: void
5640 */
5641static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5642 const u8 *bssid,
5643 tSirResultCodes timeout_reason)
5644{
5645 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005646
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305647 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5648
5649 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5650 nl_timeout_reason);
5651}
5652
5653/**
5654 * __hdd_connect_bss() - API to send connection status to supplicant
5655 * @dev: network device
5656 * @bssid: bssid to which we want to associate
5657 * @req_ie: Request Information Element
5658 * @req_ie_len: len of the req IE
5659 * @resp_ie: Response IE
5660 * @resp_ie_len: len of ht response IE
5661 * @status: status
5662 * @gfp: Kernel Flag
5663 * @timeout_reason: reason for connect timeout
5664 *
5665 * Return: void
5666 */
5667static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5668 struct cfg80211_bss *bss, const u8 *req_ie,
5669 size_t req_ie_len, const u8 *resp_ie,
5670 size_t resp_ie_len, int status, gfp_t gfp,
5671 tSirResultCodes timeout_reason)
5672{
5673 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005674
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305675 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5676
5677 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5678 resp_ie, resp_ie_len, status, gfp,
5679 nl_timeout_reason);
5680}
5681#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305682#if defined CFG80211_CONNECT_TIMEOUT || \
5683 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305684static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5685 const u8 *bssid,
5686 tSirResultCodes timeout_reason)
5687{
5688 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5689}
5690#endif
5691
5692static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5693 struct cfg80211_bss *bss, const u8 *req_ie,
5694 size_t req_ie_len, const u8 *resp_ie,
5695 size_t resp_ie_len, int status, gfp_t gfp,
5696 tSirResultCodes timeout_reason)
5697{
5698 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5699 resp_ie, resp_ie_len, status, gfp);
5700}
5701#endif
5702
Abhishek Singha84d3952016-09-13 13:45:05 +05305703/**
5704 * hdd_connect_bss() - API to send connection status to supplicant
5705 * @dev: network device
5706 * @bssid: bssid to which we want to associate
5707 * @req_ie: Request Information Element
5708 * @req_ie_len: len of the req IE
5709 * @resp_ie: Response IE
5710 * @resp_ie_len: len of ht response IE
5711 * @status: status
5712 * @gfp: Kernel Flag
5713 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305714 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05305715 *
5716 * The API is a wrapper to send connection status to supplicant
5717 *
5718 * Return: Void
5719 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305720#if defined CFG80211_CONNECT_TIMEOUT || \
5721 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05305722static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5723 struct cfg80211_bss *bss, const u8 *req_ie,
5724 size_t req_ie_len, const u8 *resp_ie,
5725 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305726 bool connect_timeout,
5727 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305728{
5729 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305730 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305731 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305732 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5733 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305734}
5735#else
5736static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5737 struct cfg80211_bss *bss, const u8 *req_ie,
5738 size_t req_ie_len, const u8 *resp_ie,
5739 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305740 bool connect_timeout,
5741 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305742{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305743 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5744 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305745}
5746#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305747
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305748#if defined(WLAN_FEATURE_FILS_SK)
5749#if defined(CFG80211_CONNECT_DONE) || \
5750 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
5751#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
5752 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305753/**
5754 * hdd_populate_fils_params() - Populate FILS keys to connect response
5755 * @fils_params: connect response to supplicant
5756 * @fils_kek: FILS kek
5757 * @fils_kek_len: FILS kek length
5758 * @pmk: FILS PMK
5759 * @pmk_len: FILS PMK length
5760 * @pmkid: PMKID
5761 * @fils_seq_num: FILS Seq number
5762 *
5763 * Return: None
5764 */
5765static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5766 *fils_params, const uint8_t *fils_kek,
5767 size_t fils_kek_len, const uint8_t *pmk,
5768 size_t pmk_len, const uint8_t *pmkid,
5769 uint16_t fils_seq_num)
5770{
5771 /* Increament seq number to be used for next FILS */
5772 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
5773 fils_params->update_erp_next_seq_num = true;
5774 fils_params->fils_kek = fils_kek;
5775 fils_params->fils_kek_len = fils_kek_len;
5776 fils_params->pmk = pmk;
5777 fils_params->pmk_len = pmk_len;
5778 fils_params->pmkid = pmkid;
5779}
5780#else
5781static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5782 *fils_params, const uint8_t
5783 *fils_kek, size_t fils_kek_len,
5784 const uint8_t *pmk, size_t pmk_len,
5785 const uint8_t *pmkid,
5786 uint16_t fils_seq_num)
5787{ }
5788#endif
5789
Jeff Johnson172237b2017-11-07 15:32:59 -08005790void hdd_update_hlp_info(struct net_device *dev,
5791 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305792{
5793 struct sk_buff *skb;
5794 uint16_t skb_len;
5795 struct llc_snap_hdr_t *llc_hdr;
5796 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305797 uint8_t *hlp_data;
5798 uint16_t hlp_data_len;
5799 struct fils_join_rsp_params *roam_fils_params
5800 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305801 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
5802
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305803 if (!roam_fils_params) {
5804 hdd_err("FILS Roam Param NULL");
5805 return;
5806 }
5807
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08005808 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305809 hdd_err("FILS HLP Data NULL, len %d",
5810 roam_fils_params->hlp_data_len);
5811 return;
5812 }
5813
5814 hlp_data = roam_fils_params->hlp_data;
5815 hlp_data_len = roam_fils_params->hlp_data_len;
5816
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305817 /* Calculate skb length */
5818 skb_len = (2 * ETH_ALEN) + hlp_data_len;
5819 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
5820 if (skb == NULL) {
5821 hdd_err("HLP packet nbuf alloc fails");
5822 return;
5823 }
5824
5825 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
5826 QDF_MAC_ADDR_SIZE);
5827 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
5828 QDF_MAC_ADDR_SIZE);
5829
5830 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
5831 if (IS_SNAP(llc_hdr)) {
5832 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5833 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5834 }
5835
5836 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
5837
5838 /*
5839 * This HLP packet is formed from HLP info encapsulated
5840 * in assoc response frame which is AEAD encrypted.
5841 * Hence, this checksum validation can be set unnecessary.
5842 * i.e. network layer need not worry about checksum.
5843 */
5844 skb->ip_summed = CHECKSUM_UNNECESSARY;
5845
5846 status = hdd_rx_packet_cbk(padapter, skb);
5847 if (QDF_IS_STATUS_ERROR(status)) {
5848 hdd_err("Sending HLP packet fails");
5849 return;
5850 }
5851 hdd_debug("send HLP packet to netif successfully");
5852}
5853
5854/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305855 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
5856 * @dev: network device
5857 * @bssid: bssid to which we want to associate
5858 * @bss: cfg80211 bss info
5859 * @roam_info: information about connected bss
5860 * @req_ie: Request Information Element
5861 * @req_ie_len: len of the req IE
5862 * @resp_ie: Response IE
5863 * @resp_ie_len: len of ht response IE
5864 * @status: status
5865 * @gfp: allocation flags
5866 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5867 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305868 *
5869 * This API is used as wrapper to send FILS key/sequence number
5870 * params etc. to supplicant in case of FILS connection
5871 *
5872 * Return: None
5873 */
5874static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005875 struct cfg80211_bss *bss,
5876 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305877 const u8 *req_ie, size_t req_ie_len,
5878 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005879 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305880 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305881{
5882 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305883 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5884 struct fils_join_rsp_params *roam_fils_params =
5885 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005886
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305887 qdf_mem_zero(&fils_params, sizeof(fils_params));
5888
5889 if (!roam_fils_params) {
5890 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5891 } else {
5892 fils_params.status = status;
5893 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08005894 fils_params.timeout_reason =
5895 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305896 fils_params.req_ie = req_ie;
5897 fils_params.req_ie_len = req_ie_len;
5898 fils_params.resp_ie = resp_ie;
5899 fils_params.resp_ie_len = resp_ie_len;
5900 fils_params.bss = bss;
5901 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5902 roam_fils_params->kek_len,
5903 roam_fils_params->fils_pmk,
5904 roam_fils_params->fils_pmk_len,
5905 roam_fils_params->fils_pmkid,
5906 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305907 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305908 }
5909 hdd_debug("FILS indicate connect status %d seq no %d",
5910 fils_params.status,
5911 fils_params.fils_erp_next_seq_num);
5912
5913 cfg80211_connect_done(dev, &fils_params, gfp);
5914
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305915 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305916 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305917
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305918 /* Clear all the FILS key info */
5919 if (roam_fils_params && roam_fils_params->fils_pmk)
5920 qdf_mem_free(roam_fils_params->fils_pmk);
5921 if (roam_fils_params)
5922 qdf_mem_free(roam_fils_params);
5923 roam_info->fils_join_rsp = NULL;
5924}
5925#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005926static inline void
5927hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005928 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005929 const u8 *req_ie, size_t req_ie_len,
5930 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5931 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305932 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305933{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305934#endif
5935#endif
5936
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305937#if defined(WLAN_FEATURE_FILS_SK) && \
5938 (defined(CFG80211_CONNECT_DONE) || \
5939 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305940/**
5941 * hdd_fils_update_connect_results() - API to send fils connection status to
5942 * supplicant.
5943 * @dev: network device
5944 * @bssid: bssid to which we want to associate
5945 * @bss: cfg80211 bss info
5946 * @roam_info: information about connected bss
5947 * @req_ie: Request Information Element
5948 * @req_ie_len: len of the req IE
5949 * @resp_ie: Response IE
5950 * @resp_ie_len: len of ht response IE
5951 * @status: status
5952 * @gfp: allocation flags
5953 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5954 * @timeout_reason: reason for connect timeout
5955 *
5956 * The API is a wrapper to send connection status to supplicant
5957 *
5958 * Return: 0 if success else failure
5959 */
5960static int hdd_fils_update_connect_results(struct net_device *dev,
5961 const u8 *bssid,
5962 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005963 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305964 size_t req_ie_len, const u8 *resp_ie,
5965 size_t resp_ie_len, u16 status, gfp_t gfp,
5966 bool connect_timeout,
5967 tSirResultCodes timeout_reason)
5968{
Dustin Brown491d54b2018-03-14 12:39:11 -07005969 hdd_enter();
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305970 if (!roam_info || !roam_info->is_fils_connection)
5971 return -EINVAL;
5972
5973 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5974 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305975 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305976 return 0;
5977}
5978#else
5979static inline int hdd_fils_update_connect_results(struct net_device *dev,
5980 const u8 *bssid,
5981 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005982 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305983 size_t req_ie_len, const u8 *resp_ie,
5984 size_t resp_ie_len, u16 status, gfp_t gfp,
5985 bool connect_timeout,
5986 tSirResultCodes timeout_reason)
5987{
5988 return -EINVAL;
5989}
5990#endif
5991
Anurag Chouhanc4092922016-09-08 15:56:11 +05305992/**
5993 * hdd_connect_result() - API to send connection status to supplicant
5994 * @dev: network device
5995 * @bssid: bssid to which we want to associate
5996 * @roam_info: information about connected bss
5997 * @req_ie: Request Information Element
5998 * @req_ie_len: len of the req IE
5999 * @resp_ie: Response IE
6000 * @resp_ie_len: len of ht response IE
6001 * @status: status
6002 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05306003 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306004 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05306005 *
6006 * The API is a wrapper to send connection status to supplicant
6007 * and allow runtime suspend
6008 *
6009 * Return: Void
6010 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306011void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006012 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05306013 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05306014 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306015 bool connect_timeout,
6016 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05306017{
Jeff Johnson9d295242017-08-29 14:39:48 -07006018 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306019 struct cfg80211_bss *bss = NULL;
Jingxiang Ge929c7932018-01-24 14:01:12 +08006020 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306021
6022 if (WLAN_STATUS_SUCCESS == status) {
6023 struct ieee80211_channel *chan;
6024 int freq;
6025 int chan_no = roam_info->pBssDesc->channelId;
6026
6027 if (chan_no <= 14)
6028 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07006029 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306030 else
6031 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07006032 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306033
6034 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
6035 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
6036 roam_info->u.pConnectedProfile->SSID.ssId,
6037 roam_info->u.pConnectedProfile->SSID.length);
6038 }
Komal Seelama89be8d2016-09-29 11:09:26 +05306039
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306040 if (hdd_fils_update_connect_results(dev, bssid, bss,
6041 roam_info, req_ie, req_ie_len, resp_ie,
6042 resp_ie_len, status, gfp, connect_timeout,
6043 timeout_reason) != 0) {
6044 hdd_connect_bss(dev, bssid, bss, req_ie,
6045 req_ie_len, resp_ie, resp_ie_len,
6046 status, gfp, connect_timeout, timeout_reason);
6047 }
Komal Seelama89be8d2016-09-29 11:09:26 +05306048
Jingxiang Geb49aa302018-01-17 20:54:15 +08006049 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07006050 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306051}
6052#else
6053void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006054 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05306055 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05306056 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306057 bool connect_timeout,
6058 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05306059{
Jeff Johnson9d295242017-08-29 14:39:48 -07006060 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Jingxiang Ge929c7932018-01-24 14:01:12 +08006061 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05306062
Anurag Chouhanc4092922016-09-08 15:56:11 +05306063 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
6064 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08006065
Jingxiang Geb49aa302018-01-17 20:54:15 +08006066 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07006067 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306068}
6069#endif
6070
Nirav Shah73713f72018-05-17 14:50:41 +05306071#ifdef FEATURE_MONITOR_MODE_SUPPORT
Jeff Johnsond9952752018-04-18 12:15:35 -07006072int wlan_hdd_set_mon_chan(struct hdd_adapter *adapter, uint32_t chan,
6073 uint32_t bandwidth)
6074{
6075 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6076 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
6077 struct hdd_mon_set_ch_info *ch_info = &sta_ctx->ch_info;
6078 QDF_STATUS status;
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006079 tHalHandle hal_hdl = hdd_ctx->mac_handle;
Jeff Johnsond9952752018-04-18 12:15:35 -07006080 struct qdf_mac_addr bssid;
6081 struct csr_roam_profile roam_profile;
6082 struct ch_params ch_params;
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006083 eConnectionState connstate;
Jeff Johnsond9952752018-04-18 12:15:35 -07006084
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006085 if (hdd_get_conparam() != QDF_GLOBAL_MONITOR_MODE &&
6086 adapter->device_mode != QDF_STA_MODE) {
6087 hdd_err("Not supported, device is not in monitor mode or sta mission mode");
Jeff Johnsond9952752018-04-18 12:15:35 -07006088 return -EINVAL;
6089 }
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006090 if (adapter->device_mode == QDF_STA_MODE &&
6091 hdd_ctx->config->enable_change_channel_bandwidth) {
6092 connstate = sta_ctx->conn_info.connState;
6093 if (eConnectionState_Associated == connstate ||
6094 eConnectionState_Connecting == connstate) {
6095 return -EINVAL;
6096 }
6097 }
Jeff Johnsond9952752018-04-18 12:15:35 -07006098
Visweswara Tanuku006313a2018-04-12 12:26:34 +05306099 /* Validate Channel */
6100 if (!WLAN_REG_IS_24GHZ_CH(chan) && !WLAN_REG_IS_5GHZ_CH(chan)) {
6101 hdd_err("Channel %d Not supported", chan);
6102 return -EINVAL;
6103 }
6104
6105 if (WLAN_REG_IS_24GHZ_CH(chan)) {
6106 if (bandwidth == CH_WIDTH_80MHZ) {
6107 hdd_err("BW80 not possible in 2.4GHz band");
6108 return -EINVAL;
6109 }
6110 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 14) &&
6111 (bandwidth != CH_WIDTH_MAX)) {
6112 hdd_err("Only BW20 possible on channel 14");
6113 return -EINVAL;
6114 }
6115 }
6116
6117 if (WLAN_REG_IS_5GHZ_CH(chan)) {
6118 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 165) &&
6119 (bandwidth != CH_WIDTH_MAX)) {
6120 hdd_err("Only BW20 possible on channel 165");
6121 return -EINVAL;
6122 }
6123 }
6124
Jeff Johnsond9952752018-04-18 12:15:35 -07006125 hdd_debug("Set monitor mode Channel %d", chan);
6126 qdf_mem_zero(&roam_profile, sizeof(roam_profile));
6127 roam_profile.ChannelInfo.ChannelList = &ch_info->channel;
6128 roam_profile.ChannelInfo.numOfChannels = 1;
6129 roam_profile.phyMode = ch_info->phy_mode;
6130 roam_profile.ch_params.ch_width = bandwidth;
6131 hdd_select_cbmode(adapter, chan, &roam_profile.ch_params);
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006132 if (hdd_ctx->config->enable_change_channel_bandwidth &&
6133 (!sme_find_session_by_bssid(hal_hdl, adapter->mac_addr.bytes))) {
6134 status = sme_create_mon_session(hal_hdl,
6135 adapter->mac_addr.bytes);
6136 if (status != QDF_STATUS_SUCCESS) {
6137 hdd_err("Status: %d Failed to create session.",
6138 status);
6139 return qdf_status_to_os_return(status);
6140 }
6141 }
Jeff Johnsond9952752018-04-18 12:15:35 -07006142 qdf_mem_copy(bssid.bytes, adapter->mac_addr.bytes,
6143 QDF_MAC_ADDR_SIZE);
6144
6145 ch_params.ch_width = bandwidth;
6146 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev, chan, 0, &ch_params);
6147 if (ch_params.ch_width == CH_WIDTH_INVALID) {
6148 hdd_err("Invalid capture channel or bandwidth for a country");
6149 return -EINVAL;
6150 }
6151 if (wlan_hdd_change_hw_mode_for_given_chnl(adapter, chan,
6152 POLICY_MGR_UPDATE_REASON_SET_OPER_CHAN)) {
6153 hdd_err("Failed to change hw mode");
6154 return -EINVAL;
6155 }
6156
Jeff Johnson16528362018-06-14 12:34:16 -07006157 status = sme_roam_channel_change_req(hdd_ctx->mac_handle,
6158 bssid, &ch_params,
Jeff Johnsond9952752018-04-18 12:15:35 -07006159 &roam_profile);
6160 if (status) {
6161 hdd_err("Status: %d Failed to set sme_roam Channel for monitor mode",
6162 status);
6163 }
6164
6165 adapter->mon_chan = chan;
6166 adapter->mon_bandwidth = bandwidth;
6167 return qdf_status_to_os_return(status);
6168}
Nirav Shah73713f72018-05-17 14:50:41 +05306169#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05306170
Wu Gaodf929f12018-05-25 18:12:25 +08006171#ifdef MSM_PLATFORM
6172/**
6173 * hdd_stop_p2p_go() - call cfg80211 API to stop P2P GO
6174 * @adapter: pointer to adapter
6175 *
6176 * This function calls cfg80211 API to stop P2P GO
6177 *
6178 * Return: None
6179 */
6180static void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6181{
6182 hdd_debug("[SSR] send stop ap to supplicant");
6183 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
6184}
6185
6186static inline void hdd_delete_sta(struct hdd_adapter *adapter)
6187{
6188}
6189#else
6190static inline void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6191{
6192}
6193
6194/**
6195 * hdd_delete_sta() - call cfg80211 API to delete STA
6196 * @adapter: pointer to adapter
6197 *
6198 * This function calls cfg80211 API to delete STA
6199 *
6200 * Return: None
6201 */
6202static void hdd_delete_sta(struct hdd_adapter *adapter)
6203{
6204 struct qdf_mac_addr bcast_mac = QDF_MAC_ADDR_BCAST_INIT;
6205
6206 hdd_debug("[SSR] send restart supplicant");
6207 /* event supplicant to restart */
6208 cfg80211_del_sta(adapter->dev,
6209 (const u8 *)&bcast_mac.bytes[0],
6210 GFP_KERNEL);
6211}
6212#endif
6213
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006214QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006215{
Jeff Johnson9d295242017-08-29 14:39:48 -07006216 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006217 eConnectionState connState;
6218
Dustin Brown491d54b2018-03-14 12:39:11 -07006219 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006220
Dustin Brown920397d2017-12-13 16:27:50 -08006221 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05306222 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08006223 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05306224
Yue Ma42654682018-01-11 16:55:24 -08006225 hdd_debug("[SSR] start adapter with device mode %s(%d)",
6226 hdd_device_mode_to_string(adapter->device_mode),
6227 adapter->device_mode);
6228
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006229 hdd_wmm_init(adapter);
6230
6231 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006232 case QDF_STA_MODE:
6233 case QDF_P2P_CLIENT_MODE:
6234 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006235
6236 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
6237 ->conn_info.connState;
6238
Krunal Sonib51eec72017-11-20 21:53:01 -08006239 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006240 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07006241 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006242
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006243 /* Indicate disconnect event to supplicant
6244 * if associated previously
6245 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006246 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07006247 eConnectionState_IbssConnected == connState ||
6248 eConnectionState_NotConnected == connState ||
6249 eConnectionState_IbssDisconnected == connState ||
6250 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006251 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006252
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006253 memset(&wrqu, '\0', sizeof(wrqu));
6254 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
6255 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
6256 wireless_send_event(adapter->dev, SIOCGIWAP,
6257 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07006258 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07006259 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006260
6261 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05306262 wlan_hdd_cfg80211_indicate_disconnect(
6263 adapter->dev, false,
6264 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006265 } else if (eConnectionState_Connecting == connState) {
6266 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006267 * Indicate connect failure to supplicant if we
6268 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006269 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306270 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306271 NULL, 0, NULL, 0,
6272 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006273 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006274 }
6275
6276 hdd_register_tx_flow_control(adapter,
6277 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08006278 hdd_tx_resume_cb,
6279 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006280
Arunk Khandavalli40943af2017-05-15 19:25:34 +05306281 hdd_lpass_notify_start(hdd_ctx, adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05306282 hdd_nud_ignore_tracking(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006283 break;
6284
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006285 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006286 if (hdd_ctx->config->sap_internal_restart)
Krunal Sonib51eec72017-11-20 21:53:01 -08006287 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05306288
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006289 break;
6290
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006291 case QDF_P2P_GO_MODE:
Wu Gaodf929f12018-05-25 18:12:25 +08006292 hdd_delete_sta(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006293 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306294 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08006295 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306296 hdd_set_mon_rx_cb(adapter->dev);
6297 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
6298 adapter->mon_bandwidth);
6299 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006300 default:
6301 break;
6302 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07006303 /*
6304 * Action frame registered in one adapter which will
6305 * applicable to all interfaces
6306 */
6307 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006308 }
6309
Wu Gaodf929f12018-05-25 18:12:25 +08006310 hdd_for_each_adapter(hdd_ctx, adapter) {
6311 if (!hdd_is_interface_up(adapter))
6312 continue;
6313
6314 if (adapter->device_mode == QDF_P2P_GO_MODE)
6315 hdd_stop_p2p_go(adapter);
6316 }
6317
Dustin Browne74003f2018-03-14 12:51:58 -07006318 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006319
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306320 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006321}
6322
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006323QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006324 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006325{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306326 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006327 qdf_list_node_t *node;
6328
6329 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006330
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006331 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006332 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006333 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006334
6335 if (QDF_IS_STATUS_ERROR(status))
6336 return status;
6337
6338 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6339
6340 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006341}
6342
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006343QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006344 struct hdd_adapter *current_adapter,
6345 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006346{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306347 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006348 qdf_list_node_t *node;
6349
6350 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006351
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006352 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006353 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08006354 &current_adapter->node,
6355 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006356 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006357
6358 if (QDF_IS_STATUS_ERROR(status))
6359 return status;
6360
6361 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6362
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006363 return status;
6364}
6365
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006366QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006367 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006368{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306369 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006370
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006371 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006372 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006373 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006374
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006375 return status;
6376}
6377
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006378QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006379 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006380{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306381 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006382 qdf_list_node_t *node;
6383
6384 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006385
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006386 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006387 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006388 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006389
6390 if (QDF_IS_STATUS_ERROR(status))
6391 return status;
6392
6393 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6394
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006395 return status;
6396}
6397
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006398QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006399 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006400{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306401 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006402
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006403 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006404 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006405 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006406
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006407 return status;
6408}
6409
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006410QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006411 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006412{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306413 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006414
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006415 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006416 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006417 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006418
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006419 return status;
6420}
6421
Jeff Johnson9d295242017-08-29 14:39:48 -07006422struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006423 tSirMacAddr macAddr)
6424{
Jeff Johnson9d295242017-08-29 14:39:48 -07006425 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006426
Dustin Brown920397d2017-12-13 16:27:50 -08006427 hdd_for_each_adapter(hdd_ctx, adapter) {
6428 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
6429 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006430 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006431 }
6432
6433 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006434}
6435
Jeff Johnson9d295242017-08-29 14:39:48 -07006436struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006437 uint32_t vdev_id)
6438{
Jeff Johnson9d295242017-08-29 14:39:48 -07006439 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006440
Dustin Brown920397d2017-12-13 16:27:50 -08006441 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07006442 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006443 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006444 }
6445
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006446 return NULL;
6447}
6448
Abhishek Singh7996eb72015-12-30 17:24:02 +05306449/**
6450 * hdd_get_adapter_by_sme_session_id() - Return adapter with
6451 * the sessionid
6452 * @hdd_ctx: hdd context.
6453 * @sme_session_id: sme session is for the adapter to get.
6454 *
6455 * This function is used to get the adapter with provided session id
6456 *
6457 * Return: adapter pointer if found
6458 *
6459 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07006460struct hdd_adapter *
6461hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
6462 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306463{
Jeff Johnson9d295242017-08-29 14:39:48 -07006464 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306465
Dustin Brown920397d2017-12-13 16:27:50 -08006466 hdd_for_each_adapter(hdd_ctx, adapter) {
6467 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306468 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306469 }
Dustin Brown920397d2017-12-13 16:27:50 -08006470
Abhishek Singh7996eb72015-12-30 17:24:02 +05306471 return NULL;
6472}
6473
Jeff Johnson9d295242017-08-29 14:39:48 -07006474struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07006475 const char *iface_name)
6476{
Jeff Johnson9d295242017-08-29 14:39:48 -07006477 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006478
Dustin Brown920397d2017-12-13 16:27:50 -08006479 hdd_for_each_adapter(hdd_ctx, adapter) {
6480 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07006481 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006482 }
Dustin Brown920397d2017-12-13 16:27:50 -08006483
Naveen Rawat4edb6822017-04-12 10:09:17 -07006484 return NULL;
6485}
6486
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006487/**
6488 * hdd_get_adapter() - to get adapter matching the mode
6489 * @hdd_ctx: hdd context
6490 * @mode: adapter mode
6491 *
6492 * This routine will return the pointer to adapter matching
6493 * with the passed mode.
6494 *
6495 * Return: pointer to adapter or null
6496 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006497struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006498 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006499{
Jeff Johnson9d295242017-08-29 14:39:48 -07006500 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006501
Dustin Brown920397d2017-12-13 16:27:50 -08006502 hdd_for_each_adapter(hdd_ctx, adapter) {
6503 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006504 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006505 }
6506
6507 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006508}
6509
Jeff Johnson36a0abf2018-05-20 11:24:25 -07006510enum QDF_OPMODE hdd_get_device_mode(uint32_t session_id)
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306511{
6512 struct hdd_context *hdd_ctx;
6513 struct hdd_adapter *adapter;
6514
6515 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
6516 if (!hdd_ctx) {
6517 hdd_err("Invalid HDD context");
6518 return QDF_MAX_NO_OF_MODE;
6519 }
6520
6521 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
6522 if (!adapter) {
6523 hdd_err("Invalid HDD adapter");
6524 return QDF_MAX_NO_OF_MODE;
6525 }
6526
6527 return adapter->device_mode;
6528}
6529
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006530/**
6531 * hdd_get_operating_channel() - return operating channel of the device mode
6532 * @hdd_ctx: Pointer to the HDD context.
6533 * @mode: Device mode for which operating channel is required.
Jeff Johnson77f89bb2018-05-06 16:21:36 -07006534 * Supported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006535 * QDF_STA_MODE,
6536 * QDF_P2P_CLIENT_MODE,
6537 * QDF_SAP_MODE,
6538 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006539 *
6540 * This API returns the operating channel of the requested device mode
6541 *
6542 * Return: channel number. "0" id the requested device is not found OR it is
6543 * not connected.
6544 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006545uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006546 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006547{
Jeff Johnson9d295242017-08-29 14:39:48 -07006548 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006549 uint8_t operatingChannel = 0;
6550
Dustin Brown920397d2017-12-13 16:27:50 -08006551 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006552 if (mode == adapter->device_mode) {
6553 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006554 case QDF_STA_MODE:
6555 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006556 if (hdd_conn_is_connected
6557 (WLAN_HDD_GET_STATION_CTX_PTR
6558 (adapter))) {
6559 operatingChannel =
6560 (WLAN_HDD_GET_STATION_CTX_PTR
6561 (adapter))->conn_info.
6562 operationChannel;
6563 }
6564 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006565 case QDF_SAP_MODE:
6566 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006567 /* softap connection info */
6568 if (test_bit
6569 (SOFTAP_BSS_STARTED,
6570 &adapter->event_flags))
6571 operatingChannel =
6572 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07006573 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006574 break;
6575 default:
6576 break;
6577 }
6578
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006579 /* Found the device of interest. break the loop */
6580 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006581 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006582 }
Dustin Brown920397d2017-12-13 16:27:50 -08006583
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006584 return operatingChannel;
6585}
6586
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006587static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006588 hdd_ctx)
6589{
Jeff Johnson9d295242017-08-29 14:39:48 -07006590 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006591
Dustin Brown491d54b2018-03-14 12:39:11 -07006592 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006593
Dustin Brown920397d2017-12-13 16:27:50 -08006594 hdd_for_each_adapter(hdd_ctx, adapter) {
6595 if (adapter->device_mode == QDF_STA_MODE ||
6596 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6597 adapter->device_mode == QDF_IBSS_MODE ||
6598 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6599 adapter->device_mode == QDF_SAP_MODE ||
6600 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006601 hdd_unregister_wext(adapter->dev);
6602 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006603 }
6604
Dustin Browne74003f2018-03-14 12:51:58 -07006605 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006606
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306607 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006608}
6609
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006610QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006611{
Jeff Johnson9d295242017-08-29 14:39:48 -07006612 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006613
Dustin Brown491d54b2018-03-14 12:39:11 -07006614 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006615
Dustin Brown920397d2017-12-13 16:27:50 -08006616 hdd_for_each_adapter(hdd_ctx, adapter) {
6617 if (adapter->device_mode == QDF_STA_MODE ||
6618 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6619 adapter->device_mode == QDF_IBSS_MODE ||
6620 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6621 adapter->device_mode == QDF_SAP_MODE ||
6622 adapter->device_mode == QDF_P2P_GO_MODE) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006623 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006624 adapter->session_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05306625 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006626 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006627 }
6628
Dustin Browne74003f2018-03-14 12:51:58 -07006629 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006630
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306631 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006632}
6633
Dustin Brownf27bce82016-11-03 12:52:27 -07006634/**
6635 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
6636 * adapters
6637 * @hdd_ctx: The HDD context containing the adapters to operate on
6638 *
6639 * return: QDF_STATUS_SUCCESS
6640 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006641static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07006642{
Jeff Johnson9d295242017-08-29 14:39:48 -07006643 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07006644 int err;
6645
Dustin Brown491d54b2018-03-14 12:39:11 -07006646 hdd_enter();
Dustin Brownf27bce82016-11-03 12:52:27 -07006647
Dustin Brown920397d2017-12-13 16:27:50 -08006648 hdd_for_each_adapter(hdd_ctx, adapter) {
6649 if (adapter->device_mode == QDF_STA_MODE ||
6650 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6651 adapter->device_mode == QDF_IBSS_MODE ||
6652 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6653 adapter->device_mode == QDF_SAP_MODE ||
6654 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07006655 err = wlan_hdd_sched_scan_stop(adapter->dev);
6656 if (err)
6657 hdd_err("Unable to stop scheduled scan");
6658 }
Dustin Brownf27bce82016-11-03 12:52:27 -07006659 }
6660
Dustin Browne74003f2018-03-14 12:51:58 -07006661 hdd_exit();
Dustin Brownf27bce82016-11-03 12:52:27 -07006662
6663 return QDF_STATUS_SUCCESS;
6664}
6665
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006666#ifdef WLAN_NS_OFFLOAD
6667/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006668 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006669 * @hdd_ctx: Pointer to hdd context
6670 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006671 * Unregister for IPv6 address change notifications.
6672 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006673 * Return: None
6674 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006675static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006676{
6677 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006678}
6679
6680/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006681 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006682 * @hdd_ctx: Pointer to hdd context
6683 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006684 * Register for IPv6 address change notifications.
6685 *
6686 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006687 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006688static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006689{
6690 int ret;
6691
6692 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
6693 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006694 if (ret) {
6695 hdd_err("Failed to register IPv6 notifier: %d", ret);
6696 goto out;
6697 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006698
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006699 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006700out:
6701 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006702}
6703#else
6704/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006705 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006706 * @hdd_ctx: Pointer to hdd context
6707 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006708 * Unregister for IPv6 address change notifications.
6709 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006710 * Return: None
6711 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006712static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006713{
6714}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006715
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006716/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006717 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006718 * @hdd_ctx: Pointer to hdd context
6719 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006720 * Register for IPv6 address change notifications.
6721 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006722 * Return: None
6723 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006724static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006725{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006726 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006727}
6728#endif
6729
Alok Kumarb64650c2018-03-23 17:05:11 +05306730void hdd_set_disconnect_status(struct hdd_adapter *adapter, bool status)
6731{
6732 qdf_mutex_acquire(&adapter->disconnection_status_lock);
6733 adapter->disconnection_in_progress = status;
6734 qdf_mutex_release(&adapter->disconnection_status_lock);
6735 hdd_debug("setting disconnection status: %d", status);
6736}
6737
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006738/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006739 * hdd_register_notifiers - Register netdev notifiers.
6740 * @hdd_ctx: HDD context
6741 *
6742 * Register netdev notifiers like IPv4 and IPv6.
6743 *
6744 * Return: 0 on success and errno on failure
6745 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006746static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006747{
6748 int ret;
6749
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006750 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
6751 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306752 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006753
6754 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
6755 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
6756 if (ret) {
6757 hdd_err("Failed to register IPv4 notifier: %d", ret);
6758 goto unregister_ip6_notifier;
6759 }
6760
Alok Kumarb64650c2018-03-23 17:05:11 +05306761 ret = hdd_nud_register_netevent_notifier(hdd_ctx);
6762 if (ret) {
6763 hdd_err("Failed to register netevent notifier: %d",
6764 ret);
6765 goto unregister_inetaddr_notifier;
6766 }
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006767 return 0;
6768
Alok Kumarb64650c2018-03-23 17:05:11 +05306769unregister_inetaddr_notifier:
6770 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006771unregister_ip6_notifier:
6772 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006773out:
6774 return ret;
6775
6776}
6777
6778/**
6779 * hdd_unregister_notifiers - Unregister netdev notifiers.
6780 * @hdd_ctx: HDD context
6781 *
6782 * Unregister netdev notifiers like IPv4 and IPv6.
6783 *
6784 * Return: None.
6785 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006786void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006787{
Alok Kumarb64650c2018-03-23 17:05:11 +05306788 hdd_nud_unregister_netevent_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006789 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
6790
6791 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006792}
6793
6794/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006795 * hdd_exit_netlink_services - Exit netlink services
6796 * @hdd_ctx: HDD context
6797 *
6798 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
6799 * nl service.
6800 *
6801 * Return: None.
6802 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006803static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006804{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306805 spectral_scan_deactivate_service();
6806 cnss_diag_deactivate_service();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006807 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006808 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306809 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006810
6811 nl_srv_exit();
6812}
6813
6814/**
6815 * hdd_init_netlink_services- Init netlink services
6816 * @hdd_ctx: HDD context
6817 *
6818 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
6819 * nl service.
6820 *
6821 * Return: 0 on success and errno on failure.
6822 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006823static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006824{
6825 int ret;
6826
Ryan Hsuceddceb2016-04-28 10:20:14 -07006827 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006828 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006829 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006830 goto out;
6831 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07006832 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006833
Naveen Rawat910726a2017-03-06 11:42:51 -08006834 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006835 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006836 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006837 goto err_nl_srv;
6838 }
6839
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306840 ptt_sock_activate_svc();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006841
6842 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07006843 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006844 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006845
6846 ret = cnss_diag_activate_service();
6847 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006848 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006849 goto err_close_cesium;
6850 }
6851
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306852 spectral_scan_activate_service();
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08006853
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006854 return 0;
6855
6856err_close_cesium:
6857 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006858 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306859 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006860err_nl_srv:
6861 nl_srv_exit();
6862out:
6863 return ret;
6864}
6865
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006866/**
6867 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
6868 * @hdd_ctx: HDD context.
6869 *
6870 * Destroy RX wakelock.
6871 *
6872 * Return: None.
6873 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006874static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006875{
6876 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
6877}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006878
6879/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006880 * hdd_rx_wake_lock_create() - Create RX wakelock
6881 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006882 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006883 * Create RX wakelock.
6884 *
6885 * Return: None.
6886 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006887static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006888{
6889 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
6890}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006891
6892/**
Houston Hoffman160db392016-10-10 17:37:51 -07006893 * hdd_context_deinit() - Deinitialize HDD context
6894 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006895 *
Houston Hoffman160db392016-10-10 17:37:51 -07006896 * Deinitialize HDD context along with all the feature specific contexts but
6897 * do not free hdd context itself. Caller of this API is supposed to free
6898 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006899 *
Houston Hoffman160db392016-10-10 17:37:51 -07006900 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006901 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006902static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006903{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306904 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
6905
Houston Hoffman160db392016-10-10 17:37:51 -07006906 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006907
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006908 hdd_sap_context_destroy(hdd_ctx);
6909
6910 hdd_rx_wake_lock_destroy(hdd_ctx);
6911
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006912 hdd_scan_context_destroy(hdd_ctx);
6913
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006914 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006915
Houston Hoffman160db392016-10-10 17:37:51 -07006916 return 0;
6917}
6918
6919/**
6920 * hdd_context_destroy() - Destroy HDD context
6921 * @hdd_ctx: HDD context to be destroyed.
6922 *
6923 * Free config and HDD context as well as destroy all the resources.
6924 *
6925 * Return: None
6926 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006927static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07006928{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07006929 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05306930
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05306931 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
6932
Houston Hoffman160db392016-10-10 17:37:51 -07006933 hdd_context_deinit(hdd_ctx);
6934
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306935 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006936 hdd_ctx->config = NULL;
6937
Dustin Brown84f46ea2018-02-15 11:57:36 -08006938 cfg_release();
6939
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006940 wiphy_free(hdd_ctx->wiphy);
6941}
6942
6943/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306944 * wlan_destroy_bug_report_lock() - Destroy bug report lock
6945 *
6946 * This function is used to destroy bug report lock
6947 *
6948 * Return: None
6949 */
6950static void wlan_destroy_bug_report_lock(void)
6951{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07006952 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306953
6954 p_cds_context = cds_get_global_context();
6955 if (!p_cds_context) {
6956 hdd_err("cds context is NULL");
6957 return;
6958 }
6959
6960 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6961}
6962
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05306963#ifdef DISABLE_CHANNEL_LIST
6964static void wlan_hdd_cache_chann_mutex_destroy(struct hdd_context *hdd_ctx)
6965{
6966 qdf_mutex_destroy(&hdd_ctx->cache_channel_lock);
6967}
6968#else
6969static void wlan_hdd_cache_chann_mutex_destroy(struct hdd_context *hdd_ctx)
6970{
6971}
6972#endif
6973
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306974/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006975 * hdd_wlan_exit() - HDD WLAN exit function
6976 * @hdd_ctx: Pointer to the HDD Context
6977 *
6978 * This is the driver exit point (invoked during rmmod)
6979 *
6980 * Return: None
6981 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006982static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006983{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006984 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306985 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006986
Dustin Brown491d54b2018-03-14 12:39:11 -07006987 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006988
Arun Khandavallifae92942016-08-01 13:31:08 +05306989 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006990
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006991#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306992 if (QDF_TIMER_STATE_RUNNING ==
6993 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6994 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006995 }
6996
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306997 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306998 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006999 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007000 }
Liangwei Dongaef84342016-10-21 05:28:00 -04007001 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
7002 qdf_mem_free(hdd_ctx->last_acs_channel_list);
7003 hdd_ctx->last_acs_channel_list = NULL;
7004 hdd_ctx->num_of_channels = 0;
7005 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007006#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007007
Arun Khandavallifae92942016-08-01 13:31:08 +05307008 mutex_lock(&hdd_ctx->iface_change_lock);
7009 driver_status = hdd_ctx->driver_status;
7010 mutex_unlock(&hdd_ctx->iface_change_lock);
7011
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007012 /*
7013 * Powersave Offload Case
7014 * Disable Idle Power Save Mode
7015 */
7016 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07007017 /* clear the scan queue in all the scenarios */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +05307018 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007019
Arun Khandavallifae92942016-08-01 13:31:08 +05307020 if (driver_status != DRIVER_MODULES_CLOSED) {
7021 hdd_unregister_wext_all_adapters(hdd_ctx);
7022 /*
7023 * Cancel any outstanding scan requests. We are about to close
7024 * all of our adapters, but an adapter structure is what SME
7025 * passes back to our callback function. Hence if there
7026 * are any outstanding scan requests then there is a
7027 * race condition between when the adapter is closed and
7028 * when the callback is invoked. We try to resolve that
7029 * race condition here by canceling any outstanding scans
7030 * before we close the adapters.
7031 * Note that the scans may be cancelled in an asynchronous
7032 * manner, so ideally there needs to be some kind of
7033 * synchronization. Rather than introduce a new
7034 * synchronization here, we will utilize the fact that we are
7035 * about to Request Full Power, and since that is synchronized,
7036 * the expectation is that by the time Request Full Power has
7037 * completed, all scans will be cancelled
7038 */
7039 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07007040 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08007041 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08007042 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007043 }
7044
Arunk Khandavalli830c9692018-03-22 12:17:40 +05307045 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavalli08479ba2017-08-07 19:56:23 +05307046 unregister_netdevice_notifier(&hdd_netdev_notifier);
7047
Rachit Kankane30807332018-06-27 18:39:36 +05307048 qdf_dp_trace_deinit();
7049
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07007050 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05307051
Dustin Brown86d196b2018-08-02 11:51:49 -07007052 hdd_bus_bandwidth_deinit(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -08007053 hdd_driver_memdump_deinit();
7054
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05307055 qdf_nbuf_deinit_replenish_timer();
7056
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05307057 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
7058 hdd_info("Release wakelock for monitor mode!");
7059 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
7060 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
7061 }
7062
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307063 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
7064 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
7065 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05307066 wlan_hdd_cache_chann_mutex_destroy(hdd_ctx);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307067
Naveen Rawate02f8f52018-04-05 11:58:04 -07007068 osif_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007069
Dustin Brownd005ad82018-01-19 10:32:13 -08007070 hdd_close_all_adapters(hdd_ctx, false);
7071
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05307072 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307073 /*
7074 * If there is re_init failure wiphy would have already de-registered
7075 * check the wiphy status before un-registering again
7076 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05307077 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307078 wiphy_unregister(wiphy);
7079 wlan_hdd_cfg80211_deinit(wiphy);
7080 hdd_lpass_notify_stop(hdd_ctx);
7081 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07007082
Arun Khandavallifae92942016-08-01 13:31:08 +05307083 hdd_exit_netlink_services(hdd_ctx);
7084 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307085#ifdef FEATURE_WLAN_CH_AVOID
7086 mutex_destroy(&hdd_ctx->avoid_freq_lock);
7087#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05307088
Abhishek Singhe9068f12017-03-31 14:14:52 +05307089 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
7090 if (driver_status)
7091 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07007092
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007093 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007094}
7095
7096void __hdd_wlan_exit(void)
7097{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007098 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007099
Dustin Brown491d54b2018-03-14 12:39:11 -07007100 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007101
Anurag Chouhan6d760662016-02-20 16:05:43 +05307102 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007103 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007104 hdd_err("Invalid HDD Context");
Dustin Browne74003f2018-03-14 12:51:58 -07007105 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007106 return;
7107 }
7108
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007109 /* Do all the cleanup before deregistering the driver */
7110 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07007111
Dustin Browne74003f2018-03-14 12:51:58 -07007112 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007113}
7114
7115#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04007116/**
7117 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007118 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04007119 *
7120 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
7121 * Then new ACS request will do a fresh scan without reusing the cached
7122 * scan information.
7123 *
7124 * Return: void
7125 */
Tang Yingying523322d2017-01-17 23:28:43 +08007126static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007127{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007128 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Jeff Johnson16528362018-06-14 12:34:16 -07007129 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007130
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007131 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007132 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04007133 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
7134 qdf_mem_free(hdd_ctx->last_acs_channel_list);
7135 hdd_ctx->last_acs_channel_list = NULL;
7136 hdd_ctx->num_of_channels = 0;
7137 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007138
Jeff Johnson16528362018-06-14 12:34:16 -07007139 mac_handle = hdd_ctx->mac_handle;
7140 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007141 return;
Jeff Johnson16528362018-06-14 12:34:16 -07007142 sme_scan_flush_result(mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007143}
7144#endif
7145
7146#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07007147int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
7148 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007149{
7150 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307151 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07007152 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07007153 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007154
7155 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7156
7157 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307158 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007159 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307160
Jeff Johnson16528362018-06-14 12:34:16 -07007161 mac_handle = hdd_ctx->mac_handle;
7162 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007163 return -EINVAL;
7164
Jeff Johnson16528362018-06-14 12:34:16 -07007165 qdf_status = sme_notify_ht2040_mode(mac_handle, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007166 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307167 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007168 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007169 return -EINVAL;
7170 }
7171
7172 return 0;
7173}
7174#endif
7175
7176/**
7177 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
7178 * @state: state
7179 *
7180 * This function notifies FW with modem power status
7181 *
7182 * Return: 0 if successful, error number otherwise
7183 */
7184int hdd_wlan_notify_modem_power_state(int state)
7185{
7186 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307187 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007188 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07007189 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007190
Anurag Chouhan6d760662016-02-20 16:05:43 +05307191 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007192 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307193 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007194 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307195
Jeff Johnson16528362018-06-14 12:34:16 -07007196 mac_handle = hdd_ctx->mac_handle;
7197 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007198 return -EINVAL;
7199
Jeff Johnson16528362018-06-14 12:34:16 -07007200 qdf_status = sme_notify_modem_power_state(mac_handle, state);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307201 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007202 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007203 state);
7204 return -EINVAL;
7205 }
7206 return 0;
7207}
7208
7209/**
7210 *
7211 * hdd_post_cds_enable_config() - HDD post cds start config helper
7212 * @adapter - Pointer to the HDD
7213 *
7214 * Return: None
7215 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007216QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007217{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307218 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007219
7220 /*
7221 * Send ready indication to the HDD. This will kick off the MAC
7222 * into a 'running' state and should kick off an initial scan.
7223 */
Jeff Johnson16528362018-06-14 12:34:16 -07007224 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->mac_handle);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307225 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007226 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
7227 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307228 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007229 }
7230
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307231 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007232}
7233
Sourav Mohapatra92ea8d62018-02-05 10:03:10 +05307234struct hdd_adapter *hdd_get_first_valid_adapter(struct hdd_context *hdd_ctx)
7235{
7236 struct hdd_adapter *adapter;
7237
7238 hdd_for_each_adapter(hdd_ctx, adapter) {
7239 if (adapter && adapter->magic == WLAN_HDD_ADAPTER_MAGIC)
7240 return adapter;
7241 }
7242
7243 return NULL;
7244}
7245
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007246/* wake lock APIs for HDD */
7247void hdd_prevent_suspend(uint32_t reason)
7248{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307249 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007250}
7251
7252void hdd_allow_suspend(uint32_t reason)
7253{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307254 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007255}
7256
7257void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
7258{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05307259 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
7260 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007261}
7262
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007263/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007264QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007265{
Jeff Johnson16528362018-06-14 12:34:16 -07007266 return sme_init_chan_list(hdd_ctx->mac_handle,
Amar Singhal6f8592b2017-04-26 14:31:58 -07007267 hdd_ctx->reg.alpha2,
7268 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007269}
7270
7271/**
7272 * hdd_is_5g_supported() - check if hardware supports 5GHz
7273 * @hdd_ctx: Pointer to the hdd context
7274 *
7275 * HDD function to know if hardware supports 5GHz
7276 *
7277 * Return: true if hardware supports 5GHz
7278 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007279bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007280{
Amar Singhal58b45ef2017-08-01 13:43:54 -07007281 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08007282 return true;
7283
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08007284 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08007285 return true;
7286 else
7287 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007288}
7289
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007290static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007291{
7292 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07007293 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007294
7295 wiphy = hdd_ctx->wiphy;
7296
7297 /*
7298 * The channel information in
7299 * wiphy needs to be initialized before wiphy registration
7300 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007301 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
7302 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007303 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07007304 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007305 }
7306
7307#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
7308 wiphy->wowlan = &wowlan_support_reg_init;
7309#else
7310 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
7311 WIPHY_WOWLAN_MAGIC_PKT |
7312 WIPHY_WOWLAN_DISCONNECT |
7313 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
7314 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
7315 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
7316 WIPHY_WOWLAN_4WAY_HANDSHAKE |
7317 WIPHY_WOWLAN_RFKILL_RELEASE;
7318
7319 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
7320 WOW_MAX_FILTERS_PER_LIST);
7321 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
7322 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
7323#endif
Liangwei Dong0da14262018-07-03 03:30:23 -04007324 if (hdd_ctx->obss_scan_offload) {
7325 hdd_debug("wmi_service_obss_scan supported");
7326 } else if (hdd_ctx->config->nChannelBondingMode24GHz) {
7327 hdd_debug("enable wpa_supp obss_scan");
7328 wiphy->features |= NL80211_FEATURE_NEED_OBSS_SCAN;
7329 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007330
7331 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007332 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307333 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07007334 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307335 return ret_val;
7336 }
Amar Singhalac26de22018-06-22 12:53:06 -07007337
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007338 /* Check the kernel version for upstream commit aced43ce780dc5 that
7339 * has support for processing user cell_base hints when wiphy is
7340 * self managed or check the backport flag for the same.
7341 */
Amar Singhalac26de22018-06-22 12:53:06 -07007342#if defined CFG80211_USER_HINT_CELL_BASE_SELF_MANAGED || \
7343 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0))
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007344 hdd_send_wiphy_regd_sync_event(hdd_ctx);
7345#endif
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307346
Amar Singhal2d812012018-02-03 15:06:47 +08007347 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007348
Amar Singhale4f28ee2015-10-21 14:36:56 -07007349 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007350}
7351
Mohit Khannaca4173b2017-09-12 21:52:19 -07007352#ifdef MSM_PLATFORM
7353/**
7354 * hdd_display_periodic_stats() - Function to display periodic stats
7355 * @hdd_ctx - handle to hdd context
7356 * @bool data_in_interval - true, if data detected in bw time interval
7357 *
7358 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
7359 * Stats show up in wlan driver logs.
7360 *
7361 * Returns: None
7362 */
Mohit Khanna70322002018-05-15 19:21:32 -07007363static void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
7364 bool data_in_interval)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007365{
Mohit Khanna70322002018-05-15 19:21:32 -07007366 static uint32_t counter;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007367 static bool data_in_time_period;
7368 ol_txrx_pdev_handle pdev;
7369
7370 if (hdd_ctx->config->periodic_stats_disp_time == 0)
7371 return;
7372
7373 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
7374 if (!pdev) {
7375 hdd_err("pdev is NULL");
7376 return;
7377 }
7378
7379 counter++;
7380 if (data_in_interval)
7381 data_in_time_period = data_in_interval;
7382
7383 if (counter * hdd_ctx->config->busBandwidthComputeInterval >=
7384 hdd_ctx->config->periodic_stats_disp_time * 1000) {
7385 if (data_in_time_period) {
Mohit Khanna70322002018-05-15 19:21:32 -07007386 wlan_hdd_display_txrx_stats(hdd_ctx);
7387 dp_txrx_dump_stats(cds_get_context(QDF_MODULE_ID_SOC));
7388 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
7389 CDP_RX_RING_STATS,
7390 QDF_STATS_VERBOSITY_LEVEL_LOW);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007391 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
7392 CDP_TXRX_PATH_STATS,
7393 QDF_STATS_VERBOSITY_LEVEL_LOW);
7394 wlan_hdd_display_netif_queue_history
7395 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
7396 qdf_dp_trace_dump_stats();
7397 }
7398 counter = 0;
7399 data_in_time_period = false;
7400 }
7401}
7402
Ravi Joshie2331e82015-07-01 18:18:54 -07007403/**
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007404 * hdd_clear_rps_cpu_mask - clear RPS CPU mask for interfaces
7405 * @hdd_ctx: pointer to struct hdd_context
7406 *
7407 * Return: none
7408 */
7409static void hdd_clear_rps_cpu_mask(struct hdd_context *hdd_ctx)
7410{
7411 struct hdd_adapter *adapter;
7412
7413 hdd_for_each_adapter(hdd_ctx, adapter)
7414 hdd_send_rps_disable_ind(adapter);
7415}
7416
7417/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07007418 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07007419 * @hdd_ctx - handle to hdd context
7420 * @tx_packets - transmit packet count
7421 * @rx_packets - receive packet count
7422 *
7423 * The function controls the bus bandwidth and dynamic control of
7424 * tcp delayed ack configuration
7425 *
7426 * Returns: None
7427 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007428
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007429static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07007430 const uint64_t tx_packets,
7431 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007432{
Mohit Khannaca4173b2017-09-12 21:52:19 -07007433 u64 total_pkts = tx_packets + rx_packets;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007434 uint64_t temp_tx = 0, avg_rx = 0;
7435 uint64_t no_rx_offload_pkts = 0, avg_no_rx_offload_pkts = 0;
7436 uint64_t rx_offload_pkts = 0, avg_rx_offload_pkts = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007437 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08007438 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08007439 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007440 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007441 uint16_t index = 0;
7442 bool vote_level_change = false;
7443 bool rx_level_change = false;
7444 bool tx_level_change = false;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007445 bool rxthread_high_tput_req = false;
Mohit Khannaf7562c32018-07-05 17:42:36 -07007446 bool dptrace_high_tput_req;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007447 if (total_pkts > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007448 next_vote_level = PLD_BUS_WIDTH_HIGH;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007449 else if (total_pkts > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007450 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007451 else if (total_pkts > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007452 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07007453 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07007454 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007455
Mohit Khannaf7562c32018-07-05 17:42:36 -07007456 dptrace_high_tput_req =
7457 next_vote_level > PLD_BUS_WIDTH_NONE ? true : false;
7458
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007459 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07007460 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
7461 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007462 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007463 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007464 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007465 if ((next_vote_level == PLD_BUS_WIDTH_LOW) ||
7466 (next_vote_level == PLD_BUS_WIDTH_NONE)) {
Nirav Shahffc6a092016-06-09 16:09:08 +05307467 if (hdd_ctx->hbw_requested) {
7468 pld_remove_pm_qos(hdd_ctx->parent_dev);
7469 hdd_ctx->hbw_requested = false;
7470 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007471 if (hdd_ctx->dynamic_rps)
7472 hdd_clear_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007473 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05307474 if (!hdd_ctx->hbw_requested) {
7475 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
7476 hdd_ctx->hbw_requested = true;
7477 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007478 if (hdd_ctx->dynamic_rps)
7479 hdd_set_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007480 }
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007481
Manjunathappa Prakashcb6df762018-05-29 18:54:58 -07007482 if (hdd_ctx->config->napi_cpu_affinity_mask)
7483 hdd_napi_apply_throughput_policy(hdd_ctx,
7484 tx_packets,
7485 rx_packets);
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007486
7487 if (rx_packets < hdd_ctx->config->busBandwidthLowThreshold)
7488 hdd_disable_rx_ol_for_low_tput(hdd_ctx, true);
7489 else
7490 hdd_disable_rx_ol_for_low_tput(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007491 }
Mohit Khannae71e2262015-11-10 09:37:24 -08007492
Mohit Khannaf7562c32018-07-05 17:42:36 -07007493 qdf_dp_trace_apply_tput_policy(dptrace_high_tput_req);
7494
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007495 /*
7496 * Includes tcp+udp, if perf core is required for tcp, then
7497 * perf core is also required for udp.
7498 */
7499 no_rx_offload_pkts = hdd_ctx->no_rx_offload_pkt_cnt;
7500 hdd_ctx->no_rx_offload_pkt_cnt = 0;
7501 rx_offload_pkts = rx_packets - no_rx_offload_pkts;
Mohit Khannae71e2262015-11-10 09:37:24 -08007502
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007503 avg_no_rx_offload_pkts = (no_rx_offload_pkts +
7504 hdd_ctx->prev_no_rx_offload_pkts) / 2;
7505 hdd_ctx->prev_no_rx_offload_pkts = no_rx_offload_pkts;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08007506
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007507 avg_rx_offload_pkts = (rx_offload_pkts +
7508 hdd_ctx->prev_rx_offload_pkts) / 2;
7509 hdd_ctx->prev_rx_offload_pkts = rx_offload_pkts;
7510
7511 avg_rx = avg_no_rx_offload_pkts + avg_rx_offload_pkts;
7512 /*
7513 * Takes care to set Rx_thread affinity for below case
7514 * 1)LRO/GRO not supported ROME case
7515 * 2)when rx_ol is disabled in cases like concurrency etc
7516 * 3)For UDP cases
7517 */
7518 if (avg_no_rx_offload_pkts >
7519 hdd_ctx->config->busBandwidthHighThreshold)
7520 rxthread_high_tput_req = true;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307521 else
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007522 rxthread_high_tput_req = false;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307523
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007524 if (cds_sched_handle_throughput_req(rxthread_high_tput_req))
7525 hdd_warn("Rx thread high_tput(%d) affinity request failed",
7526 rxthread_high_tput_req);
7527
7528 /* fine-tuning parameters for RX Flows */
7529 if (avg_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
Ravi Joshifed83572016-10-07 16:20:37 -07007530 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
7531 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
7532 next_rx_level = WLAN_SVC_TP_HIGH;
7533 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07007534 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07007535 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08007536 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007537 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007538
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007539 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007540 struct wlan_rx_tp_data rx_tp_data = {0};
7541
Ravi Joshie2331e82015-07-01 18:18:54 -07007542 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Jeff Johnsonb9feee42018-07-08 10:34:48 -07007543 next_rx_level, avg_rx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007544 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007545 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07007546 /* Send throughput indication only if it is enabled.
7547 * Disabling tcp_del_ack will revert the tcp stack behavior
7548 * to default delayed ack. Note that this will disable the
7549 * dynamic delayed ack mechanism across the system
7550 */
Manjunathappa Prakashbfd12762018-04-29 22:44:52 -07007551 if (hdd_ctx->en_tcp_delack_no_lro)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007552 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
7553
Mohit Khanna6272fb682017-04-13 09:34:36 -07007554 if (hdd_ctx->config->enable_tcp_adv_win_scale)
7555 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
7556
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007557 rx_tp_data.level = next_rx_level;
7558 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7559 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
7560 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007561 }
7562
Mohit Khannae71e2262015-11-10 09:37:24 -08007563 /* fine-tuning parameters for TX Flows */
7564 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
7565 hdd_ctx->prev_tx = tx_packets;
7566 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
7567 next_tx_level = WLAN_SVC_TP_HIGH;
7568 else
7569 next_tx_level = WLAN_SVC_TP_LOW;
7570
Prakash Manjunathappae73e3b52018-02-27 18:56:22 -08007571 if ((hdd_ctx->config->enable_tcp_limit_output) &&
7572 (hdd_ctx->cur_tx_level != next_tx_level)) {
Mohit Khannae71e2262015-11-10 09:37:24 -08007573 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
7574 next_tx_level, temp_tx);
7575 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007576 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05307577 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7578 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08007579 &next_tx_level,
7580 sizeof(next_tx_level));
7581 }
7582
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007583 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007584 if (vote_level_change || tx_level_change || rx_level_change) {
7585 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
7586 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
7587 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
7588 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
7589 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
7590 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
7591 hdd_ctx->hdd_txrx_hist_idx++;
7592 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
7593 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07007594
7595 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007596}
7597
7598#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307599static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007600{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007601 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307602 bus_bw_work);
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307603 struct hdd_adapter *adapter = NULL, *con_sap_adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307604 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05307605 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
7606 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007607 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307608 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007609 bool connected = false;
7610 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
7611
Dustin Brown35008ba2018-08-23 14:34:21 -07007612 hdd_enter();
7613
Prashanth Bhattaab004382016-10-11 16:08:11 -07007614 if (wlan_hdd_validate_context(hdd_ctx))
7615 return;
7616
Jeff Johnson214671b2017-10-30 19:45:23 -07007617 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08007618 goto restart_timer;
7619
Dustin Brown920397d2017-12-13 16:27:50 -08007620 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05307621 /*
7622 * Validate magic so we don't end up accessing
7623 * an invalid adapter.
7624 */
7625 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
7626 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007627
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007628 if ((adapter->device_mode == QDF_STA_MODE ||
7629 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007630 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
7631 != eConnectionState_Associated) {
7632
7633 continue;
7634 }
7635
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007636 if ((adapter->device_mode == QDF_SAP_MODE ||
7637 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07007638 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007639
7640 continue;
7641 }
7642
7643 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
7644 adapter->prev_tx_packets);
7645 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
7646 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307647
7648 if (adapter->device_mode == QDF_SAP_MODE ||
7649 adapter->device_mode == QDF_P2P_GO_MODE ||
7650 adapter->device_mode == QDF_IBSS_MODE) {
7651
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08007652 ret = cdp_get_intra_bss_fwd_pkts_count(
7653 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007654 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307655 &fwd_tx_packets, &fwd_rx_packets);
7656 if (ret == A_OK) {
7657 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
7658 fwd_tx_packets,
7659 adapter->prev_fwd_tx_packets);
7660 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
7661 fwd_tx_packets,
7662 adapter->prev_fwd_rx_packets);
7663 }
7664 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007665
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307666 if (adapter->device_mode == QDF_SAP_MODE)
7667 con_sap_adapter = adapter;
7668
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007669 total_rx += adapter->stats.rx_packets;
7670 total_tx += adapter->stats.tx_packets;
7671
7672 spin_lock_bh(&hdd_ctx->bus_bw_lock);
7673 adapter->prev_tx_packets = adapter->stats.tx_packets;
7674 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307675 adapter->prev_fwd_tx_packets = fwd_tx_packets;
7676 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007677 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
7678 connected = true;
7679 }
7680
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007681 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007682 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007683 return;
7684 }
7685
Yun Parka29974a2018-04-09 12:05:49 -07007686 /* add intra bss forwarded tx and rx packets */
7687 tx_packets += fwd_tx_packets_diff;
7688 rx_packets += fwd_rx_packets_diff;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007689
Yun Parka29974a2018-04-09 12:05:49 -07007690 if (ucfg_ipa_is_fw_wdi_activated(hdd_ctx->hdd_pdev)) {
7691 ucfg_ipa_uc_stat_query(hdd_ctx->hdd_pdev, &ipa_tx_packets,
7692 &ipa_rx_packets);
7693 tx_packets += (uint64_t)ipa_tx_packets;
7694 rx_packets += (uint64_t)ipa_rx_packets;
7695
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307696 if (con_sap_adapter) {
7697 con_sap_adapter->stats.tx_packets += ipa_tx_packets;
7698 con_sap_adapter->stats.rx_packets += ipa_rx_packets;
7699 }
7700
Yun Parka29974a2018-04-09 12:05:49 -07007701 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, tx_packets, rx_packets);
7702 ucfg_ipa_uc_stat_request(hdd_ctx->hdd_pdev, 2);
7703 }
7704
7705 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007706
Jingxiang Gec64e1932017-08-22 14:38:59 +08007707restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08007708 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08007709 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08007710 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05307711 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08007712 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08007713 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07007714
7715 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007716}
Prashanth Bhattaab004382016-10-11 16:08:11 -07007717
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307718/**
7719 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
7720 * @arg: Argument of timer function
7721 *
7722 * Schedule a workqueue in this function where all the processing is done.
7723 *
7724 * Return: None.
7725 */
7726static void __hdd_bus_bw_cbk(void *arg)
7727{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007728 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307729
7730 if (wlan_hdd_validate_context(hdd_ctx))
7731 return;
7732
7733 schedule_work(&hdd_ctx->bus_bw_work);
7734}
7735
7736/**
7737 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
7738 * @arg: Argument of timer function
7739 *
7740 * Return: None.
7741 */
7742static void hdd_bus_bw_cbk(void *arg)
7743{
7744 cds_ssr_protect(__func__);
7745 __hdd_bus_bw_cbk(arg);
7746 cds_ssr_unprotect(__func__);
7747}
7748
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007749int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007750{
Dustin Brown35008ba2018-08-23 14:34:21 -07007751 hdd_enter();
7752
Prashanth Bhattaab004382016-10-11 16:08:11 -07007753 spin_lock_init(&hdd_ctx->bus_bw_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07007754 INIT_WORK(&hdd_ctx->bus_bw_work, hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08007755 hdd_ctx->bus_bw_timer_running = false;
7756 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07007757 qdf_timer_init(NULL, &hdd_ctx->bus_bw_timer, hdd_bus_bw_cbk,
7758 (void *)hdd_ctx, QDF_TIMER_TYPE_SW);
7759
7760 hdd_exit();
Prashanth Bhattaab004382016-10-11 16:08:11 -07007761
7762 return 0;
7763}
7764
Dustin Brown86d196b2018-08-02 11:51:49 -07007765void hdd_bus_bandwidth_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007766{
Dustin Brown35008ba2018-08-23 14:34:21 -07007767 hdd_enter();
Prashanth Bhattaab004382016-10-11 16:08:11 -07007768
Rajeev Kumarc27efb62018-08-31 14:21:22 -07007769 QDF_BUG(!hdd_ctx->bus_bw_timer_running);
Dustin Brown35008ba2018-08-23 14:34:21 -07007770
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307771 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08007772 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07007773
7774 hdd_exit();
Prashanth Bhattaab004382016-10-11 16:08:11 -07007775}
Lin Baic5c06882017-09-21 13:58:43 +08007776
Dustin Brown35008ba2018-08-23 14:34:21 -07007777#endif /* MSM_PLATFORM */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007778
7779/**
Nirav Shahed34b212016-04-25 10:59:16 +05307780 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
7781 * @hdd_ctx: hdd context
7782 *
7783 * Return: 0 for success or error code
7784 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007785static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307786{
7787 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
7788 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
7789 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007790 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05307791 return -ENOMEM;
7792 }
7793 return 0;
7794}
7795
7796/**
7797 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
7798 * @hdd_ctx: hdd context
7799 *
7800 * Return: none
7801 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007802void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307803{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307804 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
7805 return;
7806
7807 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
7808 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05307809}
7810
Nirav Shahda008342016-05-17 18:50:40 +05307811static uint8_t *convert_level_to_string(uint32_t level)
7812{
7813 switch (level) {
7814 /* initialize the wlan sub system */
7815 case WLAN_SVC_TP_NONE:
7816 return "NONE";
7817 case WLAN_SVC_TP_LOW:
7818 return "LOW";
7819 case WLAN_SVC_TP_MEDIUM:
7820 return "MED";
7821 case WLAN_SVC_TP_HIGH:
7822 return "HIGH";
7823 default:
7824 return "INVAL";
7825 }
7826}
7827
Nirav Shahed34b212016-04-25 10:59:16 +05307828
7829/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007830 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
7831 * @hdd_ctx: hdd context
7832 *
7833 * Return: none
7834 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007835void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007836{
7837 int i;
7838
7839#ifdef MSM_PLATFORM
Nirav Shahe6194ac2018-07-13 11:04:41 +05307840 hdd_nofl_info("BW compute Interval: %dms",
7841 hdd_ctx->config->busBandwidthComputeInterval);
7842 hdd_nofl_info("BW High TH: %d BW Med TH: %d BW Low TH: %d",
7843 hdd_ctx->config->busBandwidthHighThreshold,
7844 hdd_ctx->config->busBandwidthMediumThreshold,
7845 hdd_ctx->config->busBandwidthLowThreshold);
7846 hdd_nofl_info("Enable TCP DEL ACK: %d",
7847 hdd_ctx->en_tcp_delack_no_lro);
7848 hdd_nofl_info("TCP DEL High TH: %d TCP DEL Low TH: %d",
7849 hdd_ctx->config->tcpDelackThresholdHigh,
7850 hdd_ctx->config->tcpDelackThresholdLow);
7851 hdd_nofl_info("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
7852 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007853#endif
7854
Nirav Shahe6194ac2018-07-13 11:04:41 +05307855 hdd_nofl_info("Total entries: %d Current index: %d",
7856 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
Nirav Shahda008342016-05-17 18:50:40 +05307857
Nirav Shahe6194ac2018-07-13 11:04:41 +05307858 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 -08007859
7860 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007861 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007862 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Nirav Shahe6194ac2018-07-13 11:04:41 +05307863 hdd_nofl_info("[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
7864 i, hdd_ctx->hdd_txrx_hist[i].qtime,
7865 hdd_ctx->hdd_txrx_hist[i].interval_rx,
7866 hdd_ctx->hdd_txrx_hist[i].interval_tx,
7867 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007868 hdd_ctx->hdd_txrx_hist[i].
7869 next_vote_level),
Nirav Shahe6194ac2018-07-13 11:04:41 +05307870 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007871 hdd_ctx->hdd_txrx_hist[i].
7872 next_rx_level),
Nirav Shahe6194ac2018-07-13 11:04:41 +05307873 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007874 hdd_ctx->hdd_txrx_hist[i].
7875 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007876 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007877}
7878
7879/**
7880 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
7881 * @hdd_ctx: hdd context
7882 *
7883 * Return: none
7884 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007885void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007886{
7887 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05307888 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
7889 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007890}
7891
Mohit Khannaca4173b2017-09-12 21:52:19 -07007892/* length of the netif queue log needed per adapter */
7893#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
7894
7895/**
7896 *
7897 * hdd_display_netif_queue_history_compact() - display compact netifq history
7898 * @hdd_ctx: hdd context
7899 *
7900 * Return: none
7901 */
7902static void
7903hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
7904{
7905 int adapter_num = 0;
7906 int i;
7907 int bytes_written;
7908 u32 tbytes;
7909 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007910 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08007911 char *comb_log_str;
7912 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007913 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007914
Dustin Brownbee82832018-07-23 10:10:51 -07007915 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * CSR_ROAM_SESSION_MAX) + 1;
jiadbdefb252018-01-03 14:27:06 +08007916 comb_log_str = qdf_mem_malloc(comb_log_str_size);
7917 if (!comb_log_str) {
7918 hdd_err("failed to alloc comb_log_str");
7919 return;
7920 }
7921
Mohit Khannaca4173b2017-09-12 21:52:19 -07007922 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007923
Dustin Brown920397d2017-12-13 16:27:50 -08007924 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007925 curr_time = qdf_system_ticks();
7926 total = curr_time - adapter->start_time;
7927 delta = curr_time - adapter->last_time;
7928
7929 if (adapter->pause_map) {
7930 pause = adapter->total_pause_time + delta;
7931 unpause = adapter->total_unpause_time;
7932 } else {
7933 unpause = adapter->total_unpause_time + delta;
7934 pause = adapter->total_pause_time;
7935 }
7936
7937 tbytes = 0;
7938 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7939 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7940 if (adapter->queue_oper_stats[i].pause_count == 0)
7941 continue;
7942 tbytes +=
7943 snprintf(
7944 &temp_str[tbytes],
7945 (tbytes >= sizeof(temp_str) ?
7946 0 : sizeof(temp_str) - tbytes),
7947 "%d(%d,%d) ",
7948 i,
7949 adapter->queue_oper_stats[i].
7950 pause_count,
7951 adapter->queue_oper_stats[i].
7952 unpause_count);
7953 }
7954 if (tbytes >= sizeof(temp_str))
7955 hdd_warn("log truncated");
7956
7957 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08007958 bytes_written >= comb_log_str_size ? 0 :
7959 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007960 "[%d %d] (%d) %u/%ums %s|",
7961 adapter->session_id, adapter->device_mode,
7962 adapter->pause_map,
7963 qdf_system_ticks_to_msecs(pause),
7964 qdf_system_ticks_to_msecs(total),
7965 temp_str);
7966
Mohit Khannaca4173b2017-09-12 21:52:19 -07007967 adapter_num++;
7968 }
7969
7970 /* using QDF_TRACE to avoid printing function name */
7971 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
7972 "STATS |%s", comb_log_str);
7973
jiadbdefb252018-01-03 14:27:06 +08007974 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007975 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08007976
7977 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007978}
7979
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007980/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007981 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07007982 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007983 *
7984 * Return: none
7985 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007986void
7987wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
7988 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007989{
7990
Jeff Johnson9d295242017-08-29 14:39:48 -07007991 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007992 int i;
Nirav Shahda008342016-05-17 18:50:40 +05307993 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007994
Mohit Khannaca4173b2017-09-12 21:52:19 -07007995 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
7996 hdd_display_netif_queue_history_compact(hdd_ctx);
7997 return;
7998 }
7999
Dustin Brown920397d2017-12-13 16:27:50 -08008000 hdd_for_each_adapter(hdd_ctx, adapter) {
Nirav Shahe6194ac2018-07-13 11:04:41 +05308001 hdd_nofl_info("Netif queue operation statistics:");
8002 hdd_nofl_info("Session_id %d device mode %d",
8003 adapter->session_id, adapter->device_mode);
8004 hdd_nofl_info("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05308005 curr_time = qdf_system_ticks();
8006 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05308007 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05308008 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05308009 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05308010 unpause = adapter->total_unpause_time;
8011 } else {
Nirav Shahda008342016-05-17 18:50:40 +05308012 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05308013 pause = adapter->total_pause_time;
8014 }
Nirav Shahe6194ac2018-07-13 11:04:41 +05308015 hdd_nofl_info("Total: %ums Pause: %ums Unpause: %ums",
8016 qdf_system_ticks_to_msecs(total),
8017 qdf_system_ticks_to_msecs(pause),
8018 qdf_system_ticks_to_msecs(unpause));
8019 hdd_nofl_info("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008020
Nirav Shahda008342016-05-17 18:50:40 +05308021 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
8022 qdf_time_t pause_delta = 0;
8023
8024 if (adapter->pause_map & (1 << i))
8025 pause_delta = delta;
8026
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008027 /* using hdd_log to avoid printing function name */
Nirav Shahe6194ac2018-07-13 11:04:41 +05308028 hdd_nofl_info("%s: %d: %d: %ums",
8029 hdd_reason_type_to_string(i),
8030 adapter->queue_oper_stats[i].pause_count,
8031 adapter->queue_oper_stats[i].
8032 unpause_count,
8033 qdf_system_ticks_to_msecs(
8034 adapter->queue_oper_stats[i].
8035 total_pause_time + pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008036 }
8037
Nirav Shahe6194ac2018-07-13 11:04:41 +05308038 hdd_nofl_info("Netif queue operation history:");
8039 hdd_nofl_info("Total entries: %d current index %d",
8040 WLAN_HDD_MAX_HISTORY_ENTRY,
8041 adapter->history_index);
Nirav Shahda008342016-05-17 18:50:40 +05308042
Nirav Shahe6194ac2018-07-13 11:04:41 +05308043 hdd_nofl_info("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008044
8045 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008046 /* using hdd_log to avoid printing function name */
8047 if (adapter->queue_oper_history[i].time == 0)
8048 continue;
Nirav Shahe6194ac2018-07-13 11:04:41 +05308049 hdd_nofl_info("%d: %u: %s: %s: %x",
8050 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008051 adapter->queue_oper_history[i].time),
Nirav Shahe6194ac2018-07-13 11:04:41 +05308052 hdd_action_type_to_string(
8053 adapter->queue_oper_history[i].
8054 netif_action),
8055 hdd_reason_type_to_string(
8056 adapter->queue_oper_history[i].
8057 netif_reason),
8058 adapter->queue_oper_history[i].pause_map);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008059 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008060 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008061}
8062
8063/**
8064 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
8065 * @hdd_ctx: hdd context
8066 *
8067 * Return: none
8068 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008069void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008070{
Jeff Johnson9d295242017-08-29 14:39:48 -07008071 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008072
Dustin Brown920397d2017-12-13 16:27:50 -08008073 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308074 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008075 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308076 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008077 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05308078 adapter->history_index = 0;
8079 adapter->start_time = adapter->last_time = qdf_system_ticks();
8080 adapter->total_pause_time = 0;
8081 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008082 }
8083}
8084
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008085#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
8086/**
8087 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
8088 * @hdd_ctx: hdd global context
8089 *
8090 * Return: none
8091 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008092static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008093{
8094 uint8_t i;
8095
8096 mutex_init(&hdd_ctx->op_ctx.op_lock);
8097 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
8098 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
8099 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
8100 }
8101}
8102#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008103static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008104{
8105}
8106#endif
8107
Yingying Tang95409972016-10-20 15:16:15 +08008108#ifdef WLAN_FEATURE_WOW_PULSE
8109/**
8110 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008111 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08008112 * @enable: enable or disable this behaviour
8113 *
8114 * Return: int
8115 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008116static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008117{
8118 struct hdd_config *pcfg_ini = phddctx->config;
8119 struct wow_pulse_mode wow_pulse_set_info;
8120 QDF_STATUS status;
8121
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008122 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08008123
8124 if (false == phddctx->config->wow_pulse_support)
8125 return 0;
8126
8127 /* prepare the request to send to SME */
8128 if (enable == true) {
8129 wow_pulse_set_info.wow_pulse_enable = true;
8130 wow_pulse_set_info.wow_pulse_pin =
8131 pcfg_ini->wow_pulse_pin;
8132 wow_pulse_set_info.wow_pulse_interval_low =
8133 pcfg_ini->wow_pulse_interval_low;
8134 wow_pulse_set_info.wow_pulse_interval_high =
8135 pcfg_ini->wow_pulse_interval_high;
8136 } else {
8137 wow_pulse_set_info.wow_pulse_enable = false;
8138 wow_pulse_set_info.wow_pulse_pin = 0;
8139 wow_pulse_set_info.wow_pulse_interval_low = 0;
8140 wow_pulse_set_info.wow_pulse_interval_high = 0;
8141 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008142 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08008143 wow_pulse_set_info.wow_pulse_enable,
8144 wow_pulse_set_info.wow_pulse_pin,
8145 wow_pulse_set_info.wow_pulse_interval_low,
8146 wow_pulse_set_info.wow_pulse_interval_high);
8147
8148 status = sme_set_wow_pulse(&wow_pulse_set_info);
8149 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008150 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08008151 return -EIO;
8152 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008153 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08008154 return 0;
8155}
8156#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008157static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008158{
8159 return 0;
8160}
8161#endif
8162
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008163#ifdef WLAN_FEATURE_FASTPATH
8164/**
8165 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
8166 * @hdd_cfg: hdd config
8167 * @context: lower layer context
8168 *
8169 * Return: none
8170 */
Arun Khandavallifae92942016-08-01 13:31:08 +05308171void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008172 void *context)
8173{
8174 if (hdd_cfg->fastpath_enable)
8175 hif_enable_fastpath(context);
8176}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008177#endif
8178
Yuanyuan Liu13738502016-04-06 17:41:37 -07008179#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008180/**
8181 * hdd_set_thermal_level_cb() - set thermal level callback function
Jeff Johnson0e963082018-07-04 19:39:20 -07008182 * @hdd_handle: opaque handle for the hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008183 * @level: thermal level
8184 *
8185 * Change IPA data path to SW path when the thermal throttle level greater
8186 * than 0, and restore the original data path when throttle level is 0
8187 *
8188 * Return: none
8189 */
Jeff Johnson0e963082018-07-04 19:39:20 -07008190static void hdd_set_thermal_level_cb(hdd_handle_t hdd_handle, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008191{
Jeff Johnson0e963082018-07-04 19:39:20 -07008192 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008193
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008194 /* Change IPA to SW path when throttle level greater than 0 */
8195 if (level > THROTTLE_LEVEL_0)
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308196 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008197 else
8198 /* restore original concurrency mode */
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308199 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, hdd_ctx->mcc_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008200}
8201
8202/**
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308203 * hdd_get_safe_channel() - Get safe channel from current regulatory
8204 * @hdd_ctx: pointer to hdd context
8205 * @adapter: pointer to softap adapter
8206 *
8207 * This function is used to get safe channel from current regulatory valid
8208 * channels to restart SAP if failed to get safe channel from PCL.
8209 *
8210 * Return: Channel number to restart SAP in case of success. In case of any
8211 * failure, the channel number returned is zero.
8212 */
8213static uint8_t
8214hdd_get_safe_channel(struct hdd_context *hdd_ctx,
8215 struct hdd_adapter *adapter)
8216{
8217 struct sir_pcl_list pcl = {0};
8218 uint32_t i, j;
8219 bool found = false;
8220 int ret;
8221
8222 /* Try for safe channel from all valid channel */
8223 pcl.pcl_len = MAX_NUM_CHAN;
8224 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
8225 &pcl.pcl_len);
8226 if (ret) {
8227 hdd_err("error %d in getting valid channel list", ret);
8228 return INVALID_CHANNEL_ID;
8229 }
8230
8231 for (i = 0; i < pcl.pcl_len; i++) {
8232 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
8233 found = false;
8234 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
8235 if (pcl.pcl_list[i] ==
8236 hdd_ctx->unsafe_channel_list[j]) {
8237 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
8238 found = true;
8239 break;
8240 }
8241 }
8242
8243 if (found)
8244 continue;
8245
8246 if ((pcl.pcl_list[i] >=
8247 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
8248 (pcl.pcl_list[i] <=
8249 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
8250 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
8251 return pcl.pcl_list[i];
8252 }
8253 }
8254
8255 return INVALID_CHANNEL_ID;
8256}
8257
8258#else
8259/**
8260 * hdd_set_thermal_level_cb() - set thermal level callback function
8261 * @hdd_handle: opaque handle for the hdd context
8262 * @level: thermal level
8263 *
8264 * Change IPA data path to SW path when the thermal throttle level greater
8265 * than 0, and restore the original data path when throttle level is 0
8266 *
8267 * Return: none
8268 */
8269static void hdd_set_thermal_level_cb(hdd_handle_t hdd_handle, u_int8_t level)
8270{
8271}
8272
8273/**
8274 * hdd_get_safe_channel() - Get safe channel from current regulatory
8275 * @hdd_ctx: pointer to hdd context
8276 * @adapter: pointer to softap adapter
8277 *
8278 * This function is used to get safe channel from current regulatory valid
8279 * channels to restart SAP if failed to get safe channel from PCL.
8280 *
8281 * Return: Channel number to restart SAP in case of success. In case of any
8282 * failure, the channel number returned is zero.
8283 */
8284static uint8_t
8285hdd_get_safe_channel(struct hdd_context *hdd_ctx,
8286 struct hdd_adapter *adapter)
8287{
8288 return 0;
8289}
8290#endif
8291
8292/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308293 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
8294 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05308295 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008296 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308297 * Get a safe channel to restart SAP. PCL already takes into account the
8298 * unsafe channels. So, the PCL is validated with the ACS range to provide
8299 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008300 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308301 * Return: Channel number to restart SAP in case of success. In case of any
8302 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008303 */
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308304static uint8_t
8305hdd_get_safe_channel_from_pcl_and_acs_range(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008306{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308307 struct sir_pcl_list pcl;
8308 QDF_STATUS status;
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308309 uint32_t i;
Jeff Johnson16528362018-06-14 12:34:16 -07008310 mac_handle_t mac_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008311 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008312
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308313 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8314 if (!hdd_ctx) {
8315 hdd_err("invalid HDD context");
8316 return INVALID_CHANNEL_ID;
8317 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008318
Jeff Johnson16528362018-06-14 12:34:16 -07008319 mac_handle = hdd_ctx->mac_handle;
8320 if (!mac_handle) {
8321 hdd_err("invalid MAC handle");
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05308322 return INVALID_CHANNEL_ID;
8323 }
8324
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008325 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
8326 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08008327 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
8328 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308329 if (QDF_IS_STATUS_ERROR(status)) {
8330 hdd_err("Get PCL failed");
8331 return INVALID_CHANNEL_ID;
8332 }
8333
Frank Liudc2cefb2017-06-21 15:38:18 +08008334 /*
8335 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
8336 * channel is unsafe channel, the pcl may be empty, instead of return,
8337 * try to choose a safe channel from acs range.
8338 */
8339 if (!pcl.pcl_len)
8340 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308341
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008342 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07008343 adapter->session.ap.sap_config.acs_cfg.start_ch,
8344 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308345
8346 /* PCL already takes unsafe channel into account */
8347 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008348 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308349 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008350 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308351 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008352 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008353 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308354 return pcl.pcl_list[i];
8355 }
8356 }
8357
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008358 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308359
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308360 return hdd_get_safe_channel(hdd_ctx, adapter);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308361}
8362
8363/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008364 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308365 * @adapter: AP adapter
8366 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08008367 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308368 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008369 * Moves the SAP interface by invoking the function which
8370 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308371 *
8372 * Return: None
8373 */
Min Liu2fef5792018-01-19 17:59:42 +08008374void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
8375 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308376{
Jeff Johnson87251032017-08-29 13:31:11 -07008377 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008378 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07008379 mac_handle_t mac_handle;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308380
8381 if (!adapter) {
8382 hdd_err("invalid adapter");
8383 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008384 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308385
8386 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
8387
Jeff Johnson16528362018-06-14 12:34:16 -07008388 mac_handle = hdd_adapter_get_mac_handle(adapter);
8389 if (!mac_handle) {
8390 hdd_err("invalid MAC handle");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308391 return;
8392 }
8393
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008394 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8395
Jeff Johnson91df29d2017-10-27 19:29:50 -07008396 hdd_ap_ctx->sap_config.channel = channel;
Himanshu Agarwalf5c5b102018-05-22 20:13:57 +05308397 hdd_ap_ctx->sap_config.ch_params.ch_width = CH_WIDTH_MAX;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308398
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008399 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07008400 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308401
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07008402 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07008403 hdd_ap_ctx->sap_config.channel,
8404 hdd_ap_ctx->sap_config.sec_ch,
8405 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308406
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008407 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07008408 adapter->session_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08008409 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008410}
Kapil Gupta8878ad92017-02-13 11:56:04 +05308411
Jeff Johnson9d295242017-08-29 14:39:48 -07008412int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05308413{
8414 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308415 int status;
8416 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308417
8418 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8419
8420 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07008421 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05308422 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07008423 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308424 }
8425 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07008426 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308427 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308428 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07008429 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308430 WLAN_VENDOR_ACS_WAIT_TIME);
8431 if (qdf_status != QDF_STATUS_SUCCESS) {
8432 hdd_err("failed to start external acs timer");
8433 return -ENOSPC;
8434 }
8435 /* Update config to application */
8436 status = hdd_cfg80211_update_acs_config(adapter, reason);
Dustin Brown5e89ef82018-03-14 11:50:23 -07008437 hdd_info("Updated ACS config to nl with reason %d", reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308438
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308439 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308440}
8441
Nirav Shaheb017be2018-02-15 11:20:58 +05308442#if defined(FEATURE_WLAN_CH_AVOID)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308443/**
8444 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
8445 * @hdd_ctx: hdd context pointer
8446 *
8447 * hdd_unsafe_channel_restart_sap check all unsafe channel list
8448 * and if ACS is enabled, driver will ask userspace to restart the
8449 * sap. User space on LTE coex indication restart driver.
8450 *
8451 * Return - none
8452 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008453void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308454{
Dustin Brown920397d2017-12-13 16:27:50 -08008455 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308456 uint32_t i;
8457 bool found = false;
8458 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008459
Dustin Brown920397d2017-12-13 16:27:50 -08008460 hdd_for_each_adapter(hdd_ctxt, adapter) {
8461 if (!(adapter->device_mode == QDF_SAP_MODE &&
8462 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008463 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08008464 adapter->device_mode,
8465 adapter->session.ap.sap_config.
8466 acs_cfg.acs_mode);
8467 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308468 }
8469
8470 found = false;
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008471 /*
8472 * If STA+SAP is doing SCC & g_sta_sap_scc_on_lte_coex_chan
8473 * is set, no need to move SAP.
8474 */
8475 if (policy_mgr_is_sta_sap_scc(hdd_ctxt->hdd_psoc,
8476 adapter->session.ap.operating_channel) &&
8477 hdd_ctxt->config->sta_sap_scc_on_lte_coex_chan)
8478 hdd_debug("SAP is allowed on SCC channel, no need to move SAP");
8479 else {
8480 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
8481 if (adapter->session.ap.operating_channel ==
8482 hdd_ctxt->unsafe_channel_list[i]) {
8483 found = true;
8484 hdd_debug("operating ch:%d is unsafe",
8485 adapter->session.ap.operating_channel);
8486 break;
8487 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308488 }
8489 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308490 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008491 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08008492 adapter->session.ap.operating_channel);
8493 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308494 }
8495
Kapil Gupta8878ad92017-02-13 11:56:04 +05308496 if (hdd_ctxt->config->vendor_acs_support &&
8497 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08008498 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05308499 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08008500 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308501 } else
8502 restart_chan =
8503 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08008504 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308505 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008506 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308507 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008508 /*
8509 * SAP restart due to unsafe channel. While
8510 * restarting the SAP, make sure to clear
8511 * acs_channel, channel to reset to
8512 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308513 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008514 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308515 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008516 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308517 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
8518 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04008519 hdd_debug("driver to start sap: %d",
8520 hdd_ctxt->config->sap_internal_restart);
8521 if (hdd_ctxt->config->sap_internal_restart)
Min Liu2fef5792018-01-19 17:59:42 +08008522 hdd_switch_sap_channel(adapter, restart_chan,
8523 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04008524 else
8525 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308526 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308527 }
8528}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05308529
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008530/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008531 * hdd_init_channel_avoidance() - Initialize channel avoidance
8532 * @hdd_ctx: HDD global context
8533 *
8534 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07008535 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008536 * down to the lower layers. Then subscribe to subsequent channel
8537 * avoidance events.
8538 *
8539 * Return: None
8540 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008541static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008542{
8543 uint16_t unsafe_channel_count;
8544 int index;
8545
Yuanyuan Liu13738502016-04-06 17:41:37 -07008546 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
8547 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008548 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08008549 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008550
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008551 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008552 hdd_ctx->unsafe_channel_count);
8553
Anurag Chouhan6d760662016-02-20 16:05:43 +05308554 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08008555 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008556
8557 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008558 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008559 hdd_ctx->unsafe_channel_list[index]);
8560
8561 }
8562
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008563}
Dustin Brown676a2322017-08-15 13:16:13 -07008564
Jeff Johnson9d295242017-08-29 14:39:48 -07008565static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008566 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008567{
8568 uint8_t restart_chan;
8569
8570 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
8571 if (!restart_chan) {
8572 hdd_alert("fail to restart SAP");
8573 return;
8574 }
8575
8576 /* SAP restart due to unsafe channel. While restarting
8577 * the SAP, make sure to clear acs_channel, channel to
8578 * reset to 0. Otherwise these settings will override
8579 * the ACS while restart.
8580 */
8581 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07008582
8583 hdd_debug("sending coex indication");
8584
8585 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
8586 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08008587 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07008588}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008589
8590int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
8591 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
8592{
8593 uint32_t size;
8594 uint16_t *unsafe_list;
8595 uint16_t chan_count;
8596
8597 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
8598 return -EINVAL;
8599
8600 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
8601 NUM_CHANNELS);
8602 if (chan_count) {
8603 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
8604 unsafe_list = qdf_mem_malloc(size);
8605 if (!unsafe_list) {
8606 hdd_err("No memory for unsafe chan list size%d",
8607 size);
8608 return -ENOMEM;
8609 }
8610 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
8611 } else {
8612 unsafe_list = NULL;
8613 }
8614
8615 *local_unsafe_list = unsafe_list;
8616 *local_unsafe_list_count = chan_count;
8617
8618 return 0;
8619}
8620
8621bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
8622 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
8623{
8624 int i, j;
8625
8626 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
8627 return true;
8628 if (local_unsafe_list_count == 0)
8629 return false;
8630 for (i = 0; i < local_unsafe_list_count; i++) {
8631 for (j = 0; j < local_unsafe_list_count; j++)
8632 if (local_unsafe_list[i] ==
8633 hdd_ctx->unsafe_channel_list[j])
8634 break;
8635 if (j >= local_unsafe_list_count)
8636 break;
8637 }
8638 if (i >= local_unsafe_list_count) {
8639 hdd_info("unsafe chan list same");
8640 return false;
8641 }
8642
8643 return true;
8644}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008645#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008646static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008647{
8648}
Dustin Brown676a2322017-08-15 13:16:13 -07008649
Jeff Johnson9d295242017-08-29 14:39:48 -07008650static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008651 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008652{
8653 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
8654}
Yuanyuan Liu13738502016-04-06 17:41:37 -07008655#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008656
8657/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08008658 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
8659 * user space
8660 * @frame_ind: Management frame data to be informed.
8661 *
8662 * This function is used to indicate management frame to
8663 * user space
8664 *
8665 * Return: None
8666 *
8667 */
8668void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
8669{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008670 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07008671 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008672 int i;
Pragaspathi Thilagaraj28ffc042018-07-18 15:19:36 +05308673 struct ieee80211_mgmt *mgmt =
8674 (struct ieee80211_mgmt *)frame_ind->frameBuf;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008675
Dustin Browne7e71d32018-05-11 16:00:08 -07008676 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
8677 if (wlan_hdd_validate_context(hdd_ctx))
Rajeev Kumard004abc2016-02-17 12:09:56 -08008678 return;
8679
Pragaspathi Thilagaraj28ffc042018-07-18 15:19:36 +05308680 if (frame_ind->frame_len < ieee80211_hdrlen(mgmt->frame_control)) {
8681 hdd_err(" Invalid frame length");
8682 return;
8683 }
8684
Rajeev Kumard004abc2016-02-17 12:09:56 -08008685 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
8686 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
8687 adapter =
8688 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
8689 if (adapter)
8690 break;
8691 }
Wu Gaoa0230a62018-01-04 20:56:57 +08008692 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
8693 hdd_for_each_adapter(hdd_ctx, adapter) {
8694 if ((NULL != adapter) &&
8695 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
8696 __hdd_indicate_mgmt_frame(adapter,
8697 frame_ind->frame_len,
8698 frame_ind->frameBuf,
8699 frame_ind->frameType,
8700 frame_ind->rxChan,
8701 frame_ind->rxRssi);
8702 }
8703 }
8704 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008705 } else {
8706 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
8707 frame_ind->sessionId);
8708 }
8709
8710 if ((NULL != adapter) &&
8711 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
8712 __hdd_indicate_mgmt_frame(adapter,
8713 frame_ind->frame_len,
8714 frame_ind->frameBuf,
8715 frame_ind->frameType,
8716 frame_ind->rxChan,
8717 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008718}
8719
Kapil Gupta8878ad92017-02-13 11:56:04 +05308720void hdd_acs_response_timeout_handler(void *context)
8721{
8722 struct hdd_external_acs_timer_context *timer_context =
8723 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07008724 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008725 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308726 uint8_t reason;
8727
Dustin Brown491d54b2018-03-14 12:39:11 -07008728 hdd_enter();
Kapil Gupta8878ad92017-02-13 11:56:04 +05308729 if (!timer_context) {
8730 hdd_err("invlaid timer context");
8731 return;
8732 }
8733 adapter = timer_context->adapter;
8734 reason = timer_context->reason;
8735
8736
8737 if ((!adapter) ||
8738 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
8739 hdd_err("invalid adapter or adapter has invalid magic");
8740 return;
8741 }
8742 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8743 if (wlan_hdd_validate_context(hdd_ctx))
8744 return;
8745
8746 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
8747 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8748 else
8749 return;
8750
8751 hdd_err("ACS timeout happened for %s reason %d",
8752 adapter->dev->name, reason);
Jeff Johnson16528362018-06-14 12:34:16 -07008753
Kapil Gupta8878ad92017-02-13 11:56:04 +05308754 switch (reason) {
8755 /* SAP init case */
8756 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
8757 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
8758 false);
8759 wlan_hdd_cfg80211_start_acs(adapter);
8760 break;
8761 /* DFS detected on current channel */
8762 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
8763 wlan_sap_update_next_channel(
8764 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
Jeff Johnson16528362018-06-14 12:34:16 -07008765 sme_update_new_channel_event(hdd_ctx->mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07008766 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308767 break;
8768 /* LTE coex event on current channel */
8769 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
8770 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
8771 break;
8772 default:
8773 hdd_info("invalid reason for timer invoke");
8774
8775 }
8776}
8777
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008778/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008779 * hdd_override_ini_config - Override INI config
8780 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008781 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008782 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008783 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008784 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008785 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008786static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008787{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008788
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008789 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
8790 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008791 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008792 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008793 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008794 if (0 == enable_11d || 1 == enable_11d) {
8795 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008796 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008797 }
Leo Chang11545d62016-10-17 14:53:50 -07008798
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308799 if (!ucfg_ipa_is_present()) {
Leo Chang11545d62016-10-17 14:53:50 -07008800 hdd_ctx->config->IpaConfig = 0;
Jingxiang Ge7a040dc2018-02-02 11:07:59 +08008801 hdd_debug("IpaConfig override to %d",
8802 hdd_ctx->config->IpaConfig);
8803 }
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05308804
8805 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
8806 !hdd_ctx->config->enable_bcast_probe_rsp) {
8807 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
8808 hdd_ctx->config->rssi_assoc_reject_enabled,
8809 hdd_ctx->config->enable_bcast_probe_rsp);
8810 hdd_ctx->config->oce_sta_enabled = 0;
8811 }
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +05308812
8813 if (hdd_ctx->config->action_oui_enable && !ucfg_action_oui_enabled()) {
8814 hdd_ctx->config->action_oui_enable = 0;
8815 hdd_err("Ignore ini: %s, since no action_oui component",
8816 CFG_ENABLE_ACTION_OUI);
8817 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008818}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008819
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008820/**
8821 * hdd_set_trace_level_for_each - Set trace level for each INI config
8822 * @hdd_ctx - HDD context
8823 *
8824 * Set trace level for each module based on INI config.
8825 *
8826 * Return: None
8827 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008828static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008829{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308830 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
8831 hdd_ctx->config->qdf_trace_enable_wdi);
8832 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
8833 hdd_ctx->config->qdf_trace_enable_hdd);
8834 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
8835 hdd_ctx->config->qdf_trace_enable_sme);
8836 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
8837 hdd_ctx->config->qdf_trace_enable_pe);
8838 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
8839 hdd_ctx->config->qdf_trace_enable_wma);
8840 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
8841 hdd_ctx->config->qdf_trace_enable_sys);
8842 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
8843 hdd_ctx->config->qdf_trace_enable_qdf);
8844 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
8845 hdd_ctx->config->qdf_trace_enable_sap);
8846 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
8847 hdd_ctx->config->qdf_trace_enable_hdd_sap);
8848 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
8849 hdd_ctx->config->qdf_trace_enable_bmi);
8850 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
8851 hdd_ctx->config->qdf_trace_enable_cfg);
8852 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
8853 hdd_ctx->config->qdf_trace_enable_epping);
8854 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
8855 hdd_ctx->config->qdf_trace_enable_qdf_devices);
8856 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07008857 hdd_ctx->config->qdf_trace_enable_txrx);
8858 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
8859 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308860 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
8861 hdd_ctx->config->qdf_trace_enable_htc);
8862 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
8863 hdd_ctx->config->qdf_trace_enable_hif);
8864 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
8865 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
8866 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
8867 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08008868 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
8869 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07008870 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
8871 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008872 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
8873 hdd_ctx->config->qdf_trace_enable_regulatory);
Naveen Rawat3cb779e2018-02-16 16:36:10 -08008874 hdd_qdf_trace_enable(QDF_MODULE_ID_CP_STATS,
8875 hdd_ctx->config->qdf_trace_enable_cp_stats);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05308876 hdd_qdf_trace_enable(QDF_MODULE_ID_MLME, 0xffff);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008877
Nirav Shah5c083da2018-08-03 13:46:02 +05308878 hdd_cfg_print_global_config(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008879}
8880
8881/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008882 * hdd_context_init() - Initialize HDD context
8883 * @hdd_ctx: HDD context.
8884 *
8885 * Initialize HDD context along with all the feature specific contexts.
8886 *
8887 * return: 0 on success and errno on failure.
8888 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008889static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008890{
8891 int ret;
8892
8893 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
8894 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
8895
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008896 init_completion(&hdd_ctx->mc_sus_event_var);
8897 init_completion(&hdd_ctx->ready_to_suspend);
8898
8899 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308900 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008901 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308902
Dustin Brownbee82832018-07-23 10:10:51 -07008903 qdf_list_create(&hdd_ctx->hdd_adapters, 0);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008904
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008905 ret = hdd_scan_context_init(hdd_ctx);
8906 if (ret)
8907 goto list_destroy;
8908
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008909 hdd_rx_wake_lock_create(hdd_ctx);
8910
8911 ret = hdd_sap_context_init(hdd_ctx);
8912 if (ret)
8913 goto scan_destroy;
8914
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008915 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8916
8917 hdd_init_offloaded_packets_ctx(hdd_ctx);
8918
8919 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8920 hdd_ctx->config);
8921 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08008922 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008923
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05308924 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
8925 "monitor_mode_wakelock");
8926
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008927 return 0;
8928
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008929sap_destroy:
8930 hdd_sap_context_destroy(hdd_ctx);
8931
8932scan_destroy:
8933 hdd_scan_context_destroy(hdd_ctx);
8934 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008935list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008936 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08008937
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008938 return ret;
8939}
8940
8941/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308942 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
8943 * @hdd_ctx: pointer to hdd context
8944 *
8945 * Return: status of initialization
8946 * 0 - success
8947 * negative value - failure
8948 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008949static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308950{
8951 int ret;
8952
8953 if (!hdd_ctx->config->probe_req_ie_whitelist)
8954 return 0;
8955
8956 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
8957 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
8958 hdd_ctx->config->probe_req_ie_whitelist = false;
8959 return -EINVAL;
8960 }
8961
8962 /* parse ini string probe req oui */
8963 ret = hdd_parse_probe_req_ouis(hdd_ctx);
8964 if (ret) {
8965 hdd_err("parsing error: disable ie whitelisting");
8966 hdd_ctx->config->probe_req_ie_whitelist = false;
8967 }
8968
8969 return ret;
8970}
8971
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308972/**
8973 * hdd_iface_change_callback() - Function invoked when stop modules expires
8974 * @priv: pointer to hdd context
8975 *
8976 * This function is invoked when the timer waiting for the interface change
8977 * expires, it shall cut-down the power to wlan and stop all the modules.
8978 *
8979 * Return: void
8980 */
8981static void hdd_iface_change_callback(void *priv)
8982{
8983 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
8984 int ret;
8985 int status = wlan_hdd_validate_context(hdd_ctx);
8986
8987 if (status)
8988 return;
8989
Dustin Brown491d54b2018-03-14 12:39:11 -07008990 hdd_enter();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308991 hdd_debug("Interface change timer expired close the modules!");
8992 ret = hdd_wlan_stop_modules(hdd_ctx, false);
8993 if (ret)
8994 hdd_err("Failed to stop modules");
Dustin Browne74003f2018-03-14 12:51:58 -07008995 hdd_exit();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308996}
8997
Nirav Shaheb017be2018-02-15 11:20:58 +05308998#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
8999static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
9000{
9001 wlan_logging_set_log_to_console(hdd_ctx->config->
9002 wlan_logging_to_console);
9003 wlan_logging_set_active(hdd_ctx->config->wlan_logging_enable);
9004}
9005#else
9006static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
9007{ }
9008#endif
9009
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05309010/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009011 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05309012 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009013 *
9014 * Allocate and initialize HDD context. HDD context is allocated as part of
9015 * wiphy allocation and then context is initialized.
9016 *
9017 * Return: HDD context on success and ERR_PTR on failure
9018 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009019static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009020{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309021 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009022 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009023 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009024
Dustin Brown491d54b2018-03-14 12:39:11 -07009025 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009026
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009027 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009028 if (hdd_ctx == NULL) {
9029 ret = -ENOMEM;
9030 goto err_out;
9031 }
9032
Dustin Brown6f427922017-09-19 12:19:00 -07009033 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
9034 hdd_iface_change_callback,
9035 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309036
9037 mutex_init(&hdd_ctx->iface_change_lock);
9038
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009039 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05309040 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009041
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309042 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009043 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009044 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009045 ret = -ENOMEM;
9046 goto err_free_hdd_context;
9047 }
9048
9049 /* Read and parse the qcom_cfg.ini file */
9050 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309051 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309052 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009053 WLAN_INI_FILE);
9054 ret = -EINVAL;
9055 goto err_free_config;
9056 }
9057
Dustin Brown84f46ea2018-02-15 11:57:36 -08009058 status = cfg_parse(WLAN_INI_FILE);
9059 if (QDF_IS_STATUS_ERROR(status))
9060 hdd_err("Failed to parse cfg %s; status:%d\n",
9061 WLAN_INI_FILE, status);
9062
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05309063 ie_whitelist_attrs_init(hdd_ctx);
9064
Dustin Brown7f939932017-05-18 15:02:17 -07009065 hdd_debug("setting timer multiplier: %u",
9066 hdd_ctx->config->timer_multiplier);
9067 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
9068
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009069
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05309070 if (hdd_ctx->config->fhostNSOffload)
9071 hdd_ctx->ns_offload_enable = true;
9072
Abhishek Singh5ea86532016-04-27 14:10:53 +05309073 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
9074
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009075 hdd_override_ini_config(hdd_ctx);
9076
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009077 ret = hdd_context_init(hdd_ctx);
9078
9079 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009080 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009081
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009082 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05309083 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009084
Anurag Chouhan6d760662016-02-20 16:05:43 +05309085 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009086 goto skip_multicast_logging;
9087
9088 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
9089
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07009090 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
9091 if (ret)
9092 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05309093
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009094 ret = hdd_init_netlink_services(hdd_ctx);
9095 if (ret)
9096 goto err_deinit_txrx_histogram;
9097
Nirav Shaheb017be2018-02-15 11:20:58 +05309098 hdd_set_wlan_logging(hdd_ctx);
Nirav Shahed34b212016-04-25 10:59:16 +05309099
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009100skip_multicast_logging:
9101 hdd_set_trace_level_for_each(hdd_ctx);
9102
Rajeev Kumar493a31b2017-09-29 14:01:24 -07009103 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
9104
Dustin Browne74003f2018-03-14 12:51:58 -07009105 hdd_exit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07009106
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009107 return hdd_ctx;
9108
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009109err_deinit_txrx_histogram:
9110 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
9111
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07009112err_deinit_hdd_context:
9113 hdd_context_deinit(hdd_ctx);
9114
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009115err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309116 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009117
9118err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309119 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08009120 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009121
9122err_out:
9123 return ERR_PTR(ret);
9124}
9125
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009126#ifdef WLAN_OPEN_P2P_INTERFACE
9127/**
9128 * hdd_open_p2p_interface - Open P2P interface
9129 * @hdd_ctx: HDD context
9130 * @rtnl_held: True if RTNL lock held
9131 *
9132 * Open P2P interface during probe. This function called to open the P2P
9133 * interface at probe along with STA interface.
9134 *
9135 * Return: 0 on success and errno on failure
9136 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009137static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009138{
Jeff Johnson9d295242017-08-29 14:39:48 -07009139 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009140 uint8_t *p2p_dev_addr;
Wu Gaoe5689792018-07-05 19:20:13 +08009141 bool p2p_dev_addr_admin = false;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009142
Wu Gaoe5689792018-07-05 19:20:13 +08009143 cfg_p2p_get_device_addr_admin(hdd_ctx->hdd_psoc, &p2p_dev_addr_admin);
9144 if (p2p_dev_addr_admin &&
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009145 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009146 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009147 hdd_ctx->config->intfMacAddr[0].bytes,
9148 sizeof(tSirMacAddr));
9149
9150 /*
9151 * Generate the P2P Device Address. This consists of
9152 * the device's primary MAC address with the locally
9153 * administered bit set.
9154 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009155 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009156 } else {
9157 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
9158 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009159 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009160 return -ENOSPC;
9161 }
9162
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009163 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
9164 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009165 }
9166
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009167 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009168 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08009169 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009170
9171 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009172 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009173 return -ENOSPC;
9174 }
9175
9176 return 0;
9177}
9178#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009179static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009180 bool rtnl_held)
9181{
9182 return 0;
9183}
9184#endif
9185
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009186static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08009187{
Jeff Johnson9d295242017-08-29 14:39:48 -07009188 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08009189 int ret = 0;
9190
9191 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
9192 wlan_hdd_get_intf_addr(hdd_ctx),
9193 NET_NAME_UNKNOWN, rtnl_held);
9194 if (adapter == NULL) {
9195 hdd_err("Failed to open 802.11p interface");
9196 ret = -ENOSPC;
9197 }
9198
9199 return ret;
9200}
9201
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009202/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309203 * hdd_start_station_adapter()- Start the Station Adapter
9204 * @adapter: HDD adapter
9205 *
9206 * This function initializes the adapter for the station mode.
9207 *
9208 * Return: 0 on success or errno on failure.
9209 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009210int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309211{
9212 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08009213 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309214
Dustin Brownfdf17c12018-03-14 12:55:34 -07009215 hdd_enter_dev(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08009216 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9217 hdd_err("session is already opened, %d",
9218 adapter->session_id);
9219 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9220 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309221
Krunal Sonib51eec72017-11-20 21:53:01 -08009222 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
9223 if (ret) {
9224 hdd_err("failed to create vdev: %d", ret);
9225 return ret;
9226 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309227 status = hdd_init_station_mode(adapter);
9228
9229 if (QDF_STATUS_SUCCESS != status) {
9230 hdd_err("Error Initializing station mode: %d", status);
9231 return qdf_status_to_os_return(status);
9232 }
9233
Arun Khandavallifae92942016-08-01 13:31:08 +05309234 hdd_register_tx_flow_control(adapter,
9235 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009236 hdd_tx_resume_cb,
9237 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309238
Dustin Browne74003f2018-03-14 12:51:58 -07009239 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309240 return 0;
9241}
9242
9243/**
9244 * hdd_start_ap_adapter()- Start AP Adapter
9245 * @adapter: HDD adapter
9246 *
9247 * This function initializes the adapter for the AP mode.
9248 *
9249 * Return: 0 on success errno on failure.
9250 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009251int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309252{
9253 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009254 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08009255 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08009256 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309257
Dustin Brown491d54b2018-03-14 12:39:11 -07009258 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309259
Krunal Sonib51eec72017-11-20 21:53:01 -08009260 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9261 hdd_err("session is already opened, %d",
9262 adapter->session_id);
9263 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9264 }
9265 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009266 * In SSR case no need to create new sap context.
9267 * Otherwise create sap context first and then create
9268 * vdev as while creating the vdev, driver needs to
9269 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08009270 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009271 if (adapter->session.ap.sap_context) {
9272 is_ssr = true;
9273 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08009274 hdd_err("sap creation failed");
9275 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
9276 }
9277
9278 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
9279 adapter->session.ap.sap_context);
9280 if (ret) {
9281 hdd_err("failed to create vdev, status:%d", ret);
9282 hdd_sap_destroy_ctx(adapter);
9283 return ret;
9284 }
Naveen Rawat1af09392018-01-03 17:28:21 -08009285
9286 if (adapter->device_mode == QDF_SAP_MODE)
9287 sme_cli_set_command(adapter->session_id,
9288 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
9289 (bool)(hdd_ctx->config->fine_time_meas_cap &
9290 WMI_FW_AP_RTT_RESPR),
9291 VDEV_CMD);
9292
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009293 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309294
9295 if (QDF_STATUS_SUCCESS != status) {
9296 hdd_err("Error Initializing the AP mode: %d", status);
9297 return qdf_status_to_os_return(status);
9298 }
9299
Arun Khandavallifae92942016-08-01 13:31:08 +05309300 hdd_register_tx_flow_control(adapter,
9301 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009302 hdd_softap_tx_resume_cb,
9303 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309304
Dustin Browne74003f2018-03-14 12:51:58 -07009305 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309306 return 0;
9307}
9308
Sourav Mohapatra57006c72017-11-19 16:15:55 +05309309static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
9310 bool rtnl_held)
9311{
9312 struct hdd_adapter *adapter;
9313
9314 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
9315 hdd_ctx->config->enableConcurrentSTA,
9316 wlan_hdd_get_intf_addr(hdd_ctx),
9317 NET_NAME_UNKNOWN, rtnl_held);
9318
9319 if (!adapter)
9320 return -ENOSPC;
9321
9322 return 0;
9323}
9324
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309325/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009326 * hdd_open_interfaces - Open all required interfaces
9327 * hdd_ctx: HDD context
9328 * rtnl_held: True if RTNL lock is held
9329 *
9330 * Open all the interfaces like STA, P2P and OCB based on the configuration.
9331 *
Jeff Johnson957bc272017-02-02 08:54:48 -08009332 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009333 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009334static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009335{
Jeff Johnson9d295242017-08-29 14:39:48 -07009336 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009337 int ret;
9338
Ravi Joshia307f632017-07-17 23:41:41 -07009339 /* open monitor mode adapter if con_mode is monitor mode */
Lin Bai1c678482017-12-18 18:29:11 +08009340 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
9341 con_mode == QDF_GLOBAL_FTM_MODE) {
9342 uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
9343 QDF_MONITOR_MODE : QDF_FTM_MODE;
9344
9345 adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
9346 wlan_hdd_get_intf_addr(hdd_ctx),
9347 NET_NAME_UNKNOWN, rtnl_held);
Ravi Joshia307f632017-07-17 23:41:41 -07009348 if (!adapter) {
9349 hdd_err("open adapter failed");
9350 return -ENOSPC;
9351 }
Lin Bai1c678482017-12-18 18:29:11 +08009352
Ravi Joshia307f632017-07-17 23:41:41 -07009353 return 0;
9354 }
9355
Jeff Johnson957bc272017-02-02 08:54:48 -08009356 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05309357 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08009358 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009359
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009360 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009361 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08009362 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009363
9364 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08009365 return -ENOSPC;
9366
Sourav Mohapatra57006c72017-11-19 16:15:55 +05309367 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
9368 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
9369 if (ret)
9370 hdd_err("Cannot create concurrent STA interface");
9371 }
9372
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009373 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
9374 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08009375 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009376
9377 /* Open 802.11p Interface */
9378 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08009379 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
9380 if (ret)
9381 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009382 }
9383
Jeff Johnson957bc272017-02-02 08:54:48 -08009384 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009385
Jeff Johnson957bc272017-02-02 08:54:48 -08009386err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009387 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08009388 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009389}
9390
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009391
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309392#ifdef QCA_LL_TX_FLOW_CONTROL_V2
9393/**
9394 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
9395 * @cds_cfg: CDS Configuration
9396 * @hdd_ctx: Pointer to hdd context
9397 *
9398 * Return: none
9399 */
9400static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9401 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009402 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309403{
9404 cds_cfg->tx_flow_stop_queue_th =
9405 hdd_ctx->config->TxFlowStopQueueThreshold;
9406 cds_cfg->tx_flow_start_queue_offset =
9407 hdd_ctx->config->TxFlowStartQueueOffset;
Mohit Khanna70322002018-05-15 19:21:32 -07009408 /* configuration for DP RX Threads */
9409 cds_cfg->enable_dp_rx_threads = hdd_ctx->enable_dp_rx_threads;
9410 cds_cfg->num_dp_rx_threads = hdd_ctx->config->num_dp_rx_threads;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309411}
9412#else
9413static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9414 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009415 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309416{
9417}
9418#endif
9419
9420#ifdef FEATURE_WLAN_RA_FILTERING
9421/**
9422 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
9423 * @cds_cfg: CDS Configuration
9424 * @hdd_ctx: Pointer to hdd context
9425 *
9426 * Return: none
9427 */
Anand Kumar3b92a912016-12-05 12:01:26 +05309428static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009429 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309430{
9431 cds_cfg->ra_ratelimit_interval =
9432 hdd_ctx->config->RArateLimitInterval;
9433 cds_cfg->is_ra_ratelimit_enabled =
9434 hdd_ctx->config->IsRArateLimitEnabled;
9435}
9436#else
Anand Kumar3b92a912016-12-05 12:01:26 +05309437static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009438 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309439{
9440}
9441#endif
9442
9443/**
9444 * hdd_update_cds_config() - API to update cds configuration parameters
9445 * @hdd_ctx: HDD Context
9446 *
9447 * Return: 0 for Success, errno on failure
9448 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009449static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309450{
9451 struct cds_config_info *cds_cfg;
9452
9453 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
9454 if (!cds_cfg) {
9455 hdd_err("failed to allocate cds config");
9456 return -ENOMEM;
9457 }
9458
Srinivas Girigowda35b00312017-06-27 21:52:03 -07009459 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08009460 if (!hdd_ctx->config->nMaxPsPoll ||
9461 !hdd_ctx->config->enablePowersaveOffload) {
9462 cds_cfg->powersave_offload_enabled =
9463 hdd_ctx->config->enablePowersaveOffload;
9464 } else {
9465 if ((hdd_ctx->config->enablePowersaveOffload ==
9466 PS_QPOWER_NODEEPSLEEP) ||
9467 (hdd_ctx->config->enablePowersaveOffload ==
9468 PS_LEGACY_NODEEPSLEEP))
9469 cds_cfg->powersave_offload_enabled =
9470 PS_LEGACY_NODEEPSLEEP;
9471 else
9472 cds_cfg->powersave_offload_enabled =
9473 PS_LEGACY_DEEPSLEEP;
9474 hdd_info("Qpower disabled in cds config, %d",
9475 cds_cfg->powersave_offload_enabled);
9476 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309477 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
9478 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
9479 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
9480 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309481
9482 /*
9483 * Copy the DFS Phyerr Filtering Offload status.
9484 * This parameter reflects the value of the
9485 * dfs_phyerr_filter_offload flag as set in the ini.
9486 */
9487 cds_cfg->dfs_phyerr_filter_offload =
9488 hdd_ctx->config->fDfsPhyerrFilterOffload;
9489 if (hdd_ctx->config->ssdp)
9490 cds_cfg->ssdp = hdd_ctx->config->ssdp;
9491
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05309492 cds_cfg->force_target_assert_enabled =
9493 hdd_ctx->config->crash_inject_enabled;
9494
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309495 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
9496 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
9497
9498 cds_cfg->ap_maxoffload_reorderbuffs =
9499 hdd_ctx->config->apMaxOffloadReorderBuffs;
9500
9501 cds_cfg->ap_disable_intrabss_fwd =
9502 hdd_ctx->config->apDisableIntraBssFwd;
9503
9504 cds_cfg->dfs_pri_multiplier =
9505 hdd_ctx->config->dfsRadarPriMultiplier;
9506 cds_cfg->reorder_offload =
9507 hdd_ctx->config->reorderOffloadSupport;
9508
9509 /* IPA micro controller data path offload resource config item */
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05309510 cds_cfg->uc_offload_enabled = ucfg_ipa_uc_is_enabled();
Yun Parkde380782016-08-17 16:26:54 -07009511 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
9512 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009513 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009514 hdd_ctx->config->IpaUcTxBufCount);
9515 hdd_ctx->config->IpaUcTxBufCount =
9516 rounddown_pow_of_two(
9517 hdd_ctx->config->IpaUcTxBufCount);
9518 if (!hdd_ctx->config->IpaUcTxBufCount) {
9519 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309520 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07009521 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009522 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009523 hdd_ctx->config->IpaUcTxBufCount);
9524 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309525 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
9526 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07009527 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
9528 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009529 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009530 hdd_ctx->config->IpaUcRxIndRingCount);
9531 hdd_ctx->config->IpaUcRxIndRingCount =
9532 rounddown_pow_of_two(
9533 hdd_ctx->config->IpaUcRxIndRingCount);
9534 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
9535 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309536 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07009537 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009538 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009539 hdd_ctx->config->IpaUcRxIndRingCount);
9540 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309541 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07009542 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309543 cds_cfg->uc_tx_partition_base =
9544 hdd_ctx->config->IpaUcTxPartitionBase;
9545 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
9546
9547 cds_cfg->ip_tcp_udp_checksum_offload =
9548 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07009549 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309550 cds_cfg->ce_classify_enabled =
9551 hdd_ctx->config->ce_classify_enabled;
Nachiket Kukadee547a482018-05-22 16:43:30 +05309552 cds_cfg->apf_packet_filter_enable =
9553 hdd_ctx->config->apf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309554 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
9555 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
9556 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07009557 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07009558 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07009559 cds_cfg->max_msdus_per_rxinorderind =
9560 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07009561 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07009562 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Nachiket Kukadee547a482018-05-22 16:43:30 +05309563 cds_cfg->active_uc_apf_mode = hdd_ctx->config->active_uc_apf_mode;
9564 cds_cfg->active_mc_bc_apf_mode = hdd_ctx->config->active_mc_bc_apf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05309565 cds_cfg->auto_power_save_fail_mode =
9566 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309567
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309568 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07009569 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Zhu Jianmina2f8e8d2018-02-11 16:37:10 +08009570 cds_cfg->delay_before_vdev_stop =
9571 hdd_ctx->config->delay_before_vdev_stop;
Rachit Kankane0106e382018-05-16 18:59:28 +05309572 cds_cfg->num_vdevs = hdd_ctx->config->num_vdevs;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309573
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309574 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
9575 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07009576 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309577 cds_init_ini_config(cds_cfg);
9578 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309579
9580exit:
9581 qdf_mem_free(cds_cfg);
9582 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309583}
9584
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009585/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009586 * hdd_update_user_config() - API to update user configuration
9587 * parameters to obj mgr which are used by multiple components
9588 * @hdd_ctx: HDD Context
9589 *
9590 * Return: 0 for Success, errno on failure
9591 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009592static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009593{
9594 struct wlan_objmgr_psoc_user_config *user_config;
Wu Gaoe5689792018-07-05 19:20:13 +08009595 bool skip_dfs_in_p2p_search = false;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009596
9597 user_config = qdf_mem_malloc(sizeof(*user_config));
9598 if (user_config == NULL) {
9599 hdd_alert("Failed to alloc memory for user_config!");
9600 return -ENOMEM;
9601 }
9602
9603 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
9604 user_config->dual_mac_feature_disable =
9605 hdd_ctx->config->dual_mac_feature_disable;
9606 user_config->indoor_channel_support =
9607 hdd_ctx->config->indoor_channel_support;
9608 user_config->is_11d_support_enabled =
9609 hdd_ctx->config->Is11dSupportEnabled;
9610 user_config->is_11h_support_enabled =
9611 hdd_ctx->config->Is11hSupportEnabled;
9612 user_config->optimize_chan_avoid_event =
9613 hdd_ctx->config->goptimize_chan_avoid_event;
Wu Gaoe5689792018-07-05 19:20:13 +08009614 cfg_p2p_get_skip_dfs_channel_p2p_search(hdd_ctx->hdd_psoc,
9615 &skip_dfs_in_p2p_search);
9616 user_config->skip_dfs_chnl_in_p2p_search = skip_dfs_in_p2p_search;
Naveen Rawat222b2e92017-03-16 09:52:21 -07009617 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009618 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
9619
9620 qdf_mem_free(user_config);
9621 return 0;
9622}
9623
9624/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009625 * hdd_init_thermal_info - Initialize thermal level
9626 * @hdd_ctx: HDD context
9627 *
9628 * Initialize thermal level at SME layer and set the thermal level callback
9629 * which would be called when a configured thermal threshold is hit.
9630 *
9631 * Return: 0 on success and errno on failure
9632 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009633static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009634{
9635 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309636 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -07009637 mac_handle_t mac_handle;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009638
9639 thermal_param.smeThermalMgmtEnabled =
9640 hdd_ctx->config->thermalMitigationEnable;
9641 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
9642
Poddar, Siddarth83905022016-04-16 17:56:08 -07009643 thermal_param.sme_throttle_duty_cycle_tbl[0] =
9644 hdd_ctx->config->throttle_dutycycle_level0;
9645 thermal_param.sme_throttle_duty_cycle_tbl[1] =
9646 hdd_ctx->config->throttle_dutycycle_level1;
9647 thermal_param.sme_throttle_duty_cycle_tbl[2] =
9648 hdd_ctx->config->throttle_dutycycle_level2;
9649 thermal_param.sme_throttle_duty_cycle_tbl[3] =
9650 hdd_ctx->config->throttle_dutycycle_level3;
9651
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009652 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
9653 hdd_ctx->config->thermalTempMinLevel0;
9654 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
9655 hdd_ctx->config->thermalTempMaxLevel0;
9656 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
9657 hdd_ctx->config->thermalTempMinLevel1;
9658 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
9659 hdd_ctx->config->thermalTempMaxLevel1;
9660 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
9661 hdd_ctx->config->thermalTempMinLevel2;
9662 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
9663 hdd_ctx->config->thermalTempMaxLevel2;
9664 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
9665 hdd_ctx->config->thermalTempMinLevel3;
9666 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
9667 hdd_ctx->config->thermalTempMaxLevel3;
9668
Jeff Johnson16528362018-06-14 12:34:16 -07009669 mac_handle = hdd_ctx->mac_handle;
9670 status = sme_init_thermal_info(mac_handle, thermal_param);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009671
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309672 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05309673 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009674
Jeff Johnson16528362018-06-14 12:34:16 -07009675 sme_add_set_thermal_level_callback(mac_handle,
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009676 hdd_set_thermal_level_cb);
9677
9678 return 0;
9679
9680}
9681
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009682#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
9683/**
9684 * hdd_hold_rtnl_lock - Hold RTNL lock
9685 *
9686 * Hold RTNL lock
9687 *
9688 * Return: True if held and false otherwise
9689 */
9690static inline bool hdd_hold_rtnl_lock(void)
9691{
9692 rtnl_lock();
9693 return true;
9694}
9695
9696/**
9697 * hdd_release_rtnl_lock - Release RTNL lock
9698 *
9699 * Release RTNL lock
9700 *
9701 * Return: None
9702 */
9703static inline void hdd_release_rtnl_lock(void)
9704{
9705 rtnl_unlock();
9706}
9707#else
9708static inline bool hdd_hold_rtnl_lock(void) { return false; }
9709static inline void hdd_release_rtnl_lock(void) { }
9710#endif
9711
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009712#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009713
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309714/* MAX iwpriv command support */
9715#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309716#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309717#define MAX_PKTLOG_SIZE 16
9718
9719/**
9720 * hdd_pktlog_set_buff_size() - set pktlog buffer size
9721 * @hdd_ctx: hdd context
9722 * @set_value2: pktlog buffer size value
9723 *
9724 *
9725 * Return: 0 for success or error.
9726 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009727static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309728{
9729 struct sir_wifi_start_log start_log = { 0 };
9730 QDF_STATUS status;
9731
9732 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9733 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9734 start_log.ini_triggered = cds_is_packet_log_enabled();
9735 start_log.user_triggered = 1;
9736 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309737 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309738
Jeff Johnson16528362018-06-14 12:34:16 -07009739 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309740 if (!QDF_IS_STATUS_SUCCESS(status)) {
9741 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009742 hdd_exit();
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309743 return -EINVAL;
9744 }
9745
9746 return 0;
9747}
9748
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009749/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309750 * hdd_pktlog_clear_buff() - clear pktlog buffer
9751 * @hdd_ctx: hdd context
9752 *
9753 * Return: 0 for success or error.
9754 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009755static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309756{
9757 struct sir_wifi_start_log start_log;
9758 QDF_STATUS status;
9759
9760 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9761 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9762 start_log.ini_triggered = cds_is_packet_log_enabled();
9763 start_log.user_triggered = 1;
9764 start_log.size = 0;
9765 start_log.is_pktlog_buff_clear = true;
9766
Jeff Johnson16528362018-06-14 12:34:16 -07009767 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309768 if (!QDF_IS_STATUS_SUCCESS(status)) {
9769 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009770 hdd_exit();
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309771 return -EINVAL;
9772 }
9773
9774 return 0;
9775}
9776
9777
9778/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009779 * hdd_process_pktlog_command() - process pktlog command
9780 * @hdd_ctx: hdd context
9781 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309782 * @set_value2: pktlog buffer size value
9783 *
9784 * This function process pktlog command.
9785 * set_value2 only matters when set_value is 3 (set buff size)
9786 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009787 *
9788 * Return: 0 for success or error.
9789 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009790int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309791 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009792{
9793 int ret;
9794 bool enable;
9795 uint8_t user_triggered = 0;
9796
9797 ret = wlan_hdd_validate_context(hdd_ctx);
9798 if (0 != ret)
9799 return ret;
9800
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009801 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009802
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309803 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009804 hdd_err("invalid pktlog value %d", set_value);
9805 return -EINVAL;
9806 }
9807
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309808 if (set_value == PKTLOG_SET_BUFF_SIZE) {
9809 if (set_value2 <= 0) {
9810 hdd_err("invalid pktlog size %d", set_value2);
9811 return -EINVAL;
9812 } else if (set_value2 > MAX_PKTLOG_SIZE) {
9813 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
9814 return -EINVAL;
9815 }
9816 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309817 } else if (set_value == PKTLOG_CLEAR_BUFF) {
9818 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309819 }
9820
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009821 /*
9822 * set_value = 0 then disable packetlog
9823 * set_value = 1 enable packetlog forcefully
9824 * set_vlaue = 2 then disable packetlog if disabled through ini or
9825 * enable packetlog with AUTO type.
9826 */
9827 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
9828 true : false;
9829
9830 if (1 == set_value) {
9831 enable = true;
9832 user_triggered = 1;
9833 }
9834
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309835 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009836}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07009837
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009838/**
9839 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
9840 * @hdd_ctx: HDD context
9841 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309842 * @user_triggered: triggered through iwpriv
9843 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009844 *
9845 * Return: 0 on success; error number otherwise
9846 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009847int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309848 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009849{
9850 struct sir_wifi_start_log start_log;
9851 QDF_STATUS status;
9852
9853 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9854 start_log.verbose_level =
9855 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009856 start_log.ini_triggered = cds_is_packet_log_enabled();
9857 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309858 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309859 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05309860 /*
9861 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
9862 * commands. Host uses this flag to decide whether to send pktlog
9863 * disable command to fw without sending pktlog enable command
9864 * previously. For eg, If vendor sends pktlog disable command without
9865 * sending pktlog enable command, then host discards the packet
9866 * but for iwpriv command, host will send it to fw.
9867 */
9868 start_log.is_iwpriv_command = 1;
Jeff Johnson16528362018-06-14 12:34:16 -07009869 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009870 if (!QDF_IS_STATUS_SUCCESS(status)) {
9871 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009872 hdd_exit();
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009873 return -EINVAL;
9874 }
9875
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309876 if (enable == true)
9877 hdd_ctx->is_pktlog_enabled = 1;
9878 else
9879 hdd_ctx->is_pktlog_enabled = 0;
9880
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009881 return 0;
9882}
9883#endif /* REMOVE_PKT_LOG */
9884
Komal Seelam92fff912016-03-24 11:51:41 +05309885/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009886 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
9887 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05309888 * @dev: Device Pointer
9889 * @num: Number of Valid Mac address
9890 *
9891 * Return: Pointer to MAC address buffer
9892 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009893static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9894 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309895{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009896 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309897}
Komal Seelam92fff912016-03-24 11:51:41 +05309898
9899/**
9900 * hdd_populate_random_mac_addr() - API to populate random mac addresses
9901 * @hdd_ctx: HDD Context
9902 * @num: Number of random mac addresses needed
9903 *
9904 * Generate random addresses using bit manipulation on the base mac address
9905 *
9906 * Return: None
9907 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009908void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05309909{
9910 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
9911 uint32_t iter;
9912 struct hdd_config *ini = hdd_ctx->config;
9913 uint8_t *buf = NULL;
9914 uint8_t macaddr_b3, tmp_br3;
9915 uint8_t *src = ini->intfMacAddr[0].bytes;
9916
9917 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
9918 buf = ini->intfMacAddr[iter].bytes;
9919 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
9920 macaddr_b3 = buf[3];
9921 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
9922 INTF_MACADDR_MASK;
9923 macaddr_b3 += tmp_br3;
9924 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
9925 buf[0] |= 0x02;
9926 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009927 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309928 }
9929}
9930
9931/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009932 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05309933 * @hdd_ctx: HDD Context
9934 *
9935 * API to get mac addresses from platform driver and update the driver
9936 * structures and configure FW with the base mac address.
9937 * Return: int
9938 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009939static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309940{
9941 uint32_t no_of_mac_addr, iter;
9942 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
9943 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
9944 uint8_t *addr, *buf;
9945 struct device *dev = hdd_ctx->parent_dev;
9946 struct hdd_config *ini = hdd_ctx->config;
9947 tSirMacAddr mac_addr;
9948 QDF_STATUS status;
9949
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009950 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05309951
Dustin Brown7e761c72018-07-31 13:50:17 -07009952 if (no_of_mac_addr == 0 || !addr)
Komal Seelam92fff912016-03-24 11:51:41 +05309953 return -EINVAL;
Komal Seelam92fff912016-03-24 11:51:41 +05309954
9955 if (no_of_mac_addr > max_mac_addr)
9956 no_of_mac_addr = max_mac_addr;
9957
9958 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
9959
9960 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
9961 buf = ini->intfMacAddr[iter].bytes;
9962 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009963 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309964 }
9965
9966 status = sme_set_custom_mac_addr(mac_addr);
9967
9968 if (!QDF_IS_STATUS_SUCCESS(status))
9969 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009970
Komal Seelam92fff912016-03-24 11:51:41 +05309971 if (no_of_mac_addr < max_mac_addr)
9972 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
9973 no_of_mac_addr);
9974 return 0;
9975}
9976
9977/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009978 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
9979 * @hdd_ctx: HDD Context
9980 *
9981 * Update MAC address to FW. If MAC address passed by FW is invalid, host
9982 * will generate its own MAC and update it to FW.
9983 *
9984 * Return: 0 for success
9985 * Non-zero error code for failure
9986 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009987static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009988{
9989 tSirMacAddr customMacAddr;
9990 QDF_STATUS status;
9991
9992 qdf_mem_copy(&customMacAddr,
9993 &hdd_ctx->config->intfMacAddr[0].bytes[0],
9994 sizeof(tSirMacAddr));
9995 status = sme_set_custom_mac_addr(customMacAddr);
9996 if (!QDF_IS_STATUS_SUCCESS(status))
9997 return -EAGAIN;
9998 return 0;
9999}
10000
10001/**
Komal Seelam92fff912016-03-24 11:51:41 +053010002 * hdd_initialize_mac_address() - API to get wlan mac addresses
10003 * @hdd_ctx: HDD Context
10004 *
10005 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
10006 * is provisioned with mac addresses, driver uses it, else it will use
10007 * wlan_mac.bin to update HW MAC addresses.
10008 *
10009 * Return: None
10010 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010011static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +053010012{
10013 QDF_STATUS status;
10014 int ret;
10015
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010016 ret = hdd_platform_wlan_mac(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010017 if (!ret) {
10018 hdd_info("using MAC address from platform driver");
Komal Seelam92fff912016-03-24 11:51:41 +053010019 return;
Dustin Brown7e761c72018-07-31 13:50:17 -070010020 }
Komal Seelam92fff912016-03-24 11:51:41 +053010021
10022 status = hdd_update_mac_config(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010023 if (QDF_IS_STATUS_SUCCESS(status)) {
10024 hdd_info("using MAC address from wlan_mac.bin");
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010025 return;
Dustin Brown7e761c72018-07-31 13:50:17 -070010026 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010027
Dustin Brown7e761c72018-07-31 13:50:17 -070010028 hdd_info("using default MAC address");
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010029
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -080010030 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010031 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010032 if (ret)
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -080010033 hdd_err("MAC address out-of-sync, ret:%d", ret);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010034 }
Komal Seelam92fff912016-03-24 11:51:41 +053010035}
10036
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010037static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010038{
10039 int vdev_id = 0;
10040 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
10041 int value = hdd_ctx->config->smart_chainmask_enabled;
10042 int vpdev = PDEV_CMD;
10043 int ret;
10044
Naveen Rawat247a8682017-06-05 15:00:31 -070010045 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010046 if (ret)
10047 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
10048
10049 return ret;
10050}
10051
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010052static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010053{
10054 int vdev_id = 0;
10055 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
10056 int value = hdd_ctx->config->alternative_chainmask_enabled;
10057 int vpdev = PDEV_CMD;
10058 int ret;
10059
Naveen Rawat247a8682017-06-05 15:00:31 -070010060 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010061 if (ret)
10062 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
10063 ret);
10064
10065 return ret;
10066}
10067
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010068static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -070010069{
10070 int vdev_id = 0;
10071 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
10072 int value = hdd_ctx->config->ani_enabled;
10073 int vpdev = PDEV_CMD;
10074 int ret;
10075
Naveen Rawat247a8682017-06-05 15:00:31 -070010076 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -070010077 if (ret)
10078 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
10079
10080 return ret;
10081}
10082
Jeff Johnson89c66ff2016-04-22 15:21:37 -070010083/**
Prashanth Bhatta07998752016-04-28 12:35:33 -070010084 * hdd_pre_enable_configure() - Configurations prior to cds_enable
10085 * @hdd_ctx: HDD context
10086 *
10087 * Pre configurations to be done at lower layer before calling cds enable.
10088 *
10089 * Return: 0 on success and errno on failure.
10090 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010091static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -070010092{
10093 int ret;
10094 QDF_STATUS status;
Leo Changfdb45c32016-10-28 11:09:23 -070010095 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010096
Leo Changfdb45c32016-10-28 11:09:23 -070010097 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Ajit Pal Singh5d269612018-04-19 16:29:12 +053010098 /* Register HL netdev flow control callback */
10099 cdp_hl_fc_register(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010100 /*
10101 * Set 802.11p config
10102 * TODO-OCB: This has been temporarily added here to ensure this
10103 * parameter is set in CSR when we init the channel list. This should
10104 * be removed once the 5.9 GHz channels are added to the regulatory
10105 * domain.
10106 */
10107 hdd_set_dot11p_config(hdd_ctx);
10108
10109 /*
10110 * Note that the cds_pre_enable() sequence triggers the cfg download.
10111 * The cfg download must occur before we update the SME config
10112 * since the SME config operation must access the cfg database
10113 */
10114 status = hdd_set_sme_config(hdd_ctx);
10115
10116 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010117 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010118 ret = qdf_status_to_os_return(status);
10119 goto out;
10120 }
10121
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -070010122 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
10123 if (QDF_STATUS_SUCCESS != status) {
10124 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
10125 ret = qdf_status_to_os_return(status);
10126 goto out;
10127 }
10128
Naveen Rawat247a8682017-06-05 15:00:31 -070010129 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -070010130 hdd_ctx->config->tx_chain_mask_1ss,
10131 PDEV_CMD);
10132 if (0 != ret) {
10133 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
10134 goto out;
10135 }
10136
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010137 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
10138 if (ret)
10139 goto out;
10140
10141 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
10142 if (ret)
10143 goto out;
10144
Jeff Johnson12a744b2017-04-04 08:19:37 -070010145 ret = hdd_set_ani_enabled(hdd_ctx);
10146 if (ret)
10147 goto out;
10148
Naveen Rawat247a8682017-06-05 15:00:31 -070010149 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -080010150 hdd_ctx->config->arp_ac_category,
10151 PDEV_CMD);
10152 if (0 != ret) {
10153 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
10154 hdd_ctx->config->arp_ac_category, ret);
10155 goto out;
10156 }
10157
Prashanth Bhatta07998752016-04-28 12:35:33 -070010158 status = hdd_set_sme_chan_list(hdd_ctx);
10159 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010160 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010161 ret = qdf_status_to_os_return(status);
10162 goto out;
10163 }
10164
10165 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -070010166 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010167 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -070010168 ret = -EINVAL;
10169 goto out;
10170 }
10171
Prashanth Bhatta07998752016-04-28 12:35:33 -070010172 /*
10173 * Set the MAC Address Currently this is used by HAL to add self sta.
10174 * Remove this once self sta is added as part of session open.
10175 */
Jeff Johnson16528362018-06-14 12:34:16 -070010176 status = sme_cfg_set_str(hdd_ctx->mac_handle, WNI_CFG_STA_ID,
Jeff Johnsonbae59f92018-06-01 17:05:43 -070010177 hdd_ctx->config->intfMacAddr[0].bytes,
10178 sizeof(hdd_ctx->config->intfMacAddr[0]));
Prashanth Bhatta07998752016-04-28 12:35:33 -070010179
Jeff Johnsonbae59f92018-06-01 17:05:43 -070010180 if (QDF_IS_STATUS_ERROR(status)) {
10181 hdd_err("Failed to set MAC Address, status %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010182 ret = -EINVAL;
10183 goto out;
10184 }
10185
10186 hdd_init_channel_avoidance(hdd_ctx);
10187
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +053010188 /* update enable sap mandatory chan list */
10189 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
10190 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010191out:
10192 return ret;
10193}
10194
10195/**
Peng Xu8fdaa492016-06-22 10:20:47 -070010196 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010197 * @context: context registered with sme_register_p2p_lo_event(). HDD
10198 * always registers a hdd context pointer
10199 * @evt:event structure pointer
Peng Xu8fdaa492016-06-22 10:20:47 -070010200 *
10201 * This is the p2p listen offload stop event handler, it sends vendor
10202 * event back to supplicant to notify the stop reason.
10203 *
10204 * Return: None
10205 */
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010206static void wlan_hdd_p2p_lo_event_callback(void *context,
10207 struct sir_p2p_lo_event *evt)
Peng Xu8fdaa492016-06-22 10:20:47 -070010208{
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010209 struct hdd_context *hdd_ctx = context;
Peng Xu8fdaa492016-06-22 10:20:47 -070010210 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -070010211 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -070010212
Dustin Brown491d54b2018-03-14 12:39:11 -070010213 hdd_enter();
Peng Xu8fdaa492016-06-22 10:20:47 -070010214
10215 if (hdd_ctx == NULL) {
10216 hdd_err("Invalid HDD context pointer");
10217 return;
10218 }
10219
Peng Xu5c682812017-08-06 07:39:13 -070010220 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
10221 if (!adapter) {
10222 hdd_err("Cannot find adapter by vdev_id = %d",
10223 evt->vdev_id);
10224 return;
10225 }
10226
Peng Xu8fdaa492016-06-22 10:20:47 -070010227 vendor_event =
10228 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -070010229 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -070010230 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
10231 GFP_KERNEL);
10232
10233 if (!vendor_event) {
10234 hdd_err("cfg80211_vendor_event_alloc failed");
10235 return;
10236 }
10237
10238 if (nla_put_u32(vendor_event,
10239 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
10240 evt->reason_code)) {
10241 hdd_err("nla put failed");
10242 kfree_skb(vendor_event);
10243 return;
10244 }
10245
10246 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -070010247 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
10248 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -070010249}
10250
Rachit Kankanef6834c42018-08-02 18:47:50 +053010251#ifdef FEATURE_WLAN_DYNAMIC_CVM
10252static inline int hdd_set_vc_mode_config(struct hdd_context *hdd_ctx)
10253{
10254 return sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap);
10255}
10256#else
10257static inline int hdd_set_vc_mode_config(struct hdd_context *hdd_ctx)
10258{
10259 return QDF_STATUS_SUCCESS;
10260}
10261#endif
10262
Peng Xu8fdaa492016-06-22 10:20:47 -070010263/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010264 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
10265 * @hdd_ctx: HDD context
10266 *
10267 * This function sends the adaptive dwell time config configuration to the
10268 * firmware via WMA
10269 *
10270 * Return: 0 - success, < 0 - failure
10271 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010272static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010273{
10274 QDF_STATUS status;
10275 struct adaptive_dwelltime_params dwelltime_params;
10276
10277 dwelltime_params.is_enabled =
10278 hdd_ctx->config->adaptive_dwell_mode_enabled;
10279 dwelltime_params.dwelltime_mode =
10280 hdd_ctx->config->global_adapt_dwelltime_mode;
10281 dwelltime_params.lpf_weight =
10282 hdd_ctx->config->adapt_dwell_lpf_weight;
10283 dwelltime_params.passive_mon_intval =
10284 hdd_ctx->config->adapt_dwell_passive_mon_intval;
10285 dwelltime_params.wifi_act_threshold =
10286 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
10287
Jeff Johnson16528362018-06-14 12:34:16 -070010288 status = sme_set_adaptive_dwelltime_config(hdd_ctx->mac_handle,
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010289 &dwelltime_params);
10290
10291 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
10292 if (!QDF_IS_STATUS_SUCCESS(status)) {
10293 hdd_err("Failed to send Adaptive Dwelltime configuration!");
10294 return -EAGAIN;
10295 }
10296 return 0;
10297}
10298
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010299int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010300{
10301 QDF_STATUS status;
10302 struct wmi_dbs_scan_sel_params dbs_scan_params;
10303 uint32_t i = 0;
10304 uint8_t count = 0, numentries = 0;
10305 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
10306 * CDS_DBS_SCAN_CLIENTS_MAX];
10307
10308 /* check if DBS is enabled or supported */
Bala Venkateshc8236ca2018-03-09 12:38:29 +053010309 if ((hdd_ctx->config->dual_mac_feature_disable ==
10310 DISABLE_DBS_CXN_AND_SCAN) ||
10311 (hdd_ctx->config->dual_mac_feature_disable ==
10312 ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN))
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010313 return -EINVAL;
10314
10315 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
10316 dbs_scan_config, &numentries,
10317 (CDS_DBS_SCAN_PARAM_PER_CLIENT
10318 * CDS_DBS_SCAN_CLIENTS_MAX));
10319
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010320 if (!numentries) {
Dustin Brown6a8d39b2018-08-14 15:27:26 -070010321 hdd_debug("Do not send scan_selection_config");
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010322 return 0;
10323 }
10324
10325 /* hdd_set_fw_log_params */
10326 dbs_scan_params.num_clients = 0;
10327 while (count < (numentries - 2)) {
10328 dbs_scan_params.module_id[i] = dbs_scan_config[count];
10329 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
10330 dbs_scan_params.num_non_dbs_scans[i] =
10331 dbs_scan_config[count + 2];
10332 dbs_scan_params.num_clients++;
10333 hdd_debug("module:%d NDS:%d NNDS:%d",
10334 dbs_scan_params.module_id[i],
10335 dbs_scan_params.num_dbs_scans[i],
10336 dbs_scan_params.num_non_dbs_scans[i]);
10337 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
10338 i++;
10339 }
10340
10341 dbs_scan_params.pdev_id = 0;
10342
10343 hdd_debug("clients:%d pdev:%d",
10344 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
10345
Jeff Johnson16528362018-06-14 12:34:16 -070010346 status = sme_set_dbs_scan_selection_config(hdd_ctx->mac_handle,
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010347 &dbs_scan_params);
10348 hdd_debug("Sending DBS Scan Selection Configuration to fw");
10349 if (!QDF_IS_STATUS_SUCCESS(status)) {
10350 hdd_err("Failed to send DBS Scan selection configuration!");
10351 return -EAGAIN;
10352 }
10353 return 0;
10354}
10355
Arun Khandavallid4349a92016-07-25 11:10:43 +053010356#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10357/**
10358 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
10359 * @hdd_ctx: HDD context
10360 *
10361 * Set auto shutdown callback to get indications from firmware to indicate
10362 * userspace to shutdown WLAN after a configured amount of inactivity.
10363 *
10364 * Return: 0 on success and errno on failure.
10365 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010366static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010367{
10368 QDF_STATUS status;
10369
10370 if (!hdd_ctx->config->WlanAutoShutdown)
10371 return 0;
10372
Jeff Johnson16528362018-06-14 12:34:16 -070010373 status = sme_set_auto_shutdown_cb(hdd_ctx->mac_handle,
Arun Khandavallid4349a92016-07-25 11:10:43 +053010374 wlan_hdd_auto_shutdown_cb);
10375 if (status != QDF_STATUS_SUCCESS)
10376 hdd_err("Auto shutdown feature could not be enabled: %d",
10377 status);
10378
10379 return qdf_status_to_os_return(status);
10380}
10381#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010382static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010383{
10384 return 0;
10385}
10386#endif
10387
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010388#ifdef MWS_COEX
10389/**
10390 * hdd_set_mws_coex() - Set MWS coex configurations
10391 * @hdd_ctx: HDD context
10392 *
10393 * This function sends MWS-COEX 4G quick FTDM and
10394 * MWS-COEX 5G-NR power limit to FW
10395 *
10396 * Return: 0 on success and errno on failure.
10397 */
10398static int hdd_init_mws_coex(struct hdd_context *hdd_ctx)
10399{
10400 int ret = 0;
10401
10402 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_MWSCOEX_4G_ALLOW_QUICK_FTDM,
10403 hdd_ctx->config->mws_coex_4g_quick_tdm,
10404 PDEV_CMD);
10405 if (ret) {
10406 hdd_warn("Unable to send MWS-COEX 4G quick FTDM policy");
10407 return ret;
10408 }
10409
10410 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_MWSCOEX_SET_5GNR_PWR_LIMIT,
10411 hdd_ctx->config->mws_coex_5g_nr_pwr_limit,
10412 PDEV_CMD);
10413 if (ret) {
10414 hdd_warn("Unable to send MWS-COEX 4G quick FTDM policy");
10415 return ret;
10416 }
10417 return ret;
10418}
10419#else
10420static int hdd_init_mws_coex(struct hdd_context *hdd_ctx)
10421{
10422 return 0;
10423}
10424#endif
10425
Arun Khandavallid4349a92016-07-25 11:10:43 +053010426/**
10427 * hdd_features_init() - Init features
10428 * @hdd_ctx: HDD context
Arun Khandavallid4349a92016-07-25 11:10:43 +053010429 *
10430 * Initialize features and their feature context after WLAN firmware is up.
10431 *
10432 * Return: 0 on success and errno on failure.
10433 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010434static int hdd_features_init(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010435{
10436 tSirTxPowerLimit hddtxlimit;
10437 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +053010438 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010439 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070010440 mac_handle_t mac_handle;
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010441 struct hdd_config *cfg;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010442
Dustin Brown491d54b2018-03-14 12:39:11 -070010443 hdd_enter();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010444
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010445 ret = hdd_init_mws_coex(hdd_ctx);
10446 if (ret)
10447 hdd_warn("Error initializing mws-coex");
10448
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010449 cfg = hdd_ctx->config;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010450 /* FW capabilities received, Set the Dot11 mode */
Jeff Johnson16528362018-06-14 12:34:16 -070010451 mac_handle = hdd_ctx->mac_handle;
10452 sme_setdef_dot11mode(mac_handle);
10453 sme_set_prefer_80MHz_over_160MHz(mac_handle,
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -070010454 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010455 sme_set_etsi13_srd_ch_in_master_mode(mac_handle,
10456 cfg->
10457 etsi13_srd_chan_in_master_mode);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010458
10459 if (hdd_ctx->config->fIsImpsEnabled)
10460 hdd_set_idle_ps_config(hdd_ctx, true);
10461 else
10462 hdd_set_idle_ps_config(hdd_ctx, false);
10463
Poddar, Siddarth37033032017-10-11 15:47:40 +053010464 /* Send Enable/Disable data stall detection cmd to FW */
10465 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
10466 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
10467
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010468 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Jeff Johnson16528362018-06-14 12:34:16 -070010469 sme_set_cts2self_for_p2p_go(mac_handle);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010470
Rachit Kankanef6834c42018-08-02 18:47:50 +053010471 if (hdd_set_vc_mode_config(hdd_ctx))
Nachiket Kukade8983cf62017-10-12 18:14:48 +053010472 hdd_warn("Error in setting Voltage Corner mode config to FW");
10473
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010474 if (hdd_rx_ol_init(hdd_ctx))
10475 hdd_err("Unable to initialize Rx LRO/GRO in fw");
Arun Khandavallid4349a92016-07-25 11:10:43 +053010476
10477 if (hdd_adaptive_dwelltime_init(hdd_ctx))
10478 hdd_err("Unable to send adaptive dwelltime setting to FW");
10479
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010480 if (hdd_dbs_scan_selection_init(hdd_ctx))
10481 hdd_err("Unable to send DBS scan selection setting to FW");
10482
Arun Khandavallid4349a92016-07-25 11:10:43 +053010483 ret = hdd_init_thermal_info(hdd_ctx);
10484 if (ret) {
10485 hdd_err("Error while initializing thermal information");
Dustin Browne7e71d32018-05-11 16:00:08 -070010486 return ret;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010487 }
10488
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010489 /**
10490 * In case of SSR/PDR, if pktlog was enabled manually before
10491 * SSR/PDR, Then enabled it again automatically after Wlan
10492 * device up.
10493 */
10494 if (cds_is_driver_recovering()) {
10495 if (hdd_ctx->is_pktlog_enabled)
10496 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Alok Kumar5a75b9d2018-08-31 10:55:43 +053010497 } else if (cds_is_packet_log_enabled())
10498 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Poddar, Siddarth66a46592017-02-22 11:44:44 +053010499
Arun Khandavallid4349a92016-07-25 11:10:43 +053010500 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
10501 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
Jeff Johnson16528362018-06-14 12:34:16 -070010502 status = sme_txpower_limit(mac_handle, &hddtxlimit);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010503 if (!QDF_IS_STATUS_SUCCESS(status))
10504 hdd_err("Error setting txlimit in sme: %d", status);
10505
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010506 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010507
Arun Khandavallid4349a92016-07-25 11:10:43 +053010508 ret = hdd_register_cb(hdd_ctx);
10509 if (ret) {
10510 hdd_err("Failed to register HDD callbacks!");
Dustin Browne7e71d32018-05-11 16:00:08 -070010511 return ret;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010512 }
10513
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +053010514 if (hdd_ctx->config->goptimize_chan_avoid_event) {
10515 status = sme_enable_disable_chanavoidind_event(
Jeff Johnson16528362018-06-14 12:34:16 -070010516 mac_handle, 0);
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +053010517 if (!QDF_IS_STATUS_SUCCESS(status)) {
10518 hdd_err("Failed to disable Chan Avoidance Indication");
10519 goto deregister_cb;
10520 }
10521 }
Arun Khandavallid4349a92016-07-25 11:10:43 +053010522
Manjeet Singha9cae432017-02-28 11:58:22 +053010523 if (hdd_ctx->config->enable_5g_band_pref) {
10524 band_pref_params.rssi_boost_threshold_5g =
10525 hdd_ctx->config->rssi_boost_threshold_5g;
10526 band_pref_params.rssi_boost_factor_5g =
10527 hdd_ctx->config->rssi_boost_factor_5g;
10528 band_pref_params.max_rssi_boost_5g =
10529 hdd_ctx->config->max_rssi_boost_5g;
10530 band_pref_params.rssi_penalize_threshold_5g =
10531 hdd_ctx->config->rssi_penalize_threshold_5g;
10532 band_pref_params.rssi_penalize_factor_5g =
10533 hdd_ctx->config->rssi_penalize_factor_5g;
10534 band_pref_params.max_rssi_penalize_5g =
10535 hdd_ctx->config->max_rssi_penalize_5g;
Jeff Johnson16528362018-06-14 12:34:16 -070010536 sme_set_5g_band_pref(mac_handle, &band_pref_params);
Manjeet Singha9cae432017-02-28 11:58:22 +053010537 }
10538
Arun Khandavallid4349a92016-07-25 11:10:43 +053010539 /* register P2P Listen Offload event callback */
10540 if (wma_is_p2p_lo_capable())
Jeff Johnson16528362018-06-14 12:34:16 -070010541 sme_register_p2p_lo_event(mac_handle, hdd_ctx,
10542 wlan_hdd_p2p_lo_event_callback);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010543
10544 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
10545
10546 if (ret)
10547 goto deregister_cb;
10548
Dustin Brown11638b72018-01-25 17:37:25 +053010549 wlan_hdd_init_chan_info(hdd_ctx);
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010550 wlan_hdd_twt_init(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010551
Dustin Browne74003f2018-03-14 12:51:58 -070010552 hdd_exit();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010553 return 0;
10554
10555deregister_cb:
10556 hdd_deregister_cb(hdd_ctx);
Dustin Browne7e71d32018-05-11 16:00:08 -070010557
Arun Khandavallid4349a92016-07-25 11:10:43 +053010558 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010559}
10560
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010561/**
10562 * hdd_features_deinit() - Deinit features
10563 * @hdd_ctx: HDD context
10564 *
10565 * De-Initialize features and their feature context.
10566 *
10567 * Return: none.
10568 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010569static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010570{
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010571 wlan_hdd_twt_deinit(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010572 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010573 wlan_hdd_tsf_deinit(hdd_ctx);
10574}
10575
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010576/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010577 * hdd_register_bcn_cb() - register scan beacon callback
10578 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010579 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010580 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010581 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010582static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010583{
10584 QDF_STATUS status;
10585
10586 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
10587 wlan_cfg80211_inform_bss_frame,
10588 SCAN_CB_TYPE_INFORM_BCN);
10589 if (!QDF_IS_STATUS_SUCCESS(status)) {
10590 hdd_err("failed with status code %08d [x%08x]",
10591 status, status);
10592 return status;
10593 }
10594
10595 return QDF_STATUS_SUCCESS;
10596}
Arun Khandavallid4349a92016-07-25 11:10:43 +053010597
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010598/**
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070010599 * hdd_v2_flow_pool_map() - Flow pool create callback when vdev is active
10600 * @vdev_id: vdev_id, corresponds to flow_pool
10601 *
10602 * Return: none.
10603 */
10604static void hdd_v2_flow_pool_map(int vdev_id)
10605{
10606 QDF_STATUS status;
10607
10608 status = cdp_flow_pool_map(cds_get_context(QDF_MODULE_ID_SOC),
10609 cds_get_context(QDF_MODULE_ID_TXRX),
10610 vdev_id);
10611 /*
10612 * For Adrastea flow control v2 is based on FW MAP events,
10613 * so this above callback is not implemented.
10614 * Hence this is not actual failure. Dont return failure
10615 */
10616 if ((status != QDF_STATUS_SUCCESS) &&
10617 (status != QDF_STATUS_E_INVAL)) {
10618 hdd_err("vdev_id: %d, failed to create flow pool status %d",
10619 vdev_id, status);
10620 }
10621}
10622
10623/**
10624 * hdd_v2_flow_pool_unmap() - Flow pool create callback when vdev is not active
10625 * @vdev_id: vdev_id, corresponds to flow_pool
10626 *
10627 * Return: none.
10628 */
10629static void hdd_v2_flow_pool_unmap(int vdev_id)
10630{
10631 cdp_flow_pool_unmap(cds_get_context(QDF_MODULE_ID_SOC),
10632 cds_get_context(QDF_MODULE_ID_TXRX), vdev_id);
10633}
10634
10635/**
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010636 * hdd_action_oui_config() - Configure action_oui strings
10637 * @hdd_ctx: pointer to hdd context
10638 *
10639 * This is a HDD wrapper function which invokes ucfg api
10640 * of action_oui component to parse action oui strings.
10641 *
10642 * Return: None
10643 */
10644static void hdd_action_oui_config(struct hdd_context *hdd_ctx)
10645{
10646 QDF_STATUS status;
10647 uint32_t id;
10648 uint8_t *str;
10649
10650 if (!hdd_ctx->config->action_oui_enable)
10651 return;
10652
10653 for (id = 0; id < ACTION_OUI_MAXIMUM_ID; id++) {
10654 str = hdd_ctx->config->action_oui_str[id];
10655 if (!qdf_str_len(str))
10656 continue;
10657
10658 status = ucfg_action_oui_parse(hdd_ctx->hdd_psoc, str, id);
10659 if (!QDF_IS_STATUS_SUCCESS(status))
10660 hdd_err("Failed to parse action_oui str: %u", id);
10661 }
10662}
10663
10664/**
10665 * hdd_action_oui_send() - Send action_oui extensions to firmware
10666 * @hdd_ctx: pointer to hdd context
10667 *
10668 * This is a HDD wrapper function which invokes ucfg api
10669 * of action_oui component to send action oui extensions to firmware.
10670 *
10671 * Return: None
10672 */
10673static void hdd_action_oui_send(struct hdd_context *hdd_ctx)
10674{
10675 QDF_STATUS status;
10676
10677 if (!hdd_ctx->config->action_oui_enable)
10678 return;
10679
10680 status = ucfg_action_oui_send(hdd_ctx->hdd_psoc);
10681 if (!QDF_IS_STATUS_SUCCESS(status))
10682 hdd_err("Failed to send one or all action_ouis");
10683}
10684
10685/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010686 * hdd_configure_cds() - Configure cds modules
10687 * @hdd_ctx: HDD context
10688 * @adapter: Primary adapter context
10689 *
10690 * Enable Cds modules after WLAN firmware is up.
10691 *
10692 * Return: 0 on success and errno on failure.
10693 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010694int hdd_configure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010695{
10696 int ret;
10697 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010698 int set_value;
Jeff Johnson16528362018-06-14 12:34:16 -070010699 mac_handle_t mac_handle;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010700 uint32_t num_abg_tx_chains = 0;
10701 uint32_t num_11b_tx_chains = 0;
10702 uint32_t num_11ag_tx_chains = 0;
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010703 struct policy_mgr_dp_cbacks dp_cbs = {0};
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010704
Jeff Johnson16528362018-06-14 12:34:16 -070010705 mac_handle = hdd_ctx->mac_handle;
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010706
10707 hdd_action_oui_send(hdd_ctx);
10708
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010709 if (hdd_ctx->config->is_force_1x1)
10710 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
10711 1, PDEV_CMD);
10712 /* set chip power save failure detected callback */
Jeff Johnson16528362018-06-14 12:34:16 -070010713 sme_set_chip_pwr_save_fail_cb(mac_handle,
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010714 hdd_chip_pwr_save_fail_detected_cb);
10715
10716 if (hdd_ctx->config->max_mpdus_inampdu) {
10717 set_value = hdd_ctx->config->max_mpdus_inampdu;
10718 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
10719 set_value, PDEV_CMD);
10720 }
10721
10722 if (hdd_ctx->config->enable_rts_sifsbursting) {
10723 set_value = hdd_ctx->config->enable_rts_sifsbursting;
10724 sme_cli_set_command(0,
10725 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
10726 set_value, PDEV_CMD);
10727 }
10728
10729 if (hdd_ctx->config->sap_get_peer_info) {
10730 set_value = hdd_ctx->config->sap_get_peer_info;
10731 sme_cli_set_command(0,
10732 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
10733 set_value, PDEV_CMD);
10734 }
10735
10736 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
10737 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
10738 if (!hdd_ctx->config->enable2x2) {
10739 if (num_11b_tx_chains > 1)
10740 num_11b_tx_chains = 1;
10741 if (num_11ag_tx_chains > 1)
10742 num_11ag_tx_chains = 1;
10743 }
10744 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
10745 num_11b_tx_chains);
10746 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
10747 num_11ag_tx_chains);
10748 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
10749 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +053010750
10751 ret = hdd_pre_enable_configure(hdd_ctx);
10752 if (ret) {
10753 hdd_err("Failed to pre-configure cds");
10754 goto out;
10755 }
10756
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010757 /* Always get latest IPA resources allocated from cds_open and configure
10758 * IPA module before configuring them to FW. Sequence required as crash
10759 * observed otherwise.
10760 */
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010761 if (ucfg_ipa_uc_ol_init(hdd_ctx->hdd_pdev,
10762 cds_get_context(QDF_MODULE_ID_QDF_DEVICE))) {
Manikandan Mohan2e803a02017-02-14 14:57:53 -080010763 hdd_err("Failed to setup pipes");
10764 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010765 }
10766
Arun Khandavallifae92942016-08-01 13:31:08 +053010767 /*
10768 * Start CDS which starts up the SME/MAC/HAL modules and everything
10769 * else
10770 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -070010771 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010772
10773 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010774 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053010775 goto out;
10776 }
10777
10778 status = hdd_post_cds_enable_config(hdd_ctx);
10779 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010780 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010781 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010782 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010783 status = hdd_register_bcn_cb(hdd_ctx);
10784 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +080010785 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010786 goto cds_disable;
10787 }
Arun Khandavallifae92942016-08-01 13:31:08 +053010788
Dustin Browne7e71d32018-05-11 16:00:08 -070010789 ret = hdd_features_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010790 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010791 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010792
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010793 if (hdd_ctx->ol_enable)
10794 dp_cbs.hdd_disable_rx_ol_in_concurrency =
10795 hdd_disable_rx_ol_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -070010796 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
jiadbb47e132018-03-30 16:28:30 +080010797 dp_cbs.hdd_ipa_set_mcc_mode_cb = hdd_ipa_set_mcc_mode;
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070010798 dp_cbs.hdd_v2_flow_pool_map = hdd_v2_flow_pool_map;
10799 dp_cbs.hdd_v2_flow_pool_unmap = hdd_v2_flow_pool_unmap;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010800 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
10801 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -070010802 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010803 goto cds_disable;
10804 }
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010805 status = policy_mgr_register_mode_change_cb(hdd_ctx->hdd_psoc,
10806 wlan_hdd_send_mode_change_event);
10807 if (!QDF_IS_STATUS_SUCCESS(status)) {
10808 hdd_debug("Failed to register mode change cb with Policy Manager");
10809 goto cds_disable;
10810 }
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010811
Jeff Johnson8bb61112018-03-31 13:33:54 -070010812 if (hdd_green_ap_enable_egap(hdd_ctx))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +053010813 hdd_debug("enhance green ap is not enabled");
10814
Nachiket Kukadedd302662017-07-13 17:31:44 +053010815 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
10816 hdd_debug("Failed to set wow pulse");
10817
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053010818 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
10819 hdd_ctx->config->gcmp_enabled, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053010820 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
10821 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
10822
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053010823
10824 if (hdd_ctx->config->enable_phy_reg_retention)
10825 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
10826 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
10827
Arun Khandavallifae92942016-08-01 13:31:08 +053010828 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010829
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010830cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010831 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010832
Arun Khandavallifae92942016-08-01 13:31:08 +053010833out:
10834 return -EINVAL;
10835}
10836
10837/**
10838 * hdd_deconfigure_cds() -De-Configure cds
10839 * @hdd_ctx: HDD context
10840 *
10841 * Deconfigure Cds modules before WLAN firmware is down.
10842 *
10843 * Return: 0 on success and errno on failure.
10844 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010845static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010846{
10847 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070010848 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053010849
Dustin Brown491d54b2018-03-14 12:39:11 -070010850 hdd_enter();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010851
10852 /* De-init features */
10853 hdd_features_deinit(hdd_ctx);
10854
Arun Khandavallifae92942016-08-01 13:31:08 +053010855 /* De-register the SME callbacks */
10856 hdd_deregister_cb(hdd_ctx);
10857
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010858 qdf_status = policy_mgr_deregister_mode_change_cb(hdd_ctx->hdd_psoc);
10859 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10860 hdd_debug("Failed to deregister mode change cb with Policy Manager");
10861 }
10862
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010863 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010864 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10865 hdd_err("Failed to Disable the CDS Modules! :%d",
10866 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070010867 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010868 }
10869
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010870 if (ucfg_ipa_uc_ol_deinit(hdd_ctx->hdd_pdev) != QDF_STATUS_SUCCESS) {
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053010871 hdd_err("Failed to disconnect pipes");
10872 ret = -EINVAL;
10873 }
10874
Dustin Browne74003f2018-03-14 12:51:58 -070010875 hdd_exit();
Houston Hoffman6640cf32016-10-10 16:44:29 -070010876 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010877}
10878
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010879#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
10880static void hdd_deregister_policy_manager_callback(
10881 struct wlan_objmgr_psoc *psoc)
10882{
10883 if (QDF_STATUS_SUCCESS !=
10884 policy_mgr_deregister_hdd_cb(psoc)) {
10885 hdd_err("HDD callback deregister with policy manager failed");
10886 }
10887}
10888#else
10889static void hdd_deregister_policy_manager_callback(
10890 struct wlan_objmgr_psoc *psoc)
10891{
10892}
10893#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010894
10895/**
10896 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
10897 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010898 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +053010899 *
10900 * This function maintains the driver state machine it will be invoked from
10901 * exit, shutdown and con_mode change handler. Depending on the driver state
10902 * shall perform the stopping/closing of the modules.
10903 *
10904 * Return: 0 for success; non-zero for failure
10905 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010906int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053010907{
10908 void *hif_ctx;
10909 qdf_device_t qdf_ctx;
10910 QDF_STATUS qdf_status;
Dustin Brown4bc0a622017-12-06 15:56:50 -080010911 bool is_recovery_stop = cds_is_driver_recovering();
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053010912 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -070010913 int active_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010914 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053010915
Dustin Brown491d54b2018-03-14 12:39:11 -070010916 hdd_enter();
Arun Khandavallifae92942016-08-01 13:31:08 +053010917
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010918 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
10919
Arun Khandavallifae92942016-08-01 13:31:08 +053010920 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
10921 if (!qdf_ctx) {
10922 hdd_err("QDF device context NULL");
10923 return -EINVAL;
10924 }
10925
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010926 mutex_lock(&hdd_ctx->iface_change_lock);
10927 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010928 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053010929
Dustin Brown70111822017-03-30 15:31:40 -070010930 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -070010931 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -070010932 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -070010933 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -070010934
10935 cds_print_external_threads();
10936
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053010937 if (IS_IDLE_STOP && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070010938 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -070010939 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10940 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010941 hdd_prevent_suspend_timeout(
10942 hdd_ctx->config->iface_change_wait_time,
10943 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010944 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010945 cds_set_module_stop_in_progress(false);
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070010946
Dustin Brown70111822017-03-30 15:31:40 -070010947 return 0;
10948 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070010949 }
10950
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080010951 /* free user wowl patterns */
10952 hdd_free_user_wowl_ptrns();
10953
Arun Khandavallifae92942016-08-01 13:31:08 +053010954 switch (hdd_ctx->driver_status) {
10955 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070010956 hdd_debug("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010957 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010958 case DRIVER_MODULES_CLOSED:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070010959 hdd_debug("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010960 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010961 case DRIVER_MODULES_ENABLED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010962 hdd_info("Wlan transitioning (OPENED <- ENABLED)");
10963
Komal Seelamf2136bb2016-09-28 18:30:44 +053010964 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053010965 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010966 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053010967 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010968 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010969 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010970 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080010971
Arun Khandavallifae92942016-08-01 13:31:08 +053010972 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010973 hdd_info("Wlan transitioned (now OPENED)");
10974
10975 /* fall through */
Arun Khandavallifae92942016-08-01 13:31:08 +053010976 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010977 hdd_info("Wlan transitioning (CLOSED <- OPENED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010978 break;
10979 default:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070010980 QDF_DEBUG_PANIC("Unknown driver state:%d",
Arun Khandavallifae92942016-08-01 13:31:08 +053010981 hdd_ctx->driver_status);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010982 ret = -EINVAL;
10983 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010984 }
10985
Amar Singhal18081642018-01-26 16:04:13 -080010986 hdd_sysfs_destroy_version_interface();
Dustin Brown550f6d22017-12-14 15:44:01 -080010987 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080010988
Rajeev Kumarbe021242017-02-16 16:12:23 -080010989 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053010990 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10991 hdd_err("Failed to process post CDS disable Modules! :%d",
10992 qdf_status);
10993 ret = -EINVAL;
10994 QDF_ASSERT(0);
10995 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010996
psimhadeea0a12017-12-18 14:50:02 -080010997 hdd_runtime_suspend_context_deinit(hdd_ctx);
10998
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010999 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
11000 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11001 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
11002 ret = -EINVAL;
11003 QDF_ASSERT(0);
11004 }
11005
Jeff Johnsone4b14592017-09-13 14:23:33 -070011006 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053011007 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011008 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053011009 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011010 QDF_ASSERT(0);
11011 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -070011012
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053011013 hdd_component_psoc_close(hdd_ctx->hdd_psoc);
Amar Singhal410675c2018-01-10 12:14:21 -080011014 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Liangwei Dong50a64a72018-01-11 01:17:00 -050011015 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
11016 if (ret) {
11017 hdd_err("Failed to destroy pdev; errno:%d", ret);
11018 QDF_ASSERT(0);
11019 }
11020
11021 /*
11022 * Reset total mac phy during module stop such that during
11023 * next module start same psoc is used to populate new service
11024 * ready data
11025 */
Arunk Khandavallia6305a32018-01-25 11:19:18 +053011026 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
11027 if (tgt_hdl)
11028 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
11029
Liangwei Dong50a64a72018-01-11 01:17:00 -050011030
Arun Khandavallifae92942016-08-01 13:31:08 +053011031 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
11032 if (!hif_ctx) {
11033 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011034 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011035 }
11036
Arunk Khandavalli4b404332017-09-26 12:46:00 +053011037 if (hdd_ctx->target_hw_name) {
11038 qdf_mem_free(hdd_ctx->target_hw_name);
11039 hdd_ctx->target_hw_name = NULL;
11040 }
11041
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053011042 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053011043
11044 ol_cds_free();
11045
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053011046 if (IS_IDLE_STOP && cds_is_target_ready()) {
Arun Khandavallifae92942016-08-01 13:31:08 +053011047 ret = pld_power_off(qdf_ctx->dev);
11048 if (ret)
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011049 hdd_err("Failed to power down device; errno:%d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053011050 }
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011051
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011052 /* Free the cache channels of the command SET_DISABLE_CHANNEL_LIST */
11053 wlan_hdd_free_cache_channels(hdd_ctx);
Arunk Khandavalli847969d2017-09-25 15:15:36 +053011054
Dustin Brown29533f22018-07-24 13:11:56 -070011055 hdd_check_for_leaks(hdd_ctx, is_recovery_stop);
Dustin Brown26b3d042017-12-21 11:13:27 -080011056 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080011057
Arunk Khandavalli847969d2017-09-25 15:15:36 +053011058 /* Once the firmware sequence is completed reset this flag */
11059 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053011060 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080011061 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053011062
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011063done:
11064 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011065 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011066 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4bc0a622017-12-06 15:56:50 -080011067
Dustin Browne74003f2018-03-14 12:51:58 -070011068 hdd_exit();
Arun Khandavallifae92942016-08-01 13:31:08 +053011069
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011070 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053011071}
11072
Arun Khandavallifae92942016-08-01 13:31:08 +053011073
Wen Gong3f003382018-05-14 14:26:37 +080011074#ifdef WLAN_FEATURE_MEMDUMP_ENABLE
Arun Khandavallifae92942016-08-01 13:31:08 +053011075/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011076 * hdd_state_info_dump() - prints state information of hdd layer
11077 * @buf: buffer pointer
11078 * @size: size of buffer to be filled
11079 *
11080 * This function is used to dump state information of hdd layer
11081 *
11082 * Return: None
11083 */
11084static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
11085{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011086 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070011087 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070011088 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011089 uint16_t len = 0;
11090 char *buf = *buf_ptr;
11091
11092 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11093 if (!hdd_ctx) {
11094 hdd_err("Failed to get hdd context ");
11095 return;
11096 }
11097
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011098 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011099
11100 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070011101 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011102 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080011103 "\n is_scheduler_suspended %d",
11104 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011105
Dustin Brown920397d2017-12-13 16:27:50 -080011106 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011107 if (adapter->dev)
11108 len += scnprintf(buf + len, *size - len,
11109 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080011110 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011111 "\n device_mode: %d", adapter->device_mode);
11112 switch (adapter->device_mode) {
11113 case QDF_STA_MODE:
11114 case QDF_P2P_CLIENT_MODE:
11115 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11116 len += scnprintf(buf + len, *size - len,
11117 "\n connState: %d",
11118 hdd_sta_ctx->conn_info.connState);
11119 break;
11120
11121 default:
11122 break;
11123 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011124 }
11125
11126 *size -= len;
11127 *buf_ptr += len;
11128}
11129
11130/**
11131 * hdd_register_debug_callback() - registration function for hdd layer
11132 * to print hdd state information
11133 *
11134 * Return: None
11135 */
11136static void hdd_register_debug_callback(void)
11137{
11138 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
11139}
Wen Gong3f003382018-05-14 14:26:37 +080011140#else /* WLAN_FEATURE_MEMDUMP_ENABLE */
Wen Gongaa6d55d2018-04-26 16:33:21 +080011141static void hdd_register_debug_callback(void)
11142{
11143}
Wen Gong3f003382018-05-14 14:26:37 +080011144#endif /* WLAN_FEATURE_MEMDUMP_ENABLE */
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011145
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053011146/*
11147 * wlan_init_bug_report_lock() - Initialize bug report lock
11148 *
11149 * This function is used to create bug report lock
11150 *
11151 * Return: None
11152 */
11153static void wlan_init_bug_report_lock(void)
11154{
Jeff Johnson2b6982c2018-05-29 14:56:11 -070011155 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053011156
11157 p_cds_context = cds_get_global_context();
11158 if (!p_cds_context) {
11159 hdd_err("cds context is NULL");
11160 return;
11161 }
11162
11163 qdf_spinlock_create(&p_cds_context->bug_report_lock);
11164}
11165
Nirav Shahd21a2e32018-04-20 16:34:43 +053011166#ifdef CONFIG_DP_TRACE
Mohit Khannaf8f96822017-05-17 17:11:59 -070011167void hdd_dp_trace_init(struct hdd_config *config)
11168{
Mohit Khannaf8f96822017-05-17 17:11:59 -070011169 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
11170 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
11171 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
11172 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
11173 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
11174 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
11175 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080011176 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070011177
Nirav Shahd21a2e32018-04-20 16:34:43 +053011178 if (!config->enable_dp_trace) {
11179 hdd_err("dp trace is disabled from ini");
11180 return;
11181 }
11182
Mohit Khannaf8f96822017-05-17 17:11:59 -070011183 hdd_string_to_u8_array(config->dp_trace_config, config_params,
11184 &num_entries, sizeof(config_params));
11185
11186 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080011187 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080011188 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080011189 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080011190 else if (bw_compute_interval > 1000) {
11191 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
11192 thresh_time_limit = 1;
11193 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070011194 hdd_err("busBandwidthComputeInterval is 0, using defaults");
11195
11196 switch (num_entries) {
11197 case 4:
11198 proto_bitmap = config_params[3];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011199 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011200 case 3:
11201 verbosity = config_params[2];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011202 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011203 case 2:
11204 thresh = config_params[1];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011205 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011206 case 1:
11207 live_mode = config_params[0];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011208 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011209 default:
Dustin Browna7bb6ae2018-08-16 16:51:50 -070011210 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
11211 live_mode, thresh, thresh_time_limit,
11212 verbosity, proto_bitmap);
Mohit Khannaf8f96822017-05-17 17:11:59 -070011213 };
11214
11215 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
11216 verbosity, proto_bitmap);
11217
11218}
Nirav Shahd21a2e32018-04-20 16:34:43 +053011219#endif
11220
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011221#ifdef DISABLE_CHANNEL_LIST
11222static int wlan_hdd_cache_chann_mutex_create(struct hdd_context *hdd_ctx)
11223{
11224 return qdf_mutex_create(&hdd_ctx->cache_channel_lock);
11225}
11226#else
11227static int wlan_hdd_cache_chann_mutex_create(struct hdd_context *hdd_ctx)
11228{
11229 return 0;
11230}
11231#endif
11232
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011233/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011234 * hdd_wlan_startup() - HDD init function
11235 * @dev: Pointer to the underlying device
11236 *
11237 * This is the driver startup code executed once a WLAN device has been detected
11238 *
11239 * Return: 0 for success, < 0 for failure
11240 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011241int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011242{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011243 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011244 struct hdd_context *hdd_ctx;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053011245 struct wlan_objmgr_psoc *psoc;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011246 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080011247 bool rtnl_held;
Jeff Johnson16528362018-06-14 12:34:16 -070011248 mac_handle_t mac_handle;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011249
Dustin Brown491d54b2018-03-14 12:39:11 -070011250 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011251
Arun Khandavallifae92942016-08-01 13:31:08 +053011252 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011253
11254 if (IS_ERR(hdd_ctx))
11255 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011256
Abhishek Singhe9068f12017-03-31 14:14:52 +053011257 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
11258 DEFAULT_PSOC_ID);
11259 if (ret) {
11260 hdd_err("Psoc creation fails!");
11261 QDF_BUG(0);
11262 goto err_hdd_free_context;
11263 }
11264
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011265 hdd_action_oui_config(hdd_ctx);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053011266 psoc = hdd_ctx->hdd_psoc;
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011267
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053011268 qdf_nbuf_init_replenish_timer();
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011269
11270 ret = wlan_hdd_cache_chann_mutex_create(hdd_ctx);
11271 if (QDF_IS_STATUS_ERROR(ret))
11272 goto err_hdd_free_context;
11273
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053011274#ifdef FEATURE_WLAN_CH_AVOID
11275 mutex_init(&hdd_ctx->avoid_freq_lock);
11276#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053011277
Naveen Rawate02f8f52018-04-05 11:58:04 -070011278 osif_request_manager_init();
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053011279 qdf_atomic_init(&hdd_ctx->con_mode_flag);
Dustin Brown021cecd2017-12-11 13:56:43 -080011280 hdd_driver_memdump_init();
Dustin Brown86d196b2018-08-02 11:51:49 -070011281 hdd_bus_bandwidth_init(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -080011282
Dustin Browne7e71d32018-05-11 16:00:08 -070011283 ret = hdd_wlan_start_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053011284 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011285 hdd_err("Failed to start modules: %d", ret);
Dustin Brown021cecd2017-12-11 13:56:43 -080011286 goto err_memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011287 }
11288
Yingying Tang80e15f32016-09-27 18:23:01 +080011289 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011290
Jeff Johnson16528362018-06-14 12:34:16 -070011291 mac_handle = cds_get_context(QDF_MODULE_ID_SME);
11292 hdd_ctx->mac_handle = mac_handle;
11293 if (!mac_handle) {
11294 hdd_err("Mac Handle is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053011295 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011296 }
11297
Prashanth Bhatta07998752016-04-28 12:35:33 -070011298 ret = hdd_wiphy_init(hdd_ctx);
11299 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011300 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053011301 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011302 }
11303
Nirav Shahd21a2e32018-04-20 16:34:43 +053011304 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053011305
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070011306 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080011307
Paul Zhangfb02f452017-12-22 11:58:43 +080011308 ret = register_netdevice_notifier(&hdd_netdev_notifier);
11309 if (ret) {
11310 hdd_err("register_netdevice_notifier failed: %d", ret);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053011311 goto err_wiphy_unregister;
Paul Zhangfb02f452017-12-22 11:58:43 +080011312 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053011313
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011314 ret = register_reboot_notifier(&system_reboot_notifier);
11315 if (ret) {
11316 hdd_err("Failed to register reboot notifier: %d", ret);
11317 goto err_unregister_netdev;
11318 }
11319
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080011320 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011321
Jeff Johnson957bc272017-02-02 08:54:48 -080011322 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11323 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011324 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080011325 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011326 }
11327
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080011328 hdd_release_rtnl_lock();
11329 rtnl_held = false;
11330
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080011331 wlan_hdd_update_11n_mode(hdd_ctx->config);
11332
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011333#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053011334 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053011335 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011336 hdd_skip_acs_scan_timer_handler,
11337 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011338 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070011339 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040011340 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011341#endif
11342
Arunk Khandavalli40943af2017-05-15 19:25:34 +053011343 hdd_lpass_notify_wlan_version(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011344
Nirav Shahbd36b062016-07-18 11:12:59 +053011345 if (hdd_ctx->rps)
11346 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070011347
Paul Zhangfb02f452017-12-22 11:58:43 +080011348 ret = hdd_register_notifiers(hdd_ctx);
11349 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -080011350 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070011351
Paul Zhangfb02f452017-12-22 11:58:43 +080011352 status = wlansap_global_init();
11353 if (QDF_IS_STATUS_ERROR(status)) {
11354 hdd_unregister_notifiers(hdd_ctx);
11355 goto err_close_adapters;
11356 }
11357
Arun Khandavallifae92942016-08-01 13:31:08 +053011358 if (hdd_ctx->config->fIsImpsEnabled)
11359 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070011360 else
11361 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011362
Mukul Sharma07bd8752017-10-10 16:58:14 +053011363 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070011364 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
11365 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053011366 hdd_prevent_suspend_timeout(
11367 hdd_ctx->config->iface_change_wait_time,
11368 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
11369 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053011370
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011371 goto success;
11372
Jeff Johnson957bc272017-02-02 08:54:48 -080011373err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080011374 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011375
Jeff Johnson46bde382017-02-01 15:31:16 -080011376err_release_rtnl_lock:
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011377 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavallid4349a92016-07-25 11:10:43 +053011378 if (rtnl_held)
11379 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011380
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011381err_unregister_netdev:
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011382 unregister_netdevice_notifier(&hdd_netdev_notifier);
11383
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011384err_wiphy_unregister:
Rachit Kankane30807332018-06-27 18:39:36 +053011385 qdf_dp_trace_deinit();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011386 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011387
Arun Khandavallifae92942016-08-01 13:31:08 +053011388err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011389 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053011390
Dustin Brown021cecd2017-12-11 13:56:43 -080011391err_memdump_deinit:
Dustin Brown86d196b2018-08-02 11:51:49 -070011392 hdd_bus_bandwidth_deinit(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -080011393 hdd_driver_memdump_deinit();
Dustin Brown021cecd2017-12-11 13:56:43 -080011394
Naveen Rawate02f8f52018-04-05 11:58:04 -070011395 osif_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070011396 hdd_exit_netlink_services(hdd_ctx);
11397
Dustin Brown20912462017-06-07 13:48:25 -070011398 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
11399
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011400err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053011401 if (cds_is_fw_down())
11402 hdd_err("Not setting the complete event as fw is down");
11403 else
11404 hdd_start_complete(ret);
11405
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053011406 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070011407 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070011408 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011409
11410success:
Dustin Browne74003f2018-03-14 12:51:58 -070011411 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011412 return 0;
11413}
11414
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011415/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011416 * hdd_wlan_update_target_info() - update target type info
11417 * @hdd_ctx: HDD context
11418 * @context: hif context
11419 *
11420 * Update target info received from firmware in hdd context
11421 * Return:None
11422 */
11423
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011424void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053011425{
11426 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
11427
11428 if (!tgt_info) {
11429 hdd_err("Target info is Null");
11430 return;
11431 }
11432
11433 hdd_ctx->target_type = tgt_info->target_type;
11434}
11435
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011436void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp, void *context)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011437{
11438 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011439 int status;
11440 struct hdd_adapter *adapter = NULL;
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011441 struct osif_request *request = NULL;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011442
Dustin Brown491d54b2018-03-14 12:39:11 -070011443 hdd_enter();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011444
11445 if (!rsp) {
11446 hdd_err("data is null");
11447 return;
11448 }
11449
11450 status = wlan_hdd_validate_context(hdd_ctx);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011451 if (status != 0)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011452 return;
11453
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011454 request = osif_request_get(context);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011455 if (!request) {
11456 hdd_err("obselete request");
11457 return;
11458 }
11459
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011460 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
11461 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
11462 hdd_err("Invalid adapter or adapter has invalid magic");
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011463 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011464 return;
11465 }
11466
Dustin Brown5e89ef82018-03-14 11:50:23 -070011467 hdd_info("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
11468 hdd_info("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
11469 hdd_info("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
11470 hdd_info("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
11471 hdd_info("rsp->out_of_order_arp_rsp_drop_cnt :%x",
11472 rsp->out_of_order_arp_rsp_drop_cnt);
11473 hdd_info("rsp->dad_detected :%x", rsp->dad_detected);
11474 hdd_info("rsp->connect_status :%x", rsp->connect_status);
11475 hdd_info("rsp->ba_session_establishment_status :%x",
11476 rsp->ba_session_establishment_status);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011477
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011478 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011479 adapter->dad |= rsp->dad_detected;
11480 adapter->con_status = rsp->connect_status;
11481
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053011482 /* Flag true indicates connectivity check stats present. */
11483 if (rsp->connect_stats_present) {
11484 hdd_info("rsp->tcp_ack_recvd :%x", rsp->tcp_ack_recvd);
11485 hdd_info("rsp->icmpv4_rsp_recvd :%x", rsp->icmpv4_rsp_recvd);
11486 adapter->hdd_stats.hdd_tcp_stats.rx_fw_cnt = rsp->tcp_ack_recvd;
11487 adapter->hdd_stats.hdd_icmpv4_stats.rx_fw_cnt =
11488 rsp->icmpv4_rsp_recvd;
11489 }
11490
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011491 osif_request_complete(request);
11492 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011493
Dustin Browne74003f2018-03-14 12:51:58 -070011494 hdd_exit();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011495}
11496
11497/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011498 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011499 * @hdd_ctx: HDD context
11500 *
11501 * Register the HDD callbacks to CDS/SME.
11502 *
11503 * Return: 0 for success or Error code for failure
11504 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011505int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011506{
11507 QDF_STATUS status;
11508 int ret = 0;
Jeff Johnson16528362018-06-14 12:34:16 -070011509 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011510
Dustin Brown491d54b2018-03-14 12:39:11 -070011511 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011512
Jeff Johnson16528362018-06-14 12:34:16 -070011513 mac_handle = hdd_ctx->mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011514
Jeff Johnson16528362018-06-14 12:34:16 -070011515 sme_register_oem_data_rsp_callback(mac_handle,
11516 hdd_send_oem_data_rsp_msg);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011517
Jeff Johnson16528362018-06-14 12:34:16 -070011518 sme_register_mgmt_frame_ind_callback(mac_handle,
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053011519 hdd_indicate_mgmt_frame);
Jeff Johnson16528362018-06-14 12:34:16 -070011520 sme_set_tsfcb(mac_handle, hdd_get_tsf_cb, hdd_ctx);
11521 sme_nan_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011522 wlan_hdd_cfg80211_nan_callback);
Jeff Johnson16528362018-06-14 12:34:16 -070011523 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011524 wlan_hdd_cfg80211_stats_ext_callback);
11525
Jeff Johnson16528362018-06-14 12:34:16 -070011526 sme_ext_scan_register_callback(mac_handle,
11527 wlan_hdd_cfg80211_extscan_callback);
11528 sme_stats_ext2_register_callback(mac_handle,
lifeng66831662017-05-19 16:01:35 +080011529 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011530
Jeff Johnson16528362018-06-14 12:34:16 -070011531 sme_set_rssi_threshold_breached_cb(mac_handle,
11532 hdd_rssi_threshold_breached);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011533
Jeff Johnson16528362018-06-14 12:34:16 -070011534 sme_set_link_layer_stats_ind_cb(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011535 wlan_hdd_cfg80211_link_layer_stats_callback);
11536
Jeff Johnson16528362018-06-14 12:34:16 -070011537 sme_rso_cmd_status_cb(mac_handle, wlan_hdd_rso_cmd_status_cb);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053011538
Jeff Johnson16528362018-06-14 12:34:16 -070011539 sme_set_link_layer_ext_cb(mac_handle,
Zhang Qianca38fb12016-12-23 11:10:48 +080011540 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
11541
Jeff Johnson16528362018-06-14 12:34:16 -070011542 status = sme_set_lost_link_info_cb(mac_handle,
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053011543 hdd_lost_link_info_cb);
11544 /* print error and not block the startup process */
11545 if (!QDF_IS_STATUS_SUCCESS(status))
11546 hdd_err("set lost link info callback failed");
11547
Poddar, Siddarth34872782017-08-10 14:08:51 +053011548 ret = hdd_register_data_stall_detect_cb();
11549 if (ret) {
11550 hdd_err("Register data stall detect detect callback failed.");
11551 return ret;
11552 }
11553
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011554 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
11555
Jeff Johnson16528362018-06-14 12:34:16 -070011556 sme_register_set_connection_info_cb(mac_handle,
11557 hdd_set_connection_in_progress,
11558 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053011559
Jeff Johnson16528362018-06-14 12:34:16 -070011560 status = sme_congestion_register_callback(mac_handle,
11561 hdd_update_cca_info_cb);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053011562 if (!QDF_IS_STATUS_SUCCESS(status))
11563 hdd_err("set congestion callback failed");
11564
Jeff Johnson16528362018-06-14 12:34:16 -070011565 status = sme_set_bt_activity_info_cb(mac_handle,
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053011566 hdd_bt_activity_cb);
11567 if (!QDF_IS_STATUS_SUCCESS(status))
11568 hdd_err("set bt activity info callback failed");
11569
Jeff Johnson16528362018-06-14 12:34:16 -070011570 status = sme_register_tx_queue_cb(mac_handle,
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080011571 hdd_tx_queue_cb);
11572 if (!QDF_IS_STATUS_SUCCESS(status))
11573 hdd_err("Register tx queue callback failed");
11574
Dustin Browne74003f2018-03-14 12:51:58 -070011575 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011576
11577 return ret;
11578}
11579
11580/**
11581 * hdd_deregister_cb() - De-Register HDD callbacks.
11582 * @hdd_ctx: HDD context
11583 *
11584 * De-Register the HDD callbacks to CDS/SME.
11585 *
11586 * Return: void
11587 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011588void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011589{
11590 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053011591 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070011592 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011593
Dustin Brown491d54b2018-03-14 12:39:11 -070011594 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011595
Jeff Johnson16528362018-06-14 12:34:16 -070011596 mac_handle = hdd_ctx->mac_handle;
11597 sme_deregister_tx_queue_cb(mac_handle);
11598 status = sme_deregister_for_dcc_stats_event(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011599 if (!QDF_IS_STATUS_SUCCESS(status))
11600 hdd_err("De-register of dcc stats callback failed: %d",
11601 status);
11602
Jeff Johnson16528362018-06-14 12:34:16 -070011603 sme_reset_link_layer_stats_ind_cb(mac_handle);
11604 sme_reset_rssi_threshold_breached_cb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011605
Jeff Johnson16528362018-06-14 12:34:16 -070011606 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011607 wlan_hdd_cfg80211_stats_ext_callback);
11608
Jeff Johnson16528362018-06-14 12:34:16 -070011609 sme_nan_deregister_callback(mac_handle);
11610 status = sme_reset_tsfcb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011611 if (!QDF_IS_STATUS_SUCCESS(status))
11612 hdd_err("Failed to de-register tsfcb the callback:%d",
11613 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011614
Poddar, Siddarth34872782017-08-10 14:08:51 +053011615 ret = hdd_deregister_data_stall_detect_cb();
11616 if (ret)
11617 hdd_err("Failed to de-register data stall detect event callback");
11618
Jeff Johnson16528362018-06-14 12:34:16 -070011619 sme_deregister_oem_data_rsp_callback(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011620
Dustin Browne74003f2018-03-14 12:51:58 -070011621 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011622}
11623
11624/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011625 * hdd_softap_sta_deauth() - handle deauth req from HDD
11626 * @adapter: Pointer to the HDD
11627 * @enable: bool value
11628 *
11629 * This to take counter measure to handle deauth req from HDD
11630 *
11631 * Return: None
11632 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011633QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011634 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011635{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011636 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011637
Dustin Brown491d54b2018-03-14 12:39:11 -070011638 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011639
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011640 /* Ignore request to deauth bcmc station */
11641 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011642 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011643
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011644 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011645 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
11646 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011647
Dustin Browne74003f2018-03-14 12:51:58 -070011648 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011649 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011650}
11651
11652/**
11653 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
11654 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011655 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011656 *
11657 * This to take counter measure to handle deauth req from HDD
11658 *
11659 * Return: None
11660 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011661void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011662 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011663{
Dustin Brown491d54b2018-03-14 12:39:11 -070011664 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011665
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011666 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011667 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011668 return;
11669
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011670 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011671 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011672}
11673
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011674/**
11675 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
11676 * @hdd_ctx: HDD Context
11677 *
11678 * API to find if there is any STA or P2P-Client is connected
11679 *
11680 * Return: true if connected; false otherwise
11681 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011682QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011683{
Jeff Johnson16528362018-06-14 12:34:16 -070011684 return sme_is_sta_p2p_client_connected(hdd_ctx->mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011685}
11686
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011687void wlan_hdd_disable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011688{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011689 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
11690 struct hdd_adapter *adapter = NULL;
11691 struct csr_roam_profile *roam_profile;
11692 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011693
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011694 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->hdd_psoc)) {
11695 hdd_debug("No active sta session");
11696 return;
11697 }
11698
11699 hdd_for_each_adapter(hdd_ctx, adapter) {
11700 roam_profile = hdd_roam_profile(adapter);
11701 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11702
11703 if (cur_adapter->session_id != adapter->session_id &&
11704 adapter->device_mode == QDF_STA_MODE &&
11705 hdd_conn_is_connected(sta_ctx)) {
11706 hdd_debug("%d Disable roaming", adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -070011707 sme_stop_roaming(hdd_ctx->mac_handle,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011708 adapter->session_id,
11709 ecsr_driver_disabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011710 }
11711 }
11712}
11713
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011714void wlan_hdd_enable_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 Enable roaming", adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -070011734 sme_start_roaming(hdd_ctx->mac_handle,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011735 adapter->session_id,
11736 REASON_DRIVER_ENABLED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011737 }
11738 }
11739}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011740
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011741/**
11742 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
11743 * @skb: sk buffer pointer
11744 *
11745 * Sends the bcast message to SVC multicast group with generic nl socket
11746 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
11747 *
11748 * Return: None
11749 */
11750static void nl_srv_bcast_svc(struct sk_buff *skb)
11751{
11752#ifdef CNSS_GENL
11753 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
11754#else
11755 nl_srv_bcast(skb);
11756#endif
11757}
11758
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011759void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011760{
11761 struct sk_buff *skb;
11762 struct nlmsghdr *nlh;
11763 tAniMsgHdr *ani_hdr;
11764 void *nl_data = NULL;
11765 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011766 struct radio_index_tlv *radio_info;
11767 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011768
11769 if (in_interrupt() || irqs_disabled() || in_atomic())
11770 flags = GFP_ATOMIC;
11771
11772 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
11773
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011774 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011775 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011776
11777 nlh = (struct nlmsghdr *)skb->data;
11778 nlh->nlmsg_pid = 0; /* from kernel */
11779 nlh->nlmsg_flags = 0;
11780 nlh->nlmsg_seq = 0;
11781 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
11782
11783 ani_hdr = NLMSG_DATA(nlh);
11784 ani_hdr->type = type;
11785
11786 switch (type) {
11787 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053011788 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011789 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011790 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011791 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011792 ani_hdr->length = 0;
11793 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011794 break;
11795 case WLAN_SVC_WLAN_STATUS_IND:
11796 case WLAN_SVC_WLAN_VERSION_IND:
11797 case WLAN_SVC_DFS_CAC_START_IND:
11798 case WLAN_SVC_DFS_CAC_END_IND:
11799 case WLAN_SVC_DFS_RADAR_DETECT_IND:
11800 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
11801 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080011802 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053011803 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080011804 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011805 ani_hdr->length = len;
11806 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
11807 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
11808 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011809 break;
11810
11811 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070011812 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011813 type);
11814 kfree_skb(skb);
11815 return;
11816 }
11817
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011818 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080011819 * Add radio index at the end of the svc event in TLV format
11820 * to maintain the backward compatibility with userspace
11821 * applications.
11822 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011823
11824 tlv_len = 0;
11825
11826 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
11827 < WLAN_NL_MAX_PAYLOAD) {
11828 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
11829 sizeof(*ani_hdr) + len);
11830 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
11831 radio_info->length = (unsigned short) sizeof(radio_info->radio);
11832 radio_info->radio = radio;
11833 tlv_len = sizeof(*radio_info);
Dustin Browna2868622018-03-20 11:38:14 -070011834 hdd_debug("Added radio index tlv - radio index %d",
11835 radio_info->radio);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011836 }
11837
11838 nlh->nlmsg_len += tlv_len;
11839 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
11840
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011841 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011842}
11843
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011844#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
11845void wlan_hdd_auto_shutdown_cb(void)
11846{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011847 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011848
11849 if (!hdd_ctx)
11850 return;
11851
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011852 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011853 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
11854 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011855}
11856
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011857void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011858{
Jeff Johnson9d295242017-08-29 14:39:48 -070011859 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011860 bool ap_connected = false, sta_connected = false;
Jeff Johnson16528362018-06-14 12:34:16 -070011861 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011862
Jeff Johnson16528362018-06-14 12:34:16 -070011863 mac_handle = hdd_ctx->mac_handle;
11864 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011865 return;
11866
11867 if (hdd_ctx->config->WlanAutoShutdown == 0)
11868 return;
11869
11870 if (enable == false) {
Jeff Johnson16528362018-06-14 12:34:16 -070011871 if (sme_set_auto_shutdown_timer(mac_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011872 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011873 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011874 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011875 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011876 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011877 return;
11878 }
11879
11880 /* To enable shutdown timer check conncurrency */
Dustin Brown920397d2017-12-13 16:27:50 -080011881 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->hdd_psoc)) {
11882 hdd_for_each_adapter(hdd_ctx, adapter) {
11883 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011884 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11885 conn_info.connState ==
11886 eConnectionState_Associated) {
11887 sta_connected = true;
11888 break;
11889 }
11890 }
Dustin Brown920397d2017-12-13 16:27:50 -080011891
11892 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011893 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070011894 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011895 ap_connected = true;
11896 break;
11897 }
11898 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011899 }
11900 }
11901
11902 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011903 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011904 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011905 }
Jeff Johnson68755312017-02-10 11:46:55 -080011906
Jeff Johnson16528362018-06-14 12:34:16 -070011907 if (sme_set_auto_shutdown_timer(mac_handle,
Jeff Johnson68755312017-02-10 11:46:55 -080011908 hdd_ctx->config->WlanAutoShutdown)
11909 != QDF_STATUS_SUCCESS)
11910 hdd_err("Failed to start wlan auto shutdown timer");
11911 else
Dustin Brown5e89ef82018-03-14 11:50:23 -070011912 hdd_info("Auto Shutdown timer for %d seconds enabled",
11913 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011914}
11915#endif
11916
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011917struct hdd_adapter *
11918hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
11919 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011920{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011921 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011922 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011923
11924 con_sap_adapter = NULL;
11925
Dustin Brown920397d2017-12-13 16:27:50 -080011926 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011927 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
11928 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011929 adapter != this_sap_adapter) {
11930 if (check_start_bss) {
11931 if (test_bit(SOFTAP_BSS_STARTED,
11932 &adapter->event_flags)) {
11933 con_sap_adapter = adapter;
11934 break;
11935 }
11936 } else {
11937 con_sap_adapter = adapter;
11938 break;
11939 }
11940 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011941 }
11942
11943 return con_sap_adapter;
11944}
11945
11946#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070011947static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011948{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011949 return adapter->device_mode == QDF_STA_MODE ||
11950 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011951}
11952
Jeff Johnson9d295242017-08-29 14:39:48 -070011953static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011954{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011955 return adapter->device_mode == QDF_SAP_MODE ||
11956 adapter->device_mode == QDF_P2P_GO_MODE;
11957}
11958
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011959static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011960{
Dustin Brown920397d2017-12-13 16:27:50 -080011961 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070011962
Dustin Brown920397d2017-12-13 16:27:50 -080011963 hdd_for_each_adapter(hdd_ctx, adapter) {
11964 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070011965 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11966 conn_info.connState == eConnectionState_Associated) {
11967 return true;
11968 }
11969
Dustin Brown920397d2017-12-13 16:27:50 -080011970 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070011971 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070011972 return true;
11973 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011974 }
11975
11976 return false;
11977}
11978
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011979static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011980{
11981 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011982
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011983 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011984 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011985 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011986
Dustin Brown5ec6b552017-03-31 12:11:40 -070011987 return is_running;
11988}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011989
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011990static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011991{
11992 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11993 hdd_ctx->bus_bw_timer_running = true;
11994 qdf_timer_start(&hdd_ctx->bus_bw_timer,
11995 hdd_ctx->config->busBandwidthComputeInterval);
11996 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11997}
11998
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011999void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012000{
Dustin Brown491d54b2018-03-14 12:39:11 -070012001 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012002
12003 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12004 hdd_debug("Bandwidth compute timer already started");
12005 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012006 }
12007
Dustin Brown5ec6b552017-03-31 12:11:40 -070012008 __hdd_bus_bw_compute_timer_start(hdd_ctx);
12009
Dustin Browne74003f2018-03-14 12:51:58 -070012010 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012011}
12012
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012013void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012014{
Dustin Brown491d54b2018-03-14 12:39:11 -070012015 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012016
12017 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12018 hdd_debug("Bandwidth compute timer already started");
12019 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070012020 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070012021
12022 if (hdd_any_adapter_is_assoc(hdd_ctx))
12023 __hdd_bus_bw_compute_timer_start(hdd_ctx);
12024
Dustin Browne74003f2018-03-14 12:51:58 -070012025 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012026}
12027
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012028static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012029{
Sravan Kumar Kairam9e99e9a2018-03-12 19:09:45 +053012030 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, 0, 0);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012031
12032 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012033 hdd_ctx->bus_bw_timer_running = false;
Dustin Brown35008ba2018-08-23 14:34:21 -070012034 qdf_timer_sync_cancel(&hdd_ctx->bus_bw_timer);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012035 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
12036
Dustin Brown35008ba2018-08-23 14:34:21 -070012037 /* work callback is long running; flush outside of lock */
12038 cancel_work_sync(&hdd_ctx->bus_bw_work);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012039 hdd_reset_tcp_delack(hdd_ctx);
12040}
12041
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012042void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012043{
Dustin Brown491d54b2018-03-14 12:39:11 -070012044 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012045
12046 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12047 hdd_debug("Bandwidth compute timer already stopped");
12048 return;
12049 }
12050
12051 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
12052
Dustin Browne74003f2018-03-14 12:51:58 -070012053 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012054}
12055
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012056void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012057{
Dustin Brown491d54b2018-03-14 12:39:11 -070012058 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012059
12060 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12061 hdd_debug("Bandwidth compute timer already stopped");
12062 return;
12063 }
12064
12065 if (!hdd_any_adapter_is_assoc(hdd_ctx))
12066 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
12067
Dustin Browne74003f2018-03-14 12:51:58 -070012068 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012069}
12070#endif
12071
12072/**
12073 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
12074 * and sta's operating channel.
12075 * @sta_adapter: Describe the first argument to foobar.
12076 * @ap_adapter: Describe the second argument to foobar.
12077 * @roam_profile: Roam profile of AP to which STA wants to connect.
12078 * @concurrent_chnl_same: If both SAP and STA channels are same then
12079 * set this flag to true else false.
12080 *
12081 * This function checks the sap's operating channel and sta's operating channel.
12082 * if both are same then it will return false else it will restart the sap in
12083 * sta's channel and return true.
12084 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012085 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012086 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070012087QDF_STATUS
12088wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
12089 struct hdd_adapter *ap_adapter,
Jeff Johnson61b5e982018-03-15 11:33:31 -070012090 struct csr_roam_profile *roam_profile,
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070012091 tScanResultHandle *scan_cache,
12092 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012093{
Jeff Johnson87251032017-08-29 13:31:11 -070012094 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012095 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012096 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012097 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012098 *concurrent_chnl_same = true;
12099
12100 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12101 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070012102 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012103 scan_cache,
12104 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012105 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012106 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012107 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070012108 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012109 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012110 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012111 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012112 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012113 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070012114 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012115 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012116 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012117 }
12118 }
12119 } else {
12120 /*
12121 * Lets handle worst case scenario here, Scan cache lookup is
12122 * failed so we have to stop the SAP to avoid any channel
12123 * discrepancy between SAP's channel and STA's channel.
12124 * Return the status as failure so caller function could know
12125 * that scan look up is failed.
12126 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070012127 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012128 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012129 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012130 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012131}
12132
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012133/**
12134 * wlan_hdd_stop_sap() - This function stops bss of SAP.
12135 * @ap_adapter: SAP adapter
12136 *
12137 * This function will process the stopping of sap adapter.
12138 *
12139 * Return: None
12140 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012141void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012142{
Jeff Johnson87251032017-08-29 13:31:11 -070012143 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012144 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053012145 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012146 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012147
12148 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012149 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012150 return;
12151 }
12152
12153 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12154 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012155 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012156 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012157
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012158 mutex_lock(&hdd_ctx->sap_lock);
12159 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080012160 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012161 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012162 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053012163 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012164 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012165 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053012166 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080012167 qdf_stop_bss_event,
12168 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053012169 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012170 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070012171 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012172 return;
12173 }
12174 }
12175 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012176 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
12177 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012178 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012179 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012180 false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012181 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012182 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012183 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012184 }
12185 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012186}
12187
12188/**
12189 * wlan_hdd_start_sap() - this function starts bss of SAP.
12190 * @ap_adapter: SAP adapter
12191 *
12192 * This function will process the starting of sap adapter.
12193 *
12194 * Return: None
12195 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012196void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012197{
Jeff Johnson87251032017-08-29 13:31:11 -070012198 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012199 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053012200 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012201 struct hdd_context *hdd_ctx;
Jeff Johnsone4c11db2018-05-05 23:22:32 -070012202 tsap_config_t *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012203
12204 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012205 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012206 return;
12207 }
12208
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012209 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070012210 hdd_err("SoftAp role has not been enabled");
12211 return;
12212 }
12213
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012214 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
12215 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12216 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070012217 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012218
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012219 mutex_lock(&hdd_ctx->sap_lock);
12220 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
12221 goto end;
12222
12223 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012224 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012225 goto end;
12226 }
12227
Wei Song2f76f642016-11-18 16:32:53 +080012228 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012229 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070012230 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012231 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012232 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012233 goto end;
12234
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012235 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053012236 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080012237 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053012238 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012239 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012240 goto end;
12241 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070012242 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012243 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012244 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012245 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012246 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12247 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012248 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012249 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012250 true);
12251 }
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053012252 mutex_unlock(&hdd_ctx->sap_lock);
12253
12254 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012255end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012256 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012257 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070012258 /* SAP context and beacon cleanup will happen during driver unload
12259 * in hdd_stop_adapter
12260 */
12261 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
12262
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012263}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012264
12265/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012266 * hdd_get_fw_version() - Get FW version
12267 * @hdd_ctx: pointer to HDD context.
12268 * @major_spid: FW version - major spid.
12269 * @minor_spid: FW version - minor spid
12270 * @ssid: FW version - ssid
12271 * @crmid: FW version - crmid
12272 *
12273 * This function is called to get the firmware build version stored
12274 * as part of the HDD context
12275 *
12276 * Return: None
12277 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012278void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012279 uint32_t *major_spid, uint32_t *minor_spid,
12280 uint32_t *siid, uint32_t *crmid)
12281{
12282 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
12283 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
12284 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
12285 *crmid = hdd_ctx->target_fw_version & 0x7fff;
12286}
12287
12288#ifdef QCA_CONFIG_SMP
12289/**
12290 * wlan_hdd_get_cpu() - get cpu_index
12291 *
12292 * Return: cpu_index
12293 */
12294int wlan_hdd_get_cpu(void)
12295{
12296 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012297
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012298 put_cpu();
12299 return cpu_index;
12300}
12301#endif
12302
12303/**
12304 * hdd_get_fwpath() - get framework path
12305 *
12306 * This function is used to get the string written by
12307 * userspace to start the wlan driver
12308 *
12309 * Return: string
12310 */
12311const char *hdd_get_fwpath(void)
12312{
12313 return fwpath.string;
12314}
12315
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070012316static int hdd_qdf_print_init(void)
12317{
12318 int qdf_print_idx;
12319 QDF_STATUS status;
12320
12321 status = qdf_print_setup();
12322 if (status != QDF_STATUS_SUCCESS) {
12323 pr_err("qdf_print_setup failed\n");
12324 return -EINVAL;
12325 }
12326
12327 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
12328
12329 if (qdf_print_idx < 0) {
12330 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
12331 qdf_print_idx);
12332 return -EINVAL;
12333 }
12334
12335 qdf_set_pidx(qdf_print_idx);
12336
12337 return 0;
12338}
12339
12340static void hdd_qdf_print_deinit(void)
12341{
12342 int qdf_print_idx;
12343
12344 qdf_print_idx = qdf_get_pidx();
12345 qdf_print_ctrl_cleanup(qdf_print_idx);
12346}
12347
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012348/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012349 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012350 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012351 * This function initilizes CDS global context with the help of cds_init. This
12352 * has to be the first function called after probe to get a valid global
12353 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012354 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012355 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012356 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012357int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012358{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012359 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012360 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012361
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012362 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080012363 if (QDF_IS_STATUS_ERROR(status)) {
12364 hdd_err("Failed to allocate CDS context");
12365 ret = -ENOMEM;
12366 goto err_out;
12367 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053012368
12369 wlan_init_bug_report_lock();
12370
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012371#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12372 wlan_logging_sock_init_svc();
12373#endif
12374
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012375 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
12376 (void *)hdd_drv_ops_inactivity_handler, NULL,
12377 QDF_TIMER_TYPE_SW);
12378
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012379 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070012380 hdd_qdf_print_init();
12381
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053012382 hdd_register_debug_callback();
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012383 wlan_roam_debug_init();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012384
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012385err_out:
12386 return ret;
12387}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012388
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012389/**
12390 * hdd_deinit() - Deinitialize Driver
12391 *
12392 * This function frees CDS global context with the help of cds_deinit. This
12393 * has to be the last function call in remove callback to free the global
12394 * context.
12395 */
12396void hdd_deinit(void)
12397{
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012398 wlan_roam_debug_deinit();
12399 hdd_qdf_print_deinit();
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012400 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012401
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012402#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12403 wlan_logging_sock_deinit_svc();
12404#endif
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012405
12406 wlan_destroy_bug_report_lock();
12407 cds_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012408}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012409
Yue Ma6e7b1a02017-04-03 14:17:46 -070012410#ifdef QCA_WIFI_NAPIER_EMULATION
12411#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
12412#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012413#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070012414#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012415
Sachin Ahujadddd2632017-03-07 19:07:24 +053012416static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
12417 struct file *file)
12418{
12419 return 0;
12420}
12421
12422static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
12423 const char __user *user_buf,
12424 size_t count,
12425 loff_t *f_pos)
12426{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012427 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053012428 static const char wlan_off_str[] = "OFF";
12429 static const char wlan_on_str[] = "ON";
12430 int ret;
12431 unsigned long rc;
12432
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012433 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012434 pr_err("Failed to read buffer\n");
12435 return -EINVAL;
12436 }
12437
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012438 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012439 pr_debug("Wifi turning off from UI\n");
12440 goto exit;
12441 }
12442
Sachin Ahuja16904db2017-12-13 19:56:57 +053012443 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) == 0) {
12444 pr_info("Wifi Turning On from UI\n");
12445 }
12446
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012447 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012448 pr_err("Invalid value received from framework");
12449 goto exit;
12450 }
12451
12452 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053012453 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053012454 rc = wait_for_completion_timeout(&wlan_start_comp,
12455 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
12456 if (!rc) {
12457 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
12458 ret = -EINVAL;
Sachin Ahujadddd2632017-03-07 19:07:24 +053012459 return ret;
12460 }
12461
12462 hdd_start_complete(0);
12463 }
12464
12465exit:
12466 return count;
12467}
12468
12469
12470const struct file_operations wlan_hdd_state_fops = {
12471 .owner = THIS_MODULE,
12472 .open = wlan_hdd_state_ctrl_param_open,
12473 .write = wlan_hdd_state_ctrl_param_write,
12474};
12475
12476static int wlan_hdd_state_ctrl_param_create(void)
12477{
12478 unsigned int wlan_hdd_state_major = 0;
12479 int ret;
12480 struct device *dev;
12481
12482 device = MKDEV(wlan_hdd_state_major, 0);
12483
12484 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
12485 if (ret) {
12486 pr_err("Failed to register qcwlanstate");
12487 goto dev_alloc_err;
12488 }
12489 wlan_hdd_state_major = MAJOR(device);
12490
12491 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
12492 if (IS_ERR(class)) {
12493 pr_err("wlan_hdd_state class_create error");
12494 goto class_err;
12495 }
12496
12497 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
12498 if (IS_ERR(dev)) {
12499 pr_err("wlan_hdd_statedevice_create error");
12500 goto err_class_destroy;
12501 }
12502
12503 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
12504 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
12505 if (ret) {
12506 pr_err("Failed to add cdev error");
12507 goto cdev_add_err;
12508 }
12509
12510 pr_info("wlan_hdd_state %s major(%d) initialized",
12511 WLAN_MODULE_NAME, wlan_hdd_state_major);
12512
12513 return 0;
12514
12515cdev_add_err:
12516 device_destroy(class, device);
12517err_class_destroy:
12518 class_destroy(class);
12519class_err:
12520 unregister_chrdev_region(device, dev_num);
12521dev_alloc_err:
12522 return -ENODEV;
12523}
12524
12525static void wlan_hdd_state_ctrl_param_destroy(void)
12526{
12527 cdev_del(&wlan_hdd_state_cdev);
12528 device_destroy(class, device);
12529 class_destroy(class);
12530 unregister_chrdev_region(device, dev_num);
12531
12532 pr_info("Device node unregistered");
12533}
12534
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012535/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053012536 * component_init - API to init cld component's
12537 *
12538 * Return: None
12539 */
12540static void component_init(void)
12541{
Sandeep Puligillac5609d52018-05-17 19:23:41 -070012542 mlme_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053012543 pmo_init();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012544 disa_init();
Zhang Qian47e22ce2018-01-04 15:38:38 +080012545 ucfg_ocb_init();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053012546 ipa_init();
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053012547 ucfg_action_oui_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053012548}
12549
12550/**
12551 * component_deinit - API to deinit cld component's
12552 *
12553 * Return: None
12554 */
12555static void component_deinit(void)
12556{
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053012557 ucfg_action_oui_deinit();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053012558 ipa_deinit();
Zhang Qian47e22ce2018-01-04 15:38:38 +080012559 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053012560 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012561 disa_deinit();
Sandeep Puligillac5609d52018-05-17 19:23:41 -070012562 mlme_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012563}
12564
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053012565QDF_STATUS hdd_component_psoc_open(struct wlan_objmgr_psoc *psoc)
12566{
12567 return mlme_psoc_open(psoc);
12568}
12569
12570void hdd_component_psoc_close(struct wlan_objmgr_psoc *psoc)
12571{
12572 mlme_psoc_close(psoc);
12573}
12574
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012575void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
12576{
Zhang Qian47e22ce2018-01-04 15:38:38 +080012577 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012578 disa_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012579}
12580
12581void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
12582{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012583 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080012584 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053012585}
12586
12587/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012588 * __hdd_module_init - Module init helper
12589 *
12590 * Module init helper function used by both module and static driver.
12591 *
12592 * Return: 0 for success, errno on failure
12593 */
12594static int __hdd_module_init(void)
12595{
12596 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012597
Dustin Brown96cd9632017-11-13 12:45:04 -080012598 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070012599 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080012600 g_wlan_driver_version,
Dustin Brownc1034df2018-02-07 14:51:32 -080012601 TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012602
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012603 pld_init();
12604
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012605 ret = hdd_init();
12606 if (ret) {
12607 pr_err("hdd_init failed %x\n", ret);
12608 goto err_hdd_init;
12609 }
12610
Rajeev Kumar97767a02016-11-30 11:20:40 -080012611 dispatcher_init();
12612
Mukul Sharmad75a6672017-06-22 15:40:53 +053012613 /* Ensure to call post objmgr init */
12614 component_init();
12615
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012616 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012617
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012618 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012619
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012620 ret = wlan_hdd_register_driver();
12621 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070012622 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
12623 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012624 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012625 }
12626
Sachin Ahuja16904db2017-12-13 19:56:57 +053012627 ret = wlan_hdd_state_ctrl_param_create();
12628 if (ret) {
12629 pr_err("wlan_hdd_state_create:%x\n", ret);
12630 goto out;
12631 }
12632
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053012633 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012634
12635 return 0;
12636out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012637 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080012638 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080012639 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012640 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080012641
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012642err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012643 pld_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012644 return ret;
12645}
12646
12647/**
12648 * __hdd_module_exit - Module exit helper
12649 *
12650 * Module exit helper function used by both module and static driver.
12651 */
12652static void __hdd_module_exit(void)
12653{
Will Huang36049722018-04-13 11:48:51 +080012654 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053012655
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012656 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
12657 QWLAN_VERSIONSTR);
12658
Arunk Khandavalli830c9692018-03-22 12:17:40 +053012659 if (!hdd_wait_for_recovery_completion())
12660 return;
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053012661
Will Huangba035ec2018-07-05 11:13:30 +080012662 cds_set_driver_loaded(false);
12663 cds_set_unload_in_progress(true);
12664
12665 if (!cds_wait_for_external_threads_completion(__func__))
12666 hdd_warn("External threads are still active attempting "
12667 "driver unload anyway");
12668
Rajeev Kumar3505ae52018-05-10 18:44:45 -070012669 if (hdd_ctx)
12670 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Will Huang36049722018-04-13 11:48:51 +080012671
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012672 wlan_hdd_unregister_driver();
12673
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012674 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012675
Mukul Sharmad75a6672017-06-22 15:40:53 +053012676 /* Ensure to call prior to objmgr deinit */
12677 component_deinit();
12678
Rajeev Kumar97767a02016-11-30 11:20:40 -080012679 dispatcher_deinit();
Amar Singhal0928b192017-12-01 10:50:54 -080012680
12681 hdd_sysfs_destroy_version_interface();
12682
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012683 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012684 pld_deinit();
12685
Sachin Ahujadddd2632017-03-07 19:07:24 +053012686 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012687}
12688
Arun Khandavallifae92942016-08-01 13:31:08 +053012689#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012690/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012691 * wlan_boot_cb() - Wlan boot callback
12692 * @kobj: object whose directory we're creating the link in.
12693 * @attr: attribute the user is interacting with
12694 * @buff: the buffer containing the user data
12695 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012696 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012697 * This callback is invoked when the fs is ready to start the
12698 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012699 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012700 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012701 */
Arun Khandavallifae92942016-08-01 13:31:08 +053012702static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012703 struct kobj_attribute *attr,
12704 const char *buf,
12705 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012706{
Arun Khandavallifae92942016-08-01 13:31:08 +053012707
Arun Khandavallifae92942016-08-01 13:31:08 +053012708 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012709 pr_err("%s: wlan driver already initialized\n", __func__);
12710 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053012711 }
12712
Arun Khandavallifae92942016-08-01 13:31:08 +053012713 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012714 pr_err("%s: wlan driver initialization failed\n", __func__);
12715 return -EIO;
12716 }
12717
12718 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053012719
12720 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012721}
Arun Khandavallifae92942016-08-01 13:31:08 +053012722
12723/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012724 * hdd_sysfs_cleanup() - cleanup sysfs
12725 *
12726 * Return: None
12727 *
12728 */
12729static void hdd_sysfs_cleanup(void)
12730{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012731 /* remove from group */
12732 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
12733 sysfs_remove_group(wlan_loader->boot_wlan_obj,
12734 wlan_loader->attr_group);
12735
12736 /* unlink the object from parent */
12737 kobject_del(wlan_loader->boot_wlan_obj);
12738
12739 /* free the object */
12740 kobject_put(wlan_loader->boot_wlan_obj);
12741
12742 kfree(wlan_loader->attr_group);
12743 kfree(wlan_loader);
12744
12745 wlan_loader = NULL;
12746}
12747
12748/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012749 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
12750 * ready
12751 *
12752 * This is creates the syfs entry boot_wlan. Which shall be invoked
12753 * when the filesystem is ready.
12754 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012755 * QDF API cannot be used here since this function is called even before
12756 * initializing WLAN driver.
12757 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012758 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053012759 */
12760static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012761{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012762 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012763
12764 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012765 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012766 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012767
12768 wlan_loader->boot_wlan_obj = NULL;
12769 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
12770 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012771 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053012772 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053012773
12774 wlan_loader->loaded_state = 0;
12775 wlan_loader->attr_group->attrs = attrs;
12776
12777 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
12778 kernel_kobj);
12779 if (!wlan_loader->boot_wlan_obj) {
12780 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053012781 goto error_return;
12782 }
12783
12784 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
12785 wlan_loader->attr_group);
12786 if (ret) {
12787 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
12788 goto error_return;
12789 }
12790
12791 return 0;
12792
12793error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012794 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053012795
12796 return ret;
12797}
12798
12799/**
12800 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
12801 *
12802 * Return: 0 on success or errno on failure
12803 */
12804static int wlan_deinit_sysfs(void)
12805{
Arun Khandavallifae92942016-08-01 13:31:08 +053012806 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012807 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053012808 return -EINVAL;
12809 }
12810
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012811 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012812 return 0;
12813}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012814
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012815#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053012816
12817#ifdef MODULE
12818/**
12819 * __hdd_module_init - Module init helper
12820 *
12821 * Module init helper function used by both module and static driver.
12822 *
12823 * Return: 0 for success, errno on failure
12824 */
12825static int hdd_module_init(void)
12826{
Arun Khandavallifae92942016-08-01 13:31:08 +053012827 if (__hdd_module_init()) {
12828 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070012829 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053012830 }
12831
Dustin Brownab482ac2017-06-09 17:00:44 -070012832 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053012833}
12834#else
12835static int __init hdd_module_init(void)
12836{
12837 int ret = -EINVAL;
12838
12839 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012840 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053012841 pr_err("Failed to create sysfs entry for loading wlan");
12842
12843 return ret;
12844}
12845#endif
12846
12847
12848#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012849/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012850 * hdd_module_exit() - Exit function
12851 *
12852 * This is the driver exit point (invoked when module is unloaded using rmmod)
12853 *
12854 * Return: None
12855 */
12856static void __exit hdd_module_exit(void)
12857{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012858 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012859}
Arun Khandavallifae92942016-08-01 13:31:08 +053012860#else
12861static void __exit hdd_module_exit(void)
12862{
12863 __hdd_module_exit();
12864 wlan_deinit_sysfs();
12865}
12866#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012867
Srinivas Girigowda841da292018-02-21 16:33:00 -080012868static int fwpath_changed_handler(const char *kmessage,
12869 const struct kernel_param *kp)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012870{
12871 return param_set_copystring(kmessage, kp);
12872}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012873
Nirav Shah73713f72018-05-17 14:50:41 +053012874#ifdef FEATURE_MONITOR_MODE_SUPPORT
12875static bool is_monitor_mode_supported(void)
12876{
12877 return true;
12878}
12879#else
12880static bool is_monitor_mode_supported(void)
12881{
12882 pr_err("Monitor mode not supported!");
12883 return false;
12884}
12885#endif
12886
12887#ifdef WLAN_FEATURE_EPPING
12888static bool is_epping_mode_supported(void)
12889{
12890 return true;
12891}
12892#else
12893static bool is_epping_mode_supported(void)
12894{
12895 pr_err("Epping mode not supported!");
12896 return false;
12897}
12898#endif
12899
Ryan Hsu6e9db0b2018-06-01 10:45:51 -070012900#ifdef QCA_WIFI_FTM
12901static bool is_ftm_mode_supported(void)
12902{
12903 return true;
12904}
12905#else
12906static bool is_ftm_mode_supported(void)
12907{
12908 pr_err("FTM mode not supported!");
12909 return false;
12910}
12911#endif
12912
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012913/**
12914 * is_con_mode_valid() check con mode is valid or not
12915 * @mode: global con mode
12916 *
12917 * Return: TRUE on success FALSE on failure
12918 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012919static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012920{
12921 switch (mode) {
12922 case QDF_GLOBAL_MONITOR_MODE:
Nirav Shah73713f72018-05-17 14:50:41 +053012923 return is_monitor_mode_supported();
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012924 case QDF_GLOBAL_EPPING_MODE:
Nirav Shah73713f72018-05-17 14:50:41 +053012925 return is_epping_mode_supported();
12926 case QDF_GLOBAL_FTM_MODE:
Ryan Hsu6e9db0b2018-06-01 10:45:51 -070012927 return is_ftm_mode_supported();
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012928 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012929 return true;
12930 default:
12931 return false;
12932 }
12933}
12934
12935/**
12936 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
12937 * @mode: global con mode
12938 *
12939 * Return: adapter mode
12940 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012941static enum QDF_OPMODE hdd_get_adpter_mode(
Jeff Johnson876c1a62017-12-12 10:43:07 -080012942 enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012943{
12944
12945 switch (mode) {
12946 case QDF_GLOBAL_MISSION_MODE:
12947 return QDF_STA_MODE;
12948 case QDF_GLOBAL_MONITOR_MODE:
12949 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012950 case QDF_GLOBAL_EPPING_MODE:
12951 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012952 case QDF_GLOBAL_FTM_MODE:
12953 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012954 case QDF_GLOBAL_QVIT_MODE:
12955 return QDF_QVIT_MODE;
12956 default:
12957 return QDF_MAX_NO_OF_MODE;
12958 }
12959}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012960
Dustin Brown27cd9942017-09-27 16:11:44 -070012961static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012962 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070012963{
12964 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
12965 return;
12966
12967 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070012968 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012969 hdd_info("Release wakelock for monitor mode!");
12970 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
12971 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
Dundi Raviteja0a2a65b2018-04-30 12:34:11 +053012972 /* fallthrough */
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012973 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070012974 case QDF_GLOBAL_FTM_MODE:
12975 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +053012976 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Dustin Browndb2a8be2017-12-20 11:49:56 -080012977 hdd_stop_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -070012978
Dustin Brown27cd9942017-09-27 16:11:44 -070012979 break;
12980 default:
12981 break;
12982 }
12983}
12984
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012985static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012986 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012987{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053012988 int driver_status;
12989
12990 driver_status = hdd_ctx->driver_status;
12991
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012992 switch (curr_mode) {
12993 case QDF_GLOBAL_MISSION_MODE:
12994 case QDF_GLOBAL_MONITOR_MODE:
12995 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012996 hdd_deinit_all_adapters(hdd_ctx, false);
12997 hdd_close_all_adapters(hdd_ctx, false);
12998 break;
12999 case QDF_GLOBAL_EPPING_MODE:
13000 epping_disable();
13001 epping_close();
13002 break;
13003 default:
13004 return;
13005 }
13006}
13007
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013008static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080013009 enum QDF_GLOBAL_MODE mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013010{
Jeff Johnson9d295242017-08-29 14:39:48 -070013011 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013012 int ret = 0;
13013 bool rtnl_held;
13014 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
13015 QDF_STATUS status;
13016
13017 if (!qdf_dev) {
13018 hdd_err("qdf device context is Null return!");
13019 return -EINVAL;
13020 }
13021
13022 rtnl_held = hdd_hold_rtnl_lock();
13023 switch (mode) {
13024 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080013025 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
13026 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013027 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013028 break;
13029 case QDF_GLOBAL_FTM_MODE:
13030 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
13031 wlan_hdd_get_intf_addr(hdd_ctx),
13032 NET_NAME_UNKNOWN, rtnl_held);
13033 if (adapter == NULL)
13034 ret = -EINVAL;
13035 break;
13036 case QDF_GLOBAL_MONITOR_MODE:
13037 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
13038 wlan_hdd_get_intf_addr(hdd_ctx),
13039 NET_NAME_UNKNOWN, rtnl_held);
13040 if (adapter == NULL)
13041 ret = -EINVAL;
13042 break;
13043 case QDF_GLOBAL_EPPING_MODE:
13044 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013045 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013046 hdd_err("Failed to open in eeping mode: %d", status);
13047 ret = -EINVAL;
13048 break;
13049 }
13050 ret = epping_enable(qdf_dev->dev);
13051 if (ret) {
13052 hdd_err("Failed to enable in epping mode : %d", ret);
13053 epping_close();
13054 }
13055 break;
13056 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013057 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013058 ret = -ENOTSUPP;
13059 break;
13060 }
13061 hdd_release_rtnl_lock();
13062 rtnl_held = false;
13063 return ret;
13064}
13065
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013066/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013067 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013068 * @kmessage: con mode name on which driver to be bring up
13069 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013070 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013071 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013072 * This function is invoked when user updates con mode using sys entry,
13073 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013074 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013075 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013076 */
Srinivas Girigowda841da292018-02-21 16:33:00 -080013077static int __con_mode_handler(const char *kmessage,
13078 const struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013079 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013080{
13081 int ret;
Jeff Johnson876c1a62017-12-12 10:43:07 -080013082 enum QDF_GLOBAL_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080013083 enum QDF_OPMODE adapter_mode;
Dustin Brown20024e32018-01-03 12:34:58 -080013084 int new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013085
Dustin Brownab6029b2017-05-24 13:04:19 -070013086 hdd_info("con_mode handler: %s", kmessage);
13087
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013088 ret = wlan_hdd_validate_context(hdd_ctx);
13089 if (ret)
13090 return ret;
13091
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013092 qdf_atomic_set(&hdd_ctx->con_mode_flag, 1);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013093
Dustin Brown20024e32018-01-03 12:34:58 -080013094 ret = kstrtoint(kmessage, 0, &new_con_mode);
13095 if (ret) {
13096 hdd_err("Failed to parse con_mode '%s'", kmessage);
13097 goto reset_flags;
13098 }
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013099 mutex_lock(&hdd_init_deinit_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +053013100
Dustin Brown20024e32018-01-03 12:34:58 -080013101 if (!is_con_mode_valid(new_con_mode)) {
13102 hdd_err("invalid con_mode %d", new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013103 ret = -EINVAL;
13104 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013105 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013106
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013107 curr_mode = hdd_get_conparam();
Dustin Brown20024e32018-01-03 12:34:58 -080013108 if (curr_mode == new_con_mode) {
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013109 hdd_err("curr mode: %d is same as user triggered mode %d",
Dustin Brown20024e32018-01-03 12:34:58 -080013110 curr_mode, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013111 ret = 0;
13112 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013113 }
13114
Dustin Brown27cd9942017-09-27 16:11:44 -070013115 /* ensure adapters are stopped */
13116 hdd_stop_present_mode(hdd_ctx, curr_mode);
13117
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070013118 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053013119 if (ret) {
13120 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013121 goto reset_flags;
13122 }
13123
Dustin Browndd4e50f2018-05-24 15:43:42 -070013124 /* Cleanup present mode before switching to new mode */
13125 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053013126
Dustin Brown20024e32018-01-03 12:34:58 -080013127 hdd_set_conparam(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013128
13129 /* Register for new con_mode & then kick_start modules again */
Dustin Brown20024e32018-01-03 12:34:58 -080013130 ret = hdd_register_req_mode(hdd_ctx, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013131 if (ret) {
13132 hdd_err("Failed to register for new mode");
13133 goto reset_flags;
13134 }
13135
Dustin Brown20024e32018-01-03 12:34:58 -080013136 adapter_mode = hdd_get_adpter_mode(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013137 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
13138 hdd_err("invalid adapter");
13139 ret = -EINVAL;
13140 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053013141 }
13142
Dustin Browne7e71d32018-05-11 16:00:08 -070013143 ret = hdd_wlan_start_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053013144 if (ret) {
13145 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013146 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053013147 }
13148
Dustin Brown20024e32018-01-03 12:34:58 -080013149 if (new_con_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Browne7e71d32018-05-11 16:00:08 -070013150 struct hdd_adapter *adapter =
13151 hdd_get_adapter(hdd_ctx, adapter_mode);
13152
13153 if (!adapter) {
13154 hdd_err("Failed to get adapter:%d", adapter_mode);
13155 goto reset_flags;
13156 }
13157
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013158 if (hdd_start_adapter(adapter)) {
13159 hdd_err("Failed to start %s adapter", kmessage);
13160 ret = -EINVAL;
13161 goto reset_flags;
13162 }
Arun Khandavallifae92942016-08-01 13:31:08 +053013163
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053013164 hdd_info("Acquire wakelock for monitor mode!");
13165 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
13166 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
13167 }
13168
Dustin Brown20024e32018-01-03 12:34:58 -080013169 /* con_mode is a global module parameter */
13170 con_mode = new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013171 hdd_info("Mode successfully changed to %s", kmessage);
13172 ret = 0;
13173
13174reset_flags:
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013175 mutex_unlock(&hdd_init_deinit_lock);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013176 qdf_atomic_set(&hdd_ctx->con_mode_flag, 0);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013177 return ret;
13178}
13179
13180
Srinivas Girigowda841da292018-02-21 16:33:00 -080013181static int con_mode_handler(const char *kmessage, const struct kernel_param *kp)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013182{
13183 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013184 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013185
13186 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13187 ret = wlan_hdd_validate_context(hdd_ctx);
13188 if (ret)
13189 return ret;
13190
Ashish Kumar Dhanotiya759b3272018-05-18 17:49:46 +053013191 if (!cds_wait_for_external_threads_completion(__func__)) {
13192 hdd_warn("External threads are still active, can not change mode");
13193 return -EAGAIN;
13194 }
13195
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013196 cds_ssr_protect(__func__);
13197 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
13198 cds_ssr_unprotect(__func__);
13199
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013200 return ret;
13201}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013202
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013203static int con_mode_handler_ftm(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080013204 const struct kernel_param *kp)
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013205{
13206 int ret;
13207
13208 ret = param_set_int(kmessage, kp);
13209
13210 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
13211 pr_err("Only FTM mode supported!");
13212 return -ENOTSUPP;
13213 }
13214
13215 hdd_set_conparam(con_mode_ftm);
13216 con_mode = con_mode_ftm;
13217
13218 return ret;
13219}
13220
Nirav Shah73713f72018-05-17 14:50:41 +053013221#ifdef FEATURE_MONITOR_MODE_SUPPORT
Ravi Joshia307f632017-07-17 23:41:41 -070013222static int con_mode_handler_monitor(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080013223 const struct kernel_param *kp)
Ravi Joshia307f632017-07-17 23:41:41 -070013224{
13225 int ret;
13226
13227 ret = param_set_int(kmessage, kp);
13228
13229 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
13230 pr_err("Only Monitor mode supported!");
13231 return -ENOTSUPP;
13232 }
13233
13234 hdd_set_conparam(con_mode_monitor);
13235 con_mode = con_mode_monitor;
13236
13237 return ret;
13238}
Nirav Shah73713f72018-05-17 14:50:41 +053013239#endif
Ravi Joshia307f632017-07-17 23:41:41 -070013240
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013241/**
13242 * hdd_get_conparam() - driver exit point
13243 *
13244 * This is the driver exit point (invoked when module is unloaded using rmmod)
13245 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080013246 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013247 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080013248enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013249{
Jeff Johnson876c1a62017-12-12 10:43:07 -080013250 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013251}
13252
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080013253void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013254{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080013255 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013256}
13257
Komal Seelamc11bb222016-01-27 18:57:10 +053013258/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013259 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
13260 * @hdd_ctx: HDD context
13261 *
13262 * Cleans up the pre cac interface, if it exists
13263 *
13264 * Return: None
13265 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013266void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013267{
13268 uint8_t session_id;
13269 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070013270 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013271
Jeff Johnson16528362018-06-14 12:34:16 -070013272 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->mac_handle, &session_id);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013273 if (QDF_IS_STATUS_ERROR(status)) {
13274 hdd_err("failed to get pre cac vdev id");
13275 return;
13276 }
13277
13278 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
13279 if (!precac_adapter) {
Jeff Johnsondd2f1fc2018-05-06 11:22:52 -070013280 hdd_err("invalid pre cac adapter");
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013281 return;
13282 }
13283
13284 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
13285 wlan_hdd_sap_pre_cac_failure,
13286 (void *)precac_adapter);
13287 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
13288
13289}
13290
13291/**
Komal Seelamec702b02016-02-24 18:42:16 +053013292 * hdd_update_ol_config - API to update ol configuration parameters
13293 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053013294 *
Komal Seelamc11bb222016-01-27 18:57:10 +053013295 * Return: void
13296 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013297static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053013298{
Komal Seelamec702b02016-02-24 18:42:16 +053013299 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053013300 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053013301
Komal Seelamec702b02016-02-24 18:42:16 +053013302 if (!ol_ctx)
13303 return;
13304
13305 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
13306 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
13307 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
13308 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070013309 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053013310
13311 ol_init_ini_config(ol_ctx, &cfg);
13312}
13313
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013314#ifdef FEATURE_RUNTIME_PM
13315/**
13316 * hdd_populate_runtime_cfg() - populate runtime configuration
13317 * @hdd_ctx: hdd context
13318 * @cfg: pointer to the configuration memory being populated
13319 *
13320 * Return: void
13321 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013322static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013323 struct hif_config_info *cfg)
13324{
13325 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
13326 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
13327}
13328#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013329static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013330 struct hif_config_info *cfg)
13331{
13332}
13333#endif
13334
Komal Seelamec702b02016-02-24 18:42:16 +053013335/**
13336 * hdd_update_hif_config - API to update HIF configuration parameters
13337 * @hdd_ctx: HDD Context
13338 *
13339 * Return: void
13340 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013341static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053013342{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053013343 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053013344 struct hif_config_info cfg;
13345
13346 if (!scn)
13347 return;
13348
13349 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013350 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053013351 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070013352
13353 if (hdd_ctx->config->prevent_link_down)
13354 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053013355}
13356
13357/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013358 * hdd_update_dp_config() - Propagate config parameters to Lithium
13359 * datapath
13360 * @hdd_ctx: HDD Context
13361 *
13362 * Return: 0 for success/errno for failure
13363 */
13364static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
13365{
13366 struct cdp_config_params params;
13367 QDF_STATUS status;
13368
13369 params.tso_enable = hdd_ctx->config->tso_enable;
13370 params.lro_enable = hdd_ctx->config->lro_enable;
13371#ifdef QCA_LL_TX_FLOW_CONTROL_V2
13372 params.tx_flow_stop_queue_threshold =
13373 hdd_ctx->config->TxFlowStopQueueThreshold;
13374 params.tx_flow_start_queue_offset =
13375 hdd_ctx->config->TxFlowStartQueueOffset;
13376#endif
13377 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
13378 params.napi_enable = hdd_ctx->napi_enable;
13379 params.tcp_udp_checksumoffload =
13380 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
13381
13382 status = cdp_update_config_parameters(
13383 cds_get_context(QDF_MODULE_ID_SOC),
13384 &params);
13385 if (status) {
Dustin Browna2868622018-03-20 11:38:14 -070013386 hdd_err("Failed to attach config parameters");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013387 return status;
13388 }
13389
13390 return 0;
13391}
13392
13393/**
Komal Seelamec702b02016-02-24 18:42:16 +053013394 * hdd_update_config() - Initialize driver per module ini parameters
13395 * @hdd_ctx: HDD Context
13396 *
13397 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013398 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053013399 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013400int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053013401{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013402 int ret;
13403
Komal Seelamec702b02016-02-24 18:42:16 +053013404 hdd_update_ol_config(hdd_ctx);
13405 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013406 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
13407 ret = hdd_update_cds_config_ftm(hdd_ctx);
13408 else
13409 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080013410 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013411
13412 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053013413}
13414
Mukul Sharma9d797a02017-01-05 20:26:03 +053013415#ifdef FEATURE_WLAN_RA_FILTERING
13416/**
13417 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
13418 * @psoc_cfg: pmo psoc Configuration
13419 * @hdd_ctx: Pointer to hdd context
13420 *
13421 * Return: none
13422 */
13423static inline void hdd_ra_populate_pmo_config(
13424 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013425 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013426{
13427 psoc_cfg->ra_ratelimit_interval =
13428 hdd_ctx->config->RArateLimitInterval;
13429 psoc_cfg->ra_ratelimit_enable =
13430 hdd_ctx->config->IsRArateLimitEnabled;
13431}
13432#else
13433static inline void hdd_ra_populate_pmo_config(
13434 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013435 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013436{
13437}
13438#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080013439
Mukul Sharma9d797a02017-01-05 20:26:03 +053013440/**
13441 * hdd_update_pmo_config - API to update pmo configuration parameters
13442 * @hdd_ctx: HDD context
13443 *
13444 * Return: void
13445 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013446static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013447{
Mukul Sharma9d797a02017-01-05 20:26:03 +053013448 struct pmo_psoc_cfg psoc_cfg;
13449 QDF_STATUS status;
13450
13451 /*
13452 * Value of hdd_ctx->wowEnable can be,
13453 * 0 - Disable both magic pattern match and pattern byte match.
13454 * 1 - Enable magic pattern match on all interfaces.
13455 * 2 - Enable pattern byte match on all interfaces.
13456 * 3 - Enable both magic patter and pattern byte match on
13457 * all interfaces.
13458 */
13459 psoc_cfg.magic_ptrn_enable =
13460 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
13461 psoc_cfg.ptrn_match_enable_all_vdev =
13462 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Nachiket Kukadee547a482018-05-22 16:43:30 +053013463 psoc_cfg.apf_enable = hdd_ctx->config->apf_packet_filter_enable;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013464 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Nachiket Kukadef0804072018-02-27 18:20:07 +053013465 psoc_cfg.hw_filter_mode_bitmap = hdd_ctx->config->hw_filter_mode_bitmap;
Dustin Brownb9987af2018-03-01 17:15:11 -080013466 psoc_cfg.ns_offload_enable_dynamic = hdd_ctx->config->fhostNSOffload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013467 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
Dustin Brownb9987af2018-03-01 17:15:11 -080013468 psoc_cfg.packet_filter_enabled = !hdd_ctx->config->disablePacketFilter;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013469 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
13470 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
Dustin Brownb9987af2018-03-01 17:15:11 -080013471 psoc_cfg.active_mode_offload = hdd_ctx->config->active_mode_offload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013472 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080013473 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9223f232017-03-08 18:42:27 +053013474 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
13475 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
13476 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
Dustin Brownb9987af2018-03-01 17:15:11 -080013477 psoc_cfg.power_save_mode = hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053013478 psoc_cfg.auto_power_save_fail_mode =
13479 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013480
13481 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053013482 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013483
Dustin Brownb9987af2018-03-01 17:15:11 -080013484 status = ucfg_pmo_update_psoc_config(hdd_ctx->hdd_psoc, &psoc_cfg);
13485 if (QDF_IS_STATUS_ERROR(status))
13486 hdd_err("failed pmo psoc configuration; status:%d", status);
13487
13488 return qdf_status_to_os_return(status);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013489}
13490
Abhishek Singhb20db962017-03-03 21:28:46 +053013491#ifdef FEATURE_WLAN_SCAN_PNO
13492static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
13493 struct hdd_config *cfg)
13494{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070013495 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
13496
Abhishek Singhb20db962017-03-03 21:28:46 +053013497 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
13498 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
13499 pno_cfg->stationary_thresh = cfg->stationary_thresh;
13500 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
13501 pno_cfg->channel_prediction_full_scan =
13502 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070013503 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
13504 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
13505 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
13506 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053013507}
13508#else
13509static inline void
13510hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070013511 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053013512{
Abhishek Singhb20db962017-03-03 21:28:46 +053013513}
13514#endif
13515
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013516void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
13517 struct hdd_config *cfg)
13518{
13519 uint8_t i = 0;
13520
13521 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
13522 if (!ie_whitelist->white_list)
13523 return;
13524
13525 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
13526 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
13527 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
13528 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
13529 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
13530 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
13531 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
13532 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
13533
13534 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
13535 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
13536 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
13537}
13538
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013539uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
13540{
13541 uint8_t i, score;
13542
13543 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
13544 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
13545 if (score > MAX_INDEX_SCORE)
13546 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
13547 MAX_INDEX_SCORE, i);
13548 }
13549
13550 return per_index_score;
13551}
13552
13553/**
13554 * hdd_update_score_config - API to update candidate scoring related params
13555 * configuration parameters
13556 * @score_config: score config to update
13557 * @cfg: config params
13558 *
13559 * Return: 0 if success else err
13560 */
13561static void hdd_update_score_config(
13562 struct scoring_config *score_config, struct hdd_config *cfg)
13563{
13564 int total_weight;
13565
13566 score_config->weight_cfg.rssi_weightage = cfg->rssi_weightage;
13567 score_config->weight_cfg.ht_caps_weightage = cfg->ht_caps_weightage;
13568 score_config->weight_cfg.vht_caps_weightage =
13569 cfg->vht_caps_weightage;
13570 score_config->weight_cfg.he_caps_weightage =
13571 cfg->he_caps_weightage;
13572 score_config->weight_cfg.chan_width_weightage =
13573 cfg->chan_width_weightage;
13574 score_config->weight_cfg.chan_band_weightage =
13575 cfg->chan_band_weightage;
13576 score_config->weight_cfg.nss_weightage = cfg->nss_weightage;
13577 score_config->weight_cfg.beamforming_cap_weightage =
13578 cfg->beamforming_cap_weightage;
13579 score_config->weight_cfg.pcl_weightage = cfg->pcl_weightage;
13580 score_config->weight_cfg.channel_congestion_weightage =
13581 cfg->channel_congestion_weightage;
13582 score_config->weight_cfg.oce_wan_weightage = cfg->oce_wan_weightage;
13583
13584 total_weight = score_config->weight_cfg.rssi_weightage +
13585 score_config->weight_cfg.ht_caps_weightage +
13586 score_config->weight_cfg.vht_caps_weightage +
13587 score_config->weight_cfg.he_caps_weightage +
13588 score_config->weight_cfg.chan_width_weightage +
13589 score_config->weight_cfg.chan_band_weightage +
13590 score_config->weight_cfg.nss_weightage +
13591 score_config->weight_cfg.beamforming_cap_weightage +
13592 score_config->weight_cfg.pcl_weightage +
13593 score_config->weight_cfg.channel_congestion_weightage +
13594 score_config->weight_cfg.oce_wan_weightage;
13595
13596 if (total_weight > BEST_CANDIDATE_MAX_WEIGHT) {
13597 hdd_err("total weight is greater than %d fallback to default values",
13598 BEST_CANDIDATE_MAX_WEIGHT);
13599
13600 score_config->weight_cfg.rssi_weightage = RSSI_WEIGHTAGE;
13601 score_config->weight_cfg.ht_caps_weightage =
13602 HT_CAPABILITY_WEIGHTAGE;
13603 score_config->weight_cfg.vht_caps_weightage = VHT_CAP_WEIGHTAGE;
13604 score_config->weight_cfg.he_caps_weightage = HE_CAP_WEIGHTAGE;
13605 score_config->weight_cfg.chan_width_weightage =
13606 CHAN_WIDTH_WEIGHTAGE;
13607 score_config->weight_cfg.chan_band_weightage =
13608 CHAN_BAND_WEIGHTAGE;
13609 score_config->weight_cfg.nss_weightage = NSS_WEIGHTAGE;
13610 score_config->weight_cfg.beamforming_cap_weightage =
13611 BEAMFORMING_CAP_WEIGHTAGE;
13612 score_config->weight_cfg.pcl_weightage = PCL_WEIGHT;
13613 score_config->weight_cfg.channel_congestion_weightage =
13614 CHANNEL_CONGESTION_WEIGHTAGE;
13615 score_config->weight_cfg.oce_wan_weightage = OCE_WAN_WEIGHTAGE;
13616 }
13617
13618 score_config->bandwidth_weight_per_index =
13619 hdd_limit_max_per_index_score(
13620 cfg->bandwidth_weight_per_index);
13621 score_config->nss_weight_per_index =
13622 hdd_limit_max_per_index_score(cfg->nss_weight_per_index);
13623 score_config->band_weight_per_index =
13624 hdd_limit_max_per_index_score(cfg->band_weight_per_index);
13625
13626 score_config->rssi_score.best_rssi_threshold =
13627 cfg->best_rssi_threshold;
13628 score_config->rssi_score.good_rssi_threshold =
13629 cfg->good_rssi_threshold;
13630 score_config->rssi_score.bad_rssi_threshold =
13631 cfg->bad_rssi_threshold;
13632 score_config->rssi_score.good_rssi_pcnt = cfg->good_rssi_pcnt;
13633 score_config->rssi_score.bad_rssi_pcnt = cfg->bad_rssi_pcnt;
13634 score_config->rssi_score.good_rssi_bucket_size =
13635 cfg->good_rssi_bucket_size;
13636 score_config->rssi_score.bad_rssi_bucket_size =
13637 cfg->bad_rssi_bucket_size;
13638 score_config->rssi_score.rssi_pref_5g_rssi_thresh =
13639 cfg->rssi_pref_5g_rssi_thresh;
13640
13641 score_config->esp_qbss_scoring.num_slot = cfg->num_esp_qbss_slots;
13642 score_config->esp_qbss_scoring.score_pcnt3_to_0 =
13643 hdd_limit_max_per_index_score(
13644 cfg->esp_qbss_score_slots3_to_0);
13645 score_config->esp_qbss_scoring.score_pcnt7_to_4 =
13646 hdd_limit_max_per_index_score(
13647 cfg->esp_qbss_score_slots7_to_4);
13648 score_config->esp_qbss_scoring.score_pcnt11_to_8 =
13649 hdd_limit_max_per_index_score(
13650 cfg->esp_qbss_score_slots11_to_8);
13651 score_config->esp_qbss_scoring.score_pcnt15_to_12 =
13652 hdd_limit_max_per_index_score(
13653 cfg->esp_qbss_score_slots15_to_12);
13654
13655 score_config->oce_wan_scoring.num_slot = cfg->num_oce_wan_slots;
13656 score_config->oce_wan_scoring.score_pcnt3_to_0 =
13657 hdd_limit_max_per_index_score(
13658 cfg->oce_wan_score_slots3_to_0);
13659 score_config->oce_wan_scoring.score_pcnt7_to_4 =
13660 hdd_limit_max_per_index_score(
13661 cfg->oce_wan_score_slots7_to_4);
13662 score_config->oce_wan_scoring.score_pcnt11_to_8 =
13663 hdd_limit_max_per_index_score(
13664 cfg->oce_wan_score_slots11_to_8);
13665 score_config->oce_wan_scoring.score_pcnt15_to_12 =
13666 hdd_limit_max_per_index_score(
13667 cfg->oce_wan_score_slots15_to_12);
13668
13669
13670 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
13671 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
13672 score_config->nss = cfg->enable2x2 ? 2 : 1;
13673
13674 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
13675 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
13676 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
13677 score_config->he_cap = 1;
13678
13679 if (score_config->he_cap ||
13680 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
13681 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
13682 score_config->vht_cap = 1;
13683
13684 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
13685 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
13686 score_config->ht_cap = 1;
13687
13688 if (score_config->vht_cap && cfg->enableVhtFor24GHzBand)
13689 score_config->vht_24G_cap = 1;
13690
13691 if (cfg->enableTxBF)
13692 score_config->beamformee_cap = 1;
13693
13694}
13695
Abhishek Singh257a9482017-03-06 16:52:39 +053013696/**
bings81fe50a2017-11-27 14:33:26 +080013697 * hdd_update_dfs_config() - API to update dfs configuration parameters.
13698 * @hdd_ctx: HDD context
13699 *
13700 * Return: 0 if success else err
13701 */
13702static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
13703{
13704 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13705 struct hdd_config *cfg = hdd_ctx->config;
13706 struct dfs_user_config dfs_cfg;
13707 QDF_STATUS status;
13708
13709 dfs_cfg.dfs_is_phyerr_filter_offload = !!cfg->fDfsPhyerrFilterOffload;
13710 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
13711 if (QDF_IS_STATUS_ERROR(status)) {
13712 hdd_err("failed dfs psoc configuration");
13713 return -EINVAL;
13714 }
13715
13716 return 0;
13717}
13718
13719/**
Abhishek Singh257a9482017-03-06 16:52:39 +053013720 * hdd_update_scan_config - API to update scan configuration parameters
13721 * @hdd_ctx: HDD context
13722 *
13723 * Return: 0 if success else err
13724 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013725static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053013726{
13727 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13728 struct scan_user_cfg scan_cfg;
13729 struct hdd_config *cfg = hdd_ctx->config;
13730 QDF_STATUS status;
13731
13732 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
13733 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
13734 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
13735 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
13736 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
13737 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
13738 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053013739 /* convert to ms */
13740 scan_cfg.scan_cache_aging_time =
13741 cfg->scanAgingTimeout * 1000;
13742 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
13743 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
13744 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
13745 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053013746 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053013747 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080013748 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
13749 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053013750 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070013751 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singhc87bb042018-01-30 17:10:42 +053013752 scan_cfg.sta_miracast_mcc_rest_time =
13753 cfg->sta_miracast_mcc_rest_time_val;
Abhishek Singh257a9482017-03-06 16:52:39 +053013754
Abhishek Singhb20db962017-03-03 21:28:46 +053013755 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013756 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013757 hdd_update_score_config(&scan_cfg.score_config, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053013758
Abhishek Singh257a9482017-03-06 16:52:39 +053013759 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
13760 if (status != QDF_STATUS_SUCCESS) {
13761 hdd_err("failed pmo psoc configuration");
13762 return -EINVAL;
13763 }
13764
13765 return 0;
13766}
Abhishek Singh257a9482017-03-06 16:52:39 +053013767
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013768int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013769{
13770 int ret;
13771
13772 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053013773 if (ret)
13774 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013775
Abhishek Singh257a9482017-03-06 16:52:39 +053013776 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080013777 if (ret)
13778 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013779
Frank Liud4b2fa02017-03-29 11:46:48 +080013780 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013781 if (ret)
13782 return ret;
13783
13784 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080013785 if (ret)
13786 return ret;
13787
13788 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013789
13790 return ret;
13791}
13792
Agrawal Ashish65634612016-08-18 13:24:32 +053013793/**
13794 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
13795 * @mode : cfg80211 DFS mode
13796 *
13797 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
13798 */
13799enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
13800{
13801 switch (mode) {
13802 case DFS_MODE_ENABLE:
13803 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013804 case DFS_MODE_DISABLE:
13805 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013806 case DFS_MODE_DEPRIORITIZE:
13807 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013808 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013809 hdd_debug("ACS dfs mode is NONE");
13810 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013811 }
13812}
13813
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013814/**
13815 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
13816 * @hddctx: pointer to hdd context
13817 * @set_value: enable/disable
13818 *
13819 * When Host sends vendor command enable, FW will send *ONE* CA ind to
13820 * Host(even though it is duplicate). When Host send vendor command
13821 * disable,FW doesn't perform any action. Whenever any change in
13822 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
13823 *
13824 * return - 0 on success, appropriate error values on failure.
13825 */
Jeff Johnson16528362018-06-14 12:34:16 -070013826int hdd_enable_disable_ca_event(struct hdd_context *hdd_ctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013827{
13828 QDF_STATUS status;
13829
Jeff Johnson16528362018-06-14 12:34:16 -070013830 if (0 != wlan_hdd_validate_context(hdd_ctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013831 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013832
Jeff Johnson16528362018-06-14 12:34:16 -070013833 if (!hdd_ctx->config->goptimize_chan_avoid_event) {
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013834 hdd_warn("goptimize_chan_avoid_event ini param disabled");
13835 return -EINVAL;
13836 }
13837
Jeff Johnson16528362018-06-14 12:34:16 -070013838 status = sme_enable_disable_chanavoidind_event(hdd_ctx->mac_handle,
13839 set_value);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013840 if (!QDF_IS_STATUS_SUCCESS(status)) {
13841 hdd_err("Failed to send chan avoid command to SME");
13842 return -EINVAL;
13843 }
13844 return 0;
13845}
Agrawal Ashish65634612016-08-18 13:24:32 +053013846
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013847/**
13848 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
13849 * @value: value to set
13850 *
13851 * This function will set the passed value to roaming in progress flag.
13852 *
13853 * Return: None
13854 */
13855void hdd_set_roaming_in_progress(bool value)
13856{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013857 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013858
13859 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13860 if (!hdd_ctx) {
13861 hdd_err("HDD context is NULL");
13862 return;
13863 }
13864
13865 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013866 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013867}
13868
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053013869bool hdd_is_roaming_in_progress(struct hdd_context *hdd_ctx)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013870{
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013871 if (!hdd_ctx) {
13872 hdd_err("HDD context is NULL");
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053013873 return false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013874 }
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013875
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053013876 hdd_debug("roaming_in_progress = %d", hdd_ctx->roaming_in_progress);
13877
13878 return hdd_ctx->roaming_in_progress;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013879}
13880
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013881/**
13882 * hdd_is_connection_in_progress() - check if connection is in
13883 * progress
13884 * @session_id: session id
13885 * @reason: scan reject reason
13886 *
13887 * Go through each adapter and check if Connection is in progress
13888 *
13889 * Return: true if connection is in progress else false
13890 */
13891bool hdd_is_connection_in_progress(uint8_t *session_id,
13892 enum scan_reject_states *reason)
13893{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070013894 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070013895 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013896 uint8_t sta_id = 0;
13897 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013898 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -070013899 mac_handle_t mac_handle;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013900
13901 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13902 if (!hdd_ctx) {
13903 hdd_err("HDD context is NULL");
13904 return false;
13905 }
13906
Jeff Johnson16528362018-06-14 12:34:16 -070013907 mac_handle = hdd_ctx->mac_handle;
13908
Dustin Brown920397d2017-12-13 16:27:50 -080013909 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya929afa42018-06-01 15:04:44 -070013910 hdd_debug("Adapter with device mode %s(%d) exists",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013911 hdd_device_mode_to_string(adapter->device_mode),
13912 adapter->device_mode);
13913 if (((QDF_STA_MODE == adapter->device_mode)
13914 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
13915 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
13916 && (eConnectionState_Connecting ==
13917 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
13918 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013919 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013920 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013921 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013922 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013923 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013924 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013925 }
13926 return true;
13927 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013928 /*
13929 * sme_neighbor_middle_of_roaming is for LFR2
13930 * hdd_is_roaming_in_progress is for LFR3
13931 */
13932 if (((QDF_STA_MODE == adapter->device_mode) &&
13933 sme_neighbor_middle_of_roaming(
Jeff Johnson16528362018-06-14 12:34:16 -070013934 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013935 adapter->session_id)) ||
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053013936 hdd_is_roaming_in_progress(hdd_ctx)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013937 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013938 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013939 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013940 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013941 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013942 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013943 }
13944 return true;
13945 }
13946 if ((QDF_STA_MODE == adapter->device_mode) ||
13947 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
13948 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
13949 hdd_sta_ctx =
13950 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
13951 if ((eConnectionState_Associated ==
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053013952 hdd_sta_ctx->conn_info.connState)
13953 && sme_is_sta_key_exchange_in_progress(
Jeff Johnson16528362018-06-14 12:34:16 -070013954 mac_handle, adapter->session_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013955 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070013956 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013957 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013958 " is in middle of WPS/EAPOL exchange.",
13959 MAC_ADDR_ARRAY(sta_mac));
13960 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013961 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013962 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013963 }
13964 return true;
13965 }
13966 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
13967 (QDF_P2P_GO_MODE == adapter->device_mode)) {
13968 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
13969 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013970 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013971 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013972 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013973 continue;
13974
13975 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013976 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070013977 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013978 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013979 " of SAP/GO is in middle of WPS/EAPOL exchange",
13980 MAC_ADDR_ARRAY(sta_mac));
13981 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013982 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013983 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013984 }
13985 return true;
13986 }
13987 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013988 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013989 return true;
13990 }
13991 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013992 }
Dustin Brown920397d2017-12-13 16:27:50 -080013993
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013994 return false;
13995}
13996
13997/**
13998 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070013999 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014000 *
14001 * Return: None
14002 */
Jeff Johnson9d295242017-08-29 14:39:48 -070014003void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014004{
Jeff Johnson87251032017-08-29 13:31:11 -070014005 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070014006 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014007 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014008 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Jeff Johnsone4c11db2018-05-05 23:22:32 -070014009 tsap_config_t *sap_config;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014010 void *sap_ctx;
14011
14012 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070014013 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070014014 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014015
14016 mutex_lock(&hdd_ctx->sap_lock);
14017 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
14018 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014019 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
14020 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
14021 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
14022 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053014023 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014024 qdf_stop_bss_event,
14025 SME_CMD_TIMEOUT_VALUE);
14026
14027 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014028 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014029 goto end;
14030 }
14031 }
14032 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014033 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070014034 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070014035 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014036 false);
Jeff Johnson6867ec32017-09-29 20:30:20 -070014037 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014038
14039 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014040 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014041 wlansap_reset_sap_config_add_ie(sap_config,
14042 eUPDATE_IE_ALL);
14043 goto end;
14044 }
14045
14046 qdf_event_reset(&hostapd_state->qdf_event);
14047 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
14048 sap_config,
14049 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014050 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014051 wlansap_reset_sap_config_add_ie(sap_config,
14052 eUPDATE_IE_ALL);
14053 goto end;
14054 }
14055
Jeff Johnson6867ec32017-09-29 20:30:20 -070014056 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014057 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053014058 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014059 SME_CMD_TIMEOUT_VALUE);
14060 wlansap_reset_sap_config_add_ie(sap_config,
14061 eUPDATE_IE_ALL);
14062 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014063 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014064 goto end;
14065 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070014066 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014067 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014068 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014069 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
14070 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070014071 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070014072 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014073 ap_adapter->device_mode,
14074 true);
14075 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014076 }
14077end:
14078 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014079}
14080
14081/**
14082 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
14083 * with non dfs acs
14084 *
14085 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
14086 *
14087 * Return: None
14088 */
14089void hdd_check_and_restart_sap_with_non_dfs_acs(void)
14090{
Jeff Johnson9d295242017-08-29 14:39:48 -070014091 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014092 struct hdd_context *hdd_ctx;
Jeff Johnson2b6982c2018-05-29 14:56:11 -070014093 struct cds_context *cds_ctx;
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014094 uint8_t restart_chan;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014095
14096 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14097 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014098 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014099 return;
14100 }
14101
14102 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
14103 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014104 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014105 return;
14106 }
14107
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014108 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
14109 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Dustin Brown7e761c72018-07-31 13:50:17 -070014110 hdd_debug("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014111 return;
14112 }
14113
14114 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070014115 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
14116 &ap_adapter->event_flags) &&
14117 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070014118 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014119
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014120 hdd_warn("STA-AP Mode DFS not supported, Switch SAP channel to Non DFS");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014121
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014122 restart_chan =
14123 hdd_get_safe_channel_from_pcl_and_acs_range(ap_adapter);
14124 if (!restart_chan ||
14125 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev, restart_chan))
14126 restart_chan = SAP_DEFAULT_5GHZ_CHANNEL;
14127
14128 hdd_switch_sap_channel(ap_adapter, restart_chan, true);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014129 }
14130}
14131
14132/**
14133 * hdd_set_connection_in_progress() - to set the connection in
14134 * progress flag
14135 * @value: value to set
14136 *
14137 * This function will set the passed value to connection in progress flag.
14138 * If value is previously being set to true then no need to set it again.
14139 *
14140 * Return: true if value is being set correctly and false otherwise.
14141 */
14142bool hdd_set_connection_in_progress(bool value)
14143{
14144 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014145 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014146
14147 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14148 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014149 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014150 return false;
14151 }
14152
14153 qdf_spin_lock(&hdd_ctx->connection_status_lock);
14154 /*
14155 * if the value is set to true previously and if someone is
14156 * trying to make it true again then it could be some race
14157 * condition being triggered. Avoid this situation by returning
14158 * false
14159 */
14160 if (hdd_ctx->connection_in_progress && value)
14161 status = false;
14162 else
14163 hdd_ctx->connection_in_progress = value;
14164 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
14165 return status;
14166}
14167
Jeff Johnson9d295242017-08-29 14:39:48 -070014168int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014169{
14170 if (!adapter) {
14171 hdd_err("Invalid adapter");
14172 return -EINVAL;
14173 }
14174 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070014175 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014176 WMA_VDEV_MCC_SET_TIME_QUOTA,
14177 set_value, VDEV_CMD);
14178 return 0;
14179
14180}
14181
Jeff Johnson9d295242017-08-29 14:39:48 -070014182int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014183{
14184 if (!adapter) {
14185 hdd_err("Invalid adapter");
14186 return -EINVAL;
14187 }
14188
14189 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070014190 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014191 WMA_VDEV_MCC_SET_TIME_LATENCY,
14192 set_value, VDEV_CMD);
14193 return 0;
14194}
14195
Jeff Johnson9d295242017-08-29 14:39:48 -070014196struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070014197 *psoc, uint8_t vdev_id)
14198{
Jeff Johnson9d295242017-08-29 14:39:48 -070014199 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014200 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070014201
14202 /*
14203 * Currently PSOC is not being used. But this logic will
14204 * change once we have the converged implementation of
14205 * HDD context per PSOC in place. This would break if
14206 * multiple vdev objects reuse the vdev id.
14207 */
14208 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
14209 if (!adapter)
14210 hdd_err("Get adapter by vdev id failed");
14211
14212 return adapter;
14213}
14214
Jeff Johnson9d295242017-08-29 14:39:48 -070014215int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014216 int8_t *rssi, int8_t *snr)
14217{
14218 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -070014219 mac_handle_t mac_handle;
Jeff Johnson025618c2018-03-18 14:41:00 -070014220 struct csr_roam_profile *roam_profile;
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014221
Jeff Johnson025618c2018-03-18 14:41:00 -070014222 roam_profile = hdd_roam_profile(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -070014223 mac_handle = hdd_adapter_get_mac_handle(adapter);
14224 status = sme_get_rssi_snr_by_bssid(mac_handle,
Jeff Johnson025618c2018-03-18 14:41:00 -070014225 roam_profile, bssid, rssi, snr);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014226 if (QDF_STATUS_SUCCESS != status) {
14227 hdd_warn("sme_get_rssi_snr_by_bssid failed");
14228 return -EINVAL;
14229 }
14230
14231 return 0;
14232}
14233
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014234/**
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014235 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
14236 * @adapter - HDD adapter
14237 *
14238 * Return: 0 on success and non zero value on failure
14239 */
14240int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
14241{
14242 struct hdd_context *hdd_ctx;
14243 int ret;
14244 QDF_STATUS status;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014245
14246 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
14247 ret = wlan_hdd_validate_context(hdd_ctx);
14248 if (ret < 0)
14249 return ret;
14250
14251 /* set the system preferece to default */
14252 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
14253 hdd_ctx->config->conc_system_pref);
14254
14255 /* clear the bitmap */
14256 adapter->active_ac = 0;
14257
14258 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson16528362018-06-14 12:34:16 -070014259 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014260
Jeff Johnson16528362018-06-14 12:34:16 -070014261 status = sme_send_limit_off_channel_params(hdd_ctx->mac_handle,
14262 adapter->session_id,
14263 false, 0, 0, false);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014264 if (!QDF_IS_STATUS_SUCCESS(status)) {
14265 hdd_err("failed to reset limit off chan params");
14266 ret = -EINVAL;
14267 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014268
14269 return ret;
14270}
14271
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014272/**
14273 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
14274 * @drv_op: Enum indicating driver op
14275 *
14276 * Return: none
14277 */
14278void hdd_start_driver_ops_timer(int drv_op)
14279{
14280 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
14281 switch (drv_op) {
14282 case eHDD_DRV_OP_PROBE:
14283 memcpy(drv_ops_string, "probe", sizeof("probe"));
14284 break;
14285 case eHDD_DRV_OP_REMOVE:
14286 memcpy(drv_ops_string, "remove", sizeof("remove"));
14287 break;
14288 case eHDD_DRV_OP_SHUTDOWN:
14289 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
14290 break;
14291 case eHDD_DRV_OP_REINIT:
14292 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
14293 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053014294 case eHDD_DRV_OP_IFF_UP:
14295 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
14296 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014297 }
14298
Dustin Brown45ed4bb2017-12-18 12:00:13 -080014299 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014300 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
Dustin Browncfc54fe2018-06-18 16:17:41 -070014301 HDD_OPS_INACTIVITY_TIMEOUT * qdf_timer_get_multiplier());
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014302}
14303
14304/**
14305 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
14306 *
14307 * Return: none
14308 */
14309void hdd_stop_driver_ops_timer(void)
14310{
14311 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
14312}
14313
14314/**
14315 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
14316 * inactivity timer
14317 *
14318 * Return: None
14319 */
14320void hdd_drv_ops_inactivity_handler(void)
14321{
Rajeev Kumar4471f1b2018-06-08 14:18:28 -070014322 hdd_err("WLAN_BUG_RCA %s: %d Sec timer expired while in .%s",
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014323 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
14324
Dustin Brown45ed4bb2017-12-18 12:00:13 -080014325 if (hdd_drv_ops_task) {
14326 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
14327 qdf_print_thread_trace(hdd_drv_ops_task);
14328 } else {
14329 hdd_err("hdd_drv_ops_task is null");
14330 }
14331
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014332 /* Driver shutdown is stuck, no recovery possible at this point */
14333 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
14334 sizeof("shutdown")))
14335 QDF_BUG(0);
14336
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080014337 if (cds_is_fw_down()) {
14338 hdd_err("FW is down");
14339 return;
14340 }
14341
Dustin Brown83044c22018-08-13 15:00:44 -070014342 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014343}
14344
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053014345void hdd_pld_ipa_uc_shutdown_pipes(void)
14346{
14347 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14348
14349 if (!hdd_ctx)
14350 return;
14351
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +053014352 ucfg_ipa_uc_force_pipe_shutdown(hdd_ctx->hdd_pdev);
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053014353}
14354
Yun Parkff6a16a2017-09-26 16:38:18 -070014355/**
14356 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
14357 * @struct hdd_context *hdd_ctx
14358 * @struct hdd_adapter *padapter
14359 * @bool enble
14360 *
14361 * Return: none
14362 */
14363void hdd_set_rx_mode_rps(bool enable)
14364{
14365 struct cds_config_info *cds_cfg = cds_get_ini_config();
Ryan Hsu0e878fa2018-05-04 15:22:09 -070014366 struct hdd_context *hdd_ctx;
14367 struct hdd_adapter *adapter;
Yun Parkff6a16a2017-09-26 16:38:18 -070014368
Ryan Hsu0e878fa2018-05-04 15:22:09 -070014369 if (!cds_cfg)
14370 return;
14371
14372 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14373 if (!hdd_ctx)
14374 return;
14375
14376 adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
14377 if (!adapter)
14378 return;
14379
14380 if (!hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
Yun Parkff6a16a2017-09-26 16:38:18 -070014381 if (enable && !cds_cfg->rps_enabled)
14382 hdd_send_rps_ind(adapter);
14383 else if (!enable && cds_cfg->rps_enabled)
14384 hdd_send_rps_disable_ind(adapter);
14385 }
14386}
14387
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +053014388bool hdd_is_cli_iface_up(struct hdd_context *hdd_ctx)
14389{
14390 struct hdd_adapter *adapter = NULL;
14391
14392 hdd_for_each_adapter(hdd_ctx, adapter) {
14393 if ((adapter->device_mode == QDF_STA_MODE ||
14394 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
14395 qdf_atomic_test_bit(DEVICE_IFACE_OPENED,
14396 &adapter->event_flags)){
14397 return true;
14398 }
14399 }
14400
14401 return false;
14402}
14403
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014404/* Register the module init/exit functions */
14405module_init(hdd_module_init);
14406module_exit(hdd_module_exit);
14407
14408MODULE_LICENSE("Dual BSD/GPL");
14409MODULE_AUTHOR("Qualcomm Atheros, Inc.");
14410MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
14411
Srinivas Girigowda841da292018-02-21 16:33:00 -080014412static const struct kernel_param_ops con_mode_ops = {
14413 .set = con_mode_handler,
14414 .get = param_get_int,
14415};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014416
Srinivas Girigowda841da292018-02-21 16:33:00 -080014417static const struct kernel_param_ops con_mode_ftm_ops = {
14418 .set = con_mode_handler_ftm,
14419 .get = param_get_int,
14420};
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053014421
Nirav Shah73713f72018-05-17 14:50:41 +053014422#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080014423static const struct kernel_param_ops con_mode_monitor_ops = {
14424 .set = con_mode_handler_monitor,
14425 .get = param_get_int,
14426};
Nirav Shah73713f72018-05-17 14:50:41 +053014427#endif
Ravi Joshia307f632017-07-17 23:41:41 -070014428
Srinivas Girigowda841da292018-02-21 16:33:00 -080014429static const struct kernel_param_ops fwpath_ops = {
14430 .set = fwpath_changed_handler,
14431 .get = param_get_string,
14432};
14433
14434module_param_cb(con_mode, &con_mode_ops, &con_mode,
14435 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
14436
14437module_param_cb(con_mode_ftm, &con_mode_ftm_ops, &con_mode_ftm,
14438 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
14439
Nirav Shah73713f72018-05-17 14:50:41 +053014440#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080014441module_param_cb(con_mode_monitor, &con_mode_monitor_ops, &con_mode_monitor,
14442 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Nirav Shah73713f72018-05-17 14:50:41 +053014443#endif
Srinivas Girigowda841da292018-02-21 16:33:00 -080014444
14445module_param_cb(fwpath, &fwpath_ops, &fwpath,
14446 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014447
14448module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
14449
14450module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
14451
14452module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);