blob: 6eac267b5ab037200afc61ce5e290fc079716c59 [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>
Amar Singhal0928b192017-12-01 10:50:54 -0800128#include "wlan_hdd_sysfs.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530129#include "wlan_disa_ucfg_api.h"
Wu Gao52084c12018-05-17 20:47:11 +0800130#include "wlan_disa_obj_mgmt_api.h"
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +0530131#include "wlan_action_oui_ucfg_api.h"
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +0530132#include "wlan_ipa_ucfg_api.h"
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530133#include <target_if.h>
Alok Kumarb64650c2018-03-23 17:05:11 +0530134#include "wlan_hdd_nud_tracking.h"
Nachiket Kukaded0dd62e2018-05-21 18:39:22 +0530135#include "wlan_hdd_apf.h"
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -0700136#include "wlan_hdd_twt.h"
Rachit Kankane0dc3e852018-05-07 17:33:42 +0530137#include "qc_sap_ioctl.h"
Sandeep Puligillac5609d52018-05-17 19:23:41 -0700138#include "wlan_mlme_main.h"
Wu Gaoe5689792018-07-05 19:20:13 +0800139#include "wlan_p2p_cfg_api.h"
140
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530141#ifdef CNSS_GENL
142#include <net/cnss_nl.h>
143#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800144#include "wlan_reg_ucfg_api.h"
Zhang Qian47e22ce2018-01-04 15:38:38 +0800145#include "wlan_ocb_ucfg_api.h"
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -0800146#include <wlan_hdd_spectralscan.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800147#ifdef MODULE
148#define WLAN_MODULE_NAME module_name(THIS_MODULE)
149#else
150#define WLAN_MODULE_NAME "wlan"
151#endif
152
153#ifdef TIMER_MANAGER
154#define TIMER_MANAGER_STR " +TIMER_MANAGER"
155#else
156#define TIMER_MANAGER_STR ""
157#endif
158
159#ifdef MEMORY_DEBUG
160#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
161#else
162#define MEMORY_DEBUG_STR ""
163#endif
164
Dustin Brownc1034df2018-02-07 14:51:32 -0800165#ifdef PANIC_ON_BUG
166#define PANIC_ON_BUG_STR " +PANIC_ON_BUG"
167#else
168#define PANIC_ON_BUG_STR ""
169#endif
170
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530171bool g_is_system_reboot_triggered;
Sachin Ahujadddd2632017-03-07 19:07:24 +0530172int wlan_start_ret_val;
173static DECLARE_COMPLETION(wlan_start_comp);
174static unsigned int dev_num = 1;
175static struct cdev wlan_hdd_state_cdev;
176static struct class *class;
177static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530178#ifndef MODULE
179static struct gwlan_loader *wlan_loader;
180static ssize_t wlan_boot_cb(struct kobject *kobj,
181 struct kobj_attribute *attr,
182 const char *buf, size_t count);
183struct gwlan_loader {
184 bool loaded_state;
185 struct kobject *boot_wlan_obj;
186 struct attribute_group *attr_group;
187};
188
189static struct kobj_attribute wlan_boot_attribute =
190 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
191
192static struct attribute *attrs[] = {
193 &wlan_boot_attribute.attr,
194 NULL,
195};
196
197#define MODULE_INITIALIZED 1
198#endif
199
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530200#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
201#define MAX_OPS_NAME_STRING_SIZE 20
Rajeev Kumar6d0b2ea2017-12-26 17:55:33 -0800202#define RATE_LIMIT_ERROR_LOG (256)
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530203
204static qdf_timer_t hdd_drv_ops_inactivity_timer;
Dustin Brown45ed4bb2017-12-18 12:00:13 -0800205static struct task_struct *hdd_drv_ops_task;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530206static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
207
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800208/* the Android framework expects this param even though we don't use it */
209#define BUF_LEN 20
210static char fwpath_buffer[BUF_LEN];
211static struct kparam_string fwpath = {
212 .string = fwpath_buffer,
213 .maxlen = BUF_LEN,
214};
215
216static char *country_code;
217static int enable_11d = -1;
218static int enable_dfs_chan_scan = -1;
219
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800220/*
221 * spinlock for synchronizing asynchronous request/response
222 * (full description of use in wlan_hdd_main.h)
223 */
224DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530225DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800226
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800227#define WLAN_NLINK_CESIUM 30
228
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530229static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800230
231#define WOW_MAX_FILTER_LISTS 1
232#define WOW_MAX_FILTERS_PER_LIST 4
233#define WOW_MIN_PATTERN_SIZE 6
234#define WOW_MAX_PATTERN_SIZE 64
235
Bala Venkatesh110b03e2018-07-10 16:02:08 +0530236/* max peer can be tdls peers + self peer + bss peer */
237#define HDD_MAX_VDEV_PEER_COUNT (HDD_MAX_NUM_TDLS_STA + 2)
238
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800239#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
240static const struct wiphy_wowlan_support wowlan_support_reg_init = {
241 .flags = WIPHY_WOWLAN_ANY |
242 WIPHY_WOWLAN_MAGIC_PKT |
243 WIPHY_WOWLAN_DISCONNECT |
244 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
245 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
246 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
247 WIPHY_WOWLAN_4WAY_HANDSHAKE |
248 WIPHY_WOWLAN_RFKILL_RELEASE,
249 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
250 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
251 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
252};
253#endif
254
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700255static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
256 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
257 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
258 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
259 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
260 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
261 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
262 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
263 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
264 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
265 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
266 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
267 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
268 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
269 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
270 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
271 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
272 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
273 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
274 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
275 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
276 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
277 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
278 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
279 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
280 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
281 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
282 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
283 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
284 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
285 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
286 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
287 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
288 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
289 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700290 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700291 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700292 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530293 [QDF_MODULE_ID_GREEN_AP] = {QDF_TRACE_LEVEL_ALL},
Zhang Qian47e22ce2018-01-04 15:38:38 +0800294 [QDF_MODULE_ID_OCB] = {QDF_TRACE_LEVEL_ALL},
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530295 [QDF_MODULE_ID_IPA] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +0530296 [QDF_MODULE_ID_ACTION_OUI] = {QDF_TRACE_LEVEL_ALL},
Dustin Brown84f46ea2018-02-15 11:57:36 -0800297 [QDF_MODULE_ID_CONFIG] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700298};
299
Ganesh Kondabattini35739572017-06-21 16:26:39 +0530300int limit_off_chan_tbl[HDD_MAX_AC][HDD_MAX_OFF_CHAN_ENTRIES] = {
301 { HDD_AC_BK_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BK },
302 { HDD_AC_BE_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BE },
303 { HDD_AC_VI_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VI },
304 { HDD_AC_VO_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VO },
305};
306
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530307struct notifier_block hdd_netdev_notifier;
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530308struct notifier_block system_reboot_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800309
310struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800311#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700312static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800313#endif
314
Sachin Ahujadddd2632017-03-07 19:07:24 +0530315void hdd_start_complete(int ret)
316{
317 wlan_start_ret_val = ret;
318
319 complete(&wlan_start_comp);
320}
321
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800322/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530323 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700324 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530325 *
326 * Return: none
327 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700328static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530329{
Jeff Johnson9d295242017-08-29 14:39:48 -0700330 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530331
Dustin Brown920397d2017-12-13 16:27:50 -0800332 hdd_for_each_adapter(hdd_ctx, adapter)
333 hdd_send_rps_ind(adapter);
Nirav Shahbd36b062016-07-18 11:12:59 +0530334}
335
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530336#ifdef QCA_HL_NETDEV_FLOW_CONTROL
337void wlan_hdd_mod_fc_timer(struct hdd_adapter *adapter,
338 enum netif_action_type action)
339{
340 if (!adapter->tx_flow_timer_initialized)
341 return;
342
343 if (action == WLAN_WAKE_NON_PRIORITY_QUEUE) {
344 qdf_mc_timer_stop(&adapter->tx_flow_control_timer);
345 } else if (action == WLAN_STOP_NON_PRIORITY_QUEUE) {
346 QDF_STATUS status =
347 qdf_mc_timer_start(&adapter->tx_flow_control_timer,
348 WLAN_HDD_TX_FLOW_CONTROL_OS_Q_BLOCK_TIME);
349
350 if (!QDF_IS_STATUS_SUCCESS(status))
351 hdd_err("Failed to start tx_flow_control_timer");
352 else
353 adapter->
354 hdd_stats.tx_rx_stats.txflow_timer_cnt++;
355
356 adapter->hdd_stats.tx_rx_stats.txflow_pause_cnt++;
357 adapter->hdd_stats.tx_rx_stats.is_txflow_paused = true;
358 }
359}
360#endif /* QCA_HL_NETDEV_FLOW_CONTROL */
361
Nirav Shahbd36b062016-07-18 11:12:59 +0530362/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800363 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
364 * @vdev_id: vdev_id
365 * @action: action type
366 * @reason: reason type
367 *
368 * Return: none
369 */
370void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
371 enum netif_action_type action, enum netif_reason_type reason)
372{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700373 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700374 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800375
376 if (!hdd_ctx) {
377 hdd_err("hdd ctx is NULL");
378 return;
379 }
380 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530381 wlan_hdd_mod_fc_timer(adapter, action);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800382 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800383}
384
385/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700386 * Store WLAN driver version and timestamp info in global variables such that
387 * crash debugger can extract them from driver debug symbol and crashdump for
388 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800389 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800390#ifdef BUILD_TAG
391uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR "; " BUILD_TAG;
392#else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800393uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700394#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800395
396/**
397 * hdd_device_mode_to_string() - return string conversion of device mode
398 * @device_mode: device mode
399 *
400 * This utility function helps log string conversion of device mode.
401 *
402 * Return: string conversion of device mode, if match found;
403 * "Unknown" otherwise.
404 */
405const char *hdd_device_mode_to_string(uint8_t device_mode)
406{
407 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800408 CASE_RETURN_STRING(QDF_STA_MODE);
409 CASE_RETURN_STRING(QDF_SAP_MODE);
410 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
411 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
412 CASE_RETURN_STRING(QDF_FTM_MODE);
413 CASE_RETURN_STRING(QDF_IBSS_MODE);
414 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
415 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700416 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800417 default:
418 return "Unknown";
419 }
420}
421
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530422/**
Liangwei Dong17bf2662018-01-05 02:02:05 -0500423 * hdd_get_valid_chan() - return current chan list from regulatory.
424 * @hdd_ctx: HDD context
425 * @chan_list: buf hold returned chan list
426 * @chan_num: input buf size and output returned chan num
427 *
428 * This function helps get current available chan list from regulatory
429 * module. It excludes the "disabled" and "invalid" channels.
430 *
431 * Return: 0 for success.
432 */
433static int hdd_get_valid_chan(struct hdd_context *hdd_ctx,
434 uint8_t *chan_list,
435 uint32_t *chan_num)
436{
437 int i = 0, j = 0;
438 struct regulatory_channel *cur_chan_list;
439 struct wlan_objmgr_pdev *pdev;
440
441 if (!hdd_ctx || !hdd_ctx->hdd_pdev || !chan_list || !chan_num)
442 return -EINVAL;
443
444 pdev = hdd_ctx->hdd_pdev;
445 cur_chan_list = qdf_mem_malloc(NUM_CHANNELS *
446 sizeof(struct regulatory_channel));
447 if (!cur_chan_list)
448 return -ENOMEM;
449
450 if (wlan_reg_get_current_chan_list(pdev, cur_chan_list) !=
451 QDF_STATUS_SUCCESS) {
452 qdf_mem_free(cur_chan_list);
453 return -EINVAL;
454 }
455
456 for (i = 0; i < NUM_CHANNELS; i++) {
457 uint32_t ch = cur_chan_list[i].chan_num;
458 enum channel_state state = wlan_reg_get_channel_state(pdev,
459 ch);
460
461 if (state != CHANNEL_STATE_DISABLE &&
462 state != CHANNEL_STATE_INVALID &&
463 j < *chan_num) {
464 chan_list[j] = (uint8_t)ch;
465 j++;
466 }
467 }
468 *chan_num = j;
469 qdf_mem_free(cur_chan_list);
470 return 0;
471}
472
473/**
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530474 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
475 * @adapter: HDD adapter
476 * @chan_number: Channel number
477 * @chan_bw: Bandwidth
478 *
479 * Checks if the given bandwidth is valid for the given channel number.
480 *
481 * Return: 0 for success, non-zero for failure
482 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700483int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530484 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800485 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530486{
Liangwei Dong17bf2662018-01-05 02:02:05 -0500487 uint8_t chan[NUM_CHANNELS];
488 uint32_t len = NUM_CHANNELS, i;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530489 bool found = false;
Jeff Johnson16528362018-06-14 12:34:16 -0700490 mac_handle_t mac_handle;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500491 int ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530492
Jeff Johnson16528362018-06-14 12:34:16 -0700493 mac_handle = hdd_adapter_get_mac_handle(adapter);
494 if (!mac_handle) {
495 hdd_err("Invalid MAC handle");
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530496 return -EINVAL;
497 }
498
Liangwei Dong17bf2662018-01-05 02:02:05 -0500499 ret = hdd_get_valid_chan(adapter->hdd_ctx, chan,
500 &len);
501 if (ret) {
502 hdd_err("error %d in getting valid channel list", ret);
503 return ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530504 }
505
506 for (i = 0; i < len; i++) {
507 if (chan[i] == chan_number) {
508 found = true;
509 break;
510 }
511 }
512
513 if (found == false) {
514 hdd_err("Channel not in driver's valid channel list");
515 return -EOPNOTSUPP;
516 }
517
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700518 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
519 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530520 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
521 return -EINVAL;
522 }
523
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700524 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530525 if (chan_bw == CH_WIDTH_80MHZ) {
526 hdd_err("BW80 not possible in 2.4GHz band");
527 return -EINVAL;
528 }
529 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
530 (chan_bw != CH_WIDTH_MAX)) {
531 hdd_err("Only BW20 possible on channel 14");
532 return -EINVAL;
533 }
534 }
535
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700536 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530537 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
538 (chan_bw != CH_WIDTH_MAX)) {
539 hdd_err("Only BW20 possible on channel 165");
540 return -EINVAL;
541 }
542 }
543
544 return 0;
545}
546
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530547/**
548 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
549 *
550 * Block the unloading of the driver (or) interface up until the
551 * cds recovery is completed
552 *
553 * Return: true for recovery completion else false
554 */
555static bool hdd_wait_for_recovery_completion(void)
556{
557 int retry = 0;
558
559 /* Wait for recovery to complete */
560 while (cds_is_driver_recovering()) {
561 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
562 hdd_err("Recovery in progress; wait here!!!");
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530563
564 if (g_is_system_reboot_triggered) {
565 hdd_info("System Reboot happening ignore unload!!");
566 return false;
567 }
568
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530569 msleep(1000);
570 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
571 hdd_err("SSR never completed, error");
572 /*
573 * Trigger the bug_on in the internal builds, in the
574 * customer builds self-recovery will be enabled
575 * in those cases just return error.
576 */
577 if (cds_is_self_recovery_enabled())
578 return false;
579 QDF_BUG(0);
580 }
581 }
582
583 hdd_info("Recovery completed successfully!");
584 return true;
585}
586
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530587
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800588static int __hdd_netdev_notifier_call(struct notifier_block *nb,
589 unsigned long state, void *data)
590{
591#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
592 struct netdev_notifier_info *dev_notif_info = data;
593 struct net_device *dev = dev_notif_info->dev;
594#else
595 struct net_device *dev = data;
596#endif
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530597 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700598 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800599
Dustin Brownfdf17c12018-03-14 12:55:34 -0700600 hdd_enter_dev(dev);
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800601
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800602 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700603 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800604 return NOTIFY_DONE;
605 }
606
Visweswara Tanuku6bc52de2018-04-09 18:38:30 +0530607 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
608 if (!hdd_ctx) {
609 hdd_err("HDD Context is Null");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530610 QDF_ASSERT(0);
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) {
615 hdd_err("%s: Driver module is closed", __func__);
616 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) {
622 hdd_err("Couldn't find adapter for dev name %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
631 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
632 hdd_err("Driver is in recovery or bad state");
633 return NOTIFY_DONE;
634 }
635
636 hdd_debug("%s New Net Device State = %lu", dev->name, state);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800637
638 switch (state) {
639 case NETDEV_REGISTER:
640 break;
641
642 case NETDEV_UNREGISTER:
643 break;
644
645 case NETDEV_UP:
Jeff Johnson16528362018-06-14 12:34:16 -0700646 sme_ch_avoid_update_req(hdd_ctx->mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800647 break;
648
649 case NETDEV_DOWN:
650 break;
651
652 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700653 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800654 complete(&adapter->linkup_event_var);
655 break;
656
657 case NETDEV_GOING_DOWN:
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700658 if (ucfg_scan_get_vdev_status(adapter->hdd_vdev) !=
659 SCAN_NOT_IN_PROGRESS) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530660 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -0700661 adapter->session_id, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800662 }
Min Liu9be5d4a2018-05-17 11:51:53 +0800663 cds_flush_work(&adapter->scan_block_work);
664 /* Need to clean up blocked scan request */
665 wlan_hdd_cfg80211_scan_block_cb(&adapter->scan_block_work);
Min Liu9be5d4a2018-05-17 11:51:53 +0800666 hdd_debug("Scan is not Pending from user");
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530667 /*
668 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
669 * of return status of hdd_stop call, kernel resets the IFF_UP
670 * flag after which driver does not send the cfg80211_scan_done.
671 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
672 */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +0530673 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800674 break;
675
676 default:
677 break;
678 }
679
680 return NOTIFY_DONE;
681}
682
683/**
684 * hdd_netdev_notifier_call() - netdev notifier callback function
685 * @nb: pointer to notifier block
686 * @state: state
687 * @ndev: ndev pointer
688 *
689 * Return: 0 on success, error number otherwise.
690 */
691static int hdd_netdev_notifier_call(struct notifier_block *nb,
692 unsigned long state,
693 void *ndev)
694{
695 int ret;
696
697 cds_ssr_protect(__func__);
698 ret = __hdd_netdev_notifier_call(nb, state, ndev);
699 cds_ssr_unprotect(__func__);
700
701 return ret;
702}
703
704struct notifier_block hdd_netdev_notifier = {
705 .notifier_call = hdd_netdev_notifier_call,
706};
707
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530708static int system_reboot_notifier_call(struct notifier_block *nb,
709 unsigned long msg_type, void *_unused)
710{
711 switch (msg_type) {
712 case SYS_DOWN:
713 case SYS_HALT:
714 case SYS_POWER_OFF:
715 g_is_system_reboot_triggered = true;
716 hdd_info("reboot, reason: %ld", msg_type);
717 break;
718 default:
719 break;
720 }
721
722 return NOTIFY_OK;
723}
724
725struct notifier_block system_reboot_notifier = {
726 .notifier_call = system_reboot_notifier_call,
727};
728
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800729/* variable to hold the insmod parameters */
730static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800731
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530732static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700733int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530734
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800735/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800736static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800737
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530738/**
739 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
740 * @ch_width: NL channel width
741 *
742 * Converts the NL channel width to the driver's internal representation
743 *
744 * Return: Converted channel width. In case of non matching NL channel width,
745 * CH_WIDTH_MAX will be returned.
746 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800747enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530748{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800749 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700750
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800751 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530752 switch (ch_width) {
753 case NL80211_CHAN_WIDTH_20_NOHT:
754 case NL80211_CHAN_WIDTH_20:
755 return CH_WIDTH_20MHZ;
756 case NL80211_CHAN_WIDTH_40:
757 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530758 case NL80211_CHAN_WIDTH_80:
759 return CH_WIDTH_80MHZ;
760 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800761 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
762 return CH_WIDTH_80P80MHZ;
763 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
764 return CH_WIDTH_160MHZ;
765 else
766 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530767 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800768 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_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800773 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530774 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800775 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530776 default:
777 hdd_err("Invalid channel width %d, setting to default",
778 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800779 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530780 }
781}
782
Jeff Johnson16528362018-06-14 12:34:16 -0700783uint8_t wlan_hdd_find_opclass(mac_handle_t mac_handle, uint8_t channel,
784 uint8_t bw_offset)
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530785{
786 uint8_t opclass = 0;
787
Jeff Johnson16528362018-06-14 12:34:16 -0700788 sme_get_opclass(mac_handle, channel, bw_offset, &opclass);
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530789 return opclass;
790}
791
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800792/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530793 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530794 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800795 * @bitmask: Bitmask of log levels to be enabled
796 *
797 * Called immediately after the cfg.ini is read in order to configure
798 * the desired trace levels.
799 *
800 * Return: None
801 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530802int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800803{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530804 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530805 int qdf_print_idx = -1;
806 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800807 /*
808 * if the bitmask is the default value, then a bitmask was not
809 * specified in cfg.ini, so leave the logging level alone (it
810 * will remain at the "compiled in" default value)
811 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700812 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530813 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800814
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530815 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800816
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530817 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530818 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530819 QDF_TRACE_LEVEL_NONE, 0);
820
821 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530822 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800823 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530824 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800825 while (0 != bitmask) {
826 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530827 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530828 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530829 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530830 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800831 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700832
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800833 level++;
834 bitmask >>= 1;
835 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530836 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800837}
838
839/**
Chris Guo1751acf2017-07-03 14:09:01 +0800840 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
841 * @hdd_ctx: HDD context pointer
842 *
843 * Return: 0 if the context is valid. Error code otherwise
844 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700845int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800846{
847 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
848 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
849 return -ENODEV;
850 }
851
852 if (cds_is_driver_recovering()) {
853 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
854 (void *)_RET_IP_, cds_get_driver_state());
855 return -EAGAIN;
856 }
857
858 if (hdd_ctx->start_modules_in_progress ||
859 hdd_ctx->stop_modules_in_progress) {
860 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
861 (void *)_RET_IP_);
862 return -EAGAIN;
863 }
864
865 return 0;
866}
867
868
869/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800870 * wlan_hdd_validate_context() - check the HDD context
871 * @hdd_ctx: HDD context pointer
872 *
873 * Return: 0 if the context is valid. Error code otherwise
874 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700875int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800876{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800877 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530878 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800879 return -ENODEV;
880 }
881
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800882 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800883 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530884 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800885 return -EAGAIN;
886 }
887
Yue Ma9f275d92017-09-14 16:58:41 -0700888 if (cds_is_load_or_unload_in_progress()) {
889 hdd_debug("%pS Load or unload in progress, state: 0x%x, ignore!",
890 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800891 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -0700892 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530893
894 if (hdd_ctx->start_modules_in_progress ||
895 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800896 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530897 (void *)_RET_IP_);
898 return -EAGAIN;
899 }
900
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530901 if (cds_is_driver_in_bad_state()) {
902 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
903 (void *)_RET_IP_, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +0530904 return -EAGAIN;
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530905 }
906
Arunk Khandavalli2859fa12018-02-14 10:46:26 +0530907 if (cds_is_fw_down()) {
908 hdd_debug("%pS FW is down: 0x%x Ignore!!!",
909 (void *)_RET_IP_, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +0530910 return -EAGAIN;
Arunk Khandavalli2859fa12018-02-14 10:46:26 +0530911 }
912
Liangwei Dong858feb12018-05-21 01:52:46 -0400913 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
914 hdd_debug("con_mode_handler is in progress Ignore!!!");
915 return -EAGAIN;
916 }
917
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800918 return 0;
919}
920
Jeff Johnson9d295242017-08-29 14:39:48 -0700921int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700922{
923 if (!adapter) {
924 hdd_err("adapter is null");
925 return -EINVAL;
926 }
927
928 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Mahesh Kumar Kalikot Veetil44427542018-06-08 12:29:36 -0700929 hdd_err("bad adapter magic");
Dustin Brownf13b8c32017-05-19 17:23:08 -0700930 return -EINVAL;
931 }
932
933 if (!adapter->dev) {
934 hdd_err("adapter net_device is null");
935 return -EINVAL;
936 }
937
938 if (!(adapter->dev->flags & IFF_UP)) {
939 hdd_info("adapter net_device is not up");
940 return -EAGAIN;
941 }
942
Jeff Johnson1b780e42017-10-31 14:11:45 -0700943 if (wlan_hdd_validate_session_id(adapter->session_id)) {
Dustin Brownf13b8c32017-05-19 17:23:08 -0700944 hdd_info("adapter session is not open");
945 return -EAGAIN;
946 }
947
Dustin Brownbee82832018-07-23 10:10:51 -0700948 if (adapter->session_id >= CSR_ROAM_SESSION_MAX) {
Jeff Johnson1b780e42017-10-31 14:11:45 -0700949 hdd_err("bad adapter session Id: %u", adapter->session_id);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700950 return -EINVAL;
951 }
952
953 return 0;
954}
955
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800956/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530957 * wlan_hdd_validate_modules_state() - Check modules status
958 * @hdd_ctx: HDD context pointer
959 *
960 * Check's the driver module's state and returns true if the
961 * modules are enabled returns false if modules are closed.
962 *
963 * Return: True if modules are enabled or false.
964 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700965bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530966{
967 mutex_lock(&hdd_ctx->iface_change_lock);
968 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
969 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown5e89ef82018-03-14 11:50:23 -0700970 hdd_info("Modules not enabled, Present status: %d",
971 hdd_ctx->driver_status);
Arun Khandavallica892f62017-05-26 14:25:50 +0530972 return false;
973 }
974 mutex_unlock(&hdd_ctx->iface_change_lock);
975 return true;
976}
977
978/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800979 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700980 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800981 *
982 * This function sets the IBSS power save config parameters to WMA
983 * which will send it to firmware if FW supports IBSS power save
984 * before vdev start.
985 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530986 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800987 * on failure.
988 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700989QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800990{
991 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700992 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800993
994 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700995 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530996 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800997 }
998
Jeff Johnson1b780e42017-10-31 14:11:45 -0700999 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001000 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
1001 hdd_ctx->config->ibssATIMWinSize,
1002 VDEV_CMD);
1003 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001004 hdd_err("atim window set failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301005 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001006 }
1007
Jeff Johnson1b780e42017-10-31 14:11:45 -07001008 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001009 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
1010 hdd_ctx->config->isIbssPowerSaveAllowed,
1011 VDEV_CMD);
1012 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001013 hdd_err("power save allow failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001014 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301015 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001016 }
1017
Jeff Johnson1b780e42017-10-31 14:11:45 -07001018 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001019 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
1020 hdd_ctx->config->
1021 isIbssPowerCollapseAllowed, VDEV_CMD);
1022 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001023 hdd_err("power collapse allow failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001024 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301025 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001026 }
1027
Jeff Johnson1b780e42017-10-31 14:11:45 -07001028 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001029 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
1030 hdd_ctx->config->isIbssAwakeOnTxRx,
1031 VDEV_CMD);
1032 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001033 hdd_err("set awake on tx/rx failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301034 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001035 }
1036
Jeff Johnson1b780e42017-10-31 14:11:45 -07001037 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001038 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
1039 hdd_ctx->config->ibssInactivityCount,
1040 VDEV_CMD);
1041 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001042 hdd_err("set inactivity time failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301043 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001044 }
1045
Jeff Johnson1b780e42017-10-31 14:11:45 -07001046 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001047 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
1048 hdd_ctx->config->ibssTxSpEndInactivityTime,
1049 VDEV_CMD);
1050 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001051 hdd_err("set txsp end failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001052 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301053 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001054 }
1055
Jeff Johnson1b780e42017-10-31 14:11:45 -07001056 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001057 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
1058 hdd_ctx->config->ibssPsWarmupTime,
1059 VDEV_CMD);
1060 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001061 hdd_err("set ps warmup failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001062 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301063 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001064 }
1065
Jeff Johnson1b780e42017-10-31 14:11:45 -07001066 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001067 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
1068 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
1069 VDEV_CMD);
1070 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001071 hdd_err("set 1rx chain atim failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001072 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301073 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001074 }
1075
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301076 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001077}
1078
Yue Macd359b72017-10-03 15:21:00 -07001079#ifdef FEATURE_RUNTIME_PM
1080/**
1081 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
1082 * @hdd_ctx: HDD context
1083 *
1084 * Return: None
1085 */
1086static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
1087{
1088 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1089
Yue Macd359b72017-10-03 15:21:00 -07001090 qdf_runtime_lock_init(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001091 qdf_runtime_lock_init(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001092
1093 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
1094}
1095
1096/**
1097 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1098 * @hdd_ctx: HDD Context
1099 *
1100 * Return: None
1101 */
1102static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1103{
1104 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1105
Yue Macd359b72017-10-03 15:21:00 -07001106 qdf_runtime_lock_deinit(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001107 qdf_runtime_lock_deinit(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001108
1109 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
1110}
1111
Yue Macd359b72017-10-03 15:21:00 -07001112#else /* FEATURE_RUNTIME_PM */
1113static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1114static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Yue Macd359b72017-10-03 15:21:00 -07001115#endif /* FEATURE_RUNTIME_PM */
1116
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001117#define INTF_MACADDR_MASK 0x7
1118
1119/**
1120 * hdd_update_macaddr() - update mac address
1121 * @config: hdd configuration
1122 * @hw_macaddr: mac address
1123 *
1124 * Mac address for multiple virtual interface is found as following
1125 * i) The mac address of the first interface is just the actual hw mac address.
1126 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
1127 * define the mac address for the remaining interfaces and locally
1128 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1129 * supported virtual interfaces, right now this is 0x07 (meaning 8
1130 * interface).
1131 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1132 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1133 *
1134 * Return: None
1135 */
1136void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301137 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001138{
1139 int8_t i;
1140 uint8_t macaddr_b3, tmp_br3;
1141
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301142 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301143 QDF_MAC_ADDR_SIZE);
1144 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301145 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301146 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001147 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1148 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1149 INTF_MACADDR_MASK;
1150 macaddr_b3 += tmp_br3;
1151
1152 /* XOR-ing bit-24 of the mac address. This will give enough
1153 * mac address range before collision
1154 */
1155 macaddr_b3 ^= (1 << 7);
1156
1157 /* Set locally administered bit */
1158 config->intfMacAddr[i].bytes[0] |= 0x02;
1159 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001160 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001161 MAC_ADDRESS_STR, i,
1162 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1163 }
1164}
1165
Kabilan Kannan44a58372017-12-06 18:16:11 -08001166static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1167{
1168 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
1169 struct tdls_start_params tdls_cfg;
1170 struct tdls_user_config *config = &tdls_cfg.config;
1171 struct hdd_config *cfg = hdd_ctx->config;
1172 QDF_STATUS status;
1173
1174 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
1175 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
1176 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
1177 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
1178 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
1179 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
1180 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
1181 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
1182 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
1183 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
1184 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
1185 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
1186 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
1187 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
1188 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
1189 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
1190 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
1191 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
1192 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
1193 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
1194 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
1195 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
1196 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
1197 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
1198 (cfg->fEnableTDLSImplicitTrigger ?
1199 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
1200 (cfg->fTDLSExternalControl ?
1201 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
1202 config->tdls_vdev_nss_2g = CFG_TDLS_NSS(cfg->vdev_type_nss_2g);
1203 config->tdls_vdev_nss_5g = CFG_TDLS_NSS(cfg->vdev_type_nss_5g);
1204
1205 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
1206 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
1207 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
1208 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
1209 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1210 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1211 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1212 tdls_cfg.tdls_evt_cb_data = psoc;
Jeff Johnson1d40f5b2018-03-02 08:35:53 -08001213 tdls_cfg.tdls_peer_context = hdd_ctx;
1214 tdls_cfg.tdls_reg_peer = hdd_tdls_register_peer;
1215 tdls_cfg.tdls_dereg_peer = hdd_tdls_deregister_peer;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001216 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1217 tdls_cfg.tdls_wmm_cb_data = psoc;
1218 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1219 tdls_cfg.tdls_rx_cb_data = psoc;
1220 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1221
1222 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1223 if (status != QDF_STATUS_SUCCESS) {
1224 hdd_err("failed pmo psoc configuration");
1225 return -EINVAL;
1226 }
1227
1228 hdd_ctx->tdls_umac_comp_active = true;
1229 /* enable napier specific tdls data path */
1230 hdd_ctx->tdls_nap_active = true;
1231
1232 return 0;
1233}
1234
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001235static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001236 struct wma_tgt_services *cfg)
1237{
1238 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001239
1240 /* Set up UAPSD */
1241 config->apUapsdEnabled &= cfg->uapsd;
1242
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001243 /* 11AX mode support */
1244 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1245 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1246 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1247
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001248 /* 11AC mode support */
1249 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1250 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1251 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001252
1253 /* ARP offload: override user setting if invalid */
1254 config->fhostArpOffload &= cfg->arp_offload;
1255
1256#ifdef FEATURE_WLAN_SCAN_PNO
1257 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001258 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001259 if (cfg->pno_offload)
1260 config->PnoOffload = true;
1261#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001262#ifdef FEATURE_WLAN_TDLS
1263 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301264 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1265 cfg->en_tdls_offchan;
1266 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1267 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001268 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001269 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001270 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001271 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001272#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001273#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1274 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1275#endif
Will Huang496b36c2017-07-11 16:38:50 +08001276 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001277 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001278 hdd_update_tdls_config(hdd_ctx);
Jeff Johnson16528362018-06-14 12:34:16 -07001279 sme_update_tgt_services(hdd_ctx->mac_handle, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001280
1281}
1282
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001283/**
1284 * hdd_update_vdev_nss() - sets the vdev nss
1285 * @hdd_ctx: HDD context
1286 *
1287 * Sets the Nss per vdev type based on INI
1288 *
1289 * Return: None
1290 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001291static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001292{
1293 struct hdd_config *cfg_ini = hdd_ctx->config;
1294 uint8_t max_supp_nss = 1;
Jeff Johnson16528362018-06-14 12:34:16 -07001295 mac_handle_t mac_handle;
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001296
Naveen Rawat10b1c152017-01-18 11:16:06 -08001297 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001298 max_supp_nss = 2;
Liangwei Dong22810e82018-03-15 03:42:12 -04001299 hdd_debug("max nss %d vdev_type_nss_2g %x vdev_type_nss_5g %x",
1300 max_supp_nss, cfg_ini->vdev_type_nss_2g,
1301 cfg_ini->vdev_type_nss_5g);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001302
Jeff Johnson16528362018-06-14 12:34:16 -07001303 mac_handle = hdd_ctx->mac_handle;
1304 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
1305 cfg_ini->vdev_type_nss_2g, BAND_2G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001306
Jeff Johnson16528362018-06-14 12:34:16 -07001307 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
1308 cfg_ini->vdev_type_nss_5g, BAND_5G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001309}
1310
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301311/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301312 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1313 * @hdd_ctx: HDD context
1314 *
1315 * Updates wiphy vhtcap fields
1316 *
1317 * Return: None
1318 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001319static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301320{
1321 struct ieee80211_supported_band *band_5g =
1322 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1323 uint32_t val;
1324
1325 if (!band_5g) {
1326 hdd_debug("5GHz band disabled, skipping capability population");
1327 return;
1328 }
1329
1330 val = hdd_ctx->config->txBFCsnValue;
1331 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1332
1333 val = NUM_OF_SOUNDING_DIMENSIONS;
1334 band_5g->vht_cap.cap |=
1335 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1336
1337 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1338 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1339}
1340
1341/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301342 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1343 * @hdd_ctx: HDD context
1344 *
1345 * Sets the DBS capability as per INI and firmware capability
1346 *
1347 * Return: None
1348 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001349static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301350{
1351 struct hdd_config *cfg_ini = hdd_ctx->config;
1352 uint8_t hw_dbs_capable = 0;
1353
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001354 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1355 ((cfg_ini->dual_mac_feature_disable ==
1356 ENABLE_DBS_CXN_AND_SCAN) ||
1357 (cfg_ini->dual_mac_feature_disable ==
1358 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301359 hw_dbs_capable = 1;
1360
Jeff Johnson16528362018-06-14 12:34:16 -07001361 sme_update_hw_dbs_capable(hdd_ctx->mac_handle, hw_dbs_capable);
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301362}
1363
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001364static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001365 struct wma_tgt_ht_cap *cfg)
1366{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301367 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001368 uint32_t value, val32;
1369 uint16_t val16;
1370 struct hdd_config *pconfig = hdd_ctx->config;
1371 tSirMacHTCapabilityInfo *phtCapInfo;
1372 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1373 uint8_t enable_tx_stbc;
Jeff Johnson16528362018-06-14 12:34:16 -07001374 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001375
1376 /* check and update RX STBC */
1377 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1378 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1379
Jeff Johnson16528362018-06-14 12:34:16 -07001380 mac_handle = hdd_ctx->mac_handle;
1381
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001382 /* get the MPDU density */
Jeff Johnson16528362018-06-14 12:34:16 -07001383 status = sme_cfg_get_int(mac_handle, WNI_CFG_MPDU_DENSITY, &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001384
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301385 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001386 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001387 value = 0;
1388 }
1389
1390 /*
1391 * MPDU density:
1392 * override user's setting if value is larger
1393 * than the one supported by target
1394 */
1395 if (value > cfg->mpdu_density) {
Jeff Johnson16528362018-06-14 12:34:16 -07001396 status = sme_cfg_set_int(mac_handle, WNI_CFG_MPDU_DENSITY,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001397 cfg->mpdu_density);
1398
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301399 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001400 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001401 }
1402
1403 /* get the HT capability info */
Jeff Johnson16528362018-06-14 12:34:16 -07001404 status = sme_cfg_get_int(mac_handle, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301405 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001406 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001407 return;
1408 }
1409 val16 = (uint16_t) val32;
1410 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1411
1412 /* Set the LDPC capability */
1413 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1414
1415 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1416 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1417
1418 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1419 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1420
1421 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1422 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1423
1424 enable_tx_stbc = pconfig->enableTxSTBC;
1425
1426 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1427 pconfig->enable2x2 = 1;
1428 } else {
1429 pconfig->enable2x2 = 0;
1430 enable_tx_stbc = 0;
1431
1432 /* 1x1 */
1433 /* Update Rx Highest Long GI data Rate */
Jeff Johnson16528362018-06-14 12:34:16 -07001434 if (sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001435 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001436 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301437 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001438 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001439 }
1440
1441 /* Update Tx Highest Long GI data Rate */
1442 if (sme_cfg_set_int
Jeff Johnson16528362018-06-14 12:34:16 -07001443 (mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001444 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001445 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301446 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001447 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001448 }
1449 }
1450 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1451 enable_tx_stbc = 0;
1452 phtCapInfo->txSTBC = enable_tx_stbc;
1453
1454 val32 = val16;
Jeff Johnson16528362018-06-14 12:34:16 -07001455 status = sme_cfg_set_int(mac_handle, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301456 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001457 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001458#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1459 value = SIZE_OF_SUPPORTED_MCS_SET;
Jeff Johnson16528362018-06-14 12:34:16 -07001460 if (sme_cfg_get_str(mac_handle, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301461 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001462 hdd_debug("Read MCS rate set");
gaurank kathpalia18b49362018-04-15 23:12:03 +05301463 if (cfg->num_rf_chains > SIZE_OF_SUPPORTED_MCS_SET)
1464 cfg->num_rf_chains = SIZE_OF_SUPPORTED_MCS_SET;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001465 if (pconfig->enable2x2) {
1466 for (value = 0; value < cfg->num_rf_chains; value++)
1467 mcs_set[value] =
1468 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1469
1470 status =
Jeff Johnson16528362018-06-14 12:34:16 -07001471 sme_cfg_set_str(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001472 WNI_CFG_SUPPORTED_MCS_SET,
1473 mcs_set,
1474 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301475 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001476 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001477 }
1478 }
1479#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1480}
1481
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001482static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001483 struct wma_tgt_vht_cap *cfg)
1484{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301485 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001486 uint32_t value = 0;
1487 struct hdd_config *pconfig = hdd_ctx->config;
1488 struct wiphy *wiphy = hdd_ctx->wiphy;
1489 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001490 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001491 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001492 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001493 uint32_t hw_rx_ldpc_enabled;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001494 struct wma_caps_per_phy caps_per_phy;
Jeff Johnson16528362018-06-14 12:34:16 -07001495 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001496
Dustin Brown5e06bd32016-10-04 12:49:10 -07001497 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001498 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001499 return;
1500 }
1501
Jeff Johnson16528362018-06-14 12:34:16 -07001502 mac_handle = hdd_ctx->mac_handle;
1503
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001504 /* Get the current MPDU length */
1505 status =
Jeff Johnson16528362018-06-14 12:34:16 -07001506 sme_cfg_get_int(mac_handle, WNI_CFG_VHT_MAX_MPDU_LENGTH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001507 &value);
1508
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301509 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001510 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001511 value = 0;
1512 }
1513
1514 /*
1515 * VHT max MPDU length:
1516 * override if user configured value is too high
1517 * that the target cannot support
1518 */
1519 if (value > cfg->vht_max_mpdu) {
Jeff Johnson16528362018-06-14 12:34:16 -07001520 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001521 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1522 cfg->vht_max_mpdu);
1523
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001524 if (status == QDF_STATUS_E_FAILURE)
1525 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001526 }
1527
Jeff Johnson16528362018-06-14 12:34:16 -07001528 sme_cfg_get_int(mac_handle, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001529 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1530
1531 if (pconfig->enable2x2)
1532 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1533
Jeff Johnson16528362018-06-14 12:34:16 -07001534 if (sme_cfg_set_int(mac_handle, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001535 QDF_STATUS_E_FAILURE) {
1536 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1537 }
1538
Jeff Johnson16528362018-06-14 12:34:16 -07001539 sme_cfg_get_int(mac_handle, WNI_CFG_VHT_RX_MCS_MAP, &temp);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001540 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1541 if (pconfig->enable2x2)
1542 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1543
Jeff Johnson16528362018-06-14 12:34:16 -07001544 if (sme_cfg_set_int(mac_handle, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001545 QDF_STATUS_E_FAILURE) {
1546 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1547 }
1548
Jeff Johnson16528362018-06-14 12:34:16 -07001549 sme_cfg_get_int(mac_handle, WNI_CFG_VHT_TX_MCS_MAP, &temp);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001550 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1551 if (pconfig->enable2x2)
1552 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1553
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001554 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001555 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1556
Jeff Johnson16528362018-06-14 12:34:16 -07001557 if (sme_cfg_set_int(mac_handle, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001558 QDF_STATUS_E_FAILURE) {
1559 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1560 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001561 /* Get the current RX LDPC setting */
Jeff Johnson16528362018-06-14 12:34:16 -07001562 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_LDPC_CODING_CAP,
1563 &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 LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001567 value = 0;
1568 }
1569
jiad4a7a33c2017-08-08 15:32:24 +08001570 /* Set HW RX LDPC capability */
1571 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1572 if (hw_rx_ldpc_enabled != value) {
Jeff Johnson16528362018-06-14 12:34:16 -07001573 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001574 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001575 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001576
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001577 if (status == QDF_STATUS_E_FAILURE)
1578 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001579 }
1580
1581 /* Get current GI 80 value */
Jeff Johnson16528362018-06-14 12:34:16 -07001582 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_SHORT_GI_80MHZ,
1583 &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001584
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301585 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001586 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001587 value = 0;
1588 }
1589
1590 /* set the Guard interval 80MHz */
1591 if (value && !cfg->vht_short_gi_80) {
Jeff Johnson16528362018-06-14 12:34:16 -07001592 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001593 WNI_CFG_VHT_SHORT_GI_80MHZ,
1594 cfg->vht_short_gi_80);
1595
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001596 if (status == QDF_STATUS_E_FAILURE)
1597 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001598 }
1599
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001600 /* Get VHT TX STBC cap */
Jeff Johnson16528362018-06-14 12:34:16 -07001601 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_TXSTBC, &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001602
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301603 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001604 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001605 value = 0;
1606 }
1607
1608 /* VHT TX STBC cap */
1609 if (value && !cfg->vht_tx_stbc) {
Jeff Johnson16528362018-06-14 12:34:16 -07001610 status = sme_cfg_set_int(mac_handle, WNI_CFG_VHT_TXSTBC,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001611 cfg->vht_tx_stbc);
1612
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001613 if (status == QDF_STATUS_E_FAILURE)
1614 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001615 }
1616
1617 /* Get VHT RX STBC cap */
Jeff Johnson16528362018-06-14 12:34:16 -07001618 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_RXSTBC, &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001619
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301620 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001621 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001622 value = 0;
1623 }
1624
1625 /* VHT RX STBC cap */
1626 if (value && !cfg->vht_rx_stbc) {
Jeff Johnson16528362018-06-14 12:34:16 -07001627 status = sme_cfg_set_int(mac_handle, WNI_CFG_VHT_RXSTBC,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001628 cfg->vht_rx_stbc);
1629
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001630 if (status == QDF_STATUS_E_FAILURE)
1631 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001632 }
1633
1634 /* Get VHT SU Beamformer cap */
Jeff Johnson16528362018-06-14 12:34:16 -07001635 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001636 &value);
1637
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301638 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001639 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001640 value = 0;
1641 }
1642
1643 /* set VHT SU Beamformer cap */
1644 if (value && !cfg->vht_su_bformer) {
Jeff Johnson16528362018-06-14 12:34:16 -07001645 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001646 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1647 cfg->vht_su_bformer);
1648
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001649 if (status == QDF_STATUS_E_FAILURE)
1650 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001651 }
1652
1653 /* check and update SU BEAMFORMEE capabality */
1654 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1655 pconfig->enableTxBF = cfg->vht_su_bformee;
1656
Jeff Johnson16528362018-06-14 12:34:16 -07001657 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001658 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1659 pconfig->enableTxBF);
1660
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001661 if (status == QDF_STATUS_E_FAILURE)
1662 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001663
1664 /* Get VHT MU Beamformer cap */
Jeff Johnson16528362018-06-14 12:34:16 -07001665 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
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 MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001670 value = 0;
1671 }
1672
1673 /* set VHT MU Beamformer cap */
1674 if (value && !cfg->vht_mu_bformer) {
Jeff Johnson16528362018-06-14 12:34:16 -07001675 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001676 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1677 cfg->vht_mu_bformer);
1678
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001679 if (status == QDF_STATUS_E_FAILURE)
1680 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001681 }
1682
1683 /* Get VHT MU Beamformee cap */
Jeff Johnson16528362018-06-14 12:34:16 -07001684 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001685 &value);
1686
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301687 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001688 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001689 value = 0;
1690 }
1691
1692 /* set VHT MU Beamformee cap */
1693 if (value && !cfg->vht_mu_bformee) {
Jeff Johnson16528362018-06-14 12:34:16 -07001694 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001695 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1696 cfg->vht_mu_bformee);
1697
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001698 if (status == QDF_STATUS_E_FAILURE)
1699 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001700 }
1701
1702 /* Get VHT MAX AMPDU Len exp */
Jeff Johnson16528362018-06-14 12:34:16 -07001703 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001704 &value);
1705
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301706 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001707 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001708 value = 0;
1709 }
1710
1711 /*
1712 * VHT max AMPDU len exp:
1713 * override if user configured value is too high
1714 * that the target cannot support.
1715 * Even though Rome publish ampdu_len=7, it can
1716 * only support 4 because of some h/w bug.
1717 */
1718
1719 if (value > cfg->vht_max_ampdu_len_exp) {
Jeff Johnson16528362018-06-14 12:34:16 -07001720 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001721 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1722 cfg->vht_max_ampdu_len_exp);
1723
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001724 if (status == QDF_STATUS_E_FAILURE)
1725 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001726 }
1727
1728 /* Get VHT TXOP PS CAP */
Jeff Johnson16528362018-06-14 12:34:16 -07001729 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_TXOP_PS, &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001730
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301731 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001732 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001733 value = 0;
1734 }
1735
1736 /* set VHT TXOP PS cap */
1737 if (value && !cfg->vht_txop_ps) {
Jeff Johnson16528362018-06-14 12:34:16 -07001738 status = sme_cfg_set_int(mac_handle, WNI_CFG_VHT_TXOP_PS,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001739 cfg->vht_txop_ps);
1740
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001741 if (status == QDF_STATUS_E_FAILURE)
1742 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001743 }
1744
1745 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1746 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1747 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1748 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1749 else
1750 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1751
1752
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001753 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
Jeff Johnson16528362018-06-14 12:34:16 -07001754 status = sme_cfg_set_int(mac_handle,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001755 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1756 VHT_CAP_160_AND_80P80_SUPP);
1757 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001758 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001759 band_5g->vht_cap.cap |=
1760 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001761 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1762 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
Jeff Johnson16528362018-06-14 12:34:16 -07001763 status = sme_cfg_set_int(mac_handle,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001764 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1765 VHT_CAP_160_SUPP);
1766 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001767 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001768 band_5g->vht_cap.cap |=
1769 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001770 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1771 }
1772 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1773 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301774 /* Get the current GI 160 value */
Jeff Johnson16528362018-06-14 12:34:16 -07001775 status = sme_cfg_get_int(mac_handle,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301776 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001777 &value);
1778 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301779 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001780 value = 0;
1781 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301782 /* set the Guard interval 160MHz */
1783 if (value && !cfg->vht_short_gi_160) {
Jeff Johnson16528362018-06-14 12:34:16 -07001784 status = sme_cfg_set_int(mac_handle,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301785 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1786 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001787
1788 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301789 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001790 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001791
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001792 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001793 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001794 hdd_debug("VHT RxLDPC capability is set");
1795 } else {
1796 /*
1797 * Get the RX LDPC capability for the NON DBS
1798 * hardware mode for 5G band
1799 */
1800 status = wma_get_caps_for_phyidx_hwmode(&caps_per_phy,
1801 HW_MODE_DBS_NONE, CDS_BAND_5GHZ);
1802 if ((QDF_IS_STATUS_SUCCESS(status)) &&
1803 (caps_per_phy.vht_5g & WMI_VHT_CAP_RX_LDPC)) {
1804 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1805 hdd_debug("VHT RX LDPC capability is set");
1806 }
1807 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001808
1809 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1810 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1811 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1812 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1813
1814 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1815 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1816
1817 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1818 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1819 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1820 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1821 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1822 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1823
1824 band_5g->vht_cap.cap |=
1825 (cfg->vht_max_ampdu_len_exp <<
1826 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1827
1828 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1829 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1830 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1831 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1832 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1833 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1834 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1835 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1836
1837 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1838 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1839
1840}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001841
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001842/**
1843 * hdd_generate_macaddr_auto() - Auto-generate mac address
1844 * @hdd_ctx: Pointer to the HDD context
1845 *
1846 * Auto-generate mac address using device serial number.
1847 * Keep the first 3 bytes of OUI as before and replace
1848 * the last 3 bytes with the lower 3 bytes of serial number.
1849 *
1850 * Return: 0 for success
1851 * Non zero failure code for errors
1852 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001853static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001854{
1855 unsigned int serialno = 0;
1856 struct qdf_mac_addr mac_addr = {
1857 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1858 };
1859
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001860 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001861 if (serialno == 0)
1862 return -EINVAL;
1863
1864 serialno &= 0x00ffffff;
1865
1866 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1867 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1868 mac_addr.bytes[5] = serialno & 0xff;
1869
1870 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1871 return 0;
1872}
1873
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05301874#ifdef FEATURE_WLAN_APF
1875/**
1876 * hdd_update_apf_support() - Update APF supported flag in hdd context
1877 * @hdd_ctx: Pointer to hdd_ctx
1878 * @cfg: target configuration
1879 *
1880 * Update the APF support flag in HDD Context using INI and target config.
1881 *
1882 * Return: None
1883 */
1884static void hdd_update_apf_support(struct hdd_context *hdd_ctx,
1885 struct wma_tgt_cfg *cfg)
1886{
1887 hdd_ctx->apf_supported = (cfg->apf_enabled &&
1888 hdd_ctx->config->apf_packet_filter_enable);
1889}
1890#else
1891static void hdd_update_apf_support(struct hdd_context *hdd_ctx,
1892 struct wma_tgt_cfg *cfg)
1893{
1894}
1895#endif
1896
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301897/**
1898 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1899 * configuration to cfg_ini in HDD
1900 * @hdd_ctx: Pointer to hdd_ctx
1901 * @cfg: target configuration
1902 *
1903 * Return: None
1904 */
1905#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001906static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301907 struct wma_tgt_cfg *cfg)
1908{
1909 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1910}
1911#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001912static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301913 struct wma_tgt_cfg *cfg)
1914{
1915}
1916#endif
1917
Jeff Johnson8abc5932018-06-02 22:51:37 -07001918void hdd_update_tgt_cfg(hdd_handle_t hdd_handle, struct wma_tgt_cfg *cfg)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001919{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001920 int ret;
Jeff Johnsonea70b942018-07-02 09:42:31 -07001921 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001922 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001923 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301924 uint8_t antenna_mode;
Arif Hussainee10f902017-12-27 16:30:17 -08001925 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -07001926 mac_handle_t mac_handle;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301927
gaurank kathpalia843f7c32018-07-02 18:04:14 +05301928 if (!hdd_ctx) {
1929 hdd_err("HDD context is NULL");
1930 return;
1931 }
Dustin Brownbd68fe12017-11-21 15:28:52 -08001932 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1933 if (ret) {
1934 hdd_err("Failed to create pdev; errno:%d", ret);
1935 QDF_BUG(0);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001936 } else {
Dustin Brownbd68fe12017-11-21 15:28:52 -08001937 hdd_debug("New pdev has been created with pdev_id = %u",
Arif Hussainee10f902017-12-27 16:30:17 -08001938 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Amar Singhal410675c2018-01-10 12:14:21 -08001939 if (dispatcher_pdev_open(hdd_ctx->hdd_pdev)) {
1940 hdd_err("dispatcher pdev open failed");
1941 QDF_BUG(0);
1942 }
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301943 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001944
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301945 cdp_pdev_set_ctrl_pdev(cds_get_context(QDF_MODULE_ID_SOC),
1946 cds_get_context(QDF_MODULE_ID_TXRX),
1947 (struct cdp_ctrl_objmgr_pdev *)hdd_ctx->hdd_pdev);
1948
1949 wlan_pdev_set_dp_handle(hdd_ctx->hdd_pdev,
1950 cds_get_context(QDF_MODULE_ID_TXRX));
1951
Will Huang07244172018-05-14 14:23:30 +08001952 hdd_objmgr_update_tgt_max_vdev_psoc(hdd_ctx, cfg->max_intf_count);
1953
Jeff Johnsone8846ab2018-03-31 11:54:45 -07001954 ret = hdd_green_ap_update_config(hdd_ctx);
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301955
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301956 ucfg_ipa_set_dp_handle(hdd_ctx->hdd_psoc,
1957 cds_get_context(QDF_MODULE_ID_SOC));
1958 ucfg_ipa_set_txrx_handle(hdd_ctx->hdd_psoc,
1959 cds_get_context(QDF_MODULE_ID_TXRX));
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301960 ucfg_ipa_reg_sap_xmit_cb(hdd_ctx->hdd_pdev,
1961 hdd_softap_hard_start_xmit);
1962 ucfg_ipa_reg_send_to_nw_cb(hdd_ctx->hdd_pdev,
1963 hdd_ipa_send_skb_to_network);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301964
Naveen Rawat64e477e2016-05-20 10:34:56 -07001965 if (cds_cfg) {
1966 if (hdd_ctx->config->enable_sub_20_channel_width !=
1967 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1968 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1969 cds_cfg->sub_20_channel_width =
1970 WLAN_SUB_20_CH_WIDTH_NONE;
1971 } else {
1972 cds_cfg->sub_20_channel_width =
1973 hdd_ctx->config->enable_sub_20_channel_width;
1974 }
1975 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001976
1977 /* first store the INI band capability */
1978 temp_band_cap = hdd_ctx->config->nBandCapability;
1979
1980 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301981 hdd_ctx->is_fils_roaming_supported =
1982 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001983
Vignesh Viswanathan694e28e2018-01-18 20:53:57 +05301984 hdd_ctx->config->is_11k_offload_supported =
1985 cfg->services.is_11k_offload_supported;
1986
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001987 /*
1988 * now overwrite the target band capability with INI
1989 * setting if INI setting is a subset
1990 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001991
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001992 if ((hdd_ctx->config->nBandCapability == BAND_ALL) &&
1993 (temp_band_cap != BAND_ALL))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001994 hdd_ctx->config->nBandCapability = temp_band_cap;
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001995 else if ((hdd_ctx->config->nBandCapability != BAND_ALL) &&
1996 (temp_band_cap != BAND_ALL) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001997 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001998 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001999 }
2000
Amar Singhal58b45ef2017-08-01 13:43:54 -07002001 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
2002
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05302003 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002004 hdd_ctx->reg.reg_domain = cfg->reg_domain;
2005 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
2006 }
2007
2008 /* This can be extended to other configurations like ht, vht cap... */
2009
Anurag Chouhanc5548422016-02-24 18:33:27 +05302010 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002011 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07002012 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002013 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07002014 static struct qdf_mac_addr default_mac_addr = {
2015 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
2016 };
2017 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
2018 &default_mac_addr)) {
2019 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
2020 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
2021 MAC_ADDRESS_STR,
2022 MAC_ADDR_ARRAY(hdd_ctx->config->
2023 intfMacAddr[0].bytes));
2024 } else {
2025 hdd_err("Invalid MAC passed from target, using MAC from ini file "
2026 MAC_ADDRESS_STR,
2027 MAC_ADDR_ARRAY(hdd_ctx->config->
2028 intfMacAddr[0].bytes));
2029 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07002030 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002031 }
2032
2033 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07002034 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002035
Ryan Hsuc6918552018-05-16 13:29:59 -07002036 hdd_ctx->hw_bd_id = cfg->hw_bd_id;
2037 qdf_mem_copy(&hdd_ctx->hw_bd_info, &cfg->hw_bd_info,
2038 sizeof(cfg->hw_bd_info));
2039
Dustin Brownbee82832018-07-23 10:10:51 -07002040 if (cfg->max_intf_count > CSR_ROAM_SESSION_MAX) {
2041 hdd_err("fw max vdevs (%u) > host max vdevs (%u); using %u",
2042 cfg->max_intf_count, CSR_ROAM_SESSION_MAX,
2043 CSR_ROAM_SESSION_MAX);
2044 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
2045 } else {
2046 hdd_ctx->max_intf_count = cfg->max_intf_count;
2047 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002048
Jeff Johnsonc875e242016-09-23 18:12:34 -07002049 hdd_lpass_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08002050
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002051 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
2052 hdd_update_tgt_services(hdd_ctx, &cfg->services);
2053
2054 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
2055
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002056 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07002057 if (cfg->services.en_11ax) {
2058 hdd_info("11AX: 11ax is enabled - update HDD config");
2059 hdd_update_tgt_he_cap(hdd_ctx, cfg);
2060 }
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -07002061 hdd_update_tgt_twt_cap(hdd_ctx, cfg);
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07002062
2063 hdd_update_vdev_nss(hdd_ctx);
2064
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05302065 hdd_update_hw_dbs_capable(hdd_ctx);
2066
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08002067 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07002068 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002069 hdd_debug("fine_time_meas_cap: 0x%x",
Arif Hussainee10f902017-12-27 16:30:17 -08002070 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08002071
Nitesh Shahe50711f2017-04-26 16:30:45 +05302072 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
2073 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
2074 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002075 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08002076 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08002077
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05302078 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05302079 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05302080
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302081 if ((hdd_ctx->config->txBFCsnValue >
Arif Hussainee10f902017-12-27 16:30:17 -08002082 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
2083 !cfg->tx_bfee_8ss_enabled)
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302084 hdd_ctx->config->txBFCsnValue =
2085 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
2086
Jeff Johnson16528362018-06-14 12:34:16 -07002087 mac_handle = hdd_ctx->mac_handle;
2088 status = sme_cfg_set_int(mac_handle,
Arif Hussainee10f902017-12-27 16:30:17 -08002089 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
2090 hdd_ctx->config->txBFCsnValue);
2091 if (QDF_IS_STATUS_ERROR(status))
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302092 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
2093
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05302094 hdd_update_apf_support(hdd_ctx, cfg);
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302095
Nachiket Kukadee547a482018-05-22 16:43:30 +05302096 hdd_debug("Target APF %d Host APF %d 8ss fw support %d txBFCsnValue %d",
2097 cfg->apf_enabled, hdd_ctx->config->apf_packet_filter_enable,
Arif Hussainee10f902017-12-27 16:30:17 -08002098 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05302099
2100 /*
2101 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
2102 */
2103 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05302104
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05302105 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
2106
Yue Macd359b72017-10-03 15:21:00 -07002107 /*
2108 * This needs to be done after HDD pdev is created and stored since
2109 * it will access the HDD pdev object lock.
2110 */
2111 hdd_runtime_suspend_context_init(hdd_ctx);
2112
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07002113 /* Configure NAN datapath features */
2114 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07002115 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08002116 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Liangwei Dong0da14262018-07-03 03:30:23 -04002117 hdd_ctx->obss_scan_offload = cfg->services.obss_scan_offload;
Jeff Johnson16528362018-06-14 12:34:16 -07002118 status = sme_cfg_set_int(mac_handle, WNI_CFG_OBSS_DETECTION_OFFLOAD,
Arif Hussainee10f902017-12-27 16:30:17 -08002119 cfg->obss_detection_offloaded);
2120 if (QDF_IS_STATUS_ERROR(status))
2121 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Arif Hussain05fb4872018-01-03 16:02:55 -08002122
Jeff Johnson16528362018-06-14 12:34:16 -07002123 status = sme_cfg_set_int(mac_handle,
Arif Hussain05fb4872018-01-03 16:02:55 -08002124 WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD,
2125 cfg->obss_color_collision_offloaded);
2126 if (QDF_IS_STATUS_ERROR(status))
2127 hdd_err("Failed to set WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002128}
2129
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002130bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002131{
Jeff Johnson9d295242017-08-29 14:39:48 -07002132 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002133 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002134
Jiachao Wuf610d912018-01-23 17:47:32 +08002135 if (!hdd_ctx) {
2136 hdd_info("Couldn't get hdd_ctx");
2137 return true;
2138 }
2139
2140 if (hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002141 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08002142 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302143 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002144 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002145
Dustin Brown920397d2017-12-13 16:27:50 -08002146 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002147 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2148
2149 if ((QDF_SAP_MODE == adapter->device_mode ||
2150 QDF_P2P_GO_MODE == adapter->device_mode) &&
bings0e03a982018-05-09 08:40:59 +08002151 (wlan_reg_is_passive_or_disable_ch(hdd_ctx->hdd_pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002152 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002153 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2154 true;
2155 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07002156 adapter->session_id);
bings6fb9bf62018-07-05 14:01:53 +08002157 if (adapter->txrx_vdev)
2158 cdp_fc_vdev_flush(
2159 cds_get_context(QDF_MODULE_ID_SOC),
bings0e03a982018-05-09 08:40:59 +08002160 adapter->txrx_vdev);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302161 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002162 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302163
2164 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002165}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002166
2167/**
2168 * hdd_is_valid_mac_address() - validate MAC address
2169 * @pMacAddr: Pointer to the input MAC address
2170 *
2171 * This function validates whether the given MAC address is valid or not
2172 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
2173 * where X is the hexa decimal digit character and separated by ':'
2174 * This algorithm works even if MAC address is not separated by ':'
2175 *
2176 * This code checks given input string mac contains exactly 12 hexadecimal
2177 * digits and a separator colon : appears in the input string only after
2178 * an even number of hex digits.
2179 *
2180 * Return: 1 for valid and 0 for invalid
2181 */
2182bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
2183{
2184 int xdigit = 0;
2185 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002186
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002187 while (*pMacAddr) {
2188 if (isxdigit(*pMacAddr)) {
2189 xdigit++;
2190 } else if (':' == *pMacAddr) {
2191 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2192 break;
2193
2194 ++separator;
2195 } else {
2196 /* Invalid MAC found */
2197 return 0;
2198 }
2199 ++pMacAddr;
2200 }
2201 return xdigit == 12 && (separator == 5 || separator == 0);
2202}
2203
2204/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302205 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2206 * @dev: Handle to struct net_device to be updated.
2207 *
2208 * Return: None
2209 */
2210static void hdd_mon_mode_ether_setup(struct net_device *dev)
2211{
2212 dev->header_ops = NULL;
2213 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2214 dev->hard_header_len = ETH_HLEN;
2215 dev->mtu = ETH_DATA_LEN;
2216 dev->addr_len = ETH_ALEN;
2217 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2218 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2219 dev->priv_flags |= IFF_TX_SKB_SHARING;
2220
2221 memset(dev->broadcast, 0xFF, ETH_ALEN);
2222}
2223
Nirav Shah73713f72018-05-17 14:50:41 +05302224#ifdef FEATURE_MONITOR_MODE_SUPPORT
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302225/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002226 * __hdd__mon_open() - HDD Open function
2227 * @dev: Pointer to net_device structure
2228 *
2229 * This is called in response to ifconfig up
2230 *
2231 * Return: 0 for success; non-zero for failure
2232 */
2233static int __hdd_mon_open(struct net_device *dev)
2234{
2235 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002236 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2237 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002238
Dustin Brownfdf17c12018-03-14 12:55:34 -07002239 hdd_enter_dev(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002240
2241 ret = wlan_hdd_validate_context(hdd_ctx);
2242 if (ret)
2243 return ret;
2244
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302245 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002246
2247 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Browne7e71d32018-05-11 16:00:08 -07002248 ret = hdd_wlan_start_modules(hdd_ctx, false);
Ravi Joshia307f632017-07-17 23:41:41 -07002249 if (ret) {
2250 hdd_err("Failed to start WLAN modules return");
2251 return ret;
2252 }
2253 hdd_err("hdd_wlan_start_modules() successful !");
2254
2255 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2256 ret = hdd_start_adapter(adapter);
2257 if (ret) {
2258 hdd_err("Failed to start adapter :%d",
2259 adapter->device_mode);
2260 return ret;
2261 }
2262 hdd_err("hdd_start_adapters() successful !");
2263 }
2264 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2265 }
2266
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002267 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002268
2269 if (!ret)
2270 ret = hdd_enable_monitor_mode(dev);
2271
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002272 return ret;
2273}
2274
2275/**
2276 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2277 * @dev: Pointer to net_device structure
2278 *
2279 * This is called in response to ifconfig up
2280 *
2281 * Return: 0 for success; non-zero for failure
2282 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002283static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002284{
2285 int ret;
2286
2287 cds_ssr_protect(__func__);
2288 ret = __hdd_mon_open(dev);
2289 cds_ssr_unprotect(__func__);
2290
2291 return ret;
2292}
Nirav Shah73713f72018-05-17 14:50:41 +05302293#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002294
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002295static QDF_STATUS
2296wlan_hdd_update_dbs_scan_and_fw_mode_config(void)
2297{
2298 struct policy_mgr_dual_mac_config cfg = {0};
2299 QDF_STATUS status;
2300 uint32_t channel_select_logic_conc;
2301 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2302
2303 if (!hdd_ctx) {
2304 hdd_err("HDD context is NULL");
2305 return QDF_STATUS_E_FAILURE;
2306 }
2307
2308
2309 if (!policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc))
2310 return QDF_STATUS_SUCCESS;
2311
2312 cfg.scan_config = 0;
2313 cfg.fw_mode_config = 0;
2314 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
2315
2316 channel_select_logic_conc = hdd_ctx->config->
2317 channel_select_logic_conc;
2318
2319 if (hdd_ctx->config->dual_mac_feature_disable !=
2320 DISABLE_DBS_CXN_AND_SCAN) {
2321 status = policy_mgr_get_updated_scan_and_fw_mode_config(
2322 hdd_ctx->hdd_psoc, &cfg.scan_config,
2323 &cfg.fw_mode_config,
2324 hdd_ctx->config->dual_mac_feature_disable,
2325 channel_select_logic_conc);
2326
2327 if (status != QDF_STATUS_SUCCESS) {
2328 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
2329 status);
2330 return status;
2331 }
2332 }
2333
2334 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
2335 cfg.scan_config, cfg.fw_mode_config);
2336
2337 status = sme_soc_set_dual_mac_config(cfg);
2338 if (status != QDF_STATUS_SUCCESS) {
2339 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
2340 return status;
2341 }
2342
2343 return QDF_STATUS_SUCCESS;
2344}
2345
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002346/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302347 * hdd_start_adapter() - Wrapper function for device specific adapter
2348 * @adapter: pointer to HDD adapter
2349 *
2350 * This function is called to start the device specific adapter for
2351 * the mode passed in the adapter's device_mode.
2352 *
2353 * Return: 0 for success; non-zero for failure
2354 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002355int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302356{
2357
2358 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002359 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302360
Dustin Brownfdf17c12018-03-14 12:55:34 -07002361 hdd_enter_dev(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002362 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302363
2364 switch (device_mode) {
2365 case QDF_P2P_CLIENT_MODE:
2366 case QDF_P2P_DEVICE_MODE:
2367 case QDF_OCB_MODE:
2368 case QDF_STA_MODE:
2369 case QDF_MONITOR_MODE:
2370 ret = hdd_start_station_adapter(adapter);
2371 if (ret)
2372 goto err_start_adapter;
2373 break;
2374 case QDF_P2P_GO_MODE:
2375 case QDF_SAP_MODE:
2376 ret = hdd_start_ap_adapter(adapter);
2377 if (ret)
2378 goto err_start_adapter;
2379 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302380 case QDF_IBSS_MODE:
2381 /*
2382 * For IBSS interface is initialized as part of
2383 * hdd_init_station_mode()
2384 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002385 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302386 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002387 /* vdevs are dynamically managed by firmware in FTM */
2388 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302389 default:
2390 hdd_err("Invalid session type %d", device_mode);
2391 QDF_ASSERT(0);
2392 goto err_start_adapter;
2393 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002394
Arun Khandavallifae92942016-08-01 13:31:08 +05302395 if (hdd_set_fw_params(adapter))
2396 hdd_err("Failed to set the FW params for the adapter!");
2397
Dustin Browne7e71d32018-05-11 16:00:08 -07002398 if (adapter->session_id != HDD_SESSION_ID_INVALID) {
2399 ret = wlan_hdd_cfg80211_register_frames(adapter);
2400 if (ret < 0) {
2401 hdd_err("Failed to register frames - ret %d", ret);
2402 goto err_start_adapter;
2403 }
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302404 }
Dustin Browne7e71d32018-05-11 16:00:08 -07002405
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002406 wlan_hdd_update_dbs_scan_and_fw_mode_config();
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302407
Dustin Browndb2a8be2017-12-20 11:49:56 -08002408exit_with_success:
Dustin Browne74003f2018-03-14 12:51:58 -07002409 hdd_exit();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002410
Arun Khandavallifae92942016-08-01 13:31:08 +05302411 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002412
Arun Khandavallifae92942016-08-01 13:31:08 +05302413err_start_adapter:
2414 return -EINVAL;
2415}
2416
2417/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302418 * hdd_enable_power_management() - API to Enable Power Management
2419 *
2420 * API invokes Bus Interface Layer power management functionality
2421 *
2422 * Return: None
2423 */
2424static void hdd_enable_power_management(void)
2425{
2426 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2427
2428 if (!hif_ctx) {
2429 hdd_err("Bus Interface Context is Invalid");
2430 return;
2431 }
2432
2433 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2434}
2435
2436/**
2437 * hdd_disable_power_management() - API to disable Power Management
2438 *
2439 * API disable Bus Interface Layer Power management functionality
2440 *
2441 * Return: None
2442 */
2443static void hdd_disable_power_management(void)
2444{
2445 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2446
2447 if (!hif_ctx) {
2448 hdd_err("Bus Interface Context is Invalid");
2449 return;
2450 }
2451
2452 hif_disable_power_management(hif_ctx);
2453}
2454
Ryan Hsuaadba072018-04-20 13:01:53 -07002455void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302456{
2457 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002458 size_t target_hw_name_len;
2459 const char *target_hw_name;
Ryan Hsuaadba072018-04-20 13:01:53 -07002460 uint8_t *buf;
2461 uint32_t buf_len;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302462
2463 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2464 if (!hif_sc) {
2465 hdd_err("HIF context is NULL");
2466 return;
2467 }
2468
Ryan Hsuaadba072018-04-20 13:01:53 -07002469 hif_get_hw_info(hif_sc, &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302470 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002471 &target_hw_name);
2472
2473 if (hdd_ctx->target_hw_name)
2474 qdf_mem_free(hdd_ctx->target_hw_name);
2475
2476 target_hw_name_len = strlen(target_hw_name) + 1;
2477 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2478 if (hdd_ctx->target_hw_name)
2479 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2480 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302481
Ryan Hsuaadba072018-04-20 13:01:53 -07002482 buf = qdf_mem_malloc(WE_MAX_STR_LEN);
2483 if (buf) {
2484 buf_len = hdd_wlan_get_version(hdd_ctx, WE_MAX_STR_LEN, buf);
2485 hdd_info("%s", buf);
2486 qdf_mem_free(buf);
2487 }
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302488}
2489
2490/**
gbian62edd7e2017-03-07 13:12:13 +08002491 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2492 * @hdd_ctx: Pointer to hdd context
2493 *
2494 * Return: none
2495 */
2496static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002497hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002498{
2499 uint8_t num_entries = 0;
2500 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2501 uint8_t *tx_sched_wrr_ac;
2502 int i;
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002503 struct cds_context *cds_ctx;
gbian62edd7e2017-03-07 13:12:13 +08002504
2505 if (NULL == hdd_ctx)
2506 return;
2507
2508 if (NULL == hdd_ctx->config) {
2509 /* Do nothing if hdd_ctx is invalid */
2510 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2511 return;
2512 }
2513
2514 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2515
2516 if (!cds_ctx) {
2517 hdd_err("Invalid CDS Context");
2518 return;
2519 }
2520
2521 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2522 switch (i) {
2523 case OL_TX_WMM_AC_BE:
2524 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2525 break;
2526 case OL_TX_WMM_AC_BK:
2527 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2528 break;
2529 case OL_TX_WMM_AC_VI:
2530 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2531 break;
2532 case OL_TX_WMM_AC_VO:
2533 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2534 break;
2535 default:
2536 tx_sched_wrr_ac = NULL;
2537 break;
2538 }
2539
2540 hdd_string_to_u8_array(tx_sched_wrr_ac,
2541 tx_sched_wrr_param,
2542 &num_entries,
2543 sizeof(tx_sched_wrr_param));
2544
2545 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2546 cds_ctx->ac_specs[i].wrr_skip_weight =
2547 tx_sched_wrr_param[0];
2548 cds_ctx->ac_specs[i].credit_threshold =
2549 tx_sched_wrr_param[1];
2550 cds_ctx->ac_specs[i].send_limit =
2551 tx_sched_wrr_param[2];
2552 cds_ctx->ac_specs[i].credit_reserve =
2553 tx_sched_wrr_param[3];
2554 cds_ctx->ac_specs[i].discard_weight =
2555 tx_sched_wrr_param[4];
2556 }
2557
2558 num_entries = 0;
2559 }
2560}
2561
Ryan Hsuaadba072018-04-20 13:01:53 -07002562uint32_t hdd_wlan_get_version(struct hdd_context *hdd_ctx,
2563 const size_t version_len, uint8_t *version)
2564{
2565 uint32_t size;
2566 uint32_t msp_id = 0, mspid = 0, siid = 0, crmid = 0, sub_id = 0;
2567
2568 if (!hdd_ctx) {
2569 hdd_err("Invalid context, HDD context is null");
2570 return 0;
2571 }
2572
Ashish Kumar Dhanotiya7353f882018-05-15 12:50:19 +05302573 if (!version || version_len == 0) {
Ryan Hsuaadba072018-04-20 13:01:53 -07002574 hdd_err("Invalid buffer pointr or buffer len\n");
2575 return 0;
2576 }
2577
2578 msp_id = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
2579 mspid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
2580 siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
2581 crmid = hdd_ctx->target_fw_version & 0x7fff;
2582 sub_id = (hdd_ctx->target_fw_vers_ext & 0xf0000000) >> 28;
2583
2584 size = scnprintf(version, version_len,
Ryan Hsuc6918552018-05-16 13:29:59 -07002585 "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 -07002586 QWLAN_VERSIONSTR,
2587 msp_id, mspid, siid, crmid, sub_id,
Ryan Hsuc6918552018-05-16 13:29:59 -07002588 hdd_ctx->target_hw_name,
2589 hdd_ctx->hw_bd_info.bdf_version,
2590 hdd_ctx->hw_bd_info.ref_design_id,
2591 hdd_ctx->hw_bd_info.customer_id,
2592 hdd_ctx->hw_bd_info.project_id,
2593 hdd_ctx->hw_bd_info.board_data_rev);
Ryan Hsuaadba072018-04-20 13:01:53 -07002594
2595 return size;
2596}
2597
Rachit Kankane0dc3e852018-05-07 17:33:42 +05302598int hdd_set_11ax_rate(struct hdd_adapter *adapter, int set_value,
2599 struct sap_config *sap_config)
2600{
2601 uint8_t preamble = 0, nss = 0, rix = 0;
2602 int ret;
2603 mac_handle_t mac_handle = adapter->hdd_ctx->mac_handle;
2604
2605 if (!sap_config) {
2606 if (!sme_is_feature_supported_by_fw(DOT11AX)) {
2607 hdd_err("Target does not support 11ax");
2608 return -EIO;
2609 }
2610 } else if (sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax &&
2611 sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax_ONLY) {
2612 hdd_err("Invalid hw mode, SAP hw_mode= 0x%x, ch = %d",
2613 sap_config->SapHw_mode, sap_config->channel);
2614 return -EIO;
2615 }
2616
2617 if (set_value != 0xff) {
2618 rix = RC_2_RATE_IDX_11AX(set_value);
2619 preamble = WMI_RATE_PREAMBLE_HE;
2620 nss = HT_RC_2_STREAMS_11AX(set_value);
2621
2622 set_value = hdd_assemble_rate_code(preamble, nss, rix);
2623 } else {
2624 ret = sme_set_auto_rate_he_ltf(mac_handle, adapter->session_id,
2625 QCA_WLAN_HE_LTF_AUTO);
2626 }
2627
2628 hdd_info("SET_11AX_RATE val %d rix %d preamble %x nss %d",
2629 set_value, rix, preamble, nss);
2630
2631 ret = wma_cli_set_command(adapter->session_id,
2632 WMI_VDEV_PARAM_FIXED_RATE,
2633 set_value, VDEV_CMD);
2634
2635 return ret;
2636}
2637
2638int hdd_assemble_rate_code(uint8_t preamble, uint8_t nss, uint8_t rate)
2639{
2640 int set_value;
2641
2642 if (sme_is_feature_supported_by_fw(DOT11AX))
2643 set_value = WMI_ASSEMBLE_RATECODE_V1(rate, nss, preamble);
2644 else
2645 set_value = (preamble << 6) | (nss << 4) | rate;
2646
2647 return set_value;
2648}
2649
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302650#ifdef IPA_OFFLOAD
2651/**
2652 * hdd_update_ipa_component_config() - update ipa config
2653 * @hdd_ctx: Pointer to hdd context
2654 *
2655 * Return: none
2656 */
2657static void hdd_update_ipa_component_config(struct hdd_context *hdd_ctx)
2658{
2659 struct hdd_config *cfg = hdd_ctx->config;
2660 struct wlan_ipa_config ipa_cfg;
2661
2662 ipa_cfg.ipa_config = cfg->IpaConfig;
2663 ipa_cfg.desc_size = cfg->IpaDescSize;
2664 ipa_cfg.txbuf_count = cfg->IpaUcTxBufCount;
2665 ipa_cfg.bus_bw_high = cfg->busBandwidthHighThreshold;
2666 ipa_cfg.bus_bw_medium = cfg->busBandwidthMediumThreshold;
2667 ipa_cfg.bus_bw_low = cfg->busBandwidthLowThreshold;
2668 ipa_cfg.ipa_bw_high = cfg->IpaHighBandwidthMbps;
2669 ipa_cfg.ipa_bw_medium = cfg->IpaMediumBandwidthMbps;
2670 ipa_cfg.ipa_bw_low = cfg->IpaLowBandwidthMbps;
2671
2672 ucfg_ipa_update_config(&ipa_cfg);
2673}
2674#else
2675static void hdd_update_ipa_component_config(struct hdd_context *hdd_ctx)
2676{
2677}
2678#endif
2679
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002680#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002681static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2682 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2683{
Jeff Johnson9d295242017-08-29 14:39:48 -07002684 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002685 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002686
2687 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2688 if (!adapter) {
2689 hdd_err("Adapter is NULL");
2690 return PM_MAX_NUM_OF_MODE;
2691 }
2692
2693 return policy_mgr_convert_device_mode_to_qdf_type(
2694 adapter->device_mode);
2695}
2696
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002697static void hdd_register_policy_manager_callback(
2698 struct wlan_objmgr_psoc *psoc)
2699{
2700 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002701
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002702 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002703 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002704 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2705 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002706 hdd_cbacks.get_mode_for_non_connected_vdev =
2707 wlan_hdd_get_mode_for_non_connected_vdev;
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05302708 hdd_cbacks.hdd_get_device_mode = hdd_get_device_mode;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002709
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002710 if (QDF_STATUS_SUCCESS !=
2711 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2712 hdd_err("HDD callback registration with policy manager failed");
2713 }
2714}
2715#else
2716static void hdd_register_policy_manager_callback(
2717 struct wlan_objmgr_psoc *psoc)
2718{
2719}
2720#endif
2721
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002722static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002723{
2724 struct nan_callbacks cb_obj = {0};
2725
2726 cb_obj.ndi_open = hdd_ndi_open;
2727 cb_obj.ndi_close = hdd_ndi_close;
2728 cb_obj.ndi_start = hdd_ndi_start;
2729 cb_obj.ndi_delete = hdd_ndi_delete;
2730 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2731 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2732
Naveen Rawat37f62c82017-03-26 22:24:43 -07002733 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2734 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002735 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002736
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002737 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2738}
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002739
Dustin Brown26b3d042017-12-21 11:13:27 -08002740#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002741/**
2742 * hdd_check_for_leaks() - Perform runtime memory leak checks
Dustin Browna6246dd2018-05-24 14:35:58 -07002743 * @hdd_ctx: the global HDD context
Dustin Brown4c5b9902017-12-19 11:17:19 -08002744 *
2745 * This API triggers runtime memory leak detection. This feature enforces the
2746 * policy that any memory allocated at runtime must also be released at runtime.
2747 *
2748 * Allocating memory at runtime and releasing it at unload is effectively a
2749 * memory leak for configurations which never unload (e.g. LONU, statically
2750 * compiled driver). Such memory leaks are NOT false positives, and must be
2751 * fixed.
2752 *
2753 * Return: None
2754 */
Dustin Browna6246dd2018-05-24 14:35:58 -07002755static void hdd_check_for_leaks(struct hdd_context *hdd_ctx)
Dustin Brown4bc0a622017-12-06 15:56:50 -08002756{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002757 /* DO NOT REMOVE these checks; for false positives, read above first */
2758
Dustin Browna6246dd2018-05-24 14:35:58 -07002759 wlan_objmgr_psoc_check_for_vdev_leaks(hdd_ctx->hdd_psoc);
Dustin Brown29462962018-06-18 14:02:00 -07002760 wlan_objmgr_psoc_check_for_pdev_leaks(hdd_ctx->hdd_psoc);
Dustin Brown677e0862017-10-10 16:30:09 -07002761 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002762 qdf_nbuf_map_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002763 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002764}
2765
Dustin Brown26b3d042017-12-21 11:13:27 -08002766#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2767#else
Dustin Browna6246dd2018-05-24 14:35:58 -07002768static inline void hdd_check_for_leaks(struct hdd_context *hdd_ctx) { }
Dustin Brown26b3d042017-12-21 11:13:27 -08002769
2770#define hdd_debug_domain_set(domain)
2771#endif /* CONFIG_LEAK_DETECTION */
2772
gbian62edd7e2017-03-07 13:12:13 +08002773/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002774 * hdd_update_country_code - Update country code
2775 * @hdd_ctx: HDD context
2776 *
2777 * Update country code based on module parameter country_code
2778 *
2779 * Return: 0 on success and errno on failure
2780 */
2781static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2782{
2783 if (!country_code)
2784 return 0;
2785
2786 return hdd_reg_set_country(hdd_ctx, country_code);
2787}
2788
2789/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302790 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2791 * @hdd_ctx: HDD context
Arun Khandavallifae92942016-08-01 13:31:08 +05302792 * @reinit: flag to indicate from SSR or normal path
2793 *
2794 * This function maintains the driver state machine it will be invoked from
2795 * startup, reinit and change interface. Depending on the driver state shall
2796 * perform the opening of the modules.
2797 *
2798 * Return: 0 for success; non-zero for failure
2799 */
Dustin Browne7e71d32018-05-11 16:00:08 -07002800int hdd_wlan_start_modules(struct hdd_context *hdd_ctx, bool reinit)
Arun Khandavallifae92942016-08-01 13:31:08 +05302801{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002802 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302803 qdf_device_t qdf_dev;
2804 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302805 bool unint = false;
2806 void *hif_ctx;
Jingxiang Ge95912f82018-04-19 12:01:26 +08002807 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +05302808
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002809 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302810
2811 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2812 if (!qdf_dev) {
2813 hdd_err("QDF Device Context is Invalid return");
2814 return -EINVAL;
2815 }
2816
Dustin Brown6f427922017-09-19 12:19:00 -07002817 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05302818
Dustin Brown1fe30a82017-10-03 16:13:36 -07002819 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302820 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2821 mutex_unlock(&hdd_ctx->iface_change_lock);
2822 hdd_info("Driver modules already Enabled");
Dustin Browne74003f2018-03-14 12:51:58 -07002823 hdd_exit();
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302824 return 0;
2825 }
2826
Dustin Brown1fe30a82017-10-03 16:13:36 -07002827 hdd_ctx->start_modules_in_progress = true;
2828
Arun Khandavallifae92942016-08-01 13:31:08 +05302829 switch (hdd_ctx->driver_status) {
2830 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002831 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302832 unint = true;
2833 /* Fall through dont add break here */
2834 case DRIVER_MODULES_CLOSED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002835 hdd_info("Wlan transitioning (CLOSED -> OPENED)");
2836
Dustin Brown26b3d042017-12-21 11:13:27 -08002837 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002838
Arun Khandavallifae92942016-08-01 13:31:08 +05302839 if (!reinit && !unint) {
2840 ret = pld_power_on(qdf_dev->dev);
2841 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002842 hdd_err("Failed to Powerup the device; errno: %d",
2843 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302844 goto release_lock;
2845 }
2846 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002847
2848 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2849 hdd_ctx->config->enable_fw_log);
Arun Khandavallifae92942016-08-01 13:31:08 +05302850 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2851 qdf_dev->bus_type,
2852 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2853 HIF_ENABLE_TYPE_PROBE);
2854 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002855 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302856 goto power_down;
2857 }
2858
2859 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302860 if (!hif_ctx) {
2861 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002862 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302863 goto power_down;
2864 }
2865
Arun Khandavallifae92942016-08-01 13:31:08 +05302866 status = ol_cds_init(qdf_dev, hif_ctx);
2867 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002868 hdd_err("No Memory to Create BMI Context; status: %d",
2869 status);
2870 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302871 goto hif_close;
2872 }
2873
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302874 hdd_update_ipa_component_config(hdd_ctx);
2875
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002876 ret = hdd_update_config(hdd_ctx);
2877 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002878 hdd_err("Failed to update configuration; errno: %d",
2879 ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002880 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002881 }
2882
gbian62edd7e2017-03-07 13:12:13 +08002883 hdd_update_cds_ac_specs_params(hdd_ctx);
2884
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302885 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002886 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002887 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002888 ret = qdf_status_to_os_return(status);
2889 goto deinit_config;
Arun Khandavallifae92942016-08-01 13:31:08 +05302890 }
2891
Manjunathappa Prakashb6b4ff12018-06-04 12:32:33 -07002892 if (hdd_ctx->config->rx_thread_affinity_mask)
2893 cds_set_rx_thread_cpu_mask(
2894 hdd_ctx->config->rx_thread_affinity_mask);
2895
2896 /* initialize components configurations after psoc open */
Mukul Sharma9d797a02017-01-05 20:26:03 +05302897 ret = hdd_update_components_config(hdd_ctx);
2898 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002899 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302900 ret);
2901 goto close;
2902 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002903 status = cds_dp_open(hdd_ctx->hdd_psoc);
2904 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002905 hdd_err("Failed to Open cds post open; status: %d",
2906 status);
2907 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002908 goto close;
2909 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302910
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002911 /*
2912 * NAN compoenet requires certian operations like, open adapter,
2913 * close adapter, etc. to be initiated by HDD, for those
2914 * register HDD callbacks with UMAC's NAN componenet.
2915 */
2916 hdd_nan_register_callbacks(hdd_ctx);
2917
Jeff Johnson16528362018-06-14 12:34:16 -07002918 hdd_ctx->mac_handle = cds_get_context(QDF_MODULE_ID_SME);
Arun Khandavallifae92942016-08-01 13:31:08 +05302919
Jeff Johnson3a280122017-09-13 07:42:00 -07002920 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302921 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002922 hdd_err("Failed to pre-enable CDS; status: %d", status);
2923 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002924 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302925 }
2926
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002927 hdd_register_policy_manager_callback(
2928 hdd_ctx->hdd_psoc);
2929
Amar Singhal0928b192017-12-01 10:50:54 -08002930 hdd_sysfs_create_version_interface(hdd_ctx->hdd_psoc);
2931
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302932 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302933 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002934 hdd_info("Wlan transitioned (now OPENED)");
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302935
Arun Khandavallifae92942016-08-01 13:31:08 +05302936 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002937 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302938 break;
2939 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302940
Arun Khandavallifae92942016-08-01 13:31:08 +05302941 /* Fall through dont add break here */
2942 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002943 hdd_info("Wlan transitioning (OPENED -> ENABLED)");
2944
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302945 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2946 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002947 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302948 break;
2949 }
Dustin Browndca39692017-11-09 15:30:25 -08002950
Dustin Browne7e71d32018-05-11 16:00:08 -07002951 ret = hdd_configure_cds(hdd_ctx);
Dustin Browndca39692017-11-09 15:30:25 -08002952 if (ret) {
2953 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002954 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302955 }
Dustin Browndca39692017-11-09 15:30:25 -08002956
Komal Seelamf2136bb2016-09-28 18:30:44 +05302957 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002958
Arun Khandavallifae92942016-08-01 13:31:08 +05302959 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002960 hdd_info("Wlan transitioned (now ENABLED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302961 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002962
Arun Khandavallifae92942016-08-01 13:31:08 +05302963 default:
2964 hdd_err("WLAN start invoked in wrong state! :%d\n",
2965 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002966 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302967 goto release_lock;
2968 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002969
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302970 hdd_ctx->start_modules_in_progress = false;
Paul Zhange03cf4c2018-01-19 18:33:22 +08002971 if (DRIVER_MODULES_ENABLED == hdd_ctx->driver_status) {
2972 ret = hdd_update_country_code(hdd_ctx);
2973 if (ret)
2974 hdd_err("Failed to update command line country code!");
2975 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302976 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002977
Dustin Browne74003f2018-03-14 12:51:58 -07002978 hdd_exit();
Dustin Brown550f6d22017-12-14 15:44:01 -08002979
Arun Khandavallifae92942016-08-01 13:31:08 +05302980 return 0;
2981
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002982post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002983 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002984
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002985cds_txrx_free:
Jingxiang Ge95912f82018-04-19 12:01:26 +08002986 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
2987
2988 if (tgt_hdl && target_psoc_get_wmi_ready(tgt_hdl)) {
2989 hdd_runtime_suspend_context_deinit(hdd_ctx);
2990 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
2991 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
2992 }
2993
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002994 cds_dp_close(hdd_ctx->hdd_psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08002995
Arun Khandavallifae92942016-08-01 13:31:08 +05302996close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002997 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002998 hdd_info("Wlan transition aborted (now CLOSED)");
2999
Jeff Johnsone4b14592017-09-13 14:23:33 -07003000 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05303001
Dustin Brown28b17892017-10-10 13:29:38 -07003002deinit_config:
3003 cds_deinit_ini_config();
3004
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07003005cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05303006 ol_cds_free();
3007
3008hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07003009 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
3010 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05303011power_down:
3012 if (!reinit && !unint)
3013 pld_power_off(qdf_dev->dev);
3014release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05303015 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05303016 mutex_unlock(&hdd_ctx->iface_change_lock);
Abhinav Kumar7ae9b7b2017-12-19 15:11:54 +05303017 if (hdd_ctx->target_hw_name) {
3018 qdf_mem_free(hdd_ctx->target_hw_name);
3019 hdd_ctx->target_hw_name = NULL;
3020 }
Dustin Brown4bc0a622017-12-06 15:56:50 -08003021 /* many adapter resources are not freed by design in SSR case */
3022 if (!reinit)
Dustin Browna6246dd2018-05-24 14:35:58 -07003023 hdd_check_for_leaks(hdd_ctx);
Dustin Brown26b3d042017-12-21 11:13:27 -08003024 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08003025
Dustin Browne74003f2018-03-14 12:51:58 -07003026 hdd_exit();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08003027
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07003028 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05303029}
3030
Naveen Rawat910726a2017-03-06 11:42:51 -08003031#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003032static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003033{
3034 int ret = os_if_wifi_pos_register_nl();
3035
3036 if (ret)
3037 hdd_err("os_if_wifi_pos_register_nl failed");
3038
3039 return ret;
3040}
3041
3042static int hdd_deactivate_wifi_pos(void)
3043{
3044 int ret = os_if_wifi_pos_deregister_nl();
3045
3046 if (ret)
3047 hdd_err("os_if_wifi_pos_deregister_nl failed");
3048
3049 return ret;
3050}
3051
3052/**
3053 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
3054 * @hdd_ctx: hdd context
3055 *
3056 * Return: status of operation
3057 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003058static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003059{
3060 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3061 struct hdd_config *cfg = hdd_ctx->config;
3062
3063 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
3064 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
3065 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
3066 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
3067 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
3068 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
3069 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
3070 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
3071}
3072#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003073static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003074{
3075 return oem_activate_service(hdd_ctx);
3076}
3077
3078static int hdd_deactivate_wifi_pos(void)
3079{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05303080 return oem_deactivate_service();
Naveen Rawat910726a2017-03-06 11:42:51 -08003081}
3082
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003083static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003084{
3085}
3086#endif
3087
Arun Khandavallifae92942016-08-01 13:31:08 +05303088/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003089 * __hdd_open() - HDD Open function
3090 * @dev: Pointer to net_device structure
3091 *
3092 * This is called in response to ifconfig up
3093 *
3094 * Return: 0 for success; non-zero for failure
3095 */
3096static int __hdd_open(struct net_device *dev)
3097{
Jeff Johnson9d295242017-08-29 14:39:48 -07003098 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003099 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003100 int ret;
3101
Dustin Brownfdf17c12018-03-14 12:55:34 -07003102 hdd_enter_dev(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303103 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003104 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003105
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05303106 /* Nothing to be done if device is unloading */
3107 if (cds_is_driver_unloading()) {
3108 hdd_err("Driver is unloading can not open the hdd");
3109 return -EBUSY;
3110 }
3111
Dustin Brown01847752017-10-25 13:56:27 -07003112 if (cds_is_driver_recovering()) {
3113 hdd_err("WLAN is currently recovering; Please try again.");
3114 return -EBUSY;
3115 }
3116
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05303117 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
3118 hdd_err("con_mode_handler is in progress; Please try again.");
3119 return -EBUSY;
3120 }
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303121
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05303122 mutex_lock(&hdd_init_deinit_lock);
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05303123 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
3124
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303125 /*
3126 * This scenario can be hit in cases where in the wlan driver after
3127 * registering the netdevices and there is a failure in driver
3128 * initialization. So return error gracefully because the netdevices
3129 * will be de-registered as part of the load failure.
3130 */
3131
3132 if (!cds_is_driver_loaded()) {
3133 hdd_err("Failed to start the wlan driver!!");
3134 ret = -EIO;
3135 goto err_hdd_hdd_init_deinit_lock;
3136 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303137
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003138
Dustin Browne7e71d32018-05-11 16:00:08 -07003139 ret = hdd_wlan_start_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05303140 if (ret) {
3141 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303142 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05303143 }
3144
3145
3146 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3147 ret = hdd_start_adapter(adapter);
3148 if (ret) {
3149 hdd_err("Failed to start adapter :%d",
3150 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303151 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05303152 }
3153 }
3154
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003155 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3156 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003157 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003158 /* Enable TX queues only when we are connected */
3159 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05303160 WLAN_START_ALL_NETIF_QUEUE,
3161 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003162 }
3163
Naveen Rawat286def52016-09-23 15:38:02 -07003164 /* Enable carrier and transmit queues for NDI */
3165 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003166 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07003167 wlan_hdd_netif_queue_control(adapter,
3168 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
3169 WLAN_CONTROL_PATH);
3170 }
3171
Naveen Rawat910726a2017-03-06 11:42:51 -08003172 hdd_populate_wifi_pos_cfg(hdd_ctx);
3173
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303174err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05303175 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303176 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003177 return ret;
3178}
3179
Arun Khandavallifae92942016-08-01 13:31:08 +05303180
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003181/**
3182 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
3183 * @dev: Pointer to net_device structure
3184 *
3185 * This is called in response to ifconfig up
3186 *
3187 * Return: 0 for success; non-zero for failure
3188 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003189static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003190{
3191 int ret;
3192
3193 cds_ssr_protect(__func__);
3194 ret = __hdd_open(dev);
3195 cds_ssr_unprotect(__func__);
3196
3197 return ret;
3198}
3199
3200/**
3201 * __hdd_stop() - HDD stop function
3202 * @dev: Pointer to net_device structure
3203 *
3204 * This is called in response to ifconfig down
3205 *
3206 * Return: 0 for success; non-zero for failure
3207 */
3208static int __hdd_stop(struct net_device *dev)
3209{
Jeff Johnson9d295242017-08-29 14:39:48 -07003210 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003211 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003212 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -07003213 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003214
Dustin Brownfdf17c12018-03-14 12:55:34 -07003215 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003216
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303217 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003218 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003219
3220 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303221 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003222 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003223
3224 /* Nothing to be done if the interface is not opened */
3225 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003226 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003227 return -ENODEV;
3228 }
3229
3230 /* Make sure the interface is marked as closed */
3231 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303232
Jeff Johnson16528362018-06-14 12:34:16 -07003233 mac_handle = hdd_ctx->mac_handle;
3234
Mukul Sharmad16c2022017-07-25 18:56:12 +05303235 hdd_debug("Disabling Auto Power save timer");
3236 sme_ps_disable_auto_ps_timer(
Jeff Johnson16528362018-06-14 12:34:16 -07003237 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003238 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303239
3240 /*
3241 * Disable TX on the interface, after this hard_start_xmit() will not
3242 * be called on that interface
3243 */
Dustin Brown5e89ef82018-03-14 11:50:23 -07003244 hdd_info("Disabling queues, adapter device mode: %s(%d)",
Kabilan Kannan8dac3502017-10-30 12:40:27 -07003245 hdd_device_mode_to_string(adapter->device_mode),
3246 adapter->device_mode);
3247
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303248 wlan_hdd_netif_queue_control(adapter,
3249 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3250 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003251
3252 /*
Naveen Rawat286def52016-09-23 15:38:02 -07003253 * NAN data interface is different in some sense. The traffic on NDI is
3254 * bursty in nature and depends on the need to transfer. The service
3255 * layer may down the interface after the usage and up again when
3256 * required. In some sense, the NDI is expected to be available
3257 * (like SAP) iface until NDI delete request is issued by the service
3258 * layer. Skip BSS termination and adapter deletion for NAN Data
3259 * interface (NDI).
3260 */
3261 if (WLAN_HDD_IS_NDI(adapter))
3262 return 0;
3263
3264 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003265 * The interface is marked as down for outside world (aka kernel)
3266 * But the driver is pretty much alive inside. The driver needs to
3267 * tear down the existing connection on the netdev (session)
3268 * cleanup the data pipes and wait until the control plane is stabilized
3269 * for this interface. The call also needs to wait until the above
3270 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003271 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003272 * That is intentional to be able to scan if it is a STA/P2P interface
3273 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08003274 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003275
3276 /* DeInit the adapter. This ensures datapath cleanup as well */
3277 hdd_deinit_adapter(hdd_ctx, adapter, true);
3278
Arun Khandavallifae92942016-08-01 13:31:08 +05303279
3280 /*
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +05303281 * Upon wifi turn off, DUT has to flush the scan results so if
3282 * this is the last cli iface, flush the scan database.
3283 */
3284 if (!hdd_is_cli_iface_up(hdd_ctx))
Jeff Johnson16528362018-06-14 12:34:16 -07003285 sme_scan_flush_result(mac_handle);
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +05303286
3287 /*
Arun Khandavallifae92942016-08-01 13:31:08 +05303288 * Find if any iface is up. If any iface is up then can't put device to
3289 * sleep/power save mode
3290 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05303291 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003292 hdd_debug("Closing all modules from the hdd_stop");
Dustin Brown6f427922017-09-19 12:19:00 -07003293 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
3294 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05303295 hdd_prevent_suspend_timeout(
3296 hdd_ctx->config->iface_change_wait_time,
3297 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05303298 }
3299
Dustin Browne74003f2018-03-14 12:51:58 -07003300 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003301 return 0;
3302}
3303
3304/**
3305 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3306 * @dev: pointer to net_device structure
3307 *
3308 * This is called in response to ifconfig down
3309 *
3310 * Return: 0 for success and error number for failure
3311 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003312static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003313{
3314 int ret;
3315
3316 cds_ssr_protect(__func__);
3317 ret = __hdd_stop(dev);
3318 cds_ssr_unprotect(__func__);
3319
3320 return ret;
3321}
3322
3323/**
3324 * __hdd_uninit() - HDD uninit function
3325 * @dev: Pointer to net_device structure
3326 *
3327 * This is called during the netdev unregister to uninitialize all data
3328 * associated with the device
3329 *
3330 * Return: None
3331 */
3332static void __hdd_uninit(struct net_device *dev)
3333{
Jeff Johnson9d295242017-08-29 14:39:48 -07003334 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003335 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003336
Dustin Brownfdf17c12018-03-14 12:55:34 -07003337 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003338
3339 do {
3340 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003341 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003342 break;
3343 }
3344
Jeff Johnson399c6272017-08-30 10:51:00 -07003345 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3346 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003347 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003348 break;
3349 }
3350
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003351 if (dev != adapter->dev)
3352 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003353
Jeff Johnson399c6272017-08-30 10:51:00 -07003354 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003355
3356 /* after uninit our adapter structure will no longer be valid */
3357 adapter->dev = NULL;
3358 adapter->magic = 0;
3359 } while (0);
3360
Dustin Browne74003f2018-03-14 12:51:58 -07003361 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003362}
3363
3364/**
3365 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
3366 * @dev: pointer to net_device structure
3367 *
3368 * This is called during the netdev unregister to uninitialize all data
3369 * associated with the device
3370 *
3371 * Return: none
3372 */
3373static void hdd_uninit(struct net_device *dev)
3374{
3375 cds_ssr_protect(__func__);
3376 __hdd_uninit(dev);
3377 cds_ssr_unprotect(__func__);
3378}
3379
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003380static int hdd_open_cesium_nl_sock(void)
3381{
3382#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3383 struct netlink_kernel_cfg cfg = {
3384 .groups = WLAN_NLINK_MCAST_GRP_ID,
3385 .input = NULL
3386 };
3387#endif
3388 int ret = 0;
3389
3390#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3391 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3392#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3393 THIS_MODULE,
3394#endif
3395 &cfg);
3396#else
3397 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3398 WLAN_NLINK_MCAST_GRP_ID,
3399 NULL, NULL, THIS_MODULE);
3400#endif
3401
3402 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003403 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003404 ret = -ECONNREFUSED;
3405 }
3406
3407 return ret;
3408}
3409
3410static void hdd_close_cesium_nl_sock(void)
3411{
3412 if (NULL != cesium_nl_srv_sock) {
3413 netlink_kernel_release(cesium_nl_srv_sock);
3414 cesium_nl_srv_sock = NULL;
3415 }
3416}
3417
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003418/**
3419 * __hdd_set_mac_address() - set the user specified mac address
3420 * @dev: Pointer to the net device.
3421 * @addr: Pointer to the sockaddr.
3422 *
3423 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003424 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003425 *
3426 * Return: 0 for success, non zero for failure
3427 */
3428static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3429{
Jeff Johnson9d295242017-08-29 14:39:48 -07003430 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303431 struct hdd_adapter *adapter_temp;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003432 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003433 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303434 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003435 int ret;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303436 struct qdf_mac_addr mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003437
Dustin Brownfdf17c12018-03-14 12:55:34 -07003438 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003439
Hanumanth Reddy Pothula5c7a7812018-03-09 12:55:32 +05303440 if (netif_running(dev)) {
3441 hdd_err("On iface up, set mac address change isn't supported");
3442 return -EBUSY;
3443 }
3444
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003445 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3446 ret = wlan_hdd_validate_context(hdd_ctx);
3447 if (0 != ret)
3448 return ret;
3449
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303450 qdf_mem_copy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303451 adapter_temp = hdd_get_adapter_by_macaddr(hdd_ctx, mac_addr.bytes);
3452 if (adapter_temp) {
3453 if (!qdf_str_cmp(adapter_temp->dev->name, dev->name))
3454 return 0;
3455 hdd_err("%s adapter exist with same address " MAC_ADDRESS_STR,
3456 adapter_temp->dev->name,
Ashish Kumar Dhanotiyaf974f332018-04-19 16:03:15 +05303457 MAC_ADDR_ARRAY(mac_addr.bytes));
3458 return -EINVAL;
3459 }
3460
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303461 if (qdf_is_macaddr_zero(&mac_addr)) {
3462 hdd_err("MAC is all zero");
3463 return -EINVAL;
3464 }
3465
3466 if (qdf_is_macaddr_broadcast(&mac_addr)) {
3467 hdd_err("MAC is Broadcast");
3468 return -EINVAL;
3469 }
3470
3471 if (ETHER_IS_MULTICAST(psta_mac_addr->sa_data)) {
3472 hdd_err("MAC is Multicast");
3473 return -EINVAL;
3474 }
Ashish Kumar Dhanotiya8bfef122018-04-18 16:48:27 +05303475 hdd_info("Changing MAC to " MAC_ADDRESS_STR " of the interface %s ",
3476 MAC_ADDR_ARRAY(mac_addr.bytes), dev->name);
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303477
Jeff Johnson1e851a12017-10-28 14:36:12 -07003478 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003479 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3480
Dustin Browne74003f2018-03-14 12:51:58 -07003481 hdd_exit();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303482 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003483}
3484
3485/**
3486 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3487 * function from SSR
3488 * @dev: pointer to net_device structure
3489 * @addr: Pointer to the sockaddr
3490 *
3491 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003492 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003493 *
3494 * Return: 0 for success.
3495 */
3496static int hdd_set_mac_address(struct net_device *dev, void *addr)
3497{
3498 int ret;
3499
3500 cds_ssr_protect(__func__);
3501 ret = __hdd_set_mac_address(dev, addr);
3502 cds_ssr_unprotect(__func__);
3503
3504 return ret;
3505}
3506
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003507uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003508{
3509 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003510
Anurag Chouhan6d760662016-02-20 16:05:43 +05303511 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003512 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
3513 break;
3514 }
3515
Anurag Chouhan6d760662016-02-20 16:05:43 +05303516 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003517 return NULL;
3518
3519 hdd_ctx->config->intfAddrMask |= (1 << i);
3520 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
3521}
3522
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003523void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3524 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003525{
3526 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003527
Anurag Chouhan6d760662016-02-20 16:05:43 +05303528 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003529 if (!memcmp(releaseAddr,
3530 &hdd_ctx->config->intfMacAddr[i].bytes[0],
3531 6)) {
3532 hdd_ctx->config->intfAddrMask &= ~(1 << i);
3533 break;
3534 }
3535 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003536}
3537
3538#ifdef WLAN_FEATURE_PACKET_FILTERING
3539/**
3540 * __hdd_set_multicast_list() - set the multicast address list
3541 * @dev: Pointer to the WLAN device.
3542 * @skb: Pointer to OS packet (sk_buff).
3543 *
3544 * This funciton sets the multicast address list.
3545 *
3546 * Return: None
3547 */
3548static void __hdd_set_multicast_list(struct net_device *dev)
3549{
Jeff Johnson9d295242017-08-29 14:39:48 -07003550 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Dustin Brown0f874482018-06-13 14:39:22 -07003551 int i = 0, errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003552 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003553 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303554 struct pmo_mc_addr_list_params *mc_list_request = NULL;
3555 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3556 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003557
Dustin Brownfdf17c12018-03-14 12:55:34 -07003558 hdd_enter_dev(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303559 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303560 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303561
Dustin Brown0f874482018-06-13 14:39:22 -07003562 errno = wlan_hdd_validate_context(hdd_ctx);
3563 if (errno)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303564 goto out;
3565
Dustin Brown0f874482018-06-13 14:39:22 -07003566 errno = hdd_validate_adapter(adapter);
3567 if (errno)
Dustin Brownc788acb2017-08-01 17:43:51 -07003568 goto out;
3569
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303570 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3571 hdd_err("%s: Driver module is closed", __func__);
Dustin Brown0f874482018-06-13 14:39:22 -07003572 goto out;
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303573 }
3574
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303575 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
3576 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003577 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303578 goto out;
3579 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003580
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303581 /* Delete already configured multicast address list */
3582 if (adapter->mc_addr_list.mc_cnt > 0) {
Dustin Brown0f874482018-06-13 14:39:22 -07003583 hdd_debug("clear previously configured MC address list");
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303584 hdd_disable_and_flush_mc_addr_list(adapter,
3585 pmo_mc_list_change_notify);
3586 }
3587
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003588 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003589 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303590 hdd_disable_and_flush_mc_addr_list(adapter,
3591 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003592 } else {
3593 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303594 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003595 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Dustin Brown0f874482018-06-13 14:39:22 -07003596 pmo_ucfg_max_mc_addr_supported(psoc));
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303597 hdd_disable_and_flush_mc_addr_list(adapter,
3598 pmo_mc_list_change_notify);
Dustin Brown0f874482018-06-13 14:39:22 -07003599 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003600 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003601 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003602 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303603 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003604 if (i == mc_count)
3605 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303606 memset(&(mc_list_request->mc_addr[i].bytes),
3607 0, ETH_ALEN);
3608 memcpy(&(mc_list_request->mc_addr[i].bytes),
3609 ha->addr, ETH_ALEN);
Dustin Brown0f874482018-06-13 14:39:22 -07003610 hdd_debug("mlist[%d] = %pM", i,
3611 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003612 i++;
3613 }
3614 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303615
3616 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003617 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303618 mc_list_request->count = mc_count;
Dustin Brown0f874482018-06-13 14:39:22 -07003619
3620 errno = hdd_cache_mc_addr_list(mc_list_request);
3621 if (errno) {
3622 hdd_err("Failed to cache MC address list for vdev %u; errno:%d",
3623 adapter->session_id, errno);
3624 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003625 }
Dustin Brown0f874482018-06-13 14:39:22 -07003626
3627 hdd_enable_mc_addr_filtering(adapter, pmo_mc_list_change_notify);
3628
3629free_req:
3630 qdf_mem_free(mc_list_request);
3631
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303632out:
Dustin Browne74003f2018-03-14 12:51:58 -07003633 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003634}
3635
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303636
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003637/**
3638 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3639 * @dev: pointer to net_device
3640 *
3641 * Return: none
3642 */
3643static void hdd_set_multicast_list(struct net_device *dev)
3644{
3645 cds_ssr_protect(__func__);
3646 __hdd_set_multicast_list(dev);
3647 cds_ssr_unprotect(__func__);
3648}
3649#endif
3650
3651/**
3652 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3653 * @dev: Pointer to the WLAN device.
3654 * @skb: Pointer to OS packet (sk_buff).
3655 *
3656 * This function is registered with the Linux OS for network
3657 * core to decide which queue to use first.
3658 *
3659 * Return: ac, Queue Index/access category corresponding to UP in IP header
3660 */
3661static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3662#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3663 , void *accel_priv
3664#endif
3665#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3666 , select_queue_fallback_t fallback
3667#endif
3668)
3669{
3670 return hdd_wmm_select_queue(dev, skb);
3671}
3672
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003673static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003674 .ndo_open = hdd_open,
3675 .ndo_stop = hdd_stop,
3676 .ndo_uninit = hdd_uninit,
3677 .ndo_start_xmit = hdd_hard_start_xmit,
3678 .ndo_tx_timeout = hdd_tx_timeout,
3679 .ndo_get_stats = hdd_get_stats,
3680 .ndo_do_ioctl = hdd_ioctl,
3681 .ndo_set_mac_address = hdd_set_mac_address,
3682 .ndo_select_queue = hdd_select_queue,
3683#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003684 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003685#endif
3686};
3687
Nirav Shah73713f72018-05-17 14:50:41 +05303688#ifdef FEATURE_MONITOR_MODE_SUPPORT
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003689/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003690static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003691 .ndo_open = hdd_mon_open,
3692 .ndo_stop = hdd_stop,
3693 .ndo_get_stats = hdd_get_stats,
3694};
3695
3696/**
3697 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003698 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003699 * Return: None
3700 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003701void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003702{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003703 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003704 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003705 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003706 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003707}
Nirav Shah73713f72018-05-17 14:50:41 +05303708#else
3709void hdd_set_station_ops(struct net_device *dev)
3710{
3711 dev->netdev_ops = &wlan_drv_ops;
3712}
3713#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003714
3715/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003716 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3717 * @hdd_ctx: global hdd context
3718 * @macAddr: mac address to assign to the interface
3719 * @name: User-visible name of the interface
3720 *
3721 * hdd adapter pointer would point to the netdev->priv space, this function
Jeff Johnson62018292018-05-06 16:18:35 -07003722 * would retrieve the pointer, and setup the hdd adapter configuration.
Ryan Hsu07495ea2016-01-21 15:25:39 -08003723 *
3724 * Return: the pointer to hdd adapter, otherwise NULL
3725 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003726static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003727 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003728 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003729 const char *name)
3730{
Jeff Johnson5505db82017-11-02 21:19:23 -07003731 struct net_device *dev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003732 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003733 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303734 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003735 /*
3736 * cfg80211 initialization and registration....
3737 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003738 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003739#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3740 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003741#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003742 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3743 hdd_mon_mode_ether_setup : ether_setup),
3744 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003745
Jeff Johnson5505db82017-11-02 21:19:23 -07003746 if (dev != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003747
3748 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson5505db82017-11-02 21:19:23 -07003749 adapter = (struct hdd_adapter *) netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003750
Jeff Johnson9d295242017-08-29 14:39:48 -07003751 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Jeff Johnsonb9424862017-10-30 08:49:35 -07003752 sta_ctx = &adapter->session.station;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303753 qdf_mem_set(sta_ctx->conn_info.staId,
3754 sizeof(sta_ctx->conn_info.staId),
3755 HDD_WLAN_INVALID_STA_ID);
Jeff Johnson5505db82017-11-02 21:19:23 -07003756 adapter->dev = dev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003757 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003758 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003759 adapter->session_id = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003760
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303761 qdf_status = qdf_event_create(
3762 &adapter->qdf_session_open_event);
3763 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3764 hdd_err("Session open QDF event init failed!");
3765 free_netdev(adapter->dev);
3766 return NULL;
3767 }
3768
3769 qdf_status = qdf_event_create(
3770 &adapter->qdf_session_close_event);
3771 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3772 hdd_err("Session close QDF event init failed!");
3773 free_netdev(adapter->dev);
3774 return NULL;
3775 }
3776
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003777 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303778 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003779 init_completion(&adapter->linkup_event_var);
3780 init_completion(&adapter->cancel_rem_on_chan_var);
3781 init_completion(&adapter->rem_on_chan_ready_event);
3782 init_completion(&adapter->sta_authorized_event);
3783 init_completion(&adapter->offchannel_tx_event);
3784 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003785 init_completion(&adapter->ibss_peer_info_comp);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303786 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003787
3788 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003789 adapter->is_link_up_service_needed = false;
Alok Kumarb64650c2018-03-23 17:05:11 +05303790 adapter->disconnection_in_progress = false;
Yeshwanth Sriram Guntuka4fe30bd2018-06-13 11:41:42 +05303791 adapter->send_mode_change = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003792 /* Init the net_device structure */
Jeff Johnson5505db82017-11-02 21:19:23 -07003793 strlcpy(dev->name, name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003794
Jeff Johnson5505db82017-11-02 21:19:23 -07003795 qdf_mem_copy(dev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003796 sizeof(tSirMacAddr));
Jeff Johnson1e851a12017-10-28 14:36:12 -07003797 qdf_mem_copy(adapter->mac_addr.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003798 sizeof(tSirMacAddr));
Jeff Johnson5505db82017-11-02 21:19:23 -07003799 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003800
3801 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
Jeff Johnson5505db82017-11-02 21:19:23 -07003802 dev->features |=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003803 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Jeff Johnson5505db82017-11-02 21:19:23 -07003804 dev->features |= NETIF_F_RXCSUM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003805
Jeff Johnson5505db82017-11-02 21:19:23 -07003806 hdd_set_tso_flags(hdd_ctx, dev);
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003807
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003808 hdd_set_station_ops(adapter->dev);
3809
Jeff Johnson5505db82017-11-02 21:19:23 -07003810 hdd_dev_setup_destructor(dev);
3811 dev->ieee80211_ptr = &adapter->wdev;
3812 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003813 adapter->wdev.wiphy = hdd_ctx->wiphy;
Jeff Johnson5505db82017-11-02 21:19:23 -07003814 adapter->wdev.netdev = dev;
3815 /* set dev's parent to underlying device */
3816 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003817 hdd_wmm_init(adapter);
3818 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303819 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003820 }
3821
3822 return adapter;
3823}
3824
Jeff Johnson9d295242017-08-29 14:39:48 -07003825static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003826{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003827 struct net_device *dev = adapter->dev;
3828 int ret;
3829
Dustin Brown491d54b2018-03-14 12:39:11 -07003830 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003831
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003832 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003833 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3834
3835 ret = dev_alloc_name(dev, dev->name);
3836 if (ret < 0) {
3837 hdd_err(
3838 "unable to get dev name: %s, err = 0x%x",
3839 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303840 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003841 }
3842 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003843
3844 ret = register_netdevice(dev);
3845 if (ret) {
3846 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3847 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303848 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003849 }
3850 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003851 ret = register_netdev(dev);
3852 if (ret) {
3853 hdd_err("register_netdev(%s) failed, err = 0x%x",
3854 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303855 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003856 }
3857 }
3858 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3859
Dustin Browne74003f2018-03-14 12:51:58 -07003860 hdd_exit();
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003861
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303862 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003863}
3864
Krunal Sonib51eec72017-11-20 21:53:01 -08003865QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003866{
Krunal Sonib51eec72017-11-20 21:53:01 -08003867 struct hdd_adapter *adapter;
3868 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003869
Krunal Sonib51eec72017-11-20 21:53:01 -08003870 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3871 if (!hdd_ctx) {
3872 hdd_err("Invalid HDD_CTX");
3873 return QDF_STATUS_E_FAILURE;
3874 }
3875
3876 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3877 if (NULL == adapter) {
Naveen Rawat23a3b912018-05-30 17:45:52 -07003878 hdd_err("NULL adapter for %d", session_id);
Krunal Sonib51eec72017-11-20 21:53:01 -08003879 return QDF_STATUS_E_INVAL;
3880 }
3881 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303882 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003883 hdd_debug("session %d opened", adapter->session_id);
3884
3885 return QDF_STATUS_SUCCESS;
3886}
3887
3888QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3889{
3890 struct hdd_adapter *adapter;
3891 struct hdd_context *hdd_ctx;
3892
3893 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3894 if (!hdd_ctx) {
3895 hdd_err("Invalid HDD_CTX");
3896 return QDF_STATUS_E_FAILURE;
3897 }
3898
3899 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003900 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003901 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303902 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003903 }
3904
3905 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003906 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303907 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003908 }
3909
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003910 /*
3911 * For NAN Data interface, the close session results in the final
3912 * indication to the userspace
3913 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003914 if (adapter->device_mode == QDF_NDI_MODE)
3915 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003916
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003917 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3918
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003919 /*
3920 * We can be blocked while waiting for scheduled work to be
3921 * flushed, and the adapter structure can potentially be freed, in
3922 * which case the magic will have been reset. So make sure the
3923 * magic is still good, and hence the adapter structure is still
3924 * valid, before signaling completion
3925 */
3926 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303927 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003928
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303929 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003930}
3931
Jeff Johnson9d295242017-08-29 14:39:48 -07003932int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003933{
Dustin Brownd28772b2017-03-17 14:16:07 -07003934 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003935
Dustin Brownd28772b2017-03-17 14:16:07 -07003936 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003937 if (QDF_IS_STATUS_ERROR(status))
3938 return qdf_status_to_os_return(status);
3939
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003940 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003941 if (QDF_IS_STATUS_ERROR(status))
3942 return qdf_status_to_os_return(status);
3943
3944 if (wma_capability_enhanced_mcast_filter())
3945 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3946 else
3947 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003948
3949 return qdf_status_to_os_return(status);
3950}
3951
Jeff Johnson9d295242017-08-29 14:39:48 -07003952int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003953{
3954 QDF_STATUS status;
Dustin Brown2da29eb2018-07-13 14:23:12 -07003955 int errno;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003956 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003957 uint8_t vdev_id;
Dustin Brownd28772b2017-03-17 14:16:07 -07003958
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003959 vdev_id = adapter->session_id;
3960 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003961
3962 /* vdev created sanity check */
3963 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Dustin Brown2da29eb2018-07-13 14:23:12 -07003964 hdd_err("vdev %u does not exist", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003965 return -EINVAL;
3966 }
Dustin Brown2da29eb2018-07-13 14:23:12 -07003967
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003968 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Krunal Soni8a06d832018-06-20 16:41:17 -07003969 ucfg_scan_set_vdev_del_in_progress(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003970
Dustin Brownd28772b2017-03-17 14:16:07 -07003971 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303972 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07003973 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -07003974 status = sme_close_session(hdd_ctx->mac_handle, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003975 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Brown2da29eb2018-07-13 14:23:12 -07003976 hdd_err("failed to close sme session; status:%d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003977 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07003978 }
3979
3980 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303981 status = qdf_wait_for_event_completion(
3982 &adapter->qdf_session_close_event,
3983 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
Dustin Brown2da29eb2018-07-13 14:23:12 -07003984
3985 if (QDF_IS_STATUS_ERROR(status)) {
3986 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3987
Dustin Brownd28772b2017-03-17 14:16:07 -07003988 if (adapter->device_mode == QDF_NDI_MODE)
3989 hdd_ndp_session_end_handler(adapter);
Dustin Brown2da29eb2018-07-13 14:23:12 -07003990
3991 if (status == QDF_STATUS_E_TIMEOUT)
3992 hdd_err("timed out waiting for sme close session");
3993 else if (adapter->qdf_session_close_event.force_set)
3994 hdd_info("SSR occurred during sme close session");
3995 else
3996 hdd_err("failed to wait for sme close session; status:%u",
3997 status);
Dustin Brownd28772b2017-03-17 14:16:07 -07003998 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08003999
Yue Maf9782842017-05-08 12:49:49 -07004000release_vdev:
Krunal Soni8a06d832018-06-20 16:41:17 -07004001 ucfg_scan_clear_vdev_del_in_progress(adapter->hdd_vdev);
Jiachao Wu2c42c222018-01-15 18:13:19 +08004002
Sandeep Puligillaef415362017-08-30 16:37:13 -07004003 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08004004 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07004005 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08004006 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07004007 return errno;
4008 }
4009
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004010 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004011
4012 return 0;
4013}
4014
Krunal Sonib51eec72017-11-20 21:53:01 -08004015static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
4016 struct sme_session_params *session_param,
Jeff Johnson6a18c962018-07-01 09:09:37 -07004017 csr_roam_complete_cb callback,
Krunal Sonib51eec72017-11-20 21:53:01 -08004018 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07004019{
Dustin Brownd28772b2017-03-17 14:16:07 -07004020 uint32_t type;
4021 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08004022 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07004023
4024 /* determine vdev (sub)type */
4025 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304026 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07004027 hdd_err("failed to get vdev type: %d", status);
4028 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004029 }
Krunal Sonib51eec72017-11-20 21:53:01 -08004030 session_param->sme_session_id = adapter->session_id;
4031 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
4032 session_param->type_of_persona = type;
4033 session_param->subtype_of_persona = sub_type;
4034 session_param->session_open_cb = hdd_sme_open_session_callback;
4035 session_param->session_close_cb = hdd_sme_close_session_callback;
4036 session_param->callback = callback;
4037 session_param->callback_ctx = callback_ctx;
4038
4039 return 0;
4040}
4041
4042int hdd_vdev_create(struct hdd_adapter *adapter,
Jeff Johnson6a18c962018-07-01 09:09:37 -07004043 csr_roam_complete_cb callback, void *ctx)
Krunal Sonib51eec72017-11-20 21:53:01 -08004044{
4045 QDF_STATUS status;
4046 int errno;
4047 struct hdd_context *hdd_ctx;
4048 struct sme_session_params sme_session_params = {0};
Krunal Sonib51eec72017-11-20 21:53:01 -08004049
4050 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07004051
4052 /* do vdev create via objmgr */
4053 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07004054 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07004055 if (errno) {
4056 hdd_err("failed to create objmgr vdev: %d", errno);
4057 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004058 }
Dustin Brownd28772b2017-03-17 14:16:07 -07004059
4060 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304061 status = qdf_event_reset(&adapter->qdf_session_open_event);
4062 if (QDF_STATUS_SUCCESS != status) {
4063 hdd_err("failed to reinit session open event");
4064 return -EINVAL;
4065 }
Krunal Sonib51eec72017-11-20 21:53:01 -08004066 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
4067 callback, ctx);
4068 if (errno) {
4069 hdd_err("failed to populating SME params");
4070 goto objmgr_vdev_destroy_procedure;
4071 }
4072
Jeff Johnson16528362018-06-14 12:34:16 -07004073 status = sme_open_session(hdd_ctx->mac_handle, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07004074 if (QDF_IS_STATUS_ERROR(status)) {
4075 hdd_err("failed to open sme session: %d", status);
4076 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07004077 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004078 }
4079
4080 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304081 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
4082 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
4083 if (QDF_STATUS_SUCCESS != status) {
4084 if (adapter->qdf_session_open_event.force_set) {
4085 /*
4086 * SSR/PDR has caused shutdown, which has forcefully
4087 * set the event. Return without the closing session.
4088 */
4089 adapter->session_id = HDD_SESSION_ID_INVALID;
4090 hdd_err("Session open event forcefully set");
4091 return -EINVAL;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304092 }
Jeff Johnsonc66d3102018-02-28 11:58:26 -08004093
4094 if (QDF_STATUS_E_TIMEOUT == status)
4095 hdd_err("Session failed to open within timeout period");
4096 else
4097 hdd_err("Failed to wait for session open event(status-%d)",
4098 status);
4099 errno = -ETIMEDOUT;
4100 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
4101 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004102 }
4103
4104 /* firmware ready for component communication, raise vdev_ready event */
4105 errno = hdd_vdev_ready(adapter);
4106 if (errno) {
4107 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07004108 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004109 }
4110
Naveen Rawat2b430892018-03-13 13:58:18 -07004111 if (adapter->device_mode == QDF_STA_MODE) {
4112 hdd_debug("setting RTT mac randomization param: %d",
4113 hdd_ctx->config->enable_rtt_mac_randomization);
4114 errno = sme_cli_set_command(adapter->session_id,
4115 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_INITIATOR_RANDOM_MAC,
4116 hdd_ctx->config->enable_rtt_mac_randomization,
4117 VDEV_CMD);
4118 if (0 != errno)
4119 hdd_err("RTT mac randomization param set failed %d",
4120 errno);
4121 }
4122
Bala Venkatesh110b03e2018-07-10 16:02:08 +05304123 if (adapter->device_mode == QDF_STA_MODE ||
4124 adapter->device_mode == QDF_P2P_CLIENT_MODE)
4125 wlan_vdev_set_max_peer_count(adapter->hdd_vdev,
4126 HDD_MAX_VDEV_PEER_COUNT);
4127
Jeff Johnson1b780e42017-10-31 14:11:45 -07004128 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004129
4130 return 0;
4131
4132 /*
4133 * Due to legacy constraints, we need to destroy in the same order as
4134 * create. So, split error handling into 2 cases to accommodate.
4135 */
4136
Krunal Soni4a020c72017-10-30 20:58:40 -07004137objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07004138 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07004139
4140 return errno;
4141
Krunal Soni4a020c72017-10-30 20:58:40 -07004142hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07004143 QDF_BUG(!hdd_vdev_destroy(adapter));
4144
4145 return errno;
4146}
4147
Jeff Johnson9d295242017-08-29 14:39:48 -07004148QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07004149{
Jeff Johnsonb9424862017-10-30 08:49:35 -07004150 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004151 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07004152 QDF_STATUS status;
4153 int ret_val;
Jeff Johnson16528362018-06-14 12:34:16 -07004154 mac_handle_t mac_handle;
Dustin Brownd28772b2017-03-17 14:16:07 -07004155
Dustin Brownd28772b2017-03-17 14:16:07 -07004156 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -07004157 mac_handle = hdd_ctx->mac_handle;
4158 sme_set_curr_device_mode(mac_handle, adapter->device_mode);
4159 sme_set_pdev_ht_vht_ies(mac_handle, hdd_ctx->config->enable2x2);
4160 sme_set_vdev_ies_per_band(mac_handle, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004161
Jeff Johnson7f2c5912018-03-23 11:42:28 -07004162 hdd_roam_profile_init(adapter);
4163 hdd_register_wext(adapter->dev);
4164
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07004165 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004166
Jeff Johnsond377dce2017-10-04 10:32:42 -07004167 qdf_mem_set(sta_ctx->conn_info.staId,
4168 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05304169
Deepak Dhamdherea2785822016-11-17 01:17:45 -08004170 /* set fast roaming capability in sme session */
Jeff Johnson16528362018-06-14 12:34:16 -07004171 status = sme_config_fast_roaming(mac_handle, adapter->session_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05304172 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004173 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004174 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004175 hdd_ctx->config->OperatingChannel;
4176
4177 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004178 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004179
4180 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304181 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004182 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004183 status, status);
4184 goto error_init_txrx;
4185 }
4186
4187 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4188
4189 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304190 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004191 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004192 status, status);
4193 goto error_wmm_init;
4194 }
4195
4196 set_bit(WMM_INIT_DONE, &adapter->event_flags);
4197
Jeff Johnson1b780e42017-10-31 14:11:45 -07004198 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004199 WMI_PDEV_PARAM_BURST_ENABLE,
Dundi Raviteja3aa01be2018-05-21 18:58:59 +05304200 HDD_ENABLE_SIFS_BURST_DEFAULT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004201 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07004202 if (ret_val)
4203 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004204
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05304205 /*
4206 * In case of USB tethering, LRO is disabled. If SSR happened
4207 * during that time, then as part of SSR init, do not enable
4208 * the LRO again. Keep the LRO state same as before SSR.
4209 */
4210 if (!(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07004211 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05304212
4213 /* rcpi info initialization */
4214 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
4215
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304216 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004217
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004218error_wmm_init:
4219 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4220 hdd_deinit_tx_rx(adapter);
4221error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07004222 hdd_unregister_wext(adapter->dev);
Dustin Brownd28772b2017-03-17 14:16:07 -07004223 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004224
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004225 return status;
4226}
4227
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304228/**
Krunal Soni4a020c72017-10-30 20:58:40 -07004229 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304230 * @hdd_ctx: global hdd context
4231 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07004232 * @rtnl_held: Used to indicate whether or not the caller is holding
4233 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304234 *
4235 * This function De-initializes the STA/P2P/OCB adapter.
4236 *
4237 * Return: None.
4238 */
Krunal Soni4a020c72017-10-30 20:58:40 -07004239static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004240 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004241 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304242{
Dustin Brownfdf17c12018-03-14 12:55:34 -07004243 hdd_enter_dev(adapter->dev);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304244
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05304245 if (adapter->dev) {
4246 if (rtnl_held)
4247 adapter->dev->wireless_handlers = NULL;
4248 else {
4249 rtnl_lock();
4250 adapter->dev->wireless_handlers = NULL;
4251 rtnl_unlock();
4252 }
4253 }
4254
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304255 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
4256 hdd_deinit_tx_rx(adapter);
4257 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4258 }
4259
4260 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4261 hdd_wmm_adapter_close(adapter);
4262 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4263 }
4264
Krunal Sonib51eec72017-11-20 21:53:01 -08004265
Dustin Browne74003f2018-03-14 12:51:58 -07004266 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304267}
4268
Krunal Sonib51eec72017-11-20 21:53:01 -08004269void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
4270 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004271 bool rtnl_held)
4272{
Dustin Brown491d54b2018-03-14 12:39:11 -07004273 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304274
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004275 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004276 case QDF_STA_MODE:
4277 case QDF_P2P_CLIENT_MODE:
4278 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08004279 case QDF_IBSS_MODE:
4280 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004281 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004282 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004283 break;
4284 }
4285
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004286 case QDF_SAP_MODE:
4287 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004288 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004289 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004290 break;
4291 }
4292
4293 default:
4294 break;
4295 }
4296
Dustin Browne74003f2018-03-14 12:51:58 -07004297 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004298}
4299
Jeff Johnson9d295242017-08-29 14:39:48 -07004300static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004301 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004302{
Jeff Johnson5505db82017-11-02 21:19:23 -07004303 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004304
4305 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07004306 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004307 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004308 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004309 return;
4310 }
4311
Alok Kumarb64650c2018-03-23 17:05:11 +05304312 hdd_nud_deinit_tracking(adapter);
4313 qdf_mutex_destroy(&adapter->disconnection_status_lock);
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05304314 hdd_apf_context_destroy(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05304315
Rajeev Kumardca5f812016-02-04 17:28:06 -08004316 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05304317
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004318 /*
4319 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
4320 * the driver is almost closed and cannot handle either control
4321 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004322 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
4323 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004324 * is not right. Setting this flag helps hdd_stop() to recognize that
4325 * the interface is closed and restricts any operations on that
4326 */
4327 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
4328
4329 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004330 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07004331 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004332 else
Jeff Johnson5505db82017-11-02 21:19:23 -07004333 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004334 /*
4335 * Note that the adapter is no longer valid at this point
4336 * since the memory has been reclaimed
4337 */
4338 }
4339}
4340
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004341static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07004342 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004343{
Jeff Johnson9d295242017-08-29 14:39:48 -07004344 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004345
Dustin Brown920397d2017-12-13 16:27:50 -08004346 hdd_for_each_adapter(hdd_ctx, adapter) {
4347 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
4348 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304349 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004350 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004351 }
Dustin Brown920397d2017-12-13 16:27:50 -08004352
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304353 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004354}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004355
Arun Khandavalli2358d522016-05-16 18:05:37 +05304356#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4357/**
4358 * hdd_set_fw_log_params() - Set log parameters to FW
4359 * @hdd_ctx: HDD Context
4360 * @adapter: HDD Adapter
4361 *
4362 * This function set the FW Debug log level based on the INI.
4363 *
4364 * Return: None
4365 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004366static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004367 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304368{
4369 uint8_t count = 0, numentries = 0,
4370 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
4371 uint32_t value = 0;
4372 int ret;
4373
Arun Khandavallifae92942016-08-01 13:31:08 +05304374 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4375 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004376 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304377 return;
4378 }
4379
Arun Khandavallifae92942016-08-01 13:31:08 +05304380 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05304381 hdd_ctx->fw_log_settings.dl_type =
4382 hdd_ctx->config->enableFwLogType;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004383 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304384 WMI_DBGLOG_TYPE,
4385 hdd_ctx->config->enableFwLogType,
4386 DBG_CMD);
4387 if (ret != 0)
4388 hdd_err("Failed to enable FW log type ret %d",
4389 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304390
4391 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05304392 hdd_ctx->config->enableFwLogLevel;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004393 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304394 WMI_DBGLOG_LOG_LEVEL,
4395 hdd_ctx->config->enableFwLogLevel,
4396 DBG_CMD);
4397 if (ret != 0)
4398 hdd_err("Failed to enable FW log level ret %d",
4399 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304400
4401 hdd_string_to_u8_array(
4402 hdd_ctx->config->enableFwModuleLogLevel,
4403 moduleloglevel,
4404 &numentries,
4405 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
4406
4407 while (count < numentries) {
4408 /*
4409 * FW module log level input string looks like
4410 * below:
4411 * gFwDebugModuleLoglevel=<FW Module ID>,
4412 * <Log Level>,...
4413 * For example:
4414 * gFwDebugModuleLoglevel=
4415 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
4416 * Above input string means :
4417 * For FW module ID 1 enable log level 0
4418 * For FW module ID 2 enable log level 1
4419 * For FW module ID 3 enable log level 2
4420 * For FW module ID 4 enable log level 3
4421 * For FW module ID 5 enable log level 4
4422 * For FW module ID 6 enable log level 5
4423 * For FW module ID 7 enable log level 6
4424 */
4425
Nishank Aggarwale239d962017-03-03 12:26:02 +05304426 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
4427 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
4428 hdd_err("Module id %d and dbglog level %d input length is more than max",
4429 moduleloglevel[count],
4430 moduleloglevel[count + 1]);
4431 return;
4432 }
4433
4434 value = moduleloglevel[count] << 16;
4435 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07004436 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304437 WMI_DBGLOG_MOD_LOG_LEVEL,
4438 value, DBG_CMD);
4439 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304440 hdd_err("Failed to enable FW module log level %d ret %d",
4441 value, ret);
4442
4443 count += 2;
4444 }
Arun Khandavallifae92942016-08-01 13:31:08 +05304445
Arun Khandavalli2358d522016-05-16 18:05:37 +05304446}
4447#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004448static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004449 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304450{
4451}
4452
4453#endif
4454
4455/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004456 * hdd_configure_chain_mask() - programs chain mask to firmware
4457 * @adapter: HDD adapter
4458 *
4459 * Return: 0 on success or errno on failure
4460 */
4461static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4462{
4463 int ret_val;
Naveen Rawat98322472018-03-06 10:29:42 -08004464 QDF_STATUS status;
4465 struct wma_caps_per_phy non_dbs_phy_cap;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004466 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4467
4468 hdd_debug("enable2x2: %d, lte_coex: %d, ChainMask1x1: tx: %d rx: %d",
4469 hdd_ctx->config->enable2x2, hdd_ctx->lte_coex_ant_share,
4470 hdd_ctx->config->txchainmask1x1,
4471 hdd_ctx->config->rxchainmask1x1);
4472 hdd_debug("disable_DBS: %d, tx_chain_mask_2g: %d, rx_chain_mask_2g: %d",
4473 hdd_ctx->config->dual_mac_feature_disable,
4474 hdd_ctx->config->tx_chain_mask_2g,
4475 hdd_ctx->config->rx_chain_mask_2g);
4476 hdd_debug("tx_chain_mask_5g: %d, rx_chain_mask_5g: %d",
4477 hdd_ctx->config->tx_chain_mask_5g,
4478 hdd_ctx->config->rx_chain_mask_5g);
Liangwei Dong22810e82018-03-15 03:42:12 -04004479 hdd_debug("enable_bt_chain_separation %d",
4480 hdd_ctx->config->enable_bt_chain_separation);
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004481
Naveen Rawat98322472018-03-06 10:29:42 -08004482 status = wma_get_caps_for_phyidx_hwmode(&non_dbs_phy_cap,
4483 HW_MODE_DBS_NONE,
4484 CDS_BAND_ALL);
4485 if (QDF_IS_STATUS_ERROR(status)) {
4486 hdd_err("couldn't get phy caps. skip chain mask programming");
4487 return qdf_status_to_os_return(status);
4488 }
4489
4490 if (non_dbs_phy_cap.tx_chain_mask_2G < 3 ||
4491 non_dbs_phy_cap.rx_chain_mask_2G < 3 ||
4492 non_dbs_phy_cap.tx_chain_mask_5G < 3 ||
4493 non_dbs_phy_cap.rx_chain_mask_5G < 3) {
4494 hdd_info("firmware not capable. skip chain mask programming");
4495 return 0;
4496 }
4497
Liangwei Dong22810e82018-03-15 03:42:12 -04004498 if (hdd_ctx->config->enable2x2 &&
4499 !hdd_ctx->config->enable_bt_chain_separation) {
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004500 hdd_info("2x2 enabled. skip chain mask programming");
4501 return 0;
4502 }
4503
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004504 if (hdd_ctx->config->dual_mac_feature_disable !=
4505 DISABLE_DBS_CXN_AND_SCAN) {
4506 hdd_info("DBS enabled(%d). skip chain mask programming",
4507 hdd_ctx->config->dual_mac_feature_disable);
4508 return 0;
4509 }
4510
Naveen Rawatdacb5032018-02-08 15:23:24 -08004511 if (hdd_ctx->lte_coex_ant_share) {
4512 hdd_info("lte ant sharing enabled. skip chainmask programming");
4513 return 0;
4514 }
4515
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004516 if (hdd_ctx->config->txchainmask1x1) {
4517 ret_val = sme_cli_set_command(adapter->session_id,
4518 WMI_PDEV_PARAM_TX_CHAIN_MASK,
4519 hdd_ctx->config->txchainmask1x1,
4520 PDEV_CMD);
4521 if (ret_val)
4522 goto error;
4523 }
4524
4525 if (hdd_ctx->config->rxchainmask1x1) {
4526 ret_val = sme_cli_set_command(adapter->session_id,
4527 WMI_PDEV_PARAM_RX_CHAIN_MASK,
4528 hdd_ctx->config->rxchainmask1x1,
4529 PDEV_CMD);
4530 if (ret_val)
4531 goto error;
4532 }
4533
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004534 if (hdd_ctx->config->txchainmask1x1 ||
4535 hdd_ctx->config->rxchainmask1x1) {
4536 hdd_info("band agnostic tx/rx chain mask set. skip per band chain mask");
4537 return 0;
4538 }
4539
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004540 if (hdd_ctx->config->tx_chain_mask_2g) {
4541 ret_val = sme_cli_set_command(adapter->session_id,
4542 WMI_PDEV_PARAM_TX_CHAIN_MASK_2G,
4543 hdd_ctx->config->tx_chain_mask_2g, PDEV_CMD);
4544 if (0 != ret_val)
4545 goto error;
4546 }
4547
4548 if (hdd_ctx->config->rx_chain_mask_2g) {
4549 ret_val = sme_cli_set_command(adapter->session_id,
4550 WMI_PDEV_PARAM_RX_CHAIN_MASK_2G,
4551 hdd_ctx->config->rx_chain_mask_2g, PDEV_CMD);
4552 if (0 != ret_val)
4553 goto error;
4554 }
4555
4556 if (hdd_ctx->config->tx_chain_mask_5g) {
4557 ret_val = sme_cli_set_command(adapter->session_id,
4558 WMI_PDEV_PARAM_TX_CHAIN_MASK_5G,
4559 hdd_ctx->config->tx_chain_mask_5g, PDEV_CMD);
4560 if (0 != ret_val)
4561 goto error;
4562 }
4563
4564 if (hdd_ctx->config->rx_chain_mask_5g) {
4565 ret_val = sme_cli_set_command(adapter->session_id,
4566 WMI_PDEV_PARAM_RX_CHAIN_MASK_5G,
4567 hdd_ctx->config->rx_chain_mask_5g, PDEV_CMD);
4568 if (0 != ret_val)
4569 goto error;
4570 }
4571
4572 return 0;
4573
4574error:
4575 hdd_err("WMI PDEV set param failed %d", ret_val);
4576 return -EINVAL;
4577}
4578
4579/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304580 * hdd_set_fw_params() - Set parameters to firmware
4581 * @adapter: HDD adapter
4582 *
4583 * This function Sets various parameters to fw once the
4584 * adapter is started.
4585 *
4586 * Return: 0 on success or errno on failure
4587 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004588int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304589{
4590 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004591 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304592
Dustin Brownfdf17c12018-03-14 12:55:34 -07004593 hdd_enter_dev(adapter->dev);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304594
4595 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4596 if (!hdd_ctx)
4597 return -EINVAL;
4598
Dustin Brown732ab9c2017-06-15 13:24:09 -07004599 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4600 hdd_debug("FTM Mode is active; nothing to do");
4601 return 0;
4602 }
4603
Jeff Johnson1b780e42017-10-31 14:11:45 -07004604 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304605 WMI_PDEV_PARAM_DTIM_SYNTH,
4606 hdd_ctx->config->enable_lprx, PDEV_CMD);
4607 if (ret) {
4608 hdd_err("Failed to set LPRx");
4609 goto error;
4610 }
4611
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304612
4613 ret = sme_cli_set_command(
4614 adapter->session_id,
4615 WMI_PDEV_PARAM_1CH_DTIM_OPTIMIZED_CHAIN_SELECTION,
4616 hdd_ctx->config->enable_dtim_selection_diversity,
4617 PDEV_CMD);
4618 if (ret) {
4619 hdd_err("Failed to set DTIM_OPTIMIZED_CHAIN_SELECTION");
4620 goto error;
4621 }
4622
Ashish Kumar Dhanotiya48dac7d2018-03-28 14:59:50 +05304623 ret = sme_cli_set_command(
4624 adapter->session_id,
4625 WMI_PDEV_PARAM_TX_SCH_DELAY,
4626 hdd_ctx->config->enable_tx_sch_delay,
4627 PDEV_CMD);
4628 if (ret) {
4629 hdd_err("Failed to set WMI_PDEV_PARAM_TX_SCH_DELAY");
4630 goto error;
4631 }
4632
Ashish Kumar Dhanotiya959b38c2018-04-06 21:07:57 +05304633 ret = sme_cli_set_command(
4634 adapter->session_id,
4635 WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE,
4636 hdd_ctx->config->enable_secondary_rate,
4637 PDEV_CMD);
4638 if (ret) {
4639 hdd_err("Failed to set WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE");
4640 goto error;
4641 }
4642
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304643 if (adapter->device_mode == QDF_STA_MODE) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07004644 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304645 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4646 hdd_ctx->config->upper_brssi_thresh);
4647
Jeff Johnson1b780e42017-10-31 14:11:45 -07004648 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304649 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4650 hdd_ctx->config->lower_brssi_thresh);
4651
Jeff Johnson1b780e42017-10-31 14:11:45 -07004652 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304653 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4654 hdd_ctx->config->enable_dtim_1chrx);
4655 }
4656
Dustin Brown732ab9c2017-06-15 13:24:09 -07004657 if (hdd_ctx->config->enable2x2) {
4658 hdd_debug("configuring 2x2 mode fw params");
4659
Jeff Johnson1b780e42017-10-31 14:11:45 -07004660 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004661 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
4662 hdd_ctx->config->enable_cck_tx_fir_override,
4663 PDEV_CMD);
4664 if (ret) {
4665 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4666 ret);
4667 goto error;
4668 }
Liangwei Dong22810e82018-03-15 03:42:12 -04004669
4670 if (hdd_configure_chain_mask(adapter))
4671 goto error;
Dustin Brown732ab9c2017-06-15 13:24:09 -07004672 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304673#define HDD_DTIM_1CHAIN_RX_ID 0x5
4674#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004675 hdd_debug("configuring 1x1 mode fw params");
4676
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004677 /*
4678 * Disable DTIM 1 chain Rx when in 1x1,
4679 * we are passing two value
4680 * as param_id << 29 | param_value.
4681 * Below param_value = 0(disable)
4682 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004683 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004684 WMI_STA_SMPS_PARAM_CMDID,
4685 HDD_DTIM_1CHAIN_RX_ID <<
4686 HDD_SMPS_PARAM_VALUE_S,
4687 VDEV_CMD);
4688 if (ret) {
4689 hdd_err("DTIM 1 chain set failed %d", ret);
4690 goto error;
4691 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304692
Arun Khandavalli2358d522016-05-16 18:05:37 +05304693#undef HDD_DTIM_1CHAIN_RX_ID
4694#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004695
4696 if (hdd_configure_chain_mask(adapter))
4697 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004698 }
4699
Jeff Johnson1b780e42017-10-31 14:11:45 -07004700 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004701 WMI_PDEV_PARAM_HYST_EN,
4702 hdd_ctx->config->enableMemDeepSleep,
4703 PDEV_CMD);
4704 if (ret) {
4705 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4706 goto error;
4707 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304708
Jeff Johnson1b780e42017-10-31 14:11:45 -07004709 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004710 WMI_VDEV_PARAM_ENABLE_RTSCTS,
4711 hdd_ctx->config->rts_profile,
4712 VDEV_CMD);
4713 if (ret) {
4714 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4715 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304716 }
4717
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004718 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
4719
Jeff Johnson1b780e42017-10-31 14:11:45 -07004720 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004721 GEN_VDEV_PARAM_AMSDU,
4722 hdd_ctx->config->max_amsdu_num,
4723 GEN_CMD);
4724 if (ret != 0) {
4725 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4726 goto error;
4727 }
4728
Arun Khandavalli2358d522016-05-16 18:05:37 +05304729 hdd_set_fw_log_params(hdd_ctx, adapter);
Dustin Browne74003f2018-03-14 12:51:58 -07004730 hdd_exit();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004731
Arun Khandavalli2358d522016-05-16 18:05:37 +05304732 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304733
Arun Khandavalli2358d522016-05-16 18:05:37 +05304734error:
4735 return -EINVAL;
4736}
4737
Ryan Hsu07495ea2016-01-21 15:25:39 -08004738/**
4739 * hdd_open_adapter() - open and setup the hdd adatper
4740 * @hdd_ctx: global hdd context
4741 * @session_type: type of the interface to be created
4742 * @iface_name: User-visible name of the interface
4743 * @macAddr: MAC address to assign to the interface
4744 * @name_assign_type: the name of assign type of the netdev
4745 * @rtnl_held: the rtnl lock hold flag
4746 *
4747 * This function open and setup the hdd adpater according to the device
4748 * type request, assign the name, the mac address assigned, and then prepared
4749 * the hdd related parameters, queue, lock and ready to start.
4750 *
4751 * Return: the pointer of hdd adapter, otherwise NULL.
4752 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004753struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004754 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08004755 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004756 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004757{
Jeff Johnson9d295242017-08-29 14:39:48 -07004758 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304759 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004760
4761 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4762 /*
4763 * Max limit reached on the number of vdevs configured by the
4764 * host. Return error
4765 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304766 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4767 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004768 return NULL;
4769 }
4770
4771 if (macAddr == NULL) {
4772 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304773 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004774 return NULL;
4775 }
4776 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304777 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304778 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4779 " already exists",
4780 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004781 return NULL;
4782 }
4783
4784 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004785 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004786 /* Reset locally administered bit if the device mode is STA */
4787 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05304788 hdd_info("locally administered bit reset in sta mode: "
4789 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004790 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004791 case QDF_P2P_CLIENT_MODE:
4792 case QDF_P2P_DEVICE_MODE:
4793 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07004794 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304795 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004796 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4797 name_assign_type,
4798 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004799
4800 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304801 hdd_err("failed to allocate adapter for session %d",
4802 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004803 return NULL;
4804 }
4805
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004806 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004807 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004808 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004809 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304810 else if (QDF_MONITOR_MODE == session_type)
4811 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004812 else
4813 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4814
4815 adapter->device_mode = session_type;
4816
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004817
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004818 /*
4819 * Workqueue which gets scheduled in IPv4 notification
4820 * callback
4821 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004822 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004823 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004824
4825#ifdef WLAN_NS_OFFLOAD
4826 /*
4827 * Workqueue which gets scheduled in IPv6
4828 * notification callback.
4829 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004830 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004831 hdd_ipv6_notifier_work_queue);
4832#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004833 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004834 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004835 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004836
4837 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004838 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004839 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304840 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4841 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304842
Alok Kumarb64650c2018-03-23 17:05:11 +05304843 hdd_nud_init_tracking(adapter);
4844
4845 qdf_mutex_create(&adapter->disconnection_status_lock);
4846
Ravi Joshi1a292562017-05-18 16:28:54 -07004847 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004848
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004849 case QDF_P2P_GO_MODE:
4850 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004851 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4852 name_assign_type,
4853 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004854 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004855 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304856 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004857 return NULL;
4858 }
4859
4860 adapter->wdev.iftype =
4861 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004862 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004863 NL80211_IFTYPE_P2P_GO;
4864 adapter->device_mode = session_type;
4865
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004866 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004867 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004868 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004869
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004870 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004871 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304872 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4873 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304874
4875 /*
4876 * Workqueue which gets scheduled in IPv4 notification
4877 * callback
4878 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004879 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304880 hdd_ipv4_notifier_work_queue);
4881
4882#ifdef WLAN_NS_OFFLOAD
4883 /*
4884 * Workqueue which gets scheduled in IPv6
4885 * notification callback.
4886 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004887 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304888 hdd_ipv6_notifier_work_queue);
4889#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004890 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304891 case QDF_FTM_MODE:
4892 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4893 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08004894 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304895 if (NULL == adapter) {
4896 hdd_err("Failed to allocate adapter for FTM mode");
4897 return NULL;
4898 }
4899 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4900 adapter->device_mode = session_type;
4901 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004902 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004903 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004904
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304905 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004906 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304907 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304908 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4909 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304910 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004911 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004912 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304913 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004914 return NULL;
4915 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004916
hqueaa33ee2017-05-04 17:56:35 +08004917 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
Min Liu9be5d4a2018-05-17 11:51:53 +08004918 qdf_list_create(&adapter->blocked_scan_request_q, WLAN_MAX_SCAN_COUNT);
4919 qdf_mutex_create(&adapter->blocked_scan_request_q_lock);
hqueaa33ee2017-05-04 17:56:35 +08004920
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304921 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004922 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08004923 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004924 }
4925
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304926 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004927 if (NULL != adapter) {
4928 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4929 adapter = NULL;
4930 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004931
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004932 return NULL;
4933 }
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05304934 hdd_apf_context_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004935
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304936 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004937 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4938 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004939
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004940 /* Adapter successfully added. Increment the vdev count */
4941 hdd_ctx->current_intf_count++;
4942
Jeff Johnson5880d792016-08-15 13:32:30 -07004943 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004944 hdd_ctx->current_intf_count);
4945
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004946 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004947 }
4948
Rajeev Kumardca5f812016-02-04 17:28:06 -08004949 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004950 hdd_err("Interface %s wow debug_fs init failed",
4951 netdev_name(adapter->dev));
4952
Ajit Pal Singh106c1412018-04-18 18:08:49 +05304953 hdd_register_hl_netdev_fc_timer(adapter,
4954 hdd_tx_resume_timer_expired_handler);
4955
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004956 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4957 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004958
4959 return adapter;
4960
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004961err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07004962 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304963 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004964
4965 return NULL;
4966}
4967
Nirav Shaheb017be2018-02-15 11:20:58 +05304968#ifdef MSM_PLATFORM
4969static inline
4970void hdd_cancel_bus_bw_work(struct hdd_context *hdd_ctx)
4971{
4972 cancel_work_sync(&hdd_ctx->bus_bw_work);
4973}
4974#else
4975static inline
4976void hdd_cancel_bus_bw_work(struct hdd_context *hdd_ctx)
4977{
4978}
4979#endif
4980
Jeff Johnson9d295242017-08-29 14:39:48 -07004981QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004982 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004983{
Dustin Brown920397d2017-12-13 16:27:50 -08004984 /*
4985 * Here we are stopping global bus_bw timer & work per adapter.
4986 *
4987 * The reason is to fix one race condition between
4988 * bus bandwidth work and cleaning up an adapter.
4989 * Under some conditions, it is possible for the bus bandwidth
4990 * work to access a particularly destroyed adapter, leading to
4991 * use-after-free.
4992 */
4993 hdd_debug("wait for bus bw work to flush");
4994 hdd_bus_bw_compute_timer_stop(hdd_ctx);
4995 hdd_bus_bw_cancel_work(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004996
Min Liuef92ef52018-06-25 18:08:54 +08004997 qdf_list_destroy(&adapter->blocked_scan_request_q);
4998 qdf_mutex_destroy(&adapter->blocked_scan_request_q_lock);
4999
Dustin Brown920397d2017-12-13 16:27:50 -08005000 /* cleanup adapter */
5001 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
5002 adapter->device_mode);
Dustin Brown920397d2017-12-13 16:27:50 -08005003 hdd_remove_adapter(hdd_ctx, adapter);
Liangwei Dongad89c762018-06-01 01:56:23 -04005004 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005005
Dustin Brown920397d2017-12-13 16:27:50 -08005006 /* conditionally restart the bw timer */
5007 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005008
Dustin Brown920397d2017-12-13 16:27:50 -08005009 /* Adapter removed. Decrement vdev count */
5010 if (hdd_ctx->current_intf_count != 0)
5011 hdd_ctx->current_intf_count--;
Dustin Brown5ec6b552017-03-31 12:11:40 -07005012
Dustin Brown920397d2017-12-13 16:27:50 -08005013 /* Fw will take care incase of concurrency */
5014 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005015}
5016
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08005017/**
5018 * hdd_close_all_adapters - Close all open adapters
5019 * @hdd_ctx: Hdd context
5020 * rtnl_held: True if RTNL lock held
5021 *
5022 * Close all open adapters.
5023 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305024 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08005025 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005026QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005027{
Dustin Brown920397d2017-12-13 16:27:50 -08005028 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305029 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005030
Dustin Brown491d54b2018-03-14 12:39:11 -07005031 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005032
5033 do {
Dustin Brown920397d2017-12-13 16:27:50 -08005034 status = hdd_remove_front_adapter(hdd_ctx, &adapter);
5035 if (QDF_IS_STATUS_SUCCESS(status)) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305036 wlan_hdd_release_intf_addr(hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005037 adapter->mac_addr.bytes);
5038 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
5039
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305040 /* Adapter removed. Decrement vdev count */
5041 if (hdd_ctx->current_intf_count != 0)
5042 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005043 }
Dustin Brown920397d2017-12-13 16:27:50 -08005044 } while (QDF_IS_STATUS_SUCCESS(status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005045
Dustin Browne74003f2018-03-14 12:51:58 -07005046 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005047
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305048 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005049}
5050
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005051void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005052{
Anurag Chouhan6d760662016-02-20 16:05:43 +05305053 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005054 tSirUpdateIE updateIE;
Jeff Johnson16528362018-06-14 12:34:16 -07005055 mac_handle_t mac_handle;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005056
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005057 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005058 case QDF_STA_MODE:
5059 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005060 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005061 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005062 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07005063 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005064 break;
5065 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005066 case QDF_SAP_MODE:
5067 case QDF_P2P_GO_MODE:
5068 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005069 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07005070 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005071 break;
5072 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005073 case QDF_FTM_MODE:
5074 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005075 default:
5076 /*
5077 * wlan_hdd_reset_prob_rspies should not have been called
5078 * for these kind of devices
5079 */
Jeff Johnson5880d792016-08-15 13:32:30 -07005080 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005081 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005082 return;
5083 }
5084
Anurag Chouhanc5548422016-02-24 18:33:27 +05305085 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005086 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005087 updateIE.ieBufferlength = 0;
5088 updateIE.pAdditionIEBuffer = NULL;
5089 updateIE.append = true;
5090 updateIE.notify = false;
Jeff Johnson16528362018-06-14 12:34:16 -07005091 mac_handle = hdd_adapter_get_mac_handle(adapter);
5092 if (sme_update_add_ie(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005093 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305094 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005095 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005096 }
5097}
5098
Dustin Browndb2a8be2017-12-20 11:49:56 -08005099QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
5100 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005101{
Liangwei Dongad89c762018-06-01 01:56:23 -04005102 return hdd_stop_adapter_ext(hdd_ctx, adapter, 0);
5103}
5104
5105QDF_STATUS hdd_stop_adapter_ext(struct hdd_context *hdd_ctx,
5106 struct hdd_adapter *adapter,
5107 enum hdd_adapter_stop_flag_t flag)
5108{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305109 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson025618c2018-03-18 14:41:00 -07005110 struct csr_roam_profile *roam_profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005111 union iwreq_data wrqu;
5112 tSirUpdateIE updateIE;
5113 unsigned long rc;
Jeff Johnsone4c11db2018-05-05 23:22:32 -07005114 tsap_config_t *sap_config;
Jeff Johnson16528362018-06-14 12:34:16 -07005115 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005116
Dustin Brown491d54b2018-03-14 12:39:11 -07005117 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005118
Dustin Browne7e71d32018-05-11 16:00:08 -07005119 if (adapter->session_id != HDD_SESSION_ID_INVALID)
5120 wlan_hdd_cfg80211_deregister_frames(adapter);
5121
Alok Kumarb64650c2018-03-23 17:05:11 +05305122 hdd_nud_ignore_tracking(adapter, true);
5123 hdd_nud_reset_tracking(adapter);
5124
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005125 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305126 wlan_hdd_netif_queue_control(adapter,
5127 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5128 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08005129 /*
5130 * if this is the last active connection check & stop the
5131 * opportunistic timer first
5132 */
5133 if (((policy_mgr_get_connection_count(hdd_ctx->hdd_psoc) == 1) &&
5134 (policy_mgr_mode_specific_connection_count(hdd_ctx->hdd_psoc,
5135 policy_mgr_convert_device_mode_to_qdf_type(
5136 adapter->device_mode), NULL) == 1)) ||
5137 !policy_mgr_get_connection_count(hdd_ctx->hdd_psoc))
5138 policy_mgr_check_and_stop_opportunistic_timer(
5139 hdd_ctx->hdd_psoc, adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -07005140
5141 mac_handle = hdd_ctx->mac_handle;
5142
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005143 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005144 case QDF_STA_MODE:
5145 case QDF_P2P_CLIENT_MODE:
5146 case QDF_IBSS_MODE:
5147 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005148 case QDF_NDI_MODE:
5149 if ((QDF_NDI_MODE == adapter->device_mode) ||
5150 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005151 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
5152 hdd_is_connecting(
5153 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005154 INIT_COMPLETION(adapter->disconnect_comp_var);
Jeff Johnson025618c2018-03-18 14:41:00 -07005155 roam_profile = hdd_roam_profile(adapter);
5156 /* For NDI do not use roam_profile */
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005157 if (QDF_NDI_MODE == adapter->device_mode)
5158 qdf_ret_status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005159 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005160 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005161 eCSR_DISCONNECT_REASON_NDI_DELETE);
Jeff Johnson025618c2018-03-18 14:41:00 -07005162 else if (roam_profile->BSSType ==
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005163 eCSR_BSS_TYPE_START_IBSS)
5164 qdf_ret_status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005165 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005166 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005167 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Abhinav Kumar19a7a402018-07-12 17:36:57 +05305168 else if (adapter->device_mode == QDF_STA_MODE)
5169 wlan_hdd_disconnect(adapter,
5170 eCSR_DISCONNECT_REASON_DEAUTH);
5171 else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005172 qdf_ret_status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005173 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005174 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005175 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005176 /* success implies disconnect command got
5177 * queued up successfully
5178 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005179 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
5180 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005181 rc = wait_for_completion_timeout(
5182 &adapter->disconnect_comp_var,
5183 msecs_to_jiffies
5184 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005185 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005186 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005187 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005188 if (qdf_ret_status != QDF_STATUS_SUCCESS)
5189 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005190 memset(&wrqu, '\0', sizeof(wrqu));
5191 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5192 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5193 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
5194 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05305195 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08005196 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005197
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05305198 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05305199 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005200
5201#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005202 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005203#endif
5204
5205 hdd_deregister_tx_flow_control(adapter);
5206
5207#ifdef WLAN_NS_OFFLOAD
5208#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005209 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005210#endif
5211#endif
5212
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05305213 if (adapter->device_mode == QDF_STA_MODE)
5214 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
5215 adapter->dev);
Dustin Browndb2a8be2017-12-20 11:49:56 -08005216
5217 if (wlan_hdd_try_disconnect(adapter)) {
5218 hdd_err("Error: Can't disconnect adapter");
5219 return QDF_STATUS_E_FAILURE;
Krunal Soni985b8132017-02-10 18:49:08 -08005220 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08005221
Himanshu Agarwalb229a142017-12-21 10:16:45 +05305222 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005223 break;
5224
Rajeev Kumar3b906202018-02-01 10:55:14 -08005225 case QDF_MONITOR_MODE:
5226 wlan_hdd_scan_abort(adapter);
5227 hdd_deregister_tx_flow_control(adapter);
5228 hdd_vdev_destroy(adapter);
5229 break;
5230
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005231 case QDF_SAP_MODE:
wadesongf9b15ed2017-12-14 14:12:32 +08005232 wlan_hdd_scan_abort(adapter);
Govind Singh1dab23b2017-08-12 13:31:00 +05305233 /* Flush IPA exception path packets */
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05305234 sap_config = &adapter->session.ap.sap_config;
5235 if (sap_config)
5236 wlansap_reset_sap_config_add_ie(sap_config,
5237 eUPDATE_IE_ALL);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05305238 ucfg_ipa_flush(hdd_ctx->hdd_pdev);
Liangwei Dongad89c762018-06-01 01:56:23 -04005239 if (!(flag & HDD_IN_CAC_WORK_TH_CONTEXT))
5240 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Jeff Johnson46807cd2018-04-29 21:32:22 -07005241 /* fallthrough */
Dustin Browna5cf8e02017-10-19 16:04:19 -07005242
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005243 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07005244 if (QDF_SAP_MODE == adapter->device_mode) {
5245 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
5246 cds_flush_delayed_work(
5247 &adapter->acs_pending_work);
5248 clear_bit(ACS_PENDING, &adapter->event_flags);
5249 }
5250 }
Krunal Soni22208392017-09-29 18:10:34 -07005251 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005252
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005253 /* Any softap specific cleanup here... */
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305254 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005255 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005256 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005257 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5258
5259 hdd_deregister_tx_flow_control(adapter);
5260
Kapil Guptac1224bf2017-06-22 21:22:40 +05305261 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005262 mutex_lock(&hdd_ctx->sap_lock);
5263 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305264 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05305265 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005266
5267 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005268 status = wlansap_stop_bss(
5269 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005270
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305271 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07005272 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005273 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305274 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305275 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305276 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +05305277 qdf_wait_for_event_completion(
5278 &hostapd_state->qdf_stop_bss_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -08005279 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005280
Anurag Chouhance0dc992016-02-16 18:18:03 +05305281 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005282 hdd_err("failure waiting for wlansap_stop_bss %d",
5283 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005284 }
5285 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07005286 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005287 }
5288 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005289 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
5290 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005291 adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005292 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305293 adapter->device_mode,
5294 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005295
Anurag Chouhanc5548422016-02-24 18:33:27 +05305296 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07005297 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005298 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005299 updateIE.ieBufferlength = 0;
5300 updateIE.pAdditionIEBuffer = NULL;
5301 updateIE.append = false;
5302 updateIE.notify = false;
5303 /* Probe bcn reset */
Jeff Johnson16528362018-06-14 12:34:16 -07005304 if (sme_update_add_ie(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005305 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305306 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005307 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005308 }
5309 /* Assoc resp reset */
Jeff Johnson16528362018-06-14 12:34:16 -07005310 if (sme_update_add_ie(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005311 &updateIE,
5312 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305313 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005314 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005315 }
5316 /* Reset WNI_CFG_PROBE_RSP Flags */
5317 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005318 }
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005319 clear_bit(SOFTAP_INIT_DONE, &adapter->event_flags);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005320 qdf_mem_free(adapter->session.ap.beacon);
5321 adapter->session.ap.beacon = NULL;
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005322
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305323 /*
5324 * If Do_Not_Break_Stream was enabled clear avoid channel list.
5325 */
5326 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
5327 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
5328
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305329#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005330 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305331#endif
5332
5333#ifdef WLAN_NS_OFFLOAD
5334#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005335 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305336#endif
5337#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08005338
5339 hdd_vdev_destroy(adapter);
5340
Krunal Sonib51eec72017-11-20 21:53:01 -08005341 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005342 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005343 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08005344 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08005345 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07005346 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Zhang Qian79d0d132018-02-05 13:40:16 +08005347 hdd_deregister_tx_flow_control(adapter);
5348 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005349 break;
5350 default:
5351 break;
5352 }
5353
Ajit Pal Singh106c1412018-04-18 18:08:49 +05305354 hdd_deregister_hl_netdev_fc_timer(adapter);
5355
Dustin Brown04348372017-12-14 16:13:39 -08005356 if (adapter->scan_info.default_scan_ies) {
5357 qdf_mem_free(adapter->scan_info.default_scan_ies);
5358 adapter->scan_info.default_scan_ies = NULL;
5359 }
5360
Dustin Browne74003f2018-03-14 12:51:58 -07005361 hdd_exit();
Dustin Brown04348372017-12-14 16:13:39 -08005362
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305363 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005364}
5365
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305366/**
5367 * hdd_deinit_all_adapters - deinit all adapters
5368 * @hdd_ctx: HDD context
5369 * @rtnl_held: True if RTNL lock held
5370 *
5371 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005372void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305373{
Jeff Johnson9d295242017-08-29 14:39:48 -07005374 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305375
Dustin Brown491d54b2018-03-14 12:39:11 -07005376 hdd_enter();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305377
Dustin Brown920397d2017-12-13 16:27:50 -08005378 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305379 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305380
Dustin Browne74003f2018-03-14 12:51:58 -07005381 hdd_exit();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305382}
5383
Dustin Browndb2a8be2017-12-20 11:49:56 -08005384QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005385{
Jeff Johnson9d295242017-08-29 14:39:48 -07005386 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005387
Dustin Brown491d54b2018-03-14 12:39:11 -07005388 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005389
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305390 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5391
Dustin Brown920397d2017-12-13 16:27:50 -08005392 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08005393 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005394
Dustin Browne74003f2018-03-14 12:51:58 -07005395 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005396
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305397 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005398}
5399
Paul Zhang84fa9382017-11-10 21:18:21 +08005400static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
5401 struct hdd_adapter *adapter)
5402{
5403 switch (adapter->device_mode) {
5404 case QDF_STA_MODE:
5405 case QDF_P2P_CLIENT_MODE:
5406 case QDF_IBSS_MODE:
5407 case QDF_P2P_DEVICE_MODE:
5408 case QDF_NDI_MODE:
5409 wlan_hdd_scan_abort(adapter);
5410 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5411 if (adapter->device_mode == QDF_STA_MODE)
5412 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
5413 adapter->dev);
5414 break;
5415 case QDF_P2P_GO_MODE:
5416 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5417 break;
5418 case QDF_SAP_MODE:
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305419 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Paul Zhang84fa9382017-11-10 21:18:21 +08005420 wlan_hdd_undo_acs(adapter);
5421 break;
5422 default:
5423 break;
5424 }
5425}
5426
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005427QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005428{
Jeff Johnson9d295242017-08-29 14:39:48 -07005429 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07005430 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07005431 struct qdf_mac_addr peerMacAddr;
Yue Ma42654682018-01-11 16:55:24 -08005432 int sta_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005433
Dustin Brown491d54b2018-03-14 12:39:11 -07005434 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005435
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305436 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5437
Dustin Brown920397d2017-12-13 16:27:50 -08005438 hdd_for_each_adapter(hdd_ctx, adapter) {
Dustin Brown5e89ef82018-03-14 11:50:23 -07005439 hdd_info("[SSR] reset adapter with device mode %s(%d)",
5440 hdd_device_mode_to_string(adapter->device_mode),
5441 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305442
5443 if ((adapter->device_mode == QDF_STA_MODE) ||
Paul Zhang679025e2018-03-08 22:39:44 +08005444 (adapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305445 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07005446 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Paul Zhang679025e2018-03-08 22:39:44 +08005447 adapter->session.station.hdd_reassoc_scenario = false;
5448 }
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305449
Arun Khandavallicc544b32017-01-30 19:52:16 +05305450 if (hdd_ctx->config->sap_internal_restart &&
5451 adapter->device_mode == QDF_SAP_MODE) {
5452 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305453 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05305454 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005455 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08005456 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005457 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005458 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
5459 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305460 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305461 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005462 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005463 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005464
Paul Zhang84fa9382017-11-10 21:18:21 +08005465 hdd_reset_scan_operation(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005466
5467 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005468 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005469 adapter->device_mode, adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005470 hdd_green_ap_start_state_mc(hdd_ctx, adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305471 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005472 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5473 hdd_wmm_adapter_close(adapter);
5474 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5475 }
5476
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305477 if (adapter->device_mode == QDF_STA_MODE)
5478 hdd_clear_fils_connection_info(adapter);
5479
Wu Gao3545e642017-07-14 19:24:41 +08005480 if (adapter->device_mode == QDF_SAP_MODE) {
5481 /*
5482 * If adapter is SAP, set session ID to invalid
5483 * since SAP session will be cleanup during SSR.
5484 */
Wu Gao36717432016-11-21 15:09:48 +08005485 wlansap_set_invalid_session(
5486 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5487
Wu Gao3545e642017-07-14 19:24:41 +08005488 wlansap_cleanup_cac_timer(
5489 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5490 }
5491
Yue Ma42654682018-01-11 16:55:24 -08005492 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005493 if (adapter->device_mode == QDF_STA_MODE ||
5494 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005495 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005496 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07005497 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005498
Yue Ma42654682018-01-11 16:55:24 -08005499 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
Wu Gao6b81fc52018-05-24 19:27:27 +08005500 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Yue Ma42654682018-01-11 16:55:24 -08005501 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5502 if (adapter->sta_info[sta_id].in_use) {
5503 hdd_debug("[SSR] deregister STA with ID %d",
5504 sta_id);
5505 hdd_softap_deregister_sta(adapter,
5506 sta_id);
5507 adapter->sta_info[sta_id].in_use = 0;
5508 }
5509 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005510 }
5511
Alok Kumarb64650c2018-03-23 17:05:11 +05305512 hdd_nud_reset_tracking(adapter);
5513 hdd_nud_ignore_tracking(adapter, true);
5514 hdd_set_disconnect_status(adapter, false);
5515
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005516 hdd_softap_deinit_tx_rx(adapter);
Tiger Yu8c387702018-07-06 16:56:42 +08005517 hdd_deregister_tx_flow_control(adapter);
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005518
Yue Maf9782842017-05-08 12:49:49 -07005519 /* Destroy vdev which will be recreated during reinit. */
5520 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005521 }
5522
Dustin Browne74003f2018-03-14 12:51:58 -07005523 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005524
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305525 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005526}
5527
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005528bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305529{
Dustin Brown920397d2017-12-13 16:27:50 -08005530 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305531 bool close_modules = true;
5532
Arun Khandavalliba479c42017-07-26 21:29:40 +05305533 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
5534 hdd_info("FTM mode, don't close the module");
5535 return false;
5536 }
5537
Dustin Brown920397d2017-12-13 16:27:50 -08005538 hdd_for_each_adapter(hdd_ctx, adapter) {
5539 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
5540 test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005541 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305542 close_modules = false;
5543 break;
5544 }
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305545 }
5546
5547 return close_modules;
5548}
5549
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305550bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305551{
5552 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5553 return true;
5554 else
5555 return false;
5556}
5557
Anurag Chouhanc4092922016-09-08 15:56:11 +05305558#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08005559 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305560struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5561 struct ieee80211_channel *channel,
5562 const u8 *bssid, const u8 *ssid,
5563 size_t ssid_len)
5564{
5565 return cfg80211_get_bss(wiphy, channel, bssid,
5566 ssid, ssid_len,
5567 WLAN_CAPABILITY_ESS,
5568 WLAN_CAPABILITY_ESS);
5569}
5570#else
5571struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5572 struct ieee80211_channel *channel,
5573 const u8 *bssid, const u8 *ssid,
5574 size_t ssid_len)
5575{
5576 return cfg80211_get_bss(wiphy, channel, bssid,
5577 ssid, ssid_len,
5578 IEEE80211_BSS_TYPE_ESS,
5579 IEEE80211_PRIVACY_ANY);
5580}
5581#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305582
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305583#if defined CFG80211_CONNECT_BSS || \
5584 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305585#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305586 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305587/**
5588 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5589 * @timeout_reason: reason for connect timeout
5590 *
5591 * This function is used to convert host timeout
5592 * reason enum to kernel specific enum.
5593 *
5594 * Return: nl timeout enum
5595 */
5596static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5597 tSirResultCodes timeout_reason)
5598{
5599 switch (timeout_reason) {
5600 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5601 return NL80211_TIMEOUT_SCAN;
5602 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5603 return NL80211_TIMEOUT_AUTH;
5604 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5605 return NL80211_TIMEOUT_ASSOC;
5606 default:
5607 return NL80211_TIMEOUT_UNSPECIFIED;
5608 }
5609}
5610
5611/**
5612 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5613 * @dev: network device
5614 * @bssid: bssid to which we want to associate
5615 * @timeout_reason: reason for connect timeout
5616 *
5617 * This API is used to send connection timeout reason to supplicant
5618 *
5619 * Return: void
5620 */
5621static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5622 const u8 *bssid,
5623 tSirResultCodes timeout_reason)
5624{
5625 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005626
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305627 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5628
5629 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5630 nl_timeout_reason);
5631}
5632
5633/**
5634 * __hdd_connect_bss() - API to send connection status to supplicant
5635 * @dev: network device
5636 * @bssid: bssid to which we want to associate
5637 * @req_ie: Request Information Element
5638 * @req_ie_len: len of the req IE
5639 * @resp_ie: Response IE
5640 * @resp_ie_len: len of ht response IE
5641 * @status: status
5642 * @gfp: Kernel Flag
5643 * @timeout_reason: reason for connect timeout
5644 *
5645 * Return: void
5646 */
5647static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5648 struct cfg80211_bss *bss, const u8 *req_ie,
5649 size_t req_ie_len, const u8 *resp_ie,
5650 size_t resp_ie_len, int status, gfp_t gfp,
5651 tSirResultCodes timeout_reason)
5652{
5653 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005654
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305655 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5656
5657 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5658 resp_ie, resp_ie_len, status, gfp,
5659 nl_timeout_reason);
5660}
5661#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305662#if defined CFG80211_CONNECT_TIMEOUT || \
5663 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305664static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5665 const u8 *bssid,
5666 tSirResultCodes timeout_reason)
5667{
5668 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5669}
5670#endif
5671
5672static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5673 struct cfg80211_bss *bss, const u8 *req_ie,
5674 size_t req_ie_len, const u8 *resp_ie,
5675 size_t resp_ie_len, int status, gfp_t gfp,
5676 tSirResultCodes timeout_reason)
5677{
5678 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5679 resp_ie, resp_ie_len, status, gfp);
5680}
5681#endif
5682
Abhishek Singha84d3952016-09-13 13:45:05 +05305683/**
5684 * hdd_connect_bss() - API to send connection status to supplicant
5685 * @dev: network device
5686 * @bssid: bssid to which we want to associate
5687 * @req_ie: Request Information Element
5688 * @req_ie_len: len of the req IE
5689 * @resp_ie: Response IE
5690 * @resp_ie_len: len of ht response IE
5691 * @status: status
5692 * @gfp: Kernel Flag
5693 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305694 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05305695 *
5696 * The API is a wrapper to send connection status to supplicant
5697 *
5698 * Return: Void
5699 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305700#if defined CFG80211_CONNECT_TIMEOUT || \
5701 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05305702static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5703 struct cfg80211_bss *bss, const u8 *req_ie,
5704 size_t req_ie_len, const u8 *resp_ie,
5705 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305706 bool connect_timeout,
5707 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305708{
5709 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305710 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305711 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305712 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5713 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305714}
5715#else
5716static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5717 struct cfg80211_bss *bss, const u8 *req_ie,
5718 size_t req_ie_len, const u8 *resp_ie,
5719 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305720 bool connect_timeout,
5721 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305722{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305723 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5724 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305725}
5726#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305727
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305728#if defined(WLAN_FEATURE_FILS_SK)
5729#if defined(CFG80211_CONNECT_DONE) || \
5730 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
5731#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
5732 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305733/**
5734 * hdd_populate_fils_params() - Populate FILS keys to connect response
5735 * @fils_params: connect response to supplicant
5736 * @fils_kek: FILS kek
5737 * @fils_kek_len: FILS kek length
5738 * @pmk: FILS PMK
5739 * @pmk_len: FILS PMK length
5740 * @pmkid: PMKID
5741 * @fils_seq_num: FILS Seq number
5742 *
5743 * Return: None
5744 */
5745static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5746 *fils_params, const uint8_t *fils_kek,
5747 size_t fils_kek_len, const uint8_t *pmk,
5748 size_t pmk_len, const uint8_t *pmkid,
5749 uint16_t fils_seq_num)
5750{
5751 /* Increament seq number to be used for next FILS */
5752 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
5753 fils_params->update_erp_next_seq_num = true;
5754 fils_params->fils_kek = fils_kek;
5755 fils_params->fils_kek_len = fils_kek_len;
5756 fils_params->pmk = pmk;
5757 fils_params->pmk_len = pmk_len;
5758 fils_params->pmkid = pmkid;
5759}
5760#else
5761static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5762 *fils_params, const uint8_t
5763 *fils_kek, size_t fils_kek_len,
5764 const uint8_t *pmk, size_t pmk_len,
5765 const uint8_t *pmkid,
5766 uint16_t fils_seq_num)
5767{ }
5768#endif
5769
Jeff Johnson172237b2017-11-07 15:32:59 -08005770void hdd_update_hlp_info(struct net_device *dev,
5771 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305772{
5773 struct sk_buff *skb;
5774 uint16_t skb_len;
5775 struct llc_snap_hdr_t *llc_hdr;
5776 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305777 uint8_t *hlp_data;
5778 uint16_t hlp_data_len;
5779 struct fils_join_rsp_params *roam_fils_params
5780 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305781 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
5782
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305783 if (!roam_fils_params) {
5784 hdd_err("FILS Roam Param NULL");
5785 return;
5786 }
5787
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08005788 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305789 hdd_err("FILS HLP Data NULL, len %d",
5790 roam_fils_params->hlp_data_len);
5791 return;
5792 }
5793
5794 hlp_data = roam_fils_params->hlp_data;
5795 hlp_data_len = roam_fils_params->hlp_data_len;
5796
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305797 /* Calculate skb length */
5798 skb_len = (2 * ETH_ALEN) + hlp_data_len;
5799 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
5800 if (skb == NULL) {
5801 hdd_err("HLP packet nbuf alloc fails");
5802 return;
5803 }
5804
5805 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
5806 QDF_MAC_ADDR_SIZE);
5807 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
5808 QDF_MAC_ADDR_SIZE);
5809
5810 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
5811 if (IS_SNAP(llc_hdr)) {
5812 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5813 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5814 }
5815
5816 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
5817
5818 /*
5819 * This HLP packet is formed from HLP info encapsulated
5820 * in assoc response frame which is AEAD encrypted.
5821 * Hence, this checksum validation can be set unnecessary.
5822 * i.e. network layer need not worry about checksum.
5823 */
5824 skb->ip_summed = CHECKSUM_UNNECESSARY;
5825
5826 status = hdd_rx_packet_cbk(padapter, skb);
5827 if (QDF_IS_STATUS_ERROR(status)) {
5828 hdd_err("Sending HLP packet fails");
5829 return;
5830 }
5831 hdd_debug("send HLP packet to netif successfully");
5832}
5833
5834/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305835 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
5836 * @dev: network device
5837 * @bssid: bssid to which we want to associate
5838 * @bss: cfg80211 bss info
5839 * @roam_info: information about connected bss
5840 * @req_ie: Request Information Element
5841 * @req_ie_len: len of the req IE
5842 * @resp_ie: Response IE
5843 * @resp_ie_len: len of ht response IE
5844 * @status: status
5845 * @gfp: allocation flags
5846 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5847 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305848 *
5849 * This API is used as wrapper to send FILS key/sequence number
5850 * params etc. to supplicant in case of FILS connection
5851 *
5852 * Return: None
5853 */
5854static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005855 struct cfg80211_bss *bss,
5856 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305857 const u8 *req_ie, size_t req_ie_len,
5858 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005859 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305860 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305861{
5862 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305863 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5864 struct fils_join_rsp_params *roam_fils_params =
5865 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005866
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305867 qdf_mem_zero(&fils_params, sizeof(fils_params));
5868
5869 if (!roam_fils_params) {
5870 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5871 } else {
5872 fils_params.status = status;
5873 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08005874 fils_params.timeout_reason =
5875 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305876 fils_params.req_ie = req_ie;
5877 fils_params.req_ie_len = req_ie_len;
5878 fils_params.resp_ie = resp_ie;
5879 fils_params.resp_ie_len = resp_ie_len;
5880 fils_params.bss = bss;
5881 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5882 roam_fils_params->kek_len,
5883 roam_fils_params->fils_pmk,
5884 roam_fils_params->fils_pmk_len,
5885 roam_fils_params->fils_pmkid,
5886 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305887 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305888 }
5889 hdd_debug("FILS indicate connect status %d seq no %d",
5890 fils_params.status,
5891 fils_params.fils_erp_next_seq_num);
5892
5893 cfg80211_connect_done(dev, &fils_params, gfp);
5894
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305895 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305896 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305897
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305898 /* Clear all the FILS key info */
5899 if (roam_fils_params && roam_fils_params->fils_pmk)
5900 qdf_mem_free(roam_fils_params->fils_pmk);
5901 if (roam_fils_params)
5902 qdf_mem_free(roam_fils_params);
5903 roam_info->fils_join_rsp = NULL;
5904}
5905#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005906static inline void
5907hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005908 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005909 const u8 *req_ie, size_t req_ie_len,
5910 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5911 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305912 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305913{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305914#endif
5915#endif
5916
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305917#if defined(WLAN_FEATURE_FILS_SK) && \
5918 (defined(CFG80211_CONNECT_DONE) || \
5919 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305920/**
5921 * hdd_fils_update_connect_results() - API to send fils connection status to
5922 * supplicant.
5923 * @dev: network device
5924 * @bssid: bssid to which we want to associate
5925 * @bss: cfg80211 bss info
5926 * @roam_info: information about connected bss
5927 * @req_ie: Request Information Element
5928 * @req_ie_len: len of the req IE
5929 * @resp_ie: Response IE
5930 * @resp_ie_len: len of ht response IE
5931 * @status: status
5932 * @gfp: allocation flags
5933 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5934 * @timeout_reason: reason for connect timeout
5935 *
5936 * The API is a wrapper to send connection status to supplicant
5937 *
5938 * Return: 0 if success else failure
5939 */
5940static int hdd_fils_update_connect_results(struct net_device *dev,
5941 const u8 *bssid,
5942 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005943 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305944 size_t req_ie_len, const u8 *resp_ie,
5945 size_t resp_ie_len, u16 status, gfp_t gfp,
5946 bool connect_timeout,
5947 tSirResultCodes timeout_reason)
5948{
Dustin Brown491d54b2018-03-14 12:39:11 -07005949 hdd_enter();
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305950 if (!roam_info || !roam_info->is_fils_connection)
5951 return -EINVAL;
5952
5953 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5954 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305955 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305956 return 0;
5957}
5958#else
5959static inline int hdd_fils_update_connect_results(struct net_device *dev,
5960 const u8 *bssid,
5961 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005962 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305963 size_t req_ie_len, const u8 *resp_ie,
5964 size_t resp_ie_len, u16 status, gfp_t gfp,
5965 bool connect_timeout,
5966 tSirResultCodes timeout_reason)
5967{
5968 return -EINVAL;
5969}
5970#endif
5971
Anurag Chouhanc4092922016-09-08 15:56:11 +05305972/**
5973 * hdd_connect_result() - API to send connection status to supplicant
5974 * @dev: network device
5975 * @bssid: bssid to which we want to associate
5976 * @roam_info: information about connected bss
5977 * @req_ie: Request Information Element
5978 * @req_ie_len: len of the req IE
5979 * @resp_ie: Response IE
5980 * @resp_ie_len: len of ht response IE
5981 * @status: status
5982 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305983 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305984 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305985 *
5986 * The API is a wrapper to send connection status to supplicant
5987 * and allow runtime suspend
5988 *
5989 * Return: Void
5990 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305991void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005992 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305993 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305994 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305995 bool connect_timeout,
5996 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305997{
Jeff Johnson9d295242017-08-29 14:39:48 -07005998 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305999 struct cfg80211_bss *bss = NULL;
Jingxiang Ge929c7932018-01-24 14:01:12 +08006000 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306001
6002 if (WLAN_STATUS_SUCCESS == status) {
6003 struct ieee80211_channel *chan;
6004 int freq;
6005 int chan_no = roam_info->pBssDesc->channelId;
6006
6007 if (chan_no <= 14)
6008 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07006009 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306010 else
6011 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07006012 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306013
6014 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
6015 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
6016 roam_info->u.pConnectedProfile->SSID.ssId,
6017 roam_info->u.pConnectedProfile->SSID.length);
6018 }
Komal Seelama89be8d2016-09-29 11:09:26 +05306019
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05306020 if (hdd_fils_update_connect_results(dev, bssid, bss,
6021 roam_info, req_ie, req_ie_len, resp_ie,
6022 resp_ie_len, status, gfp, connect_timeout,
6023 timeout_reason) != 0) {
6024 hdd_connect_bss(dev, bssid, bss, req_ie,
6025 req_ie_len, resp_ie, resp_ie_len,
6026 status, gfp, connect_timeout, timeout_reason);
6027 }
Komal Seelama89be8d2016-09-29 11:09:26 +05306028
Jingxiang Geb49aa302018-01-17 20:54:15 +08006029 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07006030 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306031}
6032#else
6033void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08006034 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05306035 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05306036 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306037 bool connect_timeout,
6038 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05306039{
Jeff Johnson9d295242017-08-29 14:39:48 -07006040 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Jingxiang Ge929c7932018-01-24 14:01:12 +08006041 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05306042
Anurag Chouhanc4092922016-09-08 15:56:11 +05306043 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
6044 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08006045
Jingxiang Geb49aa302018-01-17 20:54:15 +08006046 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07006047 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306048}
6049#endif
6050
Nirav Shah73713f72018-05-17 14:50:41 +05306051#ifdef FEATURE_MONITOR_MODE_SUPPORT
Jeff Johnsond9952752018-04-18 12:15:35 -07006052int wlan_hdd_set_mon_chan(struct hdd_adapter *adapter, uint32_t chan,
6053 uint32_t bandwidth)
6054{
6055 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6056 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
6057 struct hdd_mon_set_ch_info *ch_info = &sta_ctx->ch_info;
6058 QDF_STATUS status;
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006059 tHalHandle hal_hdl = hdd_ctx->mac_handle;
Jeff Johnsond9952752018-04-18 12:15:35 -07006060 struct qdf_mac_addr bssid;
6061 struct csr_roam_profile roam_profile;
6062 struct ch_params ch_params;
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006063 eConnectionState connstate;
Jeff Johnsond9952752018-04-18 12:15:35 -07006064
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006065 if (hdd_get_conparam() != QDF_GLOBAL_MONITOR_MODE &&
6066 adapter->device_mode != QDF_STA_MODE) {
6067 hdd_err("Not supported, device is not in monitor mode or sta mission mode");
Jeff Johnsond9952752018-04-18 12:15:35 -07006068 return -EINVAL;
6069 }
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006070 if (adapter->device_mode == QDF_STA_MODE &&
6071 hdd_ctx->config->enable_change_channel_bandwidth) {
6072 connstate = sta_ctx->conn_info.connState;
6073 if (eConnectionState_Associated == connstate ||
6074 eConnectionState_Connecting == connstate) {
6075 return -EINVAL;
6076 }
6077 }
Jeff Johnsond9952752018-04-18 12:15:35 -07006078
Visweswara Tanuku006313a2018-04-12 12:26:34 +05306079 /* Validate Channel */
6080 if (!WLAN_REG_IS_24GHZ_CH(chan) && !WLAN_REG_IS_5GHZ_CH(chan)) {
6081 hdd_err("Channel %d Not supported", chan);
6082 return -EINVAL;
6083 }
6084
6085 if (WLAN_REG_IS_24GHZ_CH(chan)) {
6086 if (bandwidth == CH_WIDTH_80MHZ) {
6087 hdd_err("BW80 not possible in 2.4GHz band");
6088 return -EINVAL;
6089 }
6090 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 14) &&
6091 (bandwidth != CH_WIDTH_MAX)) {
6092 hdd_err("Only BW20 possible on channel 14");
6093 return -EINVAL;
6094 }
6095 }
6096
6097 if (WLAN_REG_IS_5GHZ_CH(chan)) {
6098 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 165) &&
6099 (bandwidth != CH_WIDTH_MAX)) {
6100 hdd_err("Only BW20 possible on channel 165");
6101 return -EINVAL;
6102 }
6103 }
6104
Jeff Johnsond9952752018-04-18 12:15:35 -07006105 hdd_debug("Set monitor mode Channel %d", chan);
6106 qdf_mem_zero(&roam_profile, sizeof(roam_profile));
6107 roam_profile.ChannelInfo.ChannelList = &ch_info->channel;
6108 roam_profile.ChannelInfo.numOfChannels = 1;
6109 roam_profile.phyMode = ch_info->phy_mode;
6110 roam_profile.ch_params.ch_width = bandwidth;
6111 hdd_select_cbmode(adapter, chan, &roam_profile.ch_params);
Chaoli Zhou75b062f2018-06-11 12:36:54 +08006112 if (hdd_ctx->config->enable_change_channel_bandwidth &&
6113 (!sme_find_session_by_bssid(hal_hdl, adapter->mac_addr.bytes))) {
6114 status = sme_create_mon_session(hal_hdl,
6115 adapter->mac_addr.bytes);
6116 if (status != QDF_STATUS_SUCCESS) {
6117 hdd_err("Status: %d Failed to create session.",
6118 status);
6119 return qdf_status_to_os_return(status);
6120 }
6121 }
Jeff Johnsond9952752018-04-18 12:15:35 -07006122 qdf_mem_copy(bssid.bytes, adapter->mac_addr.bytes,
6123 QDF_MAC_ADDR_SIZE);
6124
6125 ch_params.ch_width = bandwidth;
6126 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev, chan, 0, &ch_params);
6127 if (ch_params.ch_width == CH_WIDTH_INVALID) {
6128 hdd_err("Invalid capture channel or bandwidth for a country");
6129 return -EINVAL;
6130 }
6131 if (wlan_hdd_change_hw_mode_for_given_chnl(adapter, chan,
6132 POLICY_MGR_UPDATE_REASON_SET_OPER_CHAN)) {
6133 hdd_err("Failed to change hw mode");
6134 return -EINVAL;
6135 }
6136
Jeff Johnson16528362018-06-14 12:34:16 -07006137 status = sme_roam_channel_change_req(hdd_ctx->mac_handle,
6138 bssid, &ch_params,
Jeff Johnsond9952752018-04-18 12:15:35 -07006139 &roam_profile);
6140 if (status) {
6141 hdd_err("Status: %d Failed to set sme_roam Channel for monitor mode",
6142 status);
6143 }
6144
6145 adapter->mon_chan = chan;
6146 adapter->mon_bandwidth = bandwidth;
6147 return qdf_status_to_os_return(status);
6148}
Nirav Shah73713f72018-05-17 14:50:41 +05306149#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05306150
Wu Gaodf929f12018-05-25 18:12:25 +08006151#ifdef MSM_PLATFORM
6152/**
6153 * hdd_stop_p2p_go() - call cfg80211 API to stop P2P GO
6154 * @adapter: pointer to adapter
6155 *
6156 * This function calls cfg80211 API to stop P2P GO
6157 *
6158 * Return: None
6159 */
6160static void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6161{
6162 hdd_debug("[SSR] send stop ap to supplicant");
6163 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
6164}
6165
6166static inline void hdd_delete_sta(struct hdd_adapter *adapter)
6167{
6168}
6169#else
6170static inline void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6171{
6172}
6173
6174/**
6175 * hdd_delete_sta() - call cfg80211 API to delete STA
6176 * @adapter: pointer to adapter
6177 *
6178 * This function calls cfg80211 API to delete STA
6179 *
6180 * Return: None
6181 */
6182static void hdd_delete_sta(struct hdd_adapter *adapter)
6183{
6184 struct qdf_mac_addr bcast_mac = QDF_MAC_ADDR_BCAST_INIT;
6185
6186 hdd_debug("[SSR] send restart supplicant");
6187 /* event supplicant to restart */
6188 cfg80211_del_sta(adapter->dev,
6189 (const u8 *)&bcast_mac.bytes[0],
6190 GFP_KERNEL);
6191}
6192#endif
6193
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006194QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006195{
Jeff Johnson9d295242017-08-29 14:39:48 -07006196 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006197 eConnectionState connState;
6198
Dustin Brown491d54b2018-03-14 12:39:11 -07006199 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006200
Dustin Brown920397d2017-12-13 16:27:50 -08006201 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05306202 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08006203 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05306204
Yue Ma42654682018-01-11 16:55:24 -08006205 hdd_debug("[SSR] start adapter with device mode %s(%d)",
6206 hdd_device_mode_to_string(adapter->device_mode),
6207 adapter->device_mode);
6208
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006209 hdd_wmm_init(adapter);
6210
6211 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006212 case QDF_STA_MODE:
6213 case QDF_P2P_CLIENT_MODE:
6214 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006215
6216 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
6217 ->conn_info.connState;
6218
Krunal Sonib51eec72017-11-20 21:53:01 -08006219 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006220 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07006221 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006222
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006223 /* Indicate disconnect event to supplicant
6224 * if associated previously
6225 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006226 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07006227 eConnectionState_IbssConnected == connState ||
6228 eConnectionState_NotConnected == connState ||
6229 eConnectionState_IbssDisconnected == connState ||
6230 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006231 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006232
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006233 memset(&wrqu, '\0', sizeof(wrqu));
6234 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
6235 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
6236 wireless_send_event(adapter->dev, SIOCGIWAP,
6237 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07006238 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07006239 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006240
6241 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05306242 wlan_hdd_cfg80211_indicate_disconnect(
6243 adapter->dev, false,
6244 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006245 } else if (eConnectionState_Connecting == connState) {
6246 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006247 * Indicate connect failure to supplicant if we
6248 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006249 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306250 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306251 NULL, 0, NULL, 0,
6252 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006253 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006254 }
6255
6256 hdd_register_tx_flow_control(adapter,
6257 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08006258 hdd_tx_resume_cb,
6259 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006260
Alok Kumarb64650c2018-03-23 17:05:11 +05306261 hdd_nud_ignore_tracking(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006262 break;
6263
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006264 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006265 if (hdd_ctx->config->sap_internal_restart)
Krunal Sonib51eec72017-11-20 21:53:01 -08006266 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05306267
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006268 break;
6269
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006270 case QDF_P2P_GO_MODE:
Wu Gaodf929f12018-05-25 18:12:25 +08006271 hdd_delete_sta(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006272 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306273 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08006274 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306275 hdd_set_mon_rx_cb(adapter->dev);
6276 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
6277 adapter->mon_bandwidth);
6278 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006279 default:
6280 break;
6281 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07006282 /*
6283 * Action frame registered in one adapter which will
6284 * applicable to all interfaces
6285 */
6286 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006287 }
6288
Wu Gaodf929f12018-05-25 18:12:25 +08006289 hdd_for_each_adapter(hdd_ctx, adapter) {
6290 if (!hdd_is_interface_up(adapter))
6291 continue;
6292
6293 if (adapter->device_mode == QDF_P2P_GO_MODE)
6294 hdd_stop_p2p_go(adapter);
6295 }
6296
Dustin Browne74003f2018-03-14 12:51:58 -07006297 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006298
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306299 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006300}
6301
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006302QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006303 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006304{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306305 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006306 qdf_list_node_t *node;
6307
6308 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006309
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006310 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006311 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006312 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006313
6314 if (QDF_IS_STATUS_ERROR(status))
6315 return status;
6316
6317 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6318
6319 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006320}
6321
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006322QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006323 struct hdd_adapter *current_adapter,
6324 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006325{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306326 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006327 qdf_list_node_t *node;
6328
6329 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006330
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006331 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006332 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08006333 &current_adapter->node,
6334 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006335 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006336
6337 if (QDF_IS_STATUS_ERROR(status))
6338 return status;
6339
6340 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6341
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006342 return status;
6343}
6344
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006345QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006346 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006347{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306348 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006349
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006350 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006351 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006352 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006353
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006354 return status;
6355}
6356
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006357QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006358 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006359{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306360 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006361 qdf_list_node_t *node;
6362
6363 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006364
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006365 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006366 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006367 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006368
6369 if (QDF_IS_STATUS_ERROR(status))
6370 return status;
6371
6372 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6373
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006374 return status;
6375}
6376
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006377QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006378 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006379{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306380 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006381
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006382 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006383 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006384 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006385
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006386 return status;
6387}
6388
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006389QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006390 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006391{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306392 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006393
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006394 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006395 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006396 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006397
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006398 return status;
6399}
6400
Jeff Johnson9d295242017-08-29 14:39:48 -07006401struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006402 tSirMacAddr macAddr)
6403{
Jeff Johnson9d295242017-08-29 14:39:48 -07006404 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006405
Dustin Brown920397d2017-12-13 16:27:50 -08006406 hdd_for_each_adapter(hdd_ctx, adapter) {
6407 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
6408 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006409 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006410 }
6411
6412 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006413}
6414
Jeff Johnson9d295242017-08-29 14:39:48 -07006415struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006416 uint32_t vdev_id)
6417{
Jeff Johnson9d295242017-08-29 14:39:48 -07006418 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006419
Dustin Brown920397d2017-12-13 16:27:50 -08006420 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07006421 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006422 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006423 }
6424
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006425 return NULL;
6426}
6427
Abhishek Singh7996eb72015-12-30 17:24:02 +05306428/**
6429 * hdd_get_adapter_by_sme_session_id() - Return adapter with
6430 * the sessionid
6431 * @hdd_ctx: hdd context.
6432 * @sme_session_id: sme session is for the adapter to get.
6433 *
6434 * This function is used to get the adapter with provided session id
6435 *
6436 * Return: adapter pointer if found
6437 *
6438 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07006439struct hdd_adapter *
6440hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
6441 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306442{
Jeff Johnson9d295242017-08-29 14:39:48 -07006443 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306444
Dustin Brown920397d2017-12-13 16:27:50 -08006445 hdd_for_each_adapter(hdd_ctx, adapter) {
6446 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306447 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306448 }
Dustin Brown920397d2017-12-13 16:27:50 -08006449
Abhishek Singh7996eb72015-12-30 17:24:02 +05306450 return NULL;
6451}
6452
Jeff Johnson9d295242017-08-29 14:39:48 -07006453struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07006454 const char *iface_name)
6455{
Jeff Johnson9d295242017-08-29 14:39:48 -07006456 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006457
Dustin Brown920397d2017-12-13 16:27:50 -08006458 hdd_for_each_adapter(hdd_ctx, adapter) {
6459 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07006460 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006461 }
Dustin Brown920397d2017-12-13 16:27:50 -08006462
Naveen Rawat4edb6822017-04-12 10:09:17 -07006463 return NULL;
6464}
6465
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006466/**
6467 * hdd_get_adapter() - to get adapter matching the mode
6468 * @hdd_ctx: hdd context
6469 * @mode: adapter mode
6470 *
6471 * This routine will return the pointer to adapter matching
6472 * with the passed mode.
6473 *
6474 * Return: pointer to adapter or null
6475 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006476struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006477 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006478{
Jeff Johnson9d295242017-08-29 14:39:48 -07006479 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006480
Dustin Brown920397d2017-12-13 16:27:50 -08006481 hdd_for_each_adapter(hdd_ctx, adapter) {
6482 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006483 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006484 }
6485
6486 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006487}
6488
Jeff Johnson36a0abf2018-05-20 11:24:25 -07006489enum QDF_OPMODE hdd_get_device_mode(uint32_t session_id)
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306490{
6491 struct hdd_context *hdd_ctx;
6492 struct hdd_adapter *adapter;
6493
6494 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
6495 if (!hdd_ctx) {
6496 hdd_err("Invalid HDD context");
6497 return QDF_MAX_NO_OF_MODE;
6498 }
6499
6500 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
6501 if (!adapter) {
6502 hdd_err("Invalid HDD adapter");
6503 return QDF_MAX_NO_OF_MODE;
6504 }
6505
6506 return adapter->device_mode;
6507}
6508
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006509/**
6510 * hdd_get_operating_channel() - return operating channel of the device mode
6511 * @hdd_ctx: Pointer to the HDD context.
6512 * @mode: Device mode for which operating channel is required.
Jeff Johnson77f89bb2018-05-06 16:21:36 -07006513 * Supported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006514 * QDF_STA_MODE,
6515 * QDF_P2P_CLIENT_MODE,
6516 * QDF_SAP_MODE,
6517 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006518 *
6519 * This API returns the operating channel of the requested device mode
6520 *
6521 * Return: channel number. "0" id the requested device is not found OR it is
6522 * not connected.
6523 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006524uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006525 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006526{
Jeff Johnson9d295242017-08-29 14:39:48 -07006527 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006528 uint8_t operatingChannel = 0;
6529
Dustin Brown920397d2017-12-13 16:27:50 -08006530 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006531 if (mode == adapter->device_mode) {
6532 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006533 case QDF_STA_MODE:
6534 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006535 if (hdd_conn_is_connected
6536 (WLAN_HDD_GET_STATION_CTX_PTR
6537 (adapter))) {
6538 operatingChannel =
6539 (WLAN_HDD_GET_STATION_CTX_PTR
6540 (adapter))->conn_info.
6541 operationChannel;
6542 }
6543 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006544 case QDF_SAP_MODE:
6545 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006546 /* softap connection info */
6547 if (test_bit
6548 (SOFTAP_BSS_STARTED,
6549 &adapter->event_flags))
6550 operatingChannel =
6551 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07006552 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006553 break;
6554 default:
6555 break;
6556 }
6557
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006558 /* Found the device of interest. break the loop */
6559 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006560 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006561 }
Dustin Brown920397d2017-12-13 16:27:50 -08006562
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006563 return operatingChannel;
6564}
6565
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006566static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006567 hdd_ctx)
6568{
Jeff Johnson9d295242017-08-29 14:39:48 -07006569 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006570
Dustin Brown491d54b2018-03-14 12:39:11 -07006571 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006572
Dustin Brown920397d2017-12-13 16:27:50 -08006573 hdd_for_each_adapter(hdd_ctx, adapter) {
6574 if (adapter->device_mode == QDF_STA_MODE ||
6575 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6576 adapter->device_mode == QDF_IBSS_MODE ||
6577 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6578 adapter->device_mode == QDF_SAP_MODE ||
6579 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006580 hdd_unregister_wext(adapter->dev);
6581 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006582 }
6583
Dustin Browne74003f2018-03-14 12:51:58 -07006584 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006585
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306586 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006587}
6588
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006589QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006590{
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) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006602 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006603 adapter->session_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05306604 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006605 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006606 }
6607
Dustin Browne74003f2018-03-14 12:51:58 -07006608 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006609
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306610 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006611}
6612
Dustin Brownf27bce82016-11-03 12:52:27 -07006613/**
6614 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
6615 * adapters
6616 * @hdd_ctx: The HDD context containing the adapters to operate on
6617 *
6618 * return: QDF_STATUS_SUCCESS
6619 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006620static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07006621{
Jeff Johnson9d295242017-08-29 14:39:48 -07006622 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07006623 int err;
6624
Dustin Brown491d54b2018-03-14 12:39:11 -07006625 hdd_enter();
Dustin Brownf27bce82016-11-03 12:52:27 -07006626
Dustin Brown920397d2017-12-13 16:27:50 -08006627 hdd_for_each_adapter(hdd_ctx, adapter) {
6628 if (adapter->device_mode == QDF_STA_MODE ||
6629 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6630 adapter->device_mode == QDF_IBSS_MODE ||
6631 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6632 adapter->device_mode == QDF_SAP_MODE ||
6633 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07006634 err = wlan_hdd_sched_scan_stop(adapter->dev);
6635 if (err)
6636 hdd_err("Unable to stop scheduled scan");
6637 }
Dustin Brownf27bce82016-11-03 12:52:27 -07006638 }
6639
Dustin Browne74003f2018-03-14 12:51:58 -07006640 hdd_exit();
Dustin Brownf27bce82016-11-03 12:52:27 -07006641
6642 return QDF_STATUS_SUCCESS;
6643}
6644
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006645#ifdef WLAN_NS_OFFLOAD
6646/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006647 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006648 * @hdd_ctx: Pointer to hdd context
6649 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006650 * Unregister for IPv6 address change notifications.
6651 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006652 * Return: None
6653 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006654static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006655{
6656 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006657}
6658
6659/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006660 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006661 * @hdd_ctx: Pointer to hdd context
6662 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006663 * Register for IPv6 address change notifications.
6664 *
6665 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006666 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006667static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006668{
6669 int ret;
6670
6671 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
6672 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006673 if (ret) {
6674 hdd_err("Failed to register IPv6 notifier: %d", ret);
6675 goto out;
6676 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006677
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006678 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006679out:
6680 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006681}
6682#else
6683/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006684 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006685 * @hdd_ctx: Pointer to hdd context
6686 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006687 * Unregister for IPv6 address change notifications.
6688 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006689 * Return: None
6690 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006691static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006692{
6693}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006694
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006695/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006696 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006697 * @hdd_ctx: Pointer to hdd context
6698 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006699 * Register for IPv6 address change notifications.
6700 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006701 * Return: None
6702 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006703static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006704{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006705 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006706}
6707#endif
6708
Alok Kumarb64650c2018-03-23 17:05:11 +05306709void hdd_set_disconnect_status(struct hdd_adapter *adapter, bool status)
6710{
6711 qdf_mutex_acquire(&adapter->disconnection_status_lock);
6712 adapter->disconnection_in_progress = status;
6713 qdf_mutex_release(&adapter->disconnection_status_lock);
6714 hdd_debug("setting disconnection status: %d", status);
6715}
6716
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006717/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006718 * hdd_register_notifiers - Register netdev notifiers.
6719 * @hdd_ctx: HDD context
6720 *
6721 * Register netdev notifiers like IPv4 and IPv6.
6722 *
6723 * Return: 0 on success and errno on failure
6724 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006725static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006726{
6727 int ret;
6728
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006729 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
6730 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306731 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006732
6733 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
6734 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
6735 if (ret) {
6736 hdd_err("Failed to register IPv4 notifier: %d", ret);
6737 goto unregister_ip6_notifier;
6738 }
6739
Alok Kumarb64650c2018-03-23 17:05:11 +05306740 ret = hdd_nud_register_netevent_notifier(hdd_ctx);
6741 if (ret) {
6742 hdd_err("Failed to register netevent notifier: %d",
6743 ret);
6744 goto unregister_inetaddr_notifier;
6745 }
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006746 return 0;
6747
Alok Kumarb64650c2018-03-23 17:05:11 +05306748unregister_inetaddr_notifier:
6749 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006750unregister_ip6_notifier:
6751 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006752out:
6753 return ret;
6754
6755}
6756
6757/**
6758 * hdd_unregister_notifiers - Unregister netdev notifiers.
6759 * @hdd_ctx: HDD context
6760 *
6761 * Unregister netdev notifiers like IPv4 and IPv6.
6762 *
6763 * Return: None.
6764 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006765void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006766{
Alok Kumarb64650c2018-03-23 17:05:11 +05306767 hdd_nud_unregister_netevent_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006768 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
6769
6770 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006771}
6772
6773/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006774 * hdd_exit_netlink_services - Exit netlink services
6775 * @hdd_ctx: HDD context
6776 *
6777 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
6778 * nl service.
6779 *
6780 * Return: None.
6781 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006782static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006783{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306784 spectral_scan_deactivate_service();
6785 cnss_diag_deactivate_service();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006786 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006787 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306788 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006789
6790 nl_srv_exit();
6791}
6792
6793/**
6794 * hdd_init_netlink_services- Init netlink services
6795 * @hdd_ctx: HDD context
6796 *
6797 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
6798 * nl service.
6799 *
6800 * Return: 0 on success and errno on failure.
6801 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006802static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006803{
6804 int ret;
6805
Ryan Hsuceddceb2016-04-28 10:20:14 -07006806 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006807 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006808 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006809 goto out;
6810 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07006811 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006812
Naveen Rawat910726a2017-03-06 11:42:51 -08006813 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006814 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006815 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006816 goto err_nl_srv;
6817 }
6818
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306819 ptt_sock_activate_svc();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006820
6821 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07006822 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006823 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006824
6825 ret = cnss_diag_activate_service();
6826 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006827 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006828 goto err_close_cesium;
6829 }
6830
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306831 spectral_scan_activate_service();
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08006832
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006833 return 0;
6834
6835err_close_cesium:
6836 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006837 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306838 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006839err_nl_srv:
6840 nl_srv_exit();
6841out:
6842 return ret;
6843}
6844
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006845/**
6846 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
6847 * @hdd_ctx: HDD context.
6848 *
6849 * Destroy RX wakelock.
6850 *
6851 * Return: None.
6852 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006853static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006854{
6855 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
6856}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006857
6858/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006859 * hdd_rx_wake_lock_create() - Create RX wakelock
6860 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006861 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006862 * Create RX wakelock.
6863 *
6864 * Return: None.
6865 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006866static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006867{
6868 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
6869}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006870
6871/**
Houston Hoffman160db392016-10-10 17:37:51 -07006872 * hdd_context_deinit() - Deinitialize HDD context
6873 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006874 *
Houston Hoffman160db392016-10-10 17:37:51 -07006875 * Deinitialize HDD context along with all the feature specific contexts but
6876 * do not free hdd context itself. Caller of this API is supposed to free
6877 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006878 *
Houston Hoffman160db392016-10-10 17:37:51 -07006879 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006880 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006881static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006882{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306883 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
6884
Houston Hoffman160db392016-10-10 17:37:51 -07006885 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006886
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006887 hdd_sap_context_destroy(hdd_ctx);
6888
6889 hdd_rx_wake_lock_destroy(hdd_ctx);
6890
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006891 hdd_scan_context_destroy(hdd_ctx);
6892
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006893 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006894
Houston Hoffman160db392016-10-10 17:37:51 -07006895 return 0;
6896}
6897
6898/**
6899 * hdd_context_destroy() - Destroy HDD context
6900 * @hdd_ctx: HDD context to be destroyed.
6901 *
6902 * Free config and HDD context as well as destroy all the resources.
6903 *
6904 * Return: None
6905 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006906static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07006907{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07006908 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05306909
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05306910 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
6911
Houston Hoffman160db392016-10-10 17:37:51 -07006912 hdd_context_deinit(hdd_ctx);
6913
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306914 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006915 hdd_ctx->config = NULL;
6916
Dustin Brown84f46ea2018-02-15 11:57:36 -08006917 cfg_release();
6918
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006919 wiphy_free(hdd_ctx->wiphy);
6920}
6921
6922/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306923 * wlan_destroy_bug_report_lock() - Destroy bug report lock
6924 *
6925 * This function is used to destroy bug report lock
6926 *
6927 * Return: None
6928 */
6929static void wlan_destroy_bug_report_lock(void)
6930{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07006931 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306932
6933 p_cds_context = cds_get_global_context();
6934 if (!p_cds_context) {
6935 hdd_err("cds context is NULL");
6936 return;
6937 }
6938
6939 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6940}
6941
6942/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006943 * hdd_wlan_exit() - HDD WLAN exit function
6944 * @hdd_ctx: Pointer to the HDD Context
6945 *
6946 * This is the driver exit point (invoked during rmmod)
6947 *
6948 * Return: None
6949 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006950static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006951{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006952 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306953 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006954
Dustin Brown491d54b2018-03-14 12:39:11 -07006955 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006956
Arun Khandavallifae92942016-08-01 13:31:08 +05306957 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006958
Prashanth Bhattaab004382016-10-11 16:08:11 -07006959 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006960
6961#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306962 if (QDF_TIMER_STATE_RUNNING ==
6963 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6964 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006965 }
6966
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306967 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306968 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006969 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006970 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006971 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6972 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6973 hdd_ctx->last_acs_channel_list = NULL;
6974 hdd_ctx->num_of_channels = 0;
6975 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006976#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006977
Arun Khandavallifae92942016-08-01 13:31:08 +05306978 mutex_lock(&hdd_ctx->iface_change_lock);
6979 driver_status = hdd_ctx->driver_status;
6980 mutex_unlock(&hdd_ctx->iface_change_lock);
6981
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006982 /*
6983 * Powersave Offload Case
6984 * Disable Idle Power Save Mode
6985 */
6986 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07006987 /* clear the scan queue in all the scenarios */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +05306988 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006989
Arun Khandavallifae92942016-08-01 13:31:08 +05306990 if (driver_status != DRIVER_MODULES_CLOSED) {
6991 hdd_unregister_wext_all_adapters(hdd_ctx);
6992 /*
6993 * Cancel any outstanding scan requests. We are about to close
6994 * all of our adapters, but an adapter structure is what SME
6995 * passes back to our callback function. Hence if there
6996 * are any outstanding scan requests then there is a
6997 * race condition between when the adapter is closed and
6998 * when the callback is invoked. We try to resolve that
6999 * race condition here by canceling any outstanding scans
7000 * before we close the adapters.
7001 * Note that the scans may be cancelled in an asynchronous
7002 * manner, so ideally there needs to be some kind of
7003 * synchronization. Rather than introduce a new
7004 * synchronization here, we will utilize the fact that we are
7005 * about to Request Full Power, and since that is synchronized,
7006 * the expectation is that by the time Request Full Power has
7007 * completed, all scans will be cancelled
7008 */
7009 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07007010 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08007011 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08007012 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007013 }
7014
Arunk Khandavalli830c9692018-03-22 12:17:40 +05307015 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavalli08479ba2017-08-07 19:56:23 +05307016 unregister_netdevice_notifier(&hdd_netdev_notifier);
7017
Rachit Kankane30807332018-06-27 18:39:36 +05307018 qdf_dp_trace_deinit();
7019
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07007020 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05307021
Dustin Brown021cecd2017-12-11 13:56:43 -08007022 hdd_driver_memdump_deinit();
7023
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05307024 qdf_nbuf_deinit_replenish_timer();
7025
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05307026 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
7027 hdd_info("Release wakelock for monitor mode!");
7028 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
7029 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
7030 }
7031
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307032 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
7033 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
7034 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
7035
Naveen Rawate02f8f52018-04-05 11:58:04 -07007036 osif_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007037
Dustin Brownd005ad82018-01-19 10:32:13 -08007038 hdd_close_all_adapters(hdd_ctx, false);
7039
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05307040 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307041 /*
7042 * If there is re_init failure wiphy would have already de-registered
7043 * check the wiphy status before un-registering again
7044 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05307045 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307046 wiphy_unregister(wiphy);
7047 wlan_hdd_cfg80211_deinit(wiphy);
7048 hdd_lpass_notify_stop(hdd_ctx);
7049 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07007050
Arun Khandavallifae92942016-08-01 13:31:08 +05307051 hdd_exit_netlink_services(hdd_ctx);
7052 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307053#ifdef FEATURE_WLAN_CH_AVOID
7054 mutex_destroy(&hdd_ctx->avoid_freq_lock);
7055#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05307056
Abhishek Singhe9068f12017-03-31 14:14:52 +05307057 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
7058 if (driver_status)
7059 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07007060
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007061 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007062}
7063
7064void __hdd_wlan_exit(void)
7065{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007066 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007067
Dustin Brown491d54b2018-03-14 12:39:11 -07007068 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007069
Anurag Chouhan6d760662016-02-20 16:05:43 +05307070 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007071 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007072 hdd_err("Invalid HDD Context");
Dustin Browne74003f2018-03-14 12:51:58 -07007073 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007074 return;
7075 }
7076
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007077 /* Do all the cleanup before deregistering the driver */
7078 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07007079
Dustin Browne74003f2018-03-14 12:51:58 -07007080 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007081}
7082
7083#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04007084/**
7085 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007086 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04007087 *
7088 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
7089 * Then new ACS request will do a fresh scan without reusing the cached
7090 * scan information.
7091 *
7092 * Return: void
7093 */
Tang Yingying523322d2017-01-17 23:28:43 +08007094static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007095{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007096 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Jeff Johnson16528362018-06-14 12:34:16 -07007097 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007098
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007099 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007100 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04007101 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
7102 qdf_mem_free(hdd_ctx->last_acs_channel_list);
7103 hdd_ctx->last_acs_channel_list = NULL;
7104 hdd_ctx->num_of_channels = 0;
7105 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007106
Jeff Johnson16528362018-06-14 12:34:16 -07007107 mac_handle = hdd_ctx->mac_handle;
7108 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007109 return;
Jeff Johnson16528362018-06-14 12:34:16 -07007110 sme_scan_flush_result(mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007111}
7112#endif
7113
7114#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07007115int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
7116 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007117{
7118 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307119 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07007120 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07007121 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007122
7123 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7124
7125 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307126 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007127 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307128
Jeff Johnson16528362018-06-14 12:34:16 -07007129 mac_handle = hdd_ctx->mac_handle;
7130 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007131 return -EINVAL;
7132
Jeff Johnson16528362018-06-14 12:34:16 -07007133 qdf_status = sme_notify_ht2040_mode(mac_handle, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007134 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307135 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007136 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007137 return -EINVAL;
7138 }
7139
7140 return 0;
7141}
7142#endif
7143
7144/**
7145 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
7146 * @state: state
7147 *
7148 * This function notifies FW with modem power status
7149 *
7150 * Return: 0 if successful, error number otherwise
7151 */
7152int hdd_wlan_notify_modem_power_state(int state)
7153{
7154 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307155 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007156 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07007157 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007158
Anurag Chouhan6d760662016-02-20 16:05:43 +05307159 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007160 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307161 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007162 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307163
Jeff Johnson16528362018-06-14 12:34:16 -07007164 mac_handle = hdd_ctx->mac_handle;
7165 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007166 return -EINVAL;
7167
Jeff Johnson16528362018-06-14 12:34:16 -07007168 qdf_status = sme_notify_modem_power_state(mac_handle, state);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307169 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007170 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007171 state);
7172 return -EINVAL;
7173 }
7174 return 0;
7175}
7176
7177/**
7178 *
7179 * hdd_post_cds_enable_config() - HDD post cds start config helper
7180 * @adapter - Pointer to the HDD
7181 *
7182 * Return: None
7183 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007184QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007185{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307186 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007187
7188 /*
7189 * Send ready indication to the HDD. This will kick off the MAC
7190 * into a 'running' state and should kick off an initial scan.
7191 */
Jeff Johnson16528362018-06-14 12:34:16 -07007192 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->mac_handle);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307193 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007194 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
7195 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307196 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007197 }
7198
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307199 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007200}
7201
Sourav Mohapatra92ea8d62018-02-05 10:03:10 +05307202struct hdd_adapter *hdd_get_first_valid_adapter(struct hdd_context *hdd_ctx)
7203{
7204 struct hdd_adapter *adapter;
7205
7206 hdd_for_each_adapter(hdd_ctx, adapter) {
7207 if (adapter && adapter->magic == WLAN_HDD_ADAPTER_MAGIC)
7208 return adapter;
7209 }
7210
7211 return NULL;
7212}
7213
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007214/* wake lock APIs for HDD */
7215void hdd_prevent_suspend(uint32_t reason)
7216{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307217 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007218}
7219
7220void hdd_allow_suspend(uint32_t reason)
7221{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307222 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007223}
7224
7225void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
7226{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05307227 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
7228 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007229}
7230
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007231/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007232QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007233{
Jeff Johnson16528362018-06-14 12:34:16 -07007234 return sme_init_chan_list(hdd_ctx->mac_handle,
Amar Singhal6f8592b2017-04-26 14:31:58 -07007235 hdd_ctx->reg.alpha2,
7236 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007237}
7238
7239/**
7240 * hdd_is_5g_supported() - check if hardware supports 5GHz
7241 * @hdd_ctx: Pointer to the hdd context
7242 *
7243 * HDD function to know if hardware supports 5GHz
7244 *
7245 * Return: true if hardware supports 5GHz
7246 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007247bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007248{
Amar Singhal58b45ef2017-08-01 13:43:54 -07007249 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08007250 return true;
7251
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08007252 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08007253 return true;
7254 else
7255 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007256}
7257
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007258static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007259{
7260 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07007261 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007262
7263 wiphy = hdd_ctx->wiphy;
7264
7265 /*
7266 * The channel information in
7267 * wiphy needs to be initialized before wiphy registration
7268 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007269 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
7270 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007271 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07007272 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007273 }
7274
7275#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
7276 wiphy->wowlan = &wowlan_support_reg_init;
7277#else
7278 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
7279 WIPHY_WOWLAN_MAGIC_PKT |
7280 WIPHY_WOWLAN_DISCONNECT |
7281 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
7282 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
7283 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
7284 WIPHY_WOWLAN_4WAY_HANDSHAKE |
7285 WIPHY_WOWLAN_RFKILL_RELEASE;
7286
7287 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
7288 WOW_MAX_FILTERS_PER_LIST);
7289 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
7290 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
7291#endif
Liangwei Dong0da14262018-07-03 03:30:23 -04007292 if (hdd_ctx->obss_scan_offload) {
7293 hdd_debug("wmi_service_obss_scan supported");
7294 } else if (hdd_ctx->config->nChannelBondingMode24GHz) {
7295 hdd_debug("enable wpa_supp obss_scan");
7296 wiphy->features |= NL80211_FEATURE_NEED_OBSS_SCAN;
7297 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007298
7299 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007300 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307301 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07007302 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307303 return ret_val;
7304 }
Amar Singhalac26de22018-06-22 12:53:06 -07007305
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007306 /* Check the kernel version for upstream commit aced43ce780dc5 that
7307 * has support for processing user cell_base hints when wiphy is
7308 * self managed or check the backport flag for the same.
7309 */
Amar Singhalac26de22018-06-22 12:53:06 -07007310#if defined CFG80211_USER_HINT_CELL_BASE_SELF_MANAGED || \
7311 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0))
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007312 hdd_send_wiphy_regd_sync_event(hdd_ctx);
7313#endif
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307314
Amar Singhal2d812012018-02-03 15:06:47 +08007315 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007316
Amar Singhale4f28ee2015-10-21 14:36:56 -07007317 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007318}
7319
Mohit Khannaca4173b2017-09-12 21:52:19 -07007320#ifdef MSM_PLATFORM
7321/**
7322 * hdd_display_periodic_stats() - Function to display periodic stats
7323 * @hdd_ctx - handle to hdd context
7324 * @bool data_in_interval - true, if data detected in bw time interval
7325 *
7326 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
7327 * Stats show up in wlan driver logs.
7328 *
7329 * Returns: None
7330 */
7331static inline
7332void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
7333 bool data_in_interval)
7334{
7335 static u32 counter;
7336 static bool data_in_time_period;
7337 ol_txrx_pdev_handle pdev;
7338
7339 if (hdd_ctx->config->periodic_stats_disp_time == 0)
7340 return;
7341
7342 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
7343 if (!pdev) {
7344 hdd_err("pdev is NULL");
7345 return;
7346 }
7347
7348 counter++;
7349 if (data_in_interval)
7350 data_in_time_period = data_in_interval;
7351
7352 if (counter * hdd_ctx->config->busBandwidthComputeInterval >=
7353 hdd_ctx->config->periodic_stats_disp_time * 1000) {
7354 if (data_in_time_period) {
7355 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
7356 CDP_TXRX_PATH_STATS,
7357 QDF_STATS_VERBOSITY_LEVEL_LOW);
7358 wlan_hdd_display_netif_queue_history
7359 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
7360 qdf_dp_trace_dump_stats();
7361 }
7362 counter = 0;
7363 data_in_time_period = false;
7364 }
7365}
7366
Ravi Joshie2331e82015-07-01 18:18:54 -07007367/**
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007368 * hdd_clear_rps_cpu_mask - clear RPS CPU mask for interfaces
7369 * @hdd_ctx: pointer to struct hdd_context
7370 *
7371 * Return: none
7372 */
7373static void hdd_clear_rps_cpu_mask(struct hdd_context *hdd_ctx)
7374{
7375 struct hdd_adapter *adapter;
7376
7377 hdd_for_each_adapter(hdd_ctx, adapter)
7378 hdd_send_rps_disable_ind(adapter);
7379}
7380
7381/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07007382 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07007383 * @hdd_ctx - handle to hdd context
7384 * @tx_packets - transmit packet count
7385 * @rx_packets - receive packet count
7386 *
7387 * The function controls the bus bandwidth and dynamic control of
7388 * tcp delayed ack configuration
7389 *
7390 * Returns: None
7391 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007392
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007393static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07007394 const uint64_t tx_packets,
7395 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007396{
Mohit Khannaca4173b2017-09-12 21:52:19 -07007397 u64 total_pkts = tx_packets + rx_packets;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007398 uint64_t temp_tx = 0, avg_rx = 0;
7399 uint64_t no_rx_offload_pkts = 0, avg_no_rx_offload_pkts = 0;
7400 uint64_t rx_offload_pkts = 0, avg_rx_offload_pkts = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007401 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08007402 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08007403 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007404 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007405 uint16_t index = 0;
7406 bool vote_level_change = false;
7407 bool rx_level_change = false;
7408 bool tx_level_change = false;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007409 bool rxthread_high_tput_req = false;
Mohit Khannaf7562c32018-07-05 17:42:36 -07007410 bool dptrace_high_tput_req;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007411 if (total_pkts > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007412 next_vote_level = PLD_BUS_WIDTH_HIGH;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007413 else if (total_pkts > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007414 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007415 else if (total_pkts > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007416 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07007417 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07007418 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007419
Mohit Khannaf7562c32018-07-05 17:42:36 -07007420 dptrace_high_tput_req =
7421 next_vote_level > PLD_BUS_WIDTH_NONE ? true : false;
7422
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007423 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07007424 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
7425 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007426 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007427 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007428 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007429 if ((next_vote_level == PLD_BUS_WIDTH_LOW) ||
7430 (next_vote_level == PLD_BUS_WIDTH_NONE)) {
Nirav Shahffc6a092016-06-09 16:09:08 +05307431 if (hdd_ctx->hbw_requested) {
7432 pld_remove_pm_qos(hdd_ctx->parent_dev);
7433 hdd_ctx->hbw_requested = false;
7434 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007435 if (hdd_ctx->dynamic_rps)
7436 hdd_clear_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007437 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05307438 if (!hdd_ctx->hbw_requested) {
7439 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
7440 hdd_ctx->hbw_requested = true;
7441 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007442 if (hdd_ctx->dynamic_rps)
7443 hdd_set_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007444 }
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007445
Manjunathappa Prakashcb6df762018-05-29 18:54:58 -07007446 if (hdd_ctx->config->napi_cpu_affinity_mask)
7447 hdd_napi_apply_throughput_policy(hdd_ctx,
7448 tx_packets,
7449 rx_packets);
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007450
7451 if (rx_packets < hdd_ctx->config->busBandwidthLowThreshold)
7452 hdd_disable_rx_ol_for_low_tput(hdd_ctx, true);
7453 else
7454 hdd_disable_rx_ol_for_low_tput(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007455 }
Mohit Khannae71e2262015-11-10 09:37:24 -08007456
Mohit Khannaf7562c32018-07-05 17:42:36 -07007457 qdf_dp_trace_apply_tput_policy(dptrace_high_tput_req);
7458
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007459 /*
7460 * Includes tcp+udp, if perf core is required for tcp, then
7461 * perf core is also required for udp.
7462 */
7463 no_rx_offload_pkts = hdd_ctx->no_rx_offload_pkt_cnt;
7464 hdd_ctx->no_rx_offload_pkt_cnt = 0;
7465 rx_offload_pkts = rx_packets - no_rx_offload_pkts;
Mohit Khannae71e2262015-11-10 09:37:24 -08007466
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007467 avg_no_rx_offload_pkts = (no_rx_offload_pkts +
7468 hdd_ctx->prev_no_rx_offload_pkts) / 2;
7469 hdd_ctx->prev_no_rx_offload_pkts = no_rx_offload_pkts;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08007470
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007471 avg_rx_offload_pkts = (rx_offload_pkts +
7472 hdd_ctx->prev_rx_offload_pkts) / 2;
7473 hdd_ctx->prev_rx_offload_pkts = rx_offload_pkts;
7474
7475 avg_rx = avg_no_rx_offload_pkts + avg_rx_offload_pkts;
7476 /*
7477 * Takes care to set Rx_thread affinity for below case
7478 * 1)LRO/GRO not supported ROME case
7479 * 2)when rx_ol is disabled in cases like concurrency etc
7480 * 3)For UDP cases
7481 */
7482 if (avg_no_rx_offload_pkts >
7483 hdd_ctx->config->busBandwidthHighThreshold)
7484 rxthread_high_tput_req = true;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307485 else
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007486 rxthread_high_tput_req = false;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307487
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007488 if (cds_sched_handle_throughput_req(rxthread_high_tput_req))
7489 hdd_warn("Rx thread high_tput(%d) affinity request failed",
7490 rxthread_high_tput_req);
7491
7492 /* fine-tuning parameters for RX Flows */
7493 if (avg_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
Ravi Joshifed83572016-10-07 16:20:37 -07007494 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
7495 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
7496 next_rx_level = WLAN_SVC_TP_HIGH;
7497 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07007498 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07007499 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08007500 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007501 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007502
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007503 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007504 struct wlan_rx_tp_data rx_tp_data = {0};
7505
Ravi Joshie2331e82015-07-01 18:18:54 -07007506 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Jeff Johnsonb9feee42018-07-08 10:34:48 -07007507 next_rx_level, avg_rx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007508 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007509 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07007510 /* Send throughput indication only if it is enabled.
7511 * Disabling tcp_del_ack will revert the tcp stack behavior
7512 * to default delayed ack. Note that this will disable the
7513 * dynamic delayed ack mechanism across the system
7514 */
Manjunathappa Prakashbfd12762018-04-29 22:44:52 -07007515 if (hdd_ctx->en_tcp_delack_no_lro)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007516 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
7517
Mohit Khanna6272fb682017-04-13 09:34:36 -07007518 if (hdd_ctx->config->enable_tcp_adv_win_scale)
7519 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
7520
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007521 rx_tp_data.level = next_rx_level;
7522 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7523 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
7524 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007525 }
7526
Mohit Khannae71e2262015-11-10 09:37:24 -08007527 /* fine-tuning parameters for TX Flows */
7528 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
7529 hdd_ctx->prev_tx = tx_packets;
7530 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
7531 next_tx_level = WLAN_SVC_TP_HIGH;
7532 else
7533 next_tx_level = WLAN_SVC_TP_LOW;
7534
Prakash Manjunathappae73e3b52018-02-27 18:56:22 -08007535 if ((hdd_ctx->config->enable_tcp_limit_output) &&
7536 (hdd_ctx->cur_tx_level != next_tx_level)) {
Mohit Khannae71e2262015-11-10 09:37:24 -08007537 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
7538 next_tx_level, temp_tx);
7539 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007540 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05307541 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7542 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08007543 &next_tx_level,
7544 sizeof(next_tx_level));
7545 }
7546
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007547 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007548 if (vote_level_change || tx_level_change || rx_level_change) {
7549 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
7550 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
7551 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
7552 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
7553 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
7554 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
7555 hdd_ctx->hdd_txrx_hist_idx++;
7556 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
7557 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07007558
7559 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007560}
7561
7562#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307563static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007564{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007565 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307566 bus_bw_work);
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307567 struct hdd_adapter *adapter = NULL, *con_sap_adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307568 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05307569 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
7570 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007571 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307572 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007573 bool connected = false;
7574 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
7575
Prashanth Bhattaab004382016-10-11 16:08:11 -07007576 if (wlan_hdd_validate_context(hdd_ctx))
7577 return;
7578
Jeff Johnson214671b2017-10-30 19:45:23 -07007579 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08007580 goto restart_timer;
7581
Dustin Brown920397d2017-12-13 16:27:50 -08007582 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05307583 /*
7584 * Validate magic so we don't end up accessing
7585 * an invalid adapter.
7586 */
7587 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
7588 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007589
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007590 if ((adapter->device_mode == QDF_STA_MODE ||
7591 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007592 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
7593 != eConnectionState_Associated) {
7594
7595 continue;
7596 }
7597
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007598 if ((adapter->device_mode == QDF_SAP_MODE ||
7599 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07007600 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007601
7602 continue;
7603 }
7604
7605 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
7606 adapter->prev_tx_packets);
7607 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
7608 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307609
7610 if (adapter->device_mode == QDF_SAP_MODE ||
7611 adapter->device_mode == QDF_P2P_GO_MODE ||
7612 adapter->device_mode == QDF_IBSS_MODE) {
7613
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08007614 ret = cdp_get_intra_bss_fwd_pkts_count(
7615 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007616 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307617 &fwd_tx_packets, &fwd_rx_packets);
7618 if (ret == A_OK) {
7619 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
7620 fwd_tx_packets,
7621 adapter->prev_fwd_tx_packets);
7622 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
7623 fwd_tx_packets,
7624 adapter->prev_fwd_rx_packets);
7625 }
7626 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007627
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307628 if (adapter->device_mode == QDF_SAP_MODE)
7629 con_sap_adapter = adapter;
7630
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007631 total_rx += adapter->stats.rx_packets;
7632 total_tx += adapter->stats.tx_packets;
7633
7634 spin_lock_bh(&hdd_ctx->bus_bw_lock);
7635 adapter->prev_tx_packets = adapter->stats.tx_packets;
7636 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307637 adapter->prev_fwd_tx_packets = fwd_tx_packets;
7638 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007639 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
7640 connected = true;
7641 }
7642
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007643 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007644 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007645 return;
7646 }
7647
Yun Parka29974a2018-04-09 12:05:49 -07007648 /* add intra bss forwarded tx and rx packets */
7649 tx_packets += fwd_tx_packets_diff;
7650 rx_packets += fwd_rx_packets_diff;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007651
Yun Parka29974a2018-04-09 12:05:49 -07007652 if (ucfg_ipa_is_fw_wdi_activated(hdd_ctx->hdd_pdev)) {
7653 ucfg_ipa_uc_stat_query(hdd_ctx->hdd_pdev, &ipa_tx_packets,
7654 &ipa_rx_packets);
7655 tx_packets += (uint64_t)ipa_tx_packets;
7656 rx_packets += (uint64_t)ipa_rx_packets;
7657
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307658 if (con_sap_adapter) {
7659 con_sap_adapter->stats.tx_packets += ipa_tx_packets;
7660 con_sap_adapter->stats.rx_packets += ipa_rx_packets;
7661 }
7662
Yun Parka29974a2018-04-09 12:05:49 -07007663 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, tx_packets, rx_packets);
7664 ucfg_ipa_uc_stat_request(hdd_ctx->hdd_pdev, 2);
7665 }
7666
7667 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007668
Jingxiang Gec64e1932017-08-22 14:38:59 +08007669restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08007670 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08007671 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08007672 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05307673 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08007674 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08007675 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007676}
Prashanth Bhattaab004382016-10-11 16:08:11 -07007677
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307678/**
7679 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
7680 * @arg: Argument of timer function
7681 *
7682 * Schedule a workqueue in this function where all the processing is done.
7683 *
7684 * Return: None.
7685 */
7686static void __hdd_bus_bw_cbk(void *arg)
7687{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007688 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307689
7690 if (wlan_hdd_validate_context(hdd_ctx))
7691 return;
7692
7693 schedule_work(&hdd_ctx->bus_bw_work);
7694}
7695
7696/**
7697 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
7698 * @arg: Argument of timer function
7699 *
7700 * Return: None.
7701 */
7702static void hdd_bus_bw_cbk(void *arg)
7703{
7704 cds_ssr_protect(__func__);
7705 __hdd_bus_bw_cbk(arg);
7706 cds_ssr_unprotect(__func__);
7707}
7708
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007709int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007710{
7711 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307712 INIT_WORK(&hdd_ctx->bus_bw_work,
7713 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08007714 hdd_ctx->bus_bw_timer_running = false;
7715 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307716 qdf_timer_init(NULL,
7717 &hdd_ctx->bus_bw_timer,
7718 hdd_bus_bw_cbk, (void *)hdd_ctx,
7719 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007720
7721 return 0;
7722}
7723
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007724void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007725{
Dustin Brownfce08d12017-01-17 16:29:38 -08007726 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007727 hdd_reset_tcp_delack(hdd_ctx);
7728
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007729 hdd_debug("wait for bus bw work to flush");
Nirav Shaheb017be2018-02-15 11:20:58 +05307730 hdd_cancel_bus_bw_work(hdd_ctx);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307731 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08007732 hdd_ctx->bus_bw_timer_running = false;
7733 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007734}
Lin Baic5c06882017-09-21 13:58:43 +08007735
7736void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
7737{
7738 if (hdd_ctx)
7739 cancel_work_sync(&hdd_ctx->bus_bw_work);
7740}
jiadcdaf9bd2017-10-26 12:20:21 +08007741
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007742#endif
7743
7744/**
Nirav Shahed34b212016-04-25 10:59:16 +05307745 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
7746 * @hdd_ctx: hdd context
7747 *
7748 * Return: 0 for success or error code
7749 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007750static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307751{
7752 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
7753 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
7754 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007755 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05307756 return -ENOMEM;
7757 }
7758 return 0;
7759}
7760
7761/**
7762 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
7763 * @hdd_ctx: hdd context
7764 *
7765 * Return: none
7766 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007767void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307768{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307769 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
7770 return;
7771
7772 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
7773 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05307774}
7775
Nirav Shahda008342016-05-17 18:50:40 +05307776static uint8_t *convert_level_to_string(uint32_t level)
7777{
7778 switch (level) {
7779 /* initialize the wlan sub system */
7780 case WLAN_SVC_TP_NONE:
7781 return "NONE";
7782 case WLAN_SVC_TP_LOW:
7783 return "LOW";
7784 case WLAN_SVC_TP_MEDIUM:
7785 return "MED";
7786 case WLAN_SVC_TP_HIGH:
7787 return "HIGH";
7788 default:
7789 return "INVAL";
7790 }
7791}
7792
Nirav Shahed34b212016-04-25 10:59:16 +05307793
7794/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007795 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
7796 * @hdd_ctx: hdd context
7797 *
7798 * Return: none
7799 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007800void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007801{
7802 int i;
7803
7804#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007805 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05307806 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007807 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007808 hdd_ctx->config->busBandwidthHighThreshold,
7809 hdd_ctx->config->busBandwidthMediumThreshold,
7810 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007811 hdd_debug("Enable TCP DEL ACK: %d",
Manjunathappa Prakashbfd12762018-04-29 22:44:52 -07007812 hdd_ctx->en_tcp_delack_no_lro);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007813 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007814 hdd_ctx->config->tcpDelackThresholdHigh,
7815 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007816 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05307817 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007818#endif
7819
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007820 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307821 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
7822
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007823 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007824
7825 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007826 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007827 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Dustin Brown632af712018-03-14 15:03:55 -07007828 hdd_debug("[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
7829 i, hdd_ctx->hdd_txrx_hist[i].qtime,
7830 hdd_ctx->hdd_txrx_hist[i].interval_rx,
7831 hdd_ctx->hdd_txrx_hist[i].interval_tx,
7832 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007833 hdd_ctx->hdd_txrx_hist[i].
7834 next_vote_level),
Dustin Brown632af712018-03-14 15:03:55 -07007835 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007836 hdd_ctx->hdd_txrx_hist[i].
7837 next_rx_level),
Dustin Brown632af712018-03-14 15:03:55 -07007838 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007839 hdd_ctx->hdd_txrx_hist[i].
7840 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007841 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007842}
7843
7844/**
7845 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
7846 * @hdd_ctx: hdd context
7847 *
7848 * Return: none
7849 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007850void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007851{
7852 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05307853 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
7854 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007855}
7856
Mohit Khannaca4173b2017-09-12 21:52:19 -07007857/* length of the netif queue log needed per adapter */
7858#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
7859
7860/**
7861 *
7862 * hdd_display_netif_queue_history_compact() - display compact netifq history
7863 * @hdd_ctx: hdd context
7864 *
7865 * Return: none
7866 */
7867static void
7868hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
7869{
7870 int adapter_num = 0;
7871 int i;
7872 int bytes_written;
7873 u32 tbytes;
7874 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007875 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08007876 char *comb_log_str;
7877 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007878 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007879
Dustin Brownbee82832018-07-23 10:10:51 -07007880 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * CSR_ROAM_SESSION_MAX) + 1;
jiadbdefb252018-01-03 14:27:06 +08007881 comb_log_str = qdf_mem_malloc(comb_log_str_size);
7882 if (!comb_log_str) {
7883 hdd_err("failed to alloc comb_log_str");
7884 return;
7885 }
7886
Mohit Khannaca4173b2017-09-12 21:52:19 -07007887 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007888
Dustin Brown920397d2017-12-13 16:27:50 -08007889 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007890 curr_time = qdf_system_ticks();
7891 total = curr_time - adapter->start_time;
7892 delta = curr_time - adapter->last_time;
7893
7894 if (adapter->pause_map) {
7895 pause = adapter->total_pause_time + delta;
7896 unpause = adapter->total_unpause_time;
7897 } else {
7898 unpause = adapter->total_unpause_time + delta;
7899 pause = adapter->total_pause_time;
7900 }
7901
7902 tbytes = 0;
7903 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7904 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7905 if (adapter->queue_oper_stats[i].pause_count == 0)
7906 continue;
7907 tbytes +=
7908 snprintf(
7909 &temp_str[tbytes],
7910 (tbytes >= sizeof(temp_str) ?
7911 0 : sizeof(temp_str) - tbytes),
7912 "%d(%d,%d) ",
7913 i,
7914 adapter->queue_oper_stats[i].
7915 pause_count,
7916 adapter->queue_oper_stats[i].
7917 unpause_count);
7918 }
7919 if (tbytes >= sizeof(temp_str))
7920 hdd_warn("log truncated");
7921
7922 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08007923 bytes_written >= comb_log_str_size ? 0 :
7924 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007925 "[%d %d] (%d) %u/%ums %s|",
7926 adapter->session_id, adapter->device_mode,
7927 adapter->pause_map,
7928 qdf_system_ticks_to_msecs(pause),
7929 qdf_system_ticks_to_msecs(total),
7930 temp_str);
7931
Mohit Khannaca4173b2017-09-12 21:52:19 -07007932 adapter_num++;
7933 }
7934
7935 /* using QDF_TRACE to avoid printing function name */
7936 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
7937 "STATS |%s", comb_log_str);
7938
jiadbdefb252018-01-03 14:27:06 +08007939 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007940 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08007941
7942 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007943}
7944
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007945/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007946 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07007947 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007948 *
7949 * Return: none
7950 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007951void
7952wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
7953 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007954{
7955
Jeff Johnson9d295242017-08-29 14:39:48 -07007956 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007957 int i;
Nirav Shahda008342016-05-17 18:50:40 +05307958 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007959
Mohit Khannaca4173b2017-09-12 21:52:19 -07007960 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
7961 hdd_display_netif_queue_history_compact(hdd_ctx);
7962 return;
7963 }
7964
Dustin Brown920397d2017-12-13 16:27:50 -08007965 hdd_for_each_adapter(hdd_ctx, adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007966 hdd_debug("Netif queue operation statistics:");
7967 hdd_debug("Session_id %d device mode %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07007968 adapter->session_id, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007969 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05307970 curr_time = qdf_system_ticks();
7971 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05307972 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05307973 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05307974 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307975 unpause = adapter->total_unpause_time;
7976 } else {
Nirav Shahda008342016-05-17 18:50:40 +05307977 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307978 pause = adapter->total_pause_time;
7979 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007980 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05307981 qdf_system_ticks_to_msecs(total),
7982 qdf_system_ticks_to_msecs(pause),
7983 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007984 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007985
Nirav Shahda008342016-05-17 18:50:40 +05307986 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7987 qdf_time_t pause_delta = 0;
7988
7989 if (adapter->pause_map & (1 << i))
7990 pause_delta = delta;
7991
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007992 /* using hdd_log to avoid printing function name */
Dustin Brown632af712018-03-14 15:03:55 -07007993 hdd_debug("%s: %d: %d: %ums",
7994 hdd_reason_type_to_string(i),
7995 adapter->queue_oper_stats[i].pause_count,
7996 adapter->queue_oper_stats[i].unpause_count,
7997 qdf_system_ticks_to_msecs(
7998 adapter->queue_oper_stats[i].total_pause_time +
7999 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008000 }
8001
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008002 hdd_debug("Netif queue operation history:");
8003 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05308004 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
8005
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008006 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008007
8008 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07008009 /* using hdd_log to avoid printing function name */
8010 if (adapter->queue_oper_history[i].time == 0)
8011 continue;
Dustin Brown632af712018-03-14 15:03:55 -07008012 hdd_debug("%d: %u: %s: %s: %x",
8013 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008014 adapter->queue_oper_history[i].time),
Dustin Brown632af712018-03-14 15:03:55 -07008015 hdd_action_type_to_string(
8016 adapter->queue_oper_history[i].netif_action),
8017 hdd_reason_type_to_string(
8018 adapter->queue_oper_history[i].netif_reason),
8019 adapter->queue_oper_history[i].pause_map);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008020 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008021 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008022}
8023
8024/**
8025 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
8026 * @hdd_ctx: hdd context
8027 *
8028 * Return: none
8029 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008030void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008031{
Jeff Johnson9d295242017-08-29 14:39:48 -07008032 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008033
Dustin Brown920397d2017-12-13 16:27:50 -08008034 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308035 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008036 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308037 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008038 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05308039 adapter->history_index = 0;
8040 adapter->start_time = adapter->last_time = qdf_system_ticks();
8041 adapter->total_pause_time = 0;
8042 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008043 }
8044}
8045
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008046#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
8047/**
8048 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
8049 * @hdd_ctx: hdd global context
8050 *
8051 * Return: none
8052 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008053static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008054{
8055 uint8_t i;
8056
8057 mutex_init(&hdd_ctx->op_ctx.op_lock);
8058 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
8059 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
8060 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
8061 }
8062}
8063#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008064static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008065{
8066}
8067#endif
8068
Yingying Tang95409972016-10-20 15:16:15 +08008069#ifdef WLAN_FEATURE_WOW_PULSE
8070/**
8071 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008072 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08008073 * @enable: enable or disable this behaviour
8074 *
8075 * Return: int
8076 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008077static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008078{
8079 struct hdd_config *pcfg_ini = phddctx->config;
8080 struct wow_pulse_mode wow_pulse_set_info;
8081 QDF_STATUS status;
8082
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008083 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08008084
8085 if (false == phddctx->config->wow_pulse_support)
8086 return 0;
8087
8088 /* prepare the request to send to SME */
8089 if (enable == true) {
8090 wow_pulse_set_info.wow_pulse_enable = true;
8091 wow_pulse_set_info.wow_pulse_pin =
8092 pcfg_ini->wow_pulse_pin;
8093 wow_pulse_set_info.wow_pulse_interval_low =
8094 pcfg_ini->wow_pulse_interval_low;
8095 wow_pulse_set_info.wow_pulse_interval_high =
8096 pcfg_ini->wow_pulse_interval_high;
8097 } else {
8098 wow_pulse_set_info.wow_pulse_enable = false;
8099 wow_pulse_set_info.wow_pulse_pin = 0;
8100 wow_pulse_set_info.wow_pulse_interval_low = 0;
8101 wow_pulse_set_info.wow_pulse_interval_high = 0;
8102 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008103 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08008104 wow_pulse_set_info.wow_pulse_enable,
8105 wow_pulse_set_info.wow_pulse_pin,
8106 wow_pulse_set_info.wow_pulse_interval_low,
8107 wow_pulse_set_info.wow_pulse_interval_high);
8108
8109 status = sme_set_wow_pulse(&wow_pulse_set_info);
8110 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008111 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08008112 return -EIO;
8113 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008114 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08008115 return 0;
8116}
8117#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008118static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008119{
8120 return 0;
8121}
8122#endif
8123
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008124#ifdef WLAN_FEATURE_FASTPATH
8125/**
8126 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
8127 * @hdd_cfg: hdd config
8128 * @context: lower layer context
8129 *
8130 * Return: none
8131 */
Arun Khandavallifae92942016-08-01 13:31:08 +05308132void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008133 void *context)
8134{
8135 if (hdd_cfg->fastpath_enable)
8136 hif_enable_fastpath(context);
8137}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008138#endif
8139
Yuanyuan Liu13738502016-04-06 17:41:37 -07008140#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008141/**
8142 * hdd_set_thermal_level_cb() - set thermal level callback function
Jeff Johnson0e963082018-07-04 19:39:20 -07008143 * @hdd_handle: opaque handle for the hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008144 * @level: thermal level
8145 *
8146 * Change IPA data path to SW path when the thermal throttle level greater
8147 * than 0, and restore the original data path when throttle level is 0
8148 *
8149 * Return: none
8150 */
Jeff Johnson0e963082018-07-04 19:39:20 -07008151static void hdd_set_thermal_level_cb(hdd_handle_t hdd_handle, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008152{
Jeff Johnson0e963082018-07-04 19:39:20 -07008153 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008154
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008155 /* Change IPA to SW path when throttle level greater than 0 */
8156 if (level > THROTTLE_LEVEL_0)
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308157 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008158 else
8159 /* restore original concurrency mode */
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308160 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, hdd_ctx->mcc_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008161}
8162
8163/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308164 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
8165 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05308166 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008167 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308168 * Get a safe channel to restart SAP. PCL already takes into account the
8169 * unsafe channels. So, the PCL is validated with the ACS range to provide
8170 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008171 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308172 * Return: Channel number to restart SAP in case of success. In case of any
8173 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008174 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308175static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07008176 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008177{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308178 struct sir_pcl_list pcl;
8179 QDF_STATUS status;
8180 uint32_t i, j;
Jeff Johnson16528362018-06-14 12:34:16 -07008181 mac_handle_t mac_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008182 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308183 bool found = false;
Liangwei Dong17bf2662018-01-05 02:02:05 -05008184 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008185
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308186 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8187 if (!hdd_ctx) {
8188 hdd_err("invalid HDD context");
8189 return INVALID_CHANNEL_ID;
8190 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008191
Jeff Johnson16528362018-06-14 12:34:16 -07008192 mac_handle = hdd_ctx->mac_handle;
8193 if (!mac_handle) {
8194 hdd_err("invalid MAC handle");
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05308195 return INVALID_CHANNEL_ID;
8196 }
8197
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008198 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
8199 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08008200 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
8201 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308202 if (QDF_IS_STATUS_ERROR(status)) {
8203 hdd_err("Get PCL failed");
8204 return INVALID_CHANNEL_ID;
8205 }
8206
Frank Liudc2cefb2017-06-21 15:38:18 +08008207 /*
8208 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
8209 * channel is unsafe channel, the pcl may be empty, instead of return,
8210 * try to choose a safe channel from acs range.
8211 */
8212 if (!pcl.pcl_len)
8213 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308214
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008215 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07008216 adapter->session.ap.sap_config.acs_cfg.start_ch,
8217 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308218
8219 /* PCL already takes unsafe channel into account */
8220 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008221 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308222 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008223 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308224 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008225 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008226 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308227 return pcl.pcl_list[i];
8228 }
8229 }
8230
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008231 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308232
8233 /* Try for safe channel from all valid channel */
8234 pcl.pcl_len = MAX_NUM_CHAN;
Liangwei Dong17bf2662018-01-05 02:02:05 -05008235 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
8236 &pcl.pcl_len);
8237 if (ret) {
8238 hdd_err("error %d in getting valid channel list", ret);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308239 return INVALID_CHANNEL_ID;
8240 }
8241
8242 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008243 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308244 found = false;
8245 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07008246 if (pcl.pcl_list[i] ==
8247 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008248 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308249 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008250 break;
8251 }
8252 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308253
8254 if (found)
8255 continue;
8256
8257 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008258 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308259 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008260 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008261 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308262 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008263 }
8264 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308265
8266 return INVALID_CHANNEL_ID;
8267}
Nirav Shaheb017be2018-02-15 11:20:58 +05308268#endif
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308269
8270/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008271 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308272 * @adapter: AP adapter
8273 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08008274 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308275 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008276 * Moves the SAP interface by invoking the function which
8277 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308278 *
8279 * Return: None
8280 */
Min Liu2fef5792018-01-19 17:59:42 +08008281void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
8282 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308283{
Jeff Johnson87251032017-08-29 13:31:11 -07008284 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008285 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07008286 mac_handle_t mac_handle;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308287
8288 if (!adapter) {
8289 hdd_err("invalid adapter");
8290 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008291 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308292
8293 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
8294
Jeff Johnson16528362018-06-14 12:34:16 -07008295 mac_handle = hdd_adapter_get_mac_handle(adapter);
8296 if (!mac_handle) {
8297 hdd_err("invalid MAC handle");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308298 return;
8299 }
8300
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008301 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8302
Jeff Johnson91df29d2017-10-27 19:29:50 -07008303 hdd_ap_ctx->sap_config.channel = channel;
Himanshu Agarwalf5c5b102018-05-22 20:13:57 +05308304 hdd_ap_ctx->sap_config.ch_params.ch_width = CH_WIDTH_MAX;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308305
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008306 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07008307 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308308
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07008309 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07008310 hdd_ap_ctx->sap_config.channel,
8311 hdd_ap_ctx->sap_config.sec_ch,
8312 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308313
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008314 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07008315 adapter->session_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08008316 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008317}
Kapil Gupta8878ad92017-02-13 11:56:04 +05308318
Jeff Johnson9d295242017-08-29 14:39:48 -07008319int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05308320{
8321 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308322 int status;
8323 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308324
8325 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8326
8327 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07008328 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05308329 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07008330 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308331 }
8332 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07008333 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308334 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308335 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07008336 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308337 WLAN_VENDOR_ACS_WAIT_TIME);
8338 if (qdf_status != QDF_STATUS_SUCCESS) {
8339 hdd_err("failed to start external acs timer");
8340 return -ENOSPC;
8341 }
8342 /* Update config to application */
8343 status = hdd_cfg80211_update_acs_config(adapter, reason);
Dustin Brown5e89ef82018-03-14 11:50:23 -07008344 hdd_info("Updated ACS config to nl with reason %d", reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308345
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308346 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308347}
8348
Nirav Shaheb017be2018-02-15 11:20:58 +05308349#if defined(FEATURE_WLAN_CH_AVOID)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308350/**
8351 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
8352 * @hdd_ctx: hdd context pointer
8353 *
8354 * hdd_unsafe_channel_restart_sap check all unsafe channel list
8355 * and if ACS is enabled, driver will ask userspace to restart the
8356 * sap. User space on LTE coex indication restart driver.
8357 *
8358 * Return - none
8359 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008360void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308361{
Dustin Brown920397d2017-12-13 16:27:50 -08008362 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308363 uint32_t i;
8364 bool found = false;
8365 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008366
Dustin Brown920397d2017-12-13 16:27:50 -08008367 hdd_for_each_adapter(hdd_ctxt, adapter) {
8368 if (!(adapter->device_mode == QDF_SAP_MODE &&
8369 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008370 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08008371 adapter->device_mode,
8372 adapter->session.ap.sap_config.
8373 acs_cfg.acs_mode);
8374 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308375 }
8376
8377 found = false;
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008378 /*
8379 * If STA+SAP is doing SCC & g_sta_sap_scc_on_lte_coex_chan
8380 * is set, no need to move SAP.
8381 */
8382 if (policy_mgr_is_sta_sap_scc(hdd_ctxt->hdd_psoc,
8383 adapter->session.ap.operating_channel) &&
8384 hdd_ctxt->config->sta_sap_scc_on_lte_coex_chan)
8385 hdd_debug("SAP is allowed on SCC channel, no need to move SAP");
8386 else {
8387 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
8388 if (adapter->session.ap.operating_channel ==
8389 hdd_ctxt->unsafe_channel_list[i]) {
8390 found = true;
8391 hdd_debug("operating ch:%d is unsafe",
8392 adapter->session.ap.operating_channel);
8393 break;
8394 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308395 }
8396 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308397 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008398 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08008399 adapter->session.ap.operating_channel);
8400 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308401 }
8402
Kapil Gupta8878ad92017-02-13 11:56:04 +05308403 if (hdd_ctxt->config->vendor_acs_support &&
8404 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08008405 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05308406 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08008407 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308408 } else
8409 restart_chan =
8410 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08008411 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308412 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008413 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308414 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008415 /*
8416 * SAP restart due to unsafe channel. While
8417 * restarting the SAP, make sure to clear
8418 * acs_channel, channel to reset to
8419 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308420 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008421 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308422 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown920397d2017-12-13 16:27:50 -08008423 adapter->session.ap.sap_config.channel =
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308424 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008425 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308426 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
8427 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04008428 hdd_debug("driver to start sap: %d",
8429 hdd_ctxt->config->sap_internal_restart);
8430 if (hdd_ctxt->config->sap_internal_restart)
Min Liu2fef5792018-01-19 17:59:42 +08008431 hdd_switch_sap_channel(adapter, restart_chan,
8432 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04008433 else
8434 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308435 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308436 }
8437}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05308438
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008439/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008440 * hdd_init_channel_avoidance() - Initialize channel avoidance
8441 * @hdd_ctx: HDD global context
8442 *
8443 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07008444 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008445 * down to the lower layers. Then subscribe to subsequent channel
8446 * avoidance events.
8447 *
8448 * Return: None
8449 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008450static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008451{
8452 uint16_t unsafe_channel_count;
8453 int index;
8454
Yuanyuan Liu13738502016-04-06 17:41:37 -07008455 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
8456 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008457 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08008458 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008459
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008460 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008461 hdd_ctx->unsafe_channel_count);
8462
Anurag Chouhan6d760662016-02-20 16:05:43 +05308463 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08008464 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008465
8466 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008467 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008468 hdd_ctx->unsafe_channel_list[index]);
8469
8470 }
8471
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008472}
Dustin Brown676a2322017-08-15 13:16:13 -07008473
Jeff Johnson9d295242017-08-29 14:39:48 -07008474static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008475 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008476{
8477 uint8_t restart_chan;
8478
8479 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
8480 if (!restart_chan) {
8481 hdd_alert("fail to restart SAP");
8482 return;
8483 }
8484
8485 /* SAP restart due to unsafe channel. While restarting
8486 * the SAP, make sure to clear acs_channel, channel to
8487 * reset to 0. Otherwise these settings will override
8488 * the ACS while restart.
8489 */
8490 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07008491 adapter->session.ap.sap_config.channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07008492
8493 hdd_debug("sending coex indication");
8494
8495 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
8496 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08008497 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07008498}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008499
8500int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
8501 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
8502{
8503 uint32_t size;
8504 uint16_t *unsafe_list;
8505 uint16_t chan_count;
8506
8507 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
8508 return -EINVAL;
8509
8510 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
8511 NUM_CHANNELS);
8512 if (chan_count) {
8513 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
8514 unsafe_list = qdf_mem_malloc(size);
8515 if (!unsafe_list) {
8516 hdd_err("No memory for unsafe chan list size%d",
8517 size);
8518 return -ENOMEM;
8519 }
8520 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
8521 } else {
8522 unsafe_list = NULL;
8523 }
8524
8525 *local_unsafe_list = unsafe_list;
8526 *local_unsafe_list_count = chan_count;
8527
8528 return 0;
8529}
8530
8531bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
8532 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
8533{
8534 int i, j;
8535
8536 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
8537 return true;
8538 if (local_unsafe_list_count == 0)
8539 return false;
8540 for (i = 0; i < local_unsafe_list_count; i++) {
8541 for (j = 0; j < local_unsafe_list_count; j++)
8542 if (local_unsafe_list[i] ==
8543 hdd_ctx->unsafe_channel_list[j])
8544 break;
8545 if (j >= local_unsafe_list_count)
8546 break;
8547 }
8548 if (i >= local_unsafe_list_count) {
8549 hdd_info("unsafe chan list same");
8550 return false;
8551 }
8552
8553 return true;
8554}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008555#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008556static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008557{
8558}
Dustin Brown676a2322017-08-15 13:16:13 -07008559
Jeff Johnson0e963082018-07-04 19:39:20 -07008560static void hdd_set_thermal_level_cb(hdd_handle_t hdd_handle, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008561{
8562}
Dustin Brown676a2322017-08-15 13:16:13 -07008563
Jeff Johnson9d295242017-08-29 14:39:48 -07008564static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008565 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008566{
8567 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
8568}
Yuanyuan Liu13738502016-04-06 17:41:37 -07008569#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008570
8571/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08008572 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
8573 * user space
8574 * @frame_ind: Management frame data to be informed.
8575 *
8576 * This function is used to indicate management frame to
8577 * user space
8578 *
8579 * Return: None
8580 *
8581 */
8582void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
8583{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008584 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07008585 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008586 int i;
Pragaspathi Thilagaraj28ffc042018-07-18 15:19:36 +05308587 struct ieee80211_mgmt *mgmt =
8588 (struct ieee80211_mgmt *)frame_ind->frameBuf;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008589
Dustin Browne7e71d32018-05-11 16:00:08 -07008590 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
8591 if (wlan_hdd_validate_context(hdd_ctx))
Rajeev Kumard004abc2016-02-17 12:09:56 -08008592 return;
8593
Pragaspathi Thilagaraj28ffc042018-07-18 15:19:36 +05308594 if (frame_ind->frame_len < ieee80211_hdrlen(mgmt->frame_control)) {
8595 hdd_err(" Invalid frame length");
8596 return;
8597 }
8598
Rajeev Kumard004abc2016-02-17 12:09:56 -08008599 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
8600 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
8601 adapter =
8602 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
8603 if (adapter)
8604 break;
8605 }
Wu Gaoa0230a62018-01-04 20:56:57 +08008606 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
8607 hdd_for_each_adapter(hdd_ctx, adapter) {
8608 if ((NULL != adapter) &&
8609 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
8610 __hdd_indicate_mgmt_frame(adapter,
8611 frame_ind->frame_len,
8612 frame_ind->frameBuf,
8613 frame_ind->frameType,
8614 frame_ind->rxChan,
8615 frame_ind->rxRssi);
8616 }
8617 }
8618 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008619 } else {
8620 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
8621 frame_ind->sessionId);
8622 }
8623
8624 if ((NULL != adapter) &&
8625 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
8626 __hdd_indicate_mgmt_frame(adapter,
8627 frame_ind->frame_len,
8628 frame_ind->frameBuf,
8629 frame_ind->frameType,
8630 frame_ind->rxChan,
8631 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008632}
8633
Kapil Gupta8878ad92017-02-13 11:56:04 +05308634void hdd_acs_response_timeout_handler(void *context)
8635{
8636 struct hdd_external_acs_timer_context *timer_context =
8637 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07008638 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008639 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308640 uint8_t reason;
8641
Dustin Brown491d54b2018-03-14 12:39:11 -07008642 hdd_enter();
Kapil Gupta8878ad92017-02-13 11:56:04 +05308643 if (!timer_context) {
8644 hdd_err("invlaid timer context");
8645 return;
8646 }
8647 adapter = timer_context->adapter;
8648 reason = timer_context->reason;
8649
8650
8651 if ((!adapter) ||
8652 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
8653 hdd_err("invalid adapter or adapter has invalid magic");
8654 return;
8655 }
8656 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8657 if (wlan_hdd_validate_context(hdd_ctx))
8658 return;
8659
8660 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
8661 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8662 else
8663 return;
8664
8665 hdd_err("ACS timeout happened for %s reason %d",
8666 adapter->dev->name, reason);
Jeff Johnson16528362018-06-14 12:34:16 -07008667
Kapil Gupta8878ad92017-02-13 11:56:04 +05308668 switch (reason) {
8669 /* SAP init case */
8670 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
8671 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
8672 false);
8673 wlan_hdd_cfg80211_start_acs(adapter);
8674 break;
8675 /* DFS detected on current channel */
8676 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
8677 wlan_sap_update_next_channel(
8678 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
Jeff Johnson16528362018-06-14 12:34:16 -07008679 sme_update_new_channel_event(hdd_ctx->mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07008680 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308681 break;
8682 /* LTE coex event on current channel */
8683 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
8684 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
8685 break;
8686 default:
8687 hdd_info("invalid reason for timer invoke");
8688
8689 }
8690}
8691
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008692/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008693 * hdd_override_ini_config - Override INI config
8694 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008695 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008696 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008697 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008698 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008699 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008700static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008701{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008702
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008703 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
8704 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008705 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008706 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008707 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008708 if (0 == enable_11d || 1 == enable_11d) {
8709 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008710 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008711 }
Leo Chang11545d62016-10-17 14:53:50 -07008712
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308713 if (!ucfg_ipa_is_present()) {
Leo Chang11545d62016-10-17 14:53:50 -07008714 hdd_ctx->config->IpaConfig = 0;
Jingxiang Ge7a040dc2018-02-02 11:07:59 +08008715 hdd_debug("IpaConfig override to %d",
8716 hdd_ctx->config->IpaConfig);
8717 }
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05308718
8719 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
8720 !hdd_ctx->config->enable_bcast_probe_rsp) {
8721 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
8722 hdd_ctx->config->rssi_assoc_reject_enabled,
8723 hdd_ctx->config->enable_bcast_probe_rsp);
8724 hdd_ctx->config->oce_sta_enabled = 0;
8725 }
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +05308726
8727 if (hdd_ctx->config->action_oui_enable && !ucfg_action_oui_enabled()) {
8728 hdd_ctx->config->action_oui_enable = 0;
8729 hdd_err("Ignore ini: %s, since no action_oui component",
8730 CFG_ENABLE_ACTION_OUI);
8731 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008732}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008733
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008734/**
8735 * hdd_set_trace_level_for_each - Set trace level for each INI config
8736 * @hdd_ctx - HDD context
8737 *
8738 * Set trace level for each module based on INI config.
8739 *
8740 * Return: None
8741 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008742static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008743{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308744 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
8745 hdd_ctx->config->qdf_trace_enable_wdi);
8746 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
8747 hdd_ctx->config->qdf_trace_enable_hdd);
8748 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
8749 hdd_ctx->config->qdf_trace_enable_sme);
8750 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
8751 hdd_ctx->config->qdf_trace_enable_pe);
8752 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
8753 hdd_ctx->config->qdf_trace_enable_wma);
8754 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
8755 hdd_ctx->config->qdf_trace_enable_sys);
8756 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
8757 hdd_ctx->config->qdf_trace_enable_qdf);
8758 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
8759 hdd_ctx->config->qdf_trace_enable_sap);
8760 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
8761 hdd_ctx->config->qdf_trace_enable_hdd_sap);
8762 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
8763 hdd_ctx->config->qdf_trace_enable_bmi);
8764 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
8765 hdd_ctx->config->qdf_trace_enable_cfg);
8766 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
8767 hdd_ctx->config->qdf_trace_enable_epping);
8768 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
8769 hdd_ctx->config->qdf_trace_enable_qdf_devices);
8770 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07008771 hdd_ctx->config->qdf_trace_enable_txrx);
8772 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
8773 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308774 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
8775 hdd_ctx->config->qdf_trace_enable_htc);
8776 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
8777 hdd_ctx->config->qdf_trace_enable_hif);
8778 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
8779 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
8780 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
8781 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08008782 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
8783 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07008784 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
8785 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008786 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
8787 hdd_ctx->config->qdf_trace_enable_regulatory);
Naveen Rawat3cb779e2018-02-16 16:36:10 -08008788 hdd_qdf_trace_enable(QDF_MODULE_ID_CP_STATS,
8789 hdd_ctx->config->qdf_trace_enable_cp_stats);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008790
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008791 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008792}
8793
8794/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008795 * hdd_context_init() - Initialize HDD context
8796 * @hdd_ctx: HDD context.
8797 *
8798 * Initialize HDD context along with all the feature specific contexts.
8799 *
8800 * return: 0 on success and errno on failure.
8801 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008802static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008803{
8804 int ret;
8805
8806 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
8807 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
8808
8809 hdd_init_ll_stats_ctx();
8810
8811 init_completion(&hdd_ctx->mc_sus_event_var);
8812 init_completion(&hdd_ctx->ready_to_suspend);
8813
8814 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308815 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008816 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308817
Dustin Brownbee82832018-07-23 10:10:51 -07008818 qdf_list_create(&hdd_ctx->hdd_adapters, 0);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008819
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008820 ret = hdd_scan_context_init(hdd_ctx);
8821 if (ret)
8822 goto list_destroy;
8823
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008824 hdd_rx_wake_lock_create(hdd_ctx);
8825
8826 ret = hdd_sap_context_init(hdd_ctx);
8827 if (ret)
8828 goto scan_destroy;
8829
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008830 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8831
8832 hdd_init_offloaded_packets_ctx(hdd_ctx);
8833
8834 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8835 hdd_ctx->config);
8836 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08008837 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008838
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05308839 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
8840 "monitor_mode_wakelock");
8841
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008842 return 0;
8843
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008844sap_destroy:
8845 hdd_sap_context_destroy(hdd_ctx);
8846
8847scan_destroy:
8848 hdd_scan_context_destroy(hdd_ctx);
8849 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008850list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008851 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08008852
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008853 return ret;
8854}
8855
8856/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308857 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
8858 * @hdd_ctx: pointer to hdd context
8859 *
8860 * Return: status of initialization
8861 * 0 - success
8862 * negative value - failure
8863 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008864static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308865{
8866 int ret;
8867
8868 if (!hdd_ctx->config->probe_req_ie_whitelist)
8869 return 0;
8870
8871 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
8872 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
8873 hdd_ctx->config->probe_req_ie_whitelist = false;
8874 return -EINVAL;
8875 }
8876
8877 /* parse ini string probe req oui */
8878 ret = hdd_parse_probe_req_ouis(hdd_ctx);
8879 if (ret) {
8880 hdd_err("parsing error: disable ie whitelisting");
8881 hdd_ctx->config->probe_req_ie_whitelist = false;
8882 }
8883
8884 return ret;
8885}
8886
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308887/**
8888 * hdd_iface_change_callback() - Function invoked when stop modules expires
8889 * @priv: pointer to hdd context
8890 *
8891 * This function is invoked when the timer waiting for the interface change
8892 * expires, it shall cut-down the power to wlan and stop all the modules.
8893 *
8894 * Return: void
8895 */
8896static void hdd_iface_change_callback(void *priv)
8897{
8898 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
8899 int ret;
8900 int status = wlan_hdd_validate_context(hdd_ctx);
8901
8902 if (status)
8903 return;
8904
Dustin Brown491d54b2018-03-14 12:39:11 -07008905 hdd_enter();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308906 hdd_debug("Interface change timer expired close the modules!");
8907 ret = hdd_wlan_stop_modules(hdd_ctx, false);
8908 if (ret)
8909 hdd_err("Failed to stop modules");
Dustin Browne74003f2018-03-14 12:51:58 -07008910 hdd_exit();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308911}
8912
Nirav Shaheb017be2018-02-15 11:20:58 +05308913#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
8914static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8915{
8916 wlan_logging_set_log_to_console(hdd_ctx->config->
8917 wlan_logging_to_console);
8918 wlan_logging_set_active(hdd_ctx->config->wlan_logging_enable);
8919}
8920#else
8921static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8922{ }
8923#endif
8924
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308925/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008926 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05308927 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008928 *
8929 * Allocate and initialize HDD context. HDD context is allocated as part of
8930 * wiphy allocation and then context is initialized.
8931 *
8932 * Return: HDD context on success and ERR_PTR on failure
8933 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008934static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008935{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308936 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008937 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008938 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008939
Dustin Brown491d54b2018-03-14 12:39:11 -07008940 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008941
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008942 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008943 if (hdd_ctx == NULL) {
8944 ret = -ENOMEM;
8945 goto err_out;
8946 }
8947
Dustin Brown6f427922017-09-19 12:19:00 -07008948 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
8949 hdd_iface_change_callback,
8950 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308951
8952 mutex_init(&hdd_ctx->iface_change_lock);
8953
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008954 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05308955 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008956
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308957 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008958 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008959 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008960 ret = -ENOMEM;
8961 goto err_free_hdd_context;
8962 }
8963
8964 /* Read and parse the qcom_cfg.ini file */
8965 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308966 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05308967 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008968 WLAN_INI_FILE);
8969 ret = -EINVAL;
8970 goto err_free_config;
8971 }
8972
Dustin Brown84f46ea2018-02-15 11:57:36 -08008973 status = cfg_parse(WLAN_INI_FILE);
8974 if (QDF_IS_STATUS_ERROR(status))
8975 hdd_err("Failed to parse cfg %s; status:%d\n",
8976 WLAN_INI_FILE, status);
8977
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308978 ie_whitelist_attrs_init(hdd_ctx);
8979
Dustin Brown7f939932017-05-18 15:02:17 -07008980 hdd_debug("setting timer multiplier: %u",
8981 hdd_ctx->config->timer_multiplier);
8982 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
8983
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008984
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05308985 if (hdd_ctx->config->fhostNSOffload)
8986 hdd_ctx->ns_offload_enable = true;
8987
Abhishek Singh5ea86532016-04-27 14:10:53 +05308988 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
8989
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008990 hdd_override_ini_config(hdd_ctx);
8991
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008992 ret = hdd_context_init(hdd_ctx);
8993
8994 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008995 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008996
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008997 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05308998 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008999
Anurag Chouhan6d760662016-02-20 16:05:43 +05309000 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009001 goto skip_multicast_logging;
9002
9003 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
9004
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07009005 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
9006 if (ret)
9007 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05309008
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009009 ret = hdd_init_netlink_services(hdd_ctx);
9010 if (ret)
9011 goto err_deinit_txrx_histogram;
9012
Nirav Shaheb017be2018-02-15 11:20:58 +05309013 hdd_set_wlan_logging(hdd_ctx);
Nirav Shahed34b212016-04-25 10:59:16 +05309014
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009015skip_multicast_logging:
9016 hdd_set_trace_level_for_each(hdd_ctx);
9017
Rajeev Kumar493a31b2017-09-29 14:01:24 -07009018 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
9019
Dustin Browne74003f2018-03-14 12:51:58 -07009020 hdd_exit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07009021
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009022 return hdd_ctx;
9023
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07009024err_deinit_txrx_histogram:
9025 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
9026
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07009027err_deinit_hdd_context:
9028 hdd_context_deinit(hdd_ctx);
9029
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009030err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309031 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009032
9033err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309034 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08009035 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009036
9037err_out:
9038 return ERR_PTR(ret);
9039}
9040
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009041#ifdef WLAN_OPEN_P2P_INTERFACE
9042/**
9043 * hdd_open_p2p_interface - Open P2P interface
9044 * @hdd_ctx: HDD context
9045 * @rtnl_held: True if RTNL lock held
9046 *
9047 * Open P2P interface during probe. This function called to open the P2P
9048 * interface at probe along with STA interface.
9049 *
9050 * Return: 0 on success and errno on failure
9051 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009052static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009053{
Jeff Johnson9d295242017-08-29 14:39:48 -07009054 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009055 uint8_t *p2p_dev_addr;
Wu Gaoe5689792018-07-05 19:20:13 +08009056 bool p2p_dev_addr_admin = false;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009057
Wu Gaoe5689792018-07-05 19:20:13 +08009058 cfg_p2p_get_device_addr_admin(hdd_ctx->hdd_psoc, &p2p_dev_addr_admin);
9059 if (p2p_dev_addr_admin &&
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009060 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009061 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009062 hdd_ctx->config->intfMacAddr[0].bytes,
9063 sizeof(tSirMacAddr));
9064
9065 /*
9066 * Generate the P2P Device Address. This consists of
9067 * the device's primary MAC address with the locally
9068 * administered bit set.
9069 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009070 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009071 } else {
9072 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
9073 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009074 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009075 return -ENOSPC;
9076 }
9077
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009078 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
9079 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009080 }
9081
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009082 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009083 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08009084 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009085
9086 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009087 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009088 return -ENOSPC;
9089 }
9090
9091 return 0;
9092}
9093#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009094static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009095 bool rtnl_held)
9096{
9097 return 0;
9098}
9099#endif
9100
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009101static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08009102{
Jeff Johnson9d295242017-08-29 14:39:48 -07009103 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08009104 int ret = 0;
9105
9106 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
9107 wlan_hdd_get_intf_addr(hdd_ctx),
9108 NET_NAME_UNKNOWN, rtnl_held);
9109 if (adapter == NULL) {
9110 hdd_err("Failed to open 802.11p interface");
9111 ret = -ENOSPC;
9112 }
9113
9114 return ret;
9115}
9116
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009117/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309118 * hdd_start_station_adapter()- Start the Station Adapter
9119 * @adapter: HDD adapter
9120 *
9121 * This function initializes the adapter for the station mode.
9122 *
9123 * Return: 0 on success or errno on failure.
9124 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009125int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309126{
9127 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08009128 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309129
Dustin Brownfdf17c12018-03-14 12:55:34 -07009130 hdd_enter_dev(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08009131 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9132 hdd_err("session is already opened, %d",
9133 adapter->session_id);
9134 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9135 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309136
Krunal Sonib51eec72017-11-20 21:53:01 -08009137 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
9138 if (ret) {
9139 hdd_err("failed to create vdev: %d", ret);
9140 return ret;
9141 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309142 status = hdd_init_station_mode(adapter);
9143
9144 if (QDF_STATUS_SUCCESS != status) {
9145 hdd_err("Error Initializing station mode: %d", status);
9146 return qdf_status_to_os_return(status);
9147 }
9148
Arun Khandavallifae92942016-08-01 13:31:08 +05309149 hdd_register_tx_flow_control(adapter,
9150 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009151 hdd_tx_resume_cb,
9152 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309153
Dustin Browne74003f2018-03-14 12:51:58 -07009154 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309155 return 0;
9156}
9157
9158/**
9159 * hdd_start_ap_adapter()- Start AP Adapter
9160 * @adapter: HDD adapter
9161 *
9162 * This function initializes the adapter for the AP mode.
9163 *
9164 * Return: 0 on success errno on failure.
9165 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009166int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309167{
9168 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009169 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08009170 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08009171 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309172
Dustin Brown491d54b2018-03-14 12:39:11 -07009173 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309174
Krunal Sonib51eec72017-11-20 21:53:01 -08009175 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9176 hdd_err("session is already opened, %d",
9177 adapter->session_id);
9178 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9179 }
9180 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009181 * In SSR case no need to create new sap context.
9182 * Otherwise create sap context first and then create
9183 * vdev as while creating the vdev, driver needs to
9184 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08009185 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009186 if (adapter->session.ap.sap_context) {
9187 is_ssr = true;
9188 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08009189 hdd_err("sap creation failed");
9190 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
9191 }
9192
9193 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
9194 adapter->session.ap.sap_context);
9195 if (ret) {
9196 hdd_err("failed to create vdev, status:%d", ret);
9197 hdd_sap_destroy_ctx(adapter);
9198 return ret;
9199 }
Naveen Rawat1af09392018-01-03 17:28:21 -08009200
9201 if (adapter->device_mode == QDF_SAP_MODE)
9202 sme_cli_set_command(adapter->session_id,
9203 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
9204 (bool)(hdd_ctx->config->fine_time_meas_cap &
9205 WMI_FW_AP_RTT_RESPR),
9206 VDEV_CMD);
9207
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009208 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309209
9210 if (QDF_STATUS_SUCCESS != status) {
9211 hdd_err("Error Initializing the AP mode: %d", status);
9212 return qdf_status_to_os_return(status);
9213 }
9214
Arun Khandavallifae92942016-08-01 13:31:08 +05309215 hdd_register_tx_flow_control(adapter,
9216 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009217 hdd_softap_tx_resume_cb,
9218 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309219
Dustin Browne74003f2018-03-14 12:51:58 -07009220 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309221 return 0;
9222}
9223
Sourav Mohapatra57006c72017-11-19 16:15:55 +05309224static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
9225 bool rtnl_held)
9226{
9227 struct hdd_adapter *adapter;
9228
9229 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
9230 hdd_ctx->config->enableConcurrentSTA,
9231 wlan_hdd_get_intf_addr(hdd_ctx),
9232 NET_NAME_UNKNOWN, rtnl_held);
9233
9234 if (!adapter)
9235 return -ENOSPC;
9236
9237 return 0;
9238}
9239
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309240/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009241 * hdd_open_interfaces - Open all required interfaces
9242 * hdd_ctx: HDD context
9243 * rtnl_held: True if RTNL lock is held
9244 *
9245 * Open all the interfaces like STA, P2P and OCB based on the configuration.
9246 *
Jeff Johnson957bc272017-02-02 08:54:48 -08009247 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009248 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009249static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009250{
Jeff Johnson9d295242017-08-29 14:39:48 -07009251 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009252 int ret;
9253
Ravi Joshia307f632017-07-17 23:41:41 -07009254 /* open monitor mode adapter if con_mode is monitor mode */
Lin Bai1c678482017-12-18 18:29:11 +08009255 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
9256 con_mode == QDF_GLOBAL_FTM_MODE) {
9257 uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
9258 QDF_MONITOR_MODE : QDF_FTM_MODE;
9259
9260 adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
9261 wlan_hdd_get_intf_addr(hdd_ctx),
9262 NET_NAME_UNKNOWN, rtnl_held);
Ravi Joshia307f632017-07-17 23:41:41 -07009263 if (!adapter) {
9264 hdd_err("open adapter failed");
9265 return -ENOSPC;
9266 }
Lin Bai1c678482017-12-18 18:29:11 +08009267
Ravi Joshia307f632017-07-17 23:41:41 -07009268 return 0;
9269 }
9270
Jeff Johnson957bc272017-02-02 08:54:48 -08009271 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05309272 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08009273 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009274
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009275 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009276 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08009277 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009278
9279 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08009280 return -ENOSPC;
9281
Sourav Mohapatra57006c72017-11-19 16:15:55 +05309282 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
9283 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
9284 if (ret)
9285 hdd_err("Cannot create concurrent STA interface");
9286 }
9287
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009288 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
9289 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08009290 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009291
9292 /* Open 802.11p Interface */
9293 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08009294 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
9295 if (ret)
9296 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009297 }
9298
Jeff Johnson957bc272017-02-02 08:54:48 -08009299 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009300
Jeff Johnson957bc272017-02-02 08:54:48 -08009301err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009302 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08009303 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009304}
9305
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009306
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309307#ifdef QCA_LL_TX_FLOW_CONTROL_V2
9308/**
9309 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
9310 * @cds_cfg: CDS Configuration
9311 * @hdd_ctx: Pointer to hdd context
9312 *
9313 * Return: none
9314 */
9315static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9316 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009317 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309318{
9319 cds_cfg->tx_flow_stop_queue_th =
9320 hdd_ctx->config->TxFlowStopQueueThreshold;
9321 cds_cfg->tx_flow_start_queue_offset =
9322 hdd_ctx->config->TxFlowStartQueueOffset;
9323}
9324#else
9325static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9326 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009327 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309328{
9329}
9330#endif
9331
9332#ifdef FEATURE_WLAN_RA_FILTERING
9333/**
9334 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
9335 * @cds_cfg: CDS Configuration
9336 * @hdd_ctx: Pointer to hdd context
9337 *
9338 * Return: none
9339 */
Anand Kumar3b92a912016-12-05 12:01:26 +05309340static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009341 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309342{
9343 cds_cfg->ra_ratelimit_interval =
9344 hdd_ctx->config->RArateLimitInterval;
9345 cds_cfg->is_ra_ratelimit_enabled =
9346 hdd_ctx->config->IsRArateLimitEnabled;
9347}
9348#else
Anand Kumar3b92a912016-12-05 12:01:26 +05309349static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009350 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309351{
9352}
9353#endif
9354
9355/**
9356 * hdd_update_cds_config() - API to update cds configuration parameters
9357 * @hdd_ctx: HDD Context
9358 *
9359 * Return: 0 for Success, errno on failure
9360 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009361static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309362{
9363 struct cds_config_info *cds_cfg;
9364
9365 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
9366 if (!cds_cfg) {
9367 hdd_err("failed to allocate cds config");
9368 return -ENOMEM;
9369 }
9370
Srinivas Girigowda35b00312017-06-27 21:52:03 -07009371 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08009372 if (!hdd_ctx->config->nMaxPsPoll ||
9373 !hdd_ctx->config->enablePowersaveOffload) {
9374 cds_cfg->powersave_offload_enabled =
9375 hdd_ctx->config->enablePowersaveOffload;
9376 } else {
9377 if ((hdd_ctx->config->enablePowersaveOffload ==
9378 PS_QPOWER_NODEEPSLEEP) ||
9379 (hdd_ctx->config->enablePowersaveOffload ==
9380 PS_LEGACY_NODEEPSLEEP))
9381 cds_cfg->powersave_offload_enabled =
9382 PS_LEGACY_NODEEPSLEEP;
9383 else
9384 cds_cfg->powersave_offload_enabled =
9385 PS_LEGACY_DEEPSLEEP;
9386 hdd_info("Qpower disabled in cds config, %d",
9387 cds_cfg->powersave_offload_enabled);
9388 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309389 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
9390 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
9391 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
9392 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309393
9394 /*
9395 * Copy the DFS Phyerr Filtering Offload status.
9396 * This parameter reflects the value of the
9397 * dfs_phyerr_filter_offload flag as set in the ini.
9398 */
9399 cds_cfg->dfs_phyerr_filter_offload =
9400 hdd_ctx->config->fDfsPhyerrFilterOffload;
9401 if (hdd_ctx->config->ssdp)
9402 cds_cfg->ssdp = hdd_ctx->config->ssdp;
9403
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05309404 cds_cfg->force_target_assert_enabled =
9405 hdd_ctx->config->crash_inject_enabled;
9406
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309407 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
9408 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
9409
9410 cds_cfg->ap_maxoffload_reorderbuffs =
9411 hdd_ctx->config->apMaxOffloadReorderBuffs;
9412
9413 cds_cfg->ap_disable_intrabss_fwd =
9414 hdd_ctx->config->apDisableIntraBssFwd;
9415
9416 cds_cfg->dfs_pri_multiplier =
9417 hdd_ctx->config->dfsRadarPriMultiplier;
9418 cds_cfg->reorder_offload =
9419 hdd_ctx->config->reorderOffloadSupport;
9420
9421 /* IPA micro controller data path offload resource config item */
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05309422 cds_cfg->uc_offload_enabled = ucfg_ipa_uc_is_enabled();
Yun Parkde380782016-08-17 16:26:54 -07009423 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
9424 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009425 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009426 hdd_ctx->config->IpaUcTxBufCount);
9427 hdd_ctx->config->IpaUcTxBufCount =
9428 rounddown_pow_of_two(
9429 hdd_ctx->config->IpaUcTxBufCount);
9430 if (!hdd_ctx->config->IpaUcTxBufCount) {
9431 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309432 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07009433 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009434 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009435 hdd_ctx->config->IpaUcTxBufCount);
9436 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309437 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
9438 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07009439 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
9440 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009441 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009442 hdd_ctx->config->IpaUcRxIndRingCount);
9443 hdd_ctx->config->IpaUcRxIndRingCount =
9444 rounddown_pow_of_two(
9445 hdd_ctx->config->IpaUcRxIndRingCount);
9446 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
9447 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309448 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07009449 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009450 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009451 hdd_ctx->config->IpaUcRxIndRingCount);
9452 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309453 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07009454 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309455 cds_cfg->uc_tx_partition_base =
9456 hdd_ctx->config->IpaUcTxPartitionBase;
9457 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
9458
9459 cds_cfg->ip_tcp_udp_checksum_offload =
9460 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07009461 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309462 cds_cfg->ce_classify_enabled =
9463 hdd_ctx->config->ce_classify_enabled;
Nachiket Kukadee547a482018-05-22 16:43:30 +05309464 cds_cfg->apf_packet_filter_enable =
9465 hdd_ctx->config->apf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309466 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
9467 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
9468 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07009469 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07009470 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07009471 cds_cfg->max_msdus_per_rxinorderind =
9472 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07009473 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07009474 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Nachiket Kukadee547a482018-05-22 16:43:30 +05309475 cds_cfg->active_uc_apf_mode = hdd_ctx->config->active_uc_apf_mode;
9476 cds_cfg->active_mc_bc_apf_mode = hdd_ctx->config->active_mc_bc_apf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05309477 cds_cfg->auto_power_save_fail_mode =
9478 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309479
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309480 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07009481 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Zhu Jianmina2f8e8d2018-02-11 16:37:10 +08009482 cds_cfg->delay_before_vdev_stop =
9483 hdd_ctx->config->delay_before_vdev_stop;
Rachit Kankane0106e382018-05-16 18:59:28 +05309484 cds_cfg->num_vdevs = hdd_ctx->config->num_vdevs;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309485
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309486 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
9487 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
9488 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07009489 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309490 cds_init_ini_config(cds_cfg);
9491 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309492
9493exit:
9494 qdf_mem_free(cds_cfg);
9495 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309496}
9497
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009498/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009499 * hdd_update_user_config() - API to update user configuration
9500 * parameters to obj mgr which are used by multiple components
9501 * @hdd_ctx: HDD Context
9502 *
9503 * Return: 0 for Success, errno on failure
9504 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009505static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009506{
9507 struct wlan_objmgr_psoc_user_config *user_config;
Wu Gaoe5689792018-07-05 19:20:13 +08009508 bool skip_dfs_in_p2p_search = false;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009509
9510 user_config = qdf_mem_malloc(sizeof(*user_config));
9511 if (user_config == NULL) {
9512 hdd_alert("Failed to alloc memory for user_config!");
9513 return -ENOMEM;
9514 }
9515
9516 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
9517 user_config->dual_mac_feature_disable =
9518 hdd_ctx->config->dual_mac_feature_disable;
9519 user_config->indoor_channel_support =
9520 hdd_ctx->config->indoor_channel_support;
9521 user_config->is_11d_support_enabled =
9522 hdd_ctx->config->Is11dSupportEnabled;
9523 user_config->is_11h_support_enabled =
9524 hdd_ctx->config->Is11hSupportEnabled;
9525 user_config->optimize_chan_avoid_event =
9526 hdd_ctx->config->goptimize_chan_avoid_event;
Wu Gaoe5689792018-07-05 19:20:13 +08009527 cfg_p2p_get_skip_dfs_channel_p2p_search(hdd_ctx->hdd_psoc,
9528 &skip_dfs_in_p2p_search);
9529 user_config->skip_dfs_chnl_in_p2p_search = skip_dfs_in_p2p_search;
Naveen Rawat222b2e92017-03-16 09:52:21 -07009530 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009531 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
9532
9533 qdf_mem_free(user_config);
9534 return 0;
9535}
9536
9537/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009538 * hdd_init_thermal_info - Initialize thermal level
9539 * @hdd_ctx: HDD context
9540 *
9541 * Initialize thermal level at SME layer and set the thermal level callback
9542 * which would be called when a configured thermal threshold is hit.
9543 *
9544 * Return: 0 on success and errno on failure
9545 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009546static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009547{
9548 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309549 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -07009550 mac_handle_t mac_handle;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009551
9552 thermal_param.smeThermalMgmtEnabled =
9553 hdd_ctx->config->thermalMitigationEnable;
9554 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
9555
Poddar, Siddarth83905022016-04-16 17:56:08 -07009556 thermal_param.sme_throttle_duty_cycle_tbl[0] =
9557 hdd_ctx->config->throttle_dutycycle_level0;
9558 thermal_param.sme_throttle_duty_cycle_tbl[1] =
9559 hdd_ctx->config->throttle_dutycycle_level1;
9560 thermal_param.sme_throttle_duty_cycle_tbl[2] =
9561 hdd_ctx->config->throttle_dutycycle_level2;
9562 thermal_param.sme_throttle_duty_cycle_tbl[3] =
9563 hdd_ctx->config->throttle_dutycycle_level3;
9564
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009565 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
9566 hdd_ctx->config->thermalTempMinLevel0;
9567 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
9568 hdd_ctx->config->thermalTempMaxLevel0;
9569 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
9570 hdd_ctx->config->thermalTempMinLevel1;
9571 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
9572 hdd_ctx->config->thermalTempMaxLevel1;
9573 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
9574 hdd_ctx->config->thermalTempMinLevel2;
9575 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
9576 hdd_ctx->config->thermalTempMaxLevel2;
9577 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
9578 hdd_ctx->config->thermalTempMinLevel3;
9579 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
9580 hdd_ctx->config->thermalTempMaxLevel3;
9581
Jeff Johnson16528362018-06-14 12:34:16 -07009582 mac_handle = hdd_ctx->mac_handle;
9583 status = sme_init_thermal_info(mac_handle, thermal_param);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009584
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309585 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05309586 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009587
Jeff Johnson16528362018-06-14 12:34:16 -07009588 sme_add_set_thermal_level_callback(mac_handle,
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009589 hdd_set_thermal_level_cb);
9590
9591 return 0;
9592
9593}
9594
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009595#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
9596/**
9597 * hdd_hold_rtnl_lock - Hold RTNL lock
9598 *
9599 * Hold RTNL lock
9600 *
9601 * Return: True if held and false otherwise
9602 */
9603static inline bool hdd_hold_rtnl_lock(void)
9604{
9605 rtnl_lock();
9606 return true;
9607}
9608
9609/**
9610 * hdd_release_rtnl_lock - Release RTNL lock
9611 *
9612 * Release RTNL lock
9613 *
9614 * Return: None
9615 */
9616static inline void hdd_release_rtnl_lock(void)
9617{
9618 rtnl_unlock();
9619}
9620#else
9621static inline bool hdd_hold_rtnl_lock(void) { return false; }
9622static inline void hdd_release_rtnl_lock(void) { }
9623#endif
9624
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009625#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009626
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309627/* MAX iwpriv command support */
9628#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309629#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309630#define MAX_PKTLOG_SIZE 16
9631
9632/**
9633 * hdd_pktlog_set_buff_size() - set pktlog buffer size
9634 * @hdd_ctx: hdd context
9635 * @set_value2: pktlog buffer size value
9636 *
9637 *
9638 * Return: 0 for success or error.
9639 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009640static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309641{
9642 struct sir_wifi_start_log start_log = { 0 };
9643 QDF_STATUS status;
9644
9645 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9646 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9647 start_log.ini_triggered = cds_is_packet_log_enabled();
9648 start_log.user_triggered = 1;
9649 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309650 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309651
Jeff Johnson16528362018-06-14 12:34:16 -07009652 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309653 if (!QDF_IS_STATUS_SUCCESS(status)) {
9654 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009655 hdd_exit();
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309656 return -EINVAL;
9657 }
9658
9659 return 0;
9660}
9661
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009662/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309663 * hdd_pktlog_clear_buff() - clear pktlog buffer
9664 * @hdd_ctx: hdd context
9665 *
9666 * Return: 0 for success or error.
9667 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009668static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309669{
9670 struct sir_wifi_start_log start_log;
9671 QDF_STATUS status;
9672
9673 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9674 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9675 start_log.ini_triggered = cds_is_packet_log_enabled();
9676 start_log.user_triggered = 1;
9677 start_log.size = 0;
9678 start_log.is_pktlog_buff_clear = true;
9679
Jeff Johnson16528362018-06-14 12:34:16 -07009680 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309681 if (!QDF_IS_STATUS_SUCCESS(status)) {
9682 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009683 hdd_exit();
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309684 return -EINVAL;
9685 }
9686
9687 return 0;
9688}
9689
9690
9691/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009692 * hdd_process_pktlog_command() - process pktlog command
9693 * @hdd_ctx: hdd context
9694 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309695 * @set_value2: pktlog buffer size value
9696 *
9697 * This function process pktlog command.
9698 * set_value2 only matters when set_value is 3 (set buff size)
9699 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009700 *
9701 * Return: 0 for success or error.
9702 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009703int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309704 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009705{
9706 int ret;
9707 bool enable;
9708 uint8_t user_triggered = 0;
9709
9710 ret = wlan_hdd_validate_context(hdd_ctx);
9711 if (0 != ret)
9712 return ret;
9713
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009714 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009715
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309716 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009717 hdd_err("invalid pktlog value %d", set_value);
9718 return -EINVAL;
9719 }
9720
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309721 if (set_value == PKTLOG_SET_BUFF_SIZE) {
9722 if (set_value2 <= 0) {
9723 hdd_err("invalid pktlog size %d", set_value2);
9724 return -EINVAL;
9725 } else if (set_value2 > MAX_PKTLOG_SIZE) {
9726 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
9727 return -EINVAL;
9728 }
9729 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309730 } else if (set_value == PKTLOG_CLEAR_BUFF) {
9731 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309732 }
9733
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009734 /*
9735 * set_value = 0 then disable packetlog
9736 * set_value = 1 enable packetlog forcefully
9737 * set_vlaue = 2 then disable packetlog if disabled through ini or
9738 * enable packetlog with AUTO type.
9739 */
9740 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
9741 true : false;
9742
9743 if (1 == set_value) {
9744 enable = true;
9745 user_triggered = 1;
9746 }
9747
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309748 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009749}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07009750
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009751/**
9752 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
9753 * @hdd_ctx: HDD context
9754 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309755 * @user_triggered: triggered through iwpriv
9756 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009757 *
9758 * Return: 0 on success; error number otherwise
9759 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009760int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309761 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009762{
9763 struct sir_wifi_start_log start_log;
9764 QDF_STATUS status;
9765
9766 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9767 start_log.verbose_level =
9768 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009769 start_log.ini_triggered = cds_is_packet_log_enabled();
9770 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309771 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309772 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05309773 /*
9774 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
9775 * commands. Host uses this flag to decide whether to send pktlog
9776 * disable command to fw without sending pktlog enable command
9777 * previously. For eg, If vendor sends pktlog disable command without
9778 * sending pktlog enable command, then host discards the packet
9779 * but for iwpriv command, host will send it to fw.
9780 */
9781 start_log.is_iwpriv_command = 1;
Jeff Johnson16528362018-06-14 12:34:16 -07009782 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009783 if (!QDF_IS_STATUS_SUCCESS(status)) {
9784 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009785 hdd_exit();
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009786 return -EINVAL;
9787 }
9788
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309789 if (enable == true)
9790 hdd_ctx->is_pktlog_enabled = 1;
9791 else
9792 hdd_ctx->is_pktlog_enabled = 0;
9793
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009794 return 0;
9795}
9796#endif /* REMOVE_PKT_LOG */
9797
Komal Seelam92fff912016-03-24 11:51:41 +05309798/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009799 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
9800 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05309801 * @dev: Device Pointer
9802 * @num: Number of Valid Mac address
9803 *
9804 * Return: Pointer to MAC address buffer
9805 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009806static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9807 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309808{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009809 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309810}
Komal Seelam92fff912016-03-24 11:51:41 +05309811
9812/**
9813 * hdd_populate_random_mac_addr() - API to populate random mac addresses
9814 * @hdd_ctx: HDD Context
9815 * @num: Number of random mac addresses needed
9816 *
9817 * Generate random addresses using bit manipulation on the base mac address
9818 *
9819 * Return: None
9820 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009821void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05309822{
9823 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
9824 uint32_t iter;
9825 struct hdd_config *ini = hdd_ctx->config;
9826 uint8_t *buf = NULL;
9827 uint8_t macaddr_b3, tmp_br3;
9828 uint8_t *src = ini->intfMacAddr[0].bytes;
9829
9830 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
9831 buf = ini->intfMacAddr[iter].bytes;
9832 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
9833 macaddr_b3 = buf[3];
9834 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
9835 INTF_MACADDR_MASK;
9836 macaddr_b3 += tmp_br3;
9837 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
9838 buf[0] |= 0x02;
9839 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009840 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309841 }
9842}
9843
9844/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009845 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05309846 * @hdd_ctx: HDD Context
9847 *
9848 * API to get mac addresses from platform driver and update the driver
9849 * structures and configure FW with the base mac address.
9850 * Return: int
9851 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009852static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309853{
9854 uint32_t no_of_mac_addr, iter;
9855 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
9856 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
9857 uint8_t *addr, *buf;
9858 struct device *dev = hdd_ctx->parent_dev;
9859 struct hdd_config *ini = hdd_ctx->config;
9860 tSirMacAddr mac_addr;
9861 QDF_STATUS status;
9862
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009863 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05309864
9865 if (no_of_mac_addr == 0 || !addr) {
9866 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
9867 return -EINVAL;
9868 }
9869
9870 if (no_of_mac_addr > max_mac_addr)
9871 no_of_mac_addr = max_mac_addr;
9872
9873 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
9874
9875 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
9876 buf = ini->intfMacAddr[iter].bytes;
9877 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009878 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309879 }
9880
9881 status = sme_set_custom_mac_addr(mac_addr);
9882
9883 if (!QDF_IS_STATUS_SUCCESS(status))
9884 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009885
Komal Seelam92fff912016-03-24 11:51:41 +05309886 if (no_of_mac_addr < max_mac_addr)
9887 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
9888 no_of_mac_addr);
9889 return 0;
9890}
9891
9892/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009893 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
9894 * @hdd_ctx: HDD Context
9895 *
9896 * Update MAC address to FW. If MAC address passed by FW is invalid, host
9897 * will generate its own MAC and update it to FW.
9898 *
9899 * Return: 0 for success
9900 * Non-zero error code for failure
9901 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009902static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009903{
9904 tSirMacAddr customMacAddr;
9905 QDF_STATUS status;
9906
9907 qdf_mem_copy(&customMacAddr,
9908 &hdd_ctx->config->intfMacAddr[0].bytes[0],
9909 sizeof(tSirMacAddr));
9910 status = sme_set_custom_mac_addr(customMacAddr);
9911 if (!QDF_IS_STATUS_SUCCESS(status))
9912 return -EAGAIN;
9913 return 0;
9914}
9915
9916/**
Komal Seelam92fff912016-03-24 11:51:41 +05309917 * hdd_initialize_mac_address() - API to get wlan mac addresses
9918 * @hdd_ctx: HDD Context
9919 *
9920 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
9921 * is provisioned with mac addresses, driver uses it, else it will use
9922 * wlan_mac.bin to update HW MAC addresses.
9923 *
9924 * Return: None
9925 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009926static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309927{
9928 QDF_STATUS status;
9929 int ret;
9930
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009931 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05309932 if (ret == 0)
9933 return;
9934
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009935 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
9936 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05309937
9938 status = hdd_update_mac_config(hdd_ctx);
9939
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009940 if (QDF_IS_STATUS_SUCCESS(status))
9941 return;
9942
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009943 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
9944 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009945
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009946 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009947 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009948 if (ret != 0) {
9949 hdd_err("MAC address out-of-sync, ret:%d", ret);
9950 QDF_ASSERT(ret);
9951 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009952 }
Komal Seelam92fff912016-03-24 11:51:41 +05309953}
9954
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009955static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009956{
9957 int vdev_id = 0;
9958 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
9959 int value = hdd_ctx->config->smart_chainmask_enabled;
9960 int vpdev = PDEV_CMD;
9961 int ret;
9962
Naveen Rawat247a8682017-06-05 15:00:31 -07009963 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009964 if (ret)
9965 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
9966
9967 return ret;
9968}
9969
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009970static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009971{
9972 int vdev_id = 0;
9973 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
9974 int value = hdd_ctx->config->alternative_chainmask_enabled;
9975 int vpdev = PDEV_CMD;
9976 int ret;
9977
Naveen Rawat247a8682017-06-05 15:00:31 -07009978 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009979 if (ret)
9980 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
9981 ret);
9982
9983 return ret;
9984}
9985
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009986static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07009987{
9988 int vdev_id = 0;
9989 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
9990 int value = hdd_ctx->config->ani_enabled;
9991 int vpdev = PDEV_CMD;
9992 int ret;
9993
Naveen Rawat247a8682017-06-05 15:00:31 -07009994 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07009995 if (ret)
9996 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
9997
9998 return ret;
9999}
10000
Jeff Johnson89c66ff2016-04-22 15:21:37 -070010001/**
Prashanth Bhatta07998752016-04-28 12:35:33 -070010002 * hdd_pre_enable_configure() - Configurations prior to cds_enable
10003 * @hdd_ctx: HDD context
10004 *
10005 * Pre configurations to be done at lower layer before calling cds enable.
10006 *
10007 * Return: 0 on success and errno on failure.
10008 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010009static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -070010010{
10011 int ret;
10012 QDF_STATUS status;
Leo Changfdb45c32016-10-28 11:09:23 -070010013 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010014
Leo Changfdb45c32016-10-28 11:09:23 -070010015 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Ajit Pal Singh5d269612018-04-19 16:29:12 +053010016 /* Register HL netdev flow control callback */
10017 cdp_hl_fc_register(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010018 /*
10019 * Set 802.11p config
10020 * TODO-OCB: This has been temporarily added here to ensure this
10021 * parameter is set in CSR when we init the channel list. This should
10022 * be removed once the 5.9 GHz channels are added to the regulatory
10023 * domain.
10024 */
10025 hdd_set_dot11p_config(hdd_ctx);
10026
10027 /*
10028 * Note that the cds_pre_enable() sequence triggers the cfg download.
10029 * The cfg download must occur before we update the SME config
10030 * since the SME config operation must access the cfg database
10031 */
10032 status = hdd_set_sme_config(hdd_ctx);
10033
10034 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010035 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010036 ret = qdf_status_to_os_return(status);
10037 goto out;
10038 }
10039
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -070010040 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
10041 if (QDF_STATUS_SUCCESS != status) {
10042 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
10043 ret = qdf_status_to_os_return(status);
10044 goto out;
10045 }
10046
Naveen Rawat247a8682017-06-05 15:00:31 -070010047 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -070010048 hdd_ctx->config->tx_chain_mask_1ss,
10049 PDEV_CMD);
10050 if (0 != ret) {
10051 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
10052 goto out;
10053 }
10054
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010055 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
10056 if (ret)
10057 goto out;
10058
10059 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
10060 if (ret)
10061 goto out;
10062
Jeff Johnson12a744b2017-04-04 08:19:37 -070010063 ret = hdd_set_ani_enabled(hdd_ctx);
10064 if (ret)
10065 goto out;
10066
Naveen Rawat247a8682017-06-05 15:00:31 -070010067 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -080010068 hdd_ctx->config->arp_ac_category,
10069 PDEV_CMD);
10070 if (0 != ret) {
10071 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
10072 hdd_ctx->config->arp_ac_category, ret);
10073 goto out;
10074 }
10075
Prashanth Bhatta07998752016-04-28 12:35:33 -070010076 status = hdd_set_sme_chan_list(hdd_ctx);
10077 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010078 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010079 ret = qdf_status_to_os_return(status);
10080 goto out;
10081 }
10082
10083 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -070010084 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010085 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -070010086 ret = -EINVAL;
10087 goto out;
10088 }
10089
Prashanth Bhatta07998752016-04-28 12:35:33 -070010090 /*
10091 * Set the MAC Address Currently this is used by HAL to add self sta.
10092 * Remove this once self sta is added as part of session open.
10093 */
Jeff Johnson16528362018-06-14 12:34:16 -070010094 status = sme_cfg_set_str(hdd_ctx->mac_handle, WNI_CFG_STA_ID,
Jeff Johnsonbae59f92018-06-01 17:05:43 -070010095 hdd_ctx->config->intfMacAddr[0].bytes,
10096 sizeof(hdd_ctx->config->intfMacAddr[0]));
Prashanth Bhatta07998752016-04-28 12:35:33 -070010097
Jeff Johnsonbae59f92018-06-01 17:05:43 -070010098 if (QDF_IS_STATUS_ERROR(status)) {
10099 hdd_err("Failed to set MAC Address, status %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010100 ret = -EINVAL;
10101 goto out;
10102 }
10103
10104 hdd_init_channel_avoidance(hdd_ctx);
10105
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +053010106 /* update enable sap mandatory chan list */
10107 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
10108 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010109out:
10110 return ret;
10111}
10112
10113/**
Peng Xu8fdaa492016-06-22 10:20:47 -070010114 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010115 * @context: context registered with sme_register_p2p_lo_event(). HDD
10116 * always registers a hdd context pointer
10117 * @evt:event structure pointer
Peng Xu8fdaa492016-06-22 10:20:47 -070010118 *
10119 * This is the p2p listen offload stop event handler, it sends vendor
10120 * event back to supplicant to notify the stop reason.
10121 *
10122 * Return: None
10123 */
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010124static void wlan_hdd_p2p_lo_event_callback(void *context,
10125 struct sir_p2p_lo_event *evt)
Peng Xu8fdaa492016-06-22 10:20:47 -070010126{
Jeff Johnsonf7e36d62018-07-04 21:14:02 -070010127 struct hdd_context *hdd_ctx = context;
Peng Xu8fdaa492016-06-22 10:20:47 -070010128 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -070010129 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -070010130
Dustin Brown491d54b2018-03-14 12:39:11 -070010131 hdd_enter();
Peng Xu8fdaa492016-06-22 10:20:47 -070010132
10133 if (hdd_ctx == NULL) {
10134 hdd_err("Invalid HDD context pointer");
10135 return;
10136 }
10137
Peng Xu5c682812017-08-06 07:39:13 -070010138 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
10139 if (!adapter) {
10140 hdd_err("Cannot find adapter by vdev_id = %d",
10141 evt->vdev_id);
10142 return;
10143 }
10144
Peng Xu8fdaa492016-06-22 10:20:47 -070010145 vendor_event =
10146 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -070010147 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -070010148 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
10149 GFP_KERNEL);
10150
10151 if (!vendor_event) {
10152 hdd_err("cfg80211_vendor_event_alloc failed");
10153 return;
10154 }
10155
10156 if (nla_put_u32(vendor_event,
10157 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
10158 evt->reason_code)) {
10159 hdd_err("nla put failed");
10160 kfree_skb(vendor_event);
10161 return;
10162 }
10163
10164 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -070010165 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
10166 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -070010167}
10168
10169/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010170 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
10171 * @hdd_ctx: HDD context
10172 *
10173 * This function sends the adaptive dwell time config configuration to the
10174 * firmware via WMA
10175 *
10176 * Return: 0 - success, < 0 - failure
10177 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010178static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010179{
10180 QDF_STATUS status;
10181 struct adaptive_dwelltime_params dwelltime_params;
10182
10183 dwelltime_params.is_enabled =
10184 hdd_ctx->config->adaptive_dwell_mode_enabled;
10185 dwelltime_params.dwelltime_mode =
10186 hdd_ctx->config->global_adapt_dwelltime_mode;
10187 dwelltime_params.lpf_weight =
10188 hdd_ctx->config->adapt_dwell_lpf_weight;
10189 dwelltime_params.passive_mon_intval =
10190 hdd_ctx->config->adapt_dwell_passive_mon_intval;
10191 dwelltime_params.wifi_act_threshold =
10192 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
10193
Jeff Johnson16528362018-06-14 12:34:16 -070010194 status = sme_set_adaptive_dwelltime_config(hdd_ctx->mac_handle,
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010195 &dwelltime_params);
10196
10197 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
10198 if (!QDF_IS_STATUS_SUCCESS(status)) {
10199 hdd_err("Failed to send Adaptive Dwelltime configuration!");
10200 return -EAGAIN;
10201 }
10202 return 0;
10203}
10204
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010205int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010206{
10207 QDF_STATUS status;
10208 struct wmi_dbs_scan_sel_params dbs_scan_params;
10209 uint32_t i = 0;
10210 uint8_t count = 0, numentries = 0;
10211 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
10212 * CDS_DBS_SCAN_CLIENTS_MAX];
10213
10214 /* check if DBS is enabled or supported */
Bala Venkateshc8236ca2018-03-09 12:38:29 +053010215 if ((hdd_ctx->config->dual_mac_feature_disable ==
10216 DISABLE_DBS_CXN_AND_SCAN) ||
10217 (hdd_ctx->config->dual_mac_feature_disable ==
10218 ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN))
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010219 return -EINVAL;
10220
10221 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
10222 dbs_scan_config, &numentries,
10223 (CDS_DBS_SCAN_PARAM_PER_CLIENT
10224 * CDS_DBS_SCAN_CLIENTS_MAX));
10225
10226 hdd_info("numentries %hu", numentries);
10227 if (!numentries) {
10228 hdd_info("Donot send scan_selection_config");
10229 return 0;
10230 }
10231
10232 /* hdd_set_fw_log_params */
10233 dbs_scan_params.num_clients = 0;
10234 while (count < (numentries - 2)) {
10235 dbs_scan_params.module_id[i] = dbs_scan_config[count];
10236 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
10237 dbs_scan_params.num_non_dbs_scans[i] =
10238 dbs_scan_config[count + 2];
10239 dbs_scan_params.num_clients++;
10240 hdd_debug("module:%d NDS:%d NNDS:%d",
10241 dbs_scan_params.module_id[i],
10242 dbs_scan_params.num_dbs_scans[i],
10243 dbs_scan_params.num_non_dbs_scans[i]);
10244 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
10245 i++;
10246 }
10247
10248 dbs_scan_params.pdev_id = 0;
10249
10250 hdd_debug("clients:%d pdev:%d",
10251 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
10252
Jeff Johnson16528362018-06-14 12:34:16 -070010253 status = sme_set_dbs_scan_selection_config(hdd_ctx->mac_handle,
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010254 &dbs_scan_params);
10255 hdd_debug("Sending DBS Scan Selection Configuration to fw");
10256 if (!QDF_IS_STATUS_SUCCESS(status)) {
10257 hdd_err("Failed to send DBS Scan selection configuration!");
10258 return -EAGAIN;
10259 }
10260 return 0;
10261}
10262
Arun Khandavallid4349a92016-07-25 11:10:43 +053010263#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10264/**
10265 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
10266 * @hdd_ctx: HDD context
10267 *
10268 * Set auto shutdown callback to get indications from firmware to indicate
10269 * userspace to shutdown WLAN after a configured amount of inactivity.
10270 *
10271 * Return: 0 on success and errno on failure.
10272 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010273static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010274{
10275 QDF_STATUS status;
10276
10277 if (!hdd_ctx->config->WlanAutoShutdown)
10278 return 0;
10279
Jeff Johnson16528362018-06-14 12:34:16 -070010280 status = sme_set_auto_shutdown_cb(hdd_ctx->mac_handle,
Arun Khandavallid4349a92016-07-25 11:10:43 +053010281 wlan_hdd_auto_shutdown_cb);
10282 if (status != QDF_STATUS_SUCCESS)
10283 hdd_err("Auto shutdown feature could not be enabled: %d",
10284 status);
10285
10286 return qdf_status_to_os_return(status);
10287}
10288#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010289static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010290{
10291 return 0;
10292}
10293#endif
10294
10295/**
10296 * hdd_features_init() - Init features
10297 * @hdd_ctx: HDD context
Arun Khandavallid4349a92016-07-25 11:10:43 +053010298 *
10299 * Initialize features and their feature context after WLAN firmware is up.
10300 *
10301 * Return: 0 on success and errno on failure.
10302 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010303static int hdd_features_init(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010304{
10305 tSirTxPowerLimit hddtxlimit;
10306 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +053010307 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010308 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070010309 mac_handle_t mac_handle;
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010310 struct hdd_config *cfg;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010311
Dustin Brown491d54b2018-03-14 12:39:11 -070010312 hdd_enter();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010313
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010314 cfg = hdd_ctx->config;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010315 /* FW capabilities received, Set the Dot11 mode */
Jeff Johnson16528362018-06-14 12:34:16 -070010316 mac_handle = hdd_ctx->mac_handle;
10317 sme_setdef_dot11mode(mac_handle);
10318 sme_set_prefer_80MHz_over_160MHz(mac_handle,
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -070010319 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010320 sme_set_etsi13_srd_ch_in_master_mode(mac_handle,
10321 cfg->
10322 etsi13_srd_chan_in_master_mode);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010323
10324 if (hdd_ctx->config->fIsImpsEnabled)
10325 hdd_set_idle_ps_config(hdd_ctx, true);
10326 else
10327 hdd_set_idle_ps_config(hdd_ctx, false);
10328
Poddar, Siddarth37033032017-10-11 15:47:40 +053010329 /* Send Enable/Disable data stall detection cmd to FW */
10330 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
10331 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
10332
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010333 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Jeff Johnson16528362018-06-14 12:34:16 -070010334 sme_set_cts2self_for_p2p_go(mac_handle);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010335
Nachiket Kukade8983cf62017-10-12 18:14:48 +053010336 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
10337 hdd_warn("Error in setting Voltage Corner mode config to FW");
10338
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010339 if (hdd_rx_ol_init(hdd_ctx))
10340 hdd_err("Unable to initialize Rx LRO/GRO in fw");
Arun Khandavallid4349a92016-07-25 11:10:43 +053010341
10342 if (hdd_adaptive_dwelltime_init(hdd_ctx))
10343 hdd_err("Unable to send adaptive dwelltime setting to FW");
10344
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010345 if (hdd_dbs_scan_selection_init(hdd_ctx))
10346 hdd_err("Unable to send DBS scan selection setting to FW");
10347
Arun Khandavallid4349a92016-07-25 11:10:43 +053010348 ret = hdd_init_thermal_info(hdd_ctx);
10349 if (ret) {
10350 hdd_err("Error while initializing thermal information");
Dustin Browne7e71d32018-05-11 16:00:08 -070010351 return ret;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010352 }
10353
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010354 /**
10355 * In case of SSR/PDR, if pktlog was enabled manually before
10356 * SSR/PDR, Then enabled it again automatically after Wlan
10357 * device up.
10358 */
10359 if (cds_is_driver_recovering()) {
10360 if (hdd_ctx->is_pktlog_enabled)
10361 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Tiger Yuf3d5d7f2018-03-15 14:48:11 +080010362 }
Poddar, Siddarth66a46592017-02-22 11:44:44 +053010363
Arun Khandavallid4349a92016-07-25 11:10:43 +053010364 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
10365 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
Jeff Johnson16528362018-06-14 12:34:16 -070010366 status = sme_txpower_limit(mac_handle, &hddtxlimit);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010367 if (!QDF_IS_STATUS_SUCCESS(status))
10368 hdd_err("Error setting txlimit in sme: %d", status);
10369
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010370 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010371
Arun Khandavallid4349a92016-07-25 11:10:43 +053010372 ret = hdd_register_cb(hdd_ctx);
10373 if (ret) {
10374 hdd_err("Failed to register HDD callbacks!");
Dustin Browne7e71d32018-05-11 16:00:08 -070010375 return ret;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010376 }
10377
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +053010378 if (hdd_ctx->config->goptimize_chan_avoid_event) {
10379 status = sme_enable_disable_chanavoidind_event(
Jeff Johnson16528362018-06-14 12:34:16 -070010380 mac_handle, 0);
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +053010381 if (!QDF_IS_STATUS_SUCCESS(status)) {
10382 hdd_err("Failed to disable Chan Avoidance Indication");
10383 goto deregister_cb;
10384 }
10385 }
Arun Khandavallid4349a92016-07-25 11:10:43 +053010386
Manjeet Singha9cae432017-02-28 11:58:22 +053010387 if (hdd_ctx->config->enable_5g_band_pref) {
10388 band_pref_params.rssi_boost_threshold_5g =
10389 hdd_ctx->config->rssi_boost_threshold_5g;
10390 band_pref_params.rssi_boost_factor_5g =
10391 hdd_ctx->config->rssi_boost_factor_5g;
10392 band_pref_params.max_rssi_boost_5g =
10393 hdd_ctx->config->max_rssi_boost_5g;
10394 band_pref_params.rssi_penalize_threshold_5g =
10395 hdd_ctx->config->rssi_penalize_threshold_5g;
10396 band_pref_params.rssi_penalize_factor_5g =
10397 hdd_ctx->config->rssi_penalize_factor_5g;
10398 band_pref_params.max_rssi_penalize_5g =
10399 hdd_ctx->config->max_rssi_penalize_5g;
Jeff Johnson16528362018-06-14 12:34:16 -070010400 sme_set_5g_band_pref(mac_handle, &band_pref_params);
Manjeet Singha9cae432017-02-28 11:58:22 +053010401 }
10402
Arun Khandavallid4349a92016-07-25 11:10:43 +053010403 /* register P2P Listen Offload event callback */
10404 if (wma_is_p2p_lo_capable())
Jeff Johnson16528362018-06-14 12:34:16 -070010405 sme_register_p2p_lo_event(mac_handle, hdd_ctx,
10406 wlan_hdd_p2p_lo_event_callback);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010407
10408 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
10409
10410 if (ret)
10411 goto deregister_cb;
10412
Dustin Brown11638b72018-01-25 17:37:25 +053010413 wlan_hdd_init_chan_info(hdd_ctx);
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010414 wlan_hdd_twt_init(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010415
Dustin Browne74003f2018-03-14 12:51:58 -070010416 hdd_exit();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010417 return 0;
10418
10419deregister_cb:
10420 hdd_deregister_cb(hdd_ctx);
Dustin Browne7e71d32018-05-11 16:00:08 -070010421
Arun Khandavallid4349a92016-07-25 11:10:43 +053010422 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010423}
10424
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010425/**
10426 * hdd_features_deinit() - Deinit features
10427 * @hdd_ctx: HDD context
10428 *
10429 * De-Initialize features and their feature context.
10430 *
10431 * Return: none.
10432 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010433static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010434{
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010435 wlan_hdd_twt_deinit(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010436 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010437 wlan_hdd_tsf_deinit(hdd_ctx);
10438}
10439
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010440/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010441 * hdd_register_bcn_cb() - register scan beacon callback
10442 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010443 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010444 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010445 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010446static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010447{
10448 QDF_STATUS status;
10449
10450 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
10451 wlan_cfg80211_inform_bss_frame,
10452 SCAN_CB_TYPE_INFORM_BCN);
10453 if (!QDF_IS_STATUS_SUCCESS(status)) {
10454 hdd_err("failed with status code %08d [x%08x]",
10455 status, status);
10456 return status;
10457 }
10458
10459 return QDF_STATUS_SUCCESS;
10460}
Arun Khandavallid4349a92016-07-25 11:10:43 +053010461
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010462/**
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070010463 * hdd_v2_flow_pool_map() - Flow pool create callback when vdev is active
10464 * @vdev_id: vdev_id, corresponds to flow_pool
10465 *
10466 * Return: none.
10467 */
10468static void hdd_v2_flow_pool_map(int vdev_id)
10469{
10470 QDF_STATUS status;
10471
10472 status = cdp_flow_pool_map(cds_get_context(QDF_MODULE_ID_SOC),
10473 cds_get_context(QDF_MODULE_ID_TXRX),
10474 vdev_id);
10475 /*
10476 * For Adrastea flow control v2 is based on FW MAP events,
10477 * so this above callback is not implemented.
10478 * Hence this is not actual failure. Dont return failure
10479 */
10480 if ((status != QDF_STATUS_SUCCESS) &&
10481 (status != QDF_STATUS_E_INVAL)) {
10482 hdd_err("vdev_id: %d, failed to create flow pool status %d",
10483 vdev_id, status);
10484 }
10485}
10486
10487/**
10488 * hdd_v2_flow_pool_unmap() - Flow pool create callback when vdev is not active
10489 * @vdev_id: vdev_id, corresponds to flow_pool
10490 *
10491 * Return: none.
10492 */
10493static void hdd_v2_flow_pool_unmap(int vdev_id)
10494{
10495 cdp_flow_pool_unmap(cds_get_context(QDF_MODULE_ID_SOC),
10496 cds_get_context(QDF_MODULE_ID_TXRX), vdev_id);
10497}
10498
10499/**
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010500 * hdd_action_oui_config() - Configure action_oui strings
10501 * @hdd_ctx: pointer to hdd context
10502 *
10503 * This is a HDD wrapper function which invokes ucfg api
10504 * of action_oui component to parse action oui strings.
10505 *
10506 * Return: None
10507 */
10508static void hdd_action_oui_config(struct hdd_context *hdd_ctx)
10509{
10510 QDF_STATUS status;
10511 uint32_t id;
10512 uint8_t *str;
10513
10514 if (!hdd_ctx->config->action_oui_enable)
10515 return;
10516
10517 for (id = 0; id < ACTION_OUI_MAXIMUM_ID; id++) {
10518 str = hdd_ctx->config->action_oui_str[id];
10519 if (!qdf_str_len(str))
10520 continue;
10521
10522 status = ucfg_action_oui_parse(hdd_ctx->hdd_psoc, str, id);
10523 if (!QDF_IS_STATUS_SUCCESS(status))
10524 hdd_err("Failed to parse action_oui str: %u", id);
10525 }
10526}
10527
10528/**
10529 * hdd_action_oui_send() - Send action_oui extensions to firmware
10530 * @hdd_ctx: pointer to hdd context
10531 *
10532 * This is a HDD wrapper function which invokes ucfg api
10533 * of action_oui component to send action oui extensions to firmware.
10534 *
10535 * Return: None
10536 */
10537static void hdd_action_oui_send(struct hdd_context *hdd_ctx)
10538{
10539 QDF_STATUS status;
10540
10541 if (!hdd_ctx->config->action_oui_enable)
10542 return;
10543
10544 status = ucfg_action_oui_send(hdd_ctx->hdd_psoc);
10545 if (!QDF_IS_STATUS_SUCCESS(status))
10546 hdd_err("Failed to send one or all action_ouis");
10547}
10548
10549/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010550 * hdd_configure_cds() - Configure cds modules
10551 * @hdd_ctx: HDD context
10552 * @adapter: Primary adapter context
10553 *
10554 * Enable Cds modules after WLAN firmware is up.
10555 *
10556 * Return: 0 on success and errno on failure.
10557 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010558int hdd_configure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010559{
10560 int ret;
10561 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010562 int set_value;
Jeff Johnson16528362018-06-14 12:34:16 -070010563 mac_handle_t mac_handle;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010564 uint32_t num_abg_tx_chains = 0;
10565 uint32_t num_11b_tx_chains = 0;
10566 uint32_t num_11ag_tx_chains = 0;
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010567 struct policy_mgr_dp_cbacks dp_cbs = {0};
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010568
Jeff Johnson16528362018-06-14 12:34:16 -070010569 mac_handle = hdd_ctx->mac_handle;
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053010570
10571 hdd_action_oui_send(hdd_ctx);
10572
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010573 if (hdd_ctx->config->is_force_1x1)
10574 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
10575 1, PDEV_CMD);
10576 /* set chip power save failure detected callback */
Jeff Johnson16528362018-06-14 12:34:16 -070010577 sme_set_chip_pwr_save_fail_cb(mac_handle,
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010578 hdd_chip_pwr_save_fail_detected_cb);
10579
10580 if (hdd_ctx->config->max_mpdus_inampdu) {
10581 set_value = hdd_ctx->config->max_mpdus_inampdu;
10582 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
10583 set_value, PDEV_CMD);
10584 }
10585
10586 if (hdd_ctx->config->enable_rts_sifsbursting) {
10587 set_value = hdd_ctx->config->enable_rts_sifsbursting;
10588 sme_cli_set_command(0,
10589 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
10590 set_value, PDEV_CMD);
10591 }
10592
10593 if (hdd_ctx->config->sap_get_peer_info) {
10594 set_value = hdd_ctx->config->sap_get_peer_info;
10595 sme_cli_set_command(0,
10596 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
10597 set_value, PDEV_CMD);
10598 }
10599
10600 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
10601 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
10602 if (!hdd_ctx->config->enable2x2) {
10603 if (num_11b_tx_chains > 1)
10604 num_11b_tx_chains = 1;
10605 if (num_11ag_tx_chains > 1)
10606 num_11ag_tx_chains = 1;
10607 }
10608 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
10609 num_11b_tx_chains);
10610 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
10611 num_11ag_tx_chains);
10612 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
10613 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +053010614
10615 ret = hdd_pre_enable_configure(hdd_ctx);
10616 if (ret) {
10617 hdd_err("Failed to pre-configure cds");
10618 goto out;
10619 }
10620
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010621 /* Always get latest IPA resources allocated from cds_open and configure
10622 * IPA module before configuring them to FW. Sequence required as crash
10623 * observed otherwise.
10624 */
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010625 if (ucfg_ipa_uc_ol_init(hdd_ctx->hdd_pdev,
10626 cds_get_context(QDF_MODULE_ID_QDF_DEVICE))) {
Manikandan Mohan2e803a02017-02-14 14:57:53 -080010627 hdd_err("Failed to setup pipes");
10628 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010629 }
10630
Arun Khandavallifae92942016-08-01 13:31:08 +053010631 /*
10632 * Start CDS which starts up the SME/MAC/HAL modules and everything
10633 * else
10634 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -070010635 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010636
10637 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010638 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053010639 goto out;
10640 }
10641
10642 status = hdd_post_cds_enable_config(hdd_ctx);
10643 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010644 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010645 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010646 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010647 status = hdd_register_bcn_cb(hdd_ctx);
10648 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +080010649 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010650 goto cds_disable;
10651 }
Arun Khandavallifae92942016-08-01 13:31:08 +053010652
Dustin Browne7e71d32018-05-11 16:00:08 -070010653 ret = hdd_features_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010654 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010655 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010656
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010657 if (hdd_ctx->ol_enable)
10658 dp_cbs.hdd_disable_rx_ol_in_concurrency =
10659 hdd_disable_rx_ol_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -070010660 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
jiadbb47e132018-03-30 16:28:30 +080010661 dp_cbs.hdd_ipa_set_mcc_mode_cb = hdd_ipa_set_mcc_mode;
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070010662 dp_cbs.hdd_v2_flow_pool_map = hdd_v2_flow_pool_map;
10663 dp_cbs.hdd_v2_flow_pool_unmap = hdd_v2_flow_pool_unmap;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010664 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
10665 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -070010666 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010667 goto cds_disable;
10668 }
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010669 status = policy_mgr_register_mode_change_cb(hdd_ctx->hdd_psoc,
10670 wlan_hdd_send_mode_change_event);
10671 if (!QDF_IS_STATUS_SUCCESS(status)) {
10672 hdd_debug("Failed to register mode change cb with Policy Manager");
10673 goto cds_disable;
10674 }
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010675
Jeff Johnson8bb61112018-03-31 13:33:54 -070010676 if (hdd_green_ap_enable_egap(hdd_ctx))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +053010677 hdd_debug("enhance green ap is not enabled");
10678
Nachiket Kukadedd302662017-07-13 17:31:44 +053010679 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
10680 hdd_debug("Failed to set wow pulse");
10681
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053010682 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
10683 hdd_ctx->config->gcmp_enabled, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053010684 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
10685 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
10686
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053010687
10688 if (hdd_ctx->config->enable_phy_reg_retention)
10689 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
10690 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
10691
Arun Khandavallifae92942016-08-01 13:31:08 +053010692 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010693
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010694cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010695 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010696
Arun Khandavallifae92942016-08-01 13:31:08 +053010697out:
10698 return -EINVAL;
10699}
10700
10701/**
10702 * hdd_deconfigure_cds() -De-Configure cds
10703 * @hdd_ctx: HDD context
10704 *
10705 * Deconfigure Cds modules before WLAN firmware is down.
10706 *
10707 * Return: 0 on success and errno on failure.
10708 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010709static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010710{
10711 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070010712 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053010713
Dustin Brown491d54b2018-03-14 12:39:11 -070010714 hdd_enter();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010715
10716 /* De-init features */
10717 hdd_features_deinit(hdd_ctx);
10718
Arun Khandavallifae92942016-08-01 13:31:08 +053010719 /* De-register the SME callbacks */
10720 hdd_deregister_cb(hdd_ctx);
10721
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010722 qdf_status = policy_mgr_deregister_mode_change_cb(hdd_ctx->hdd_psoc);
10723 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10724 hdd_debug("Failed to deregister mode change cb with Policy Manager");
10725 }
10726
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010727 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010728 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10729 hdd_err("Failed to Disable the CDS Modules! :%d",
10730 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070010731 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010732 }
10733
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010734 if (ucfg_ipa_uc_ol_deinit(hdd_ctx->hdd_pdev) != QDF_STATUS_SUCCESS) {
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053010735 hdd_err("Failed to disconnect pipes");
10736 ret = -EINVAL;
10737 }
10738
Dustin Browne74003f2018-03-14 12:51:58 -070010739 hdd_exit();
Houston Hoffman6640cf32016-10-10 16:44:29 -070010740 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010741}
10742
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010743#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
10744static void hdd_deregister_policy_manager_callback(
10745 struct wlan_objmgr_psoc *psoc)
10746{
10747 if (QDF_STATUS_SUCCESS !=
10748 policy_mgr_deregister_hdd_cb(psoc)) {
10749 hdd_err("HDD callback deregister with policy manager failed");
10750 }
10751}
10752#else
10753static void hdd_deregister_policy_manager_callback(
10754 struct wlan_objmgr_psoc *psoc)
10755{
10756}
10757#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010758
10759/**
10760 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
10761 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010762 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +053010763 *
10764 * This function maintains the driver state machine it will be invoked from
10765 * exit, shutdown and con_mode change handler. Depending on the driver state
10766 * shall perform the stopping/closing of the modules.
10767 *
10768 * Return: 0 for success; non-zero for failure
10769 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010770int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053010771{
10772 void *hif_ctx;
10773 qdf_device_t qdf_ctx;
10774 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010775 int ret = 0;
Dustin Brown4bc0a622017-12-06 15:56:50 -080010776 bool is_recovery_stop = cds_is_driver_recovering();
Liangwei Donga78cc1d2018-02-01 02:19:30 -050010777 bool is_idle_stop = !cds_is_driver_unloading() && !is_recovery_stop &&
10778 !cds_is_driver_loading();
Dustin Brown70111822017-03-30 15:31:40 -070010779 int active_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010780 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053010781
Dustin Brown491d54b2018-03-14 12:39:11 -070010782 hdd_enter();
Yun Parkfec73dc2017-09-06 10:40:07 -070010783 hdd_alert("stop WLAN module: entering driver status=%d",
10784 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +053010785
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010786 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
10787
Arun Khandavallifae92942016-08-01 13:31:08 +053010788 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
10789 if (!qdf_ctx) {
10790 hdd_err("QDF device context NULL");
10791 return -EINVAL;
10792 }
10793
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010794 mutex_lock(&hdd_ctx->iface_change_lock);
10795 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010796 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053010797
Dustin Brown70111822017-03-30 15:31:40 -070010798 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -070010799 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -070010800 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -070010801 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -070010802
10803 cds_print_external_threads();
10804
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010805 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070010806 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -070010807 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10808 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010809 hdd_prevent_suspend_timeout(
10810 hdd_ctx->config->iface_change_wait_time,
10811 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010812 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010813 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -070010814 return 0;
10815 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070010816 }
10817
Arun Khandavallifae92942016-08-01 13:31:08 +053010818 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
10819
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080010820 /* free user wowl patterns */
10821 hdd_free_user_wowl_ptrns();
10822
Arun Khandavallifae92942016-08-01 13:31:08 +053010823 switch (hdd_ctx->driver_status) {
10824 case DRIVER_MODULES_UNINITIALIZED:
10825 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010826 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010827 case DRIVER_MODULES_CLOSED:
10828 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010829 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010830 case DRIVER_MODULES_ENABLED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010831 hdd_info("Wlan transitioning (OPENED <- ENABLED)");
10832
Komal Seelamf2136bb2016-09-28 18:30:44 +053010833 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053010834 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010835 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053010836 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010837 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010838 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010839 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080010840
Arun Khandavallifae92942016-08-01 13:31:08 +053010841 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010842 hdd_info("Wlan transitioned (now OPENED)");
10843
10844 /* fall through */
Arun Khandavallifae92942016-08-01 13:31:08 +053010845 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010846 hdd_info("Wlan transitioning (CLOSED <- OPENED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010847 break;
10848 default:
10849 hdd_err("Trying to stop wlan in a wrong state: %d",
10850 hdd_ctx->driver_status);
10851 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010852 ret = -EINVAL;
10853 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010854 }
10855
Amar Singhal18081642018-01-26 16:04:13 -080010856 hdd_sysfs_destroy_version_interface();
Dustin Brown550f6d22017-12-14 15:44:01 -080010857 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080010858
Rajeev Kumarbe021242017-02-16 16:12:23 -080010859 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053010860 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10861 hdd_err("Failed to process post CDS disable Modules! :%d",
10862 qdf_status);
10863 ret = -EINVAL;
10864 QDF_ASSERT(0);
10865 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010866
psimhadeea0a12017-12-18 14:50:02 -080010867 hdd_runtime_suspend_context_deinit(hdd_ctx);
10868
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010869 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
10870 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10871 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
10872 ret = -EINVAL;
10873 QDF_ASSERT(0);
10874 }
10875
Jeff Johnsone4b14592017-09-13 14:23:33 -070010876 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010877 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010878 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053010879 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010880 QDF_ASSERT(0);
10881 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -070010882
Amar Singhal410675c2018-01-10 12:14:21 -080010883 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Liangwei Dong50a64a72018-01-11 01:17:00 -050010884 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
10885 if (ret) {
10886 hdd_err("Failed to destroy pdev; errno:%d", ret);
10887 QDF_ASSERT(0);
10888 }
10889
10890 /*
10891 * Reset total mac phy during module stop such that during
10892 * next module start same psoc is used to populate new service
10893 * ready data
10894 */
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010895 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
10896 if (tgt_hdl)
10897 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
10898
Liangwei Dong50a64a72018-01-11 01:17:00 -050010899
Arun Khandavallifae92942016-08-01 13:31:08 +053010900 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
10901 if (!hif_ctx) {
10902 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010903 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010904 }
10905
Arunk Khandavalli4b404332017-09-26 12:46:00 +053010906 if (hdd_ctx->target_hw_name) {
10907 qdf_mem_free(hdd_ctx->target_hw_name);
10908 hdd_ctx->target_hw_name = NULL;
10909 }
10910
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053010911 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010912
10913 ol_cds_free();
10914
Dustin Brown70111822017-03-30 15:31:40 -070010915 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +053010916 ret = pld_power_off(qdf_ctx->dev);
10917 if (ret)
10918 hdd_err("CNSS power down failed put device into Low power mode:%d",
10919 ret);
10920 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010921
Dustin Brown4bc0a622017-12-06 15:56:50 -080010922 /* many adapter resources are not freed by design in SSR case */
10923 if (!is_recovery_stop)
Dustin Browna6246dd2018-05-24 14:35:58 -070010924 hdd_check_for_leaks(hdd_ctx);
Dustin Brown26b3d042017-12-21 11:13:27 -080010925 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010926
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010927 /* Once the firmware sequence is completed reset this flag */
10928 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053010929 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010930 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010931
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010932done:
10933 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010934 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010935 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -070010936 hdd_alert("stop WLAN module: exit driver status=%d",
10937 hdd_ctx->driver_status);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010938
Dustin Browne74003f2018-03-14 12:51:58 -070010939 hdd_exit();
Arun Khandavallifae92942016-08-01 13:31:08 +053010940
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010941 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010942}
10943
Arun Khandavallifae92942016-08-01 13:31:08 +053010944
Wen Gong3f003382018-05-14 14:26:37 +080010945#ifdef WLAN_FEATURE_MEMDUMP_ENABLE
Arun Khandavallifae92942016-08-01 13:31:08 +053010946/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010947 * hdd_state_info_dump() - prints state information of hdd layer
10948 * @buf: buffer pointer
10949 * @size: size of buffer to be filled
10950 *
10951 * This function is used to dump state information of hdd layer
10952 *
10953 * Return: None
10954 */
10955static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
10956{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010957 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070010958 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070010959 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010960 uint16_t len = 0;
10961 char *buf = *buf_ptr;
10962
10963 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10964 if (!hdd_ctx) {
10965 hdd_err("Failed to get hdd context ");
10966 return;
10967 }
10968
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010969 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010970
10971 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070010972 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010973 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080010974 "\n is_scheduler_suspended %d",
10975 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010976
Dustin Brown920397d2017-12-13 16:27:50 -080010977 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010978 if (adapter->dev)
10979 len += scnprintf(buf + len, *size - len,
10980 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080010981 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010982 "\n device_mode: %d", adapter->device_mode);
10983 switch (adapter->device_mode) {
10984 case QDF_STA_MODE:
10985 case QDF_P2P_CLIENT_MODE:
10986 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
10987 len += scnprintf(buf + len, *size - len,
10988 "\n connState: %d",
10989 hdd_sta_ctx->conn_info.connState);
10990 break;
10991
10992 default:
10993 break;
10994 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010995 }
10996
10997 *size -= len;
10998 *buf_ptr += len;
10999}
11000
11001/**
11002 * hdd_register_debug_callback() - registration function for hdd layer
11003 * to print hdd state information
11004 *
11005 * Return: None
11006 */
11007static void hdd_register_debug_callback(void)
11008{
11009 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
11010}
Wen Gong3f003382018-05-14 14:26:37 +080011011#else /* WLAN_FEATURE_MEMDUMP_ENABLE */
Wen Gongaa6d55d2018-04-26 16:33:21 +080011012static void hdd_register_debug_callback(void)
11013{
11014}
Wen Gong3f003382018-05-14 14:26:37 +080011015#endif /* WLAN_FEATURE_MEMDUMP_ENABLE */
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011016
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053011017/*
11018 * wlan_init_bug_report_lock() - Initialize bug report lock
11019 *
11020 * This function is used to create bug report lock
11021 *
11022 * Return: None
11023 */
11024static void wlan_init_bug_report_lock(void)
11025{
Jeff Johnson2b6982c2018-05-29 14:56:11 -070011026 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053011027
11028 p_cds_context = cds_get_global_context();
11029 if (!p_cds_context) {
11030 hdd_err("cds context is NULL");
11031 return;
11032 }
11033
11034 qdf_spinlock_create(&p_cds_context->bug_report_lock);
11035}
11036
Nirav Shahd21a2e32018-04-20 16:34:43 +053011037#ifdef CONFIG_DP_TRACE
Mohit Khannaf8f96822017-05-17 17:11:59 -070011038void hdd_dp_trace_init(struct hdd_config *config)
11039{
Mohit Khannaf8f96822017-05-17 17:11:59 -070011040 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
11041 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
11042 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
11043 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
11044 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
11045 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
11046 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080011047 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070011048
Nirav Shahd21a2e32018-04-20 16:34:43 +053011049 if (!config->enable_dp_trace) {
11050 hdd_err("dp trace is disabled from ini");
11051 return;
11052 }
11053
Mohit Khannaf8f96822017-05-17 17:11:59 -070011054 hdd_string_to_u8_array(config->dp_trace_config, config_params,
11055 &num_entries, sizeof(config_params));
11056
11057 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080011058 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080011059 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080011060 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080011061 else if (bw_compute_interval > 1000) {
11062 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
11063 thresh_time_limit = 1;
11064 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070011065 hdd_err("busBandwidthComputeInterval is 0, using defaults");
11066
11067 switch (num_entries) {
11068 case 4:
11069 proto_bitmap = config_params[3];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011070 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011071 case 3:
11072 verbosity = config_params[2];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011073 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011074 case 2:
11075 thresh = config_params[1];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011076 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011077 case 1:
11078 live_mode = config_params[0];
Alok Kumarb5a33a22018-05-07 18:09:14 +053011079 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070011080 default:
Mohit Khannaf7562c32018-07-05 17:42:36 -070011081 hdd_info("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
11082 live_mode, thresh, thresh_time_limit,
11083 verbosity, proto_bitmap);
Mohit Khannaf8f96822017-05-17 17:11:59 -070011084 };
11085
11086 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
11087 verbosity, proto_bitmap);
11088
11089}
Nirav Shahd21a2e32018-04-20 16:34:43 +053011090#endif
11091
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011092/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011093 * hdd_wlan_startup() - HDD init function
11094 * @dev: Pointer to the underlying device
11095 *
11096 * This is the driver startup code executed once a WLAN device has been detected
11097 *
11098 * Return: 0 for success, < 0 for failure
11099 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011100int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011101{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011102 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011103 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011104 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080011105 bool rtnl_held;
Jeff Johnson16528362018-06-14 12:34:16 -070011106 mac_handle_t mac_handle;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011107
Dustin Brown491d54b2018-03-14 12:39:11 -070011108 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011109
Arun Khandavallifae92942016-08-01 13:31:08 +053011110 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011111
11112 if (IS_ERR(hdd_ctx))
11113 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011114
Abhishek Singhe9068f12017-03-31 14:14:52 +053011115 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
11116 DEFAULT_PSOC_ID);
11117 if (ret) {
11118 hdd_err("Psoc creation fails!");
11119 QDF_BUG(0);
11120 goto err_hdd_free_context;
11121 }
11122
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053011123 hdd_action_oui_config(hdd_ctx);
11124
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053011125 qdf_nbuf_init_replenish_timer();
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053011126#ifdef FEATURE_WLAN_CH_AVOID
11127 mutex_init(&hdd_ctx->avoid_freq_lock);
11128#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053011129
Naveen Rawate02f8f52018-04-05 11:58:04 -070011130 osif_request_manager_init();
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053011131 qdf_atomic_init(&hdd_ctx->con_mode_flag);
Arun Khandavallifae92942016-08-01 13:31:08 +053011132
Dustin Brown021cecd2017-12-11 13:56:43 -080011133 hdd_driver_memdump_init();
11134
Dustin Browne7e71d32018-05-11 16:00:08 -070011135 ret = hdd_wlan_start_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053011136 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011137 hdd_err("Failed to start modules: %d", ret);
Dustin Brown021cecd2017-12-11 13:56:43 -080011138 goto err_memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011139 }
11140
Yingying Tang80e15f32016-09-27 18:23:01 +080011141 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011142
Jeff Johnson16528362018-06-14 12:34:16 -070011143 mac_handle = cds_get_context(QDF_MODULE_ID_SME);
11144 hdd_ctx->mac_handle = mac_handle;
11145 if (!mac_handle) {
11146 hdd_err("Mac Handle is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053011147 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011148 }
11149
Prashanth Bhatta07998752016-04-28 12:35:33 -070011150 ret = hdd_wiphy_init(hdd_ctx);
11151 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011152 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053011153 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011154 }
11155
Nirav Shahd21a2e32018-04-20 16:34:43 +053011156 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053011157
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070011158 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080011159
Paul Zhangfb02f452017-12-22 11:58:43 +080011160 ret = register_netdevice_notifier(&hdd_netdev_notifier);
11161 if (ret) {
11162 hdd_err("register_netdevice_notifier failed: %d", ret);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053011163 goto err_wiphy_unregister;
Paul Zhangfb02f452017-12-22 11:58:43 +080011164 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053011165
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011166 ret = register_reboot_notifier(&system_reboot_notifier);
11167 if (ret) {
11168 hdd_err("Failed to register reboot notifier: %d", ret);
11169 goto err_unregister_netdev;
11170 }
11171
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080011172 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011173
Jeff Johnson957bc272017-02-02 08:54:48 -080011174 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11175 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011176 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080011177 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011178 }
11179
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080011180 hdd_release_rtnl_lock();
11181 rtnl_held = false;
11182
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080011183 wlan_hdd_update_11n_mode(hdd_ctx->config);
11184
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011185#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053011186 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053011187 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011188 hdd_skip_acs_scan_timer_handler,
11189 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011190 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070011191 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040011192 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011193#endif
11194
Prashanth Bhattaab004382016-10-11 16:08:11 -070011195 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011196
Jeff Johnson9afc5012016-09-23 13:56:27 -070011197 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011198
Nirav Shahbd36b062016-07-18 11:12:59 +053011199 if (hdd_ctx->rps)
11200 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070011201
Paul Zhangfb02f452017-12-22 11:58:43 +080011202 ret = hdd_register_notifiers(hdd_ctx);
11203 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -080011204 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070011205
Paul Zhangfb02f452017-12-22 11:58:43 +080011206 status = wlansap_global_init();
11207 if (QDF_IS_STATUS_ERROR(status)) {
11208 hdd_unregister_notifiers(hdd_ctx);
11209 goto err_close_adapters;
11210 }
11211
Arun Khandavallifae92942016-08-01 13:31:08 +053011212 if (hdd_ctx->config->fIsImpsEnabled)
11213 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070011214 else
11215 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011216
Mukul Sharma07bd8752017-10-10 16:58:14 +053011217 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070011218 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
11219 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053011220 hdd_prevent_suspend_timeout(
11221 hdd_ctx->config->iface_change_wait_time,
11222 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
11223 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053011224
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011225 goto success;
11226
Jeff Johnson957bc272017-02-02 08:54:48 -080011227err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080011228 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011229
Jeff Johnson46bde382017-02-01 15:31:16 -080011230err_release_rtnl_lock:
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011231 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavallid4349a92016-07-25 11:10:43 +053011232 if (rtnl_held)
11233 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011234
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011235err_unregister_netdev:
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011236 unregister_netdevice_notifier(&hdd_netdev_notifier);
11237
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011238err_wiphy_unregister:
Rachit Kankane30807332018-06-27 18:39:36 +053011239 qdf_dp_trace_deinit();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011240 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011241
Arun Khandavallifae92942016-08-01 13:31:08 +053011242err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011243 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053011244
Dustin Brown021cecd2017-12-11 13:56:43 -080011245err_memdump_deinit:
11246 hdd_driver_memdump_deinit();
Dustin Brown021cecd2017-12-11 13:56:43 -080011247
Naveen Rawate02f8f52018-04-05 11:58:04 -070011248 osif_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070011249 hdd_exit_netlink_services(hdd_ctx);
11250
Dustin Brown20912462017-06-07 13:48:25 -070011251 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
11252
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011253err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053011254 if (cds_is_fw_down())
11255 hdd_err("Not setting the complete event as fw is down");
11256 else
11257 hdd_start_complete(ret);
11258
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053011259 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070011260 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070011261 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011262
11263success:
Dustin Browne74003f2018-03-14 12:51:58 -070011264 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011265 return 0;
11266}
11267
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011268/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011269 * hdd_wlan_update_target_info() - update target type info
11270 * @hdd_ctx: HDD context
11271 * @context: hif context
11272 *
11273 * Update target info received from firmware in hdd context
11274 * Return:None
11275 */
11276
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011277void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053011278{
11279 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
11280
11281 if (!tgt_info) {
11282 hdd_err("Target info is Null");
11283 return;
11284 }
11285
11286 hdd_ctx->target_type = tgt_info->target_type;
11287}
11288
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011289void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp, void *context)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011290{
11291 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011292 int status;
11293 struct hdd_adapter *adapter = NULL;
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011294 struct osif_request *request = NULL;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011295
Dustin Brown491d54b2018-03-14 12:39:11 -070011296 hdd_enter();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011297
11298 if (!rsp) {
11299 hdd_err("data is null");
11300 return;
11301 }
11302
11303 status = wlan_hdd_validate_context(hdd_ctx);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011304 if (status != 0)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011305 return;
11306
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011307 request = osif_request_get(context);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011308 if (!request) {
11309 hdd_err("obselete request");
11310 return;
11311 }
11312
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011313 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
11314 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
11315 hdd_err("Invalid adapter or adapter has invalid magic");
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011316 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011317 return;
11318 }
11319
Dustin Brown5e89ef82018-03-14 11:50:23 -070011320 hdd_info("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
11321 hdd_info("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
11322 hdd_info("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
11323 hdd_info("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
11324 hdd_info("rsp->out_of_order_arp_rsp_drop_cnt :%x",
11325 rsp->out_of_order_arp_rsp_drop_cnt);
11326 hdd_info("rsp->dad_detected :%x", rsp->dad_detected);
11327 hdd_info("rsp->connect_status :%x", rsp->connect_status);
11328 hdd_info("rsp->ba_session_establishment_status :%x",
11329 rsp->ba_session_establishment_status);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011330
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011331 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011332 adapter->dad |= rsp->dad_detected;
11333 adapter->con_status = rsp->connect_status;
11334
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053011335 /* Flag true indicates connectivity check stats present. */
11336 if (rsp->connect_stats_present) {
11337 hdd_info("rsp->tcp_ack_recvd :%x", rsp->tcp_ack_recvd);
11338 hdd_info("rsp->icmpv4_rsp_recvd :%x", rsp->icmpv4_rsp_recvd);
11339 adapter->hdd_stats.hdd_tcp_stats.rx_fw_cnt = rsp->tcp_ack_recvd;
11340 adapter->hdd_stats.hdd_icmpv4_stats.rx_fw_cnt =
11341 rsp->icmpv4_rsp_recvd;
11342 }
11343
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011344 osif_request_complete(request);
11345 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011346
Dustin Browne74003f2018-03-14 12:51:58 -070011347 hdd_exit();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011348}
11349
11350/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011351 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011352 * @hdd_ctx: HDD context
11353 *
11354 * Register the HDD callbacks to CDS/SME.
11355 *
11356 * Return: 0 for success or Error code for failure
11357 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011358int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011359{
11360 QDF_STATUS status;
11361 int ret = 0;
Jeff Johnson16528362018-06-14 12:34:16 -070011362 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011363
Dustin Brown491d54b2018-03-14 12:39:11 -070011364 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011365
Jeff Johnson16528362018-06-14 12:34:16 -070011366 mac_handle = hdd_ctx->mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011367
Jeff Johnson16528362018-06-14 12:34:16 -070011368 sme_register_oem_data_rsp_callback(mac_handle,
11369 hdd_send_oem_data_rsp_msg);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011370
Jeff Johnson16528362018-06-14 12:34:16 -070011371 sme_register_mgmt_frame_ind_callback(mac_handle,
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053011372 hdd_indicate_mgmt_frame);
Jeff Johnson16528362018-06-14 12:34:16 -070011373 sme_set_tsfcb(mac_handle, hdd_get_tsf_cb, hdd_ctx);
11374 sme_nan_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011375 wlan_hdd_cfg80211_nan_callback);
Jeff Johnson16528362018-06-14 12:34:16 -070011376 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011377 wlan_hdd_cfg80211_stats_ext_callback);
11378
Jeff Johnson16528362018-06-14 12:34:16 -070011379 sme_ext_scan_register_callback(mac_handle,
11380 wlan_hdd_cfg80211_extscan_callback);
11381 sme_stats_ext2_register_callback(mac_handle,
lifeng66831662017-05-19 16:01:35 +080011382 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011383
Jeff Johnson16528362018-06-14 12:34:16 -070011384 sme_set_rssi_threshold_breached_cb(mac_handle,
11385 hdd_rssi_threshold_breached);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011386
Jeff Johnson16528362018-06-14 12:34:16 -070011387 sme_set_link_layer_stats_ind_cb(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011388 wlan_hdd_cfg80211_link_layer_stats_callback);
11389
Jeff Johnson16528362018-06-14 12:34:16 -070011390 sme_rso_cmd_status_cb(mac_handle, wlan_hdd_rso_cmd_status_cb);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053011391
Jeff Johnson16528362018-06-14 12:34:16 -070011392 sme_set_link_layer_ext_cb(mac_handle,
Zhang Qianca38fb12016-12-23 11:10:48 +080011393 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
11394
Jeff Johnson16528362018-06-14 12:34:16 -070011395 status = sme_set_lost_link_info_cb(mac_handle,
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053011396 hdd_lost_link_info_cb);
11397 /* print error and not block the startup process */
11398 if (!QDF_IS_STATUS_SUCCESS(status))
11399 hdd_err("set lost link info callback failed");
11400
Poddar, Siddarth34872782017-08-10 14:08:51 +053011401 ret = hdd_register_data_stall_detect_cb();
11402 if (ret) {
11403 hdd_err("Register data stall detect detect callback failed.");
11404 return ret;
11405 }
11406
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011407 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
11408
Jeff Johnson16528362018-06-14 12:34:16 -070011409 sme_register_set_connection_info_cb(mac_handle,
11410 hdd_set_connection_in_progress,
11411 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053011412
Jeff Johnson16528362018-06-14 12:34:16 -070011413 status = sme_congestion_register_callback(mac_handle,
11414 hdd_update_cca_info_cb);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053011415 if (!QDF_IS_STATUS_SUCCESS(status))
11416 hdd_err("set congestion callback failed");
11417
Jeff Johnson16528362018-06-14 12:34:16 -070011418 status = sme_set_bt_activity_info_cb(mac_handle,
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053011419 hdd_bt_activity_cb);
11420 if (!QDF_IS_STATUS_SUCCESS(status))
11421 hdd_err("set bt activity info callback failed");
11422
Jeff Johnson16528362018-06-14 12:34:16 -070011423 status = sme_register_tx_queue_cb(mac_handle,
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080011424 hdd_tx_queue_cb);
11425 if (!QDF_IS_STATUS_SUCCESS(status))
11426 hdd_err("Register tx queue callback failed");
11427
Dustin Browne74003f2018-03-14 12:51:58 -070011428 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011429
11430 return ret;
11431}
11432
11433/**
11434 * hdd_deregister_cb() - De-Register HDD callbacks.
11435 * @hdd_ctx: HDD context
11436 *
11437 * De-Register the HDD callbacks to CDS/SME.
11438 *
11439 * Return: void
11440 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011441void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011442{
11443 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053011444 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070011445 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011446
Dustin Brown491d54b2018-03-14 12:39:11 -070011447 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011448
Jeff Johnson16528362018-06-14 12:34:16 -070011449 mac_handle = hdd_ctx->mac_handle;
11450 sme_deregister_tx_queue_cb(mac_handle);
11451 status = sme_deregister_for_dcc_stats_event(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011452 if (!QDF_IS_STATUS_SUCCESS(status))
11453 hdd_err("De-register of dcc stats callback failed: %d",
11454 status);
11455
Jeff Johnson16528362018-06-14 12:34:16 -070011456 sme_reset_link_layer_stats_ind_cb(mac_handle);
11457 sme_reset_rssi_threshold_breached_cb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011458
Jeff Johnson16528362018-06-14 12:34:16 -070011459 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011460 wlan_hdd_cfg80211_stats_ext_callback);
11461
Jeff Johnson16528362018-06-14 12:34:16 -070011462 sme_nan_deregister_callback(mac_handle);
11463 status = sme_reset_tsfcb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011464 if (!QDF_IS_STATUS_SUCCESS(status))
11465 hdd_err("Failed to de-register tsfcb the callback:%d",
11466 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011467
Poddar, Siddarth34872782017-08-10 14:08:51 +053011468 ret = hdd_deregister_data_stall_detect_cb();
11469 if (ret)
11470 hdd_err("Failed to de-register data stall detect event callback");
11471
Jeff Johnson16528362018-06-14 12:34:16 -070011472 sme_deregister_oem_data_rsp_callback(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011473
Dustin Browne74003f2018-03-14 12:51:58 -070011474 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011475}
11476
11477/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011478 * hdd_softap_sta_deauth() - handle deauth req from HDD
11479 * @adapter: Pointer to the HDD
11480 * @enable: bool value
11481 *
11482 * This to take counter measure to handle deauth req from HDD
11483 *
11484 * Return: None
11485 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011486QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011487 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011488{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011489 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011490
Dustin Brown491d54b2018-03-14 12:39:11 -070011491 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011492
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011493 /* Ignore request to deauth bcmc station */
11494 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011495 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011496
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011497 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011498 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
11499 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011500
Dustin Browne74003f2018-03-14 12:51:58 -070011501 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011502 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011503}
11504
11505/**
11506 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
11507 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011508 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011509 *
11510 * This to take counter measure to handle deauth req from HDD
11511 *
11512 * Return: None
11513 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011514void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011515 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011516{
Dustin Brown491d54b2018-03-14 12:39:11 -070011517 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011518
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011519 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011520 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011521 return;
11522
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011523 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011524 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011525}
11526
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011527/**
11528 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
11529 * @hdd_ctx: HDD Context
11530 *
11531 * API to find if there is any STA or P2P-Client is connected
11532 *
11533 * Return: true if connected; false otherwise
11534 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011535QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011536{
Jeff Johnson16528362018-06-14 12:34:16 -070011537 return sme_is_sta_p2p_client_connected(hdd_ctx->mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011538}
11539
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011540void wlan_hdd_disable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011541{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011542 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
11543 struct hdd_adapter *adapter = NULL;
11544 struct csr_roam_profile *roam_profile;
11545 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011546
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011547 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->hdd_psoc)) {
11548 hdd_debug("No active sta session");
11549 return;
11550 }
11551
11552 hdd_for_each_adapter(hdd_ctx, adapter) {
11553 roam_profile = hdd_roam_profile(adapter);
11554 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11555
11556 if (cur_adapter->session_id != adapter->session_id &&
11557 adapter->device_mode == QDF_STA_MODE &&
11558 hdd_conn_is_connected(sta_ctx)) {
11559 hdd_debug("%d Disable roaming", adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -070011560 sme_stop_roaming(hdd_ctx->mac_handle,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011561 adapter->session_id,
11562 ecsr_driver_disabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011563 }
11564 }
11565}
11566
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011567void wlan_hdd_enable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011568{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011569 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
11570 struct hdd_adapter *adapter = NULL;
11571 struct csr_roam_profile *roam_profile;
11572 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011573
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011574 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->hdd_psoc)) {
11575 hdd_debug("No active sta session");
11576 return;
11577 }
11578
11579 hdd_for_each_adapter(hdd_ctx, adapter) {
11580 roam_profile = hdd_roam_profile(adapter);
11581 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11582
11583 if (cur_adapter->session_id != adapter->session_id &&
11584 adapter->device_mode == QDF_STA_MODE &&
11585 hdd_conn_is_connected(sta_ctx)) {
11586 hdd_debug("%d Enable roaming", adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -070011587 sme_start_roaming(hdd_ctx->mac_handle,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011588 adapter->session_id,
11589 REASON_DRIVER_ENABLED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011590 }
11591 }
11592}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011593
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011594/**
11595 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
11596 * @skb: sk buffer pointer
11597 *
11598 * Sends the bcast message to SVC multicast group with generic nl socket
11599 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
11600 *
11601 * Return: None
11602 */
11603static void nl_srv_bcast_svc(struct sk_buff *skb)
11604{
11605#ifdef CNSS_GENL
11606 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
11607#else
11608 nl_srv_bcast(skb);
11609#endif
11610}
11611
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011612void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011613{
11614 struct sk_buff *skb;
11615 struct nlmsghdr *nlh;
11616 tAniMsgHdr *ani_hdr;
11617 void *nl_data = NULL;
11618 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011619 struct radio_index_tlv *radio_info;
11620 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011621
11622 if (in_interrupt() || irqs_disabled() || in_atomic())
11623 flags = GFP_ATOMIC;
11624
11625 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
11626
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011627 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011628 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011629
11630 nlh = (struct nlmsghdr *)skb->data;
11631 nlh->nlmsg_pid = 0; /* from kernel */
11632 nlh->nlmsg_flags = 0;
11633 nlh->nlmsg_seq = 0;
11634 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
11635
11636 ani_hdr = NLMSG_DATA(nlh);
11637 ani_hdr->type = type;
11638
11639 switch (type) {
11640 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053011641 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011642 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011643 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011644 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011645 ani_hdr->length = 0;
11646 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011647 break;
11648 case WLAN_SVC_WLAN_STATUS_IND:
11649 case WLAN_SVC_WLAN_VERSION_IND:
11650 case WLAN_SVC_DFS_CAC_START_IND:
11651 case WLAN_SVC_DFS_CAC_END_IND:
11652 case WLAN_SVC_DFS_RADAR_DETECT_IND:
11653 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
11654 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080011655 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053011656 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080011657 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011658 ani_hdr->length = len;
11659 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
11660 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
11661 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011662 break;
11663
11664 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070011665 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011666 type);
11667 kfree_skb(skb);
11668 return;
11669 }
11670
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011671 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080011672 * Add radio index at the end of the svc event in TLV format
11673 * to maintain the backward compatibility with userspace
11674 * applications.
11675 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011676
11677 tlv_len = 0;
11678
11679 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
11680 < WLAN_NL_MAX_PAYLOAD) {
11681 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
11682 sizeof(*ani_hdr) + len);
11683 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
11684 radio_info->length = (unsigned short) sizeof(radio_info->radio);
11685 radio_info->radio = radio;
11686 tlv_len = sizeof(*radio_info);
Dustin Browna2868622018-03-20 11:38:14 -070011687 hdd_debug("Added radio index tlv - radio index %d",
11688 radio_info->radio);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011689 }
11690
11691 nlh->nlmsg_len += tlv_len;
11692 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
11693
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011694 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011695}
11696
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011697#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
11698void wlan_hdd_auto_shutdown_cb(void)
11699{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011700 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011701
11702 if (!hdd_ctx)
11703 return;
11704
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011705 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011706 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
11707 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011708}
11709
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011710void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011711{
Jeff Johnson9d295242017-08-29 14:39:48 -070011712 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011713 bool ap_connected = false, sta_connected = false;
Jeff Johnson16528362018-06-14 12:34:16 -070011714 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011715
Jeff Johnson16528362018-06-14 12:34:16 -070011716 mac_handle = hdd_ctx->mac_handle;
11717 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011718 return;
11719
11720 if (hdd_ctx->config->WlanAutoShutdown == 0)
11721 return;
11722
11723 if (enable == false) {
Jeff Johnson16528362018-06-14 12:34:16 -070011724 if (sme_set_auto_shutdown_timer(mac_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011725 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011726 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011727 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011728 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011729 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011730 return;
11731 }
11732
11733 /* To enable shutdown timer check conncurrency */
Dustin Brown920397d2017-12-13 16:27:50 -080011734 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->hdd_psoc)) {
11735 hdd_for_each_adapter(hdd_ctx, adapter) {
11736 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011737 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11738 conn_info.connState ==
11739 eConnectionState_Associated) {
11740 sta_connected = true;
11741 break;
11742 }
11743 }
Dustin Brown920397d2017-12-13 16:27:50 -080011744
11745 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011746 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070011747 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011748 ap_connected = true;
11749 break;
11750 }
11751 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011752 }
11753 }
11754
11755 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011756 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011757 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011758 }
Jeff Johnson68755312017-02-10 11:46:55 -080011759
Jeff Johnson16528362018-06-14 12:34:16 -070011760 if (sme_set_auto_shutdown_timer(mac_handle,
Jeff Johnson68755312017-02-10 11:46:55 -080011761 hdd_ctx->config->WlanAutoShutdown)
11762 != QDF_STATUS_SUCCESS)
11763 hdd_err("Failed to start wlan auto shutdown timer");
11764 else
Dustin Brown5e89ef82018-03-14 11:50:23 -070011765 hdd_info("Auto Shutdown timer for %d seconds enabled",
11766 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011767}
11768#endif
11769
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011770struct hdd_adapter *
11771hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
11772 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011773{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011774 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011775 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011776
11777 con_sap_adapter = NULL;
11778
Dustin Brown920397d2017-12-13 16:27:50 -080011779 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011780 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
11781 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011782 adapter != this_sap_adapter) {
11783 if (check_start_bss) {
11784 if (test_bit(SOFTAP_BSS_STARTED,
11785 &adapter->event_flags)) {
11786 con_sap_adapter = adapter;
11787 break;
11788 }
11789 } else {
11790 con_sap_adapter = adapter;
11791 break;
11792 }
11793 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011794 }
11795
11796 return con_sap_adapter;
11797}
11798
11799#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070011800static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011801{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011802 return adapter->device_mode == QDF_STA_MODE ||
11803 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011804}
11805
Jeff Johnson9d295242017-08-29 14:39:48 -070011806static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011807{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011808 return adapter->device_mode == QDF_SAP_MODE ||
11809 adapter->device_mode == QDF_P2P_GO_MODE;
11810}
11811
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011812static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011813{
Dustin Brown920397d2017-12-13 16:27:50 -080011814 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070011815
Dustin Brown920397d2017-12-13 16:27:50 -080011816 hdd_for_each_adapter(hdd_ctx, adapter) {
11817 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070011818 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11819 conn_info.connState == eConnectionState_Associated) {
11820 return true;
11821 }
11822
Dustin Brown920397d2017-12-13 16:27:50 -080011823 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070011824 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070011825 return true;
11826 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011827 }
11828
11829 return false;
11830}
11831
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011832static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011833{
11834 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011835
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011836 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011837 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011838 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011839
Dustin Brown5ec6b552017-03-31 12:11:40 -070011840 return is_running;
11841}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011842
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011843static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011844{
11845 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11846 hdd_ctx->bus_bw_timer_running = true;
11847 qdf_timer_start(&hdd_ctx->bus_bw_timer,
11848 hdd_ctx->config->busBandwidthComputeInterval);
11849 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11850}
11851
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011852void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011853{
Dustin Brown491d54b2018-03-14 12:39:11 -070011854 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011855
11856 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11857 hdd_debug("Bandwidth compute timer already started");
11858 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011859 }
11860
Dustin Brown5ec6b552017-03-31 12:11:40 -070011861 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11862
Dustin Browne74003f2018-03-14 12:51:58 -070011863 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011864}
11865
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011866void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011867{
Dustin Brown491d54b2018-03-14 12:39:11 -070011868 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011869
11870 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11871 hdd_debug("Bandwidth compute timer already started");
11872 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070011873 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011874
11875 if (hdd_any_adapter_is_assoc(hdd_ctx))
11876 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11877
Dustin Browne74003f2018-03-14 12:51:58 -070011878 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011879}
11880
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011881static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011882{
Sravan Kumar Kairam9e99e9a2018-03-12 19:09:45 +053011883 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, 0, 0);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011884
11885 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11886 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
11887 hdd_ctx->bus_bw_timer_running = false;
11888 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11889
11890 hdd_reset_tcp_delack(hdd_ctx);
11891}
11892
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011893void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011894{
Dustin Brown491d54b2018-03-14 12:39:11 -070011895 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011896
11897 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11898 hdd_debug("Bandwidth compute timer already stopped");
11899 return;
11900 }
11901
11902 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11903
Dustin Browne74003f2018-03-14 12:51:58 -070011904 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011905}
11906
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011907void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011908{
Dustin Brown491d54b2018-03-14 12:39:11 -070011909 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011910
11911 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11912 hdd_debug("Bandwidth compute timer already stopped");
11913 return;
11914 }
11915
11916 if (!hdd_any_adapter_is_assoc(hdd_ctx))
11917 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11918
Dustin Browne74003f2018-03-14 12:51:58 -070011919 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011920}
11921#endif
11922
11923/**
11924 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
11925 * and sta's operating channel.
11926 * @sta_adapter: Describe the first argument to foobar.
11927 * @ap_adapter: Describe the second argument to foobar.
11928 * @roam_profile: Roam profile of AP to which STA wants to connect.
11929 * @concurrent_chnl_same: If both SAP and STA channels are same then
11930 * set this flag to true else false.
11931 *
11932 * This function checks the sap's operating channel and sta's operating channel.
11933 * if both are same then it will return false else it will restart the sap in
11934 * sta's channel and return true.
11935 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011936 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011937 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011938QDF_STATUS
11939wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
11940 struct hdd_adapter *ap_adapter,
Jeff Johnson61b5e982018-03-15 11:33:31 -070011941 struct csr_roam_profile *roam_profile,
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011942 tScanResultHandle *scan_cache,
11943 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011944{
Jeff Johnson87251032017-08-29 13:31:11 -070011945 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011946 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011947 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011948 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011949 *concurrent_chnl_same = true;
11950
11951 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11952 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070011953 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011954 scan_cache,
11955 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011956 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011957 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011958 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011959 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011960 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011961 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011962 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011963 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011964 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011965 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011966 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011967 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011968 }
11969 }
11970 } else {
11971 /*
11972 * Lets handle worst case scenario here, Scan cache lookup is
11973 * failed so we have to stop the SAP to avoid any channel
11974 * discrepancy between SAP's channel and STA's channel.
11975 * Return the status as failure so caller function could know
11976 * that scan look up is failed.
11977 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070011978 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011979 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011980 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011981 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011982}
11983
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011984/**
11985 * wlan_hdd_stop_sap() - This function stops bss of SAP.
11986 * @ap_adapter: SAP adapter
11987 *
11988 * This function will process the stopping of sap adapter.
11989 *
11990 * Return: None
11991 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011992void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011993{
Jeff Johnson87251032017-08-29 13:31:11 -070011994 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011995 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011996 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011997 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011998
11999 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012000 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012001 return;
12002 }
12003
12004 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12005 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012006 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012007 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053012008
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012009 mutex_lock(&hdd_ctx->sap_lock);
12010 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080012011 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012012 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012013 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053012014 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012015 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012016 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053012017 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080012018 qdf_stop_bss_event,
12019 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053012020 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012021 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070012022 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012023 return;
12024 }
12025 }
12026 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012027 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
12028 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012029 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012030 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012031 false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012032 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012033 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012034 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012035 }
12036 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012037}
12038
12039/**
12040 * wlan_hdd_start_sap() - this function starts bss of SAP.
12041 * @ap_adapter: SAP adapter
12042 *
12043 * This function will process the starting of sap adapter.
12044 *
12045 * Return: None
12046 */
Jeff Johnson9d295242017-08-29 14:39:48 -070012047void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012048{
Jeff Johnson87251032017-08-29 13:31:11 -070012049 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070012050 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053012051 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012052 struct hdd_context *hdd_ctx;
Jeff Johnsone4c11db2018-05-05 23:22:32 -070012053 tsap_config_t *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012054
12055 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012056 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012057 return;
12058 }
12059
Krunal Soni9b04c9b2016-03-10 13:08:05 -080012060 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070012061 hdd_err("SoftAp role has not been enabled");
12062 return;
12063 }
12064
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012065 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
12066 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
12067 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070012068 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012069
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012070 mutex_lock(&hdd_ctx->sap_lock);
12071 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
12072 goto end;
12073
12074 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012075 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012076 goto end;
12077 }
12078
Wei Song2f76f642016-11-18 16:32:53 +080012079 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070012080 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070012081 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012082 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053012083 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012084 goto end;
12085
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012086 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053012087 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080012088 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053012089 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012090 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012091 goto end;
12092 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070012093 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012094 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012095 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012096 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012097 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12098 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012099 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012100 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012101 true);
12102 }
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053012103 mutex_unlock(&hdd_ctx->sap_lock);
12104
12105 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012106end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012107 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012108 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070012109 /* SAP context and beacon cleanup will happen during driver unload
12110 * in hdd_stop_adapter
12111 */
12112 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
12113
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012114}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012115
12116/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080012117 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
12118 * mac scan config
12119 * @status: Status of set antenna mode
Dundi Raviteja6bb9e322018-05-16 17:04:41 +053012120 * @context: callback context
Archana Ramachandrana20ef812015-11-13 16:12:13 -080012121 *
12122 * Callback on setting the dual mac configuration
12123 *
12124 * Return: None
12125 */
Dundi Raviteja6bb9e322018-05-16 17:04:41 +053012126void wlan_hdd_soc_set_antenna_mode_cb(enum set_antenna_mode_status status,
12127 void *context)
Archana Ramachandrana20ef812015-11-13 16:12:13 -080012128{
Dundi Raviteja6bb9e322018-05-16 17:04:41 +053012129 struct osif_request *request = NULL;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080012130
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012131 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080012132
Dundi Raviteja6bb9e322018-05-16 17:04:41 +053012133 request = osif_request_get(context);
12134 if (!request) {
12135 hdd_err("obselete request");
Archana Ramachandrana20ef812015-11-13 16:12:13 -080012136 return;
Dundi Raviteja6bb9e322018-05-16 17:04:41 +053012137 }
Archana Ramachandrana20ef812015-11-13 16:12:13 -080012138
12139 /* Signal the completion of set dual mac config */
Dundi Raviteja6bb9e322018-05-16 17:04:41 +053012140 osif_request_complete(request);
12141 osif_request_put(request);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080012142}
12143
12144/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012145 * hdd_get_fw_version() - Get FW version
12146 * @hdd_ctx: pointer to HDD context.
12147 * @major_spid: FW version - major spid.
12148 * @minor_spid: FW version - minor spid
12149 * @ssid: FW version - ssid
12150 * @crmid: FW version - crmid
12151 *
12152 * This function is called to get the firmware build version stored
12153 * as part of the HDD context
12154 *
12155 * Return: None
12156 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012157void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012158 uint32_t *major_spid, uint32_t *minor_spid,
12159 uint32_t *siid, uint32_t *crmid)
12160{
12161 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
12162 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
12163 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
12164 *crmid = hdd_ctx->target_fw_version & 0x7fff;
12165}
12166
12167#ifdef QCA_CONFIG_SMP
12168/**
12169 * wlan_hdd_get_cpu() - get cpu_index
12170 *
12171 * Return: cpu_index
12172 */
12173int wlan_hdd_get_cpu(void)
12174{
12175 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012176
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012177 put_cpu();
12178 return cpu_index;
12179}
12180#endif
12181
12182/**
12183 * hdd_get_fwpath() - get framework path
12184 *
12185 * This function is used to get the string written by
12186 * userspace to start the wlan driver
12187 *
12188 * Return: string
12189 */
12190const char *hdd_get_fwpath(void)
12191{
12192 return fwpath.string;
12193}
12194
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070012195static int hdd_qdf_print_init(void)
12196{
12197 int qdf_print_idx;
12198 QDF_STATUS status;
12199
12200 status = qdf_print_setup();
12201 if (status != QDF_STATUS_SUCCESS) {
12202 pr_err("qdf_print_setup failed\n");
12203 return -EINVAL;
12204 }
12205
12206 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
12207
12208 if (qdf_print_idx < 0) {
12209 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
12210 qdf_print_idx);
12211 return -EINVAL;
12212 }
12213
12214 qdf_set_pidx(qdf_print_idx);
12215
12216 return 0;
12217}
12218
12219static void hdd_qdf_print_deinit(void)
12220{
12221 int qdf_print_idx;
12222
12223 qdf_print_idx = qdf_get_pidx();
12224 qdf_print_ctrl_cleanup(qdf_print_idx);
12225}
12226
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012227/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012228 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012229 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012230 * This function initilizes CDS global context with the help of cds_init. This
12231 * has to be the first function called after probe to get a valid global
12232 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012233 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012234 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012235 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012236int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012237{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012238 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012239 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012240
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012241 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080012242 if (QDF_IS_STATUS_ERROR(status)) {
12243 hdd_err("Failed to allocate CDS context");
12244 ret = -ENOMEM;
12245 goto err_out;
12246 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053012247
12248 wlan_init_bug_report_lock();
12249
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012250#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12251 wlan_logging_sock_init_svc();
12252#endif
12253
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012254 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
12255 (void *)hdd_drv_ops_inactivity_handler, NULL,
12256 QDF_TIMER_TYPE_SW);
12257
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012258 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070012259 hdd_qdf_print_init();
12260
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053012261 hdd_register_debug_callback();
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012262 wlan_roam_debug_init();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012263
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012264err_out:
12265 return ret;
12266}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012267
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012268/**
12269 * hdd_deinit() - Deinitialize Driver
12270 *
12271 * This function frees CDS global context with the help of cds_deinit. This
12272 * has to be the last function call in remove callback to free the global
12273 * context.
12274 */
12275void hdd_deinit(void)
12276{
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012277 wlan_roam_debug_deinit();
12278 hdd_qdf_print_deinit();
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012279 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012280
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012281#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12282 wlan_logging_sock_deinit_svc();
12283#endif
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012284
12285 wlan_destroy_bug_report_lock();
12286 cds_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012287}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012288
Yue Ma6e7b1a02017-04-03 14:17:46 -070012289#ifdef QCA_WIFI_NAPIER_EMULATION
12290#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
12291#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012292#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070012293#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012294
Sachin Ahujadddd2632017-03-07 19:07:24 +053012295static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
12296 struct file *file)
12297{
12298 return 0;
12299}
12300
12301static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
12302 const char __user *user_buf,
12303 size_t count,
12304 loff_t *f_pos)
12305{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012306 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053012307 static const char wlan_off_str[] = "OFF";
12308 static const char wlan_on_str[] = "ON";
12309 int ret;
12310 unsigned long rc;
12311
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012312 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012313 pr_err("Failed to read buffer\n");
12314 return -EINVAL;
12315 }
12316
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012317 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012318 pr_debug("Wifi turning off from UI\n");
12319 goto exit;
12320 }
12321
Sachin Ahuja16904db2017-12-13 19:56:57 +053012322 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) == 0) {
12323 pr_info("Wifi Turning On from UI\n");
12324 }
12325
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012326 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012327 pr_err("Invalid value received from framework");
12328 goto exit;
12329 }
12330
12331 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053012332 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053012333 rc = wait_for_completion_timeout(&wlan_start_comp,
12334 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
12335 if (!rc) {
12336 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
12337 ret = -EINVAL;
Sachin Ahujadddd2632017-03-07 19:07:24 +053012338 return ret;
12339 }
12340
12341 hdd_start_complete(0);
12342 }
12343
12344exit:
12345 return count;
12346}
12347
12348
12349const struct file_operations wlan_hdd_state_fops = {
12350 .owner = THIS_MODULE,
12351 .open = wlan_hdd_state_ctrl_param_open,
12352 .write = wlan_hdd_state_ctrl_param_write,
12353};
12354
12355static int wlan_hdd_state_ctrl_param_create(void)
12356{
12357 unsigned int wlan_hdd_state_major = 0;
12358 int ret;
12359 struct device *dev;
12360
12361 device = MKDEV(wlan_hdd_state_major, 0);
12362
12363 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
12364 if (ret) {
12365 pr_err("Failed to register qcwlanstate");
12366 goto dev_alloc_err;
12367 }
12368 wlan_hdd_state_major = MAJOR(device);
12369
12370 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
12371 if (IS_ERR(class)) {
12372 pr_err("wlan_hdd_state class_create error");
12373 goto class_err;
12374 }
12375
12376 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
12377 if (IS_ERR(dev)) {
12378 pr_err("wlan_hdd_statedevice_create error");
12379 goto err_class_destroy;
12380 }
12381
12382 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
12383 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
12384 if (ret) {
12385 pr_err("Failed to add cdev error");
12386 goto cdev_add_err;
12387 }
12388
12389 pr_info("wlan_hdd_state %s major(%d) initialized",
12390 WLAN_MODULE_NAME, wlan_hdd_state_major);
12391
12392 return 0;
12393
12394cdev_add_err:
12395 device_destroy(class, device);
12396err_class_destroy:
12397 class_destroy(class);
12398class_err:
12399 unregister_chrdev_region(device, dev_num);
12400dev_alloc_err:
12401 return -ENODEV;
12402}
12403
12404static void wlan_hdd_state_ctrl_param_destroy(void)
12405{
12406 cdev_del(&wlan_hdd_state_cdev);
12407 device_destroy(class, device);
12408 class_destroy(class);
12409 unregister_chrdev_region(device, dev_num);
12410
12411 pr_info("Device node unregistered");
12412}
12413
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012414/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053012415 * component_init - API to init cld component's
12416 *
12417 * Return: None
12418 */
12419static void component_init(void)
12420{
Sandeep Puligillac5609d52018-05-17 19:23:41 -070012421 mlme_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053012422 pmo_init();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012423 disa_init();
Zhang Qian47e22ce2018-01-04 15:38:38 +080012424 ucfg_ocb_init();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053012425 ipa_init();
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053012426 ucfg_action_oui_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053012427}
12428
12429/**
12430 * component_deinit - API to deinit cld component's
12431 *
12432 * Return: None
12433 */
12434static void component_deinit(void)
12435{
Rajeev Kumar Sirasanagandla4725ae42018-05-24 22:33:34 +053012436 ucfg_action_oui_deinit();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053012437 ipa_deinit();
Zhang Qian47e22ce2018-01-04 15:38:38 +080012438 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053012439 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012440 disa_deinit();
Sandeep Puligillac5609d52018-05-17 19:23:41 -070012441 mlme_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012442}
12443
12444void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
12445{
Zhang Qian47e22ce2018-01-04 15:38:38 +080012446 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012447 disa_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012448}
12449
12450void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
12451{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012452 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080012453 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053012454}
12455
12456/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012457 * __hdd_module_init - Module init helper
12458 *
12459 * Module init helper function used by both module and static driver.
12460 *
12461 * Return: 0 for success, errno on failure
12462 */
12463static int __hdd_module_init(void)
12464{
12465 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012466
Dustin Brown96cd9632017-11-13 12:45:04 -080012467 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070012468 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080012469 g_wlan_driver_version,
Dustin Brownc1034df2018-02-07 14:51:32 -080012470 TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012471
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012472 pld_init();
12473
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012474 ret = hdd_init();
12475 if (ret) {
12476 pr_err("hdd_init failed %x\n", ret);
12477 goto err_hdd_init;
12478 }
12479
Rajeev Kumar97767a02016-11-30 11:20:40 -080012480 dispatcher_init();
12481
Mukul Sharmad75a6672017-06-22 15:40:53 +053012482 /* Ensure to call post objmgr init */
12483 component_init();
12484
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012485 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012486
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012487 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012488
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012489 ret = wlan_hdd_register_driver();
12490 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070012491 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
12492 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012493 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012494 }
12495
Sachin Ahuja16904db2017-12-13 19:56:57 +053012496 ret = wlan_hdd_state_ctrl_param_create();
12497 if (ret) {
12498 pr_err("wlan_hdd_state_create:%x\n", ret);
12499 goto out;
12500 }
12501
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053012502 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012503
12504 return 0;
12505out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012506 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080012507 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080012508 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012509 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080012510
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012511err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012512 pld_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012513 return ret;
12514}
12515
12516/**
12517 * __hdd_module_exit - Module exit helper
12518 *
12519 * Module exit helper function used by both module and static driver.
12520 */
12521static void __hdd_module_exit(void)
12522{
Will Huang36049722018-04-13 11:48:51 +080012523 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053012524
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012525 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
12526 QWLAN_VERSIONSTR);
12527
Arunk Khandavalli830c9692018-03-22 12:17:40 +053012528 if (!hdd_wait_for_recovery_completion())
12529 return;
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053012530
Will Huangba035ec2018-07-05 11:13:30 +080012531 cds_set_driver_loaded(false);
12532 cds_set_unload_in_progress(true);
12533
12534 if (!cds_wait_for_external_threads_completion(__func__))
12535 hdd_warn("External threads are still active attempting "
12536 "driver unload anyway");
12537
Rajeev Kumar3505ae52018-05-10 18:44:45 -070012538 if (hdd_ctx)
12539 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Will Huang36049722018-04-13 11:48:51 +080012540
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012541 wlan_hdd_unregister_driver();
12542
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012543 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012544
Mukul Sharmad75a6672017-06-22 15:40:53 +053012545 /* Ensure to call prior to objmgr deinit */
12546 component_deinit();
12547
Rajeev Kumar97767a02016-11-30 11:20:40 -080012548 dispatcher_deinit();
Amar Singhal0928b192017-12-01 10:50:54 -080012549
12550 hdd_sysfs_destroy_version_interface();
12551
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012552 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012553 pld_deinit();
12554
Sachin Ahujadddd2632017-03-07 19:07:24 +053012555 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012556}
12557
Arun Khandavallifae92942016-08-01 13:31:08 +053012558#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012559/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012560 * wlan_boot_cb() - Wlan boot callback
12561 * @kobj: object whose directory we're creating the link in.
12562 * @attr: attribute the user is interacting with
12563 * @buff: the buffer containing the user data
12564 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012565 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012566 * This callback is invoked when the fs is ready to start the
12567 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012568 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012569 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012570 */
Arun Khandavallifae92942016-08-01 13:31:08 +053012571static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012572 struct kobj_attribute *attr,
12573 const char *buf,
12574 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012575{
Arun Khandavallifae92942016-08-01 13:31:08 +053012576
Arun Khandavallifae92942016-08-01 13:31:08 +053012577 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012578 pr_err("%s: wlan driver already initialized\n", __func__);
12579 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053012580 }
12581
Arun Khandavallifae92942016-08-01 13:31:08 +053012582 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012583 pr_err("%s: wlan driver initialization failed\n", __func__);
12584 return -EIO;
12585 }
12586
12587 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053012588
12589 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012590}
Arun Khandavallifae92942016-08-01 13:31:08 +053012591
12592/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012593 * hdd_sysfs_cleanup() - cleanup sysfs
12594 *
12595 * Return: None
12596 *
12597 */
12598static void hdd_sysfs_cleanup(void)
12599{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012600 /* remove from group */
12601 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
12602 sysfs_remove_group(wlan_loader->boot_wlan_obj,
12603 wlan_loader->attr_group);
12604
12605 /* unlink the object from parent */
12606 kobject_del(wlan_loader->boot_wlan_obj);
12607
12608 /* free the object */
12609 kobject_put(wlan_loader->boot_wlan_obj);
12610
12611 kfree(wlan_loader->attr_group);
12612 kfree(wlan_loader);
12613
12614 wlan_loader = NULL;
12615}
12616
12617/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012618 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
12619 * ready
12620 *
12621 * This is creates the syfs entry boot_wlan. Which shall be invoked
12622 * when the filesystem is ready.
12623 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012624 * QDF API cannot be used here since this function is called even before
12625 * initializing WLAN driver.
12626 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012627 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053012628 */
12629static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012630{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012631 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012632
12633 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012634 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012635 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012636
12637 wlan_loader->boot_wlan_obj = NULL;
12638 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
12639 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012640 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053012641 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053012642
12643 wlan_loader->loaded_state = 0;
12644 wlan_loader->attr_group->attrs = attrs;
12645
12646 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
12647 kernel_kobj);
12648 if (!wlan_loader->boot_wlan_obj) {
12649 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053012650 goto error_return;
12651 }
12652
12653 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
12654 wlan_loader->attr_group);
12655 if (ret) {
12656 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
12657 goto error_return;
12658 }
12659
12660 return 0;
12661
12662error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012663 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053012664
12665 return ret;
12666}
12667
12668/**
12669 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
12670 *
12671 * Return: 0 on success or errno on failure
12672 */
12673static int wlan_deinit_sysfs(void)
12674{
Arun Khandavallifae92942016-08-01 13:31:08 +053012675 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012676 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053012677 return -EINVAL;
12678 }
12679
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012680 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012681 return 0;
12682}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012683
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012684#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053012685
12686#ifdef MODULE
12687/**
12688 * __hdd_module_init - Module init helper
12689 *
12690 * Module init helper function used by both module and static driver.
12691 *
12692 * Return: 0 for success, errno on failure
12693 */
12694static int hdd_module_init(void)
12695{
Arun Khandavallifae92942016-08-01 13:31:08 +053012696 if (__hdd_module_init()) {
12697 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070012698 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053012699 }
12700
Dustin Brownab482ac2017-06-09 17:00:44 -070012701 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053012702}
12703#else
12704static int __init hdd_module_init(void)
12705{
12706 int ret = -EINVAL;
12707
12708 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012709 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053012710 pr_err("Failed to create sysfs entry for loading wlan");
12711
12712 return ret;
12713}
12714#endif
12715
12716
12717#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012718/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012719 * hdd_module_exit() - Exit function
12720 *
12721 * This is the driver exit point (invoked when module is unloaded using rmmod)
12722 *
12723 * Return: None
12724 */
12725static void __exit hdd_module_exit(void)
12726{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012727 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012728}
Arun Khandavallifae92942016-08-01 13:31:08 +053012729#else
12730static void __exit hdd_module_exit(void)
12731{
12732 __hdd_module_exit();
12733 wlan_deinit_sysfs();
12734}
12735#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012736
Srinivas Girigowda841da292018-02-21 16:33:00 -080012737static int fwpath_changed_handler(const char *kmessage,
12738 const struct kernel_param *kp)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012739{
12740 return param_set_copystring(kmessage, kp);
12741}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012742
Nirav Shah73713f72018-05-17 14:50:41 +053012743#ifdef FEATURE_MONITOR_MODE_SUPPORT
12744static bool is_monitor_mode_supported(void)
12745{
12746 return true;
12747}
12748#else
12749static bool is_monitor_mode_supported(void)
12750{
12751 pr_err("Monitor mode not supported!");
12752 return false;
12753}
12754#endif
12755
12756#ifdef WLAN_FEATURE_EPPING
12757static bool is_epping_mode_supported(void)
12758{
12759 return true;
12760}
12761#else
12762static bool is_epping_mode_supported(void)
12763{
12764 pr_err("Epping mode not supported!");
12765 return false;
12766}
12767#endif
12768
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012769/**
12770 * is_con_mode_valid() check con mode is valid or not
12771 * @mode: global con mode
12772 *
12773 * Return: TRUE on success FALSE on failure
12774 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012775static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012776{
12777 switch (mode) {
12778 case QDF_GLOBAL_MONITOR_MODE:
Nirav Shah73713f72018-05-17 14:50:41 +053012779 return is_monitor_mode_supported();
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012780 case QDF_GLOBAL_EPPING_MODE:
Nirav Shah73713f72018-05-17 14:50:41 +053012781 return is_epping_mode_supported();
12782 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012783 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012784 return true;
12785 default:
12786 return false;
12787 }
12788}
12789
12790/**
12791 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
12792 * @mode: global con mode
12793 *
12794 * Return: adapter mode
12795 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012796static enum QDF_OPMODE hdd_get_adpter_mode(
Jeff Johnson876c1a62017-12-12 10:43:07 -080012797 enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012798{
12799
12800 switch (mode) {
12801 case QDF_GLOBAL_MISSION_MODE:
12802 return QDF_STA_MODE;
12803 case QDF_GLOBAL_MONITOR_MODE:
12804 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012805 case QDF_GLOBAL_EPPING_MODE:
12806 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012807 case QDF_GLOBAL_FTM_MODE:
12808 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012809 case QDF_GLOBAL_QVIT_MODE:
12810 return QDF_QVIT_MODE;
12811 default:
12812 return QDF_MAX_NO_OF_MODE;
12813 }
12814}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012815
Dustin Brown27cd9942017-09-27 16:11:44 -070012816static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012817 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070012818{
12819 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
12820 return;
12821
12822 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070012823 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012824 hdd_info("Release wakelock for monitor mode!");
12825 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
12826 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
Dundi Raviteja0a2a65b2018-04-30 12:34:11 +053012827 /* fallthrough */
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012828 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070012829 case QDF_GLOBAL_FTM_MODE:
12830 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +053012831 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Dustin Browndb2a8be2017-12-20 11:49:56 -080012832 hdd_stop_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -070012833
Dustin Brown27cd9942017-09-27 16:11:44 -070012834 break;
12835 default:
12836 break;
12837 }
12838}
12839
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012840static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012841 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012842{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053012843 int driver_status;
12844
12845 driver_status = hdd_ctx->driver_status;
12846
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012847 switch (curr_mode) {
12848 case QDF_GLOBAL_MISSION_MODE:
12849 case QDF_GLOBAL_MONITOR_MODE:
12850 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012851 hdd_deinit_all_adapters(hdd_ctx, false);
12852 hdd_close_all_adapters(hdd_ctx, false);
12853 break;
12854 case QDF_GLOBAL_EPPING_MODE:
12855 epping_disable();
12856 epping_close();
12857 break;
12858 default:
12859 return;
12860 }
12861}
12862
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012863static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012864 enum QDF_GLOBAL_MODE mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012865{
Jeff Johnson9d295242017-08-29 14:39:48 -070012866 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012867 int ret = 0;
12868 bool rtnl_held;
12869 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
12870 QDF_STATUS status;
12871
12872 if (!qdf_dev) {
12873 hdd_err("qdf device context is Null return!");
12874 return -EINVAL;
12875 }
12876
12877 rtnl_held = hdd_hold_rtnl_lock();
12878 switch (mode) {
12879 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080012880 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
12881 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012882 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012883 break;
12884 case QDF_GLOBAL_FTM_MODE:
12885 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
12886 wlan_hdd_get_intf_addr(hdd_ctx),
12887 NET_NAME_UNKNOWN, rtnl_held);
12888 if (adapter == NULL)
12889 ret = -EINVAL;
12890 break;
12891 case QDF_GLOBAL_MONITOR_MODE:
12892 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
12893 wlan_hdd_get_intf_addr(hdd_ctx),
12894 NET_NAME_UNKNOWN, rtnl_held);
12895 if (adapter == NULL)
12896 ret = -EINVAL;
12897 break;
12898 case QDF_GLOBAL_EPPING_MODE:
12899 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012900 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012901 hdd_err("Failed to open in eeping mode: %d", status);
12902 ret = -EINVAL;
12903 break;
12904 }
12905 ret = epping_enable(qdf_dev->dev);
12906 if (ret) {
12907 hdd_err("Failed to enable in epping mode : %d", ret);
12908 epping_close();
12909 }
12910 break;
12911 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012912 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012913 ret = -ENOTSUPP;
12914 break;
12915 }
12916 hdd_release_rtnl_lock();
12917 rtnl_held = false;
12918 return ret;
12919}
12920
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012921/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012922 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012923 * @kmessage: con mode name on which driver to be bring up
12924 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012925 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012926 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012927 * This function is invoked when user updates con mode using sys entry,
12928 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012929 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012930 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012931 */
Srinivas Girigowda841da292018-02-21 16:33:00 -080012932static int __con_mode_handler(const char *kmessage,
12933 const struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012934 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012935{
12936 int ret;
Jeff Johnson876c1a62017-12-12 10:43:07 -080012937 enum QDF_GLOBAL_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012938 enum QDF_OPMODE adapter_mode;
Dustin Brown20024e32018-01-03 12:34:58 -080012939 int new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012940
Dustin Brownab6029b2017-05-24 13:04:19 -070012941 hdd_info("con_mode handler: %s", kmessage);
12942
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012943 ret = wlan_hdd_validate_context(hdd_ctx);
12944 if (ret)
12945 return ret;
12946
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012947 qdf_atomic_set(&hdd_ctx->con_mode_flag, 1);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012948
Dustin Brown20024e32018-01-03 12:34:58 -080012949 ret = kstrtoint(kmessage, 0, &new_con_mode);
12950 if (ret) {
12951 hdd_err("Failed to parse con_mode '%s'", kmessage);
12952 goto reset_flags;
12953 }
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012954 mutex_lock(&hdd_init_deinit_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +053012955
Dustin Brown20024e32018-01-03 12:34:58 -080012956 if (!is_con_mode_valid(new_con_mode)) {
12957 hdd_err("invalid con_mode %d", new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012958 ret = -EINVAL;
12959 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012960 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012961
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012962 curr_mode = hdd_get_conparam();
Dustin Brown20024e32018-01-03 12:34:58 -080012963 if (curr_mode == new_con_mode) {
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012964 hdd_err("curr mode: %d is same as user triggered mode %d",
Dustin Brown20024e32018-01-03 12:34:58 -080012965 curr_mode, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012966 ret = 0;
12967 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012968 }
12969
Dustin Brown27cd9942017-09-27 16:11:44 -070012970 /* ensure adapters are stopped */
12971 hdd_stop_present_mode(hdd_ctx, curr_mode);
12972
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070012973 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053012974 if (ret) {
12975 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012976 goto reset_flags;
12977 }
12978
Dustin Browndd4e50f2018-05-24 15:43:42 -070012979 /* Cleanup present mode before switching to new mode */
12980 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053012981
Dustin Brown20024e32018-01-03 12:34:58 -080012982 hdd_set_conparam(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012983
12984 /* Register for new con_mode & then kick_start modules again */
Dustin Brown20024e32018-01-03 12:34:58 -080012985 ret = hdd_register_req_mode(hdd_ctx, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012986 if (ret) {
12987 hdd_err("Failed to register for new mode");
12988 goto reset_flags;
12989 }
12990
Dustin Brown20024e32018-01-03 12:34:58 -080012991 adapter_mode = hdd_get_adpter_mode(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012992 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
12993 hdd_err("invalid adapter");
12994 ret = -EINVAL;
12995 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012996 }
12997
Dustin Browne7e71d32018-05-11 16:00:08 -070012998 ret = hdd_wlan_start_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053012999 if (ret) {
13000 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013001 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053013002 }
13003
Dustin Brown20024e32018-01-03 12:34:58 -080013004 if (new_con_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Browne7e71d32018-05-11 16:00:08 -070013005 struct hdd_adapter *adapter =
13006 hdd_get_adapter(hdd_ctx, adapter_mode);
13007
13008 if (!adapter) {
13009 hdd_err("Failed to get adapter:%d", adapter_mode);
13010 goto reset_flags;
13011 }
13012
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013013 if (hdd_start_adapter(adapter)) {
13014 hdd_err("Failed to start %s adapter", kmessage);
13015 ret = -EINVAL;
13016 goto reset_flags;
13017 }
Arun Khandavallifae92942016-08-01 13:31:08 +053013018
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053013019 hdd_info("Acquire wakelock for monitor mode!");
13020 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
13021 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
13022 }
13023
Dustin Brown20024e32018-01-03 12:34:58 -080013024 /* con_mode is a global module parameter */
13025 con_mode = new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013026 hdd_info("Mode successfully changed to %s", kmessage);
13027 ret = 0;
13028
13029reset_flags:
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013030 mutex_unlock(&hdd_init_deinit_lock);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053013031 qdf_atomic_set(&hdd_ctx->con_mode_flag, 0);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013032 return ret;
13033}
13034
13035
Srinivas Girigowda841da292018-02-21 16:33:00 -080013036static int con_mode_handler(const char *kmessage, const struct kernel_param *kp)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013037{
13038 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013039 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013040
13041 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13042 ret = wlan_hdd_validate_context(hdd_ctx);
13043 if (ret)
13044 return ret;
13045
Ashish Kumar Dhanotiya759b3272018-05-18 17:49:46 +053013046 if (!cds_wait_for_external_threads_completion(__func__)) {
13047 hdd_warn("External threads are still active, can not change mode");
13048 return -EAGAIN;
13049 }
13050
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053013051 cds_ssr_protect(__func__);
13052 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
13053 cds_ssr_unprotect(__func__);
13054
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013055 return ret;
13056}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013057
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013058static int con_mode_handler_ftm(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080013059 const struct kernel_param *kp)
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013060{
13061 int ret;
13062
13063 ret = param_set_int(kmessage, kp);
13064
13065 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
13066 pr_err("Only FTM mode supported!");
13067 return -ENOTSUPP;
13068 }
13069
13070 hdd_set_conparam(con_mode_ftm);
13071 con_mode = con_mode_ftm;
13072
13073 return ret;
13074}
13075
Nirav Shah73713f72018-05-17 14:50:41 +053013076#ifdef FEATURE_MONITOR_MODE_SUPPORT
Ravi Joshia307f632017-07-17 23:41:41 -070013077static int con_mode_handler_monitor(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080013078 const struct kernel_param *kp)
Ravi Joshia307f632017-07-17 23:41:41 -070013079{
13080 int ret;
13081
13082 ret = param_set_int(kmessage, kp);
13083
13084 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
13085 pr_err("Only Monitor mode supported!");
13086 return -ENOTSUPP;
13087 }
13088
13089 hdd_set_conparam(con_mode_monitor);
13090 con_mode = con_mode_monitor;
13091
13092 return ret;
13093}
Nirav Shah73713f72018-05-17 14:50:41 +053013094#endif
Ravi Joshia307f632017-07-17 23:41:41 -070013095
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013096/**
13097 * hdd_get_conparam() - driver exit point
13098 *
13099 * This is the driver exit point (invoked when module is unloaded using rmmod)
13100 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080013101 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013102 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080013103enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013104{
Jeff Johnson876c1a62017-12-12 10:43:07 -080013105 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013106}
13107
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080013108void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013109{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080013110 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013111}
13112
Komal Seelamc11bb222016-01-27 18:57:10 +053013113/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013114 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
13115 * @hdd_ctx: HDD context
13116 *
13117 * Cleans up the pre cac interface, if it exists
13118 *
13119 * Return: None
13120 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013121void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013122{
13123 uint8_t session_id;
13124 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070013125 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013126
Jeff Johnson16528362018-06-14 12:34:16 -070013127 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->mac_handle, &session_id);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013128 if (QDF_IS_STATUS_ERROR(status)) {
13129 hdd_err("failed to get pre cac vdev id");
13130 return;
13131 }
13132
13133 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
13134 if (!precac_adapter) {
Jeff Johnsondd2f1fc2018-05-06 11:22:52 -070013135 hdd_err("invalid pre cac adapter");
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013136 return;
13137 }
13138
13139 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
13140 wlan_hdd_sap_pre_cac_failure,
13141 (void *)precac_adapter);
13142 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
13143
13144}
13145
13146/**
Komal Seelamec702b02016-02-24 18:42:16 +053013147 * hdd_update_ol_config - API to update ol configuration parameters
13148 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053013149 *
Komal Seelamc11bb222016-01-27 18:57:10 +053013150 * Return: void
13151 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013152static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053013153{
Komal Seelamec702b02016-02-24 18:42:16 +053013154 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053013155 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053013156
Komal Seelamec702b02016-02-24 18:42:16 +053013157 if (!ol_ctx)
13158 return;
13159
13160 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
13161 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
13162 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
13163 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070013164 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053013165
13166 ol_init_ini_config(ol_ctx, &cfg);
13167}
13168
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013169#ifdef FEATURE_RUNTIME_PM
13170/**
13171 * hdd_populate_runtime_cfg() - populate runtime configuration
13172 * @hdd_ctx: hdd context
13173 * @cfg: pointer to the configuration memory being populated
13174 *
13175 * Return: void
13176 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013177static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013178 struct hif_config_info *cfg)
13179{
13180 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
13181 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
13182}
13183#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013184static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013185 struct hif_config_info *cfg)
13186{
13187}
13188#endif
13189
Komal Seelamec702b02016-02-24 18:42:16 +053013190/**
13191 * hdd_update_hif_config - API to update HIF configuration parameters
13192 * @hdd_ctx: HDD Context
13193 *
13194 * Return: void
13195 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013196static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053013197{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053013198 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053013199 struct hif_config_info cfg;
13200
13201 if (!scn)
13202 return;
13203
13204 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013205 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053013206 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070013207
13208 if (hdd_ctx->config->prevent_link_down)
13209 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053013210}
13211
13212/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013213 * hdd_update_dp_config() - Propagate config parameters to Lithium
13214 * datapath
13215 * @hdd_ctx: HDD Context
13216 *
13217 * Return: 0 for success/errno for failure
13218 */
13219static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
13220{
13221 struct cdp_config_params params;
13222 QDF_STATUS status;
13223
13224 params.tso_enable = hdd_ctx->config->tso_enable;
13225 params.lro_enable = hdd_ctx->config->lro_enable;
13226#ifdef QCA_LL_TX_FLOW_CONTROL_V2
13227 params.tx_flow_stop_queue_threshold =
13228 hdd_ctx->config->TxFlowStopQueueThreshold;
13229 params.tx_flow_start_queue_offset =
13230 hdd_ctx->config->TxFlowStartQueueOffset;
13231#endif
13232 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
13233 params.napi_enable = hdd_ctx->napi_enable;
13234 params.tcp_udp_checksumoffload =
13235 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
13236
13237 status = cdp_update_config_parameters(
13238 cds_get_context(QDF_MODULE_ID_SOC),
13239 &params);
13240 if (status) {
Dustin Browna2868622018-03-20 11:38:14 -070013241 hdd_err("Failed to attach config parameters");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013242 return status;
13243 }
13244
13245 return 0;
13246}
13247
13248/**
Komal Seelamec702b02016-02-24 18:42:16 +053013249 * hdd_update_config() - Initialize driver per module ini parameters
13250 * @hdd_ctx: HDD Context
13251 *
13252 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013253 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053013254 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013255int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053013256{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013257 int ret;
13258
Komal Seelamec702b02016-02-24 18:42:16 +053013259 hdd_update_ol_config(hdd_ctx);
13260 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013261 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
13262 ret = hdd_update_cds_config_ftm(hdd_ctx);
13263 else
13264 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080013265 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013266
13267 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053013268}
13269
Mukul Sharma9d797a02017-01-05 20:26:03 +053013270#ifdef FEATURE_WLAN_RA_FILTERING
13271/**
13272 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
13273 * @psoc_cfg: pmo psoc Configuration
13274 * @hdd_ctx: Pointer to hdd context
13275 *
13276 * Return: none
13277 */
13278static inline void hdd_ra_populate_pmo_config(
13279 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013280 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013281{
13282 psoc_cfg->ra_ratelimit_interval =
13283 hdd_ctx->config->RArateLimitInterval;
13284 psoc_cfg->ra_ratelimit_enable =
13285 hdd_ctx->config->IsRArateLimitEnabled;
13286}
13287#else
13288static inline void hdd_ra_populate_pmo_config(
13289 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013290 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013291{
13292}
13293#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080013294
Mukul Sharma9d797a02017-01-05 20:26:03 +053013295/**
13296 * hdd_update_pmo_config - API to update pmo configuration parameters
13297 * @hdd_ctx: HDD context
13298 *
13299 * Return: void
13300 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013301static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013302{
Mukul Sharma9d797a02017-01-05 20:26:03 +053013303 struct pmo_psoc_cfg psoc_cfg;
13304 QDF_STATUS status;
13305
13306 /*
13307 * Value of hdd_ctx->wowEnable can be,
13308 * 0 - Disable both magic pattern match and pattern byte match.
13309 * 1 - Enable magic pattern match on all interfaces.
13310 * 2 - Enable pattern byte match on all interfaces.
13311 * 3 - Enable both magic patter and pattern byte match on
13312 * all interfaces.
13313 */
13314 psoc_cfg.magic_ptrn_enable =
13315 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
13316 psoc_cfg.ptrn_match_enable_all_vdev =
13317 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Nachiket Kukadee547a482018-05-22 16:43:30 +053013318 psoc_cfg.apf_enable = hdd_ctx->config->apf_packet_filter_enable;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013319 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Nachiket Kukadef0804072018-02-27 18:20:07 +053013320 psoc_cfg.hw_filter_mode_bitmap = hdd_ctx->config->hw_filter_mode_bitmap;
Dustin Brownb9987af2018-03-01 17:15:11 -080013321 psoc_cfg.ns_offload_enable_dynamic = hdd_ctx->config->fhostNSOffload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013322 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
Dustin Brownb9987af2018-03-01 17:15:11 -080013323 psoc_cfg.packet_filter_enabled = !hdd_ctx->config->disablePacketFilter;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013324 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
13325 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
Dustin Brownb9987af2018-03-01 17:15:11 -080013326 psoc_cfg.active_mode_offload = hdd_ctx->config->active_mode_offload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013327 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080013328 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9223f232017-03-08 18:42:27 +053013329 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
13330 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
13331 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
Dustin Brownb9987af2018-03-01 17:15:11 -080013332 psoc_cfg.power_save_mode = hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053013333 psoc_cfg.auto_power_save_fail_mode =
13334 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013335
13336 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053013337 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
13338 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013339
Dustin Brownb9987af2018-03-01 17:15:11 -080013340 status = ucfg_pmo_update_psoc_config(hdd_ctx->hdd_psoc, &psoc_cfg);
13341 if (QDF_IS_STATUS_ERROR(status))
13342 hdd_err("failed pmo psoc configuration; status:%d", status);
13343
13344 return qdf_status_to_os_return(status);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013345}
13346
Abhishek Singhb20db962017-03-03 21:28:46 +053013347#ifdef FEATURE_WLAN_SCAN_PNO
13348static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
13349 struct hdd_config *cfg)
13350{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070013351 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
13352
Abhishek Singhb20db962017-03-03 21:28:46 +053013353 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
13354 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
13355 pno_cfg->stationary_thresh = cfg->stationary_thresh;
13356 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
13357 pno_cfg->channel_prediction_full_scan =
13358 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070013359 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
13360 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
13361 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
13362 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053013363}
13364#else
13365static inline void
13366hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070013367 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053013368{
Abhishek Singhb20db962017-03-03 21:28:46 +053013369}
13370#endif
13371
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013372void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
13373 struct hdd_config *cfg)
13374{
13375 uint8_t i = 0;
13376
13377 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
13378 if (!ie_whitelist->white_list)
13379 return;
13380
13381 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
13382 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
13383 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
13384 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
13385 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
13386 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
13387 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
13388 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
13389
13390 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
13391 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
13392 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
13393}
13394
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013395uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
13396{
13397 uint8_t i, score;
13398
13399 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
13400 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
13401 if (score > MAX_INDEX_SCORE)
13402 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
13403 MAX_INDEX_SCORE, i);
13404 }
13405
13406 return per_index_score;
13407}
13408
13409/**
13410 * hdd_update_score_config - API to update candidate scoring related params
13411 * configuration parameters
13412 * @score_config: score config to update
13413 * @cfg: config params
13414 *
13415 * Return: 0 if success else err
13416 */
13417static void hdd_update_score_config(
13418 struct scoring_config *score_config, struct hdd_config *cfg)
13419{
13420 int total_weight;
13421
13422 score_config->weight_cfg.rssi_weightage = cfg->rssi_weightage;
13423 score_config->weight_cfg.ht_caps_weightage = cfg->ht_caps_weightage;
13424 score_config->weight_cfg.vht_caps_weightage =
13425 cfg->vht_caps_weightage;
13426 score_config->weight_cfg.he_caps_weightage =
13427 cfg->he_caps_weightage;
13428 score_config->weight_cfg.chan_width_weightage =
13429 cfg->chan_width_weightage;
13430 score_config->weight_cfg.chan_band_weightage =
13431 cfg->chan_band_weightage;
13432 score_config->weight_cfg.nss_weightage = cfg->nss_weightage;
13433 score_config->weight_cfg.beamforming_cap_weightage =
13434 cfg->beamforming_cap_weightage;
13435 score_config->weight_cfg.pcl_weightage = cfg->pcl_weightage;
13436 score_config->weight_cfg.channel_congestion_weightage =
13437 cfg->channel_congestion_weightage;
13438 score_config->weight_cfg.oce_wan_weightage = cfg->oce_wan_weightage;
13439
13440 total_weight = score_config->weight_cfg.rssi_weightage +
13441 score_config->weight_cfg.ht_caps_weightage +
13442 score_config->weight_cfg.vht_caps_weightage +
13443 score_config->weight_cfg.he_caps_weightage +
13444 score_config->weight_cfg.chan_width_weightage +
13445 score_config->weight_cfg.chan_band_weightage +
13446 score_config->weight_cfg.nss_weightage +
13447 score_config->weight_cfg.beamforming_cap_weightage +
13448 score_config->weight_cfg.pcl_weightage +
13449 score_config->weight_cfg.channel_congestion_weightage +
13450 score_config->weight_cfg.oce_wan_weightage;
13451
13452 if (total_weight > BEST_CANDIDATE_MAX_WEIGHT) {
13453 hdd_err("total weight is greater than %d fallback to default values",
13454 BEST_CANDIDATE_MAX_WEIGHT);
13455
13456 score_config->weight_cfg.rssi_weightage = RSSI_WEIGHTAGE;
13457 score_config->weight_cfg.ht_caps_weightage =
13458 HT_CAPABILITY_WEIGHTAGE;
13459 score_config->weight_cfg.vht_caps_weightage = VHT_CAP_WEIGHTAGE;
13460 score_config->weight_cfg.he_caps_weightage = HE_CAP_WEIGHTAGE;
13461 score_config->weight_cfg.chan_width_weightage =
13462 CHAN_WIDTH_WEIGHTAGE;
13463 score_config->weight_cfg.chan_band_weightage =
13464 CHAN_BAND_WEIGHTAGE;
13465 score_config->weight_cfg.nss_weightage = NSS_WEIGHTAGE;
13466 score_config->weight_cfg.beamforming_cap_weightage =
13467 BEAMFORMING_CAP_WEIGHTAGE;
13468 score_config->weight_cfg.pcl_weightage = PCL_WEIGHT;
13469 score_config->weight_cfg.channel_congestion_weightage =
13470 CHANNEL_CONGESTION_WEIGHTAGE;
13471 score_config->weight_cfg.oce_wan_weightage = OCE_WAN_WEIGHTAGE;
13472 }
13473
13474 score_config->bandwidth_weight_per_index =
13475 hdd_limit_max_per_index_score(
13476 cfg->bandwidth_weight_per_index);
13477 score_config->nss_weight_per_index =
13478 hdd_limit_max_per_index_score(cfg->nss_weight_per_index);
13479 score_config->band_weight_per_index =
13480 hdd_limit_max_per_index_score(cfg->band_weight_per_index);
13481
13482 score_config->rssi_score.best_rssi_threshold =
13483 cfg->best_rssi_threshold;
13484 score_config->rssi_score.good_rssi_threshold =
13485 cfg->good_rssi_threshold;
13486 score_config->rssi_score.bad_rssi_threshold =
13487 cfg->bad_rssi_threshold;
13488 score_config->rssi_score.good_rssi_pcnt = cfg->good_rssi_pcnt;
13489 score_config->rssi_score.bad_rssi_pcnt = cfg->bad_rssi_pcnt;
13490 score_config->rssi_score.good_rssi_bucket_size =
13491 cfg->good_rssi_bucket_size;
13492 score_config->rssi_score.bad_rssi_bucket_size =
13493 cfg->bad_rssi_bucket_size;
13494 score_config->rssi_score.rssi_pref_5g_rssi_thresh =
13495 cfg->rssi_pref_5g_rssi_thresh;
13496
13497 score_config->esp_qbss_scoring.num_slot = cfg->num_esp_qbss_slots;
13498 score_config->esp_qbss_scoring.score_pcnt3_to_0 =
13499 hdd_limit_max_per_index_score(
13500 cfg->esp_qbss_score_slots3_to_0);
13501 score_config->esp_qbss_scoring.score_pcnt7_to_4 =
13502 hdd_limit_max_per_index_score(
13503 cfg->esp_qbss_score_slots7_to_4);
13504 score_config->esp_qbss_scoring.score_pcnt11_to_8 =
13505 hdd_limit_max_per_index_score(
13506 cfg->esp_qbss_score_slots11_to_8);
13507 score_config->esp_qbss_scoring.score_pcnt15_to_12 =
13508 hdd_limit_max_per_index_score(
13509 cfg->esp_qbss_score_slots15_to_12);
13510
13511 score_config->oce_wan_scoring.num_slot = cfg->num_oce_wan_slots;
13512 score_config->oce_wan_scoring.score_pcnt3_to_0 =
13513 hdd_limit_max_per_index_score(
13514 cfg->oce_wan_score_slots3_to_0);
13515 score_config->oce_wan_scoring.score_pcnt7_to_4 =
13516 hdd_limit_max_per_index_score(
13517 cfg->oce_wan_score_slots7_to_4);
13518 score_config->oce_wan_scoring.score_pcnt11_to_8 =
13519 hdd_limit_max_per_index_score(
13520 cfg->oce_wan_score_slots11_to_8);
13521 score_config->oce_wan_scoring.score_pcnt15_to_12 =
13522 hdd_limit_max_per_index_score(
13523 cfg->oce_wan_score_slots15_to_12);
13524
13525
13526 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
13527 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
13528 score_config->nss = cfg->enable2x2 ? 2 : 1;
13529
13530 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
13531 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
13532 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
13533 score_config->he_cap = 1;
13534
13535 if (score_config->he_cap ||
13536 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
13537 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
13538 score_config->vht_cap = 1;
13539
13540 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
13541 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
13542 score_config->ht_cap = 1;
13543
13544 if (score_config->vht_cap && cfg->enableVhtFor24GHzBand)
13545 score_config->vht_24G_cap = 1;
13546
13547 if (cfg->enableTxBF)
13548 score_config->beamformee_cap = 1;
13549
13550}
13551
Abhishek Singh257a9482017-03-06 16:52:39 +053013552/**
bings81fe50a2017-11-27 14:33:26 +080013553 * hdd_update_dfs_config() - API to update dfs configuration parameters.
13554 * @hdd_ctx: HDD context
13555 *
13556 * Return: 0 if success else err
13557 */
13558static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
13559{
13560 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13561 struct hdd_config *cfg = hdd_ctx->config;
13562 struct dfs_user_config dfs_cfg;
13563 QDF_STATUS status;
13564
13565 dfs_cfg.dfs_is_phyerr_filter_offload = !!cfg->fDfsPhyerrFilterOffload;
13566 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
13567 if (QDF_IS_STATUS_ERROR(status)) {
13568 hdd_err("failed dfs psoc configuration");
13569 return -EINVAL;
13570 }
13571
13572 return 0;
13573}
13574
13575/**
Abhishek Singh257a9482017-03-06 16:52:39 +053013576 * hdd_update_scan_config - API to update scan configuration parameters
13577 * @hdd_ctx: HDD context
13578 *
13579 * Return: 0 if success else err
13580 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013581static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053013582{
13583 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13584 struct scan_user_cfg scan_cfg;
13585 struct hdd_config *cfg = hdd_ctx->config;
13586 QDF_STATUS status;
13587
13588 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
13589 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
13590 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
13591 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
13592 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
13593 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
13594 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053013595 /* convert to ms */
13596 scan_cfg.scan_cache_aging_time =
13597 cfg->scanAgingTimeout * 1000;
13598 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
13599 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
13600 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
13601 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053013602 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053013603 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080013604 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
13605 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053013606 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070013607 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singhc87bb042018-01-30 17:10:42 +053013608 scan_cfg.sta_miracast_mcc_rest_time =
13609 cfg->sta_miracast_mcc_rest_time_val;
Abhishek Singh257a9482017-03-06 16:52:39 +053013610
Abhishek Singhb20db962017-03-03 21:28:46 +053013611 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013612 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013613 hdd_update_score_config(&scan_cfg.score_config, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053013614
Abhishek Singh257a9482017-03-06 16:52:39 +053013615 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
13616 if (status != QDF_STATUS_SUCCESS) {
13617 hdd_err("failed pmo psoc configuration");
13618 return -EINVAL;
13619 }
13620
13621 return 0;
13622}
Abhishek Singh257a9482017-03-06 16:52:39 +053013623
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013624int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013625{
13626 int ret;
13627
13628 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053013629 if (ret)
13630 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013631
Abhishek Singh257a9482017-03-06 16:52:39 +053013632 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080013633 if (ret)
13634 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013635
Frank Liud4b2fa02017-03-29 11:46:48 +080013636 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013637 if (ret)
13638 return ret;
13639
13640 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080013641 if (ret)
13642 return ret;
13643
13644 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013645
13646 return ret;
13647}
13648
Agrawal Ashish65634612016-08-18 13:24:32 +053013649/**
13650 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
13651 * @mode : cfg80211 DFS mode
13652 *
13653 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
13654 */
13655enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
13656{
13657 switch (mode) {
13658 case DFS_MODE_ENABLE:
13659 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013660 case DFS_MODE_DISABLE:
13661 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013662 case DFS_MODE_DEPRIORITIZE:
13663 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013664 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013665 hdd_debug("ACS dfs mode is NONE");
13666 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013667 }
13668}
13669
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013670/**
13671 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
13672 * @hddctx: pointer to hdd context
13673 * @set_value: enable/disable
13674 *
13675 * When Host sends vendor command enable, FW will send *ONE* CA ind to
13676 * Host(even though it is duplicate). When Host send vendor command
13677 * disable,FW doesn't perform any action. Whenever any change in
13678 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
13679 *
13680 * return - 0 on success, appropriate error values on failure.
13681 */
Jeff Johnson16528362018-06-14 12:34:16 -070013682int hdd_enable_disable_ca_event(struct hdd_context *hdd_ctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013683{
13684 QDF_STATUS status;
13685
Jeff Johnson16528362018-06-14 12:34:16 -070013686 if (0 != wlan_hdd_validate_context(hdd_ctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013687 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013688
Jeff Johnson16528362018-06-14 12:34:16 -070013689 if (!hdd_ctx->config->goptimize_chan_avoid_event) {
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013690 hdd_warn("goptimize_chan_avoid_event ini param disabled");
13691 return -EINVAL;
13692 }
13693
Jeff Johnson16528362018-06-14 12:34:16 -070013694 status = sme_enable_disable_chanavoidind_event(hdd_ctx->mac_handle,
13695 set_value);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013696 if (!QDF_IS_STATUS_SUCCESS(status)) {
13697 hdd_err("Failed to send chan avoid command to SME");
13698 return -EINVAL;
13699 }
13700 return 0;
13701}
Agrawal Ashish65634612016-08-18 13:24:32 +053013702
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013703/**
13704 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
13705 * @value: value to set
13706 *
13707 * This function will set the passed value to roaming in progress flag.
13708 *
13709 * Return: None
13710 */
13711void hdd_set_roaming_in_progress(bool value)
13712{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013713 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013714
13715 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13716 if (!hdd_ctx) {
13717 hdd_err("HDD context is NULL");
13718 return;
13719 }
13720
13721 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013722 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013723}
13724
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053013725bool hdd_is_roaming_in_progress(struct hdd_context *hdd_ctx)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013726{
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013727 if (!hdd_ctx) {
13728 hdd_err("HDD context is NULL");
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053013729 return false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013730 }
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013731
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053013732 hdd_debug("roaming_in_progress = %d", hdd_ctx->roaming_in_progress);
13733
13734 return hdd_ctx->roaming_in_progress;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013735}
13736
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013737/**
13738 * hdd_is_connection_in_progress() - check if connection is in
13739 * progress
13740 * @session_id: session id
13741 * @reason: scan reject reason
13742 *
13743 * Go through each adapter and check if Connection is in progress
13744 *
13745 * Return: true if connection is in progress else false
13746 */
13747bool hdd_is_connection_in_progress(uint8_t *session_id,
13748 enum scan_reject_states *reason)
13749{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070013750 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070013751 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013752 uint8_t sta_id = 0;
13753 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013754 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -070013755 mac_handle_t mac_handle;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013756
13757 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13758 if (!hdd_ctx) {
13759 hdd_err("HDD context is NULL");
13760 return false;
13761 }
13762
Jeff Johnson16528362018-06-14 12:34:16 -070013763 mac_handle = hdd_ctx->mac_handle;
13764
Dustin Brown920397d2017-12-13 16:27:50 -080013765 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya929afa42018-06-01 15:04:44 -070013766 hdd_debug("Adapter with device mode %s(%d) exists",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013767 hdd_device_mode_to_string(adapter->device_mode),
13768 adapter->device_mode);
13769 if (((QDF_STA_MODE == adapter->device_mode)
13770 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
13771 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
13772 && (eConnectionState_Connecting ==
13773 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
13774 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013775 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013776 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013777 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013778 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013779 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013780 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013781 }
13782 return true;
13783 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013784 /*
13785 * sme_neighbor_middle_of_roaming is for LFR2
13786 * hdd_is_roaming_in_progress is for LFR3
13787 */
13788 if (((QDF_STA_MODE == adapter->device_mode) &&
13789 sme_neighbor_middle_of_roaming(
Jeff Johnson16528362018-06-14 12:34:16 -070013790 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013791 adapter->session_id)) ||
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053013792 hdd_is_roaming_in_progress(hdd_ctx)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013793 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013794 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013795 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013796 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013797 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013798 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013799 }
13800 return true;
13801 }
13802 if ((QDF_STA_MODE == adapter->device_mode) ||
13803 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
13804 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
13805 hdd_sta_ctx =
13806 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
13807 if ((eConnectionState_Associated ==
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053013808 hdd_sta_ctx->conn_info.connState)
13809 && sme_is_sta_key_exchange_in_progress(
Jeff Johnson16528362018-06-14 12:34:16 -070013810 mac_handle, adapter->session_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013811 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070013812 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013813 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013814 " is in middle of WPS/EAPOL exchange.",
13815 MAC_ADDR_ARRAY(sta_mac));
13816 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013817 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013818 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013819 }
13820 return true;
13821 }
13822 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
13823 (QDF_P2P_GO_MODE == adapter->device_mode)) {
13824 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
13825 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013826 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013827 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013828 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013829 continue;
13830
13831 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013832 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070013833 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013834 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013835 " of SAP/GO is in middle of WPS/EAPOL exchange",
13836 MAC_ADDR_ARRAY(sta_mac));
13837 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013838 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013839 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013840 }
13841 return true;
13842 }
13843 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013844 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013845 return true;
13846 }
13847 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013848 }
Dustin Brown920397d2017-12-13 16:27:50 -080013849
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013850 return false;
13851}
13852
13853/**
13854 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070013855 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013856 *
13857 * Return: None
13858 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013859void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013860{
Jeff Johnson87251032017-08-29 13:31:11 -070013861 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070013862 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013863 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013864 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Jeff Johnsone4c11db2018-05-05 23:22:32 -070013865 tsap_config_t *sap_config;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013866 void *sap_ctx;
13867
13868 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070013869 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070013870 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013871
13872 mutex_lock(&hdd_ctx->sap_lock);
13873 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
13874 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013875 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
13876 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
13877 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
13878 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013879 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013880 qdf_stop_bss_event,
13881 SME_CMD_TIMEOUT_VALUE);
13882
13883 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013884 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013885 goto end;
13886 }
13887 }
13888 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013889 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013890 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070013891 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013892 false);
Jeff Johnson6867ec32017-09-29 20:30:20 -070013893 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013894
13895 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013896 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013897 wlansap_reset_sap_config_add_ie(sap_config,
13898 eUPDATE_IE_ALL);
13899 goto end;
13900 }
13901
13902 qdf_event_reset(&hostapd_state->qdf_event);
13903 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
13904 sap_config,
13905 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013906 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013907 wlansap_reset_sap_config_add_ie(sap_config,
13908 eUPDATE_IE_ALL);
13909 goto end;
13910 }
13911
Jeff Johnson6867ec32017-09-29 20:30:20 -070013912 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013913 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013914 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013915 SME_CMD_TIMEOUT_VALUE);
13916 wlansap_reset_sap_config_add_ie(sap_config,
13917 eUPDATE_IE_ALL);
13918 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013919 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013920 goto end;
13921 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070013922 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013923 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013924 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013925 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
13926 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013927 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070013928 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013929 ap_adapter->device_mode,
13930 true);
13931 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013932 }
13933end:
13934 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013935}
13936
13937/**
13938 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
13939 * with non dfs acs
13940 *
13941 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
13942 *
13943 * Return: None
13944 */
13945void hdd_check_and_restart_sap_with_non_dfs_acs(void)
13946{
Jeff Johnson9d295242017-08-29 14:39:48 -070013947 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013948 struct hdd_context *hdd_ctx;
Jeff Johnson2b6982c2018-05-29 14:56:11 -070013949 struct cds_context *cds_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013950
13951 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13952 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013953 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013954 return;
13955 }
13956
13957 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
13958 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013959 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013960 return;
13961 }
13962
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013963 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
13964 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013965 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013966 return;
13967 }
13968
13969 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070013970 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
13971 &ap_adapter->event_flags) &&
13972 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070013973 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013974
Jeff Johnson6867ec32017-09-29 20:30:20 -070013975 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Jeff Johnsonb9424862017-10-30 08:49:35 -070013976 ap_adapter->session.ap.sap_config.channel =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013977 AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -070013978 ap_adapter->session.ap.sap_config.
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013979 acs_cfg.acs_mode = true;
13980
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013981 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013982 }
13983}
13984
13985/**
13986 * hdd_set_connection_in_progress() - to set the connection in
13987 * progress flag
13988 * @value: value to set
13989 *
13990 * This function will set the passed value to connection in progress flag.
13991 * If value is previously being set to true then no need to set it again.
13992 *
13993 * Return: true if value is being set correctly and false otherwise.
13994 */
13995bool hdd_set_connection_in_progress(bool value)
13996{
13997 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013998 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013999
14000 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14001 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070014002 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080014003 return false;
14004 }
14005
14006 qdf_spin_lock(&hdd_ctx->connection_status_lock);
14007 /*
14008 * if the value is set to true previously and if someone is
14009 * trying to make it true again then it could be some race
14010 * condition being triggered. Avoid this situation by returning
14011 * false
14012 */
14013 if (hdd_ctx->connection_in_progress && value)
14014 status = false;
14015 else
14016 hdd_ctx->connection_in_progress = value;
14017 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
14018 return status;
14019}
14020
Jeff Johnson9d295242017-08-29 14:39:48 -070014021int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014022{
14023 if (!adapter) {
14024 hdd_err("Invalid adapter");
14025 return -EINVAL;
14026 }
14027 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070014028 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014029 WMA_VDEV_MCC_SET_TIME_QUOTA,
14030 set_value, VDEV_CMD);
14031 return 0;
14032
14033}
14034
Jeff Johnson9d295242017-08-29 14:39:48 -070014035int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014036{
14037 if (!adapter) {
14038 hdd_err("Invalid adapter");
14039 return -EINVAL;
14040 }
14041
14042 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070014043 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070014044 WMA_VDEV_MCC_SET_TIME_LATENCY,
14045 set_value, VDEV_CMD);
14046 return 0;
14047}
14048
Jeff Johnson9d295242017-08-29 14:39:48 -070014049struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070014050 *psoc, uint8_t vdev_id)
14051{
Jeff Johnson9d295242017-08-29 14:39:48 -070014052 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070014053 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070014054
14055 /*
14056 * Currently PSOC is not being used. But this logic will
14057 * change once we have the converged implementation of
14058 * HDD context per PSOC in place. This would break if
14059 * multiple vdev objects reuse the vdev id.
14060 */
14061 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
14062 if (!adapter)
14063 hdd_err("Get adapter by vdev id failed");
14064
14065 return adapter;
14066}
14067
Jeff Johnson9d295242017-08-29 14:39:48 -070014068int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014069 int8_t *rssi, int8_t *snr)
14070{
14071 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -070014072 mac_handle_t mac_handle;
Jeff Johnson025618c2018-03-18 14:41:00 -070014073 struct csr_roam_profile *roam_profile;
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014074
Jeff Johnson025618c2018-03-18 14:41:00 -070014075 roam_profile = hdd_roam_profile(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -070014076 mac_handle = hdd_adapter_get_mac_handle(adapter);
14077 status = sme_get_rssi_snr_by_bssid(mac_handle,
Jeff Johnson025618c2018-03-18 14:41:00 -070014078 roam_profile, bssid, rssi, snr);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053014079 if (QDF_STATUS_SUCCESS != status) {
14080 hdd_warn("sme_get_rssi_snr_by_bssid failed");
14081 return -EINVAL;
14082 }
14083
14084 return 0;
14085}
14086
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014087/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014088 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
14089 * @adapter - HDD adapter
14090 * @tos - type of service
14091 * @status - status of the traffic
14092 *
14093 * Return: 0 on success and non zero value on failure
14094 */
14095
14096int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
14097 bool is_tos_active)
14098{
14099 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014100 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014101 uint32_t max_off_chan_time = 0;
14102 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014103 int ret;
14104
14105 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
14106 ret = wlan_hdd_validate_context(hdd_ctx);
14107
14108 if (ret < 0) {
14109 hdd_err("failed to set limit off chan params");
14110 return ret;
14111 }
14112
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014113 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
14114
14115 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053014116 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014117 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053014118 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014119
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053014120 if (adapter->active_ac) {
14121 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014122 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014123 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
14124 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
14125 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053014126 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014127 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014128 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
14129 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
14130 PM_LATENCY);
14131 } else {
14132 /*ignore this command if only BE/BK is active */
14133 is_tos_active = false;
14134 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
14135 hdd_ctx->config->conc_system_pref);
14136 }
14137 } else {
14138 /* No active tos */
14139 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
14140 hdd_ctx->config->conc_system_pref);
14141 }
14142
Jeff Johnson16528362018-06-14 12:34:16 -070014143 status = sme_send_limit_off_channel_params(hdd_ctx->mac_handle,
14144 adapter->session_id,
14145 is_tos_active,
14146 max_off_chan_time,
14147 hdd_ctx->config->nRestTimeConc,
14148 true);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014149 if (!QDF_IS_STATUS_SUCCESS(status)) {
14150 hdd_err("failed to set limit off chan params");
14151 ret = -EINVAL;
14152 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014153
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014154 return ret;
14155}
14156
14157/**
14158 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
14159 * @adapter - HDD adapter
14160 *
14161 * Return: 0 on success and non zero value on failure
14162 */
14163int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
14164{
14165 struct hdd_context *hdd_ctx;
14166 int ret;
14167 QDF_STATUS status;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014168
14169 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
14170 ret = wlan_hdd_validate_context(hdd_ctx);
14171 if (ret < 0)
14172 return ret;
14173
14174 /* set the system preferece to default */
14175 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
14176 hdd_ctx->config->conc_system_pref);
14177
14178 /* clear the bitmap */
14179 adapter->active_ac = 0;
14180
14181 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson16528362018-06-14 12:34:16 -070014182 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014183
Jeff Johnson16528362018-06-14 12:34:16 -070014184 status = sme_send_limit_off_channel_params(hdd_ctx->mac_handle,
14185 adapter->session_id,
14186 false, 0, 0, false);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014187 if (!QDF_IS_STATUS_SUCCESS(status)) {
14188 hdd_err("failed to reset limit off chan params");
14189 ret = -EINVAL;
14190 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014191
14192 return ret;
14193}
14194
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014195/**
14196 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
14197 * @drv_op: Enum indicating driver op
14198 *
14199 * Return: none
14200 */
14201void hdd_start_driver_ops_timer(int drv_op)
14202{
14203 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
14204 switch (drv_op) {
14205 case eHDD_DRV_OP_PROBE:
14206 memcpy(drv_ops_string, "probe", sizeof("probe"));
14207 break;
14208 case eHDD_DRV_OP_REMOVE:
14209 memcpy(drv_ops_string, "remove", sizeof("remove"));
14210 break;
14211 case eHDD_DRV_OP_SHUTDOWN:
14212 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
14213 break;
14214 case eHDD_DRV_OP_REINIT:
14215 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
14216 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053014217 case eHDD_DRV_OP_IFF_UP:
14218 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
14219 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014220 }
14221
Dustin Brown45ed4bb2017-12-18 12:00:13 -080014222 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014223 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
Dustin Browncfc54fe2018-06-18 16:17:41 -070014224 HDD_OPS_INACTIVITY_TIMEOUT * qdf_timer_get_multiplier());
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014225}
14226
14227/**
14228 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
14229 *
14230 * Return: none
14231 */
14232void hdd_stop_driver_ops_timer(void)
14233{
14234 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
14235}
14236
14237/**
14238 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
14239 * inactivity timer
14240 *
14241 * Return: None
14242 */
14243void hdd_drv_ops_inactivity_handler(void)
14244{
Rajeev Kumar4471f1b2018-06-08 14:18:28 -070014245 hdd_err("WLAN_BUG_RCA %s: %d Sec timer expired while in .%s",
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014246 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
14247
Dustin Brown45ed4bb2017-12-18 12:00:13 -080014248 if (hdd_drv_ops_task) {
14249 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
14250 qdf_print_thread_trace(hdd_drv_ops_task);
14251 } else {
14252 hdd_err("hdd_drv_ops_task is null");
14253 }
14254
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014255 /* Driver shutdown is stuck, no recovery possible at this point */
14256 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
14257 sizeof("shutdown")))
14258 QDF_BUG(0);
14259
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080014260 if (cds_is_fw_down()) {
14261 hdd_err("FW is down");
14262 return;
14263 }
14264
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014265 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053014266 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014267 else
14268 QDF_BUG(0);
14269}
14270
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053014271void hdd_pld_ipa_uc_shutdown_pipes(void)
14272{
14273 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14274
14275 if (!hdd_ctx)
14276 return;
14277
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +053014278 ucfg_ipa_uc_force_pipe_shutdown(hdd_ctx->hdd_pdev);
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053014279}
14280
Yun Parkff6a16a2017-09-26 16:38:18 -070014281/**
14282 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
14283 * @struct hdd_context *hdd_ctx
14284 * @struct hdd_adapter *padapter
14285 * @bool enble
14286 *
14287 * Return: none
14288 */
14289void hdd_set_rx_mode_rps(bool enable)
14290{
14291 struct cds_config_info *cds_cfg = cds_get_ini_config();
Ryan Hsu0e878fa2018-05-04 15:22:09 -070014292 struct hdd_context *hdd_ctx;
14293 struct hdd_adapter *adapter;
Yun Parkff6a16a2017-09-26 16:38:18 -070014294
Ryan Hsu0e878fa2018-05-04 15:22:09 -070014295 if (!cds_cfg)
14296 return;
14297
14298 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14299 if (!hdd_ctx)
14300 return;
14301
14302 adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
14303 if (!adapter)
14304 return;
14305
14306 if (!hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
Yun Parkff6a16a2017-09-26 16:38:18 -070014307 if (enable && !cds_cfg->rps_enabled)
14308 hdd_send_rps_ind(adapter);
14309 else if (!enable && cds_cfg->rps_enabled)
14310 hdd_send_rps_disable_ind(adapter);
14311 }
14312}
14313
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +053014314bool hdd_is_cli_iface_up(struct hdd_context *hdd_ctx)
14315{
14316 struct hdd_adapter *adapter = NULL;
14317
14318 hdd_for_each_adapter(hdd_ctx, adapter) {
14319 if ((adapter->device_mode == QDF_STA_MODE ||
14320 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
14321 qdf_atomic_test_bit(DEVICE_IFACE_OPENED,
14322 &adapter->event_flags)){
14323 return true;
14324 }
14325 }
14326
14327 return false;
14328}
14329
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014330/* Register the module init/exit functions */
14331module_init(hdd_module_init);
14332module_exit(hdd_module_exit);
14333
14334MODULE_LICENSE("Dual BSD/GPL");
14335MODULE_AUTHOR("Qualcomm Atheros, Inc.");
14336MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
14337
Srinivas Girigowda841da292018-02-21 16:33:00 -080014338static const struct kernel_param_ops con_mode_ops = {
14339 .set = con_mode_handler,
14340 .get = param_get_int,
14341};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014342
Srinivas Girigowda841da292018-02-21 16:33:00 -080014343static const struct kernel_param_ops con_mode_ftm_ops = {
14344 .set = con_mode_handler_ftm,
14345 .get = param_get_int,
14346};
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053014347
Nirav Shah73713f72018-05-17 14:50:41 +053014348#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080014349static const struct kernel_param_ops con_mode_monitor_ops = {
14350 .set = con_mode_handler_monitor,
14351 .get = param_get_int,
14352};
Nirav Shah73713f72018-05-17 14:50:41 +053014353#endif
Ravi Joshia307f632017-07-17 23:41:41 -070014354
Srinivas Girigowda841da292018-02-21 16:33:00 -080014355static const struct kernel_param_ops fwpath_ops = {
14356 .set = fwpath_changed_handler,
14357 .get = param_get_string,
14358};
14359
14360module_param_cb(con_mode, &con_mode_ops, &con_mode,
14361 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
14362
14363module_param_cb(con_mode_ftm, &con_mode_ftm_ops, &con_mode_ftm,
14364 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
14365
Nirav Shah73713f72018-05-17 14:50:41 +053014366#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080014367module_param_cb(con_mode_monitor, &con_mode_monitor_ops, &con_mode_monitor,
14368 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Nirav Shah73713f72018-05-17 14:50:41 +053014369#endif
Srinivas Girigowda841da292018-02-21 16:33:00 -080014370
14371module_param_cb(fwpath, &fwpath_ops, &fwpath,
14372 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014373
14374module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
14375
14376module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
14377
14378module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);