blob: bfd3af29e69d12e09f13f10f3bb2b5fe057ffea0 [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"
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +0530131#include "wlan_ipa_ucfg_api.h"
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530132#include <target_if.h>
Alok Kumarb64650c2018-03-23 17:05:11 +0530133#include "wlan_hdd_nud_tracking.h"
Nachiket Kukaded0dd62e2018-05-21 18:39:22 +0530134#include "wlan_hdd_apf.h"
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -0700135#include "wlan_hdd_twt.h"
Rachit Kankane0dc3e852018-05-07 17:33:42 +0530136#include "qc_sap_ioctl.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530137
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530138#ifdef CNSS_GENL
139#include <net/cnss_nl.h>
140#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800141#include "wlan_reg_ucfg_api.h"
Zhang Qian47e22ce2018-01-04 15:38:38 +0800142#include "wlan_ocb_ucfg_api.h"
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -0800143#include <wlan_hdd_spectralscan.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800144#ifdef MODULE
145#define WLAN_MODULE_NAME module_name(THIS_MODULE)
146#else
147#define WLAN_MODULE_NAME "wlan"
148#endif
149
150#ifdef TIMER_MANAGER
151#define TIMER_MANAGER_STR " +TIMER_MANAGER"
152#else
153#define TIMER_MANAGER_STR ""
154#endif
155
156#ifdef MEMORY_DEBUG
157#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
158#else
159#define MEMORY_DEBUG_STR ""
160#endif
161
Dustin Brownc1034df2018-02-07 14:51:32 -0800162#ifdef PANIC_ON_BUG
163#define PANIC_ON_BUG_STR " +PANIC_ON_BUG"
164#else
165#define PANIC_ON_BUG_STR ""
166#endif
167
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530168bool g_is_system_reboot_triggered;
Sachin Ahujadddd2632017-03-07 19:07:24 +0530169int wlan_start_ret_val;
170static DECLARE_COMPLETION(wlan_start_comp);
171static unsigned int dev_num = 1;
172static struct cdev wlan_hdd_state_cdev;
173static struct class *class;
174static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530175#ifndef MODULE
176static struct gwlan_loader *wlan_loader;
177static ssize_t wlan_boot_cb(struct kobject *kobj,
178 struct kobj_attribute *attr,
179 const char *buf, size_t count);
180struct gwlan_loader {
181 bool loaded_state;
182 struct kobject *boot_wlan_obj;
183 struct attribute_group *attr_group;
184};
185
186static struct kobj_attribute wlan_boot_attribute =
187 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
188
189static struct attribute *attrs[] = {
190 &wlan_boot_attribute.attr,
191 NULL,
192};
193
194#define MODULE_INITIALIZED 1
195#endif
196
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530197#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
198#define MAX_OPS_NAME_STRING_SIZE 20
Rajeev Kumar6d0b2ea2017-12-26 17:55:33 -0800199#define RATE_LIMIT_ERROR_LOG (256)
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530200
201static qdf_timer_t hdd_drv_ops_inactivity_timer;
Dustin Brown45ed4bb2017-12-18 12:00:13 -0800202static struct task_struct *hdd_drv_ops_task;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530203static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
204
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800205/* the Android framework expects this param even though we don't use it */
206#define BUF_LEN 20
207static char fwpath_buffer[BUF_LEN];
208static struct kparam_string fwpath = {
209 .string = fwpath_buffer,
210 .maxlen = BUF_LEN,
211};
212
213static char *country_code;
214static int enable_11d = -1;
215static int enable_dfs_chan_scan = -1;
216
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800217/*
218 * spinlock for synchronizing asynchronous request/response
219 * (full description of use in wlan_hdd_main.h)
220 */
221DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530222DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800223
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800224#define WLAN_NLINK_CESIUM 30
225
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530226static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800227
228#define WOW_MAX_FILTER_LISTS 1
229#define WOW_MAX_FILTERS_PER_LIST 4
230#define WOW_MIN_PATTERN_SIZE 6
231#define WOW_MAX_PATTERN_SIZE 64
232
Bala Venkatesh110b03e2018-07-10 16:02:08 +0530233/* max peer can be tdls peers + self peer + bss peer */
234#define HDD_MAX_VDEV_PEER_COUNT (HDD_MAX_NUM_TDLS_STA + 2)
235
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800236#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
237static const struct wiphy_wowlan_support wowlan_support_reg_init = {
238 .flags = WIPHY_WOWLAN_ANY |
239 WIPHY_WOWLAN_MAGIC_PKT |
240 WIPHY_WOWLAN_DISCONNECT |
241 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
242 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
243 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
244 WIPHY_WOWLAN_4WAY_HANDSHAKE |
245 WIPHY_WOWLAN_RFKILL_RELEASE,
246 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
247 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
248 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
249};
250#endif
251
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700252static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
253 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
254 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
255 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
256 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
257 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
258 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
259 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
260 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
261 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
262 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
263 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
264 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
265 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
266 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
267 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
268 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
269 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
270 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
271 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
272 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
273 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
274 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
275 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
276 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
277 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
278 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
279 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
280 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
281 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
282 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
283 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
284 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
285 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
286 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700287 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700288 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700289 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530290 [QDF_MODULE_ID_GREEN_AP] = {QDF_TRACE_LEVEL_ALL},
Zhang Qian47e22ce2018-01-04 15:38:38 +0800291 [QDF_MODULE_ID_OCB] = {QDF_TRACE_LEVEL_ALL},
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530292 [QDF_MODULE_ID_IPA] = {QDF_TRACE_LEVEL_ALL},
Dustin Brown84f46ea2018-02-15 11:57:36 -0800293 [QDF_MODULE_ID_CONFIG] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700294};
295
Ganesh Kondabattini35739572017-06-21 16:26:39 +0530296int limit_off_chan_tbl[HDD_MAX_AC][HDD_MAX_OFF_CHAN_ENTRIES] = {
297 { HDD_AC_BK_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BK },
298 { HDD_AC_BE_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BE },
299 { HDD_AC_VI_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VI },
300 { HDD_AC_VO_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VO },
301};
302
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530303struct notifier_block hdd_netdev_notifier;
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530304struct notifier_block system_reboot_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800305
306struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800307#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700308static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800309#endif
310
Sachin Ahujadddd2632017-03-07 19:07:24 +0530311void hdd_start_complete(int ret)
312{
313 wlan_start_ret_val = ret;
314
315 complete(&wlan_start_comp);
316}
317
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800318/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530319 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700320 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530321 *
322 * Return: none
323 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700324static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530325{
Jeff Johnson9d295242017-08-29 14:39:48 -0700326 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530327
Dustin Brown920397d2017-12-13 16:27:50 -0800328 hdd_for_each_adapter(hdd_ctx, adapter)
329 hdd_send_rps_ind(adapter);
Nirav Shahbd36b062016-07-18 11:12:59 +0530330}
331
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530332#ifdef QCA_HL_NETDEV_FLOW_CONTROL
333void wlan_hdd_mod_fc_timer(struct hdd_adapter *adapter,
334 enum netif_action_type action)
335{
336 if (!adapter->tx_flow_timer_initialized)
337 return;
338
339 if (action == WLAN_WAKE_NON_PRIORITY_QUEUE) {
340 qdf_mc_timer_stop(&adapter->tx_flow_control_timer);
341 } else if (action == WLAN_STOP_NON_PRIORITY_QUEUE) {
342 QDF_STATUS status =
343 qdf_mc_timer_start(&adapter->tx_flow_control_timer,
344 WLAN_HDD_TX_FLOW_CONTROL_OS_Q_BLOCK_TIME);
345
346 if (!QDF_IS_STATUS_SUCCESS(status))
347 hdd_err("Failed to start tx_flow_control_timer");
348 else
349 adapter->
350 hdd_stats.tx_rx_stats.txflow_timer_cnt++;
351
352 adapter->hdd_stats.tx_rx_stats.txflow_pause_cnt++;
353 adapter->hdd_stats.tx_rx_stats.is_txflow_paused = true;
354 }
355}
356#endif /* QCA_HL_NETDEV_FLOW_CONTROL */
357
Nirav Shahbd36b062016-07-18 11:12:59 +0530358/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800359 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
360 * @vdev_id: vdev_id
361 * @action: action type
362 * @reason: reason type
363 *
364 * Return: none
365 */
366void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
367 enum netif_action_type action, enum netif_reason_type reason)
368{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700369 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700370 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800371
372 if (!hdd_ctx) {
373 hdd_err("hdd ctx is NULL");
374 return;
375 }
376 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530377 wlan_hdd_mod_fc_timer(adapter, action);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800378 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800379}
380
381/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700382 * Store WLAN driver version and timestamp info in global variables such that
383 * crash debugger can extract them from driver debug symbol and crashdump for
384 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800385 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800386#ifdef BUILD_TAG
387uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR "; " BUILD_TAG;
388#else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800389uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700390#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800391
392/**
393 * hdd_device_mode_to_string() - return string conversion of device mode
394 * @device_mode: device mode
395 *
396 * This utility function helps log string conversion of device mode.
397 *
398 * Return: string conversion of device mode, if match found;
399 * "Unknown" otherwise.
400 */
401const char *hdd_device_mode_to_string(uint8_t device_mode)
402{
403 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800404 CASE_RETURN_STRING(QDF_STA_MODE);
405 CASE_RETURN_STRING(QDF_SAP_MODE);
406 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
407 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
408 CASE_RETURN_STRING(QDF_FTM_MODE);
409 CASE_RETURN_STRING(QDF_IBSS_MODE);
410 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
411 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700412 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800413 default:
414 return "Unknown";
415 }
416}
417
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530418/**
Liangwei Dong17bf2662018-01-05 02:02:05 -0500419 * hdd_get_valid_chan() - return current chan list from regulatory.
420 * @hdd_ctx: HDD context
421 * @chan_list: buf hold returned chan list
422 * @chan_num: input buf size and output returned chan num
423 *
424 * This function helps get current available chan list from regulatory
425 * module. It excludes the "disabled" and "invalid" channels.
426 *
427 * Return: 0 for success.
428 */
429static int hdd_get_valid_chan(struct hdd_context *hdd_ctx,
430 uint8_t *chan_list,
431 uint32_t *chan_num)
432{
433 int i = 0, j = 0;
434 struct regulatory_channel *cur_chan_list;
435 struct wlan_objmgr_pdev *pdev;
436
437 if (!hdd_ctx || !hdd_ctx->hdd_pdev || !chan_list || !chan_num)
438 return -EINVAL;
439
440 pdev = hdd_ctx->hdd_pdev;
441 cur_chan_list = qdf_mem_malloc(NUM_CHANNELS *
442 sizeof(struct regulatory_channel));
443 if (!cur_chan_list)
444 return -ENOMEM;
445
446 if (wlan_reg_get_current_chan_list(pdev, cur_chan_list) !=
447 QDF_STATUS_SUCCESS) {
448 qdf_mem_free(cur_chan_list);
449 return -EINVAL;
450 }
451
452 for (i = 0; i < NUM_CHANNELS; i++) {
453 uint32_t ch = cur_chan_list[i].chan_num;
454 enum channel_state state = wlan_reg_get_channel_state(pdev,
455 ch);
456
457 if (state != CHANNEL_STATE_DISABLE &&
458 state != CHANNEL_STATE_INVALID &&
459 j < *chan_num) {
460 chan_list[j] = (uint8_t)ch;
461 j++;
462 }
463 }
464 *chan_num = j;
465 qdf_mem_free(cur_chan_list);
466 return 0;
467}
468
469/**
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530470 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
471 * @adapter: HDD adapter
472 * @chan_number: Channel number
473 * @chan_bw: Bandwidth
474 *
475 * Checks if the given bandwidth is valid for the given channel number.
476 *
477 * Return: 0 for success, non-zero for failure
478 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700479int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530480 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800481 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530482{
Liangwei Dong17bf2662018-01-05 02:02:05 -0500483 uint8_t chan[NUM_CHANNELS];
484 uint32_t len = NUM_CHANNELS, i;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530485 bool found = false;
Jeff Johnson16528362018-06-14 12:34:16 -0700486 mac_handle_t mac_handle;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500487 int ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530488
Jeff Johnson16528362018-06-14 12:34:16 -0700489 mac_handle = hdd_adapter_get_mac_handle(adapter);
490 if (!mac_handle) {
491 hdd_err("Invalid MAC handle");
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530492 return -EINVAL;
493 }
494
Liangwei Dong17bf2662018-01-05 02:02:05 -0500495 ret = hdd_get_valid_chan(adapter->hdd_ctx, chan,
496 &len);
497 if (ret) {
498 hdd_err("error %d in getting valid channel list", ret);
499 return ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530500 }
501
502 for (i = 0; i < len; i++) {
503 if (chan[i] == chan_number) {
504 found = true;
505 break;
506 }
507 }
508
509 if (found == false) {
510 hdd_err("Channel not in driver's valid channel list");
511 return -EOPNOTSUPP;
512 }
513
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700514 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
515 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530516 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
517 return -EINVAL;
518 }
519
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700520 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530521 if (chan_bw == CH_WIDTH_80MHZ) {
522 hdd_err("BW80 not possible in 2.4GHz band");
523 return -EINVAL;
524 }
525 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
526 (chan_bw != CH_WIDTH_MAX)) {
527 hdd_err("Only BW20 possible on channel 14");
528 return -EINVAL;
529 }
530 }
531
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700532 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530533 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
534 (chan_bw != CH_WIDTH_MAX)) {
535 hdd_err("Only BW20 possible on channel 165");
536 return -EINVAL;
537 }
538 }
539
540 return 0;
541}
542
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530543/**
544 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
545 *
546 * Block the unloading of the driver (or) interface up until the
547 * cds recovery is completed
548 *
549 * Return: true for recovery completion else false
550 */
551static bool hdd_wait_for_recovery_completion(void)
552{
553 int retry = 0;
554
555 /* Wait for recovery to complete */
556 while (cds_is_driver_recovering()) {
557 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
558 hdd_err("Recovery in progress; wait here!!!");
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530559
560 if (g_is_system_reboot_triggered) {
561 hdd_info("System Reboot happening ignore unload!!");
562 return false;
563 }
564
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530565 msleep(1000);
566 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
567 hdd_err("SSR never completed, error");
568 /*
569 * Trigger the bug_on in the internal builds, in the
570 * customer builds self-recovery will be enabled
571 * in those cases just return error.
572 */
573 if (cds_is_self_recovery_enabled())
574 return false;
575 QDF_BUG(0);
576 }
577 }
578
579 hdd_info("Recovery completed successfully!");
580 return true;
581}
582
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530583
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800584static int __hdd_netdev_notifier_call(struct notifier_block *nb,
585 unsigned long state, void *data)
586{
587#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
588 struct netdev_notifier_info *dev_notif_info = data;
589 struct net_device *dev = dev_notif_info->dev;
590#else
591 struct net_device *dev = data;
592#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700593 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700594 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800595
Dustin Brownfdf17c12018-03-14 12:55:34 -0700596 hdd_enter_dev(dev);
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800597
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800598 /* Make sure that this callback corresponds to our device. */
599 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
600 return NOTIFY_DONE;
601
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530602 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800603 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700604 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800605 return NOTIFY_DONE;
606 }
607
608 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700609 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800610 return NOTIFY_DONE;
611 }
612
613 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
614 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800615 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530616 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800617 return NOTIFY_DONE;
618 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800619
620 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
621 hdd_err("%s: Driver module is closed", __func__);
622 return NOTIFY_DONE;
623 }
624
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530625 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800626 return NOTIFY_DONE;
627
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800628 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800629 dev->name, state);
630
631 switch (state) {
632 case NETDEV_REGISTER:
633 break;
634
635 case NETDEV_UNREGISTER:
636 break;
637
638 case NETDEV_UP:
Jeff Johnson16528362018-06-14 12:34:16 -0700639 sme_ch_avoid_update_req(hdd_ctx->mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800640 break;
641
642 case NETDEV_DOWN:
643 break;
644
645 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700646 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800647 complete(&adapter->linkup_event_var);
648 break;
649
650 case NETDEV_GOING_DOWN:
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700651 if (ucfg_scan_get_vdev_status(adapter->hdd_vdev) !=
652 SCAN_NOT_IN_PROGRESS) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530653 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -0700654 adapter->session_id, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800655 }
Min Liu9be5d4a2018-05-17 11:51:53 +0800656 cds_flush_work(&adapter->scan_block_work);
657 /* Need to clean up blocked scan request */
658 wlan_hdd_cfg80211_scan_block_cb(&adapter->scan_block_work);
Min Liu9be5d4a2018-05-17 11:51:53 +0800659 hdd_debug("Scan is not Pending from user");
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530660 /*
661 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
662 * of return status of hdd_stop call, kernel resets the IFF_UP
663 * flag after which driver does not send the cfg80211_scan_done.
664 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
665 */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +0530666 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800667 break;
668
669 default:
670 break;
671 }
672
673 return NOTIFY_DONE;
674}
675
676/**
677 * hdd_netdev_notifier_call() - netdev notifier callback function
678 * @nb: pointer to notifier block
679 * @state: state
680 * @ndev: ndev pointer
681 *
682 * Return: 0 on success, error number otherwise.
683 */
684static int hdd_netdev_notifier_call(struct notifier_block *nb,
685 unsigned long state,
686 void *ndev)
687{
688 int ret;
689
690 cds_ssr_protect(__func__);
691 ret = __hdd_netdev_notifier_call(nb, state, ndev);
692 cds_ssr_unprotect(__func__);
693
694 return ret;
695}
696
697struct notifier_block hdd_netdev_notifier = {
698 .notifier_call = hdd_netdev_notifier_call,
699};
700
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530701static int system_reboot_notifier_call(struct notifier_block *nb,
702 unsigned long msg_type, void *_unused)
703{
704 switch (msg_type) {
705 case SYS_DOWN:
706 case SYS_HALT:
707 case SYS_POWER_OFF:
708 g_is_system_reboot_triggered = true;
709 hdd_info("reboot, reason: %ld", msg_type);
710 break;
711 default:
712 break;
713 }
714
715 return NOTIFY_OK;
716}
717
718struct notifier_block system_reboot_notifier = {
719 .notifier_call = system_reboot_notifier_call,
720};
721
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800722/* variable to hold the insmod parameters */
723static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800724
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530725static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700726int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530727
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800728/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800729static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800730
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530731/**
732 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
733 * @ch_width: NL channel width
734 *
735 * Converts the NL channel width to the driver's internal representation
736 *
737 * Return: Converted channel width. In case of non matching NL channel width,
738 * CH_WIDTH_MAX will be returned.
739 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800740enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530741{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800742 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700743
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800744 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530745 switch (ch_width) {
746 case NL80211_CHAN_WIDTH_20_NOHT:
747 case NL80211_CHAN_WIDTH_20:
748 return CH_WIDTH_20MHZ;
749 case NL80211_CHAN_WIDTH_40:
750 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530751 case NL80211_CHAN_WIDTH_80:
752 return CH_WIDTH_80MHZ;
753 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800754 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
755 return CH_WIDTH_80P80MHZ;
756 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
757 return CH_WIDTH_160MHZ;
758 else
759 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530760 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800761 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
762 return CH_WIDTH_160MHZ;
763 else
764 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530765 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800766 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530767 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800768 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530769 default:
770 hdd_err("Invalid channel width %d, setting to default",
771 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800772 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530773 }
774}
775
Jeff Johnson16528362018-06-14 12:34:16 -0700776uint8_t wlan_hdd_find_opclass(mac_handle_t mac_handle, uint8_t channel,
777 uint8_t bw_offset)
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530778{
779 uint8_t opclass = 0;
780
Jeff Johnson16528362018-06-14 12:34:16 -0700781 sme_get_opclass(mac_handle, channel, bw_offset, &opclass);
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530782 return opclass;
783}
784
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800785/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530786 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530787 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800788 * @bitmask: Bitmask of log levels to be enabled
789 *
790 * Called immediately after the cfg.ini is read in order to configure
791 * the desired trace levels.
792 *
793 * Return: None
794 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530795int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800796{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530797 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530798 int qdf_print_idx = -1;
799 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800800 /*
801 * if the bitmask is the default value, then a bitmask was not
802 * specified in cfg.ini, so leave the logging level alone (it
803 * will remain at the "compiled in" default value)
804 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700805 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530806 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800807
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530808 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800809
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530810 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530811 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530812 QDF_TRACE_LEVEL_NONE, 0);
813
814 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530815 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800816 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530817 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800818 while (0 != bitmask) {
819 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530820 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530821 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530822 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530823 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800824 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700825
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800826 level++;
827 bitmask >>= 1;
828 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530829 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800830}
831
832/**
Chris Guo1751acf2017-07-03 14:09:01 +0800833 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
834 * @hdd_ctx: HDD context pointer
835 *
836 * Return: 0 if the context is valid. Error code otherwise
837 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700838int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800839{
840 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
841 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
842 return -ENODEV;
843 }
844
845 if (cds_is_driver_recovering()) {
846 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
847 (void *)_RET_IP_, cds_get_driver_state());
848 return -EAGAIN;
849 }
850
851 if (hdd_ctx->start_modules_in_progress ||
852 hdd_ctx->stop_modules_in_progress) {
853 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
854 (void *)_RET_IP_);
855 return -EAGAIN;
856 }
857
858 return 0;
859}
860
861
862/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800863 * wlan_hdd_validate_context() - check the HDD context
864 * @hdd_ctx: HDD context pointer
865 *
866 * Return: 0 if the context is valid. Error code otherwise
867 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700868int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800869{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800870 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530871 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800872 return -ENODEV;
873 }
874
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800875 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800876 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530877 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800878 return -EAGAIN;
879 }
880
Yue Ma9f275d92017-09-14 16:58:41 -0700881 if (cds_is_load_or_unload_in_progress()) {
882 hdd_debug("%pS Load or unload in progress, state: 0x%x, ignore!",
883 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800884 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -0700885 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530886
887 if (hdd_ctx->start_modules_in_progress ||
888 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800889 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530890 (void *)_RET_IP_);
891 return -EAGAIN;
892 }
893
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530894 if (cds_is_driver_in_bad_state()) {
895 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
896 (void *)_RET_IP_, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +0530897 return -EAGAIN;
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530898 }
899
Arunk Khandavalli2859fa12018-02-14 10:46:26 +0530900 if (cds_is_fw_down()) {
901 hdd_debug("%pS FW is down: 0x%x Ignore!!!",
902 (void *)_RET_IP_, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +0530903 return -EAGAIN;
Arunk Khandavalli2859fa12018-02-14 10:46:26 +0530904 }
905
Liangwei Dong858feb12018-05-21 01:52:46 -0400906 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
907 hdd_debug("con_mode_handler is in progress Ignore!!!");
908 return -EAGAIN;
909 }
910
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800911 return 0;
912}
913
Jeff Johnson9d295242017-08-29 14:39:48 -0700914int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700915{
916 if (!adapter) {
917 hdd_err("adapter is null");
918 return -EINVAL;
919 }
920
921 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Mahesh Kumar Kalikot Veetil44427542018-06-08 12:29:36 -0700922 hdd_err("bad adapter magic");
Dustin Brownf13b8c32017-05-19 17:23:08 -0700923 return -EINVAL;
924 }
925
926 if (!adapter->dev) {
927 hdd_err("adapter net_device is null");
928 return -EINVAL;
929 }
930
931 if (!(adapter->dev->flags & IFF_UP)) {
932 hdd_info("adapter net_device is not up");
933 return -EAGAIN;
934 }
935
Jeff Johnson1b780e42017-10-31 14:11:45 -0700936 if (wlan_hdd_validate_session_id(adapter->session_id)) {
Dustin Brownf13b8c32017-05-19 17:23:08 -0700937 hdd_info("adapter session is not open");
938 return -EAGAIN;
939 }
940
Jeff Johnson1b780e42017-10-31 14:11:45 -0700941 if (adapter->session_id >= MAX_NUMBER_OF_ADAPTERS) {
942 hdd_err("bad adapter session Id: %u", adapter->session_id);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700943 return -EINVAL;
944 }
945
946 return 0;
947}
948
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800949/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530950 * wlan_hdd_validate_modules_state() - Check modules status
951 * @hdd_ctx: HDD context pointer
952 *
953 * Check's the driver module's state and returns true if the
954 * modules are enabled returns false if modules are closed.
955 *
956 * Return: True if modules are enabled or false.
957 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700958bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530959{
960 mutex_lock(&hdd_ctx->iface_change_lock);
961 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
962 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown5e89ef82018-03-14 11:50:23 -0700963 hdd_info("Modules not enabled, Present status: %d",
964 hdd_ctx->driver_status);
Arun Khandavallica892f62017-05-26 14:25:50 +0530965 return false;
966 }
967 mutex_unlock(&hdd_ctx->iface_change_lock);
968 return true;
969}
970
971/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800972 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700973 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800974 *
975 * This function sets the IBSS power save config parameters to WMA
976 * which will send it to firmware if FW supports IBSS power save
977 * before vdev start.
978 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530979 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800980 * on failure.
981 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700982QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800983{
984 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700985 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800986
987 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700988 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530989 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800990 }
991
Jeff Johnson1b780e42017-10-31 14:11:45 -0700992 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800993 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
994 hdd_ctx->config->ibssATIMWinSize,
995 VDEV_CMD);
996 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -0700997 hdd_err("atim window set failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530998 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800999 }
1000
Jeff Johnson1b780e42017-10-31 14:11:45 -07001001 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001002 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
1003 hdd_ctx->config->isIbssPowerSaveAllowed,
1004 VDEV_CMD);
1005 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001006 hdd_err("power save allow failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001007 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301008 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001009 }
1010
Jeff Johnson1b780e42017-10-31 14:11:45 -07001011 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001012 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
1013 hdd_ctx->config->
1014 isIbssPowerCollapseAllowed, VDEV_CMD);
1015 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001016 hdd_err("power collapse allow failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001017 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301018 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001019 }
1020
Jeff Johnson1b780e42017-10-31 14:11:45 -07001021 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001022 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
1023 hdd_ctx->config->isIbssAwakeOnTxRx,
1024 VDEV_CMD);
1025 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001026 hdd_err("set awake on tx/rx failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301027 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001028 }
1029
Jeff Johnson1b780e42017-10-31 14:11:45 -07001030 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001031 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
1032 hdd_ctx->config->ibssInactivityCount,
1033 VDEV_CMD);
1034 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001035 hdd_err("set inactivity time failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301036 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001037 }
1038
Jeff Johnson1b780e42017-10-31 14:11:45 -07001039 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001040 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
1041 hdd_ctx->config->ibssTxSpEndInactivityTime,
1042 VDEV_CMD);
1043 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001044 hdd_err("set txsp end failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001045 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301046 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001047 }
1048
Jeff Johnson1b780e42017-10-31 14:11:45 -07001049 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001050 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
1051 hdd_ctx->config->ibssPsWarmupTime,
1052 VDEV_CMD);
1053 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001054 hdd_err("set ps warmup failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001055 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301056 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001057 }
1058
Jeff Johnson1b780e42017-10-31 14:11:45 -07001059 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001060 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
1061 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
1062 VDEV_CMD);
1063 if (0 != ret) {
Rajeev Kumareeeb6f22018-07-12 11:10:27 -07001064 hdd_err("set 1rx chain atim failed %d",
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001065 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301066 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001067 }
1068
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301069 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001070}
1071
Yue Macd359b72017-10-03 15:21:00 -07001072#ifdef FEATURE_RUNTIME_PM
1073/**
1074 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
1075 * @hdd_ctx: HDD context
1076 *
1077 * Return: None
1078 */
1079static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
1080{
1081 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1082
Yue Macd359b72017-10-03 15:21:00 -07001083 qdf_runtime_lock_init(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001084 qdf_runtime_lock_init(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001085
1086 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
1087}
1088
1089/**
1090 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1091 * @hdd_ctx: HDD Context
1092 *
1093 * Return: None
1094 */
1095static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1096{
1097 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1098
Yue Macd359b72017-10-03 15:21:00 -07001099 qdf_runtime_lock_deinit(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001100 qdf_runtime_lock_deinit(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001101
1102 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
1103}
1104
Yue Macd359b72017-10-03 15:21:00 -07001105#else /* FEATURE_RUNTIME_PM */
1106static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1107static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Yue Macd359b72017-10-03 15:21:00 -07001108#endif /* FEATURE_RUNTIME_PM */
1109
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001110#define INTF_MACADDR_MASK 0x7
1111
1112/**
1113 * hdd_update_macaddr() - update mac address
1114 * @config: hdd configuration
1115 * @hw_macaddr: mac address
1116 *
1117 * Mac address for multiple virtual interface is found as following
1118 * i) The mac address of the first interface is just the actual hw mac address.
1119 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
1120 * define the mac address for the remaining interfaces and locally
1121 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1122 * supported virtual interfaces, right now this is 0x07 (meaning 8
1123 * interface).
1124 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1125 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1126 *
1127 * Return: None
1128 */
1129void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301130 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001131{
1132 int8_t i;
1133 uint8_t macaddr_b3, tmp_br3;
1134
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301135 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301136 QDF_MAC_ADDR_SIZE);
1137 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301138 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301139 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001140 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1141 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1142 INTF_MACADDR_MASK;
1143 macaddr_b3 += tmp_br3;
1144
1145 /* XOR-ing bit-24 of the mac address. This will give enough
1146 * mac address range before collision
1147 */
1148 macaddr_b3 ^= (1 << 7);
1149
1150 /* Set locally administered bit */
1151 config->intfMacAddr[i].bytes[0] |= 0x02;
1152 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001153 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001154 MAC_ADDRESS_STR, i,
1155 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1156 }
1157}
1158
Kabilan Kannan44a58372017-12-06 18:16:11 -08001159static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1160{
1161 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
1162 struct tdls_start_params tdls_cfg;
1163 struct tdls_user_config *config = &tdls_cfg.config;
1164 struct hdd_config *cfg = hdd_ctx->config;
1165 QDF_STATUS status;
1166
1167 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
1168 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
1169 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
1170 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
1171 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
1172 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
1173 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
1174 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
1175 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
1176 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
1177 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
1178 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
1179 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
1180 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
1181 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
1182 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
1183 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
1184 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
1185 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
1186 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
1187 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
1188 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
1189 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
1190 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
1191 (cfg->fEnableTDLSImplicitTrigger ?
1192 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
1193 (cfg->fTDLSExternalControl ?
1194 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
1195 config->tdls_vdev_nss_2g = CFG_TDLS_NSS(cfg->vdev_type_nss_2g);
1196 config->tdls_vdev_nss_5g = CFG_TDLS_NSS(cfg->vdev_type_nss_5g);
1197
1198 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
1199 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
1200 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
1201 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
1202 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1203 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1204 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1205 tdls_cfg.tdls_evt_cb_data = psoc;
Jeff Johnson1d40f5b2018-03-02 08:35:53 -08001206 tdls_cfg.tdls_peer_context = hdd_ctx;
1207 tdls_cfg.tdls_reg_peer = hdd_tdls_register_peer;
1208 tdls_cfg.tdls_dereg_peer = hdd_tdls_deregister_peer;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001209 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1210 tdls_cfg.tdls_wmm_cb_data = psoc;
1211 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1212 tdls_cfg.tdls_rx_cb_data = psoc;
1213 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1214
1215 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1216 if (status != QDF_STATUS_SUCCESS) {
1217 hdd_err("failed pmo psoc configuration");
1218 return -EINVAL;
1219 }
1220
1221 hdd_ctx->tdls_umac_comp_active = true;
1222 /* enable napier specific tdls data path */
1223 hdd_ctx->tdls_nap_active = true;
1224
1225 return 0;
1226}
1227
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001228static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001229 struct wma_tgt_services *cfg)
1230{
1231 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001232
1233 /* Set up UAPSD */
1234 config->apUapsdEnabled &= cfg->uapsd;
1235
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001236 /* 11AX mode support */
1237 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1238 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1239 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1240
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001241 /* 11AC mode support */
1242 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1243 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1244 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001245
1246 /* ARP offload: override user setting if invalid */
1247 config->fhostArpOffload &= cfg->arp_offload;
1248
1249#ifdef FEATURE_WLAN_SCAN_PNO
1250 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001251 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001252 if (cfg->pno_offload)
1253 config->PnoOffload = true;
1254#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001255#ifdef FEATURE_WLAN_TDLS
1256 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301257 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1258 cfg->en_tdls_offchan;
1259 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1260 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001261 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001262 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001263 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001264 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001265#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001266#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1267 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1268#endif
Will Huang496b36c2017-07-11 16:38:50 +08001269 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001270 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001271 hdd_update_tdls_config(hdd_ctx);
Jeff Johnson16528362018-06-14 12:34:16 -07001272 sme_update_tgt_services(hdd_ctx->mac_handle, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001273
1274}
1275
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001276/**
1277 * hdd_update_vdev_nss() - sets the vdev nss
1278 * @hdd_ctx: HDD context
1279 *
1280 * Sets the Nss per vdev type based on INI
1281 *
1282 * Return: None
1283 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001284static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001285{
1286 struct hdd_config *cfg_ini = hdd_ctx->config;
1287 uint8_t max_supp_nss = 1;
Jeff Johnson16528362018-06-14 12:34:16 -07001288 mac_handle_t mac_handle;
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001289
Naveen Rawat10b1c152017-01-18 11:16:06 -08001290 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001291 max_supp_nss = 2;
Liangwei Dong22810e82018-03-15 03:42:12 -04001292 hdd_debug("max nss %d vdev_type_nss_2g %x vdev_type_nss_5g %x",
1293 max_supp_nss, cfg_ini->vdev_type_nss_2g,
1294 cfg_ini->vdev_type_nss_5g);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001295
Jeff Johnson16528362018-06-14 12:34:16 -07001296 mac_handle = hdd_ctx->mac_handle;
1297 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
1298 cfg_ini->vdev_type_nss_2g, BAND_2G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001299
Jeff Johnson16528362018-06-14 12:34:16 -07001300 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
1301 cfg_ini->vdev_type_nss_5g, BAND_5G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001302}
1303
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301304/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301305 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1306 * @hdd_ctx: HDD context
1307 *
1308 * Updates wiphy vhtcap fields
1309 *
1310 * Return: None
1311 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001312static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301313{
1314 struct ieee80211_supported_band *band_5g =
1315 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1316 uint32_t val;
1317
1318 if (!band_5g) {
1319 hdd_debug("5GHz band disabled, skipping capability population");
1320 return;
1321 }
1322
1323 val = hdd_ctx->config->txBFCsnValue;
1324 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1325
1326 val = NUM_OF_SOUNDING_DIMENSIONS;
1327 band_5g->vht_cap.cap |=
1328 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1329
1330 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1331 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1332}
1333
1334/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301335 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1336 * @hdd_ctx: HDD context
1337 *
1338 * Sets the DBS capability as per INI and firmware capability
1339 *
1340 * Return: None
1341 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001342static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301343{
1344 struct hdd_config *cfg_ini = hdd_ctx->config;
1345 uint8_t hw_dbs_capable = 0;
1346
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001347 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1348 ((cfg_ini->dual_mac_feature_disable ==
1349 ENABLE_DBS_CXN_AND_SCAN) ||
1350 (cfg_ini->dual_mac_feature_disable ==
1351 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301352 hw_dbs_capable = 1;
1353
Jeff Johnson16528362018-06-14 12:34:16 -07001354 sme_update_hw_dbs_capable(hdd_ctx->mac_handle, hw_dbs_capable);
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301355}
1356
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001357static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001358 struct wma_tgt_ht_cap *cfg)
1359{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301360 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001361 uint32_t value, val32;
1362 uint16_t val16;
1363 struct hdd_config *pconfig = hdd_ctx->config;
1364 tSirMacHTCapabilityInfo *phtCapInfo;
1365 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1366 uint8_t enable_tx_stbc;
Jeff Johnson16528362018-06-14 12:34:16 -07001367 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001368
1369 /* check and update RX STBC */
1370 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1371 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1372
Jeff Johnson16528362018-06-14 12:34:16 -07001373 mac_handle = hdd_ctx->mac_handle;
1374
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001375 /* get the MPDU density */
Jeff Johnson16528362018-06-14 12:34:16 -07001376 status = sme_cfg_get_int(mac_handle, WNI_CFG_MPDU_DENSITY, &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001377
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301378 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001379 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001380 value = 0;
1381 }
1382
1383 /*
1384 * MPDU density:
1385 * override user's setting if value is larger
1386 * than the one supported by target
1387 */
1388 if (value > cfg->mpdu_density) {
Jeff Johnson16528362018-06-14 12:34:16 -07001389 status = sme_cfg_set_int(mac_handle, WNI_CFG_MPDU_DENSITY,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001390 cfg->mpdu_density);
1391
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301392 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001393 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001394 }
1395
1396 /* get the HT capability info */
Jeff Johnson16528362018-06-14 12:34:16 -07001397 status = sme_cfg_get_int(mac_handle, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301398 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001399 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001400 return;
1401 }
1402 val16 = (uint16_t) val32;
1403 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1404
1405 /* Set the LDPC capability */
1406 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1407
1408 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1409 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1410
1411 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1412 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1413
1414 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1415 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1416
1417 enable_tx_stbc = pconfig->enableTxSTBC;
1418
1419 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1420 pconfig->enable2x2 = 1;
1421 } else {
1422 pconfig->enable2x2 = 0;
1423 enable_tx_stbc = 0;
1424
1425 /* 1x1 */
1426 /* Update Rx Highest Long GI data Rate */
Jeff Johnson16528362018-06-14 12:34:16 -07001427 if (sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001428 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001429 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301430 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001431 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001432 }
1433
1434 /* Update Tx Highest Long GI data Rate */
1435 if (sme_cfg_set_int
Jeff Johnson16528362018-06-14 12:34:16 -07001436 (mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001437 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001438 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301439 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001440 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001441 }
1442 }
1443 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1444 enable_tx_stbc = 0;
1445 phtCapInfo->txSTBC = enable_tx_stbc;
1446
1447 val32 = val16;
Jeff Johnson16528362018-06-14 12:34:16 -07001448 status = sme_cfg_set_int(mac_handle, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301449 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001450 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001451#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1452 value = SIZE_OF_SUPPORTED_MCS_SET;
Jeff Johnson16528362018-06-14 12:34:16 -07001453 if (sme_cfg_get_str(mac_handle, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301454 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001455 hdd_debug("Read MCS rate set");
gaurank kathpalia18b49362018-04-15 23:12:03 +05301456 if (cfg->num_rf_chains > SIZE_OF_SUPPORTED_MCS_SET)
1457 cfg->num_rf_chains = SIZE_OF_SUPPORTED_MCS_SET;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001458 if (pconfig->enable2x2) {
1459 for (value = 0; value < cfg->num_rf_chains; value++)
1460 mcs_set[value] =
1461 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1462
1463 status =
Jeff Johnson16528362018-06-14 12:34:16 -07001464 sme_cfg_set_str(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001465 WNI_CFG_SUPPORTED_MCS_SET,
1466 mcs_set,
1467 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301468 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001469 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001470 }
1471 }
1472#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1473}
1474
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001475static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001476 struct wma_tgt_vht_cap *cfg)
1477{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301478 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001479 uint32_t value = 0;
1480 struct hdd_config *pconfig = hdd_ctx->config;
1481 struct wiphy *wiphy = hdd_ctx->wiphy;
1482 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001483 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001484 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001485 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001486 uint32_t hw_rx_ldpc_enabled;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001487 struct wma_caps_per_phy caps_per_phy;
Jeff Johnson16528362018-06-14 12:34:16 -07001488 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001489
Dustin Brown5e06bd32016-10-04 12:49:10 -07001490 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001491 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001492 return;
1493 }
1494
Jeff Johnson16528362018-06-14 12:34:16 -07001495 mac_handle = hdd_ctx->mac_handle;
1496
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001497 /* Get the current MPDU length */
1498 status =
Jeff Johnson16528362018-06-14 12:34:16 -07001499 sme_cfg_get_int(mac_handle, WNI_CFG_VHT_MAX_MPDU_LENGTH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001500 &value);
1501
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301502 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001503 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001504 value = 0;
1505 }
1506
1507 /*
1508 * VHT max MPDU length:
1509 * override if user configured value is too high
1510 * that the target cannot support
1511 */
1512 if (value > cfg->vht_max_mpdu) {
Jeff Johnson16528362018-06-14 12:34:16 -07001513 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001514 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1515 cfg->vht_max_mpdu);
1516
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001517 if (status == QDF_STATUS_E_FAILURE)
1518 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001519 }
1520
Jeff Johnson16528362018-06-14 12:34:16 -07001521 sme_cfg_get_int(mac_handle, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001522 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1523
1524 if (pconfig->enable2x2)
1525 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1526
Jeff Johnson16528362018-06-14 12:34:16 -07001527 if (sme_cfg_set_int(mac_handle, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001528 QDF_STATUS_E_FAILURE) {
1529 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1530 }
1531
Jeff Johnson16528362018-06-14 12:34:16 -07001532 sme_cfg_get_int(mac_handle, WNI_CFG_VHT_RX_MCS_MAP, &temp);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001533 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1534 if (pconfig->enable2x2)
1535 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1536
Jeff Johnson16528362018-06-14 12:34:16 -07001537 if (sme_cfg_set_int(mac_handle, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001538 QDF_STATUS_E_FAILURE) {
1539 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1540 }
1541
Jeff Johnson16528362018-06-14 12:34:16 -07001542 sme_cfg_get_int(mac_handle, WNI_CFG_VHT_TX_MCS_MAP, &temp);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001543 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1544 if (pconfig->enable2x2)
1545 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1546
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001547 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001548 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1549
Jeff Johnson16528362018-06-14 12:34:16 -07001550 if (sme_cfg_set_int(mac_handle, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001551 QDF_STATUS_E_FAILURE) {
1552 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1553 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001554 /* Get the current RX LDPC setting */
Jeff Johnson16528362018-06-14 12:34:16 -07001555 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_LDPC_CODING_CAP,
1556 &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001557
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301558 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001559 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001560 value = 0;
1561 }
1562
jiad4a7a33c2017-08-08 15:32:24 +08001563 /* Set HW RX LDPC capability */
1564 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1565 if (hw_rx_ldpc_enabled != value) {
Jeff Johnson16528362018-06-14 12:34:16 -07001566 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001567 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001568 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001569
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001570 if (status == QDF_STATUS_E_FAILURE)
1571 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001572 }
1573
1574 /* Get current GI 80 value */
Jeff Johnson16528362018-06-14 12:34:16 -07001575 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_SHORT_GI_80MHZ,
1576 &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001577
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301578 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001579 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001580 value = 0;
1581 }
1582
1583 /* set the Guard interval 80MHz */
1584 if (value && !cfg->vht_short_gi_80) {
Jeff Johnson16528362018-06-14 12:34:16 -07001585 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001586 WNI_CFG_VHT_SHORT_GI_80MHZ,
1587 cfg->vht_short_gi_80);
1588
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001589 if (status == QDF_STATUS_E_FAILURE)
1590 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001591 }
1592
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001593 /* Get VHT TX STBC cap */
Jeff Johnson16528362018-06-14 12:34:16 -07001594 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_TXSTBC, &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001595
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301596 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001597 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001598 value = 0;
1599 }
1600
1601 /* VHT TX STBC cap */
1602 if (value && !cfg->vht_tx_stbc) {
Jeff Johnson16528362018-06-14 12:34:16 -07001603 status = sme_cfg_set_int(mac_handle, WNI_CFG_VHT_TXSTBC,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001604 cfg->vht_tx_stbc);
1605
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001606 if (status == QDF_STATUS_E_FAILURE)
1607 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001608 }
1609
1610 /* Get VHT RX STBC cap */
Jeff Johnson16528362018-06-14 12:34:16 -07001611 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_RXSTBC, &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001612
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301613 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001614 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001615 value = 0;
1616 }
1617
1618 /* VHT RX STBC cap */
1619 if (value && !cfg->vht_rx_stbc) {
Jeff Johnson16528362018-06-14 12:34:16 -07001620 status = sme_cfg_set_int(mac_handle, WNI_CFG_VHT_RXSTBC,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001621 cfg->vht_rx_stbc);
1622
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001623 if (status == QDF_STATUS_E_FAILURE)
1624 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001625 }
1626
1627 /* Get VHT SU Beamformer cap */
Jeff Johnson16528362018-06-14 12:34:16 -07001628 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001629 &value);
1630
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301631 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001632 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001633 value = 0;
1634 }
1635
1636 /* set VHT SU Beamformer cap */
1637 if (value && !cfg->vht_su_bformer) {
Jeff Johnson16528362018-06-14 12:34:16 -07001638 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001639 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1640 cfg->vht_su_bformer);
1641
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001642 if (status == QDF_STATUS_E_FAILURE)
1643 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001644 }
1645
1646 /* check and update SU BEAMFORMEE capabality */
1647 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1648 pconfig->enableTxBF = cfg->vht_su_bformee;
1649
Jeff Johnson16528362018-06-14 12:34:16 -07001650 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001651 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1652 pconfig->enableTxBF);
1653
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001654 if (status == QDF_STATUS_E_FAILURE)
1655 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001656
1657 /* Get VHT MU Beamformer cap */
Jeff Johnson16528362018-06-14 12:34:16 -07001658 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001659 &value);
1660
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301661 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001662 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001663 value = 0;
1664 }
1665
1666 /* set VHT MU Beamformer cap */
1667 if (value && !cfg->vht_mu_bformer) {
Jeff Johnson16528362018-06-14 12:34:16 -07001668 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001669 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1670 cfg->vht_mu_bformer);
1671
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001672 if (status == QDF_STATUS_E_FAILURE)
1673 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001674 }
1675
1676 /* Get VHT MU Beamformee cap */
Jeff Johnson16528362018-06-14 12:34:16 -07001677 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001678 &value);
1679
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301680 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001681 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001682 value = 0;
1683 }
1684
1685 /* set VHT MU Beamformee cap */
1686 if (value && !cfg->vht_mu_bformee) {
Jeff Johnson16528362018-06-14 12:34:16 -07001687 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001688 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1689 cfg->vht_mu_bformee);
1690
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001691 if (status == QDF_STATUS_E_FAILURE)
1692 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001693 }
1694
1695 /* Get VHT MAX AMPDU Len exp */
Jeff Johnson16528362018-06-14 12:34:16 -07001696 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001697 &value);
1698
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301699 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001700 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001701 value = 0;
1702 }
1703
1704 /*
1705 * VHT max AMPDU len exp:
1706 * override if user configured value is too high
1707 * that the target cannot support.
1708 * Even though Rome publish ampdu_len=7, it can
1709 * only support 4 because of some h/w bug.
1710 */
1711
1712 if (value > cfg->vht_max_ampdu_len_exp) {
Jeff Johnson16528362018-06-14 12:34:16 -07001713 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001714 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1715 cfg->vht_max_ampdu_len_exp);
1716
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001717 if (status == QDF_STATUS_E_FAILURE)
1718 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001719 }
1720
1721 /* Get VHT TXOP PS CAP */
Jeff Johnson16528362018-06-14 12:34:16 -07001722 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_TXOP_PS, &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001723
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301724 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001725 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001726 value = 0;
1727 }
1728
1729 /* set VHT TXOP PS cap */
1730 if (value && !cfg->vht_txop_ps) {
Jeff Johnson16528362018-06-14 12:34:16 -07001731 status = sme_cfg_set_int(mac_handle, WNI_CFG_VHT_TXOP_PS,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001732 cfg->vht_txop_ps);
1733
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001734 if (status == QDF_STATUS_E_FAILURE)
1735 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001736 }
1737
1738 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1739 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1740 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1741 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1742 else
1743 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1744
1745
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001746 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
Jeff Johnson16528362018-06-14 12:34:16 -07001747 status = sme_cfg_set_int(mac_handle,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001748 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1749 VHT_CAP_160_AND_80P80_SUPP);
1750 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001751 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001752 band_5g->vht_cap.cap |=
1753 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001754 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1755 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
Jeff Johnson16528362018-06-14 12:34:16 -07001756 status = sme_cfg_set_int(mac_handle,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001757 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1758 VHT_CAP_160_SUPP);
1759 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001760 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001761 band_5g->vht_cap.cap |=
1762 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001763 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1764 }
1765 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1766 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301767 /* Get the current GI 160 value */
Jeff Johnson16528362018-06-14 12:34:16 -07001768 status = sme_cfg_get_int(mac_handle,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301769 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001770 &value);
1771 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301772 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001773 value = 0;
1774 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301775 /* set the Guard interval 160MHz */
1776 if (value && !cfg->vht_short_gi_160) {
Jeff Johnson16528362018-06-14 12:34:16 -07001777 status = sme_cfg_set_int(mac_handle,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301778 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1779 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001780
1781 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301782 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001783 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001784
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001785 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001786 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001787 hdd_debug("VHT RxLDPC capability is set");
1788 } else {
1789 /*
1790 * Get the RX LDPC capability for the NON DBS
1791 * hardware mode for 5G band
1792 */
1793 status = wma_get_caps_for_phyidx_hwmode(&caps_per_phy,
1794 HW_MODE_DBS_NONE, CDS_BAND_5GHZ);
1795 if ((QDF_IS_STATUS_SUCCESS(status)) &&
1796 (caps_per_phy.vht_5g & WMI_VHT_CAP_RX_LDPC)) {
1797 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1798 hdd_debug("VHT RX LDPC capability is set");
1799 }
1800 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001801
1802 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1803 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1804 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1805 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1806
1807 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1808 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1809
1810 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1811 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1812 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1813 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1814 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1815 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1816
1817 band_5g->vht_cap.cap |=
1818 (cfg->vht_max_ampdu_len_exp <<
1819 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1820
1821 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1822 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1823 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1824 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1825 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1826 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1827 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1828 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1829
1830 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1831 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1832
1833}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001834
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001835/**
1836 * hdd_generate_macaddr_auto() - Auto-generate mac address
1837 * @hdd_ctx: Pointer to the HDD context
1838 *
1839 * Auto-generate mac address using device serial number.
1840 * Keep the first 3 bytes of OUI as before and replace
1841 * the last 3 bytes with the lower 3 bytes of serial number.
1842 *
1843 * Return: 0 for success
1844 * Non zero failure code for errors
1845 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001846static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001847{
1848 unsigned int serialno = 0;
1849 struct qdf_mac_addr mac_addr = {
1850 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1851 };
1852
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001853 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001854 if (serialno == 0)
1855 return -EINVAL;
1856
1857 serialno &= 0x00ffffff;
1858
1859 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1860 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1861 mac_addr.bytes[5] = serialno & 0xff;
1862
1863 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1864 return 0;
1865}
1866
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05301867#ifdef FEATURE_WLAN_APF
1868/**
1869 * hdd_update_apf_support() - Update APF supported flag in hdd context
1870 * @hdd_ctx: Pointer to hdd_ctx
1871 * @cfg: target configuration
1872 *
1873 * Update the APF support flag in HDD Context using INI and target config.
1874 *
1875 * Return: None
1876 */
1877static void hdd_update_apf_support(struct hdd_context *hdd_ctx,
1878 struct wma_tgt_cfg *cfg)
1879{
1880 hdd_ctx->apf_supported = (cfg->apf_enabled &&
1881 hdd_ctx->config->apf_packet_filter_enable);
1882}
1883#else
1884static void hdd_update_apf_support(struct hdd_context *hdd_ctx,
1885 struct wma_tgt_cfg *cfg)
1886{
1887}
1888#endif
1889
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301890/**
1891 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1892 * configuration to cfg_ini in HDD
1893 * @hdd_ctx: Pointer to hdd_ctx
1894 * @cfg: target configuration
1895 *
1896 * Return: None
1897 */
1898#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001899static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301900 struct wma_tgt_cfg *cfg)
1901{
1902 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1903}
1904#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001905static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301906 struct wma_tgt_cfg *cfg)
1907{
1908}
1909#endif
1910
Jeff Johnson8abc5932018-06-02 22:51:37 -07001911void hdd_update_tgt_cfg(hdd_handle_t hdd_handle, struct wma_tgt_cfg *cfg)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001912{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001913 int ret;
Jeff Johnsonea70b942018-07-02 09:42:31 -07001914 struct hdd_context *hdd_ctx = hdd_handle_to_context(hdd_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001915 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001916 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301917 uint8_t antenna_mode;
Arif Hussainee10f902017-12-27 16:30:17 -08001918 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -07001919 mac_handle_t mac_handle;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301920
gaurank kathpalia843f7c32018-07-02 18:04:14 +05301921 if (!hdd_ctx) {
1922 hdd_err("HDD context is NULL");
1923 return;
1924 }
Dustin Brownbd68fe12017-11-21 15:28:52 -08001925 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1926 if (ret) {
1927 hdd_err("Failed to create pdev; errno:%d", ret);
1928 QDF_BUG(0);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001929 } else {
Dustin Brownbd68fe12017-11-21 15:28:52 -08001930 hdd_debug("New pdev has been created with pdev_id = %u",
Arif Hussainee10f902017-12-27 16:30:17 -08001931 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Amar Singhal410675c2018-01-10 12:14:21 -08001932 if (dispatcher_pdev_open(hdd_ctx->hdd_pdev)) {
1933 hdd_err("dispatcher pdev open failed");
1934 QDF_BUG(0);
1935 }
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301936 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001937
Sravan Kumar Kairamcb5fd012018-07-04 17:43:22 +05301938 cdp_pdev_set_ctrl_pdev(cds_get_context(QDF_MODULE_ID_SOC),
1939 cds_get_context(QDF_MODULE_ID_TXRX),
1940 (struct cdp_ctrl_objmgr_pdev *)hdd_ctx->hdd_pdev);
1941
1942 wlan_pdev_set_dp_handle(hdd_ctx->hdd_pdev,
1943 cds_get_context(QDF_MODULE_ID_TXRX));
1944
Will Huang07244172018-05-14 14:23:30 +08001945 hdd_objmgr_update_tgt_max_vdev_psoc(hdd_ctx, cfg->max_intf_count);
1946
Jeff Johnsone8846ab2018-03-31 11:54:45 -07001947 ret = hdd_green_ap_update_config(hdd_ctx);
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301948
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301949 ucfg_ipa_set_dp_handle(hdd_ctx->hdd_psoc,
1950 cds_get_context(QDF_MODULE_ID_SOC));
1951 ucfg_ipa_set_txrx_handle(hdd_ctx->hdd_psoc,
1952 cds_get_context(QDF_MODULE_ID_TXRX));
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301953 ucfg_ipa_reg_sap_xmit_cb(hdd_ctx->hdd_pdev,
1954 hdd_softap_hard_start_xmit);
1955 ucfg_ipa_reg_send_to_nw_cb(hdd_ctx->hdd_pdev,
1956 hdd_ipa_send_skb_to_network);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301957
Naveen Rawat64e477e2016-05-20 10:34:56 -07001958 if (cds_cfg) {
1959 if (hdd_ctx->config->enable_sub_20_channel_width !=
1960 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1961 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1962 cds_cfg->sub_20_channel_width =
1963 WLAN_SUB_20_CH_WIDTH_NONE;
1964 } else {
1965 cds_cfg->sub_20_channel_width =
1966 hdd_ctx->config->enable_sub_20_channel_width;
1967 }
1968 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001969
1970 /* first store the INI band capability */
1971 temp_band_cap = hdd_ctx->config->nBandCapability;
1972
1973 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301974 hdd_ctx->is_fils_roaming_supported =
1975 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001976
Vignesh Viswanathan694e28e2018-01-18 20:53:57 +05301977 hdd_ctx->config->is_11k_offload_supported =
1978 cfg->services.is_11k_offload_supported;
1979
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001980 /*
1981 * now overwrite the target band capability with INI
1982 * setting if INI setting is a subset
1983 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001984
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001985 if ((hdd_ctx->config->nBandCapability == BAND_ALL) &&
1986 (temp_band_cap != BAND_ALL))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001987 hdd_ctx->config->nBandCapability = temp_band_cap;
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001988 else if ((hdd_ctx->config->nBandCapability != BAND_ALL) &&
1989 (temp_band_cap != BAND_ALL) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001990 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001991 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001992 }
1993
Amar Singhal58b45ef2017-08-01 13:43:54 -07001994 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1995
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301996 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001997 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1998 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1999 }
2000
2001 /* This can be extended to other configurations like ht, vht cap... */
2002
Anurag Chouhanc5548422016-02-24 18:33:27 +05302003 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002004 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07002005 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002006 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07002007 static struct qdf_mac_addr default_mac_addr = {
2008 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
2009 };
2010 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
2011 &default_mac_addr)) {
2012 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
2013 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
2014 MAC_ADDRESS_STR,
2015 MAC_ADDR_ARRAY(hdd_ctx->config->
2016 intfMacAddr[0].bytes));
2017 } else {
2018 hdd_err("Invalid MAC passed from target, using MAC from ini file "
2019 MAC_ADDRESS_STR,
2020 MAC_ADDR_ARRAY(hdd_ctx->config->
2021 intfMacAddr[0].bytes));
2022 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07002023 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002024 }
2025
2026 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07002027 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002028
Ryan Hsuc6918552018-05-16 13:29:59 -07002029 hdd_ctx->hw_bd_id = cfg->hw_bd_id;
2030 qdf_mem_copy(&hdd_ctx->hw_bd_info, &cfg->hw_bd_info,
2031 sizeof(cfg->hw_bd_info));
2032
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002033 hdd_ctx->max_intf_count = cfg->max_intf_count;
2034
Jeff Johnsonc875e242016-09-23 18:12:34 -07002035 hdd_lpass_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08002036
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002037 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
2038 hdd_update_tgt_services(hdd_ctx, &cfg->services);
2039
2040 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
2041
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002042 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07002043 if (cfg->services.en_11ax) {
2044 hdd_info("11AX: 11ax is enabled - update HDD config");
2045 hdd_update_tgt_he_cap(hdd_ctx, cfg);
2046 }
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -07002047 hdd_update_tgt_twt_cap(hdd_ctx, cfg);
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07002048
2049 hdd_update_vdev_nss(hdd_ctx);
2050
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05302051 hdd_update_hw_dbs_capable(hdd_ctx);
2052
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08002053 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07002054 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002055 hdd_debug("fine_time_meas_cap: 0x%x",
Arif Hussainee10f902017-12-27 16:30:17 -08002056 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08002057
Nitesh Shahe50711f2017-04-26 16:30:45 +05302058 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
2059 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
2060 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002061 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08002062 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08002063
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05302064 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05302065 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05302066
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302067 if ((hdd_ctx->config->txBFCsnValue >
Arif Hussainee10f902017-12-27 16:30:17 -08002068 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
2069 !cfg->tx_bfee_8ss_enabled)
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302070 hdd_ctx->config->txBFCsnValue =
2071 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
2072
Jeff Johnson16528362018-06-14 12:34:16 -07002073 mac_handle = hdd_ctx->mac_handle;
2074 status = sme_cfg_set_int(mac_handle,
Arif Hussainee10f902017-12-27 16:30:17 -08002075 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
2076 hdd_ctx->config->txBFCsnValue);
2077 if (QDF_IS_STATUS_ERROR(status))
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302078 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
2079
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05302080 hdd_update_apf_support(hdd_ctx, cfg);
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302081
Nachiket Kukadee547a482018-05-22 16:43:30 +05302082 hdd_debug("Target APF %d Host APF %d 8ss fw support %d txBFCsnValue %d",
2083 cfg->apf_enabled, hdd_ctx->config->apf_packet_filter_enable,
Arif Hussainee10f902017-12-27 16:30:17 -08002084 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05302085
2086 /*
2087 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
2088 */
2089 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05302090
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05302091 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
2092
Yue Macd359b72017-10-03 15:21:00 -07002093 /*
2094 * This needs to be done after HDD pdev is created and stored since
2095 * it will access the HDD pdev object lock.
2096 */
2097 hdd_runtime_suspend_context_init(hdd_ctx);
2098
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07002099 /* Configure NAN datapath features */
2100 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07002101 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08002102 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Liangwei Dong0da14262018-07-03 03:30:23 -04002103 hdd_ctx->obss_scan_offload = cfg->services.obss_scan_offload;
Jeff Johnson16528362018-06-14 12:34:16 -07002104 status = sme_cfg_set_int(mac_handle, WNI_CFG_OBSS_DETECTION_OFFLOAD,
Arif Hussainee10f902017-12-27 16:30:17 -08002105 cfg->obss_detection_offloaded);
2106 if (QDF_IS_STATUS_ERROR(status))
2107 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Arif Hussain05fb4872018-01-03 16:02:55 -08002108
Jeff Johnson16528362018-06-14 12:34:16 -07002109 status = sme_cfg_set_int(mac_handle,
Arif Hussain05fb4872018-01-03 16:02:55 -08002110 WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD,
2111 cfg->obss_color_collision_offloaded);
2112 if (QDF_IS_STATUS_ERROR(status))
2113 hdd_err("Failed to set WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002114}
2115
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002116bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002117{
Jeff Johnson9d295242017-08-29 14:39:48 -07002118 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002119 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002120
Jiachao Wuf610d912018-01-23 17:47:32 +08002121 if (!hdd_ctx) {
2122 hdd_info("Couldn't get hdd_ctx");
2123 return true;
2124 }
2125
2126 if (hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002127 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08002128 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302129 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002130 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002131
Dustin Brown920397d2017-12-13 16:27:50 -08002132 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002133 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2134
2135 if ((QDF_SAP_MODE == adapter->device_mode ||
2136 QDF_P2P_GO_MODE == adapter->device_mode) &&
bings0e03a982018-05-09 08:40:59 +08002137 (wlan_reg_is_passive_or_disable_ch(hdd_ctx->hdd_pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002138 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002139 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2140 true;
2141 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07002142 adapter->session_id);
bings6fb9bf62018-07-05 14:01:53 +08002143 if (adapter->txrx_vdev)
2144 cdp_fc_vdev_flush(
2145 cds_get_context(QDF_MODULE_ID_SOC),
bings0e03a982018-05-09 08:40:59 +08002146 adapter->txrx_vdev);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302147 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002148 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302149
2150 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002151}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002152
2153/**
2154 * hdd_is_valid_mac_address() - validate MAC address
2155 * @pMacAddr: Pointer to the input MAC address
2156 *
2157 * This function validates whether the given MAC address is valid or not
2158 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
2159 * where X is the hexa decimal digit character and separated by ':'
2160 * This algorithm works even if MAC address is not separated by ':'
2161 *
2162 * This code checks given input string mac contains exactly 12 hexadecimal
2163 * digits and a separator colon : appears in the input string only after
2164 * an even number of hex digits.
2165 *
2166 * Return: 1 for valid and 0 for invalid
2167 */
2168bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
2169{
2170 int xdigit = 0;
2171 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002172
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002173 while (*pMacAddr) {
2174 if (isxdigit(*pMacAddr)) {
2175 xdigit++;
2176 } else if (':' == *pMacAddr) {
2177 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2178 break;
2179
2180 ++separator;
2181 } else {
2182 /* Invalid MAC found */
2183 return 0;
2184 }
2185 ++pMacAddr;
2186 }
2187 return xdigit == 12 && (separator == 5 || separator == 0);
2188}
2189
2190/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302191 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2192 * @dev: Handle to struct net_device to be updated.
2193 *
2194 * Return: None
2195 */
2196static void hdd_mon_mode_ether_setup(struct net_device *dev)
2197{
2198 dev->header_ops = NULL;
2199 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2200 dev->hard_header_len = ETH_HLEN;
2201 dev->mtu = ETH_DATA_LEN;
2202 dev->addr_len = ETH_ALEN;
2203 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2204 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2205 dev->priv_flags |= IFF_TX_SKB_SHARING;
2206
2207 memset(dev->broadcast, 0xFF, ETH_ALEN);
2208}
2209
Nirav Shah73713f72018-05-17 14:50:41 +05302210#ifdef FEATURE_MONITOR_MODE_SUPPORT
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302211/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002212 * __hdd__mon_open() - HDD Open function
2213 * @dev: Pointer to net_device structure
2214 *
2215 * This is called in response to ifconfig up
2216 *
2217 * Return: 0 for success; non-zero for failure
2218 */
2219static int __hdd_mon_open(struct net_device *dev)
2220{
2221 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002222 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2223 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002224
Dustin Brownfdf17c12018-03-14 12:55:34 -07002225 hdd_enter_dev(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002226
2227 ret = wlan_hdd_validate_context(hdd_ctx);
2228 if (ret)
2229 return ret;
2230
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302231 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002232
2233 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Browne7e71d32018-05-11 16:00:08 -07002234 ret = hdd_wlan_start_modules(hdd_ctx, false);
Ravi Joshia307f632017-07-17 23:41:41 -07002235 if (ret) {
2236 hdd_err("Failed to start WLAN modules return");
2237 return ret;
2238 }
2239 hdd_err("hdd_wlan_start_modules() successful !");
2240
2241 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2242 ret = hdd_start_adapter(adapter);
2243 if (ret) {
2244 hdd_err("Failed to start adapter :%d",
2245 adapter->device_mode);
2246 return ret;
2247 }
2248 hdd_err("hdd_start_adapters() successful !");
2249 }
2250 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2251 }
2252
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002253 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002254
2255 if (!ret)
2256 ret = hdd_enable_monitor_mode(dev);
2257
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002258 return ret;
2259}
2260
2261/**
2262 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2263 * @dev: Pointer to net_device structure
2264 *
2265 * This is called in response to ifconfig up
2266 *
2267 * Return: 0 for success; non-zero for failure
2268 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002269static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002270{
2271 int ret;
2272
2273 cds_ssr_protect(__func__);
2274 ret = __hdd_mon_open(dev);
2275 cds_ssr_unprotect(__func__);
2276
2277 return ret;
2278}
Nirav Shah73713f72018-05-17 14:50:41 +05302279#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002280
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002281static QDF_STATUS
2282wlan_hdd_update_dbs_scan_and_fw_mode_config(void)
2283{
2284 struct policy_mgr_dual_mac_config cfg = {0};
2285 QDF_STATUS status;
2286 uint32_t channel_select_logic_conc;
2287 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2288
2289 if (!hdd_ctx) {
2290 hdd_err("HDD context is NULL");
2291 return QDF_STATUS_E_FAILURE;
2292 }
2293
2294
2295 if (!policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc))
2296 return QDF_STATUS_SUCCESS;
2297
2298 cfg.scan_config = 0;
2299 cfg.fw_mode_config = 0;
2300 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
2301
2302 channel_select_logic_conc = hdd_ctx->config->
2303 channel_select_logic_conc;
2304
2305 if (hdd_ctx->config->dual_mac_feature_disable !=
2306 DISABLE_DBS_CXN_AND_SCAN) {
2307 status = policy_mgr_get_updated_scan_and_fw_mode_config(
2308 hdd_ctx->hdd_psoc, &cfg.scan_config,
2309 &cfg.fw_mode_config,
2310 hdd_ctx->config->dual_mac_feature_disable,
2311 channel_select_logic_conc);
2312
2313 if (status != QDF_STATUS_SUCCESS) {
2314 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
2315 status);
2316 return status;
2317 }
2318 }
2319
2320 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
2321 cfg.scan_config, cfg.fw_mode_config);
2322
2323 status = sme_soc_set_dual_mac_config(cfg);
2324 if (status != QDF_STATUS_SUCCESS) {
2325 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
2326 return status;
2327 }
2328
2329 return QDF_STATUS_SUCCESS;
2330}
2331
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002332/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302333 * hdd_start_adapter() - Wrapper function for device specific adapter
2334 * @adapter: pointer to HDD adapter
2335 *
2336 * This function is called to start the device specific adapter for
2337 * the mode passed in the adapter's device_mode.
2338 *
2339 * Return: 0 for success; non-zero for failure
2340 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002341int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302342{
2343
2344 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002345 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302346
Dustin Brownfdf17c12018-03-14 12:55:34 -07002347 hdd_enter_dev(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002348 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302349
2350 switch (device_mode) {
2351 case QDF_P2P_CLIENT_MODE:
2352 case QDF_P2P_DEVICE_MODE:
2353 case QDF_OCB_MODE:
2354 case QDF_STA_MODE:
2355 case QDF_MONITOR_MODE:
2356 ret = hdd_start_station_adapter(adapter);
2357 if (ret)
2358 goto err_start_adapter;
2359 break;
2360 case QDF_P2P_GO_MODE:
2361 case QDF_SAP_MODE:
2362 ret = hdd_start_ap_adapter(adapter);
2363 if (ret)
2364 goto err_start_adapter;
2365 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302366 case QDF_IBSS_MODE:
2367 /*
2368 * For IBSS interface is initialized as part of
2369 * hdd_init_station_mode()
2370 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002371 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302372 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002373 /* vdevs are dynamically managed by firmware in FTM */
2374 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302375 default:
2376 hdd_err("Invalid session type %d", device_mode);
2377 QDF_ASSERT(0);
2378 goto err_start_adapter;
2379 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002380
Arun Khandavallifae92942016-08-01 13:31:08 +05302381 if (hdd_set_fw_params(adapter))
2382 hdd_err("Failed to set the FW params for the adapter!");
2383
Dustin Browne7e71d32018-05-11 16:00:08 -07002384 if (adapter->session_id != HDD_SESSION_ID_INVALID) {
2385 ret = wlan_hdd_cfg80211_register_frames(adapter);
2386 if (ret < 0) {
2387 hdd_err("Failed to register frames - ret %d", ret);
2388 goto err_start_adapter;
2389 }
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302390 }
Dustin Browne7e71d32018-05-11 16:00:08 -07002391
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002392 wlan_hdd_update_dbs_scan_and_fw_mode_config();
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302393
Dustin Browndb2a8be2017-12-20 11:49:56 -08002394exit_with_success:
Dustin Browne74003f2018-03-14 12:51:58 -07002395 hdd_exit();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002396
Arun Khandavallifae92942016-08-01 13:31:08 +05302397 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002398
Arun Khandavallifae92942016-08-01 13:31:08 +05302399err_start_adapter:
2400 return -EINVAL;
2401}
2402
2403/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302404 * hdd_enable_power_management() - API to Enable Power Management
2405 *
2406 * API invokes Bus Interface Layer power management functionality
2407 *
2408 * Return: None
2409 */
2410static void hdd_enable_power_management(void)
2411{
2412 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2413
2414 if (!hif_ctx) {
2415 hdd_err("Bus Interface Context is Invalid");
2416 return;
2417 }
2418
2419 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2420}
2421
2422/**
2423 * hdd_disable_power_management() - API to disable Power Management
2424 *
2425 * API disable Bus Interface Layer Power management functionality
2426 *
2427 * Return: None
2428 */
2429static void hdd_disable_power_management(void)
2430{
2431 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2432
2433 if (!hif_ctx) {
2434 hdd_err("Bus Interface Context is Invalid");
2435 return;
2436 }
2437
2438 hif_disable_power_management(hif_ctx);
2439}
2440
Ryan Hsuaadba072018-04-20 13:01:53 -07002441void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302442{
2443 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002444 size_t target_hw_name_len;
2445 const char *target_hw_name;
Ryan Hsuaadba072018-04-20 13:01:53 -07002446 uint8_t *buf;
2447 uint32_t buf_len;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302448
2449 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2450 if (!hif_sc) {
2451 hdd_err("HIF context is NULL");
2452 return;
2453 }
2454
Ryan Hsuaadba072018-04-20 13:01:53 -07002455 hif_get_hw_info(hif_sc, &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302456 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002457 &target_hw_name);
2458
2459 if (hdd_ctx->target_hw_name)
2460 qdf_mem_free(hdd_ctx->target_hw_name);
2461
2462 target_hw_name_len = strlen(target_hw_name) + 1;
2463 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2464 if (hdd_ctx->target_hw_name)
2465 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2466 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302467
Ryan Hsuaadba072018-04-20 13:01:53 -07002468 buf = qdf_mem_malloc(WE_MAX_STR_LEN);
2469 if (buf) {
2470 buf_len = hdd_wlan_get_version(hdd_ctx, WE_MAX_STR_LEN, buf);
2471 hdd_info("%s", buf);
2472 qdf_mem_free(buf);
2473 }
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302474}
2475
2476/**
gbian62edd7e2017-03-07 13:12:13 +08002477 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2478 * @hdd_ctx: Pointer to hdd context
2479 *
2480 * Return: none
2481 */
2482static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002483hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002484{
2485 uint8_t num_entries = 0;
2486 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2487 uint8_t *tx_sched_wrr_ac;
2488 int i;
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002489 struct cds_context *cds_ctx;
gbian62edd7e2017-03-07 13:12:13 +08002490
2491 if (NULL == hdd_ctx)
2492 return;
2493
2494 if (NULL == hdd_ctx->config) {
2495 /* Do nothing if hdd_ctx is invalid */
2496 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2497 return;
2498 }
2499
2500 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2501
2502 if (!cds_ctx) {
2503 hdd_err("Invalid CDS Context");
2504 return;
2505 }
2506
2507 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2508 switch (i) {
2509 case OL_TX_WMM_AC_BE:
2510 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2511 break;
2512 case OL_TX_WMM_AC_BK:
2513 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2514 break;
2515 case OL_TX_WMM_AC_VI:
2516 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2517 break;
2518 case OL_TX_WMM_AC_VO:
2519 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2520 break;
2521 default:
2522 tx_sched_wrr_ac = NULL;
2523 break;
2524 }
2525
2526 hdd_string_to_u8_array(tx_sched_wrr_ac,
2527 tx_sched_wrr_param,
2528 &num_entries,
2529 sizeof(tx_sched_wrr_param));
2530
2531 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2532 cds_ctx->ac_specs[i].wrr_skip_weight =
2533 tx_sched_wrr_param[0];
2534 cds_ctx->ac_specs[i].credit_threshold =
2535 tx_sched_wrr_param[1];
2536 cds_ctx->ac_specs[i].send_limit =
2537 tx_sched_wrr_param[2];
2538 cds_ctx->ac_specs[i].credit_reserve =
2539 tx_sched_wrr_param[3];
2540 cds_ctx->ac_specs[i].discard_weight =
2541 tx_sched_wrr_param[4];
2542 }
2543
2544 num_entries = 0;
2545 }
2546}
2547
Ryan Hsuaadba072018-04-20 13:01:53 -07002548uint32_t hdd_wlan_get_version(struct hdd_context *hdd_ctx,
2549 const size_t version_len, uint8_t *version)
2550{
2551 uint32_t size;
2552 uint32_t msp_id = 0, mspid = 0, siid = 0, crmid = 0, sub_id = 0;
2553
2554 if (!hdd_ctx) {
2555 hdd_err("Invalid context, HDD context is null");
2556 return 0;
2557 }
2558
Ashish Kumar Dhanotiya7353f882018-05-15 12:50:19 +05302559 if (!version || version_len == 0) {
Ryan Hsuaadba072018-04-20 13:01:53 -07002560 hdd_err("Invalid buffer pointr or buffer len\n");
2561 return 0;
2562 }
2563
2564 msp_id = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
2565 mspid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
2566 siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
2567 crmid = hdd_ctx->target_fw_version & 0x7fff;
2568 sub_id = (hdd_ctx->target_fw_vers_ext & 0xf0000000) >> 28;
2569
2570 size = scnprintf(version, version_len,
Ryan Hsuc6918552018-05-16 13:29:59 -07002571 "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 -07002572 QWLAN_VERSIONSTR,
2573 msp_id, mspid, siid, crmid, sub_id,
Ryan Hsuc6918552018-05-16 13:29:59 -07002574 hdd_ctx->target_hw_name,
2575 hdd_ctx->hw_bd_info.bdf_version,
2576 hdd_ctx->hw_bd_info.ref_design_id,
2577 hdd_ctx->hw_bd_info.customer_id,
2578 hdd_ctx->hw_bd_info.project_id,
2579 hdd_ctx->hw_bd_info.board_data_rev);
Ryan Hsuaadba072018-04-20 13:01:53 -07002580
2581 return size;
2582}
2583
Rachit Kankane0dc3e852018-05-07 17:33:42 +05302584int hdd_set_11ax_rate(struct hdd_adapter *adapter, int set_value,
2585 struct sap_config *sap_config)
2586{
2587 uint8_t preamble = 0, nss = 0, rix = 0;
2588 int ret;
2589 mac_handle_t mac_handle = adapter->hdd_ctx->mac_handle;
2590
2591 if (!sap_config) {
2592 if (!sme_is_feature_supported_by_fw(DOT11AX)) {
2593 hdd_err("Target does not support 11ax");
2594 return -EIO;
2595 }
2596 } else if (sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax &&
2597 sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax_ONLY) {
2598 hdd_err("Invalid hw mode, SAP hw_mode= 0x%x, ch = %d",
2599 sap_config->SapHw_mode, sap_config->channel);
2600 return -EIO;
2601 }
2602
2603 if (set_value != 0xff) {
2604 rix = RC_2_RATE_IDX_11AX(set_value);
2605 preamble = WMI_RATE_PREAMBLE_HE;
2606 nss = HT_RC_2_STREAMS_11AX(set_value);
2607
2608 set_value = hdd_assemble_rate_code(preamble, nss, rix);
2609 } else {
2610 ret = sme_set_auto_rate_he_ltf(mac_handle, adapter->session_id,
2611 QCA_WLAN_HE_LTF_AUTO);
2612 }
2613
2614 hdd_info("SET_11AX_RATE val %d rix %d preamble %x nss %d",
2615 set_value, rix, preamble, nss);
2616
2617 ret = wma_cli_set_command(adapter->session_id,
2618 WMI_VDEV_PARAM_FIXED_RATE,
2619 set_value, VDEV_CMD);
2620
2621 return ret;
2622}
2623
2624int hdd_assemble_rate_code(uint8_t preamble, uint8_t nss, uint8_t rate)
2625{
2626 int set_value;
2627
2628 if (sme_is_feature_supported_by_fw(DOT11AX))
2629 set_value = WMI_ASSEMBLE_RATECODE_V1(rate, nss, preamble);
2630 else
2631 set_value = (preamble << 6) | (nss << 4) | rate;
2632
2633 return set_value;
2634}
2635
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302636#ifdef IPA_OFFLOAD
2637/**
2638 * hdd_update_ipa_component_config() - update ipa config
2639 * @hdd_ctx: Pointer to hdd context
2640 *
2641 * Return: none
2642 */
2643static void hdd_update_ipa_component_config(struct hdd_context *hdd_ctx)
2644{
2645 struct hdd_config *cfg = hdd_ctx->config;
2646 struct wlan_ipa_config ipa_cfg;
2647
2648 ipa_cfg.ipa_config = cfg->IpaConfig;
2649 ipa_cfg.desc_size = cfg->IpaDescSize;
2650 ipa_cfg.txbuf_count = cfg->IpaUcTxBufCount;
2651 ipa_cfg.bus_bw_high = cfg->busBandwidthHighThreshold;
2652 ipa_cfg.bus_bw_medium = cfg->busBandwidthMediumThreshold;
2653 ipa_cfg.bus_bw_low = cfg->busBandwidthLowThreshold;
2654 ipa_cfg.ipa_bw_high = cfg->IpaHighBandwidthMbps;
2655 ipa_cfg.ipa_bw_medium = cfg->IpaMediumBandwidthMbps;
2656 ipa_cfg.ipa_bw_low = cfg->IpaLowBandwidthMbps;
2657
2658 ucfg_ipa_update_config(&ipa_cfg);
2659}
2660#else
2661static void hdd_update_ipa_component_config(struct hdd_context *hdd_ctx)
2662{
2663}
2664#endif
2665
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002666#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002667static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2668 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2669{
Jeff Johnson9d295242017-08-29 14:39:48 -07002670 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002671 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002672
2673 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2674 if (!adapter) {
2675 hdd_err("Adapter is NULL");
2676 return PM_MAX_NUM_OF_MODE;
2677 }
2678
2679 return policy_mgr_convert_device_mode_to_qdf_type(
2680 adapter->device_mode);
2681}
2682
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002683static void hdd_register_policy_manager_callback(
2684 struct wlan_objmgr_psoc *psoc)
2685{
2686 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002687
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002688 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002689 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002690 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2691 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002692 hdd_cbacks.get_mode_for_non_connected_vdev =
2693 wlan_hdd_get_mode_for_non_connected_vdev;
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05302694 hdd_cbacks.hdd_get_device_mode = hdd_get_device_mode;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002695
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002696 if (QDF_STATUS_SUCCESS !=
2697 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2698 hdd_err("HDD callback registration with policy manager failed");
2699 }
2700}
2701#else
2702static void hdd_register_policy_manager_callback(
2703 struct wlan_objmgr_psoc *psoc)
2704{
2705}
2706#endif
2707
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002708static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002709{
2710 struct nan_callbacks cb_obj = {0};
2711
2712 cb_obj.ndi_open = hdd_ndi_open;
2713 cb_obj.ndi_close = hdd_ndi_close;
2714 cb_obj.ndi_start = hdd_ndi_start;
2715 cb_obj.ndi_delete = hdd_ndi_delete;
2716 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2717 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2718
Naveen Rawat37f62c82017-03-26 22:24:43 -07002719 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2720 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002721 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002722
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002723 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2724}
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002725
Dustin Brown26b3d042017-12-21 11:13:27 -08002726#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002727/**
2728 * hdd_check_for_leaks() - Perform runtime memory leak checks
Dustin Browna6246dd2018-05-24 14:35:58 -07002729 * @hdd_ctx: the global HDD context
Dustin Brown4c5b9902017-12-19 11:17:19 -08002730 *
2731 * This API triggers runtime memory leak detection. This feature enforces the
2732 * policy that any memory allocated at runtime must also be released at runtime.
2733 *
2734 * Allocating memory at runtime and releasing it at unload is effectively a
2735 * memory leak for configurations which never unload (e.g. LONU, statically
2736 * compiled driver). Such memory leaks are NOT false positives, and must be
2737 * fixed.
2738 *
2739 * Return: None
2740 */
Dustin Browna6246dd2018-05-24 14:35:58 -07002741static void hdd_check_for_leaks(struct hdd_context *hdd_ctx)
Dustin Brown4bc0a622017-12-06 15:56:50 -08002742{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002743 /* DO NOT REMOVE these checks; for false positives, read above first */
2744
Dustin Browna6246dd2018-05-24 14:35:58 -07002745 wlan_objmgr_psoc_check_for_vdev_leaks(hdd_ctx->hdd_psoc);
Dustin Brown29462962018-06-18 14:02:00 -07002746 wlan_objmgr_psoc_check_for_pdev_leaks(hdd_ctx->hdd_psoc);
Dustin Brown677e0862017-10-10 16:30:09 -07002747 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002748 qdf_nbuf_map_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002749 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002750}
2751
Dustin Brown26b3d042017-12-21 11:13:27 -08002752#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2753#else
Dustin Browna6246dd2018-05-24 14:35:58 -07002754static inline void hdd_check_for_leaks(struct hdd_context *hdd_ctx) { }
Dustin Brown26b3d042017-12-21 11:13:27 -08002755
2756#define hdd_debug_domain_set(domain)
2757#endif /* CONFIG_LEAK_DETECTION */
2758
gbian62edd7e2017-03-07 13:12:13 +08002759/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002760 * hdd_update_country_code - Update country code
2761 * @hdd_ctx: HDD context
2762 *
2763 * Update country code based on module parameter country_code
2764 *
2765 * Return: 0 on success and errno on failure
2766 */
2767static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2768{
2769 if (!country_code)
2770 return 0;
2771
2772 return hdd_reg_set_country(hdd_ctx, country_code);
2773}
2774
2775/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302776 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2777 * @hdd_ctx: HDD context
Arun Khandavallifae92942016-08-01 13:31:08 +05302778 * @reinit: flag to indicate from SSR or normal path
2779 *
2780 * This function maintains the driver state machine it will be invoked from
2781 * startup, reinit and change interface. Depending on the driver state shall
2782 * perform the opening of the modules.
2783 *
2784 * Return: 0 for success; non-zero for failure
2785 */
Dustin Browne7e71d32018-05-11 16:00:08 -07002786int hdd_wlan_start_modules(struct hdd_context *hdd_ctx, bool reinit)
Arun Khandavallifae92942016-08-01 13:31:08 +05302787{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002788 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302789 qdf_device_t qdf_dev;
2790 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302791 bool unint = false;
2792 void *hif_ctx;
Jingxiang Ge95912f82018-04-19 12:01:26 +08002793 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +05302794
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002795 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302796
2797 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2798 if (!qdf_dev) {
2799 hdd_err("QDF Device Context is Invalid return");
2800 return -EINVAL;
2801 }
2802
Dustin Brown6f427922017-09-19 12:19:00 -07002803 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05302804
Dustin Brown1fe30a82017-10-03 16:13:36 -07002805 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302806 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2807 mutex_unlock(&hdd_ctx->iface_change_lock);
2808 hdd_info("Driver modules already Enabled");
Dustin Browne74003f2018-03-14 12:51:58 -07002809 hdd_exit();
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302810 return 0;
2811 }
2812
Dustin Brown1fe30a82017-10-03 16:13:36 -07002813 hdd_ctx->start_modules_in_progress = true;
2814
Arun Khandavallifae92942016-08-01 13:31:08 +05302815 switch (hdd_ctx->driver_status) {
2816 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002817 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302818 unint = true;
2819 /* Fall through dont add break here */
2820 case DRIVER_MODULES_CLOSED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002821 hdd_info("Wlan transitioning (CLOSED -> OPENED)");
2822
Dustin Brown26b3d042017-12-21 11:13:27 -08002823 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002824
Arun Khandavallifae92942016-08-01 13:31:08 +05302825 if (!reinit && !unint) {
2826 ret = pld_power_on(qdf_dev->dev);
2827 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002828 hdd_err("Failed to Powerup the device; errno: %d",
2829 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302830 goto release_lock;
2831 }
2832 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002833
2834 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2835 hdd_ctx->config->enable_fw_log);
Arun Khandavallifae92942016-08-01 13:31:08 +05302836 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2837 qdf_dev->bus_type,
2838 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2839 HIF_ENABLE_TYPE_PROBE);
2840 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002841 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302842 goto power_down;
2843 }
2844
2845 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302846 if (!hif_ctx) {
2847 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002848 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302849 goto power_down;
2850 }
2851
Arun Khandavallifae92942016-08-01 13:31:08 +05302852 status = ol_cds_init(qdf_dev, hif_ctx);
2853 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002854 hdd_err("No Memory to Create BMI Context; status: %d",
2855 status);
2856 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302857 goto hif_close;
2858 }
2859
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302860 hdd_update_ipa_component_config(hdd_ctx);
2861
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002862 ret = hdd_update_config(hdd_ctx);
2863 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002864 hdd_err("Failed to update configuration; errno: %d",
2865 ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002866 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002867 }
2868
gbian62edd7e2017-03-07 13:12:13 +08002869 hdd_update_cds_ac_specs_params(hdd_ctx);
2870
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302871 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002872 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002873 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002874 ret = qdf_status_to_os_return(status);
2875 goto deinit_config;
Arun Khandavallifae92942016-08-01 13:31:08 +05302876 }
2877
Manjunathappa Prakashb6b4ff12018-06-04 12:32:33 -07002878 if (hdd_ctx->config->rx_thread_affinity_mask)
2879 cds_set_rx_thread_cpu_mask(
2880 hdd_ctx->config->rx_thread_affinity_mask);
2881
2882 /* initialize components configurations after psoc open */
Mukul Sharma9d797a02017-01-05 20:26:03 +05302883 ret = hdd_update_components_config(hdd_ctx);
2884 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002885 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302886 ret);
2887 goto close;
2888 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002889 status = cds_dp_open(hdd_ctx->hdd_psoc);
2890 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002891 hdd_err("Failed to Open cds post open; status: %d",
2892 status);
2893 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002894 goto close;
2895 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302896
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002897 /*
2898 * NAN compoenet requires certian operations like, open adapter,
2899 * close adapter, etc. to be initiated by HDD, for those
2900 * register HDD callbacks with UMAC's NAN componenet.
2901 */
2902 hdd_nan_register_callbacks(hdd_ctx);
2903
Jeff Johnson16528362018-06-14 12:34:16 -07002904 hdd_ctx->mac_handle = cds_get_context(QDF_MODULE_ID_SME);
Arun Khandavallifae92942016-08-01 13:31:08 +05302905
Jeff Johnson3a280122017-09-13 07:42:00 -07002906 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302907 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002908 hdd_err("Failed to pre-enable CDS; status: %d", status);
2909 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002910 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302911 }
2912
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002913 hdd_register_policy_manager_callback(
2914 hdd_ctx->hdd_psoc);
2915
Amar Singhal0928b192017-12-01 10:50:54 -08002916 hdd_sysfs_create_version_interface(hdd_ctx->hdd_psoc);
2917
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302918 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302919 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002920 hdd_info("Wlan transitioned (now OPENED)");
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302921
Arun Khandavallifae92942016-08-01 13:31:08 +05302922 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002923 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302924 break;
2925 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302926
Arun Khandavallifae92942016-08-01 13:31:08 +05302927 /* Fall through dont add break here */
2928 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002929 hdd_info("Wlan transitioning (OPENED -> ENABLED)");
2930
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302931 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2932 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002933 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302934 break;
2935 }
Dustin Browndca39692017-11-09 15:30:25 -08002936
Dustin Browne7e71d32018-05-11 16:00:08 -07002937 ret = hdd_configure_cds(hdd_ctx);
Dustin Browndca39692017-11-09 15:30:25 -08002938 if (ret) {
2939 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002940 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302941 }
Dustin Browndca39692017-11-09 15:30:25 -08002942
Komal Seelamf2136bb2016-09-28 18:30:44 +05302943 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002944
Arun Khandavallifae92942016-08-01 13:31:08 +05302945 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002946 hdd_info("Wlan transitioned (now ENABLED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302947 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002948
Arun Khandavallifae92942016-08-01 13:31:08 +05302949 default:
2950 hdd_err("WLAN start invoked in wrong state! :%d\n",
2951 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002952 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302953 goto release_lock;
2954 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002955
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302956 hdd_ctx->start_modules_in_progress = false;
Paul Zhange03cf4c2018-01-19 18:33:22 +08002957 if (DRIVER_MODULES_ENABLED == hdd_ctx->driver_status) {
2958 ret = hdd_update_country_code(hdd_ctx);
2959 if (ret)
2960 hdd_err("Failed to update command line country code!");
2961 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302962 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002963
Dustin Browne74003f2018-03-14 12:51:58 -07002964 hdd_exit();
Dustin Brown550f6d22017-12-14 15:44:01 -08002965
Arun Khandavallifae92942016-08-01 13:31:08 +05302966 return 0;
2967
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002968post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002969 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002970
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002971cds_txrx_free:
Jingxiang Ge95912f82018-04-19 12:01:26 +08002972 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
2973
2974 if (tgt_hdl && target_psoc_get_wmi_ready(tgt_hdl)) {
2975 hdd_runtime_suspend_context_deinit(hdd_ctx);
2976 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
2977 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
2978 }
2979
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002980 cds_dp_close(hdd_ctx->hdd_psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08002981
Arun Khandavallifae92942016-08-01 13:31:08 +05302982close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002983 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002984 hdd_info("Wlan transition aborted (now CLOSED)");
2985
Jeff Johnsone4b14592017-09-13 14:23:33 -07002986 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302987
Dustin Brown28b17892017-10-10 13:29:38 -07002988deinit_config:
2989 cds_deinit_ini_config();
2990
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002991cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302992 ol_cds_free();
2993
2994hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002995 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2996 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302997power_down:
2998 if (!reinit && !unint)
2999 pld_power_off(qdf_dev->dev);
3000release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05303001 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05303002 mutex_unlock(&hdd_ctx->iface_change_lock);
Abhinav Kumar7ae9b7b2017-12-19 15:11:54 +05303003 if (hdd_ctx->target_hw_name) {
3004 qdf_mem_free(hdd_ctx->target_hw_name);
3005 hdd_ctx->target_hw_name = NULL;
3006 }
Dustin Brown4bc0a622017-12-06 15:56:50 -08003007 /* many adapter resources are not freed by design in SSR case */
3008 if (!reinit)
Dustin Browna6246dd2018-05-24 14:35:58 -07003009 hdd_check_for_leaks(hdd_ctx);
Dustin Brown26b3d042017-12-21 11:13:27 -08003010 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08003011
Dustin Browne74003f2018-03-14 12:51:58 -07003012 hdd_exit();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08003013
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07003014 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05303015}
3016
Naveen Rawat910726a2017-03-06 11:42:51 -08003017#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003018static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003019{
3020 int ret = os_if_wifi_pos_register_nl();
3021
3022 if (ret)
3023 hdd_err("os_if_wifi_pos_register_nl failed");
3024
3025 return ret;
3026}
3027
3028static int hdd_deactivate_wifi_pos(void)
3029{
3030 int ret = os_if_wifi_pos_deregister_nl();
3031
3032 if (ret)
3033 hdd_err("os_if_wifi_pos_deregister_nl failed");
3034
3035 return ret;
3036}
3037
3038/**
3039 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
3040 * @hdd_ctx: hdd context
3041 *
3042 * Return: status of operation
3043 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003044static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003045{
3046 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3047 struct hdd_config *cfg = hdd_ctx->config;
3048
3049 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
3050 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
3051 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
3052 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
3053 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
3054 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
3055 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
3056 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
3057}
3058#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003059static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003060{
3061 return oem_activate_service(hdd_ctx);
3062}
3063
3064static int hdd_deactivate_wifi_pos(void)
3065{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05303066 return oem_deactivate_service();
Naveen Rawat910726a2017-03-06 11:42:51 -08003067}
3068
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003069static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003070{
3071}
3072#endif
3073
Arun Khandavallifae92942016-08-01 13:31:08 +05303074/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003075 * __hdd_open() - HDD Open function
3076 * @dev: Pointer to net_device structure
3077 *
3078 * This is called in response to ifconfig up
3079 *
3080 * Return: 0 for success; non-zero for failure
3081 */
3082static int __hdd_open(struct net_device *dev)
3083{
Jeff Johnson9d295242017-08-29 14:39:48 -07003084 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003085 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003086 int ret;
3087
Dustin Brownfdf17c12018-03-14 12:55:34 -07003088 hdd_enter_dev(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303089 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003090 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003091
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05303092 /* Nothing to be done if device is unloading */
3093 if (cds_is_driver_unloading()) {
3094 hdd_err("Driver is unloading can not open the hdd");
3095 return -EBUSY;
3096 }
3097
Dustin Brown01847752017-10-25 13:56:27 -07003098 if (cds_is_driver_recovering()) {
3099 hdd_err("WLAN is currently recovering; Please try again.");
3100 return -EBUSY;
3101 }
3102
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05303103 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
3104 hdd_err("con_mode_handler is in progress; Please try again.");
3105 return -EBUSY;
3106 }
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303107
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05303108 mutex_lock(&hdd_init_deinit_lock);
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05303109 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
3110
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303111 /*
3112 * This scenario can be hit in cases where in the wlan driver after
3113 * registering the netdevices and there is a failure in driver
3114 * initialization. So return error gracefully because the netdevices
3115 * will be de-registered as part of the load failure.
3116 */
3117
3118 if (!cds_is_driver_loaded()) {
3119 hdd_err("Failed to start the wlan driver!!");
3120 ret = -EIO;
3121 goto err_hdd_hdd_init_deinit_lock;
3122 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303123
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003124
Dustin Browne7e71d32018-05-11 16:00:08 -07003125 ret = hdd_wlan_start_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05303126 if (ret) {
3127 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303128 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05303129 }
3130
3131
3132 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3133 ret = hdd_start_adapter(adapter);
3134 if (ret) {
3135 hdd_err("Failed to start adapter :%d",
3136 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303137 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05303138 }
3139 }
3140
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003141 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3142 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003143 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003144 /* Enable TX queues only when we are connected */
3145 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05303146 WLAN_START_ALL_NETIF_QUEUE,
3147 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003148 }
3149
Naveen Rawat286def52016-09-23 15:38:02 -07003150 /* Enable carrier and transmit queues for NDI */
3151 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003152 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07003153 wlan_hdd_netif_queue_control(adapter,
3154 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
3155 WLAN_CONTROL_PATH);
3156 }
3157
Naveen Rawat910726a2017-03-06 11:42:51 -08003158 hdd_populate_wifi_pos_cfg(hdd_ctx);
3159
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303160err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05303161 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303162 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003163 return ret;
3164}
3165
Arun Khandavallifae92942016-08-01 13:31:08 +05303166
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003167/**
3168 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
3169 * @dev: Pointer to net_device structure
3170 *
3171 * This is called in response to ifconfig up
3172 *
3173 * Return: 0 for success; non-zero for failure
3174 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003175static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003176{
3177 int ret;
3178
3179 cds_ssr_protect(__func__);
3180 ret = __hdd_open(dev);
3181 cds_ssr_unprotect(__func__);
3182
3183 return ret;
3184}
3185
3186/**
3187 * __hdd_stop() - HDD stop function
3188 * @dev: Pointer to net_device structure
3189 *
3190 * This is called in response to ifconfig down
3191 *
3192 * Return: 0 for success; non-zero for failure
3193 */
3194static int __hdd_stop(struct net_device *dev)
3195{
Jeff Johnson9d295242017-08-29 14:39:48 -07003196 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003197 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003198 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -07003199 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003200
Dustin Brownfdf17c12018-03-14 12:55:34 -07003201 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003202
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303203 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003204 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003205
3206 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303207 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003208 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003209
3210 /* Nothing to be done if the interface is not opened */
3211 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003212 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003213 return -ENODEV;
3214 }
3215
3216 /* Make sure the interface is marked as closed */
3217 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303218
Jeff Johnson16528362018-06-14 12:34:16 -07003219 mac_handle = hdd_ctx->mac_handle;
3220
Mukul Sharmad16c2022017-07-25 18:56:12 +05303221 hdd_debug("Disabling Auto Power save timer");
3222 sme_ps_disable_auto_ps_timer(
Jeff Johnson16528362018-06-14 12:34:16 -07003223 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003224 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303225
3226 /*
3227 * Disable TX on the interface, after this hard_start_xmit() will not
3228 * be called on that interface
3229 */
Dustin Brown5e89ef82018-03-14 11:50:23 -07003230 hdd_info("Disabling queues, adapter device mode: %s(%d)",
Kabilan Kannan8dac3502017-10-30 12:40:27 -07003231 hdd_device_mode_to_string(adapter->device_mode),
3232 adapter->device_mode);
3233
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303234 wlan_hdd_netif_queue_control(adapter,
3235 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3236 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003237
3238 /*
Naveen Rawat286def52016-09-23 15:38:02 -07003239 * NAN data interface is different in some sense. The traffic on NDI is
3240 * bursty in nature and depends on the need to transfer. The service
3241 * layer may down the interface after the usage and up again when
3242 * required. In some sense, the NDI is expected to be available
3243 * (like SAP) iface until NDI delete request is issued by the service
3244 * layer. Skip BSS termination and adapter deletion for NAN Data
3245 * interface (NDI).
3246 */
3247 if (WLAN_HDD_IS_NDI(adapter))
3248 return 0;
3249
3250 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003251 * The interface is marked as down for outside world (aka kernel)
3252 * But the driver is pretty much alive inside. The driver needs to
3253 * tear down the existing connection on the netdev (session)
3254 * cleanup the data pipes and wait until the control plane is stabilized
3255 * for this interface. The call also needs to wait until the above
3256 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003257 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003258 * That is intentional to be able to scan if it is a STA/P2P interface
3259 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08003260 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003261
3262 /* DeInit the adapter. This ensures datapath cleanup as well */
3263 hdd_deinit_adapter(hdd_ctx, adapter, true);
3264
Arun Khandavallifae92942016-08-01 13:31:08 +05303265
3266 /*
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +05303267 * Upon wifi turn off, DUT has to flush the scan results so if
3268 * this is the last cli iface, flush the scan database.
3269 */
3270 if (!hdd_is_cli_iface_up(hdd_ctx))
Jeff Johnson16528362018-06-14 12:34:16 -07003271 sme_scan_flush_result(mac_handle);
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +05303272
3273 /*
Arun Khandavallifae92942016-08-01 13:31:08 +05303274 * Find if any iface is up. If any iface is up then can't put device to
3275 * sleep/power save mode
3276 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05303277 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003278 hdd_debug("Closing all modules from the hdd_stop");
Dustin Brown6f427922017-09-19 12:19:00 -07003279 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
3280 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05303281 hdd_prevent_suspend_timeout(
3282 hdd_ctx->config->iface_change_wait_time,
3283 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05303284 }
3285
Dustin Browne74003f2018-03-14 12:51:58 -07003286 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003287 return 0;
3288}
3289
3290/**
3291 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3292 * @dev: pointer to net_device structure
3293 *
3294 * This is called in response to ifconfig down
3295 *
3296 * Return: 0 for success and error number for failure
3297 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003298static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003299{
3300 int ret;
3301
3302 cds_ssr_protect(__func__);
3303 ret = __hdd_stop(dev);
3304 cds_ssr_unprotect(__func__);
3305
3306 return ret;
3307}
3308
3309/**
3310 * __hdd_uninit() - HDD uninit function
3311 * @dev: Pointer to net_device structure
3312 *
3313 * This is called during the netdev unregister to uninitialize all data
3314 * associated with the device
3315 *
3316 * Return: None
3317 */
3318static void __hdd_uninit(struct net_device *dev)
3319{
Jeff Johnson9d295242017-08-29 14:39:48 -07003320 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003321 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003322
Dustin Brownfdf17c12018-03-14 12:55:34 -07003323 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003324
3325 do {
3326 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003327 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003328 break;
3329 }
3330
Jeff Johnson399c6272017-08-30 10:51:00 -07003331 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3332 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003333 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003334 break;
3335 }
3336
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003337 if (dev != adapter->dev)
3338 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003339
Jeff Johnson399c6272017-08-30 10:51:00 -07003340 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003341
3342 /* after uninit our adapter structure will no longer be valid */
3343 adapter->dev = NULL;
3344 adapter->magic = 0;
3345 } while (0);
3346
Dustin Browne74003f2018-03-14 12:51:58 -07003347 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003348}
3349
3350/**
3351 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
3352 * @dev: pointer to net_device structure
3353 *
3354 * This is called during the netdev unregister to uninitialize all data
3355 * associated with the device
3356 *
3357 * Return: none
3358 */
3359static void hdd_uninit(struct net_device *dev)
3360{
3361 cds_ssr_protect(__func__);
3362 __hdd_uninit(dev);
3363 cds_ssr_unprotect(__func__);
3364}
3365
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003366static int hdd_open_cesium_nl_sock(void)
3367{
3368#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3369 struct netlink_kernel_cfg cfg = {
3370 .groups = WLAN_NLINK_MCAST_GRP_ID,
3371 .input = NULL
3372 };
3373#endif
3374 int ret = 0;
3375
3376#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3377 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3378#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3379 THIS_MODULE,
3380#endif
3381 &cfg);
3382#else
3383 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3384 WLAN_NLINK_MCAST_GRP_ID,
3385 NULL, NULL, THIS_MODULE);
3386#endif
3387
3388 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003389 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003390 ret = -ECONNREFUSED;
3391 }
3392
3393 return ret;
3394}
3395
3396static void hdd_close_cesium_nl_sock(void)
3397{
3398 if (NULL != cesium_nl_srv_sock) {
3399 netlink_kernel_release(cesium_nl_srv_sock);
3400 cesium_nl_srv_sock = NULL;
3401 }
3402}
3403
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003404/**
3405 * __hdd_set_mac_address() - set the user specified mac address
3406 * @dev: Pointer to the net device.
3407 * @addr: Pointer to the sockaddr.
3408 *
3409 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003410 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003411 *
3412 * Return: 0 for success, non zero for failure
3413 */
3414static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3415{
Jeff Johnson9d295242017-08-29 14:39:48 -07003416 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303417 struct hdd_adapter *adapter_temp;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003418 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003419 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303420 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003421 int ret;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303422 struct qdf_mac_addr mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003423
Dustin Brownfdf17c12018-03-14 12:55:34 -07003424 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003425
Hanumanth Reddy Pothula5c7a7812018-03-09 12:55:32 +05303426 if (netif_running(dev)) {
3427 hdd_err("On iface up, set mac address change isn't supported");
3428 return -EBUSY;
3429 }
3430
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003431 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3432 ret = wlan_hdd_validate_context(hdd_ctx);
3433 if (0 != ret)
3434 return ret;
3435
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303436 qdf_mem_copy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303437 adapter_temp = hdd_get_adapter_by_macaddr(hdd_ctx, mac_addr.bytes);
3438 if (adapter_temp) {
3439 if (!qdf_str_cmp(adapter_temp->dev->name, dev->name))
3440 return 0;
3441 hdd_err("%s adapter exist with same address " MAC_ADDRESS_STR,
3442 adapter_temp->dev->name,
Ashish Kumar Dhanotiyaf974f332018-04-19 16:03:15 +05303443 MAC_ADDR_ARRAY(mac_addr.bytes));
3444 return -EINVAL;
3445 }
3446
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303447 if (qdf_is_macaddr_zero(&mac_addr)) {
3448 hdd_err("MAC is all zero");
3449 return -EINVAL;
3450 }
3451
3452 if (qdf_is_macaddr_broadcast(&mac_addr)) {
3453 hdd_err("MAC is Broadcast");
3454 return -EINVAL;
3455 }
3456
3457 if (ETHER_IS_MULTICAST(psta_mac_addr->sa_data)) {
3458 hdd_err("MAC is Multicast");
3459 return -EINVAL;
3460 }
Ashish Kumar Dhanotiya8bfef122018-04-18 16:48:27 +05303461 hdd_info("Changing MAC to " MAC_ADDRESS_STR " of the interface %s ",
3462 MAC_ADDR_ARRAY(mac_addr.bytes), dev->name);
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303463
Jeff Johnson1e851a12017-10-28 14:36:12 -07003464 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003465 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3466
Dustin Browne74003f2018-03-14 12:51:58 -07003467 hdd_exit();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303468 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003469}
3470
3471/**
3472 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3473 * function from SSR
3474 * @dev: pointer to net_device structure
3475 * @addr: Pointer to the sockaddr
3476 *
3477 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003478 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003479 *
3480 * Return: 0 for success.
3481 */
3482static int hdd_set_mac_address(struct net_device *dev, void *addr)
3483{
3484 int ret;
3485
3486 cds_ssr_protect(__func__);
3487 ret = __hdd_set_mac_address(dev, addr);
3488 cds_ssr_unprotect(__func__);
3489
3490 return ret;
3491}
3492
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003493uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003494{
3495 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003496
Anurag Chouhan6d760662016-02-20 16:05:43 +05303497 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003498 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
3499 break;
3500 }
3501
Anurag Chouhan6d760662016-02-20 16:05:43 +05303502 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003503 return NULL;
3504
3505 hdd_ctx->config->intfAddrMask |= (1 << i);
3506 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
3507}
3508
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003509void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3510 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003511{
3512 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003513
Anurag Chouhan6d760662016-02-20 16:05:43 +05303514 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003515 if (!memcmp(releaseAddr,
3516 &hdd_ctx->config->intfMacAddr[i].bytes[0],
3517 6)) {
3518 hdd_ctx->config->intfAddrMask &= ~(1 << i);
3519 break;
3520 }
3521 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003522}
3523
3524#ifdef WLAN_FEATURE_PACKET_FILTERING
3525/**
3526 * __hdd_set_multicast_list() - set the multicast address list
3527 * @dev: Pointer to the WLAN device.
3528 * @skb: Pointer to OS packet (sk_buff).
3529 *
3530 * This funciton sets the multicast address list.
3531 *
3532 * Return: None
3533 */
3534static void __hdd_set_multicast_list(struct net_device *dev)
3535{
Jeff Johnson9d295242017-08-29 14:39:48 -07003536 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Dustin Brown0f874482018-06-13 14:39:22 -07003537 int i = 0, errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003538 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003539 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303540 struct pmo_mc_addr_list_params *mc_list_request = NULL;
3541 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3542 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003543
Dustin Brownfdf17c12018-03-14 12:55:34 -07003544 hdd_enter_dev(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303545 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303546 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303547
Dustin Brown0f874482018-06-13 14:39:22 -07003548 errno = wlan_hdd_validate_context(hdd_ctx);
3549 if (errno)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303550 goto out;
3551
Dustin Brown0f874482018-06-13 14:39:22 -07003552 errno = hdd_validate_adapter(adapter);
3553 if (errno)
Dustin Brownc788acb2017-08-01 17:43:51 -07003554 goto out;
3555
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303556 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3557 hdd_err("%s: Driver module is closed", __func__);
Dustin Brown0f874482018-06-13 14:39:22 -07003558 goto out;
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303559 }
3560
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303561 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
3562 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003563 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303564 goto out;
3565 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003566
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303567 /* Delete already configured multicast address list */
3568 if (adapter->mc_addr_list.mc_cnt > 0) {
Dustin Brown0f874482018-06-13 14:39:22 -07003569 hdd_debug("clear previously configured MC address list");
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303570 hdd_disable_and_flush_mc_addr_list(adapter,
3571 pmo_mc_list_change_notify);
3572 }
3573
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003574 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003575 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303576 hdd_disable_and_flush_mc_addr_list(adapter,
3577 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003578 } else {
3579 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303580 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003581 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Dustin Brown0f874482018-06-13 14:39:22 -07003582 pmo_ucfg_max_mc_addr_supported(psoc));
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303583 hdd_disable_and_flush_mc_addr_list(adapter,
3584 pmo_mc_list_change_notify);
Dustin Brown0f874482018-06-13 14:39:22 -07003585 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003586 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003587 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003588 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303589 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003590 if (i == mc_count)
3591 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303592 memset(&(mc_list_request->mc_addr[i].bytes),
3593 0, ETH_ALEN);
3594 memcpy(&(mc_list_request->mc_addr[i].bytes),
3595 ha->addr, ETH_ALEN);
Dustin Brown0f874482018-06-13 14:39:22 -07003596 hdd_debug("mlist[%d] = %pM", i,
3597 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003598 i++;
3599 }
3600 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303601
3602 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003603 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303604 mc_list_request->count = mc_count;
Dustin Brown0f874482018-06-13 14:39:22 -07003605
3606 errno = hdd_cache_mc_addr_list(mc_list_request);
3607 if (errno) {
3608 hdd_err("Failed to cache MC address list for vdev %u; errno:%d",
3609 adapter->session_id, errno);
3610 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003611 }
Dustin Brown0f874482018-06-13 14:39:22 -07003612
3613 hdd_enable_mc_addr_filtering(adapter, pmo_mc_list_change_notify);
3614
3615free_req:
3616 qdf_mem_free(mc_list_request);
3617
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303618out:
Dustin Browne74003f2018-03-14 12:51:58 -07003619 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003620}
3621
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303622
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003623/**
3624 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3625 * @dev: pointer to net_device
3626 *
3627 * Return: none
3628 */
3629static void hdd_set_multicast_list(struct net_device *dev)
3630{
3631 cds_ssr_protect(__func__);
3632 __hdd_set_multicast_list(dev);
3633 cds_ssr_unprotect(__func__);
3634}
3635#endif
3636
3637/**
3638 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3639 * @dev: Pointer to the WLAN device.
3640 * @skb: Pointer to OS packet (sk_buff).
3641 *
3642 * This function is registered with the Linux OS for network
3643 * core to decide which queue to use first.
3644 *
3645 * Return: ac, Queue Index/access category corresponding to UP in IP header
3646 */
3647static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3648#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3649 , void *accel_priv
3650#endif
3651#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3652 , select_queue_fallback_t fallback
3653#endif
3654)
3655{
3656 return hdd_wmm_select_queue(dev, skb);
3657}
3658
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003659static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003660 .ndo_open = hdd_open,
3661 .ndo_stop = hdd_stop,
3662 .ndo_uninit = hdd_uninit,
3663 .ndo_start_xmit = hdd_hard_start_xmit,
3664 .ndo_tx_timeout = hdd_tx_timeout,
3665 .ndo_get_stats = hdd_get_stats,
3666 .ndo_do_ioctl = hdd_ioctl,
3667 .ndo_set_mac_address = hdd_set_mac_address,
3668 .ndo_select_queue = hdd_select_queue,
3669#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003670 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003671#endif
3672};
3673
Nirav Shah73713f72018-05-17 14:50:41 +05303674#ifdef FEATURE_MONITOR_MODE_SUPPORT
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003675/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003676static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003677 .ndo_open = hdd_mon_open,
3678 .ndo_stop = hdd_stop,
3679 .ndo_get_stats = hdd_get_stats,
3680};
3681
3682/**
3683 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003684 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003685 * Return: None
3686 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003687void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003688{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003689 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003690 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003691 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003692 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003693}
Nirav Shah73713f72018-05-17 14:50:41 +05303694#else
3695void hdd_set_station_ops(struct net_device *dev)
3696{
3697 dev->netdev_ops = &wlan_drv_ops;
3698}
3699#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003700
3701/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003702 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3703 * @hdd_ctx: global hdd context
3704 * @macAddr: mac address to assign to the interface
3705 * @name: User-visible name of the interface
3706 *
3707 * hdd adapter pointer would point to the netdev->priv space, this function
Jeff Johnson62018292018-05-06 16:18:35 -07003708 * would retrieve the pointer, and setup the hdd adapter configuration.
Ryan Hsu07495ea2016-01-21 15:25:39 -08003709 *
3710 * Return: the pointer to hdd adapter, otherwise NULL
3711 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003712static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003713 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003714 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003715 const char *name)
3716{
Jeff Johnson5505db82017-11-02 21:19:23 -07003717 struct net_device *dev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003718 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003719 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303720 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003721 /*
3722 * cfg80211 initialization and registration....
3723 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003724 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003725#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3726 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003727#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003728 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3729 hdd_mon_mode_ether_setup : ether_setup),
3730 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003731
Jeff Johnson5505db82017-11-02 21:19:23 -07003732 if (dev != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003733
3734 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson5505db82017-11-02 21:19:23 -07003735 adapter = (struct hdd_adapter *) netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003736
Jeff Johnson9d295242017-08-29 14:39:48 -07003737 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Jeff Johnsonb9424862017-10-30 08:49:35 -07003738 sta_ctx = &adapter->session.station;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303739 qdf_mem_set(sta_ctx->conn_info.staId,
3740 sizeof(sta_ctx->conn_info.staId),
3741 HDD_WLAN_INVALID_STA_ID);
Jeff Johnson5505db82017-11-02 21:19:23 -07003742 adapter->dev = dev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003743 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003744 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003745 adapter->session_id = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003746
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303747 qdf_status = qdf_event_create(
3748 &adapter->qdf_session_open_event);
3749 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3750 hdd_err("Session open QDF event init failed!");
3751 free_netdev(adapter->dev);
3752 return NULL;
3753 }
3754
3755 qdf_status = qdf_event_create(
3756 &adapter->qdf_session_close_event);
3757 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3758 hdd_err("Session close QDF event init failed!");
3759 free_netdev(adapter->dev);
3760 return NULL;
3761 }
3762
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003763 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303764 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003765 init_completion(&adapter->linkup_event_var);
3766 init_completion(&adapter->cancel_rem_on_chan_var);
3767 init_completion(&adapter->rem_on_chan_ready_event);
3768 init_completion(&adapter->sta_authorized_event);
3769 init_completion(&adapter->offchannel_tx_event);
3770 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003771 init_completion(&adapter->ibss_peer_info_comp);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303772 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003773
3774 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003775 adapter->is_link_up_service_needed = false;
Alok Kumarb64650c2018-03-23 17:05:11 +05303776 adapter->disconnection_in_progress = false;
Yeshwanth Sriram Guntuka4fe30bd2018-06-13 11:41:42 +05303777 adapter->send_mode_change = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003778 /* Init the net_device structure */
Jeff Johnson5505db82017-11-02 21:19:23 -07003779 strlcpy(dev->name, name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003780
Jeff Johnson5505db82017-11-02 21:19:23 -07003781 qdf_mem_copy(dev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003782 sizeof(tSirMacAddr));
Jeff Johnson1e851a12017-10-28 14:36:12 -07003783 qdf_mem_copy(adapter->mac_addr.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003784 sizeof(tSirMacAddr));
Jeff Johnson5505db82017-11-02 21:19:23 -07003785 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003786
3787 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
Jeff Johnson5505db82017-11-02 21:19:23 -07003788 dev->features |=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003789 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Jeff Johnson5505db82017-11-02 21:19:23 -07003790 dev->features |= NETIF_F_RXCSUM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003791
Jeff Johnson5505db82017-11-02 21:19:23 -07003792 hdd_set_tso_flags(hdd_ctx, dev);
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003793
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003794 hdd_set_station_ops(adapter->dev);
3795
Jeff Johnson5505db82017-11-02 21:19:23 -07003796 hdd_dev_setup_destructor(dev);
3797 dev->ieee80211_ptr = &adapter->wdev;
3798 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003799 adapter->wdev.wiphy = hdd_ctx->wiphy;
Jeff Johnson5505db82017-11-02 21:19:23 -07003800 adapter->wdev.netdev = dev;
3801 /* set dev's parent to underlying device */
3802 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003803 hdd_wmm_init(adapter);
3804 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303805 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003806 }
3807
3808 return adapter;
3809}
3810
Jeff Johnson9d295242017-08-29 14:39:48 -07003811static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003812{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003813 struct net_device *dev = adapter->dev;
3814 int ret;
3815
Dustin Brown491d54b2018-03-14 12:39:11 -07003816 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003817
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003818 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003819 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3820
3821 ret = dev_alloc_name(dev, dev->name);
3822 if (ret < 0) {
3823 hdd_err(
3824 "unable to get dev name: %s, err = 0x%x",
3825 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303826 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003827 }
3828 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003829
3830 ret = register_netdevice(dev);
3831 if (ret) {
3832 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3833 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303834 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003835 }
3836 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003837 ret = register_netdev(dev);
3838 if (ret) {
3839 hdd_err("register_netdev(%s) failed, err = 0x%x",
3840 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303841 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003842 }
3843 }
3844 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3845
Dustin Browne74003f2018-03-14 12:51:58 -07003846 hdd_exit();
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003847
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303848 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003849}
3850
Krunal Sonib51eec72017-11-20 21:53:01 -08003851QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003852{
Krunal Sonib51eec72017-11-20 21:53:01 -08003853 struct hdd_adapter *adapter;
3854 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003855
Krunal Sonib51eec72017-11-20 21:53:01 -08003856 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3857 if (!hdd_ctx) {
3858 hdd_err("Invalid HDD_CTX");
3859 return QDF_STATUS_E_FAILURE;
3860 }
3861
3862 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3863 if (NULL == adapter) {
Naveen Rawat23a3b912018-05-30 17:45:52 -07003864 hdd_err("NULL adapter for %d", session_id);
Krunal Sonib51eec72017-11-20 21:53:01 -08003865 return QDF_STATUS_E_INVAL;
3866 }
3867 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303868 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003869 hdd_debug("session %d opened", adapter->session_id);
3870
3871 return QDF_STATUS_SUCCESS;
3872}
3873
3874QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3875{
3876 struct hdd_adapter *adapter;
3877 struct hdd_context *hdd_ctx;
3878
3879 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3880 if (!hdd_ctx) {
3881 hdd_err("Invalid HDD_CTX");
3882 return QDF_STATUS_E_FAILURE;
3883 }
3884
3885 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003886 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003887 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303888 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003889 }
3890
3891 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003892 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303893 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003894 }
3895
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003896 /*
3897 * For NAN Data interface, the close session results in the final
3898 * indication to the userspace
3899 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003900 if (adapter->device_mode == QDF_NDI_MODE)
3901 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003902
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003903 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3904
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003905 /*
3906 * We can be blocked while waiting for scheduled work to be
3907 * flushed, and the adapter structure can potentially be freed, in
3908 * which case the magic will have been reset. So make sure the
3909 * magic is still good, and hence the adapter structure is still
3910 * valid, before signaling completion
3911 */
3912 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303913 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003914
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303915 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003916}
3917
Jeff Johnson9d295242017-08-29 14:39:48 -07003918int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003919{
Dustin Brownd28772b2017-03-17 14:16:07 -07003920 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003921
Dustin Brownd28772b2017-03-17 14:16:07 -07003922 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003923 if (QDF_IS_STATUS_ERROR(status))
3924 return qdf_status_to_os_return(status);
3925
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003926 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003927 if (QDF_IS_STATUS_ERROR(status))
3928 return qdf_status_to_os_return(status);
3929
3930 if (wma_capability_enhanced_mcast_filter())
3931 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3932 else
3933 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003934
3935 return qdf_status_to_os_return(status);
3936}
3937
Jeff Johnson9d295242017-08-29 14:39:48 -07003938int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003939{
3940 QDF_STATUS status;
Jiachao Wu2c42c222018-01-15 18:13:19 +08003941 int errno = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003942 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003943 uint8_t vdev_id;
Dustin Brownd28772b2017-03-17 14:16:07 -07003944
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003945 vdev_id = adapter->session_id;
3946 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003947
3948 /* vdev created sanity check */
3949 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07003950 hdd_err("vdev for Id %d does not exist", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003951 return -EINVAL;
3952 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003953 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Krunal Soni8a06d832018-06-20 16:41:17 -07003954 ucfg_scan_set_vdev_del_in_progress(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003955
Dustin Brownd28772b2017-03-17 14:16:07 -07003956 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303957 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07003958 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -07003959 status = sme_close_session(hdd_ctx->mac_handle, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003960 if (QDF_IS_STATUS_ERROR(status)) {
3961 hdd_err("failed to close sme session: %d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003962 errno = qdf_status_to_os_return(status);
3963 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07003964 }
3965
3966 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303967 status = qdf_wait_for_event_completion(
3968 &adapter->qdf_session_close_event,
3969 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3970 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003971 if (adapter->device_mode == QDF_NDI_MODE)
3972 hdd_ndp_session_end_handler(adapter);
3973 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303974 adapter->session_id = HDD_SESSION_ID_INVALID;
3975 if (QDF_STATUS_E_TIMEOUT != status) {
3976 hdd_err("timed out waiting for close sme session: %u", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003977 errno = -ETIMEDOUT;
3978 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303979 } else if (adapter->qdf_session_close_event.force_set) {
3980 hdd_err("Session close evt focefully set, SSR/PDR has occurred");
Jiachao Wu2c42c222018-01-15 18:13:19 +08003981 errno = -EINVAL;
3982 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303983 } else {
3984 hdd_err("Failed to close sme session (%u)", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003985 errno = -EINVAL;
3986 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303987 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003988 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08003989
Yue Maf9782842017-05-08 12:49:49 -07003990release_vdev:
Krunal Soni8a06d832018-06-20 16:41:17 -07003991 ucfg_scan_clear_vdev_del_in_progress(adapter->hdd_vdev);
Frank Liuc66d4bf2018-01-26 16:18:18 +08003992 /*
3993 * In SSR or driver unloading case, directly exit may cause objects
3994 * leak, if sme_close_session failed. Free objects anyway.
Jiachao Wu2c42c222018-01-15 18:13:19 +08003995 */
Kabilan Kannanb867c312018-02-15 17:43:21 -08003996 if (errno && !cds_is_driver_recovering() && !cds_is_driver_unloading())
Jiachao Wu2c42c222018-01-15 18:13:19 +08003997 return errno;
3998
Sandeep Puligillaef415362017-08-30 16:37:13 -07003999 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08004000 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07004001 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08004002 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07004003 return errno;
4004 }
4005
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08004006 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004007
4008 return 0;
4009}
4010
Krunal Sonib51eec72017-11-20 21:53:01 -08004011static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
4012 struct sme_session_params *session_param,
Jeff Johnson6a18c962018-07-01 09:09:37 -07004013 csr_roam_complete_cb callback,
Krunal Sonib51eec72017-11-20 21:53:01 -08004014 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07004015{
Dustin Brownd28772b2017-03-17 14:16:07 -07004016 uint32_t type;
4017 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08004018 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07004019
4020 /* determine vdev (sub)type */
4021 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304022 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07004023 hdd_err("failed to get vdev type: %d", status);
4024 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004025 }
Krunal Sonib51eec72017-11-20 21:53:01 -08004026 session_param->sme_session_id = adapter->session_id;
4027 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
4028 session_param->type_of_persona = type;
4029 session_param->subtype_of_persona = sub_type;
4030 session_param->session_open_cb = hdd_sme_open_session_callback;
4031 session_param->session_close_cb = hdd_sme_close_session_callback;
4032 session_param->callback = callback;
4033 session_param->callback_ctx = callback_ctx;
4034
4035 return 0;
4036}
4037
4038int hdd_vdev_create(struct hdd_adapter *adapter,
Jeff Johnson6a18c962018-07-01 09:09:37 -07004039 csr_roam_complete_cb callback, void *ctx)
Krunal Sonib51eec72017-11-20 21:53:01 -08004040{
4041 QDF_STATUS status;
4042 int errno;
4043 struct hdd_context *hdd_ctx;
4044 struct sme_session_params sme_session_params = {0};
Krunal Sonib51eec72017-11-20 21:53:01 -08004045
4046 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07004047
4048 /* do vdev create via objmgr */
4049 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07004050 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07004051 if (errno) {
4052 hdd_err("failed to create objmgr vdev: %d", errno);
4053 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004054 }
Dustin Brownd28772b2017-03-17 14:16:07 -07004055
4056 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304057 status = qdf_event_reset(&adapter->qdf_session_open_event);
4058 if (QDF_STATUS_SUCCESS != status) {
4059 hdd_err("failed to reinit session open event");
4060 return -EINVAL;
4061 }
Krunal Sonib51eec72017-11-20 21:53:01 -08004062 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
4063 callback, ctx);
4064 if (errno) {
4065 hdd_err("failed to populating SME params");
4066 goto objmgr_vdev_destroy_procedure;
4067 }
4068
Jeff Johnson16528362018-06-14 12:34:16 -07004069 status = sme_open_session(hdd_ctx->mac_handle, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07004070 if (QDF_IS_STATUS_ERROR(status)) {
4071 hdd_err("failed to open sme session: %d", status);
4072 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07004073 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004074 }
4075
4076 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304077 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
4078 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
4079 if (QDF_STATUS_SUCCESS != status) {
4080 if (adapter->qdf_session_open_event.force_set) {
4081 /*
4082 * SSR/PDR has caused shutdown, which has forcefully
4083 * set the event. Return without the closing session.
4084 */
4085 adapter->session_id = HDD_SESSION_ID_INVALID;
4086 hdd_err("Session open event forcefully set");
4087 return -EINVAL;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304088 }
Jeff Johnsonc66d3102018-02-28 11:58:26 -08004089
4090 if (QDF_STATUS_E_TIMEOUT == status)
4091 hdd_err("Session failed to open within timeout period");
4092 else
4093 hdd_err("Failed to wait for session open event(status-%d)",
4094 status);
4095 errno = -ETIMEDOUT;
4096 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
4097 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004098 }
4099
4100 /* firmware ready for component communication, raise vdev_ready event */
4101 errno = hdd_vdev_ready(adapter);
4102 if (errno) {
4103 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07004104 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004105 }
4106
Naveen Rawat2b430892018-03-13 13:58:18 -07004107 if (adapter->device_mode == QDF_STA_MODE) {
4108 hdd_debug("setting RTT mac randomization param: %d",
4109 hdd_ctx->config->enable_rtt_mac_randomization);
4110 errno = sme_cli_set_command(adapter->session_id,
4111 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_INITIATOR_RANDOM_MAC,
4112 hdd_ctx->config->enable_rtt_mac_randomization,
4113 VDEV_CMD);
4114 if (0 != errno)
4115 hdd_err("RTT mac randomization param set failed %d",
4116 errno);
4117 }
4118
Bala Venkatesh110b03e2018-07-10 16:02:08 +05304119 if (adapter->device_mode == QDF_STA_MODE ||
4120 adapter->device_mode == QDF_P2P_CLIENT_MODE)
4121 wlan_vdev_set_max_peer_count(adapter->hdd_vdev,
4122 HDD_MAX_VDEV_PEER_COUNT);
4123
Jeff Johnson1b780e42017-10-31 14:11:45 -07004124 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004125
4126 return 0;
4127
4128 /*
4129 * Due to legacy constraints, we need to destroy in the same order as
4130 * create. So, split error handling into 2 cases to accommodate.
4131 */
4132
Krunal Soni4a020c72017-10-30 20:58:40 -07004133objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07004134 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07004135
4136 return errno;
4137
Krunal Soni4a020c72017-10-30 20:58:40 -07004138hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07004139 QDF_BUG(!hdd_vdev_destroy(adapter));
4140
4141 return errno;
4142}
4143
Jeff Johnson9d295242017-08-29 14:39:48 -07004144QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07004145{
Jeff Johnsonb9424862017-10-30 08:49:35 -07004146 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004147 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07004148 QDF_STATUS status;
4149 int ret_val;
Jeff Johnson16528362018-06-14 12:34:16 -07004150 mac_handle_t mac_handle;
Dustin Brownd28772b2017-03-17 14:16:07 -07004151
Dustin Brownd28772b2017-03-17 14:16:07 -07004152 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -07004153 mac_handle = hdd_ctx->mac_handle;
4154 sme_set_curr_device_mode(mac_handle, adapter->device_mode);
4155 sme_set_pdev_ht_vht_ies(mac_handle, hdd_ctx->config->enable2x2);
4156 sme_set_vdev_ies_per_band(mac_handle, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004157
Jeff Johnson7f2c5912018-03-23 11:42:28 -07004158 hdd_roam_profile_init(adapter);
4159 hdd_register_wext(adapter->dev);
4160
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07004161 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004162
Jeff Johnsond377dce2017-10-04 10:32:42 -07004163 qdf_mem_set(sta_ctx->conn_info.staId,
4164 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05304165
Deepak Dhamdherea2785822016-11-17 01:17:45 -08004166 /* set fast roaming capability in sme session */
Jeff Johnson16528362018-06-14 12:34:16 -07004167 status = sme_config_fast_roaming(mac_handle, adapter->session_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05304168 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004169 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004170 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004171 hdd_ctx->config->OperatingChannel;
4172
4173 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004174 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004175
4176 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304177 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004178 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004179 status, status);
4180 goto error_init_txrx;
4181 }
4182
4183 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4184
4185 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304186 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004187 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004188 status, status);
4189 goto error_wmm_init;
4190 }
4191
4192 set_bit(WMM_INIT_DONE, &adapter->event_flags);
4193
Jeff Johnson1b780e42017-10-31 14:11:45 -07004194 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004195 WMI_PDEV_PARAM_BURST_ENABLE,
Dundi Raviteja3aa01be2018-05-21 18:58:59 +05304196 HDD_ENABLE_SIFS_BURST_DEFAULT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004197 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07004198 if (ret_val)
4199 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004200
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05304201 /*
4202 * In case of USB tethering, LRO is disabled. If SSR happened
4203 * during that time, then as part of SSR init, do not enable
4204 * the LRO again. Keep the LRO state same as before SSR.
4205 */
4206 if (!(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07004207 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05304208
4209 /* rcpi info initialization */
4210 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
4211
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304212 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004213
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004214error_wmm_init:
4215 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4216 hdd_deinit_tx_rx(adapter);
4217error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07004218 hdd_unregister_wext(adapter->dev);
Dustin Brownd28772b2017-03-17 14:16:07 -07004219 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004220
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004221 return status;
4222}
4223
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304224/**
Krunal Soni4a020c72017-10-30 20:58:40 -07004225 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304226 * @hdd_ctx: global hdd context
4227 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07004228 * @rtnl_held: Used to indicate whether or not the caller is holding
4229 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304230 *
4231 * This function De-initializes the STA/P2P/OCB adapter.
4232 *
4233 * Return: None.
4234 */
Krunal Soni4a020c72017-10-30 20:58:40 -07004235static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004236 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004237 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304238{
Dustin Brownfdf17c12018-03-14 12:55:34 -07004239 hdd_enter_dev(adapter->dev);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304240
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05304241 if (adapter->dev) {
4242 if (rtnl_held)
4243 adapter->dev->wireless_handlers = NULL;
4244 else {
4245 rtnl_lock();
4246 adapter->dev->wireless_handlers = NULL;
4247 rtnl_unlock();
4248 }
4249 }
4250
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304251 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
4252 hdd_deinit_tx_rx(adapter);
4253 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4254 }
4255
4256 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4257 hdd_wmm_adapter_close(adapter);
4258 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4259 }
4260
Krunal Sonib51eec72017-11-20 21:53:01 -08004261
Dustin Browne74003f2018-03-14 12:51:58 -07004262 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304263}
4264
Krunal Sonib51eec72017-11-20 21:53:01 -08004265void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
4266 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004267 bool rtnl_held)
4268{
Dustin Brown491d54b2018-03-14 12:39:11 -07004269 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304270
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004271 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004272 case QDF_STA_MODE:
4273 case QDF_P2P_CLIENT_MODE:
4274 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08004275 case QDF_IBSS_MODE:
4276 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004277 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004278 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004279 break;
4280 }
4281
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004282 case QDF_SAP_MODE:
4283 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004284 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004285 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004286 break;
4287 }
4288
4289 default:
4290 break;
4291 }
4292
Dustin Browne74003f2018-03-14 12:51:58 -07004293 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004294}
4295
Jeff Johnson9d295242017-08-29 14:39:48 -07004296static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004297 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004298{
Jeff Johnson5505db82017-11-02 21:19:23 -07004299 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004300
4301 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07004302 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004303 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004304 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004305 return;
4306 }
4307
Alok Kumarb64650c2018-03-23 17:05:11 +05304308 hdd_nud_deinit_tracking(adapter);
4309 qdf_mutex_destroy(&adapter->disconnection_status_lock);
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05304310 hdd_apf_context_destroy(adapter);
Alok Kumarb64650c2018-03-23 17:05:11 +05304311
Rajeev Kumardca5f812016-02-04 17:28:06 -08004312 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05304313
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004314 /*
4315 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
4316 * the driver is almost closed and cannot handle either control
4317 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004318 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
4319 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004320 * is not right. Setting this flag helps hdd_stop() to recognize that
4321 * the interface is closed and restricts any operations on that
4322 */
4323 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
4324
4325 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004326 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07004327 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004328 else
Jeff Johnson5505db82017-11-02 21:19:23 -07004329 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004330 /*
4331 * Note that the adapter is no longer valid at this point
4332 * since the memory has been reclaimed
4333 */
4334 }
4335}
4336
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004337static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07004338 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004339{
Jeff Johnson9d295242017-08-29 14:39:48 -07004340 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004341
Dustin Brown920397d2017-12-13 16:27:50 -08004342 hdd_for_each_adapter(hdd_ctx, adapter) {
4343 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
4344 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304345 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004346 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004347 }
Dustin Brown920397d2017-12-13 16:27:50 -08004348
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304349 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004350}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004351
Arun Khandavalli2358d522016-05-16 18:05:37 +05304352#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4353/**
4354 * hdd_set_fw_log_params() - Set log parameters to FW
4355 * @hdd_ctx: HDD Context
4356 * @adapter: HDD Adapter
4357 *
4358 * This function set the FW Debug log level based on the INI.
4359 *
4360 * Return: None
4361 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004362static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004363 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304364{
4365 uint8_t count = 0, numentries = 0,
4366 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
4367 uint32_t value = 0;
4368 int ret;
4369
Arun Khandavallifae92942016-08-01 13:31:08 +05304370 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4371 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004372 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304373 return;
4374 }
4375
Arun Khandavallifae92942016-08-01 13:31:08 +05304376 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05304377 hdd_ctx->fw_log_settings.dl_type =
4378 hdd_ctx->config->enableFwLogType;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004379 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304380 WMI_DBGLOG_TYPE,
4381 hdd_ctx->config->enableFwLogType,
4382 DBG_CMD);
4383 if (ret != 0)
4384 hdd_err("Failed to enable FW log type ret %d",
4385 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304386
4387 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05304388 hdd_ctx->config->enableFwLogLevel;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004389 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304390 WMI_DBGLOG_LOG_LEVEL,
4391 hdd_ctx->config->enableFwLogLevel,
4392 DBG_CMD);
4393 if (ret != 0)
4394 hdd_err("Failed to enable FW log level ret %d",
4395 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304396
4397 hdd_string_to_u8_array(
4398 hdd_ctx->config->enableFwModuleLogLevel,
4399 moduleloglevel,
4400 &numentries,
4401 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
4402
4403 while (count < numentries) {
4404 /*
4405 * FW module log level input string looks like
4406 * below:
4407 * gFwDebugModuleLoglevel=<FW Module ID>,
4408 * <Log Level>,...
4409 * For example:
4410 * gFwDebugModuleLoglevel=
4411 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
4412 * Above input string means :
4413 * For FW module ID 1 enable log level 0
4414 * For FW module ID 2 enable log level 1
4415 * For FW module ID 3 enable log level 2
4416 * For FW module ID 4 enable log level 3
4417 * For FW module ID 5 enable log level 4
4418 * For FW module ID 6 enable log level 5
4419 * For FW module ID 7 enable log level 6
4420 */
4421
Nishank Aggarwale239d962017-03-03 12:26:02 +05304422 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
4423 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
4424 hdd_err("Module id %d and dbglog level %d input length is more than max",
4425 moduleloglevel[count],
4426 moduleloglevel[count + 1]);
4427 return;
4428 }
4429
4430 value = moduleloglevel[count] << 16;
4431 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07004432 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304433 WMI_DBGLOG_MOD_LOG_LEVEL,
4434 value, DBG_CMD);
4435 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304436 hdd_err("Failed to enable FW module log level %d ret %d",
4437 value, ret);
4438
4439 count += 2;
4440 }
Arun Khandavallifae92942016-08-01 13:31:08 +05304441
Arun Khandavalli2358d522016-05-16 18:05:37 +05304442}
4443#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004444static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004445 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304446{
4447}
4448
4449#endif
4450
4451/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004452 * hdd_configure_chain_mask() - programs chain mask to firmware
4453 * @adapter: HDD adapter
4454 *
4455 * Return: 0 on success or errno on failure
4456 */
4457static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4458{
4459 int ret_val;
Naveen Rawat98322472018-03-06 10:29:42 -08004460 QDF_STATUS status;
4461 struct wma_caps_per_phy non_dbs_phy_cap;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004462 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4463
4464 hdd_debug("enable2x2: %d, lte_coex: %d, ChainMask1x1: tx: %d rx: %d",
4465 hdd_ctx->config->enable2x2, hdd_ctx->lte_coex_ant_share,
4466 hdd_ctx->config->txchainmask1x1,
4467 hdd_ctx->config->rxchainmask1x1);
4468 hdd_debug("disable_DBS: %d, tx_chain_mask_2g: %d, rx_chain_mask_2g: %d",
4469 hdd_ctx->config->dual_mac_feature_disable,
4470 hdd_ctx->config->tx_chain_mask_2g,
4471 hdd_ctx->config->rx_chain_mask_2g);
4472 hdd_debug("tx_chain_mask_5g: %d, rx_chain_mask_5g: %d",
4473 hdd_ctx->config->tx_chain_mask_5g,
4474 hdd_ctx->config->rx_chain_mask_5g);
Liangwei Dong22810e82018-03-15 03:42:12 -04004475 hdd_debug("enable_bt_chain_separation %d",
4476 hdd_ctx->config->enable_bt_chain_separation);
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004477
Naveen Rawat98322472018-03-06 10:29:42 -08004478 status = wma_get_caps_for_phyidx_hwmode(&non_dbs_phy_cap,
4479 HW_MODE_DBS_NONE,
4480 CDS_BAND_ALL);
4481 if (QDF_IS_STATUS_ERROR(status)) {
4482 hdd_err("couldn't get phy caps. skip chain mask programming");
4483 return qdf_status_to_os_return(status);
4484 }
4485
4486 if (non_dbs_phy_cap.tx_chain_mask_2G < 3 ||
4487 non_dbs_phy_cap.rx_chain_mask_2G < 3 ||
4488 non_dbs_phy_cap.tx_chain_mask_5G < 3 ||
4489 non_dbs_phy_cap.rx_chain_mask_5G < 3) {
4490 hdd_info("firmware not capable. skip chain mask programming");
4491 return 0;
4492 }
4493
Liangwei Dong22810e82018-03-15 03:42:12 -04004494 if (hdd_ctx->config->enable2x2 &&
4495 !hdd_ctx->config->enable_bt_chain_separation) {
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004496 hdd_info("2x2 enabled. skip chain mask programming");
4497 return 0;
4498 }
4499
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004500 if (hdd_ctx->config->dual_mac_feature_disable !=
4501 DISABLE_DBS_CXN_AND_SCAN) {
4502 hdd_info("DBS enabled(%d). skip chain mask programming",
4503 hdd_ctx->config->dual_mac_feature_disable);
4504 return 0;
4505 }
4506
Naveen Rawatdacb5032018-02-08 15:23:24 -08004507 if (hdd_ctx->lte_coex_ant_share) {
4508 hdd_info("lte ant sharing enabled. skip chainmask programming");
4509 return 0;
4510 }
4511
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004512 if (hdd_ctx->config->txchainmask1x1) {
4513 ret_val = sme_cli_set_command(adapter->session_id,
4514 WMI_PDEV_PARAM_TX_CHAIN_MASK,
4515 hdd_ctx->config->txchainmask1x1,
4516 PDEV_CMD);
4517 if (ret_val)
4518 goto error;
4519 }
4520
4521 if (hdd_ctx->config->rxchainmask1x1) {
4522 ret_val = sme_cli_set_command(adapter->session_id,
4523 WMI_PDEV_PARAM_RX_CHAIN_MASK,
4524 hdd_ctx->config->rxchainmask1x1,
4525 PDEV_CMD);
4526 if (ret_val)
4527 goto error;
4528 }
4529
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004530 if (hdd_ctx->config->txchainmask1x1 ||
4531 hdd_ctx->config->rxchainmask1x1) {
4532 hdd_info("band agnostic tx/rx chain mask set. skip per band chain mask");
4533 return 0;
4534 }
4535
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004536 if (hdd_ctx->config->tx_chain_mask_2g) {
4537 ret_val = sme_cli_set_command(adapter->session_id,
4538 WMI_PDEV_PARAM_TX_CHAIN_MASK_2G,
4539 hdd_ctx->config->tx_chain_mask_2g, PDEV_CMD);
4540 if (0 != ret_val)
4541 goto error;
4542 }
4543
4544 if (hdd_ctx->config->rx_chain_mask_2g) {
4545 ret_val = sme_cli_set_command(adapter->session_id,
4546 WMI_PDEV_PARAM_RX_CHAIN_MASK_2G,
4547 hdd_ctx->config->rx_chain_mask_2g, PDEV_CMD);
4548 if (0 != ret_val)
4549 goto error;
4550 }
4551
4552 if (hdd_ctx->config->tx_chain_mask_5g) {
4553 ret_val = sme_cli_set_command(adapter->session_id,
4554 WMI_PDEV_PARAM_TX_CHAIN_MASK_5G,
4555 hdd_ctx->config->tx_chain_mask_5g, PDEV_CMD);
4556 if (0 != ret_val)
4557 goto error;
4558 }
4559
4560 if (hdd_ctx->config->rx_chain_mask_5g) {
4561 ret_val = sme_cli_set_command(adapter->session_id,
4562 WMI_PDEV_PARAM_RX_CHAIN_MASK_5G,
4563 hdd_ctx->config->rx_chain_mask_5g, PDEV_CMD);
4564 if (0 != ret_val)
4565 goto error;
4566 }
4567
4568 return 0;
4569
4570error:
4571 hdd_err("WMI PDEV set param failed %d", ret_val);
4572 return -EINVAL;
4573}
4574
4575/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304576 * hdd_set_fw_params() - Set parameters to firmware
4577 * @adapter: HDD adapter
4578 *
4579 * This function Sets various parameters to fw once the
4580 * adapter is started.
4581 *
4582 * Return: 0 on success or errno on failure
4583 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004584int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304585{
4586 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004587 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304588
Dustin Brownfdf17c12018-03-14 12:55:34 -07004589 hdd_enter_dev(adapter->dev);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304590
4591 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4592 if (!hdd_ctx)
4593 return -EINVAL;
4594
Dustin Brown732ab9c2017-06-15 13:24:09 -07004595 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4596 hdd_debug("FTM Mode is active; nothing to do");
4597 return 0;
4598 }
4599
Jeff Johnson1b780e42017-10-31 14:11:45 -07004600 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304601 WMI_PDEV_PARAM_DTIM_SYNTH,
4602 hdd_ctx->config->enable_lprx, PDEV_CMD);
4603 if (ret) {
4604 hdd_err("Failed to set LPRx");
4605 goto error;
4606 }
4607
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304608
4609 ret = sme_cli_set_command(
4610 adapter->session_id,
4611 WMI_PDEV_PARAM_1CH_DTIM_OPTIMIZED_CHAIN_SELECTION,
4612 hdd_ctx->config->enable_dtim_selection_diversity,
4613 PDEV_CMD);
4614 if (ret) {
4615 hdd_err("Failed to set DTIM_OPTIMIZED_CHAIN_SELECTION");
4616 goto error;
4617 }
4618
Ashish Kumar Dhanotiya48dac7d2018-03-28 14:59:50 +05304619 ret = sme_cli_set_command(
4620 adapter->session_id,
4621 WMI_PDEV_PARAM_TX_SCH_DELAY,
4622 hdd_ctx->config->enable_tx_sch_delay,
4623 PDEV_CMD);
4624 if (ret) {
4625 hdd_err("Failed to set WMI_PDEV_PARAM_TX_SCH_DELAY");
4626 goto error;
4627 }
4628
Ashish Kumar Dhanotiya959b38c2018-04-06 21:07:57 +05304629 ret = sme_cli_set_command(
4630 adapter->session_id,
4631 WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE,
4632 hdd_ctx->config->enable_secondary_rate,
4633 PDEV_CMD);
4634 if (ret) {
4635 hdd_err("Failed to set WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE");
4636 goto error;
4637 }
4638
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304639 if (adapter->device_mode == QDF_STA_MODE) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07004640 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304641 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4642 hdd_ctx->config->upper_brssi_thresh);
4643
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_LOWER_BRSSI_THRESH,
4646 hdd_ctx->config->lower_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_DTIM_1CHRX_ENABLE,
4650 hdd_ctx->config->enable_dtim_1chrx);
4651 }
4652
Dustin Brown732ab9c2017-06-15 13:24:09 -07004653 if (hdd_ctx->config->enable2x2) {
4654 hdd_debug("configuring 2x2 mode fw params");
4655
Jeff Johnson1b780e42017-10-31 14:11:45 -07004656 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004657 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
4658 hdd_ctx->config->enable_cck_tx_fir_override,
4659 PDEV_CMD);
4660 if (ret) {
4661 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4662 ret);
4663 goto error;
4664 }
Liangwei Dong22810e82018-03-15 03:42:12 -04004665
4666 if (hdd_configure_chain_mask(adapter))
4667 goto error;
Dustin Brown732ab9c2017-06-15 13:24:09 -07004668 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304669#define HDD_DTIM_1CHAIN_RX_ID 0x5
4670#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004671 hdd_debug("configuring 1x1 mode fw params");
4672
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004673 /*
4674 * Disable DTIM 1 chain Rx when in 1x1,
4675 * we are passing two value
4676 * as param_id << 29 | param_value.
4677 * Below param_value = 0(disable)
4678 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004679 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004680 WMI_STA_SMPS_PARAM_CMDID,
4681 HDD_DTIM_1CHAIN_RX_ID <<
4682 HDD_SMPS_PARAM_VALUE_S,
4683 VDEV_CMD);
4684 if (ret) {
4685 hdd_err("DTIM 1 chain set failed %d", ret);
4686 goto error;
4687 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304688
Arun Khandavalli2358d522016-05-16 18:05:37 +05304689#undef HDD_DTIM_1CHAIN_RX_ID
4690#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004691
4692 if (hdd_configure_chain_mask(adapter))
4693 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004694 }
4695
Jeff Johnson1b780e42017-10-31 14:11:45 -07004696 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004697 WMI_PDEV_PARAM_HYST_EN,
4698 hdd_ctx->config->enableMemDeepSleep,
4699 PDEV_CMD);
4700 if (ret) {
4701 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4702 goto error;
4703 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304704
Jeff Johnson1b780e42017-10-31 14:11:45 -07004705 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004706 WMI_VDEV_PARAM_ENABLE_RTSCTS,
4707 hdd_ctx->config->rts_profile,
4708 VDEV_CMD);
4709 if (ret) {
4710 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4711 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304712 }
4713
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004714 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
4715
Jeff Johnson1b780e42017-10-31 14:11:45 -07004716 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004717 GEN_VDEV_PARAM_AMSDU,
4718 hdd_ctx->config->max_amsdu_num,
4719 GEN_CMD);
4720 if (ret != 0) {
4721 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4722 goto error;
4723 }
4724
Arun Khandavalli2358d522016-05-16 18:05:37 +05304725 hdd_set_fw_log_params(hdd_ctx, adapter);
Dustin Browne74003f2018-03-14 12:51:58 -07004726 hdd_exit();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004727
Arun Khandavalli2358d522016-05-16 18:05:37 +05304728 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304729
Arun Khandavalli2358d522016-05-16 18:05:37 +05304730error:
4731 return -EINVAL;
4732}
4733
Ryan Hsu07495ea2016-01-21 15:25:39 -08004734/**
4735 * hdd_open_adapter() - open and setup the hdd adatper
4736 * @hdd_ctx: global hdd context
4737 * @session_type: type of the interface to be created
4738 * @iface_name: User-visible name of the interface
4739 * @macAddr: MAC address to assign to the interface
4740 * @name_assign_type: the name of assign type of the netdev
4741 * @rtnl_held: the rtnl lock hold flag
4742 *
4743 * This function open and setup the hdd adpater according to the device
4744 * type request, assign the name, the mac address assigned, and then prepared
4745 * the hdd related parameters, queue, lock and ready to start.
4746 *
4747 * Return: the pointer of hdd adapter, otherwise NULL.
4748 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004749struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004750 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08004751 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004752 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004753{
Jeff Johnson9d295242017-08-29 14:39:48 -07004754 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304755 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004756
4757 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4758 /*
4759 * Max limit reached on the number of vdevs configured by the
4760 * host. Return error
4761 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304762 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4763 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004764 return NULL;
4765 }
4766
4767 if (macAddr == NULL) {
4768 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304769 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004770 return NULL;
4771 }
4772 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304773 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304774 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4775 " already exists",
4776 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004777 return NULL;
4778 }
4779
4780 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004781 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004782 /* Reset locally administered bit if the device mode is STA */
4783 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05304784 hdd_info("locally administered bit reset in sta mode: "
4785 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004786 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004787 case QDF_P2P_CLIENT_MODE:
4788 case QDF_P2P_DEVICE_MODE:
4789 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07004790 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304791 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004792 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4793 name_assign_type,
4794 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004795
4796 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304797 hdd_err("failed to allocate adapter for session %d",
4798 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004799 return NULL;
4800 }
4801
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004802 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004803 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004804 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004805 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304806 else if (QDF_MONITOR_MODE == session_type)
4807 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004808 else
4809 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4810
4811 adapter->device_mode = session_type;
4812
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004813
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004814 /*
4815 * Workqueue which gets scheduled in IPv4 notification
4816 * callback
4817 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004818 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004819 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004820
4821#ifdef WLAN_NS_OFFLOAD
4822 /*
4823 * Workqueue which gets scheduled in IPv6
4824 * notification callback.
4825 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004826 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004827 hdd_ipv6_notifier_work_queue);
4828#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004829 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004830 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004831 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004832
4833 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004834 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004835 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304836 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4837 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304838
Alok Kumarb64650c2018-03-23 17:05:11 +05304839 hdd_nud_init_tracking(adapter);
4840
4841 qdf_mutex_create(&adapter->disconnection_status_lock);
4842
Ravi Joshi1a292562017-05-18 16:28:54 -07004843 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004844
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004845 case QDF_P2P_GO_MODE:
4846 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004847 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4848 name_assign_type,
4849 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004850 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004851 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304852 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004853 return NULL;
4854 }
4855
4856 adapter->wdev.iftype =
4857 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004858 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004859 NL80211_IFTYPE_P2P_GO;
4860 adapter->device_mode = session_type;
4861
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004862 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004863 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004864 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004865
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004866 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004867 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304868 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4869 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304870
4871 /*
4872 * Workqueue which gets scheduled in IPv4 notification
4873 * callback
4874 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004875 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304876 hdd_ipv4_notifier_work_queue);
4877
4878#ifdef WLAN_NS_OFFLOAD
4879 /*
4880 * Workqueue which gets scheduled in IPv6
4881 * notification callback.
4882 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004883 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304884 hdd_ipv6_notifier_work_queue);
4885#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004886 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304887 case QDF_FTM_MODE:
4888 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4889 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08004890 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304891 if (NULL == adapter) {
4892 hdd_err("Failed to allocate adapter for FTM mode");
4893 return NULL;
4894 }
4895 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4896 adapter->device_mode = session_type;
4897 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004898 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004899 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004900
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304901 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004902 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304903 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304904 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4905 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304906 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004907 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004908 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304909 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004910 return NULL;
4911 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004912
hqueaa33ee2017-05-04 17:56:35 +08004913 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
Min Liu9be5d4a2018-05-17 11:51:53 +08004914 qdf_list_create(&adapter->blocked_scan_request_q, WLAN_MAX_SCAN_COUNT);
4915 qdf_mutex_create(&adapter->blocked_scan_request_q_lock);
hqueaa33ee2017-05-04 17:56:35 +08004916
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304917 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004918 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08004919 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004920 }
4921
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304922 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004923 if (NULL != adapter) {
4924 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4925 adapter = NULL;
4926 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004927
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004928 return NULL;
4929 }
Nachiket Kukade5f0ce4f2018-06-15 19:47:37 +05304930 hdd_apf_context_init(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004931
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304932 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004933 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4934 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004935
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004936 /* Adapter successfully added. Increment the vdev count */
4937 hdd_ctx->current_intf_count++;
4938
Jeff Johnson5880d792016-08-15 13:32:30 -07004939 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004940 hdd_ctx->current_intf_count);
4941
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004942 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004943 }
4944
Rajeev Kumardca5f812016-02-04 17:28:06 -08004945 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004946 hdd_err("Interface %s wow debug_fs init failed",
4947 netdev_name(adapter->dev));
4948
Ajit Pal Singh106c1412018-04-18 18:08:49 +05304949 hdd_register_hl_netdev_fc_timer(adapter,
4950 hdd_tx_resume_timer_expired_handler);
4951
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004952 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4953 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004954
4955 return adapter;
4956
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004957err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07004958 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304959 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004960
4961 return NULL;
4962}
4963
Nirav Shaheb017be2018-02-15 11:20:58 +05304964#ifdef MSM_PLATFORM
4965static inline
4966void hdd_cancel_bus_bw_work(struct hdd_context *hdd_ctx)
4967{
4968 cancel_work_sync(&hdd_ctx->bus_bw_work);
4969}
4970#else
4971static inline
4972void hdd_cancel_bus_bw_work(struct hdd_context *hdd_ctx)
4973{
4974}
4975#endif
4976
Jeff Johnson9d295242017-08-29 14:39:48 -07004977QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004978 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004979{
Dustin Brown920397d2017-12-13 16:27:50 -08004980 /*
4981 * Here we are stopping global bus_bw timer & work per adapter.
4982 *
4983 * The reason is to fix one race condition between
4984 * bus bandwidth work and cleaning up an adapter.
4985 * Under some conditions, it is possible for the bus bandwidth
4986 * work to access a particularly destroyed adapter, leading to
4987 * use-after-free.
4988 */
4989 hdd_debug("wait for bus bw work to flush");
4990 hdd_bus_bw_compute_timer_stop(hdd_ctx);
4991 hdd_bus_bw_cancel_work(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004992
Min Liuef92ef52018-06-25 18:08:54 +08004993 qdf_list_destroy(&adapter->blocked_scan_request_q);
4994 qdf_mutex_destroy(&adapter->blocked_scan_request_q_lock);
4995
Dustin Brown920397d2017-12-13 16:27:50 -08004996 /* cleanup adapter */
4997 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4998 adapter->device_mode);
Dustin Brown920397d2017-12-13 16:27:50 -08004999 hdd_remove_adapter(hdd_ctx, adapter);
Liangwei Dongad89c762018-06-01 01:56:23 -04005000 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005001
Dustin Brown920397d2017-12-13 16:27:50 -08005002 /* conditionally restart the bw timer */
5003 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005004
Dustin Brown920397d2017-12-13 16:27:50 -08005005 /* Adapter removed. Decrement vdev count */
5006 if (hdd_ctx->current_intf_count != 0)
5007 hdd_ctx->current_intf_count--;
Dustin Brown5ec6b552017-03-31 12:11:40 -07005008
Dustin Brown920397d2017-12-13 16:27:50 -08005009 /* Fw will take care incase of concurrency */
5010 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005011}
5012
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08005013/**
5014 * hdd_close_all_adapters - Close all open adapters
5015 * @hdd_ctx: Hdd context
5016 * rtnl_held: True if RTNL lock held
5017 *
5018 * Close all open adapters.
5019 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305020 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08005021 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005022QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005023{
Dustin Brown920397d2017-12-13 16:27:50 -08005024 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305025 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005026
Dustin Brown491d54b2018-03-14 12:39:11 -07005027 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005028
5029 do {
Dustin Brown920397d2017-12-13 16:27:50 -08005030 status = hdd_remove_front_adapter(hdd_ctx, &adapter);
5031 if (QDF_IS_STATUS_SUCCESS(status)) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305032 wlan_hdd_release_intf_addr(hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005033 adapter->mac_addr.bytes);
5034 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
5035
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05305036 /* Adapter removed. Decrement vdev count */
5037 if (hdd_ctx->current_intf_count != 0)
5038 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005039 }
Dustin Brown920397d2017-12-13 16:27:50 -08005040 } while (QDF_IS_STATUS_SUCCESS(status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005041
Dustin Browne74003f2018-03-14 12:51:58 -07005042 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005043
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305044 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005045}
5046
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005047void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005048{
Anurag Chouhan6d760662016-02-20 16:05:43 +05305049 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005050 tSirUpdateIE updateIE;
Jeff Johnson16528362018-06-14 12:34:16 -07005051 mac_handle_t mac_handle;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005052
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005053 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005054 case QDF_STA_MODE:
5055 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005056 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005057 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005058 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07005059 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005060 break;
5061 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005062 case QDF_SAP_MODE:
5063 case QDF_P2P_GO_MODE:
5064 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005065 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07005066 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005067 break;
5068 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005069 case QDF_FTM_MODE:
5070 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005071 default:
5072 /*
5073 * wlan_hdd_reset_prob_rspies should not have been called
5074 * for these kind of devices
5075 */
Jeff Johnson5880d792016-08-15 13:32:30 -07005076 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005077 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005078 return;
5079 }
5080
Anurag Chouhanc5548422016-02-24 18:33:27 +05305081 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005082 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005083 updateIE.ieBufferlength = 0;
5084 updateIE.pAdditionIEBuffer = NULL;
5085 updateIE.append = true;
5086 updateIE.notify = false;
Jeff Johnson16528362018-06-14 12:34:16 -07005087 mac_handle = hdd_adapter_get_mac_handle(adapter);
5088 if (sme_update_add_ie(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005089 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305090 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005091 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005092 }
5093}
5094
Dustin Browndb2a8be2017-12-20 11:49:56 -08005095QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
5096 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005097{
Liangwei Dongad89c762018-06-01 01:56:23 -04005098 return hdd_stop_adapter_ext(hdd_ctx, adapter, 0);
5099}
5100
5101QDF_STATUS hdd_stop_adapter_ext(struct hdd_context *hdd_ctx,
5102 struct hdd_adapter *adapter,
5103 enum hdd_adapter_stop_flag_t flag)
5104{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305105 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson025618c2018-03-18 14:41:00 -07005106 struct csr_roam_profile *roam_profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005107 union iwreq_data wrqu;
5108 tSirUpdateIE updateIE;
5109 unsigned long rc;
Jeff Johnsone4c11db2018-05-05 23:22:32 -07005110 tsap_config_t *sap_config;
Jeff Johnson16528362018-06-14 12:34:16 -07005111 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005112
Dustin Brown491d54b2018-03-14 12:39:11 -07005113 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005114
Dustin Browne7e71d32018-05-11 16:00:08 -07005115 if (adapter->session_id != HDD_SESSION_ID_INVALID)
5116 wlan_hdd_cfg80211_deregister_frames(adapter);
5117
Alok Kumarb64650c2018-03-23 17:05:11 +05305118 hdd_nud_ignore_tracking(adapter, true);
5119 hdd_nud_reset_tracking(adapter);
5120
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005121 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305122 wlan_hdd_netif_queue_control(adapter,
5123 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5124 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08005125 /*
5126 * if this is the last active connection check & stop the
5127 * opportunistic timer first
5128 */
5129 if (((policy_mgr_get_connection_count(hdd_ctx->hdd_psoc) == 1) &&
5130 (policy_mgr_mode_specific_connection_count(hdd_ctx->hdd_psoc,
5131 policy_mgr_convert_device_mode_to_qdf_type(
5132 adapter->device_mode), NULL) == 1)) ||
5133 !policy_mgr_get_connection_count(hdd_ctx->hdd_psoc))
5134 policy_mgr_check_and_stop_opportunistic_timer(
5135 hdd_ctx->hdd_psoc, adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -07005136
5137 mac_handle = hdd_ctx->mac_handle;
5138
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005139 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005140 case QDF_STA_MODE:
5141 case QDF_P2P_CLIENT_MODE:
5142 case QDF_IBSS_MODE:
5143 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005144 case QDF_NDI_MODE:
5145 if ((QDF_NDI_MODE == adapter->device_mode) ||
5146 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005147 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
5148 hdd_is_connecting(
5149 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005150 INIT_COMPLETION(adapter->disconnect_comp_var);
Jeff Johnson025618c2018-03-18 14:41:00 -07005151 roam_profile = hdd_roam_profile(adapter);
5152 /* For NDI do not use roam_profile */
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005153 if (QDF_NDI_MODE == adapter->device_mode)
5154 qdf_ret_status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005155 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005156 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005157 eCSR_DISCONNECT_REASON_NDI_DELETE);
Jeff Johnson025618c2018-03-18 14:41:00 -07005158 else if (roam_profile->BSSType ==
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005159 eCSR_BSS_TYPE_START_IBSS)
5160 qdf_ret_status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005161 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005162 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005163 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08005164 else if (QDF_STA_MODE == adapter->device_mode) {
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005165 qdf_ret_status =
5166 wlan_hdd_try_disconnect(adapter);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08005167 hdd_debug("Send disconnected event to userspace");
5168 wlan_hdd_cfg80211_indicate_disconnect(
5169 adapter->dev, true,
5170 WLAN_REASON_UNSPECIFIED);
Jeff Johnson109e79d2018-02-27 15:10:04 -08005171 } 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;
Jeff Johnsond9952752018-04-18 12:15:35 -07006059 struct qdf_mac_addr bssid;
6060 struct csr_roam_profile roam_profile;
6061 struct ch_params ch_params;
6062
6063 if (QDF_GLOBAL_MONITOR_MODE != hdd_get_conparam()) {
6064 hdd_err("Not supported, device is not in monitor mode");
6065 return -EINVAL;
6066 }
6067
Visweswara Tanuku006313a2018-04-12 12:26:34 +05306068 /* Validate Channel */
6069 if (!WLAN_REG_IS_24GHZ_CH(chan) && !WLAN_REG_IS_5GHZ_CH(chan)) {
6070 hdd_err("Channel %d Not supported", chan);
6071 return -EINVAL;
6072 }
6073
6074 if (WLAN_REG_IS_24GHZ_CH(chan)) {
6075 if (bandwidth == CH_WIDTH_80MHZ) {
6076 hdd_err("BW80 not possible in 2.4GHz band");
6077 return -EINVAL;
6078 }
6079 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 14) &&
6080 (bandwidth != CH_WIDTH_MAX)) {
6081 hdd_err("Only BW20 possible on channel 14");
6082 return -EINVAL;
6083 }
6084 }
6085
6086 if (WLAN_REG_IS_5GHZ_CH(chan)) {
6087 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 165) &&
6088 (bandwidth != CH_WIDTH_MAX)) {
6089 hdd_err("Only BW20 possible on channel 165");
6090 return -EINVAL;
6091 }
6092 }
6093
Jeff Johnsond9952752018-04-18 12:15:35 -07006094 hdd_debug("Set monitor mode Channel %d", chan);
6095 qdf_mem_zero(&roam_profile, sizeof(roam_profile));
6096 roam_profile.ChannelInfo.ChannelList = &ch_info->channel;
6097 roam_profile.ChannelInfo.numOfChannels = 1;
6098 roam_profile.phyMode = ch_info->phy_mode;
6099 roam_profile.ch_params.ch_width = bandwidth;
6100 hdd_select_cbmode(adapter, chan, &roam_profile.ch_params);
6101
6102 qdf_mem_copy(bssid.bytes, adapter->mac_addr.bytes,
6103 QDF_MAC_ADDR_SIZE);
6104
6105 ch_params.ch_width = bandwidth;
6106 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev, chan, 0, &ch_params);
6107 if (ch_params.ch_width == CH_WIDTH_INVALID) {
6108 hdd_err("Invalid capture channel or bandwidth for a country");
6109 return -EINVAL;
6110 }
6111 if (wlan_hdd_change_hw_mode_for_given_chnl(adapter, chan,
6112 POLICY_MGR_UPDATE_REASON_SET_OPER_CHAN)) {
6113 hdd_err("Failed to change hw mode");
6114 return -EINVAL;
6115 }
6116
Jeff Johnson16528362018-06-14 12:34:16 -07006117 status = sme_roam_channel_change_req(hdd_ctx->mac_handle,
6118 bssid, &ch_params,
Jeff Johnsond9952752018-04-18 12:15:35 -07006119 &roam_profile);
6120 if (status) {
6121 hdd_err("Status: %d Failed to set sme_roam Channel for monitor mode",
6122 status);
6123 }
6124
6125 adapter->mon_chan = chan;
6126 adapter->mon_bandwidth = bandwidth;
6127 return qdf_status_to_os_return(status);
6128}
Nirav Shah73713f72018-05-17 14:50:41 +05306129#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05306130
Wu Gaodf929f12018-05-25 18:12:25 +08006131#ifdef MSM_PLATFORM
6132/**
6133 * hdd_stop_p2p_go() - call cfg80211 API to stop P2P GO
6134 * @adapter: pointer to adapter
6135 *
6136 * This function calls cfg80211 API to stop P2P GO
6137 *
6138 * Return: None
6139 */
6140static void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6141{
6142 hdd_debug("[SSR] send stop ap to supplicant");
6143 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
6144}
6145
6146static inline void hdd_delete_sta(struct hdd_adapter *adapter)
6147{
6148}
6149#else
6150static inline void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6151{
6152}
6153
6154/**
6155 * hdd_delete_sta() - call cfg80211 API to delete STA
6156 * @adapter: pointer to adapter
6157 *
6158 * This function calls cfg80211 API to delete STA
6159 *
6160 * Return: None
6161 */
6162static void hdd_delete_sta(struct hdd_adapter *adapter)
6163{
6164 struct qdf_mac_addr bcast_mac = QDF_MAC_ADDR_BCAST_INIT;
6165
6166 hdd_debug("[SSR] send restart supplicant");
6167 /* event supplicant to restart */
6168 cfg80211_del_sta(adapter->dev,
6169 (const u8 *)&bcast_mac.bytes[0],
6170 GFP_KERNEL);
6171}
6172#endif
6173
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006174QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006175{
Jeff Johnson9d295242017-08-29 14:39:48 -07006176 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006177 eConnectionState connState;
6178
Dustin Brown491d54b2018-03-14 12:39:11 -07006179 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006180
Dustin Brown920397d2017-12-13 16:27:50 -08006181 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05306182 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08006183 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05306184
Yue Ma42654682018-01-11 16:55:24 -08006185 hdd_debug("[SSR] start adapter with device mode %s(%d)",
6186 hdd_device_mode_to_string(adapter->device_mode),
6187 adapter->device_mode);
6188
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006189 hdd_wmm_init(adapter);
6190
6191 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006192 case QDF_STA_MODE:
6193 case QDF_P2P_CLIENT_MODE:
6194 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006195
6196 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
6197 ->conn_info.connState;
6198
Krunal Sonib51eec72017-11-20 21:53:01 -08006199 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006200 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07006201 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006202
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006203 /* Indicate disconnect event to supplicant
6204 * if associated previously
6205 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006206 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07006207 eConnectionState_IbssConnected == connState ||
6208 eConnectionState_NotConnected == connState ||
6209 eConnectionState_IbssDisconnected == connState ||
6210 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006211 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006212
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006213 memset(&wrqu, '\0', sizeof(wrqu));
6214 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
6215 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
6216 wireless_send_event(adapter->dev, SIOCGIWAP,
6217 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07006218 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07006219 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006220
6221 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05306222 wlan_hdd_cfg80211_indicate_disconnect(
6223 adapter->dev, false,
6224 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006225 } else if (eConnectionState_Connecting == connState) {
6226 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006227 * Indicate connect failure to supplicant if we
6228 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006229 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306230 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306231 NULL, 0, NULL, 0,
6232 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006233 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006234 }
6235
6236 hdd_register_tx_flow_control(adapter,
6237 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08006238 hdd_tx_resume_cb,
6239 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006240
Alok Kumarb64650c2018-03-23 17:05:11 +05306241 hdd_nud_ignore_tracking(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006242 break;
6243
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006244 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006245 if (hdd_ctx->config->sap_internal_restart)
Krunal Sonib51eec72017-11-20 21:53:01 -08006246 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05306247
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006248 break;
6249
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006250 case QDF_P2P_GO_MODE:
Wu Gaodf929f12018-05-25 18:12:25 +08006251 hdd_delete_sta(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006252 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306253 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08006254 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306255 hdd_set_mon_rx_cb(adapter->dev);
6256 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
6257 adapter->mon_bandwidth);
6258 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006259 default:
6260 break;
6261 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07006262 /*
6263 * Action frame registered in one adapter which will
6264 * applicable to all interfaces
6265 */
6266 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006267 }
6268
Wu Gaodf929f12018-05-25 18:12:25 +08006269 hdd_for_each_adapter(hdd_ctx, adapter) {
6270 if (!hdd_is_interface_up(adapter))
6271 continue;
6272
6273 if (adapter->device_mode == QDF_P2P_GO_MODE)
6274 hdd_stop_p2p_go(adapter);
6275 }
6276
Dustin Browne74003f2018-03-14 12:51:58 -07006277 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006278
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306279 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006280}
6281
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006282QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006283 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006284{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306285 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006286 qdf_list_node_t *node;
6287
6288 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006289
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006290 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006291 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006292 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006293
6294 if (QDF_IS_STATUS_ERROR(status))
6295 return status;
6296
6297 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6298
6299 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006300}
6301
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006302QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006303 struct hdd_adapter *current_adapter,
6304 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006305{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306306 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006307 qdf_list_node_t *node;
6308
6309 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006310
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006311 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006312 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08006313 &current_adapter->node,
6314 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006315 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006316
6317 if (QDF_IS_STATUS_ERROR(status))
6318 return status;
6319
6320 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6321
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006322 return status;
6323}
6324
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006325QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006326 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006327{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306328 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006329
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006330 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006331 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006332 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006333
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006334 return status;
6335}
6336
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006337QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006338 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006339{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306340 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006341 qdf_list_node_t *node;
6342
6343 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006344
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006345 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006346 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006347 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006348
6349 if (QDF_IS_STATUS_ERROR(status))
6350 return status;
6351
6352 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6353
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006354 return status;
6355}
6356
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006357QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006358 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006359{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306360 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006361
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006362 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006363 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006364 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006365
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006366 return status;
6367}
6368
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006369QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006370 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006371{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306372 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006373
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006374 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006375 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006376 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006377
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006378 return status;
6379}
6380
Jeff Johnson9d295242017-08-29 14:39:48 -07006381struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006382 tSirMacAddr macAddr)
6383{
Jeff Johnson9d295242017-08-29 14:39:48 -07006384 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006385
Dustin Brown920397d2017-12-13 16:27:50 -08006386 hdd_for_each_adapter(hdd_ctx, adapter) {
6387 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
6388 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006389 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006390 }
6391
6392 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006393}
6394
Jeff Johnson9d295242017-08-29 14:39:48 -07006395struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006396 uint32_t vdev_id)
6397{
Jeff Johnson9d295242017-08-29 14:39:48 -07006398 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006399
Dustin Brown920397d2017-12-13 16:27:50 -08006400 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07006401 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006402 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006403 }
6404
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006405 return NULL;
6406}
6407
Abhishek Singh7996eb72015-12-30 17:24:02 +05306408/**
6409 * hdd_get_adapter_by_sme_session_id() - Return adapter with
6410 * the sessionid
6411 * @hdd_ctx: hdd context.
6412 * @sme_session_id: sme session is for the adapter to get.
6413 *
6414 * This function is used to get the adapter with provided session id
6415 *
6416 * Return: adapter pointer if found
6417 *
6418 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07006419struct hdd_adapter *
6420hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
6421 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306422{
Jeff Johnson9d295242017-08-29 14:39:48 -07006423 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306424
Dustin Brown920397d2017-12-13 16:27:50 -08006425 hdd_for_each_adapter(hdd_ctx, adapter) {
6426 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306427 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306428 }
Dustin Brown920397d2017-12-13 16:27:50 -08006429
Abhishek Singh7996eb72015-12-30 17:24:02 +05306430 return NULL;
6431}
6432
Jeff Johnson9d295242017-08-29 14:39:48 -07006433struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07006434 const char *iface_name)
6435{
Jeff Johnson9d295242017-08-29 14:39:48 -07006436 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006437
Dustin Brown920397d2017-12-13 16:27:50 -08006438 hdd_for_each_adapter(hdd_ctx, adapter) {
6439 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07006440 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006441 }
Dustin Brown920397d2017-12-13 16:27:50 -08006442
Naveen Rawat4edb6822017-04-12 10:09:17 -07006443 return NULL;
6444}
6445
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006446/**
6447 * hdd_get_adapter() - to get adapter matching the mode
6448 * @hdd_ctx: hdd context
6449 * @mode: adapter mode
6450 *
6451 * This routine will return the pointer to adapter matching
6452 * with the passed mode.
6453 *
6454 * Return: pointer to adapter or null
6455 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006456struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006457 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006458{
Jeff Johnson9d295242017-08-29 14:39:48 -07006459 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006460
Dustin Brown920397d2017-12-13 16:27:50 -08006461 hdd_for_each_adapter(hdd_ctx, adapter) {
6462 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006463 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006464 }
6465
6466 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006467}
6468
Jeff Johnson36a0abf2018-05-20 11:24:25 -07006469enum QDF_OPMODE hdd_get_device_mode(uint32_t session_id)
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306470{
6471 struct hdd_context *hdd_ctx;
6472 struct hdd_adapter *adapter;
6473
6474 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
6475 if (!hdd_ctx) {
6476 hdd_err("Invalid HDD context");
6477 return QDF_MAX_NO_OF_MODE;
6478 }
6479
6480 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
6481 if (!adapter) {
6482 hdd_err("Invalid HDD adapter");
6483 return QDF_MAX_NO_OF_MODE;
6484 }
6485
6486 return adapter->device_mode;
6487}
6488
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006489/**
6490 * hdd_get_operating_channel() - return operating channel of the device mode
6491 * @hdd_ctx: Pointer to the HDD context.
6492 * @mode: Device mode for which operating channel is required.
Jeff Johnson77f89bb2018-05-06 16:21:36 -07006493 * Supported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006494 * QDF_STA_MODE,
6495 * QDF_P2P_CLIENT_MODE,
6496 * QDF_SAP_MODE,
6497 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006498 *
6499 * This API returns the operating channel of the requested device mode
6500 *
6501 * Return: channel number. "0" id the requested device is not found OR it is
6502 * not connected.
6503 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006504uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006505 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006506{
Jeff Johnson9d295242017-08-29 14:39:48 -07006507 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006508 uint8_t operatingChannel = 0;
6509
Dustin Brown920397d2017-12-13 16:27:50 -08006510 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006511 if (mode == adapter->device_mode) {
6512 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006513 case QDF_STA_MODE:
6514 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006515 if (hdd_conn_is_connected
6516 (WLAN_HDD_GET_STATION_CTX_PTR
6517 (adapter))) {
6518 operatingChannel =
6519 (WLAN_HDD_GET_STATION_CTX_PTR
6520 (adapter))->conn_info.
6521 operationChannel;
6522 }
6523 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006524 case QDF_SAP_MODE:
6525 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006526 /* softap connection info */
6527 if (test_bit
6528 (SOFTAP_BSS_STARTED,
6529 &adapter->event_flags))
6530 operatingChannel =
6531 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07006532 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006533 break;
6534 default:
6535 break;
6536 }
6537
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006538 /* Found the device of interest. break the loop */
6539 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006540 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006541 }
Dustin Brown920397d2017-12-13 16:27:50 -08006542
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006543 return operatingChannel;
6544}
6545
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006546static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006547 hdd_ctx)
6548{
Jeff Johnson9d295242017-08-29 14:39:48 -07006549 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006550
Dustin Brown491d54b2018-03-14 12:39:11 -07006551 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006552
Dustin Brown920397d2017-12-13 16:27:50 -08006553 hdd_for_each_adapter(hdd_ctx, adapter) {
6554 if (adapter->device_mode == QDF_STA_MODE ||
6555 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6556 adapter->device_mode == QDF_IBSS_MODE ||
6557 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6558 adapter->device_mode == QDF_SAP_MODE ||
6559 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006560 hdd_unregister_wext(adapter->dev);
6561 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006562 }
6563
Dustin Browne74003f2018-03-14 12:51:58 -07006564 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006565
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306566 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006567}
6568
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006569QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006570{
Jeff Johnson9d295242017-08-29 14:39:48 -07006571 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006572
Dustin Brown491d54b2018-03-14 12:39:11 -07006573 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006574
Dustin Brown920397d2017-12-13 16:27:50 -08006575 hdd_for_each_adapter(hdd_ctx, adapter) {
6576 if (adapter->device_mode == QDF_STA_MODE ||
6577 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6578 adapter->device_mode == QDF_IBSS_MODE ||
6579 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6580 adapter->device_mode == QDF_SAP_MODE ||
6581 adapter->device_mode == QDF_P2P_GO_MODE) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006582 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006583 adapter->session_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05306584 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006585 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006586 }
6587
Dustin Browne74003f2018-03-14 12:51:58 -07006588 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006589
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306590 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006591}
6592
Dustin Brownf27bce82016-11-03 12:52:27 -07006593/**
6594 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
6595 * adapters
6596 * @hdd_ctx: The HDD context containing the adapters to operate on
6597 *
6598 * return: QDF_STATUS_SUCCESS
6599 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006600static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07006601{
Jeff Johnson9d295242017-08-29 14:39:48 -07006602 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07006603 int err;
6604
Dustin Brown491d54b2018-03-14 12:39:11 -07006605 hdd_enter();
Dustin Brownf27bce82016-11-03 12:52:27 -07006606
Dustin Brown920397d2017-12-13 16:27:50 -08006607 hdd_for_each_adapter(hdd_ctx, adapter) {
6608 if (adapter->device_mode == QDF_STA_MODE ||
6609 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6610 adapter->device_mode == QDF_IBSS_MODE ||
6611 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6612 adapter->device_mode == QDF_SAP_MODE ||
6613 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07006614 err = wlan_hdd_sched_scan_stop(adapter->dev);
6615 if (err)
6616 hdd_err("Unable to stop scheduled scan");
6617 }
Dustin Brownf27bce82016-11-03 12:52:27 -07006618 }
6619
Dustin Browne74003f2018-03-14 12:51:58 -07006620 hdd_exit();
Dustin Brownf27bce82016-11-03 12:52:27 -07006621
6622 return QDF_STATUS_SUCCESS;
6623}
6624
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006625#ifdef WLAN_NS_OFFLOAD
6626/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006627 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006628 * @hdd_ctx: Pointer to hdd context
6629 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006630 * Unregister for IPv6 address change notifications.
6631 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006632 * Return: None
6633 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006634static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006635{
6636 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006637}
6638
6639/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006640 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006641 * @hdd_ctx: Pointer to hdd context
6642 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006643 * Register for IPv6 address change notifications.
6644 *
6645 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006646 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006647static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006648{
6649 int ret;
6650
6651 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
6652 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006653 if (ret) {
6654 hdd_err("Failed to register IPv6 notifier: %d", ret);
6655 goto out;
6656 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006657
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006658 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006659out:
6660 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006661}
6662#else
6663/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006664 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006665 * @hdd_ctx: Pointer to hdd context
6666 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006667 * Unregister for IPv6 address change notifications.
6668 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006669 * Return: None
6670 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006671static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006672{
6673}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006674
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006675/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006676 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006677 * @hdd_ctx: Pointer to hdd context
6678 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006679 * Register for IPv6 address change notifications.
6680 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006681 * Return: None
6682 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006683static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006684{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006685 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006686}
6687#endif
6688
Alok Kumarb64650c2018-03-23 17:05:11 +05306689void hdd_set_disconnect_status(struct hdd_adapter *adapter, bool status)
6690{
6691 qdf_mutex_acquire(&adapter->disconnection_status_lock);
6692 adapter->disconnection_in_progress = status;
6693 qdf_mutex_release(&adapter->disconnection_status_lock);
6694 hdd_debug("setting disconnection status: %d", status);
6695}
6696
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006697/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006698 * hdd_register_notifiers - Register netdev notifiers.
6699 * @hdd_ctx: HDD context
6700 *
6701 * Register netdev notifiers like IPv4 and IPv6.
6702 *
6703 * Return: 0 on success and errno on failure
6704 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006705static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006706{
6707 int ret;
6708
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006709 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
6710 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306711 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006712
6713 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
6714 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
6715 if (ret) {
6716 hdd_err("Failed to register IPv4 notifier: %d", ret);
6717 goto unregister_ip6_notifier;
6718 }
6719
Alok Kumarb64650c2018-03-23 17:05:11 +05306720 ret = hdd_nud_register_netevent_notifier(hdd_ctx);
6721 if (ret) {
6722 hdd_err("Failed to register netevent notifier: %d",
6723 ret);
6724 goto unregister_inetaddr_notifier;
6725 }
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006726 return 0;
6727
Alok Kumarb64650c2018-03-23 17:05:11 +05306728unregister_inetaddr_notifier:
6729 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006730unregister_ip6_notifier:
6731 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006732out:
6733 return ret;
6734
6735}
6736
6737/**
6738 * hdd_unregister_notifiers - Unregister netdev notifiers.
6739 * @hdd_ctx: HDD context
6740 *
6741 * Unregister netdev notifiers like IPv4 and IPv6.
6742 *
6743 * Return: None.
6744 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006745void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006746{
Alok Kumarb64650c2018-03-23 17:05:11 +05306747 hdd_nud_unregister_netevent_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006748 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
6749
6750 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006751}
6752
6753/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006754 * hdd_exit_netlink_services - Exit netlink services
6755 * @hdd_ctx: HDD context
6756 *
6757 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
6758 * nl service.
6759 *
6760 * Return: None.
6761 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006762static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006763{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306764 spectral_scan_deactivate_service();
6765 cnss_diag_deactivate_service();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006766 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006767 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306768 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006769
6770 nl_srv_exit();
6771}
6772
6773/**
6774 * hdd_init_netlink_services- Init netlink services
6775 * @hdd_ctx: HDD context
6776 *
6777 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
6778 * nl service.
6779 *
6780 * Return: 0 on success and errno on failure.
6781 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006782static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006783{
6784 int ret;
6785
Ryan Hsuceddceb2016-04-28 10:20:14 -07006786 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006787 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006788 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006789 goto out;
6790 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07006791 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006792
Naveen Rawat910726a2017-03-06 11:42:51 -08006793 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006794 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006795 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006796 goto err_nl_srv;
6797 }
6798
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306799 ptt_sock_activate_svc();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006800
6801 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07006802 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006803 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006804
6805 ret = cnss_diag_activate_service();
6806 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006807 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006808 goto err_close_cesium;
6809 }
6810
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306811 spectral_scan_activate_service();
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08006812
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006813 return 0;
6814
6815err_close_cesium:
6816 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006817 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306818 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006819err_nl_srv:
6820 nl_srv_exit();
6821out:
6822 return ret;
6823}
6824
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006825/**
6826 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
6827 * @hdd_ctx: HDD context.
6828 *
6829 * Destroy RX wakelock.
6830 *
6831 * Return: None.
6832 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006833static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006834{
6835 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
6836}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006837
6838/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006839 * hdd_rx_wake_lock_create() - Create RX wakelock
6840 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006841 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006842 * Create RX wakelock.
6843 *
6844 * Return: None.
6845 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006846static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006847{
6848 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
6849}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006850
6851/**
Houston Hoffman160db392016-10-10 17:37:51 -07006852 * hdd_context_deinit() - Deinitialize HDD context
6853 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006854 *
Houston Hoffman160db392016-10-10 17:37:51 -07006855 * Deinitialize HDD context along with all the feature specific contexts but
6856 * do not free hdd context itself. Caller of this API is supposed to free
6857 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006858 *
Houston Hoffman160db392016-10-10 17:37:51 -07006859 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006860 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006861static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006862{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306863 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
6864
Houston Hoffman160db392016-10-10 17:37:51 -07006865 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006866
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006867 hdd_sap_context_destroy(hdd_ctx);
6868
6869 hdd_rx_wake_lock_destroy(hdd_ctx);
6870
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006871 hdd_scan_context_destroy(hdd_ctx);
6872
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006873 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006874
Houston Hoffman160db392016-10-10 17:37:51 -07006875 return 0;
6876}
6877
6878/**
6879 * hdd_context_destroy() - Destroy HDD context
6880 * @hdd_ctx: HDD context to be destroyed.
6881 *
6882 * Free config and HDD context as well as destroy all the resources.
6883 *
6884 * Return: None
6885 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006886static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07006887{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07006888 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05306889
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05306890 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
6891
Houston Hoffman160db392016-10-10 17:37:51 -07006892 hdd_context_deinit(hdd_ctx);
6893
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306894 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006895 hdd_ctx->config = NULL;
6896
Dustin Brown84f46ea2018-02-15 11:57:36 -08006897 cfg_release();
6898
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006899 wiphy_free(hdd_ctx->wiphy);
6900}
6901
6902/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306903 * wlan_destroy_bug_report_lock() - Destroy bug report lock
6904 *
6905 * This function is used to destroy bug report lock
6906 *
6907 * Return: None
6908 */
6909static void wlan_destroy_bug_report_lock(void)
6910{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07006911 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306912
6913 p_cds_context = cds_get_global_context();
6914 if (!p_cds_context) {
6915 hdd_err("cds context is NULL");
6916 return;
6917 }
6918
6919 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6920}
6921
6922/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006923 * hdd_wlan_exit() - HDD WLAN exit function
6924 * @hdd_ctx: Pointer to the HDD Context
6925 *
6926 * This is the driver exit point (invoked during rmmod)
6927 *
6928 * Return: None
6929 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006930static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006931{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006932 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306933 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006934
Dustin Brown491d54b2018-03-14 12:39:11 -07006935 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006936
Arun Khandavallifae92942016-08-01 13:31:08 +05306937 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006938
Prashanth Bhattaab004382016-10-11 16:08:11 -07006939 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006940
6941#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306942 if (QDF_TIMER_STATE_RUNNING ==
6943 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6944 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006945 }
6946
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306947 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306948 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006949 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006950 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006951 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6952 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6953 hdd_ctx->last_acs_channel_list = NULL;
6954 hdd_ctx->num_of_channels = 0;
6955 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006956#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006957
Arun Khandavallifae92942016-08-01 13:31:08 +05306958 mutex_lock(&hdd_ctx->iface_change_lock);
6959 driver_status = hdd_ctx->driver_status;
6960 mutex_unlock(&hdd_ctx->iface_change_lock);
6961
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006962 /*
6963 * Powersave Offload Case
6964 * Disable Idle Power Save Mode
6965 */
6966 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07006967 /* clear the scan queue in all the scenarios */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +05306968 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006969
Arun Khandavallifae92942016-08-01 13:31:08 +05306970 if (driver_status != DRIVER_MODULES_CLOSED) {
6971 hdd_unregister_wext_all_adapters(hdd_ctx);
6972 /*
6973 * Cancel any outstanding scan requests. We are about to close
6974 * all of our adapters, but an adapter structure is what SME
6975 * passes back to our callback function. Hence if there
6976 * are any outstanding scan requests then there is a
6977 * race condition between when the adapter is closed and
6978 * when the callback is invoked. We try to resolve that
6979 * race condition here by canceling any outstanding scans
6980 * before we close the adapters.
6981 * Note that the scans may be cancelled in an asynchronous
6982 * manner, so ideally there needs to be some kind of
6983 * synchronization. Rather than introduce a new
6984 * synchronization here, we will utilize the fact that we are
6985 * about to Request Full Power, and since that is synchronized,
6986 * the expectation is that by the time Request Full Power has
6987 * completed, all scans will be cancelled
6988 */
6989 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006990 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08006991 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08006992 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006993 }
6994
Arunk Khandavalli830c9692018-03-22 12:17:40 +05306995 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306996 unregister_netdevice_notifier(&hdd_netdev_notifier);
6997
Rachit Kankane30807332018-06-27 18:39:36 +05306998 qdf_dp_trace_deinit();
6999
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07007000 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05307001
Dustin Brown021cecd2017-12-11 13:56:43 -08007002 hdd_driver_memdump_deinit();
7003
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05307004 qdf_nbuf_deinit_replenish_timer();
7005
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05307006 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
7007 hdd_info("Release wakelock for monitor mode!");
7008 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
7009 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
7010 }
7011
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05307012 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
7013 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
7014 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
7015
Naveen Rawate02f8f52018-04-05 11:58:04 -07007016 osif_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007017
Dustin Brownd005ad82018-01-19 10:32:13 -08007018 hdd_close_all_adapters(hdd_ctx, false);
7019
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05307020 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307021 /*
7022 * If there is re_init failure wiphy would have already de-registered
7023 * check the wiphy status before un-registering again
7024 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05307025 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307026 wiphy_unregister(wiphy);
7027 wlan_hdd_cfg80211_deinit(wiphy);
7028 hdd_lpass_notify_stop(hdd_ctx);
7029 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07007030
Arun Khandavallifae92942016-08-01 13:31:08 +05307031 hdd_exit_netlink_services(hdd_ctx);
7032 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05307033#ifdef FEATURE_WLAN_CH_AVOID
7034 mutex_destroy(&hdd_ctx->avoid_freq_lock);
7035#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05307036
Abhishek Singhe9068f12017-03-31 14:14:52 +05307037 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
7038 if (driver_status)
7039 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07007040
Prashanth Bhatta527fd752016-04-28 12:35:23 -07007041 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007042}
7043
7044void __hdd_wlan_exit(void)
7045{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007046 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007047
Dustin Brown491d54b2018-03-14 12:39:11 -07007048 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007049
Anurag Chouhan6d760662016-02-20 16:05:43 +05307050 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007051 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007052 hdd_err("Invalid HDD Context");
Dustin Browne74003f2018-03-14 12:51:58 -07007053 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007054 return;
7055 }
7056
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007057 /* Do all the cleanup before deregistering the driver */
7058 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07007059
Dustin Browne74003f2018-03-14 12:51:58 -07007060 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007061}
7062
7063#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04007064/**
7065 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007066 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04007067 *
7068 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
7069 * Then new ACS request will do a fresh scan without reusing the cached
7070 * scan information.
7071 *
7072 * Return: void
7073 */
Tang Yingying523322d2017-01-17 23:28:43 +08007074static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007075{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007076 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Jeff Johnson16528362018-06-14 12:34:16 -07007077 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007078
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007079 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007080 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04007081 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
7082 qdf_mem_free(hdd_ctx->last_acs_channel_list);
7083 hdd_ctx->last_acs_channel_list = NULL;
7084 hdd_ctx->num_of_channels = 0;
7085 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007086
Jeff Johnson16528362018-06-14 12:34:16 -07007087 mac_handle = hdd_ctx->mac_handle;
7088 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007089 return;
Jeff Johnson16528362018-06-14 12:34:16 -07007090 sme_scan_flush_result(mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007091}
7092#endif
7093
7094#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07007095int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
7096 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007097{
7098 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307099 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07007100 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07007101 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007102
7103 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7104
7105 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307106 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007107 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307108
Jeff Johnson16528362018-06-14 12:34:16 -07007109 mac_handle = hdd_ctx->mac_handle;
7110 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007111 return -EINVAL;
7112
Jeff Johnson16528362018-06-14 12:34:16 -07007113 qdf_status = sme_notify_ht2040_mode(mac_handle, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007114 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307115 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007116 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007117 return -EINVAL;
7118 }
7119
7120 return 0;
7121}
7122#endif
7123
7124/**
7125 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
7126 * @state: state
7127 *
7128 * This function notifies FW with modem power status
7129 *
7130 * Return: 0 if successful, error number otherwise
7131 */
7132int hdd_wlan_notify_modem_power_state(int state)
7133{
7134 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307135 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007136 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07007137 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007138
Anurag Chouhan6d760662016-02-20 16:05:43 +05307139 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007140 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307141 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007142 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307143
Jeff Johnson16528362018-06-14 12:34:16 -07007144 mac_handle = hdd_ctx->mac_handle;
7145 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007146 return -EINVAL;
7147
Jeff Johnson16528362018-06-14 12:34:16 -07007148 qdf_status = sme_notify_modem_power_state(mac_handle, state);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307149 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007150 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007151 state);
7152 return -EINVAL;
7153 }
7154 return 0;
7155}
7156
7157/**
7158 *
7159 * hdd_post_cds_enable_config() - HDD post cds start config helper
7160 * @adapter - Pointer to the HDD
7161 *
7162 * Return: None
7163 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007164QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007165{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307166 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007167
7168 /*
7169 * Send ready indication to the HDD. This will kick off the MAC
7170 * into a 'running' state and should kick off an initial scan.
7171 */
Jeff Johnson16528362018-06-14 12:34:16 -07007172 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->mac_handle);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307173 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007174 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
7175 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307176 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007177 }
7178
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307179 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007180}
7181
Sourav Mohapatra92ea8d62018-02-05 10:03:10 +05307182struct hdd_adapter *hdd_get_first_valid_adapter(struct hdd_context *hdd_ctx)
7183{
7184 struct hdd_adapter *adapter;
7185
7186 hdd_for_each_adapter(hdd_ctx, adapter) {
7187 if (adapter && adapter->magic == WLAN_HDD_ADAPTER_MAGIC)
7188 return adapter;
7189 }
7190
7191 return NULL;
7192}
7193
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007194/* wake lock APIs for HDD */
7195void hdd_prevent_suspend(uint32_t reason)
7196{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307197 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007198}
7199
7200void hdd_allow_suspend(uint32_t reason)
7201{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307202 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007203}
7204
7205void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
7206{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05307207 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
7208 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007209}
7210
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007211/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007212QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007213{
Jeff Johnson16528362018-06-14 12:34:16 -07007214 return sme_init_chan_list(hdd_ctx->mac_handle,
Amar Singhal6f8592b2017-04-26 14:31:58 -07007215 hdd_ctx->reg.alpha2,
7216 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007217}
7218
7219/**
7220 * hdd_is_5g_supported() - check if hardware supports 5GHz
7221 * @hdd_ctx: Pointer to the hdd context
7222 *
7223 * HDD function to know if hardware supports 5GHz
7224 *
7225 * Return: true if hardware supports 5GHz
7226 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007227bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007228{
Amar Singhal58b45ef2017-08-01 13:43:54 -07007229 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08007230 return true;
7231
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08007232 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08007233 return true;
7234 else
7235 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007236}
7237
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007238static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007239{
7240 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07007241 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007242
7243 wiphy = hdd_ctx->wiphy;
7244
7245 /*
7246 * The channel information in
7247 * wiphy needs to be initialized before wiphy registration
7248 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007249 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
7250 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007251 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07007252 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007253 }
7254
7255#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
7256 wiphy->wowlan = &wowlan_support_reg_init;
7257#else
7258 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
7259 WIPHY_WOWLAN_MAGIC_PKT |
7260 WIPHY_WOWLAN_DISCONNECT |
7261 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
7262 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
7263 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
7264 WIPHY_WOWLAN_4WAY_HANDSHAKE |
7265 WIPHY_WOWLAN_RFKILL_RELEASE;
7266
7267 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
7268 WOW_MAX_FILTERS_PER_LIST);
7269 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
7270 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
7271#endif
Liangwei Dong0da14262018-07-03 03:30:23 -04007272 if (hdd_ctx->obss_scan_offload) {
7273 hdd_debug("wmi_service_obss_scan supported");
7274 } else if (hdd_ctx->config->nChannelBondingMode24GHz) {
7275 hdd_debug("enable wpa_supp obss_scan");
7276 wiphy->features |= NL80211_FEATURE_NEED_OBSS_SCAN;
7277 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007278
7279 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007280 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307281 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07007282 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307283 return ret_val;
7284 }
Amar Singhalac26de22018-06-22 12:53:06 -07007285
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007286 /* Check the kernel version for upstream commit aced43ce780dc5 that
7287 * has support for processing user cell_base hints when wiphy is
7288 * self managed or check the backport flag for the same.
7289 */
Amar Singhalac26de22018-06-22 12:53:06 -07007290#if defined CFG80211_USER_HINT_CELL_BASE_SELF_MANAGED || \
7291 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0))
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007292 hdd_send_wiphy_regd_sync_event(hdd_ctx);
7293#endif
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307294
Amar Singhal2d812012018-02-03 15:06:47 +08007295 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007296
Amar Singhale4f28ee2015-10-21 14:36:56 -07007297 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007298}
7299
Mohit Khannaca4173b2017-09-12 21:52:19 -07007300#ifdef MSM_PLATFORM
7301/**
7302 * hdd_display_periodic_stats() - Function to display periodic stats
7303 * @hdd_ctx - handle to hdd context
7304 * @bool data_in_interval - true, if data detected in bw time interval
7305 *
7306 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
7307 * Stats show up in wlan driver logs.
7308 *
7309 * Returns: None
7310 */
7311static inline
7312void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
7313 bool data_in_interval)
7314{
7315 static u32 counter;
7316 static bool data_in_time_period;
7317 ol_txrx_pdev_handle pdev;
7318
7319 if (hdd_ctx->config->periodic_stats_disp_time == 0)
7320 return;
7321
7322 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
7323 if (!pdev) {
7324 hdd_err("pdev is NULL");
7325 return;
7326 }
7327
7328 counter++;
7329 if (data_in_interval)
7330 data_in_time_period = data_in_interval;
7331
7332 if (counter * hdd_ctx->config->busBandwidthComputeInterval >=
7333 hdd_ctx->config->periodic_stats_disp_time * 1000) {
7334 if (data_in_time_period) {
7335 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
7336 CDP_TXRX_PATH_STATS,
7337 QDF_STATS_VERBOSITY_LEVEL_LOW);
7338 wlan_hdd_display_netif_queue_history
7339 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
7340 qdf_dp_trace_dump_stats();
7341 }
7342 counter = 0;
7343 data_in_time_period = false;
7344 }
7345}
7346
Ravi Joshie2331e82015-07-01 18:18:54 -07007347/**
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007348 * hdd_clear_rps_cpu_mask - clear RPS CPU mask for interfaces
7349 * @hdd_ctx: pointer to struct hdd_context
7350 *
7351 * Return: none
7352 */
7353static void hdd_clear_rps_cpu_mask(struct hdd_context *hdd_ctx)
7354{
7355 struct hdd_adapter *adapter;
7356
7357 hdd_for_each_adapter(hdd_ctx, adapter)
7358 hdd_send_rps_disable_ind(adapter);
7359}
7360
7361/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07007362 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07007363 * @hdd_ctx - handle to hdd context
7364 * @tx_packets - transmit packet count
7365 * @rx_packets - receive packet count
7366 *
7367 * The function controls the bus bandwidth and dynamic control of
7368 * tcp delayed ack configuration
7369 *
7370 * Returns: None
7371 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007372
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007373static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07007374 const uint64_t tx_packets,
7375 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007376{
Mohit Khannaca4173b2017-09-12 21:52:19 -07007377 u64 total_pkts = tx_packets + rx_packets;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007378 uint64_t temp_tx = 0, avg_rx = 0;
7379 uint64_t no_rx_offload_pkts = 0, avg_no_rx_offload_pkts = 0;
7380 uint64_t rx_offload_pkts = 0, avg_rx_offload_pkts = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007381 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08007382 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08007383 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007384 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007385 uint16_t index = 0;
7386 bool vote_level_change = false;
7387 bool rx_level_change = false;
7388 bool tx_level_change = false;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007389 bool rxthread_high_tput_req = false;
Mohit Khannaf7562c32018-07-05 17:42:36 -07007390 bool dptrace_high_tput_req;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007391 if (total_pkts > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007392 next_vote_level = PLD_BUS_WIDTH_HIGH;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007393 else if (total_pkts > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007394 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007395 else if (total_pkts > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007396 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07007397 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07007398 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007399
Mohit Khannaf7562c32018-07-05 17:42:36 -07007400 dptrace_high_tput_req =
7401 next_vote_level > PLD_BUS_WIDTH_NONE ? true : false;
7402
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007403 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07007404 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
7405 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007406 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007407 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007408 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007409 if ((next_vote_level == PLD_BUS_WIDTH_LOW) ||
7410 (next_vote_level == PLD_BUS_WIDTH_NONE)) {
Nirav Shahffc6a092016-06-09 16:09:08 +05307411 if (hdd_ctx->hbw_requested) {
7412 pld_remove_pm_qos(hdd_ctx->parent_dev);
7413 hdd_ctx->hbw_requested = false;
7414 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007415 if (hdd_ctx->dynamic_rps)
7416 hdd_clear_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007417 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05307418 if (!hdd_ctx->hbw_requested) {
7419 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
7420 hdd_ctx->hbw_requested = true;
7421 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007422 if (hdd_ctx->dynamic_rps)
7423 hdd_set_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007424 }
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007425
Manjunathappa Prakashcb6df762018-05-29 18:54:58 -07007426 if (hdd_ctx->config->napi_cpu_affinity_mask)
7427 hdd_napi_apply_throughput_policy(hdd_ctx,
7428 tx_packets,
7429 rx_packets);
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007430
7431 if (rx_packets < hdd_ctx->config->busBandwidthLowThreshold)
7432 hdd_disable_rx_ol_for_low_tput(hdd_ctx, true);
7433 else
7434 hdd_disable_rx_ol_for_low_tput(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007435 }
Mohit Khannae71e2262015-11-10 09:37:24 -08007436
Mohit Khannaf7562c32018-07-05 17:42:36 -07007437 qdf_dp_trace_apply_tput_policy(dptrace_high_tput_req);
7438
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007439 /*
7440 * Includes tcp+udp, if perf core is required for tcp, then
7441 * perf core is also required for udp.
7442 */
7443 no_rx_offload_pkts = hdd_ctx->no_rx_offload_pkt_cnt;
7444 hdd_ctx->no_rx_offload_pkt_cnt = 0;
7445 rx_offload_pkts = rx_packets - no_rx_offload_pkts;
Mohit Khannae71e2262015-11-10 09:37:24 -08007446
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007447 avg_no_rx_offload_pkts = (no_rx_offload_pkts +
7448 hdd_ctx->prev_no_rx_offload_pkts) / 2;
7449 hdd_ctx->prev_no_rx_offload_pkts = no_rx_offload_pkts;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08007450
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007451 avg_rx_offload_pkts = (rx_offload_pkts +
7452 hdd_ctx->prev_rx_offload_pkts) / 2;
7453 hdd_ctx->prev_rx_offload_pkts = rx_offload_pkts;
7454
7455 avg_rx = avg_no_rx_offload_pkts + avg_rx_offload_pkts;
7456 /*
7457 * Takes care to set Rx_thread affinity for below case
7458 * 1)LRO/GRO not supported ROME case
7459 * 2)when rx_ol is disabled in cases like concurrency etc
7460 * 3)For UDP cases
7461 */
7462 if (avg_no_rx_offload_pkts >
7463 hdd_ctx->config->busBandwidthHighThreshold)
7464 rxthread_high_tput_req = true;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307465 else
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007466 rxthread_high_tput_req = false;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307467
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007468 if (cds_sched_handle_throughput_req(rxthread_high_tput_req))
7469 hdd_warn("Rx thread high_tput(%d) affinity request failed",
7470 rxthread_high_tput_req);
7471
7472 /* fine-tuning parameters for RX Flows */
7473 if (avg_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
Ravi Joshifed83572016-10-07 16:20:37 -07007474 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
7475 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
7476 next_rx_level = WLAN_SVC_TP_HIGH;
7477 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07007478 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07007479 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08007480 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007481 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007482
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007483 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007484 struct wlan_rx_tp_data rx_tp_data = {0};
7485
Ravi Joshie2331e82015-07-01 18:18:54 -07007486 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Jeff Johnsonb9feee42018-07-08 10:34:48 -07007487 next_rx_level, avg_rx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007488 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007489 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07007490 /* Send throughput indication only if it is enabled.
7491 * Disabling tcp_del_ack will revert the tcp stack behavior
7492 * to default delayed ack. Note that this will disable the
7493 * dynamic delayed ack mechanism across the system
7494 */
Manjunathappa Prakashbfd12762018-04-29 22:44:52 -07007495 if (hdd_ctx->en_tcp_delack_no_lro)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007496 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
7497
Mohit Khanna6272fb682017-04-13 09:34:36 -07007498 if (hdd_ctx->config->enable_tcp_adv_win_scale)
7499 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
7500
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007501 rx_tp_data.level = next_rx_level;
7502 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7503 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
7504 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007505 }
7506
Mohit Khannae71e2262015-11-10 09:37:24 -08007507 /* fine-tuning parameters for TX Flows */
7508 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
7509 hdd_ctx->prev_tx = tx_packets;
7510 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
7511 next_tx_level = WLAN_SVC_TP_HIGH;
7512 else
7513 next_tx_level = WLAN_SVC_TP_LOW;
7514
Prakash Manjunathappae73e3b52018-02-27 18:56:22 -08007515 if ((hdd_ctx->config->enable_tcp_limit_output) &&
7516 (hdd_ctx->cur_tx_level != next_tx_level)) {
Mohit Khannae71e2262015-11-10 09:37:24 -08007517 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
7518 next_tx_level, temp_tx);
7519 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007520 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05307521 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7522 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08007523 &next_tx_level,
7524 sizeof(next_tx_level));
7525 }
7526
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007527 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007528 if (vote_level_change || tx_level_change || rx_level_change) {
7529 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
7530 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
7531 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
7532 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
7533 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
7534 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
7535 hdd_ctx->hdd_txrx_hist_idx++;
7536 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
7537 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07007538
7539 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007540}
7541
7542#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307543static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007544{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007545 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307546 bus_bw_work);
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307547 struct hdd_adapter *adapter = NULL, *con_sap_adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307548 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05307549 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
7550 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007551 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307552 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007553 bool connected = false;
7554 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
7555
Prashanth Bhattaab004382016-10-11 16:08:11 -07007556 if (wlan_hdd_validate_context(hdd_ctx))
7557 return;
7558
Jeff Johnson214671b2017-10-30 19:45:23 -07007559 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08007560 goto restart_timer;
7561
Dustin Brown920397d2017-12-13 16:27:50 -08007562 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05307563 /*
7564 * Validate magic so we don't end up accessing
7565 * an invalid adapter.
7566 */
7567 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
7568 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007569
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007570 if ((adapter->device_mode == QDF_STA_MODE ||
7571 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007572 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
7573 != eConnectionState_Associated) {
7574
7575 continue;
7576 }
7577
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007578 if ((adapter->device_mode == QDF_SAP_MODE ||
7579 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07007580 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007581
7582 continue;
7583 }
7584
7585 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
7586 adapter->prev_tx_packets);
7587 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
7588 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307589
7590 if (adapter->device_mode == QDF_SAP_MODE ||
7591 adapter->device_mode == QDF_P2P_GO_MODE ||
7592 adapter->device_mode == QDF_IBSS_MODE) {
7593
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08007594 ret = cdp_get_intra_bss_fwd_pkts_count(
7595 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007596 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307597 &fwd_tx_packets, &fwd_rx_packets);
7598 if (ret == A_OK) {
7599 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
7600 fwd_tx_packets,
7601 adapter->prev_fwd_tx_packets);
7602 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
7603 fwd_tx_packets,
7604 adapter->prev_fwd_rx_packets);
7605 }
7606 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007607
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307608 if (adapter->device_mode == QDF_SAP_MODE)
7609 con_sap_adapter = adapter;
7610
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007611 total_rx += adapter->stats.rx_packets;
7612 total_tx += adapter->stats.tx_packets;
7613
7614 spin_lock_bh(&hdd_ctx->bus_bw_lock);
7615 adapter->prev_tx_packets = adapter->stats.tx_packets;
7616 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307617 adapter->prev_fwd_tx_packets = fwd_tx_packets;
7618 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007619 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
7620 connected = true;
7621 }
7622
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007623 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007624 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007625 return;
7626 }
7627
Yun Parka29974a2018-04-09 12:05:49 -07007628 /* add intra bss forwarded tx and rx packets */
7629 tx_packets += fwd_tx_packets_diff;
7630 rx_packets += fwd_rx_packets_diff;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007631
Yun Parka29974a2018-04-09 12:05:49 -07007632 if (ucfg_ipa_is_fw_wdi_activated(hdd_ctx->hdd_pdev)) {
7633 ucfg_ipa_uc_stat_query(hdd_ctx->hdd_pdev, &ipa_tx_packets,
7634 &ipa_rx_packets);
7635 tx_packets += (uint64_t)ipa_tx_packets;
7636 rx_packets += (uint64_t)ipa_rx_packets;
7637
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307638 if (con_sap_adapter) {
7639 con_sap_adapter->stats.tx_packets += ipa_tx_packets;
7640 con_sap_adapter->stats.rx_packets += ipa_rx_packets;
7641 }
7642
Yun Parka29974a2018-04-09 12:05:49 -07007643 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, tx_packets, rx_packets);
7644 ucfg_ipa_uc_stat_request(hdd_ctx->hdd_pdev, 2);
7645 }
7646
7647 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007648
Jingxiang Gec64e1932017-08-22 14:38:59 +08007649restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08007650 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08007651 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08007652 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05307653 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08007654 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08007655 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007656}
Prashanth Bhattaab004382016-10-11 16:08:11 -07007657
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307658/**
7659 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
7660 * @arg: Argument of timer function
7661 *
7662 * Schedule a workqueue in this function where all the processing is done.
7663 *
7664 * Return: None.
7665 */
7666static void __hdd_bus_bw_cbk(void *arg)
7667{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007668 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307669
7670 if (wlan_hdd_validate_context(hdd_ctx))
7671 return;
7672
7673 schedule_work(&hdd_ctx->bus_bw_work);
7674}
7675
7676/**
7677 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
7678 * @arg: Argument of timer function
7679 *
7680 * Return: None.
7681 */
7682static void hdd_bus_bw_cbk(void *arg)
7683{
7684 cds_ssr_protect(__func__);
7685 __hdd_bus_bw_cbk(arg);
7686 cds_ssr_unprotect(__func__);
7687}
7688
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007689int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007690{
7691 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307692 INIT_WORK(&hdd_ctx->bus_bw_work,
7693 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08007694 hdd_ctx->bus_bw_timer_running = false;
7695 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307696 qdf_timer_init(NULL,
7697 &hdd_ctx->bus_bw_timer,
7698 hdd_bus_bw_cbk, (void *)hdd_ctx,
7699 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007700
7701 return 0;
7702}
7703
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007704void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007705{
Dustin Brownfce08d12017-01-17 16:29:38 -08007706 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007707 hdd_reset_tcp_delack(hdd_ctx);
7708
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007709 hdd_debug("wait for bus bw work to flush");
Nirav Shaheb017be2018-02-15 11:20:58 +05307710 hdd_cancel_bus_bw_work(hdd_ctx);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307711 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08007712 hdd_ctx->bus_bw_timer_running = false;
7713 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007714}
Lin Baic5c06882017-09-21 13:58:43 +08007715
7716void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
7717{
7718 if (hdd_ctx)
7719 cancel_work_sync(&hdd_ctx->bus_bw_work);
7720}
jiadcdaf9bd2017-10-26 12:20:21 +08007721
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007722#endif
7723
7724/**
Nirav Shahed34b212016-04-25 10:59:16 +05307725 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
7726 * @hdd_ctx: hdd context
7727 *
7728 * Return: 0 for success or error code
7729 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007730static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307731{
7732 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
7733 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
7734 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007735 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05307736 return -ENOMEM;
7737 }
7738 return 0;
7739}
7740
7741/**
7742 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
7743 * @hdd_ctx: hdd context
7744 *
7745 * Return: none
7746 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007747void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307748{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307749 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
7750 return;
7751
7752 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
7753 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05307754}
7755
Nirav Shahda008342016-05-17 18:50:40 +05307756static uint8_t *convert_level_to_string(uint32_t level)
7757{
7758 switch (level) {
7759 /* initialize the wlan sub system */
7760 case WLAN_SVC_TP_NONE:
7761 return "NONE";
7762 case WLAN_SVC_TP_LOW:
7763 return "LOW";
7764 case WLAN_SVC_TP_MEDIUM:
7765 return "MED";
7766 case WLAN_SVC_TP_HIGH:
7767 return "HIGH";
7768 default:
7769 return "INVAL";
7770 }
7771}
7772
Nirav Shahed34b212016-04-25 10:59:16 +05307773
7774/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007775 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
7776 * @hdd_ctx: hdd context
7777 *
7778 * Return: none
7779 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007780void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007781{
7782 int i;
7783
7784#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007785 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05307786 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007787 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007788 hdd_ctx->config->busBandwidthHighThreshold,
7789 hdd_ctx->config->busBandwidthMediumThreshold,
7790 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007791 hdd_debug("Enable TCP DEL ACK: %d",
Manjunathappa Prakashbfd12762018-04-29 22:44:52 -07007792 hdd_ctx->en_tcp_delack_no_lro);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007793 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007794 hdd_ctx->config->tcpDelackThresholdHigh,
7795 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007796 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05307797 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007798#endif
7799
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007800 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307801 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
7802
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007803 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007804
7805 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007806 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007807 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Dustin Brown632af712018-03-14 15:03:55 -07007808 hdd_debug("[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
7809 i, hdd_ctx->hdd_txrx_hist[i].qtime,
7810 hdd_ctx->hdd_txrx_hist[i].interval_rx,
7811 hdd_ctx->hdd_txrx_hist[i].interval_tx,
7812 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007813 hdd_ctx->hdd_txrx_hist[i].
7814 next_vote_level),
Dustin Brown632af712018-03-14 15:03:55 -07007815 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007816 hdd_ctx->hdd_txrx_hist[i].
7817 next_rx_level),
Dustin Brown632af712018-03-14 15:03:55 -07007818 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007819 hdd_ctx->hdd_txrx_hist[i].
7820 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007821 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007822}
7823
7824/**
7825 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
7826 * @hdd_ctx: hdd context
7827 *
7828 * Return: none
7829 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007830void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007831{
7832 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05307833 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
7834 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007835}
7836
Mohit Khannaca4173b2017-09-12 21:52:19 -07007837/* length of the netif queue log needed per adapter */
7838#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
7839
7840/**
7841 *
7842 * hdd_display_netif_queue_history_compact() - display compact netifq history
7843 * @hdd_ctx: hdd context
7844 *
7845 * Return: none
7846 */
7847static void
7848hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
7849{
7850 int adapter_num = 0;
7851 int i;
7852 int bytes_written;
7853 u32 tbytes;
7854 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007855 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08007856 char *comb_log_str;
7857 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007858 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007859
jiadbdefb252018-01-03 14:27:06 +08007860 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * MAX_NUMBER_OF_ADAPTERS) + 1;
7861 comb_log_str = qdf_mem_malloc(comb_log_str_size);
7862 if (!comb_log_str) {
7863 hdd_err("failed to alloc comb_log_str");
7864 return;
7865 }
7866
Mohit Khannaca4173b2017-09-12 21:52:19 -07007867 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007868
Dustin Brown920397d2017-12-13 16:27:50 -08007869 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007870 curr_time = qdf_system_ticks();
7871 total = curr_time - adapter->start_time;
7872 delta = curr_time - adapter->last_time;
7873
7874 if (adapter->pause_map) {
7875 pause = adapter->total_pause_time + delta;
7876 unpause = adapter->total_unpause_time;
7877 } else {
7878 unpause = adapter->total_unpause_time + delta;
7879 pause = adapter->total_pause_time;
7880 }
7881
7882 tbytes = 0;
7883 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7884 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7885 if (adapter->queue_oper_stats[i].pause_count == 0)
7886 continue;
7887 tbytes +=
7888 snprintf(
7889 &temp_str[tbytes],
7890 (tbytes >= sizeof(temp_str) ?
7891 0 : sizeof(temp_str) - tbytes),
7892 "%d(%d,%d) ",
7893 i,
7894 adapter->queue_oper_stats[i].
7895 pause_count,
7896 adapter->queue_oper_stats[i].
7897 unpause_count);
7898 }
7899 if (tbytes >= sizeof(temp_str))
7900 hdd_warn("log truncated");
7901
7902 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08007903 bytes_written >= comb_log_str_size ? 0 :
7904 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007905 "[%d %d] (%d) %u/%ums %s|",
7906 adapter->session_id, adapter->device_mode,
7907 adapter->pause_map,
7908 qdf_system_ticks_to_msecs(pause),
7909 qdf_system_ticks_to_msecs(total),
7910 temp_str);
7911
Mohit Khannaca4173b2017-09-12 21:52:19 -07007912 adapter_num++;
7913 }
7914
7915 /* using QDF_TRACE to avoid printing function name */
7916 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
7917 "STATS |%s", comb_log_str);
7918
jiadbdefb252018-01-03 14:27:06 +08007919 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007920 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08007921
7922 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007923}
7924
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007925/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007926 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07007927 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007928 *
7929 * Return: none
7930 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007931void
7932wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
7933 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007934{
7935
Jeff Johnson9d295242017-08-29 14:39:48 -07007936 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007937 int i;
Nirav Shahda008342016-05-17 18:50:40 +05307938 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007939
Mohit Khannaca4173b2017-09-12 21:52:19 -07007940 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
7941 hdd_display_netif_queue_history_compact(hdd_ctx);
7942 return;
7943 }
7944
Dustin Brown920397d2017-12-13 16:27:50 -08007945 hdd_for_each_adapter(hdd_ctx, adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007946 hdd_debug("Netif queue operation statistics:");
7947 hdd_debug("Session_id %d device mode %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07007948 adapter->session_id, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007949 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05307950 curr_time = qdf_system_ticks();
7951 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05307952 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05307953 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05307954 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307955 unpause = adapter->total_unpause_time;
7956 } else {
Nirav Shahda008342016-05-17 18:50:40 +05307957 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307958 pause = adapter->total_pause_time;
7959 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007960 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05307961 qdf_system_ticks_to_msecs(total),
7962 qdf_system_ticks_to_msecs(pause),
7963 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007964 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007965
Nirav Shahda008342016-05-17 18:50:40 +05307966 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7967 qdf_time_t pause_delta = 0;
7968
7969 if (adapter->pause_map & (1 << i))
7970 pause_delta = delta;
7971
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007972 /* using hdd_log to avoid printing function name */
Dustin Brown632af712018-03-14 15:03:55 -07007973 hdd_debug("%s: %d: %d: %ums",
7974 hdd_reason_type_to_string(i),
7975 adapter->queue_oper_stats[i].pause_count,
7976 adapter->queue_oper_stats[i].unpause_count,
7977 qdf_system_ticks_to_msecs(
7978 adapter->queue_oper_stats[i].total_pause_time +
7979 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007980 }
7981
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007982 hdd_debug("Netif queue operation history:");
7983 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05307984 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
7985
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007986 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007987
7988 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007989 /* using hdd_log to avoid printing function name */
7990 if (adapter->queue_oper_history[i].time == 0)
7991 continue;
Dustin Brown632af712018-03-14 15:03:55 -07007992 hdd_debug("%d: %u: %s: %s: %x",
7993 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007994 adapter->queue_oper_history[i].time),
Dustin Brown632af712018-03-14 15:03:55 -07007995 hdd_action_type_to_string(
7996 adapter->queue_oper_history[i].netif_action),
7997 hdd_reason_type_to_string(
7998 adapter->queue_oper_history[i].netif_reason),
7999 adapter->queue_oper_history[i].pause_map);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008000 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008001 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008002}
8003
8004/**
8005 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
8006 * @hdd_ctx: hdd context
8007 *
8008 * Return: none
8009 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008010void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008011{
Jeff Johnson9d295242017-08-29 14:39:48 -07008012 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008013
Dustin Brown920397d2017-12-13 16:27:50 -08008014 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308015 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008016 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308017 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008018 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05308019 adapter->history_index = 0;
8020 adapter->start_time = adapter->last_time = qdf_system_ticks();
8021 adapter->total_pause_time = 0;
8022 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008023 }
8024}
8025
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008026#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
8027/**
8028 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
8029 * @hdd_ctx: hdd global context
8030 *
8031 * Return: none
8032 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008033static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008034{
8035 uint8_t i;
8036
8037 mutex_init(&hdd_ctx->op_ctx.op_lock);
8038 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
8039 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
8040 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
8041 }
8042}
8043#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008044static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008045{
8046}
8047#endif
8048
Yingying Tang95409972016-10-20 15:16:15 +08008049#ifdef WLAN_FEATURE_WOW_PULSE
8050/**
8051 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008052 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08008053 * @enable: enable or disable this behaviour
8054 *
8055 * Return: int
8056 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008057static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008058{
8059 struct hdd_config *pcfg_ini = phddctx->config;
8060 struct wow_pulse_mode wow_pulse_set_info;
8061 QDF_STATUS status;
8062
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008063 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08008064
8065 if (false == phddctx->config->wow_pulse_support)
8066 return 0;
8067
8068 /* prepare the request to send to SME */
8069 if (enable == true) {
8070 wow_pulse_set_info.wow_pulse_enable = true;
8071 wow_pulse_set_info.wow_pulse_pin =
8072 pcfg_ini->wow_pulse_pin;
8073 wow_pulse_set_info.wow_pulse_interval_low =
8074 pcfg_ini->wow_pulse_interval_low;
8075 wow_pulse_set_info.wow_pulse_interval_high =
8076 pcfg_ini->wow_pulse_interval_high;
8077 } else {
8078 wow_pulse_set_info.wow_pulse_enable = false;
8079 wow_pulse_set_info.wow_pulse_pin = 0;
8080 wow_pulse_set_info.wow_pulse_interval_low = 0;
8081 wow_pulse_set_info.wow_pulse_interval_high = 0;
8082 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008083 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08008084 wow_pulse_set_info.wow_pulse_enable,
8085 wow_pulse_set_info.wow_pulse_pin,
8086 wow_pulse_set_info.wow_pulse_interval_low,
8087 wow_pulse_set_info.wow_pulse_interval_high);
8088
8089 status = sme_set_wow_pulse(&wow_pulse_set_info);
8090 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008091 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08008092 return -EIO;
8093 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008094 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08008095 return 0;
8096}
8097#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008098static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008099{
8100 return 0;
8101}
8102#endif
8103
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008104#ifdef WLAN_FEATURE_FASTPATH
8105/**
8106 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
8107 * @hdd_cfg: hdd config
8108 * @context: lower layer context
8109 *
8110 * Return: none
8111 */
Arun Khandavallifae92942016-08-01 13:31:08 +05308112void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008113 void *context)
8114{
8115 if (hdd_cfg->fastpath_enable)
8116 hif_enable_fastpath(context);
8117}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008118#endif
8119
Yuanyuan Liu13738502016-04-06 17:41:37 -07008120#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008121/**
8122 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008123 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008124 * @level: thermal level
8125 *
8126 * Change IPA data path to SW path when the thermal throttle level greater
8127 * than 0, and restore the original data path when throttle level is 0
8128 *
8129 * Return: none
8130 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008131static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008132{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008133 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008134
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008135 /* Change IPA to SW path when throttle level greater than 0 */
8136 if (level > THROTTLE_LEVEL_0)
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308137 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008138 else
8139 /* restore original concurrency mode */
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308140 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, hdd_ctx->mcc_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008141}
8142
8143/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308144 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
8145 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05308146 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008147 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308148 * Get a safe channel to restart SAP. PCL already takes into account the
8149 * unsafe channels. So, the PCL is validated with the ACS range to provide
8150 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008151 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308152 * Return: Channel number to restart SAP in case of success. In case of any
8153 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008154 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308155static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07008156 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008157{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308158 struct sir_pcl_list pcl;
8159 QDF_STATUS status;
8160 uint32_t i, j;
Jeff Johnson16528362018-06-14 12:34:16 -07008161 mac_handle_t mac_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008162 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308163 bool found = false;
Liangwei Dong17bf2662018-01-05 02:02:05 -05008164 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008165
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308166 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8167 if (!hdd_ctx) {
8168 hdd_err("invalid HDD context");
8169 return INVALID_CHANNEL_ID;
8170 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008171
Jeff Johnson16528362018-06-14 12:34:16 -07008172 mac_handle = hdd_ctx->mac_handle;
8173 if (!mac_handle) {
8174 hdd_err("invalid MAC handle");
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05308175 return INVALID_CHANNEL_ID;
8176 }
8177
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008178 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
8179 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08008180 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
8181 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308182 if (QDF_IS_STATUS_ERROR(status)) {
8183 hdd_err("Get PCL failed");
8184 return INVALID_CHANNEL_ID;
8185 }
8186
Frank Liudc2cefb2017-06-21 15:38:18 +08008187 /*
8188 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
8189 * channel is unsafe channel, the pcl may be empty, instead of return,
8190 * try to choose a safe channel from acs range.
8191 */
8192 if (!pcl.pcl_len)
8193 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308194
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008195 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07008196 adapter->session.ap.sap_config.acs_cfg.start_ch,
8197 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308198
8199 /* PCL already takes unsafe channel into account */
8200 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008201 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308202 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008203 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308204 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008205 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008206 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308207 return pcl.pcl_list[i];
8208 }
8209 }
8210
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008211 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308212
8213 /* Try for safe channel from all valid channel */
8214 pcl.pcl_len = MAX_NUM_CHAN;
Liangwei Dong17bf2662018-01-05 02:02:05 -05008215 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
8216 &pcl.pcl_len);
8217 if (ret) {
8218 hdd_err("error %d in getting valid channel list", ret);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308219 return INVALID_CHANNEL_ID;
8220 }
8221
8222 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008223 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308224 found = false;
8225 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07008226 if (pcl.pcl_list[i] ==
8227 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008228 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308229 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008230 break;
8231 }
8232 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308233
8234 if (found)
8235 continue;
8236
8237 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008238 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308239 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008240 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008241 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308242 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008243 }
8244 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308245
8246 return INVALID_CHANNEL_ID;
8247}
Nirav Shaheb017be2018-02-15 11:20:58 +05308248#endif
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308249
8250/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008251 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308252 * @adapter: AP adapter
8253 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08008254 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308255 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008256 * Moves the SAP interface by invoking the function which
8257 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308258 *
8259 * Return: None
8260 */
Min Liu2fef5792018-01-19 17:59:42 +08008261void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
8262 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308263{
Jeff Johnson87251032017-08-29 13:31:11 -07008264 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008265 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07008266 mac_handle_t mac_handle;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308267
8268 if (!adapter) {
8269 hdd_err("invalid adapter");
8270 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008271 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308272
8273 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
8274
Jeff Johnson16528362018-06-14 12:34:16 -07008275 mac_handle = hdd_adapter_get_mac_handle(adapter);
8276 if (!mac_handle) {
8277 hdd_err("invalid MAC handle");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308278 return;
8279 }
8280
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008281 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8282
Jeff Johnson91df29d2017-10-27 19:29:50 -07008283 hdd_ap_ctx->sap_config.channel = channel;
Himanshu Agarwalf5c5b102018-05-22 20:13:57 +05308284 hdd_ap_ctx->sap_config.ch_params.ch_width = CH_WIDTH_MAX;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308285
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008286 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07008287 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308288
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07008289 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07008290 hdd_ap_ctx->sap_config.channel,
8291 hdd_ap_ctx->sap_config.sec_ch,
8292 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308293
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008294 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07008295 adapter->session_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08008296 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008297}
Kapil Gupta8878ad92017-02-13 11:56:04 +05308298
Jeff Johnson9d295242017-08-29 14:39:48 -07008299int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05308300{
8301 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308302 int status;
8303 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308304
8305 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8306
8307 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07008308 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05308309 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07008310 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308311 }
8312 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07008313 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308314 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308315 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07008316 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308317 WLAN_VENDOR_ACS_WAIT_TIME);
8318 if (qdf_status != QDF_STATUS_SUCCESS) {
8319 hdd_err("failed to start external acs timer");
8320 return -ENOSPC;
8321 }
8322 /* Update config to application */
8323 status = hdd_cfg80211_update_acs_config(adapter, reason);
Dustin Brown5e89ef82018-03-14 11:50:23 -07008324 hdd_info("Updated ACS config to nl with reason %d", reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308325
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308326 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308327}
8328
Nirav Shaheb017be2018-02-15 11:20:58 +05308329#if defined(FEATURE_WLAN_CH_AVOID)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308330/**
8331 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
8332 * @hdd_ctx: hdd context pointer
8333 *
8334 * hdd_unsafe_channel_restart_sap check all unsafe channel list
8335 * and if ACS is enabled, driver will ask userspace to restart the
8336 * sap. User space on LTE coex indication restart driver.
8337 *
8338 * Return - none
8339 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008340void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308341{
Dustin Brown920397d2017-12-13 16:27:50 -08008342 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308343 uint32_t i;
8344 bool found = false;
8345 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008346
Dustin Brown920397d2017-12-13 16:27:50 -08008347 hdd_for_each_adapter(hdd_ctxt, adapter) {
8348 if (!(adapter->device_mode == QDF_SAP_MODE &&
8349 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008350 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08008351 adapter->device_mode,
8352 adapter->session.ap.sap_config.
8353 acs_cfg.acs_mode);
8354 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308355 }
8356
8357 found = false;
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008358 /*
8359 * If STA+SAP is doing SCC & g_sta_sap_scc_on_lte_coex_chan
8360 * is set, no need to move SAP.
8361 */
8362 if (policy_mgr_is_sta_sap_scc(hdd_ctxt->hdd_psoc,
8363 adapter->session.ap.operating_channel) &&
8364 hdd_ctxt->config->sta_sap_scc_on_lte_coex_chan)
8365 hdd_debug("SAP is allowed on SCC channel, no need to move SAP");
8366 else {
8367 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
8368 if (adapter->session.ap.operating_channel ==
8369 hdd_ctxt->unsafe_channel_list[i]) {
8370 found = true;
8371 hdd_debug("operating ch:%d is unsafe",
8372 adapter->session.ap.operating_channel);
8373 break;
8374 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308375 }
8376 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308377 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008378 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08008379 adapter->session.ap.operating_channel);
8380 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308381 }
8382
Kapil Gupta8878ad92017-02-13 11:56:04 +05308383 if (hdd_ctxt->config->vendor_acs_support &&
8384 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08008385 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05308386 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08008387 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308388 } else
8389 restart_chan =
8390 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08008391 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308392 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008393 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308394 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008395 /*
8396 * SAP restart due to unsafe channel. While
8397 * restarting the SAP, make sure to clear
8398 * acs_channel, channel to reset to
8399 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308400 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008401 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308402 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown920397d2017-12-13 16:27:50 -08008403 adapter->session.ap.sap_config.channel =
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308404 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008405 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308406 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
8407 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04008408 hdd_debug("driver to start sap: %d",
8409 hdd_ctxt->config->sap_internal_restart);
8410 if (hdd_ctxt->config->sap_internal_restart)
Min Liu2fef5792018-01-19 17:59:42 +08008411 hdd_switch_sap_channel(adapter, restart_chan,
8412 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04008413 else
8414 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308415 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308416 }
8417}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05308418
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008419/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008420 * hdd_init_channel_avoidance() - Initialize channel avoidance
8421 * @hdd_ctx: HDD global context
8422 *
8423 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07008424 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008425 * down to the lower layers. Then subscribe to subsequent channel
8426 * avoidance events.
8427 *
8428 * Return: None
8429 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008430static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008431{
8432 uint16_t unsafe_channel_count;
8433 int index;
8434
Yuanyuan Liu13738502016-04-06 17:41:37 -07008435 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
8436 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008437 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08008438 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008439
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008440 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008441 hdd_ctx->unsafe_channel_count);
8442
Anurag Chouhan6d760662016-02-20 16:05:43 +05308443 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08008444 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008445
8446 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008447 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008448 hdd_ctx->unsafe_channel_list[index]);
8449
8450 }
8451
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008452}
Dustin Brown676a2322017-08-15 13:16:13 -07008453
Jeff Johnson9d295242017-08-29 14:39:48 -07008454static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008455 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008456{
8457 uint8_t restart_chan;
8458
8459 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
8460 if (!restart_chan) {
8461 hdd_alert("fail to restart SAP");
8462 return;
8463 }
8464
8465 /* SAP restart due to unsafe channel. While restarting
8466 * the SAP, make sure to clear acs_channel, channel to
8467 * reset to 0. Otherwise these settings will override
8468 * the ACS while restart.
8469 */
8470 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07008471 adapter->session.ap.sap_config.channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07008472
8473 hdd_debug("sending coex indication");
8474
8475 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
8476 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08008477 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07008478}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008479
8480int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
8481 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
8482{
8483 uint32_t size;
8484 uint16_t *unsafe_list;
8485 uint16_t chan_count;
8486
8487 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
8488 return -EINVAL;
8489
8490 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
8491 NUM_CHANNELS);
8492 if (chan_count) {
8493 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
8494 unsafe_list = qdf_mem_malloc(size);
8495 if (!unsafe_list) {
8496 hdd_err("No memory for unsafe chan list size%d",
8497 size);
8498 return -ENOMEM;
8499 }
8500 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
8501 } else {
8502 unsafe_list = NULL;
8503 }
8504
8505 *local_unsafe_list = unsafe_list;
8506 *local_unsafe_list_count = chan_count;
8507
8508 return 0;
8509}
8510
8511bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
8512 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
8513{
8514 int i, j;
8515
8516 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
8517 return true;
8518 if (local_unsafe_list_count == 0)
8519 return false;
8520 for (i = 0; i < local_unsafe_list_count; i++) {
8521 for (j = 0; j < local_unsafe_list_count; j++)
8522 if (local_unsafe_list[i] ==
8523 hdd_ctx->unsafe_channel_list[j])
8524 break;
8525 if (j >= local_unsafe_list_count)
8526 break;
8527 }
8528 if (i >= local_unsafe_list_count) {
8529 hdd_info("unsafe chan list same");
8530 return false;
8531 }
8532
8533 return true;
8534}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008535#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008536static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008537{
8538}
Dustin Brown676a2322017-08-15 13:16:13 -07008539
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008540static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008541{
8542}
Dustin Brown676a2322017-08-15 13:16:13 -07008543
Jeff Johnson9d295242017-08-29 14:39:48 -07008544static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008545 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008546{
8547 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
8548}
Yuanyuan Liu13738502016-04-06 17:41:37 -07008549#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008550
8551/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08008552 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
8553 * user space
8554 * @frame_ind: Management frame data to be informed.
8555 *
8556 * This function is used to indicate management frame to
8557 * user space
8558 *
8559 * Return: None
8560 *
8561 */
8562void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
8563{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008564 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07008565 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008566 int i;
8567
Dustin Browne7e71d32018-05-11 16:00:08 -07008568 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
8569 if (wlan_hdd_validate_context(hdd_ctx))
Rajeev Kumard004abc2016-02-17 12:09:56 -08008570 return;
8571
8572 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
8573 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
8574 adapter =
8575 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
8576 if (adapter)
8577 break;
8578 }
Wu Gaoa0230a62018-01-04 20:56:57 +08008579 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
8580 hdd_for_each_adapter(hdd_ctx, adapter) {
8581 if ((NULL != adapter) &&
8582 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
8583 __hdd_indicate_mgmt_frame(adapter,
8584 frame_ind->frame_len,
8585 frame_ind->frameBuf,
8586 frame_ind->frameType,
8587 frame_ind->rxChan,
8588 frame_ind->rxRssi);
8589 }
8590 }
8591 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008592 } else {
8593 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
8594 frame_ind->sessionId);
8595 }
8596
8597 if ((NULL != adapter) &&
8598 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
8599 __hdd_indicate_mgmt_frame(adapter,
8600 frame_ind->frame_len,
8601 frame_ind->frameBuf,
8602 frame_ind->frameType,
8603 frame_ind->rxChan,
8604 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008605}
8606
Kapil Gupta8878ad92017-02-13 11:56:04 +05308607void hdd_acs_response_timeout_handler(void *context)
8608{
8609 struct hdd_external_acs_timer_context *timer_context =
8610 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07008611 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008612 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308613 uint8_t reason;
8614
Dustin Brown491d54b2018-03-14 12:39:11 -07008615 hdd_enter();
Kapil Gupta8878ad92017-02-13 11:56:04 +05308616 if (!timer_context) {
8617 hdd_err("invlaid timer context");
8618 return;
8619 }
8620 adapter = timer_context->adapter;
8621 reason = timer_context->reason;
8622
8623
8624 if ((!adapter) ||
8625 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
8626 hdd_err("invalid adapter or adapter has invalid magic");
8627 return;
8628 }
8629 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8630 if (wlan_hdd_validate_context(hdd_ctx))
8631 return;
8632
8633 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
8634 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8635 else
8636 return;
8637
8638 hdd_err("ACS timeout happened for %s reason %d",
8639 adapter->dev->name, reason);
Jeff Johnson16528362018-06-14 12:34:16 -07008640
Kapil Gupta8878ad92017-02-13 11:56:04 +05308641 switch (reason) {
8642 /* SAP init case */
8643 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
8644 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
8645 false);
8646 wlan_hdd_cfg80211_start_acs(adapter);
8647 break;
8648 /* DFS detected on current channel */
8649 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
8650 wlan_sap_update_next_channel(
8651 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
Jeff Johnson16528362018-06-14 12:34:16 -07008652 sme_update_new_channel_event(hdd_ctx->mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07008653 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308654 break;
8655 /* LTE coex event on current channel */
8656 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
8657 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
8658 break;
8659 default:
8660 hdd_info("invalid reason for timer invoke");
8661
8662 }
8663}
8664
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008665/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008666 * hdd_override_ini_config - Override INI config
8667 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008668 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008669 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008670 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008671 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008672 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008673static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008674{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008675
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008676 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
8677 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008678 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008679 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008680 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008681 if (0 == enable_11d || 1 == enable_11d) {
8682 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008683 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008684 }
Leo Chang11545d62016-10-17 14:53:50 -07008685
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308686 if (!ucfg_ipa_is_present()) {
Leo Chang11545d62016-10-17 14:53:50 -07008687 hdd_ctx->config->IpaConfig = 0;
Jingxiang Ge7a040dc2018-02-02 11:07:59 +08008688 hdd_debug("IpaConfig override to %d",
8689 hdd_ctx->config->IpaConfig);
8690 }
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05308691
8692 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
8693 !hdd_ctx->config->enable_bcast_probe_rsp) {
8694 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
8695 hdd_ctx->config->rssi_assoc_reject_enabled,
8696 hdd_ctx->config->enable_bcast_probe_rsp);
8697 hdd_ctx->config->oce_sta_enabled = 0;
8698 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008699}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008700
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008701/**
8702 * hdd_set_trace_level_for_each - Set trace level for each INI config
8703 * @hdd_ctx - HDD context
8704 *
8705 * Set trace level for each module based on INI config.
8706 *
8707 * Return: None
8708 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008709static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008710{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308711 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
8712 hdd_ctx->config->qdf_trace_enable_wdi);
8713 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
8714 hdd_ctx->config->qdf_trace_enable_hdd);
8715 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
8716 hdd_ctx->config->qdf_trace_enable_sme);
8717 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
8718 hdd_ctx->config->qdf_trace_enable_pe);
8719 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
8720 hdd_ctx->config->qdf_trace_enable_wma);
8721 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
8722 hdd_ctx->config->qdf_trace_enable_sys);
8723 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
8724 hdd_ctx->config->qdf_trace_enable_qdf);
8725 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
8726 hdd_ctx->config->qdf_trace_enable_sap);
8727 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
8728 hdd_ctx->config->qdf_trace_enable_hdd_sap);
8729 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
8730 hdd_ctx->config->qdf_trace_enable_bmi);
8731 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
8732 hdd_ctx->config->qdf_trace_enable_cfg);
8733 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
8734 hdd_ctx->config->qdf_trace_enable_epping);
8735 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
8736 hdd_ctx->config->qdf_trace_enable_qdf_devices);
8737 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07008738 hdd_ctx->config->qdf_trace_enable_txrx);
8739 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
8740 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308741 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
8742 hdd_ctx->config->qdf_trace_enable_htc);
8743 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
8744 hdd_ctx->config->qdf_trace_enable_hif);
8745 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
8746 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
8747 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
8748 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08008749 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
8750 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07008751 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
8752 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008753 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
8754 hdd_ctx->config->qdf_trace_enable_regulatory);
Naveen Rawat3cb779e2018-02-16 16:36:10 -08008755 hdd_qdf_trace_enable(QDF_MODULE_ID_CP_STATS,
8756 hdd_ctx->config->qdf_trace_enable_cp_stats);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008757
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008758 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008759}
8760
8761/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008762 * hdd_context_init() - Initialize HDD context
8763 * @hdd_ctx: HDD context.
8764 *
8765 * Initialize HDD context along with all the feature specific contexts.
8766 *
8767 * return: 0 on success and errno on failure.
8768 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008769static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008770{
8771 int ret;
8772
8773 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
8774 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
8775
8776 hdd_init_ll_stats_ctx();
8777
8778 init_completion(&hdd_ctx->mc_sus_event_var);
8779 init_completion(&hdd_ctx->ready_to_suspend);
8780
8781 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308782 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008783 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308784
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008785 qdf_list_create(&hdd_ctx->hdd_adapters, MAX_NUMBER_OF_ADAPTERS);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008786
8787 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
8788
8789 ret = hdd_scan_context_init(hdd_ctx);
8790 if (ret)
8791 goto list_destroy;
8792
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008793 hdd_rx_wake_lock_create(hdd_ctx);
8794
8795 ret = hdd_sap_context_init(hdd_ctx);
8796 if (ret)
8797 goto scan_destroy;
8798
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008799 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8800
8801 hdd_init_offloaded_packets_ctx(hdd_ctx);
8802
8803 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8804 hdd_ctx->config);
8805 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08008806 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008807
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05308808 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
8809 "monitor_mode_wakelock");
8810
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008811 return 0;
8812
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008813sap_destroy:
8814 hdd_sap_context_destroy(hdd_ctx);
8815
8816scan_destroy:
8817 hdd_scan_context_destroy(hdd_ctx);
8818 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008819list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008820 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08008821
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008822 return ret;
8823}
8824
8825/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308826 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
8827 * @hdd_ctx: pointer to hdd context
8828 *
8829 * Return: status of initialization
8830 * 0 - success
8831 * negative value - failure
8832 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008833static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308834{
8835 int ret;
8836
8837 if (!hdd_ctx->config->probe_req_ie_whitelist)
8838 return 0;
8839
8840 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
8841 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
8842 hdd_ctx->config->probe_req_ie_whitelist = false;
8843 return -EINVAL;
8844 }
8845
8846 /* parse ini string probe req oui */
8847 ret = hdd_parse_probe_req_ouis(hdd_ctx);
8848 if (ret) {
8849 hdd_err("parsing error: disable ie whitelisting");
8850 hdd_ctx->config->probe_req_ie_whitelist = false;
8851 }
8852
8853 return ret;
8854}
8855
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308856/**
8857 * hdd_iface_change_callback() - Function invoked when stop modules expires
8858 * @priv: pointer to hdd context
8859 *
8860 * This function is invoked when the timer waiting for the interface change
8861 * expires, it shall cut-down the power to wlan and stop all the modules.
8862 *
8863 * Return: void
8864 */
8865static void hdd_iface_change_callback(void *priv)
8866{
8867 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
8868 int ret;
8869 int status = wlan_hdd_validate_context(hdd_ctx);
8870
8871 if (status)
8872 return;
8873
Dustin Brown491d54b2018-03-14 12:39:11 -07008874 hdd_enter();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308875 hdd_debug("Interface change timer expired close the modules!");
8876 ret = hdd_wlan_stop_modules(hdd_ctx, false);
8877 if (ret)
8878 hdd_err("Failed to stop modules");
Dustin Browne74003f2018-03-14 12:51:58 -07008879 hdd_exit();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308880}
8881
Nirav Shaheb017be2018-02-15 11:20:58 +05308882#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
8883static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8884{
8885 wlan_logging_set_log_to_console(hdd_ctx->config->
8886 wlan_logging_to_console);
8887 wlan_logging_set_active(hdd_ctx->config->wlan_logging_enable);
8888}
8889#else
8890static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8891{ }
8892#endif
8893
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308894/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008895 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05308896 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008897 *
8898 * Allocate and initialize HDD context. HDD context is allocated as part of
8899 * wiphy allocation and then context is initialized.
8900 *
8901 * Return: HDD context on success and ERR_PTR on failure
8902 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008903static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008904{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308905 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008906 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008907 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008908
Dustin Brown491d54b2018-03-14 12:39:11 -07008909 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008910
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008911 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008912 if (hdd_ctx == NULL) {
8913 ret = -ENOMEM;
8914 goto err_out;
8915 }
8916
Dustin Brown6f427922017-09-19 12:19:00 -07008917 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
8918 hdd_iface_change_callback,
8919 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308920
8921 mutex_init(&hdd_ctx->iface_change_lock);
8922
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008923 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05308924 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008925
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308926 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008927 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008928 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008929 ret = -ENOMEM;
8930 goto err_free_hdd_context;
8931 }
8932
8933 /* Read and parse the qcom_cfg.ini file */
8934 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308935 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05308936 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008937 WLAN_INI_FILE);
8938 ret = -EINVAL;
8939 goto err_free_config;
8940 }
8941
Dustin Brown84f46ea2018-02-15 11:57:36 -08008942 status = cfg_parse(WLAN_INI_FILE);
8943 if (QDF_IS_STATUS_ERROR(status))
8944 hdd_err("Failed to parse cfg %s; status:%d\n",
8945 WLAN_INI_FILE, status);
8946
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308947 ie_whitelist_attrs_init(hdd_ctx);
8948
Dustin Brown7f939932017-05-18 15:02:17 -07008949 hdd_debug("setting timer multiplier: %u",
8950 hdd_ctx->config->timer_multiplier);
8951 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
8952
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008953
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05308954 if (hdd_ctx->config->fhostNSOffload)
8955 hdd_ctx->ns_offload_enable = true;
8956
Abhishek Singh5ea86532016-04-27 14:10:53 +05308957 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
8958
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008959 hdd_override_ini_config(hdd_ctx);
8960
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008961 ret = hdd_context_init(hdd_ctx);
8962
8963 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008964 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008965
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008966 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05308967 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008968
Anurag Chouhan6d760662016-02-20 16:05:43 +05308969 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008970 goto skip_multicast_logging;
8971
8972 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
8973
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008974 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
8975 if (ret)
8976 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05308977
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008978 ret = hdd_init_netlink_services(hdd_ctx);
8979 if (ret)
8980 goto err_deinit_txrx_histogram;
8981
Nirav Shaheb017be2018-02-15 11:20:58 +05308982 hdd_set_wlan_logging(hdd_ctx);
Nirav Shahed34b212016-04-25 10:59:16 +05308983
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008984skip_multicast_logging:
8985 hdd_set_trace_level_for_each(hdd_ctx);
8986
Rajeev Kumar493a31b2017-09-29 14:01:24 -07008987 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
8988
Dustin Browne74003f2018-03-14 12:51:58 -07008989 hdd_exit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07008990
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008991 return hdd_ctx;
8992
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008993err_deinit_txrx_histogram:
8994 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
8995
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008996err_deinit_hdd_context:
8997 hdd_context_deinit(hdd_ctx);
8998
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008999err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05309000 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009001
9002err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05309003 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08009004 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08009005
9006err_out:
9007 return ERR_PTR(ret);
9008}
9009
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009010#ifdef WLAN_OPEN_P2P_INTERFACE
9011/**
9012 * hdd_open_p2p_interface - Open P2P interface
9013 * @hdd_ctx: HDD context
9014 * @rtnl_held: True if RTNL lock held
9015 *
9016 * Open P2P interface during probe. This function called to open the P2P
9017 * interface at probe along with STA interface.
9018 *
9019 * Return: 0 on success and errno on failure
9020 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009021static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009022{
Jeff Johnson9d295242017-08-29 14:39:48 -07009023 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009024 uint8_t *p2p_dev_addr;
9025
9026 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
9027 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009028 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009029 hdd_ctx->config->intfMacAddr[0].bytes,
9030 sizeof(tSirMacAddr));
9031
9032 /*
9033 * Generate the P2P Device Address. This consists of
9034 * the device's primary MAC address with the locally
9035 * administered bit set.
9036 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009037 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009038 } else {
9039 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
9040 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009041 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009042 return -ENOSPC;
9043 }
9044
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009045 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
9046 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009047 }
9048
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009049 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009050 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08009051 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009052
9053 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009054 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009055 return -ENOSPC;
9056 }
9057
9058 return 0;
9059}
9060#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009061static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009062 bool rtnl_held)
9063{
9064 return 0;
9065}
9066#endif
9067
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009068static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08009069{
Jeff Johnson9d295242017-08-29 14:39:48 -07009070 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08009071 int ret = 0;
9072
9073 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
9074 wlan_hdd_get_intf_addr(hdd_ctx),
9075 NET_NAME_UNKNOWN, rtnl_held);
9076 if (adapter == NULL) {
9077 hdd_err("Failed to open 802.11p interface");
9078 ret = -ENOSPC;
9079 }
9080
9081 return ret;
9082}
9083
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009084/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309085 * hdd_start_station_adapter()- Start the Station Adapter
9086 * @adapter: HDD adapter
9087 *
9088 * This function initializes the adapter for the station mode.
9089 *
9090 * Return: 0 on success or errno on failure.
9091 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009092int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309093{
9094 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08009095 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309096
Dustin Brownfdf17c12018-03-14 12:55:34 -07009097 hdd_enter_dev(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08009098 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9099 hdd_err("session is already opened, %d",
9100 adapter->session_id);
9101 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9102 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309103
Krunal Sonib51eec72017-11-20 21:53:01 -08009104 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
9105 if (ret) {
9106 hdd_err("failed to create vdev: %d", ret);
9107 return ret;
9108 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309109 status = hdd_init_station_mode(adapter);
9110
9111 if (QDF_STATUS_SUCCESS != status) {
9112 hdd_err("Error Initializing station mode: %d", status);
9113 return qdf_status_to_os_return(status);
9114 }
9115
Arun Khandavallifae92942016-08-01 13:31:08 +05309116 hdd_register_tx_flow_control(adapter,
9117 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009118 hdd_tx_resume_cb,
9119 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309120
Dustin Browne74003f2018-03-14 12:51:58 -07009121 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309122 return 0;
9123}
9124
9125/**
9126 * hdd_start_ap_adapter()- Start AP Adapter
9127 * @adapter: HDD adapter
9128 *
9129 * This function initializes the adapter for the AP mode.
9130 *
9131 * Return: 0 on success errno on failure.
9132 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009133int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309134{
9135 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009136 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08009137 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08009138 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309139
Dustin Brown491d54b2018-03-14 12:39:11 -07009140 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309141
Krunal Sonib51eec72017-11-20 21:53:01 -08009142 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9143 hdd_err("session is already opened, %d",
9144 adapter->session_id);
9145 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9146 }
9147 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009148 * In SSR case no need to create new sap context.
9149 * Otherwise create sap context first and then create
9150 * vdev as while creating the vdev, driver needs to
9151 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08009152 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009153 if (adapter->session.ap.sap_context) {
9154 is_ssr = true;
9155 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08009156 hdd_err("sap creation failed");
9157 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
9158 }
9159
9160 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
9161 adapter->session.ap.sap_context);
9162 if (ret) {
9163 hdd_err("failed to create vdev, status:%d", ret);
9164 hdd_sap_destroy_ctx(adapter);
9165 return ret;
9166 }
Naveen Rawat1af09392018-01-03 17:28:21 -08009167
9168 if (adapter->device_mode == QDF_SAP_MODE)
9169 sme_cli_set_command(adapter->session_id,
9170 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
9171 (bool)(hdd_ctx->config->fine_time_meas_cap &
9172 WMI_FW_AP_RTT_RESPR),
9173 VDEV_CMD);
9174
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009175 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309176
9177 if (QDF_STATUS_SUCCESS != status) {
9178 hdd_err("Error Initializing the AP mode: %d", status);
9179 return qdf_status_to_os_return(status);
9180 }
9181
Arun Khandavallifae92942016-08-01 13:31:08 +05309182 hdd_register_tx_flow_control(adapter,
9183 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009184 hdd_softap_tx_resume_cb,
9185 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309186
Dustin Browne74003f2018-03-14 12:51:58 -07009187 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309188 return 0;
9189}
9190
Sourav Mohapatra57006c72017-11-19 16:15:55 +05309191static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
9192 bool rtnl_held)
9193{
9194 struct hdd_adapter *adapter;
9195
9196 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
9197 hdd_ctx->config->enableConcurrentSTA,
9198 wlan_hdd_get_intf_addr(hdd_ctx),
9199 NET_NAME_UNKNOWN, rtnl_held);
9200
9201 if (!adapter)
9202 return -ENOSPC;
9203
9204 return 0;
9205}
9206
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309207/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009208 * hdd_open_interfaces - Open all required interfaces
9209 * hdd_ctx: HDD context
9210 * rtnl_held: True if RTNL lock is held
9211 *
9212 * Open all the interfaces like STA, P2P and OCB based on the configuration.
9213 *
Jeff Johnson957bc272017-02-02 08:54:48 -08009214 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009215 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009216static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009217{
Jeff Johnson9d295242017-08-29 14:39:48 -07009218 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009219 int ret;
9220
Ravi Joshia307f632017-07-17 23:41:41 -07009221 /* open monitor mode adapter if con_mode is monitor mode */
Lin Bai1c678482017-12-18 18:29:11 +08009222 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
9223 con_mode == QDF_GLOBAL_FTM_MODE) {
9224 uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
9225 QDF_MONITOR_MODE : QDF_FTM_MODE;
9226
9227 adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
9228 wlan_hdd_get_intf_addr(hdd_ctx),
9229 NET_NAME_UNKNOWN, rtnl_held);
Ravi Joshia307f632017-07-17 23:41:41 -07009230 if (!adapter) {
9231 hdd_err("open adapter failed");
9232 return -ENOSPC;
9233 }
Lin Bai1c678482017-12-18 18:29:11 +08009234
Ravi Joshia307f632017-07-17 23:41:41 -07009235 return 0;
9236 }
9237
Jeff Johnson957bc272017-02-02 08:54:48 -08009238 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05309239 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08009240 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009241
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009242 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009243 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08009244 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009245
9246 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08009247 return -ENOSPC;
9248
Sourav Mohapatra57006c72017-11-19 16:15:55 +05309249 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
9250 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
9251 if (ret)
9252 hdd_err("Cannot create concurrent STA interface");
9253 }
9254
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009255 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
9256 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08009257 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009258
9259 /* Open 802.11p Interface */
9260 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08009261 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
9262 if (ret)
9263 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009264 }
9265
Jeff Johnson957bc272017-02-02 08:54:48 -08009266 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009267
Jeff Johnson957bc272017-02-02 08:54:48 -08009268err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009269 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08009270 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009271}
9272
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009273
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309274#ifdef QCA_LL_TX_FLOW_CONTROL_V2
9275/**
9276 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
9277 * @cds_cfg: CDS Configuration
9278 * @hdd_ctx: Pointer to hdd context
9279 *
9280 * Return: none
9281 */
9282static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9283 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009284 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309285{
9286 cds_cfg->tx_flow_stop_queue_th =
9287 hdd_ctx->config->TxFlowStopQueueThreshold;
9288 cds_cfg->tx_flow_start_queue_offset =
9289 hdd_ctx->config->TxFlowStartQueueOffset;
9290}
9291#else
9292static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9293 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009294 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309295{
9296}
9297#endif
9298
9299#ifdef FEATURE_WLAN_RA_FILTERING
9300/**
9301 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
9302 * @cds_cfg: CDS Configuration
9303 * @hdd_ctx: Pointer to hdd context
9304 *
9305 * Return: none
9306 */
Anand Kumar3b92a912016-12-05 12:01:26 +05309307static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009308 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309309{
9310 cds_cfg->ra_ratelimit_interval =
9311 hdd_ctx->config->RArateLimitInterval;
9312 cds_cfg->is_ra_ratelimit_enabled =
9313 hdd_ctx->config->IsRArateLimitEnabled;
9314}
9315#else
Anand Kumar3b92a912016-12-05 12:01:26 +05309316static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009317 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309318{
9319}
9320#endif
9321
9322/**
9323 * hdd_update_cds_config() - API to update cds configuration parameters
9324 * @hdd_ctx: HDD Context
9325 *
9326 * Return: 0 for Success, errno on failure
9327 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009328static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309329{
9330 struct cds_config_info *cds_cfg;
9331
9332 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
9333 if (!cds_cfg) {
9334 hdd_err("failed to allocate cds config");
9335 return -ENOMEM;
9336 }
9337
Srinivas Girigowda35b00312017-06-27 21:52:03 -07009338 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08009339 if (!hdd_ctx->config->nMaxPsPoll ||
9340 !hdd_ctx->config->enablePowersaveOffload) {
9341 cds_cfg->powersave_offload_enabled =
9342 hdd_ctx->config->enablePowersaveOffload;
9343 } else {
9344 if ((hdd_ctx->config->enablePowersaveOffload ==
9345 PS_QPOWER_NODEEPSLEEP) ||
9346 (hdd_ctx->config->enablePowersaveOffload ==
9347 PS_LEGACY_NODEEPSLEEP))
9348 cds_cfg->powersave_offload_enabled =
9349 PS_LEGACY_NODEEPSLEEP;
9350 else
9351 cds_cfg->powersave_offload_enabled =
9352 PS_LEGACY_DEEPSLEEP;
9353 hdd_info("Qpower disabled in cds config, %d",
9354 cds_cfg->powersave_offload_enabled);
9355 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309356 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
9357 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
9358 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
9359 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309360
9361 /*
9362 * Copy the DFS Phyerr Filtering Offload status.
9363 * This parameter reflects the value of the
9364 * dfs_phyerr_filter_offload flag as set in the ini.
9365 */
9366 cds_cfg->dfs_phyerr_filter_offload =
9367 hdd_ctx->config->fDfsPhyerrFilterOffload;
9368 if (hdd_ctx->config->ssdp)
9369 cds_cfg->ssdp = hdd_ctx->config->ssdp;
9370
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05309371 cds_cfg->force_target_assert_enabled =
9372 hdd_ctx->config->crash_inject_enabled;
9373
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309374 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
9375 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
9376
9377 cds_cfg->ap_maxoffload_reorderbuffs =
9378 hdd_ctx->config->apMaxOffloadReorderBuffs;
9379
9380 cds_cfg->ap_disable_intrabss_fwd =
9381 hdd_ctx->config->apDisableIntraBssFwd;
9382
9383 cds_cfg->dfs_pri_multiplier =
9384 hdd_ctx->config->dfsRadarPriMultiplier;
9385 cds_cfg->reorder_offload =
9386 hdd_ctx->config->reorderOffloadSupport;
9387
9388 /* IPA micro controller data path offload resource config item */
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05309389 cds_cfg->uc_offload_enabled = ucfg_ipa_uc_is_enabled();
Yun Parkde380782016-08-17 16:26:54 -07009390 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
9391 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009392 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009393 hdd_ctx->config->IpaUcTxBufCount);
9394 hdd_ctx->config->IpaUcTxBufCount =
9395 rounddown_pow_of_two(
9396 hdd_ctx->config->IpaUcTxBufCount);
9397 if (!hdd_ctx->config->IpaUcTxBufCount) {
9398 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309399 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07009400 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009401 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009402 hdd_ctx->config->IpaUcTxBufCount);
9403 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309404 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
9405 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07009406 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
9407 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009408 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009409 hdd_ctx->config->IpaUcRxIndRingCount);
9410 hdd_ctx->config->IpaUcRxIndRingCount =
9411 rounddown_pow_of_two(
9412 hdd_ctx->config->IpaUcRxIndRingCount);
9413 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
9414 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309415 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07009416 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009417 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009418 hdd_ctx->config->IpaUcRxIndRingCount);
9419 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309420 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07009421 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309422 cds_cfg->uc_tx_partition_base =
9423 hdd_ctx->config->IpaUcTxPartitionBase;
9424 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
9425
9426 cds_cfg->ip_tcp_udp_checksum_offload =
9427 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07009428 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309429 cds_cfg->ce_classify_enabled =
9430 hdd_ctx->config->ce_classify_enabled;
Nachiket Kukadee547a482018-05-22 16:43:30 +05309431 cds_cfg->apf_packet_filter_enable =
9432 hdd_ctx->config->apf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309433 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
9434 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
9435 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07009436 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07009437 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07009438 cds_cfg->max_msdus_per_rxinorderind =
9439 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07009440 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07009441 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Nachiket Kukadee547a482018-05-22 16:43:30 +05309442 cds_cfg->active_uc_apf_mode = hdd_ctx->config->active_uc_apf_mode;
9443 cds_cfg->active_mc_bc_apf_mode = hdd_ctx->config->active_mc_bc_apf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05309444 cds_cfg->auto_power_save_fail_mode =
9445 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309446
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309447 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07009448 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Zhu Jianmina2f8e8d2018-02-11 16:37:10 +08009449 cds_cfg->delay_before_vdev_stop =
9450 hdd_ctx->config->delay_before_vdev_stop;
Rachit Kankane0106e382018-05-16 18:59:28 +05309451 cds_cfg->num_vdevs = hdd_ctx->config->num_vdevs;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309452
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309453 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
9454 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
9455 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07009456 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309457 cds_init_ini_config(cds_cfg);
9458 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309459
9460exit:
9461 qdf_mem_free(cds_cfg);
9462 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309463}
9464
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009465/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009466 * hdd_update_user_config() - API to update user configuration
9467 * parameters to obj mgr which are used by multiple components
9468 * @hdd_ctx: HDD Context
9469 *
9470 * Return: 0 for Success, errno on failure
9471 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009472static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009473{
9474 struct wlan_objmgr_psoc_user_config *user_config;
9475
9476 user_config = qdf_mem_malloc(sizeof(*user_config));
9477 if (user_config == NULL) {
9478 hdd_alert("Failed to alloc memory for user_config!");
9479 return -ENOMEM;
9480 }
9481
9482 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
9483 user_config->dual_mac_feature_disable =
9484 hdd_ctx->config->dual_mac_feature_disable;
9485 user_config->indoor_channel_support =
9486 hdd_ctx->config->indoor_channel_support;
9487 user_config->is_11d_support_enabled =
9488 hdd_ctx->config->Is11dSupportEnabled;
9489 user_config->is_11h_support_enabled =
9490 hdd_ctx->config->Is11hSupportEnabled;
9491 user_config->optimize_chan_avoid_event =
9492 hdd_ctx->config->goptimize_chan_avoid_event;
9493 user_config->skip_dfs_chnl_in_p2p_search =
9494 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07009495 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009496 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
9497
9498 qdf_mem_free(user_config);
9499 return 0;
9500}
9501
9502/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009503 * hdd_init_thermal_info - Initialize thermal level
9504 * @hdd_ctx: HDD context
9505 *
9506 * Initialize thermal level at SME layer and set the thermal level callback
9507 * which would be called when a configured thermal threshold is hit.
9508 *
9509 * Return: 0 on success and errno on failure
9510 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009511static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009512{
9513 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309514 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -07009515 mac_handle_t mac_handle;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009516
9517 thermal_param.smeThermalMgmtEnabled =
9518 hdd_ctx->config->thermalMitigationEnable;
9519 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
9520
Poddar, Siddarth83905022016-04-16 17:56:08 -07009521 thermal_param.sme_throttle_duty_cycle_tbl[0] =
9522 hdd_ctx->config->throttle_dutycycle_level0;
9523 thermal_param.sme_throttle_duty_cycle_tbl[1] =
9524 hdd_ctx->config->throttle_dutycycle_level1;
9525 thermal_param.sme_throttle_duty_cycle_tbl[2] =
9526 hdd_ctx->config->throttle_dutycycle_level2;
9527 thermal_param.sme_throttle_duty_cycle_tbl[3] =
9528 hdd_ctx->config->throttle_dutycycle_level3;
9529
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009530 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
9531 hdd_ctx->config->thermalTempMinLevel0;
9532 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
9533 hdd_ctx->config->thermalTempMaxLevel0;
9534 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
9535 hdd_ctx->config->thermalTempMinLevel1;
9536 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
9537 hdd_ctx->config->thermalTempMaxLevel1;
9538 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
9539 hdd_ctx->config->thermalTempMinLevel2;
9540 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
9541 hdd_ctx->config->thermalTempMaxLevel2;
9542 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
9543 hdd_ctx->config->thermalTempMinLevel3;
9544 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
9545 hdd_ctx->config->thermalTempMaxLevel3;
9546
Jeff Johnson16528362018-06-14 12:34:16 -07009547 mac_handle = hdd_ctx->mac_handle;
9548 status = sme_init_thermal_info(mac_handle, thermal_param);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009549
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309550 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05309551 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009552
Jeff Johnson16528362018-06-14 12:34:16 -07009553 sme_add_set_thermal_level_callback(mac_handle,
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009554 hdd_set_thermal_level_cb);
9555
9556 return 0;
9557
9558}
9559
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009560#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
9561/**
9562 * hdd_hold_rtnl_lock - Hold RTNL lock
9563 *
9564 * Hold RTNL lock
9565 *
9566 * Return: True if held and false otherwise
9567 */
9568static inline bool hdd_hold_rtnl_lock(void)
9569{
9570 rtnl_lock();
9571 return true;
9572}
9573
9574/**
9575 * hdd_release_rtnl_lock - Release RTNL lock
9576 *
9577 * Release RTNL lock
9578 *
9579 * Return: None
9580 */
9581static inline void hdd_release_rtnl_lock(void)
9582{
9583 rtnl_unlock();
9584}
9585#else
9586static inline bool hdd_hold_rtnl_lock(void) { return false; }
9587static inline void hdd_release_rtnl_lock(void) { }
9588#endif
9589
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009590#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009591
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309592/* MAX iwpriv command support */
9593#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309594#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309595#define MAX_PKTLOG_SIZE 16
9596
9597/**
9598 * hdd_pktlog_set_buff_size() - set pktlog buffer size
9599 * @hdd_ctx: hdd context
9600 * @set_value2: pktlog buffer size value
9601 *
9602 *
9603 * Return: 0 for success or error.
9604 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009605static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309606{
9607 struct sir_wifi_start_log start_log = { 0 };
9608 QDF_STATUS status;
9609
9610 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9611 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9612 start_log.ini_triggered = cds_is_packet_log_enabled();
9613 start_log.user_triggered = 1;
9614 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309615 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309616
Jeff Johnson16528362018-06-14 12:34:16 -07009617 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309618 if (!QDF_IS_STATUS_SUCCESS(status)) {
9619 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009620 hdd_exit();
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309621 return -EINVAL;
9622 }
9623
9624 return 0;
9625}
9626
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009627/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309628 * hdd_pktlog_clear_buff() - clear pktlog buffer
9629 * @hdd_ctx: hdd context
9630 *
9631 * Return: 0 for success or error.
9632 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009633static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309634{
9635 struct sir_wifi_start_log start_log;
9636 QDF_STATUS status;
9637
9638 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9639 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9640 start_log.ini_triggered = cds_is_packet_log_enabled();
9641 start_log.user_triggered = 1;
9642 start_log.size = 0;
9643 start_log.is_pktlog_buff_clear = true;
9644
Jeff Johnson16528362018-06-14 12:34:16 -07009645 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309646 if (!QDF_IS_STATUS_SUCCESS(status)) {
9647 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009648 hdd_exit();
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309649 return -EINVAL;
9650 }
9651
9652 return 0;
9653}
9654
9655
9656/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009657 * hdd_process_pktlog_command() - process pktlog command
9658 * @hdd_ctx: hdd context
9659 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309660 * @set_value2: pktlog buffer size value
9661 *
9662 * This function process pktlog command.
9663 * set_value2 only matters when set_value is 3 (set buff size)
9664 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009665 *
9666 * Return: 0 for success or error.
9667 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009668int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309669 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009670{
9671 int ret;
9672 bool enable;
9673 uint8_t user_triggered = 0;
9674
9675 ret = wlan_hdd_validate_context(hdd_ctx);
9676 if (0 != ret)
9677 return ret;
9678
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009679 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009680
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309681 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009682 hdd_err("invalid pktlog value %d", set_value);
9683 return -EINVAL;
9684 }
9685
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309686 if (set_value == PKTLOG_SET_BUFF_SIZE) {
9687 if (set_value2 <= 0) {
9688 hdd_err("invalid pktlog size %d", set_value2);
9689 return -EINVAL;
9690 } else if (set_value2 > MAX_PKTLOG_SIZE) {
9691 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
9692 return -EINVAL;
9693 }
9694 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309695 } else if (set_value == PKTLOG_CLEAR_BUFF) {
9696 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309697 }
9698
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009699 /*
9700 * set_value = 0 then disable packetlog
9701 * set_value = 1 enable packetlog forcefully
9702 * set_vlaue = 2 then disable packetlog if disabled through ini or
9703 * enable packetlog with AUTO type.
9704 */
9705 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
9706 true : false;
9707
9708 if (1 == set_value) {
9709 enable = true;
9710 user_triggered = 1;
9711 }
9712
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309713 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009714}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07009715
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009716/**
9717 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
9718 * @hdd_ctx: HDD context
9719 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309720 * @user_triggered: triggered through iwpriv
9721 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009722 *
9723 * Return: 0 on success; error number otherwise
9724 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009725int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309726 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009727{
9728 struct sir_wifi_start_log start_log;
9729 QDF_STATUS status;
9730
9731 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9732 start_log.verbose_level =
9733 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009734 start_log.ini_triggered = cds_is_packet_log_enabled();
9735 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309736 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309737 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05309738 /*
9739 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
9740 * commands. Host uses this flag to decide whether to send pktlog
9741 * disable command to fw without sending pktlog enable command
9742 * previously. For eg, If vendor sends pktlog disable command without
9743 * sending pktlog enable command, then host discards the packet
9744 * but for iwpriv command, host will send it to fw.
9745 */
9746 start_log.is_iwpriv_command = 1;
Jeff Johnson16528362018-06-14 12:34:16 -07009747 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009748 if (!QDF_IS_STATUS_SUCCESS(status)) {
9749 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009750 hdd_exit();
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009751 return -EINVAL;
9752 }
9753
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309754 if (enable == true)
9755 hdd_ctx->is_pktlog_enabled = 1;
9756 else
9757 hdd_ctx->is_pktlog_enabled = 0;
9758
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009759 return 0;
9760}
9761#endif /* REMOVE_PKT_LOG */
9762
Komal Seelam92fff912016-03-24 11:51:41 +05309763/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009764 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
9765 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05309766 * @dev: Device Pointer
9767 * @num: Number of Valid Mac address
9768 *
9769 * Return: Pointer to MAC address buffer
9770 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009771static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9772 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309773{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009774 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309775}
Komal Seelam92fff912016-03-24 11:51:41 +05309776
9777/**
9778 * hdd_populate_random_mac_addr() - API to populate random mac addresses
9779 * @hdd_ctx: HDD Context
9780 * @num: Number of random mac addresses needed
9781 *
9782 * Generate random addresses using bit manipulation on the base mac address
9783 *
9784 * Return: None
9785 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009786void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05309787{
9788 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
9789 uint32_t iter;
9790 struct hdd_config *ini = hdd_ctx->config;
9791 uint8_t *buf = NULL;
9792 uint8_t macaddr_b3, tmp_br3;
9793 uint8_t *src = ini->intfMacAddr[0].bytes;
9794
9795 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
9796 buf = ini->intfMacAddr[iter].bytes;
9797 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
9798 macaddr_b3 = buf[3];
9799 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
9800 INTF_MACADDR_MASK;
9801 macaddr_b3 += tmp_br3;
9802 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
9803 buf[0] |= 0x02;
9804 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009805 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309806 }
9807}
9808
9809/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009810 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05309811 * @hdd_ctx: HDD Context
9812 *
9813 * API to get mac addresses from platform driver and update the driver
9814 * structures and configure FW with the base mac address.
9815 * Return: int
9816 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009817static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309818{
9819 uint32_t no_of_mac_addr, iter;
9820 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
9821 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
9822 uint8_t *addr, *buf;
9823 struct device *dev = hdd_ctx->parent_dev;
9824 struct hdd_config *ini = hdd_ctx->config;
9825 tSirMacAddr mac_addr;
9826 QDF_STATUS status;
9827
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009828 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05309829
9830 if (no_of_mac_addr == 0 || !addr) {
9831 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
9832 return -EINVAL;
9833 }
9834
9835 if (no_of_mac_addr > max_mac_addr)
9836 no_of_mac_addr = max_mac_addr;
9837
9838 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
9839
9840 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
9841 buf = ini->intfMacAddr[iter].bytes;
9842 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009843 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309844 }
9845
9846 status = sme_set_custom_mac_addr(mac_addr);
9847
9848 if (!QDF_IS_STATUS_SUCCESS(status))
9849 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009850
Komal Seelam92fff912016-03-24 11:51:41 +05309851 if (no_of_mac_addr < max_mac_addr)
9852 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
9853 no_of_mac_addr);
9854 return 0;
9855}
9856
9857/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009858 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
9859 * @hdd_ctx: HDD Context
9860 *
9861 * Update MAC address to FW. If MAC address passed by FW is invalid, host
9862 * will generate its own MAC and update it to FW.
9863 *
9864 * Return: 0 for success
9865 * Non-zero error code for failure
9866 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009867static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009868{
9869 tSirMacAddr customMacAddr;
9870 QDF_STATUS status;
9871
9872 qdf_mem_copy(&customMacAddr,
9873 &hdd_ctx->config->intfMacAddr[0].bytes[0],
9874 sizeof(tSirMacAddr));
9875 status = sme_set_custom_mac_addr(customMacAddr);
9876 if (!QDF_IS_STATUS_SUCCESS(status))
9877 return -EAGAIN;
9878 return 0;
9879}
9880
9881/**
Komal Seelam92fff912016-03-24 11:51:41 +05309882 * hdd_initialize_mac_address() - API to get wlan mac addresses
9883 * @hdd_ctx: HDD Context
9884 *
9885 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
9886 * is provisioned with mac addresses, driver uses it, else it will use
9887 * wlan_mac.bin to update HW MAC addresses.
9888 *
9889 * Return: None
9890 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009891static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309892{
9893 QDF_STATUS status;
9894 int ret;
9895
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009896 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05309897 if (ret == 0)
9898 return;
9899
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009900 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
9901 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05309902
9903 status = hdd_update_mac_config(hdd_ctx);
9904
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009905 if (QDF_IS_STATUS_SUCCESS(status))
9906 return;
9907
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009908 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
9909 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009910
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009911 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009912 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009913 if (ret != 0) {
9914 hdd_err("MAC address out-of-sync, ret:%d", ret);
9915 QDF_ASSERT(ret);
9916 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009917 }
Komal Seelam92fff912016-03-24 11:51:41 +05309918}
9919
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009920static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009921{
9922 int vdev_id = 0;
9923 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
9924 int value = hdd_ctx->config->smart_chainmask_enabled;
9925 int vpdev = PDEV_CMD;
9926 int ret;
9927
Naveen Rawat247a8682017-06-05 15:00:31 -07009928 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009929 if (ret)
9930 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
9931
9932 return ret;
9933}
9934
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009935static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009936{
9937 int vdev_id = 0;
9938 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
9939 int value = hdd_ctx->config->alternative_chainmask_enabled;
9940 int vpdev = PDEV_CMD;
9941 int ret;
9942
Naveen Rawat247a8682017-06-05 15:00:31 -07009943 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009944 if (ret)
9945 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
9946 ret);
9947
9948 return ret;
9949}
9950
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009951static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07009952{
9953 int vdev_id = 0;
9954 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
9955 int value = hdd_ctx->config->ani_enabled;
9956 int vpdev = PDEV_CMD;
9957 int ret;
9958
Naveen Rawat247a8682017-06-05 15:00:31 -07009959 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07009960 if (ret)
9961 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
9962
9963 return ret;
9964}
9965
Jeff Johnson89c66ff2016-04-22 15:21:37 -07009966/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07009967 * hdd_pre_enable_configure() - Configurations prior to cds_enable
9968 * @hdd_ctx: HDD context
9969 *
9970 * Pre configurations to be done at lower layer before calling cds enable.
9971 *
9972 * Return: 0 on success and errno on failure.
9973 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009974static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07009975{
9976 int ret;
9977 QDF_STATUS status;
Leo Changfdb45c32016-10-28 11:09:23 -07009978 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009979
Leo Changfdb45c32016-10-28 11:09:23 -07009980 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Ajit Pal Singh5d269612018-04-19 16:29:12 +05309981 /* Register HL netdev flow control callback */
9982 cdp_hl_fc_register(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009983 /*
9984 * Set 802.11p config
9985 * TODO-OCB: This has been temporarily added here to ensure this
9986 * parameter is set in CSR when we init the channel list. This should
9987 * be removed once the 5.9 GHz channels are added to the regulatory
9988 * domain.
9989 */
9990 hdd_set_dot11p_config(hdd_ctx);
9991
9992 /*
9993 * Note that the cds_pre_enable() sequence triggers the cfg download.
9994 * The cfg download must occur before we update the SME config
9995 * since the SME config operation must access the cfg database
9996 */
9997 status = hdd_set_sme_config(hdd_ctx);
9998
9999 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010000 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010001 ret = qdf_status_to_os_return(status);
10002 goto out;
10003 }
10004
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -070010005 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
10006 if (QDF_STATUS_SUCCESS != status) {
10007 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
10008 ret = qdf_status_to_os_return(status);
10009 goto out;
10010 }
10011
Naveen Rawat247a8682017-06-05 15:00:31 -070010012 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -070010013 hdd_ctx->config->tx_chain_mask_1ss,
10014 PDEV_CMD);
10015 if (0 != ret) {
10016 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
10017 goto out;
10018 }
10019
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010020 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
10021 if (ret)
10022 goto out;
10023
10024 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
10025 if (ret)
10026 goto out;
10027
Jeff Johnson12a744b2017-04-04 08:19:37 -070010028 ret = hdd_set_ani_enabled(hdd_ctx);
10029 if (ret)
10030 goto out;
10031
Naveen Rawat247a8682017-06-05 15:00:31 -070010032 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -080010033 hdd_ctx->config->arp_ac_category,
10034 PDEV_CMD);
10035 if (0 != ret) {
10036 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
10037 hdd_ctx->config->arp_ac_category, ret);
10038 goto out;
10039 }
10040
Prashanth Bhatta07998752016-04-28 12:35:33 -070010041 status = hdd_set_sme_chan_list(hdd_ctx);
10042 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010043 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010044 ret = qdf_status_to_os_return(status);
10045 goto out;
10046 }
10047
10048 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -070010049 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010050 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -070010051 ret = -EINVAL;
10052 goto out;
10053 }
10054
Prashanth Bhatta07998752016-04-28 12:35:33 -070010055 /*
10056 * Set the MAC Address Currently this is used by HAL to add self sta.
10057 * Remove this once self sta is added as part of session open.
10058 */
Jeff Johnson16528362018-06-14 12:34:16 -070010059 status = sme_cfg_set_str(hdd_ctx->mac_handle, WNI_CFG_STA_ID,
Jeff Johnsonbae59f92018-06-01 17:05:43 -070010060 hdd_ctx->config->intfMacAddr[0].bytes,
10061 sizeof(hdd_ctx->config->intfMacAddr[0]));
Prashanth Bhatta07998752016-04-28 12:35:33 -070010062
Jeff Johnsonbae59f92018-06-01 17:05:43 -070010063 if (QDF_IS_STATUS_ERROR(status)) {
10064 hdd_err("Failed to set MAC Address, status %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010065 ret = -EINVAL;
10066 goto out;
10067 }
10068
10069 hdd_init_channel_avoidance(hdd_ctx);
10070
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +053010071 /* update enable sap mandatory chan list */
10072 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
10073 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010074out:
10075 return ret;
10076}
10077
10078/**
Peng Xu8fdaa492016-06-22 10:20:47 -070010079 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
10080 * @context_ptr - hdd context pointer
10081 * @event_ptr - event structure pointer
10082 *
10083 * This is the p2p listen offload stop event handler, it sends vendor
10084 * event back to supplicant to notify the stop reason.
10085 *
10086 * Return: None
10087 */
10088static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
10089 void *event_ptr)
10090{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010091 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -070010092 struct sir_p2p_lo_event *evt = event_ptr;
10093 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -070010094 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -070010095
Dustin Brown491d54b2018-03-14 12:39:11 -070010096 hdd_enter();
Peng Xu8fdaa492016-06-22 10:20:47 -070010097
10098 if (hdd_ctx == NULL) {
10099 hdd_err("Invalid HDD context pointer");
10100 return;
10101 }
10102
Peng Xu5c682812017-08-06 07:39:13 -070010103 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
10104 if (!adapter) {
10105 hdd_err("Cannot find adapter by vdev_id = %d",
10106 evt->vdev_id);
10107 return;
10108 }
10109
Peng Xu8fdaa492016-06-22 10:20:47 -070010110 vendor_event =
10111 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -070010112 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -070010113 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
10114 GFP_KERNEL);
10115
10116 if (!vendor_event) {
10117 hdd_err("cfg80211_vendor_event_alloc failed");
10118 return;
10119 }
10120
10121 if (nla_put_u32(vendor_event,
10122 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
10123 evt->reason_code)) {
10124 hdd_err("nla put failed");
10125 kfree_skb(vendor_event);
10126 return;
10127 }
10128
10129 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -070010130 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
10131 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -070010132}
10133
10134/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010135 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
10136 * @hdd_ctx: HDD context
10137 *
10138 * This function sends the adaptive dwell time config configuration to the
10139 * firmware via WMA
10140 *
10141 * Return: 0 - success, < 0 - failure
10142 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010143static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010144{
10145 QDF_STATUS status;
10146 struct adaptive_dwelltime_params dwelltime_params;
10147
10148 dwelltime_params.is_enabled =
10149 hdd_ctx->config->adaptive_dwell_mode_enabled;
10150 dwelltime_params.dwelltime_mode =
10151 hdd_ctx->config->global_adapt_dwelltime_mode;
10152 dwelltime_params.lpf_weight =
10153 hdd_ctx->config->adapt_dwell_lpf_weight;
10154 dwelltime_params.passive_mon_intval =
10155 hdd_ctx->config->adapt_dwell_passive_mon_intval;
10156 dwelltime_params.wifi_act_threshold =
10157 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
10158
Jeff Johnson16528362018-06-14 12:34:16 -070010159 status = sme_set_adaptive_dwelltime_config(hdd_ctx->mac_handle,
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010160 &dwelltime_params);
10161
10162 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
10163 if (!QDF_IS_STATUS_SUCCESS(status)) {
10164 hdd_err("Failed to send Adaptive Dwelltime configuration!");
10165 return -EAGAIN;
10166 }
10167 return 0;
10168}
10169
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010170int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010171{
10172 QDF_STATUS status;
10173 struct wmi_dbs_scan_sel_params dbs_scan_params;
10174 uint32_t i = 0;
10175 uint8_t count = 0, numentries = 0;
10176 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
10177 * CDS_DBS_SCAN_CLIENTS_MAX];
10178
10179 /* check if DBS is enabled or supported */
Bala Venkateshc8236ca2018-03-09 12:38:29 +053010180 if ((hdd_ctx->config->dual_mac_feature_disable ==
10181 DISABLE_DBS_CXN_AND_SCAN) ||
10182 (hdd_ctx->config->dual_mac_feature_disable ==
10183 ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN))
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010184 return -EINVAL;
10185
10186 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
10187 dbs_scan_config, &numentries,
10188 (CDS_DBS_SCAN_PARAM_PER_CLIENT
10189 * CDS_DBS_SCAN_CLIENTS_MAX));
10190
10191 hdd_info("numentries %hu", numentries);
10192 if (!numentries) {
10193 hdd_info("Donot send scan_selection_config");
10194 return 0;
10195 }
10196
10197 /* hdd_set_fw_log_params */
10198 dbs_scan_params.num_clients = 0;
10199 while (count < (numentries - 2)) {
10200 dbs_scan_params.module_id[i] = dbs_scan_config[count];
10201 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
10202 dbs_scan_params.num_non_dbs_scans[i] =
10203 dbs_scan_config[count + 2];
10204 dbs_scan_params.num_clients++;
10205 hdd_debug("module:%d NDS:%d NNDS:%d",
10206 dbs_scan_params.module_id[i],
10207 dbs_scan_params.num_dbs_scans[i],
10208 dbs_scan_params.num_non_dbs_scans[i]);
10209 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
10210 i++;
10211 }
10212
10213 dbs_scan_params.pdev_id = 0;
10214
10215 hdd_debug("clients:%d pdev:%d",
10216 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
10217
Jeff Johnson16528362018-06-14 12:34:16 -070010218 status = sme_set_dbs_scan_selection_config(hdd_ctx->mac_handle,
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010219 &dbs_scan_params);
10220 hdd_debug("Sending DBS Scan Selection Configuration to fw");
10221 if (!QDF_IS_STATUS_SUCCESS(status)) {
10222 hdd_err("Failed to send DBS Scan selection configuration!");
10223 return -EAGAIN;
10224 }
10225 return 0;
10226}
10227
Arun Khandavallid4349a92016-07-25 11:10:43 +053010228#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10229/**
10230 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
10231 * @hdd_ctx: HDD context
10232 *
10233 * Set auto shutdown callback to get indications from firmware to indicate
10234 * userspace to shutdown WLAN after a configured amount of inactivity.
10235 *
10236 * Return: 0 on success and errno on failure.
10237 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010238static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010239{
10240 QDF_STATUS status;
10241
10242 if (!hdd_ctx->config->WlanAutoShutdown)
10243 return 0;
10244
Jeff Johnson16528362018-06-14 12:34:16 -070010245 status = sme_set_auto_shutdown_cb(hdd_ctx->mac_handle,
Arun Khandavallid4349a92016-07-25 11:10:43 +053010246 wlan_hdd_auto_shutdown_cb);
10247 if (status != QDF_STATUS_SUCCESS)
10248 hdd_err("Auto shutdown feature could not be enabled: %d",
10249 status);
10250
10251 return qdf_status_to_os_return(status);
10252}
10253#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010254static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010255{
10256 return 0;
10257}
10258#endif
10259
10260/**
10261 * hdd_features_init() - Init features
10262 * @hdd_ctx: HDD context
Arun Khandavallid4349a92016-07-25 11:10:43 +053010263 *
10264 * Initialize features and their feature context after WLAN firmware is up.
10265 *
10266 * Return: 0 on success and errno on failure.
10267 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010268static int hdd_features_init(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010269{
10270 tSirTxPowerLimit hddtxlimit;
10271 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +053010272 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010273 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070010274 mac_handle_t mac_handle;
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010275 struct hdd_config *cfg;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010276
Dustin Brown491d54b2018-03-14 12:39:11 -070010277 hdd_enter();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010278
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010279 cfg = hdd_ctx->config;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010280 /* FW capabilities received, Set the Dot11 mode */
Jeff Johnson16528362018-06-14 12:34:16 -070010281 mac_handle = hdd_ctx->mac_handle;
10282 sme_setdef_dot11mode(mac_handle);
10283 sme_set_prefer_80MHz_over_160MHz(mac_handle,
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -070010284 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Kiran Kumar Lokere1a43bcf2018-05-15 15:51:58 -070010285 sme_set_etsi13_srd_ch_in_master_mode(mac_handle,
10286 cfg->
10287 etsi13_srd_chan_in_master_mode);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010288
10289 if (hdd_ctx->config->fIsImpsEnabled)
10290 hdd_set_idle_ps_config(hdd_ctx, true);
10291 else
10292 hdd_set_idle_ps_config(hdd_ctx, false);
10293
Poddar, Siddarth37033032017-10-11 15:47:40 +053010294 /* Send Enable/Disable data stall detection cmd to FW */
10295 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
10296 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
10297
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010298 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Jeff Johnson16528362018-06-14 12:34:16 -070010299 sme_set_cts2self_for_p2p_go(mac_handle);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010300
Nachiket Kukade8983cf62017-10-12 18:14:48 +053010301 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
10302 hdd_warn("Error in setting Voltage Corner mode config to FW");
10303
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010304 if (hdd_rx_ol_init(hdd_ctx))
10305 hdd_err("Unable to initialize Rx LRO/GRO in fw");
Arun Khandavallid4349a92016-07-25 11:10:43 +053010306
10307 if (hdd_adaptive_dwelltime_init(hdd_ctx))
10308 hdd_err("Unable to send adaptive dwelltime setting to FW");
10309
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010310 if (hdd_dbs_scan_selection_init(hdd_ctx))
10311 hdd_err("Unable to send DBS scan selection setting to FW");
10312
Arun Khandavallid4349a92016-07-25 11:10:43 +053010313 ret = hdd_init_thermal_info(hdd_ctx);
10314 if (ret) {
10315 hdd_err("Error while initializing thermal information");
Dustin Browne7e71d32018-05-11 16:00:08 -070010316 return ret;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010317 }
10318
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010319 /**
10320 * In case of SSR/PDR, if pktlog was enabled manually before
10321 * SSR/PDR, Then enabled it again automatically after Wlan
10322 * device up.
10323 */
10324 if (cds_is_driver_recovering()) {
10325 if (hdd_ctx->is_pktlog_enabled)
10326 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Tiger Yuf3d5d7f2018-03-15 14:48:11 +080010327 }
Poddar, Siddarth66a46592017-02-22 11:44:44 +053010328
Arun Khandavallid4349a92016-07-25 11:10:43 +053010329 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
10330 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
Jeff Johnson16528362018-06-14 12:34:16 -070010331 status = sme_txpower_limit(mac_handle, &hddtxlimit);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010332 if (!QDF_IS_STATUS_SUCCESS(status))
10333 hdd_err("Error setting txlimit in sme: %d", status);
10334
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010335 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010336
Arun Khandavallid4349a92016-07-25 11:10:43 +053010337 ret = hdd_register_cb(hdd_ctx);
10338 if (ret) {
10339 hdd_err("Failed to register HDD callbacks!");
Dustin Browne7e71d32018-05-11 16:00:08 -070010340 return ret;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010341 }
10342
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +053010343 if (hdd_ctx->config->goptimize_chan_avoid_event) {
10344 status = sme_enable_disable_chanavoidind_event(
Jeff Johnson16528362018-06-14 12:34:16 -070010345 mac_handle, 0);
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +053010346 if (!QDF_IS_STATUS_SUCCESS(status)) {
10347 hdd_err("Failed to disable Chan Avoidance Indication");
10348 goto deregister_cb;
10349 }
10350 }
Arun Khandavallid4349a92016-07-25 11:10:43 +053010351
Manjeet Singha9cae432017-02-28 11:58:22 +053010352 if (hdd_ctx->config->enable_5g_band_pref) {
10353 band_pref_params.rssi_boost_threshold_5g =
10354 hdd_ctx->config->rssi_boost_threshold_5g;
10355 band_pref_params.rssi_boost_factor_5g =
10356 hdd_ctx->config->rssi_boost_factor_5g;
10357 band_pref_params.max_rssi_boost_5g =
10358 hdd_ctx->config->max_rssi_boost_5g;
10359 band_pref_params.rssi_penalize_threshold_5g =
10360 hdd_ctx->config->rssi_penalize_threshold_5g;
10361 band_pref_params.rssi_penalize_factor_5g =
10362 hdd_ctx->config->rssi_penalize_factor_5g;
10363 band_pref_params.max_rssi_penalize_5g =
10364 hdd_ctx->config->max_rssi_penalize_5g;
Jeff Johnson16528362018-06-14 12:34:16 -070010365 sme_set_5g_band_pref(mac_handle, &band_pref_params);
Manjeet Singha9cae432017-02-28 11:58:22 +053010366 }
10367
Arun Khandavallid4349a92016-07-25 11:10:43 +053010368 /* register P2P Listen Offload event callback */
10369 if (wma_is_p2p_lo_capable())
Jeff Johnson16528362018-06-14 12:34:16 -070010370 sme_register_p2p_lo_event(mac_handle, hdd_ctx,
10371 wlan_hdd_p2p_lo_event_callback);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010372
10373 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
10374
10375 if (ret)
10376 goto deregister_cb;
10377
Dustin Brown11638b72018-01-25 17:37:25 +053010378 wlan_hdd_init_chan_info(hdd_ctx);
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010379 wlan_hdd_twt_init(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010380
Dustin Browne74003f2018-03-14 12:51:58 -070010381 hdd_exit();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010382 return 0;
10383
10384deregister_cb:
10385 hdd_deregister_cb(hdd_ctx);
Dustin Browne7e71d32018-05-11 16:00:08 -070010386
Arun Khandavallid4349a92016-07-25 11:10:43 +053010387 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010388}
10389
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010390/**
10391 * hdd_features_deinit() - Deinit features
10392 * @hdd_ctx: HDD context
10393 *
10394 * De-Initialize features and their feature context.
10395 *
10396 * Return: none.
10397 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010398static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010399{
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010400 wlan_hdd_twt_deinit(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010401 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010402 wlan_hdd_tsf_deinit(hdd_ctx);
10403}
10404
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010405/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010406 * hdd_register_bcn_cb() - register scan beacon callback
10407 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010408 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010409 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010410 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010411static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010412{
10413 QDF_STATUS status;
10414
10415 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
10416 wlan_cfg80211_inform_bss_frame,
10417 SCAN_CB_TYPE_INFORM_BCN);
10418 if (!QDF_IS_STATUS_SUCCESS(status)) {
10419 hdd_err("failed with status code %08d [x%08x]",
10420 status, status);
10421 return status;
10422 }
10423
10424 return QDF_STATUS_SUCCESS;
10425}
Arun Khandavallid4349a92016-07-25 11:10:43 +053010426
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010427/**
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070010428 * hdd_v2_flow_pool_map() - Flow pool create callback when vdev is active
10429 * @vdev_id: vdev_id, corresponds to flow_pool
10430 *
10431 * Return: none.
10432 */
10433static void hdd_v2_flow_pool_map(int vdev_id)
10434{
10435 QDF_STATUS status;
10436
10437 status = cdp_flow_pool_map(cds_get_context(QDF_MODULE_ID_SOC),
10438 cds_get_context(QDF_MODULE_ID_TXRX),
10439 vdev_id);
10440 /*
10441 * For Adrastea flow control v2 is based on FW MAP events,
10442 * so this above callback is not implemented.
10443 * Hence this is not actual failure. Dont return failure
10444 */
10445 if ((status != QDF_STATUS_SUCCESS) &&
10446 (status != QDF_STATUS_E_INVAL)) {
10447 hdd_err("vdev_id: %d, failed to create flow pool status %d",
10448 vdev_id, status);
10449 }
10450}
10451
10452/**
10453 * hdd_v2_flow_pool_unmap() - Flow pool create callback when vdev is not active
10454 * @vdev_id: vdev_id, corresponds to flow_pool
10455 *
10456 * Return: none.
10457 */
10458static void hdd_v2_flow_pool_unmap(int vdev_id)
10459{
10460 cdp_flow_pool_unmap(cds_get_context(QDF_MODULE_ID_SOC),
10461 cds_get_context(QDF_MODULE_ID_TXRX), vdev_id);
10462}
10463
10464/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010465 * hdd_configure_cds() - Configure cds modules
10466 * @hdd_ctx: HDD context
10467 * @adapter: Primary adapter context
10468 *
10469 * Enable Cds modules after WLAN firmware is up.
10470 *
10471 * Return: 0 on success and errno on failure.
10472 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010473int hdd_configure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010474{
10475 int ret;
10476 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010477 int set_value;
Jeff Johnson16528362018-06-14 12:34:16 -070010478 mac_handle_t mac_handle;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010479 uint32_t num_abg_tx_chains = 0;
10480 uint32_t num_11b_tx_chains = 0;
10481 uint32_t num_11ag_tx_chains = 0;
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010482 struct policy_mgr_dp_cbacks dp_cbs = {0};
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010483
Jeff Johnson16528362018-06-14 12:34:16 -070010484 mac_handle = hdd_ctx->mac_handle;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010485 if (hdd_ctx->config->is_force_1x1)
10486 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
10487 1, PDEV_CMD);
10488 /* set chip power save failure detected callback */
Jeff Johnson16528362018-06-14 12:34:16 -070010489 sme_set_chip_pwr_save_fail_cb(mac_handle,
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010490 hdd_chip_pwr_save_fail_detected_cb);
10491
10492 if (hdd_ctx->config->max_mpdus_inampdu) {
10493 set_value = hdd_ctx->config->max_mpdus_inampdu;
10494 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
10495 set_value, PDEV_CMD);
10496 }
10497
10498 if (hdd_ctx->config->enable_rts_sifsbursting) {
10499 set_value = hdd_ctx->config->enable_rts_sifsbursting;
10500 sme_cli_set_command(0,
10501 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
10502 set_value, PDEV_CMD);
10503 }
10504
10505 if (hdd_ctx->config->sap_get_peer_info) {
10506 set_value = hdd_ctx->config->sap_get_peer_info;
10507 sme_cli_set_command(0,
10508 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
10509 set_value, PDEV_CMD);
10510 }
10511
10512 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
10513 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
10514 if (!hdd_ctx->config->enable2x2) {
10515 if (num_11b_tx_chains > 1)
10516 num_11b_tx_chains = 1;
10517 if (num_11ag_tx_chains > 1)
10518 num_11ag_tx_chains = 1;
10519 }
10520 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
10521 num_11b_tx_chains);
10522 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
10523 num_11ag_tx_chains);
10524 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
10525 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +053010526
10527 ret = hdd_pre_enable_configure(hdd_ctx);
10528 if (ret) {
10529 hdd_err("Failed to pre-configure cds");
10530 goto out;
10531 }
10532
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010533 /* Always get latest IPA resources allocated from cds_open and configure
10534 * IPA module before configuring them to FW. Sequence required as crash
10535 * observed otherwise.
10536 */
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010537 if (ucfg_ipa_uc_ol_init(hdd_ctx->hdd_pdev,
10538 cds_get_context(QDF_MODULE_ID_QDF_DEVICE))) {
Manikandan Mohan2e803a02017-02-14 14:57:53 -080010539 hdd_err("Failed to setup pipes");
10540 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010541 }
10542
Arun Khandavallifae92942016-08-01 13:31:08 +053010543 /*
10544 * Start CDS which starts up the SME/MAC/HAL modules and everything
10545 * else
10546 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -070010547 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010548
10549 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010550 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053010551 goto out;
10552 }
10553
10554 status = hdd_post_cds_enable_config(hdd_ctx);
10555 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010556 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010557 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010558 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010559 status = hdd_register_bcn_cb(hdd_ctx);
10560 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +080010561 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010562 goto cds_disable;
10563 }
Arun Khandavallifae92942016-08-01 13:31:08 +053010564
Dustin Browne7e71d32018-05-11 16:00:08 -070010565 ret = hdd_features_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010566 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010567 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010568
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010569 if (hdd_ctx->ol_enable)
10570 dp_cbs.hdd_disable_rx_ol_in_concurrency =
10571 hdd_disable_rx_ol_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -070010572 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
jiadbb47e132018-03-30 16:28:30 +080010573 dp_cbs.hdd_ipa_set_mcc_mode_cb = hdd_ipa_set_mcc_mode;
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070010574 dp_cbs.hdd_v2_flow_pool_map = hdd_v2_flow_pool_map;
10575 dp_cbs.hdd_v2_flow_pool_unmap = hdd_v2_flow_pool_unmap;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010576 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
10577 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -070010578 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010579 goto cds_disable;
10580 }
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010581 status = policy_mgr_register_mode_change_cb(hdd_ctx->hdd_psoc,
10582 wlan_hdd_send_mode_change_event);
10583 if (!QDF_IS_STATUS_SUCCESS(status)) {
10584 hdd_debug("Failed to register mode change cb with Policy Manager");
10585 goto cds_disable;
10586 }
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010587
Jeff Johnson8bb61112018-03-31 13:33:54 -070010588 if (hdd_green_ap_enable_egap(hdd_ctx))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +053010589 hdd_debug("enhance green ap is not enabled");
10590
Nachiket Kukadedd302662017-07-13 17:31:44 +053010591 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
10592 hdd_debug("Failed to set wow pulse");
10593
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053010594 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
10595 hdd_ctx->config->gcmp_enabled, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053010596 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
10597 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
10598
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053010599
10600 if (hdd_ctx->config->enable_phy_reg_retention)
10601 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
10602 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
10603
Arun Khandavallifae92942016-08-01 13:31:08 +053010604 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010605
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010606cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010607 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010608
Arun Khandavallifae92942016-08-01 13:31:08 +053010609out:
10610 return -EINVAL;
10611}
10612
10613/**
10614 * hdd_deconfigure_cds() -De-Configure cds
10615 * @hdd_ctx: HDD context
10616 *
10617 * Deconfigure Cds modules before WLAN firmware is down.
10618 *
10619 * Return: 0 on success and errno on failure.
10620 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010621static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010622{
10623 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070010624 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053010625
Dustin Brown491d54b2018-03-14 12:39:11 -070010626 hdd_enter();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010627
10628 /* De-init features */
10629 hdd_features_deinit(hdd_ctx);
10630
Arun Khandavallifae92942016-08-01 13:31:08 +053010631 /* De-register the SME callbacks */
10632 hdd_deregister_cb(hdd_ctx);
10633
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010634 qdf_status = policy_mgr_deregister_mode_change_cb(hdd_ctx->hdd_psoc);
10635 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10636 hdd_debug("Failed to deregister mode change cb with Policy Manager");
10637 }
10638
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010639 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010640 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10641 hdd_err("Failed to Disable the CDS Modules! :%d",
10642 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070010643 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010644 }
10645
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010646 if (ucfg_ipa_uc_ol_deinit(hdd_ctx->hdd_pdev) != QDF_STATUS_SUCCESS) {
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053010647 hdd_err("Failed to disconnect pipes");
10648 ret = -EINVAL;
10649 }
10650
Dustin Browne74003f2018-03-14 12:51:58 -070010651 hdd_exit();
Houston Hoffman6640cf32016-10-10 16:44:29 -070010652 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010653}
10654
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010655#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
10656static void hdd_deregister_policy_manager_callback(
10657 struct wlan_objmgr_psoc *psoc)
10658{
10659 if (QDF_STATUS_SUCCESS !=
10660 policy_mgr_deregister_hdd_cb(psoc)) {
10661 hdd_err("HDD callback deregister with policy manager failed");
10662 }
10663}
10664#else
10665static void hdd_deregister_policy_manager_callback(
10666 struct wlan_objmgr_psoc *psoc)
10667{
10668}
10669#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010670
10671/**
10672 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
10673 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010674 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +053010675 *
10676 * This function maintains the driver state machine it will be invoked from
10677 * exit, shutdown and con_mode change handler. Depending on the driver state
10678 * shall perform the stopping/closing of the modules.
10679 *
10680 * Return: 0 for success; non-zero for failure
10681 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010682int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053010683{
10684 void *hif_ctx;
10685 qdf_device_t qdf_ctx;
10686 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010687 int ret = 0;
Dustin Brown4bc0a622017-12-06 15:56:50 -080010688 bool is_recovery_stop = cds_is_driver_recovering();
Liangwei Donga78cc1d2018-02-01 02:19:30 -050010689 bool is_idle_stop = !cds_is_driver_unloading() && !is_recovery_stop &&
10690 !cds_is_driver_loading();
Dustin Brown70111822017-03-30 15:31:40 -070010691 int active_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010692 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053010693
Dustin Brown491d54b2018-03-14 12:39:11 -070010694 hdd_enter();
Yun Parkfec73dc2017-09-06 10:40:07 -070010695 hdd_alert("stop WLAN module: entering driver status=%d",
10696 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +053010697
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010698 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
10699
Arun Khandavallifae92942016-08-01 13:31:08 +053010700 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
10701 if (!qdf_ctx) {
10702 hdd_err("QDF device context NULL");
10703 return -EINVAL;
10704 }
10705
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010706 mutex_lock(&hdd_ctx->iface_change_lock);
10707 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010708 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053010709
Dustin Brown70111822017-03-30 15:31:40 -070010710 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -070010711 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -070010712 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -070010713 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -070010714
10715 cds_print_external_threads();
10716
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010717 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070010718 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -070010719 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10720 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010721 hdd_prevent_suspend_timeout(
10722 hdd_ctx->config->iface_change_wait_time,
10723 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010724 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010725 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -070010726 return 0;
10727 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070010728 }
10729
Arun Khandavallifae92942016-08-01 13:31:08 +053010730 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
10731
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080010732 /* free user wowl patterns */
10733 hdd_free_user_wowl_ptrns();
10734
Arun Khandavallifae92942016-08-01 13:31:08 +053010735 switch (hdd_ctx->driver_status) {
10736 case DRIVER_MODULES_UNINITIALIZED:
10737 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010738 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010739 case DRIVER_MODULES_CLOSED:
10740 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010741 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010742 case DRIVER_MODULES_ENABLED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010743 hdd_info("Wlan transitioning (OPENED <- ENABLED)");
10744
Komal Seelamf2136bb2016-09-28 18:30:44 +053010745 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053010746 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010747 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053010748 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010749 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010750 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010751 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080010752
Arun Khandavallifae92942016-08-01 13:31:08 +053010753 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010754 hdd_info("Wlan transitioned (now OPENED)");
10755
10756 /* fall through */
Arun Khandavallifae92942016-08-01 13:31:08 +053010757 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010758 hdd_info("Wlan transitioning (CLOSED <- OPENED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010759 break;
10760 default:
10761 hdd_err("Trying to stop wlan in a wrong state: %d",
10762 hdd_ctx->driver_status);
10763 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010764 ret = -EINVAL;
10765 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010766 }
10767
Amar Singhal18081642018-01-26 16:04:13 -080010768 hdd_sysfs_destroy_version_interface();
Dustin Brown550f6d22017-12-14 15:44:01 -080010769 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080010770
Rajeev Kumarbe021242017-02-16 16:12:23 -080010771 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053010772 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10773 hdd_err("Failed to process post CDS disable Modules! :%d",
10774 qdf_status);
10775 ret = -EINVAL;
10776 QDF_ASSERT(0);
10777 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010778
psimhadeea0a12017-12-18 14:50:02 -080010779 hdd_runtime_suspend_context_deinit(hdd_ctx);
10780
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010781 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
10782 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10783 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
10784 ret = -EINVAL;
10785 QDF_ASSERT(0);
10786 }
10787
Jeff Johnsone4b14592017-09-13 14:23:33 -070010788 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010789 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010790 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053010791 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010792 QDF_ASSERT(0);
10793 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -070010794
Amar Singhal410675c2018-01-10 12:14:21 -080010795 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Liangwei Dong50a64a72018-01-11 01:17:00 -050010796 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
10797 if (ret) {
10798 hdd_err("Failed to destroy pdev; errno:%d", ret);
10799 QDF_ASSERT(0);
10800 }
10801
10802 /*
10803 * Reset total mac phy during module stop such that during
10804 * next module start same psoc is used to populate new service
10805 * ready data
10806 */
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010807 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
10808 if (tgt_hdl)
10809 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
10810
Liangwei Dong50a64a72018-01-11 01:17:00 -050010811
Arun Khandavallifae92942016-08-01 13:31:08 +053010812 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
10813 if (!hif_ctx) {
10814 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010815 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010816 }
10817
Arunk Khandavalli4b404332017-09-26 12:46:00 +053010818 if (hdd_ctx->target_hw_name) {
10819 qdf_mem_free(hdd_ctx->target_hw_name);
10820 hdd_ctx->target_hw_name = NULL;
10821 }
10822
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053010823 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010824
10825 ol_cds_free();
10826
Dustin Brown70111822017-03-30 15:31:40 -070010827 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +053010828 ret = pld_power_off(qdf_ctx->dev);
10829 if (ret)
10830 hdd_err("CNSS power down failed put device into Low power mode:%d",
10831 ret);
10832 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010833
Dustin Brown4bc0a622017-12-06 15:56:50 -080010834 /* many adapter resources are not freed by design in SSR case */
10835 if (!is_recovery_stop)
Dustin Browna6246dd2018-05-24 14:35:58 -070010836 hdd_check_for_leaks(hdd_ctx);
Dustin Brown26b3d042017-12-21 11:13:27 -080010837 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010838
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010839 /* Once the firmware sequence is completed reset this flag */
10840 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053010841 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010842 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010843
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010844done:
10845 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010846 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010847 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -070010848 hdd_alert("stop WLAN module: exit driver status=%d",
10849 hdd_ctx->driver_status);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010850
Dustin Browne74003f2018-03-14 12:51:58 -070010851 hdd_exit();
Arun Khandavallifae92942016-08-01 13:31:08 +053010852
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010853 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010854}
10855
Arun Khandavallifae92942016-08-01 13:31:08 +053010856
Wen Gong3f003382018-05-14 14:26:37 +080010857#ifdef WLAN_FEATURE_MEMDUMP_ENABLE
Arun Khandavallifae92942016-08-01 13:31:08 +053010858/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010859 * hdd_state_info_dump() - prints state information of hdd layer
10860 * @buf: buffer pointer
10861 * @size: size of buffer to be filled
10862 *
10863 * This function is used to dump state information of hdd layer
10864 *
10865 * Return: None
10866 */
10867static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
10868{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010869 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070010870 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070010871 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010872 uint16_t len = 0;
10873 char *buf = *buf_ptr;
10874
10875 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10876 if (!hdd_ctx) {
10877 hdd_err("Failed to get hdd context ");
10878 return;
10879 }
10880
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010881 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010882
10883 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070010884 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010885 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080010886 "\n is_scheduler_suspended %d",
10887 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010888
Dustin Brown920397d2017-12-13 16:27:50 -080010889 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010890 if (adapter->dev)
10891 len += scnprintf(buf + len, *size - len,
10892 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080010893 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010894 "\n device_mode: %d", adapter->device_mode);
10895 switch (adapter->device_mode) {
10896 case QDF_STA_MODE:
10897 case QDF_P2P_CLIENT_MODE:
10898 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
10899 len += scnprintf(buf + len, *size - len,
10900 "\n connState: %d",
10901 hdd_sta_ctx->conn_info.connState);
10902 break;
10903
10904 default:
10905 break;
10906 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010907 }
10908
10909 *size -= len;
10910 *buf_ptr += len;
10911}
10912
10913/**
10914 * hdd_register_debug_callback() - registration function for hdd layer
10915 * to print hdd state information
10916 *
10917 * Return: None
10918 */
10919static void hdd_register_debug_callback(void)
10920{
10921 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
10922}
Wen Gong3f003382018-05-14 14:26:37 +080010923#else /* WLAN_FEATURE_MEMDUMP_ENABLE */
Wen Gongaa6d55d2018-04-26 16:33:21 +080010924static void hdd_register_debug_callback(void)
10925{
10926}
Wen Gong3f003382018-05-14 14:26:37 +080010927#endif /* WLAN_FEATURE_MEMDUMP_ENABLE */
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010928
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053010929/*
10930 * wlan_init_bug_report_lock() - Initialize bug report lock
10931 *
10932 * This function is used to create bug report lock
10933 *
10934 * Return: None
10935 */
10936static void wlan_init_bug_report_lock(void)
10937{
Jeff Johnson2b6982c2018-05-29 14:56:11 -070010938 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053010939
10940 p_cds_context = cds_get_global_context();
10941 if (!p_cds_context) {
10942 hdd_err("cds context is NULL");
10943 return;
10944 }
10945
10946 qdf_spinlock_create(&p_cds_context->bug_report_lock);
10947}
10948
Nirav Shahd21a2e32018-04-20 16:34:43 +053010949#ifdef CONFIG_DP_TRACE
Mohit Khannaf8f96822017-05-17 17:11:59 -070010950void hdd_dp_trace_init(struct hdd_config *config)
10951{
Mohit Khannaf8f96822017-05-17 17:11:59 -070010952 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
10953 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
10954 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
10955 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
10956 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
10957 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
10958 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080010959 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070010960
Nirav Shahd21a2e32018-04-20 16:34:43 +053010961 if (!config->enable_dp_trace) {
10962 hdd_err("dp trace is disabled from ini");
10963 return;
10964 }
10965
Mohit Khannaf8f96822017-05-17 17:11:59 -070010966 hdd_string_to_u8_array(config->dp_trace_config, config_params,
10967 &num_entries, sizeof(config_params));
10968
10969 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080010970 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010971 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080010972 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010973 else if (bw_compute_interval > 1000) {
10974 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
10975 thresh_time_limit = 1;
10976 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070010977 hdd_err("busBandwidthComputeInterval is 0, using defaults");
10978
10979 switch (num_entries) {
10980 case 4:
10981 proto_bitmap = config_params[3];
Alok Kumarb5a33a22018-05-07 18:09:14 +053010982 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070010983 case 3:
10984 verbosity = config_params[2];
Alok Kumarb5a33a22018-05-07 18:09:14 +053010985 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070010986 case 2:
10987 thresh = config_params[1];
Alok Kumarb5a33a22018-05-07 18:09:14 +053010988 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070010989 case 1:
10990 live_mode = config_params[0];
Alok Kumarb5a33a22018-05-07 18:09:14 +053010991 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070010992 default:
Mohit Khannaf7562c32018-07-05 17:42:36 -070010993 hdd_info("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
10994 live_mode, thresh, thresh_time_limit,
10995 verbosity, proto_bitmap);
Mohit Khannaf8f96822017-05-17 17:11:59 -070010996 };
10997
10998 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
10999 verbosity, proto_bitmap);
11000
11001}
Nirav Shahd21a2e32018-04-20 16:34:43 +053011002#endif
11003
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011004/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011005 * hdd_wlan_startup() - HDD init function
11006 * @dev: Pointer to the underlying device
11007 *
11008 * This is the driver startup code executed once a WLAN device has been detected
11009 *
11010 * Return: 0 for success, < 0 for failure
11011 */
Arun Khandavallifae92942016-08-01 13:31:08 +053011012int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011013{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011014 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011015 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011016 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080011017 bool rtnl_held;
Jeff Johnson16528362018-06-14 12:34:16 -070011018 mac_handle_t mac_handle;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011019
Dustin Brown491d54b2018-03-14 12:39:11 -070011020 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011021
Arun Khandavallifae92942016-08-01 13:31:08 +053011022 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011023
11024 if (IS_ERR(hdd_ctx))
11025 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011026
Abhishek Singhe9068f12017-03-31 14:14:52 +053011027 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
11028 DEFAULT_PSOC_ID);
11029 if (ret) {
11030 hdd_err("Psoc creation fails!");
11031 QDF_BUG(0);
11032 goto err_hdd_free_context;
11033 }
11034
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053011035 qdf_nbuf_init_replenish_timer();
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053011036#ifdef FEATURE_WLAN_CH_AVOID
11037 mutex_init(&hdd_ctx->avoid_freq_lock);
11038#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053011039
Naveen Rawate02f8f52018-04-05 11:58:04 -070011040 osif_request_manager_init();
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053011041 qdf_atomic_init(&hdd_ctx->con_mode_flag);
Arun Khandavallifae92942016-08-01 13:31:08 +053011042
Dustin Brown021cecd2017-12-11 13:56:43 -080011043 hdd_driver_memdump_init();
11044
Dustin Browne7e71d32018-05-11 16:00:08 -070011045 ret = hdd_wlan_start_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053011046 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011047 hdd_err("Failed to start modules: %d", ret);
Dustin Brown021cecd2017-12-11 13:56:43 -080011048 goto err_memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011049 }
11050
Yingying Tang80e15f32016-09-27 18:23:01 +080011051 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011052
Jeff Johnson16528362018-06-14 12:34:16 -070011053 mac_handle = cds_get_context(QDF_MODULE_ID_SME);
11054 hdd_ctx->mac_handle = mac_handle;
11055 if (!mac_handle) {
11056 hdd_err("Mac Handle is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053011057 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011058 }
11059
Prashanth Bhatta07998752016-04-28 12:35:33 -070011060 ret = hdd_wiphy_init(hdd_ctx);
11061 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011062 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053011063 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011064 }
11065
Nirav Shahd21a2e32018-04-20 16:34:43 +053011066 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053011067
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070011068 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080011069
Paul Zhangfb02f452017-12-22 11:58:43 +080011070 ret = register_netdevice_notifier(&hdd_netdev_notifier);
11071 if (ret) {
11072 hdd_err("register_netdevice_notifier failed: %d", ret);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053011073 goto err_wiphy_unregister;
Paul Zhangfb02f452017-12-22 11:58:43 +080011074 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053011075
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011076 ret = register_reboot_notifier(&system_reboot_notifier);
11077 if (ret) {
11078 hdd_err("Failed to register reboot notifier: %d", ret);
11079 goto err_unregister_netdev;
11080 }
11081
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080011082 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011083
Jeff Johnson957bc272017-02-02 08:54:48 -080011084 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11085 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011086 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080011087 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011088 }
11089
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080011090 hdd_release_rtnl_lock();
11091 rtnl_held = false;
11092
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080011093 wlan_hdd_update_11n_mode(hdd_ctx->config);
11094
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011095#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053011096 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053011097 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011098 hdd_skip_acs_scan_timer_handler,
11099 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011100 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070011101 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040011102 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011103#endif
11104
Prashanth Bhattaab004382016-10-11 16:08:11 -070011105 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011106
Jeff Johnson9afc5012016-09-23 13:56:27 -070011107 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011108
Nirav Shahbd36b062016-07-18 11:12:59 +053011109 if (hdd_ctx->rps)
11110 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070011111
Paul Zhangfb02f452017-12-22 11:58:43 +080011112 ret = hdd_register_notifiers(hdd_ctx);
11113 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -080011114 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070011115
Paul Zhangfb02f452017-12-22 11:58:43 +080011116 status = wlansap_global_init();
11117 if (QDF_IS_STATUS_ERROR(status)) {
11118 hdd_unregister_notifiers(hdd_ctx);
11119 goto err_close_adapters;
11120 }
11121
Arun Khandavallifae92942016-08-01 13:31:08 +053011122 if (hdd_ctx->config->fIsImpsEnabled)
11123 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070011124 else
11125 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011126
Mukul Sharma07bd8752017-10-10 16:58:14 +053011127 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070011128 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
11129 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053011130 hdd_prevent_suspend_timeout(
11131 hdd_ctx->config->iface_change_wait_time,
11132 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
11133 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053011134
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011135 goto success;
11136
Jeff Johnson957bc272017-02-02 08:54:48 -080011137err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080011138 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011139
Jeff Johnson46bde382017-02-01 15:31:16 -080011140err_release_rtnl_lock:
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011141 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavallid4349a92016-07-25 11:10:43 +053011142 if (rtnl_held)
11143 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011144
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011145err_unregister_netdev:
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011146 unregister_netdevice_notifier(&hdd_netdev_notifier);
11147
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011148err_wiphy_unregister:
Rachit Kankane30807332018-06-27 18:39:36 +053011149 qdf_dp_trace_deinit();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011150 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011151
Arun Khandavallifae92942016-08-01 13:31:08 +053011152err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011153 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053011154
Dustin Brown021cecd2017-12-11 13:56:43 -080011155err_memdump_deinit:
11156 hdd_driver_memdump_deinit();
Dustin Brown021cecd2017-12-11 13:56:43 -080011157
Naveen Rawate02f8f52018-04-05 11:58:04 -070011158 osif_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070011159 hdd_exit_netlink_services(hdd_ctx);
11160
Dustin Brown20912462017-06-07 13:48:25 -070011161 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
11162
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011163err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053011164 if (cds_is_fw_down())
11165 hdd_err("Not setting the complete event as fw is down");
11166 else
11167 hdd_start_complete(ret);
11168
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053011169 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070011170 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070011171 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011172
11173success:
Dustin Browne74003f2018-03-14 12:51:58 -070011174 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011175 return 0;
11176}
11177
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011178/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011179 * hdd_wlan_update_target_info() - update target type info
11180 * @hdd_ctx: HDD context
11181 * @context: hif context
11182 *
11183 * Update target info received from firmware in hdd context
11184 * Return:None
11185 */
11186
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011187void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053011188{
11189 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
11190
11191 if (!tgt_info) {
11192 hdd_err("Target info is Null");
11193 return;
11194 }
11195
11196 hdd_ctx->target_type = tgt_info->target_type;
11197}
11198
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011199void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp, void *context)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011200{
11201 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011202 int status;
11203 struct hdd_adapter *adapter = NULL;
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011204 struct osif_request *request = NULL;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011205
Dustin Brown491d54b2018-03-14 12:39:11 -070011206 hdd_enter();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011207
11208 if (!rsp) {
11209 hdd_err("data is null");
11210 return;
11211 }
11212
11213 status = wlan_hdd_validate_context(hdd_ctx);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011214 if (status != 0)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011215 return;
11216
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011217 request = osif_request_get(context);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011218 if (!request) {
11219 hdd_err("obselete request");
11220 return;
11221 }
11222
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011223 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
11224 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
11225 hdd_err("Invalid adapter or adapter has invalid magic");
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011226 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011227 return;
11228 }
11229
Dustin Brown5e89ef82018-03-14 11:50:23 -070011230 hdd_info("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
11231 hdd_info("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
11232 hdd_info("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
11233 hdd_info("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
11234 hdd_info("rsp->out_of_order_arp_rsp_drop_cnt :%x",
11235 rsp->out_of_order_arp_rsp_drop_cnt);
11236 hdd_info("rsp->dad_detected :%x", rsp->dad_detected);
11237 hdd_info("rsp->connect_status :%x", rsp->connect_status);
11238 hdd_info("rsp->ba_session_establishment_status :%x",
11239 rsp->ba_session_establishment_status);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011240
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011241 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011242 adapter->dad |= rsp->dad_detected;
11243 adapter->con_status = rsp->connect_status;
11244
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053011245 /* Flag true indicates connectivity check stats present. */
11246 if (rsp->connect_stats_present) {
11247 hdd_info("rsp->tcp_ack_recvd :%x", rsp->tcp_ack_recvd);
11248 hdd_info("rsp->icmpv4_rsp_recvd :%x", rsp->icmpv4_rsp_recvd);
11249 adapter->hdd_stats.hdd_tcp_stats.rx_fw_cnt = rsp->tcp_ack_recvd;
11250 adapter->hdd_stats.hdd_icmpv4_stats.rx_fw_cnt =
11251 rsp->icmpv4_rsp_recvd;
11252 }
11253
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011254 osif_request_complete(request);
11255 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011256
Dustin Browne74003f2018-03-14 12:51:58 -070011257 hdd_exit();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011258}
11259
11260/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011261 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011262 * @hdd_ctx: HDD context
11263 *
11264 * Register the HDD callbacks to CDS/SME.
11265 *
11266 * Return: 0 for success or Error code for failure
11267 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011268int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011269{
11270 QDF_STATUS status;
11271 int ret = 0;
Jeff Johnson16528362018-06-14 12:34:16 -070011272 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011273
Dustin Brown491d54b2018-03-14 12:39:11 -070011274 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011275
Jeff Johnson16528362018-06-14 12:34:16 -070011276 mac_handle = hdd_ctx->mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011277
Jeff Johnson16528362018-06-14 12:34:16 -070011278 sme_register_oem_data_rsp_callback(mac_handle,
11279 hdd_send_oem_data_rsp_msg);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011280
Jeff Johnson16528362018-06-14 12:34:16 -070011281 sme_register_mgmt_frame_ind_callback(mac_handle,
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053011282 hdd_indicate_mgmt_frame);
Jeff Johnson16528362018-06-14 12:34:16 -070011283 sme_set_tsfcb(mac_handle, hdd_get_tsf_cb, hdd_ctx);
11284 sme_nan_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011285 wlan_hdd_cfg80211_nan_callback);
Jeff Johnson16528362018-06-14 12:34:16 -070011286 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011287 wlan_hdd_cfg80211_stats_ext_callback);
11288
Jeff Johnson16528362018-06-14 12:34:16 -070011289 sme_ext_scan_register_callback(mac_handle,
11290 wlan_hdd_cfg80211_extscan_callback);
11291 sme_stats_ext2_register_callback(mac_handle,
lifeng66831662017-05-19 16:01:35 +080011292 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011293
Jeff Johnson16528362018-06-14 12:34:16 -070011294 sme_set_rssi_threshold_breached_cb(mac_handle,
11295 hdd_rssi_threshold_breached);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011296
Jeff Johnson16528362018-06-14 12:34:16 -070011297 sme_set_link_layer_stats_ind_cb(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011298 wlan_hdd_cfg80211_link_layer_stats_callback);
11299
Jeff Johnson16528362018-06-14 12:34:16 -070011300 sme_rso_cmd_status_cb(mac_handle, wlan_hdd_rso_cmd_status_cb);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053011301
Jeff Johnson16528362018-06-14 12:34:16 -070011302 sme_set_link_layer_ext_cb(mac_handle,
Zhang Qianca38fb12016-12-23 11:10:48 +080011303 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
11304
Jeff Johnson16528362018-06-14 12:34:16 -070011305 status = sme_set_lost_link_info_cb(mac_handle,
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053011306 hdd_lost_link_info_cb);
11307 /* print error and not block the startup process */
11308 if (!QDF_IS_STATUS_SUCCESS(status))
11309 hdd_err("set lost link info callback failed");
11310
Poddar, Siddarth34872782017-08-10 14:08:51 +053011311 ret = hdd_register_data_stall_detect_cb();
11312 if (ret) {
11313 hdd_err("Register data stall detect detect callback failed.");
11314 return ret;
11315 }
11316
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011317 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
11318
Jeff Johnson16528362018-06-14 12:34:16 -070011319 sme_register_set_connection_info_cb(mac_handle,
11320 hdd_set_connection_in_progress,
11321 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053011322
Jeff Johnson16528362018-06-14 12:34:16 -070011323 status = sme_congestion_register_callback(mac_handle,
11324 hdd_update_cca_info_cb);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053011325 if (!QDF_IS_STATUS_SUCCESS(status))
11326 hdd_err("set congestion callback failed");
11327
Jeff Johnson16528362018-06-14 12:34:16 -070011328 status = sme_set_bt_activity_info_cb(mac_handle,
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053011329 hdd_bt_activity_cb);
11330 if (!QDF_IS_STATUS_SUCCESS(status))
11331 hdd_err("set bt activity info callback failed");
11332
Jeff Johnson16528362018-06-14 12:34:16 -070011333 status = sme_register_tx_queue_cb(mac_handle,
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080011334 hdd_tx_queue_cb);
11335 if (!QDF_IS_STATUS_SUCCESS(status))
11336 hdd_err("Register tx queue callback failed");
11337
Dustin Browne74003f2018-03-14 12:51:58 -070011338 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011339
11340 return ret;
11341}
11342
11343/**
11344 * hdd_deregister_cb() - De-Register HDD callbacks.
11345 * @hdd_ctx: HDD context
11346 *
11347 * De-Register the HDD callbacks to CDS/SME.
11348 *
11349 * Return: void
11350 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011351void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011352{
11353 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053011354 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070011355 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011356
Dustin Brown491d54b2018-03-14 12:39:11 -070011357 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011358
Jeff Johnson16528362018-06-14 12:34:16 -070011359 mac_handle = hdd_ctx->mac_handle;
11360 sme_deregister_tx_queue_cb(mac_handle);
11361 status = sme_deregister_for_dcc_stats_event(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011362 if (!QDF_IS_STATUS_SUCCESS(status))
11363 hdd_err("De-register of dcc stats callback failed: %d",
11364 status);
11365
Jeff Johnson16528362018-06-14 12:34:16 -070011366 sme_reset_link_layer_stats_ind_cb(mac_handle);
11367 sme_reset_rssi_threshold_breached_cb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011368
Jeff Johnson16528362018-06-14 12:34:16 -070011369 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011370 wlan_hdd_cfg80211_stats_ext_callback);
11371
Jeff Johnson16528362018-06-14 12:34:16 -070011372 sme_nan_deregister_callback(mac_handle);
11373 status = sme_reset_tsfcb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011374 if (!QDF_IS_STATUS_SUCCESS(status))
11375 hdd_err("Failed to de-register tsfcb the callback:%d",
11376 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011377
Poddar, Siddarth34872782017-08-10 14:08:51 +053011378 ret = hdd_deregister_data_stall_detect_cb();
11379 if (ret)
11380 hdd_err("Failed to de-register data stall detect event callback");
11381
Jeff Johnson16528362018-06-14 12:34:16 -070011382 sme_deregister_oem_data_rsp_callback(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011383
Dustin Browne74003f2018-03-14 12:51:58 -070011384 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011385}
11386
11387/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011388 * hdd_softap_sta_deauth() - handle deauth req from HDD
11389 * @adapter: Pointer to the HDD
11390 * @enable: bool value
11391 *
11392 * This to take counter measure to handle deauth req from HDD
11393 *
11394 * Return: None
11395 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011396QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011397 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011398{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011399 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011400
Dustin Brown491d54b2018-03-14 12:39:11 -070011401 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011402
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011403 /* Ignore request to deauth bcmc station */
11404 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011405 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011406
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011407 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011408 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
11409 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011410
Dustin Browne74003f2018-03-14 12:51:58 -070011411 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011412 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011413}
11414
11415/**
11416 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
11417 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011418 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011419 *
11420 * This to take counter measure to handle deauth req from HDD
11421 *
11422 * Return: None
11423 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011424void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011425 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011426{
Dustin Brown491d54b2018-03-14 12:39:11 -070011427 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011428
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011429 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011430 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011431 return;
11432
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011433 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011434 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011435}
11436
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011437/**
11438 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
11439 * @hdd_ctx: HDD Context
11440 *
11441 * API to find if there is any STA or P2P-Client is connected
11442 *
11443 * Return: true if connected; false otherwise
11444 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011445QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011446{
Jeff Johnson16528362018-06-14 12:34:16 -070011447 return sme_is_sta_p2p_client_connected(hdd_ctx->mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011448}
11449
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011450void wlan_hdd_disable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011451{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011452 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
11453 struct hdd_adapter *adapter = NULL;
11454 struct csr_roam_profile *roam_profile;
11455 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011456
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011457 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->hdd_psoc)) {
11458 hdd_debug("No active sta session");
11459 return;
11460 }
11461
11462 hdd_for_each_adapter(hdd_ctx, adapter) {
11463 roam_profile = hdd_roam_profile(adapter);
11464 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11465
11466 if (cur_adapter->session_id != adapter->session_id &&
11467 adapter->device_mode == QDF_STA_MODE &&
11468 hdd_conn_is_connected(sta_ctx)) {
11469 hdd_debug("%d Disable roaming", adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -070011470 sme_stop_roaming(hdd_ctx->mac_handle,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011471 adapter->session_id,
11472 ecsr_driver_disabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011473 }
11474 }
11475}
11476
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011477void wlan_hdd_enable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011478{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011479 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
11480 struct hdd_adapter *adapter = NULL;
11481 struct csr_roam_profile *roam_profile;
11482 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011483
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011484 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->hdd_psoc)) {
11485 hdd_debug("No active sta session");
11486 return;
11487 }
11488
11489 hdd_for_each_adapter(hdd_ctx, adapter) {
11490 roam_profile = hdd_roam_profile(adapter);
11491 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11492
11493 if (cur_adapter->session_id != adapter->session_id &&
11494 adapter->device_mode == QDF_STA_MODE &&
11495 hdd_conn_is_connected(sta_ctx)) {
11496 hdd_debug("%d Enable roaming", adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -070011497 sme_start_roaming(hdd_ctx->mac_handle,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011498 adapter->session_id,
11499 REASON_DRIVER_ENABLED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011500 }
11501 }
11502}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011503
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011504/**
11505 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
11506 * @skb: sk buffer pointer
11507 *
11508 * Sends the bcast message to SVC multicast group with generic nl socket
11509 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
11510 *
11511 * Return: None
11512 */
11513static void nl_srv_bcast_svc(struct sk_buff *skb)
11514{
11515#ifdef CNSS_GENL
11516 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
11517#else
11518 nl_srv_bcast(skb);
11519#endif
11520}
11521
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011522void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011523{
11524 struct sk_buff *skb;
11525 struct nlmsghdr *nlh;
11526 tAniMsgHdr *ani_hdr;
11527 void *nl_data = NULL;
11528 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011529 struct radio_index_tlv *radio_info;
11530 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011531
11532 if (in_interrupt() || irqs_disabled() || in_atomic())
11533 flags = GFP_ATOMIC;
11534
11535 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
11536
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011537 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011538 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011539
11540 nlh = (struct nlmsghdr *)skb->data;
11541 nlh->nlmsg_pid = 0; /* from kernel */
11542 nlh->nlmsg_flags = 0;
11543 nlh->nlmsg_seq = 0;
11544 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
11545
11546 ani_hdr = NLMSG_DATA(nlh);
11547 ani_hdr->type = type;
11548
11549 switch (type) {
11550 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053011551 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011552 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011553 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011554 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011555 ani_hdr->length = 0;
11556 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011557 break;
11558 case WLAN_SVC_WLAN_STATUS_IND:
11559 case WLAN_SVC_WLAN_VERSION_IND:
11560 case WLAN_SVC_DFS_CAC_START_IND:
11561 case WLAN_SVC_DFS_CAC_END_IND:
11562 case WLAN_SVC_DFS_RADAR_DETECT_IND:
11563 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
11564 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080011565 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053011566 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080011567 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011568 ani_hdr->length = len;
11569 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
11570 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
11571 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011572 break;
11573
11574 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070011575 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011576 type);
11577 kfree_skb(skb);
11578 return;
11579 }
11580
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011581 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080011582 * Add radio index at the end of the svc event in TLV format
11583 * to maintain the backward compatibility with userspace
11584 * applications.
11585 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011586
11587 tlv_len = 0;
11588
11589 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
11590 < WLAN_NL_MAX_PAYLOAD) {
11591 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
11592 sizeof(*ani_hdr) + len);
11593 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
11594 radio_info->length = (unsigned short) sizeof(radio_info->radio);
11595 radio_info->radio = radio;
11596 tlv_len = sizeof(*radio_info);
Dustin Browna2868622018-03-20 11:38:14 -070011597 hdd_debug("Added radio index tlv - radio index %d",
11598 radio_info->radio);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011599 }
11600
11601 nlh->nlmsg_len += tlv_len;
11602 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
11603
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011604 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011605}
11606
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011607#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
11608void wlan_hdd_auto_shutdown_cb(void)
11609{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011610 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011611
11612 if (!hdd_ctx)
11613 return;
11614
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011615 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011616 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
11617 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011618}
11619
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011620void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011621{
Jeff Johnson9d295242017-08-29 14:39:48 -070011622 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011623 bool ap_connected = false, sta_connected = false;
Jeff Johnson16528362018-06-14 12:34:16 -070011624 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011625
Jeff Johnson16528362018-06-14 12:34:16 -070011626 mac_handle = hdd_ctx->mac_handle;
11627 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011628 return;
11629
11630 if (hdd_ctx->config->WlanAutoShutdown == 0)
11631 return;
11632
11633 if (enable == false) {
Jeff Johnson16528362018-06-14 12:34:16 -070011634 if (sme_set_auto_shutdown_timer(mac_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011635 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011636 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011637 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011638 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011639 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011640 return;
11641 }
11642
11643 /* To enable shutdown timer check conncurrency */
Dustin Brown920397d2017-12-13 16:27:50 -080011644 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->hdd_psoc)) {
11645 hdd_for_each_adapter(hdd_ctx, adapter) {
11646 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011647 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11648 conn_info.connState ==
11649 eConnectionState_Associated) {
11650 sta_connected = true;
11651 break;
11652 }
11653 }
Dustin Brown920397d2017-12-13 16:27:50 -080011654
11655 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011656 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070011657 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011658 ap_connected = true;
11659 break;
11660 }
11661 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011662 }
11663 }
11664
11665 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011666 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011667 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011668 }
Jeff Johnson68755312017-02-10 11:46:55 -080011669
Jeff Johnson16528362018-06-14 12:34:16 -070011670 if (sme_set_auto_shutdown_timer(mac_handle,
Jeff Johnson68755312017-02-10 11:46:55 -080011671 hdd_ctx->config->WlanAutoShutdown)
11672 != QDF_STATUS_SUCCESS)
11673 hdd_err("Failed to start wlan auto shutdown timer");
11674 else
Dustin Brown5e89ef82018-03-14 11:50:23 -070011675 hdd_info("Auto Shutdown timer for %d seconds enabled",
11676 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011677}
11678#endif
11679
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011680struct hdd_adapter *
11681hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
11682 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011683{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011684 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011685 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011686
11687 con_sap_adapter = NULL;
11688
Dustin Brown920397d2017-12-13 16:27:50 -080011689 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011690 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
11691 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011692 adapter != this_sap_adapter) {
11693 if (check_start_bss) {
11694 if (test_bit(SOFTAP_BSS_STARTED,
11695 &adapter->event_flags)) {
11696 con_sap_adapter = adapter;
11697 break;
11698 }
11699 } else {
11700 con_sap_adapter = adapter;
11701 break;
11702 }
11703 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011704 }
11705
11706 return con_sap_adapter;
11707}
11708
11709#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070011710static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011711{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011712 return adapter->device_mode == QDF_STA_MODE ||
11713 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011714}
11715
Jeff Johnson9d295242017-08-29 14:39:48 -070011716static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011717{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011718 return adapter->device_mode == QDF_SAP_MODE ||
11719 adapter->device_mode == QDF_P2P_GO_MODE;
11720}
11721
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011722static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011723{
Dustin Brown920397d2017-12-13 16:27:50 -080011724 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070011725
Dustin Brown920397d2017-12-13 16:27:50 -080011726 hdd_for_each_adapter(hdd_ctx, adapter) {
11727 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070011728 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11729 conn_info.connState == eConnectionState_Associated) {
11730 return true;
11731 }
11732
Dustin Brown920397d2017-12-13 16:27:50 -080011733 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070011734 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070011735 return true;
11736 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011737 }
11738
11739 return false;
11740}
11741
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011742static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011743{
11744 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011745
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011746 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011747 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011748 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011749
Dustin Brown5ec6b552017-03-31 12:11:40 -070011750 return is_running;
11751}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011752
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011753static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011754{
11755 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11756 hdd_ctx->bus_bw_timer_running = true;
11757 qdf_timer_start(&hdd_ctx->bus_bw_timer,
11758 hdd_ctx->config->busBandwidthComputeInterval);
11759 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11760}
11761
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011762void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011763{
Dustin Brown491d54b2018-03-14 12:39:11 -070011764 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011765
11766 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11767 hdd_debug("Bandwidth compute timer already started");
11768 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011769 }
11770
Dustin Brown5ec6b552017-03-31 12:11:40 -070011771 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11772
Dustin Browne74003f2018-03-14 12:51:58 -070011773 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011774}
11775
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011776void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011777{
Dustin Brown491d54b2018-03-14 12:39:11 -070011778 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011779
11780 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11781 hdd_debug("Bandwidth compute timer already started");
11782 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070011783 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011784
11785 if (hdd_any_adapter_is_assoc(hdd_ctx))
11786 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11787
Dustin Browne74003f2018-03-14 12:51:58 -070011788 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011789}
11790
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011791static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011792{
Sravan Kumar Kairam9e99e9a2018-03-12 19:09:45 +053011793 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, 0, 0);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011794
11795 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11796 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
11797 hdd_ctx->bus_bw_timer_running = false;
11798 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11799
11800 hdd_reset_tcp_delack(hdd_ctx);
11801}
11802
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011803void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011804{
Dustin Brown491d54b2018-03-14 12:39:11 -070011805 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011806
11807 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11808 hdd_debug("Bandwidth compute timer already stopped");
11809 return;
11810 }
11811
11812 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11813
Dustin Browne74003f2018-03-14 12:51:58 -070011814 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011815}
11816
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011817void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011818{
Dustin Brown491d54b2018-03-14 12:39:11 -070011819 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011820
11821 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11822 hdd_debug("Bandwidth compute timer already stopped");
11823 return;
11824 }
11825
11826 if (!hdd_any_adapter_is_assoc(hdd_ctx))
11827 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11828
Dustin Browne74003f2018-03-14 12:51:58 -070011829 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011830}
11831#endif
11832
11833/**
11834 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
11835 * and sta's operating channel.
11836 * @sta_adapter: Describe the first argument to foobar.
11837 * @ap_adapter: Describe the second argument to foobar.
11838 * @roam_profile: Roam profile of AP to which STA wants to connect.
11839 * @concurrent_chnl_same: If both SAP and STA channels are same then
11840 * set this flag to true else false.
11841 *
11842 * This function checks the sap's operating channel and sta's operating channel.
11843 * if both are same then it will return false else it will restart the sap in
11844 * sta's channel and return true.
11845 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011846 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011847 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011848QDF_STATUS
11849wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
11850 struct hdd_adapter *ap_adapter,
Jeff Johnson61b5e982018-03-15 11:33:31 -070011851 struct csr_roam_profile *roam_profile,
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011852 tScanResultHandle *scan_cache,
11853 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011854{
Jeff Johnson87251032017-08-29 13:31:11 -070011855 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011856 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011857 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011858 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011859 *concurrent_chnl_same = true;
11860
11861 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11862 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070011863 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011864 scan_cache,
11865 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011866 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011867 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011868 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011869 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011870 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011871 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011872 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011873 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011874 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011875 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011876 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011877 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011878 }
11879 }
11880 } else {
11881 /*
11882 * Lets handle worst case scenario here, Scan cache lookup is
11883 * failed so we have to stop the SAP to avoid any channel
11884 * discrepancy between SAP's channel and STA's channel.
11885 * Return the status as failure so caller function could know
11886 * that scan look up is failed.
11887 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070011888 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011889 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011890 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011891 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011892}
11893
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011894/**
11895 * wlan_hdd_stop_sap() - This function stops bss of SAP.
11896 * @ap_adapter: SAP adapter
11897 *
11898 * This function will process the stopping of sap adapter.
11899 *
11900 * Return: None
11901 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011902void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011903{
Jeff Johnson87251032017-08-29 13:31:11 -070011904 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011905 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011906 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011907 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011908
11909 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011910 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011911 return;
11912 }
11913
11914 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11915 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011916 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011917 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011918
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011919 mutex_lock(&hdd_ctx->sap_lock);
11920 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080011921 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011922 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011923 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011924 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011925 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011926 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053011927 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080011928 qdf_stop_bss_event,
11929 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011930 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011931 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070011932 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011933 return;
11934 }
11935 }
11936 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011937 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
11938 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011939 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070011940 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011941 false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011942 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011943 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011944 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011945 }
11946 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011947}
11948
11949/**
11950 * wlan_hdd_start_sap() - this function starts bss of SAP.
11951 * @ap_adapter: SAP adapter
11952 *
11953 * This function will process the starting of sap adapter.
11954 *
11955 * Return: None
11956 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011957void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011958{
Jeff Johnson87251032017-08-29 13:31:11 -070011959 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011960 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011961 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011962 struct hdd_context *hdd_ctx;
Jeff Johnsone4c11db2018-05-05 23:22:32 -070011963 tsap_config_t *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011964
11965 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011966 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011967 return;
11968 }
11969
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011970 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070011971 hdd_err("SoftAp role has not been enabled");
11972 return;
11973 }
11974
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011975 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
11976 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11977 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070011978 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011979
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011980 mutex_lock(&hdd_ctx->sap_lock);
11981 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
11982 goto end;
11983
11984 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011985 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011986 goto end;
11987 }
11988
Wei Song2f76f642016-11-18 16:32:53 +080011989 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011990 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070011991 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011992 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011993 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011994 goto end;
11995
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011996 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053011997 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080011998 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011999 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070012000 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012001 goto end;
12002 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070012003 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012004 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012005 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012006 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080012007 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
12008 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070012009 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070012010 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053012011 true);
12012 }
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053012013 mutex_unlock(&hdd_ctx->sap_lock);
12014
12015 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012016end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012017 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012018 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070012019 /* SAP context and beacon cleanup will happen during driver unload
12020 * in hdd_stop_adapter
12021 */
12022 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
12023
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012024}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012025
12026/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080012027 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
12028 * mac scan config
12029 * @status: Status of set antenna mode
12030 *
12031 * Callback on setting the dual mac configuration
12032 *
12033 * Return: None
12034 */
12035void wlan_hdd_soc_set_antenna_mode_cb(
12036 enum set_antenna_mode_status status)
12037{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012038 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080012039
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012040 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080012041
12042 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12043 if (0 != wlan_hdd_validate_context(hdd_ctx))
12044 return;
12045
12046 /* Signal the completion of set dual mac config */
12047 complete(&hdd_ctx->set_antenna_mode_cmpl);
12048}
12049
12050/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012051 * hdd_get_fw_version() - Get FW version
12052 * @hdd_ctx: pointer to HDD context.
12053 * @major_spid: FW version - major spid.
12054 * @minor_spid: FW version - minor spid
12055 * @ssid: FW version - ssid
12056 * @crmid: FW version - crmid
12057 *
12058 * This function is called to get the firmware build version stored
12059 * as part of the HDD context
12060 *
12061 * Return: None
12062 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012063void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012064 uint32_t *major_spid, uint32_t *minor_spid,
12065 uint32_t *siid, uint32_t *crmid)
12066{
12067 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
12068 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
12069 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
12070 *crmid = hdd_ctx->target_fw_version & 0x7fff;
12071}
12072
12073#ifdef QCA_CONFIG_SMP
12074/**
12075 * wlan_hdd_get_cpu() - get cpu_index
12076 *
12077 * Return: cpu_index
12078 */
12079int wlan_hdd_get_cpu(void)
12080{
12081 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012082
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012083 put_cpu();
12084 return cpu_index;
12085}
12086#endif
12087
12088/**
12089 * hdd_get_fwpath() - get framework path
12090 *
12091 * This function is used to get the string written by
12092 * userspace to start the wlan driver
12093 *
12094 * Return: string
12095 */
12096const char *hdd_get_fwpath(void)
12097{
12098 return fwpath.string;
12099}
12100
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070012101static int hdd_qdf_print_init(void)
12102{
12103 int qdf_print_idx;
12104 QDF_STATUS status;
12105
12106 status = qdf_print_setup();
12107 if (status != QDF_STATUS_SUCCESS) {
12108 pr_err("qdf_print_setup failed\n");
12109 return -EINVAL;
12110 }
12111
12112 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
12113
12114 if (qdf_print_idx < 0) {
12115 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
12116 qdf_print_idx);
12117 return -EINVAL;
12118 }
12119
12120 qdf_set_pidx(qdf_print_idx);
12121
12122 return 0;
12123}
12124
12125static void hdd_qdf_print_deinit(void)
12126{
12127 int qdf_print_idx;
12128
12129 qdf_print_idx = qdf_get_pidx();
12130 qdf_print_ctrl_cleanup(qdf_print_idx);
12131}
12132
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012133/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012134 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012135 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012136 * This function initilizes CDS global context with the help of cds_init. This
12137 * has to be the first function called after probe to get a valid global
12138 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012139 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012140 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012141 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012142int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012143{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012144 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012145 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012146
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012147 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080012148 if (QDF_IS_STATUS_ERROR(status)) {
12149 hdd_err("Failed to allocate CDS context");
12150 ret = -ENOMEM;
12151 goto err_out;
12152 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053012153
12154 wlan_init_bug_report_lock();
12155
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012156#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12157 wlan_logging_sock_init_svc();
12158#endif
12159
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012160 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
12161 (void *)hdd_drv_ops_inactivity_handler, NULL,
12162 QDF_TIMER_TYPE_SW);
12163
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012164 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070012165 hdd_qdf_print_init();
12166
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053012167 hdd_register_debug_callback();
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012168 wlan_roam_debug_init();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012169
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012170err_out:
12171 return ret;
12172}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012173
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012174/**
12175 * hdd_deinit() - Deinitialize Driver
12176 *
12177 * This function frees CDS global context with the help of cds_deinit. This
12178 * has to be the last function call in remove callback to free the global
12179 * context.
12180 */
12181void hdd_deinit(void)
12182{
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012183 wlan_roam_debug_deinit();
12184 hdd_qdf_print_deinit();
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012185 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012186
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012187#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12188 wlan_logging_sock_deinit_svc();
12189#endif
Qiwei Caiad9b01c2018-07-09 17:21:31 +080012190
12191 wlan_destroy_bug_report_lock();
12192 cds_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012193}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012194
Yue Ma6e7b1a02017-04-03 14:17:46 -070012195#ifdef QCA_WIFI_NAPIER_EMULATION
12196#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
12197#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012198#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070012199#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012200
Sachin Ahujadddd2632017-03-07 19:07:24 +053012201static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
12202 struct file *file)
12203{
12204 return 0;
12205}
12206
12207static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
12208 const char __user *user_buf,
12209 size_t count,
12210 loff_t *f_pos)
12211{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012212 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053012213 static const char wlan_off_str[] = "OFF";
12214 static const char wlan_on_str[] = "ON";
12215 int ret;
12216 unsigned long rc;
12217
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012218 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012219 pr_err("Failed to read buffer\n");
12220 return -EINVAL;
12221 }
12222
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012223 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012224 pr_debug("Wifi turning off from UI\n");
12225 goto exit;
12226 }
12227
Sachin Ahuja16904db2017-12-13 19:56:57 +053012228 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) == 0) {
12229 pr_info("Wifi Turning On from UI\n");
12230 }
12231
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012232 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012233 pr_err("Invalid value received from framework");
12234 goto exit;
12235 }
12236
12237 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053012238 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053012239 rc = wait_for_completion_timeout(&wlan_start_comp,
12240 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
12241 if (!rc) {
12242 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
12243 ret = -EINVAL;
Sachin Ahujadddd2632017-03-07 19:07:24 +053012244 return ret;
12245 }
12246
12247 hdd_start_complete(0);
12248 }
12249
12250exit:
12251 return count;
12252}
12253
12254
12255const struct file_operations wlan_hdd_state_fops = {
12256 .owner = THIS_MODULE,
12257 .open = wlan_hdd_state_ctrl_param_open,
12258 .write = wlan_hdd_state_ctrl_param_write,
12259};
12260
12261static int wlan_hdd_state_ctrl_param_create(void)
12262{
12263 unsigned int wlan_hdd_state_major = 0;
12264 int ret;
12265 struct device *dev;
12266
12267 device = MKDEV(wlan_hdd_state_major, 0);
12268
12269 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
12270 if (ret) {
12271 pr_err("Failed to register qcwlanstate");
12272 goto dev_alloc_err;
12273 }
12274 wlan_hdd_state_major = MAJOR(device);
12275
12276 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
12277 if (IS_ERR(class)) {
12278 pr_err("wlan_hdd_state class_create error");
12279 goto class_err;
12280 }
12281
12282 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
12283 if (IS_ERR(dev)) {
12284 pr_err("wlan_hdd_statedevice_create error");
12285 goto err_class_destroy;
12286 }
12287
12288 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
12289 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
12290 if (ret) {
12291 pr_err("Failed to add cdev error");
12292 goto cdev_add_err;
12293 }
12294
12295 pr_info("wlan_hdd_state %s major(%d) initialized",
12296 WLAN_MODULE_NAME, wlan_hdd_state_major);
12297
12298 return 0;
12299
12300cdev_add_err:
12301 device_destroy(class, device);
12302err_class_destroy:
12303 class_destroy(class);
12304class_err:
12305 unregister_chrdev_region(device, dev_num);
12306dev_alloc_err:
12307 return -ENODEV;
12308}
12309
12310static void wlan_hdd_state_ctrl_param_destroy(void)
12311{
12312 cdev_del(&wlan_hdd_state_cdev);
12313 device_destroy(class, device);
12314 class_destroy(class);
12315 unregister_chrdev_region(device, dev_num);
12316
12317 pr_info("Device node unregistered");
12318}
12319
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012320/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053012321 * component_init - API to init cld component's
12322 *
12323 * Return: None
12324 */
12325static void component_init(void)
12326{
12327 pmo_init();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012328 disa_init();
Zhang Qian47e22ce2018-01-04 15:38:38 +080012329 ucfg_ocb_init();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053012330 ipa_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053012331}
12332
12333/**
12334 * component_deinit - API to deinit cld component's
12335 *
12336 * Return: None
12337 */
12338static void component_deinit(void)
12339{
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053012340 ipa_deinit();
Zhang Qian47e22ce2018-01-04 15:38:38 +080012341 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053012342 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012343 disa_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012344}
12345
12346void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
12347{
Zhang Qian47e22ce2018-01-04 15:38:38 +080012348 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012349 disa_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012350}
12351
12352void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
12353{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012354 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080012355 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053012356}
12357
12358/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012359 * __hdd_module_init - Module init helper
12360 *
12361 * Module init helper function used by both module and static driver.
12362 *
12363 * Return: 0 for success, errno on failure
12364 */
12365static int __hdd_module_init(void)
12366{
12367 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012368
Dustin Brown96cd9632017-11-13 12:45:04 -080012369 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070012370 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080012371 g_wlan_driver_version,
Dustin Brownc1034df2018-02-07 14:51:32 -080012372 TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012373
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012374 pld_init();
12375
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012376 ret = hdd_init();
12377 if (ret) {
12378 pr_err("hdd_init failed %x\n", ret);
12379 goto err_hdd_init;
12380 }
12381
Rajeev Kumar97767a02016-11-30 11:20:40 -080012382 dispatcher_init();
12383
Mukul Sharmad75a6672017-06-22 15:40:53 +053012384 /* Ensure to call post objmgr init */
12385 component_init();
12386
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012387 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012388
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012389 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012390
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012391 ret = wlan_hdd_register_driver();
12392 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070012393 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
12394 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012395 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012396 }
12397
Sachin Ahuja16904db2017-12-13 19:56:57 +053012398 ret = wlan_hdd_state_ctrl_param_create();
12399 if (ret) {
12400 pr_err("wlan_hdd_state_create:%x\n", ret);
12401 goto out;
12402 }
12403
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053012404 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012405
12406 return 0;
12407out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012408 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080012409 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080012410 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012411 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080012412
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012413err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012414 pld_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012415 return ret;
12416}
12417
12418/**
12419 * __hdd_module_exit - Module exit helper
12420 *
12421 * Module exit helper function used by both module and static driver.
12422 */
12423static void __hdd_module_exit(void)
12424{
Will Huang36049722018-04-13 11:48:51 +080012425 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053012426
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012427 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
12428 QWLAN_VERSIONSTR);
12429
Arunk Khandavalli830c9692018-03-22 12:17:40 +053012430 if (!hdd_wait_for_recovery_completion())
12431 return;
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053012432
Will Huangba035ec2018-07-05 11:13:30 +080012433 cds_set_driver_loaded(false);
12434 cds_set_unload_in_progress(true);
12435
12436 if (!cds_wait_for_external_threads_completion(__func__))
12437 hdd_warn("External threads are still active attempting "
12438 "driver unload anyway");
12439
Rajeev Kumar3505ae52018-05-10 18:44:45 -070012440 if (hdd_ctx)
12441 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Will Huang36049722018-04-13 11:48:51 +080012442
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012443 wlan_hdd_unregister_driver();
12444
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012445 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012446
Mukul Sharmad75a6672017-06-22 15:40:53 +053012447 /* Ensure to call prior to objmgr deinit */
12448 component_deinit();
12449
Rajeev Kumar97767a02016-11-30 11:20:40 -080012450 dispatcher_deinit();
Amar Singhal0928b192017-12-01 10:50:54 -080012451
12452 hdd_sysfs_destroy_version_interface();
12453
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012454 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012455 pld_deinit();
12456
Sachin Ahujadddd2632017-03-07 19:07:24 +053012457 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012458}
12459
Arun Khandavallifae92942016-08-01 13:31:08 +053012460#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012461/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012462 * wlan_boot_cb() - Wlan boot callback
12463 * @kobj: object whose directory we're creating the link in.
12464 * @attr: attribute the user is interacting with
12465 * @buff: the buffer containing the user data
12466 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012467 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012468 * This callback is invoked when the fs is ready to start the
12469 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012470 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012471 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012472 */
Arun Khandavallifae92942016-08-01 13:31:08 +053012473static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012474 struct kobj_attribute *attr,
12475 const char *buf,
12476 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012477{
Arun Khandavallifae92942016-08-01 13:31:08 +053012478
Arun Khandavallifae92942016-08-01 13:31:08 +053012479 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012480 pr_err("%s: wlan driver already initialized\n", __func__);
12481 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053012482 }
12483
Arun Khandavallifae92942016-08-01 13:31:08 +053012484 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012485 pr_err("%s: wlan driver initialization failed\n", __func__);
12486 return -EIO;
12487 }
12488
12489 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053012490
12491 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012492}
Arun Khandavallifae92942016-08-01 13:31:08 +053012493
12494/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012495 * hdd_sysfs_cleanup() - cleanup sysfs
12496 *
12497 * Return: None
12498 *
12499 */
12500static void hdd_sysfs_cleanup(void)
12501{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012502 /* remove from group */
12503 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
12504 sysfs_remove_group(wlan_loader->boot_wlan_obj,
12505 wlan_loader->attr_group);
12506
12507 /* unlink the object from parent */
12508 kobject_del(wlan_loader->boot_wlan_obj);
12509
12510 /* free the object */
12511 kobject_put(wlan_loader->boot_wlan_obj);
12512
12513 kfree(wlan_loader->attr_group);
12514 kfree(wlan_loader);
12515
12516 wlan_loader = NULL;
12517}
12518
12519/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012520 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
12521 * ready
12522 *
12523 * This is creates the syfs entry boot_wlan. Which shall be invoked
12524 * when the filesystem is ready.
12525 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012526 * QDF API cannot be used here since this function is called even before
12527 * initializing WLAN driver.
12528 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012529 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053012530 */
12531static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012532{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012533 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012534
12535 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012536 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012537 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012538
12539 wlan_loader->boot_wlan_obj = NULL;
12540 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
12541 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012542 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053012543 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053012544
12545 wlan_loader->loaded_state = 0;
12546 wlan_loader->attr_group->attrs = attrs;
12547
12548 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
12549 kernel_kobj);
12550 if (!wlan_loader->boot_wlan_obj) {
12551 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053012552 goto error_return;
12553 }
12554
12555 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
12556 wlan_loader->attr_group);
12557 if (ret) {
12558 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
12559 goto error_return;
12560 }
12561
12562 return 0;
12563
12564error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012565 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053012566
12567 return ret;
12568}
12569
12570/**
12571 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
12572 *
12573 * Return: 0 on success or errno on failure
12574 */
12575static int wlan_deinit_sysfs(void)
12576{
Arun Khandavallifae92942016-08-01 13:31:08 +053012577 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012578 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053012579 return -EINVAL;
12580 }
12581
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012582 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012583 return 0;
12584}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012585
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012586#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053012587
12588#ifdef MODULE
12589/**
12590 * __hdd_module_init - Module init helper
12591 *
12592 * Module init helper function used by both module and static driver.
12593 *
12594 * Return: 0 for success, errno on failure
12595 */
12596static int hdd_module_init(void)
12597{
Arun Khandavallifae92942016-08-01 13:31:08 +053012598 if (__hdd_module_init()) {
12599 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070012600 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053012601 }
12602
Dustin Brownab482ac2017-06-09 17:00:44 -070012603 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053012604}
12605#else
12606static int __init hdd_module_init(void)
12607{
12608 int ret = -EINVAL;
12609
12610 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012611 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053012612 pr_err("Failed to create sysfs entry for loading wlan");
12613
12614 return ret;
12615}
12616#endif
12617
12618
12619#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012620/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012621 * hdd_module_exit() - Exit function
12622 *
12623 * This is the driver exit point (invoked when module is unloaded using rmmod)
12624 *
12625 * Return: None
12626 */
12627static void __exit hdd_module_exit(void)
12628{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012629 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012630}
Arun Khandavallifae92942016-08-01 13:31:08 +053012631#else
12632static void __exit hdd_module_exit(void)
12633{
12634 __hdd_module_exit();
12635 wlan_deinit_sysfs();
12636}
12637#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012638
Srinivas Girigowda841da292018-02-21 16:33:00 -080012639static int fwpath_changed_handler(const char *kmessage,
12640 const struct kernel_param *kp)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012641{
12642 return param_set_copystring(kmessage, kp);
12643}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012644
Nirav Shah73713f72018-05-17 14:50:41 +053012645#ifdef FEATURE_MONITOR_MODE_SUPPORT
12646static bool is_monitor_mode_supported(void)
12647{
12648 return true;
12649}
12650#else
12651static bool is_monitor_mode_supported(void)
12652{
12653 pr_err("Monitor mode not supported!");
12654 return false;
12655}
12656#endif
12657
12658#ifdef WLAN_FEATURE_EPPING
12659static bool is_epping_mode_supported(void)
12660{
12661 return true;
12662}
12663#else
12664static bool is_epping_mode_supported(void)
12665{
12666 pr_err("Epping mode not supported!");
12667 return false;
12668}
12669#endif
12670
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012671/**
12672 * is_con_mode_valid() check con mode is valid or not
12673 * @mode: global con mode
12674 *
12675 * Return: TRUE on success FALSE on failure
12676 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012677static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012678{
12679 switch (mode) {
12680 case QDF_GLOBAL_MONITOR_MODE:
Nirav Shah73713f72018-05-17 14:50:41 +053012681 return is_monitor_mode_supported();
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012682 case QDF_GLOBAL_EPPING_MODE:
Nirav Shah73713f72018-05-17 14:50:41 +053012683 return is_epping_mode_supported();
12684 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012685 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012686 return true;
12687 default:
12688 return false;
12689 }
12690}
12691
12692/**
12693 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
12694 * @mode: global con mode
12695 *
12696 * Return: adapter mode
12697 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012698static enum QDF_OPMODE hdd_get_adpter_mode(
Jeff Johnson876c1a62017-12-12 10:43:07 -080012699 enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012700{
12701
12702 switch (mode) {
12703 case QDF_GLOBAL_MISSION_MODE:
12704 return QDF_STA_MODE;
12705 case QDF_GLOBAL_MONITOR_MODE:
12706 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012707 case QDF_GLOBAL_EPPING_MODE:
12708 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012709 case QDF_GLOBAL_FTM_MODE:
12710 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012711 case QDF_GLOBAL_QVIT_MODE:
12712 return QDF_QVIT_MODE;
12713 default:
12714 return QDF_MAX_NO_OF_MODE;
12715 }
12716}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012717
Dustin Brown27cd9942017-09-27 16:11:44 -070012718static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012719 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070012720{
12721 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
12722 return;
12723
12724 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070012725 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012726 hdd_info("Release wakelock for monitor mode!");
12727 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
12728 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
Dundi Raviteja0a2a65b2018-04-30 12:34:11 +053012729 /* fallthrough */
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012730 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070012731 case QDF_GLOBAL_FTM_MODE:
12732 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +053012733 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Dustin Browndb2a8be2017-12-20 11:49:56 -080012734 hdd_stop_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -070012735
Dustin Brown27cd9942017-09-27 16:11:44 -070012736 break;
12737 default:
12738 break;
12739 }
12740}
12741
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012742static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012743 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012744{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053012745 int driver_status;
12746
12747 driver_status = hdd_ctx->driver_status;
12748
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012749 switch (curr_mode) {
12750 case QDF_GLOBAL_MISSION_MODE:
12751 case QDF_GLOBAL_MONITOR_MODE:
12752 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012753 hdd_deinit_all_adapters(hdd_ctx, false);
12754 hdd_close_all_adapters(hdd_ctx, false);
12755 break;
12756 case QDF_GLOBAL_EPPING_MODE:
12757 epping_disable();
12758 epping_close();
12759 break;
12760 default:
12761 return;
12762 }
12763}
12764
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012765static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012766 enum QDF_GLOBAL_MODE mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012767{
Jeff Johnson9d295242017-08-29 14:39:48 -070012768 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012769 int ret = 0;
12770 bool rtnl_held;
12771 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
12772 QDF_STATUS status;
12773
12774 if (!qdf_dev) {
12775 hdd_err("qdf device context is Null return!");
12776 return -EINVAL;
12777 }
12778
12779 rtnl_held = hdd_hold_rtnl_lock();
12780 switch (mode) {
12781 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080012782 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
12783 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012784 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012785 break;
12786 case QDF_GLOBAL_FTM_MODE:
12787 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
12788 wlan_hdd_get_intf_addr(hdd_ctx),
12789 NET_NAME_UNKNOWN, rtnl_held);
12790 if (adapter == NULL)
12791 ret = -EINVAL;
12792 break;
12793 case QDF_GLOBAL_MONITOR_MODE:
12794 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
12795 wlan_hdd_get_intf_addr(hdd_ctx),
12796 NET_NAME_UNKNOWN, rtnl_held);
12797 if (adapter == NULL)
12798 ret = -EINVAL;
12799 break;
12800 case QDF_GLOBAL_EPPING_MODE:
12801 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012802 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012803 hdd_err("Failed to open in eeping mode: %d", status);
12804 ret = -EINVAL;
12805 break;
12806 }
12807 ret = epping_enable(qdf_dev->dev);
12808 if (ret) {
12809 hdd_err("Failed to enable in epping mode : %d", ret);
12810 epping_close();
12811 }
12812 break;
12813 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012814 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012815 ret = -ENOTSUPP;
12816 break;
12817 }
12818 hdd_release_rtnl_lock();
12819 rtnl_held = false;
12820 return ret;
12821}
12822
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012823/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012824 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012825 * @kmessage: con mode name on which driver to be bring up
12826 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012827 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012828 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012829 * This function is invoked when user updates con mode using sys entry,
12830 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012831 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012832 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012833 */
Srinivas Girigowda841da292018-02-21 16:33:00 -080012834static int __con_mode_handler(const char *kmessage,
12835 const struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012836 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012837{
12838 int ret;
Jeff Johnson876c1a62017-12-12 10:43:07 -080012839 enum QDF_GLOBAL_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012840 enum QDF_OPMODE adapter_mode;
Dustin Brown20024e32018-01-03 12:34:58 -080012841 int new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012842
Dustin Brownab6029b2017-05-24 13:04:19 -070012843 hdd_info("con_mode handler: %s", kmessage);
12844
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012845 ret = wlan_hdd_validate_context(hdd_ctx);
12846 if (ret)
12847 return ret;
12848
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012849 qdf_atomic_set(&hdd_ctx->con_mode_flag, 1);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012850
Dustin Brown20024e32018-01-03 12:34:58 -080012851 ret = kstrtoint(kmessage, 0, &new_con_mode);
12852 if (ret) {
12853 hdd_err("Failed to parse con_mode '%s'", kmessage);
12854 goto reset_flags;
12855 }
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012856 mutex_lock(&hdd_init_deinit_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +053012857
Dustin Brown20024e32018-01-03 12:34:58 -080012858 if (!is_con_mode_valid(new_con_mode)) {
12859 hdd_err("invalid con_mode %d", new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012860 ret = -EINVAL;
12861 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012862 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012863
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012864 curr_mode = hdd_get_conparam();
Dustin Brown20024e32018-01-03 12:34:58 -080012865 if (curr_mode == new_con_mode) {
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012866 hdd_err("curr mode: %d is same as user triggered mode %d",
Dustin Brown20024e32018-01-03 12:34:58 -080012867 curr_mode, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012868 ret = 0;
12869 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012870 }
12871
Dustin Brown27cd9942017-09-27 16:11:44 -070012872 /* ensure adapters are stopped */
12873 hdd_stop_present_mode(hdd_ctx, curr_mode);
12874
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070012875 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053012876 if (ret) {
12877 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012878 goto reset_flags;
12879 }
12880
Dustin Browndd4e50f2018-05-24 15:43:42 -070012881 /* Cleanup present mode before switching to new mode */
12882 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053012883
Dustin Brown20024e32018-01-03 12:34:58 -080012884 hdd_set_conparam(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012885
12886 /* Register for new con_mode & then kick_start modules again */
Dustin Brown20024e32018-01-03 12:34:58 -080012887 ret = hdd_register_req_mode(hdd_ctx, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012888 if (ret) {
12889 hdd_err("Failed to register for new mode");
12890 goto reset_flags;
12891 }
12892
Dustin Brown20024e32018-01-03 12:34:58 -080012893 adapter_mode = hdd_get_adpter_mode(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012894 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
12895 hdd_err("invalid adapter");
12896 ret = -EINVAL;
12897 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012898 }
12899
Dustin Browne7e71d32018-05-11 16:00:08 -070012900 ret = hdd_wlan_start_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053012901 if (ret) {
12902 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012903 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012904 }
12905
Dustin Brown20024e32018-01-03 12:34:58 -080012906 if (new_con_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Browne7e71d32018-05-11 16:00:08 -070012907 struct hdd_adapter *adapter =
12908 hdd_get_adapter(hdd_ctx, adapter_mode);
12909
12910 if (!adapter) {
12911 hdd_err("Failed to get adapter:%d", adapter_mode);
12912 goto reset_flags;
12913 }
12914
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012915 if (hdd_start_adapter(adapter)) {
12916 hdd_err("Failed to start %s adapter", kmessage);
12917 ret = -EINVAL;
12918 goto reset_flags;
12919 }
Arun Khandavallifae92942016-08-01 13:31:08 +053012920
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012921 hdd_info("Acquire wakelock for monitor mode!");
12922 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
12923 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12924 }
12925
Dustin Brown20024e32018-01-03 12:34:58 -080012926 /* con_mode is a global module parameter */
12927 con_mode = new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012928 hdd_info("Mode successfully changed to %s", kmessage);
12929 ret = 0;
12930
12931reset_flags:
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012932 mutex_unlock(&hdd_init_deinit_lock);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012933 qdf_atomic_set(&hdd_ctx->con_mode_flag, 0);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012934 return ret;
12935}
12936
12937
Srinivas Girigowda841da292018-02-21 16:33:00 -080012938static int con_mode_handler(const char *kmessage, const struct kernel_param *kp)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012939{
12940 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012941 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012942
12943 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12944 ret = wlan_hdd_validate_context(hdd_ctx);
12945 if (ret)
12946 return ret;
12947
Ashish Kumar Dhanotiya759b3272018-05-18 17:49:46 +053012948 if (!cds_wait_for_external_threads_completion(__func__)) {
12949 hdd_warn("External threads are still active, can not change mode");
12950 return -EAGAIN;
12951 }
12952
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012953 cds_ssr_protect(__func__);
12954 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
12955 cds_ssr_unprotect(__func__);
12956
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012957 return ret;
12958}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012959
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012960static int con_mode_handler_ftm(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080012961 const struct kernel_param *kp)
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012962{
12963 int ret;
12964
12965 ret = param_set_int(kmessage, kp);
12966
12967 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
12968 pr_err("Only FTM mode supported!");
12969 return -ENOTSUPP;
12970 }
12971
12972 hdd_set_conparam(con_mode_ftm);
12973 con_mode = con_mode_ftm;
12974
12975 return ret;
12976}
12977
Nirav Shah73713f72018-05-17 14:50:41 +053012978#ifdef FEATURE_MONITOR_MODE_SUPPORT
Ravi Joshia307f632017-07-17 23:41:41 -070012979static int con_mode_handler_monitor(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080012980 const struct kernel_param *kp)
Ravi Joshia307f632017-07-17 23:41:41 -070012981{
12982 int ret;
12983
12984 ret = param_set_int(kmessage, kp);
12985
12986 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
12987 pr_err("Only Monitor mode supported!");
12988 return -ENOTSUPP;
12989 }
12990
12991 hdd_set_conparam(con_mode_monitor);
12992 con_mode = con_mode_monitor;
12993
12994 return ret;
12995}
Nirav Shah73713f72018-05-17 14:50:41 +053012996#endif
Ravi Joshia307f632017-07-17 23:41:41 -070012997
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012998/**
12999 * hdd_get_conparam() - driver exit point
13000 *
13001 * This is the driver exit point (invoked when module is unloaded using rmmod)
13002 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080013003 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013004 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080013005enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013006{
Jeff Johnson876c1a62017-12-12 10:43:07 -080013007 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013008}
13009
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080013010void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013011{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080013012 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080013013}
13014
Komal Seelamc11bb222016-01-27 18:57:10 +053013015/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013016 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
13017 * @hdd_ctx: HDD context
13018 *
13019 * Cleans up the pre cac interface, if it exists
13020 *
13021 * Return: None
13022 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013023void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013024{
13025 uint8_t session_id;
13026 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070013027 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013028
Jeff Johnson16528362018-06-14 12:34:16 -070013029 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->mac_handle, &session_id);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013030 if (QDF_IS_STATUS_ERROR(status)) {
13031 hdd_err("failed to get pre cac vdev id");
13032 return;
13033 }
13034
13035 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
13036 if (!precac_adapter) {
Jeff Johnsondd2f1fc2018-05-06 11:22:52 -070013037 hdd_err("invalid pre cac adapter");
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013038 return;
13039 }
13040
13041 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
13042 wlan_hdd_sap_pre_cac_failure,
13043 (void *)precac_adapter);
13044 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
13045
13046}
13047
13048/**
Komal Seelamec702b02016-02-24 18:42:16 +053013049 * hdd_update_ol_config - API to update ol configuration parameters
13050 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053013051 *
Komal Seelamc11bb222016-01-27 18:57:10 +053013052 * Return: void
13053 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013054static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053013055{
Komal Seelamec702b02016-02-24 18:42:16 +053013056 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053013057 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053013058
Komal Seelamec702b02016-02-24 18:42:16 +053013059 if (!ol_ctx)
13060 return;
13061
13062 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
13063 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
13064 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
13065 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070013066 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053013067
13068 ol_init_ini_config(ol_ctx, &cfg);
13069}
13070
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013071#ifdef FEATURE_RUNTIME_PM
13072/**
13073 * hdd_populate_runtime_cfg() - populate runtime configuration
13074 * @hdd_ctx: hdd context
13075 * @cfg: pointer to the configuration memory being populated
13076 *
13077 * Return: void
13078 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013079static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013080 struct hif_config_info *cfg)
13081{
13082 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
13083 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
13084}
13085#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013086static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013087 struct hif_config_info *cfg)
13088{
13089}
13090#endif
13091
Komal Seelamec702b02016-02-24 18:42:16 +053013092/**
13093 * hdd_update_hif_config - API to update HIF configuration parameters
13094 * @hdd_ctx: HDD Context
13095 *
13096 * Return: void
13097 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013098static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053013099{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053013100 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053013101 struct hif_config_info cfg;
13102
13103 if (!scn)
13104 return;
13105
13106 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013107 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053013108 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070013109
13110 if (hdd_ctx->config->prevent_link_down)
13111 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053013112}
13113
13114/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013115 * hdd_update_dp_config() - Propagate config parameters to Lithium
13116 * datapath
13117 * @hdd_ctx: HDD Context
13118 *
13119 * Return: 0 for success/errno for failure
13120 */
13121static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
13122{
13123 struct cdp_config_params params;
13124 QDF_STATUS status;
13125
13126 params.tso_enable = hdd_ctx->config->tso_enable;
13127 params.lro_enable = hdd_ctx->config->lro_enable;
13128#ifdef QCA_LL_TX_FLOW_CONTROL_V2
13129 params.tx_flow_stop_queue_threshold =
13130 hdd_ctx->config->TxFlowStopQueueThreshold;
13131 params.tx_flow_start_queue_offset =
13132 hdd_ctx->config->TxFlowStartQueueOffset;
13133#endif
13134 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
13135 params.napi_enable = hdd_ctx->napi_enable;
13136 params.tcp_udp_checksumoffload =
13137 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
13138
13139 status = cdp_update_config_parameters(
13140 cds_get_context(QDF_MODULE_ID_SOC),
13141 &params);
13142 if (status) {
Dustin Browna2868622018-03-20 11:38:14 -070013143 hdd_err("Failed to attach config parameters");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013144 return status;
13145 }
13146
13147 return 0;
13148}
13149
13150/**
Komal Seelamec702b02016-02-24 18:42:16 +053013151 * hdd_update_config() - Initialize driver per module ini parameters
13152 * @hdd_ctx: HDD Context
13153 *
13154 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013155 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053013156 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013157int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053013158{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013159 int ret;
13160
Komal Seelamec702b02016-02-24 18:42:16 +053013161 hdd_update_ol_config(hdd_ctx);
13162 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013163 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
13164 ret = hdd_update_cds_config_ftm(hdd_ctx);
13165 else
13166 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080013167 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013168
13169 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053013170}
13171
Mukul Sharma9d797a02017-01-05 20:26:03 +053013172#ifdef FEATURE_WLAN_RA_FILTERING
13173/**
13174 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
13175 * @psoc_cfg: pmo psoc Configuration
13176 * @hdd_ctx: Pointer to hdd context
13177 *
13178 * Return: none
13179 */
13180static inline void hdd_ra_populate_pmo_config(
13181 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013182 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013183{
13184 psoc_cfg->ra_ratelimit_interval =
13185 hdd_ctx->config->RArateLimitInterval;
13186 psoc_cfg->ra_ratelimit_enable =
13187 hdd_ctx->config->IsRArateLimitEnabled;
13188}
13189#else
13190static inline void hdd_ra_populate_pmo_config(
13191 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013192 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013193{
13194}
13195#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080013196
Mukul Sharma9d797a02017-01-05 20:26:03 +053013197/**
13198 * hdd_update_pmo_config - API to update pmo configuration parameters
13199 * @hdd_ctx: HDD context
13200 *
13201 * Return: void
13202 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013203static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013204{
Mukul Sharma9d797a02017-01-05 20:26:03 +053013205 struct pmo_psoc_cfg psoc_cfg;
13206 QDF_STATUS status;
13207
13208 /*
13209 * Value of hdd_ctx->wowEnable can be,
13210 * 0 - Disable both magic pattern match and pattern byte match.
13211 * 1 - Enable magic pattern match on all interfaces.
13212 * 2 - Enable pattern byte match on all interfaces.
13213 * 3 - Enable both magic patter and pattern byte match on
13214 * all interfaces.
13215 */
13216 psoc_cfg.magic_ptrn_enable =
13217 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
13218 psoc_cfg.ptrn_match_enable_all_vdev =
13219 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Nachiket Kukadee547a482018-05-22 16:43:30 +053013220 psoc_cfg.apf_enable = hdd_ctx->config->apf_packet_filter_enable;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013221 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Nachiket Kukadef0804072018-02-27 18:20:07 +053013222 psoc_cfg.hw_filter_mode_bitmap = hdd_ctx->config->hw_filter_mode_bitmap;
Dustin Brownb9987af2018-03-01 17:15:11 -080013223 psoc_cfg.ns_offload_enable_dynamic = hdd_ctx->config->fhostNSOffload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013224 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
Dustin Brownb9987af2018-03-01 17:15:11 -080013225 psoc_cfg.packet_filter_enabled = !hdd_ctx->config->disablePacketFilter;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013226 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
13227 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
Dustin Brownb9987af2018-03-01 17:15:11 -080013228 psoc_cfg.active_mode_offload = hdd_ctx->config->active_mode_offload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013229 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080013230 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9223f232017-03-08 18:42:27 +053013231 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
13232 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
13233 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
Dustin Brownb9987af2018-03-01 17:15:11 -080013234 psoc_cfg.power_save_mode = hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053013235 psoc_cfg.auto_power_save_fail_mode =
13236 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013237
13238 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053013239 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
13240 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013241
Dustin Brownb9987af2018-03-01 17:15:11 -080013242 status = ucfg_pmo_update_psoc_config(hdd_ctx->hdd_psoc, &psoc_cfg);
13243 if (QDF_IS_STATUS_ERROR(status))
13244 hdd_err("failed pmo psoc configuration; status:%d", status);
13245
13246 return qdf_status_to_os_return(status);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013247}
13248
Abhishek Singhb20db962017-03-03 21:28:46 +053013249#ifdef FEATURE_WLAN_SCAN_PNO
13250static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
13251 struct hdd_config *cfg)
13252{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070013253 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
13254
Abhishek Singhb20db962017-03-03 21:28:46 +053013255 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
13256 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
13257 pno_cfg->stationary_thresh = cfg->stationary_thresh;
13258 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
13259 pno_cfg->channel_prediction_full_scan =
13260 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070013261 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
13262 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
13263 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
13264 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053013265}
13266#else
13267static inline void
13268hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070013269 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053013270{
Abhishek Singhb20db962017-03-03 21:28:46 +053013271}
13272#endif
13273
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013274void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
13275 struct hdd_config *cfg)
13276{
13277 uint8_t i = 0;
13278
13279 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
13280 if (!ie_whitelist->white_list)
13281 return;
13282
13283 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
13284 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
13285 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
13286 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
13287 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
13288 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
13289 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
13290 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
13291
13292 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
13293 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
13294 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
13295}
13296
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013297uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
13298{
13299 uint8_t i, score;
13300
13301 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
13302 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
13303 if (score > MAX_INDEX_SCORE)
13304 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
13305 MAX_INDEX_SCORE, i);
13306 }
13307
13308 return per_index_score;
13309}
13310
13311/**
13312 * hdd_update_score_config - API to update candidate scoring related params
13313 * configuration parameters
13314 * @score_config: score config to update
13315 * @cfg: config params
13316 *
13317 * Return: 0 if success else err
13318 */
13319static void hdd_update_score_config(
13320 struct scoring_config *score_config, struct hdd_config *cfg)
13321{
13322 int total_weight;
13323
13324 score_config->weight_cfg.rssi_weightage = cfg->rssi_weightage;
13325 score_config->weight_cfg.ht_caps_weightage = cfg->ht_caps_weightage;
13326 score_config->weight_cfg.vht_caps_weightage =
13327 cfg->vht_caps_weightage;
13328 score_config->weight_cfg.he_caps_weightage =
13329 cfg->he_caps_weightage;
13330 score_config->weight_cfg.chan_width_weightage =
13331 cfg->chan_width_weightage;
13332 score_config->weight_cfg.chan_band_weightage =
13333 cfg->chan_band_weightage;
13334 score_config->weight_cfg.nss_weightage = cfg->nss_weightage;
13335 score_config->weight_cfg.beamforming_cap_weightage =
13336 cfg->beamforming_cap_weightage;
13337 score_config->weight_cfg.pcl_weightage = cfg->pcl_weightage;
13338 score_config->weight_cfg.channel_congestion_weightage =
13339 cfg->channel_congestion_weightage;
13340 score_config->weight_cfg.oce_wan_weightage = cfg->oce_wan_weightage;
13341
13342 total_weight = score_config->weight_cfg.rssi_weightage +
13343 score_config->weight_cfg.ht_caps_weightage +
13344 score_config->weight_cfg.vht_caps_weightage +
13345 score_config->weight_cfg.he_caps_weightage +
13346 score_config->weight_cfg.chan_width_weightage +
13347 score_config->weight_cfg.chan_band_weightage +
13348 score_config->weight_cfg.nss_weightage +
13349 score_config->weight_cfg.beamforming_cap_weightage +
13350 score_config->weight_cfg.pcl_weightage +
13351 score_config->weight_cfg.channel_congestion_weightage +
13352 score_config->weight_cfg.oce_wan_weightage;
13353
13354 if (total_weight > BEST_CANDIDATE_MAX_WEIGHT) {
13355 hdd_err("total weight is greater than %d fallback to default values",
13356 BEST_CANDIDATE_MAX_WEIGHT);
13357
13358 score_config->weight_cfg.rssi_weightage = RSSI_WEIGHTAGE;
13359 score_config->weight_cfg.ht_caps_weightage =
13360 HT_CAPABILITY_WEIGHTAGE;
13361 score_config->weight_cfg.vht_caps_weightage = VHT_CAP_WEIGHTAGE;
13362 score_config->weight_cfg.he_caps_weightage = HE_CAP_WEIGHTAGE;
13363 score_config->weight_cfg.chan_width_weightage =
13364 CHAN_WIDTH_WEIGHTAGE;
13365 score_config->weight_cfg.chan_band_weightage =
13366 CHAN_BAND_WEIGHTAGE;
13367 score_config->weight_cfg.nss_weightage = NSS_WEIGHTAGE;
13368 score_config->weight_cfg.beamforming_cap_weightage =
13369 BEAMFORMING_CAP_WEIGHTAGE;
13370 score_config->weight_cfg.pcl_weightage = PCL_WEIGHT;
13371 score_config->weight_cfg.channel_congestion_weightage =
13372 CHANNEL_CONGESTION_WEIGHTAGE;
13373 score_config->weight_cfg.oce_wan_weightage = OCE_WAN_WEIGHTAGE;
13374 }
13375
13376 score_config->bandwidth_weight_per_index =
13377 hdd_limit_max_per_index_score(
13378 cfg->bandwidth_weight_per_index);
13379 score_config->nss_weight_per_index =
13380 hdd_limit_max_per_index_score(cfg->nss_weight_per_index);
13381 score_config->band_weight_per_index =
13382 hdd_limit_max_per_index_score(cfg->band_weight_per_index);
13383
13384 score_config->rssi_score.best_rssi_threshold =
13385 cfg->best_rssi_threshold;
13386 score_config->rssi_score.good_rssi_threshold =
13387 cfg->good_rssi_threshold;
13388 score_config->rssi_score.bad_rssi_threshold =
13389 cfg->bad_rssi_threshold;
13390 score_config->rssi_score.good_rssi_pcnt = cfg->good_rssi_pcnt;
13391 score_config->rssi_score.bad_rssi_pcnt = cfg->bad_rssi_pcnt;
13392 score_config->rssi_score.good_rssi_bucket_size =
13393 cfg->good_rssi_bucket_size;
13394 score_config->rssi_score.bad_rssi_bucket_size =
13395 cfg->bad_rssi_bucket_size;
13396 score_config->rssi_score.rssi_pref_5g_rssi_thresh =
13397 cfg->rssi_pref_5g_rssi_thresh;
13398
13399 score_config->esp_qbss_scoring.num_slot = cfg->num_esp_qbss_slots;
13400 score_config->esp_qbss_scoring.score_pcnt3_to_0 =
13401 hdd_limit_max_per_index_score(
13402 cfg->esp_qbss_score_slots3_to_0);
13403 score_config->esp_qbss_scoring.score_pcnt7_to_4 =
13404 hdd_limit_max_per_index_score(
13405 cfg->esp_qbss_score_slots7_to_4);
13406 score_config->esp_qbss_scoring.score_pcnt11_to_8 =
13407 hdd_limit_max_per_index_score(
13408 cfg->esp_qbss_score_slots11_to_8);
13409 score_config->esp_qbss_scoring.score_pcnt15_to_12 =
13410 hdd_limit_max_per_index_score(
13411 cfg->esp_qbss_score_slots15_to_12);
13412
13413 score_config->oce_wan_scoring.num_slot = cfg->num_oce_wan_slots;
13414 score_config->oce_wan_scoring.score_pcnt3_to_0 =
13415 hdd_limit_max_per_index_score(
13416 cfg->oce_wan_score_slots3_to_0);
13417 score_config->oce_wan_scoring.score_pcnt7_to_4 =
13418 hdd_limit_max_per_index_score(
13419 cfg->oce_wan_score_slots7_to_4);
13420 score_config->oce_wan_scoring.score_pcnt11_to_8 =
13421 hdd_limit_max_per_index_score(
13422 cfg->oce_wan_score_slots11_to_8);
13423 score_config->oce_wan_scoring.score_pcnt15_to_12 =
13424 hdd_limit_max_per_index_score(
13425 cfg->oce_wan_score_slots15_to_12);
13426
13427
13428 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
13429 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
13430 score_config->nss = cfg->enable2x2 ? 2 : 1;
13431
13432 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
13433 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
13434 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
13435 score_config->he_cap = 1;
13436
13437 if (score_config->he_cap ||
13438 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
13439 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
13440 score_config->vht_cap = 1;
13441
13442 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
13443 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
13444 score_config->ht_cap = 1;
13445
13446 if (score_config->vht_cap && cfg->enableVhtFor24GHzBand)
13447 score_config->vht_24G_cap = 1;
13448
13449 if (cfg->enableTxBF)
13450 score_config->beamformee_cap = 1;
13451
13452}
13453
Abhishek Singh257a9482017-03-06 16:52:39 +053013454/**
bings81fe50a2017-11-27 14:33:26 +080013455 * hdd_update_dfs_config() - API to update dfs configuration parameters.
13456 * @hdd_ctx: HDD context
13457 *
13458 * Return: 0 if success else err
13459 */
13460static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
13461{
13462 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13463 struct hdd_config *cfg = hdd_ctx->config;
13464 struct dfs_user_config dfs_cfg;
13465 QDF_STATUS status;
13466
13467 dfs_cfg.dfs_is_phyerr_filter_offload = !!cfg->fDfsPhyerrFilterOffload;
13468 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
13469 if (QDF_IS_STATUS_ERROR(status)) {
13470 hdd_err("failed dfs psoc configuration");
13471 return -EINVAL;
13472 }
13473
13474 return 0;
13475}
13476
13477/**
Abhishek Singh257a9482017-03-06 16:52:39 +053013478 * hdd_update_scan_config - API to update scan configuration parameters
13479 * @hdd_ctx: HDD context
13480 *
13481 * Return: 0 if success else err
13482 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013483static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053013484{
13485 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13486 struct scan_user_cfg scan_cfg;
13487 struct hdd_config *cfg = hdd_ctx->config;
13488 QDF_STATUS status;
13489
13490 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
13491 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
13492 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
13493 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
13494 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
13495 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
13496 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053013497 /* convert to ms */
13498 scan_cfg.scan_cache_aging_time =
13499 cfg->scanAgingTimeout * 1000;
13500 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
13501 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
13502 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
13503 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053013504 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053013505 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080013506 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
13507 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053013508 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070013509 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singhc87bb042018-01-30 17:10:42 +053013510 scan_cfg.sta_miracast_mcc_rest_time =
13511 cfg->sta_miracast_mcc_rest_time_val;
Abhishek Singh257a9482017-03-06 16:52:39 +053013512
Abhishek Singhb20db962017-03-03 21:28:46 +053013513 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013514 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013515 hdd_update_score_config(&scan_cfg.score_config, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053013516
Abhishek Singh257a9482017-03-06 16:52:39 +053013517 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
13518 if (status != QDF_STATUS_SUCCESS) {
13519 hdd_err("failed pmo psoc configuration");
13520 return -EINVAL;
13521 }
13522
13523 return 0;
13524}
Abhishek Singh257a9482017-03-06 16:52:39 +053013525
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013526int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013527{
13528 int ret;
13529
13530 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053013531 if (ret)
13532 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013533
Abhishek Singh257a9482017-03-06 16:52:39 +053013534 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080013535 if (ret)
13536 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013537
Frank Liud4b2fa02017-03-29 11:46:48 +080013538 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013539 if (ret)
13540 return ret;
13541
13542 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080013543 if (ret)
13544 return ret;
13545
13546 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013547
13548 return ret;
13549}
13550
Agrawal Ashish65634612016-08-18 13:24:32 +053013551/**
13552 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
13553 * @mode : cfg80211 DFS mode
13554 *
13555 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
13556 */
13557enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
13558{
13559 switch (mode) {
13560 case DFS_MODE_ENABLE:
13561 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013562 case DFS_MODE_DISABLE:
13563 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013564 case DFS_MODE_DEPRIORITIZE:
13565 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013566 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013567 hdd_debug("ACS dfs mode is NONE");
13568 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013569 }
13570}
13571
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013572/**
13573 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
13574 * @hddctx: pointer to hdd context
13575 * @set_value: enable/disable
13576 *
13577 * When Host sends vendor command enable, FW will send *ONE* CA ind to
13578 * Host(even though it is duplicate). When Host send vendor command
13579 * disable,FW doesn't perform any action. Whenever any change in
13580 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
13581 *
13582 * return - 0 on success, appropriate error values on failure.
13583 */
Jeff Johnson16528362018-06-14 12:34:16 -070013584int hdd_enable_disable_ca_event(struct hdd_context *hdd_ctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013585{
13586 QDF_STATUS status;
13587
Jeff Johnson16528362018-06-14 12:34:16 -070013588 if (0 != wlan_hdd_validate_context(hdd_ctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013589 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013590
Jeff Johnson16528362018-06-14 12:34:16 -070013591 if (!hdd_ctx->config->goptimize_chan_avoid_event) {
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013592 hdd_warn("goptimize_chan_avoid_event ini param disabled");
13593 return -EINVAL;
13594 }
13595
Jeff Johnson16528362018-06-14 12:34:16 -070013596 status = sme_enable_disable_chanavoidind_event(hdd_ctx->mac_handle,
13597 set_value);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013598 if (!QDF_IS_STATUS_SUCCESS(status)) {
13599 hdd_err("Failed to send chan avoid command to SME");
13600 return -EINVAL;
13601 }
13602 return 0;
13603}
Agrawal Ashish65634612016-08-18 13:24:32 +053013604
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013605/**
13606 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
13607 * @value: value to set
13608 *
13609 * This function will set the passed value to roaming in progress flag.
13610 *
13611 * Return: None
13612 */
13613void hdd_set_roaming_in_progress(bool value)
13614{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013615 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013616
13617 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13618 if (!hdd_ctx) {
13619 hdd_err("HDD context is NULL");
13620 return;
13621 }
13622
13623 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013624 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013625}
13626
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053013627bool hdd_is_roaming_in_progress(struct hdd_context *hdd_ctx)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013628{
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013629 if (!hdd_ctx) {
13630 hdd_err("HDD context is NULL");
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053013631 return false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013632 }
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013633
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053013634 hdd_debug("roaming_in_progress = %d", hdd_ctx->roaming_in_progress);
13635
13636 return hdd_ctx->roaming_in_progress;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013637}
13638
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013639/**
13640 * hdd_is_connection_in_progress() - check if connection is in
13641 * progress
13642 * @session_id: session id
13643 * @reason: scan reject reason
13644 *
13645 * Go through each adapter and check if Connection is in progress
13646 *
13647 * Return: true if connection is in progress else false
13648 */
13649bool hdd_is_connection_in_progress(uint8_t *session_id,
13650 enum scan_reject_states *reason)
13651{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070013652 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070013653 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013654 uint8_t sta_id = 0;
13655 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013656 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -070013657 mac_handle_t mac_handle;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013658
13659 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13660 if (!hdd_ctx) {
13661 hdd_err("HDD context is NULL");
13662 return false;
13663 }
13664
Jeff Johnson16528362018-06-14 12:34:16 -070013665 mac_handle = hdd_ctx->mac_handle;
13666
Dustin Brown920397d2017-12-13 16:27:50 -080013667 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya929afa42018-06-01 15:04:44 -070013668 hdd_debug("Adapter with device mode %s(%d) exists",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013669 hdd_device_mode_to_string(adapter->device_mode),
13670 adapter->device_mode);
13671 if (((QDF_STA_MODE == adapter->device_mode)
13672 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
13673 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
13674 && (eConnectionState_Connecting ==
13675 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
13676 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013677 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013678 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013679 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013680 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013681 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013682 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013683 }
13684 return true;
13685 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013686 /*
13687 * sme_neighbor_middle_of_roaming is for LFR2
13688 * hdd_is_roaming_in_progress is for LFR3
13689 */
13690 if (((QDF_STA_MODE == adapter->device_mode) &&
13691 sme_neighbor_middle_of_roaming(
Jeff Johnson16528362018-06-14 12:34:16 -070013692 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013693 adapter->session_id)) ||
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053013694 hdd_is_roaming_in_progress(hdd_ctx)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013695 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013696 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013697 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013698 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013699 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013700 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013701 }
13702 return true;
13703 }
13704 if ((QDF_STA_MODE == adapter->device_mode) ||
13705 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
13706 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
13707 hdd_sta_ctx =
13708 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
13709 if ((eConnectionState_Associated ==
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053013710 hdd_sta_ctx->conn_info.connState)
13711 && sme_is_sta_key_exchange_in_progress(
Jeff Johnson16528362018-06-14 12:34:16 -070013712 mac_handle, adapter->session_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013713 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070013714 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013715 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013716 " is in middle of WPS/EAPOL exchange.",
13717 MAC_ADDR_ARRAY(sta_mac));
13718 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013719 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013720 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013721 }
13722 return true;
13723 }
13724 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
13725 (QDF_P2P_GO_MODE == adapter->device_mode)) {
13726 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
13727 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013728 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013729 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013730 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013731 continue;
13732
13733 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013734 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070013735 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013736 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013737 " of SAP/GO is in middle of WPS/EAPOL exchange",
13738 MAC_ADDR_ARRAY(sta_mac));
13739 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013740 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013741 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013742 }
13743 return true;
13744 }
13745 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013746 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013747 return true;
13748 }
13749 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013750 }
Dustin Brown920397d2017-12-13 16:27:50 -080013751
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013752 return false;
13753}
13754
13755/**
13756 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070013757 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013758 *
13759 * Return: None
13760 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013761void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013762{
Jeff Johnson87251032017-08-29 13:31:11 -070013763 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070013764 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013765 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013766 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Jeff Johnsone4c11db2018-05-05 23:22:32 -070013767 tsap_config_t *sap_config;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013768 void *sap_ctx;
13769
13770 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070013771 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070013772 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013773
13774 mutex_lock(&hdd_ctx->sap_lock);
13775 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
13776 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013777 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
13778 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
13779 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
13780 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013781 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013782 qdf_stop_bss_event,
13783 SME_CMD_TIMEOUT_VALUE);
13784
13785 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013786 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013787 goto end;
13788 }
13789 }
13790 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013791 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013792 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070013793 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013794 false);
Jeff Johnson6867ec32017-09-29 20:30:20 -070013795 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013796
13797 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013798 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013799 wlansap_reset_sap_config_add_ie(sap_config,
13800 eUPDATE_IE_ALL);
13801 goto end;
13802 }
13803
13804 qdf_event_reset(&hostapd_state->qdf_event);
13805 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
13806 sap_config,
13807 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013808 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013809 wlansap_reset_sap_config_add_ie(sap_config,
13810 eUPDATE_IE_ALL);
13811 goto end;
13812 }
13813
Jeff Johnson6867ec32017-09-29 20:30:20 -070013814 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013815 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013816 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013817 SME_CMD_TIMEOUT_VALUE);
13818 wlansap_reset_sap_config_add_ie(sap_config,
13819 eUPDATE_IE_ALL);
13820 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013821 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013822 goto end;
13823 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070013824 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013825 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013826 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013827 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
13828 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013829 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070013830 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013831 ap_adapter->device_mode,
13832 true);
13833 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013834 }
13835end:
13836 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013837}
13838
13839/**
13840 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
13841 * with non dfs acs
13842 *
13843 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
13844 *
13845 * Return: None
13846 */
13847void hdd_check_and_restart_sap_with_non_dfs_acs(void)
13848{
Jeff Johnson9d295242017-08-29 14:39:48 -070013849 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013850 struct hdd_context *hdd_ctx;
Jeff Johnson2b6982c2018-05-29 14:56:11 -070013851 struct cds_context *cds_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013852
13853 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13854 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013855 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013856 return;
13857 }
13858
13859 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
13860 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013861 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013862 return;
13863 }
13864
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013865 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
13866 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013867 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013868 return;
13869 }
13870
13871 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070013872 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
13873 &ap_adapter->event_flags) &&
13874 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070013875 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013876
Jeff Johnson6867ec32017-09-29 20:30:20 -070013877 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Jeff Johnsonb9424862017-10-30 08:49:35 -070013878 ap_adapter->session.ap.sap_config.channel =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013879 AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -070013880 ap_adapter->session.ap.sap_config.
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013881 acs_cfg.acs_mode = true;
13882
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013883 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013884 }
13885}
13886
13887/**
13888 * hdd_set_connection_in_progress() - to set the connection in
13889 * progress flag
13890 * @value: value to set
13891 *
13892 * This function will set the passed value to connection in progress flag.
13893 * If value is previously being set to true then no need to set it again.
13894 *
13895 * Return: true if value is being set correctly and false otherwise.
13896 */
13897bool hdd_set_connection_in_progress(bool value)
13898{
13899 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013900 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013901
13902 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13903 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013904 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013905 return false;
13906 }
13907
13908 qdf_spin_lock(&hdd_ctx->connection_status_lock);
13909 /*
13910 * if the value is set to true previously and if someone is
13911 * trying to make it true again then it could be some race
13912 * condition being triggered. Avoid this situation by returning
13913 * false
13914 */
13915 if (hdd_ctx->connection_in_progress && value)
13916 status = false;
13917 else
13918 hdd_ctx->connection_in_progress = value;
13919 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
13920 return status;
13921}
13922
Jeff Johnson9d295242017-08-29 14:39:48 -070013923int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013924{
13925 if (!adapter) {
13926 hdd_err("Invalid adapter");
13927 return -EINVAL;
13928 }
13929 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013930 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013931 WMA_VDEV_MCC_SET_TIME_QUOTA,
13932 set_value, VDEV_CMD);
13933 return 0;
13934
13935}
13936
Jeff Johnson9d295242017-08-29 14:39:48 -070013937int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013938{
13939 if (!adapter) {
13940 hdd_err("Invalid adapter");
13941 return -EINVAL;
13942 }
13943
13944 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013945 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013946 WMA_VDEV_MCC_SET_TIME_LATENCY,
13947 set_value, VDEV_CMD);
13948 return 0;
13949}
13950
Jeff Johnson9d295242017-08-29 14:39:48 -070013951struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013952 *psoc, uint8_t vdev_id)
13953{
Jeff Johnson9d295242017-08-29 14:39:48 -070013954 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013955 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013956
13957 /*
13958 * Currently PSOC is not being used. But this logic will
13959 * change once we have the converged implementation of
13960 * HDD context per PSOC in place. This would break if
13961 * multiple vdev objects reuse the vdev id.
13962 */
13963 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
13964 if (!adapter)
13965 hdd_err("Get adapter by vdev id failed");
13966
13967 return adapter;
13968}
13969
Jeff Johnson9d295242017-08-29 14:39:48 -070013970int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013971 int8_t *rssi, int8_t *snr)
13972{
13973 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -070013974 mac_handle_t mac_handle;
Jeff Johnson025618c2018-03-18 14:41:00 -070013975 struct csr_roam_profile *roam_profile;
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013976
Jeff Johnson025618c2018-03-18 14:41:00 -070013977 roam_profile = hdd_roam_profile(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -070013978 mac_handle = hdd_adapter_get_mac_handle(adapter);
13979 status = sme_get_rssi_snr_by_bssid(mac_handle,
Jeff Johnson025618c2018-03-18 14:41:00 -070013980 roam_profile, bssid, rssi, snr);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013981 if (QDF_STATUS_SUCCESS != status) {
13982 hdd_warn("sme_get_rssi_snr_by_bssid failed");
13983 return -EINVAL;
13984 }
13985
13986 return 0;
13987}
13988
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013989/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013990 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
13991 * @adapter - HDD adapter
13992 * @tos - type of service
13993 * @status - status of the traffic
13994 *
13995 * Return: 0 on success and non zero value on failure
13996 */
13997
13998int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
13999 bool is_tos_active)
14000{
14001 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014002 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014003 uint32_t max_off_chan_time = 0;
14004 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014005 int ret;
14006
14007 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
14008 ret = wlan_hdd_validate_context(hdd_ctx);
14009
14010 if (ret < 0) {
14011 hdd_err("failed to set limit off chan params");
14012 return ret;
14013 }
14014
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014015 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
14016
14017 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053014018 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014019 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053014020 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014021
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053014022 if (adapter->active_ac) {
14023 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014024 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014025 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
14026 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
14027 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053014028 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014029 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014030 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
14031 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
14032 PM_LATENCY);
14033 } else {
14034 /*ignore this command if only BE/BK is active */
14035 is_tos_active = false;
14036 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
14037 hdd_ctx->config->conc_system_pref);
14038 }
14039 } else {
14040 /* No active tos */
14041 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
14042 hdd_ctx->config->conc_system_pref);
14043 }
14044
Jeff Johnson16528362018-06-14 12:34:16 -070014045 status = sme_send_limit_off_channel_params(hdd_ctx->mac_handle,
14046 adapter->session_id,
14047 is_tos_active,
14048 max_off_chan_time,
14049 hdd_ctx->config->nRestTimeConc,
14050 true);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014051 if (!QDF_IS_STATUS_SUCCESS(status)) {
14052 hdd_err("failed to set limit off chan params");
14053 ret = -EINVAL;
14054 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014055
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014056 return ret;
14057}
14058
14059/**
14060 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
14061 * @adapter - HDD adapter
14062 *
14063 * Return: 0 on success and non zero value on failure
14064 */
14065int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
14066{
14067 struct hdd_context *hdd_ctx;
14068 int ret;
14069 QDF_STATUS status;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014070
14071 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
14072 ret = wlan_hdd_validate_context(hdd_ctx);
14073 if (ret < 0)
14074 return ret;
14075
14076 /* set the system preferece to default */
14077 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
14078 hdd_ctx->config->conc_system_pref);
14079
14080 /* clear the bitmap */
14081 adapter->active_ac = 0;
14082
14083 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson16528362018-06-14 12:34:16 -070014084 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014085
Jeff Johnson16528362018-06-14 12:34:16 -070014086 status = sme_send_limit_off_channel_params(hdd_ctx->mac_handle,
14087 adapter->session_id,
14088 false, 0, 0, false);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014089 if (!QDF_IS_STATUS_SUCCESS(status)) {
14090 hdd_err("failed to reset limit off chan params");
14091 ret = -EINVAL;
14092 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014093
14094 return ret;
14095}
14096
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014097/**
14098 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
14099 * @drv_op: Enum indicating driver op
14100 *
14101 * Return: none
14102 */
14103void hdd_start_driver_ops_timer(int drv_op)
14104{
14105 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
14106 switch (drv_op) {
14107 case eHDD_DRV_OP_PROBE:
14108 memcpy(drv_ops_string, "probe", sizeof("probe"));
14109 break;
14110 case eHDD_DRV_OP_REMOVE:
14111 memcpy(drv_ops_string, "remove", sizeof("remove"));
14112 break;
14113 case eHDD_DRV_OP_SHUTDOWN:
14114 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
14115 break;
14116 case eHDD_DRV_OP_REINIT:
14117 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
14118 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053014119 case eHDD_DRV_OP_IFF_UP:
14120 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
14121 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014122 }
14123
Dustin Brown45ed4bb2017-12-18 12:00:13 -080014124 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014125 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
Dustin Browncfc54fe2018-06-18 16:17:41 -070014126 HDD_OPS_INACTIVITY_TIMEOUT * qdf_timer_get_multiplier());
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014127}
14128
14129/**
14130 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
14131 *
14132 * Return: none
14133 */
14134void hdd_stop_driver_ops_timer(void)
14135{
14136 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
14137}
14138
14139/**
14140 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
14141 * inactivity timer
14142 *
14143 * Return: None
14144 */
14145void hdd_drv_ops_inactivity_handler(void)
14146{
Rajeev Kumar4471f1b2018-06-08 14:18:28 -070014147 hdd_err("WLAN_BUG_RCA %s: %d Sec timer expired while in .%s",
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014148 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
14149
Dustin Brown45ed4bb2017-12-18 12:00:13 -080014150 if (hdd_drv_ops_task) {
14151 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
14152 qdf_print_thread_trace(hdd_drv_ops_task);
14153 } else {
14154 hdd_err("hdd_drv_ops_task is null");
14155 }
14156
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014157 /* Driver shutdown is stuck, no recovery possible at this point */
14158 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
14159 sizeof("shutdown")))
14160 QDF_BUG(0);
14161
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080014162 if (cds_is_fw_down()) {
14163 hdd_err("FW is down");
14164 return;
14165 }
14166
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014167 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053014168 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014169 else
14170 QDF_BUG(0);
14171}
14172
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053014173void hdd_pld_ipa_uc_shutdown_pipes(void)
14174{
14175 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14176
14177 if (!hdd_ctx)
14178 return;
14179
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +053014180 ucfg_ipa_uc_force_pipe_shutdown(hdd_ctx->hdd_pdev);
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053014181}
14182
Yun Parkff6a16a2017-09-26 16:38:18 -070014183/**
14184 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
14185 * @struct hdd_context *hdd_ctx
14186 * @struct hdd_adapter *padapter
14187 * @bool enble
14188 *
14189 * Return: none
14190 */
14191void hdd_set_rx_mode_rps(bool enable)
14192{
14193 struct cds_config_info *cds_cfg = cds_get_ini_config();
Ryan Hsu0e878fa2018-05-04 15:22:09 -070014194 struct hdd_context *hdd_ctx;
14195 struct hdd_adapter *adapter;
Yun Parkff6a16a2017-09-26 16:38:18 -070014196
Ryan Hsu0e878fa2018-05-04 15:22:09 -070014197 if (!cds_cfg)
14198 return;
14199
14200 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14201 if (!hdd_ctx)
14202 return;
14203
14204 adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
14205 if (!adapter)
14206 return;
14207
14208 if (!hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
Yun Parkff6a16a2017-09-26 16:38:18 -070014209 if (enable && !cds_cfg->rps_enabled)
14210 hdd_send_rps_ind(adapter);
14211 else if (!enable && cds_cfg->rps_enabled)
14212 hdd_send_rps_disable_ind(adapter);
14213 }
14214}
14215
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +053014216bool hdd_is_cli_iface_up(struct hdd_context *hdd_ctx)
14217{
14218 struct hdd_adapter *adapter = NULL;
14219
14220 hdd_for_each_adapter(hdd_ctx, adapter) {
14221 if ((adapter->device_mode == QDF_STA_MODE ||
14222 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
14223 qdf_atomic_test_bit(DEVICE_IFACE_OPENED,
14224 &adapter->event_flags)){
14225 return true;
14226 }
14227 }
14228
14229 return false;
14230}
14231
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014232/* Register the module init/exit functions */
14233module_init(hdd_module_init);
14234module_exit(hdd_module_exit);
14235
14236MODULE_LICENSE("Dual BSD/GPL");
14237MODULE_AUTHOR("Qualcomm Atheros, Inc.");
14238MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
14239
Srinivas Girigowda841da292018-02-21 16:33:00 -080014240static const struct kernel_param_ops con_mode_ops = {
14241 .set = con_mode_handler,
14242 .get = param_get_int,
14243};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014244
Srinivas Girigowda841da292018-02-21 16:33:00 -080014245static const struct kernel_param_ops con_mode_ftm_ops = {
14246 .set = con_mode_handler_ftm,
14247 .get = param_get_int,
14248};
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053014249
Nirav Shah73713f72018-05-17 14:50:41 +053014250#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080014251static const struct kernel_param_ops con_mode_monitor_ops = {
14252 .set = con_mode_handler_monitor,
14253 .get = param_get_int,
14254};
Nirav Shah73713f72018-05-17 14:50:41 +053014255#endif
Ravi Joshia307f632017-07-17 23:41:41 -070014256
Srinivas Girigowda841da292018-02-21 16:33:00 -080014257static const struct kernel_param_ops fwpath_ops = {
14258 .set = fwpath_changed_handler,
14259 .get = param_get_string,
14260};
14261
14262module_param_cb(con_mode, &con_mode_ops, &con_mode,
14263 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
14264
14265module_param_cb(con_mode_ftm, &con_mode_ftm_ops, &con_mode_ftm,
14266 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
14267
Nirav Shah73713f72018-05-17 14:50:41 +053014268#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080014269module_param_cb(con_mode_monitor, &con_mode_monitor_ops, &con_mode_monitor,
14270 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Nirav Shah73713f72018-05-17 14:50:41 +053014271#endif
Srinivas Girigowda841da292018-02-21 16:33:00 -080014272
14273module_param_cb(fwpath, &fwpath_ops, &fwpath,
14274 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014275
14276module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
14277
14278module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
14279
14280module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);