blob: 8be506b1b123c47050864c85feba36ef01489f2b [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,
Rajeev Kumar Sirasanagandlae3b59912018-08-24 15:53:31 +05306135 adapter->mac_addr.bytes,
6136 adapter->session_id);
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006137 if (status != QDF_STATUS_SUCCESS) {
6138 hdd_err("Status: %d Failed to create session.",
6139 status);
6140 return qdf_status_to_os_return(status);
6141 }
6142 }
Jeff Johnsond9952752018-04-18 12:15:35 -07006143 qdf_mem_copy(bssid.bytes, adapter->mac_addr.bytes,
6144 QDF_MAC_ADDR_SIZE);
6145
6146 ch_params.ch_width = bandwidth;
6147 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev, chan, 0, &ch_params);
6148 if (ch_params.ch_width == CH_WIDTH_INVALID) {
6149 hdd_err("Invalid capture channel or bandwidth for a country");
6150 return -EINVAL;
6151 }
6152 if (wlan_hdd_change_hw_mode_for_given_chnl(adapter, chan,
6153 POLICY_MGR_UPDATE_REASON_SET_OPER_CHAN)) {
6154 hdd_err("Failed to change hw mode");
6155 return -EINVAL;
6156 }
6157
Jeff Johnson16528362018-06-14 12:34:16 -07006158 status = sme_roam_channel_change_req(hdd_ctx->mac_handle,
6159 bssid, &ch_params,
Jeff Johnsond9952752018-04-18 12:15:35 -07006160 &roam_profile);
6161 if (status) {
6162 hdd_err("Status: %d Failed to set sme_roam Channel for monitor mode",
6163 status);
6164 }
6165
6166 adapter->mon_chan = chan;
6167 adapter->mon_bandwidth = bandwidth;
6168 return qdf_status_to_os_return(status);
6169}
Nirav Shah73713f72018-05-17 14:50:41 +05306170#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05306171
Wu Gaodf929f12018-05-25 18:12:25 +08006172#ifdef MSM_PLATFORM
6173/**
6174 * hdd_stop_p2p_go() - call cfg80211 API to stop P2P GO
6175 * @adapter: pointer to adapter
6176 *
6177 * This function calls cfg80211 API to stop P2P GO
6178 *
6179 * Return: None
6180 */
6181static void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6182{
6183 hdd_debug("[SSR] send stop ap to supplicant");
6184 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
6185}
6186
6187static inline void hdd_delete_sta(struct hdd_adapter *adapter)
6188{
6189}
6190#else
6191static inline void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6192{
6193}
6194
6195/**
6196 * hdd_delete_sta() - call cfg80211 API to delete STA
6197 * @adapter: pointer to adapter
6198 *
6199 * This function calls cfg80211 API to delete STA
6200 *
6201 * Return: None
6202 */
6203static void hdd_delete_sta(struct hdd_adapter *adapter)
6204{
6205 struct qdf_mac_addr bcast_mac = QDF_MAC_ADDR_BCAST_INIT;
6206
6207 hdd_debug("[SSR] send restart supplicant");
6208 /* event supplicant to restart */
6209 cfg80211_del_sta(adapter->dev,
6210 (const u8 *)&bcast_mac.bytes[0],
6211 GFP_KERNEL);
6212}
6213#endif
6214
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006215QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006216{
Jeff Johnson9d295242017-08-29 14:39:48 -07006217 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006218 eConnectionState connState;
6219
Dustin Brown491d54b2018-03-14 12:39:11 -07006220 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006221
Dustin Brown920397d2017-12-13 16:27:50 -08006222 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05306223 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08006224 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05306225
Yue Ma42654682018-01-11 16:55:24 -08006226 hdd_debug("[SSR] start adapter with device mode %s(%d)",
6227 hdd_device_mode_to_string(adapter->device_mode),
6228 adapter->device_mode);
6229
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006230 hdd_wmm_init(adapter);
6231
6232 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006233 case QDF_STA_MODE:
6234 case QDF_P2P_CLIENT_MODE:
6235 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006236
6237 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
6238 ->conn_info.connState;
6239
Krunal Sonib51eec72017-11-20 21:53:01 -08006240 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006241 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07006242 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006243
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006244 /* Indicate disconnect event to supplicant
6245 * if associated previously
6246 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006247 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07006248 eConnectionState_IbssConnected == connState ||
6249 eConnectionState_NotConnected == connState ||
6250 eConnectionState_IbssDisconnected == connState ||
6251 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006252 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006253
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006254 memset(&wrqu, '\0', sizeof(wrqu));
6255 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
6256 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
6257 wireless_send_event(adapter->dev, SIOCGIWAP,
6258 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07006259 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07006260 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006261
6262 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05306263 wlan_hdd_cfg80211_indicate_disconnect(
6264 adapter->dev, false,
6265 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006266 } else if (eConnectionState_Connecting == connState) {
6267 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006268 * Indicate connect failure to supplicant if we
6269 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006270 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306271 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306272 NULL, 0, NULL, 0,
6273 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006274 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006275 }
6276
6277 hdd_register_tx_flow_control(adapter,
6278 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08006279 hdd_tx_resume_cb,
6280 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006281
Arunk Khandavalli40943af2017-05-15 19:25:34 +05306282 hdd_lpass_notify_start(hdd_ctx, adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05306283 hdd_nud_ignore_tracking(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006284 break;
6285
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006286 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006287 if (hdd_ctx->config->sap_internal_restart)
Krunal Sonib51eec72017-11-20 21:53:01 -08006288 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05306289
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006290 break;
6291
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006292 case QDF_P2P_GO_MODE:
Wu Gaodf929f12018-05-25 18:12:25 +08006293 hdd_delete_sta(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006294 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306295 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08006296 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306297 hdd_set_mon_rx_cb(adapter->dev);
6298 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
6299 adapter->mon_bandwidth);
6300 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006301 default:
6302 break;
6303 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07006304 /*
6305 * Action frame registered in one adapter which will
6306 * applicable to all interfaces
6307 */
6308 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006309 }
6310
Wu Gaodf929f12018-05-25 18:12:25 +08006311 hdd_for_each_adapter(hdd_ctx, adapter) {
6312 if (!hdd_is_interface_up(adapter))
6313 continue;
6314
6315 if (adapter->device_mode == QDF_P2P_GO_MODE)
6316 hdd_stop_p2p_go(adapter);
6317 }
6318
Dustin Browne74003f2018-03-14 12:51:58 -07006319 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006320
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306321 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006322}
6323
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006324QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006325 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006326{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306327 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006328 qdf_list_node_t *node;
6329
6330 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006331
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006332 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006333 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006334 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006335
6336 if (QDF_IS_STATUS_ERROR(status))
6337 return status;
6338
6339 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6340
6341 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006342}
6343
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006344QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006345 struct hdd_adapter *current_adapter,
6346 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006347{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306348 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006349 qdf_list_node_t *node;
6350
6351 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006352
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006353 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006354 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08006355 &current_adapter->node,
6356 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006357 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006358
6359 if (QDF_IS_STATUS_ERROR(status))
6360 return status;
6361
6362 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6363
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006364 return status;
6365}
6366
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006367QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006368 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006369{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306370 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006371
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006372 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006373 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006374 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006375
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006376 return status;
6377}
6378
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006379QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006380 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006381{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306382 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006383 qdf_list_node_t *node;
6384
6385 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006386
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006387 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006388 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006389 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006390
6391 if (QDF_IS_STATUS_ERROR(status))
6392 return status;
6393
6394 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6395
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006396 return status;
6397}
6398
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006399QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006400 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006401{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306402 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006403
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006404 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006405 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006406 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006407
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006408 return status;
6409}
6410
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006411QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006412 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006413{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306414 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006415
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006416 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006417 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006418 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006419
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006420 return status;
6421}
6422
Jeff Johnson9d295242017-08-29 14:39:48 -07006423struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006424 tSirMacAddr macAddr)
6425{
Jeff Johnson9d295242017-08-29 14:39:48 -07006426 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006427
Dustin Brown920397d2017-12-13 16:27:50 -08006428 hdd_for_each_adapter(hdd_ctx, adapter) {
6429 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
6430 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006431 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006432 }
6433
6434 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006435}
6436
Jeff Johnson9d295242017-08-29 14:39:48 -07006437struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006438 uint32_t vdev_id)
6439{
Jeff Johnson9d295242017-08-29 14:39:48 -07006440 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006441
Dustin Brown920397d2017-12-13 16:27:50 -08006442 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07006443 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006444 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006445 }
6446
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006447 return NULL;
6448}
6449
Abhishek Singh7996eb72015-12-30 17:24:02 +05306450/**
6451 * hdd_get_adapter_by_sme_session_id() - Return adapter with
6452 * the sessionid
6453 * @hdd_ctx: hdd context.
6454 * @sme_session_id: sme session is for the adapter to get.
6455 *
6456 * This function is used to get the adapter with provided session id
6457 *
6458 * Return: adapter pointer if found
6459 *
6460 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07006461struct hdd_adapter *
6462hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
6463 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306464{
Jeff Johnson9d295242017-08-29 14:39:48 -07006465 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306466
Dustin Brown920397d2017-12-13 16:27:50 -08006467 hdd_for_each_adapter(hdd_ctx, adapter) {
6468 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306469 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306470 }
Dustin Brown920397d2017-12-13 16:27:50 -08006471
Abhishek Singh7996eb72015-12-30 17:24:02 +05306472 return NULL;
6473}
6474
Jeff Johnson9d295242017-08-29 14:39:48 -07006475struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07006476 const char *iface_name)
6477{
Jeff Johnson9d295242017-08-29 14:39:48 -07006478 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006479
Dustin Brown920397d2017-12-13 16:27:50 -08006480 hdd_for_each_adapter(hdd_ctx, adapter) {
6481 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07006482 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006483 }
Dustin Brown920397d2017-12-13 16:27:50 -08006484
Naveen Rawat4edb6822017-04-12 10:09:17 -07006485 return NULL;
6486}
6487
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006488/**
6489 * hdd_get_adapter() - to get adapter matching the mode
6490 * @hdd_ctx: hdd context
6491 * @mode: adapter mode
6492 *
6493 * This routine will return the pointer to adapter matching
6494 * with the passed mode.
6495 *
6496 * Return: pointer to adapter or null
6497 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006498struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006499 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006500{
Jeff Johnson9d295242017-08-29 14:39:48 -07006501 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006502
Dustin Brown920397d2017-12-13 16:27:50 -08006503 hdd_for_each_adapter(hdd_ctx, adapter) {
6504 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006505 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006506 }
6507
6508 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006509}
6510
Jeff Johnson36a0abf2018-05-20 11:24:25 -07006511enum QDF_OPMODE hdd_get_device_mode(uint32_t session_id)
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306512{
6513 struct hdd_context *hdd_ctx;
6514 struct hdd_adapter *adapter;
6515
6516 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
6517 if (!hdd_ctx) {
6518 hdd_err("Invalid HDD context");
6519 return QDF_MAX_NO_OF_MODE;
6520 }
6521
6522 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
6523 if (!adapter) {
6524 hdd_err("Invalid HDD adapter");
6525 return QDF_MAX_NO_OF_MODE;
6526 }
6527
6528 return adapter->device_mode;
6529}
6530
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006531/**
6532 * hdd_get_operating_channel() - return operating channel of the device mode
6533 * @hdd_ctx: Pointer to the HDD context.
6534 * @mode: Device mode for which operating channel is required.
Jeff Johnson77f89bb2018-05-06 16:21:36 -07006535 * Supported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006536 * QDF_STA_MODE,
6537 * QDF_P2P_CLIENT_MODE,
6538 * QDF_SAP_MODE,
6539 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006540 *
6541 * This API returns the operating channel of the requested device mode
6542 *
6543 * Return: channel number. "0" id the requested device is not found OR it is
6544 * not connected.
6545 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006546uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006547 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006548{
Jeff Johnson9d295242017-08-29 14:39:48 -07006549 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006550 uint8_t operatingChannel = 0;
6551
Dustin Brown920397d2017-12-13 16:27:50 -08006552 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006553 if (mode == adapter->device_mode) {
6554 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006555 case QDF_STA_MODE:
6556 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006557 if (hdd_conn_is_connected
6558 (WLAN_HDD_GET_STATION_CTX_PTR
6559 (adapter))) {
6560 operatingChannel =
6561 (WLAN_HDD_GET_STATION_CTX_PTR
6562 (adapter))->conn_info.
6563 operationChannel;
6564 }
6565 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006566 case QDF_SAP_MODE:
6567 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006568 /* softap connection info */
6569 if (test_bit
6570 (SOFTAP_BSS_STARTED,
6571 &adapter->event_flags))
6572 operatingChannel =
6573 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07006574 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006575 break;
6576 default:
6577 break;
6578 }
6579
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006580 /* Found the device of interest. break the loop */
6581 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006582 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006583 }
Dustin Brown920397d2017-12-13 16:27:50 -08006584
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006585 return operatingChannel;
6586}
6587
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006588static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006589 hdd_ctx)
6590{
Jeff Johnson9d295242017-08-29 14:39:48 -07006591 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006592
Dustin Brown491d54b2018-03-14 12:39:11 -07006593 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006594
Dustin Brown920397d2017-12-13 16:27:50 -08006595 hdd_for_each_adapter(hdd_ctx, adapter) {
6596 if (adapter->device_mode == QDF_STA_MODE ||
6597 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6598 adapter->device_mode == QDF_IBSS_MODE ||
6599 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6600 adapter->device_mode == QDF_SAP_MODE ||
6601 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006602 hdd_unregister_wext(adapter->dev);
6603 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006604 }
6605
Dustin Browne74003f2018-03-14 12:51:58 -07006606 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006607
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306608 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006609}
6610
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006611QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006612{
Jeff Johnson9d295242017-08-29 14:39:48 -07006613 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006614
Dustin Brown491d54b2018-03-14 12:39:11 -07006615 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006616
Dustin Brown920397d2017-12-13 16:27:50 -08006617 hdd_for_each_adapter(hdd_ctx, adapter) {
6618 if (adapter->device_mode == QDF_STA_MODE ||
6619 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6620 adapter->device_mode == QDF_IBSS_MODE ||
6621 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6622 adapter->device_mode == QDF_SAP_MODE ||
6623 adapter->device_mode == QDF_P2P_GO_MODE) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006624 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006625 adapter->session_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05306626 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006627 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006628 }
6629
Dustin Browne74003f2018-03-14 12:51:58 -07006630 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006631
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306632 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006633}
6634
Dustin Brownf27bce82016-11-03 12:52:27 -07006635/**
6636 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
6637 * adapters
6638 * @hdd_ctx: The HDD context containing the adapters to operate on
6639 *
6640 * return: QDF_STATUS_SUCCESS
6641 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006642static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07006643{
Jeff Johnson9d295242017-08-29 14:39:48 -07006644 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07006645 int err;
6646
Dustin Brown491d54b2018-03-14 12:39:11 -07006647 hdd_enter();
Dustin Brownf27bce82016-11-03 12:52:27 -07006648
Dustin Brown920397d2017-12-13 16:27:50 -08006649 hdd_for_each_adapter(hdd_ctx, adapter) {
6650 if (adapter->device_mode == QDF_STA_MODE ||
6651 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6652 adapter->device_mode == QDF_IBSS_MODE ||
6653 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6654 adapter->device_mode == QDF_SAP_MODE ||
6655 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07006656 err = wlan_hdd_sched_scan_stop(adapter->dev);
6657 if (err)
6658 hdd_err("Unable to stop scheduled scan");
6659 }
Dustin Brownf27bce82016-11-03 12:52:27 -07006660 }
6661
Dustin Browne74003f2018-03-14 12:51:58 -07006662 hdd_exit();
Dustin Brownf27bce82016-11-03 12:52:27 -07006663
6664 return QDF_STATUS_SUCCESS;
6665}
6666
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006667#ifdef WLAN_NS_OFFLOAD
6668/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006669 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006670 * @hdd_ctx: Pointer to hdd context
6671 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006672 * Unregister for IPv6 address change notifications.
6673 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006674 * Return: None
6675 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006676static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006677{
6678 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006679}
6680
6681/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006682 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006683 * @hdd_ctx: Pointer to hdd context
6684 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006685 * Register for IPv6 address change notifications.
6686 *
6687 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006688 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006689static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006690{
6691 int ret;
6692
6693 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
6694 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006695 if (ret) {
6696 hdd_err("Failed to register IPv6 notifier: %d", ret);
6697 goto out;
6698 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006699
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006700 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006701out:
6702 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006703}
6704#else
6705/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006706 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006707 * @hdd_ctx: Pointer to hdd context
6708 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006709 * Unregister for IPv6 address change notifications.
6710 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006711 * Return: None
6712 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006713static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006714{
6715}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006716
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006717/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006718 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006719 * @hdd_ctx: Pointer to hdd context
6720 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006721 * Register for IPv6 address change notifications.
6722 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006723 * Return: None
6724 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006725static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006726{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006727 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006728}
6729#endif
6730
Alok Kumarb64650c2018-03-23 17:05:11 +05306731void hdd_set_disconnect_status(struct hdd_adapter *adapter, bool status)
6732{
6733 qdf_mutex_acquire(&adapter->disconnection_status_lock);
6734 adapter->disconnection_in_progress = status;
6735 qdf_mutex_release(&adapter->disconnection_status_lock);
6736 hdd_debug("setting disconnection status: %d", status);
6737}
6738
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006739/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006740 * hdd_register_notifiers - Register netdev notifiers.
6741 * @hdd_ctx: HDD context
6742 *
6743 * Register netdev notifiers like IPv4 and IPv6.
6744 *
6745 * Return: 0 on success and errno on failure
6746 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006747static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006748{
6749 int ret;
6750
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006751 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
6752 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306753 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006754
6755 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
6756 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
6757 if (ret) {
6758 hdd_err("Failed to register IPv4 notifier: %d", ret);
6759 goto unregister_ip6_notifier;
6760 }
6761
Alok Kumarb64650c2018-03-23 17:05:11 +05306762 ret = hdd_nud_register_netevent_notifier(hdd_ctx);
6763 if (ret) {
6764 hdd_err("Failed to register netevent notifier: %d",
6765 ret);
6766 goto unregister_inetaddr_notifier;
6767 }
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006768 return 0;
6769
Alok Kumarb64650c2018-03-23 17:05:11 +05306770unregister_inetaddr_notifier:
6771 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006772unregister_ip6_notifier:
6773 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006774out:
6775 return ret;
6776
6777}
6778
6779/**
6780 * hdd_unregister_notifiers - Unregister netdev notifiers.
6781 * @hdd_ctx: HDD context
6782 *
6783 * Unregister netdev notifiers like IPv4 and IPv6.
6784 *
6785 * Return: None.
6786 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006787void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006788{
Alok Kumarb64650c2018-03-23 17:05:11 +05306789 hdd_nud_unregister_netevent_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006790 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
6791
6792 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006793}
6794
6795/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006796 * hdd_exit_netlink_services - Exit netlink services
6797 * @hdd_ctx: HDD context
6798 *
6799 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
6800 * nl service.
6801 *
6802 * Return: None.
6803 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006804static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006805{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306806 spectral_scan_deactivate_service();
6807 cnss_diag_deactivate_service();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006808 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006809 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306810 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006811
6812 nl_srv_exit();
6813}
6814
6815/**
6816 * hdd_init_netlink_services- Init netlink services
6817 * @hdd_ctx: HDD context
6818 *
6819 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
6820 * nl service.
6821 *
6822 * Return: 0 on success and errno on failure.
6823 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006824static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006825{
6826 int ret;
6827
Ryan Hsuceddceb2016-04-28 10:20:14 -07006828 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006829 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006830 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006831 goto out;
6832 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07006833 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006834
Naveen Rawat910726a2017-03-06 11:42:51 -08006835 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006836 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006837 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006838 goto err_nl_srv;
6839 }
6840
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306841 ptt_sock_activate_svc();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006842
6843 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07006844 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006845 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006846
6847 ret = cnss_diag_activate_service();
6848 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006849 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006850 goto err_close_cesium;
6851 }
6852
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306853 spectral_scan_activate_service();
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08006854
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006855 return 0;
6856
6857err_close_cesium:
6858 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006859 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306860 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006861err_nl_srv:
6862 nl_srv_exit();
6863out:
6864 return ret;
6865}
6866
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006867/**
6868 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
6869 * @hdd_ctx: HDD context.
6870 *
6871 * Destroy RX wakelock.
6872 *
6873 * Return: None.
6874 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006875static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006876{
6877 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
6878}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006879
6880/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006881 * hdd_rx_wake_lock_create() - Create RX wakelock
6882 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006883 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006884 * Create RX wakelock.
6885 *
6886 * Return: None.
6887 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006888static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006889{
6890 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
6891}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006892
6893/**
Houston Hoffman160db392016-10-10 17:37:51 -07006894 * hdd_context_deinit() - Deinitialize HDD context
6895 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006896 *
Houston Hoffman160db392016-10-10 17:37:51 -07006897 * Deinitialize HDD context along with all the feature specific contexts but
6898 * do not free hdd context itself. Caller of this API is supposed to free
6899 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006900 *
Houston Hoffman160db392016-10-10 17:37:51 -07006901 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006902 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006903static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006904{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306905 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
6906
Houston Hoffman160db392016-10-10 17:37:51 -07006907 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006908
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006909 hdd_sap_context_destroy(hdd_ctx);
6910
6911 hdd_rx_wake_lock_destroy(hdd_ctx);
6912
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006913 hdd_scan_context_destroy(hdd_ctx);
6914
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006915 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006916
Houston Hoffman160db392016-10-10 17:37:51 -07006917 return 0;
6918}
6919
6920/**
6921 * hdd_context_destroy() - Destroy HDD context
6922 * @hdd_ctx: HDD context to be destroyed.
6923 *
6924 * Free config and HDD context as well as destroy all the resources.
6925 *
6926 * Return: None
6927 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006928static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07006929{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07006930 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05306931
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05306932 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
6933
Houston Hoffman160db392016-10-10 17:37:51 -07006934 hdd_context_deinit(hdd_ctx);
6935
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306936 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006937 hdd_ctx->config = NULL;
6938
Dustin Brown84f46ea2018-02-15 11:57:36 -08006939 cfg_release();
6940
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006941 wiphy_free(hdd_ctx->wiphy);
6942}
6943
6944/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306945 * wlan_destroy_bug_report_lock() - Destroy bug report lock
6946 *
6947 * This function is used to destroy bug report lock
6948 *
6949 * Return: None
6950 */
6951static void wlan_destroy_bug_report_lock(void)
6952{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07006953 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306954
6955 p_cds_context = cds_get_global_context();
6956 if (!p_cds_context) {
6957 hdd_err("cds context is NULL");
6958 return;
6959 }
6960
6961 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6962}
6963
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05306964#ifdef DISABLE_CHANNEL_LIST
6965static void wlan_hdd_cache_chann_mutex_destroy(struct hdd_context *hdd_ctx)
6966{
6967 qdf_mutex_destroy(&hdd_ctx->cache_channel_lock);
6968}
6969#else
6970static void wlan_hdd_cache_chann_mutex_destroy(struct hdd_context *hdd_ctx)
6971{
6972}
6973#endif
6974
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306975/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006976 * hdd_wlan_exit() - HDD WLAN exit function
6977 * @hdd_ctx: Pointer to the HDD Context
6978 *
6979 * This is the driver exit point (invoked during rmmod)
6980 *
6981 * Return: None
6982 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006983static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006984{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006985 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306986 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006987
Dustin Brown491d54b2018-03-14 12:39:11 -07006988 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006989
Arun Khandavallifae92942016-08-01 13:31:08 +05306990 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006991
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006992#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306993 if (QDF_TIMER_STATE_RUNNING ==
6994 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6995 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006996 }
6997
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306998 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306999 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07007000 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007001 }
Liangwei Dongaef84342016-10-21 05:28:00 -04007002 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
7003 qdf_mem_free(hdd_ctx->last_acs_channel_list);
7004 hdd_ctx->last_acs_channel_list = NULL;
7005 hdd_ctx->num_of_channels = 0;
7006 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007007#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007008
Arun Khandavallifae92942016-08-01 13:31:08 +05307009 mutex_lock(&hdd_ctx->iface_change_lock);
7010 driver_status = hdd_ctx->driver_status;
7011 mutex_unlock(&hdd_ctx->iface_change_lock);
7012
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007013 /*
7014 * Powersave Offload Case
7015 * Disable Idle Power Save Mode
7016 */
7017 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07007018 /* clear the scan queue in all the scenarios */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +05307019 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007020
Arun Khandavallifae92942016-08-01 13:31:08 +05307021 if (driver_status != DRIVER_MODULES_CLOSED) {
7022 hdd_unregister_wext_all_adapters(hdd_ctx);
7023 /*
7024 * Cancel any outstanding scan requests. We are about to close
7025 * all of our adapters, but an adapter structure is what SME
7026 * passes back to our callback function. Hence if there
7027 * are any outstanding scan requests then there is a
7028 * race condition between when the adapter is closed and
7029 * when the callback is invoked. We try to resolve that
7030 * race condition here by canceling any outstanding scans
7031 * before we close the adapters.
7032 * Note that the scans may be cancelled in an asynchronous
7033 * manner, so ideally there needs to be some kind of
7034 * synchronization. Rather than introduce a new
7035 * synchronization here, we will utilize the fact that we are
7036 * about to Request Full Power, and since that is synchronized,
7037 * the expectation is that by the time Request Full Power has
7038 * completed, all scans will be cancelled
7039 */
7040 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07007041 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08007042 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08007043 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007044 }
7045
Arunk Khandavalli830c9692018-03-22 12:17:40 +05307046 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavalli08479ba2017-08-07 19:56:23 +05307047 unregister_netdevice_notifier(&hdd_netdev_notifier);
7048
Rachit Kankane30807332018-06-27 18:39:36 +05307049 qdf_dp_trace_deinit();
7050
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07007051 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05307052
Dustin Brown86d196b2018-08-02 11:51:49 -07007053 hdd_bus_bandwidth_deinit(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -08007054 hdd_driver_memdump_deinit();
7055
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05307056 qdf_nbuf_deinit_replenish_timer();
7057
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05307058 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
7059 hdd_info("Release wakelock for monitor mode!");
7060 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
7061 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
7062 }
7063
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307064 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
7065 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
7066 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +05307067 wlan_hdd_cache_chann_mutex_destroy(hdd_ctx);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307068
Naveen Rawate02f8f52018-04-05 11:58:04 -07007069 osif_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007070
Dustin Brownd005ad82018-01-19 10:32:13 -08007071 hdd_close_all_adapters(hdd_ctx, false);
7072
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05307073 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307074 /*
7075 * If there is re_init failure wiphy would have already de-registered
7076 * check the wiphy status before un-registering again
7077 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05307078 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307079 wiphy_unregister(wiphy);
7080 wlan_hdd_cfg80211_deinit(wiphy);
7081 hdd_lpass_notify_stop(hdd_ctx);
7082 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07007083
Arun Khandavallifae92942016-08-01 13:31:08 +05307084 hdd_exit_netlink_services(hdd_ctx);
7085 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307086#ifdef FEATURE_WLAN_CH_AVOID
7087 mutex_destroy(&hdd_ctx->avoid_freq_lock);
7088#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05307089
Abhishek Singhe9068f12017-03-31 14:14:52 +05307090 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
7091 if (driver_status)
7092 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07007093
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007094 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007095}
7096
7097void __hdd_wlan_exit(void)
7098{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007099 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007100
Dustin Brown491d54b2018-03-14 12:39:11 -07007101 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007102
Anurag Chouhan6d760662016-02-20 16:05:43 +05307103 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007104 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007105 hdd_err("Invalid HDD Context");
Dustin Browne74003f2018-03-14 12:51:58 -07007106 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007107 return;
7108 }
7109
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007110 /* Do all the cleanup before deregistering the driver */
7111 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07007112
Dustin Browne74003f2018-03-14 12:51:58 -07007113 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007114}
7115
7116#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04007117/**
7118 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007119 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04007120 *
7121 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
7122 * Then new ACS request will do a fresh scan without reusing the cached
7123 * scan information.
7124 *
7125 * Return: void
7126 */
Tang Yingying523322d2017-01-17 23:28:43 +08007127static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007128{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007129 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Jeff Johnson16528362018-06-14 12:34:16 -07007130 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007131
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007132 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007133 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04007134 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
7135 qdf_mem_free(hdd_ctx->last_acs_channel_list);
7136 hdd_ctx->last_acs_channel_list = NULL;
7137 hdd_ctx->num_of_channels = 0;
7138 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007139
Jeff Johnson16528362018-06-14 12:34:16 -07007140 mac_handle = hdd_ctx->mac_handle;
7141 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007142 return;
Jeff Johnson16528362018-06-14 12:34:16 -07007143 sme_scan_flush_result(mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007144}
7145#endif
7146
7147#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07007148int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
7149 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007150{
7151 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307152 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07007153 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07007154 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007155
7156 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7157
7158 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307159 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007160 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307161
Jeff Johnson16528362018-06-14 12:34:16 -07007162 mac_handle = hdd_ctx->mac_handle;
7163 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007164 return -EINVAL;
7165
Jeff Johnson16528362018-06-14 12:34:16 -07007166 qdf_status = sme_notify_ht2040_mode(mac_handle, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007167 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307168 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007169 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007170 return -EINVAL;
7171 }
7172
7173 return 0;
7174}
7175#endif
7176
7177/**
7178 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
7179 * @state: state
7180 *
7181 * This function notifies FW with modem power status
7182 *
7183 * Return: 0 if successful, error number otherwise
7184 */
7185int hdd_wlan_notify_modem_power_state(int state)
7186{
7187 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307188 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007189 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07007190 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007191
Anurag Chouhan6d760662016-02-20 16:05:43 +05307192 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007193 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307194 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007195 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307196
Jeff Johnson16528362018-06-14 12:34:16 -07007197 mac_handle = hdd_ctx->mac_handle;
7198 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007199 return -EINVAL;
7200
Jeff Johnson16528362018-06-14 12:34:16 -07007201 qdf_status = sme_notify_modem_power_state(mac_handle, state);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307202 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007203 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007204 state);
7205 return -EINVAL;
7206 }
7207 return 0;
7208}
7209
7210/**
7211 *
7212 * hdd_post_cds_enable_config() - HDD post cds start config helper
7213 * @adapter - Pointer to the HDD
7214 *
7215 * Return: None
7216 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007217QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007218{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307219 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007220
7221 /*
7222 * Send ready indication to the HDD. This will kick off the MAC
7223 * into a 'running' state and should kick off an initial scan.
7224 */
Jeff Johnson16528362018-06-14 12:34:16 -07007225 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->mac_handle);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307226 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007227 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
7228 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307229 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007230 }
7231
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307232 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007233}
7234
Sourav Mohapatra92ea8d62018-02-05 10:03:10 +05307235struct hdd_adapter *hdd_get_first_valid_adapter(struct hdd_context *hdd_ctx)
7236{
7237 struct hdd_adapter *adapter;
7238
7239 hdd_for_each_adapter(hdd_ctx, adapter) {
7240 if (adapter && adapter->magic == WLAN_HDD_ADAPTER_MAGIC)
7241 return adapter;
7242 }
7243
7244 return NULL;
7245}
7246
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007247/* wake lock APIs for HDD */
7248void hdd_prevent_suspend(uint32_t reason)
7249{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307250 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007251}
7252
7253void hdd_allow_suspend(uint32_t reason)
7254{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307255 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007256}
7257
7258void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
7259{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05307260 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
7261 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007262}
7263
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007264/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007265QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007266{
Jeff Johnson16528362018-06-14 12:34:16 -07007267 return sme_init_chan_list(hdd_ctx->mac_handle,
Amar Singhal6f8592b2017-04-26 14:31:58 -07007268 hdd_ctx->reg.alpha2,
7269 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007270}
7271
7272/**
7273 * hdd_is_5g_supported() - check if hardware supports 5GHz
7274 * @hdd_ctx: Pointer to the hdd context
7275 *
7276 * HDD function to know if hardware supports 5GHz
7277 *
7278 * Return: true if hardware supports 5GHz
7279 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007280bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007281{
Amar Singhal58b45ef2017-08-01 13:43:54 -07007282 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08007283 return true;
7284
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08007285 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08007286 return true;
7287 else
7288 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007289}
7290
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007291static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007292{
7293 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07007294 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007295
7296 wiphy = hdd_ctx->wiphy;
7297
7298 /*
7299 * The channel information in
7300 * wiphy needs to be initialized before wiphy registration
7301 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007302 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
7303 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007304 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07007305 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007306 }
7307
7308#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
7309 wiphy->wowlan = &wowlan_support_reg_init;
7310#else
7311 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
7312 WIPHY_WOWLAN_MAGIC_PKT |
7313 WIPHY_WOWLAN_DISCONNECT |
7314 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
7315 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
7316 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
7317 WIPHY_WOWLAN_4WAY_HANDSHAKE |
7318 WIPHY_WOWLAN_RFKILL_RELEASE;
7319
7320 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
7321 WOW_MAX_FILTERS_PER_LIST);
7322 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
7323 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
7324#endif
Liangwei Dong0da14262018-07-03 03:30:23 -04007325 if (hdd_ctx->obss_scan_offload) {
7326 hdd_debug("wmi_service_obss_scan supported");
7327 } else if (hdd_ctx->config->nChannelBondingMode24GHz) {
7328 hdd_debug("enable wpa_supp obss_scan");
7329 wiphy->features |= NL80211_FEATURE_NEED_OBSS_SCAN;
7330 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007331
7332 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007333 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307334 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07007335 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307336 return ret_val;
7337 }
Amar Singhalac26de22018-06-22 12:53:06 -07007338
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007339 /* Check the kernel version for upstream commit aced43ce780dc5 that
7340 * has support for processing user cell_base hints when wiphy is
7341 * self managed or check the backport flag for the same.
7342 */
Amar Singhalac26de22018-06-22 12:53:06 -07007343#if defined CFG80211_USER_HINT_CELL_BASE_SELF_MANAGED || \
7344 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0))
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007345 hdd_send_wiphy_regd_sync_event(hdd_ctx);
7346#endif
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307347
Amar Singhal2d812012018-02-03 15:06:47 +08007348 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007349
Amar Singhale4f28ee2015-10-21 14:36:56 -07007350 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007351}
7352
Mohit Khannaca4173b2017-09-12 21:52:19 -07007353#ifdef MSM_PLATFORM
7354/**
7355 * hdd_display_periodic_stats() - Function to display periodic stats
7356 * @hdd_ctx - handle to hdd context
7357 * @bool data_in_interval - true, if data detected in bw time interval
7358 *
7359 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
7360 * Stats show up in wlan driver logs.
7361 *
7362 * Returns: None
7363 */
Mohit Khanna70322002018-05-15 19:21:32 -07007364static void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
7365 bool data_in_interval)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007366{
Mohit Khanna70322002018-05-15 19:21:32 -07007367 static uint32_t counter;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007368 static bool data_in_time_period;
7369 ol_txrx_pdev_handle pdev;
7370
7371 if (hdd_ctx->config->periodic_stats_disp_time == 0)
7372 return;
7373
7374 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
7375 if (!pdev) {
7376 hdd_err("pdev is NULL");
7377 return;
7378 }
7379
7380 counter++;
7381 if (data_in_interval)
7382 data_in_time_period = data_in_interval;
7383
7384 if (counter * hdd_ctx->config->busBandwidthComputeInterval >=
7385 hdd_ctx->config->periodic_stats_disp_time * 1000) {
7386 if (data_in_time_period) {
Mohit Khanna70322002018-05-15 19:21:32 -07007387 wlan_hdd_display_txrx_stats(hdd_ctx);
7388 dp_txrx_dump_stats(cds_get_context(QDF_MODULE_ID_SOC));
7389 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
7390 CDP_RX_RING_STATS,
7391 QDF_STATS_VERBOSITY_LEVEL_LOW);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007392 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
7393 CDP_TXRX_PATH_STATS,
7394 QDF_STATS_VERBOSITY_LEVEL_LOW);
7395 wlan_hdd_display_netif_queue_history
7396 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
7397 qdf_dp_trace_dump_stats();
7398 }
7399 counter = 0;
7400 data_in_time_period = false;
7401 }
7402}
7403
Ravi Joshie2331e82015-07-01 18:18:54 -07007404/**
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007405 * hdd_clear_rps_cpu_mask - clear RPS CPU mask for interfaces
7406 * @hdd_ctx: pointer to struct hdd_context
7407 *
7408 * Return: none
7409 */
7410static void hdd_clear_rps_cpu_mask(struct hdd_context *hdd_ctx)
7411{
7412 struct hdd_adapter *adapter;
7413
7414 hdd_for_each_adapter(hdd_ctx, adapter)
7415 hdd_send_rps_disable_ind(adapter);
7416}
7417
7418/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07007419 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07007420 * @hdd_ctx - handle to hdd context
7421 * @tx_packets - transmit packet count
7422 * @rx_packets - receive packet count
7423 *
7424 * The function controls the bus bandwidth and dynamic control of
7425 * tcp delayed ack configuration
7426 *
7427 * Returns: None
7428 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007429
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007430static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07007431 const uint64_t tx_packets,
7432 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007433{
Mohit Khannaca4173b2017-09-12 21:52:19 -07007434 u64 total_pkts = tx_packets + rx_packets;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007435 uint64_t temp_tx = 0, avg_rx = 0;
7436 uint64_t no_rx_offload_pkts = 0, avg_no_rx_offload_pkts = 0;
7437 uint64_t rx_offload_pkts = 0, avg_rx_offload_pkts = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007438 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08007439 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08007440 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007441 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007442 uint16_t index = 0;
7443 bool vote_level_change = false;
7444 bool rx_level_change = false;
7445 bool tx_level_change = false;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007446 bool rxthread_high_tput_req = false;
Mohit Khannaf7562c32018-07-05 17:42:36 -07007447 bool dptrace_high_tput_req;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007448 if (total_pkts > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007449 next_vote_level = PLD_BUS_WIDTH_HIGH;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007450 else if (total_pkts > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007451 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007452 else if (total_pkts > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007453 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07007454 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07007455 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007456
Mohit Khannaf7562c32018-07-05 17:42:36 -07007457 dptrace_high_tput_req =
7458 next_vote_level > PLD_BUS_WIDTH_NONE ? true : false;
7459
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007460 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07007461 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
7462 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007463 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007464 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007465 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007466 if ((next_vote_level == PLD_BUS_WIDTH_LOW) ||
7467 (next_vote_level == PLD_BUS_WIDTH_NONE)) {
Nirav Shahffc6a092016-06-09 16:09:08 +05307468 if (hdd_ctx->hbw_requested) {
7469 pld_remove_pm_qos(hdd_ctx->parent_dev);
7470 hdd_ctx->hbw_requested = false;
7471 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007472 if (hdd_ctx->dynamic_rps)
7473 hdd_clear_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007474 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05307475 if (!hdd_ctx->hbw_requested) {
7476 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
7477 hdd_ctx->hbw_requested = true;
7478 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007479 if (hdd_ctx->dynamic_rps)
7480 hdd_set_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007481 }
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007482
Manjunathappa Prakashcb6df762018-05-29 18:54:58 -07007483 if (hdd_ctx->config->napi_cpu_affinity_mask)
7484 hdd_napi_apply_throughput_policy(hdd_ctx,
7485 tx_packets,
7486 rx_packets);
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007487
7488 if (rx_packets < hdd_ctx->config->busBandwidthLowThreshold)
7489 hdd_disable_rx_ol_for_low_tput(hdd_ctx, true);
7490 else
7491 hdd_disable_rx_ol_for_low_tput(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007492 }
Mohit Khannae71e2262015-11-10 09:37:24 -08007493
Mohit Khannaf7562c32018-07-05 17:42:36 -07007494 qdf_dp_trace_apply_tput_policy(dptrace_high_tput_req);
7495
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007496 /*
7497 * Includes tcp+udp, if perf core is required for tcp, then
7498 * perf core is also required for udp.
7499 */
7500 no_rx_offload_pkts = hdd_ctx->no_rx_offload_pkt_cnt;
7501 hdd_ctx->no_rx_offload_pkt_cnt = 0;
7502 rx_offload_pkts = rx_packets - no_rx_offload_pkts;
Mohit Khannae71e2262015-11-10 09:37:24 -08007503
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007504 avg_no_rx_offload_pkts = (no_rx_offload_pkts +
7505 hdd_ctx->prev_no_rx_offload_pkts) / 2;
7506 hdd_ctx->prev_no_rx_offload_pkts = no_rx_offload_pkts;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08007507
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007508 avg_rx_offload_pkts = (rx_offload_pkts +
7509 hdd_ctx->prev_rx_offload_pkts) / 2;
7510 hdd_ctx->prev_rx_offload_pkts = rx_offload_pkts;
7511
7512 avg_rx = avg_no_rx_offload_pkts + avg_rx_offload_pkts;
7513 /*
7514 * Takes care to set Rx_thread affinity for below case
7515 * 1)LRO/GRO not supported ROME case
7516 * 2)when rx_ol is disabled in cases like concurrency etc
7517 * 3)For UDP cases
7518 */
7519 if (avg_no_rx_offload_pkts >
7520 hdd_ctx->config->busBandwidthHighThreshold)
7521 rxthread_high_tput_req = true;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307522 else
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007523 rxthread_high_tput_req = false;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307524
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007525 if (cds_sched_handle_throughput_req(rxthread_high_tput_req))
7526 hdd_warn("Rx thread high_tput(%d) affinity request failed",
7527 rxthread_high_tput_req);
7528
7529 /* fine-tuning parameters for RX Flows */
7530 if (avg_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
Ravi Joshifed83572016-10-07 16:20:37 -07007531 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
7532 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
7533 next_rx_level = WLAN_SVC_TP_HIGH;
7534 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07007535 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07007536 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08007537 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007538 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007539
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007540 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007541 struct wlan_rx_tp_data rx_tp_data = {0};
7542
Ravi Joshie2331e82015-07-01 18:18:54 -07007543 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Jeff Johnsonb9feee42018-07-08 10:34:48 -07007544 next_rx_level, avg_rx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007545 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007546 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07007547 /* Send throughput indication only if it is enabled.
7548 * Disabling tcp_del_ack will revert the tcp stack behavior
7549 * to default delayed ack. Note that this will disable the
7550 * dynamic delayed ack mechanism across the system
7551 */
Manjunathappa Prakashbfd12762018-04-29 22:44:52 -07007552 if (hdd_ctx->en_tcp_delack_no_lro)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007553 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
7554
Mohit Khanna6272fb682017-04-13 09:34:36 -07007555 if (hdd_ctx->config->enable_tcp_adv_win_scale)
7556 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
7557
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007558 rx_tp_data.level = next_rx_level;
7559 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7560 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
7561 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007562 }
7563
Mohit Khannae71e2262015-11-10 09:37:24 -08007564 /* fine-tuning parameters for TX Flows */
7565 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
7566 hdd_ctx->prev_tx = tx_packets;
7567 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
7568 next_tx_level = WLAN_SVC_TP_HIGH;
7569 else
7570 next_tx_level = WLAN_SVC_TP_LOW;
7571
Prakash Manjunathappae73e3b52018-02-27 18:56:22 -08007572 if ((hdd_ctx->config->enable_tcp_limit_output) &&
7573 (hdd_ctx->cur_tx_level != next_tx_level)) {
Mohit Khannae71e2262015-11-10 09:37:24 -08007574 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
7575 next_tx_level, temp_tx);
7576 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007577 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05307578 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7579 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08007580 &next_tx_level,
7581 sizeof(next_tx_level));
7582 }
7583
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007584 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007585 if (vote_level_change || tx_level_change || rx_level_change) {
7586 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
7587 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
7588 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
7589 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
7590 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
7591 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
7592 hdd_ctx->hdd_txrx_hist_idx++;
7593 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
7594 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07007595
7596 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007597}
7598
7599#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Rajeev Kumarb2b5e692018-08-31 15:12:40 -07007600static void __hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007601{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007602 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307603 bus_bw_work);
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307604 struct hdd_adapter *adapter = NULL, *con_sap_adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307605 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05307606 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
7607 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007608 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307609 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007610 bool connected = false;
7611 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
7612
Dustin Brown35008ba2018-08-23 14:34:21 -07007613 hdd_enter();
7614
Prashanth Bhattaab004382016-10-11 16:08:11 -07007615 if (wlan_hdd_validate_context(hdd_ctx))
7616 return;
7617
Jeff Johnson214671b2017-10-30 19:45:23 -07007618 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08007619 goto restart_timer;
7620
Dustin Brown920397d2017-12-13 16:27:50 -08007621 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05307622 /*
7623 * Validate magic so we don't end up accessing
7624 * an invalid adapter.
7625 */
7626 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
7627 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007628
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007629 if ((adapter->device_mode == QDF_STA_MODE ||
7630 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007631 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
7632 != eConnectionState_Associated) {
7633
7634 continue;
7635 }
7636
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007637 if ((adapter->device_mode == QDF_SAP_MODE ||
7638 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07007639 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007640
7641 continue;
7642 }
7643
7644 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
7645 adapter->prev_tx_packets);
7646 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
7647 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307648
7649 if (adapter->device_mode == QDF_SAP_MODE ||
7650 adapter->device_mode == QDF_P2P_GO_MODE ||
7651 adapter->device_mode == QDF_IBSS_MODE) {
7652
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08007653 ret = cdp_get_intra_bss_fwd_pkts_count(
7654 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007655 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307656 &fwd_tx_packets, &fwd_rx_packets);
7657 if (ret == A_OK) {
7658 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
7659 fwd_tx_packets,
7660 adapter->prev_fwd_tx_packets);
7661 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
7662 fwd_tx_packets,
7663 adapter->prev_fwd_rx_packets);
7664 }
7665 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007666
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307667 if (adapter->device_mode == QDF_SAP_MODE)
7668 con_sap_adapter = adapter;
7669
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007670 total_rx += adapter->stats.rx_packets;
7671 total_tx += adapter->stats.tx_packets;
7672
7673 spin_lock_bh(&hdd_ctx->bus_bw_lock);
7674 adapter->prev_tx_packets = adapter->stats.tx_packets;
7675 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307676 adapter->prev_fwd_tx_packets = fwd_tx_packets;
7677 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007678 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
7679 connected = true;
7680 }
7681
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007682 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007683 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007684 return;
7685 }
7686
Yun Parka29974a2018-04-09 12:05:49 -07007687 /* add intra bss forwarded tx and rx packets */
7688 tx_packets += fwd_tx_packets_diff;
7689 rx_packets += fwd_rx_packets_diff;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007690
Yun Parka29974a2018-04-09 12:05:49 -07007691 if (ucfg_ipa_is_fw_wdi_activated(hdd_ctx->hdd_pdev)) {
7692 ucfg_ipa_uc_stat_query(hdd_ctx->hdd_pdev, &ipa_tx_packets,
7693 &ipa_rx_packets);
7694 tx_packets += (uint64_t)ipa_tx_packets;
7695 rx_packets += (uint64_t)ipa_rx_packets;
7696
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307697 if (con_sap_adapter) {
7698 con_sap_adapter->stats.tx_packets += ipa_tx_packets;
7699 con_sap_adapter->stats.rx_packets += ipa_rx_packets;
7700 }
7701
Yun Parka29974a2018-04-09 12:05:49 -07007702 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, tx_packets, rx_packets);
7703 ucfg_ipa_uc_stat_request(hdd_ctx->hdd_pdev, 2);
7704 }
7705
7706 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007707
Jingxiang Gec64e1932017-08-22 14:38:59 +08007708restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08007709 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08007710 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08007711 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05307712 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08007713 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08007714 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07007715
7716 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007717}
Prashanth Bhattaab004382016-10-11 16:08:11 -07007718
Rajeev Kumarb2b5e692018-08-31 15:12:40 -07007719static void hdd_bus_bw_work_handler(struct work_struct *work)
7720{
7721 cds_ssr_protect(__func__);
7722 __hdd_bus_bw_work_handler(work);
7723 cds_ssr_unprotect(__func__);
7724}
7725
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307726/**
7727 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
7728 * @arg: Argument of timer function
7729 *
7730 * Schedule a workqueue in this function where all the processing is done.
7731 *
7732 * Return: None.
7733 */
7734static void __hdd_bus_bw_cbk(void *arg)
7735{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007736 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307737
7738 if (wlan_hdd_validate_context(hdd_ctx))
7739 return;
7740
7741 schedule_work(&hdd_ctx->bus_bw_work);
7742}
7743
7744/**
7745 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
7746 * @arg: Argument of timer function
7747 *
7748 * Return: None.
7749 */
7750static void hdd_bus_bw_cbk(void *arg)
7751{
7752 cds_ssr_protect(__func__);
7753 __hdd_bus_bw_cbk(arg);
7754 cds_ssr_unprotect(__func__);
7755}
7756
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007757int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007758{
Dustin Brown35008ba2018-08-23 14:34:21 -07007759 hdd_enter();
7760
Prashanth Bhattaab004382016-10-11 16:08:11 -07007761 spin_lock_init(&hdd_ctx->bus_bw_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07007762 INIT_WORK(&hdd_ctx->bus_bw_work, hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08007763 hdd_ctx->bus_bw_timer_running = false;
7764 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07007765 qdf_timer_init(NULL, &hdd_ctx->bus_bw_timer, hdd_bus_bw_cbk,
7766 (void *)hdd_ctx, QDF_TIMER_TYPE_SW);
7767
7768 hdd_exit();
Prashanth Bhattaab004382016-10-11 16:08:11 -07007769
7770 return 0;
7771}
7772
Dustin Brown86d196b2018-08-02 11:51:49 -07007773void hdd_bus_bandwidth_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007774{
Dustin Brown35008ba2018-08-23 14:34:21 -07007775 hdd_enter();
Prashanth Bhattaab004382016-10-11 16:08:11 -07007776
Rajeev Kumarc27efb62018-08-31 14:21:22 -07007777 QDF_BUG(!hdd_ctx->bus_bw_timer_running);
Dustin Brown35008ba2018-08-23 14:34:21 -07007778
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307779 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08007780 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown35008ba2018-08-23 14:34:21 -07007781
7782 hdd_exit();
Prashanth Bhattaab004382016-10-11 16:08:11 -07007783}
Lin Baic5c06882017-09-21 13:58:43 +08007784
Dustin Brown35008ba2018-08-23 14:34:21 -07007785#endif /* MSM_PLATFORM */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007786
7787/**
Nirav Shahed34b212016-04-25 10:59:16 +05307788 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
7789 * @hdd_ctx: hdd context
7790 *
7791 * Return: 0 for success or error code
7792 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007793static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307794{
7795 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
7796 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
7797 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007798 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05307799 return -ENOMEM;
7800 }
7801 return 0;
7802}
7803
7804/**
7805 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
7806 * @hdd_ctx: hdd context
7807 *
7808 * Return: none
7809 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007810void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307811{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307812 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
7813 return;
7814
7815 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
7816 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05307817}
7818
Nirav Shahda008342016-05-17 18:50:40 +05307819static uint8_t *convert_level_to_string(uint32_t level)
7820{
7821 switch (level) {
7822 /* initialize the wlan sub system */
7823 case WLAN_SVC_TP_NONE:
7824 return "NONE";
7825 case WLAN_SVC_TP_LOW:
7826 return "LOW";
7827 case WLAN_SVC_TP_MEDIUM:
7828 return "MED";
7829 case WLAN_SVC_TP_HIGH:
7830 return "HIGH";
7831 default:
7832 return "INVAL";
7833 }
7834}
7835
Nirav Shahed34b212016-04-25 10:59:16 +05307836
7837/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007838 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
7839 * @hdd_ctx: hdd context
7840 *
7841 * Return: none
7842 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007843void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007844{
7845 int i;
7846
7847#ifdef MSM_PLATFORM
Nirav Shahe6194ac2018-07-13 11:04:41 +05307848 hdd_nofl_info("BW compute Interval: %dms",
7849 hdd_ctx->config->busBandwidthComputeInterval);
7850 hdd_nofl_info("BW High TH: %d BW Med TH: %d BW Low TH: %d",
7851 hdd_ctx->config->busBandwidthHighThreshold,
7852 hdd_ctx->config->busBandwidthMediumThreshold,
7853 hdd_ctx->config->busBandwidthLowThreshold);
7854 hdd_nofl_info("Enable TCP DEL ACK: %d",
7855 hdd_ctx->en_tcp_delack_no_lro);
7856 hdd_nofl_info("TCP DEL High TH: %d TCP DEL Low TH: %d",
7857 hdd_ctx->config->tcpDelackThresholdHigh,
7858 hdd_ctx->config->tcpDelackThresholdLow);
7859 hdd_nofl_info("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
7860 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007861#endif
7862
Nirav Shahe6194ac2018-07-13 11:04:41 +05307863 hdd_nofl_info("Total entries: %d Current index: %d",
7864 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
Nirav Shahda008342016-05-17 18:50:40 +05307865
Nirav Shahe6194ac2018-07-13 11:04:41 +05307866 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 -08007867
7868 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007869 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007870 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Nirav Shahe6194ac2018-07-13 11:04:41 +05307871 hdd_nofl_info("[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
7872 i, hdd_ctx->hdd_txrx_hist[i].qtime,
7873 hdd_ctx->hdd_txrx_hist[i].interval_rx,
7874 hdd_ctx->hdd_txrx_hist[i].interval_tx,
7875 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007876 hdd_ctx->hdd_txrx_hist[i].
7877 next_vote_level),
Nirav Shahe6194ac2018-07-13 11:04:41 +05307878 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007879 hdd_ctx->hdd_txrx_hist[i].
7880 next_rx_level),
Nirav Shahe6194ac2018-07-13 11:04:41 +05307881 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007882 hdd_ctx->hdd_txrx_hist[i].
7883 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007884 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007885}
7886
7887/**
7888 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
7889 * @hdd_ctx: hdd context
7890 *
7891 * Return: none
7892 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007893void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007894{
7895 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05307896 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
7897 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007898}
7899
Mohit Khannaca4173b2017-09-12 21:52:19 -07007900/* length of the netif queue log needed per adapter */
7901#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
7902
7903/**
7904 *
7905 * hdd_display_netif_queue_history_compact() - display compact netifq history
7906 * @hdd_ctx: hdd context
7907 *
7908 * Return: none
7909 */
7910static void
7911hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
7912{
7913 int adapter_num = 0;
7914 int i;
7915 int bytes_written;
7916 u32 tbytes;
7917 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007918 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08007919 char *comb_log_str;
7920 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007921 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007922
Dustin Brownbee82832018-07-23 10:10:51 -07007923 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * CSR_ROAM_SESSION_MAX) + 1;
jiadbdefb252018-01-03 14:27:06 +08007924 comb_log_str = qdf_mem_malloc(comb_log_str_size);
7925 if (!comb_log_str) {
7926 hdd_err("failed to alloc comb_log_str");
7927 return;
7928 }
7929
Mohit Khannaca4173b2017-09-12 21:52:19 -07007930 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007931
Dustin Brown920397d2017-12-13 16:27:50 -08007932 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007933 curr_time = qdf_system_ticks();
7934 total = curr_time - adapter->start_time;
7935 delta = curr_time - adapter->last_time;
7936
7937 if (adapter->pause_map) {
7938 pause = adapter->total_pause_time + delta;
7939 unpause = adapter->total_unpause_time;
7940 } else {
7941 unpause = adapter->total_unpause_time + delta;
7942 pause = adapter->total_pause_time;
7943 }
7944
7945 tbytes = 0;
7946 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7947 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7948 if (adapter->queue_oper_stats[i].pause_count == 0)
7949 continue;
7950 tbytes +=
7951 snprintf(
7952 &temp_str[tbytes],
7953 (tbytes >= sizeof(temp_str) ?
7954 0 : sizeof(temp_str) - tbytes),
7955 "%d(%d,%d) ",
7956 i,
7957 adapter->queue_oper_stats[i].
7958 pause_count,
7959 adapter->queue_oper_stats[i].
7960 unpause_count);
7961 }
7962 if (tbytes >= sizeof(temp_str))
7963 hdd_warn("log truncated");
7964
7965 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08007966 bytes_written >= comb_log_str_size ? 0 :
7967 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007968 "[%d %d] (%d) %u/%ums %s|",
7969 adapter->session_id, adapter->device_mode,
7970 adapter->pause_map,
7971 qdf_system_ticks_to_msecs(pause),
7972 qdf_system_ticks_to_msecs(total),
7973 temp_str);
7974
Mohit Khannaca4173b2017-09-12 21:52:19 -07007975 adapter_num++;
7976 }
7977
7978 /* using QDF_TRACE to avoid printing function name */
7979 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
7980 "STATS |%s", comb_log_str);
7981
jiadbdefb252018-01-03 14:27:06 +08007982 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007983 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08007984
7985 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007986}
7987
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007988/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007989 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07007990 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007991 *
7992 * Return: none
7993 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007994void
7995wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
7996 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007997{
7998
Jeff Johnson9d295242017-08-29 14:39:48 -07007999 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008000 int i;
Nirav Shahda008342016-05-17 18:50:40 +05308001 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008002
Mohit Khannaca4173b2017-09-12 21:52:19 -07008003 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
8004 hdd_display_netif_queue_history_compact(hdd_ctx);
8005 return;
8006 }
8007
Dustin Brown920397d2017-12-13 16:27:50 -08008008 hdd_for_each_adapter(hdd_ctx, adapter) {
Nirav Shahe6194ac2018-07-13 11:04:41 +05308009 hdd_nofl_info("Netif queue operation statistics:");
8010 hdd_nofl_info("Session_id %d device mode %d",
8011 adapter->session_id, adapter->device_mode);
8012 hdd_nofl_info("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05308013 curr_time = qdf_system_ticks();
8014 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05308015 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05308016 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05308017 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05308018 unpause = adapter->total_unpause_time;
8019 } else {
Nirav Shahda008342016-05-17 18:50:40 +05308020 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05308021 pause = adapter->total_pause_time;
8022 }
Nirav Shahe6194ac2018-07-13 11:04:41 +05308023 hdd_nofl_info("Total: %ums Pause: %ums Unpause: %ums",
8024 qdf_system_ticks_to_msecs(total),
8025 qdf_system_ticks_to_msecs(pause),
8026 qdf_system_ticks_to_msecs(unpause));
8027 hdd_nofl_info("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008028
Nirav Shahda008342016-05-17 18:50:40 +05308029 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
8030 qdf_time_t pause_delta = 0;
8031
8032 if (adapter->pause_map & (1 << i))
8033 pause_delta = delta;
8034
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008035 /* using hdd_log to avoid printing function name */
Nirav Shahe6194ac2018-07-13 11:04:41 +05308036 hdd_nofl_info("%s: %d: %d: %ums",
8037 hdd_reason_type_to_string(i),
8038 adapter->queue_oper_stats[i].pause_count,
8039 adapter->queue_oper_stats[i].
8040 unpause_count,
8041 qdf_system_ticks_to_msecs(
8042 adapter->queue_oper_stats[i].
8043 total_pause_time + pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008044 }
8045
Nirav Shahe6194ac2018-07-13 11:04:41 +05308046 hdd_nofl_info("Netif queue operation history:");
8047 hdd_nofl_info("Total entries: %d current index %d",
8048 WLAN_HDD_MAX_HISTORY_ENTRY,
8049 adapter->history_index);
Nirav Shahda008342016-05-17 18:50:40 +05308050
Nirav Shahe6194ac2018-07-13 11:04:41 +05308051 hdd_nofl_info("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008052
8053 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008054 /* using hdd_log to avoid printing function name */
8055 if (adapter->queue_oper_history[i].time == 0)
8056 continue;
Nirav Shahe6194ac2018-07-13 11:04:41 +05308057 hdd_nofl_info("%d: %u: %s: %s: %x",
8058 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008059 adapter->queue_oper_history[i].time),
Nirav Shahe6194ac2018-07-13 11:04:41 +05308060 hdd_action_type_to_string(
8061 adapter->queue_oper_history[i].
8062 netif_action),
8063 hdd_reason_type_to_string(
8064 adapter->queue_oper_history[i].
8065 netif_reason),
8066 adapter->queue_oper_history[i].pause_map);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008067 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008068 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008069}
8070
8071/**
8072 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
8073 * @hdd_ctx: hdd context
8074 *
8075 * Return: none
8076 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008077void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008078{
Jeff Johnson9d295242017-08-29 14:39:48 -07008079 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008080
Dustin Brown920397d2017-12-13 16:27:50 -08008081 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308082 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008083 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308084 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008085 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05308086 adapter->history_index = 0;
8087 adapter->start_time = adapter->last_time = qdf_system_ticks();
8088 adapter->total_pause_time = 0;
8089 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008090 }
8091}
8092
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008093#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
8094/**
8095 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
8096 * @hdd_ctx: hdd global context
8097 *
8098 * Return: none
8099 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008100static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008101{
8102 uint8_t i;
8103
8104 mutex_init(&hdd_ctx->op_ctx.op_lock);
8105 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
8106 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
8107 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
8108 }
8109}
8110#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008111static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008112{
8113}
8114#endif
8115
Yingying Tang95409972016-10-20 15:16:15 +08008116#ifdef WLAN_FEATURE_WOW_PULSE
8117/**
8118 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008119 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08008120 * @enable: enable or disable this behaviour
8121 *
8122 * Return: int
8123 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008124static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008125{
8126 struct hdd_config *pcfg_ini = phddctx->config;
8127 struct wow_pulse_mode wow_pulse_set_info;
8128 QDF_STATUS status;
8129
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008130 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08008131
8132 if (false == phddctx->config->wow_pulse_support)
8133 return 0;
8134
8135 /* prepare the request to send to SME */
8136 if (enable == true) {
8137 wow_pulse_set_info.wow_pulse_enable = true;
8138 wow_pulse_set_info.wow_pulse_pin =
8139 pcfg_ini->wow_pulse_pin;
8140 wow_pulse_set_info.wow_pulse_interval_low =
8141 pcfg_ini->wow_pulse_interval_low;
8142 wow_pulse_set_info.wow_pulse_interval_high =
8143 pcfg_ini->wow_pulse_interval_high;
8144 } else {
8145 wow_pulse_set_info.wow_pulse_enable = false;
8146 wow_pulse_set_info.wow_pulse_pin = 0;
8147 wow_pulse_set_info.wow_pulse_interval_low = 0;
8148 wow_pulse_set_info.wow_pulse_interval_high = 0;
8149 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008150 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08008151 wow_pulse_set_info.wow_pulse_enable,
8152 wow_pulse_set_info.wow_pulse_pin,
8153 wow_pulse_set_info.wow_pulse_interval_low,
8154 wow_pulse_set_info.wow_pulse_interval_high);
8155
8156 status = sme_set_wow_pulse(&wow_pulse_set_info);
8157 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008158 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08008159 return -EIO;
8160 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008161 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08008162 return 0;
8163}
8164#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008165static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008166{
8167 return 0;
8168}
8169#endif
8170
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008171#ifdef WLAN_FEATURE_FASTPATH
8172/**
8173 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
8174 * @hdd_cfg: hdd config
8175 * @context: lower layer context
8176 *
8177 * Return: none
8178 */
Arun Khandavallifae92942016-08-01 13:31:08 +05308179void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008180 void *context)
8181{
8182 if (hdd_cfg->fastpath_enable)
8183 hif_enable_fastpath(context);
8184}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008185#endif
8186
Yuanyuan Liu13738502016-04-06 17:41:37 -07008187#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008188/**
8189 * hdd_set_thermal_level_cb() - set thermal level callback function
Jeff Johnson0e963082018-07-04 19:39:20 -07008190 * @hdd_handle: opaque handle for the hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008191 * @level: thermal level
8192 *
8193 * Change IPA data path to SW path when the thermal throttle level greater
8194 * than 0, and restore the original data path when throttle level is 0
8195 *
8196 * Return: none
8197 */
Jeff Johnson0e963082018-07-04 19:39:20 -07008198static void hdd_set_thermal_level_cb(hdd_handle_t hdd_handle, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008199{
Jeff Johnson0e963082018-07-04 19:39:20 -07008200 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008201
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008202 /* Change IPA to SW path when throttle level greater than 0 */
8203 if (level > THROTTLE_LEVEL_0)
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308204 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008205 else
8206 /* restore original concurrency mode */
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308207 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, hdd_ctx->mcc_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008208}
8209
8210/**
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308211 * hdd_get_safe_channel() - Get safe channel from current regulatory
8212 * @hdd_ctx: pointer to hdd context
8213 * @adapter: pointer to softap adapter
8214 *
8215 * This function is used to get safe channel from current regulatory valid
8216 * channels to restart SAP if failed to get safe channel from PCL.
8217 *
8218 * Return: Channel number to restart SAP in case of success. In case of any
8219 * failure, the channel number returned is zero.
8220 */
8221static uint8_t
8222hdd_get_safe_channel(struct hdd_context *hdd_ctx,
8223 struct hdd_adapter *adapter)
8224{
8225 struct sir_pcl_list pcl = {0};
8226 uint32_t i, j;
8227 bool found = false;
8228 int ret;
8229
8230 /* Try for safe channel from all valid channel */
8231 pcl.pcl_len = MAX_NUM_CHAN;
8232 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
8233 &pcl.pcl_len);
8234 if (ret) {
8235 hdd_err("error %d in getting valid channel list", ret);
8236 return INVALID_CHANNEL_ID;
8237 }
8238
8239 for (i = 0; i < pcl.pcl_len; i++) {
8240 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
8241 found = false;
8242 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
8243 if (pcl.pcl_list[i] ==
8244 hdd_ctx->unsafe_channel_list[j]) {
8245 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
8246 found = true;
8247 break;
8248 }
8249 }
8250
8251 if (found)
8252 continue;
8253
8254 if ((pcl.pcl_list[i] >=
8255 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
8256 (pcl.pcl_list[i] <=
8257 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
8258 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
8259 return pcl.pcl_list[i];
8260 }
8261 }
8262
8263 return INVALID_CHANNEL_ID;
8264}
8265
8266#else
8267/**
8268 * hdd_set_thermal_level_cb() - set thermal level callback function
8269 * @hdd_handle: opaque handle for the hdd context
8270 * @level: thermal level
8271 *
8272 * Change IPA data path to SW path when the thermal throttle level greater
8273 * than 0, and restore the original data path when throttle level is 0
8274 *
8275 * Return: none
8276 */
8277static void hdd_set_thermal_level_cb(hdd_handle_t hdd_handle, u_int8_t level)
8278{
8279}
8280
8281/**
8282 * hdd_get_safe_channel() - Get safe channel from current regulatory
8283 * @hdd_ctx: pointer to hdd context
8284 * @adapter: pointer to softap adapter
8285 *
8286 * This function is used to get safe channel from current regulatory valid
8287 * channels to restart SAP if failed to get safe channel from PCL.
8288 *
8289 * Return: Channel number to restart SAP in case of success. In case of any
8290 * failure, the channel number returned is zero.
8291 */
8292static uint8_t
8293hdd_get_safe_channel(struct hdd_context *hdd_ctx,
8294 struct hdd_adapter *adapter)
8295{
8296 return 0;
8297}
8298#endif
8299
8300/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308301 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
8302 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05308303 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008304 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308305 * Get a safe channel to restart SAP. PCL already takes into account the
8306 * unsafe channels. So, the PCL is validated with the ACS range to provide
8307 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008308 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308309 * Return: Channel number to restart SAP in case of success. In case of any
8310 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008311 */
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308312static uint8_t
8313hdd_get_safe_channel_from_pcl_and_acs_range(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008314{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308315 struct sir_pcl_list pcl;
8316 QDF_STATUS status;
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308317 uint32_t i;
Jeff Johnson16528362018-06-14 12:34:16 -07008318 mac_handle_t mac_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008319 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008320
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308321 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8322 if (!hdd_ctx) {
8323 hdd_err("invalid HDD context");
8324 return INVALID_CHANNEL_ID;
8325 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008326
Jeff Johnson16528362018-06-14 12:34:16 -07008327 mac_handle = hdd_ctx->mac_handle;
8328 if (!mac_handle) {
8329 hdd_err("invalid MAC handle");
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05308330 return INVALID_CHANNEL_ID;
8331 }
8332
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008333 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
8334 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08008335 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
8336 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308337 if (QDF_IS_STATUS_ERROR(status)) {
8338 hdd_err("Get PCL failed");
8339 return INVALID_CHANNEL_ID;
8340 }
8341
Frank Liudc2cefb2017-06-21 15:38:18 +08008342 /*
8343 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
8344 * channel is unsafe channel, the pcl may be empty, instead of return,
8345 * try to choose a safe channel from acs range.
8346 */
8347 if (!pcl.pcl_len)
8348 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308349
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008350 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07008351 adapter->session.ap.sap_config.acs_cfg.start_ch,
8352 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308353
8354 /* PCL already takes unsafe channel into account */
8355 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008356 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308357 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008358 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308359 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008360 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008361 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308362 return pcl.pcl_list[i];
8363 }
8364 }
8365
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008366 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308367
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +05308368 return hdd_get_safe_channel(hdd_ctx, adapter);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308369}
8370
8371/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008372 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308373 * @adapter: AP adapter
8374 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08008375 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308376 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008377 * Moves the SAP interface by invoking the function which
8378 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308379 *
8380 * Return: None
8381 */
Min Liu2fef5792018-01-19 17:59:42 +08008382void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
8383 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308384{
Jeff Johnson87251032017-08-29 13:31:11 -07008385 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008386 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07008387 mac_handle_t mac_handle;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308388
8389 if (!adapter) {
8390 hdd_err("invalid adapter");
8391 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008392 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308393
8394 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
8395
Jeff Johnson16528362018-06-14 12:34:16 -07008396 mac_handle = hdd_adapter_get_mac_handle(adapter);
8397 if (!mac_handle) {
8398 hdd_err("invalid MAC handle");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308399 return;
8400 }
8401
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008402 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8403
Jeff Johnson91df29d2017-10-27 19:29:50 -07008404 hdd_ap_ctx->sap_config.channel = channel;
Himanshu Agarwalf5c5b102018-05-22 20:13:57 +05308405 hdd_ap_ctx->sap_config.ch_params.ch_width = CH_WIDTH_MAX;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308406
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008407 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07008408 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308409
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07008410 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07008411 hdd_ap_ctx->sap_config.channel,
8412 hdd_ap_ctx->sap_config.sec_ch,
8413 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308414
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008415 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07008416 adapter->session_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08008417 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008418}
Kapil Gupta8878ad92017-02-13 11:56:04 +05308419
Jeff Johnson9d295242017-08-29 14:39:48 -07008420int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05308421{
8422 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308423 int status;
8424 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308425
8426 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8427
8428 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07008429 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05308430 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07008431 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308432 }
8433 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07008434 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308435 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308436 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07008437 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308438 WLAN_VENDOR_ACS_WAIT_TIME);
8439 if (qdf_status != QDF_STATUS_SUCCESS) {
8440 hdd_err("failed to start external acs timer");
8441 return -ENOSPC;
8442 }
8443 /* Update config to application */
8444 status = hdd_cfg80211_update_acs_config(adapter, reason);
Dustin Brown5e89ef82018-03-14 11:50:23 -07008445 hdd_info("Updated ACS config to nl with reason %d", reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308446
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308447 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308448}
8449
Nirav Shaheb017be2018-02-15 11:20:58 +05308450#if defined(FEATURE_WLAN_CH_AVOID)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308451/**
8452 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
8453 * @hdd_ctx: hdd context pointer
8454 *
8455 * hdd_unsafe_channel_restart_sap check all unsafe channel list
8456 * and if ACS is enabled, driver will ask userspace to restart the
8457 * sap. User space on LTE coex indication restart driver.
8458 *
8459 * Return - none
8460 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008461void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308462{
Dustin Brown920397d2017-12-13 16:27:50 -08008463 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308464 uint32_t i;
8465 bool found = false;
8466 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008467
Dustin Brown920397d2017-12-13 16:27:50 -08008468 hdd_for_each_adapter(hdd_ctxt, adapter) {
8469 if (!(adapter->device_mode == QDF_SAP_MODE &&
8470 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008471 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08008472 adapter->device_mode,
8473 adapter->session.ap.sap_config.
8474 acs_cfg.acs_mode);
8475 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308476 }
8477
8478 found = false;
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008479 /*
8480 * If STA+SAP is doing SCC & g_sta_sap_scc_on_lte_coex_chan
8481 * is set, no need to move SAP.
8482 */
8483 if (policy_mgr_is_sta_sap_scc(hdd_ctxt->hdd_psoc,
8484 adapter->session.ap.operating_channel) &&
8485 hdd_ctxt->config->sta_sap_scc_on_lte_coex_chan)
8486 hdd_debug("SAP is allowed on SCC channel, no need to move SAP");
8487 else {
8488 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
8489 if (adapter->session.ap.operating_channel ==
8490 hdd_ctxt->unsafe_channel_list[i]) {
8491 found = true;
8492 hdd_debug("operating ch:%d is unsafe",
8493 adapter->session.ap.operating_channel);
8494 break;
8495 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308496 }
8497 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308498 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008499 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08008500 adapter->session.ap.operating_channel);
8501 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308502 }
8503
Kapil Gupta8878ad92017-02-13 11:56:04 +05308504 if (hdd_ctxt->config->vendor_acs_support &&
8505 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08008506 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05308507 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08008508 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308509 } else
8510 restart_chan =
8511 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08008512 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308513 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008514 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308515 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008516 /*
8517 * SAP restart due to unsafe channel. While
8518 * restarting the SAP, make sure to clear
8519 * acs_channel, channel to reset to
8520 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308521 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008522 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308523 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008524 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308525 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
8526 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04008527 hdd_debug("driver to start sap: %d",
8528 hdd_ctxt->config->sap_internal_restart);
8529 if (hdd_ctxt->config->sap_internal_restart)
Min Liu2fef5792018-01-19 17:59:42 +08008530 hdd_switch_sap_channel(adapter, restart_chan,
8531 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04008532 else
8533 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308534 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308535 }
8536}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05308537
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008538/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008539 * hdd_init_channel_avoidance() - Initialize channel avoidance
8540 * @hdd_ctx: HDD global context
8541 *
8542 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07008543 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008544 * down to the lower layers. Then subscribe to subsequent channel
8545 * avoidance events.
8546 *
8547 * Return: None
8548 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008549static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008550{
8551 uint16_t unsafe_channel_count;
8552 int index;
8553
Yuanyuan Liu13738502016-04-06 17:41:37 -07008554 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
8555 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008556 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08008557 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008558
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008559 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008560 hdd_ctx->unsafe_channel_count);
8561
Anurag Chouhan6d760662016-02-20 16:05:43 +05308562 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08008563 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008564
8565 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008566 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008567 hdd_ctx->unsafe_channel_list[index]);
8568
8569 }
8570
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008571}
Dustin Brown676a2322017-08-15 13:16:13 -07008572
Jeff Johnson9d295242017-08-29 14:39:48 -07008573static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008574 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008575{
8576 uint8_t restart_chan;
8577
8578 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
8579 if (!restart_chan) {
8580 hdd_alert("fail to restart SAP");
8581 return;
8582 }
8583
8584 /* SAP restart due to unsafe channel. While restarting
8585 * the SAP, make sure to clear acs_channel, channel to
8586 * reset to 0. Otherwise these settings will override
8587 * the ACS while restart.
8588 */
8589 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07008590
8591 hdd_debug("sending coex indication");
8592
8593 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
8594 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08008595 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07008596}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008597
8598int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
8599 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
8600{
8601 uint32_t size;
8602 uint16_t *unsafe_list;
8603 uint16_t chan_count;
8604
8605 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
8606 return -EINVAL;
8607
8608 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
8609 NUM_CHANNELS);
8610 if (chan_count) {
8611 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
8612 unsafe_list = qdf_mem_malloc(size);
8613 if (!unsafe_list) {
8614 hdd_err("No memory for unsafe chan list size%d",
8615 size);
8616 return -ENOMEM;
8617 }
8618 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
8619 } else {
8620 unsafe_list = NULL;
8621 }
8622
8623 *local_unsafe_list = unsafe_list;
8624 *local_unsafe_list_count = chan_count;
8625
8626 return 0;
8627}
8628
8629bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
8630 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
8631{
8632 int i, j;
8633
8634 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
8635 return true;
8636 if (local_unsafe_list_count == 0)
8637 return false;
8638 for (i = 0; i < local_unsafe_list_count; i++) {
8639 for (j = 0; j < local_unsafe_list_count; j++)
8640 if (local_unsafe_list[i] ==
8641 hdd_ctx->unsafe_channel_list[j])
8642 break;
8643 if (j >= local_unsafe_list_count)
8644 break;
8645 }
8646 if (i >= local_unsafe_list_count) {
8647 hdd_info("unsafe chan list same");
8648 return false;
8649 }
8650
8651 return true;
8652}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008653#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008654static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008655{
8656}
Dustin Brown676a2322017-08-15 13:16:13 -07008657
Jeff Johnson9d295242017-08-29 14:39:48 -07008658static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008659 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008660{
8661 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
8662}
Yuanyuan Liu13738502016-04-06 17:41:37 -07008663#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008664
8665/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08008666 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
8667 * user space
8668 * @frame_ind: Management frame data to be informed.
8669 *
8670 * This function is used to indicate management frame to
8671 * user space
8672 *
8673 * Return: None
8674 *
8675 */
8676void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
8677{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008678 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07008679 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008680 int i;
Pragaspathi Thilagaraj28ffc042018-07-18 15:19:36 +05308681 struct ieee80211_mgmt *mgmt =
8682 (struct ieee80211_mgmt *)frame_ind->frameBuf;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008683
Dustin Browne7e71d32018-05-11 16:00:08 -07008684 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
8685 if (wlan_hdd_validate_context(hdd_ctx))
Rajeev Kumard004abc2016-02-17 12:09:56 -08008686 return;
8687
Pragaspathi Thilagaraj28ffc042018-07-18 15:19:36 +05308688 if (frame_ind->frame_len < ieee80211_hdrlen(mgmt->frame_control)) {
8689 hdd_err(" Invalid frame length");
8690 return;
8691 }
8692
Rajeev Kumard004abc2016-02-17 12:09:56 -08008693 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
8694 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
8695 adapter =
8696 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
8697 if (adapter)
8698 break;
8699 }
Wu Gaoa0230a62018-01-04 20:56:57 +08008700 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
8701 hdd_for_each_adapter(hdd_ctx, adapter) {
8702 if ((NULL != adapter) &&
8703 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
8704 __hdd_indicate_mgmt_frame(adapter,
8705 frame_ind->frame_len,
8706 frame_ind->frameBuf,
8707 frame_ind->frameType,
8708 frame_ind->rxChan,
8709 frame_ind->rxRssi);
8710 }
8711 }
8712 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008713 } else {
8714 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
8715 frame_ind->sessionId);
8716 }
8717
8718 if ((NULL != adapter) &&
8719 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
8720 __hdd_indicate_mgmt_frame(adapter,
8721 frame_ind->frame_len,
8722 frame_ind->frameBuf,
8723 frame_ind->frameType,
8724 frame_ind->rxChan,
8725 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008726}
8727
Kapil Gupta8878ad92017-02-13 11:56:04 +05308728void hdd_acs_response_timeout_handler(void *context)
8729{
8730 struct hdd_external_acs_timer_context *timer_context =
8731 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07008732 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008733 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308734 uint8_t reason;
8735
Dustin Brown491d54b2018-03-14 12:39:11 -07008736 hdd_enter();
Kapil Gupta8878ad92017-02-13 11:56:04 +05308737 if (!timer_context) {
8738 hdd_err("invlaid timer context");
8739 return;
8740 }
8741 adapter = timer_context->adapter;
8742 reason = timer_context->reason;
8743
8744
8745 if ((!adapter) ||
8746 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
8747 hdd_err("invalid adapter or adapter has invalid magic");
8748 return;
8749 }
8750 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8751 if (wlan_hdd_validate_context(hdd_ctx))
8752 return;
8753
8754 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
8755 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8756 else
8757 return;
8758
8759 hdd_err("ACS timeout happened for %s reason %d",
8760 adapter->dev->name, reason);
Jeff Johnson16528362018-06-14 12:34:16 -07008761
Kapil Gupta8878ad92017-02-13 11:56:04 +05308762 switch (reason) {
8763 /* SAP init case */
8764 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
8765 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
8766 false);
8767 wlan_hdd_cfg80211_start_acs(adapter);
8768 break;
8769 /* DFS detected on current channel */
8770 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
8771 wlan_sap_update_next_channel(
8772 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
Jeff Johnson16528362018-06-14 12:34:16 -07008773 sme_update_new_channel_event(hdd_ctx->mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07008774 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308775 break;
8776 /* LTE coex event on current channel */
8777 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
8778 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
8779 break;
8780 default:
8781 hdd_info("invalid reason for timer invoke");
8782
8783 }
8784}
8785
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008786/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008787 * hdd_override_ini_config - Override INI config
8788 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008789 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008790 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008791 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008792 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008793 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008794static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008795{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008796
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008797 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
8798 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008799 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008800 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008801 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008802 if (0 == enable_11d || 1 == enable_11d) {
8803 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008804 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008805 }
Leo Chang11545d62016-10-17 14:53:50 -07008806
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308807 if (!ucfg_ipa_is_present()) {
Leo Chang11545d62016-10-17 14:53:50 -07008808 hdd_ctx->config->IpaConfig = 0;
Jingxiang Ge7a040dc2018-02-02 11:07:59 +08008809 hdd_debug("IpaConfig override to %d",
8810 hdd_ctx->config->IpaConfig);
8811 }
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05308812
8813 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
8814 !hdd_ctx->config->enable_bcast_probe_rsp) {
8815 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
8816 hdd_ctx->config->rssi_assoc_reject_enabled,
8817 hdd_ctx->config->enable_bcast_probe_rsp);
8818 hdd_ctx->config->oce_sta_enabled = 0;
8819 }
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +05308820
8821 if (hdd_ctx->config->action_oui_enable && !ucfg_action_oui_enabled()) {
8822 hdd_ctx->config->action_oui_enable = 0;
8823 hdd_err("Ignore ini: %s, since no action_oui component",
8824 CFG_ENABLE_ACTION_OUI);
8825 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008826}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008827
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008828/**
8829 * hdd_set_trace_level_for_each - Set trace level for each INI config
8830 * @hdd_ctx - HDD context
8831 *
8832 * Set trace level for each module based on INI config.
8833 *
8834 * Return: None
8835 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008836static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008837{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308838 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
8839 hdd_ctx->config->qdf_trace_enable_wdi);
8840 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
8841 hdd_ctx->config->qdf_trace_enable_hdd);
8842 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
8843 hdd_ctx->config->qdf_trace_enable_sme);
8844 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
8845 hdd_ctx->config->qdf_trace_enable_pe);
8846 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
8847 hdd_ctx->config->qdf_trace_enable_wma);
8848 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
8849 hdd_ctx->config->qdf_trace_enable_sys);
8850 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
8851 hdd_ctx->config->qdf_trace_enable_qdf);
8852 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
8853 hdd_ctx->config->qdf_trace_enable_sap);
8854 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
8855 hdd_ctx->config->qdf_trace_enable_hdd_sap);
8856 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
8857 hdd_ctx->config->qdf_trace_enable_bmi);
8858 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
8859 hdd_ctx->config->qdf_trace_enable_cfg);
8860 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
8861 hdd_ctx->config->qdf_trace_enable_epping);
8862 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
8863 hdd_ctx->config->qdf_trace_enable_qdf_devices);
8864 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07008865 hdd_ctx->config->qdf_trace_enable_txrx);
8866 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
8867 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308868 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
8869 hdd_ctx->config->qdf_trace_enable_htc);
8870 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
8871 hdd_ctx->config->qdf_trace_enable_hif);
8872 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
8873 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
8874 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
8875 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08008876 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
8877 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07008878 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
8879 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008880 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
8881 hdd_ctx->config->qdf_trace_enable_regulatory);
Naveen Rawat3cb779e2018-02-16 16:36:10 -08008882 hdd_qdf_trace_enable(QDF_MODULE_ID_CP_STATS,
8883 hdd_ctx->config->qdf_trace_enable_cp_stats);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +05308884 hdd_qdf_trace_enable(QDF_MODULE_ID_MLME, 0xffff);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008885
Nirav Shah5c083da2018-08-03 13:46:02 +05308886 hdd_cfg_print_global_config(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008887}
8888
8889/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008890 * hdd_context_init() - Initialize HDD context
8891 * @hdd_ctx: HDD context.
8892 *
8893 * Initialize HDD context along with all the feature specific contexts.
8894 *
8895 * return: 0 on success and errno on failure.
8896 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008897static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008898{
8899 int ret;
8900
8901 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
8902 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
8903
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008904 init_completion(&hdd_ctx->mc_sus_event_var);
8905 init_completion(&hdd_ctx->ready_to_suspend);
8906
8907 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308908 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008909 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308910
Dustin Brownbee82832018-07-23 10:10:51 -07008911 qdf_list_create(&hdd_ctx->hdd_adapters, 0);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008912
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008913 ret = hdd_scan_context_init(hdd_ctx);
8914 if (ret)
8915 goto list_destroy;
8916
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008917 hdd_rx_wake_lock_create(hdd_ctx);
8918
8919 ret = hdd_sap_context_init(hdd_ctx);
8920 if (ret)
8921 goto scan_destroy;
8922
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008923 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8924
8925 hdd_init_offloaded_packets_ctx(hdd_ctx);
8926
8927 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8928 hdd_ctx->config);
8929 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08008930 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008931
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05308932 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
8933 "monitor_mode_wakelock");
8934
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008935 return 0;
8936
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008937sap_destroy:
8938 hdd_sap_context_destroy(hdd_ctx);
8939
8940scan_destroy:
8941 hdd_scan_context_destroy(hdd_ctx);
8942 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008943list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008944 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08008945
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008946 return ret;
8947}
8948
8949/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308950 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
8951 * @hdd_ctx: pointer to hdd context
8952 *
8953 * Return: status of initialization
8954 * 0 - success
8955 * negative value - failure
8956 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008957static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308958{
8959 int ret;
8960
8961 if (!hdd_ctx->config->probe_req_ie_whitelist)
8962 return 0;
8963
8964 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
8965 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
8966 hdd_ctx->config->probe_req_ie_whitelist = false;
8967 return -EINVAL;
8968 }
8969
8970 /* parse ini string probe req oui */
8971 ret = hdd_parse_probe_req_ouis(hdd_ctx);
8972 if (ret) {
8973 hdd_err("parsing error: disable ie whitelisting");
8974 hdd_ctx->config->probe_req_ie_whitelist = false;
8975 }
8976
8977 return ret;
8978}
8979
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308980/**
8981 * hdd_iface_change_callback() - Function invoked when stop modules expires
8982 * @priv: pointer to hdd context
8983 *
8984 * This function is invoked when the timer waiting for the interface change
8985 * expires, it shall cut-down the power to wlan and stop all the modules.
8986 *
8987 * Return: void
8988 */
8989static void hdd_iface_change_callback(void *priv)
8990{
8991 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
8992 int ret;
8993 int status = wlan_hdd_validate_context(hdd_ctx);
8994
8995 if (status)
8996 return;
8997
Dustin Brown491d54b2018-03-14 12:39:11 -07008998 hdd_enter();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308999 hdd_debug("Interface change timer expired close the modules!");
9000 ret = hdd_wlan_stop_modules(hdd_ctx, false);
9001 if (ret)
9002 hdd_err("Failed to stop modules");
Dustin Browne74003f2018-03-14 12:51:58 -07009003 hdd_exit();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309004}
9005
Nirav Shaheb017be2018-02-15 11:20:58 +05309006#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
9007static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
9008{
9009 wlan_logging_set_log_to_console(hdd_ctx->config->
9010 wlan_logging_to_console);
9011 wlan_logging_set_active(hdd_ctx->config->wlan_logging_enable);
9012}
9013#else
9014static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
9015{ }
9016#endif
9017
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05309018/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009019 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05309020 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009021 *
9022 * Allocate and initialize HDD context. HDD context is allocated as part of
9023 * wiphy allocation and then context is initialized.
9024 *
9025 * Return: HDD context on success and ERR_PTR on failure
9026 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009027static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009028{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309029 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009030 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009031 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009032
Dustin Brown491d54b2018-03-14 12:39:11 -07009033 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009034
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009035 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009036 if (hdd_ctx == NULL) {
9037 ret = -ENOMEM;
9038 goto err_out;
9039 }
9040
Dustin Brown6f427922017-09-19 12:19:00 -07009041 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
9042 hdd_iface_change_callback,
9043 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309044
9045 mutex_init(&hdd_ctx->iface_change_lock);
9046
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009047 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05309048 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009049
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309050 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009051 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009052 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009053 ret = -ENOMEM;
9054 goto err_free_hdd_context;
9055 }
9056
9057 /* Read and parse the qcom_cfg.ini file */
9058 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309059 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05309060 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009061 WLAN_INI_FILE);
9062 ret = -EINVAL;
9063 goto err_free_config;
9064 }
9065
Dustin Brown84f46ea2018-02-15 11:57:36 -08009066 status = cfg_parse(WLAN_INI_FILE);
9067 if (QDF_IS_STATUS_ERROR(status))
9068 hdd_err("Failed to parse cfg %s; status:%d\n",
9069 WLAN_INI_FILE, status);
9070
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05309071 ie_whitelist_attrs_init(hdd_ctx);
9072
Dustin Brown7f939932017-05-18 15:02:17 -07009073 hdd_debug("setting timer multiplier: %u",
9074 hdd_ctx->config->timer_multiplier);
9075 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
9076
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009077
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05309078 if (hdd_ctx->config->fhostNSOffload)
9079 hdd_ctx->ns_offload_enable = true;
9080
Abhishek Singh5ea86532016-04-27 14:10:53 +05309081 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
9082
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009083 hdd_override_ini_config(hdd_ctx);
9084
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009085 ret = hdd_context_init(hdd_ctx);
9086
9087 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009088 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07009089
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009090 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05309091 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009092
Anurag Chouhan6d760662016-02-20 16:05:43 +05309093 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009094 goto skip_multicast_logging;
9095
9096 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
9097
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07009098 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
9099 if (ret)
9100 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05309101
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009102 ret = hdd_init_netlink_services(hdd_ctx);
9103 if (ret)
9104 goto err_deinit_txrx_histogram;
9105
Nirav Shaheb017be2018-02-15 11:20:58 +05309106 hdd_set_wlan_logging(hdd_ctx);
Nirav Shahed34b212016-04-25 10:59:16 +05309107
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009108skip_multicast_logging:
9109 hdd_set_trace_level_for_each(hdd_ctx);
9110
Rajeev Kumar493a31b2017-09-29 14:01:24 -07009111 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
9112
Dustin Browne74003f2018-03-14 12:51:58 -07009113 hdd_exit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07009114
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009115 return hdd_ctx;
9116
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009117err_deinit_txrx_histogram:
9118 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
9119
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07009120err_deinit_hdd_context:
9121 hdd_context_deinit(hdd_ctx);
9122
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009123err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309124 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009125
9126err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309127 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08009128 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009129
9130err_out:
9131 return ERR_PTR(ret);
9132}
9133
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009134#ifdef WLAN_OPEN_P2P_INTERFACE
9135/**
9136 * hdd_open_p2p_interface - Open P2P interface
9137 * @hdd_ctx: HDD context
9138 * @rtnl_held: True if RTNL lock held
9139 *
9140 * Open P2P interface during probe. This function called to open the P2P
9141 * interface at probe along with STA interface.
9142 *
9143 * Return: 0 on success and errno on failure
9144 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009145static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009146{
Jeff Johnson9d295242017-08-29 14:39:48 -07009147 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009148 uint8_t *p2p_dev_addr;
Wu Gaoe5689792018-07-05 19:20:13 +08009149 bool p2p_dev_addr_admin = false;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009150
Wu Gaoe5689792018-07-05 19:20:13 +08009151 cfg_p2p_get_device_addr_admin(hdd_ctx->hdd_psoc, &p2p_dev_addr_admin);
9152 if (p2p_dev_addr_admin &&
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009153 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009154 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009155 hdd_ctx->config->intfMacAddr[0].bytes,
9156 sizeof(tSirMacAddr));
9157
9158 /*
9159 * Generate the P2P Device Address. This consists of
9160 * the device's primary MAC address with the locally
9161 * administered bit set.
9162 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009163 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009164 } else {
9165 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
9166 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009167 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009168 return -ENOSPC;
9169 }
9170
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009171 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
9172 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009173 }
9174
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009175 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009176 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08009177 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009178
9179 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009180 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009181 return -ENOSPC;
9182 }
9183
9184 return 0;
9185}
9186#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009187static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009188 bool rtnl_held)
9189{
9190 return 0;
9191}
9192#endif
9193
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009194static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08009195{
Jeff Johnson9d295242017-08-29 14:39:48 -07009196 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08009197 int ret = 0;
9198
9199 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
9200 wlan_hdd_get_intf_addr(hdd_ctx),
9201 NET_NAME_UNKNOWN, rtnl_held);
9202 if (adapter == NULL) {
9203 hdd_err("Failed to open 802.11p interface");
9204 ret = -ENOSPC;
9205 }
9206
9207 return ret;
9208}
9209
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009210/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309211 * hdd_start_station_adapter()- Start the Station Adapter
9212 * @adapter: HDD adapter
9213 *
9214 * This function initializes the adapter for the station mode.
9215 *
9216 * Return: 0 on success or errno on failure.
9217 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009218int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309219{
9220 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08009221 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309222
Dustin Brownfdf17c12018-03-14 12:55:34 -07009223 hdd_enter_dev(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08009224 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9225 hdd_err("session is already opened, %d",
9226 adapter->session_id);
9227 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9228 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309229
Krunal Sonib51eec72017-11-20 21:53:01 -08009230 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
9231 if (ret) {
9232 hdd_err("failed to create vdev: %d", ret);
9233 return ret;
9234 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309235 status = hdd_init_station_mode(adapter);
9236
9237 if (QDF_STATUS_SUCCESS != status) {
9238 hdd_err("Error Initializing station mode: %d", status);
9239 return qdf_status_to_os_return(status);
9240 }
9241
Arun Khandavallifae92942016-08-01 13:31:08 +05309242 hdd_register_tx_flow_control(adapter,
9243 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009244 hdd_tx_resume_cb,
9245 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309246
Dustin Browne74003f2018-03-14 12:51:58 -07009247 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309248 return 0;
9249}
9250
9251/**
9252 * hdd_start_ap_adapter()- Start AP Adapter
9253 * @adapter: HDD adapter
9254 *
9255 * This function initializes the adapter for the AP mode.
9256 *
9257 * Return: 0 on success errno on failure.
9258 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009259int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309260{
9261 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009262 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08009263 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08009264 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309265
Dustin Brown491d54b2018-03-14 12:39:11 -07009266 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309267
Krunal Sonib51eec72017-11-20 21:53:01 -08009268 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9269 hdd_err("session is already opened, %d",
9270 adapter->session_id);
9271 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9272 }
9273 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009274 * In SSR case no need to create new sap context.
9275 * Otherwise create sap context first and then create
9276 * vdev as while creating the vdev, driver needs to
9277 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08009278 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009279 if (adapter->session.ap.sap_context) {
9280 is_ssr = true;
9281 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08009282 hdd_err("sap creation failed");
9283 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
9284 }
9285
9286 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
9287 adapter->session.ap.sap_context);
9288 if (ret) {
9289 hdd_err("failed to create vdev, status:%d", ret);
9290 hdd_sap_destroy_ctx(adapter);
9291 return ret;
9292 }
Naveen Rawat1af09392018-01-03 17:28:21 -08009293
9294 if (adapter->device_mode == QDF_SAP_MODE)
9295 sme_cli_set_command(adapter->session_id,
9296 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
9297 (bool)(hdd_ctx->config->fine_time_meas_cap &
9298 WMI_FW_AP_RTT_RESPR),
9299 VDEV_CMD);
9300
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009301 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309302
9303 if (QDF_STATUS_SUCCESS != status) {
9304 hdd_err("Error Initializing the AP mode: %d", status);
9305 return qdf_status_to_os_return(status);
9306 }
9307
Arun Khandavallifae92942016-08-01 13:31:08 +05309308 hdd_register_tx_flow_control(adapter,
9309 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009310 hdd_softap_tx_resume_cb,
9311 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309312
Dustin Browne74003f2018-03-14 12:51:58 -07009313 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309314 return 0;
9315}
9316
Sourav Mohapatra57006c72017-11-19 16:15:55 +05309317static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
9318 bool rtnl_held)
9319{
9320 struct hdd_adapter *adapter;
9321
9322 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
9323 hdd_ctx->config->enableConcurrentSTA,
9324 wlan_hdd_get_intf_addr(hdd_ctx),
9325 NET_NAME_UNKNOWN, rtnl_held);
9326
9327 if (!adapter)
9328 return -ENOSPC;
9329
9330 return 0;
9331}
9332
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309333/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009334 * hdd_open_interfaces - Open all required interfaces
9335 * hdd_ctx: HDD context
9336 * rtnl_held: True if RTNL lock is held
9337 *
9338 * Open all the interfaces like STA, P2P and OCB based on the configuration.
9339 *
Jeff Johnson957bc272017-02-02 08:54:48 -08009340 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009341 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009342static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009343{
Jeff Johnson9d295242017-08-29 14:39:48 -07009344 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009345 int ret;
9346
Ravi Joshia307f632017-07-17 23:41:41 -07009347 /* open monitor mode adapter if con_mode is monitor mode */
Lin Bai1c678482017-12-18 18:29:11 +08009348 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
9349 con_mode == QDF_GLOBAL_FTM_MODE) {
9350 uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
9351 QDF_MONITOR_MODE : QDF_FTM_MODE;
9352
9353 adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
9354 wlan_hdd_get_intf_addr(hdd_ctx),
9355 NET_NAME_UNKNOWN, rtnl_held);
Ravi Joshia307f632017-07-17 23:41:41 -07009356 if (!adapter) {
9357 hdd_err("open adapter failed");
9358 return -ENOSPC;
9359 }
Lin Bai1c678482017-12-18 18:29:11 +08009360
Ravi Joshia307f632017-07-17 23:41:41 -07009361 return 0;
9362 }
9363
Jeff Johnson957bc272017-02-02 08:54:48 -08009364 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05309365 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08009366 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009367
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009368 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009369 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08009370 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009371
9372 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08009373 return -ENOSPC;
9374
Sourav Mohapatra57006c72017-11-19 16:15:55 +05309375 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
9376 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
9377 if (ret)
9378 hdd_err("Cannot create concurrent STA interface");
9379 }
9380
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009381 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
9382 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08009383 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009384
9385 /* Open 802.11p Interface */
9386 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08009387 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
9388 if (ret)
9389 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009390 }
9391
Jeff Johnson957bc272017-02-02 08:54:48 -08009392 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009393
Jeff Johnson957bc272017-02-02 08:54:48 -08009394err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009395 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08009396 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009397}
9398
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009399
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309400#ifdef QCA_LL_TX_FLOW_CONTROL_V2
9401/**
9402 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
9403 * @cds_cfg: CDS Configuration
9404 * @hdd_ctx: Pointer to hdd context
9405 *
9406 * Return: none
9407 */
9408static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9409 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009410 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309411{
9412 cds_cfg->tx_flow_stop_queue_th =
9413 hdd_ctx->config->TxFlowStopQueueThreshold;
9414 cds_cfg->tx_flow_start_queue_offset =
9415 hdd_ctx->config->TxFlowStartQueueOffset;
Mohit Khanna70322002018-05-15 19:21:32 -07009416 /* configuration for DP RX Threads */
9417 cds_cfg->enable_dp_rx_threads = hdd_ctx->enable_dp_rx_threads;
9418 cds_cfg->num_dp_rx_threads = hdd_ctx->config->num_dp_rx_threads;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309419}
9420#else
9421static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9422 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009423 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309424{
9425}
9426#endif
9427
9428#ifdef FEATURE_WLAN_RA_FILTERING
9429/**
9430 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
9431 * @cds_cfg: CDS Configuration
9432 * @hdd_ctx: Pointer to hdd context
9433 *
9434 * Return: none
9435 */
Anand Kumar3b92a912016-12-05 12:01:26 +05309436static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009437 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309438{
9439 cds_cfg->ra_ratelimit_interval =
9440 hdd_ctx->config->RArateLimitInterval;
9441 cds_cfg->is_ra_ratelimit_enabled =
9442 hdd_ctx->config->IsRArateLimitEnabled;
9443}
9444#else
Anand Kumar3b92a912016-12-05 12:01:26 +05309445static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009446 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309447{
9448}
9449#endif
9450
9451/**
9452 * hdd_update_cds_config() - API to update cds configuration parameters
9453 * @hdd_ctx: HDD Context
9454 *
9455 * Return: 0 for Success, errno on failure
9456 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009457static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309458{
9459 struct cds_config_info *cds_cfg;
9460
9461 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
9462 if (!cds_cfg) {
9463 hdd_err("failed to allocate cds config");
9464 return -ENOMEM;
9465 }
9466
Srinivas Girigowda35b00312017-06-27 21:52:03 -07009467 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08009468 if (!hdd_ctx->config->nMaxPsPoll ||
9469 !hdd_ctx->config->enablePowersaveOffload) {
9470 cds_cfg->powersave_offload_enabled =
9471 hdd_ctx->config->enablePowersaveOffload;
9472 } else {
9473 if ((hdd_ctx->config->enablePowersaveOffload ==
9474 PS_QPOWER_NODEEPSLEEP) ||
9475 (hdd_ctx->config->enablePowersaveOffload ==
9476 PS_LEGACY_NODEEPSLEEP))
9477 cds_cfg->powersave_offload_enabled =
9478 PS_LEGACY_NODEEPSLEEP;
9479 else
9480 cds_cfg->powersave_offload_enabled =
9481 PS_LEGACY_DEEPSLEEP;
9482 hdd_info("Qpower disabled in cds config, %d",
9483 cds_cfg->powersave_offload_enabled);
9484 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309485 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
9486 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
9487 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
9488 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309489
9490 /*
9491 * Copy the DFS Phyerr Filtering Offload status.
9492 * This parameter reflects the value of the
9493 * dfs_phyerr_filter_offload flag as set in the ini.
9494 */
9495 cds_cfg->dfs_phyerr_filter_offload =
9496 hdd_ctx->config->fDfsPhyerrFilterOffload;
9497 if (hdd_ctx->config->ssdp)
9498 cds_cfg->ssdp = hdd_ctx->config->ssdp;
9499
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05309500 cds_cfg->force_target_assert_enabled =
9501 hdd_ctx->config->crash_inject_enabled;
9502
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309503 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
9504 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
9505
9506 cds_cfg->ap_maxoffload_reorderbuffs =
9507 hdd_ctx->config->apMaxOffloadReorderBuffs;
9508
9509 cds_cfg->ap_disable_intrabss_fwd =
9510 hdd_ctx->config->apDisableIntraBssFwd;
9511
9512 cds_cfg->dfs_pri_multiplier =
9513 hdd_ctx->config->dfsRadarPriMultiplier;
9514 cds_cfg->reorder_offload =
9515 hdd_ctx->config->reorderOffloadSupport;
9516
9517 /* IPA micro controller data path offload resource config item */
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05309518 cds_cfg->uc_offload_enabled = ucfg_ipa_uc_is_enabled();
Yun Parkde380782016-08-17 16:26:54 -07009519 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
9520 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009521 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009522 hdd_ctx->config->IpaUcTxBufCount);
9523 hdd_ctx->config->IpaUcTxBufCount =
9524 rounddown_pow_of_two(
9525 hdd_ctx->config->IpaUcTxBufCount);
9526 if (!hdd_ctx->config->IpaUcTxBufCount) {
9527 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309528 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07009529 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009530 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009531 hdd_ctx->config->IpaUcTxBufCount);
9532 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309533 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
9534 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07009535 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
9536 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009537 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009538 hdd_ctx->config->IpaUcRxIndRingCount);
9539 hdd_ctx->config->IpaUcRxIndRingCount =
9540 rounddown_pow_of_two(
9541 hdd_ctx->config->IpaUcRxIndRingCount);
9542 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
9543 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309544 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07009545 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009546 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009547 hdd_ctx->config->IpaUcRxIndRingCount);
9548 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309549 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07009550 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309551 cds_cfg->uc_tx_partition_base =
9552 hdd_ctx->config->IpaUcTxPartitionBase;
9553 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
9554
9555 cds_cfg->ip_tcp_udp_checksum_offload =
9556 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07009557 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309558 cds_cfg->ce_classify_enabled =
9559 hdd_ctx->config->ce_classify_enabled;
Nachiket Kukadee547a482018-05-22 16:43:30 +05309560 cds_cfg->apf_packet_filter_enable =
9561 hdd_ctx->config->apf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309562 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
9563 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
9564 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07009565 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07009566 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07009567 cds_cfg->max_msdus_per_rxinorderind =
9568 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07009569 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07009570 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Nachiket Kukadee547a482018-05-22 16:43:30 +05309571 cds_cfg->active_uc_apf_mode = hdd_ctx->config->active_uc_apf_mode;
9572 cds_cfg->active_mc_bc_apf_mode = hdd_ctx->config->active_mc_bc_apf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05309573 cds_cfg->auto_power_save_fail_mode =
9574 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309575
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309576 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07009577 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Zhu Jianmina2f8e8d2018-02-11 16:37:10 +08009578 cds_cfg->delay_before_vdev_stop =
9579 hdd_ctx->config->delay_before_vdev_stop;
Rachit Kankane0106e382018-05-16 18:59:28 +05309580 cds_cfg->num_vdevs = hdd_ctx->config->num_vdevs;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309581
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309582 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
9583 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07009584 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309585 cds_init_ini_config(cds_cfg);
9586 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309587
9588exit:
9589 qdf_mem_free(cds_cfg);
9590 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309591}
9592
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009593/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009594 * hdd_update_user_config() - API to update user configuration
9595 * parameters to obj mgr which are used by multiple components
9596 * @hdd_ctx: HDD Context
9597 *
9598 * Return: 0 for Success, errno on failure
9599 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009600static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009601{
9602 struct wlan_objmgr_psoc_user_config *user_config;
Wu Gaoe5689792018-07-05 19:20:13 +08009603 bool skip_dfs_in_p2p_search = false;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009604
9605 user_config = qdf_mem_malloc(sizeof(*user_config));
9606 if (user_config == NULL) {
9607 hdd_alert("Failed to alloc memory for user_config!");
9608 return -ENOMEM;
9609 }
9610
9611 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
9612 user_config->dual_mac_feature_disable =
9613 hdd_ctx->config->dual_mac_feature_disable;
9614 user_config->indoor_channel_support =
9615 hdd_ctx->config->indoor_channel_support;
9616 user_config->is_11d_support_enabled =
9617 hdd_ctx->config->Is11dSupportEnabled;
9618 user_config->is_11h_support_enabled =
9619 hdd_ctx->config->Is11hSupportEnabled;
9620 user_config->optimize_chan_avoid_event =
9621 hdd_ctx->config->goptimize_chan_avoid_event;
Wu Gaoe5689792018-07-05 19:20:13 +08009622 cfg_p2p_get_skip_dfs_channel_p2p_search(hdd_ctx->hdd_psoc,
9623 &skip_dfs_in_p2p_search);
9624 user_config->skip_dfs_chnl_in_p2p_search = skip_dfs_in_p2p_search;
Naveen Rawat222b2e92017-03-16 09:52:21 -07009625 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009626 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
9627
9628 qdf_mem_free(user_config);
9629 return 0;
9630}
9631
9632/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009633 * hdd_init_thermal_info - Initialize thermal level
9634 * @hdd_ctx: HDD context
9635 *
9636 * Initialize thermal level at SME layer and set the thermal level callback
9637 * which would be called when a configured thermal threshold is hit.
9638 *
9639 * Return: 0 on success and errno on failure
9640 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009641static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009642{
9643 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309644 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -07009645 mac_handle_t mac_handle;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009646
9647 thermal_param.smeThermalMgmtEnabled =
9648 hdd_ctx->config->thermalMitigationEnable;
9649 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
9650
Poddar, Siddarth83905022016-04-16 17:56:08 -07009651 thermal_param.sme_throttle_duty_cycle_tbl[0] =
9652 hdd_ctx->config->throttle_dutycycle_level0;
9653 thermal_param.sme_throttle_duty_cycle_tbl[1] =
9654 hdd_ctx->config->throttle_dutycycle_level1;
9655 thermal_param.sme_throttle_duty_cycle_tbl[2] =
9656 hdd_ctx->config->throttle_dutycycle_level2;
9657 thermal_param.sme_throttle_duty_cycle_tbl[3] =
9658 hdd_ctx->config->throttle_dutycycle_level3;
9659
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009660 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
9661 hdd_ctx->config->thermalTempMinLevel0;
9662 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
9663 hdd_ctx->config->thermalTempMaxLevel0;
9664 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
9665 hdd_ctx->config->thermalTempMinLevel1;
9666 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
9667 hdd_ctx->config->thermalTempMaxLevel1;
9668 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
9669 hdd_ctx->config->thermalTempMinLevel2;
9670 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
9671 hdd_ctx->config->thermalTempMaxLevel2;
9672 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
9673 hdd_ctx->config->thermalTempMinLevel3;
9674 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
9675 hdd_ctx->config->thermalTempMaxLevel3;
9676
Jeff Johnson16528362018-06-14 12:34:16 -07009677 mac_handle = hdd_ctx->mac_handle;
9678 status = sme_init_thermal_info(mac_handle, thermal_param);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009679
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309680 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05309681 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009682
Jeff Johnson16528362018-06-14 12:34:16 -07009683 sme_add_set_thermal_level_callback(mac_handle,
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009684 hdd_set_thermal_level_cb);
9685
9686 return 0;
9687
9688}
9689
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009690#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
9691/**
9692 * hdd_hold_rtnl_lock - Hold RTNL lock
9693 *
9694 * Hold RTNL lock
9695 *
9696 * Return: True if held and false otherwise
9697 */
9698static inline bool hdd_hold_rtnl_lock(void)
9699{
9700 rtnl_lock();
9701 return true;
9702}
9703
9704/**
9705 * hdd_release_rtnl_lock - Release RTNL lock
9706 *
9707 * Release RTNL lock
9708 *
9709 * Return: None
9710 */
9711static inline void hdd_release_rtnl_lock(void)
9712{
9713 rtnl_unlock();
9714}
9715#else
9716static inline bool hdd_hold_rtnl_lock(void) { return false; }
9717static inline void hdd_release_rtnl_lock(void) { }
9718#endif
9719
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009720#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009721
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309722/* MAX iwpriv command support */
9723#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309724#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309725#define MAX_PKTLOG_SIZE 16
9726
9727/**
9728 * hdd_pktlog_set_buff_size() - set pktlog buffer size
9729 * @hdd_ctx: hdd context
9730 * @set_value2: pktlog buffer size value
9731 *
9732 *
9733 * Return: 0 for success or error.
9734 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009735static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309736{
9737 struct sir_wifi_start_log start_log = { 0 };
9738 QDF_STATUS status;
9739
9740 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9741 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9742 start_log.ini_triggered = cds_is_packet_log_enabled();
9743 start_log.user_triggered = 1;
9744 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309745 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309746
Jeff Johnson16528362018-06-14 12:34:16 -07009747 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309748 if (!QDF_IS_STATUS_SUCCESS(status)) {
9749 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009750 hdd_exit();
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309751 return -EINVAL;
9752 }
9753
9754 return 0;
9755}
9756
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009757/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309758 * hdd_pktlog_clear_buff() - clear pktlog buffer
9759 * @hdd_ctx: hdd context
9760 *
9761 * Return: 0 for success or error.
9762 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009763static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309764{
9765 struct sir_wifi_start_log start_log;
9766 QDF_STATUS status;
9767
9768 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9769 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9770 start_log.ini_triggered = cds_is_packet_log_enabled();
9771 start_log.user_triggered = 1;
9772 start_log.size = 0;
9773 start_log.is_pktlog_buff_clear = true;
9774
Jeff Johnson16528362018-06-14 12:34:16 -07009775 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309776 if (!QDF_IS_STATUS_SUCCESS(status)) {
9777 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009778 hdd_exit();
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309779 return -EINVAL;
9780 }
9781
9782 return 0;
9783}
9784
9785
9786/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009787 * hdd_process_pktlog_command() - process pktlog command
9788 * @hdd_ctx: hdd context
9789 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309790 * @set_value2: pktlog buffer size value
9791 *
9792 * This function process pktlog command.
9793 * set_value2 only matters when set_value is 3 (set buff size)
9794 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009795 *
9796 * Return: 0 for success or error.
9797 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009798int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309799 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009800{
9801 int ret;
9802 bool enable;
9803 uint8_t user_triggered = 0;
9804
9805 ret = wlan_hdd_validate_context(hdd_ctx);
9806 if (0 != ret)
9807 return ret;
9808
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009809 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009810
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309811 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009812 hdd_err("invalid pktlog value %d", set_value);
9813 return -EINVAL;
9814 }
9815
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309816 if (set_value == PKTLOG_SET_BUFF_SIZE) {
9817 if (set_value2 <= 0) {
9818 hdd_err("invalid pktlog size %d", set_value2);
9819 return -EINVAL;
9820 } else if (set_value2 > MAX_PKTLOG_SIZE) {
9821 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
9822 return -EINVAL;
9823 }
9824 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309825 } else if (set_value == PKTLOG_CLEAR_BUFF) {
9826 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309827 }
9828
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009829 /*
9830 * set_value = 0 then disable packetlog
9831 * set_value = 1 enable packetlog forcefully
9832 * set_vlaue = 2 then disable packetlog if disabled through ini or
9833 * enable packetlog with AUTO type.
9834 */
9835 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
9836 true : false;
9837
9838 if (1 == set_value) {
9839 enable = true;
9840 user_triggered = 1;
9841 }
9842
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309843 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009844}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07009845
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009846/**
9847 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
9848 * @hdd_ctx: HDD context
9849 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309850 * @user_triggered: triggered through iwpriv
9851 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009852 *
9853 * Return: 0 on success; error number otherwise
9854 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009855int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309856 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009857{
9858 struct sir_wifi_start_log start_log;
9859 QDF_STATUS status;
9860
9861 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9862 start_log.verbose_level =
9863 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009864 start_log.ini_triggered = cds_is_packet_log_enabled();
9865 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309866 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309867 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05309868 /*
9869 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
9870 * commands. Host uses this flag to decide whether to send pktlog
9871 * disable command to fw without sending pktlog enable command
9872 * previously. For eg, If vendor sends pktlog disable command without
9873 * sending pktlog enable command, then host discards the packet
9874 * but for iwpriv command, host will send it to fw.
9875 */
9876 start_log.is_iwpriv_command = 1;
Jeff Johnson16528362018-06-14 12:34:16 -07009877 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009878 if (!QDF_IS_STATUS_SUCCESS(status)) {
9879 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009880 hdd_exit();
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009881 return -EINVAL;
9882 }
9883
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309884 if (enable == true)
9885 hdd_ctx->is_pktlog_enabled = 1;
9886 else
9887 hdd_ctx->is_pktlog_enabled = 0;
9888
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009889 return 0;
9890}
9891#endif /* REMOVE_PKT_LOG */
9892
Komal Seelam92fff912016-03-24 11:51:41 +05309893/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009894 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
9895 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05309896 * @dev: Device Pointer
9897 * @num: Number of Valid Mac address
9898 *
9899 * Return: Pointer to MAC address buffer
9900 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009901static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9902 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309903{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009904 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309905}
Komal Seelam92fff912016-03-24 11:51:41 +05309906
9907/**
9908 * hdd_populate_random_mac_addr() - API to populate random mac addresses
9909 * @hdd_ctx: HDD Context
9910 * @num: Number of random mac addresses needed
9911 *
9912 * Generate random addresses using bit manipulation on the base mac address
9913 *
9914 * Return: None
9915 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009916void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05309917{
9918 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
9919 uint32_t iter;
9920 struct hdd_config *ini = hdd_ctx->config;
9921 uint8_t *buf = NULL;
9922 uint8_t macaddr_b3, tmp_br3;
9923 uint8_t *src = ini->intfMacAddr[0].bytes;
9924
9925 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
9926 buf = ini->intfMacAddr[iter].bytes;
9927 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
9928 macaddr_b3 = buf[3];
9929 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
9930 INTF_MACADDR_MASK;
9931 macaddr_b3 += tmp_br3;
9932 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
9933 buf[0] |= 0x02;
9934 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009935 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309936 }
9937}
9938
9939/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009940 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05309941 * @hdd_ctx: HDD Context
9942 *
9943 * API to get mac addresses from platform driver and update the driver
9944 * structures and configure FW with the base mac address.
9945 * Return: int
9946 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009947static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309948{
9949 uint32_t no_of_mac_addr, iter;
9950 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
9951 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
9952 uint8_t *addr, *buf;
9953 struct device *dev = hdd_ctx->parent_dev;
9954 struct hdd_config *ini = hdd_ctx->config;
9955 tSirMacAddr mac_addr;
9956 QDF_STATUS status;
9957
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009958 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05309959
Dustin Brown7e761c72018-07-31 13:50:17 -07009960 if (no_of_mac_addr == 0 || !addr)
Komal Seelam92fff912016-03-24 11:51:41 +05309961 return -EINVAL;
Komal Seelam92fff912016-03-24 11:51:41 +05309962
9963 if (no_of_mac_addr > max_mac_addr)
9964 no_of_mac_addr = max_mac_addr;
9965
9966 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
9967
9968 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
9969 buf = ini->intfMacAddr[iter].bytes;
9970 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009971 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309972 }
9973
9974 status = sme_set_custom_mac_addr(mac_addr);
9975
9976 if (!QDF_IS_STATUS_SUCCESS(status))
9977 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009978
Komal Seelam92fff912016-03-24 11:51:41 +05309979 if (no_of_mac_addr < max_mac_addr)
9980 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
9981 no_of_mac_addr);
9982 return 0;
9983}
9984
9985/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009986 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
9987 * @hdd_ctx: HDD Context
9988 *
9989 * Update MAC address to FW. If MAC address passed by FW is invalid, host
9990 * will generate its own MAC and update it to FW.
9991 *
9992 * Return: 0 for success
9993 * Non-zero error code for failure
9994 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009995static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009996{
9997 tSirMacAddr customMacAddr;
9998 QDF_STATUS status;
9999
10000 qdf_mem_copy(&customMacAddr,
10001 &hdd_ctx->config->intfMacAddr[0].bytes[0],
10002 sizeof(tSirMacAddr));
10003 status = sme_set_custom_mac_addr(customMacAddr);
10004 if (!QDF_IS_STATUS_SUCCESS(status))
10005 return -EAGAIN;
10006 return 0;
10007}
10008
10009/**
Komal Seelam92fff912016-03-24 11:51:41 +053010010 * hdd_initialize_mac_address() - API to get wlan mac addresses
10011 * @hdd_ctx: HDD Context
10012 *
10013 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
10014 * is provisioned with mac addresses, driver uses it, else it will use
10015 * wlan_mac.bin to update HW MAC addresses.
10016 *
10017 * Return: None
10018 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010019static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +053010020{
10021 QDF_STATUS status;
10022 int ret;
10023
Yuanyuan Liu7145eb22016-12-01 10:59:29 -080010024 ret = hdd_platform_wlan_mac(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010025 if (!ret) {
10026 hdd_info("using MAC address from platform driver");
Komal Seelam92fff912016-03-24 11:51:41 +053010027 return;
Dustin Brown7e761c72018-07-31 13:50:17 -070010028 }
Komal Seelam92fff912016-03-24 11:51:41 +053010029
10030 status = hdd_update_mac_config(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010031 if (QDF_IS_STATUS_SUCCESS(status)) {
10032 hdd_info("using MAC address from wlan_mac.bin");
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010033 return;
Dustin Brown7e761c72018-07-31 13:50:17 -070010034 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010035
Dustin Brown7e761c72018-07-31 13:50:17 -070010036 hdd_info("using default MAC address");
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010037
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -080010038 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010039 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Dustin Brown7e761c72018-07-31 13:50:17 -070010040 if (ret)
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -080010041 hdd_err("MAC address out-of-sync, ret:%d", ret);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -070010042 }
Komal Seelam92fff912016-03-24 11:51:41 +053010043}
10044
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010045static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010046{
10047 int vdev_id = 0;
10048 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
10049 int value = hdd_ctx->config->smart_chainmask_enabled;
10050 int vpdev = PDEV_CMD;
10051 int ret;
10052
Naveen Rawat247a8682017-06-05 15:00:31 -070010053 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010054 if (ret)
10055 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
10056
10057 return ret;
10058}
10059
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010060static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010061{
10062 int vdev_id = 0;
10063 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
10064 int value = hdd_ctx->config->alternative_chainmask_enabled;
10065 int vpdev = PDEV_CMD;
10066 int ret;
10067
Naveen Rawat247a8682017-06-05 15:00:31 -070010068 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010069 if (ret)
10070 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
10071 ret);
10072
10073 return ret;
10074}
10075
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010076static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -070010077{
10078 int vdev_id = 0;
10079 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
10080 int value = hdd_ctx->config->ani_enabled;
10081 int vpdev = PDEV_CMD;
10082 int ret;
10083
Naveen Rawat247a8682017-06-05 15:00:31 -070010084 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -070010085 if (ret)
10086 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
10087
10088 return ret;
10089}
10090
Jeff Johnson89c66ff2016-04-22 15:21:37 -070010091/**
Prashanth Bhatta07998752016-04-28 12:35:33 -070010092 * hdd_pre_enable_configure() - Configurations prior to cds_enable
10093 * @hdd_ctx: HDD context
10094 *
10095 * Pre configurations to be done at lower layer before calling cds enable.
10096 *
10097 * Return: 0 on success and errno on failure.
10098 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010099static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -070010100{
10101 int ret;
10102 QDF_STATUS status;
Leo Changfdb45c32016-10-28 11:09:23 -070010103 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010104
Leo Changfdb45c32016-10-28 11:09:23 -070010105 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Ajit Pal Singh5d269612018-04-19 16:29:12 +053010106 /* Register HL netdev flow control callback */
10107 cdp_hl_fc_register(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010108 /*
10109 * Set 802.11p config
10110 * TODO-OCB: This has been temporarily added here to ensure this
10111 * parameter is set in CSR when we init the channel list. This should
10112 * be removed once the 5.9 GHz channels are added to the regulatory
10113 * domain.
10114 */
10115 hdd_set_dot11p_config(hdd_ctx);
10116
10117 /*
10118 * Note that the cds_pre_enable() sequence triggers the cfg download.
10119 * The cfg download must occur before we update the SME config
10120 * since the SME config operation must access the cfg database
10121 */
10122 status = hdd_set_sme_config(hdd_ctx);
10123
10124 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010125 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010126 ret = qdf_status_to_os_return(status);
10127 goto out;
10128 }
10129
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -070010130 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
10131 if (QDF_STATUS_SUCCESS != status) {
10132 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
10133 ret = qdf_status_to_os_return(status);
10134 goto out;
10135 }
10136
Naveen Rawat247a8682017-06-05 15:00:31 -070010137 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -070010138 hdd_ctx->config->tx_chain_mask_1ss,
10139 PDEV_CMD);
10140 if (0 != ret) {
10141 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
10142 goto out;
10143 }
10144
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010145 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
10146 if (ret)
10147 goto out;
10148
10149 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
10150 if (ret)
10151 goto out;
10152
Jeff Johnson12a744b2017-04-04 08:19:37 -070010153 ret = hdd_set_ani_enabled(hdd_ctx);
10154 if (ret)
10155 goto out;
10156
Naveen Rawat247a8682017-06-05 15:00:31 -070010157 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -080010158 hdd_ctx->config->arp_ac_category,
10159 PDEV_CMD);
10160 if (0 != ret) {
10161 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
10162 hdd_ctx->config->arp_ac_category, ret);
10163 goto out;
10164 }
10165
Prashanth Bhatta07998752016-04-28 12:35:33 -070010166 status = hdd_set_sme_chan_list(hdd_ctx);
10167 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010168 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010169 ret = qdf_status_to_os_return(status);
10170 goto out;
10171 }
10172
10173 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -070010174 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010175 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -070010176 ret = -EINVAL;
10177 goto out;
10178 }
10179
Prashanth Bhatta07998752016-04-28 12:35:33 -070010180 /*
10181 * Set the MAC Address Currently this is used by HAL to add self sta.
10182 * Remove this once self sta is added as part of session open.
10183 */
Jeff Johnson16528362018-06-14 12:34:16 -070010184 status = sme_cfg_set_str(hdd_ctx->mac_handle, WNI_CFG_STA_ID,
Jeff Johnsonbae59f92018-06-01 17:05:43 -070010185 hdd_ctx->config->intfMacAddr[0].bytes,
10186 sizeof(hdd_ctx->config->intfMacAddr[0]));
Prashanth Bhatta07998752016-04-28 12:35:33 -070010187
Jeff Johnsonbae59f92018-06-01 17:05:43 -070010188 if (QDF_IS_STATUS_ERROR(status)) {
10189 hdd_err("Failed to set MAC Address, status %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010190 ret = -EINVAL;
10191 goto out;
10192 }
10193
10194 hdd_init_channel_avoidance(hdd_ctx);
10195
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +053010196 /* update enable sap mandatory chan list */
10197 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
10198 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010199out:
10200 return ret;
10201}
10202
10203/**
Peng Xu8fdaa492016-06-22 10:20:47 -070010204 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010205 * @context: context registered with sme_register_p2p_lo_event(). HDD
10206 * always registers a hdd context pointer
10207 * @evt:event structure pointer
Peng Xu8fdaa492016-06-22 10:20:47 -070010208 *
10209 * This is the p2p listen offload stop event handler, it sends vendor
10210 * event back to supplicant to notify the stop reason.
10211 *
10212 * Return: None
10213 */
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010214static void wlan_hdd_p2p_lo_event_callback(void *context,
10215 struct sir_p2p_lo_event *evt)
Peng Xu8fdaa492016-06-22 10:20:47 -070010216{
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010217 struct hdd_context *hdd_ctx = context;
Peng Xu8fdaa492016-06-22 10:20:47 -070010218 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -070010219 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -070010220
Dustin Brown491d54b2018-03-14 12:39:11 -070010221 hdd_enter();
Peng Xu8fdaa492016-06-22 10:20:47 -070010222
10223 if (hdd_ctx == NULL) {
10224 hdd_err("Invalid HDD context pointer");
10225 return;
10226 }
10227
Peng Xu5c682812017-08-06 07:39:13 -070010228 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
10229 if (!adapter) {
10230 hdd_err("Cannot find adapter by vdev_id = %d",
10231 evt->vdev_id);
10232 return;
10233 }
10234
Peng Xu8fdaa492016-06-22 10:20:47 -070010235 vendor_event =
10236 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -070010237 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -070010238 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
10239 GFP_KERNEL);
10240
10241 if (!vendor_event) {
10242 hdd_err("cfg80211_vendor_event_alloc failed");
10243 return;
10244 }
10245
10246 if (nla_put_u32(vendor_event,
10247 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
10248 evt->reason_code)) {
10249 hdd_err("nla put failed");
10250 kfree_skb(vendor_event);
10251 return;
10252 }
10253
10254 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -070010255 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
10256 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -070010257}
10258
Rachit Kankanef6834c42018-08-02 18:47:50 +053010259#ifdef FEATURE_WLAN_DYNAMIC_CVM
10260static inline int hdd_set_vc_mode_config(struct hdd_context *hdd_ctx)
10261{
10262 return sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap);
10263}
10264#else
10265static inline int hdd_set_vc_mode_config(struct hdd_context *hdd_ctx)
10266{
10267 return QDF_STATUS_SUCCESS;
10268}
10269#endif
10270
Peng Xu8fdaa492016-06-22 10:20:47 -070010271/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010272 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
10273 * @hdd_ctx: HDD context
10274 *
10275 * This function sends the adaptive dwell time config configuration to the
10276 * firmware via WMA
10277 *
10278 * Return: 0 - success, < 0 - failure
10279 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010280static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010281{
10282 QDF_STATUS status;
10283 struct adaptive_dwelltime_params dwelltime_params;
10284
10285 dwelltime_params.is_enabled =
10286 hdd_ctx->config->adaptive_dwell_mode_enabled;
10287 dwelltime_params.dwelltime_mode =
10288 hdd_ctx->config->global_adapt_dwelltime_mode;
10289 dwelltime_params.lpf_weight =
10290 hdd_ctx->config->adapt_dwell_lpf_weight;
10291 dwelltime_params.passive_mon_intval =
10292 hdd_ctx->config->adapt_dwell_passive_mon_intval;
10293 dwelltime_params.wifi_act_threshold =
10294 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
10295
Jeff Johnson16528362018-06-14 12:34:16 -070010296 status = sme_set_adaptive_dwelltime_config(hdd_ctx->mac_handle,
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010297 &dwelltime_params);
10298
10299 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
10300 if (!QDF_IS_STATUS_SUCCESS(status)) {
10301 hdd_err("Failed to send Adaptive Dwelltime configuration!");
10302 return -EAGAIN;
10303 }
10304 return 0;
10305}
10306
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010307int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010308{
10309 QDF_STATUS status;
10310 struct wmi_dbs_scan_sel_params dbs_scan_params;
10311 uint32_t i = 0;
10312 uint8_t count = 0, numentries = 0;
10313 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
10314 * CDS_DBS_SCAN_CLIENTS_MAX];
10315
10316 /* check if DBS is enabled or supported */
Bala Venkateshc8236ca2018-03-09 12:38:29 +053010317 if ((hdd_ctx->config->dual_mac_feature_disable ==
10318 DISABLE_DBS_CXN_AND_SCAN) ||
10319 (hdd_ctx->config->dual_mac_feature_disable ==
10320 ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN))
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010321 return -EINVAL;
10322
10323 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
10324 dbs_scan_config, &numentries,
10325 (CDS_DBS_SCAN_PARAM_PER_CLIENT
10326 * CDS_DBS_SCAN_CLIENTS_MAX));
10327
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010328 if (!numentries) {
Dustin Brown6a8d39b2018-08-14 15:27:26 -070010329 hdd_debug("Do not send scan_selection_config");
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010330 return 0;
10331 }
10332
10333 /* hdd_set_fw_log_params */
10334 dbs_scan_params.num_clients = 0;
10335 while (count < (numentries - 2)) {
10336 dbs_scan_params.module_id[i] = dbs_scan_config[count];
10337 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
10338 dbs_scan_params.num_non_dbs_scans[i] =
10339 dbs_scan_config[count + 2];
10340 dbs_scan_params.num_clients++;
10341 hdd_debug("module:%d NDS:%d NNDS:%d",
10342 dbs_scan_params.module_id[i],
10343 dbs_scan_params.num_dbs_scans[i],
10344 dbs_scan_params.num_non_dbs_scans[i]);
10345 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
10346 i++;
10347 }
10348
10349 dbs_scan_params.pdev_id = 0;
10350
10351 hdd_debug("clients:%d pdev:%d",
10352 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
10353
Jeff Johnson16528362018-06-14 12:34:16 -070010354 status = sme_set_dbs_scan_selection_config(hdd_ctx->mac_handle,
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010355 &dbs_scan_params);
10356 hdd_debug("Sending DBS Scan Selection Configuration to fw");
10357 if (!QDF_IS_STATUS_SUCCESS(status)) {
10358 hdd_err("Failed to send DBS Scan selection configuration!");
10359 return -EAGAIN;
10360 }
10361 return 0;
10362}
10363
Arun Khandavallid4349a92016-07-25 11:10:43 +053010364#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10365/**
10366 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
10367 * @hdd_ctx: HDD context
10368 *
10369 * Set auto shutdown callback to get indications from firmware to indicate
10370 * userspace to shutdown WLAN after a configured amount of inactivity.
10371 *
10372 * Return: 0 on success and errno on failure.
10373 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010374static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010375{
10376 QDF_STATUS status;
10377
10378 if (!hdd_ctx->config->WlanAutoShutdown)
10379 return 0;
10380
Jeff Johnson16528362018-06-14 12:34:16 -070010381 status = sme_set_auto_shutdown_cb(hdd_ctx->mac_handle,
Arun Khandavallid4349a92016-07-25 11:10:43 +053010382 wlan_hdd_auto_shutdown_cb);
10383 if (status != QDF_STATUS_SUCCESS)
10384 hdd_err("Auto shutdown feature could not be enabled: %d",
10385 status);
10386
10387 return qdf_status_to_os_return(status);
10388}
10389#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010390static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010391{
10392 return 0;
10393}
10394#endif
10395
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010396#ifdef MWS_COEX
10397/**
10398 * hdd_set_mws_coex() - Set MWS coex configurations
10399 * @hdd_ctx: HDD context
10400 *
10401 * This function sends MWS-COEX 4G quick FTDM and
10402 * MWS-COEX 5G-NR power limit to FW
10403 *
10404 * Return: 0 on success and errno on failure.
10405 */
10406static int hdd_init_mws_coex(struct hdd_context *hdd_ctx)
10407{
10408 int ret = 0;
10409
10410 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_MWSCOEX_4G_ALLOW_QUICK_FTDM,
10411 hdd_ctx->config->mws_coex_4g_quick_tdm,
10412 PDEV_CMD);
10413 if (ret) {
10414 hdd_warn("Unable to send MWS-COEX 4G quick FTDM policy");
10415 return ret;
10416 }
10417
10418 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_MWSCOEX_SET_5GNR_PWR_LIMIT,
10419 hdd_ctx->config->mws_coex_5g_nr_pwr_limit,
10420 PDEV_CMD);
10421 if (ret) {
10422 hdd_warn("Unable to send MWS-COEX 4G quick FTDM policy");
10423 return ret;
10424 }
10425 return ret;
10426}
10427#else
10428static int hdd_init_mws_coex(struct hdd_context *hdd_ctx)
10429{
10430 return 0;
10431}
10432#endif
10433
Arun Khandavallid4349a92016-07-25 11:10:43 +053010434/**
10435 * hdd_features_init() - Init features
10436 * @hdd_ctx: HDD context
Arun Khandavallid4349a92016-07-25 11:10:43 +053010437 *
10438 * Initialize features and their feature context after WLAN firmware is up.
10439 *
10440 * Return: 0 on success and errno on failure.
10441 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010442static int hdd_features_init(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010443{
10444 tSirTxPowerLimit hddtxlimit;
10445 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +053010446 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010447 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070010448 mac_handle_t mac_handle;
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010449 struct hdd_config *cfg;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010450
Dustin Brown491d54b2018-03-14 12:39:11 -070010451 hdd_enter();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010452
Dundi Ravitejaeab3b8d2018-07-17 18:10:41 +053010453 ret = hdd_init_mws_coex(hdd_ctx);
10454 if (ret)
10455 hdd_warn("Error initializing mws-coex");
10456
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010457 cfg = hdd_ctx->config;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010458 /* FW capabilities received, Set the Dot11 mode */
Jeff Johnson16528362018-06-14 12:34:16 -070010459 mac_handle = hdd_ctx->mac_handle;
10460 sme_setdef_dot11mode(mac_handle);
10461 sme_set_prefer_80MHz_over_160MHz(mac_handle,
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -070010462 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010463 sme_set_etsi13_srd_ch_in_master_mode(mac_handle,
10464 cfg->
10465 etsi13_srd_chan_in_master_mode);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010466
10467 if (hdd_ctx->config->fIsImpsEnabled)
10468 hdd_set_idle_ps_config(hdd_ctx, true);
10469 else
10470 hdd_set_idle_ps_config(hdd_ctx, false);
10471
Poddar, Siddarth37033032017-10-11 15:47:40 +053010472 /* Send Enable/Disable data stall detection cmd to FW */
10473 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
10474 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
10475
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010476 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Jeff Johnson16528362018-06-14 12:34:16 -070010477 sme_set_cts2self_for_p2p_go(mac_handle);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010478
Rachit Kankanef6834c42018-08-02 18:47:50 +053010479 if (hdd_set_vc_mode_config(hdd_ctx))
Nachiket Kukade8983cf62017-10-12 18:14:48 +053010480 hdd_warn("Error in setting Voltage Corner mode config to FW");
10481
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010482 if (hdd_rx_ol_init(hdd_ctx))
10483 hdd_err("Unable to initialize Rx LRO/GRO in fw");
Arun Khandavallid4349a92016-07-25 11:10:43 +053010484
10485 if (hdd_adaptive_dwelltime_init(hdd_ctx))
10486 hdd_err("Unable to send adaptive dwelltime setting to FW");
10487
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010488 if (hdd_dbs_scan_selection_init(hdd_ctx))
10489 hdd_err("Unable to send DBS scan selection setting to FW");
10490
Arun Khandavallid4349a92016-07-25 11:10:43 +053010491 ret = hdd_init_thermal_info(hdd_ctx);
10492 if (ret) {
10493 hdd_err("Error while initializing thermal information");
Dustin Browne7e71d32018-05-11 16:00:08 -070010494 return ret;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010495 }
10496
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010497 /**
10498 * In case of SSR/PDR, if pktlog was enabled manually before
10499 * SSR/PDR, Then enabled it again automatically after Wlan
10500 * device up.
10501 */
10502 if (cds_is_driver_recovering()) {
10503 if (hdd_ctx->is_pktlog_enabled)
10504 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Alok Kumar5a75b9d2018-08-31 10:55:43 +053010505 } else if (cds_is_packet_log_enabled())
10506 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Poddar, Siddarth66a46592017-02-22 11:44:44 +053010507
Arun Khandavallid4349a92016-07-25 11:10:43 +053010508 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
10509 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
Jeff Johnson16528362018-06-14 12:34:16 -070010510 status = sme_txpower_limit(mac_handle, &hddtxlimit);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010511 if (!QDF_IS_STATUS_SUCCESS(status))
10512 hdd_err("Error setting txlimit in sme: %d", status);
10513
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010514 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010515
Arun Khandavallid4349a92016-07-25 11:10:43 +053010516 ret = hdd_register_cb(hdd_ctx);
10517 if (ret) {
10518 hdd_err("Failed to register HDD callbacks!");
Dustin Browne7e71d32018-05-11 16:00:08 -070010519 return ret;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010520 }
10521
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +053010522 if (hdd_ctx->config->goptimize_chan_avoid_event) {
10523 status = sme_enable_disable_chanavoidind_event(
Jeff Johnson16528362018-06-14 12:34:16 -070010524 mac_handle, 0);
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +053010525 if (!QDF_IS_STATUS_SUCCESS(status)) {
10526 hdd_err("Failed to disable Chan Avoidance Indication");
10527 goto deregister_cb;
10528 }
10529 }
Arun Khandavallid4349a92016-07-25 11:10:43 +053010530
Manjeet Singha9cae432017-02-28 11:58:22 +053010531 if (hdd_ctx->config->enable_5g_band_pref) {
10532 band_pref_params.rssi_boost_threshold_5g =
10533 hdd_ctx->config->rssi_boost_threshold_5g;
10534 band_pref_params.rssi_boost_factor_5g =
10535 hdd_ctx->config->rssi_boost_factor_5g;
10536 band_pref_params.max_rssi_boost_5g =
10537 hdd_ctx->config->max_rssi_boost_5g;
10538 band_pref_params.rssi_penalize_threshold_5g =
10539 hdd_ctx->config->rssi_penalize_threshold_5g;
10540 band_pref_params.rssi_penalize_factor_5g =
10541 hdd_ctx->config->rssi_penalize_factor_5g;
10542 band_pref_params.max_rssi_penalize_5g =
10543 hdd_ctx->config->max_rssi_penalize_5g;
Jeff Johnson16528362018-06-14 12:34:16 -070010544 sme_set_5g_band_pref(mac_handle, &band_pref_params);
Manjeet Singha9cae432017-02-28 11:58:22 +053010545 }
10546
Arun Khandavallid4349a92016-07-25 11:10:43 +053010547 /* register P2P Listen Offload event callback */
10548 if (wma_is_p2p_lo_capable())
Jeff Johnson16528362018-06-14 12:34:16 -070010549 sme_register_p2p_lo_event(mac_handle, hdd_ctx,
10550 wlan_hdd_p2p_lo_event_callback);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010551
10552 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
10553
10554 if (ret)
10555 goto deregister_cb;
10556
Dustin Brown11638b72018-01-25 17:37:25 +053010557 wlan_hdd_init_chan_info(hdd_ctx);
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010558 wlan_hdd_twt_init(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010559
Dustin Browne74003f2018-03-14 12:51:58 -070010560 hdd_exit();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010561 return 0;
10562
10563deregister_cb:
10564 hdd_deregister_cb(hdd_ctx);
Dustin Browne7e71d32018-05-11 16:00:08 -070010565
Arun Khandavallid4349a92016-07-25 11:10:43 +053010566 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010567}
10568
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010569/**
10570 * hdd_features_deinit() - Deinit features
10571 * @hdd_ctx: HDD context
10572 *
10573 * De-Initialize features and their feature context.
10574 *
10575 * Return: none.
10576 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010577static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010578{
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010579 wlan_hdd_twt_deinit(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010580 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010581 wlan_hdd_tsf_deinit(hdd_ctx);
10582}
10583
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010584/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010585 * hdd_register_bcn_cb() - register scan beacon callback
10586 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010587 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010588 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010589 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010590static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010591{
10592 QDF_STATUS status;
10593
10594 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
10595 wlan_cfg80211_inform_bss_frame,
10596 SCAN_CB_TYPE_INFORM_BCN);
10597 if (!QDF_IS_STATUS_SUCCESS(status)) {
10598 hdd_err("failed with status code %08d [x%08x]",
10599 status, status);
10600 return status;
10601 }
10602
10603 return QDF_STATUS_SUCCESS;
10604}
Arun Khandavallid4349a92016-07-25 11:10:43 +053010605
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010606/**
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070010607 * hdd_v2_flow_pool_map() - Flow pool create callback when vdev is active
10608 * @vdev_id: vdev_id, corresponds to flow_pool
10609 *
10610 * Return: none.
10611 */
10612static void hdd_v2_flow_pool_map(int vdev_id)
10613{
10614 QDF_STATUS status;
10615
10616 status = cdp_flow_pool_map(cds_get_context(QDF_MODULE_ID_SOC),
10617 cds_get_context(QDF_MODULE_ID_TXRX),
10618 vdev_id);
10619 /*
10620 * For Adrastea flow control v2 is based on FW MAP events,
10621 * so this above callback is not implemented.
10622 * Hence this is not actual failure. Dont return failure
10623 */
10624 if ((status != QDF_STATUS_SUCCESS) &&
10625 (status != QDF_STATUS_E_INVAL)) {
10626 hdd_err("vdev_id: %d, failed to create flow pool status %d",
10627 vdev_id, status);
10628 }
10629}
10630
10631/**
10632 * hdd_v2_flow_pool_unmap() - Flow pool create callback when vdev is not active
10633 * @vdev_id: vdev_id, corresponds to flow_pool
10634 *
10635 * Return: none.
10636 */
10637static void hdd_v2_flow_pool_unmap(int vdev_id)
10638{
10639 cdp_flow_pool_unmap(cds_get_context(QDF_MODULE_ID_SOC),
10640 cds_get_context(QDF_MODULE_ID_TXRX), vdev_id);
10641}
10642
10643/**
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010644 * hdd_action_oui_config() - Configure action_oui strings
10645 * @hdd_ctx: pointer to hdd context
10646 *
10647 * This is a HDD wrapper function which invokes ucfg api
10648 * of action_oui component to parse action oui strings.
10649 *
10650 * Return: None
10651 */
10652static void hdd_action_oui_config(struct hdd_context *hdd_ctx)
10653{
10654 QDF_STATUS status;
10655 uint32_t id;
10656 uint8_t *str;
10657
10658 if (!hdd_ctx->config->action_oui_enable)
10659 return;
10660
10661 for (id = 0; id < ACTION_OUI_MAXIMUM_ID; id++) {
10662 str = hdd_ctx->config->action_oui_str[id];
10663 if (!qdf_str_len(str))
10664 continue;
10665
10666 status = ucfg_action_oui_parse(hdd_ctx->hdd_psoc, str, id);
10667 if (!QDF_IS_STATUS_SUCCESS(status))
10668 hdd_err("Failed to parse action_oui str: %u", id);
10669 }
10670}
10671
10672/**
10673 * hdd_action_oui_send() - Send action_oui extensions to firmware
10674 * @hdd_ctx: pointer to hdd context
10675 *
10676 * This is a HDD wrapper function which invokes ucfg api
10677 * of action_oui component to send action oui extensions to firmware.
10678 *
10679 * Return: None
10680 */
10681static void hdd_action_oui_send(struct hdd_context *hdd_ctx)
10682{
10683 QDF_STATUS status;
10684
10685 if (!hdd_ctx->config->action_oui_enable)
10686 return;
10687
10688 status = ucfg_action_oui_send(hdd_ctx->hdd_psoc);
10689 if (!QDF_IS_STATUS_SUCCESS(status))
10690 hdd_err("Failed to send one or all action_ouis");
10691}
10692
10693/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010694 * hdd_configure_cds() - Configure cds modules
10695 * @hdd_ctx: HDD context
10696 * @adapter: Primary adapter context
10697 *
10698 * Enable Cds modules after WLAN firmware is up.
10699 *
10700 * Return: 0 on success and errno on failure.
10701 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010702int hdd_configure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010703{
10704 int ret;
10705 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010706 int set_value;
Jeff Johnson16528362018-06-14 12:34:16 -070010707 mac_handle_t mac_handle;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010708 uint32_t num_abg_tx_chains = 0;
10709 uint32_t num_11b_tx_chains = 0;
10710 uint32_t num_11ag_tx_chains = 0;
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010711 struct policy_mgr_dp_cbacks dp_cbs = {0};
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010712
Jeff Johnson16528362018-06-14 12:34:16 -070010713 mac_handle = hdd_ctx->mac_handle;
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010714
10715 hdd_action_oui_send(hdd_ctx);
10716
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010717 if (hdd_ctx->config->is_force_1x1)
10718 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
10719 1, PDEV_CMD);
10720 /* set chip power save failure detected callback */
Jeff Johnson16528362018-06-14 12:34:16 -070010721 sme_set_chip_pwr_save_fail_cb(mac_handle,
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010722 hdd_chip_pwr_save_fail_detected_cb);
10723
10724 if (hdd_ctx->config->max_mpdus_inampdu) {
10725 set_value = hdd_ctx->config->max_mpdus_inampdu;
10726 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
10727 set_value, PDEV_CMD);
10728 }
10729
10730 if (hdd_ctx->config->enable_rts_sifsbursting) {
10731 set_value = hdd_ctx->config->enable_rts_sifsbursting;
10732 sme_cli_set_command(0,
10733 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
10734 set_value, PDEV_CMD);
10735 }
10736
10737 if (hdd_ctx->config->sap_get_peer_info) {
10738 set_value = hdd_ctx->config->sap_get_peer_info;
10739 sme_cli_set_command(0,
10740 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
10741 set_value, PDEV_CMD);
10742 }
10743
10744 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
10745 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
10746 if (!hdd_ctx->config->enable2x2) {
10747 if (num_11b_tx_chains > 1)
10748 num_11b_tx_chains = 1;
10749 if (num_11ag_tx_chains > 1)
10750 num_11ag_tx_chains = 1;
10751 }
10752 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
10753 num_11b_tx_chains);
10754 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
10755 num_11ag_tx_chains);
10756 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
10757 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +053010758
10759 ret = hdd_pre_enable_configure(hdd_ctx);
10760 if (ret) {
10761 hdd_err("Failed to pre-configure cds");
10762 goto out;
10763 }
10764
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010765 /* Always get latest IPA resources allocated from cds_open and configure
10766 * IPA module before configuring them to FW. Sequence required as crash
10767 * observed otherwise.
10768 */
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010769 if (ucfg_ipa_uc_ol_init(hdd_ctx->hdd_pdev,
10770 cds_get_context(QDF_MODULE_ID_QDF_DEVICE))) {
Manikandan Mohan2e803a02017-02-14 14:57:53 -080010771 hdd_err("Failed to setup pipes");
10772 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010773 }
10774
Arun Khandavallifae92942016-08-01 13:31:08 +053010775 /*
10776 * Start CDS which starts up the SME/MAC/HAL modules and everything
10777 * else
10778 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -070010779 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010780
10781 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010782 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053010783 goto out;
10784 }
10785
10786 status = hdd_post_cds_enable_config(hdd_ctx);
10787 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010788 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010789 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010790 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010791 status = hdd_register_bcn_cb(hdd_ctx);
10792 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +080010793 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010794 goto cds_disable;
10795 }
Arun Khandavallifae92942016-08-01 13:31:08 +053010796
Dustin Browne7e71d32018-05-11 16:00:08 -070010797 ret = hdd_features_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010798 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010799 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010800
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010801 if (hdd_ctx->ol_enable)
10802 dp_cbs.hdd_disable_rx_ol_in_concurrency =
10803 hdd_disable_rx_ol_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -070010804 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
jiadbb47e132018-03-30 16:28:30 +080010805 dp_cbs.hdd_ipa_set_mcc_mode_cb = hdd_ipa_set_mcc_mode;
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070010806 dp_cbs.hdd_v2_flow_pool_map = hdd_v2_flow_pool_map;
10807 dp_cbs.hdd_v2_flow_pool_unmap = hdd_v2_flow_pool_unmap;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010808 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
10809 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -070010810 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010811 goto cds_disable;
10812 }
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010813 status = policy_mgr_register_mode_change_cb(hdd_ctx->hdd_psoc,
10814 wlan_hdd_send_mode_change_event);
10815 if (!QDF_IS_STATUS_SUCCESS(status)) {
10816 hdd_debug("Failed to register mode change cb with Policy Manager");
10817 goto cds_disable;
10818 }
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010819
Jeff Johnson8bb61112018-03-31 13:33:54 -070010820 if (hdd_green_ap_enable_egap(hdd_ctx))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +053010821 hdd_debug("enhance green ap is not enabled");
10822
Nachiket Kukadedd302662017-07-13 17:31:44 +053010823 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
10824 hdd_debug("Failed to set wow pulse");
10825
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053010826 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
10827 hdd_ctx->config->gcmp_enabled, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053010828 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
10829 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
10830
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053010831
10832 if (hdd_ctx->config->enable_phy_reg_retention)
10833 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
10834 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
10835
Arun Khandavallifae92942016-08-01 13:31:08 +053010836 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010837
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010838cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010839 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010840
Arun Khandavallifae92942016-08-01 13:31:08 +053010841out:
10842 return -EINVAL;
10843}
10844
10845/**
10846 * hdd_deconfigure_cds() -De-Configure cds
10847 * @hdd_ctx: HDD context
10848 *
10849 * Deconfigure Cds modules before WLAN firmware is down.
10850 *
10851 * Return: 0 on success and errno on failure.
10852 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010853static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010854{
10855 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070010856 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053010857
Dustin Brown491d54b2018-03-14 12:39:11 -070010858 hdd_enter();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010859
10860 /* De-init features */
10861 hdd_features_deinit(hdd_ctx);
10862
Arun Khandavallifae92942016-08-01 13:31:08 +053010863 /* De-register the SME callbacks */
10864 hdd_deregister_cb(hdd_ctx);
10865
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010866 qdf_status = policy_mgr_deregister_mode_change_cb(hdd_ctx->hdd_psoc);
10867 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10868 hdd_debug("Failed to deregister mode change cb with Policy Manager");
10869 }
10870
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010871 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010872 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10873 hdd_err("Failed to Disable the CDS Modules! :%d",
10874 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070010875 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010876 }
10877
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010878 if (ucfg_ipa_uc_ol_deinit(hdd_ctx->hdd_pdev) != QDF_STATUS_SUCCESS) {
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053010879 hdd_err("Failed to disconnect pipes");
10880 ret = -EINVAL;
10881 }
10882
Dustin Browne74003f2018-03-14 12:51:58 -070010883 hdd_exit();
Houston Hoffman6640cf32016-10-10 16:44:29 -070010884 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010885}
10886
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010887#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
10888static void hdd_deregister_policy_manager_callback(
10889 struct wlan_objmgr_psoc *psoc)
10890{
10891 if (QDF_STATUS_SUCCESS !=
10892 policy_mgr_deregister_hdd_cb(psoc)) {
10893 hdd_err("HDD callback deregister with policy manager failed");
10894 }
10895}
10896#else
10897static void hdd_deregister_policy_manager_callback(
10898 struct wlan_objmgr_psoc *psoc)
10899{
10900}
10901#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010902
10903/**
10904 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
10905 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010906 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +053010907 *
10908 * This function maintains the driver state machine it will be invoked from
10909 * exit, shutdown and con_mode change handler. Depending on the driver state
10910 * shall perform the stopping/closing of the modules.
10911 *
10912 * Return: 0 for success; non-zero for failure
10913 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010914int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053010915{
10916 void *hif_ctx;
10917 qdf_device_t qdf_ctx;
10918 QDF_STATUS qdf_status;
Dustin Brown4bc0a622017-12-06 15:56:50 -080010919 bool is_recovery_stop = cds_is_driver_recovering();
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053010920 int ret = 0;
Dustin Brown70111822017-03-30 15:31:40 -070010921 int active_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010922 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053010923
Dustin Brown491d54b2018-03-14 12:39:11 -070010924 hdd_enter();
Arun Khandavallifae92942016-08-01 13:31:08 +053010925
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010926 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
10927
Arun Khandavallifae92942016-08-01 13:31:08 +053010928 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
10929 if (!qdf_ctx) {
10930 hdd_err("QDF device context NULL");
10931 return -EINVAL;
10932 }
10933
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010934 mutex_lock(&hdd_ctx->iface_change_lock);
10935 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010936 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053010937
Dustin Brown70111822017-03-30 15:31:40 -070010938 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -070010939 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -070010940 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -070010941 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -070010942
10943 cds_print_external_threads();
10944
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053010945 if (IS_IDLE_STOP && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070010946 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -070010947 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10948 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010949 hdd_prevent_suspend_timeout(
10950 hdd_ctx->config->iface_change_wait_time,
10951 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010952 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010953 cds_set_module_stop_in_progress(false);
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070010954
Dustin Brown70111822017-03-30 15:31:40 -070010955 return 0;
10956 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070010957 }
10958
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080010959 /* free user wowl patterns */
10960 hdd_free_user_wowl_ptrns();
10961
Arun Khandavallifae92942016-08-01 13:31:08 +053010962 switch (hdd_ctx->driver_status) {
10963 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070010964 hdd_debug("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010965 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010966 case DRIVER_MODULES_CLOSED:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070010967 hdd_debug("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010968 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010969 case DRIVER_MODULES_ENABLED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010970 hdd_info("Wlan transitioning (OPENED <- ENABLED)");
10971
Komal Seelamf2136bb2016-09-28 18:30:44 +053010972 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053010973 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010974 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053010975 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010976 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010977 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010978 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080010979
Arun Khandavallifae92942016-08-01 13:31:08 +053010980 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010981 hdd_info("Wlan transitioned (now OPENED)");
10982
10983 /* fall through */
Arun Khandavallifae92942016-08-01 13:31:08 +053010984 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010985 hdd_info("Wlan transitioning (CLOSED <- OPENED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010986 break;
10987 default:
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070010988 QDF_DEBUG_PANIC("Unknown driver state:%d",
Arun Khandavallifae92942016-08-01 13:31:08 +053010989 hdd_ctx->driver_status);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010990 ret = -EINVAL;
10991 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010992 }
10993
Amar Singhal18081642018-01-26 16:04:13 -080010994 hdd_sysfs_destroy_version_interface();
Dustin Brown550f6d22017-12-14 15:44:01 -080010995 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080010996
Rajeev Kumarbe021242017-02-16 16:12:23 -080010997 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053010998 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10999 hdd_err("Failed to process post CDS disable Modules! :%d",
11000 qdf_status);
11001 ret = -EINVAL;
11002 QDF_ASSERT(0);
11003 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011004
psimhadeea0a12017-12-18 14:50:02 -080011005 hdd_runtime_suspend_context_deinit(hdd_ctx);
11006
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070011007 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
11008 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
11009 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
11010 ret = -EINVAL;
11011 QDF_ASSERT(0);
11012 }
11013
Jeff Johnsone4b14592017-09-13 14:23:33 -070011014 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053011015 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011016 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053011017 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011018 QDF_ASSERT(0);
11019 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -070011020
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053011021 hdd_component_psoc_close(hdd_ctx->hdd_psoc);
Amar Singhal410675c2018-01-10 12:14:21 -080011022 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Liangwei Dong50a64a72018-01-11 01:17:00 -050011023 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
11024 if (ret) {
11025 hdd_err("Failed to destroy pdev; errno:%d", ret);
11026 QDF_ASSERT(0);
11027 }
11028
11029 /*
11030 * Reset total mac phy during module stop such that during
11031 * next module start same psoc is used to populate new service
11032 * ready data
11033 */
Arunk Khandavallia6305a32018-01-25 11:19:18 +053011034 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
11035 if (tgt_hdl)
11036 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
11037
Liangwei Dong50a64a72018-01-11 01:17:00 -050011038
Arun Khandavallifae92942016-08-01 13:31:08 +053011039 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
11040 if (!hif_ctx) {
11041 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011042 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053011043 }
11044
Arunk Khandavalli4b404332017-09-26 12:46:00 +053011045 if (hdd_ctx->target_hw_name) {
11046 qdf_mem_free(hdd_ctx->target_hw_name);
11047 hdd_ctx->target_hw_name = NULL;
11048 }
11049
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053011050 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053011051
11052 ol_cds_free();
11053
Sourav Mohapatra808e3d42018-07-04 09:34:23 +053011054 if (IS_IDLE_STOP && cds_is_target_ready()) {
Arun Khandavallifae92942016-08-01 13:31:08 +053011055 ret = pld_power_off(qdf_ctx->dev);
11056 if (ret)
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011057 hdd_err("Failed to power down device; errno:%d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053011058 }
Dustin Brown1e3ec6b2018-08-07 11:18:47 -070011059
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011060 /* Free the cache channels of the command SET_DISABLE_CHANNEL_LIST */
11061 wlan_hdd_free_cache_channels(hdd_ctx);
Arunk Khandavalli847969d2017-09-25 15:15:36 +053011062
Dustin Brown29533f22018-07-24 13:11:56 -070011063 hdd_check_for_leaks(hdd_ctx, is_recovery_stop);
Dustin Brown26b3d042017-12-21 11:13:27 -080011064 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080011065
Arunk Khandavalli847969d2017-09-25 15:15:36 +053011066 /* Once the firmware sequence is completed reset this flag */
11067 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053011068 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080011069 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053011070
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011071done:
11072 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070011073 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011074 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4bc0a622017-12-06 15:56:50 -080011075
Dustin Browne74003f2018-03-14 12:51:58 -070011076 hdd_exit();
Arun Khandavallifae92942016-08-01 13:31:08 +053011077
Arun Khandavallia172c3e2016-08-26 17:33:13 +053011078 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053011079}
11080
Arun Khandavallifae92942016-08-01 13:31:08 +053011081
Wen Gong3f003382018-05-14 14:26:37 +080011082#ifdef WLAN_FEATURE_MEMDUMP_ENABLE
Arun Khandavallifae92942016-08-01 13:31:08 +053011083/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011084 * hdd_state_info_dump() - prints state information of hdd layer
11085 * @buf: buffer pointer
11086 * @size: size of buffer to be filled
11087 *
11088 * This function is used to dump state information of hdd layer
11089 *
11090 * Return: None
11091 */
11092static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
11093{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011094 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070011095 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070011096 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011097 uint16_t len = 0;
11098 char *buf = *buf_ptr;
11099
11100 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11101 if (!hdd_ctx) {
11102 hdd_err("Failed to get hdd context ");
11103 return;
11104 }
11105
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011106 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011107
11108 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070011109 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011110 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080011111 "\n is_scheduler_suspended %d",
11112 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011113
Dustin Brown920397d2017-12-13 16:27:50 -080011114 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011115 if (adapter->dev)
11116 len += scnprintf(buf + len, *size - len,
11117 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080011118 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011119 "\n device_mode: %d", adapter->device_mode);
11120 switch (adapter->device_mode) {
11121 case QDF_STA_MODE:
11122 case QDF_P2P_CLIENT_MODE:
11123 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11124 len += scnprintf(buf + len, *size - len,
11125 "\n connState: %d",
11126 hdd_sta_ctx->conn_info.connState);
11127 break;
11128
11129 default:
11130 break;
11131 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011132 }
11133
11134 *size -= len;
11135 *buf_ptr += len;
11136}
11137
11138/**
11139 * hdd_register_debug_callback() - registration function for hdd layer
11140 * to print hdd state information
11141 *
11142 * Return: None
11143 */
11144static void hdd_register_debug_callback(void)
11145{
11146 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
11147}
Wen Gong3f003382018-05-14 14:26:37 +080011148#else /* WLAN_FEATURE_MEMDUMP_ENABLE */
Wen Gongaa6d55d2018-04-26 16:33:21 +080011149static void hdd_register_debug_callback(void)
11150{
11151}
Wen Gong3f003382018-05-14 14:26:37 +080011152#endif /* WLAN_FEATURE_MEMDUMP_ENABLE */
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011153
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053011154/*
11155 * wlan_init_bug_report_lock() - Initialize bug report lock
11156 *
11157 * This function is used to create bug report lock
11158 *
11159 * Return: None
11160 */
11161static void wlan_init_bug_report_lock(void)
11162{
Jeff Johnson2b6982c2018-05-29 14:56:11 -070011163 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053011164
11165 p_cds_context = cds_get_global_context();
11166 if (!p_cds_context) {
11167 hdd_err("cds context is NULL");
11168 return;
11169 }
11170
11171 qdf_spinlock_create(&p_cds_context->bug_report_lock);
11172}
11173
Nirav Shahd21a2e32018-04-20 16:34:43 +053011174#ifdef CONFIG_DP_TRACE
Mohit Khannaf8f96822017-05-17 17:11:59 -070011175void hdd_dp_trace_init(struct hdd_config *config)
11176{
Mohit Khannaf8f96822017-05-17 17:11:59 -070011177 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
11178 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
11179 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
11180 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
11181 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
11182 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
11183 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080011184 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070011185
Nirav Shahd21a2e32018-04-20 16:34:43 +053011186 if (!config->enable_dp_trace) {
11187 hdd_err("dp trace is disabled from ini");
11188 return;
11189 }
11190
Mohit Khannaf8f96822017-05-17 17:11:59 -070011191 hdd_string_to_u8_array(config->dp_trace_config, config_params,
11192 &num_entries, sizeof(config_params));
11193
11194 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080011195 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080011196 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080011197 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080011198 else if (bw_compute_interval > 1000) {
11199 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
11200 thresh_time_limit = 1;
11201 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070011202 hdd_err("busBandwidthComputeInterval is 0, using defaults");
11203
11204 switch (num_entries) {
11205 case 4:
11206 proto_bitmap = config_params[3];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011207 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011208 case 3:
11209 verbosity = config_params[2];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011210 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011211 case 2:
11212 thresh = config_params[1];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011213 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011214 case 1:
11215 live_mode = config_params[0];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011216 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011217 default:
Dustin Browna7bb6ae2018-08-16 16:51:50 -070011218 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
11219 live_mode, thresh, thresh_time_limit,
11220 verbosity, proto_bitmap);
Mohit Khannaf8f96822017-05-17 17:11:59 -070011221 };
11222
11223 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
11224 verbosity, proto_bitmap);
11225
11226}
Nirav Shahd21a2e32018-04-20 16:34:43 +053011227#endif
11228
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011229#ifdef DISABLE_CHANNEL_LIST
11230static int wlan_hdd_cache_chann_mutex_create(struct hdd_context *hdd_ctx)
11231{
11232 return qdf_mutex_create(&hdd_ctx->cache_channel_lock);
11233}
11234#else
11235static int wlan_hdd_cache_chann_mutex_create(struct hdd_context *hdd_ctx)
11236{
11237 return 0;
11238}
11239#endif
11240
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011241/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011242 * hdd_wlan_startup() - HDD init function
11243 * @dev: Pointer to the underlying device
11244 *
11245 * This is the driver startup code executed once a WLAN device has been detected
11246 *
11247 * Return: 0 for success, < 0 for failure
11248 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011249int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011250{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011251 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011252 struct hdd_context *hdd_ctx;
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053011253 struct wlan_objmgr_psoc *psoc;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011254 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080011255 bool rtnl_held;
Jeff Johnson16528362018-06-14 12:34:16 -070011256 mac_handle_t mac_handle;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011257
Dustin Brown491d54b2018-03-14 12:39:11 -070011258 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011259
Arun Khandavallifae92942016-08-01 13:31:08 +053011260 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011261
11262 if (IS_ERR(hdd_ctx))
11263 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011264
Abhishek Singhe9068f12017-03-31 14:14:52 +053011265 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
11266 DEFAULT_PSOC_ID);
11267 if (ret) {
11268 hdd_err("Psoc creation fails!");
11269 QDF_BUG(0);
11270 goto err_hdd_free_context;
11271 }
11272
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011273 hdd_action_oui_config(hdd_ctx);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053011274 psoc = hdd_ctx->hdd_psoc;
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011275
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053011276 qdf_nbuf_init_replenish_timer();
Ashish Kumar Dhanotiya3f78e682018-03-14 11:19:27 +053011277
11278 ret = wlan_hdd_cache_chann_mutex_create(hdd_ctx);
11279 if (QDF_IS_STATUS_ERROR(ret))
11280 goto err_hdd_free_context;
11281
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053011282#ifdef FEATURE_WLAN_CH_AVOID
11283 mutex_init(&hdd_ctx->avoid_freq_lock);
11284#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053011285
Naveen Rawate02f8f52018-04-05 11:58:04 -070011286 osif_request_manager_init();
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053011287 qdf_atomic_init(&hdd_ctx->con_mode_flag);
Dustin Brown021cecd2017-12-11 13:56:43 -080011288 hdd_driver_memdump_init();
Dustin Brown86d196b2018-08-02 11:51:49 -070011289 hdd_bus_bandwidth_init(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -080011290
Dustin Browne7e71d32018-05-11 16:00:08 -070011291 ret = hdd_wlan_start_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053011292 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011293 hdd_err("Failed to start modules: %d", ret);
Dustin Brown021cecd2017-12-11 13:56:43 -080011294 goto err_memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011295 }
11296
Yingying Tang80e15f32016-09-27 18:23:01 +080011297 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011298
Jeff Johnson16528362018-06-14 12:34:16 -070011299 mac_handle = cds_get_context(QDF_MODULE_ID_SME);
11300 hdd_ctx->mac_handle = mac_handle;
11301 if (!mac_handle) {
11302 hdd_err("Mac Handle is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053011303 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011304 }
11305
Prashanth Bhatta07998752016-04-28 12:35:33 -070011306 ret = hdd_wiphy_init(hdd_ctx);
11307 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011308 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053011309 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011310 }
11311
Nirav Shahd21a2e32018-04-20 16:34:43 +053011312 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053011313
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070011314 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080011315
Paul Zhangfb02f452017-12-22 11:58:43 +080011316 ret = register_netdevice_notifier(&hdd_netdev_notifier);
11317 if (ret) {
11318 hdd_err("register_netdevice_notifier failed: %d", ret);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053011319 goto err_wiphy_unregister;
Paul Zhangfb02f452017-12-22 11:58:43 +080011320 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053011321
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011322 ret = register_reboot_notifier(&system_reboot_notifier);
11323 if (ret) {
11324 hdd_err("Failed to register reboot notifier: %d", ret);
11325 goto err_unregister_netdev;
11326 }
11327
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080011328 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011329
Jeff Johnson957bc272017-02-02 08:54:48 -080011330 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11331 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011332 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080011333 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011334 }
11335
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080011336 hdd_release_rtnl_lock();
11337 rtnl_held = false;
11338
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080011339 wlan_hdd_update_11n_mode(hdd_ctx->config);
11340
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011341#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053011342 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053011343 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011344 hdd_skip_acs_scan_timer_handler,
11345 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011346 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070011347 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040011348 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011349#endif
11350
Arunk Khandavalli40943af2017-05-15 19:25:34 +053011351 hdd_lpass_notify_wlan_version(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011352
Nirav Shahbd36b062016-07-18 11:12:59 +053011353 if (hdd_ctx->rps)
11354 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070011355
Paul Zhangfb02f452017-12-22 11:58:43 +080011356 ret = hdd_register_notifiers(hdd_ctx);
11357 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -080011358 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070011359
Paul Zhangfb02f452017-12-22 11:58:43 +080011360 status = wlansap_global_init();
11361 if (QDF_IS_STATUS_ERROR(status)) {
11362 hdd_unregister_notifiers(hdd_ctx);
11363 goto err_close_adapters;
11364 }
11365
Arun Khandavallifae92942016-08-01 13:31:08 +053011366 if (hdd_ctx->config->fIsImpsEnabled)
11367 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070011368 else
11369 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011370
Mukul Sharma07bd8752017-10-10 16:58:14 +053011371 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070011372 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
11373 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053011374 hdd_prevent_suspend_timeout(
11375 hdd_ctx->config->iface_change_wait_time,
11376 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
11377 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053011378
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011379 goto success;
11380
Jeff Johnson957bc272017-02-02 08:54:48 -080011381err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080011382 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011383
Jeff Johnson46bde382017-02-01 15:31:16 -080011384err_release_rtnl_lock:
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011385 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavallid4349a92016-07-25 11:10:43 +053011386 if (rtnl_held)
11387 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011388
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011389err_unregister_netdev:
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011390 unregister_netdevice_notifier(&hdd_netdev_notifier);
11391
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011392err_wiphy_unregister:
Rachit Kankane30807332018-06-27 18:39:36 +053011393 qdf_dp_trace_deinit();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011394 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011395
Arun Khandavallifae92942016-08-01 13:31:08 +053011396err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011397 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053011398
Dustin Brown021cecd2017-12-11 13:56:43 -080011399err_memdump_deinit:
Dustin Brown86d196b2018-08-02 11:51:49 -070011400 hdd_bus_bandwidth_deinit(hdd_ctx);
Dustin Brown021cecd2017-12-11 13:56:43 -080011401 hdd_driver_memdump_deinit();
Dustin Brown021cecd2017-12-11 13:56:43 -080011402
Naveen Rawate02f8f52018-04-05 11:58:04 -070011403 osif_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070011404 hdd_exit_netlink_services(hdd_ctx);
11405
Dustin Brown20912462017-06-07 13:48:25 -070011406 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
11407
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011408err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053011409 if (cds_is_fw_down())
11410 hdd_err("Not setting the complete event as fw is down");
11411 else
11412 hdd_start_complete(ret);
11413
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053011414 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070011415 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070011416 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011417
11418success:
Dustin Browne74003f2018-03-14 12:51:58 -070011419 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011420 return 0;
11421}
11422
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011423/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011424 * hdd_wlan_update_target_info() - update target type info
11425 * @hdd_ctx: HDD context
11426 * @context: hif context
11427 *
11428 * Update target info received from firmware in hdd context
11429 * Return:None
11430 */
11431
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011432void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053011433{
11434 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
11435
11436 if (!tgt_info) {
11437 hdd_err("Target info is Null");
11438 return;
11439 }
11440
11441 hdd_ctx->target_type = tgt_info->target_type;
11442}
11443
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011444void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp, void *context)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011445{
11446 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011447 int status;
11448 struct hdd_adapter *adapter = NULL;
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011449 struct osif_request *request = NULL;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011450
Dustin Brown491d54b2018-03-14 12:39:11 -070011451 hdd_enter();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011452
11453 if (!rsp) {
11454 hdd_err("data is null");
11455 return;
11456 }
11457
11458 status = wlan_hdd_validate_context(hdd_ctx);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011459 if (status != 0)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011460 return;
11461
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011462 request = osif_request_get(context);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011463 if (!request) {
11464 hdd_err("obselete request");
11465 return;
11466 }
11467
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011468 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
11469 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
11470 hdd_err("Invalid adapter or adapter has invalid magic");
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011471 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011472 return;
11473 }
11474
Dustin Brown5e89ef82018-03-14 11:50:23 -070011475 hdd_info("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
11476 hdd_info("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
11477 hdd_info("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
11478 hdd_info("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
11479 hdd_info("rsp->out_of_order_arp_rsp_drop_cnt :%x",
11480 rsp->out_of_order_arp_rsp_drop_cnt);
11481 hdd_info("rsp->dad_detected :%x", rsp->dad_detected);
11482 hdd_info("rsp->connect_status :%x", rsp->connect_status);
11483 hdd_info("rsp->ba_session_establishment_status :%x",
11484 rsp->ba_session_establishment_status);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011485
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011486 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011487 adapter->dad |= rsp->dad_detected;
11488 adapter->con_status = rsp->connect_status;
11489
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053011490 /* Flag true indicates connectivity check stats present. */
11491 if (rsp->connect_stats_present) {
11492 hdd_info("rsp->tcp_ack_recvd :%x", rsp->tcp_ack_recvd);
11493 hdd_info("rsp->icmpv4_rsp_recvd :%x", rsp->icmpv4_rsp_recvd);
11494 adapter->hdd_stats.hdd_tcp_stats.rx_fw_cnt = rsp->tcp_ack_recvd;
11495 adapter->hdd_stats.hdd_icmpv4_stats.rx_fw_cnt =
11496 rsp->icmpv4_rsp_recvd;
11497 }
11498
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011499 osif_request_complete(request);
11500 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011501
Dustin Browne74003f2018-03-14 12:51:58 -070011502 hdd_exit();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011503}
11504
11505/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011506 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011507 * @hdd_ctx: HDD context
11508 *
11509 * Register the HDD callbacks to CDS/SME.
11510 *
11511 * Return: 0 for success or Error code for failure
11512 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011513int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011514{
11515 QDF_STATUS status;
11516 int ret = 0;
Jeff Johnson16528362018-06-14 12:34:16 -070011517 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011518
Dustin Brown491d54b2018-03-14 12:39:11 -070011519 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011520
Jeff Johnson16528362018-06-14 12:34:16 -070011521 mac_handle = hdd_ctx->mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011522
Jeff Johnson16528362018-06-14 12:34:16 -070011523 sme_register_oem_data_rsp_callback(mac_handle,
11524 hdd_send_oem_data_rsp_msg);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011525
Jeff Johnson16528362018-06-14 12:34:16 -070011526 sme_register_mgmt_frame_ind_callback(mac_handle,
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053011527 hdd_indicate_mgmt_frame);
Jeff Johnson16528362018-06-14 12:34:16 -070011528 sme_set_tsfcb(mac_handle, hdd_get_tsf_cb, hdd_ctx);
11529 sme_nan_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011530 wlan_hdd_cfg80211_nan_callback);
Jeff Johnson16528362018-06-14 12:34:16 -070011531 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011532 wlan_hdd_cfg80211_stats_ext_callback);
11533
Jeff Johnson16528362018-06-14 12:34:16 -070011534 sme_ext_scan_register_callback(mac_handle,
11535 wlan_hdd_cfg80211_extscan_callback);
11536 sme_stats_ext2_register_callback(mac_handle,
lifeng66831662017-05-19 16:01:35 +080011537 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011538
Jeff Johnson16528362018-06-14 12:34:16 -070011539 sme_set_rssi_threshold_breached_cb(mac_handle,
11540 hdd_rssi_threshold_breached);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011541
Jeff Johnson16528362018-06-14 12:34:16 -070011542 sme_set_link_layer_stats_ind_cb(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011543 wlan_hdd_cfg80211_link_layer_stats_callback);
11544
Jeff Johnson16528362018-06-14 12:34:16 -070011545 sme_rso_cmd_status_cb(mac_handle, wlan_hdd_rso_cmd_status_cb);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053011546
Jeff Johnson16528362018-06-14 12:34:16 -070011547 sme_set_link_layer_ext_cb(mac_handle,
Zhang Qianca38fb12016-12-23 11:10:48 +080011548 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
11549
Jeff Johnson16528362018-06-14 12:34:16 -070011550 status = sme_set_lost_link_info_cb(mac_handle,
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053011551 hdd_lost_link_info_cb);
11552 /* print error and not block the startup process */
11553 if (!QDF_IS_STATUS_SUCCESS(status))
11554 hdd_err("set lost link info callback failed");
11555
Poddar, Siddarth34872782017-08-10 14:08:51 +053011556 ret = hdd_register_data_stall_detect_cb();
11557 if (ret) {
11558 hdd_err("Register data stall detect detect callback failed.");
11559 return ret;
11560 }
11561
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011562 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
11563
Jeff Johnson16528362018-06-14 12:34:16 -070011564 sme_register_set_connection_info_cb(mac_handle,
11565 hdd_set_connection_in_progress,
11566 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053011567
Jeff Johnson16528362018-06-14 12:34:16 -070011568 status = sme_congestion_register_callback(mac_handle,
11569 hdd_update_cca_info_cb);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053011570 if (!QDF_IS_STATUS_SUCCESS(status))
11571 hdd_err("set congestion callback failed");
11572
Jeff Johnson16528362018-06-14 12:34:16 -070011573 status = sme_set_bt_activity_info_cb(mac_handle,
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053011574 hdd_bt_activity_cb);
11575 if (!QDF_IS_STATUS_SUCCESS(status))
11576 hdd_err("set bt activity info callback failed");
11577
Jeff Johnson16528362018-06-14 12:34:16 -070011578 status = sme_register_tx_queue_cb(mac_handle,
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080011579 hdd_tx_queue_cb);
11580 if (!QDF_IS_STATUS_SUCCESS(status))
11581 hdd_err("Register tx queue callback failed");
11582
Dustin Browne74003f2018-03-14 12:51:58 -070011583 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011584
11585 return ret;
11586}
11587
11588/**
11589 * hdd_deregister_cb() - De-Register HDD callbacks.
11590 * @hdd_ctx: HDD context
11591 *
11592 * De-Register the HDD callbacks to CDS/SME.
11593 *
11594 * Return: void
11595 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011596void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011597{
11598 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053011599 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070011600 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011601
Dustin Brown491d54b2018-03-14 12:39:11 -070011602 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011603
Jeff Johnson16528362018-06-14 12:34:16 -070011604 mac_handle = hdd_ctx->mac_handle;
11605 sme_deregister_tx_queue_cb(mac_handle);
11606 status = sme_deregister_for_dcc_stats_event(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011607 if (!QDF_IS_STATUS_SUCCESS(status))
11608 hdd_err("De-register of dcc stats callback failed: %d",
11609 status);
11610
Jeff Johnson16528362018-06-14 12:34:16 -070011611 sme_reset_link_layer_stats_ind_cb(mac_handle);
11612 sme_reset_rssi_threshold_breached_cb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011613
Jeff Johnson16528362018-06-14 12:34:16 -070011614 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011615 wlan_hdd_cfg80211_stats_ext_callback);
11616
Jeff Johnson16528362018-06-14 12:34:16 -070011617 sme_nan_deregister_callback(mac_handle);
11618 status = sme_reset_tsfcb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011619 if (!QDF_IS_STATUS_SUCCESS(status))
11620 hdd_err("Failed to de-register tsfcb the callback:%d",
11621 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011622
Poddar, Siddarth34872782017-08-10 14:08:51 +053011623 ret = hdd_deregister_data_stall_detect_cb();
11624 if (ret)
11625 hdd_err("Failed to de-register data stall detect event callback");
11626
Jeff Johnson16528362018-06-14 12:34:16 -070011627 sme_deregister_oem_data_rsp_callback(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011628
Dustin Browne74003f2018-03-14 12:51:58 -070011629 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011630}
11631
11632/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011633 * hdd_softap_sta_deauth() - handle deauth req from HDD
11634 * @adapter: Pointer to the HDD
11635 * @enable: bool value
11636 *
11637 * This to take counter measure to handle deauth req from HDD
11638 *
11639 * Return: None
11640 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011641QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011642 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011643{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011644 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011645
Dustin Brown491d54b2018-03-14 12:39:11 -070011646 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011647
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011648 /* Ignore request to deauth bcmc station */
11649 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011650 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011651
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011652 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011653 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
11654 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011655
Dustin Browne74003f2018-03-14 12:51:58 -070011656 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011657 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011658}
11659
11660/**
11661 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
11662 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011663 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011664 *
11665 * This to take counter measure to handle deauth req from HDD
11666 *
11667 * Return: None
11668 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011669void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011670 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011671{
Dustin Brown491d54b2018-03-14 12:39:11 -070011672 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011673
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011674 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011675 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011676 return;
11677
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011678 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011679 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011680}
11681
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011682/**
11683 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
11684 * @hdd_ctx: HDD Context
11685 *
11686 * API to find if there is any STA or P2P-Client is connected
11687 *
11688 * Return: true if connected; false otherwise
11689 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011690QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011691{
Jeff Johnson16528362018-06-14 12:34:16 -070011692 return sme_is_sta_p2p_client_connected(hdd_ctx->mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011693}
11694
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011695void wlan_hdd_disable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011696{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011697 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
11698 struct hdd_adapter *adapter = NULL;
11699 struct csr_roam_profile *roam_profile;
11700 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011701
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011702 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->hdd_psoc)) {
11703 hdd_debug("No active sta session");
11704 return;
11705 }
11706
11707 hdd_for_each_adapter(hdd_ctx, adapter) {
11708 roam_profile = hdd_roam_profile(adapter);
11709 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11710
11711 if (cur_adapter->session_id != adapter->session_id &&
11712 adapter->device_mode == QDF_STA_MODE &&
11713 hdd_conn_is_connected(sta_ctx)) {
11714 hdd_debug("%d Disable roaming", adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -070011715 sme_stop_roaming(hdd_ctx->mac_handle,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011716 adapter->session_id,
11717 ecsr_driver_disabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011718 }
11719 }
11720}
11721
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011722void wlan_hdd_enable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011723{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011724 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
11725 struct hdd_adapter *adapter = NULL;
11726 struct csr_roam_profile *roam_profile;
11727 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011728
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011729 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->hdd_psoc)) {
11730 hdd_debug("No active sta session");
11731 return;
11732 }
11733
11734 hdd_for_each_adapter(hdd_ctx, adapter) {
11735 roam_profile = hdd_roam_profile(adapter);
11736 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11737
11738 if (cur_adapter->session_id != adapter->session_id &&
11739 adapter->device_mode == QDF_STA_MODE &&
11740 hdd_conn_is_connected(sta_ctx)) {
11741 hdd_debug("%d Enable roaming", adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -070011742 sme_start_roaming(hdd_ctx->mac_handle,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011743 adapter->session_id,
11744 REASON_DRIVER_ENABLED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011745 }
11746 }
11747}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011748
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011749/**
11750 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
11751 * @skb: sk buffer pointer
11752 *
11753 * Sends the bcast message to SVC multicast group with generic nl socket
11754 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
11755 *
11756 * Return: None
11757 */
11758static void nl_srv_bcast_svc(struct sk_buff *skb)
11759{
11760#ifdef CNSS_GENL
11761 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
11762#else
11763 nl_srv_bcast(skb);
11764#endif
11765}
11766
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011767void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011768{
11769 struct sk_buff *skb;
11770 struct nlmsghdr *nlh;
11771 tAniMsgHdr *ani_hdr;
11772 void *nl_data = NULL;
11773 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011774 struct radio_index_tlv *radio_info;
11775 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011776
11777 if (in_interrupt() || irqs_disabled() || in_atomic())
11778 flags = GFP_ATOMIC;
11779
11780 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
11781
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011782 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011783 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011784
11785 nlh = (struct nlmsghdr *)skb->data;
11786 nlh->nlmsg_pid = 0; /* from kernel */
11787 nlh->nlmsg_flags = 0;
11788 nlh->nlmsg_seq = 0;
11789 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
11790
11791 ani_hdr = NLMSG_DATA(nlh);
11792 ani_hdr->type = type;
11793
11794 switch (type) {
11795 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053011796 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011797 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011798 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011799 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011800 ani_hdr->length = 0;
11801 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011802 break;
11803 case WLAN_SVC_WLAN_STATUS_IND:
11804 case WLAN_SVC_WLAN_VERSION_IND:
11805 case WLAN_SVC_DFS_CAC_START_IND:
11806 case WLAN_SVC_DFS_CAC_END_IND:
11807 case WLAN_SVC_DFS_RADAR_DETECT_IND:
11808 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
11809 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080011810 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053011811 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080011812 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011813 ani_hdr->length = len;
11814 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
11815 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
11816 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011817 break;
11818
11819 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070011820 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011821 type);
11822 kfree_skb(skb);
11823 return;
11824 }
11825
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011826 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080011827 * Add radio index at the end of the svc event in TLV format
11828 * to maintain the backward compatibility with userspace
11829 * applications.
11830 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011831
11832 tlv_len = 0;
11833
11834 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
11835 < WLAN_NL_MAX_PAYLOAD) {
11836 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
11837 sizeof(*ani_hdr) + len);
11838 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
11839 radio_info->length = (unsigned short) sizeof(radio_info->radio);
11840 radio_info->radio = radio;
11841 tlv_len = sizeof(*radio_info);
Dustin Browna2868622018-03-20 11:38:14 -070011842 hdd_debug("Added radio index tlv - radio index %d",
11843 radio_info->radio);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011844 }
11845
11846 nlh->nlmsg_len += tlv_len;
11847 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
11848
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011849 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011850}
11851
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011852#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
11853void wlan_hdd_auto_shutdown_cb(void)
11854{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011855 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011856
11857 if (!hdd_ctx)
11858 return;
11859
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011860 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011861 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
11862 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011863}
11864
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011865void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011866{
Jeff Johnson9d295242017-08-29 14:39:48 -070011867 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011868 bool ap_connected = false, sta_connected = false;
Jeff Johnson16528362018-06-14 12:34:16 -070011869 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011870
Jeff Johnson16528362018-06-14 12:34:16 -070011871 mac_handle = hdd_ctx->mac_handle;
11872 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011873 return;
11874
11875 if (hdd_ctx->config->WlanAutoShutdown == 0)
11876 return;
11877
11878 if (enable == false) {
Jeff Johnson16528362018-06-14 12:34:16 -070011879 if (sme_set_auto_shutdown_timer(mac_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011880 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011881 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011882 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011883 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011884 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011885 return;
11886 }
11887
11888 /* To enable shutdown timer check conncurrency */
Dustin Brown920397d2017-12-13 16:27:50 -080011889 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->hdd_psoc)) {
11890 hdd_for_each_adapter(hdd_ctx, adapter) {
11891 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011892 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11893 conn_info.connState ==
11894 eConnectionState_Associated) {
11895 sta_connected = true;
11896 break;
11897 }
11898 }
Dustin Brown920397d2017-12-13 16:27:50 -080011899
11900 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011901 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070011902 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011903 ap_connected = true;
11904 break;
11905 }
11906 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011907 }
11908 }
11909
11910 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011911 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011912 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011913 }
Jeff Johnson68755312017-02-10 11:46:55 -080011914
Jeff Johnson16528362018-06-14 12:34:16 -070011915 if (sme_set_auto_shutdown_timer(mac_handle,
Jeff Johnson68755312017-02-10 11:46:55 -080011916 hdd_ctx->config->WlanAutoShutdown)
11917 != QDF_STATUS_SUCCESS)
11918 hdd_err("Failed to start wlan auto shutdown timer");
11919 else
Dustin Brown5e89ef82018-03-14 11:50:23 -070011920 hdd_info("Auto Shutdown timer for %d seconds enabled",
11921 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011922}
11923#endif
11924
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011925struct hdd_adapter *
11926hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
11927 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011928{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011929 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011930 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011931
11932 con_sap_adapter = NULL;
11933
Dustin Brown920397d2017-12-13 16:27:50 -080011934 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011935 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
11936 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011937 adapter != this_sap_adapter) {
11938 if (check_start_bss) {
11939 if (test_bit(SOFTAP_BSS_STARTED,
11940 &adapter->event_flags)) {
11941 con_sap_adapter = adapter;
11942 break;
11943 }
11944 } else {
11945 con_sap_adapter = adapter;
11946 break;
11947 }
11948 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011949 }
11950
11951 return con_sap_adapter;
11952}
11953
11954#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070011955static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011956{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011957 return adapter->device_mode == QDF_STA_MODE ||
11958 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011959}
11960
Jeff Johnson9d295242017-08-29 14:39:48 -070011961static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011962{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011963 return adapter->device_mode == QDF_SAP_MODE ||
11964 adapter->device_mode == QDF_P2P_GO_MODE;
11965}
11966
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011967static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011968{
Dustin Brown920397d2017-12-13 16:27:50 -080011969 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070011970
Dustin Brown920397d2017-12-13 16:27:50 -080011971 hdd_for_each_adapter(hdd_ctx, adapter) {
11972 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070011973 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11974 conn_info.connState == eConnectionState_Associated) {
11975 return true;
11976 }
11977
Dustin Brown920397d2017-12-13 16:27:50 -080011978 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070011979 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070011980 return true;
11981 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011982 }
11983
11984 return false;
11985}
11986
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011987static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011988{
11989 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011990
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011991 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011992 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011993 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011994
Dustin Brown5ec6b552017-03-31 12:11:40 -070011995 return is_running;
11996}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011997
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011998static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011999{
12000 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
12001 hdd_ctx->bus_bw_timer_running = true;
12002 qdf_timer_start(&hdd_ctx->bus_bw_timer,
12003 hdd_ctx->config->busBandwidthComputeInterval);
12004 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
12005}
12006
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012007void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012008{
Dustin Brown491d54b2018-03-14 12:39:11 -070012009 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012010
12011 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12012 hdd_debug("Bandwidth compute timer already started");
12013 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012014 }
12015
Dustin Brown5ec6b552017-03-31 12:11:40 -070012016 __hdd_bus_bw_compute_timer_start(hdd_ctx);
12017
Dustin Browne74003f2018-03-14 12:51:58 -070012018 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012019}
12020
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012021void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012022{
Dustin Brown491d54b2018-03-14 12:39:11 -070012023 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012024
12025 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12026 hdd_debug("Bandwidth compute timer already started");
12027 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070012028 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070012029
12030 if (hdd_any_adapter_is_assoc(hdd_ctx))
12031 __hdd_bus_bw_compute_timer_start(hdd_ctx);
12032
Dustin Browne74003f2018-03-14 12:51:58 -070012033 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012034}
12035
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012036static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012037{
Sravan Kumar Kairam9e99e9a2018-03-12 19:09:45 +053012038 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, 0, 0);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012039
12040 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012041 hdd_ctx->bus_bw_timer_running = false;
Dustin Brown35008ba2018-08-23 14:34:21 -070012042 qdf_timer_sync_cancel(&hdd_ctx->bus_bw_timer);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012043 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
12044
Dustin Brown35008ba2018-08-23 14:34:21 -070012045 /* work callback is long running; flush outside of lock */
12046 cancel_work_sync(&hdd_ctx->bus_bw_work);
Dustin Brown5ec6b552017-03-31 12:11:40 -070012047 hdd_reset_tcp_delack(hdd_ctx);
12048}
12049
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012050void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012051{
Dustin Brown491d54b2018-03-14 12:39:11 -070012052 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012053
12054 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12055 hdd_debug("Bandwidth compute timer already stopped");
12056 return;
12057 }
12058
12059 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
12060
Dustin Browne74003f2018-03-14 12:51:58 -070012061 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012062}
12063
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012064void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070012065{
Dustin Brown491d54b2018-03-14 12:39:11 -070012066 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070012067
12068 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
12069 hdd_debug("Bandwidth compute timer already stopped");
12070 return;
12071 }
12072
12073 if (!hdd_any_adapter_is_assoc(hdd_ctx))
12074 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
12075
Dustin Browne74003f2018-03-14 12:51:58 -070012076 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012077}
12078#endif
12079
12080/**
12081 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
12082 * and sta's operating channel.
12083 * @sta_adapter: Describe the first argument to foobar.
12084 * @ap_adapter: Describe the second argument to foobar.
12085 * @roam_profile: Roam profile of AP to which STA wants to connect.
12086 * @concurrent_chnl_same: If both SAP and STA channels are same then
12087 * set this flag to true else false.
12088 *
12089 * This function checks the sap's operating channel and sta's operating channel.
12090 * if both are same then it will return false else it will restart the sap in
12091 * sta's channel and return true.
12092 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012093 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012094 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070012095QDF_STATUS
12096wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
12097 struct hdd_adapter *ap_adapter,
Jeff Johnson61b5e982018-03-15 11:33:31 -070012098 struct csr_roam_profile *roam_profile,
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070012099 tScanResultHandle *scan_cache,
12100 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012101{
Jeff Johnson87251032017-08-29 13:31:11 -070012102 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012103 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012104 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012105 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012106 *concurrent_chnl_same = true;
12107
12108 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12109 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070012110 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012111 scan_cache,
12112 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012113 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012114 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012115 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070012116 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012117 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012118 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012119 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012120 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012121 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070012122 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012123 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012124 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012125 }
12126 }
12127 } else {
12128 /*
12129 * Lets handle worst case scenario here, Scan cache lookup is
12130 * failed so we have to stop the SAP to avoid any channel
12131 * discrepancy between SAP's channel and STA's channel.
12132 * Return the status as failure so caller function could know
12133 * that scan look up is failed.
12134 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070012135 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012136 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012137 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012138 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012139}
12140
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012141/**
12142 * wlan_hdd_stop_sap() - This function stops bss of SAP.
12143 * @ap_adapter: SAP adapter
12144 *
12145 * This function will process the stopping of sap adapter.
12146 *
12147 * Return: None
12148 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012149void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012150{
Jeff Johnson87251032017-08-29 13:31:11 -070012151 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012152 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053012153 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012154 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012155
12156 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012157 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012158 return;
12159 }
12160
12161 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12162 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012163 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012164 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012165
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012166 mutex_lock(&hdd_ctx->sap_lock);
12167 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080012168 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012169 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012170 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053012171 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012172 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012173 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053012174 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080012175 qdf_stop_bss_event,
12176 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053012177 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012178 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070012179 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012180 return;
12181 }
12182 }
12183 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012184 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
12185 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012186 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012187 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012188 false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012189 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012190 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012191 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012192 }
12193 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012194}
12195
12196/**
12197 * wlan_hdd_start_sap() - this function starts bss of SAP.
12198 * @ap_adapter: SAP adapter
12199 *
12200 * This function will process the starting of sap adapter.
12201 *
12202 * Return: None
12203 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012204void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012205{
Jeff Johnson87251032017-08-29 13:31:11 -070012206 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012207 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053012208 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012209 struct hdd_context *hdd_ctx;
Jeff Johnsone4c11db2018-05-05 23:22:32 -070012210 tsap_config_t *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012211
12212 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012213 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012214 return;
12215 }
12216
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012217 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070012218 hdd_err("SoftAp role has not been enabled");
12219 return;
12220 }
12221
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012222 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
12223 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12224 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070012225 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012226
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012227 mutex_lock(&hdd_ctx->sap_lock);
12228 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
12229 goto end;
12230
12231 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012232 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012233 goto end;
12234 }
Abhinav Kumar6f694482018-09-04 16:07:39 +053012235 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
12236 hdd_ap_ctx->sap_config.channel, 0,
12237 &hdd_ap_ctx->sap_config.ch_params);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012238
Wei Song2f76f642016-11-18 16:32:53 +080012239 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012240 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070012241 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012242 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012243 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012244 goto end;
12245
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012246 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053012247 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080012248 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053012249 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012250 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012251 goto end;
12252 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070012253 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012254 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012255 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012256 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012257 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12258 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012259 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012260 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012261 true);
12262 }
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053012263 mutex_unlock(&hdd_ctx->sap_lock);
12264
12265 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012266end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012267 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012268 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070012269 /* SAP context and beacon cleanup will happen during driver unload
12270 * in hdd_stop_adapter
12271 */
12272 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
12273
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012274}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012275
12276/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012277 * hdd_get_fw_version() - Get FW version
12278 * @hdd_ctx: pointer to HDD context.
12279 * @major_spid: FW version - major spid.
12280 * @minor_spid: FW version - minor spid
12281 * @ssid: FW version - ssid
12282 * @crmid: FW version - crmid
12283 *
12284 * This function is called to get the firmware build version stored
12285 * as part of the HDD context
12286 *
12287 * Return: None
12288 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012289void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012290 uint32_t *major_spid, uint32_t *minor_spid,
12291 uint32_t *siid, uint32_t *crmid)
12292{
12293 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
12294 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
12295 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
12296 *crmid = hdd_ctx->target_fw_version & 0x7fff;
12297}
12298
12299#ifdef QCA_CONFIG_SMP
12300/**
12301 * wlan_hdd_get_cpu() - get cpu_index
12302 *
12303 * Return: cpu_index
12304 */
12305int wlan_hdd_get_cpu(void)
12306{
12307 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012308
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012309 put_cpu();
12310 return cpu_index;
12311}
12312#endif
12313
12314/**
12315 * hdd_get_fwpath() - get framework path
12316 *
12317 * This function is used to get the string written by
12318 * userspace to start the wlan driver
12319 *
12320 * Return: string
12321 */
12322const char *hdd_get_fwpath(void)
12323{
12324 return fwpath.string;
12325}
12326
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070012327static int hdd_qdf_print_init(void)
12328{
12329 int qdf_print_idx;
12330 QDF_STATUS status;
12331
12332 status = qdf_print_setup();
12333 if (status != QDF_STATUS_SUCCESS) {
12334 pr_err("qdf_print_setup failed\n");
12335 return -EINVAL;
12336 }
12337
12338 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
12339
12340 if (qdf_print_idx < 0) {
12341 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
12342 qdf_print_idx);
12343 return -EINVAL;
12344 }
12345
12346 qdf_set_pidx(qdf_print_idx);
12347
12348 return 0;
12349}
12350
12351static void hdd_qdf_print_deinit(void)
12352{
12353 int qdf_print_idx;
12354
12355 qdf_print_idx = qdf_get_pidx();
12356 qdf_print_ctrl_cleanup(qdf_print_idx);
12357}
12358
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012359/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012360 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012361 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012362 * This function initilizes CDS global context with the help of cds_init. This
12363 * has to be the first function called after probe to get a valid global
12364 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012365 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012366 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012367 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012368int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012369{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012370 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012371 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012372
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012373 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080012374 if (QDF_IS_STATUS_ERROR(status)) {
12375 hdd_err("Failed to allocate CDS context");
12376 ret = -ENOMEM;
12377 goto err_out;
12378 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053012379
12380 wlan_init_bug_report_lock();
12381
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012382#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12383 wlan_logging_sock_init_svc();
12384#endif
12385
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012386 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
12387 (void *)hdd_drv_ops_inactivity_handler, NULL,
12388 QDF_TIMER_TYPE_SW);
12389
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012390 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070012391 hdd_qdf_print_init();
12392
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053012393 hdd_register_debug_callback();
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012394 wlan_roam_debug_init();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012395
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012396err_out:
12397 return ret;
12398}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012399
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012400/**
12401 * hdd_deinit() - Deinitialize Driver
12402 *
12403 * This function frees CDS global context with the help of cds_deinit. This
12404 * has to be the last function call in remove callback to free the global
12405 * context.
12406 */
12407void hdd_deinit(void)
12408{
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012409 wlan_roam_debug_deinit();
12410 hdd_qdf_print_deinit();
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012411 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012412
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012413#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12414 wlan_logging_sock_deinit_svc();
12415#endif
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012416
12417 wlan_destroy_bug_report_lock();
12418 cds_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012419}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012420
Yue Ma6e7b1a02017-04-03 14:17:46 -070012421#ifdef QCA_WIFI_NAPIER_EMULATION
12422#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
12423#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012424#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070012425#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012426
Sachin Ahujadddd2632017-03-07 19:07:24 +053012427static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
12428 struct file *file)
12429{
12430 return 0;
12431}
12432
12433static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
12434 const char __user *user_buf,
12435 size_t count,
12436 loff_t *f_pos)
12437{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012438 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053012439 static const char wlan_off_str[] = "OFF";
12440 static const char wlan_on_str[] = "ON";
12441 int ret;
12442 unsigned long rc;
12443
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012444 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012445 pr_err("Failed to read buffer\n");
12446 return -EINVAL;
12447 }
12448
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012449 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012450 pr_debug("Wifi turning off from UI\n");
12451 goto exit;
12452 }
12453
Sachin Ahuja16904db2017-12-13 19:56:57 +053012454 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) == 0) {
12455 pr_info("Wifi Turning On from UI\n");
12456 }
12457
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012458 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012459 pr_err("Invalid value received from framework");
12460 goto exit;
12461 }
12462
12463 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053012464 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053012465 rc = wait_for_completion_timeout(&wlan_start_comp,
12466 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
12467 if (!rc) {
12468 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
12469 ret = -EINVAL;
Sachin Ahujadddd2632017-03-07 19:07:24 +053012470 return ret;
12471 }
12472
12473 hdd_start_complete(0);
12474 }
12475
12476exit:
12477 return count;
12478}
12479
12480
12481const struct file_operations wlan_hdd_state_fops = {
12482 .owner = THIS_MODULE,
12483 .open = wlan_hdd_state_ctrl_param_open,
12484 .write = wlan_hdd_state_ctrl_param_write,
12485};
12486
12487static int wlan_hdd_state_ctrl_param_create(void)
12488{
12489 unsigned int wlan_hdd_state_major = 0;
12490 int ret;
12491 struct device *dev;
12492
12493 device = MKDEV(wlan_hdd_state_major, 0);
12494
12495 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
12496 if (ret) {
12497 pr_err("Failed to register qcwlanstate");
12498 goto dev_alloc_err;
12499 }
12500 wlan_hdd_state_major = MAJOR(device);
12501
12502 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
12503 if (IS_ERR(class)) {
12504 pr_err("wlan_hdd_state class_create error");
12505 goto class_err;
12506 }
12507
12508 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
12509 if (IS_ERR(dev)) {
12510 pr_err("wlan_hdd_statedevice_create error");
12511 goto err_class_destroy;
12512 }
12513
12514 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
12515 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
12516 if (ret) {
12517 pr_err("Failed to add cdev error");
12518 goto cdev_add_err;
12519 }
12520
12521 pr_info("wlan_hdd_state %s major(%d) initialized",
12522 WLAN_MODULE_NAME, wlan_hdd_state_major);
12523
12524 return 0;
12525
12526cdev_add_err:
12527 device_destroy(class, device);
12528err_class_destroy:
12529 class_destroy(class);
12530class_err:
12531 unregister_chrdev_region(device, dev_num);
12532dev_alloc_err:
12533 return -ENODEV;
12534}
12535
12536static void wlan_hdd_state_ctrl_param_destroy(void)
12537{
12538 cdev_del(&wlan_hdd_state_cdev);
12539 device_destroy(class, device);
12540 class_destroy(class);
12541 unregister_chrdev_region(device, dev_num);
12542
12543 pr_info("Device node unregistered");
12544}
12545
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012546/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053012547 * component_init - API to init cld component's
12548 *
12549 * Return: None
12550 */
12551static void component_init(void)
12552{
Vignesh Viswanathana0921c42018-09-04 19:03:35 +053012553 ucfg_mlme_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053012554 pmo_init();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012555 disa_init();
Zhang Qian47e22ce2018-01-04 15:38:38 +080012556 ucfg_ocb_init();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053012557 ipa_init();
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053012558 ucfg_action_oui_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053012559}
12560
12561/**
12562 * component_deinit - API to deinit cld component's
12563 *
12564 * Return: None
12565 */
12566static void component_deinit(void)
12567{
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053012568 ucfg_action_oui_deinit();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053012569 ipa_deinit();
Zhang Qian47e22ce2018-01-04 15:38:38 +080012570 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053012571 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012572 disa_deinit();
Vignesh Viswanathana0921c42018-09-04 19:03:35 +053012573 ucfg_mlme_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012574}
12575
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053012576QDF_STATUS hdd_component_psoc_open(struct wlan_objmgr_psoc *psoc)
12577{
Vignesh Viswanathana0921c42018-09-04 19:03:35 +053012578 return ucfg_mlme_psoc_open(psoc);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053012579}
12580
12581void hdd_component_psoc_close(struct wlan_objmgr_psoc *psoc)
12582{
Vignesh Viswanathana0921c42018-09-04 19:03:35 +053012583 ucfg_mlme_psoc_close(psoc);
Vignesh Viswanathan21c58cb2018-05-24 15:53:58 +053012584}
12585
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012586void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
12587{
Zhang Qian47e22ce2018-01-04 15:38:38 +080012588 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012589 disa_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012590}
12591
12592void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
12593{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012594 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080012595 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053012596}
12597
12598/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012599 * __hdd_module_init - Module init helper
12600 *
12601 * Module init helper function used by both module and static driver.
12602 *
12603 * Return: 0 for success, errno on failure
12604 */
12605static int __hdd_module_init(void)
12606{
12607 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012608
Dustin Brown96cd9632017-11-13 12:45:04 -080012609 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070012610 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080012611 g_wlan_driver_version,
Dustin Brownc1034df2018-02-07 14:51:32 -080012612 TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012613
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012614 pld_init();
12615
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012616 ret = hdd_init();
12617 if (ret) {
12618 pr_err("hdd_init failed %x\n", ret);
12619 goto err_hdd_init;
12620 }
12621
Rajeev Kumar97767a02016-11-30 11:20:40 -080012622 dispatcher_init();
12623
Mukul Sharmad75a6672017-06-22 15:40:53 +053012624 /* Ensure to call post objmgr init */
12625 component_init();
12626
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012627 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012628
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012629 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012630
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012631 ret = wlan_hdd_register_driver();
12632 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070012633 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
12634 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012635 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012636 }
12637
Sachin Ahuja16904db2017-12-13 19:56:57 +053012638 ret = wlan_hdd_state_ctrl_param_create();
12639 if (ret) {
12640 pr_err("wlan_hdd_state_create:%x\n", ret);
12641 goto out;
12642 }
12643
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053012644 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012645
12646 return 0;
12647out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012648 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080012649 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080012650 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012651 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080012652
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012653err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012654 pld_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012655 return ret;
12656}
12657
12658/**
12659 * __hdd_module_exit - Module exit helper
12660 *
12661 * Module exit helper function used by both module and static driver.
12662 */
12663static void __hdd_module_exit(void)
12664{
Will Huang36049722018-04-13 11:48:51 +080012665 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053012666
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012667 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
12668 QWLAN_VERSIONSTR);
12669
Arunk Khandavalli830c9692018-03-22 12:17:40 +053012670 if (!hdd_wait_for_recovery_completion())
12671 return;
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053012672
Will Huangba035ec2018-07-05 11:13:30 +080012673 cds_set_driver_loaded(false);
12674 cds_set_unload_in_progress(true);
12675
12676 if (!cds_wait_for_external_threads_completion(__func__))
12677 hdd_warn("External threads are still active attempting "
12678 "driver unload anyway");
12679
Rajeev Kumar3505ae52018-05-10 18:44:45 -070012680 if (hdd_ctx)
12681 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Will Huang36049722018-04-13 11:48:51 +080012682
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012683 wlan_hdd_unregister_driver();
12684
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012685 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012686
Mukul Sharmad75a6672017-06-22 15:40:53 +053012687 /* Ensure to call prior to objmgr deinit */
12688 component_deinit();
12689
Rajeev Kumar97767a02016-11-30 11:20:40 -080012690 dispatcher_deinit();
Amar Singhal0928b192017-12-01 10:50:54 -080012691
12692 hdd_sysfs_destroy_version_interface();
12693
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012694 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012695 pld_deinit();
12696
Sachin Ahujadddd2632017-03-07 19:07:24 +053012697 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012698}
12699
Arun Khandavallifae92942016-08-01 13:31:08 +053012700#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012701/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012702 * wlan_boot_cb() - Wlan boot callback
12703 * @kobj: object whose directory we're creating the link in.
12704 * @attr: attribute the user is interacting with
12705 * @buff: the buffer containing the user data
12706 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012707 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012708 * This callback is invoked when the fs is ready to start the
12709 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012710 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012711 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012712 */
Arun Khandavallifae92942016-08-01 13:31:08 +053012713static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012714 struct kobj_attribute *attr,
12715 const char *buf,
12716 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012717{
Arun Khandavallifae92942016-08-01 13:31:08 +053012718
Arun Khandavallifae92942016-08-01 13:31:08 +053012719 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012720 pr_err("%s: wlan driver already initialized\n", __func__);
12721 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053012722 }
12723
Arun Khandavallifae92942016-08-01 13:31:08 +053012724 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012725 pr_err("%s: wlan driver initialization failed\n", __func__);
12726 return -EIO;
12727 }
12728
12729 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053012730
12731 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012732}
Arun Khandavallifae92942016-08-01 13:31:08 +053012733
12734/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012735 * hdd_sysfs_cleanup() - cleanup sysfs
12736 *
12737 * Return: None
12738 *
12739 */
12740static void hdd_sysfs_cleanup(void)
12741{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012742 /* remove from group */
12743 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
12744 sysfs_remove_group(wlan_loader->boot_wlan_obj,
12745 wlan_loader->attr_group);
12746
12747 /* unlink the object from parent */
12748 kobject_del(wlan_loader->boot_wlan_obj);
12749
12750 /* free the object */
12751 kobject_put(wlan_loader->boot_wlan_obj);
12752
12753 kfree(wlan_loader->attr_group);
12754 kfree(wlan_loader);
12755
12756 wlan_loader = NULL;
12757}
12758
12759/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012760 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
12761 * ready
12762 *
12763 * This is creates the syfs entry boot_wlan. Which shall be invoked
12764 * when the filesystem is ready.
12765 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012766 * QDF API cannot be used here since this function is called even before
12767 * initializing WLAN driver.
12768 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012769 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053012770 */
12771static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012772{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012773 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012774
12775 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012776 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012777 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012778
12779 wlan_loader->boot_wlan_obj = NULL;
12780 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
12781 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012782 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053012783 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053012784
12785 wlan_loader->loaded_state = 0;
12786 wlan_loader->attr_group->attrs = attrs;
12787
12788 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
12789 kernel_kobj);
12790 if (!wlan_loader->boot_wlan_obj) {
12791 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053012792 goto error_return;
12793 }
12794
12795 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
12796 wlan_loader->attr_group);
12797 if (ret) {
12798 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
12799 goto error_return;
12800 }
12801
12802 return 0;
12803
12804error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012805 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053012806
12807 return ret;
12808}
12809
12810/**
12811 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
12812 *
12813 * Return: 0 on success or errno on failure
12814 */
12815static int wlan_deinit_sysfs(void)
12816{
Arun Khandavallifae92942016-08-01 13:31:08 +053012817 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012818 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053012819 return -EINVAL;
12820 }
12821
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012822 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012823 return 0;
12824}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012825
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012826#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053012827
12828#ifdef MODULE
12829/**
12830 * __hdd_module_init - Module init helper
12831 *
12832 * Module init helper function used by both module and static driver.
12833 *
12834 * Return: 0 for success, errno on failure
12835 */
12836static int hdd_module_init(void)
12837{
Arun Khandavallifae92942016-08-01 13:31:08 +053012838 if (__hdd_module_init()) {
12839 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070012840 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053012841 }
12842
Dustin Brownab482ac2017-06-09 17:00:44 -070012843 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053012844}
12845#else
12846static int __init hdd_module_init(void)
12847{
12848 int ret = -EINVAL;
12849
12850 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012851 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053012852 pr_err("Failed to create sysfs entry for loading wlan");
12853
12854 return ret;
12855}
12856#endif
12857
12858
12859#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012860/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012861 * hdd_module_exit() - Exit function
12862 *
12863 * This is the driver exit point (invoked when module is unloaded using rmmod)
12864 *
12865 * Return: None
12866 */
12867static void __exit hdd_module_exit(void)
12868{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012869 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012870}
Arun Khandavallifae92942016-08-01 13:31:08 +053012871#else
12872static void __exit hdd_module_exit(void)
12873{
12874 __hdd_module_exit();
12875 wlan_deinit_sysfs();
12876}
12877#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012878
Srinivas Girigowda841da292018-02-21 16:33:00 -080012879static int fwpath_changed_handler(const char *kmessage,
12880 const struct kernel_param *kp)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012881{
12882 return param_set_copystring(kmessage, kp);
12883}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012884
Nirav Shah73713f72018-05-17 14:50:41 +053012885#ifdef FEATURE_MONITOR_MODE_SUPPORT
12886static bool is_monitor_mode_supported(void)
12887{
12888 return true;
12889}
12890#else
12891static bool is_monitor_mode_supported(void)
12892{
12893 pr_err("Monitor mode not supported!");
12894 return false;
12895}
12896#endif
12897
12898#ifdef WLAN_FEATURE_EPPING
12899static bool is_epping_mode_supported(void)
12900{
12901 return true;
12902}
12903#else
12904static bool is_epping_mode_supported(void)
12905{
12906 pr_err("Epping mode not supported!");
12907 return false;
12908}
12909#endif
12910
Ryan Hsu6e9db0b2018-06-01 10:45:51 -070012911#ifdef QCA_WIFI_FTM
12912static bool is_ftm_mode_supported(void)
12913{
12914 return true;
12915}
12916#else
12917static bool is_ftm_mode_supported(void)
12918{
12919 pr_err("FTM mode not supported!");
12920 return false;
12921}
12922#endif
12923
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012924/**
12925 * is_con_mode_valid() check con mode is valid or not
12926 * @mode: global con mode
12927 *
12928 * Return: TRUE on success FALSE on failure
12929 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012930static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012931{
12932 switch (mode) {
12933 case QDF_GLOBAL_MONITOR_MODE:
Nirav Shah73713f72018-05-17 14:50:41 +053012934 return is_monitor_mode_supported();
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012935 case QDF_GLOBAL_EPPING_MODE:
Nirav Shah73713f72018-05-17 14:50:41 +053012936 return is_epping_mode_supported();
12937 case QDF_GLOBAL_FTM_MODE:
Ryan Hsu6e9db0b2018-06-01 10:45:51 -070012938 return is_ftm_mode_supported();
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012939 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012940 return true;
12941 default:
12942 return false;
12943 }
12944}
12945
12946/**
12947 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
12948 * @mode: global con mode
12949 *
12950 * Return: adapter mode
12951 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012952static enum QDF_OPMODE hdd_get_adpter_mode(
Jeff Johnson876c1a62017-12-12 10:43:07 -080012953 enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012954{
12955
12956 switch (mode) {
12957 case QDF_GLOBAL_MISSION_MODE:
12958 return QDF_STA_MODE;
12959 case QDF_GLOBAL_MONITOR_MODE:
12960 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012961 case QDF_GLOBAL_EPPING_MODE:
12962 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012963 case QDF_GLOBAL_FTM_MODE:
12964 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012965 case QDF_GLOBAL_QVIT_MODE:
12966 return QDF_QVIT_MODE;
12967 default:
12968 return QDF_MAX_NO_OF_MODE;
12969 }
12970}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012971
Dustin Brown27cd9942017-09-27 16:11:44 -070012972static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012973 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070012974{
12975 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
12976 return;
12977
12978 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070012979 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012980 hdd_info("Release wakelock for monitor mode!");
12981 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
12982 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
Dundi Raviteja0a2a65b2018-04-30 12:34:11 +053012983 /* fallthrough */
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012984 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070012985 case QDF_GLOBAL_FTM_MODE:
12986 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +053012987 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Dustin Browndb2a8be2017-12-20 11:49:56 -080012988 hdd_stop_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -070012989
Dustin Brown27cd9942017-09-27 16:11:44 -070012990 break;
12991 default:
12992 break;
12993 }
12994}
12995
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012996static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012997 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012998{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053012999 int driver_status;
13000
13001 driver_status = hdd_ctx->driver_status;
13002
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013003 switch (curr_mode) {
13004 case QDF_GLOBAL_MISSION_MODE:
13005 case QDF_GLOBAL_MONITOR_MODE:
13006 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013007 hdd_deinit_all_adapters(hdd_ctx, false);
13008 hdd_close_all_adapters(hdd_ctx, false);
13009 break;
13010 case QDF_GLOBAL_EPPING_MODE:
13011 epping_disable();
13012 epping_close();
13013 break;
13014 default:
13015 return;
13016 }
13017}
13018
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013019static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080013020 enum QDF_GLOBAL_MODE mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013021{
Jeff Johnson9d295242017-08-29 14:39:48 -070013022 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013023 int ret = 0;
13024 bool rtnl_held;
13025 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
13026 QDF_STATUS status;
13027
13028 if (!qdf_dev) {
13029 hdd_err("qdf device context is Null return!");
13030 return -EINVAL;
13031 }
13032
13033 rtnl_held = hdd_hold_rtnl_lock();
13034 switch (mode) {
13035 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080013036 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
13037 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013038 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013039 break;
13040 case QDF_GLOBAL_FTM_MODE:
13041 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
13042 wlan_hdd_get_intf_addr(hdd_ctx),
13043 NET_NAME_UNKNOWN, rtnl_held);
13044 if (adapter == NULL)
13045 ret = -EINVAL;
13046 break;
13047 case QDF_GLOBAL_MONITOR_MODE:
13048 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
13049 wlan_hdd_get_intf_addr(hdd_ctx),
13050 NET_NAME_UNKNOWN, rtnl_held);
13051 if (adapter == NULL)
13052 ret = -EINVAL;
13053 break;
13054 case QDF_GLOBAL_EPPING_MODE:
13055 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013056 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013057 hdd_err("Failed to open in eeping mode: %d", status);
13058 ret = -EINVAL;
13059 break;
13060 }
13061 ret = epping_enable(qdf_dev->dev);
13062 if (ret) {
13063 hdd_err("Failed to enable in epping mode : %d", ret);
13064 epping_close();
13065 }
13066 break;
13067 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013068 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013069 ret = -ENOTSUPP;
13070 break;
13071 }
13072 hdd_release_rtnl_lock();
13073 rtnl_held = false;
13074 return ret;
13075}
13076
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013077/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013078 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013079 * @kmessage: con mode name on which driver to be bring up
13080 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013081 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013082 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013083 * This function is invoked when user updates con mode using sys entry,
13084 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013085 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013086 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013087 */
Srinivas Girigowda841da292018-02-21 16:33:00 -080013088static int __con_mode_handler(const char *kmessage,
13089 const struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013090 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013091{
13092 int ret;
Jeff Johnson876c1a62017-12-12 10:43:07 -080013093 enum QDF_GLOBAL_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080013094 enum QDF_OPMODE adapter_mode;
Dustin Brown20024e32018-01-03 12:34:58 -080013095 int new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013096
Dustin Brownab6029b2017-05-24 13:04:19 -070013097 hdd_info("con_mode handler: %s", kmessage);
13098
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053013099 ret = wlan_hdd_validate_context(hdd_ctx);
13100 if (ret)
13101 return ret;
13102
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013103 qdf_atomic_set(&hdd_ctx->con_mode_flag, 1);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013104
Dustin Brown20024e32018-01-03 12:34:58 -080013105 ret = kstrtoint(kmessage, 0, &new_con_mode);
13106 if (ret) {
13107 hdd_err("Failed to parse con_mode '%s'", kmessage);
13108 goto reset_flags;
13109 }
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013110 mutex_lock(&hdd_init_deinit_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +053013111
Dustin Brown20024e32018-01-03 12:34:58 -080013112 if (!is_con_mode_valid(new_con_mode)) {
13113 hdd_err("invalid con_mode %d", new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013114 ret = -EINVAL;
13115 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013116 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013117
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013118 curr_mode = hdd_get_conparam();
Dustin Brown20024e32018-01-03 12:34:58 -080013119 if (curr_mode == new_con_mode) {
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013120 hdd_err("curr mode: %d is same as user triggered mode %d",
Dustin Brown20024e32018-01-03 12:34:58 -080013121 curr_mode, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013122 ret = 0;
13123 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053013124 }
13125
Dustin Brown27cd9942017-09-27 16:11:44 -070013126 /* ensure adapters are stopped */
13127 hdd_stop_present_mode(hdd_ctx, curr_mode);
13128
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070013129 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053013130 if (ret) {
13131 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013132 goto reset_flags;
13133 }
13134
Dustin Browndd4e50f2018-05-24 15:43:42 -070013135 /* Cleanup present mode before switching to new mode */
13136 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053013137
Dustin Brown20024e32018-01-03 12:34:58 -080013138 hdd_set_conparam(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013139
13140 /* Register for new con_mode & then kick_start modules again */
Dustin Brown20024e32018-01-03 12:34:58 -080013141 ret = hdd_register_req_mode(hdd_ctx, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013142 if (ret) {
13143 hdd_err("Failed to register for new mode");
13144 goto reset_flags;
13145 }
13146
Dustin Brown20024e32018-01-03 12:34:58 -080013147 adapter_mode = hdd_get_adpter_mode(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013148 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
13149 hdd_err("invalid adapter");
13150 ret = -EINVAL;
13151 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053013152 }
13153
Dustin Browne7e71d32018-05-11 16:00:08 -070013154 ret = hdd_wlan_start_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053013155 if (ret) {
13156 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013157 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053013158 }
13159
Dustin Brown20024e32018-01-03 12:34:58 -080013160 if (new_con_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Browne7e71d32018-05-11 16:00:08 -070013161 struct hdd_adapter *adapter =
13162 hdd_get_adapter(hdd_ctx, adapter_mode);
13163
13164 if (!adapter) {
13165 hdd_err("Failed to get adapter:%d", adapter_mode);
13166 goto reset_flags;
13167 }
13168
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013169 if (hdd_start_adapter(adapter)) {
13170 hdd_err("Failed to start %s adapter", kmessage);
13171 ret = -EINVAL;
13172 goto reset_flags;
13173 }
Arun Khandavallifae92942016-08-01 13:31:08 +053013174
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053013175 hdd_info("Acquire wakelock for monitor mode!");
13176 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
13177 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
13178 }
13179
Dustin Brown20024e32018-01-03 12:34:58 -080013180 /* con_mode is a global module parameter */
13181 con_mode = new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013182 hdd_info("Mode successfully changed to %s", kmessage);
13183 ret = 0;
13184
13185reset_flags:
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013186 mutex_unlock(&hdd_init_deinit_lock);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013187 qdf_atomic_set(&hdd_ctx->con_mode_flag, 0);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013188 return ret;
13189}
13190
13191
Srinivas Girigowda841da292018-02-21 16:33:00 -080013192static int con_mode_handler(const char *kmessage, const struct kernel_param *kp)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013193{
13194 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013195 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013196
13197 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13198 ret = wlan_hdd_validate_context(hdd_ctx);
13199 if (ret)
13200 return ret;
13201
Ashish Kumar Dhanotiya759b3272018-05-18 17:49:46 +053013202 if (!cds_wait_for_external_threads_completion(__func__)) {
13203 hdd_warn("External threads are still active, can not change mode");
13204 return -EAGAIN;
13205 }
13206
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013207 cds_ssr_protect(__func__);
13208 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
13209 cds_ssr_unprotect(__func__);
13210
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013211 return ret;
13212}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013213
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013214static int con_mode_handler_ftm(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080013215 const struct kernel_param *kp)
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013216{
13217 int ret;
13218
13219 ret = param_set_int(kmessage, kp);
13220
13221 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
13222 pr_err("Only FTM mode supported!");
13223 return -ENOTSUPP;
13224 }
13225
13226 hdd_set_conparam(con_mode_ftm);
13227 con_mode = con_mode_ftm;
13228
13229 return ret;
13230}
13231
Nirav Shah73713f72018-05-17 14:50:41 +053013232#ifdef FEATURE_MONITOR_MODE_SUPPORT
Ravi Joshia307f632017-07-17 23:41:41 -070013233static int con_mode_handler_monitor(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080013234 const struct kernel_param *kp)
Ravi Joshia307f632017-07-17 23:41:41 -070013235{
13236 int ret;
13237
13238 ret = param_set_int(kmessage, kp);
13239
13240 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
13241 pr_err("Only Monitor mode supported!");
13242 return -ENOTSUPP;
13243 }
13244
13245 hdd_set_conparam(con_mode_monitor);
13246 con_mode = con_mode_monitor;
13247
13248 return ret;
13249}
Nirav Shah73713f72018-05-17 14:50:41 +053013250#endif
Ravi Joshia307f632017-07-17 23:41:41 -070013251
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013252/**
13253 * hdd_get_conparam() - driver exit point
13254 *
13255 * This is the driver exit point (invoked when module is unloaded using rmmod)
13256 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080013257 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013258 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080013259enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013260{
Jeff Johnson876c1a62017-12-12 10:43:07 -080013261 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013262}
13263
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080013264void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013265{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080013266 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013267}
13268
Komal Seelamc11bb222016-01-27 18:57:10 +053013269/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013270 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
13271 * @hdd_ctx: HDD context
13272 *
13273 * Cleans up the pre cac interface, if it exists
13274 *
13275 * Return: None
13276 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013277void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013278{
13279 uint8_t session_id;
13280 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070013281 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013282
Jeff Johnson16528362018-06-14 12:34:16 -070013283 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->mac_handle, &session_id);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013284 if (QDF_IS_STATUS_ERROR(status)) {
13285 hdd_err("failed to get pre cac vdev id");
13286 return;
13287 }
13288
13289 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
13290 if (!precac_adapter) {
Jeff Johnsondd2f1fc2018-05-06 11:22:52 -070013291 hdd_err("invalid pre cac adapter");
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013292 return;
13293 }
13294
13295 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
13296 wlan_hdd_sap_pre_cac_failure,
13297 (void *)precac_adapter);
13298 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
13299
13300}
13301
13302/**
Komal Seelamec702b02016-02-24 18:42:16 +053013303 * hdd_update_ol_config - API to update ol configuration parameters
13304 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053013305 *
Komal Seelamc11bb222016-01-27 18:57:10 +053013306 * Return: void
13307 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013308static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053013309{
Komal Seelamec702b02016-02-24 18:42:16 +053013310 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053013311 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053013312
Komal Seelamec702b02016-02-24 18:42:16 +053013313 if (!ol_ctx)
13314 return;
13315
13316 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
13317 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
13318 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
13319 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070013320 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053013321
13322 ol_init_ini_config(ol_ctx, &cfg);
13323}
13324
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013325#ifdef FEATURE_RUNTIME_PM
13326/**
13327 * hdd_populate_runtime_cfg() - populate runtime configuration
13328 * @hdd_ctx: hdd context
13329 * @cfg: pointer to the configuration memory being populated
13330 *
13331 * Return: void
13332 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013333static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013334 struct hif_config_info *cfg)
13335{
13336 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
13337 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
13338}
13339#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013340static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013341 struct hif_config_info *cfg)
13342{
13343}
13344#endif
13345
Komal Seelamec702b02016-02-24 18:42:16 +053013346/**
13347 * hdd_update_hif_config - API to update HIF configuration parameters
13348 * @hdd_ctx: HDD Context
13349 *
13350 * Return: void
13351 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013352static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053013353{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053013354 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053013355 struct hif_config_info cfg;
13356
13357 if (!scn)
13358 return;
13359
13360 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013361 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053013362 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070013363
13364 if (hdd_ctx->config->prevent_link_down)
13365 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053013366}
13367
13368/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013369 * hdd_update_dp_config() - Propagate config parameters to Lithium
13370 * datapath
13371 * @hdd_ctx: HDD Context
13372 *
13373 * Return: 0 for success/errno for failure
13374 */
13375static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
13376{
13377 struct cdp_config_params params;
13378 QDF_STATUS status;
13379
13380 params.tso_enable = hdd_ctx->config->tso_enable;
13381 params.lro_enable = hdd_ctx->config->lro_enable;
13382#ifdef QCA_LL_TX_FLOW_CONTROL_V2
13383 params.tx_flow_stop_queue_threshold =
13384 hdd_ctx->config->TxFlowStopQueueThreshold;
13385 params.tx_flow_start_queue_offset =
13386 hdd_ctx->config->TxFlowStartQueueOffset;
13387#endif
13388 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
13389 params.napi_enable = hdd_ctx->napi_enable;
13390 params.tcp_udp_checksumoffload =
13391 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
13392
13393 status = cdp_update_config_parameters(
13394 cds_get_context(QDF_MODULE_ID_SOC),
13395 &params);
13396 if (status) {
Dustin Browna2868622018-03-20 11:38:14 -070013397 hdd_err("Failed to attach config parameters");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013398 return status;
13399 }
13400
13401 return 0;
13402}
13403
13404/**
Komal Seelamec702b02016-02-24 18:42:16 +053013405 * hdd_update_config() - Initialize driver per module ini parameters
13406 * @hdd_ctx: HDD Context
13407 *
13408 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013409 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053013410 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013411int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053013412{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013413 int ret;
13414
Komal Seelamec702b02016-02-24 18:42:16 +053013415 hdd_update_ol_config(hdd_ctx);
13416 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013417 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
13418 ret = hdd_update_cds_config_ftm(hdd_ctx);
13419 else
13420 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080013421 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013422
13423 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053013424}
13425
Mukul Sharma9d797a02017-01-05 20:26:03 +053013426#ifdef FEATURE_WLAN_RA_FILTERING
13427/**
13428 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
13429 * @psoc_cfg: pmo psoc Configuration
13430 * @hdd_ctx: Pointer to hdd context
13431 *
13432 * Return: none
13433 */
13434static inline void hdd_ra_populate_pmo_config(
13435 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013436 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013437{
13438 psoc_cfg->ra_ratelimit_interval =
13439 hdd_ctx->config->RArateLimitInterval;
13440 psoc_cfg->ra_ratelimit_enable =
13441 hdd_ctx->config->IsRArateLimitEnabled;
13442}
13443#else
13444static inline void hdd_ra_populate_pmo_config(
13445 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013446 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013447{
13448}
13449#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080013450
Mukul Sharma9d797a02017-01-05 20:26:03 +053013451/**
13452 * hdd_update_pmo_config - API to update pmo configuration parameters
13453 * @hdd_ctx: HDD context
13454 *
13455 * Return: void
13456 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013457static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013458{
Mukul Sharma9d797a02017-01-05 20:26:03 +053013459 struct pmo_psoc_cfg psoc_cfg;
13460 QDF_STATUS status;
13461
13462 /*
13463 * Value of hdd_ctx->wowEnable can be,
13464 * 0 - Disable both magic pattern match and pattern byte match.
13465 * 1 - Enable magic pattern match on all interfaces.
13466 * 2 - Enable pattern byte match on all interfaces.
13467 * 3 - Enable both magic patter and pattern byte match on
13468 * all interfaces.
13469 */
13470 psoc_cfg.magic_ptrn_enable =
13471 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
13472 psoc_cfg.ptrn_match_enable_all_vdev =
13473 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Nachiket Kukadee547a482018-05-22 16:43:30 +053013474 psoc_cfg.apf_enable = hdd_ctx->config->apf_packet_filter_enable;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013475 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Nachiket Kukadef0804072018-02-27 18:20:07 +053013476 psoc_cfg.hw_filter_mode_bitmap = hdd_ctx->config->hw_filter_mode_bitmap;
Dustin Brownb9987af2018-03-01 17:15:11 -080013477 psoc_cfg.ns_offload_enable_dynamic = hdd_ctx->config->fhostNSOffload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013478 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
Dustin Brownb9987af2018-03-01 17:15:11 -080013479 psoc_cfg.packet_filter_enabled = !hdd_ctx->config->disablePacketFilter;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013480 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
13481 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
Dustin Brownb9987af2018-03-01 17:15:11 -080013482 psoc_cfg.active_mode_offload = hdd_ctx->config->active_mode_offload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013483 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080013484 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9223f232017-03-08 18:42:27 +053013485 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
13486 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
13487 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
Dustin Brownb9987af2018-03-01 17:15:11 -080013488 psoc_cfg.power_save_mode = hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053013489 psoc_cfg.auto_power_save_fail_mode =
13490 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013491
13492 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053013493 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013494
Dustin Brownb9987af2018-03-01 17:15:11 -080013495 status = ucfg_pmo_update_psoc_config(hdd_ctx->hdd_psoc, &psoc_cfg);
13496 if (QDF_IS_STATUS_ERROR(status))
13497 hdd_err("failed pmo psoc configuration; status:%d", status);
13498
13499 return qdf_status_to_os_return(status);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013500}
13501
Abhishek Singhb20db962017-03-03 21:28:46 +053013502#ifdef FEATURE_WLAN_SCAN_PNO
13503static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
13504 struct hdd_config *cfg)
13505{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070013506 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
13507
Abhishek Singhb20db962017-03-03 21:28:46 +053013508 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
13509 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
13510 pno_cfg->stationary_thresh = cfg->stationary_thresh;
13511 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
13512 pno_cfg->channel_prediction_full_scan =
13513 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070013514 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
13515 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
13516 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
13517 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053013518}
13519#else
13520static inline void
13521hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070013522 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053013523{
Abhishek Singhb20db962017-03-03 21:28:46 +053013524}
13525#endif
13526
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013527void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
13528 struct hdd_config *cfg)
13529{
13530 uint8_t i = 0;
13531
13532 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
13533 if (!ie_whitelist->white_list)
13534 return;
13535
13536 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
13537 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
13538 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
13539 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
13540 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
13541 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
13542 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
13543 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
13544
13545 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
13546 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
13547 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
13548}
13549
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013550uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
13551{
13552 uint8_t i, score;
13553
13554 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
13555 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
13556 if (score > MAX_INDEX_SCORE)
13557 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
13558 MAX_INDEX_SCORE, i);
13559 }
13560
13561 return per_index_score;
13562}
13563
13564/**
13565 * hdd_update_score_config - API to update candidate scoring related params
13566 * configuration parameters
13567 * @score_config: score config to update
13568 * @cfg: config params
13569 *
13570 * Return: 0 if success else err
13571 */
13572static void hdd_update_score_config(
13573 struct scoring_config *score_config, struct hdd_config *cfg)
13574{
13575 int total_weight;
13576
13577 score_config->weight_cfg.rssi_weightage = cfg->rssi_weightage;
13578 score_config->weight_cfg.ht_caps_weightage = cfg->ht_caps_weightage;
13579 score_config->weight_cfg.vht_caps_weightage =
13580 cfg->vht_caps_weightage;
13581 score_config->weight_cfg.he_caps_weightage =
13582 cfg->he_caps_weightage;
13583 score_config->weight_cfg.chan_width_weightage =
13584 cfg->chan_width_weightage;
13585 score_config->weight_cfg.chan_band_weightage =
13586 cfg->chan_band_weightage;
13587 score_config->weight_cfg.nss_weightage = cfg->nss_weightage;
13588 score_config->weight_cfg.beamforming_cap_weightage =
13589 cfg->beamforming_cap_weightage;
13590 score_config->weight_cfg.pcl_weightage = cfg->pcl_weightage;
13591 score_config->weight_cfg.channel_congestion_weightage =
13592 cfg->channel_congestion_weightage;
13593 score_config->weight_cfg.oce_wan_weightage = cfg->oce_wan_weightage;
13594
13595 total_weight = score_config->weight_cfg.rssi_weightage +
13596 score_config->weight_cfg.ht_caps_weightage +
13597 score_config->weight_cfg.vht_caps_weightage +
13598 score_config->weight_cfg.he_caps_weightage +
13599 score_config->weight_cfg.chan_width_weightage +
13600 score_config->weight_cfg.chan_band_weightage +
13601 score_config->weight_cfg.nss_weightage +
13602 score_config->weight_cfg.beamforming_cap_weightage +
13603 score_config->weight_cfg.pcl_weightage +
13604 score_config->weight_cfg.channel_congestion_weightage +
13605 score_config->weight_cfg.oce_wan_weightage;
13606
13607 if (total_weight > BEST_CANDIDATE_MAX_WEIGHT) {
13608 hdd_err("total weight is greater than %d fallback to default values",
13609 BEST_CANDIDATE_MAX_WEIGHT);
13610
13611 score_config->weight_cfg.rssi_weightage = RSSI_WEIGHTAGE;
13612 score_config->weight_cfg.ht_caps_weightage =
13613 HT_CAPABILITY_WEIGHTAGE;
13614 score_config->weight_cfg.vht_caps_weightage = VHT_CAP_WEIGHTAGE;
13615 score_config->weight_cfg.he_caps_weightage = HE_CAP_WEIGHTAGE;
13616 score_config->weight_cfg.chan_width_weightage =
13617 CHAN_WIDTH_WEIGHTAGE;
13618 score_config->weight_cfg.chan_band_weightage =
13619 CHAN_BAND_WEIGHTAGE;
13620 score_config->weight_cfg.nss_weightage = NSS_WEIGHTAGE;
13621 score_config->weight_cfg.beamforming_cap_weightage =
13622 BEAMFORMING_CAP_WEIGHTAGE;
13623 score_config->weight_cfg.pcl_weightage = PCL_WEIGHT;
13624 score_config->weight_cfg.channel_congestion_weightage =
13625 CHANNEL_CONGESTION_WEIGHTAGE;
13626 score_config->weight_cfg.oce_wan_weightage = OCE_WAN_WEIGHTAGE;
13627 }
13628
13629 score_config->bandwidth_weight_per_index =
13630 hdd_limit_max_per_index_score(
13631 cfg->bandwidth_weight_per_index);
13632 score_config->nss_weight_per_index =
13633 hdd_limit_max_per_index_score(cfg->nss_weight_per_index);
13634 score_config->band_weight_per_index =
13635 hdd_limit_max_per_index_score(cfg->band_weight_per_index);
13636
13637 score_config->rssi_score.best_rssi_threshold =
13638 cfg->best_rssi_threshold;
13639 score_config->rssi_score.good_rssi_threshold =
13640 cfg->good_rssi_threshold;
13641 score_config->rssi_score.bad_rssi_threshold =
13642 cfg->bad_rssi_threshold;
13643 score_config->rssi_score.good_rssi_pcnt = cfg->good_rssi_pcnt;
13644 score_config->rssi_score.bad_rssi_pcnt = cfg->bad_rssi_pcnt;
13645 score_config->rssi_score.good_rssi_bucket_size =
13646 cfg->good_rssi_bucket_size;
13647 score_config->rssi_score.bad_rssi_bucket_size =
13648 cfg->bad_rssi_bucket_size;
13649 score_config->rssi_score.rssi_pref_5g_rssi_thresh =
13650 cfg->rssi_pref_5g_rssi_thresh;
13651
13652 score_config->esp_qbss_scoring.num_slot = cfg->num_esp_qbss_slots;
13653 score_config->esp_qbss_scoring.score_pcnt3_to_0 =
13654 hdd_limit_max_per_index_score(
13655 cfg->esp_qbss_score_slots3_to_0);
13656 score_config->esp_qbss_scoring.score_pcnt7_to_4 =
13657 hdd_limit_max_per_index_score(
13658 cfg->esp_qbss_score_slots7_to_4);
13659 score_config->esp_qbss_scoring.score_pcnt11_to_8 =
13660 hdd_limit_max_per_index_score(
13661 cfg->esp_qbss_score_slots11_to_8);
13662 score_config->esp_qbss_scoring.score_pcnt15_to_12 =
13663 hdd_limit_max_per_index_score(
13664 cfg->esp_qbss_score_slots15_to_12);
13665
13666 score_config->oce_wan_scoring.num_slot = cfg->num_oce_wan_slots;
13667 score_config->oce_wan_scoring.score_pcnt3_to_0 =
13668 hdd_limit_max_per_index_score(
13669 cfg->oce_wan_score_slots3_to_0);
13670 score_config->oce_wan_scoring.score_pcnt7_to_4 =
13671 hdd_limit_max_per_index_score(
13672 cfg->oce_wan_score_slots7_to_4);
13673 score_config->oce_wan_scoring.score_pcnt11_to_8 =
13674 hdd_limit_max_per_index_score(
13675 cfg->oce_wan_score_slots11_to_8);
13676 score_config->oce_wan_scoring.score_pcnt15_to_12 =
13677 hdd_limit_max_per_index_score(
13678 cfg->oce_wan_score_slots15_to_12);
13679
13680
13681 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
13682 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
13683 score_config->nss = cfg->enable2x2 ? 2 : 1;
13684
13685 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
13686 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
13687 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
13688 score_config->he_cap = 1;
13689
13690 if (score_config->he_cap ||
13691 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
13692 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
13693 score_config->vht_cap = 1;
13694
13695 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
13696 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
13697 score_config->ht_cap = 1;
13698
13699 if (score_config->vht_cap && cfg->enableVhtFor24GHzBand)
13700 score_config->vht_24G_cap = 1;
13701
13702 if (cfg->enableTxBF)
13703 score_config->beamformee_cap = 1;
13704
13705}
13706
Abhishek Singh257a9482017-03-06 16:52:39 +053013707/**
bings81fe50a2017-11-27 14:33:26 +080013708 * hdd_update_dfs_config() - API to update dfs configuration parameters.
13709 * @hdd_ctx: HDD context
13710 *
13711 * Return: 0 if success else err
13712 */
13713static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
13714{
13715 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13716 struct hdd_config *cfg = hdd_ctx->config;
13717 struct dfs_user_config dfs_cfg;
13718 QDF_STATUS status;
13719
13720 dfs_cfg.dfs_is_phyerr_filter_offload = !!cfg->fDfsPhyerrFilterOffload;
13721 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
13722 if (QDF_IS_STATUS_ERROR(status)) {
13723 hdd_err("failed dfs psoc configuration");
13724 return -EINVAL;
13725 }
13726
13727 return 0;
13728}
13729
13730/**
Abhishek Singh257a9482017-03-06 16:52:39 +053013731 * hdd_update_scan_config - API to update scan configuration parameters
13732 * @hdd_ctx: HDD context
13733 *
13734 * Return: 0 if success else err
13735 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013736static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053013737{
13738 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13739 struct scan_user_cfg scan_cfg;
13740 struct hdd_config *cfg = hdd_ctx->config;
13741 QDF_STATUS status;
13742
13743 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
13744 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
13745 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
13746 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
13747 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
13748 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
13749 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053013750 /* convert to ms */
13751 scan_cfg.scan_cache_aging_time =
13752 cfg->scanAgingTimeout * 1000;
13753 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
13754 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
13755 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
13756 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053013757 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053013758 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080013759 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
13760 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053013761 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070013762 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singhc87bb042018-01-30 17:10:42 +053013763 scan_cfg.sta_miracast_mcc_rest_time =
13764 cfg->sta_miracast_mcc_rest_time_val;
Abhishek Singh257a9482017-03-06 16:52:39 +053013765
Abhishek Singhb20db962017-03-03 21:28:46 +053013766 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013767 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013768 hdd_update_score_config(&scan_cfg.score_config, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053013769
Abhishek Singh257a9482017-03-06 16:52:39 +053013770 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
13771 if (status != QDF_STATUS_SUCCESS) {
13772 hdd_err("failed pmo psoc configuration");
13773 return -EINVAL;
13774 }
13775
13776 return 0;
13777}
Abhishek Singh257a9482017-03-06 16:52:39 +053013778
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013779int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013780{
13781 int ret;
13782
13783 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053013784 if (ret)
13785 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013786
Abhishek Singh257a9482017-03-06 16:52:39 +053013787 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080013788 if (ret)
13789 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013790
Frank Liud4b2fa02017-03-29 11:46:48 +080013791 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013792 if (ret)
13793 return ret;
13794
13795 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080013796 if (ret)
13797 return ret;
13798
13799 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013800
13801 return ret;
13802}
13803
Agrawal Ashish65634612016-08-18 13:24:32 +053013804/**
13805 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
13806 * @mode : cfg80211 DFS mode
13807 *
13808 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
13809 */
13810enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
13811{
13812 switch (mode) {
13813 case DFS_MODE_ENABLE:
13814 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013815 case DFS_MODE_DISABLE:
13816 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013817 case DFS_MODE_DEPRIORITIZE:
13818 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013819 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013820 hdd_debug("ACS dfs mode is NONE");
13821 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013822 }
13823}
13824
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013825/**
13826 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
13827 * @hddctx: pointer to hdd context
13828 * @set_value: enable/disable
13829 *
13830 * When Host sends vendor command enable, FW will send *ONE* CA ind to
13831 * Host(even though it is duplicate). When Host send vendor command
13832 * disable,FW doesn't perform any action. Whenever any change in
13833 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
13834 *
13835 * return - 0 on success, appropriate error values on failure.
13836 */
Jeff Johnson16528362018-06-14 12:34:16 -070013837int hdd_enable_disable_ca_event(struct hdd_context *hdd_ctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013838{
13839 QDF_STATUS status;
13840
Jeff Johnson16528362018-06-14 12:34:16 -070013841 if (0 != wlan_hdd_validate_context(hdd_ctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013842 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013843
Jeff Johnson16528362018-06-14 12:34:16 -070013844 if (!hdd_ctx->config->goptimize_chan_avoid_event) {
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013845 hdd_warn("goptimize_chan_avoid_event ini param disabled");
13846 return -EINVAL;
13847 }
13848
Jeff Johnson16528362018-06-14 12:34:16 -070013849 status = sme_enable_disable_chanavoidind_event(hdd_ctx->mac_handle,
13850 set_value);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013851 if (!QDF_IS_STATUS_SUCCESS(status)) {
13852 hdd_err("Failed to send chan avoid command to SME");
13853 return -EINVAL;
13854 }
13855 return 0;
13856}
Agrawal Ashish65634612016-08-18 13:24:32 +053013857
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013858/**
13859 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
13860 * @value: value to set
13861 *
13862 * This function will set the passed value to roaming in progress flag.
13863 *
13864 * Return: None
13865 */
13866void hdd_set_roaming_in_progress(bool value)
13867{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013868 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013869
13870 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13871 if (!hdd_ctx) {
13872 hdd_err("HDD context is NULL");
13873 return;
13874 }
13875
13876 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013877 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013878}
13879
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053013880bool hdd_is_roaming_in_progress(struct hdd_context *hdd_ctx)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013881{
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013882 if (!hdd_ctx) {
13883 hdd_err("HDD context is NULL");
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053013884 return false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013885 }
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013886
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053013887 hdd_debug("roaming_in_progress = %d", hdd_ctx->roaming_in_progress);
13888
13889 return hdd_ctx->roaming_in_progress;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013890}
13891
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013892/**
13893 * hdd_is_connection_in_progress() - check if connection is in
13894 * progress
13895 * @session_id: session id
13896 * @reason: scan reject reason
13897 *
13898 * Go through each adapter and check if Connection is in progress
13899 *
13900 * Return: true if connection is in progress else false
13901 */
13902bool hdd_is_connection_in_progress(uint8_t *session_id,
13903 enum scan_reject_states *reason)
13904{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070013905 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070013906 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013907 uint8_t sta_id = 0;
13908 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013909 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -070013910 mac_handle_t mac_handle;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013911
13912 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13913 if (!hdd_ctx) {
13914 hdd_err("HDD context is NULL");
13915 return false;
13916 }
13917
Jeff Johnson16528362018-06-14 12:34:16 -070013918 mac_handle = hdd_ctx->mac_handle;
13919
Dustin Brown920397d2017-12-13 16:27:50 -080013920 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya929afa42018-06-01 15:04:44 -070013921 hdd_debug("Adapter with device mode %s(%d) exists",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013922 hdd_device_mode_to_string(adapter->device_mode),
13923 adapter->device_mode);
13924 if (((QDF_STA_MODE == adapter->device_mode)
13925 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
13926 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
13927 && (eConnectionState_Connecting ==
13928 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
13929 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013930 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013931 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013932 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013933 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013934 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013935 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013936 }
13937 return true;
13938 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013939 /*
13940 * sme_neighbor_middle_of_roaming is for LFR2
13941 * hdd_is_roaming_in_progress is for LFR3
13942 */
13943 if (((QDF_STA_MODE == adapter->device_mode) &&
13944 sme_neighbor_middle_of_roaming(
Jeff Johnson16528362018-06-14 12:34:16 -070013945 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013946 adapter->session_id)) ||
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053013947 hdd_is_roaming_in_progress(hdd_ctx)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013948 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013949 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013950 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013951 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013952 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013953 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013954 }
13955 return true;
13956 }
13957 if ((QDF_STA_MODE == adapter->device_mode) ||
13958 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
13959 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
13960 hdd_sta_ctx =
13961 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
13962 if ((eConnectionState_Associated ==
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053013963 hdd_sta_ctx->conn_info.connState)
13964 && sme_is_sta_key_exchange_in_progress(
Jeff Johnson16528362018-06-14 12:34:16 -070013965 mac_handle, adapter->session_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013966 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070013967 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013968 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013969 " is in middle of WPS/EAPOL exchange.",
13970 MAC_ADDR_ARRAY(sta_mac));
13971 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013972 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013973 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013974 }
13975 return true;
13976 }
13977 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
13978 (QDF_P2P_GO_MODE == adapter->device_mode)) {
13979 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
13980 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013981 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013982 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013983 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013984 continue;
13985
13986 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013987 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070013988 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013989 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013990 " of SAP/GO is in middle of WPS/EAPOL exchange",
13991 MAC_ADDR_ARRAY(sta_mac));
13992 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013993 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013994 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013995 }
13996 return true;
13997 }
13998 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013999 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014000 return true;
14001 }
14002 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014003 }
Dustin Brown920397d2017-12-13 16:27:50 -080014004
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014005 return false;
14006}
14007
14008/**
14009 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070014010 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014011 *
14012 * Return: None
14013 */
Jeff Johnson9d295242017-08-29 14:39:48 -070014014void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014015{
Jeff Johnson87251032017-08-29 13:31:11 -070014016 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070014017 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014018 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014019 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Jeff Johnsone4c11db2018-05-05 23:22:32 -070014020 tsap_config_t *sap_config;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014021 void *sap_ctx;
14022
14023 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070014024 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070014025 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014026
14027 mutex_lock(&hdd_ctx->sap_lock);
14028 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
14029 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014030 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
14031 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
14032 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
14033 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053014034 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014035 qdf_stop_bss_event,
14036 SME_CMD_TIMEOUT_VALUE);
14037
14038 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014039 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014040 goto end;
14041 }
14042 }
14043 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014044 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070014045 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070014046 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014047 false);
Jeff Johnson6867ec32017-09-29 20:30:20 -070014048 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014049
14050 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014051 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014052 wlansap_reset_sap_config_add_ie(sap_config,
14053 eUPDATE_IE_ALL);
14054 goto end;
14055 }
14056
14057 qdf_event_reset(&hostapd_state->qdf_event);
14058 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
14059 sap_config,
14060 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014061 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014062 wlansap_reset_sap_config_add_ie(sap_config,
14063 eUPDATE_IE_ALL);
14064 goto end;
14065 }
14066
Jeff Johnson6867ec32017-09-29 20:30:20 -070014067 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014068 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053014069 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014070 SME_CMD_TIMEOUT_VALUE);
14071 wlansap_reset_sap_config_add_ie(sap_config,
14072 eUPDATE_IE_ALL);
14073 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014074 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014075 goto end;
14076 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070014077 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014078 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014079 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014080 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
14081 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070014082 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070014083 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053014084 ap_adapter->device_mode,
14085 true);
14086 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014087 }
14088end:
14089 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014090}
14091
14092/**
14093 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
14094 * with non dfs acs
14095 *
14096 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
14097 *
14098 * Return: None
14099 */
14100void hdd_check_and_restart_sap_with_non_dfs_acs(void)
14101{
Jeff Johnson9d295242017-08-29 14:39:48 -070014102 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014103 struct hdd_context *hdd_ctx;
Jeff Johnson2b6982c2018-05-29 14:56:11 -070014104 struct cds_context *cds_ctx;
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014105 uint8_t restart_chan;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014106
14107 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14108 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014109 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014110 return;
14111 }
14112
14113 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
14114 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014115 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014116 return;
14117 }
14118
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080014119 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
14120 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Dustin Brown7e761c72018-07-31 13:50:17 -070014121 hdd_debug("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014122 return;
14123 }
14124
14125 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070014126 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
14127 &ap_adapter->event_flags) &&
14128 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070014129 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014130
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014131 hdd_warn("STA-AP Mode DFS not supported, Switch SAP channel to Non DFS");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014132
Rajeev Kumar Sirasanagandla4133d862018-08-23 12:21:36 +053014133 restart_chan =
14134 hdd_get_safe_channel_from_pcl_and_acs_range(ap_adapter);
14135 if (!restart_chan ||
14136 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev, restart_chan))
14137 restart_chan = SAP_DEFAULT_5GHZ_CHANNEL;
14138
14139 hdd_switch_sap_channel(ap_adapter, restart_chan, true);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014140 }
14141}
14142
14143/**
14144 * hdd_set_connection_in_progress() - to set the connection in
14145 * progress flag
14146 * @value: value to set
14147 *
14148 * This function will set the passed value to connection in progress flag.
14149 * If value is previously being set to true then no need to set it again.
14150 *
14151 * Return: true if value is being set correctly and false otherwise.
14152 */
14153bool hdd_set_connection_in_progress(bool value)
14154{
14155 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014156 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014157
14158 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14159 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014160 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014161 return false;
14162 }
14163
14164 qdf_spin_lock(&hdd_ctx->connection_status_lock);
14165 /*
14166 * if the value is set to true previously and if someone is
14167 * trying to make it true again then it could be some race
14168 * condition being triggered. Avoid this situation by returning
14169 * false
14170 */
14171 if (hdd_ctx->connection_in_progress && value)
14172 status = false;
14173 else
14174 hdd_ctx->connection_in_progress = value;
14175 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
14176 return status;
14177}
14178
Jeff Johnson9d295242017-08-29 14:39:48 -070014179int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014180{
14181 if (!adapter) {
14182 hdd_err("Invalid adapter");
14183 return -EINVAL;
14184 }
14185 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070014186 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014187 WMA_VDEV_MCC_SET_TIME_QUOTA,
14188 set_value, VDEV_CMD);
14189 return 0;
14190
14191}
14192
Jeff Johnson9d295242017-08-29 14:39:48 -070014193int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014194{
14195 if (!adapter) {
14196 hdd_err("Invalid adapter");
14197 return -EINVAL;
14198 }
14199
14200 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070014201 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014202 WMA_VDEV_MCC_SET_TIME_LATENCY,
14203 set_value, VDEV_CMD);
14204 return 0;
14205}
14206
Jeff Johnson9d295242017-08-29 14:39:48 -070014207struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070014208 *psoc, uint8_t vdev_id)
14209{
Jeff Johnson9d295242017-08-29 14:39:48 -070014210 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014211 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070014212
14213 /*
14214 * Currently PSOC is not being used. But this logic will
14215 * change once we have the converged implementation of
14216 * HDD context per PSOC in place. This would break if
14217 * multiple vdev objects reuse the vdev id.
14218 */
14219 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
14220 if (!adapter)
14221 hdd_err("Get adapter by vdev id failed");
14222
14223 return adapter;
14224}
14225
Jeff Johnson9d295242017-08-29 14:39:48 -070014226int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014227 int8_t *rssi, int8_t *snr)
14228{
14229 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -070014230 mac_handle_t mac_handle;
Jeff Johnson025618c2018-03-18 14:41:00 -070014231 struct csr_roam_profile *roam_profile;
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014232
Jeff Johnson025618c2018-03-18 14:41:00 -070014233 roam_profile = hdd_roam_profile(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -070014234 mac_handle = hdd_adapter_get_mac_handle(adapter);
14235 status = sme_get_rssi_snr_by_bssid(mac_handle,
Jeff Johnson025618c2018-03-18 14:41:00 -070014236 roam_profile, bssid, rssi, snr);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014237 if (QDF_STATUS_SUCCESS != status) {
14238 hdd_warn("sme_get_rssi_snr_by_bssid failed");
14239 return -EINVAL;
14240 }
14241
14242 return 0;
14243}
14244
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014245/**
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014246 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
14247 * @adapter - HDD adapter
14248 *
14249 * Return: 0 on success and non zero value on failure
14250 */
14251int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
14252{
14253 struct hdd_context *hdd_ctx;
14254 int ret;
14255 QDF_STATUS status;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014256
14257 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
14258 ret = wlan_hdd_validate_context(hdd_ctx);
14259 if (ret < 0)
14260 return ret;
14261
14262 /* set the system preferece to default */
14263 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
14264 hdd_ctx->config->conc_system_pref);
14265
14266 /* clear the bitmap */
14267 adapter->active_ac = 0;
14268
14269 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson16528362018-06-14 12:34:16 -070014270 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014271
Jeff Johnson16528362018-06-14 12:34:16 -070014272 status = sme_send_limit_off_channel_params(hdd_ctx->mac_handle,
14273 adapter->session_id,
14274 false, 0, 0, false);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014275 if (!QDF_IS_STATUS_SUCCESS(status)) {
14276 hdd_err("failed to reset limit off chan params");
14277 ret = -EINVAL;
14278 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014279
14280 return ret;
14281}
14282
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014283/**
14284 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
14285 * @drv_op: Enum indicating driver op
14286 *
14287 * Return: none
14288 */
14289void hdd_start_driver_ops_timer(int drv_op)
14290{
14291 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
14292 switch (drv_op) {
14293 case eHDD_DRV_OP_PROBE:
14294 memcpy(drv_ops_string, "probe", sizeof("probe"));
14295 break;
14296 case eHDD_DRV_OP_REMOVE:
14297 memcpy(drv_ops_string, "remove", sizeof("remove"));
14298 break;
14299 case eHDD_DRV_OP_SHUTDOWN:
14300 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
14301 break;
14302 case eHDD_DRV_OP_REINIT:
14303 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
14304 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053014305 case eHDD_DRV_OP_IFF_UP:
14306 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
14307 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014308 }
14309
Dustin Brown45ed4bb2017-12-18 12:00:13 -080014310 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014311 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
Dustin Browncfc54fe2018-06-18 16:17:41 -070014312 HDD_OPS_INACTIVITY_TIMEOUT * qdf_timer_get_multiplier());
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014313}
14314
14315/**
14316 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
14317 *
14318 * Return: none
14319 */
14320void hdd_stop_driver_ops_timer(void)
14321{
14322 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
14323}
14324
14325/**
14326 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
14327 * inactivity timer
14328 *
14329 * Return: None
14330 */
14331void hdd_drv_ops_inactivity_handler(void)
14332{
Rajeev Kumar4471f1b2018-06-08 14:18:28 -070014333 hdd_err("WLAN_BUG_RCA %s: %d Sec timer expired while in .%s",
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014334 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
14335
Dustin Brown45ed4bb2017-12-18 12:00:13 -080014336 if (hdd_drv_ops_task) {
14337 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
14338 qdf_print_thread_trace(hdd_drv_ops_task);
14339 } else {
14340 hdd_err("hdd_drv_ops_task is null");
14341 }
14342
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014343 /* Driver shutdown is stuck, no recovery possible at this point */
14344 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
14345 sizeof("shutdown")))
14346 QDF_BUG(0);
14347
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080014348 if (cds_is_fw_down()) {
14349 hdd_err("FW is down");
14350 return;
14351 }
14352
Dustin Brown83044c22018-08-13 15:00:44 -070014353 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014354}
14355
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053014356void hdd_pld_ipa_uc_shutdown_pipes(void)
14357{
14358 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14359
14360 if (!hdd_ctx)
14361 return;
14362
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +053014363 ucfg_ipa_uc_force_pipe_shutdown(hdd_ctx->hdd_pdev);
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053014364}
14365
Yun Parkff6a16a2017-09-26 16:38:18 -070014366/**
14367 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
14368 * @struct hdd_context *hdd_ctx
14369 * @struct hdd_adapter *padapter
14370 * @bool enble
14371 *
14372 * Return: none
14373 */
14374void hdd_set_rx_mode_rps(bool enable)
14375{
14376 struct cds_config_info *cds_cfg = cds_get_ini_config();
Ryan Hsu0e878fa2018-05-04 15:22:09 -070014377 struct hdd_context *hdd_ctx;
14378 struct hdd_adapter *adapter;
Yun Parkff6a16a2017-09-26 16:38:18 -070014379
Ryan Hsu0e878fa2018-05-04 15:22:09 -070014380 if (!cds_cfg)
14381 return;
14382
14383 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14384 if (!hdd_ctx)
14385 return;
14386
14387 adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
14388 if (!adapter)
14389 return;
14390
14391 if (!hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
Yun Parkff6a16a2017-09-26 16:38:18 -070014392 if (enable && !cds_cfg->rps_enabled)
14393 hdd_send_rps_ind(adapter);
14394 else if (!enable && cds_cfg->rps_enabled)
14395 hdd_send_rps_disable_ind(adapter);
14396 }
14397}
14398
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +053014399bool hdd_is_cli_iface_up(struct hdd_context *hdd_ctx)
14400{
14401 struct hdd_adapter *adapter = NULL;
14402
14403 hdd_for_each_adapter(hdd_ctx, adapter) {
14404 if ((adapter->device_mode == QDF_STA_MODE ||
14405 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
14406 qdf_atomic_test_bit(DEVICE_IFACE_OPENED,
14407 &adapter->event_flags)){
14408 return true;
14409 }
14410 }
14411
14412 return false;
14413}
14414
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014415/* Register the module init/exit functions */
14416module_init(hdd_module_init);
14417module_exit(hdd_module_exit);
14418
14419MODULE_LICENSE("Dual BSD/GPL");
14420MODULE_AUTHOR("Qualcomm Atheros, Inc.");
14421MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
14422
Srinivas Girigowda841da292018-02-21 16:33:00 -080014423static const struct kernel_param_ops con_mode_ops = {
14424 .set = con_mode_handler,
14425 .get = param_get_int,
14426};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014427
Srinivas Girigowda841da292018-02-21 16:33:00 -080014428static const struct kernel_param_ops con_mode_ftm_ops = {
14429 .set = con_mode_handler_ftm,
14430 .get = param_get_int,
14431};
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053014432
Nirav Shah73713f72018-05-17 14:50:41 +053014433#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080014434static const struct kernel_param_ops con_mode_monitor_ops = {
14435 .set = con_mode_handler_monitor,
14436 .get = param_get_int,
14437};
Nirav Shah73713f72018-05-17 14:50:41 +053014438#endif
Ravi Joshia307f632017-07-17 23:41:41 -070014439
Srinivas Girigowda841da292018-02-21 16:33:00 -080014440static const struct kernel_param_ops fwpath_ops = {
14441 .set = fwpath_changed_handler,
14442 .get = param_get_string,
14443};
14444
14445module_param_cb(con_mode, &con_mode_ops, &con_mode,
14446 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
14447
14448module_param_cb(con_mode_ftm, &con_mode_ftm_ops, &con_mode_ftm,
14449 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
14450
Nirav Shah73713f72018-05-17 14:50:41 +053014451#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080014452module_param_cb(con_mode_monitor, &con_mode_monitor_ops, &con_mode_monitor,
14453 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Nirav Shah73713f72018-05-17 14:50:41 +053014454#endif
Srinivas Girigowda841da292018-02-21 16:33:00 -080014455
14456module_param_cb(fwpath, &fwpath_ops, &fwpath,
14457 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014458
14459module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
14460
14461module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
14462
14463module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);