blob: 93115f0743ee84dbb678e978cc2bdad2cef00e40 [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>
40#include <wlan_hdd_wowl.h>
41#include <wlan_hdd_misc.h>
42#include <wlan_hdd_wext.h>
43#include "wlan_hdd_trace.h"
44#include "wlan_hdd_ioctl.h"
45#include "wlan_hdd_ftm.h"
46#include "wlan_hdd_power.h"
47#include "wlan_hdd_stats.h"
Prashanth Bhatta527fd752016-04-28 12:35:23 -070048#include "wlan_hdd_scan.h"
Naveen Rawate02f8f52018-04-05 11:58:04 -070049#include <wlan_osif_request_manager.h>
Dustin Brown26b3d042017-12-21 11:13:27 -080050#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4bc0a622017-12-06 15:56:50 -080051#include "qdf_debug_domain.h"
Dustin Brown26b3d042017-12-21 11:13:27 -080052#endif
Dustin Brownd4241942018-02-26 12:51:37 -080053#include "qdf_str.h"
54#include "qdf_trace.h"
55#include "qdf_types.h"
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070056#include <cdp_txrx_peer_ops.h>
Dhanashri Atrea8f82f22017-01-23 12:58:24 -080057#include <cdp_txrx_misc.h>
Mohit Khannaca4173b2017-09-12 21:52:19 -070058#include <cdp_txrx_stats.h>
bings0e03a982018-05-09 08:40:59 +080059#include "cdp_txrx_flow_ctrl_legacy.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080060
61#include <net/addrconf.h>
62#include <linux/wireless.h>
63#include <net/cfg80211.h>
64#include <linux/inetdevice.h>
65#include <net/addrconf.h>
66#include "wlan_hdd_cfg80211.h"
67#include "wlan_hdd_ext_scan.h"
68#include "wlan_hdd_p2p.h"
69#include <linux/rtnetlink.h>
70#include "sap_api.h"
71#include <linux/semaphore.h>
72#include <linux/ctype.h>
73#include <linux/compat.h>
Arunk Khandavalli830c9692018-03-22 12:17:40 +053074#include <linux/reboot.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080075#ifdef MSM_PLATFORM
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080076#include <soc/qcom/subsystem_restart.h>
77#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080078#include <wlan_hdd_hostapd.h>
79#include <wlan_hdd_softap_tx_rx.h>
Jeff Johnson8bb61112018-03-31 13:33:54 -070080#include <wlan_hdd_green_ap.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080081#include "cfg_api.h"
82#include "qwlan_version.h"
83#include "wma_types.h"
84#include "wlan_hdd_tdls.h"
85#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053086#include "cds_regdomain.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080087#endif /* FEATURE_WLAN_CH_AVOID */
Dustin Brownce46d1d2017-08-15 13:34:24 -070088#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070089#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -080090#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080091#include "wlan_hdd_nan.h"
92#include "wlan_hdd_debugfs.h"
93#include "wlan_hdd_driver_ops.h"
94#include "epping_main.h"
Poddar, Siddarth34872782017-08-10 14:08:51 +053095#include "wlan_hdd_data_stall_detection.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080096
97#include <wlan_hdd_ipa.h>
98#include "hif.h"
99#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -0800100#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700101#include "wlan_hdd_tsf.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530102#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700103#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700104#include "wlan_hdd_lpass.h"
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530105#include "nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700106#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530107#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800108#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800109#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530110#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800111#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800112#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530113#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530114#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800115#include "os_if_wifi_pos.h"
116#include "wifi_pos_api.h"
117#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800118#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700119#include "os_if_nan.h"
120#include "nan_public_structs.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700121#include "wlan_reg_ucfg_api.h"
bings81fe50a2017-11-27 14:33:26 +0800122#include "wlan_dfs_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700123#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530124#include "sme_power_save_api.h"
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +0530125#include "enet.h"
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700126#include <cdp_txrx_cmn_struct.h>
Amar Singhal0928b192017-12-01 10:50:54 -0800127#include "wlan_hdd_sysfs.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530128#include "wlan_disa_ucfg_api.h"
Wu Gao52084c12018-05-17 20:47:11 +0800129#include "wlan_disa_obj_mgmt_api.h"
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +0530130#include "wlan_ipa_ucfg_api.h"
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530131#include <target_if.h>
Alok Kumarb64650c2018-03-23 17:05:11 +0530132#include "wlan_hdd_nud_tracking.h"
Nachiket Kukaded0dd62e2018-05-21 18:39:22 +0530133#include "wlan_hdd_apf.h"
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -0700134#include "wlan_hdd_twt.h"
Rachit Kankane0dc3e852018-05-07 17:33:42 +0530135#include "qc_sap_ioctl.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530136
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530137#ifdef CNSS_GENL
138#include <net/cnss_nl.h>
139#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800140#include "wlan_reg_ucfg_api.h"
Zhang Qian47e22ce2018-01-04 15:38:38 +0800141#include "wlan_ocb_ucfg_api.h"
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -0800142#include <wlan_hdd_spectralscan.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800143#ifdef MODULE
144#define WLAN_MODULE_NAME module_name(THIS_MODULE)
145#else
146#define WLAN_MODULE_NAME "wlan"
147#endif
148
149#ifdef TIMER_MANAGER
150#define TIMER_MANAGER_STR " +TIMER_MANAGER"
151#else
152#define TIMER_MANAGER_STR ""
153#endif
154
155#ifdef MEMORY_DEBUG
156#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
157#else
158#define MEMORY_DEBUG_STR ""
159#endif
160
Dustin Brownc1034df2018-02-07 14:51:32 -0800161#ifdef PANIC_ON_BUG
162#define PANIC_ON_BUG_STR " +PANIC_ON_BUG"
163#else
164#define PANIC_ON_BUG_STR ""
165#endif
166
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530167bool g_is_system_reboot_triggered;
Sachin Ahujadddd2632017-03-07 19:07:24 +0530168int wlan_start_ret_val;
169static DECLARE_COMPLETION(wlan_start_comp);
170static unsigned int dev_num = 1;
171static struct cdev wlan_hdd_state_cdev;
172static struct class *class;
173static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530174#ifndef MODULE
175static struct gwlan_loader *wlan_loader;
176static ssize_t wlan_boot_cb(struct kobject *kobj,
177 struct kobj_attribute *attr,
178 const char *buf, size_t count);
179struct gwlan_loader {
180 bool loaded_state;
181 struct kobject *boot_wlan_obj;
182 struct attribute_group *attr_group;
183};
184
185static struct kobj_attribute wlan_boot_attribute =
186 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
187
188static struct attribute *attrs[] = {
189 &wlan_boot_attribute.attr,
190 NULL,
191};
192
193#define MODULE_INITIALIZED 1
194#endif
195
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530196#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
197#define MAX_OPS_NAME_STRING_SIZE 20
Rajeev Kumar6d0b2ea2017-12-26 17:55:33 -0800198#define RATE_LIMIT_ERROR_LOG (256)
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530199
200static qdf_timer_t hdd_drv_ops_inactivity_timer;
Dustin Brown45ed4bb2017-12-18 12:00:13 -0800201static struct task_struct *hdd_drv_ops_task;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530202static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
203
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800204/* the Android framework expects this param even though we don't use it */
205#define BUF_LEN 20
206static char fwpath_buffer[BUF_LEN];
207static struct kparam_string fwpath = {
208 .string = fwpath_buffer,
209 .maxlen = BUF_LEN,
210};
211
212static char *country_code;
213static int enable_11d = -1;
214static int enable_dfs_chan_scan = -1;
215
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800216/*
217 * spinlock for synchronizing asynchronous request/response
218 * (full description of use in wlan_hdd_main.h)
219 */
220DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530221DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800222
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800223#define WLAN_NLINK_CESIUM 30
224
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530225static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800226
227#define WOW_MAX_FILTER_LISTS 1
228#define WOW_MAX_FILTERS_PER_LIST 4
229#define WOW_MIN_PATTERN_SIZE 6
230#define WOW_MAX_PATTERN_SIZE 64
231
232#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
233static const struct wiphy_wowlan_support wowlan_support_reg_init = {
234 .flags = WIPHY_WOWLAN_ANY |
235 WIPHY_WOWLAN_MAGIC_PKT |
236 WIPHY_WOWLAN_DISCONNECT |
237 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
238 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
239 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
240 WIPHY_WOWLAN_4WAY_HANDSHAKE |
241 WIPHY_WOWLAN_RFKILL_RELEASE,
242 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
243 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
244 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
245};
246#endif
247
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700248static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
249 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
250 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
251 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
252 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
253 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
254 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
255 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
256 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
257 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
258 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
259 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
260 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
261 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
262 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
263 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
264 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
265 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
266 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
267 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
268 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
269 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
270 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
271 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
272 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
273 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
274 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
275 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
276 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
277 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
278 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
279 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
280 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
281 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
282 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700283 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700284 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700285 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530286 [QDF_MODULE_ID_GREEN_AP] = {QDF_TRACE_LEVEL_ALL},
Zhang Qian47e22ce2018-01-04 15:38:38 +0800287 [QDF_MODULE_ID_OCB] = {QDF_TRACE_LEVEL_ALL},
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530288 [QDF_MODULE_ID_IPA] = {QDF_TRACE_LEVEL_ALL},
Dustin Brown84f46ea2018-02-15 11:57:36 -0800289 [QDF_MODULE_ID_CONFIG] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700290};
291
Ganesh Kondabattini35739572017-06-21 16:26:39 +0530292int limit_off_chan_tbl[HDD_MAX_AC][HDD_MAX_OFF_CHAN_ENTRIES] = {
293 { HDD_AC_BK_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BK },
294 { HDD_AC_BE_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BE },
295 { HDD_AC_VI_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VI },
296 { HDD_AC_VO_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VO },
297};
298
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530299struct notifier_block hdd_netdev_notifier;
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530300struct notifier_block system_reboot_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800301
302struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800303#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700304static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800305#endif
306
Sachin Ahujadddd2632017-03-07 19:07:24 +0530307void hdd_start_complete(int ret)
308{
309 wlan_start_ret_val = ret;
310
311 complete(&wlan_start_comp);
312}
313
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800314/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530315 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700316 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530317 *
318 * Return: none
319 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700320static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530321{
Jeff Johnson9d295242017-08-29 14:39:48 -0700322 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530323
Dustin Brown920397d2017-12-13 16:27:50 -0800324 hdd_for_each_adapter(hdd_ctx, adapter)
325 hdd_send_rps_ind(adapter);
Nirav Shahbd36b062016-07-18 11:12:59 +0530326}
327
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530328#ifdef QCA_HL_NETDEV_FLOW_CONTROL
329void wlan_hdd_mod_fc_timer(struct hdd_adapter *adapter,
330 enum netif_action_type action)
331{
332 if (!adapter->tx_flow_timer_initialized)
333 return;
334
335 if (action == WLAN_WAKE_NON_PRIORITY_QUEUE) {
336 qdf_mc_timer_stop(&adapter->tx_flow_control_timer);
337 } else if (action == WLAN_STOP_NON_PRIORITY_QUEUE) {
338 QDF_STATUS status =
339 qdf_mc_timer_start(&adapter->tx_flow_control_timer,
340 WLAN_HDD_TX_FLOW_CONTROL_OS_Q_BLOCK_TIME);
341
342 if (!QDF_IS_STATUS_SUCCESS(status))
343 hdd_err("Failed to start tx_flow_control_timer");
344 else
345 adapter->
346 hdd_stats.tx_rx_stats.txflow_timer_cnt++;
347
348 adapter->hdd_stats.tx_rx_stats.txflow_pause_cnt++;
349 adapter->hdd_stats.tx_rx_stats.is_txflow_paused = true;
350 }
351}
352#endif /* QCA_HL_NETDEV_FLOW_CONTROL */
353
Nirav Shahbd36b062016-07-18 11:12:59 +0530354/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800355 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
356 * @vdev_id: vdev_id
357 * @action: action type
358 * @reason: reason type
359 *
360 * Return: none
361 */
362void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
363 enum netif_action_type action, enum netif_reason_type reason)
364{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700365 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700366 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800367
368 if (!hdd_ctx) {
369 hdd_err("hdd ctx is NULL");
370 return;
371 }
372 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Ajit Pal Singh106c1412018-04-18 18:08:49 +0530373 wlan_hdd_mod_fc_timer(adapter, action);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800374 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800375}
376
377/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700378 * Store WLAN driver version and timestamp info in global variables such that
379 * crash debugger can extract them from driver debug symbol and crashdump for
380 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800381 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800382#ifdef BUILD_TAG
383uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR "; " BUILD_TAG;
384#else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800385uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700386#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800387
388/**
389 * hdd_device_mode_to_string() - return string conversion of device mode
390 * @device_mode: device mode
391 *
392 * This utility function helps log string conversion of device mode.
393 *
394 * Return: string conversion of device mode, if match found;
395 * "Unknown" otherwise.
396 */
397const char *hdd_device_mode_to_string(uint8_t device_mode)
398{
399 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800400 CASE_RETURN_STRING(QDF_STA_MODE);
401 CASE_RETURN_STRING(QDF_SAP_MODE);
402 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
403 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
404 CASE_RETURN_STRING(QDF_FTM_MODE);
405 CASE_RETURN_STRING(QDF_IBSS_MODE);
406 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
407 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700408 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800409 default:
410 return "Unknown";
411 }
412}
413
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530414/**
Liangwei Dong17bf2662018-01-05 02:02:05 -0500415 * hdd_get_valid_chan() - return current chan list from regulatory.
416 * @hdd_ctx: HDD context
417 * @chan_list: buf hold returned chan list
418 * @chan_num: input buf size and output returned chan num
419 *
420 * This function helps get current available chan list from regulatory
421 * module. It excludes the "disabled" and "invalid" channels.
422 *
423 * Return: 0 for success.
424 */
425static int hdd_get_valid_chan(struct hdd_context *hdd_ctx,
426 uint8_t *chan_list,
427 uint32_t *chan_num)
428{
429 int i = 0, j = 0;
430 struct regulatory_channel *cur_chan_list;
431 struct wlan_objmgr_pdev *pdev;
432
433 if (!hdd_ctx || !hdd_ctx->hdd_pdev || !chan_list || !chan_num)
434 return -EINVAL;
435
436 pdev = hdd_ctx->hdd_pdev;
437 cur_chan_list = qdf_mem_malloc(NUM_CHANNELS *
438 sizeof(struct regulatory_channel));
439 if (!cur_chan_list)
440 return -ENOMEM;
441
442 if (wlan_reg_get_current_chan_list(pdev, cur_chan_list) !=
443 QDF_STATUS_SUCCESS) {
444 qdf_mem_free(cur_chan_list);
445 return -EINVAL;
446 }
447
448 for (i = 0; i < NUM_CHANNELS; i++) {
449 uint32_t ch = cur_chan_list[i].chan_num;
450 enum channel_state state = wlan_reg_get_channel_state(pdev,
451 ch);
452
453 if (state != CHANNEL_STATE_DISABLE &&
454 state != CHANNEL_STATE_INVALID &&
455 j < *chan_num) {
456 chan_list[j] = (uint8_t)ch;
457 j++;
458 }
459 }
460 *chan_num = j;
461 qdf_mem_free(cur_chan_list);
462 return 0;
463}
464
465/**
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530466 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
467 * @adapter: HDD adapter
468 * @chan_number: Channel number
469 * @chan_bw: Bandwidth
470 *
471 * Checks if the given bandwidth is valid for the given channel number.
472 *
473 * Return: 0 for success, non-zero for failure
474 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700475int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530476 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800477 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530478{
Liangwei Dong17bf2662018-01-05 02:02:05 -0500479 uint8_t chan[NUM_CHANNELS];
480 uint32_t len = NUM_CHANNELS, i;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530481 bool found = false;
Jeff Johnson16528362018-06-14 12:34:16 -0700482 mac_handle_t mac_handle;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500483 int ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530484
Jeff Johnson16528362018-06-14 12:34:16 -0700485 mac_handle = hdd_adapter_get_mac_handle(adapter);
486 if (!mac_handle) {
487 hdd_err("Invalid MAC handle");
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530488 return -EINVAL;
489 }
490
Liangwei Dong17bf2662018-01-05 02:02:05 -0500491 ret = hdd_get_valid_chan(adapter->hdd_ctx, chan,
492 &len);
493 if (ret) {
494 hdd_err("error %d in getting valid channel list", ret);
495 return ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530496 }
497
498 for (i = 0; i < len; i++) {
499 if (chan[i] == chan_number) {
500 found = true;
501 break;
502 }
503 }
504
505 if (found == false) {
506 hdd_err("Channel not in driver's valid channel list");
507 return -EOPNOTSUPP;
508 }
509
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700510 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
511 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530512 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
513 return -EINVAL;
514 }
515
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700516 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530517 if (chan_bw == CH_WIDTH_80MHZ) {
518 hdd_err("BW80 not possible in 2.4GHz band");
519 return -EINVAL;
520 }
521 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
522 (chan_bw != CH_WIDTH_MAX)) {
523 hdd_err("Only BW20 possible on channel 14");
524 return -EINVAL;
525 }
526 }
527
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700528 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530529 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
530 (chan_bw != CH_WIDTH_MAX)) {
531 hdd_err("Only BW20 possible on channel 165");
532 return -EINVAL;
533 }
534 }
535
536 return 0;
537}
538
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530539/**
540 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
541 *
542 * Block the unloading of the driver (or) interface up until the
543 * cds recovery is completed
544 *
545 * Return: true for recovery completion else false
546 */
547static bool hdd_wait_for_recovery_completion(void)
548{
549 int retry = 0;
550
551 /* Wait for recovery to complete */
552 while (cds_is_driver_recovering()) {
553 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
554 hdd_err("Recovery in progress; wait here!!!");
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530555
556 if (g_is_system_reboot_triggered) {
557 hdd_info("System Reboot happening ignore unload!!");
558 return false;
559 }
560
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530561 msleep(1000);
562 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
563 hdd_err("SSR never completed, error");
564 /*
565 * Trigger the bug_on in the internal builds, in the
566 * customer builds self-recovery will be enabled
567 * in those cases just return error.
568 */
569 if (cds_is_self_recovery_enabled())
570 return false;
571 QDF_BUG(0);
572 }
573 }
574
575 hdd_info("Recovery completed successfully!");
576 return true;
577}
578
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530579
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800580static int __hdd_netdev_notifier_call(struct notifier_block *nb,
581 unsigned long state, void *data)
582{
583#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
584 struct netdev_notifier_info *dev_notif_info = data;
585 struct net_device *dev = dev_notif_info->dev;
586#else
587 struct net_device *dev = data;
588#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700589 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700590 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800591
Dustin Brownfdf17c12018-03-14 12:55:34 -0700592 hdd_enter_dev(dev);
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800593
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800594 /* Make sure that this callback corresponds to our device. */
595 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
596 return NOTIFY_DONE;
597
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530598 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800599 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700600 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800601 return NOTIFY_DONE;
602 }
603
604 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700605 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800606 return NOTIFY_DONE;
607 }
608
609 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
610 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800611 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530612 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800613 return NOTIFY_DONE;
614 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800615
616 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
617 hdd_err("%s: Driver module is closed", __func__);
618 return NOTIFY_DONE;
619 }
620
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530621 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800622 return NOTIFY_DONE;
623
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800624 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800625 dev->name, state);
626
627 switch (state) {
628 case NETDEV_REGISTER:
629 break;
630
631 case NETDEV_UNREGISTER:
632 break;
633
634 case NETDEV_UP:
Jeff Johnson16528362018-06-14 12:34:16 -0700635 sme_ch_avoid_update_req(hdd_ctx->mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800636 break;
637
638 case NETDEV_DOWN:
639 break;
640
641 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700642 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800643 complete(&adapter->linkup_event_var);
644 break;
645
646 case NETDEV_GOING_DOWN:
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700647 if (ucfg_scan_get_vdev_status(adapter->hdd_vdev) !=
648 SCAN_NOT_IN_PROGRESS) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530649 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -0700650 adapter->session_id, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800651 }
Min Liu9be5d4a2018-05-17 11:51:53 +0800652 cds_flush_work(&adapter->scan_block_work);
653 /* Need to clean up blocked scan request */
654 wlan_hdd_cfg80211_scan_block_cb(&adapter->scan_block_work);
Min Liu9be5d4a2018-05-17 11:51:53 +0800655 hdd_debug("Scan is not Pending from user");
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530656 /*
657 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
658 * of return status of hdd_stop call, kernel resets the IFF_UP
659 * flag after which driver does not send the cfg80211_scan_done.
660 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
661 */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +0530662 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800663 break;
664
665 default:
666 break;
667 }
668
669 return NOTIFY_DONE;
670}
671
672/**
673 * hdd_netdev_notifier_call() - netdev notifier callback function
674 * @nb: pointer to notifier block
675 * @state: state
676 * @ndev: ndev pointer
677 *
678 * Return: 0 on success, error number otherwise.
679 */
680static int hdd_netdev_notifier_call(struct notifier_block *nb,
681 unsigned long state,
682 void *ndev)
683{
684 int ret;
685
686 cds_ssr_protect(__func__);
687 ret = __hdd_netdev_notifier_call(nb, state, ndev);
688 cds_ssr_unprotect(__func__);
689
690 return ret;
691}
692
693struct notifier_block hdd_netdev_notifier = {
694 .notifier_call = hdd_netdev_notifier_call,
695};
696
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530697static int system_reboot_notifier_call(struct notifier_block *nb,
698 unsigned long msg_type, void *_unused)
699{
700 switch (msg_type) {
701 case SYS_DOWN:
702 case SYS_HALT:
703 case SYS_POWER_OFF:
704 g_is_system_reboot_triggered = true;
705 hdd_info("reboot, reason: %ld", msg_type);
706 break;
707 default:
708 break;
709 }
710
711 return NOTIFY_OK;
712}
713
714struct notifier_block system_reboot_notifier = {
715 .notifier_call = system_reboot_notifier_call,
716};
717
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800718/* variable to hold the insmod parameters */
719static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800720
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530721static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700722int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530723
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800724/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800725static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800726
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530727/**
728 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
729 * @ch_width: NL channel width
730 *
731 * Converts the NL channel width to the driver's internal representation
732 *
733 * Return: Converted channel width. In case of non matching NL channel width,
734 * CH_WIDTH_MAX will be returned.
735 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800736enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530737{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800738 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700739
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800740 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530741 switch (ch_width) {
742 case NL80211_CHAN_WIDTH_20_NOHT:
743 case NL80211_CHAN_WIDTH_20:
744 return CH_WIDTH_20MHZ;
745 case NL80211_CHAN_WIDTH_40:
746 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530747 case NL80211_CHAN_WIDTH_80:
748 return CH_WIDTH_80MHZ;
749 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800750 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
751 return CH_WIDTH_80P80MHZ;
752 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
753 return CH_WIDTH_160MHZ;
754 else
755 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530756 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800757 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
758 return CH_WIDTH_160MHZ;
759 else
760 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530761 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800762 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530763 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800764 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530765 default:
766 hdd_err("Invalid channel width %d, setting to default",
767 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800768 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530769 }
770}
771
Jeff Johnson16528362018-06-14 12:34:16 -0700772uint8_t wlan_hdd_find_opclass(mac_handle_t mac_handle, uint8_t channel,
773 uint8_t bw_offset)
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530774{
775 uint8_t opclass = 0;
776
Jeff Johnson16528362018-06-14 12:34:16 -0700777 sme_get_opclass(mac_handle, channel, bw_offset, &opclass);
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530778 return opclass;
779}
780
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800781/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530782 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530783 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800784 * @bitmask: Bitmask of log levels to be enabled
785 *
786 * Called immediately after the cfg.ini is read in order to configure
787 * the desired trace levels.
788 *
789 * Return: None
790 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530791int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800792{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530793 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530794 int qdf_print_idx = -1;
795 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800796 /*
797 * if the bitmask is the default value, then a bitmask was not
798 * specified in cfg.ini, so leave the logging level alone (it
799 * will remain at the "compiled in" default value)
800 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700801 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530802 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800803
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530804 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800805
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530806 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530807 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530808 QDF_TRACE_LEVEL_NONE, 0);
809
810 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530811 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800812 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530813 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800814 while (0 != bitmask) {
815 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530816 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530817 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530818 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530819 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800820 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700821
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800822 level++;
823 bitmask >>= 1;
824 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530825 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800826}
827
828/**
Chris Guo1751acf2017-07-03 14:09:01 +0800829 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
830 * @hdd_ctx: HDD context pointer
831 *
832 * Return: 0 if the context is valid. Error code otherwise
833 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700834int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800835{
836 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
837 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
838 return -ENODEV;
839 }
840
841 if (cds_is_driver_recovering()) {
842 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
843 (void *)_RET_IP_, cds_get_driver_state());
844 return -EAGAIN;
845 }
846
847 if (hdd_ctx->start_modules_in_progress ||
848 hdd_ctx->stop_modules_in_progress) {
849 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
850 (void *)_RET_IP_);
851 return -EAGAIN;
852 }
853
854 return 0;
855}
856
857
858/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800859 * wlan_hdd_validate_context() - check the HDD context
860 * @hdd_ctx: HDD context pointer
861 *
862 * Return: 0 if the context is valid. Error code otherwise
863 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700864int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800865{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800866 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530867 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800868 return -ENODEV;
869 }
870
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800871 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800872 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530873 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800874 return -EAGAIN;
875 }
876
Yue Ma9f275d92017-09-14 16:58:41 -0700877 if (cds_is_load_or_unload_in_progress()) {
878 hdd_debug("%pS Load or unload in progress, state: 0x%x, ignore!",
879 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800880 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -0700881 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530882
883 if (hdd_ctx->start_modules_in_progress ||
884 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800885 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530886 (void *)_RET_IP_);
887 return -EAGAIN;
888 }
889
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530890 if (cds_is_driver_in_bad_state()) {
891 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
892 (void *)_RET_IP_, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +0530893 return -EAGAIN;
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530894 }
895
Arunk Khandavalli2859fa12018-02-14 10:46:26 +0530896 if (cds_is_fw_down()) {
897 hdd_debug("%pS FW is down: 0x%x Ignore!!!",
898 (void *)_RET_IP_, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +0530899 return -EAGAIN;
Arunk Khandavalli2859fa12018-02-14 10:46:26 +0530900 }
901
Liangwei Dong858feb12018-05-21 01:52:46 -0400902 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
903 hdd_debug("con_mode_handler is in progress Ignore!!!");
904 return -EAGAIN;
905 }
906
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800907 return 0;
908}
909
Jeff Johnson9d295242017-08-29 14:39:48 -0700910int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700911{
912 if (!adapter) {
913 hdd_err("adapter is null");
914 return -EINVAL;
915 }
916
917 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Mahesh Kumar Kalikot Veetil44427542018-06-08 12:29:36 -0700918 hdd_err("bad adapter magic");
Dustin Brownf13b8c32017-05-19 17:23:08 -0700919 return -EINVAL;
920 }
921
922 if (!adapter->dev) {
923 hdd_err("adapter net_device is null");
924 return -EINVAL;
925 }
926
927 if (!(adapter->dev->flags & IFF_UP)) {
928 hdd_info("adapter net_device is not up");
929 return -EAGAIN;
930 }
931
Jeff Johnson1b780e42017-10-31 14:11:45 -0700932 if (wlan_hdd_validate_session_id(adapter->session_id)) {
Dustin Brownf13b8c32017-05-19 17:23:08 -0700933 hdd_info("adapter session is not open");
934 return -EAGAIN;
935 }
936
Jeff Johnson1b780e42017-10-31 14:11:45 -0700937 if (adapter->session_id >= MAX_NUMBER_OF_ADAPTERS) {
938 hdd_err("bad adapter session Id: %u", adapter->session_id);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700939 return -EINVAL;
940 }
941
942 return 0;
943}
944
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800945/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530946 * wlan_hdd_validate_modules_state() - Check modules status
947 * @hdd_ctx: HDD context pointer
948 *
949 * Check's the driver module's state and returns true if the
950 * modules are enabled returns false if modules are closed.
951 *
952 * Return: True if modules are enabled or false.
953 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700954bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530955{
956 mutex_lock(&hdd_ctx->iface_change_lock);
957 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
958 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown5e89ef82018-03-14 11:50:23 -0700959 hdd_info("Modules not enabled, Present status: %d",
960 hdd_ctx->driver_status);
Arun Khandavallica892f62017-05-26 14:25:50 +0530961 return false;
962 }
963 mutex_unlock(&hdd_ctx->iface_change_lock);
964 return true;
965}
966
967/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800968 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700969 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800970 *
971 * This function sets the IBSS power save config parameters to WMA
972 * which will send it to firmware if FW supports IBSS power save
973 * before vdev start.
974 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530975 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800976 * on failure.
977 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700978QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800979{
980 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700981 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800982
983 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700984 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530985 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800986 }
987
Jeff Johnson1b780e42017-10-31 14:11:45 -0700988 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800989 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
990 hdd_ctx->config->ibssATIMWinSize,
991 VDEV_CMD);
992 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700993 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530994 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800995 }
996
Jeff Johnson1b780e42017-10-31 14:11:45 -0700997 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800998 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
999 hdd_ctx->config->isIbssPowerSaveAllowed,
1000 VDEV_CMD);
1001 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001002 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
1003 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301004 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001005 }
1006
Jeff Johnson1b780e42017-10-31 14:11:45 -07001007 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001008 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
1009 hdd_ctx->config->
1010 isIbssPowerCollapseAllowed, VDEV_CMD);
1011 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001012 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
1013 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301014 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001015 }
1016
Jeff Johnson1b780e42017-10-31 14:11:45 -07001017 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001018 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
1019 hdd_ctx->config->isIbssAwakeOnTxRx,
1020 VDEV_CMD);
1021 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001022 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301023 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001024 }
1025
Jeff Johnson1b780e42017-10-31 14:11:45 -07001026 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001027 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
1028 hdd_ctx->config->ibssInactivityCount,
1029 VDEV_CMD);
1030 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001031 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301032 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001033 }
1034
Jeff Johnson1b780e42017-10-31 14:11:45 -07001035 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001036 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
1037 hdd_ctx->config->ibssTxSpEndInactivityTime,
1038 VDEV_CMD);
1039 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001040 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
1041 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301042 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001043 }
1044
Jeff Johnson1b780e42017-10-31 14:11:45 -07001045 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001046 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
1047 hdd_ctx->config->ibssPsWarmupTime,
1048 VDEV_CMD);
1049 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001050 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
1051 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301052 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001053 }
1054
Jeff Johnson1b780e42017-10-31 14:11:45 -07001055 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001056 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
1057 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
1058 VDEV_CMD);
1059 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001060 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
1061 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301062 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001063 }
1064
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301065 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001066}
1067
Yue Macd359b72017-10-03 15:21:00 -07001068#ifdef FEATURE_RUNTIME_PM
1069/**
1070 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
1071 * @hdd_ctx: HDD context
1072 *
1073 * Return: None
1074 */
1075static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
1076{
1077 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1078
Yue Macd359b72017-10-03 15:21:00 -07001079 qdf_runtime_lock_init(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001080 qdf_runtime_lock_init(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001081
1082 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
1083}
1084
1085/**
1086 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1087 * @hdd_ctx: HDD Context
1088 *
1089 * Return: None
1090 */
1091static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1092{
1093 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1094
Yue Macd359b72017-10-03 15:21:00 -07001095 qdf_runtime_lock_deinit(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001096 qdf_runtime_lock_deinit(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001097
1098 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
1099}
1100
Yue Macd359b72017-10-03 15:21:00 -07001101#else /* FEATURE_RUNTIME_PM */
1102static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1103static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Yue Macd359b72017-10-03 15:21:00 -07001104#endif /* FEATURE_RUNTIME_PM */
1105
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001106#define INTF_MACADDR_MASK 0x7
1107
1108/**
1109 * hdd_update_macaddr() - update mac address
1110 * @config: hdd configuration
1111 * @hw_macaddr: mac address
1112 *
1113 * Mac address for multiple virtual interface is found as following
1114 * i) The mac address of the first interface is just the actual hw mac address.
1115 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
1116 * define the mac address for the remaining interfaces and locally
1117 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1118 * supported virtual interfaces, right now this is 0x07 (meaning 8
1119 * interface).
1120 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1121 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1122 *
1123 * Return: None
1124 */
1125void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301126 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001127{
1128 int8_t i;
1129 uint8_t macaddr_b3, tmp_br3;
1130
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301131 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301132 QDF_MAC_ADDR_SIZE);
1133 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301134 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301135 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001136 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1137 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1138 INTF_MACADDR_MASK;
1139 macaddr_b3 += tmp_br3;
1140
1141 /* XOR-ing bit-24 of the mac address. This will give enough
1142 * mac address range before collision
1143 */
1144 macaddr_b3 ^= (1 << 7);
1145
1146 /* Set locally administered bit */
1147 config->intfMacAddr[i].bytes[0] |= 0x02;
1148 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001149 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001150 MAC_ADDRESS_STR, i,
1151 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1152 }
1153}
1154
Kabilan Kannan44a58372017-12-06 18:16:11 -08001155static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1156{
1157 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
1158 struct tdls_start_params tdls_cfg;
1159 struct tdls_user_config *config = &tdls_cfg.config;
1160 struct hdd_config *cfg = hdd_ctx->config;
1161 QDF_STATUS status;
1162
1163 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
1164 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
1165 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
1166 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
1167 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
1168 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
1169 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
1170 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
1171 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
1172 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
1173 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
1174 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
1175 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
1176 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
1177 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
1178 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
1179 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
1180 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
1181 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
1182 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
1183 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
1184 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
1185 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
1186 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
1187 (cfg->fEnableTDLSImplicitTrigger ?
1188 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
1189 (cfg->fTDLSExternalControl ?
1190 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
1191 config->tdls_vdev_nss_2g = CFG_TDLS_NSS(cfg->vdev_type_nss_2g);
1192 config->tdls_vdev_nss_5g = CFG_TDLS_NSS(cfg->vdev_type_nss_5g);
1193
1194 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
1195 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
1196 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
1197 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
1198 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1199 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1200 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1201 tdls_cfg.tdls_evt_cb_data = psoc;
Jeff Johnson1d40f5b2018-03-02 08:35:53 -08001202 tdls_cfg.tdls_peer_context = hdd_ctx;
1203 tdls_cfg.tdls_reg_peer = hdd_tdls_register_peer;
1204 tdls_cfg.tdls_dereg_peer = hdd_tdls_deregister_peer;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001205 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1206 tdls_cfg.tdls_wmm_cb_data = psoc;
1207 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1208 tdls_cfg.tdls_rx_cb_data = psoc;
1209 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1210
1211 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1212 if (status != QDF_STATUS_SUCCESS) {
1213 hdd_err("failed pmo psoc configuration");
1214 return -EINVAL;
1215 }
1216
1217 hdd_ctx->tdls_umac_comp_active = true;
1218 /* enable napier specific tdls data path */
1219 hdd_ctx->tdls_nap_active = true;
1220
1221 return 0;
1222}
1223
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001224static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001225 struct wma_tgt_services *cfg)
1226{
1227 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001228
1229 /* Set up UAPSD */
1230 config->apUapsdEnabled &= cfg->uapsd;
1231
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001232 /* 11AX mode support */
1233 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1234 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1235 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1236
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001237 /* 11AC mode support */
1238 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1239 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1240 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001241
1242 /* ARP offload: override user setting if invalid */
1243 config->fhostArpOffload &= cfg->arp_offload;
1244
1245#ifdef FEATURE_WLAN_SCAN_PNO
1246 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001247 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001248 if (cfg->pno_offload)
1249 config->PnoOffload = true;
1250#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001251#ifdef FEATURE_WLAN_TDLS
1252 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301253 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1254 cfg->en_tdls_offchan;
1255 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1256 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001257 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001258 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001259 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001260 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001261#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001262#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1263 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1264#endif
Will Huang496b36c2017-07-11 16:38:50 +08001265 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001266 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001267 hdd_update_tdls_config(hdd_ctx);
Jeff Johnson16528362018-06-14 12:34:16 -07001268 sme_update_tgt_services(hdd_ctx->mac_handle, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001269
1270}
1271
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001272/**
1273 * hdd_update_vdev_nss() - sets the vdev nss
1274 * @hdd_ctx: HDD context
1275 *
1276 * Sets the Nss per vdev type based on INI
1277 *
1278 * Return: None
1279 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001280static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001281{
1282 struct hdd_config *cfg_ini = hdd_ctx->config;
1283 uint8_t max_supp_nss = 1;
Jeff Johnson16528362018-06-14 12:34:16 -07001284 mac_handle_t mac_handle;
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001285
Naveen Rawat10b1c152017-01-18 11:16:06 -08001286 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001287 max_supp_nss = 2;
Liangwei Dong22810e82018-03-15 03:42:12 -04001288 hdd_debug("max nss %d vdev_type_nss_2g %x vdev_type_nss_5g %x",
1289 max_supp_nss, cfg_ini->vdev_type_nss_2g,
1290 cfg_ini->vdev_type_nss_5g);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001291
Jeff Johnson16528362018-06-14 12:34:16 -07001292 mac_handle = hdd_ctx->mac_handle;
1293 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
1294 cfg_ini->vdev_type_nss_2g, BAND_2G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001295
Jeff Johnson16528362018-06-14 12:34:16 -07001296 sme_update_vdev_type_nss(mac_handle, max_supp_nss,
1297 cfg_ini->vdev_type_nss_5g, BAND_5G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001298}
1299
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301300/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301301 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1302 * @hdd_ctx: HDD context
1303 *
1304 * Updates wiphy vhtcap fields
1305 *
1306 * Return: None
1307 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001308static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301309{
1310 struct ieee80211_supported_band *band_5g =
1311 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1312 uint32_t val;
1313
1314 if (!band_5g) {
1315 hdd_debug("5GHz band disabled, skipping capability population");
1316 return;
1317 }
1318
1319 val = hdd_ctx->config->txBFCsnValue;
1320 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1321
1322 val = NUM_OF_SOUNDING_DIMENSIONS;
1323 band_5g->vht_cap.cap |=
1324 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1325
1326 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1327 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1328}
1329
1330/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301331 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1332 * @hdd_ctx: HDD context
1333 *
1334 * Sets the DBS capability as per INI and firmware capability
1335 *
1336 * Return: None
1337 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001338static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301339{
1340 struct hdd_config *cfg_ini = hdd_ctx->config;
1341 uint8_t hw_dbs_capable = 0;
1342
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001343 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1344 ((cfg_ini->dual_mac_feature_disable ==
1345 ENABLE_DBS_CXN_AND_SCAN) ||
1346 (cfg_ini->dual_mac_feature_disable ==
1347 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301348 hw_dbs_capable = 1;
1349
Jeff Johnson16528362018-06-14 12:34:16 -07001350 sme_update_hw_dbs_capable(hdd_ctx->mac_handle, hw_dbs_capable);
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301351}
1352
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001353static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001354 struct wma_tgt_ht_cap *cfg)
1355{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301356 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001357 uint32_t value, val32;
1358 uint16_t val16;
1359 struct hdd_config *pconfig = hdd_ctx->config;
1360 tSirMacHTCapabilityInfo *phtCapInfo;
1361 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1362 uint8_t enable_tx_stbc;
Jeff Johnson16528362018-06-14 12:34:16 -07001363 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001364
1365 /* check and update RX STBC */
1366 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1367 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1368
Jeff Johnson16528362018-06-14 12:34:16 -07001369 mac_handle = hdd_ctx->mac_handle;
1370
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001371 /* get the MPDU density */
Jeff Johnson16528362018-06-14 12:34:16 -07001372 status = sme_cfg_get_int(mac_handle, WNI_CFG_MPDU_DENSITY, &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001373
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301374 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001375 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001376 value = 0;
1377 }
1378
1379 /*
1380 * MPDU density:
1381 * override user's setting if value is larger
1382 * than the one supported by target
1383 */
1384 if (value > cfg->mpdu_density) {
Jeff Johnson16528362018-06-14 12:34:16 -07001385 status = sme_cfg_set_int(mac_handle, WNI_CFG_MPDU_DENSITY,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001386 cfg->mpdu_density);
1387
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301388 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001389 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001390 }
1391
1392 /* get the HT capability info */
Jeff Johnson16528362018-06-14 12:34:16 -07001393 status = sme_cfg_get_int(mac_handle, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301394 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001395 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001396 return;
1397 }
1398 val16 = (uint16_t) val32;
1399 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1400
1401 /* Set the LDPC capability */
1402 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1403
1404 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1405 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1406
1407 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1408 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1409
1410 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1411 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1412
1413 enable_tx_stbc = pconfig->enableTxSTBC;
1414
1415 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1416 pconfig->enable2x2 = 1;
1417 } else {
1418 pconfig->enable2x2 = 0;
1419 enable_tx_stbc = 0;
1420
1421 /* 1x1 */
1422 /* Update Rx Highest Long GI data Rate */
Jeff Johnson16528362018-06-14 12:34:16 -07001423 if (sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001424 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001425 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301426 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001427 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001428 }
1429
1430 /* Update Tx Highest Long GI data Rate */
1431 if (sme_cfg_set_int
Jeff Johnson16528362018-06-14 12:34:16 -07001432 (mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001433 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001434 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301435 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001436 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001437 }
1438 }
1439 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1440 enable_tx_stbc = 0;
1441 phtCapInfo->txSTBC = enable_tx_stbc;
1442
1443 val32 = val16;
Jeff Johnson16528362018-06-14 12:34:16 -07001444 status = sme_cfg_set_int(mac_handle, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301445 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001446 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001447#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1448 value = SIZE_OF_SUPPORTED_MCS_SET;
Jeff Johnson16528362018-06-14 12:34:16 -07001449 if (sme_cfg_get_str(mac_handle, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301450 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001451 hdd_debug("Read MCS rate set");
gaurank kathpalia18b49362018-04-15 23:12:03 +05301452 if (cfg->num_rf_chains > SIZE_OF_SUPPORTED_MCS_SET)
1453 cfg->num_rf_chains = SIZE_OF_SUPPORTED_MCS_SET;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001454 if (pconfig->enable2x2) {
1455 for (value = 0; value < cfg->num_rf_chains; value++)
1456 mcs_set[value] =
1457 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1458
1459 status =
Jeff Johnson16528362018-06-14 12:34:16 -07001460 sme_cfg_set_str(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001461 WNI_CFG_SUPPORTED_MCS_SET,
1462 mcs_set,
1463 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301464 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001465 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001466 }
1467 }
1468#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1469}
1470
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001471static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001472 struct wma_tgt_vht_cap *cfg)
1473{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301474 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001475 uint32_t value = 0;
1476 struct hdd_config *pconfig = hdd_ctx->config;
1477 struct wiphy *wiphy = hdd_ctx->wiphy;
1478 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001479 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001480 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001481 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001482 uint32_t hw_rx_ldpc_enabled;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001483 struct wma_caps_per_phy caps_per_phy;
Jeff Johnson16528362018-06-14 12:34:16 -07001484 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001485
Dustin Brown5e06bd32016-10-04 12:49:10 -07001486 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001487 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001488 return;
1489 }
1490
Jeff Johnson16528362018-06-14 12:34:16 -07001491 mac_handle = hdd_ctx->mac_handle;
1492
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001493 /* Get the current MPDU length */
1494 status =
Jeff Johnson16528362018-06-14 12:34:16 -07001495 sme_cfg_get_int(mac_handle, WNI_CFG_VHT_MAX_MPDU_LENGTH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001496 &value);
1497
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301498 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001499 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001500 value = 0;
1501 }
1502
1503 /*
1504 * VHT max MPDU length:
1505 * override if user configured value is too high
1506 * that the target cannot support
1507 */
1508 if (value > cfg->vht_max_mpdu) {
Jeff Johnson16528362018-06-14 12:34:16 -07001509 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001510 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1511 cfg->vht_max_mpdu);
1512
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001513 if (status == QDF_STATUS_E_FAILURE)
1514 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001515 }
1516
Jeff Johnson16528362018-06-14 12:34:16 -07001517 sme_cfg_get_int(mac_handle, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001518 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1519
1520 if (pconfig->enable2x2)
1521 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1522
Jeff Johnson16528362018-06-14 12:34:16 -07001523 if (sme_cfg_set_int(mac_handle, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001524 QDF_STATUS_E_FAILURE) {
1525 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1526 }
1527
Jeff Johnson16528362018-06-14 12:34:16 -07001528 sme_cfg_get_int(mac_handle, WNI_CFG_VHT_RX_MCS_MAP, &temp);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001529 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1530 if (pconfig->enable2x2)
1531 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1532
Jeff Johnson16528362018-06-14 12:34:16 -07001533 if (sme_cfg_set_int(mac_handle, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001534 QDF_STATUS_E_FAILURE) {
1535 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1536 }
1537
Jeff Johnson16528362018-06-14 12:34:16 -07001538 sme_cfg_get_int(mac_handle, WNI_CFG_VHT_TX_MCS_MAP, &temp);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001539 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1540 if (pconfig->enable2x2)
1541 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1542
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001543 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001544 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1545
Jeff Johnson16528362018-06-14 12:34:16 -07001546 if (sme_cfg_set_int(mac_handle, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001547 QDF_STATUS_E_FAILURE) {
1548 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1549 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001550 /* Get the current RX LDPC setting */
Jeff Johnson16528362018-06-14 12:34:16 -07001551 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_LDPC_CODING_CAP,
1552 &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001553
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301554 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001555 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001556 value = 0;
1557 }
1558
jiad4a7a33c2017-08-08 15:32:24 +08001559 /* Set HW RX LDPC capability */
1560 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1561 if (hw_rx_ldpc_enabled != value) {
Jeff Johnson16528362018-06-14 12:34:16 -07001562 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001563 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001564 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001565
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001566 if (status == QDF_STATUS_E_FAILURE)
1567 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001568 }
1569
1570 /* Get current GI 80 value */
Jeff Johnson16528362018-06-14 12:34:16 -07001571 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_SHORT_GI_80MHZ,
1572 &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001573
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301574 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001575 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001576 value = 0;
1577 }
1578
1579 /* set the Guard interval 80MHz */
1580 if (value && !cfg->vht_short_gi_80) {
Jeff Johnson16528362018-06-14 12:34:16 -07001581 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001582 WNI_CFG_VHT_SHORT_GI_80MHZ,
1583 cfg->vht_short_gi_80);
1584
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001585 if (status == QDF_STATUS_E_FAILURE)
1586 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001587 }
1588
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001589 /* Get VHT TX STBC cap */
Jeff Johnson16528362018-06-14 12:34:16 -07001590 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_TXSTBC, &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001591
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301592 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001593 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001594 value = 0;
1595 }
1596
1597 /* VHT TX STBC cap */
1598 if (value && !cfg->vht_tx_stbc) {
Jeff Johnson16528362018-06-14 12:34:16 -07001599 status = sme_cfg_set_int(mac_handle, WNI_CFG_VHT_TXSTBC,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001600 cfg->vht_tx_stbc);
1601
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001602 if (status == QDF_STATUS_E_FAILURE)
1603 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001604 }
1605
1606 /* Get VHT RX STBC cap */
Jeff Johnson16528362018-06-14 12:34:16 -07001607 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_RXSTBC, &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001608
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301609 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001610 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001611 value = 0;
1612 }
1613
1614 /* VHT RX STBC cap */
1615 if (value && !cfg->vht_rx_stbc) {
Jeff Johnson16528362018-06-14 12:34:16 -07001616 status = sme_cfg_set_int(mac_handle, WNI_CFG_VHT_RXSTBC,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001617 cfg->vht_rx_stbc);
1618
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001619 if (status == QDF_STATUS_E_FAILURE)
1620 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001621 }
1622
1623 /* Get VHT SU Beamformer cap */
Jeff Johnson16528362018-06-14 12:34:16 -07001624 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001625 &value);
1626
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301627 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001628 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001629 value = 0;
1630 }
1631
1632 /* set VHT SU Beamformer cap */
1633 if (value && !cfg->vht_su_bformer) {
Jeff Johnson16528362018-06-14 12:34:16 -07001634 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001635 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1636 cfg->vht_su_bformer);
1637
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001638 if (status == QDF_STATUS_E_FAILURE)
1639 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001640 }
1641
1642 /* check and update SU BEAMFORMEE capabality */
1643 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1644 pconfig->enableTxBF = cfg->vht_su_bformee;
1645
Jeff Johnson16528362018-06-14 12:34:16 -07001646 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001647 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1648 pconfig->enableTxBF);
1649
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001650 if (status == QDF_STATUS_E_FAILURE)
1651 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001652
1653 /* Get VHT MU Beamformer cap */
Jeff Johnson16528362018-06-14 12:34:16 -07001654 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001655 &value);
1656
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301657 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001658 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001659 value = 0;
1660 }
1661
1662 /* set VHT MU Beamformer cap */
1663 if (value && !cfg->vht_mu_bformer) {
Jeff Johnson16528362018-06-14 12:34:16 -07001664 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001665 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1666 cfg->vht_mu_bformer);
1667
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001668 if (status == QDF_STATUS_E_FAILURE)
1669 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001670 }
1671
1672 /* Get VHT MU Beamformee cap */
Jeff Johnson16528362018-06-14 12:34:16 -07001673 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001674 &value);
1675
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301676 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001677 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001678 value = 0;
1679 }
1680
1681 /* set VHT MU Beamformee cap */
1682 if (value && !cfg->vht_mu_bformee) {
Jeff Johnson16528362018-06-14 12:34:16 -07001683 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001684 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1685 cfg->vht_mu_bformee);
1686
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001687 if (status == QDF_STATUS_E_FAILURE)
1688 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001689 }
1690
1691 /* Get VHT MAX AMPDU Len exp */
Jeff Johnson16528362018-06-14 12:34:16 -07001692 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001693 &value);
1694
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301695 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001696 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001697 value = 0;
1698 }
1699
1700 /*
1701 * VHT max AMPDU len exp:
1702 * override if user configured value is too high
1703 * that the target cannot support.
1704 * Even though Rome publish ampdu_len=7, it can
1705 * only support 4 because of some h/w bug.
1706 */
1707
1708 if (value > cfg->vht_max_ampdu_len_exp) {
Jeff Johnson16528362018-06-14 12:34:16 -07001709 status = sme_cfg_set_int(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001710 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1711 cfg->vht_max_ampdu_len_exp);
1712
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001713 if (status == QDF_STATUS_E_FAILURE)
1714 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001715 }
1716
1717 /* Get VHT TXOP PS CAP */
Jeff Johnson16528362018-06-14 12:34:16 -07001718 status = sme_cfg_get_int(mac_handle, WNI_CFG_VHT_TXOP_PS, &value);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001719
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301720 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001721 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001722 value = 0;
1723 }
1724
1725 /* set VHT TXOP PS cap */
1726 if (value && !cfg->vht_txop_ps) {
Jeff Johnson16528362018-06-14 12:34:16 -07001727 status = sme_cfg_set_int(mac_handle, WNI_CFG_VHT_TXOP_PS,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001728 cfg->vht_txop_ps);
1729
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001730 if (status == QDF_STATUS_E_FAILURE)
1731 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001732 }
1733
1734 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1735 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1736 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1737 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1738 else
1739 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1740
1741
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001742 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
Jeff Johnson16528362018-06-14 12:34:16 -07001743 status = sme_cfg_set_int(mac_handle,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001744 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1745 VHT_CAP_160_AND_80P80_SUPP);
1746 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001747 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001748 band_5g->vht_cap.cap |=
1749 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001750 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1751 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
Jeff Johnson16528362018-06-14 12:34:16 -07001752 status = sme_cfg_set_int(mac_handle,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001753 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1754 VHT_CAP_160_SUPP);
1755 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001756 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001757 band_5g->vht_cap.cap |=
1758 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001759 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1760 }
1761 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1762 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301763 /* Get the current GI 160 value */
Jeff Johnson16528362018-06-14 12:34:16 -07001764 status = sme_cfg_get_int(mac_handle,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301765 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001766 &value);
1767 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301768 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001769 value = 0;
1770 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301771 /* set the Guard interval 160MHz */
1772 if (value && !cfg->vht_short_gi_160) {
Jeff Johnson16528362018-06-14 12:34:16 -07001773 status = sme_cfg_set_int(mac_handle,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301774 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1775 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001776
1777 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301778 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001779 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001780
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001781 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001782 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001783 hdd_debug("VHT RxLDPC capability is set");
1784 } else {
1785 /*
1786 * Get the RX LDPC capability for the NON DBS
1787 * hardware mode for 5G band
1788 */
1789 status = wma_get_caps_for_phyidx_hwmode(&caps_per_phy,
1790 HW_MODE_DBS_NONE, CDS_BAND_5GHZ);
1791 if ((QDF_IS_STATUS_SUCCESS(status)) &&
1792 (caps_per_phy.vht_5g & WMI_VHT_CAP_RX_LDPC)) {
1793 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1794 hdd_debug("VHT RX LDPC capability is set");
1795 }
1796 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001797
1798 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1799 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1800 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1801 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1802
1803 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1804 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1805
1806 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1807 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1808 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1809 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1810 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1811 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1812
1813 band_5g->vht_cap.cap |=
1814 (cfg->vht_max_ampdu_len_exp <<
1815 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1816
1817 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1818 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1819 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1820 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1821 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1822 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1823 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1824 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1825
1826 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1827 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1828
1829}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001830
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001831/**
1832 * hdd_generate_macaddr_auto() - Auto-generate mac address
1833 * @hdd_ctx: Pointer to the HDD context
1834 *
1835 * Auto-generate mac address using device serial number.
1836 * Keep the first 3 bytes of OUI as before and replace
1837 * the last 3 bytes with the lower 3 bytes of serial number.
1838 *
1839 * Return: 0 for success
1840 * Non zero failure code for errors
1841 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001842static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001843{
1844 unsigned int serialno = 0;
1845 struct qdf_mac_addr mac_addr = {
1846 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1847 };
1848
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001849 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001850 if (serialno == 0)
1851 return -EINVAL;
1852
1853 serialno &= 0x00ffffff;
1854
1855 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1856 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1857 mac_addr.bytes[5] = serialno & 0xff;
1858
1859 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1860 return 0;
1861}
1862
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301863/**
1864 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1865 * configuration to cfg_ini in HDD
1866 * @hdd_ctx: Pointer to hdd_ctx
1867 * @cfg: target configuration
1868 *
1869 * Return: None
1870 */
1871#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001872static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301873 struct wma_tgt_cfg *cfg)
1874{
1875 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1876}
1877#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001878static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301879 struct wma_tgt_cfg *cfg)
1880{
1881}
1882#endif
1883
Jeff Johnson8abc5932018-06-02 22:51:37 -07001884void hdd_update_tgt_cfg(hdd_handle_t hdd_handle, struct wma_tgt_cfg *cfg)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001885{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001886 int ret;
Jeff Johnson8abc5932018-06-02 22:51:37 -07001887 struct hdd_context *hdd_ctx = (struct hdd_context *)hdd_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001888 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001889 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301890 uint8_t antenna_mode;
Arif Hussainee10f902017-12-27 16:30:17 -08001891 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -07001892 mac_handle_t mac_handle;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301893
gaurank kathpalia843f7c32018-07-02 18:04:14 +05301894 if (!hdd_ctx) {
1895 hdd_err("HDD context is NULL");
1896 return;
1897 }
Dustin Brownbd68fe12017-11-21 15:28:52 -08001898 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1899 if (ret) {
1900 hdd_err("Failed to create pdev; errno:%d", ret);
1901 QDF_BUG(0);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001902 } else {
Dustin Brownbd68fe12017-11-21 15:28:52 -08001903 hdd_debug("New pdev has been created with pdev_id = %u",
Arif Hussainee10f902017-12-27 16:30:17 -08001904 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Amar Singhal410675c2018-01-10 12:14:21 -08001905 if (dispatcher_pdev_open(hdd_ctx->hdd_pdev)) {
1906 hdd_err("dispatcher pdev open failed");
1907 QDF_BUG(0);
1908 }
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301909 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001910
Will Huang07244172018-05-14 14:23:30 +08001911 hdd_objmgr_update_tgt_max_vdev_psoc(hdd_ctx, cfg->max_intf_count);
1912
Jeff Johnsone8846ab2018-03-31 11:54:45 -07001913 ret = hdd_green_ap_update_config(hdd_ctx);
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301914
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301915 ucfg_ipa_set_dp_handle(hdd_ctx->hdd_psoc,
1916 cds_get_context(QDF_MODULE_ID_SOC));
1917 ucfg_ipa_set_txrx_handle(hdd_ctx->hdd_psoc,
1918 cds_get_context(QDF_MODULE_ID_TXRX));
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301919 ucfg_ipa_reg_sap_xmit_cb(hdd_ctx->hdd_pdev,
1920 hdd_softap_hard_start_xmit);
1921 ucfg_ipa_reg_send_to_nw_cb(hdd_ctx->hdd_pdev,
1922 hdd_ipa_send_skb_to_network);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301923
Naveen Rawat64e477e2016-05-20 10:34:56 -07001924 if (cds_cfg) {
1925 if (hdd_ctx->config->enable_sub_20_channel_width !=
1926 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1927 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1928 cds_cfg->sub_20_channel_width =
1929 WLAN_SUB_20_CH_WIDTH_NONE;
1930 } else {
1931 cds_cfg->sub_20_channel_width =
1932 hdd_ctx->config->enable_sub_20_channel_width;
1933 }
1934 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001935
1936 /* first store the INI band capability */
1937 temp_band_cap = hdd_ctx->config->nBandCapability;
1938
1939 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301940 hdd_ctx->is_fils_roaming_supported =
1941 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001942
Vignesh Viswanathan694e28e2018-01-18 20:53:57 +05301943 hdd_ctx->config->is_11k_offload_supported =
1944 cfg->services.is_11k_offload_supported;
1945
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001946 /*
1947 * now overwrite the target band capability with INI
1948 * setting if INI setting is a subset
1949 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001950
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001951 if ((hdd_ctx->config->nBandCapability == BAND_ALL) &&
1952 (temp_band_cap != BAND_ALL))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001953 hdd_ctx->config->nBandCapability = temp_band_cap;
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001954 else if ((hdd_ctx->config->nBandCapability != BAND_ALL) &&
1955 (temp_band_cap != BAND_ALL) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001956 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001957 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001958 }
1959
Amar Singhal58b45ef2017-08-01 13:43:54 -07001960 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1961
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301962 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001963 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1964 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1965 }
1966
1967 /* This can be extended to other configurations like ht, vht cap... */
1968
Anurag Chouhanc5548422016-02-24 18:33:27 +05301969 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001970 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001971 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001972 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001973 static struct qdf_mac_addr default_mac_addr = {
1974 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1975 };
1976 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1977 &default_mac_addr)) {
1978 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1979 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1980 MAC_ADDRESS_STR,
1981 MAC_ADDR_ARRAY(hdd_ctx->config->
1982 intfMacAddr[0].bytes));
1983 } else {
1984 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1985 MAC_ADDRESS_STR,
1986 MAC_ADDR_ARRAY(hdd_ctx->config->
1987 intfMacAddr[0].bytes));
1988 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001989 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001990 }
1991
1992 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001993 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001994
Ryan Hsuc6918552018-05-16 13:29:59 -07001995 hdd_ctx->hw_bd_id = cfg->hw_bd_id;
1996 qdf_mem_copy(&hdd_ctx->hw_bd_info, &cfg->hw_bd_info,
1997 sizeof(cfg->hw_bd_info));
1998
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001999 hdd_ctx->max_intf_count = cfg->max_intf_count;
2000
Jeff Johnsonc875e242016-09-23 18:12:34 -07002001 hdd_lpass_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08002002
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002003 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
2004 hdd_update_tgt_services(hdd_ctx, &cfg->services);
2005
2006 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
2007
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002008 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07002009 if (cfg->services.en_11ax) {
2010 hdd_info("11AX: 11ax is enabled - update HDD config");
2011 hdd_update_tgt_he_cap(hdd_ctx, cfg);
2012 }
Varun Reddy Yeturue93d2462018-05-22 13:54:52 -07002013 hdd_update_tgt_twt_cap(hdd_ctx, cfg);
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07002014
2015 hdd_update_vdev_nss(hdd_ctx);
2016
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05302017 hdd_update_hw_dbs_capable(hdd_ctx);
2018
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08002019 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07002020 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002021 hdd_debug("fine_time_meas_cap: 0x%x",
Arif Hussainee10f902017-12-27 16:30:17 -08002022 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08002023
Nitesh Shahe50711f2017-04-26 16:30:45 +05302024 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
2025 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
2026 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002027 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08002028 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08002029
Nachiket Kukadee547a482018-05-22 16:43:30 +05302030 hdd_ctx->apf_enabled = (cfg->apf_enabled &&
2031 hdd_ctx->config->apf_packet_filter_enable);
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05302032 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05302033 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05302034
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302035 if ((hdd_ctx->config->txBFCsnValue >
Arif Hussainee10f902017-12-27 16:30:17 -08002036 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
2037 !cfg->tx_bfee_8ss_enabled)
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302038 hdd_ctx->config->txBFCsnValue =
2039 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
2040
Jeff Johnson16528362018-06-14 12:34:16 -07002041 mac_handle = hdd_ctx->mac_handle;
2042 status = sme_cfg_set_int(mac_handle,
Arif Hussainee10f902017-12-27 16:30:17 -08002043 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
2044 hdd_ctx->config->txBFCsnValue);
2045 if (QDF_IS_STATUS_ERROR(status))
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05302046 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
2047
2048
Nachiket Kukadee547a482018-05-22 16:43:30 +05302049 hdd_debug("Target APF %d Host APF %d 8ss fw support %d txBFCsnValue %d",
2050 cfg->apf_enabled, hdd_ctx->config->apf_packet_filter_enable,
Arif Hussainee10f902017-12-27 16:30:17 -08002051 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05302052
2053 /*
2054 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
2055 */
2056 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05302057
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05302058 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
2059
Yue Macd359b72017-10-03 15:21:00 -07002060 /*
2061 * This needs to be done after HDD pdev is created and stored since
2062 * it will access the HDD pdev object lock.
2063 */
2064 hdd_runtime_suspend_context_init(hdd_ctx);
2065
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07002066 /* Configure NAN datapath features */
2067 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07002068 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08002069 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Jeff Johnson16528362018-06-14 12:34:16 -07002070 status = sme_cfg_set_int(mac_handle, WNI_CFG_OBSS_DETECTION_OFFLOAD,
Arif Hussainee10f902017-12-27 16:30:17 -08002071 cfg->obss_detection_offloaded);
2072 if (QDF_IS_STATUS_ERROR(status))
2073 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Arif Hussain05fb4872018-01-03 16:02:55 -08002074
Jeff Johnson16528362018-06-14 12:34:16 -07002075 status = sme_cfg_set_int(mac_handle,
Arif Hussain05fb4872018-01-03 16:02:55 -08002076 WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD,
2077 cfg->obss_color_collision_offloaded);
2078 if (QDF_IS_STATUS_ERROR(status))
2079 hdd_err("Failed to set WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002080}
2081
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002082bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002083{
Jeff Johnson9d295242017-08-29 14:39:48 -07002084 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002085 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002086
Jiachao Wuf610d912018-01-23 17:47:32 +08002087 if (!hdd_ctx) {
2088 hdd_info("Couldn't get hdd_ctx");
2089 return true;
2090 }
2091
2092 if (hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002093 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08002094 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302095 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002096 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002097
Dustin Brown920397d2017-12-13 16:27:50 -08002098 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002099 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2100
2101 if ((QDF_SAP_MODE == adapter->device_mode ||
2102 QDF_P2P_GO_MODE == adapter->device_mode) &&
bings0e03a982018-05-09 08:40:59 +08002103 (wlan_reg_is_passive_or_disable_ch(hdd_ctx->hdd_pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002104 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002105 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2106 true;
2107 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07002108 adapter->session_id);
bings0e03a982018-05-09 08:40:59 +08002109 cdp_fc_vdev_flush(cds_get_context(QDF_MODULE_ID_SOC),
2110 adapter->txrx_vdev);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302111 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002112 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302113
2114 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002115}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002116
2117/**
2118 * hdd_is_valid_mac_address() - validate MAC address
2119 * @pMacAddr: Pointer to the input MAC address
2120 *
2121 * This function validates whether the given MAC address is valid or not
2122 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
2123 * where X is the hexa decimal digit character and separated by ':'
2124 * This algorithm works even if MAC address is not separated by ':'
2125 *
2126 * This code checks given input string mac contains exactly 12 hexadecimal
2127 * digits and a separator colon : appears in the input string only after
2128 * an even number of hex digits.
2129 *
2130 * Return: 1 for valid and 0 for invalid
2131 */
2132bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
2133{
2134 int xdigit = 0;
2135 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002136
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002137 while (*pMacAddr) {
2138 if (isxdigit(*pMacAddr)) {
2139 xdigit++;
2140 } else if (':' == *pMacAddr) {
2141 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2142 break;
2143
2144 ++separator;
2145 } else {
2146 /* Invalid MAC found */
2147 return 0;
2148 }
2149 ++pMacAddr;
2150 }
2151 return xdigit == 12 && (separator == 5 || separator == 0);
2152}
2153
2154/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302155 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2156 * @dev: Handle to struct net_device to be updated.
2157 *
2158 * Return: None
2159 */
2160static void hdd_mon_mode_ether_setup(struct net_device *dev)
2161{
2162 dev->header_ops = NULL;
2163 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2164 dev->hard_header_len = ETH_HLEN;
2165 dev->mtu = ETH_DATA_LEN;
2166 dev->addr_len = ETH_ALEN;
2167 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2168 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2169 dev->priv_flags |= IFF_TX_SKB_SHARING;
2170
2171 memset(dev->broadcast, 0xFF, ETH_ALEN);
2172}
2173
Nirav Shah73713f72018-05-17 14:50:41 +05302174#ifdef FEATURE_MONITOR_MODE_SUPPORT
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302175/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002176 * __hdd__mon_open() - HDD Open function
2177 * @dev: Pointer to net_device structure
2178 *
2179 * This is called in response to ifconfig up
2180 *
2181 * Return: 0 for success; non-zero for failure
2182 */
2183static int __hdd_mon_open(struct net_device *dev)
2184{
2185 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002186 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2187 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002188
Dustin Brownfdf17c12018-03-14 12:55:34 -07002189 hdd_enter_dev(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002190
2191 ret = wlan_hdd_validate_context(hdd_ctx);
2192 if (ret)
2193 return ret;
2194
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302195 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002196
2197 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Browne7e71d32018-05-11 16:00:08 -07002198 ret = hdd_wlan_start_modules(hdd_ctx, false);
Ravi Joshia307f632017-07-17 23:41:41 -07002199 if (ret) {
2200 hdd_err("Failed to start WLAN modules return");
2201 return ret;
2202 }
2203 hdd_err("hdd_wlan_start_modules() successful !");
2204
2205 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2206 ret = hdd_start_adapter(adapter);
2207 if (ret) {
2208 hdd_err("Failed to start adapter :%d",
2209 adapter->device_mode);
2210 return ret;
2211 }
2212 hdd_err("hdd_start_adapters() successful !");
2213 }
2214 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2215 }
2216
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002217 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002218
2219 if (!ret)
2220 ret = hdd_enable_monitor_mode(dev);
2221
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002222 return ret;
2223}
2224
2225/**
2226 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2227 * @dev: Pointer to net_device structure
2228 *
2229 * This is called in response to ifconfig up
2230 *
2231 * Return: 0 for success; non-zero for failure
2232 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002233static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002234{
2235 int ret;
2236
2237 cds_ssr_protect(__func__);
2238 ret = __hdd_mon_open(dev);
2239 cds_ssr_unprotect(__func__);
2240
2241 return ret;
2242}
Nirav Shah73713f72018-05-17 14:50:41 +05302243#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002244
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002245static QDF_STATUS
2246wlan_hdd_update_dbs_scan_and_fw_mode_config(void)
2247{
2248 struct policy_mgr_dual_mac_config cfg = {0};
2249 QDF_STATUS status;
2250 uint32_t channel_select_logic_conc;
2251 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2252
2253 if (!hdd_ctx) {
2254 hdd_err("HDD context is NULL");
2255 return QDF_STATUS_E_FAILURE;
2256 }
2257
2258
2259 if (!policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc))
2260 return QDF_STATUS_SUCCESS;
2261
2262 cfg.scan_config = 0;
2263 cfg.fw_mode_config = 0;
2264 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
2265
2266 channel_select_logic_conc = hdd_ctx->config->
2267 channel_select_logic_conc;
2268
2269 if (hdd_ctx->config->dual_mac_feature_disable !=
2270 DISABLE_DBS_CXN_AND_SCAN) {
2271 status = policy_mgr_get_updated_scan_and_fw_mode_config(
2272 hdd_ctx->hdd_psoc, &cfg.scan_config,
2273 &cfg.fw_mode_config,
2274 hdd_ctx->config->dual_mac_feature_disable,
2275 channel_select_logic_conc);
2276
2277 if (status != QDF_STATUS_SUCCESS) {
2278 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
2279 status);
2280 return status;
2281 }
2282 }
2283
2284 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
2285 cfg.scan_config, cfg.fw_mode_config);
2286
2287 status = sme_soc_set_dual_mac_config(cfg);
2288 if (status != QDF_STATUS_SUCCESS) {
2289 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
2290 return status;
2291 }
2292
2293 return QDF_STATUS_SUCCESS;
2294}
2295
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002296/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302297 * hdd_start_adapter() - Wrapper function for device specific adapter
2298 * @adapter: pointer to HDD adapter
2299 *
2300 * This function is called to start the device specific adapter for
2301 * the mode passed in the adapter's device_mode.
2302 *
2303 * Return: 0 for success; non-zero for failure
2304 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002305int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302306{
2307
2308 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002309 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302310
Dustin Brownfdf17c12018-03-14 12:55:34 -07002311 hdd_enter_dev(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002312 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302313
2314 switch (device_mode) {
2315 case QDF_P2P_CLIENT_MODE:
2316 case QDF_P2P_DEVICE_MODE:
2317 case QDF_OCB_MODE:
2318 case QDF_STA_MODE:
2319 case QDF_MONITOR_MODE:
2320 ret = hdd_start_station_adapter(adapter);
2321 if (ret)
2322 goto err_start_adapter;
2323 break;
2324 case QDF_P2P_GO_MODE:
2325 case QDF_SAP_MODE:
2326 ret = hdd_start_ap_adapter(adapter);
2327 if (ret)
2328 goto err_start_adapter;
2329 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302330 case QDF_IBSS_MODE:
2331 /*
2332 * For IBSS interface is initialized as part of
2333 * hdd_init_station_mode()
2334 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002335 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302336 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002337 /* vdevs are dynamically managed by firmware in FTM */
2338 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302339 default:
2340 hdd_err("Invalid session type %d", device_mode);
2341 QDF_ASSERT(0);
2342 goto err_start_adapter;
2343 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002344
Arun Khandavallifae92942016-08-01 13:31:08 +05302345 if (hdd_set_fw_params(adapter))
2346 hdd_err("Failed to set the FW params for the adapter!");
2347
Dustin Browne7e71d32018-05-11 16:00:08 -07002348 if (adapter->session_id != HDD_SESSION_ID_INVALID) {
2349 ret = wlan_hdd_cfg80211_register_frames(adapter);
2350 if (ret < 0) {
2351 hdd_err("Failed to register frames - ret %d", ret);
2352 goto err_start_adapter;
2353 }
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302354 }
Dustin Browne7e71d32018-05-11 16:00:08 -07002355
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002356 wlan_hdd_update_dbs_scan_and_fw_mode_config();
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302357
Dustin Browndb2a8be2017-12-20 11:49:56 -08002358exit_with_success:
Dustin Browne74003f2018-03-14 12:51:58 -07002359 hdd_exit();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002360
Arun Khandavallifae92942016-08-01 13:31:08 +05302361 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002362
Arun Khandavallifae92942016-08-01 13:31:08 +05302363err_start_adapter:
2364 return -EINVAL;
2365}
2366
2367/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302368 * hdd_enable_power_management() - API to Enable Power Management
2369 *
2370 * API invokes Bus Interface Layer power management functionality
2371 *
2372 * Return: None
2373 */
2374static void hdd_enable_power_management(void)
2375{
2376 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2377
2378 if (!hif_ctx) {
2379 hdd_err("Bus Interface Context is Invalid");
2380 return;
2381 }
2382
2383 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2384}
2385
2386/**
2387 * hdd_disable_power_management() - API to disable Power Management
2388 *
2389 * API disable Bus Interface Layer Power management functionality
2390 *
2391 * Return: None
2392 */
2393static void hdd_disable_power_management(void)
2394{
2395 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2396
2397 if (!hif_ctx) {
2398 hdd_err("Bus Interface Context is Invalid");
2399 return;
2400 }
2401
2402 hif_disable_power_management(hif_ctx);
2403}
2404
Ryan Hsuaadba072018-04-20 13:01:53 -07002405void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302406{
2407 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002408 size_t target_hw_name_len;
2409 const char *target_hw_name;
Ryan Hsuaadba072018-04-20 13:01:53 -07002410 uint8_t *buf;
2411 uint32_t buf_len;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302412
2413 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2414 if (!hif_sc) {
2415 hdd_err("HIF context is NULL");
2416 return;
2417 }
2418
Ryan Hsuaadba072018-04-20 13:01:53 -07002419 hif_get_hw_info(hif_sc, &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302420 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002421 &target_hw_name);
2422
2423 if (hdd_ctx->target_hw_name)
2424 qdf_mem_free(hdd_ctx->target_hw_name);
2425
2426 target_hw_name_len = strlen(target_hw_name) + 1;
2427 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2428 if (hdd_ctx->target_hw_name)
2429 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2430 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302431
Ryan Hsuaadba072018-04-20 13:01:53 -07002432 buf = qdf_mem_malloc(WE_MAX_STR_LEN);
2433 if (buf) {
2434 buf_len = hdd_wlan_get_version(hdd_ctx, WE_MAX_STR_LEN, buf);
2435 hdd_info("%s", buf);
2436 qdf_mem_free(buf);
2437 }
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302438}
2439
2440/**
gbian62edd7e2017-03-07 13:12:13 +08002441 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2442 * @hdd_ctx: Pointer to hdd context
2443 *
2444 * Return: none
2445 */
2446static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002447hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002448{
2449 uint8_t num_entries = 0;
2450 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2451 uint8_t *tx_sched_wrr_ac;
2452 int i;
Jeff Johnson2b6982c2018-05-29 14:56:11 -07002453 struct cds_context *cds_ctx;
gbian62edd7e2017-03-07 13:12:13 +08002454
2455 if (NULL == hdd_ctx)
2456 return;
2457
2458 if (NULL == hdd_ctx->config) {
2459 /* Do nothing if hdd_ctx is invalid */
2460 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2461 return;
2462 }
2463
2464 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2465
2466 if (!cds_ctx) {
2467 hdd_err("Invalid CDS Context");
2468 return;
2469 }
2470
2471 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2472 switch (i) {
2473 case OL_TX_WMM_AC_BE:
2474 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2475 break;
2476 case OL_TX_WMM_AC_BK:
2477 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2478 break;
2479 case OL_TX_WMM_AC_VI:
2480 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2481 break;
2482 case OL_TX_WMM_AC_VO:
2483 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2484 break;
2485 default:
2486 tx_sched_wrr_ac = NULL;
2487 break;
2488 }
2489
2490 hdd_string_to_u8_array(tx_sched_wrr_ac,
2491 tx_sched_wrr_param,
2492 &num_entries,
2493 sizeof(tx_sched_wrr_param));
2494
2495 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2496 cds_ctx->ac_specs[i].wrr_skip_weight =
2497 tx_sched_wrr_param[0];
2498 cds_ctx->ac_specs[i].credit_threshold =
2499 tx_sched_wrr_param[1];
2500 cds_ctx->ac_specs[i].send_limit =
2501 tx_sched_wrr_param[2];
2502 cds_ctx->ac_specs[i].credit_reserve =
2503 tx_sched_wrr_param[3];
2504 cds_ctx->ac_specs[i].discard_weight =
2505 tx_sched_wrr_param[4];
2506 }
2507
2508 num_entries = 0;
2509 }
2510}
2511
Ryan Hsuaadba072018-04-20 13:01:53 -07002512uint32_t hdd_wlan_get_version(struct hdd_context *hdd_ctx,
2513 const size_t version_len, uint8_t *version)
2514{
2515 uint32_t size;
2516 uint32_t msp_id = 0, mspid = 0, siid = 0, crmid = 0, sub_id = 0;
2517
2518 if (!hdd_ctx) {
2519 hdd_err("Invalid context, HDD context is null");
2520 return 0;
2521 }
2522
Ashish Kumar Dhanotiya7353f882018-05-15 12:50:19 +05302523 if (!version || version_len == 0) {
Ryan Hsuaadba072018-04-20 13:01:53 -07002524 hdd_err("Invalid buffer pointr or buffer len\n");
2525 return 0;
2526 }
2527
2528 msp_id = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
2529 mspid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
2530 siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
2531 crmid = hdd_ctx->target_fw_version & 0x7fff;
2532 sub_id = (hdd_ctx->target_fw_vers_ext & 0xf0000000) >> 28;
2533
2534 size = scnprintf(version, version_len,
Ryan Hsuc6918552018-05-16 13:29:59 -07002535 "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 -07002536 QWLAN_VERSIONSTR,
2537 msp_id, mspid, siid, crmid, sub_id,
Ryan Hsuc6918552018-05-16 13:29:59 -07002538 hdd_ctx->target_hw_name,
2539 hdd_ctx->hw_bd_info.bdf_version,
2540 hdd_ctx->hw_bd_info.ref_design_id,
2541 hdd_ctx->hw_bd_info.customer_id,
2542 hdd_ctx->hw_bd_info.project_id,
2543 hdd_ctx->hw_bd_info.board_data_rev);
Ryan Hsuaadba072018-04-20 13:01:53 -07002544
2545 return size;
2546}
2547
Rachit Kankane0dc3e852018-05-07 17:33:42 +05302548int hdd_set_11ax_rate(struct hdd_adapter *adapter, int set_value,
2549 struct sap_config *sap_config)
2550{
2551 uint8_t preamble = 0, nss = 0, rix = 0;
2552 int ret;
2553 mac_handle_t mac_handle = adapter->hdd_ctx->mac_handle;
2554
2555 if (!sap_config) {
2556 if (!sme_is_feature_supported_by_fw(DOT11AX)) {
2557 hdd_err("Target does not support 11ax");
2558 return -EIO;
2559 }
2560 } else if (sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax &&
2561 sap_config->SapHw_mode != eCSR_DOT11_MODE_11ax_ONLY) {
2562 hdd_err("Invalid hw mode, SAP hw_mode= 0x%x, ch = %d",
2563 sap_config->SapHw_mode, sap_config->channel);
2564 return -EIO;
2565 }
2566
2567 if (set_value != 0xff) {
2568 rix = RC_2_RATE_IDX_11AX(set_value);
2569 preamble = WMI_RATE_PREAMBLE_HE;
2570 nss = HT_RC_2_STREAMS_11AX(set_value);
2571
2572 set_value = hdd_assemble_rate_code(preamble, nss, rix);
2573 } else {
2574 ret = sme_set_auto_rate_he_ltf(mac_handle, adapter->session_id,
2575 QCA_WLAN_HE_LTF_AUTO);
2576 }
2577
2578 hdd_info("SET_11AX_RATE val %d rix %d preamble %x nss %d",
2579 set_value, rix, preamble, nss);
2580
2581 ret = wma_cli_set_command(adapter->session_id,
2582 WMI_VDEV_PARAM_FIXED_RATE,
2583 set_value, VDEV_CMD);
2584
2585 return ret;
2586}
2587
2588int hdd_assemble_rate_code(uint8_t preamble, uint8_t nss, uint8_t rate)
2589{
2590 int set_value;
2591
2592 if (sme_is_feature_supported_by_fw(DOT11AX))
2593 set_value = WMI_ASSEMBLE_RATECODE_V1(rate, nss, preamble);
2594 else
2595 set_value = (preamble << 6) | (nss << 4) | rate;
2596
2597 return set_value;
2598}
2599
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302600#ifdef IPA_OFFLOAD
2601/**
2602 * hdd_update_ipa_component_config() - update ipa config
2603 * @hdd_ctx: Pointer to hdd context
2604 *
2605 * Return: none
2606 */
2607static void hdd_update_ipa_component_config(struct hdd_context *hdd_ctx)
2608{
2609 struct hdd_config *cfg = hdd_ctx->config;
2610 struct wlan_ipa_config ipa_cfg;
2611
2612 ipa_cfg.ipa_config = cfg->IpaConfig;
2613 ipa_cfg.desc_size = cfg->IpaDescSize;
2614 ipa_cfg.txbuf_count = cfg->IpaUcTxBufCount;
2615 ipa_cfg.bus_bw_high = cfg->busBandwidthHighThreshold;
2616 ipa_cfg.bus_bw_medium = cfg->busBandwidthMediumThreshold;
2617 ipa_cfg.bus_bw_low = cfg->busBandwidthLowThreshold;
2618 ipa_cfg.ipa_bw_high = cfg->IpaHighBandwidthMbps;
2619 ipa_cfg.ipa_bw_medium = cfg->IpaMediumBandwidthMbps;
2620 ipa_cfg.ipa_bw_low = cfg->IpaLowBandwidthMbps;
2621
2622 ucfg_ipa_update_config(&ipa_cfg);
2623}
2624#else
2625static void hdd_update_ipa_component_config(struct hdd_context *hdd_ctx)
2626{
2627}
2628#endif
2629
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002630#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002631static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2632 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2633{
Jeff Johnson9d295242017-08-29 14:39:48 -07002634 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002635 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002636
2637 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2638 if (!adapter) {
2639 hdd_err("Adapter is NULL");
2640 return PM_MAX_NUM_OF_MODE;
2641 }
2642
2643 return policy_mgr_convert_device_mode_to_qdf_type(
2644 adapter->device_mode);
2645}
2646
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002647static void hdd_register_policy_manager_callback(
2648 struct wlan_objmgr_psoc *psoc)
2649{
2650 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002651
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002652 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002653 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002654 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2655 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002656 hdd_cbacks.get_mode_for_non_connected_vdev =
2657 wlan_hdd_get_mode_for_non_connected_vdev;
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05302658 hdd_cbacks.hdd_get_device_mode = hdd_get_device_mode;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002659
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002660 if (QDF_STATUS_SUCCESS !=
2661 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2662 hdd_err("HDD callback registration with policy manager failed");
2663 }
2664}
2665#else
2666static void hdd_register_policy_manager_callback(
2667 struct wlan_objmgr_psoc *psoc)
2668{
2669}
2670#endif
2671
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002672static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002673{
2674 struct nan_callbacks cb_obj = {0};
2675
2676 cb_obj.ndi_open = hdd_ndi_open;
2677 cb_obj.ndi_close = hdd_ndi_close;
2678 cb_obj.ndi_start = hdd_ndi_start;
2679 cb_obj.ndi_delete = hdd_ndi_delete;
2680 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2681 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2682
Naveen Rawat37f62c82017-03-26 22:24:43 -07002683 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2684 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002685 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002686
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002687 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2688}
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002689
Dustin Brown26b3d042017-12-21 11:13:27 -08002690#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002691/**
2692 * hdd_check_for_leaks() - Perform runtime memory leak checks
Dustin Browna6246dd2018-05-24 14:35:58 -07002693 * @hdd_ctx: the global HDD context
Dustin Brown4c5b9902017-12-19 11:17:19 -08002694 *
2695 * This API triggers runtime memory leak detection. This feature enforces the
2696 * policy that any memory allocated at runtime must also be released at runtime.
2697 *
2698 * Allocating memory at runtime and releasing it at unload is effectively a
2699 * memory leak for configurations which never unload (e.g. LONU, statically
2700 * compiled driver). Such memory leaks are NOT false positives, and must be
2701 * fixed.
2702 *
2703 * Return: None
2704 */
Dustin Browna6246dd2018-05-24 14:35:58 -07002705static void hdd_check_for_leaks(struct hdd_context *hdd_ctx)
Dustin Brown4bc0a622017-12-06 15:56:50 -08002706{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002707 /* DO NOT REMOVE these checks; for false positives, read above first */
2708
Dustin Browna6246dd2018-05-24 14:35:58 -07002709 wlan_objmgr_psoc_check_for_vdev_leaks(hdd_ctx->hdd_psoc);
Dustin Brown29462962018-06-18 14:02:00 -07002710 wlan_objmgr_psoc_check_for_pdev_leaks(hdd_ctx->hdd_psoc);
Dustin Brown677e0862017-10-10 16:30:09 -07002711 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002712 qdf_nbuf_map_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002713 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002714}
2715
Dustin Brown26b3d042017-12-21 11:13:27 -08002716#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2717#else
Dustin Browna6246dd2018-05-24 14:35:58 -07002718static inline void hdd_check_for_leaks(struct hdd_context *hdd_ctx) { }
Dustin Brown26b3d042017-12-21 11:13:27 -08002719
2720#define hdd_debug_domain_set(domain)
2721#endif /* CONFIG_LEAK_DETECTION */
2722
gbian62edd7e2017-03-07 13:12:13 +08002723/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002724 * hdd_update_country_code - Update country code
2725 * @hdd_ctx: HDD context
2726 *
2727 * Update country code based on module parameter country_code
2728 *
2729 * Return: 0 on success and errno on failure
2730 */
2731static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2732{
2733 if (!country_code)
2734 return 0;
2735
2736 return hdd_reg_set_country(hdd_ctx, country_code);
2737}
2738
2739/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302740 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2741 * @hdd_ctx: HDD context
Arun Khandavallifae92942016-08-01 13:31:08 +05302742 * @reinit: flag to indicate from SSR or normal path
2743 *
2744 * This function maintains the driver state machine it will be invoked from
2745 * startup, reinit and change interface. Depending on the driver state shall
2746 * perform the opening of the modules.
2747 *
2748 * Return: 0 for success; non-zero for failure
2749 */
Dustin Browne7e71d32018-05-11 16:00:08 -07002750int hdd_wlan_start_modules(struct hdd_context *hdd_ctx, bool reinit)
Arun Khandavallifae92942016-08-01 13:31:08 +05302751{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002752 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302753 qdf_device_t qdf_dev;
2754 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302755 bool unint = false;
2756 void *hif_ctx;
Jingxiang Ge95912f82018-04-19 12:01:26 +08002757 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +05302758
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002759 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302760
2761 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2762 if (!qdf_dev) {
2763 hdd_err("QDF Device Context is Invalid return");
2764 return -EINVAL;
2765 }
2766
Dustin Brown6f427922017-09-19 12:19:00 -07002767 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05302768
Dustin Brown1fe30a82017-10-03 16:13:36 -07002769 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302770 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2771 mutex_unlock(&hdd_ctx->iface_change_lock);
2772 hdd_info("Driver modules already Enabled");
Dustin Browne74003f2018-03-14 12:51:58 -07002773 hdd_exit();
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302774 return 0;
2775 }
2776
Dustin Brown1fe30a82017-10-03 16:13:36 -07002777 hdd_ctx->start_modules_in_progress = true;
2778
Arun Khandavallifae92942016-08-01 13:31:08 +05302779 switch (hdd_ctx->driver_status) {
2780 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002781 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302782 unint = true;
2783 /* Fall through dont add break here */
2784 case DRIVER_MODULES_CLOSED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002785 hdd_info("Wlan transitioning (CLOSED -> OPENED)");
2786
Dustin Brown26b3d042017-12-21 11:13:27 -08002787 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002788
Arun Khandavallifae92942016-08-01 13:31:08 +05302789 if (!reinit && !unint) {
2790 ret = pld_power_on(qdf_dev->dev);
2791 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002792 hdd_err("Failed to Powerup the device; errno: %d",
2793 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302794 goto release_lock;
2795 }
2796 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002797
2798 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2799 hdd_ctx->config->enable_fw_log);
Arun Khandavallifae92942016-08-01 13:31:08 +05302800 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2801 qdf_dev->bus_type,
2802 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2803 HIF_ENABLE_TYPE_PROBE);
2804 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002805 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302806 goto power_down;
2807 }
2808
2809 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302810 if (!hif_ctx) {
2811 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002812 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302813 goto power_down;
2814 }
2815
Arun Khandavallifae92942016-08-01 13:31:08 +05302816 status = ol_cds_init(qdf_dev, hif_ctx);
2817 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002818 hdd_err("No Memory to Create BMI Context; status: %d",
2819 status);
2820 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302821 goto hif_close;
2822 }
2823
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302824 hdd_update_ipa_component_config(hdd_ctx);
2825
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002826 ret = hdd_update_config(hdd_ctx);
2827 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002828 hdd_err("Failed to update configuration; errno: %d",
2829 ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002830 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002831 }
2832
gbian62edd7e2017-03-07 13:12:13 +08002833 hdd_update_cds_ac_specs_params(hdd_ctx);
2834
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302835 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002836 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002837 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002838 ret = qdf_status_to_os_return(status);
2839 goto deinit_config;
Arun Khandavallifae92942016-08-01 13:31:08 +05302840 }
2841
Manjunathappa Prakashb6b4ff12018-06-04 12:32:33 -07002842 if (hdd_ctx->config->rx_thread_affinity_mask)
2843 cds_set_rx_thread_cpu_mask(
2844 hdd_ctx->config->rx_thread_affinity_mask);
2845
2846 /* initialize components configurations after psoc open */
Mukul Sharma9d797a02017-01-05 20:26:03 +05302847 ret = hdd_update_components_config(hdd_ctx);
2848 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002849 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302850 ret);
2851 goto close;
2852 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002853 status = cds_dp_open(hdd_ctx->hdd_psoc);
2854 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002855 hdd_err("Failed to Open cds post open; status: %d",
2856 status);
2857 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002858 goto close;
2859 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302860
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002861 /*
2862 * NAN compoenet requires certian operations like, open adapter,
2863 * close adapter, etc. to be initiated by HDD, for those
2864 * register HDD callbacks with UMAC's NAN componenet.
2865 */
2866 hdd_nan_register_callbacks(hdd_ctx);
2867
Jeff Johnson16528362018-06-14 12:34:16 -07002868 hdd_ctx->mac_handle = cds_get_context(QDF_MODULE_ID_SME);
Arun Khandavallifae92942016-08-01 13:31:08 +05302869
Jeff Johnson3a280122017-09-13 07:42:00 -07002870 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302871 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002872 hdd_err("Failed to pre-enable CDS; status: %d", status);
2873 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002874 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302875 }
2876
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002877 hdd_register_policy_manager_callback(
2878 hdd_ctx->hdd_psoc);
2879
Amar Singhal0928b192017-12-01 10:50:54 -08002880 hdd_sysfs_create_version_interface(hdd_ctx->hdd_psoc);
2881
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302882 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302883 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002884 hdd_info("Wlan transitioned (now OPENED)");
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302885
Arun Khandavallifae92942016-08-01 13:31:08 +05302886 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002887 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302888 break;
2889 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302890
Arun Khandavallifae92942016-08-01 13:31:08 +05302891 /* Fall through dont add break here */
2892 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002893 hdd_info("Wlan transitioning (OPENED -> ENABLED)");
2894
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302895 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2896 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002897 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302898 break;
2899 }
Dustin Browndca39692017-11-09 15:30:25 -08002900
Dustin Browne7e71d32018-05-11 16:00:08 -07002901 ret = hdd_configure_cds(hdd_ctx);
Dustin Browndca39692017-11-09 15:30:25 -08002902 if (ret) {
2903 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002904 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302905 }
Dustin Browndca39692017-11-09 15:30:25 -08002906
Komal Seelamf2136bb2016-09-28 18:30:44 +05302907 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002908
Arun Khandavallifae92942016-08-01 13:31:08 +05302909 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002910 hdd_info("Wlan transitioned (now ENABLED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302911 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002912
Arun Khandavallifae92942016-08-01 13:31:08 +05302913 default:
2914 hdd_err("WLAN start invoked in wrong state! :%d\n",
2915 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002916 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302917 goto release_lock;
2918 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002919
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302920 hdd_ctx->start_modules_in_progress = false;
Paul Zhange03cf4c2018-01-19 18:33:22 +08002921 if (DRIVER_MODULES_ENABLED == hdd_ctx->driver_status) {
2922 ret = hdd_update_country_code(hdd_ctx);
2923 if (ret)
2924 hdd_err("Failed to update command line country code!");
2925 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302926 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002927
Dustin Browne74003f2018-03-14 12:51:58 -07002928 hdd_exit();
Dustin Brown550f6d22017-12-14 15:44:01 -08002929
Arun Khandavallifae92942016-08-01 13:31:08 +05302930 return 0;
2931
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002932post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002933 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002934
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002935cds_txrx_free:
Jingxiang Ge95912f82018-04-19 12:01:26 +08002936 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
2937
2938 if (tgt_hdl && target_psoc_get_wmi_ready(tgt_hdl)) {
2939 hdd_runtime_suspend_context_deinit(hdd_ctx);
2940 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
2941 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
2942 }
2943
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002944 cds_dp_close(hdd_ctx->hdd_psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08002945
Arun Khandavallifae92942016-08-01 13:31:08 +05302946close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002947 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002948 hdd_info("Wlan transition aborted (now CLOSED)");
2949
Jeff Johnsone4b14592017-09-13 14:23:33 -07002950 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302951
Dustin Brown28b17892017-10-10 13:29:38 -07002952deinit_config:
2953 cds_deinit_ini_config();
2954
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002955cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302956 ol_cds_free();
2957
2958hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002959 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2960 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302961power_down:
2962 if (!reinit && !unint)
2963 pld_power_off(qdf_dev->dev);
2964release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302965 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302966 mutex_unlock(&hdd_ctx->iface_change_lock);
Abhinav Kumar7ae9b7b2017-12-19 15:11:54 +05302967 if (hdd_ctx->target_hw_name) {
2968 qdf_mem_free(hdd_ctx->target_hw_name);
2969 hdd_ctx->target_hw_name = NULL;
2970 }
Dustin Brown4bc0a622017-12-06 15:56:50 -08002971 /* many adapter resources are not freed by design in SSR case */
2972 if (!reinit)
Dustin Browna6246dd2018-05-24 14:35:58 -07002973 hdd_check_for_leaks(hdd_ctx);
Dustin Brown26b3d042017-12-21 11:13:27 -08002974 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002975
Dustin Browne74003f2018-03-14 12:51:58 -07002976 hdd_exit();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002977
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002978 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302979}
2980
Naveen Rawat910726a2017-03-06 11:42:51 -08002981#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002982static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002983{
2984 int ret = os_if_wifi_pos_register_nl();
2985
2986 if (ret)
2987 hdd_err("os_if_wifi_pos_register_nl failed");
2988
2989 return ret;
2990}
2991
2992static int hdd_deactivate_wifi_pos(void)
2993{
2994 int ret = os_if_wifi_pos_deregister_nl();
2995
2996 if (ret)
2997 hdd_err("os_if_wifi_pos_deregister_nl failed");
2998
2999 return ret;
3000}
3001
3002/**
3003 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
3004 * @hdd_ctx: hdd context
3005 *
3006 * Return: status of operation
3007 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003008static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003009{
3010 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3011 struct hdd_config *cfg = hdd_ctx->config;
3012
3013 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
3014 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
3015 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
3016 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
3017 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
3018 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
3019 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
3020 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
3021}
3022#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003023static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003024{
3025 return oem_activate_service(hdd_ctx);
3026}
3027
3028static int hdd_deactivate_wifi_pos(void)
3029{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05303030 return oem_deactivate_service();
Naveen Rawat910726a2017-03-06 11:42:51 -08003031}
3032
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003033static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08003034{
3035}
3036#endif
3037
Arun Khandavallifae92942016-08-01 13:31:08 +05303038/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003039 * __hdd_open() - HDD Open function
3040 * @dev: Pointer to net_device structure
3041 *
3042 * This is called in response to ifconfig up
3043 *
3044 * Return: 0 for success; non-zero for failure
3045 */
3046static int __hdd_open(struct net_device *dev)
3047{
Jeff Johnson9d295242017-08-29 14:39:48 -07003048 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003049 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003050 int ret;
3051
Dustin Brownfdf17c12018-03-14 12:55:34 -07003052 hdd_enter_dev(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303053 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003054 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003055
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05303056 /* Nothing to be done if device is unloading */
3057 if (cds_is_driver_unloading()) {
3058 hdd_err("Driver is unloading can not open the hdd");
3059 return -EBUSY;
3060 }
3061
Dustin Brown01847752017-10-25 13:56:27 -07003062 if (cds_is_driver_recovering()) {
3063 hdd_err("WLAN is currently recovering; Please try again.");
3064 return -EBUSY;
3065 }
3066
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05303067 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
3068 hdd_err("con_mode_handler is in progress; Please try again.");
3069 return -EBUSY;
3070 }
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303071
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05303072 mutex_lock(&hdd_init_deinit_lock);
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05303073 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
3074
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303075 /*
3076 * This scenario can be hit in cases where in the wlan driver after
3077 * registering the netdevices and there is a failure in driver
3078 * initialization. So return error gracefully because the netdevices
3079 * will be de-registered as part of the load failure.
3080 */
3081
3082 if (!cds_is_driver_loaded()) {
3083 hdd_err("Failed to start the wlan driver!!");
3084 ret = -EIO;
3085 goto err_hdd_hdd_init_deinit_lock;
3086 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05303087
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003088
Dustin Browne7e71d32018-05-11 16:00:08 -07003089 ret = hdd_wlan_start_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +05303090 if (ret) {
3091 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303092 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05303093 }
3094
3095
3096 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
3097 ret = hdd_start_adapter(adapter);
3098 if (ret) {
3099 hdd_err("Failed to start adapter :%d",
3100 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303101 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05303102 }
3103 }
3104
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003105 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
3106 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003107 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003108 /* Enable TX queues only when we are connected */
3109 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05303110 WLAN_START_ALL_NETIF_QUEUE,
3111 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003112 }
3113
Naveen Rawat286def52016-09-23 15:38:02 -07003114 /* Enable carrier and transmit queues for NDI */
3115 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07003116 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07003117 wlan_hdd_netif_queue_control(adapter,
3118 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
3119 WLAN_CONTROL_PATH);
3120 }
3121
Naveen Rawat910726a2017-03-06 11:42:51 -08003122 hdd_populate_wifi_pos_cfg(hdd_ctx);
3123
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303124err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05303125 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05303126 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003127 return ret;
3128}
3129
Arun Khandavallifae92942016-08-01 13:31:08 +05303130
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003131/**
3132 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
3133 * @dev: Pointer to net_device structure
3134 *
3135 * This is called in response to ifconfig up
3136 *
3137 * Return: 0 for success; non-zero for failure
3138 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003139static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003140{
3141 int ret;
3142
3143 cds_ssr_protect(__func__);
3144 ret = __hdd_open(dev);
3145 cds_ssr_unprotect(__func__);
3146
3147 return ret;
3148}
3149
3150/**
3151 * __hdd_stop() - HDD stop function
3152 * @dev: Pointer to net_device structure
3153 *
3154 * This is called in response to ifconfig down
3155 *
3156 * Return: 0 for success; non-zero for failure
3157 */
3158static int __hdd_stop(struct net_device *dev)
3159{
Jeff Johnson9d295242017-08-29 14:39:48 -07003160 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003161 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003162 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -07003163 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003164
Dustin Brownfdf17c12018-03-14 12:55:34 -07003165 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003166
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303167 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003168 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003169
3170 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303171 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003172 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003173
3174 /* Nothing to be done if the interface is not opened */
3175 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003176 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003177 return -ENODEV;
3178 }
3179
3180 /* Make sure the interface is marked as closed */
3181 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303182
Jeff Johnson16528362018-06-14 12:34:16 -07003183 mac_handle = hdd_ctx->mac_handle;
3184
Mukul Sharmad16c2022017-07-25 18:56:12 +05303185 hdd_debug("Disabling Auto Power save timer");
3186 sme_ps_disable_auto_ps_timer(
Jeff Johnson16528362018-06-14 12:34:16 -07003187 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003188 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303189
3190 /*
3191 * Disable TX on the interface, after this hard_start_xmit() will not
3192 * be called on that interface
3193 */
Dustin Brown5e89ef82018-03-14 11:50:23 -07003194 hdd_info("Disabling queues, adapter device mode: %s(%d)",
Kabilan Kannan8dac3502017-10-30 12:40:27 -07003195 hdd_device_mode_to_string(adapter->device_mode),
3196 adapter->device_mode);
3197
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303198 wlan_hdd_netif_queue_control(adapter,
3199 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3200 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003201
3202 /*
Naveen Rawat286def52016-09-23 15:38:02 -07003203 * NAN data interface is different in some sense. The traffic on NDI is
3204 * bursty in nature and depends on the need to transfer. The service
3205 * layer may down the interface after the usage and up again when
3206 * required. In some sense, the NDI is expected to be available
3207 * (like SAP) iface until NDI delete request is issued by the service
3208 * layer. Skip BSS termination and adapter deletion for NAN Data
3209 * interface (NDI).
3210 */
3211 if (WLAN_HDD_IS_NDI(adapter))
3212 return 0;
3213
3214 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003215 * The interface is marked as down for outside world (aka kernel)
3216 * But the driver is pretty much alive inside. The driver needs to
3217 * tear down the existing connection on the netdev (session)
3218 * cleanup the data pipes and wait until the control plane is stabilized
3219 * for this interface. The call also needs to wait until the above
3220 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003221 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003222 * That is intentional to be able to scan if it is a STA/P2P interface
3223 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08003224 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003225
3226 /* DeInit the adapter. This ensures datapath cleanup as well */
3227 hdd_deinit_adapter(hdd_ctx, adapter, true);
3228
Arun Khandavallifae92942016-08-01 13:31:08 +05303229
3230 /*
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +05303231 * Upon wifi turn off, DUT has to flush the scan results so if
3232 * this is the last cli iface, flush the scan database.
3233 */
3234 if (!hdd_is_cli_iface_up(hdd_ctx))
Jeff Johnson16528362018-06-14 12:34:16 -07003235 sme_scan_flush_result(mac_handle);
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +05303236
3237 /*
Arun Khandavallifae92942016-08-01 13:31:08 +05303238 * Find if any iface is up. If any iface is up then can't put device to
3239 * sleep/power save mode
3240 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05303241 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003242 hdd_debug("Closing all modules from the hdd_stop");
Dustin Brown6f427922017-09-19 12:19:00 -07003243 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
3244 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05303245 hdd_prevent_suspend_timeout(
3246 hdd_ctx->config->iface_change_wait_time,
3247 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05303248 }
3249
Dustin Browne74003f2018-03-14 12:51:58 -07003250 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003251 return 0;
3252}
3253
3254/**
3255 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3256 * @dev: pointer to net_device structure
3257 *
3258 * This is called in response to ifconfig down
3259 *
3260 * Return: 0 for success and error number for failure
3261 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003262static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003263{
3264 int ret;
3265
3266 cds_ssr_protect(__func__);
3267 ret = __hdd_stop(dev);
3268 cds_ssr_unprotect(__func__);
3269
3270 return ret;
3271}
3272
3273/**
3274 * __hdd_uninit() - HDD uninit function
3275 * @dev: Pointer to net_device structure
3276 *
3277 * This is called during the netdev unregister to uninitialize all data
3278 * associated with the device
3279 *
3280 * Return: None
3281 */
3282static void __hdd_uninit(struct net_device *dev)
3283{
Jeff Johnson9d295242017-08-29 14:39:48 -07003284 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003285 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003286
Dustin Brownfdf17c12018-03-14 12:55:34 -07003287 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003288
3289 do {
3290 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003291 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003292 break;
3293 }
3294
Jeff Johnson399c6272017-08-30 10:51:00 -07003295 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3296 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003297 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003298 break;
3299 }
3300
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003301 if (dev != adapter->dev)
3302 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003303
Jeff Johnson399c6272017-08-30 10:51:00 -07003304 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003305
3306 /* after uninit our adapter structure will no longer be valid */
3307 adapter->dev = NULL;
3308 adapter->magic = 0;
3309 } while (0);
3310
Dustin Browne74003f2018-03-14 12:51:58 -07003311 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003312}
3313
3314/**
3315 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
3316 * @dev: pointer to net_device structure
3317 *
3318 * This is called during the netdev unregister to uninitialize all data
3319 * associated with the device
3320 *
3321 * Return: none
3322 */
3323static void hdd_uninit(struct net_device *dev)
3324{
3325 cds_ssr_protect(__func__);
3326 __hdd_uninit(dev);
3327 cds_ssr_unprotect(__func__);
3328}
3329
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003330static int hdd_open_cesium_nl_sock(void)
3331{
3332#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3333 struct netlink_kernel_cfg cfg = {
3334 .groups = WLAN_NLINK_MCAST_GRP_ID,
3335 .input = NULL
3336 };
3337#endif
3338 int ret = 0;
3339
3340#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3341 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3342#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3343 THIS_MODULE,
3344#endif
3345 &cfg);
3346#else
3347 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3348 WLAN_NLINK_MCAST_GRP_ID,
3349 NULL, NULL, THIS_MODULE);
3350#endif
3351
3352 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003353 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003354 ret = -ECONNREFUSED;
3355 }
3356
3357 return ret;
3358}
3359
3360static void hdd_close_cesium_nl_sock(void)
3361{
3362 if (NULL != cesium_nl_srv_sock) {
3363 netlink_kernel_release(cesium_nl_srv_sock);
3364 cesium_nl_srv_sock = NULL;
3365 }
3366}
3367
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003368/**
3369 * __hdd_set_mac_address() - set the user specified mac address
3370 * @dev: Pointer to the net device.
3371 * @addr: Pointer to the sockaddr.
3372 *
3373 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003374 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003375 *
3376 * Return: 0 for success, non zero for failure
3377 */
3378static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3379{
Jeff Johnson9d295242017-08-29 14:39:48 -07003380 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303381 struct hdd_adapter *adapter_temp;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003382 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003383 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303384 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003385 int ret;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303386 struct qdf_mac_addr mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003387
Dustin Brownfdf17c12018-03-14 12:55:34 -07003388 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003389
Hanumanth Reddy Pothula5c7a7812018-03-09 12:55:32 +05303390 if (netif_running(dev)) {
3391 hdd_err("On iface up, set mac address change isn't supported");
3392 return -EBUSY;
3393 }
3394
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003395 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3396 ret = wlan_hdd_validate_context(hdd_ctx);
3397 if (0 != ret)
3398 return ret;
3399
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303400 qdf_mem_copy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
Ashish Kumar Dhanotiyae533f6c2018-06-19 21:16:07 +05303401 adapter_temp = hdd_get_adapter_by_macaddr(hdd_ctx, mac_addr.bytes);
3402 if (adapter_temp) {
3403 if (!qdf_str_cmp(adapter_temp->dev->name, dev->name))
3404 return 0;
3405 hdd_err("%s adapter exist with same address " MAC_ADDRESS_STR,
3406 adapter_temp->dev->name,
Ashish Kumar Dhanotiyaf974f332018-04-19 16:03:15 +05303407 MAC_ADDR_ARRAY(mac_addr.bytes));
3408 return -EINVAL;
3409 }
3410
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303411 if (qdf_is_macaddr_zero(&mac_addr)) {
3412 hdd_err("MAC is all zero");
3413 return -EINVAL;
3414 }
3415
3416 if (qdf_is_macaddr_broadcast(&mac_addr)) {
3417 hdd_err("MAC is Broadcast");
3418 return -EINVAL;
3419 }
3420
3421 if (ETHER_IS_MULTICAST(psta_mac_addr->sa_data)) {
3422 hdd_err("MAC is Multicast");
3423 return -EINVAL;
3424 }
Ashish Kumar Dhanotiya8bfef122018-04-18 16:48:27 +05303425 hdd_info("Changing MAC to " MAC_ADDRESS_STR " of the interface %s ",
3426 MAC_ADDR_ARRAY(mac_addr.bytes), dev->name);
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303427
Jeff Johnson1e851a12017-10-28 14:36:12 -07003428 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003429 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3430
Dustin Browne74003f2018-03-14 12:51:58 -07003431 hdd_exit();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303432 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003433}
3434
3435/**
3436 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3437 * function from SSR
3438 * @dev: pointer to net_device structure
3439 * @addr: Pointer to the sockaddr
3440 *
3441 * This function sets the user specified mac address using
Jeff Johnson06095fb2018-05-06 16:16:42 -07003442 * the command ifconfig wlanX hw ether <mac address>.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003443 *
3444 * Return: 0 for success.
3445 */
3446static int hdd_set_mac_address(struct net_device *dev, void *addr)
3447{
3448 int ret;
3449
3450 cds_ssr_protect(__func__);
3451 ret = __hdd_set_mac_address(dev, addr);
3452 cds_ssr_unprotect(__func__);
3453
3454 return ret;
3455}
3456
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003457uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003458{
3459 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003460
Anurag Chouhan6d760662016-02-20 16:05:43 +05303461 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003462 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
3463 break;
3464 }
3465
Anurag Chouhan6d760662016-02-20 16:05:43 +05303466 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003467 return NULL;
3468
3469 hdd_ctx->config->intfAddrMask |= (1 << i);
3470 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
3471}
3472
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003473void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3474 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003475{
3476 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003477
Anurag Chouhan6d760662016-02-20 16:05:43 +05303478 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003479 if (!memcmp(releaseAddr,
3480 &hdd_ctx->config->intfMacAddr[i].bytes[0],
3481 6)) {
3482 hdd_ctx->config->intfAddrMask &= ~(1 << i);
3483 break;
3484 }
3485 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003486}
3487
3488#ifdef WLAN_FEATURE_PACKET_FILTERING
3489/**
3490 * __hdd_set_multicast_list() - set the multicast address list
3491 * @dev: Pointer to the WLAN device.
3492 * @skb: Pointer to OS packet (sk_buff).
3493 *
3494 * This funciton sets the multicast address list.
3495 *
3496 * Return: None
3497 */
3498static void __hdd_set_multicast_list(struct net_device *dev)
3499{
Jeff Johnson9d295242017-08-29 14:39:48 -07003500 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Dustin Brown0f874482018-06-13 14:39:22 -07003501 int i = 0, errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003502 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003503 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303504 struct pmo_mc_addr_list_params *mc_list_request = NULL;
3505 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3506 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003507
Dustin Brownfdf17c12018-03-14 12:55:34 -07003508 hdd_enter_dev(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303509 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303510 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303511
Dustin Brown0f874482018-06-13 14:39:22 -07003512 errno = wlan_hdd_validate_context(hdd_ctx);
3513 if (errno)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303514 goto out;
3515
Dustin Brown0f874482018-06-13 14:39:22 -07003516 errno = hdd_validate_adapter(adapter);
3517 if (errno)
Dustin Brownc788acb2017-08-01 17:43:51 -07003518 goto out;
3519
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303520 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3521 hdd_err("%s: Driver module is closed", __func__);
Dustin Brown0f874482018-06-13 14:39:22 -07003522 goto out;
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303523 }
3524
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303525 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
3526 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003527 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303528 goto out;
3529 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003530
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303531 /* Delete already configured multicast address list */
3532 if (adapter->mc_addr_list.mc_cnt > 0) {
Dustin Brown0f874482018-06-13 14:39:22 -07003533 hdd_debug("clear previously configured MC address list");
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303534 hdd_disable_and_flush_mc_addr_list(adapter,
3535 pmo_mc_list_change_notify);
3536 }
3537
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003538 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003539 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303540 hdd_disable_and_flush_mc_addr_list(adapter,
3541 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003542 } else {
3543 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303544 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003545 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Dustin Brown0f874482018-06-13 14:39:22 -07003546 pmo_ucfg_max_mc_addr_supported(psoc));
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303547 hdd_disable_and_flush_mc_addr_list(adapter,
3548 pmo_mc_list_change_notify);
Dustin Brown0f874482018-06-13 14:39:22 -07003549 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003550 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003551 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003552 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303553 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003554 if (i == mc_count)
3555 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303556 memset(&(mc_list_request->mc_addr[i].bytes),
3557 0, ETH_ALEN);
3558 memcpy(&(mc_list_request->mc_addr[i].bytes),
3559 ha->addr, ETH_ALEN);
Dustin Brown0f874482018-06-13 14:39:22 -07003560 hdd_debug("mlist[%d] = %pM", i,
3561 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003562 i++;
3563 }
3564 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303565
3566 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003567 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303568 mc_list_request->count = mc_count;
Dustin Brown0f874482018-06-13 14:39:22 -07003569
3570 errno = hdd_cache_mc_addr_list(mc_list_request);
3571 if (errno) {
3572 hdd_err("Failed to cache MC address list for vdev %u; errno:%d",
3573 adapter->session_id, errno);
3574 goto free_req;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003575 }
Dustin Brown0f874482018-06-13 14:39:22 -07003576
3577 hdd_enable_mc_addr_filtering(adapter, pmo_mc_list_change_notify);
3578
3579free_req:
3580 qdf_mem_free(mc_list_request);
3581
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303582out:
Dustin Browne74003f2018-03-14 12:51:58 -07003583 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003584}
3585
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303586
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003587/**
3588 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3589 * @dev: pointer to net_device
3590 *
3591 * Return: none
3592 */
3593static void hdd_set_multicast_list(struct net_device *dev)
3594{
3595 cds_ssr_protect(__func__);
3596 __hdd_set_multicast_list(dev);
3597 cds_ssr_unprotect(__func__);
3598}
3599#endif
3600
3601/**
3602 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3603 * @dev: Pointer to the WLAN device.
3604 * @skb: Pointer to OS packet (sk_buff).
3605 *
3606 * This function is registered with the Linux OS for network
3607 * core to decide which queue to use first.
3608 *
3609 * Return: ac, Queue Index/access category corresponding to UP in IP header
3610 */
3611static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3612#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3613 , void *accel_priv
3614#endif
3615#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3616 , select_queue_fallback_t fallback
3617#endif
3618)
3619{
3620 return hdd_wmm_select_queue(dev, skb);
3621}
3622
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003623static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003624 .ndo_open = hdd_open,
3625 .ndo_stop = hdd_stop,
3626 .ndo_uninit = hdd_uninit,
3627 .ndo_start_xmit = hdd_hard_start_xmit,
3628 .ndo_tx_timeout = hdd_tx_timeout,
3629 .ndo_get_stats = hdd_get_stats,
3630 .ndo_do_ioctl = hdd_ioctl,
3631 .ndo_set_mac_address = hdd_set_mac_address,
3632 .ndo_select_queue = hdd_select_queue,
3633#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003634 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003635#endif
3636};
3637
Nirav Shah73713f72018-05-17 14:50:41 +05303638#ifdef FEATURE_MONITOR_MODE_SUPPORT
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003639/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003640static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003641 .ndo_open = hdd_mon_open,
3642 .ndo_stop = hdd_stop,
3643 .ndo_get_stats = hdd_get_stats,
3644};
3645
3646/**
3647 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003648 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003649 * Return: None
3650 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003651void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003652{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003653 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003654 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003655 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003656 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003657}
Nirav Shah73713f72018-05-17 14:50:41 +05303658#else
3659void hdd_set_station_ops(struct net_device *dev)
3660{
3661 dev->netdev_ops = &wlan_drv_ops;
3662}
3663#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003664
3665/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003666 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3667 * @hdd_ctx: global hdd context
3668 * @macAddr: mac address to assign to the interface
3669 * @name: User-visible name of the interface
3670 *
3671 * hdd adapter pointer would point to the netdev->priv space, this function
Jeff Johnson62018292018-05-06 16:18:35 -07003672 * would retrieve the pointer, and setup the hdd adapter configuration.
Ryan Hsu07495ea2016-01-21 15:25:39 -08003673 *
3674 * Return: the pointer to hdd adapter, otherwise NULL
3675 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003676static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003677 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003678 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003679 const char *name)
3680{
Jeff Johnson5505db82017-11-02 21:19:23 -07003681 struct net_device *dev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003682 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003683 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303684 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003685 /*
3686 * cfg80211 initialization and registration....
3687 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003688 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003689#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3690 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003691#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003692 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3693 hdd_mon_mode_ether_setup : ether_setup),
3694 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003695
Jeff Johnson5505db82017-11-02 21:19:23 -07003696 if (dev != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003697
3698 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson5505db82017-11-02 21:19:23 -07003699 adapter = (struct hdd_adapter *) netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003700
Jeff Johnson9d295242017-08-29 14:39:48 -07003701 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Jeff Johnsonb9424862017-10-30 08:49:35 -07003702 sta_ctx = &adapter->session.station;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303703 qdf_mem_set(sta_ctx->conn_info.staId,
3704 sizeof(sta_ctx->conn_info.staId),
3705 HDD_WLAN_INVALID_STA_ID);
Jeff Johnson5505db82017-11-02 21:19:23 -07003706 adapter->dev = dev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003707 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003708 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003709 adapter->session_id = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003710
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303711 qdf_status = qdf_event_create(
3712 &adapter->qdf_session_open_event);
3713 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3714 hdd_err("Session open QDF event init failed!");
3715 free_netdev(adapter->dev);
3716 return NULL;
3717 }
3718
3719 qdf_status = qdf_event_create(
3720 &adapter->qdf_session_close_event);
3721 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3722 hdd_err("Session close QDF event init failed!");
3723 free_netdev(adapter->dev);
3724 return NULL;
3725 }
3726
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003727 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303728 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003729 init_completion(&adapter->linkup_event_var);
3730 init_completion(&adapter->cancel_rem_on_chan_var);
3731 init_completion(&adapter->rem_on_chan_ready_event);
3732 init_completion(&adapter->sta_authorized_event);
3733 init_completion(&adapter->offchannel_tx_event);
3734 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003735 init_completion(&adapter->ibss_peer_info_comp);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303736 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003737
3738 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003739 adapter->is_link_up_service_needed = false;
Alok Kumarb64650c2018-03-23 17:05:11 +05303740 adapter->disconnection_in_progress = false;
Yeshwanth Sriram Guntuka4fe30bd2018-06-13 11:41:42 +05303741 adapter->send_mode_change = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003742 /* Init the net_device structure */
Jeff Johnson5505db82017-11-02 21:19:23 -07003743 strlcpy(dev->name, name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003744
Jeff Johnson5505db82017-11-02 21:19:23 -07003745 qdf_mem_copy(dev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003746 sizeof(tSirMacAddr));
Jeff Johnson1e851a12017-10-28 14:36:12 -07003747 qdf_mem_copy(adapter->mac_addr.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003748 sizeof(tSirMacAddr));
Jeff Johnson5505db82017-11-02 21:19:23 -07003749 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003750
3751 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
Jeff Johnson5505db82017-11-02 21:19:23 -07003752 dev->features |=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003753 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Jeff Johnson5505db82017-11-02 21:19:23 -07003754 dev->features |= NETIF_F_RXCSUM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003755
Jeff Johnson5505db82017-11-02 21:19:23 -07003756 hdd_set_tso_flags(hdd_ctx, dev);
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003757
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003758 hdd_set_station_ops(adapter->dev);
3759
Jeff Johnson5505db82017-11-02 21:19:23 -07003760 hdd_dev_setup_destructor(dev);
3761 dev->ieee80211_ptr = &adapter->wdev;
3762 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003763 adapter->wdev.wiphy = hdd_ctx->wiphy;
Jeff Johnson5505db82017-11-02 21:19:23 -07003764 adapter->wdev.netdev = dev;
3765 /* set dev's parent to underlying device */
3766 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003767 hdd_wmm_init(adapter);
3768 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303769 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003770 }
3771
3772 return adapter;
3773}
3774
Jeff Johnson9d295242017-08-29 14:39:48 -07003775static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003776{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003777 struct net_device *dev = adapter->dev;
3778 int ret;
3779
Dustin Brown491d54b2018-03-14 12:39:11 -07003780 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003781
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003782 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003783 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3784
3785 ret = dev_alloc_name(dev, dev->name);
3786 if (ret < 0) {
3787 hdd_err(
3788 "unable to get dev name: %s, err = 0x%x",
3789 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303790 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003791 }
3792 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003793
3794 ret = register_netdevice(dev);
3795 if (ret) {
3796 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3797 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303798 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003799 }
3800 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003801 ret = register_netdev(dev);
3802 if (ret) {
3803 hdd_err("register_netdev(%s) failed, err = 0x%x",
3804 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303805 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003806 }
3807 }
3808 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3809
Dustin Browne74003f2018-03-14 12:51:58 -07003810 hdd_exit();
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003811
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303812 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003813}
3814
Krunal Sonib51eec72017-11-20 21:53:01 -08003815QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003816{
Krunal Sonib51eec72017-11-20 21:53:01 -08003817 struct hdd_adapter *adapter;
3818 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003819
Krunal Sonib51eec72017-11-20 21:53:01 -08003820 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3821 if (!hdd_ctx) {
3822 hdd_err("Invalid HDD_CTX");
3823 return QDF_STATUS_E_FAILURE;
3824 }
3825
3826 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3827 if (NULL == adapter) {
Naveen Rawat23a3b912018-05-30 17:45:52 -07003828 hdd_err("NULL adapter for %d", session_id);
Krunal Sonib51eec72017-11-20 21:53:01 -08003829 return QDF_STATUS_E_INVAL;
3830 }
3831 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303832 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003833 hdd_debug("session %d opened", adapter->session_id);
3834
3835 return QDF_STATUS_SUCCESS;
3836}
3837
3838QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3839{
3840 struct hdd_adapter *adapter;
3841 struct hdd_context *hdd_ctx;
3842
3843 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3844 if (!hdd_ctx) {
3845 hdd_err("Invalid HDD_CTX");
3846 return QDF_STATUS_E_FAILURE;
3847 }
3848
3849 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003850 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003851 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303852 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003853 }
3854
3855 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003856 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303857 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003858 }
3859
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003860 /*
3861 * For NAN Data interface, the close session results in the final
3862 * indication to the userspace
3863 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003864 if (adapter->device_mode == QDF_NDI_MODE)
3865 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003866
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003867 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3868
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003869 /*
3870 * We can be blocked while waiting for scheduled work to be
3871 * flushed, and the adapter structure can potentially be freed, in
3872 * which case the magic will have been reset. So make sure the
3873 * magic is still good, and hence the adapter structure is still
3874 * valid, before signaling completion
3875 */
3876 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303877 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003878
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303879 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003880}
3881
Jeff Johnson9d295242017-08-29 14:39:48 -07003882int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003883{
Dustin Brownd28772b2017-03-17 14:16:07 -07003884 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003885
Dustin Brownd28772b2017-03-17 14:16:07 -07003886 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003887 if (QDF_IS_STATUS_ERROR(status))
3888 return qdf_status_to_os_return(status);
3889
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003890 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003891 if (QDF_IS_STATUS_ERROR(status))
3892 return qdf_status_to_os_return(status);
3893
3894 if (wma_capability_enhanced_mcast_filter())
3895 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3896 else
3897 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003898
3899 return qdf_status_to_os_return(status);
3900}
3901
Jeff Johnson9d295242017-08-29 14:39:48 -07003902int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003903{
3904 QDF_STATUS status;
Jiachao Wu2c42c222018-01-15 18:13:19 +08003905 int errno = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003906 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003907 uint8_t vdev_id;
Dustin Brownd28772b2017-03-17 14:16:07 -07003908
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003909 vdev_id = adapter->session_id;
3910 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003911
3912 /* vdev created sanity check */
3913 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07003914 hdd_err("vdev for Id %d does not exist", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003915 return -EINVAL;
3916 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003917 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Krunal Soni8a06d832018-06-20 16:41:17 -07003918 ucfg_scan_set_vdev_del_in_progress(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003919
Dustin Brownd28772b2017-03-17 14:16:07 -07003920 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303921 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07003922 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -07003923 status = sme_close_session(hdd_ctx->mac_handle, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003924 if (QDF_IS_STATUS_ERROR(status)) {
3925 hdd_err("failed to close sme session: %d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003926 errno = qdf_status_to_os_return(status);
3927 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07003928 }
3929
3930 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303931 status = qdf_wait_for_event_completion(
3932 &adapter->qdf_session_close_event,
3933 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3934 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003935 if (adapter->device_mode == QDF_NDI_MODE)
3936 hdd_ndp_session_end_handler(adapter);
3937 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303938 adapter->session_id = HDD_SESSION_ID_INVALID;
3939 if (QDF_STATUS_E_TIMEOUT != status) {
3940 hdd_err("timed out waiting for close sme session: %u", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003941 errno = -ETIMEDOUT;
3942 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303943 } else if (adapter->qdf_session_close_event.force_set) {
3944 hdd_err("Session close evt focefully set, SSR/PDR has occurred");
Jiachao Wu2c42c222018-01-15 18:13:19 +08003945 errno = -EINVAL;
3946 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303947 } else {
3948 hdd_err("Failed to close sme session (%u)", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003949 errno = -EINVAL;
3950 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303951 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003952 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08003953
Yue Maf9782842017-05-08 12:49:49 -07003954release_vdev:
Krunal Soni8a06d832018-06-20 16:41:17 -07003955 ucfg_scan_clear_vdev_del_in_progress(adapter->hdd_vdev);
Frank Liuc66d4bf2018-01-26 16:18:18 +08003956 /*
3957 * In SSR or driver unloading case, directly exit may cause objects
3958 * leak, if sme_close_session failed. Free objects anyway.
Jiachao Wu2c42c222018-01-15 18:13:19 +08003959 */
Kabilan Kannanb867c312018-02-15 17:43:21 -08003960 if (errno && !cds_is_driver_recovering() && !cds_is_driver_unloading())
Jiachao Wu2c42c222018-01-15 18:13:19 +08003961 return errno;
3962
Sandeep Puligillaef415362017-08-30 16:37:13 -07003963 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08003964 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003965 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08003966 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003967 return errno;
3968 }
3969
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003970 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003971
3972 return 0;
3973}
3974
Krunal Sonib51eec72017-11-20 21:53:01 -08003975static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
3976 struct sme_session_params *session_param,
3977 csr_roam_completeCallback callback,
3978 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07003979{
Dustin Brownd28772b2017-03-17 14:16:07 -07003980 uint32_t type;
3981 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08003982 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07003983
3984 /* determine vdev (sub)type */
3985 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303986 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003987 hdd_err("failed to get vdev type: %d", status);
3988 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003989 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003990 session_param->sme_session_id = adapter->session_id;
3991 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
3992 session_param->type_of_persona = type;
3993 session_param->subtype_of_persona = sub_type;
3994 session_param->session_open_cb = hdd_sme_open_session_callback;
3995 session_param->session_close_cb = hdd_sme_close_session_callback;
3996 session_param->callback = callback;
3997 session_param->callback_ctx = callback_ctx;
3998
3999 return 0;
4000}
4001
4002int hdd_vdev_create(struct hdd_adapter *adapter,
4003 csr_roam_completeCallback callback, void *ctx)
4004{
4005 QDF_STATUS status;
4006 int errno;
4007 struct hdd_context *hdd_ctx;
4008 struct sme_session_params sme_session_params = {0};
Krunal Sonib51eec72017-11-20 21:53:01 -08004009
4010 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07004011
4012 /* do vdev create via objmgr */
4013 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07004014 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07004015 if (errno) {
4016 hdd_err("failed to create objmgr vdev: %d", errno);
4017 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004018 }
Dustin Brownd28772b2017-03-17 14:16:07 -07004019
4020 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304021 status = qdf_event_reset(&adapter->qdf_session_open_event);
4022 if (QDF_STATUS_SUCCESS != status) {
4023 hdd_err("failed to reinit session open event");
4024 return -EINVAL;
4025 }
Krunal Sonib51eec72017-11-20 21:53:01 -08004026 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
4027 callback, ctx);
4028 if (errno) {
4029 hdd_err("failed to populating SME params");
4030 goto objmgr_vdev_destroy_procedure;
4031 }
4032
Jeff Johnson16528362018-06-14 12:34:16 -07004033 status = sme_open_session(hdd_ctx->mac_handle, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07004034 if (QDF_IS_STATUS_ERROR(status)) {
4035 hdd_err("failed to open sme session: %d", status);
4036 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07004037 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004038 }
4039
4040 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304041 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
4042 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
4043 if (QDF_STATUS_SUCCESS != status) {
4044 if (adapter->qdf_session_open_event.force_set) {
4045 /*
4046 * SSR/PDR has caused shutdown, which has forcefully
4047 * set the event. Return without the closing session.
4048 */
4049 adapter->session_id = HDD_SESSION_ID_INVALID;
4050 hdd_err("Session open event forcefully set");
4051 return -EINVAL;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05304052 }
Jeff Johnsonc66d3102018-02-28 11:58:26 -08004053
4054 if (QDF_STATUS_E_TIMEOUT == status)
4055 hdd_err("Session failed to open within timeout period");
4056 else
4057 hdd_err("Failed to wait for session open event(status-%d)",
4058 status);
4059 errno = -ETIMEDOUT;
4060 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
4061 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004062 }
4063
4064 /* firmware ready for component communication, raise vdev_ready event */
4065 errno = hdd_vdev_ready(adapter);
4066 if (errno) {
4067 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07004068 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07004069 }
4070
Naveen Rawat2b430892018-03-13 13:58:18 -07004071 if (adapter->device_mode == QDF_STA_MODE) {
4072 hdd_debug("setting RTT mac randomization param: %d",
4073 hdd_ctx->config->enable_rtt_mac_randomization);
4074 errno = sme_cli_set_command(adapter->session_id,
4075 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_INITIATOR_RANDOM_MAC,
4076 hdd_ctx->config->enable_rtt_mac_randomization,
4077 VDEV_CMD);
4078 if (0 != errno)
4079 hdd_err("RTT mac randomization param set failed %d",
4080 errno);
4081 }
4082
Jeff Johnson1b780e42017-10-31 14:11:45 -07004083 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004084
4085 return 0;
4086
4087 /*
4088 * Due to legacy constraints, we need to destroy in the same order as
4089 * create. So, split error handling into 2 cases to accommodate.
4090 */
4091
Krunal Soni4a020c72017-10-30 20:58:40 -07004092objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07004093 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07004094
4095 return errno;
4096
Krunal Soni4a020c72017-10-30 20:58:40 -07004097hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07004098 QDF_BUG(!hdd_vdev_destroy(adapter));
4099
4100 return errno;
4101}
4102
Jeff Johnson9d295242017-08-29 14:39:48 -07004103QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07004104{
Jeff Johnsonb9424862017-10-30 08:49:35 -07004105 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004106 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07004107 QDF_STATUS status;
4108 int ret_val;
Jeff Johnson16528362018-06-14 12:34:16 -07004109 mac_handle_t mac_handle;
Dustin Brownd28772b2017-03-17 14:16:07 -07004110
Dustin Brownd28772b2017-03-17 14:16:07 -07004111 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -07004112 mac_handle = hdd_ctx->mac_handle;
4113 sme_set_curr_device_mode(mac_handle, adapter->device_mode);
4114 sme_set_pdev_ht_vht_ies(mac_handle, hdd_ctx->config->enable2x2);
4115 sme_set_vdev_ies_per_band(mac_handle, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07004116
Jeff Johnson7f2c5912018-03-23 11:42:28 -07004117 hdd_roam_profile_init(adapter);
4118 hdd_register_wext(adapter->dev);
4119
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07004120 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004121
Jeff Johnsond377dce2017-10-04 10:32:42 -07004122 qdf_mem_set(sta_ctx->conn_info.staId,
4123 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05304124
Deepak Dhamdherea2785822016-11-17 01:17:45 -08004125 /* set fast roaming capability in sme session */
Jeff Johnson16528362018-06-14 12:34:16 -07004126 status = sme_config_fast_roaming(mac_handle, adapter->session_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05304127 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004128 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004129 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004130 hdd_ctx->config->OperatingChannel;
4131
4132 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07004133 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004134
4135 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304136 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004137 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004138 status, status);
4139 goto error_init_txrx;
4140 }
4141
4142 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4143
4144 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304145 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004146 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004147 status, status);
4148 goto error_wmm_init;
4149 }
4150
4151 set_bit(WMM_INIT_DONE, &adapter->event_flags);
4152
Jeff Johnson1b780e42017-10-31 14:11:45 -07004153 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004154 WMI_PDEV_PARAM_BURST_ENABLE,
Dundi Raviteja3aa01be2018-05-21 18:58:59 +05304155 HDD_ENABLE_SIFS_BURST_DEFAULT,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004156 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07004157 if (ret_val)
4158 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004159
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05304160 /*
4161 * In case of USB tethering, LRO is disabled. If SSR happened
4162 * during that time, then as part of SSR init, do not enable
4163 * the LRO again. Keep the LRO state same as before SSR.
4164 */
4165 if (!(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07004166 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05304167
4168 /* rcpi info initialization */
4169 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
4170
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304171 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004172
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004173error_wmm_init:
4174 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4175 hdd_deinit_tx_rx(adapter);
4176error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07004177 hdd_unregister_wext(adapter->dev);
Dustin Brownd28772b2017-03-17 14:16:07 -07004178 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004179
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004180 return status;
4181}
4182
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304183/**
Krunal Soni4a020c72017-10-30 20:58:40 -07004184 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304185 * @hdd_ctx: global hdd context
4186 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07004187 * @rtnl_held: Used to indicate whether or not the caller is holding
4188 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304189 *
4190 * This function De-initializes the STA/P2P/OCB adapter.
4191 *
4192 * Return: None.
4193 */
Krunal Soni4a020c72017-10-30 20:58:40 -07004194static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004195 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004196 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304197{
Dustin Brownfdf17c12018-03-14 12:55:34 -07004198 hdd_enter_dev(adapter->dev);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304199
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05304200 if (adapter->dev) {
4201 if (rtnl_held)
4202 adapter->dev->wireless_handlers = NULL;
4203 else {
4204 rtnl_lock();
4205 adapter->dev->wireless_handlers = NULL;
4206 rtnl_unlock();
4207 }
4208 }
4209
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304210 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
4211 hdd_deinit_tx_rx(adapter);
4212 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4213 }
4214
4215 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4216 hdd_wmm_adapter_close(adapter);
4217 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4218 }
4219
Krunal Sonib51eec72017-11-20 21:53:01 -08004220
Dustin Browne74003f2018-03-14 12:51:58 -07004221 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304222}
4223
Krunal Sonib51eec72017-11-20 21:53:01 -08004224void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
4225 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004226 bool rtnl_held)
4227{
Dustin Brown491d54b2018-03-14 12:39:11 -07004228 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304229
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004230 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004231 case QDF_STA_MODE:
4232 case QDF_P2P_CLIENT_MODE:
4233 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08004234 case QDF_IBSS_MODE:
4235 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004236 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004237 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004238 break;
4239 }
4240
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004241 case QDF_SAP_MODE:
4242 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004243 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004244 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004245 break;
4246 }
4247
4248 default:
4249 break;
4250 }
4251
Dustin Browne74003f2018-03-14 12:51:58 -07004252 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004253}
4254
Jeff Johnson9d295242017-08-29 14:39:48 -07004255static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004256 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004257{
Jeff Johnson5505db82017-11-02 21:19:23 -07004258 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004259
4260 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07004261 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004262 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004263 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004264 return;
4265 }
4266
Alok Kumarb64650c2018-03-23 17:05:11 +05304267 hdd_nud_deinit_tracking(adapter);
4268 qdf_mutex_destroy(&adapter->disconnection_status_lock);
4269
Rajeev Kumardca5f812016-02-04 17:28:06 -08004270 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05304271
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004272 /*
4273 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
4274 * the driver is almost closed and cannot handle either control
4275 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004276 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
4277 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004278 * is not right. Setting this flag helps hdd_stop() to recognize that
4279 * the interface is closed and restricts any operations on that
4280 */
4281 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
4282
4283 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004284 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07004285 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004286 else
Jeff Johnson5505db82017-11-02 21:19:23 -07004287 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004288 /*
4289 * Note that the adapter is no longer valid at this point
4290 * since the memory has been reclaimed
4291 */
4292 }
4293}
4294
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004295static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07004296 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004297{
Jeff Johnson9d295242017-08-29 14:39:48 -07004298 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004299
Dustin Brown920397d2017-12-13 16:27:50 -08004300 hdd_for_each_adapter(hdd_ctx, adapter) {
4301 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
4302 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304303 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004304 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004305 }
Dustin Brown920397d2017-12-13 16:27:50 -08004306
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304307 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004308}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004309
Arun Khandavalli2358d522016-05-16 18:05:37 +05304310#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4311/**
4312 * hdd_set_fw_log_params() - Set log parameters to FW
4313 * @hdd_ctx: HDD Context
4314 * @adapter: HDD Adapter
4315 *
4316 * This function set the FW Debug log level based on the INI.
4317 *
4318 * Return: None
4319 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004320static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004321 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304322{
4323 uint8_t count = 0, numentries = 0,
4324 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
4325 uint32_t value = 0;
4326 int ret;
4327
Arun Khandavallifae92942016-08-01 13:31:08 +05304328 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4329 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004330 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304331 return;
4332 }
4333
Arun Khandavallifae92942016-08-01 13:31:08 +05304334 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05304335 hdd_ctx->fw_log_settings.dl_type =
4336 hdd_ctx->config->enableFwLogType;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004337 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304338 WMI_DBGLOG_TYPE,
4339 hdd_ctx->config->enableFwLogType,
4340 DBG_CMD);
4341 if (ret != 0)
4342 hdd_err("Failed to enable FW log type ret %d",
4343 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304344
4345 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05304346 hdd_ctx->config->enableFwLogLevel;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004347 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304348 WMI_DBGLOG_LOG_LEVEL,
4349 hdd_ctx->config->enableFwLogLevel,
4350 DBG_CMD);
4351 if (ret != 0)
4352 hdd_err("Failed to enable FW log level ret %d",
4353 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304354
4355 hdd_string_to_u8_array(
4356 hdd_ctx->config->enableFwModuleLogLevel,
4357 moduleloglevel,
4358 &numentries,
4359 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
4360
4361 while (count < numentries) {
4362 /*
4363 * FW module log level input string looks like
4364 * below:
4365 * gFwDebugModuleLoglevel=<FW Module ID>,
4366 * <Log Level>,...
4367 * For example:
4368 * gFwDebugModuleLoglevel=
4369 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
4370 * Above input string means :
4371 * For FW module ID 1 enable log level 0
4372 * For FW module ID 2 enable log level 1
4373 * For FW module ID 3 enable log level 2
4374 * For FW module ID 4 enable log level 3
4375 * For FW module ID 5 enable log level 4
4376 * For FW module ID 6 enable log level 5
4377 * For FW module ID 7 enable log level 6
4378 */
4379
Nishank Aggarwale239d962017-03-03 12:26:02 +05304380 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
4381 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
4382 hdd_err("Module id %d and dbglog level %d input length is more than max",
4383 moduleloglevel[count],
4384 moduleloglevel[count + 1]);
4385 return;
4386 }
4387
4388 value = moduleloglevel[count] << 16;
4389 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07004390 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304391 WMI_DBGLOG_MOD_LOG_LEVEL,
4392 value, DBG_CMD);
4393 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304394 hdd_err("Failed to enable FW module log level %d ret %d",
4395 value, ret);
4396
4397 count += 2;
4398 }
Arun Khandavallifae92942016-08-01 13:31:08 +05304399
Arun Khandavalli2358d522016-05-16 18:05:37 +05304400}
4401#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004402static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004403 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304404{
4405}
4406
4407#endif
4408
4409/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004410 * hdd_configure_chain_mask() - programs chain mask to firmware
4411 * @adapter: HDD adapter
4412 *
4413 * Return: 0 on success or errno on failure
4414 */
4415static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4416{
4417 int ret_val;
Naveen Rawat98322472018-03-06 10:29:42 -08004418 QDF_STATUS status;
4419 struct wma_caps_per_phy non_dbs_phy_cap;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004420 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4421
4422 hdd_debug("enable2x2: %d, lte_coex: %d, ChainMask1x1: tx: %d rx: %d",
4423 hdd_ctx->config->enable2x2, hdd_ctx->lte_coex_ant_share,
4424 hdd_ctx->config->txchainmask1x1,
4425 hdd_ctx->config->rxchainmask1x1);
4426 hdd_debug("disable_DBS: %d, tx_chain_mask_2g: %d, rx_chain_mask_2g: %d",
4427 hdd_ctx->config->dual_mac_feature_disable,
4428 hdd_ctx->config->tx_chain_mask_2g,
4429 hdd_ctx->config->rx_chain_mask_2g);
4430 hdd_debug("tx_chain_mask_5g: %d, rx_chain_mask_5g: %d",
4431 hdd_ctx->config->tx_chain_mask_5g,
4432 hdd_ctx->config->rx_chain_mask_5g);
Liangwei Dong22810e82018-03-15 03:42:12 -04004433 hdd_debug("enable_bt_chain_separation %d",
4434 hdd_ctx->config->enable_bt_chain_separation);
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004435
Naveen Rawat98322472018-03-06 10:29:42 -08004436 status = wma_get_caps_for_phyidx_hwmode(&non_dbs_phy_cap,
4437 HW_MODE_DBS_NONE,
4438 CDS_BAND_ALL);
4439 if (QDF_IS_STATUS_ERROR(status)) {
4440 hdd_err("couldn't get phy caps. skip chain mask programming");
4441 return qdf_status_to_os_return(status);
4442 }
4443
4444 if (non_dbs_phy_cap.tx_chain_mask_2G < 3 ||
4445 non_dbs_phy_cap.rx_chain_mask_2G < 3 ||
4446 non_dbs_phy_cap.tx_chain_mask_5G < 3 ||
4447 non_dbs_phy_cap.rx_chain_mask_5G < 3) {
4448 hdd_info("firmware not capable. skip chain mask programming");
4449 return 0;
4450 }
4451
Liangwei Dong22810e82018-03-15 03:42:12 -04004452 if (hdd_ctx->config->enable2x2 &&
4453 !hdd_ctx->config->enable_bt_chain_separation) {
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004454 hdd_info("2x2 enabled. skip chain mask programming");
4455 return 0;
4456 }
4457
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004458 if (hdd_ctx->config->dual_mac_feature_disable !=
4459 DISABLE_DBS_CXN_AND_SCAN) {
4460 hdd_info("DBS enabled(%d). skip chain mask programming",
4461 hdd_ctx->config->dual_mac_feature_disable);
4462 return 0;
4463 }
4464
Naveen Rawatdacb5032018-02-08 15:23:24 -08004465 if (hdd_ctx->lte_coex_ant_share) {
4466 hdd_info("lte ant sharing enabled. skip chainmask programming");
4467 return 0;
4468 }
4469
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004470 if (hdd_ctx->config->txchainmask1x1) {
4471 ret_val = sme_cli_set_command(adapter->session_id,
4472 WMI_PDEV_PARAM_TX_CHAIN_MASK,
4473 hdd_ctx->config->txchainmask1x1,
4474 PDEV_CMD);
4475 if (ret_val)
4476 goto error;
4477 }
4478
4479 if (hdd_ctx->config->rxchainmask1x1) {
4480 ret_val = sme_cli_set_command(adapter->session_id,
4481 WMI_PDEV_PARAM_RX_CHAIN_MASK,
4482 hdd_ctx->config->rxchainmask1x1,
4483 PDEV_CMD);
4484 if (ret_val)
4485 goto error;
4486 }
4487
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004488 if (hdd_ctx->config->txchainmask1x1 ||
4489 hdd_ctx->config->rxchainmask1x1) {
4490 hdd_info("band agnostic tx/rx chain mask set. skip per band chain mask");
4491 return 0;
4492 }
4493
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004494 if (hdd_ctx->config->tx_chain_mask_2g) {
4495 ret_val = sme_cli_set_command(adapter->session_id,
4496 WMI_PDEV_PARAM_TX_CHAIN_MASK_2G,
4497 hdd_ctx->config->tx_chain_mask_2g, PDEV_CMD);
4498 if (0 != ret_val)
4499 goto error;
4500 }
4501
4502 if (hdd_ctx->config->rx_chain_mask_2g) {
4503 ret_val = sme_cli_set_command(adapter->session_id,
4504 WMI_PDEV_PARAM_RX_CHAIN_MASK_2G,
4505 hdd_ctx->config->rx_chain_mask_2g, PDEV_CMD);
4506 if (0 != ret_val)
4507 goto error;
4508 }
4509
4510 if (hdd_ctx->config->tx_chain_mask_5g) {
4511 ret_val = sme_cli_set_command(adapter->session_id,
4512 WMI_PDEV_PARAM_TX_CHAIN_MASK_5G,
4513 hdd_ctx->config->tx_chain_mask_5g, PDEV_CMD);
4514 if (0 != ret_val)
4515 goto error;
4516 }
4517
4518 if (hdd_ctx->config->rx_chain_mask_5g) {
4519 ret_val = sme_cli_set_command(adapter->session_id,
4520 WMI_PDEV_PARAM_RX_CHAIN_MASK_5G,
4521 hdd_ctx->config->rx_chain_mask_5g, PDEV_CMD);
4522 if (0 != ret_val)
4523 goto error;
4524 }
4525
4526 return 0;
4527
4528error:
4529 hdd_err("WMI PDEV set param failed %d", ret_val);
4530 return -EINVAL;
4531}
4532
4533/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304534 * hdd_set_fw_params() - Set parameters to firmware
4535 * @adapter: HDD adapter
4536 *
4537 * This function Sets various parameters to fw once the
4538 * adapter is started.
4539 *
4540 * Return: 0 on success or errno on failure
4541 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004542int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304543{
4544 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004545 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304546
Dustin Brownfdf17c12018-03-14 12:55:34 -07004547 hdd_enter_dev(adapter->dev);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304548
4549 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4550 if (!hdd_ctx)
4551 return -EINVAL;
4552
Dustin Brown732ab9c2017-06-15 13:24:09 -07004553 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4554 hdd_debug("FTM Mode is active; nothing to do");
4555 return 0;
4556 }
4557
Jeff Johnson1b780e42017-10-31 14:11:45 -07004558 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304559 WMI_PDEV_PARAM_DTIM_SYNTH,
4560 hdd_ctx->config->enable_lprx, PDEV_CMD);
4561 if (ret) {
4562 hdd_err("Failed to set LPRx");
4563 goto error;
4564 }
4565
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304566
4567 ret = sme_cli_set_command(
4568 adapter->session_id,
4569 WMI_PDEV_PARAM_1CH_DTIM_OPTIMIZED_CHAIN_SELECTION,
4570 hdd_ctx->config->enable_dtim_selection_diversity,
4571 PDEV_CMD);
4572 if (ret) {
4573 hdd_err("Failed to set DTIM_OPTIMIZED_CHAIN_SELECTION");
4574 goto error;
4575 }
4576
Ashish Kumar Dhanotiya48dac7d2018-03-28 14:59:50 +05304577 ret = sme_cli_set_command(
4578 adapter->session_id,
4579 WMI_PDEV_PARAM_TX_SCH_DELAY,
4580 hdd_ctx->config->enable_tx_sch_delay,
4581 PDEV_CMD);
4582 if (ret) {
4583 hdd_err("Failed to set WMI_PDEV_PARAM_TX_SCH_DELAY");
4584 goto error;
4585 }
4586
Ashish Kumar Dhanotiya959b38c2018-04-06 21:07:57 +05304587 ret = sme_cli_set_command(
4588 adapter->session_id,
4589 WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE,
4590 hdd_ctx->config->enable_secondary_rate,
4591 PDEV_CMD);
4592 if (ret) {
4593 hdd_err("Failed to set WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE");
4594 goto error;
4595 }
4596
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304597 if (adapter->device_mode == QDF_STA_MODE) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07004598 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304599 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4600 hdd_ctx->config->upper_brssi_thresh);
4601
Jeff Johnson1b780e42017-10-31 14:11:45 -07004602 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304603 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4604 hdd_ctx->config->lower_brssi_thresh);
4605
Jeff Johnson1b780e42017-10-31 14:11:45 -07004606 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304607 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4608 hdd_ctx->config->enable_dtim_1chrx);
4609 }
4610
Dustin Brown732ab9c2017-06-15 13:24:09 -07004611 if (hdd_ctx->config->enable2x2) {
4612 hdd_debug("configuring 2x2 mode fw params");
4613
Jeff Johnson1b780e42017-10-31 14:11:45 -07004614 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004615 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
4616 hdd_ctx->config->enable_cck_tx_fir_override,
4617 PDEV_CMD);
4618 if (ret) {
4619 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4620 ret);
4621 goto error;
4622 }
Liangwei Dong22810e82018-03-15 03:42:12 -04004623
4624 if (hdd_configure_chain_mask(adapter))
4625 goto error;
Dustin Brown732ab9c2017-06-15 13:24:09 -07004626 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304627#define HDD_DTIM_1CHAIN_RX_ID 0x5
4628#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004629 hdd_debug("configuring 1x1 mode fw params");
4630
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004631 /*
4632 * Disable DTIM 1 chain Rx when in 1x1,
4633 * we are passing two value
4634 * as param_id << 29 | param_value.
4635 * Below param_value = 0(disable)
4636 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004637 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004638 WMI_STA_SMPS_PARAM_CMDID,
4639 HDD_DTIM_1CHAIN_RX_ID <<
4640 HDD_SMPS_PARAM_VALUE_S,
4641 VDEV_CMD);
4642 if (ret) {
4643 hdd_err("DTIM 1 chain set failed %d", ret);
4644 goto error;
4645 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304646
Arun Khandavalli2358d522016-05-16 18:05:37 +05304647#undef HDD_DTIM_1CHAIN_RX_ID
4648#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004649
4650 if (hdd_configure_chain_mask(adapter))
4651 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004652 }
4653
Jeff Johnson1b780e42017-10-31 14:11:45 -07004654 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004655 WMI_PDEV_PARAM_HYST_EN,
4656 hdd_ctx->config->enableMemDeepSleep,
4657 PDEV_CMD);
4658 if (ret) {
4659 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4660 goto error;
4661 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304662
Jeff Johnson1b780e42017-10-31 14:11:45 -07004663 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004664 WMI_VDEV_PARAM_ENABLE_RTSCTS,
4665 hdd_ctx->config->rts_profile,
4666 VDEV_CMD);
4667 if (ret) {
4668 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4669 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304670 }
4671
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004672 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
4673
Jeff Johnson1b780e42017-10-31 14:11:45 -07004674 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004675 GEN_VDEV_PARAM_AMSDU,
4676 hdd_ctx->config->max_amsdu_num,
4677 GEN_CMD);
4678 if (ret != 0) {
4679 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4680 goto error;
4681 }
4682
Arun Khandavalli2358d522016-05-16 18:05:37 +05304683 hdd_set_fw_log_params(hdd_ctx, adapter);
Dustin Browne74003f2018-03-14 12:51:58 -07004684 hdd_exit();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004685
Arun Khandavalli2358d522016-05-16 18:05:37 +05304686 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304687
Arun Khandavalli2358d522016-05-16 18:05:37 +05304688error:
4689 return -EINVAL;
4690}
4691
Ryan Hsu07495ea2016-01-21 15:25:39 -08004692/**
4693 * hdd_open_adapter() - open and setup the hdd adatper
4694 * @hdd_ctx: global hdd context
4695 * @session_type: type of the interface to be created
4696 * @iface_name: User-visible name of the interface
4697 * @macAddr: MAC address to assign to the interface
4698 * @name_assign_type: the name of assign type of the netdev
4699 * @rtnl_held: the rtnl lock hold flag
4700 *
4701 * This function open and setup the hdd adpater according to the device
4702 * type request, assign the name, the mac address assigned, and then prepared
4703 * the hdd related parameters, queue, lock and ready to start.
4704 *
4705 * Return: the pointer of hdd adapter, otherwise NULL.
4706 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004707struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004708 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08004709 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004710 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004711{
Jeff Johnson9d295242017-08-29 14:39:48 -07004712 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304713 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004714
4715 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4716 /*
4717 * Max limit reached on the number of vdevs configured by the
4718 * host. Return error
4719 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304720 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4721 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004722 return NULL;
4723 }
4724
4725 if (macAddr == NULL) {
4726 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304727 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004728 return NULL;
4729 }
4730 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304731 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304732 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4733 " already exists",
4734 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004735 return NULL;
4736 }
4737
4738 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004739 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004740 /* Reset locally administered bit if the device mode is STA */
4741 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05304742 hdd_info("locally administered bit reset in sta mode: "
4743 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004744 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004745 case QDF_P2P_CLIENT_MODE:
4746 case QDF_P2P_DEVICE_MODE:
4747 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07004748 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304749 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004750 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4751 name_assign_type,
4752 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004753
4754 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304755 hdd_err("failed to allocate adapter for session %d",
4756 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004757 return NULL;
4758 }
4759
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004760 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004761 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004762 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004763 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304764 else if (QDF_MONITOR_MODE == session_type)
4765 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004766 else
4767 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4768
4769 adapter->device_mode = session_type;
4770
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004771
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004772 /*
4773 * Workqueue which gets scheduled in IPv4 notification
4774 * callback
4775 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004776 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004777 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004778
4779#ifdef WLAN_NS_OFFLOAD
4780 /*
4781 * Workqueue which gets scheduled in IPv6
4782 * notification callback.
4783 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004784 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004785 hdd_ipv6_notifier_work_queue);
4786#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004787 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004788 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004789 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004790
4791 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004792 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004793 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304794 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4795 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304796
Alok Kumarb64650c2018-03-23 17:05:11 +05304797 hdd_nud_init_tracking(adapter);
4798
4799 qdf_mutex_create(&adapter->disconnection_status_lock);
4800
Ravi Joshi1a292562017-05-18 16:28:54 -07004801 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004802
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004803 case QDF_P2P_GO_MODE:
4804 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004805 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4806 name_assign_type,
4807 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004808 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004809 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304810 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004811 return NULL;
4812 }
4813
4814 adapter->wdev.iftype =
4815 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004816 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004817 NL80211_IFTYPE_P2P_GO;
4818 adapter->device_mode = session_type;
4819
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004820 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004821 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004822 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004823
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004824 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004825 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304826 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4827 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304828
4829 /*
4830 * Workqueue which gets scheduled in IPv4 notification
4831 * callback
4832 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004833 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304834 hdd_ipv4_notifier_work_queue);
4835
4836#ifdef WLAN_NS_OFFLOAD
4837 /*
4838 * Workqueue which gets scheduled in IPv6
4839 * notification callback.
4840 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004841 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304842 hdd_ipv6_notifier_work_queue);
4843#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004844 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304845 case QDF_FTM_MODE:
4846 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4847 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08004848 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304849 if (NULL == adapter) {
4850 hdd_err("Failed to allocate adapter for FTM mode");
4851 return NULL;
4852 }
4853 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4854 adapter->device_mode = session_type;
4855 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004856 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004857 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004858
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304859 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004860 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304861 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304862 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4863 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304864 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004865 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004866 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304867 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004868 return NULL;
4869 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004870
hqueaa33ee2017-05-04 17:56:35 +08004871 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
Min Liu9be5d4a2018-05-17 11:51:53 +08004872 qdf_list_create(&adapter->blocked_scan_request_q, WLAN_MAX_SCAN_COUNT);
4873 qdf_mutex_create(&adapter->blocked_scan_request_q_lock);
hqueaa33ee2017-05-04 17:56:35 +08004874
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304875 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004876 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08004877 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004878 }
4879
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304880 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004881 if (NULL != adapter) {
4882 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4883 adapter = NULL;
4884 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004885
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004886 return NULL;
4887 }
4888
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304889 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004890 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4891 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004892
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004893 /* Adapter successfully added. Increment the vdev count */
4894 hdd_ctx->current_intf_count++;
4895
Jeff Johnson5880d792016-08-15 13:32:30 -07004896 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004897 hdd_ctx->current_intf_count);
4898
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004899 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004900 }
4901
Rajeev Kumardca5f812016-02-04 17:28:06 -08004902 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004903 hdd_err("Interface %s wow debug_fs init failed",
4904 netdev_name(adapter->dev));
4905
Ajit Pal Singh106c1412018-04-18 18:08:49 +05304906 hdd_register_hl_netdev_fc_timer(adapter,
4907 hdd_tx_resume_timer_expired_handler);
4908
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004909 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4910 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004911
4912 return adapter;
4913
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004914err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07004915 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304916 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004917
4918 return NULL;
4919}
4920
Nirav Shaheb017be2018-02-15 11:20:58 +05304921#ifdef MSM_PLATFORM
4922static inline
4923void hdd_cancel_bus_bw_work(struct hdd_context *hdd_ctx)
4924{
4925 cancel_work_sync(&hdd_ctx->bus_bw_work);
4926}
4927#else
4928static inline
4929void hdd_cancel_bus_bw_work(struct hdd_context *hdd_ctx)
4930{
4931}
4932#endif
4933
Jeff Johnson9d295242017-08-29 14:39:48 -07004934QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004935 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004936{
Dustin Brown920397d2017-12-13 16:27:50 -08004937 /*
4938 * Here we are stopping global bus_bw timer & work per adapter.
4939 *
4940 * The reason is to fix one race condition between
4941 * bus bandwidth work and cleaning up an adapter.
4942 * Under some conditions, it is possible for the bus bandwidth
4943 * work to access a particularly destroyed adapter, leading to
4944 * use-after-free.
4945 */
4946 hdd_debug("wait for bus bw work to flush");
4947 hdd_bus_bw_compute_timer_stop(hdd_ctx);
4948 hdd_bus_bw_cancel_work(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004949
Min Liuef92ef52018-06-25 18:08:54 +08004950 qdf_list_destroy(&adapter->blocked_scan_request_q);
4951 qdf_mutex_destroy(&adapter->blocked_scan_request_q_lock);
4952
Dustin Brown920397d2017-12-13 16:27:50 -08004953 /* cleanup adapter */
4954 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4955 adapter->device_mode);
Dustin Brown920397d2017-12-13 16:27:50 -08004956 hdd_remove_adapter(hdd_ctx, adapter);
Liangwei Dongad89c762018-06-01 01:56:23 -04004957 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004958
Dustin Brown920397d2017-12-13 16:27:50 -08004959 /* conditionally restart the bw timer */
4960 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004961
Dustin Brown920397d2017-12-13 16:27:50 -08004962 /* Adapter removed. Decrement vdev count */
4963 if (hdd_ctx->current_intf_count != 0)
4964 hdd_ctx->current_intf_count--;
Dustin Brown5ec6b552017-03-31 12:11:40 -07004965
Dustin Brown920397d2017-12-13 16:27:50 -08004966 /* Fw will take care incase of concurrency */
4967 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004968}
4969
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004970/**
4971 * hdd_close_all_adapters - Close all open adapters
4972 * @hdd_ctx: Hdd context
4973 * rtnl_held: True if RTNL lock held
4974 *
4975 * Close all open adapters.
4976 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304977 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004978 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004979QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004980{
Dustin Brown920397d2017-12-13 16:27:50 -08004981 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304982 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004983
Dustin Brown491d54b2018-03-14 12:39:11 -07004984 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004985
4986 do {
Dustin Brown920397d2017-12-13 16:27:50 -08004987 status = hdd_remove_front_adapter(hdd_ctx, &adapter);
4988 if (QDF_IS_STATUS_SUCCESS(status)) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304989 wlan_hdd_release_intf_addr(hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08004990 adapter->mac_addr.bytes);
4991 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4992
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304993 /* Adapter removed. Decrement vdev count */
4994 if (hdd_ctx->current_intf_count != 0)
4995 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004996 }
Dustin Brown920397d2017-12-13 16:27:50 -08004997 } while (QDF_IS_STATUS_SUCCESS(status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004998
Dustin Browne74003f2018-03-14 12:51:58 -07004999 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005000
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305001 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005002}
5003
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005004void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005005{
Anurag Chouhan6d760662016-02-20 16:05:43 +05305006 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005007 tSirUpdateIE updateIE;
Jeff Johnson16528362018-06-14 12:34:16 -07005008 mac_handle_t mac_handle;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005009
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005010 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005011 case QDF_STA_MODE:
5012 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005013 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005014 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005015 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07005016 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005017 break;
5018 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005019 case QDF_SAP_MODE:
5020 case QDF_P2P_GO_MODE:
5021 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005022 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07005023 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005024 break;
5025 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005026 case QDF_FTM_MODE:
5027 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005028 default:
5029 /*
5030 * wlan_hdd_reset_prob_rspies should not have been called
5031 * for these kind of devices
5032 */
Jeff Johnson5880d792016-08-15 13:32:30 -07005033 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07005034 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005035 return;
5036 }
5037
Anurag Chouhanc5548422016-02-24 18:33:27 +05305038 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005039 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005040 updateIE.ieBufferlength = 0;
5041 updateIE.pAdditionIEBuffer = NULL;
5042 updateIE.append = true;
5043 updateIE.notify = false;
Jeff Johnson16528362018-06-14 12:34:16 -07005044 mac_handle = hdd_adapter_get_mac_handle(adapter);
5045 if (sme_update_add_ie(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005046 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305047 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005048 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005049 }
5050}
5051
Dustin Browndb2a8be2017-12-20 11:49:56 -08005052QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
5053 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005054{
Liangwei Dongad89c762018-06-01 01:56:23 -04005055 return hdd_stop_adapter_ext(hdd_ctx, adapter, 0);
5056}
5057
5058QDF_STATUS hdd_stop_adapter_ext(struct hdd_context *hdd_ctx,
5059 struct hdd_adapter *adapter,
5060 enum hdd_adapter_stop_flag_t flag)
5061{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305062 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson025618c2018-03-18 14:41:00 -07005063 struct csr_roam_profile *roam_profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005064 union iwreq_data wrqu;
5065 tSirUpdateIE updateIE;
5066 unsigned long rc;
Jeff Johnsone4c11db2018-05-05 23:22:32 -07005067 tsap_config_t *sap_config;
Jeff Johnson16528362018-06-14 12:34:16 -07005068 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005069
Dustin Brown491d54b2018-03-14 12:39:11 -07005070 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005071
Dustin Browne7e71d32018-05-11 16:00:08 -07005072 if (adapter->session_id != HDD_SESSION_ID_INVALID)
5073 wlan_hdd_cfg80211_deregister_frames(adapter);
5074
Alok Kumarb64650c2018-03-23 17:05:11 +05305075 hdd_nud_ignore_tracking(adapter, true);
5076 hdd_nud_reset_tracking(adapter);
5077
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07005078 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305079 wlan_hdd_netif_queue_control(adapter,
5080 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
5081 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08005082 /*
5083 * if this is the last active connection check & stop the
5084 * opportunistic timer first
5085 */
5086 if (((policy_mgr_get_connection_count(hdd_ctx->hdd_psoc) == 1) &&
5087 (policy_mgr_mode_specific_connection_count(hdd_ctx->hdd_psoc,
5088 policy_mgr_convert_device_mode_to_qdf_type(
5089 adapter->device_mode), NULL) == 1)) ||
5090 !policy_mgr_get_connection_count(hdd_ctx->hdd_psoc))
5091 policy_mgr_check_and_stop_opportunistic_timer(
5092 hdd_ctx->hdd_psoc, adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -07005093
5094 mac_handle = hdd_ctx->mac_handle;
5095
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005096 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005097 case QDF_STA_MODE:
5098 case QDF_P2P_CLIENT_MODE:
5099 case QDF_IBSS_MODE:
5100 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005101 case QDF_NDI_MODE:
5102 if ((QDF_NDI_MODE == adapter->device_mode) ||
5103 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005104 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
5105 hdd_is_connecting(
5106 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005107 INIT_COMPLETION(adapter->disconnect_comp_var);
Jeff Johnson025618c2018-03-18 14:41:00 -07005108 roam_profile = hdd_roam_profile(adapter);
5109 /* For NDI do not use roam_profile */
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005110 if (QDF_NDI_MODE == adapter->device_mode)
5111 qdf_ret_status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005112 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005113 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005114 eCSR_DISCONNECT_REASON_NDI_DELETE);
Jeff Johnson025618c2018-03-18 14:41:00 -07005115 else if (roam_profile->BSSType ==
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005116 eCSR_BSS_TYPE_START_IBSS)
5117 qdf_ret_status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005118 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005119 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005120 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08005121 else if (QDF_STA_MODE == adapter->device_mode) {
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005122 qdf_ret_status =
5123 wlan_hdd_try_disconnect(adapter);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08005124 hdd_debug("Send disconnected event to userspace");
5125 wlan_hdd_cfg80211_indicate_disconnect(
5126 adapter->dev, true,
5127 WLAN_REASON_UNSPECIFIED);
Jeff Johnson109e79d2018-02-27 15:10:04 -08005128 } else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005129 qdf_ret_status = sme_roam_disconnect(
Jeff Johnson16528362018-06-14 12:34:16 -07005130 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005131 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07005132 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005133 /* success implies disconnect command got
5134 * queued up successfully
5135 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005136 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
5137 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005138 rc = wait_for_completion_timeout(
5139 &adapter->disconnect_comp_var,
5140 msecs_to_jiffies
5141 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005142 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005143 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005144 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07005145 if (qdf_ret_status != QDF_STATUS_SUCCESS)
5146 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005147 memset(&wrqu, '\0', sizeof(wrqu));
5148 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5149 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5150 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
5151 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05305152 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08005153 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005154
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05305155 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05305156 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005157
5158#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005159 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005160#endif
5161
5162 hdd_deregister_tx_flow_control(adapter);
5163
5164#ifdef WLAN_NS_OFFLOAD
5165#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005166 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005167#endif
5168#endif
5169
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05305170 if (adapter->device_mode == QDF_STA_MODE)
5171 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
5172 adapter->dev);
Dustin Browndb2a8be2017-12-20 11:49:56 -08005173
5174 if (wlan_hdd_try_disconnect(adapter)) {
5175 hdd_err("Error: Can't disconnect adapter");
5176 return QDF_STATUS_E_FAILURE;
Krunal Soni985b8132017-02-10 18:49:08 -08005177 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08005178
Himanshu Agarwalb229a142017-12-21 10:16:45 +05305179 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005180 break;
5181
Rajeev Kumar3b906202018-02-01 10:55:14 -08005182 case QDF_MONITOR_MODE:
5183 wlan_hdd_scan_abort(adapter);
5184 hdd_deregister_tx_flow_control(adapter);
5185 hdd_vdev_destroy(adapter);
5186 break;
5187
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005188 case QDF_SAP_MODE:
wadesongf9b15ed2017-12-14 14:12:32 +08005189 wlan_hdd_scan_abort(adapter);
Govind Singh1dab23b2017-08-12 13:31:00 +05305190 /* Flush IPA exception path packets */
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05305191 sap_config = &adapter->session.ap.sap_config;
5192 if (sap_config)
5193 wlansap_reset_sap_config_add_ie(sap_config,
5194 eUPDATE_IE_ALL);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05305195 ucfg_ipa_flush(hdd_ctx->hdd_pdev);
Liangwei Dongad89c762018-06-01 01:56:23 -04005196 if (!(flag & HDD_IN_CAC_WORK_TH_CONTEXT))
5197 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Jeff Johnson46807cd2018-04-29 21:32:22 -07005198 /* fallthrough */
Dustin Browna5cf8e02017-10-19 16:04:19 -07005199
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005200 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07005201 if (QDF_SAP_MODE == adapter->device_mode) {
5202 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
5203 cds_flush_delayed_work(
5204 &adapter->acs_pending_work);
5205 clear_bit(ACS_PENDING, &adapter->event_flags);
5206 }
5207 }
Krunal Soni22208392017-09-29 18:10:34 -07005208 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005209
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005210 /* Any softap specific cleanup here... */
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305211 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005212 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005213 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005214 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5215
5216 hdd_deregister_tx_flow_control(adapter);
5217
Kapil Guptac1224bf2017-06-22 21:22:40 +05305218 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005219 mutex_lock(&hdd_ctx->sap_lock);
5220 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305221 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05305222 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005223
5224 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005225 status = wlansap_stop_bss(
5226 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005227
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305228 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07005229 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005230 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305231 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305232 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305233 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +05305234 qdf_wait_for_event_completion(
5235 &hostapd_state->qdf_stop_bss_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -08005236 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005237
Anurag Chouhance0dc992016-02-16 18:18:03 +05305238 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005239 hdd_err("failure waiting for wlansap_stop_bss %d",
5240 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005241 }
5242 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07005243 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005244 }
5245 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005246 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
5247 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005248 adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005249 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305250 adapter->device_mode,
5251 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005252
Anurag Chouhanc5548422016-02-24 18:33:27 +05305253 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07005254 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005255 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005256 updateIE.ieBufferlength = 0;
5257 updateIE.pAdditionIEBuffer = NULL;
5258 updateIE.append = false;
5259 updateIE.notify = false;
5260 /* Probe bcn reset */
Jeff Johnson16528362018-06-14 12:34:16 -07005261 if (sme_update_add_ie(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005262 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305263 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005264 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005265 }
5266 /* Assoc resp reset */
Jeff Johnson16528362018-06-14 12:34:16 -07005267 if (sme_update_add_ie(mac_handle,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005268 &updateIE,
5269 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305270 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005271 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005272 }
5273 /* Reset WNI_CFG_PROBE_RSP Flags */
5274 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005275 }
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005276 clear_bit(SOFTAP_INIT_DONE, &adapter->event_flags);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005277 qdf_mem_free(adapter->session.ap.beacon);
5278 adapter->session.ap.beacon = NULL;
Jiachao Wub1e1ddd2018-05-21 12:04:15 +08005279
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305280 /*
5281 * If Do_Not_Break_Stream was enabled clear avoid channel list.
5282 */
5283 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
5284 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
5285
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305286#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005287 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305288#endif
5289
5290#ifdef WLAN_NS_OFFLOAD
5291#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005292 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305293#endif
5294#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08005295
5296 hdd_vdev_destroy(adapter);
5297
Krunal Sonib51eec72017-11-20 21:53:01 -08005298 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005299 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005300 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08005301 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08005302 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07005303 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Zhang Qian79d0d132018-02-05 13:40:16 +08005304 hdd_deregister_tx_flow_control(adapter);
5305 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005306 break;
5307 default:
5308 break;
5309 }
5310
Ajit Pal Singh106c1412018-04-18 18:08:49 +05305311 hdd_deregister_hl_netdev_fc_timer(adapter);
5312
Dustin Brown04348372017-12-14 16:13:39 -08005313 if (adapter->scan_info.default_scan_ies) {
5314 qdf_mem_free(adapter->scan_info.default_scan_ies);
5315 adapter->scan_info.default_scan_ies = NULL;
5316 }
5317
Dustin Browne74003f2018-03-14 12:51:58 -07005318 hdd_exit();
Dustin Brown04348372017-12-14 16:13:39 -08005319
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305320 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005321}
5322
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305323/**
5324 * hdd_deinit_all_adapters - deinit all adapters
5325 * @hdd_ctx: HDD context
5326 * @rtnl_held: True if RTNL lock held
5327 *
5328 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005329void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305330{
Jeff Johnson9d295242017-08-29 14:39:48 -07005331 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305332
Dustin Brown491d54b2018-03-14 12:39:11 -07005333 hdd_enter();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305334
Dustin Brown920397d2017-12-13 16:27:50 -08005335 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305336 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305337
Dustin Browne74003f2018-03-14 12:51:58 -07005338 hdd_exit();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305339}
5340
Dustin Browndb2a8be2017-12-20 11:49:56 -08005341QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005342{
Jeff Johnson9d295242017-08-29 14:39:48 -07005343 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005344
Dustin Brown491d54b2018-03-14 12:39:11 -07005345 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005346
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305347 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5348
Dustin Brown920397d2017-12-13 16:27:50 -08005349 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08005350 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005351
Dustin Browne74003f2018-03-14 12:51:58 -07005352 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005353
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305354 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005355}
5356
Paul Zhang84fa9382017-11-10 21:18:21 +08005357static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
5358 struct hdd_adapter *adapter)
5359{
5360 switch (adapter->device_mode) {
5361 case QDF_STA_MODE:
5362 case QDF_P2P_CLIENT_MODE:
5363 case QDF_IBSS_MODE:
5364 case QDF_P2P_DEVICE_MODE:
5365 case QDF_NDI_MODE:
5366 wlan_hdd_scan_abort(adapter);
5367 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5368 if (adapter->device_mode == QDF_STA_MODE)
5369 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
5370 adapter->dev);
5371 break;
5372 case QDF_P2P_GO_MODE:
5373 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5374 break;
5375 case QDF_SAP_MODE:
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305376 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Paul Zhang84fa9382017-11-10 21:18:21 +08005377 wlan_hdd_undo_acs(adapter);
5378 break;
5379 default:
5380 break;
5381 }
5382}
5383
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005384QDF_STATUS hdd_reset_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;
Jeff Johnsond377dce2017-10-04 10:32:42 -07005387 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07005388 struct qdf_mac_addr peerMacAddr;
Yue Ma42654682018-01-11 16:55:24 -08005389 int sta_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005390
Dustin Brown491d54b2018-03-14 12:39:11 -07005391 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005392
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305393 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5394
Dustin Brown920397d2017-12-13 16:27:50 -08005395 hdd_for_each_adapter(hdd_ctx, adapter) {
Dustin Brown5e89ef82018-03-14 11:50:23 -07005396 hdd_info("[SSR] reset adapter with device mode %s(%d)",
5397 hdd_device_mode_to_string(adapter->device_mode),
5398 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305399
5400 if ((adapter->device_mode == QDF_STA_MODE) ||
Paul Zhang679025e2018-03-08 22:39:44 +08005401 (adapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305402 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07005403 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Paul Zhang679025e2018-03-08 22:39:44 +08005404 adapter->session.station.hdd_reassoc_scenario = false;
5405 }
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305406
Arun Khandavallicc544b32017-01-30 19:52:16 +05305407 if (hdd_ctx->config->sap_internal_restart &&
5408 adapter->device_mode == QDF_SAP_MODE) {
5409 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305410 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05305411 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005412 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08005413 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005414 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005415 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
5416 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305417 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305418 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005419 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005420 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005421
Paul Zhang84fa9382017-11-10 21:18:21 +08005422 hdd_reset_scan_operation(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005423
5424 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005425 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005426 adapter->device_mode, adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005427 hdd_green_ap_start_state_mc(hdd_ctx, adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305428 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005429 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5430 hdd_wmm_adapter_close(adapter);
5431 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5432 }
5433
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305434 if (adapter->device_mode == QDF_STA_MODE)
5435 hdd_clear_fils_connection_info(adapter);
5436
Wu Gao3545e642017-07-14 19:24:41 +08005437 if (adapter->device_mode == QDF_SAP_MODE) {
5438 /*
5439 * If adapter is SAP, set session ID to invalid
5440 * since SAP session will be cleanup during SSR.
5441 */
Wu Gao36717432016-11-21 15:09:48 +08005442 wlansap_set_invalid_session(
5443 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5444
Wu Gao3545e642017-07-14 19:24:41 +08005445 wlansap_cleanup_cac_timer(
5446 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5447 }
5448
Yue Ma42654682018-01-11 16:55:24 -08005449 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005450 if (adapter->device_mode == QDF_STA_MODE ||
5451 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005452 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005453 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07005454 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005455
Yue Ma42654682018-01-11 16:55:24 -08005456 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
Wu Gao6b81fc52018-05-24 19:27:27 +08005457 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Yue Ma42654682018-01-11 16:55:24 -08005458 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5459 if (adapter->sta_info[sta_id].in_use) {
5460 hdd_debug("[SSR] deregister STA with ID %d",
5461 sta_id);
5462 hdd_softap_deregister_sta(adapter,
5463 sta_id);
5464 adapter->sta_info[sta_id].in_use = 0;
5465 }
5466 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005467 }
5468
Alok Kumarb64650c2018-03-23 17:05:11 +05305469 hdd_nud_reset_tracking(adapter);
5470 hdd_nud_ignore_tracking(adapter, true);
5471 hdd_set_disconnect_status(adapter, false);
5472
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005473 hdd_softap_deinit_tx_rx(adapter);
5474
Yue Maf9782842017-05-08 12:49:49 -07005475 /* Destroy vdev which will be recreated during reinit. */
5476 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005477 }
5478
Dustin Browne74003f2018-03-14 12:51:58 -07005479 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005480
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305481 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005482}
5483
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005484bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305485{
Dustin Brown920397d2017-12-13 16:27:50 -08005486 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305487 bool close_modules = true;
5488
Arun Khandavalliba479c42017-07-26 21:29:40 +05305489 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
5490 hdd_info("FTM mode, don't close the module");
5491 return false;
5492 }
5493
Dustin Brown920397d2017-12-13 16:27:50 -08005494 hdd_for_each_adapter(hdd_ctx, adapter) {
5495 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
5496 test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005497 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305498 close_modules = false;
5499 break;
5500 }
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305501 }
5502
5503 return close_modules;
5504}
5505
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305506bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305507{
5508 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5509 return true;
5510 else
5511 return false;
5512}
5513
Anurag Chouhanc4092922016-09-08 15:56:11 +05305514#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08005515 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305516struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5517 struct ieee80211_channel *channel,
5518 const u8 *bssid, const u8 *ssid,
5519 size_t ssid_len)
5520{
5521 return cfg80211_get_bss(wiphy, channel, bssid,
5522 ssid, ssid_len,
5523 WLAN_CAPABILITY_ESS,
5524 WLAN_CAPABILITY_ESS);
5525}
5526#else
5527struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5528 struct ieee80211_channel *channel,
5529 const u8 *bssid, const u8 *ssid,
5530 size_t ssid_len)
5531{
5532 return cfg80211_get_bss(wiphy, channel, bssid,
5533 ssid, ssid_len,
5534 IEEE80211_BSS_TYPE_ESS,
5535 IEEE80211_PRIVACY_ANY);
5536}
5537#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305538
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305539#if defined CFG80211_CONNECT_BSS || \
5540 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305541#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305542 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305543/**
5544 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5545 * @timeout_reason: reason for connect timeout
5546 *
5547 * This function is used to convert host timeout
5548 * reason enum to kernel specific enum.
5549 *
5550 * Return: nl timeout enum
5551 */
5552static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5553 tSirResultCodes timeout_reason)
5554{
5555 switch (timeout_reason) {
5556 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5557 return NL80211_TIMEOUT_SCAN;
5558 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5559 return NL80211_TIMEOUT_AUTH;
5560 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5561 return NL80211_TIMEOUT_ASSOC;
5562 default:
5563 return NL80211_TIMEOUT_UNSPECIFIED;
5564 }
5565}
5566
5567/**
5568 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5569 * @dev: network device
5570 * @bssid: bssid to which we want to associate
5571 * @timeout_reason: reason for connect timeout
5572 *
5573 * This API is used to send connection timeout reason to supplicant
5574 *
5575 * Return: void
5576 */
5577static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5578 const u8 *bssid,
5579 tSirResultCodes timeout_reason)
5580{
5581 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005582
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305583 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5584
5585 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5586 nl_timeout_reason);
5587}
5588
5589/**
5590 * __hdd_connect_bss() - API to send connection status to supplicant
5591 * @dev: network device
5592 * @bssid: bssid to which we want to associate
5593 * @req_ie: Request Information Element
5594 * @req_ie_len: len of the req IE
5595 * @resp_ie: Response IE
5596 * @resp_ie_len: len of ht response IE
5597 * @status: status
5598 * @gfp: Kernel Flag
5599 * @timeout_reason: reason for connect timeout
5600 *
5601 * Return: void
5602 */
5603static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5604 struct cfg80211_bss *bss, const u8 *req_ie,
5605 size_t req_ie_len, const u8 *resp_ie,
5606 size_t resp_ie_len, int status, gfp_t gfp,
5607 tSirResultCodes timeout_reason)
5608{
5609 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005610
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305611 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5612
5613 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5614 resp_ie, resp_ie_len, status, gfp,
5615 nl_timeout_reason);
5616}
5617#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305618#if defined CFG80211_CONNECT_TIMEOUT || \
5619 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305620static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5621 const u8 *bssid,
5622 tSirResultCodes timeout_reason)
5623{
5624 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5625}
5626#endif
5627
5628static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5629 struct cfg80211_bss *bss, const u8 *req_ie,
5630 size_t req_ie_len, const u8 *resp_ie,
5631 size_t resp_ie_len, int status, gfp_t gfp,
5632 tSirResultCodes timeout_reason)
5633{
5634 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5635 resp_ie, resp_ie_len, status, gfp);
5636}
5637#endif
5638
Abhishek Singha84d3952016-09-13 13:45:05 +05305639/**
5640 * hdd_connect_bss() - API to send connection status to supplicant
5641 * @dev: network device
5642 * @bssid: bssid to which we want to associate
5643 * @req_ie: Request Information Element
5644 * @req_ie_len: len of the req IE
5645 * @resp_ie: Response IE
5646 * @resp_ie_len: len of ht response IE
5647 * @status: status
5648 * @gfp: Kernel Flag
5649 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305650 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05305651 *
5652 * The API is a wrapper to send connection status to supplicant
5653 *
5654 * Return: Void
5655 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305656#if defined CFG80211_CONNECT_TIMEOUT || \
5657 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05305658static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5659 struct cfg80211_bss *bss, const u8 *req_ie,
5660 size_t req_ie_len, const u8 *resp_ie,
5661 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305662 bool connect_timeout,
5663 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305664{
5665 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305666 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305667 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305668 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5669 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305670}
5671#else
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,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305676 bool connect_timeout,
5677 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305678{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305679 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5680 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305681}
5682#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305683
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305684#if defined(WLAN_FEATURE_FILS_SK)
5685#if defined(CFG80211_CONNECT_DONE) || \
5686 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
5687#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
5688 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305689/**
5690 * hdd_populate_fils_params() - Populate FILS keys to connect response
5691 * @fils_params: connect response to supplicant
5692 * @fils_kek: FILS kek
5693 * @fils_kek_len: FILS kek length
5694 * @pmk: FILS PMK
5695 * @pmk_len: FILS PMK length
5696 * @pmkid: PMKID
5697 * @fils_seq_num: FILS Seq number
5698 *
5699 * Return: None
5700 */
5701static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5702 *fils_params, const uint8_t *fils_kek,
5703 size_t fils_kek_len, const uint8_t *pmk,
5704 size_t pmk_len, const uint8_t *pmkid,
5705 uint16_t fils_seq_num)
5706{
5707 /* Increament seq number to be used for next FILS */
5708 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
5709 fils_params->update_erp_next_seq_num = true;
5710 fils_params->fils_kek = fils_kek;
5711 fils_params->fils_kek_len = fils_kek_len;
5712 fils_params->pmk = pmk;
5713 fils_params->pmk_len = pmk_len;
5714 fils_params->pmkid = pmkid;
5715}
5716#else
5717static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5718 *fils_params, const uint8_t
5719 *fils_kek, size_t fils_kek_len,
5720 const uint8_t *pmk, size_t pmk_len,
5721 const uint8_t *pmkid,
5722 uint16_t fils_seq_num)
5723{ }
5724#endif
5725
Jeff Johnson172237b2017-11-07 15:32:59 -08005726void hdd_update_hlp_info(struct net_device *dev,
5727 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305728{
5729 struct sk_buff *skb;
5730 uint16_t skb_len;
5731 struct llc_snap_hdr_t *llc_hdr;
5732 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305733 uint8_t *hlp_data;
5734 uint16_t hlp_data_len;
5735 struct fils_join_rsp_params *roam_fils_params
5736 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305737 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
5738
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305739 if (!roam_fils_params) {
5740 hdd_err("FILS Roam Param NULL");
5741 return;
5742 }
5743
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08005744 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305745 hdd_err("FILS HLP Data NULL, len %d",
5746 roam_fils_params->hlp_data_len);
5747 return;
5748 }
5749
5750 hlp_data = roam_fils_params->hlp_data;
5751 hlp_data_len = roam_fils_params->hlp_data_len;
5752
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305753 /* Calculate skb length */
5754 skb_len = (2 * ETH_ALEN) + hlp_data_len;
5755 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
5756 if (skb == NULL) {
5757 hdd_err("HLP packet nbuf alloc fails");
5758 return;
5759 }
5760
5761 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
5762 QDF_MAC_ADDR_SIZE);
5763 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
5764 QDF_MAC_ADDR_SIZE);
5765
5766 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
5767 if (IS_SNAP(llc_hdr)) {
5768 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5769 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5770 }
5771
5772 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
5773
5774 /*
5775 * This HLP packet is formed from HLP info encapsulated
5776 * in assoc response frame which is AEAD encrypted.
5777 * Hence, this checksum validation can be set unnecessary.
5778 * i.e. network layer need not worry about checksum.
5779 */
5780 skb->ip_summed = CHECKSUM_UNNECESSARY;
5781
5782 status = hdd_rx_packet_cbk(padapter, skb);
5783 if (QDF_IS_STATUS_ERROR(status)) {
5784 hdd_err("Sending HLP packet fails");
5785 return;
5786 }
5787 hdd_debug("send HLP packet to netif successfully");
5788}
5789
5790/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305791 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
5792 * @dev: network device
5793 * @bssid: bssid to which we want to associate
5794 * @bss: cfg80211 bss info
5795 * @roam_info: information about connected bss
5796 * @req_ie: Request Information Element
5797 * @req_ie_len: len of the req IE
5798 * @resp_ie: Response IE
5799 * @resp_ie_len: len of ht response IE
5800 * @status: status
5801 * @gfp: allocation flags
5802 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5803 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305804 *
5805 * This API is used as wrapper to send FILS key/sequence number
5806 * params etc. to supplicant in case of FILS connection
5807 *
5808 * Return: None
5809 */
5810static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005811 struct cfg80211_bss *bss,
5812 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305813 const u8 *req_ie, size_t req_ie_len,
5814 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005815 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305816 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305817{
5818 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305819 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5820 struct fils_join_rsp_params *roam_fils_params =
5821 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005822
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305823 qdf_mem_zero(&fils_params, sizeof(fils_params));
5824
5825 if (!roam_fils_params) {
5826 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5827 } else {
5828 fils_params.status = status;
5829 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08005830 fils_params.timeout_reason =
5831 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305832 fils_params.req_ie = req_ie;
5833 fils_params.req_ie_len = req_ie_len;
5834 fils_params.resp_ie = resp_ie;
5835 fils_params.resp_ie_len = resp_ie_len;
5836 fils_params.bss = bss;
5837 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5838 roam_fils_params->kek_len,
5839 roam_fils_params->fils_pmk,
5840 roam_fils_params->fils_pmk_len,
5841 roam_fils_params->fils_pmkid,
5842 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305843 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305844 }
5845 hdd_debug("FILS indicate connect status %d seq no %d",
5846 fils_params.status,
5847 fils_params.fils_erp_next_seq_num);
5848
5849 cfg80211_connect_done(dev, &fils_params, gfp);
5850
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305851 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305852 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305853
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305854 /* Clear all the FILS key info */
5855 if (roam_fils_params && roam_fils_params->fils_pmk)
5856 qdf_mem_free(roam_fils_params->fils_pmk);
5857 if (roam_fils_params)
5858 qdf_mem_free(roam_fils_params);
5859 roam_info->fils_join_rsp = NULL;
5860}
5861#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005862static inline void
5863hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005864 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005865 const u8 *req_ie, size_t req_ie_len,
5866 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5867 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305868 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305869{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305870#endif
5871#endif
5872
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305873#if defined(WLAN_FEATURE_FILS_SK) && \
5874 (defined(CFG80211_CONNECT_DONE) || \
5875 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305876/**
5877 * hdd_fils_update_connect_results() - API to send fils connection status to
5878 * supplicant.
5879 * @dev: network device
5880 * @bssid: bssid to which we want to associate
5881 * @bss: cfg80211 bss info
5882 * @roam_info: information about connected bss
5883 * @req_ie: Request Information Element
5884 * @req_ie_len: len of the req IE
5885 * @resp_ie: Response IE
5886 * @resp_ie_len: len of ht response IE
5887 * @status: status
5888 * @gfp: allocation flags
5889 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5890 * @timeout_reason: reason for connect timeout
5891 *
5892 * The API is a wrapper to send connection status to supplicant
5893 *
5894 * Return: 0 if success else failure
5895 */
5896static int hdd_fils_update_connect_results(struct net_device *dev,
5897 const u8 *bssid,
5898 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005899 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305900 size_t req_ie_len, const u8 *resp_ie,
5901 size_t resp_ie_len, u16 status, gfp_t gfp,
5902 bool connect_timeout,
5903 tSirResultCodes timeout_reason)
5904{
Dustin Brown491d54b2018-03-14 12:39:11 -07005905 hdd_enter();
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305906 if (!roam_info || !roam_info->is_fils_connection)
5907 return -EINVAL;
5908
5909 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5910 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305911 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305912 return 0;
5913}
5914#else
5915static inline int hdd_fils_update_connect_results(struct net_device *dev,
5916 const u8 *bssid,
5917 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005918 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305919 size_t req_ie_len, const u8 *resp_ie,
5920 size_t resp_ie_len, u16 status, gfp_t gfp,
5921 bool connect_timeout,
5922 tSirResultCodes timeout_reason)
5923{
5924 return -EINVAL;
5925}
5926#endif
5927
Anurag Chouhanc4092922016-09-08 15:56:11 +05305928/**
5929 * hdd_connect_result() - API to send connection status to supplicant
5930 * @dev: network device
5931 * @bssid: bssid to which we want to associate
5932 * @roam_info: information about connected bss
5933 * @req_ie: Request Information Element
5934 * @req_ie_len: len of the req IE
5935 * @resp_ie: Response IE
5936 * @resp_ie_len: len of ht response IE
5937 * @status: status
5938 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305939 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305940 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305941 *
5942 * The API is a wrapper to send connection status to supplicant
5943 * and allow runtime suspend
5944 *
5945 * Return: Void
5946 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305947void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005948 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305949 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305950 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305951 bool connect_timeout,
5952 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305953{
Jeff Johnson9d295242017-08-29 14:39:48 -07005954 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305955 struct cfg80211_bss *bss = NULL;
Jingxiang Ge929c7932018-01-24 14:01:12 +08005956 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305957
5958 if (WLAN_STATUS_SUCCESS == status) {
5959 struct ieee80211_channel *chan;
5960 int freq;
5961 int chan_no = roam_info->pBssDesc->channelId;
5962
5963 if (chan_no <= 14)
5964 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005965 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305966 else
5967 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005968 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305969
5970 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5971 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5972 roam_info->u.pConnectedProfile->SSID.ssId,
5973 roam_info->u.pConnectedProfile->SSID.length);
5974 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305975
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305976 if (hdd_fils_update_connect_results(dev, bssid, bss,
5977 roam_info, req_ie, req_ie_len, resp_ie,
5978 resp_ie_len, status, gfp, connect_timeout,
5979 timeout_reason) != 0) {
5980 hdd_connect_bss(dev, bssid, bss, req_ie,
5981 req_ie_len, resp_ie, resp_ie_len,
5982 status, gfp, connect_timeout, timeout_reason);
5983 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305984
Jingxiang Geb49aa302018-01-17 20:54:15 +08005985 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005986 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305987}
5988#else
5989void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005990 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305991 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305992 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305993 bool connect_timeout,
5994 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305995{
Jeff Johnson9d295242017-08-29 14:39:48 -07005996 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Jingxiang Ge929c7932018-01-24 14:01:12 +08005997 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05305998
Anurag Chouhanc4092922016-09-08 15:56:11 +05305999 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
6000 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08006001
Jingxiang Geb49aa302018-01-17 20:54:15 +08006002 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07006003 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05306004}
6005#endif
6006
Nirav Shah73713f72018-05-17 14:50:41 +05306007#ifdef FEATURE_MONITOR_MODE_SUPPORT
Jeff Johnsond9952752018-04-18 12:15:35 -07006008int wlan_hdd_set_mon_chan(struct hdd_adapter *adapter, uint32_t chan,
6009 uint32_t bandwidth)
6010{
6011 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6012 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
6013 struct hdd_mon_set_ch_info *ch_info = &sta_ctx->ch_info;
6014 QDF_STATUS status;
Jeff Johnsond9952752018-04-18 12:15:35 -07006015 struct qdf_mac_addr bssid;
6016 struct csr_roam_profile roam_profile;
6017 struct ch_params ch_params;
6018
6019 if (QDF_GLOBAL_MONITOR_MODE != hdd_get_conparam()) {
6020 hdd_err("Not supported, device is not in monitor mode");
6021 return -EINVAL;
6022 }
6023
Visweswara Tanuku006313a2018-04-12 12:26:34 +05306024 /* Validate Channel */
6025 if (!WLAN_REG_IS_24GHZ_CH(chan) && !WLAN_REG_IS_5GHZ_CH(chan)) {
6026 hdd_err("Channel %d Not supported", chan);
6027 return -EINVAL;
6028 }
6029
6030 if (WLAN_REG_IS_24GHZ_CH(chan)) {
6031 if (bandwidth == CH_WIDTH_80MHZ) {
6032 hdd_err("BW80 not possible in 2.4GHz band");
6033 return -EINVAL;
6034 }
6035 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 14) &&
6036 (bandwidth != CH_WIDTH_MAX)) {
6037 hdd_err("Only BW20 possible on channel 14");
6038 return -EINVAL;
6039 }
6040 }
6041
6042 if (WLAN_REG_IS_5GHZ_CH(chan)) {
6043 if ((bandwidth != CH_WIDTH_20MHZ) && (chan == 165) &&
6044 (bandwidth != CH_WIDTH_MAX)) {
6045 hdd_err("Only BW20 possible on channel 165");
6046 return -EINVAL;
6047 }
6048 }
6049
Jeff Johnsond9952752018-04-18 12:15:35 -07006050 hdd_debug("Set monitor mode Channel %d", chan);
6051 qdf_mem_zero(&roam_profile, sizeof(roam_profile));
6052 roam_profile.ChannelInfo.ChannelList = &ch_info->channel;
6053 roam_profile.ChannelInfo.numOfChannels = 1;
6054 roam_profile.phyMode = ch_info->phy_mode;
6055 roam_profile.ch_params.ch_width = bandwidth;
6056 hdd_select_cbmode(adapter, chan, &roam_profile.ch_params);
6057
6058 qdf_mem_copy(bssid.bytes, adapter->mac_addr.bytes,
6059 QDF_MAC_ADDR_SIZE);
6060
6061 ch_params.ch_width = bandwidth;
6062 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev, chan, 0, &ch_params);
6063 if (ch_params.ch_width == CH_WIDTH_INVALID) {
6064 hdd_err("Invalid capture channel or bandwidth for a country");
6065 return -EINVAL;
6066 }
6067 if (wlan_hdd_change_hw_mode_for_given_chnl(adapter, chan,
6068 POLICY_MGR_UPDATE_REASON_SET_OPER_CHAN)) {
6069 hdd_err("Failed to change hw mode");
6070 return -EINVAL;
6071 }
6072
Jeff Johnson16528362018-06-14 12:34:16 -07006073 status = sme_roam_channel_change_req(hdd_ctx->mac_handle,
6074 bssid, &ch_params,
Jeff Johnsond9952752018-04-18 12:15:35 -07006075 &roam_profile);
6076 if (status) {
6077 hdd_err("Status: %d Failed to set sme_roam Channel for monitor mode",
6078 status);
6079 }
6080
6081 adapter->mon_chan = chan;
6082 adapter->mon_bandwidth = bandwidth;
6083 return qdf_status_to_os_return(status);
6084}
Nirav Shah73713f72018-05-17 14:50:41 +05306085#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05306086
Wu Gaodf929f12018-05-25 18:12:25 +08006087#ifdef MSM_PLATFORM
6088/**
6089 * hdd_stop_p2p_go() - call cfg80211 API to stop P2P GO
6090 * @adapter: pointer to adapter
6091 *
6092 * This function calls cfg80211 API to stop P2P GO
6093 *
6094 * Return: None
6095 */
6096static void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6097{
6098 hdd_debug("[SSR] send stop ap to supplicant");
6099 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
6100}
6101
6102static inline void hdd_delete_sta(struct hdd_adapter *adapter)
6103{
6104}
6105#else
6106static inline void hdd_stop_p2p_go(struct hdd_adapter *adapter)
6107{
6108}
6109
6110/**
6111 * hdd_delete_sta() - call cfg80211 API to delete STA
6112 * @adapter: pointer to adapter
6113 *
6114 * This function calls cfg80211 API to delete STA
6115 *
6116 * Return: None
6117 */
6118static void hdd_delete_sta(struct hdd_adapter *adapter)
6119{
6120 struct qdf_mac_addr bcast_mac = QDF_MAC_ADDR_BCAST_INIT;
6121
6122 hdd_debug("[SSR] send restart supplicant");
6123 /* event supplicant to restart */
6124 cfg80211_del_sta(adapter->dev,
6125 (const u8 *)&bcast_mac.bytes[0],
6126 GFP_KERNEL);
6127}
6128#endif
6129
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006130QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006131{
Jeff Johnson9d295242017-08-29 14:39:48 -07006132 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006133 eConnectionState connState;
6134
Dustin Brown491d54b2018-03-14 12:39:11 -07006135 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006136
Dustin Brown920397d2017-12-13 16:27:50 -08006137 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05306138 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08006139 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05306140
Yue Ma42654682018-01-11 16:55:24 -08006141 hdd_debug("[SSR] start adapter with device mode %s(%d)",
6142 hdd_device_mode_to_string(adapter->device_mode),
6143 adapter->device_mode);
6144
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006145 hdd_wmm_init(adapter);
6146
6147 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006148 case QDF_STA_MODE:
6149 case QDF_P2P_CLIENT_MODE:
6150 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006151
6152 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
6153 ->conn_info.connState;
6154
Krunal Sonib51eec72017-11-20 21:53:01 -08006155 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006156 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07006157 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006158
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006159 /* Indicate disconnect event to supplicant
6160 * if associated previously
6161 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006162 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07006163 eConnectionState_IbssConnected == connState ||
6164 eConnectionState_NotConnected == connState ||
6165 eConnectionState_IbssDisconnected == connState ||
6166 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006167 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006168
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006169 memset(&wrqu, '\0', sizeof(wrqu));
6170 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
6171 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
6172 wireless_send_event(adapter->dev, SIOCGIWAP,
6173 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07006174 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07006175 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006176
6177 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05306178 wlan_hdd_cfg80211_indicate_disconnect(
6179 adapter->dev, false,
6180 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006181 } else if (eConnectionState_Connecting == connState) {
6182 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006183 * Indicate connect failure to supplicant if we
6184 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006185 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05306186 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05306187 NULL, 0, NULL, 0,
6188 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006189 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006190 }
6191
6192 hdd_register_tx_flow_control(adapter,
6193 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08006194 hdd_tx_resume_cb,
6195 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006196
Alok Kumarb64650c2018-03-23 17:05:11 +05306197 hdd_nud_ignore_tracking(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006198 break;
6199
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006200 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006201 if (hdd_ctx->config->sap_internal_restart)
Krunal Sonib51eec72017-11-20 21:53:01 -08006202 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05306203
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006204 break;
6205
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006206 case QDF_P2P_GO_MODE:
Wu Gaodf929f12018-05-25 18:12:25 +08006207 hdd_delete_sta(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006208 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306209 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08006210 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05306211 hdd_set_mon_rx_cb(adapter->dev);
6212 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
6213 adapter->mon_bandwidth);
6214 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006215 default:
6216 break;
6217 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07006218 /*
6219 * Action frame registered in one adapter which will
6220 * applicable to all interfaces
6221 */
6222 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006223 }
6224
Wu Gaodf929f12018-05-25 18:12:25 +08006225 hdd_for_each_adapter(hdd_ctx, adapter) {
6226 if (!hdd_is_interface_up(adapter))
6227 continue;
6228
6229 if (adapter->device_mode == QDF_P2P_GO_MODE)
6230 hdd_stop_p2p_go(adapter);
6231 }
6232
Dustin Browne74003f2018-03-14 12:51:58 -07006233 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006234
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306235 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006236}
6237
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006238QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006239 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006240{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306241 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006242 qdf_list_node_t *node;
6243
6244 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006245
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006246 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006247 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006248 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006249
6250 if (QDF_IS_STATUS_ERROR(status))
6251 return status;
6252
6253 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6254
6255 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006256}
6257
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006258QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006259 struct hdd_adapter *current_adapter,
6260 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006261{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306262 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006263 qdf_list_node_t *node;
6264
6265 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006266
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006267 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006268 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08006269 &current_adapter->node,
6270 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006271 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006272
6273 if (QDF_IS_STATUS_ERROR(status))
6274 return status;
6275
6276 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6277
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006278 return status;
6279}
6280
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006281QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006282 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006283{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306284 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006285
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006286 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006287 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006288 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006289
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006290 return status;
6291}
6292
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006293QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006294 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006295{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306296 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006297 qdf_list_node_t *node;
6298
6299 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006300
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006301 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006302 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006303 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006304
6305 if (QDF_IS_STATUS_ERROR(status))
6306 return status;
6307
6308 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6309
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006310 return status;
6311}
6312
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006313QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006314 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006315{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306316 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006317
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006318 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006319 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006320 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006321
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006322 return status;
6323}
6324
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006325QDF_STATUS hdd_add_adapter_front(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 Chouhanfb54ab02016-02-18 18:00:46 +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_insert_front(&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 Johnson9d295242017-08-29 14:39:48 -07006337struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006338 tSirMacAddr macAddr)
6339{
Jeff Johnson9d295242017-08-29 14:39:48 -07006340 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006341
Dustin Brown920397d2017-12-13 16:27:50 -08006342 hdd_for_each_adapter(hdd_ctx, adapter) {
6343 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
6344 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006345 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006346 }
6347
6348 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006349}
6350
Jeff Johnson9d295242017-08-29 14:39:48 -07006351struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006352 uint32_t vdev_id)
6353{
Jeff Johnson9d295242017-08-29 14:39:48 -07006354 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006355
Dustin Brown920397d2017-12-13 16:27:50 -08006356 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07006357 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006358 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006359 }
6360
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006361 return NULL;
6362}
6363
Abhishek Singh7996eb72015-12-30 17:24:02 +05306364/**
6365 * hdd_get_adapter_by_sme_session_id() - Return adapter with
6366 * the sessionid
6367 * @hdd_ctx: hdd context.
6368 * @sme_session_id: sme session is for the adapter to get.
6369 *
6370 * This function is used to get the adapter with provided session id
6371 *
6372 * Return: adapter pointer if found
6373 *
6374 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07006375struct hdd_adapter *
6376hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
6377 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306378{
Jeff Johnson9d295242017-08-29 14:39:48 -07006379 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306380
Dustin Brown920397d2017-12-13 16:27:50 -08006381 hdd_for_each_adapter(hdd_ctx, adapter) {
6382 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306383 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306384 }
Dustin Brown920397d2017-12-13 16:27:50 -08006385
Abhishek Singh7996eb72015-12-30 17:24:02 +05306386 return NULL;
6387}
6388
Jeff Johnson9d295242017-08-29 14:39:48 -07006389struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07006390 const char *iface_name)
6391{
Jeff Johnson9d295242017-08-29 14:39:48 -07006392 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006393
Dustin Brown920397d2017-12-13 16:27:50 -08006394 hdd_for_each_adapter(hdd_ctx, adapter) {
6395 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07006396 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006397 }
Dustin Brown920397d2017-12-13 16:27:50 -08006398
Naveen Rawat4edb6822017-04-12 10:09:17 -07006399 return NULL;
6400}
6401
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006402/**
6403 * hdd_get_adapter() - to get adapter matching the mode
6404 * @hdd_ctx: hdd context
6405 * @mode: adapter mode
6406 *
6407 * This routine will return the pointer to adapter matching
6408 * with the passed mode.
6409 *
6410 * Return: pointer to adapter or null
6411 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006412struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006413 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006414{
Jeff Johnson9d295242017-08-29 14:39:48 -07006415 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006416
Dustin Brown920397d2017-12-13 16:27:50 -08006417 hdd_for_each_adapter(hdd_ctx, adapter) {
6418 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006419 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006420 }
6421
6422 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006423}
6424
Jeff Johnson36a0abf2018-05-20 11:24:25 -07006425enum QDF_OPMODE hdd_get_device_mode(uint32_t session_id)
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306426{
6427 struct hdd_context *hdd_ctx;
6428 struct hdd_adapter *adapter;
6429
6430 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
6431 if (!hdd_ctx) {
6432 hdd_err("Invalid HDD context");
6433 return QDF_MAX_NO_OF_MODE;
6434 }
6435
6436 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
6437 if (!adapter) {
6438 hdd_err("Invalid HDD adapter");
6439 return QDF_MAX_NO_OF_MODE;
6440 }
6441
6442 return adapter->device_mode;
6443}
6444
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006445/**
6446 * hdd_get_operating_channel() - return operating channel of the device mode
6447 * @hdd_ctx: Pointer to the HDD context.
6448 * @mode: Device mode for which operating channel is required.
Jeff Johnson77f89bb2018-05-06 16:21:36 -07006449 * Supported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006450 * QDF_STA_MODE,
6451 * QDF_P2P_CLIENT_MODE,
6452 * QDF_SAP_MODE,
6453 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006454 *
6455 * This API returns the operating channel of the requested device mode
6456 *
6457 * Return: channel number. "0" id the requested device is not found OR it is
6458 * not connected.
6459 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006460uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006461 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006462{
Jeff Johnson9d295242017-08-29 14:39:48 -07006463 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006464 uint8_t operatingChannel = 0;
6465
Dustin Brown920397d2017-12-13 16:27:50 -08006466 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006467 if (mode == adapter->device_mode) {
6468 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006469 case QDF_STA_MODE:
6470 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006471 if (hdd_conn_is_connected
6472 (WLAN_HDD_GET_STATION_CTX_PTR
6473 (adapter))) {
6474 operatingChannel =
6475 (WLAN_HDD_GET_STATION_CTX_PTR
6476 (adapter))->conn_info.
6477 operationChannel;
6478 }
6479 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006480 case QDF_SAP_MODE:
6481 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006482 /* softap connection info */
6483 if (test_bit
6484 (SOFTAP_BSS_STARTED,
6485 &adapter->event_flags))
6486 operatingChannel =
6487 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07006488 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006489 break;
6490 default:
6491 break;
6492 }
6493
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006494 /* Found the device of interest. break the loop */
6495 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006496 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006497 }
Dustin Brown920397d2017-12-13 16:27:50 -08006498
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006499 return operatingChannel;
6500}
6501
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006502static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006503 hdd_ctx)
6504{
Jeff Johnson9d295242017-08-29 14:39:48 -07006505 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006506
Dustin Brown491d54b2018-03-14 12:39:11 -07006507 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006508
Dustin Brown920397d2017-12-13 16:27:50 -08006509 hdd_for_each_adapter(hdd_ctx, adapter) {
6510 if (adapter->device_mode == QDF_STA_MODE ||
6511 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6512 adapter->device_mode == QDF_IBSS_MODE ||
6513 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6514 adapter->device_mode == QDF_SAP_MODE ||
6515 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006516 hdd_unregister_wext(adapter->dev);
6517 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006518 }
6519
Dustin Browne74003f2018-03-14 12:51:58 -07006520 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006521
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306522 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006523}
6524
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006525QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006526{
Jeff Johnson9d295242017-08-29 14:39:48 -07006527 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006528
Dustin Brown491d54b2018-03-14 12:39:11 -07006529 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006530
Dustin Brown920397d2017-12-13 16:27:50 -08006531 hdd_for_each_adapter(hdd_ctx, adapter) {
6532 if (adapter->device_mode == QDF_STA_MODE ||
6533 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6534 adapter->device_mode == QDF_IBSS_MODE ||
6535 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6536 adapter->device_mode == QDF_SAP_MODE ||
6537 adapter->device_mode == QDF_P2P_GO_MODE) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006538 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006539 adapter->session_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05306540 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006541 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006542 }
6543
Dustin Browne74003f2018-03-14 12:51:58 -07006544 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006545
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306546 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006547}
6548
Dustin Brownf27bce82016-11-03 12:52:27 -07006549/**
6550 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
6551 * adapters
6552 * @hdd_ctx: The HDD context containing the adapters to operate on
6553 *
6554 * return: QDF_STATUS_SUCCESS
6555 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006556static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07006557{
Jeff Johnson9d295242017-08-29 14:39:48 -07006558 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07006559 int err;
6560
Dustin Brown491d54b2018-03-14 12:39:11 -07006561 hdd_enter();
Dustin Brownf27bce82016-11-03 12:52:27 -07006562
Dustin Brown920397d2017-12-13 16:27:50 -08006563 hdd_for_each_adapter(hdd_ctx, adapter) {
6564 if (adapter->device_mode == QDF_STA_MODE ||
6565 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6566 adapter->device_mode == QDF_IBSS_MODE ||
6567 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6568 adapter->device_mode == QDF_SAP_MODE ||
6569 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07006570 err = wlan_hdd_sched_scan_stop(adapter->dev);
6571 if (err)
6572 hdd_err("Unable to stop scheduled scan");
6573 }
Dustin Brownf27bce82016-11-03 12:52:27 -07006574 }
6575
Dustin Browne74003f2018-03-14 12:51:58 -07006576 hdd_exit();
Dustin Brownf27bce82016-11-03 12:52:27 -07006577
6578 return QDF_STATUS_SUCCESS;
6579}
6580
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006581#ifdef WLAN_NS_OFFLOAD
6582/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006583 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006584 * @hdd_ctx: Pointer to hdd context
6585 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006586 * Unregister for IPv6 address change notifications.
6587 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006588 * Return: None
6589 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006590static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006591{
6592 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006593}
6594
6595/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006596 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006597 * @hdd_ctx: Pointer to hdd context
6598 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006599 * Register for IPv6 address change notifications.
6600 *
6601 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006602 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006603static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006604{
6605 int ret;
6606
6607 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
6608 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006609 if (ret) {
6610 hdd_err("Failed to register IPv6 notifier: %d", ret);
6611 goto out;
6612 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006613
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006614 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006615out:
6616 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006617}
6618#else
6619/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006620 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006621 * @hdd_ctx: Pointer to hdd context
6622 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006623 * Unregister for IPv6 address change notifications.
6624 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006625 * Return: None
6626 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006627static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006628{
6629}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006630
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006631/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006632 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006633 * @hdd_ctx: Pointer to hdd context
6634 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006635 * Register for IPv6 address change notifications.
6636 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006637 * Return: None
6638 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006639static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006640{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006641 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006642}
6643#endif
6644
Alok Kumarb64650c2018-03-23 17:05:11 +05306645void hdd_set_disconnect_status(struct hdd_adapter *adapter, bool status)
6646{
6647 qdf_mutex_acquire(&adapter->disconnection_status_lock);
6648 adapter->disconnection_in_progress = status;
6649 qdf_mutex_release(&adapter->disconnection_status_lock);
6650 hdd_debug("setting disconnection status: %d", status);
6651}
6652
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006653/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006654 * hdd_register_notifiers - Register netdev notifiers.
6655 * @hdd_ctx: HDD context
6656 *
6657 * Register netdev notifiers like IPv4 and IPv6.
6658 *
6659 * Return: 0 on success and errno on failure
6660 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006661static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006662{
6663 int ret;
6664
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006665 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
6666 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306667 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006668
6669 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
6670 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
6671 if (ret) {
6672 hdd_err("Failed to register IPv4 notifier: %d", ret);
6673 goto unregister_ip6_notifier;
6674 }
6675
Alok Kumarb64650c2018-03-23 17:05:11 +05306676 ret = hdd_nud_register_netevent_notifier(hdd_ctx);
6677 if (ret) {
6678 hdd_err("Failed to register netevent notifier: %d",
6679 ret);
6680 goto unregister_inetaddr_notifier;
6681 }
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006682 return 0;
6683
Alok Kumarb64650c2018-03-23 17:05:11 +05306684unregister_inetaddr_notifier:
6685 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006686unregister_ip6_notifier:
6687 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006688out:
6689 return ret;
6690
6691}
6692
6693/**
6694 * hdd_unregister_notifiers - Unregister netdev notifiers.
6695 * @hdd_ctx: HDD context
6696 *
6697 * Unregister netdev notifiers like IPv4 and IPv6.
6698 *
6699 * Return: None.
6700 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006701void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006702{
Alok Kumarb64650c2018-03-23 17:05:11 +05306703 hdd_nud_unregister_netevent_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006704 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
6705
6706 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006707}
6708
6709/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006710 * hdd_exit_netlink_services - Exit netlink services
6711 * @hdd_ctx: HDD context
6712 *
6713 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
6714 * nl service.
6715 *
6716 * Return: None.
6717 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006718static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006719{
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306720 spectral_scan_deactivate_service();
6721 cnss_diag_deactivate_service();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006722 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006723 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306724 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006725
6726 nl_srv_exit();
6727}
6728
6729/**
6730 * hdd_init_netlink_services- Init netlink services
6731 * @hdd_ctx: HDD context
6732 *
6733 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
6734 * nl service.
6735 *
6736 * Return: 0 on success and errno on failure.
6737 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006738static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006739{
6740 int ret;
6741
Ryan Hsuceddceb2016-04-28 10:20:14 -07006742 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006743 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006744 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006745 goto out;
6746 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07006747 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006748
Naveen Rawat910726a2017-03-06 11:42:51 -08006749 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006750 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006751 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006752 goto err_nl_srv;
6753 }
6754
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306755 ptt_sock_activate_svc();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006756
6757 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07006758 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006759 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006760
6761 ret = cnss_diag_activate_service();
6762 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006763 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006764 goto err_close_cesium;
6765 }
6766
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306767 spectral_scan_activate_service();
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08006768
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006769 return 0;
6770
6771err_close_cesium:
6772 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006773 ptt_sock_deactivate_svc();
Vignesh Viswanathana1cb4b42018-05-17 21:19:27 +05306774 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006775err_nl_srv:
6776 nl_srv_exit();
6777out:
6778 return ret;
6779}
6780
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006781/**
6782 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
6783 * @hdd_ctx: HDD context.
6784 *
6785 * Destroy RX wakelock.
6786 *
6787 * Return: None.
6788 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006789static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006790{
6791 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
6792}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006793
6794/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006795 * hdd_rx_wake_lock_create() - Create RX wakelock
6796 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006797 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006798 * Create RX wakelock.
6799 *
6800 * Return: None.
6801 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006802static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006803{
6804 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
6805}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006806
6807/**
Houston Hoffman160db392016-10-10 17:37:51 -07006808 * hdd_context_deinit() - Deinitialize HDD context
6809 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006810 *
Houston Hoffman160db392016-10-10 17:37:51 -07006811 * Deinitialize HDD context along with all the feature specific contexts but
6812 * do not free hdd context itself. Caller of this API is supposed to free
6813 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006814 *
Houston Hoffman160db392016-10-10 17:37:51 -07006815 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006816 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006817static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006818{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306819 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
6820
Houston Hoffman160db392016-10-10 17:37:51 -07006821 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006822
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006823 hdd_sap_context_destroy(hdd_ctx);
6824
6825 hdd_rx_wake_lock_destroy(hdd_ctx);
6826
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006827 hdd_scan_context_destroy(hdd_ctx);
6828
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006829 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006830
Nachiket Kukade177b5b02018-05-22 20:52:17 +05306831 hdd_apf_context_destroy();
6832
Houston Hoffman160db392016-10-10 17:37:51 -07006833 return 0;
6834}
6835
6836/**
6837 * hdd_context_destroy() - Destroy HDD context
6838 * @hdd_ctx: HDD context to be destroyed.
6839 *
6840 * Free config and HDD context as well as destroy all the resources.
6841 *
6842 * Return: None
6843 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006844static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07006845{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07006846 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05306847
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05306848 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
6849
Houston Hoffman160db392016-10-10 17:37:51 -07006850 hdd_context_deinit(hdd_ctx);
6851
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306852 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006853 hdd_ctx->config = NULL;
6854
Dustin Brown84f46ea2018-02-15 11:57:36 -08006855 cfg_release();
6856
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006857 wiphy_free(hdd_ctx->wiphy);
6858}
6859
6860/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306861 * wlan_destroy_bug_report_lock() - Destroy bug report lock
6862 *
6863 * This function is used to destroy bug report lock
6864 *
6865 * Return: None
6866 */
6867static void wlan_destroy_bug_report_lock(void)
6868{
Jeff Johnson2b6982c2018-05-29 14:56:11 -07006869 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306870
6871 p_cds_context = cds_get_global_context();
6872 if (!p_cds_context) {
6873 hdd_err("cds context is NULL");
6874 return;
6875 }
6876
6877 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6878}
6879
6880/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006881 * hdd_wlan_exit() - HDD WLAN exit function
6882 * @hdd_ctx: Pointer to the HDD Context
6883 *
6884 * This is the driver exit point (invoked during rmmod)
6885 *
6886 * Return: None
6887 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006888static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006889{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006890 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306891 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006892
Dustin Brown491d54b2018-03-14 12:39:11 -07006893 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006894
Arun Khandavallifae92942016-08-01 13:31:08 +05306895 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006896
Prashanth Bhattaab004382016-10-11 16:08:11 -07006897 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006898
6899#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306900 if (QDF_TIMER_STATE_RUNNING ==
6901 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6902 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006903 }
6904
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306905 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306906 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006907 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006908 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006909 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6910 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6911 hdd_ctx->last_acs_channel_list = NULL;
6912 hdd_ctx->num_of_channels = 0;
6913 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006914#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006915
Arun Khandavallifae92942016-08-01 13:31:08 +05306916 mutex_lock(&hdd_ctx->iface_change_lock);
6917 driver_status = hdd_ctx->driver_status;
6918 mutex_unlock(&hdd_ctx->iface_change_lock);
6919
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006920 /*
6921 * Powersave Offload Case
6922 * Disable Idle Power Save Mode
6923 */
6924 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07006925 /* clear the scan queue in all the scenarios */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +05306926 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006927
Arun Khandavallifae92942016-08-01 13:31:08 +05306928 if (driver_status != DRIVER_MODULES_CLOSED) {
6929 hdd_unregister_wext_all_adapters(hdd_ctx);
6930 /*
6931 * Cancel any outstanding scan requests. We are about to close
6932 * all of our adapters, but an adapter structure is what SME
6933 * passes back to our callback function. Hence if there
6934 * are any outstanding scan requests then there is a
6935 * race condition between when the adapter is closed and
6936 * when the callback is invoked. We try to resolve that
6937 * race condition here by canceling any outstanding scans
6938 * before we close the adapters.
6939 * Note that the scans may be cancelled in an asynchronous
6940 * manner, so ideally there needs to be some kind of
6941 * synchronization. Rather than introduce a new
6942 * synchronization here, we will utilize the fact that we are
6943 * about to Request Full Power, and since that is synchronized,
6944 * the expectation is that by the time Request Full Power has
6945 * completed, all scans will be cancelled
6946 */
6947 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006948 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08006949 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08006950 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006951 }
6952
Arunk Khandavalli830c9692018-03-22 12:17:40 +05306953 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306954 unregister_netdevice_notifier(&hdd_netdev_notifier);
6955
Rachit Kankane30807332018-06-27 18:39:36 +05306956 qdf_dp_trace_deinit();
6957
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006958 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306959
Dustin Brown021cecd2017-12-11 13:56:43 -08006960 hdd_driver_memdump_deinit();
6961
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306962 qdf_nbuf_deinit_replenish_timer();
6963
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306964 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
6965 hdd_info("Release wakelock for monitor mode!");
6966 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
6967 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
6968 }
6969
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306970 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6971 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6972 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6973
Naveen Rawate02f8f52018-04-05 11:58:04 -07006974 osif_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006975
Dustin Brownd005ad82018-01-19 10:32:13 -08006976 hdd_close_all_adapters(hdd_ctx, false);
6977
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306978 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306979 /*
6980 * If there is re_init failure wiphy would have already de-registered
6981 * check the wiphy status before un-registering again
6982 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306983 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306984 wiphy_unregister(wiphy);
6985 wlan_hdd_cfg80211_deinit(wiphy);
6986 hdd_lpass_notify_stop(hdd_ctx);
6987 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006988
Arun Khandavallifae92942016-08-01 13:31:08 +05306989 hdd_exit_netlink_services(hdd_ctx);
6990 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306991#ifdef FEATURE_WLAN_CH_AVOID
6992 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6993#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306994
Abhishek Singhe9068f12017-03-31 14:14:52 +05306995 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6996 if (driver_status)
6997 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006998
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006999 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007000}
7001
7002void __hdd_wlan_exit(void)
7003{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007004 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007005
Dustin Brown491d54b2018-03-14 12:39:11 -07007006 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007007
Anurag Chouhan6d760662016-02-20 16:05:43 +05307008 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007009 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007010 hdd_err("Invalid HDD Context");
Dustin Browne74003f2018-03-14 12:51:58 -07007011 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007012 return;
7013 }
7014
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007015 /* Do all the cleanup before deregistering the driver */
7016 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07007017
Dustin Browne74003f2018-03-14 12:51:58 -07007018 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007019}
7020
7021#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04007022/**
7023 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007024 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04007025 *
7026 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
7027 * Then new ACS request will do a fresh scan without reusing the cached
7028 * scan information.
7029 *
7030 * Return: void
7031 */
Tang Yingying523322d2017-01-17 23:28:43 +08007032static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007033{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007034 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Jeff Johnson16528362018-06-14 12:34:16 -07007035 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007036
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007037 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007038 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04007039 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
7040 qdf_mem_free(hdd_ctx->last_acs_channel_list);
7041 hdd_ctx->last_acs_channel_list = NULL;
7042 hdd_ctx->num_of_channels = 0;
7043 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007044
Jeff Johnson16528362018-06-14 12:34:16 -07007045 mac_handle = hdd_ctx->mac_handle;
7046 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007047 return;
Jeff Johnson16528362018-06-14 12:34:16 -07007048 sme_scan_flush_result(mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007049}
7050#endif
7051
7052#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07007053int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
7054 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007055{
7056 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307057 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07007058 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07007059 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007060
7061 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7062
7063 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307064 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007065 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307066
Jeff Johnson16528362018-06-14 12:34:16 -07007067 mac_handle = hdd_ctx->mac_handle;
7068 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007069 return -EINVAL;
7070
Jeff Johnson16528362018-06-14 12:34:16 -07007071 qdf_status = sme_notify_ht2040_mode(mac_handle, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007072 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307073 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007074 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007075 return -EINVAL;
7076 }
7077
7078 return 0;
7079}
7080#endif
7081
7082/**
7083 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
7084 * @state: state
7085 *
7086 * This function notifies FW with modem power status
7087 *
7088 * Return: 0 if successful, error number otherwise
7089 */
7090int hdd_wlan_notify_modem_power_state(int state)
7091{
7092 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307093 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007094 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07007095 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007096
Anurag Chouhan6d760662016-02-20 16:05:43 +05307097 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007098 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307099 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007100 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05307101
Jeff Johnson16528362018-06-14 12:34:16 -07007102 mac_handle = hdd_ctx->mac_handle;
7103 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007104 return -EINVAL;
7105
Jeff Johnson16528362018-06-14 12:34:16 -07007106 qdf_status = sme_notify_modem_power_state(mac_handle, state);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307107 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007108 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007109 state);
7110 return -EINVAL;
7111 }
7112 return 0;
7113}
7114
7115/**
7116 *
7117 * hdd_post_cds_enable_config() - HDD post cds start config helper
7118 * @adapter - Pointer to the HDD
7119 *
7120 * Return: None
7121 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007122QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007123{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307124 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007125
7126 /*
7127 * Send ready indication to the HDD. This will kick off the MAC
7128 * into a 'running' state and should kick off an initial scan.
7129 */
Jeff Johnson16528362018-06-14 12:34:16 -07007130 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->mac_handle);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05307131 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007132 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
7133 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307134 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007135 }
7136
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307137 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007138}
7139
Sourav Mohapatra92ea8d62018-02-05 10:03:10 +05307140struct hdd_adapter *hdd_get_first_valid_adapter(struct hdd_context *hdd_ctx)
7141{
7142 struct hdd_adapter *adapter;
7143
7144 hdd_for_each_adapter(hdd_ctx, adapter) {
7145 if (adapter && adapter->magic == WLAN_HDD_ADAPTER_MAGIC)
7146 return adapter;
7147 }
7148
7149 return NULL;
7150}
7151
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007152/* wake lock APIs for HDD */
7153void hdd_prevent_suspend(uint32_t reason)
7154{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307155 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007156}
7157
7158void hdd_allow_suspend(uint32_t reason)
7159{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05307160 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007161}
7162
7163void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
7164{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05307165 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
7166 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007167}
7168
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007169/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007170QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007171{
Jeff Johnson16528362018-06-14 12:34:16 -07007172 return sme_init_chan_list(hdd_ctx->mac_handle,
Amar Singhal6f8592b2017-04-26 14:31:58 -07007173 hdd_ctx->reg.alpha2,
7174 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007175}
7176
7177/**
7178 * hdd_is_5g_supported() - check if hardware supports 5GHz
7179 * @hdd_ctx: Pointer to the hdd context
7180 *
7181 * HDD function to know if hardware supports 5GHz
7182 *
7183 * Return: true if hardware supports 5GHz
7184 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007185bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007186{
Amar Singhal58b45ef2017-08-01 13:43:54 -07007187 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08007188 return true;
7189
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08007190 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08007191 return true;
7192 else
7193 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007194}
7195
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007196static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007197{
7198 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07007199 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007200
7201 wiphy = hdd_ctx->wiphy;
7202
7203 /*
7204 * The channel information in
7205 * wiphy needs to be initialized before wiphy registration
7206 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007207 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
7208 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007209 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07007210 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007211 }
7212
7213#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
7214 wiphy->wowlan = &wowlan_support_reg_init;
7215#else
7216 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
7217 WIPHY_WOWLAN_MAGIC_PKT |
7218 WIPHY_WOWLAN_DISCONNECT |
7219 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
7220 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
7221 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
7222 WIPHY_WOWLAN_4WAY_HANDSHAKE |
7223 WIPHY_WOWLAN_RFKILL_RELEASE;
7224
7225 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
7226 WOW_MAX_FILTERS_PER_LIST);
7227 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
7228 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
7229#endif
7230
7231 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07007232 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307233 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07007234 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307235 return ret_val;
7236 }
Amar Singhalac26de22018-06-22 12:53:06 -07007237
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007238 /* Check the kernel version for upstream commit aced43ce780dc5 that
7239 * has support for processing user cell_base hints when wiphy is
7240 * self managed or check the backport flag for the same.
7241 */
Amar Singhalac26de22018-06-22 12:53:06 -07007242#if defined CFG80211_USER_HINT_CELL_BASE_SELF_MANAGED || \
7243 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0))
Kiran Kumar Lokere0508af92018-04-23 18:38:32 -07007244 hdd_send_wiphy_regd_sync_event(hdd_ctx);
7245#endif
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05307246
Amar Singhal2d812012018-02-03 15:06:47 +08007247 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007248
Amar Singhale4f28ee2015-10-21 14:36:56 -07007249 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007250}
7251
Mohit Khannaca4173b2017-09-12 21:52:19 -07007252#ifdef MSM_PLATFORM
7253/**
7254 * hdd_display_periodic_stats() - Function to display periodic stats
7255 * @hdd_ctx - handle to hdd context
7256 * @bool data_in_interval - true, if data detected in bw time interval
7257 *
7258 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
7259 * Stats show up in wlan driver logs.
7260 *
7261 * Returns: None
7262 */
7263static inline
7264void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
7265 bool data_in_interval)
7266{
7267 static u32 counter;
7268 static bool data_in_time_period;
7269 ol_txrx_pdev_handle pdev;
7270
7271 if (hdd_ctx->config->periodic_stats_disp_time == 0)
7272 return;
7273
7274 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
7275 if (!pdev) {
7276 hdd_err("pdev is NULL");
7277 return;
7278 }
7279
7280 counter++;
7281 if (data_in_interval)
7282 data_in_time_period = data_in_interval;
7283
7284 if (counter * hdd_ctx->config->busBandwidthComputeInterval >=
7285 hdd_ctx->config->periodic_stats_disp_time * 1000) {
7286 if (data_in_time_period) {
7287 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
7288 CDP_TXRX_PATH_STATS,
7289 QDF_STATS_VERBOSITY_LEVEL_LOW);
7290 wlan_hdd_display_netif_queue_history
7291 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
7292 qdf_dp_trace_dump_stats();
7293 }
7294 counter = 0;
7295 data_in_time_period = false;
7296 }
7297}
7298
Ravi Joshie2331e82015-07-01 18:18:54 -07007299/**
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007300 * hdd_clear_rps_cpu_mask - clear RPS CPU mask for interfaces
7301 * @hdd_ctx: pointer to struct hdd_context
7302 *
7303 * Return: none
7304 */
7305static void hdd_clear_rps_cpu_mask(struct hdd_context *hdd_ctx)
7306{
7307 struct hdd_adapter *adapter;
7308
7309 hdd_for_each_adapter(hdd_ctx, adapter)
7310 hdd_send_rps_disable_ind(adapter);
7311}
7312
7313/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07007314 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07007315 * @hdd_ctx - handle to hdd context
7316 * @tx_packets - transmit packet count
7317 * @rx_packets - receive packet count
7318 *
7319 * The function controls the bus bandwidth and dynamic control of
7320 * tcp delayed ack configuration
7321 *
7322 * Returns: None
7323 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007324
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007325static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07007326 const uint64_t tx_packets,
7327 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007328{
Mohit Khannaca4173b2017-09-12 21:52:19 -07007329 u64 total_pkts = tx_packets + rx_packets;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007330 uint64_t temp_tx = 0, avg_rx = 0;
7331 uint64_t no_rx_offload_pkts = 0, avg_no_rx_offload_pkts = 0;
7332 uint64_t rx_offload_pkts = 0, avg_rx_offload_pkts = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007333 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08007334 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08007335 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007336 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007337 uint16_t index = 0;
7338 bool vote_level_change = false;
7339 bool rx_level_change = false;
7340 bool tx_level_change = false;
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007341 bool rxthread_high_tput_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007342
Mohit Khannaca4173b2017-09-12 21:52:19 -07007343 if (total_pkts > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007344 next_vote_level = PLD_BUS_WIDTH_HIGH;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007345 else if (total_pkts > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007346 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007347 else if (total_pkts > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007348 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07007349 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07007350 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007351
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007352 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07007353 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
7354 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007355 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007356 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007357 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007358 if ((next_vote_level == PLD_BUS_WIDTH_LOW) ||
7359 (next_vote_level == PLD_BUS_WIDTH_NONE)) {
Nirav Shahffc6a092016-06-09 16:09:08 +05307360 if (hdd_ctx->hbw_requested) {
7361 pld_remove_pm_qos(hdd_ctx->parent_dev);
7362 hdd_ctx->hbw_requested = false;
7363 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007364 if (hdd_ctx->dynamic_rps)
7365 hdd_clear_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007366 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05307367 if (!hdd_ctx->hbw_requested) {
7368 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
7369 hdd_ctx->hbw_requested = true;
7370 }
Tang Yingying5a4ccf22018-03-30 15:58:27 +08007371 if (hdd_ctx->dynamic_rps)
7372 hdd_set_rps_cpu_mask(hdd_ctx);
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007373 }
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007374
Manjunathappa Prakashcb6df762018-05-29 18:54:58 -07007375 if (hdd_ctx->config->napi_cpu_affinity_mask)
7376 hdd_napi_apply_throughput_policy(hdd_ctx,
7377 tx_packets,
7378 rx_packets);
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007379
7380 if (rx_packets < hdd_ctx->config->busBandwidthLowThreshold)
7381 hdd_disable_rx_ol_for_low_tput(hdd_ctx, true);
7382 else
7383 hdd_disable_rx_ol_for_low_tput(hdd_ctx, false);
7384
Manjunathappa Prakash5f5ed132018-06-05 20:51:30 -07007385 qdf_dp_trace_apply_tput_policy(next_vote_level);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007386 }
Mohit Khannae71e2262015-11-10 09:37:24 -08007387
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007388 /*
7389 * Includes tcp+udp, if perf core is required for tcp, then
7390 * perf core is also required for udp.
7391 */
7392 no_rx_offload_pkts = hdd_ctx->no_rx_offload_pkt_cnt;
7393 hdd_ctx->no_rx_offload_pkt_cnt = 0;
7394 rx_offload_pkts = rx_packets - no_rx_offload_pkts;
Mohit Khannae71e2262015-11-10 09:37:24 -08007395
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007396 avg_no_rx_offload_pkts = (no_rx_offload_pkts +
7397 hdd_ctx->prev_no_rx_offload_pkts) / 2;
7398 hdd_ctx->prev_no_rx_offload_pkts = no_rx_offload_pkts;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08007399
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007400 avg_rx_offload_pkts = (rx_offload_pkts +
7401 hdd_ctx->prev_rx_offload_pkts) / 2;
7402 hdd_ctx->prev_rx_offload_pkts = rx_offload_pkts;
7403
7404 avg_rx = avg_no_rx_offload_pkts + avg_rx_offload_pkts;
7405 /*
7406 * Takes care to set Rx_thread affinity for below case
7407 * 1)LRO/GRO not supported ROME case
7408 * 2)when rx_ol is disabled in cases like concurrency etc
7409 * 3)For UDP cases
7410 */
7411 if (avg_no_rx_offload_pkts >
7412 hdd_ctx->config->busBandwidthHighThreshold)
7413 rxthread_high_tput_req = true;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307414 else
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007415 rxthread_high_tput_req = false;
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307416
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007417 if (cds_sched_handle_throughput_req(rxthread_high_tput_req))
7418 hdd_warn("Rx thread high_tput(%d) affinity request failed",
7419 rxthread_high_tput_req);
7420
7421 /* fine-tuning parameters for RX Flows */
7422 if (avg_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
Ravi Joshifed83572016-10-07 16:20:37 -07007423 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
7424 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
7425 next_rx_level = WLAN_SVC_TP_HIGH;
7426 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07007427 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07007428 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08007429 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007430 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007431
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007432 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007433 struct wlan_rx_tp_data rx_tp_data = {0};
7434
Ravi Joshie2331e82015-07-01 18:18:54 -07007435 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Manjunathappa Prakash3a21bea2018-05-29 20:41:12 -07007436 next_rx_level, avg_rx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007437 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007438 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07007439 /* Send throughput indication only if it is enabled.
7440 * Disabling tcp_del_ack will revert the tcp stack behavior
7441 * to default delayed ack. Note that this will disable the
7442 * dynamic delayed ack mechanism across the system
7443 */
Manjunathappa Prakashbfd12762018-04-29 22:44:52 -07007444 if (hdd_ctx->en_tcp_delack_no_lro)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007445 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
7446
Mohit Khanna6272fb682017-04-13 09:34:36 -07007447 if (hdd_ctx->config->enable_tcp_adv_win_scale)
7448 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
7449
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007450 rx_tp_data.level = next_rx_level;
7451 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7452 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
7453 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007454 }
7455
Mohit Khannae71e2262015-11-10 09:37:24 -08007456 /* fine-tuning parameters for TX Flows */
7457 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
7458 hdd_ctx->prev_tx = tx_packets;
7459 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
7460 next_tx_level = WLAN_SVC_TP_HIGH;
7461 else
7462 next_tx_level = WLAN_SVC_TP_LOW;
7463
Prakash Manjunathappae73e3b52018-02-27 18:56:22 -08007464 if ((hdd_ctx->config->enable_tcp_limit_output) &&
7465 (hdd_ctx->cur_tx_level != next_tx_level)) {
Mohit Khannae71e2262015-11-10 09:37:24 -08007466 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
7467 next_tx_level, temp_tx);
7468 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007469 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05307470 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7471 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08007472 &next_tx_level,
7473 sizeof(next_tx_level));
7474 }
7475
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007476 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007477 if (vote_level_change || tx_level_change || rx_level_change) {
7478 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
7479 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
7480 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
7481 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
7482 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
7483 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
7484 hdd_ctx->hdd_txrx_hist_idx++;
7485 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
7486 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07007487
7488 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007489}
7490
7491#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307492static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007493{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007494 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307495 bus_bw_work);
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307496 struct hdd_adapter *adapter = NULL, *con_sap_adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307497 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05307498 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
7499 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007500 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307501 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007502 bool connected = false;
7503 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
7504
Prashanth Bhattaab004382016-10-11 16:08:11 -07007505 if (wlan_hdd_validate_context(hdd_ctx))
7506 return;
7507
Jeff Johnson214671b2017-10-30 19:45:23 -07007508 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08007509 goto restart_timer;
7510
Dustin Brown920397d2017-12-13 16:27:50 -08007511 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05307512 /*
7513 * Validate magic so we don't end up accessing
7514 * an invalid adapter.
7515 */
7516 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
7517 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007518
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007519 if ((adapter->device_mode == QDF_STA_MODE ||
7520 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007521 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
7522 != eConnectionState_Associated) {
7523
7524 continue;
7525 }
7526
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007527 if ((adapter->device_mode == QDF_SAP_MODE ||
7528 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07007529 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007530
7531 continue;
7532 }
7533
7534 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
7535 adapter->prev_tx_packets);
7536 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
7537 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307538
7539 if (adapter->device_mode == QDF_SAP_MODE ||
7540 adapter->device_mode == QDF_P2P_GO_MODE ||
7541 adapter->device_mode == QDF_IBSS_MODE) {
7542
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08007543 ret = cdp_get_intra_bss_fwd_pkts_count(
7544 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007545 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307546 &fwd_tx_packets, &fwd_rx_packets);
7547 if (ret == A_OK) {
7548 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
7549 fwd_tx_packets,
7550 adapter->prev_fwd_tx_packets);
7551 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
7552 fwd_tx_packets,
7553 adapter->prev_fwd_rx_packets);
7554 }
7555 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007556
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307557 if (adapter->device_mode == QDF_SAP_MODE)
7558 con_sap_adapter = adapter;
7559
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007560 total_rx += adapter->stats.rx_packets;
7561 total_tx += adapter->stats.tx_packets;
7562
7563 spin_lock_bh(&hdd_ctx->bus_bw_lock);
7564 adapter->prev_tx_packets = adapter->stats.tx_packets;
7565 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307566 adapter->prev_fwd_tx_packets = fwd_tx_packets;
7567 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007568 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
7569 connected = true;
7570 }
7571
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007572 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007573 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007574 return;
7575 }
7576
Yun Parka29974a2018-04-09 12:05:49 -07007577 /* add intra bss forwarded tx and rx packets */
7578 tx_packets += fwd_tx_packets_diff;
7579 rx_packets += fwd_rx_packets_diff;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007580
Yun Parka29974a2018-04-09 12:05:49 -07007581 if (ucfg_ipa_is_fw_wdi_activated(hdd_ctx->hdd_pdev)) {
7582 ucfg_ipa_uc_stat_query(hdd_ctx->hdd_pdev, &ipa_tx_packets,
7583 &ipa_rx_packets);
7584 tx_packets += (uint64_t)ipa_tx_packets;
7585 rx_packets += (uint64_t)ipa_rx_packets;
7586
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307587 if (con_sap_adapter) {
7588 con_sap_adapter->stats.tx_packets += ipa_tx_packets;
7589 con_sap_adapter->stats.rx_packets += ipa_rx_packets;
7590 }
7591
Yun Parka29974a2018-04-09 12:05:49 -07007592 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, tx_packets, rx_packets);
7593 ucfg_ipa_uc_stat_request(hdd_ctx->hdd_pdev, 2);
7594 }
7595
7596 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007597
Jingxiang Gec64e1932017-08-22 14:38:59 +08007598restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08007599 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08007600 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08007601 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05307602 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08007603 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08007604 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007605}
Prashanth Bhattaab004382016-10-11 16:08:11 -07007606
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307607/**
7608 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
7609 * @arg: Argument of timer function
7610 *
7611 * Schedule a workqueue in this function where all the processing is done.
7612 *
7613 * Return: None.
7614 */
7615static void __hdd_bus_bw_cbk(void *arg)
7616{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007617 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307618
7619 if (wlan_hdd_validate_context(hdd_ctx))
7620 return;
7621
7622 schedule_work(&hdd_ctx->bus_bw_work);
7623}
7624
7625/**
7626 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
7627 * @arg: Argument of timer function
7628 *
7629 * Return: None.
7630 */
7631static void hdd_bus_bw_cbk(void *arg)
7632{
7633 cds_ssr_protect(__func__);
7634 __hdd_bus_bw_cbk(arg);
7635 cds_ssr_unprotect(__func__);
7636}
7637
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007638int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007639{
7640 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307641 INIT_WORK(&hdd_ctx->bus_bw_work,
7642 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08007643 hdd_ctx->bus_bw_timer_running = false;
7644 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307645 qdf_timer_init(NULL,
7646 &hdd_ctx->bus_bw_timer,
7647 hdd_bus_bw_cbk, (void *)hdd_ctx,
7648 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007649
7650 return 0;
7651}
7652
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007653void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007654{
Dustin Brownfce08d12017-01-17 16:29:38 -08007655 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007656 hdd_reset_tcp_delack(hdd_ctx);
7657
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007658 hdd_debug("wait for bus bw work to flush");
Nirav Shaheb017be2018-02-15 11:20:58 +05307659 hdd_cancel_bus_bw_work(hdd_ctx);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307660 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08007661 hdd_ctx->bus_bw_timer_running = false;
7662 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007663}
Lin Baic5c06882017-09-21 13:58:43 +08007664
7665void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
7666{
7667 if (hdd_ctx)
7668 cancel_work_sync(&hdd_ctx->bus_bw_work);
7669}
jiadcdaf9bd2017-10-26 12:20:21 +08007670
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007671#endif
7672
7673/**
Nirav Shahed34b212016-04-25 10:59:16 +05307674 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
7675 * @hdd_ctx: hdd context
7676 *
7677 * Return: 0 for success or error code
7678 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007679static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307680{
7681 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
7682 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
7683 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007684 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05307685 return -ENOMEM;
7686 }
7687 return 0;
7688}
7689
7690/**
7691 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
7692 * @hdd_ctx: hdd context
7693 *
7694 * Return: none
7695 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007696void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307697{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307698 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
7699 return;
7700
7701 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
7702 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05307703}
7704
Nirav Shahda008342016-05-17 18:50:40 +05307705static uint8_t *convert_level_to_string(uint32_t level)
7706{
7707 switch (level) {
7708 /* initialize the wlan sub system */
7709 case WLAN_SVC_TP_NONE:
7710 return "NONE";
7711 case WLAN_SVC_TP_LOW:
7712 return "LOW";
7713 case WLAN_SVC_TP_MEDIUM:
7714 return "MED";
7715 case WLAN_SVC_TP_HIGH:
7716 return "HIGH";
7717 default:
7718 return "INVAL";
7719 }
7720}
7721
Nirav Shahed34b212016-04-25 10:59:16 +05307722
7723/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007724 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
7725 * @hdd_ctx: hdd context
7726 *
7727 * Return: none
7728 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007729void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007730{
7731 int i;
7732
7733#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007734 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05307735 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007736 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007737 hdd_ctx->config->busBandwidthHighThreshold,
7738 hdd_ctx->config->busBandwidthMediumThreshold,
7739 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007740 hdd_debug("Enable TCP DEL ACK: %d",
Manjunathappa Prakashbfd12762018-04-29 22:44:52 -07007741 hdd_ctx->en_tcp_delack_no_lro);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007742 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007743 hdd_ctx->config->tcpDelackThresholdHigh,
7744 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007745 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05307746 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007747#endif
7748
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007749 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307750 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
7751
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007752 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007753
7754 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007755 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007756 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Dustin Brown632af712018-03-14 15:03:55 -07007757 hdd_debug("[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
7758 i, hdd_ctx->hdd_txrx_hist[i].qtime,
7759 hdd_ctx->hdd_txrx_hist[i].interval_rx,
7760 hdd_ctx->hdd_txrx_hist[i].interval_tx,
7761 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007762 hdd_ctx->hdd_txrx_hist[i].
7763 next_vote_level),
Dustin Brown632af712018-03-14 15:03:55 -07007764 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007765 hdd_ctx->hdd_txrx_hist[i].
7766 next_rx_level),
Dustin Brown632af712018-03-14 15:03:55 -07007767 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007768 hdd_ctx->hdd_txrx_hist[i].
7769 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007770 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007771}
7772
7773/**
7774 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
7775 * @hdd_ctx: hdd context
7776 *
7777 * Return: none
7778 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007779void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007780{
7781 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05307782 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
7783 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007784}
7785
Mohit Khannaca4173b2017-09-12 21:52:19 -07007786/* length of the netif queue log needed per adapter */
7787#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
7788
7789/**
7790 *
7791 * hdd_display_netif_queue_history_compact() - display compact netifq history
7792 * @hdd_ctx: hdd context
7793 *
7794 * Return: none
7795 */
7796static void
7797hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
7798{
7799 int adapter_num = 0;
7800 int i;
7801 int bytes_written;
7802 u32 tbytes;
7803 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007804 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08007805 char *comb_log_str;
7806 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007807 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007808
jiadbdefb252018-01-03 14:27:06 +08007809 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * MAX_NUMBER_OF_ADAPTERS) + 1;
7810 comb_log_str = qdf_mem_malloc(comb_log_str_size);
7811 if (!comb_log_str) {
7812 hdd_err("failed to alloc comb_log_str");
7813 return;
7814 }
7815
Mohit Khannaca4173b2017-09-12 21:52:19 -07007816 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007817
Dustin Brown920397d2017-12-13 16:27:50 -08007818 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007819 curr_time = qdf_system_ticks();
7820 total = curr_time - adapter->start_time;
7821 delta = curr_time - adapter->last_time;
7822
7823 if (adapter->pause_map) {
7824 pause = adapter->total_pause_time + delta;
7825 unpause = adapter->total_unpause_time;
7826 } else {
7827 unpause = adapter->total_unpause_time + delta;
7828 pause = adapter->total_pause_time;
7829 }
7830
7831 tbytes = 0;
7832 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7833 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7834 if (adapter->queue_oper_stats[i].pause_count == 0)
7835 continue;
7836 tbytes +=
7837 snprintf(
7838 &temp_str[tbytes],
7839 (tbytes >= sizeof(temp_str) ?
7840 0 : sizeof(temp_str) - tbytes),
7841 "%d(%d,%d) ",
7842 i,
7843 adapter->queue_oper_stats[i].
7844 pause_count,
7845 adapter->queue_oper_stats[i].
7846 unpause_count);
7847 }
7848 if (tbytes >= sizeof(temp_str))
7849 hdd_warn("log truncated");
7850
7851 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08007852 bytes_written >= comb_log_str_size ? 0 :
7853 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007854 "[%d %d] (%d) %u/%ums %s|",
7855 adapter->session_id, adapter->device_mode,
7856 adapter->pause_map,
7857 qdf_system_ticks_to_msecs(pause),
7858 qdf_system_ticks_to_msecs(total),
7859 temp_str);
7860
Mohit Khannaca4173b2017-09-12 21:52:19 -07007861 adapter_num++;
7862 }
7863
7864 /* using QDF_TRACE to avoid printing function name */
7865 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
7866 "STATS |%s", comb_log_str);
7867
jiadbdefb252018-01-03 14:27:06 +08007868 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007869 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08007870
7871 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007872}
7873
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007874/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007875 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07007876 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007877 *
7878 * Return: none
7879 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007880void
7881wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
7882 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007883{
7884
Jeff Johnson9d295242017-08-29 14:39:48 -07007885 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007886 int i;
Nirav Shahda008342016-05-17 18:50:40 +05307887 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007888
Mohit Khannaca4173b2017-09-12 21:52:19 -07007889 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
7890 hdd_display_netif_queue_history_compact(hdd_ctx);
7891 return;
7892 }
7893
Dustin Brown920397d2017-12-13 16:27:50 -08007894 hdd_for_each_adapter(hdd_ctx, adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007895 hdd_debug("Netif queue operation statistics:");
7896 hdd_debug("Session_id %d device mode %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07007897 adapter->session_id, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007898 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05307899 curr_time = qdf_system_ticks();
7900 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05307901 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05307902 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05307903 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307904 unpause = adapter->total_unpause_time;
7905 } else {
Nirav Shahda008342016-05-17 18:50:40 +05307906 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307907 pause = adapter->total_pause_time;
7908 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007909 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05307910 qdf_system_ticks_to_msecs(total),
7911 qdf_system_ticks_to_msecs(pause),
7912 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007913 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007914
Nirav Shahda008342016-05-17 18:50:40 +05307915 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7916 qdf_time_t pause_delta = 0;
7917
7918 if (adapter->pause_map & (1 << i))
7919 pause_delta = delta;
7920
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007921 /* using hdd_log to avoid printing function name */
Dustin Brown632af712018-03-14 15:03:55 -07007922 hdd_debug("%s: %d: %d: %ums",
7923 hdd_reason_type_to_string(i),
7924 adapter->queue_oper_stats[i].pause_count,
7925 adapter->queue_oper_stats[i].unpause_count,
7926 qdf_system_ticks_to_msecs(
7927 adapter->queue_oper_stats[i].total_pause_time +
7928 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007929 }
7930
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007931 hdd_debug("Netif queue operation history:");
7932 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05307933 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
7934
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007935 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007936
7937 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007938 /* using hdd_log to avoid printing function name */
7939 if (adapter->queue_oper_history[i].time == 0)
7940 continue;
Dustin Brown632af712018-03-14 15:03:55 -07007941 hdd_debug("%d: %u: %s: %s: %x",
7942 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007943 adapter->queue_oper_history[i].time),
Dustin Brown632af712018-03-14 15:03:55 -07007944 hdd_action_type_to_string(
7945 adapter->queue_oper_history[i].netif_action),
7946 hdd_reason_type_to_string(
7947 adapter->queue_oper_history[i].netif_reason),
7948 adapter->queue_oper_history[i].pause_map);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007949 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007950 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007951}
7952
7953/**
7954 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
7955 * @hdd_ctx: hdd context
7956 *
7957 * Return: none
7958 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007959void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007960{
Jeff Johnson9d295242017-08-29 14:39:48 -07007961 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007962
Dustin Brown920397d2017-12-13 16:27:50 -08007963 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307964 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007965 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307966 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007967 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05307968 adapter->history_index = 0;
7969 adapter->start_time = adapter->last_time = qdf_system_ticks();
7970 adapter->total_pause_time = 0;
7971 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007972 }
7973}
7974
7975/**
7976 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
Jeff Johnson16528362018-06-14 12:34:16 -07007977 * @mac_handle: MAC handle
7978 * @context: Pointer to the context
7979 * @session_id: Session ID
7980 * @scan_id: Scan ID
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007981 * @status: Status
7982 *
7983 * This is the callback to be executed when 11d scan is completed to flush out
7984 * the scan results
7985 *
7986 * 11d scan is done during driver load and is a passive scan on all
7987 * channels supported by the device, 11d scans may find some APs on
7988 * frequencies which are forbidden to be used in the regulatory domain
7989 * the device is operating in. If these APs are notified to the supplicant
7990 * it may try to connect to these APs, thus flush out all the scan results
7991 * which are present in SME after 11d scan is done.
7992 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307993 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007994 */
Jeff Johnson16528362018-06-14 12:34:16 -07007995static QDF_STATUS hdd_11d_scan_done(mac_handle_t mac_handle, void *context,
7996 uint8_t session_id, uint32_t scan_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007997 eCsrScanStatus status)
7998{
Dustin Brown491d54b2018-03-14 12:39:11 -07007999 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008000
Jeff Johnson16528362018-06-14 12:34:16 -07008001 sme_scan_flush_result(mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008002
Dustin Browne74003f2018-03-14 12:51:58 -07008003 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008004
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308005 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008006}
8007
8008#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
8009/**
8010 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
8011 * @hdd_ctx: hdd global context
8012 *
8013 * Return: none
8014 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008015static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008016{
8017 uint8_t i;
8018
8019 mutex_init(&hdd_ctx->op_ctx.op_lock);
8020 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
8021 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
8022 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
8023 }
8024}
8025#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008026static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008027{
8028}
8029#endif
8030
Yingying Tang95409972016-10-20 15:16:15 +08008031#ifdef WLAN_FEATURE_WOW_PULSE
8032/**
8033 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008034 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08008035 * @enable: enable or disable this behaviour
8036 *
8037 * Return: int
8038 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008039static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008040{
8041 struct hdd_config *pcfg_ini = phddctx->config;
8042 struct wow_pulse_mode wow_pulse_set_info;
8043 QDF_STATUS status;
8044
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008045 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08008046
8047 if (false == phddctx->config->wow_pulse_support)
8048 return 0;
8049
8050 /* prepare the request to send to SME */
8051 if (enable == true) {
8052 wow_pulse_set_info.wow_pulse_enable = true;
8053 wow_pulse_set_info.wow_pulse_pin =
8054 pcfg_ini->wow_pulse_pin;
8055 wow_pulse_set_info.wow_pulse_interval_low =
8056 pcfg_ini->wow_pulse_interval_low;
8057 wow_pulse_set_info.wow_pulse_interval_high =
8058 pcfg_ini->wow_pulse_interval_high;
8059 } else {
8060 wow_pulse_set_info.wow_pulse_enable = false;
8061 wow_pulse_set_info.wow_pulse_pin = 0;
8062 wow_pulse_set_info.wow_pulse_interval_low = 0;
8063 wow_pulse_set_info.wow_pulse_interval_high = 0;
8064 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008065 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08008066 wow_pulse_set_info.wow_pulse_enable,
8067 wow_pulse_set_info.wow_pulse_pin,
8068 wow_pulse_set_info.wow_pulse_interval_low,
8069 wow_pulse_set_info.wow_pulse_interval_high);
8070
8071 status = sme_set_wow_pulse(&wow_pulse_set_info);
8072 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008073 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08008074 return -EIO;
8075 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008076 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08008077 return 0;
8078}
8079#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008080static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08008081{
8082 return 0;
8083}
8084#endif
8085
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008086#ifdef WLAN_FEATURE_FASTPATH
8087/**
8088 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
8089 * @hdd_cfg: hdd config
8090 * @context: lower layer context
8091 *
8092 * Return: none
8093 */
Arun Khandavallifae92942016-08-01 13:31:08 +05308094void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008095 void *context)
8096{
8097 if (hdd_cfg->fastpath_enable)
8098 hif_enable_fastpath(context);
8099}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008100#endif
8101
Yuanyuan Liu13738502016-04-06 17:41:37 -07008102#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008103/**
8104 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008105 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008106 * @level: thermal level
8107 *
8108 * Change IPA data path to SW path when the thermal throttle level greater
8109 * than 0, and restore the original data path when throttle level is 0
8110 *
8111 * Return: none
8112 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008113static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008114{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008115 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008116
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008117 /* Change IPA to SW path when throttle level greater than 0 */
8118 if (level > THROTTLE_LEVEL_0)
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308119 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008120 else
8121 /* restore original concurrency mode */
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308122 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, hdd_ctx->mcc_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008123}
8124
8125/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308126 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
8127 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05308128 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008129 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308130 * Get a safe channel to restart SAP. PCL already takes into account the
8131 * unsafe channels. So, the PCL is validated with the ACS range to provide
8132 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008133 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308134 * Return: Channel number to restart SAP in case of success. In case of any
8135 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008136 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308137static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07008138 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008139{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308140 struct sir_pcl_list pcl;
8141 QDF_STATUS status;
8142 uint32_t i, j;
Jeff Johnson16528362018-06-14 12:34:16 -07008143 mac_handle_t mac_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008144 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308145 bool found = false;
Liangwei Dong17bf2662018-01-05 02:02:05 -05008146 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008147
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308148 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8149 if (!hdd_ctx) {
8150 hdd_err("invalid HDD context");
8151 return INVALID_CHANNEL_ID;
8152 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008153
Jeff Johnson16528362018-06-14 12:34:16 -07008154 mac_handle = hdd_ctx->mac_handle;
8155 if (!mac_handle) {
8156 hdd_err("invalid MAC handle");
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05308157 return INVALID_CHANNEL_ID;
8158 }
8159
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008160 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
8161 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08008162 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
8163 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308164 if (QDF_IS_STATUS_ERROR(status)) {
8165 hdd_err("Get PCL failed");
8166 return INVALID_CHANNEL_ID;
8167 }
8168
Frank Liudc2cefb2017-06-21 15:38:18 +08008169 /*
8170 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
8171 * channel is unsafe channel, the pcl may be empty, instead of return,
8172 * try to choose a safe channel from acs range.
8173 */
8174 if (!pcl.pcl_len)
8175 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308176
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008177 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07008178 adapter->session.ap.sap_config.acs_cfg.start_ch,
8179 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308180
8181 /* PCL already takes unsafe channel into account */
8182 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008183 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308184 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008185 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308186 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008187 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008188 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308189 return pcl.pcl_list[i];
8190 }
8191 }
8192
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008193 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308194
8195 /* Try for safe channel from all valid channel */
8196 pcl.pcl_len = MAX_NUM_CHAN;
Liangwei Dong17bf2662018-01-05 02:02:05 -05008197 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
8198 &pcl.pcl_len);
8199 if (ret) {
8200 hdd_err("error %d in getting valid channel list", ret);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308201 return INVALID_CHANNEL_ID;
8202 }
8203
8204 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008205 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308206 found = false;
8207 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07008208 if (pcl.pcl_list[i] ==
8209 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008210 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308211 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008212 break;
8213 }
8214 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308215
8216 if (found)
8217 continue;
8218
8219 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008220 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308221 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07008222 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008223 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308224 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008225 }
8226 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308227
8228 return INVALID_CHANNEL_ID;
8229}
Nirav Shaheb017be2018-02-15 11:20:58 +05308230#endif
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308231
8232/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008233 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308234 * @adapter: AP adapter
8235 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08008236 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308237 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08008238 * Moves the SAP interface by invoking the function which
8239 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308240 *
8241 * Return: None
8242 */
Min Liu2fef5792018-01-19 17:59:42 +08008243void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
8244 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308245{
Jeff Johnson87251032017-08-29 13:31:11 -07008246 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008247 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -07008248 mac_handle_t mac_handle;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308249
8250 if (!adapter) {
8251 hdd_err("invalid adapter");
8252 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008253 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308254
8255 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
8256
Jeff Johnson16528362018-06-14 12:34:16 -07008257 mac_handle = hdd_adapter_get_mac_handle(adapter);
8258 if (!mac_handle) {
8259 hdd_err("invalid MAC handle");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308260 return;
8261 }
8262
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008263 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8264
Jeff Johnson91df29d2017-10-27 19:29:50 -07008265 hdd_ap_ctx->sap_config.channel = channel;
Himanshu Agarwalf5c5b102018-05-22 20:13:57 +05308266 hdd_ap_ctx->sap_config.ch_params.ch_width = CH_WIDTH_MAX;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308267
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008268 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07008269 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308270
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07008271 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07008272 hdd_ap_ctx->sap_config.channel,
8273 hdd_ap_ctx->sap_config.sec_ch,
8274 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05308275
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08008276 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07008277 adapter->session_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08008278 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008279}
Kapil Gupta8878ad92017-02-13 11:56:04 +05308280
Jeff Johnson9d295242017-08-29 14:39:48 -07008281int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05308282{
8283 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308284 int status;
8285 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308286
8287 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8288
8289 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07008290 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05308291 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07008292 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308293 }
8294 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07008295 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308296 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308297 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07008298 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308299 WLAN_VENDOR_ACS_WAIT_TIME);
8300 if (qdf_status != QDF_STATUS_SUCCESS) {
8301 hdd_err("failed to start external acs timer");
8302 return -ENOSPC;
8303 }
8304 /* Update config to application */
8305 status = hdd_cfg80211_update_acs_config(adapter, reason);
Dustin Brown5e89ef82018-03-14 11:50:23 -07008306 hdd_info("Updated ACS config to nl with reason %d", reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308307
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308308 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308309}
8310
Nirav Shaheb017be2018-02-15 11:20:58 +05308311#if defined(FEATURE_WLAN_CH_AVOID)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308312/**
8313 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
8314 * @hdd_ctx: hdd context pointer
8315 *
8316 * hdd_unsafe_channel_restart_sap check all unsafe channel list
8317 * and if ACS is enabled, driver will ask userspace to restart the
8318 * sap. User space on LTE coex indication restart driver.
8319 *
8320 * Return - none
8321 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008322void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308323{
Dustin Brown920397d2017-12-13 16:27:50 -08008324 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308325 uint32_t i;
8326 bool found = false;
8327 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008328
Dustin Brown920397d2017-12-13 16:27:50 -08008329 hdd_for_each_adapter(hdd_ctxt, adapter) {
8330 if (!(adapter->device_mode == QDF_SAP_MODE &&
8331 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008332 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08008333 adapter->device_mode,
8334 adapter->session.ap.sap_config.
8335 acs_cfg.acs_mode);
8336 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308337 }
8338
8339 found = false;
Tushnim Bhattacharyyad2e085d2018-06-18 11:58:50 -07008340 /*
8341 * If STA+SAP is doing SCC & g_sta_sap_scc_on_lte_coex_chan
8342 * is set, no need to move SAP.
8343 */
8344 if (policy_mgr_is_sta_sap_scc(hdd_ctxt->hdd_psoc,
8345 adapter->session.ap.operating_channel) &&
8346 hdd_ctxt->config->sta_sap_scc_on_lte_coex_chan)
8347 hdd_debug("SAP is allowed on SCC channel, no need to move SAP");
8348 else {
8349 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
8350 if (adapter->session.ap.operating_channel ==
8351 hdd_ctxt->unsafe_channel_list[i]) {
8352 found = true;
8353 hdd_debug("operating ch:%d is unsafe",
8354 adapter->session.ap.operating_channel);
8355 break;
8356 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308357 }
8358 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308359 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008360 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08008361 adapter->session.ap.operating_channel);
8362 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308363 }
8364
Kapil Gupta8878ad92017-02-13 11:56:04 +05308365 if (hdd_ctxt->config->vendor_acs_support &&
8366 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08008367 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05308368 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08008369 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308370 } else
8371 restart_chan =
8372 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08008373 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308374 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008375 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308376 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008377 /*
8378 * SAP restart due to unsafe channel. While
8379 * restarting the SAP, make sure to clear
8380 * acs_channel, channel to reset to
8381 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308382 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008383 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308384 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown920397d2017-12-13 16:27:50 -08008385 adapter->session.ap.sap_config.channel =
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308386 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008387 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308388 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
8389 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04008390 hdd_debug("driver to start sap: %d",
8391 hdd_ctxt->config->sap_internal_restart);
8392 if (hdd_ctxt->config->sap_internal_restart)
Min Liu2fef5792018-01-19 17:59:42 +08008393 hdd_switch_sap_channel(adapter, restart_chan,
8394 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04008395 else
8396 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308397 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308398 }
8399}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05308400
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008401/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008402 * hdd_init_channel_avoidance() - Initialize channel avoidance
8403 * @hdd_ctx: HDD global context
8404 *
8405 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07008406 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008407 * down to the lower layers. Then subscribe to subsequent channel
8408 * avoidance events.
8409 *
8410 * Return: None
8411 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008412static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008413{
8414 uint16_t unsafe_channel_count;
8415 int index;
8416
Yuanyuan Liu13738502016-04-06 17:41:37 -07008417 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
8418 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008419 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08008420 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008421
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008422 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008423 hdd_ctx->unsafe_channel_count);
8424
Anurag Chouhan6d760662016-02-20 16:05:43 +05308425 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08008426 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008427
8428 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008429 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008430 hdd_ctx->unsafe_channel_list[index]);
8431
8432 }
8433
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008434}
Dustin Brown676a2322017-08-15 13:16:13 -07008435
Jeff Johnson9d295242017-08-29 14:39:48 -07008436static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008437 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008438{
8439 uint8_t restart_chan;
8440
8441 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
8442 if (!restart_chan) {
8443 hdd_alert("fail to restart SAP");
8444 return;
8445 }
8446
8447 /* SAP restart due to unsafe channel. While restarting
8448 * the SAP, make sure to clear acs_channel, channel to
8449 * reset to 0. Otherwise these settings will override
8450 * the ACS while restart.
8451 */
8452 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07008453 adapter->session.ap.sap_config.channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07008454
8455 hdd_debug("sending coex indication");
8456
8457 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
8458 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08008459 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07008460}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008461
8462int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
8463 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
8464{
8465 uint32_t size;
8466 uint16_t *unsafe_list;
8467 uint16_t chan_count;
8468
8469 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
8470 return -EINVAL;
8471
8472 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
8473 NUM_CHANNELS);
8474 if (chan_count) {
8475 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
8476 unsafe_list = qdf_mem_malloc(size);
8477 if (!unsafe_list) {
8478 hdd_err("No memory for unsafe chan list size%d",
8479 size);
8480 return -ENOMEM;
8481 }
8482 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
8483 } else {
8484 unsafe_list = NULL;
8485 }
8486
8487 *local_unsafe_list = unsafe_list;
8488 *local_unsafe_list_count = chan_count;
8489
8490 return 0;
8491}
8492
8493bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
8494 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
8495{
8496 int i, j;
8497
8498 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
8499 return true;
8500 if (local_unsafe_list_count == 0)
8501 return false;
8502 for (i = 0; i < local_unsafe_list_count; i++) {
8503 for (j = 0; j < local_unsafe_list_count; j++)
8504 if (local_unsafe_list[i] ==
8505 hdd_ctx->unsafe_channel_list[j])
8506 break;
8507 if (j >= local_unsafe_list_count)
8508 break;
8509 }
8510 if (i >= local_unsafe_list_count) {
8511 hdd_info("unsafe chan list same");
8512 return false;
8513 }
8514
8515 return true;
8516}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008517#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008518static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008519{
8520}
Dustin Brown676a2322017-08-15 13:16:13 -07008521
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008522static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008523{
8524}
Dustin Brown676a2322017-08-15 13:16:13 -07008525
Jeff Johnson9d295242017-08-29 14:39:48 -07008526static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008527 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008528{
8529 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
8530}
Yuanyuan Liu13738502016-04-06 17:41:37 -07008531#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008532
8533/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08008534 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
8535 * user space
8536 * @frame_ind: Management frame data to be informed.
8537 *
8538 * This function is used to indicate management frame to
8539 * user space
8540 *
8541 * Return: None
8542 *
8543 */
8544void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
8545{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008546 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07008547 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008548 int i;
8549
Dustin Browne7e71d32018-05-11 16:00:08 -07008550 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
8551 if (wlan_hdd_validate_context(hdd_ctx))
Rajeev Kumard004abc2016-02-17 12:09:56 -08008552 return;
8553
8554 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
8555 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
8556 adapter =
8557 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
8558 if (adapter)
8559 break;
8560 }
Wu Gaoa0230a62018-01-04 20:56:57 +08008561 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
8562 hdd_for_each_adapter(hdd_ctx, adapter) {
8563 if ((NULL != adapter) &&
8564 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
8565 __hdd_indicate_mgmt_frame(adapter,
8566 frame_ind->frame_len,
8567 frame_ind->frameBuf,
8568 frame_ind->frameType,
8569 frame_ind->rxChan,
8570 frame_ind->rxRssi);
8571 }
8572 }
8573 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008574 } else {
8575 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
8576 frame_ind->sessionId);
8577 }
8578
8579 if ((NULL != adapter) &&
8580 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
8581 __hdd_indicate_mgmt_frame(adapter,
8582 frame_ind->frame_len,
8583 frame_ind->frameBuf,
8584 frame_ind->frameType,
8585 frame_ind->rxChan,
8586 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008587}
8588
Kapil Gupta8878ad92017-02-13 11:56:04 +05308589void hdd_acs_response_timeout_handler(void *context)
8590{
8591 struct hdd_external_acs_timer_context *timer_context =
8592 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07008593 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008594 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308595 uint8_t reason;
8596
Dustin Brown491d54b2018-03-14 12:39:11 -07008597 hdd_enter();
Kapil Gupta8878ad92017-02-13 11:56:04 +05308598 if (!timer_context) {
8599 hdd_err("invlaid timer context");
8600 return;
8601 }
8602 adapter = timer_context->adapter;
8603 reason = timer_context->reason;
8604
8605
8606 if ((!adapter) ||
8607 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
8608 hdd_err("invalid adapter or adapter has invalid magic");
8609 return;
8610 }
8611 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8612 if (wlan_hdd_validate_context(hdd_ctx))
8613 return;
8614
8615 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
8616 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8617 else
8618 return;
8619
8620 hdd_err("ACS timeout happened for %s reason %d",
8621 adapter->dev->name, reason);
Jeff Johnson16528362018-06-14 12:34:16 -07008622
Kapil Gupta8878ad92017-02-13 11:56:04 +05308623 switch (reason) {
8624 /* SAP init case */
8625 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
8626 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
8627 false);
8628 wlan_hdd_cfg80211_start_acs(adapter);
8629 break;
8630 /* DFS detected on current channel */
8631 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
8632 wlan_sap_update_next_channel(
8633 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
Jeff Johnson16528362018-06-14 12:34:16 -07008634 sme_update_new_channel_event(hdd_ctx->mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -07008635 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308636 break;
8637 /* LTE coex event on current channel */
8638 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
8639 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
8640 break;
8641 default:
8642 hdd_info("invalid reason for timer invoke");
8643
8644 }
8645}
8646
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008647/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008648 * hdd_override_ini_config - Override INI config
8649 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008650 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008651 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008652 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008653 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008654 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008655static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008656{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008657
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008658 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
8659 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008660 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008661 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008662 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008663 if (0 == enable_11d || 1 == enable_11d) {
8664 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008665 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008666 }
Leo Chang11545d62016-10-17 14:53:50 -07008667
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308668 if (!ucfg_ipa_is_present()) {
Leo Chang11545d62016-10-17 14:53:50 -07008669 hdd_ctx->config->IpaConfig = 0;
Jingxiang Ge7a040dc2018-02-02 11:07:59 +08008670 hdd_debug("IpaConfig override to %d",
8671 hdd_ctx->config->IpaConfig);
8672 }
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05308673
8674 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
8675 !hdd_ctx->config->enable_bcast_probe_rsp) {
8676 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
8677 hdd_ctx->config->rssi_assoc_reject_enabled,
8678 hdd_ctx->config->enable_bcast_probe_rsp);
8679 hdd_ctx->config->oce_sta_enabled = 0;
8680 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008681}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008682
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008683/**
8684 * hdd_set_trace_level_for_each - Set trace level for each INI config
8685 * @hdd_ctx - HDD context
8686 *
8687 * Set trace level for each module based on INI config.
8688 *
8689 * Return: None
8690 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008691static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008692{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308693 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
8694 hdd_ctx->config->qdf_trace_enable_wdi);
8695 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
8696 hdd_ctx->config->qdf_trace_enable_hdd);
8697 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
8698 hdd_ctx->config->qdf_trace_enable_sme);
8699 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
8700 hdd_ctx->config->qdf_trace_enable_pe);
8701 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
8702 hdd_ctx->config->qdf_trace_enable_wma);
8703 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
8704 hdd_ctx->config->qdf_trace_enable_sys);
8705 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
8706 hdd_ctx->config->qdf_trace_enable_qdf);
8707 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
8708 hdd_ctx->config->qdf_trace_enable_sap);
8709 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
8710 hdd_ctx->config->qdf_trace_enable_hdd_sap);
8711 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
8712 hdd_ctx->config->qdf_trace_enable_bmi);
8713 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
8714 hdd_ctx->config->qdf_trace_enable_cfg);
8715 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
8716 hdd_ctx->config->qdf_trace_enable_epping);
8717 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
8718 hdd_ctx->config->qdf_trace_enable_qdf_devices);
8719 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07008720 hdd_ctx->config->qdf_trace_enable_txrx);
8721 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
8722 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308723 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
8724 hdd_ctx->config->qdf_trace_enable_htc);
8725 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
8726 hdd_ctx->config->qdf_trace_enable_hif);
8727 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
8728 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
8729 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
8730 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08008731 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
8732 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07008733 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
8734 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008735 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
8736 hdd_ctx->config->qdf_trace_enable_regulatory);
Naveen Rawat3cb779e2018-02-16 16:36:10 -08008737 hdd_qdf_trace_enable(QDF_MODULE_ID_CP_STATS,
8738 hdd_ctx->config->qdf_trace_enable_cp_stats);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008739
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008740 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008741}
8742
8743/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008744 * hdd_context_init() - Initialize HDD context
8745 * @hdd_ctx: HDD context.
8746 *
8747 * Initialize HDD context along with all the feature specific contexts.
8748 *
8749 * return: 0 on success and errno on failure.
8750 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008751static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008752{
8753 int ret;
8754
8755 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
8756 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
8757
8758 hdd_init_ll_stats_ctx();
8759
8760 init_completion(&hdd_ctx->mc_sus_event_var);
8761 init_completion(&hdd_ctx->ready_to_suspend);
8762
Nachiket Kukade177b5b02018-05-22 20:52:17 +05308763 hdd_apf_context_init();
8764
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008765 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308766 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008767 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308768
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008769 qdf_list_create(&hdd_ctx->hdd_adapters, MAX_NUMBER_OF_ADAPTERS);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008770
8771 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
8772
8773 ret = hdd_scan_context_init(hdd_ctx);
8774 if (ret)
8775 goto list_destroy;
8776
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008777 hdd_rx_wake_lock_create(hdd_ctx);
8778
8779 ret = hdd_sap_context_init(hdd_ctx);
8780 if (ret)
8781 goto scan_destroy;
8782
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008783 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8784
8785 hdd_init_offloaded_packets_ctx(hdd_ctx);
8786
8787 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8788 hdd_ctx->config);
8789 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08008790 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008791
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05308792 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
8793 "monitor_mode_wakelock");
8794
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008795 return 0;
8796
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008797sap_destroy:
8798 hdd_sap_context_destroy(hdd_ctx);
8799
8800scan_destroy:
8801 hdd_scan_context_destroy(hdd_ctx);
8802 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008803list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008804 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08008805
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008806 return ret;
8807}
8808
8809/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308810 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
8811 * @hdd_ctx: pointer to hdd context
8812 *
8813 * Return: status of initialization
8814 * 0 - success
8815 * negative value - failure
8816 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008817static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308818{
8819 int ret;
8820
8821 if (!hdd_ctx->config->probe_req_ie_whitelist)
8822 return 0;
8823
8824 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
8825 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
8826 hdd_ctx->config->probe_req_ie_whitelist = false;
8827 return -EINVAL;
8828 }
8829
8830 /* parse ini string probe req oui */
8831 ret = hdd_parse_probe_req_ouis(hdd_ctx);
8832 if (ret) {
8833 hdd_err("parsing error: disable ie whitelisting");
8834 hdd_ctx->config->probe_req_ie_whitelist = false;
8835 }
8836
8837 return ret;
8838}
8839
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308840/**
8841 * hdd_iface_change_callback() - Function invoked when stop modules expires
8842 * @priv: pointer to hdd context
8843 *
8844 * This function is invoked when the timer waiting for the interface change
8845 * expires, it shall cut-down the power to wlan and stop all the modules.
8846 *
8847 * Return: void
8848 */
8849static void hdd_iface_change_callback(void *priv)
8850{
8851 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
8852 int ret;
8853 int status = wlan_hdd_validate_context(hdd_ctx);
8854
8855 if (status)
8856 return;
8857
Dustin Brown491d54b2018-03-14 12:39:11 -07008858 hdd_enter();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308859 hdd_debug("Interface change timer expired close the modules!");
8860 ret = hdd_wlan_stop_modules(hdd_ctx, false);
8861 if (ret)
8862 hdd_err("Failed to stop modules");
Dustin Browne74003f2018-03-14 12:51:58 -07008863 hdd_exit();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308864}
8865
Nirav Shaheb017be2018-02-15 11:20:58 +05308866#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
8867static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8868{
8869 wlan_logging_set_log_to_console(hdd_ctx->config->
8870 wlan_logging_to_console);
8871 wlan_logging_set_active(hdd_ctx->config->wlan_logging_enable);
8872}
8873#else
8874static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8875{ }
8876#endif
8877
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308878/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008879 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05308880 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008881 *
8882 * Allocate and initialize HDD context. HDD context is allocated as part of
8883 * wiphy allocation and then context is initialized.
8884 *
8885 * Return: HDD context on success and ERR_PTR on failure
8886 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008887static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008888{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308889 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008890 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008891 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008892
Dustin Brown491d54b2018-03-14 12:39:11 -07008893 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008894
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008895 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008896 if (hdd_ctx == NULL) {
8897 ret = -ENOMEM;
8898 goto err_out;
8899 }
8900
Dustin Brown6f427922017-09-19 12:19:00 -07008901 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
8902 hdd_iface_change_callback,
8903 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308904
8905 mutex_init(&hdd_ctx->iface_change_lock);
8906
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008907 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05308908 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008909
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308910 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008911 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008912 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008913 ret = -ENOMEM;
8914 goto err_free_hdd_context;
8915 }
8916
8917 /* Read and parse the qcom_cfg.ini file */
8918 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308919 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05308920 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008921 WLAN_INI_FILE);
8922 ret = -EINVAL;
8923 goto err_free_config;
8924 }
8925
Dustin Brown84f46ea2018-02-15 11:57:36 -08008926 status = cfg_parse(WLAN_INI_FILE);
8927 if (QDF_IS_STATUS_ERROR(status))
8928 hdd_err("Failed to parse cfg %s; status:%d\n",
8929 WLAN_INI_FILE, status);
8930
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308931 ie_whitelist_attrs_init(hdd_ctx);
8932
Dustin Brown7f939932017-05-18 15:02:17 -07008933 hdd_debug("setting timer multiplier: %u",
8934 hdd_ctx->config->timer_multiplier);
8935 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
8936
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008937
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05308938 if (hdd_ctx->config->fhostNSOffload)
8939 hdd_ctx->ns_offload_enable = true;
8940
Abhishek Singh5ea86532016-04-27 14:10:53 +05308941 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
8942
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008943 hdd_override_ini_config(hdd_ctx);
8944
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008945 ret = hdd_context_init(hdd_ctx);
8946
8947 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008948 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008949
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008950 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05308951 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008952
Anurag Chouhan6d760662016-02-20 16:05:43 +05308953 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008954 goto skip_multicast_logging;
8955
8956 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
8957
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008958 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
8959 if (ret)
8960 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05308961
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008962 ret = hdd_init_netlink_services(hdd_ctx);
8963 if (ret)
8964 goto err_deinit_txrx_histogram;
8965
Nirav Shaheb017be2018-02-15 11:20:58 +05308966 hdd_set_wlan_logging(hdd_ctx);
Nirav Shahed34b212016-04-25 10:59:16 +05308967
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008968skip_multicast_logging:
8969 hdd_set_trace_level_for_each(hdd_ctx);
8970
Rajeev Kumar493a31b2017-09-29 14:01:24 -07008971 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
8972
Dustin Browne74003f2018-03-14 12:51:58 -07008973 hdd_exit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07008974
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008975 return hdd_ctx;
8976
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008977err_deinit_txrx_histogram:
8978 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
8979
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008980err_deinit_hdd_context:
8981 hdd_context_deinit(hdd_ctx);
8982
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008983err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308984 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008985
8986err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308987 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08008988 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008989
8990err_out:
8991 return ERR_PTR(ret);
8992}
8993
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008994#ifdef WLAN_OPEN_P2P_INTERFACE
8995/**
8996 * hdd_open_p2p_interface - Open P2P interface
8997 * @hdd_ctx: HDD context
8998 * @rtnl_held: True if RTNL lock held
8999 *
9000 * Open P2P interface during probe. This function called to open the P2P
9001 * interface at probe along with STA interface.
9002 *
9003 * Return: 0 on success and errno on failure
9004 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009005static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009006{
Jeff Johnson9d295242017-08-29 14:39:48 -07009007 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009008 uint8_t *p2p_dev_addr;
9009
9010 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
9011 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009012 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009013 hdd_ctx->config->intfMacAddr[0].bytes,
9014 sizeof(tSirMacAddr));
9015
9016 /*
9017 * Generate the P2P Device Address. This consists of
9018 * the device's primary MAC address with the locally
9019 * administered bit set.
9020 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009021 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009022 } else {
9023 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
9024 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009025 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009026 return -ENOSPC;
9027 }
9028
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009029 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
9030 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009031 }
9032
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009033 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07009034 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08009035 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009036
9037 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009038 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009039 return -ENOSPC;
9040 }
9041
9042 return 0;
9043}
9044#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009045static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009046 bool rtnl_held)
9047{
9048 return 0;
9049}
9050#endif
9051
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009052static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08009053{
Jeff Johnson9d295242017-08-29 14:39:48 -07009054 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08009055 int ret = 0;
9056
9057 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
9058 wlan_hdd_get_intf_addr(hdd_ctx),
9059 NET_NAME_UNKNOWN, rtnl_held);
9060 if (adapter == NULL) {
9061 hdd_err("Failed to open 802.11p interface");
9062 ret = -ENOSPC;
9063 }
9064
9065 return ret;
9066}
9067
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009068/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309069 * hdd_start_station_adapter()- Start the Station Adapter
9070 * @adapter: HDD adapter
9071 *
9072 * This function initializes the adapter for the station mode.
9073 *
9074 * Return: 0 on success or errno on failure.
9075 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009076int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309077{
9078 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08009079 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309080
Dustin Brownfdf17c12018-03-14 12:55:34 -07009081 hdd_enter_dev(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08009082 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9083 hdd_err("session is already opened, %d",
9084 adapter->session_id);
9085 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9086 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309087
Krunal Sonib51eec72017-11-20 21:53:01 -08009088 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
9089 if (ret) {
9090 hdd_err("failed to create vdev: %d", ret);
9091 return ret;
9092 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309093 status = hdd_init_station_mode(adapter);
9094
9095 if (QDF_STATUS_SUCCESS != status) {
9096 hdd_err("Error Initializing station mode: %d", status);
9097 return qdf_status_to_os_return(status);
9098 }
9099
Arun Khandavallifae92942016-08-01 13:31:08 +05309100 hdd_register_tx_flow_control(adapter,
9101 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009102 hdd_tx_resume_cb,
9103 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309104
Dustin Browne74003f2018-03-14 12:51:58 -07009105 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309106 return 0;
9107}
9108
9109/**
9110 * hdd_start_ap_adapter()- Start AP Adapter
9111 * @adapter: HDD adapter
9112 *
9113 * This function initializes the adapter for the AP mode.
9114 *
9115 * Return: 0 on success errno on failure.
9116 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009117int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309118{
9119 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009120 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08009121 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08009122 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309123
Dustin Brown491d54b2018-03-14 12:39:11 -07009124 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309125
Krunal Sonib51eec72017-11-20 21:53:01 -08009126 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
9127 hdd_err("session is already opened, %d",
9128 adapter->session_id);
9129 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
9130 }
9131 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009132 * In SSR case no need to create new sap context.
9133 * Otherwise create sap context first and then create
9134 * vdev as while creating the vdev, driver needs to
9135 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08009136 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009137 if (adapter->session.ap.sap_context) {
9138 is_ssr = true;
9139 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08009140 hdd_err("sap creation failed");
9141 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
9142 }
9143
9144 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
9145 adapter->session.ap.sap_context);
9146 if (ret) {
9147 hdd_err("failed to create vdev, status:%d", ret);
9148 hdd_sap_destroy_ctx(adapter);
9149 return ret;
9150 }
Naveen Rawat1af09392018-01-03 17:28:21 -08009151
9152 if (adapter->device_mode == QDF_SAP_MODE)
9153 sme_cli_set_command(adapter->session_id,
9154 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
9155 (bool)(hdd_ctx->config->fine_time_meas_cap &
9156 WMI_FW_AP_RTT_RESPR),
9157 VDEV_CMD);
9158
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08009159 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309160
9161 if (QDF_STATUS_SUCCESS != status) {
9162 hdd_err("Error Initializing the AP mode: %d", status);
9163 return qdf_status_to_os_return(status);
9164 }
9165
Arun Khandavallifae92942016-08-01 13:31:08 +05309166 hdd_register_tx_flow_control(adapter,
9167 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08009168 hdd_softap_tx_resume_cb,
9169 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05309170
Dustin Browne74003f2018-03-14 12:51:58 -07009171 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309172 return 0;
9173}
9174
Sourav Mohapatra57006c72017-11-19 16:15:55 +05309175static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
9176 bool rtnl_held)
9177{
9178 struct hdd_adapter *adapter;
9179
9180 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
9181 hdd_ctx->config->enableConcurrentSTA,
9182 wlan_hdd_get_intf_addr(hdd_ctx),
9183 NET_NAME_UNKNOWN, rtnl_held);
9184
9185 if (!adapter)
9186 return -ENOSPC;
9187
9188 return 0;
9189}
9190
Arun Khandavalli7e857c32016-06-26 12:07:16 +05309191/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009192 * hdd_open_interfaces - Open all required interfaces
9193 * hdd_ctx: HDD context
9194 * rtnl_held: True if RTNL lock is held
9195 *
9196 * Open all the interfaces like STA, P2P and OCB based on the configuration.
9197 *
Jeff Johnson957bc272017-02-02 08:54:48 -08009198 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009199 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009200static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009201{
Jeff Johnson9d295242017-08-29 14:39:48 -07009202 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009203 int ret;
9204
Ravi Joshia307f632017-07-17 23:41:41 -07009205 /* open monitor mode adapter if con_mode is monitor mode */
Lin Bai1c678482017-12-18 18:29:11 +08009206 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
9207 con_mode == QDF_GLOBAL_FTM_MODE) {
9208 uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
9209 QDF_MONITOR_MODE : QDF_FTM_MODE;
9210
9211 adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
9212 wlan_hdd_get_intf_addr(hdd_ctx),
9213 NET_NAME_UNKNOWN, rtnl_held);
Ravi Joshia307f632017-07-17 23:41:41 -07009214 if (!adapter) {
9215 hdd_err("open adapter failed");
9216 return -ENOSPC;
9217 }
Lin Bai1c678482017-12-18 18:29:11 +08009218
Ravi Joshia307f632017-07-17 23:41:41 -07009219 return 0;
9220 }
9221
Jeff Johnson957bc272017-02-02 08:54:48 -08009222 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05309223 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08009224 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009225
Krunal Soni9b04c9b2016-03-10 13:08:05 -08009226 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009227 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08009228 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009229
9230 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08009231 return -ENOSPC;
9232
Sourav Mohapatra57006c72017-11-19 16:15:55 +05309233 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
9234 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
9235 if (ret)
9236 hdd_err("Cannot create concurrent STA interface");
9237 }
9238
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009239 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
9240 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08009241 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009242
9243 /* Open 802.11p Interface */
9244 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08009245 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
9246 if (ret)
9247 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009248 }
9249
Jeff Johnson957bc272017-02-02 08:54:48 -08009250 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009251
Jeff Johnson957bc272017-02-02 08:54:48 -08009252err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009253 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08009254 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009255}
9256
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009257
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309258#ifdef QCA_LL_TX_FLOW_CONTROL_V2
9259/**
9260 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
9261 * @cds_cfg: CDS Configuration
9262 * @hdd_ctx: Pointer to hdd context
9263 *
9264 * Return: none
9265 */
9266static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9267 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009268 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309269{
9270 cds_cfg->tx_flow_stop_queue_th =
9271 hdd_ctx->config->TxFlowStopQueueThreshold;
9272 cds_cfg->tx_flow_start_queue_offset =
9273 hdd_ctx->config->TxFlowStartQueueOffset;
9274}
9275#else
9276static inline void hdd_txrx_populate_cds_config(struct cds_config_info
9277 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009278 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309279{
9280}
9281#endif
9282
9283#ifdef FEATURE_WLAN_RA_FILTERING
9284/**
9285 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
9286 * @cds_cfg: CDS Configuration
9287 * @hdd_ctx: Pointer to hdd context
9288 *
9289 * Return: none
9290 */
Anand Kumar3b92a912016-12-05 12:01:26 +05309291static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009292 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309293{
9294 cds_cfg->ra_ratelimit_interval =
9295 hdd_ctx->config->RArateLimitInterval;
9296 cds_cfg->is_ra_ratelimit_enabled =
9297 hdd_ctx->config->IsRArateLimitEnabled;
9298}
9299#else
Anand Kumar3b92a912016-12-05 12:01:26 +05309300static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009301 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309302{
9303}
9304#endif
9305
9306/**
9307 * hdd_update_cds_config() - API to update cds configuration parameters
9308 * @hdd_ctx: HDD Context
9309 *
9310 * Return: 0 for Success, errno on failure
9311 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009312static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309313{
9314 struct cds_config_info *cds_cfg;
9315
9316 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
9317 if (!cds_cfg) {
9318 hdd_err("failed to allocate cds config");
9319 return -ENOMEM;
9320 }
9321
Srinivas Girigowda35b00312017-06-27 21:52:03 -07009322 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08009323 if (!hdd_ctx->config->nMaxPsPoll ||
9324 !hdd_ctx->config->enablePowersaveOffload) {
9325 cds_cfg->powersave_offload_enabled =
9326 hdd_ctx->config->enablePowersaveOffload;
9327 } else {
9328 if ((hdd_ctx->config->enablePowersaveOffload ==
9329 PS_QPOWER_NODEEPSLEEP) ||
9330 (hdd_ctx->config->enablePowersaveOffload ==
9331 PS_LEGACY_NODEEPSLEEP))
9332 cds_cfg->powersave_offload_enabled =
9333 PS_LEGACY_NODEEPSLEEP;
9334 else
9335 cds_cfg->powersave_offload_enabled =
9336 PS_LEGACY_DEEPSLEEP;
9337 hdd_info("Qpower disabled in cds config, %d",
9338 cds_cfg->powersave_offload_enabled);
9339 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309340 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
9341 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
9342 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
9343 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309344
9345 /*
9346 * Copy the DFS Phyerr Filtering Offload status.
9347 * This parameter reflects the value of the
9348 * dfs_phyerr_filter_offload flag as set in the ini.
9349 */
9350 cds_cfg->dfs_phyerr_filter_offload =
9351 hdd_ctx->config->fDfsPhyerrFilterOffload;
9352 if (hdd_ctx->config->ssdp)
9353 cds_cfg->ssdp = hdd_ctx->config->ssdp;
9354
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05309355 cds_cfg->force_target_assert_enabled =
9356 hdd_ctx->config->crash_inject_enabled;
9357
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309358 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
9359 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
9360
9361 cds_cfg->ap_maxoffload_reorderbuffs =
9362 hdd_ctx->config->apMaxOffloadReorderBuffs;
9363
9364 cds_cfg->ap_disable_intrabss_fwd =
9365 hdd_ctx->config->apDisableIntraBssFwd;
9366
9367 cds_cfg->dfs_pri_multiplier =
9368 hdd_ctx->config->dfsRadarPriMultiplier;
9369 cds_cfg->reorder_offload =
9370 hdd_ctx->config->reorderOffloadSupport;
9371
9372 /* IPA micro controller data path offload resource config item */
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05309373 cds_cfg->uc_offload_enabled = ucfg_ipa_uc_is_enabled();
Yun Parkde380782016-08-17 16:26:54 -07009374 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
9375 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009376 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009377 hdd_ctx->config->IpaUcTxBufCount);
9378 hdd_ctx->config->IpaUcTxBufCount =
9379 rounddown_pow_of_two(
9380 hdd_ctx->config->IpaUcTxBufCount);
9381 if (!hdd_ctx->config->IpaUcTxBufCount) {
9382 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309383 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07009384 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009385 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009386 hdd_ctx->config->IpaUcTxBufCount);
9387 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309388 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
9389 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07009390 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
9391 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009392 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009393 hdd_ctx->config->IpaUcRxIndRingCount);
9394 hdd_ctx->config->IpaUcRxIndRingCount =
9395 rounddown_pow_of_two(
9396 hdd_ctx->config->IpaUcRxIndRingCount);
9397 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
9398 hdd_err("Failed to round down IpaUcRxIndRingCount");
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("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009402 hdd_ctx->config->IpaUcRxIndRingCount);
9403 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309404 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07009405 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309406 cds_cfg->uc_tx_partition_base =
9407 hdd_ctx->config->IpaUcTxPartitionBase;
9408 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
9409
9410 cds_cfg->ip_tcp_udp_checksum_offload =
9411 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07009412 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309413 cds_cfg->ce_classify_enabled =
9414 hdd_ctx->config->ce_classify_enabled;
Nachiket Kukadee547a482018-05-22 16:43:30 +05309415 cds_cfg->apf_packet_filter_enable =
9416 hdd_ctx->config->apf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309417 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
9418 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
9419 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07009420 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07009421 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07009422 cds_cfg->max_msdus_per_rxinorderind =
9423 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07009424 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07009425 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Nachiket Kukadee547a482018-05-22 16:43:30 +05309426 cds_cfg->active_uc_apf_mode = hdd_ctx->config->active_uc_apf_mode;
9427 cds_cfg->active_mc_bc_apf_mode = hdd_ctx->config->active_mc_bc_apf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05309428 cds_cfg->auto_power_save_fail_mode =
9429 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309430
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309431 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07009432 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Zhu Jianmina2f8e8d2018-02-11 16:37:10 +08009433 cds_cfg->delay_before_vdev_stop =
9434 hdd_ctx->config->delay_before_vdev_stop;
Rachit Kankane0106e382018-05-16 18:59:28 +05309435 cds_cfg->num_vdevs = hdd_ctx->config->num_vdevs;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309436
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309437 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
9438 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
9439 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07009440 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309441 cds_init_ini_config(cds_cfg);
9442 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309443
9444exit:
9445 qdf_mem_free(cds_cfg);
9446 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309447}
9448
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009449/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009450 * hdd_update_user_config() - API to update user configuration
9451 * parameters to obj mgr which are used by multiple components
9452 * @hdd_ctx: HDD Context
9453 *
9454 * Return: 0 for Success, errno on failure
9455 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009456static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009457{
9458 struct wlan_objmgr_psoc_user_config *user_config;
9459
9460 user_config = qdf_mem_malloc(sizeof(*user_config));
9461 if (user_config == NULL) {
9462 hdd_alert("Failed to alloc memory for user_config!");
9463 return -ENOMEM;
9464 }
9465
9466 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
9467 user_config->dual_mac_feature_disable =
9468 hdd_ctx->config->dual_mac_feature_disable;
9469 user_config->indoor_channel_support =
9470 hdd_ctx->config->indoor_channel_support;
9471 user_config->is_11d_support_enabled =
9472 hdd_ctx->config->Is11dSupportEnabled;
9473 user_config->is_11h_support_enabled =
9474 hdd_ctx->config->Is11hSupportEnabled;
9475 user_config->optimize_chan_avoid_event =
9476 hdd_ctx->config->goptimize_chan_avoid_event;
9477 user_config->skip_dfs_chnl_in_p2p_search =
9478 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07009479 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009480 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
9481
9482 qdf_mem_free(user_config);
9483 return 0;
9484}
9485
9486/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009487 * hdd_init_thermal_info - Initialize thermal level
9488 * @hdd_ctx: HDD context
9489 *
9490 * Initialize thermal level at SME layer and set the thermal level callback
9491 * which would be called when a configured thermal threshold is hit.
9492 *
9493 * Return: 0 on success and errno on failure
9494 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009495static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009496{
9497 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309498 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -07009499 mac_handle_t mac_handle;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009500
9501 thermal_param.smeThermalMgmtEnabled =
9502 hdd_ctx->config->thermalMitigationEnable;
9503 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
9504
Poddar, Siddarth83905022016-04-16 17:56:08 -07009505 thermal_param.sme_throttle_duty_cycle_tbl[0] =
9506 hdd_ctx->config->throttle_dutycycle_level0;
9507 thermal_param.sme_throttle_duty_cycle_tbl[1] =
9508 hdd_ctx->config->throttle_dutycycle_level1;
9509 thermal_param.sme_throttle_duty_cycle_tbl[2] =
9510 hdd_ctx->config->throttle_dutycycle_level2;
9511 thermal_param.sme_throttle_duty_cycle_tbl[3] =
9512 hdd_ctx->config->throttle_dutycycle_level3;
9513
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009514 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
9515 hdd_ctx->config->thermalTempMinLevel0;
9516 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
9517 hdd_ctx->config->thermalTempMaxLevel0;
9518 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
9519 hdd_ctx->config->thermalTempMinLevel1;
9520 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
9521 hdd_ctx->config->thermalTempMaxLevel1;
9522 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
9523 hdd_ctx->config->thermalTempMinLevel2;
9524 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
9525 hdd_ctx->config->thermalTempMaxLevel2;
9526 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
9527 hdd_ctx->config->thermalTempMinLevel3;
9528 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
9529 hdd_ctx->config->thermalTempMaxLevel3;
9530
Jeff Johnson16528362018-06-14 12:34:16 -07009531 mac_handle = hdd_ctx->mac_handle;
9532 status = sme_init_thermal_info(mac_handle, thermal_param);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009533
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309534 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05309535 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009536
Jeff Johnson16528362018-06-14 12:34:16 -07009537 sme_add_set_thermal_level_callback(mac_handle,
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009538 hdd_set_thermal_level_cb);
9539
9540 return 0;
9541
9542}
9543
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009544#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
9545/**
9546 * hdd_hold_rtnl_lock - Hold RTNL lock
9547 *
9548 * Hold RTNL lock
9549 *
9550 * Return: True if held and false otherwise
9551 */
9552static inline bool hdd_hold_rtnl_lock(void)
9553{
9554 rtnl_lock();
9555 return true;
9556}
9557
9558/**
9559 * hdd_release_rtnl_lock - Release RTNL lock
9560 *
9561 * Release RTNL lock
9562 *
9563 * Return: None
9564 */
9565static inline void hdd_release_rtnl_lock(void)
9566{
9567 rtnl_unlock();
9568}
9569#else
9570static inline bool hdd_hold_rtnl_lock(void) { return false; }
9571static inline void hdd_release_rtnl_lock(void) { }
9572#endif
9573
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009574#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009575
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309576/* MAX iwpriv command support */
9577#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309578#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309579#define MAX_PKTLOG_SIZE 16
9580
9581/**
9582 * hdd_pktlog_set_buff_size() - set pktlog buffer size
9583 * @hdd_ctx: hdd context
9584 * @set_value2: pktlog buffer size value
9585 *
9586 *
9587 * Return: 0 for success or error.
9588 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009589static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309590{
9591 struct sir_wifi_start_log start_log = { 0 };
9592 QDF_STATUS status;
9593
9594 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9595 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9596 start_log.ini_triggered = cds_is_packet_log_enabled();
9597 start_log.user_triggered = 1;
9598 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309599 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309600
Jeff Johnson16528362018-06-14 12:34:16 -07009601 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309602 if (!QDF_IS_STATUS_SUCCESS(status)) {
9603 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009604 hdd_exit();
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309605 return -EINVAL;
9606 }
9607
9608 return 0;
9609}
9610
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009611/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309612 * hdd_pktlog_clear_buff() - clear pktlog buffer
9613 * @hdd_ctx: hdd context
9614 *
9615 * Return: 0 for success or error.
9616 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009617static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309618{
9619 struct sir_wifi_start_log start_log;
9620 QDF_STATUS status;
9621
9622 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9623 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9624 start_log.ini_triggered = cds_is_packet_log_enabled();
9625 start_log.user_triggered = 1;
9626 start_log.size = 0;
9627 start_log.is_pktlog_buff_clear = true;
9628
Jeff Johnson16528362018-06-14 12:34:16 -07009629 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309630 if (!QDF_IS_STATUS_SUCCESS(status)) {
9631 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009632 hdd_exit();
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309633 return -EINVAL;
9634 }
9635
9636 return 0;
9637}
9638
9639
9640/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009641 * hdd_process_pktlog_command() - process pktlog command
9642 * @hdd_ctx: hdd context
9643 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309644 * @set_value2: pktlog buffer size value
9645 *
9646 * This function process pktlog command.
9647 * set_value2 only matters when set_value is 3 (set buff size)
9648 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009649 *
9650 * Return: 0 for success or error.
9651 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009652int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309653 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009654{
9655 int ret;
9656 bool enable;
9657 uint8_t user_triggered = 0;
9658
9659 ret = wlan_hdd_validate_context(hdd_ctx);
9660 if (0 != ret)
9661 return ret;
9662
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009663 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009664
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309665 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009666 hdd_err("invalid pktlog value %d", set_value);
9667 return -EINVAL;
9668 }
9669
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309670 if (set_value == PKTLOG_SET_BUFF_SIZE) {
9671 if (set_value2 <= 0) {
9672 hdd_err("invalid pktlog size %d", set_value2);
9673 return -EINVAL;
9674 } else if (set_value2 > MAX_PKTLOG_SIZE) {
9675 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
9676 return -EINVAL;
9677 }
9678 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309679 } else if (set_value == PKTLOG_CLEAR_BUFF) {
9680 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309681 }
9682
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009683 /*
9684 * set_value = 0 then disable packetlog
9685 * set_value = 1 enable packetlog forcefully
9686 * set_vlaue = 2 then disable packetlog if disabled through ini or
9687 * enable packetlog with AUTO type.
9688 */
9689 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
9690 true : false;
9691
9692 if (1 == set_value) {
9693 enable = true;
9694 user_triggered = 1;
9695 }
9696
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309697 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009698}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07009699
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009700/**
9701 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
9702 * @hdd_ctx: HDD context
9703 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309704 * @user_triggered: triggered through iwpriv
9705 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009706 *
9707 * Return: 0 on success; error number otherwise
9708 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009709int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309710 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009711{
9712 struct sir_wifi_start_log start_log;
9713 QDF_STATUS status;
9714
9715 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9716 start_log.verbose_level =
9717 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009718 start_log.ini_triggered = cds_is_packet_log_enabled();
9719 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309720 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309721 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05309722 /*
9723 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
9724 * commands. Host uses this flag to decide whether to send pktlog
9725 * disable command to fw without sending pktlog enable command
9726 * previously. For eg, If vendor sends pktlog disable command without
9727 * sending pktlog enable command, then host discards the packet
9728 * but for iwpriv command, host will send it to fw.
9729 */
9730 start_log.is_iwpriv_command = 1;
Jeff Johnson16528362018-06-14 12:34:16 -07009731 status = sme_wifi_start_logger(hdd_ctx->mac_handle, start_log);
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009732 if (!QDF_IS_STATUS_SUCCESS(status)) {
9733 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009734 hdd_exit();
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009735 return -EINVAL;
9736 }
9737
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309738 if (enable == true)
9739 hdd_ctx->is_pktlog_enabled = 1;
9740 else
9741 hdd_ctx->is_pktlog_enabled = 0;
9742
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009743 return 0;
9744}
9745#endif /* REMOVE_PKT_LOG */
9746
Komal Seelam92fff912016-03-24 11:51:41 +05309747/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009748 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
9749 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05309750 * @dev: Device Pointer
9751 * @num: Number of Valid Mac address
9752 *
9753 * Return: Pointer to MAC address buffer
9754 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009755static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9756 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309757{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009758 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309759}
Komal Seelam92fff912016-03-24 11:51:41 +05309760
9761/**
9762 * hdd_populate_random_mac_addr() - API to populate random mac addresses
9763 * @hdd_ctx: HDD Context
9764 * @num: Number of random mac addresses needed
9765 *
9766 * Generate random addresses using bit manipulation on the base mac address
9767 *
9768 * Return: None
9769 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009770void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05309771{
9772 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
9773 uint32_t iter;
9774 struct hdd_config *ini = hdd_ctx->config;
9775 uint8_t *buf = NULL;
9776 uint8_t macaddr_b3, tmp_br3;
9777 uint8_t *src = ini->intfMacAddr[0].bytes;
9778
9779 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
9780 buf = ini->intfMacAddr[iter].bytes;
9781 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
9782 macaddr_b3 = buf[3];
9783 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
9784 INTF_MACADDR_MASK;
9785 macaddr_b3 += tmp_br3;
9786 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
9787 buf[0] |= 0x02;
9788 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009789 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309790 }
9791}
9792
9793/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009794 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05309795 * @hdd_ctx: HDD Context
9796 *
9797 * API to get mac addresses from platform driver and update the driver
9798 * structures and configure FW with the base mac address.
9799 * Return: int
9800 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009801static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309802{
9803 uint32_t no_of_mac_addr, iter;
9804 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
9805 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
9806 uint8_t *addr, *buf;
9807 struct device *dev = hdd_ctx->parent_dev;
9808 struct hdd_config *ini = hdd_ctx->config;
9809 tSirMacAddr mac_addr;
9810 QDF_STATUS status;
9811
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009812 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05309813
9814 if (no_of_mac_addr == 0 || !addr) {
9815 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
9816 return -EINVAL;
9817 }
9818
9819 if (no_of_mac_addr > max_mac_addr)
9820 no_of_mac_addr = max_mac_addr;
9821
9822 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
9823
9824 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
9825 buf = ini->intfMacAddr[iter].bytes;
9826 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009827 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309828 }
9829
9830 status = sme_set_custom_mac_addr(mac_addr);
9831
9832 if (!QDF_IS_STATUS_SUCCESS(status))
9833 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009834
Komal Seelam92fff912016-03-24 11:51:41 +05309835 if (no_of_mac_addr < max_mac_addr)
9836 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
9837 no_of_mac_addr);
9838 return 0;
9839}
9840
9841/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009842 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
9843 * @hdd_ctx: HDD Context
9844 *
9845 * Update MAC address to FW. If MAC address passed by FW is invalid, host
9846 * will generate its own MAC and update it to FW.
9847 *
9848 * Return: 0 for success
9849 * Non-zero error code for failure
9850 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009851static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009852{
9853 tSirMacAddr customMacAddr;
9854 QDF_STATUS status;
9855
9856 qdf_mem_copy(&customMacAddr,
9857 &hdd_ctx->config->intfMacAddr[0].bytes[0],
9858 sizeof(tSirMacAddr));
9859 status = sme_set_custom_mac_addr(customMacAddr);
9860 if (!QDF_IS_STATUS_SUCCESS(status))
9861 return -EAGAIN;
9862 return 0;
9863}
9864
9865/**
Komal Seelam92fff912016-03-24 11:51:41 +05309866 * hdd_initialize_mac_address() - API to get wlan mac addresses
9867 * @hdd_ctx: HDD Context
9868 *
9869 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
9870 * is provisioned with mac addresses, driver uses it, else it will use
9871 * wlan_mac.bin to update HW MAC addresses.
9872 *
9873 * Return: None
9874 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009875static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309876{
9877 QDF_STATUS status;
9878 int ret;
9879
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009880 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05309881 if (ret == 0)
9882 return;
9883
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009884 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
9885 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05309886
9887 status = hdd_update_mac_config(hdd_ctx);
9888
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009889 if (QDF_IS_STATUS_SUCCESS(status))
9890 return;
9891
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009892 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
9893 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009894
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009895 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009896 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009897 if (ret != 0) {
9898 hdd_err("MAC address out-of-sync, ret:%d", ret);
9899 QDF_ASSERT(ret);
9900 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009901 }
Komal Seelam92fff912016-03-24 11:51:41 +05309902}
9903
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009904static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009905{
9906 int vdev_id = 0;
9907 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
9908 int value = hdd_ctx->config->smart_chainmask_enabled;
9909 int vpdev = PDEV_CMD;
9910 int ret;
9911
Naveen Rawat247a8682017-06-05 15:00:31 -07009912 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009913 if (ret)
9914 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
9915
9916 return ret;
9917}
9918
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009919static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009920{
9921 int vdev_id = 0;
9922 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
9923 int value = hdd_ctx->config->alternative_chainmask_enabled;
9924 int vpdev = PDEV_CMD;
9925 int ret;
9926
Naveen Rawat247a8682017-06-05 15:00:31 -07009927 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009928 if (ret)
9929 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
9930 ret);
9931
9932 return ret;
9933}
9934
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009935static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07009936{
9937 int vdev_id = 0;
9938 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
9939 int value = hdd_ctx->config->ani_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 Johnson12a744b2017-04-04 08:19:37 -07009944 if (ret)
9945 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
9946
9947 return ret;
9948}
9949
Jeff Johnson89c66ff2016-04-22 15:21:37 -07009950/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07009951 * hdd_pre_enable_configure() - Configurations prior to cds_enable
9952 * @hdd_ctx: HDD context
9953 *
9954 * Pre configurations to be done at lower layer before calling cds enable.
9955 *
9956 * Return: 0 on success and errno on failure.
9957 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009958static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07009959{
9960 int ret;
9961 QDF_STATUS status;
Leo Changfdb45c32016-10-28 11:09:23 -07009962 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009963
Leo Changfdb45c32016-10-28 11:09:23 -07009964 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Ajit Pal Singh5d269612018-04-19 16:29:12 +05309965 /* Register HL netdev flow control callback */
9966 cdp_hl_fc_register(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009967 /*
9968 * Set 802.11p config
9969 * TODO-OCB: This has been temporarily added here to ensure this
9970 * parameter is set in CSR when we init the channel list. This should
9971 * be removed once the 5.9 GHz channels are added to the regulatory
9972 * domain.
9973 */
9974 hdd_set_dot11p_config(hdd_ctx);
9975
9976 /*
9977 * Note that the cds_pre_enable() sequence triggers the cfg download.
9978 * The cfg download must occur before we update the SME config
9979 * since the SME config operation must access the cfg database
9980 */
9981 status = hdd_set_sme_config(hdd_ctx);
9982
9983 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009984 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009985 ret = qdf_status_to_os_return(status);
9986 goto out;
9987 }
9988
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07009989 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
9990 if (QDF_STATUS_SUCCESS != status) {
9991 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
9992 ret = qdf_status_to_os_return(status);
9993 goto out;
9994 }
9995
Naveen Rawat247a8682017-06-05 15:00:31 -07009996 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07009997 hdd_ctx->config->tx_chain_mask_1ss,
9998 PDEV_CMD);
9999 if (0 != ret) {
10000 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
10001 goto out;
10002 }
10003
Jeff Johnsona89e25d2017-02-24 12:25:07 -080010004 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
10005 if (ret)
10006 goto out;
10007
10008 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
10009 if (ret)
10010 goto out;
10011
Jeff Johnson12a744b2017-04-04 08:19:37 -070010012 ret = hdd_set_ani_enabled(hdd_ctx);
10013 if (ret)
10014 goto out;
10015
Naveen Rawat247a8682017-06-05 15:00:31 -070010016 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -080010017 hdd_ctx->config->arp_ac_category,
10018 PDEV_CMD);
10019 if (0 != ret) {
10020 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
10021 hdd_ctx->config->arp_ac_category, ret);
10022 goto out;
10023 }
10024
Prashanth Bhatta07998752016-04-28 12:35:33 -070010025 status = hdd_set_sme_chan_list(hdd_ctx);
10026 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010027 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010028 ret = qdf_status_to_os_return(status);
10029 goto out;
10030 }
10031
10032 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -070010033 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010034 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -070010035 ret = -EINVAL;
10036 goto out;
10037 }
10038
Prashanth Bhatta07998752016-04-28 12:35:33 -070010039 /*
10040 * Set the MAC Address Currently this is used by HAL to add self sta.
10041 * Remove this once self sta is added as part of session open.
10042 */
Jeff Johnson16528362018-06-14 12:34:16 -070010043 status = sme_cfg_set_str(hdd_ctx->mac_handle, WNI_CFG_STA_ID,
Jeff Johnsonbae59f92018-06-01 17:05:43 -070010044 hdd_ctx->config->intfMacAddr[0].bytes,
10045 sizeof(hdd_ctx->config->intfMacAddr[0]));
Prashanth Bhatta07998752016-04-28 12:35:33 -070010046
Jeff Johnsonbae59f92018-06-01 17:05:43 -070010047 if (QDF_IS_STATUS_ERROR(status)) {
10048 hdd_err("Failed to set MAC Address, status %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010049 ret = -EINVAL;
10050 goto out;
10051 }
10052
10053 hdd_init_channel_avoidance(hdd_ctx);
10054
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +053010055 /* update enable sap mandatory chan list */
10056 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
10057 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -070010058out:
10059 return ret;
10060}
10061
10062/**
Peng Xu8fdaa492016-06-22 10:20:47 -070010063 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
10064 * @context_ptr - hdd context pointer
10065 * @event_ptr - event structure pointer
10066 *
10067 * This is the p2p listen offload stop event handler, it sends vendor
10068 * event back to supplicant to notify the stop reason.
10069 *
10070 * Return: None
10071 */
10072static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
10073 void *event_ptr)
10074{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010075 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -070010076 struct sir_p2p_lo_event *evt = event_ptr;
10077 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -070010078 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -070010079
Dustin Brown491d54b2018-03-14 12:39:11 -070010080 hdd_enter();
Peng Xu8fdaa492016-06-22 10:20:47 -070010081
10082 if (hdd_ctx == NULL) {
10083 hdd_err("Invalid HDD context pointer");
10084 return;
10085 }
10086
Peng Xu5c682812017-08-06 07:39:13 -070010087 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
10088 if (!adapter) {
10089 hdd_err("Cannot find adapter by vdev_id = %d",
10090 evt->vdev_id);
10091 return;
10092 }
10093
Peng Xu8fdaa492016-06-22 10:20:47 -070010094 vendor_event =
10095 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -070010096 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -070010097 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
10098 GFP_KERNEL);
10099
10100 if (!vendor_event) {
10101 hdd_err("cfg80211_vendor_event_alloc failed");
10102 return;
10103 }
10104
10105 if (nla_put_u32(vendor_event,
10106 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
10107 evt->reason_code)) {
10108 hdd_err("nla put failed");
10109 kfree_skb(vendor_event);
10110 return;
10111 }
10112
10113 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -070010114 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
10115 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -070010116}
10117
10118/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010119 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
10120 * @hdd_ctx: HDD context
10121 *
10122 * This function sends the adaptive dwell time config configuration to the
10123 * firmware via WMA
10124 *
10125 * Return: 0 - success, < 0 - failure
10126 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010127static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010128{
10129 QDF_STATUS status;
10130 struct adaptive_dwelltime_params dwelltime_params;
10131
10132 dwelltime_params.is_enabled =
10133 hdd_ctx->config->adaptive_dwell_mode_enabled;
10134 dwelltime_params.dwelltime_mode =
10135 hdd_ctx->config->global_adapt_dwelltime_mode;
10136 dwelltime_params.lpf_weight =
10137 hdd_ctx->config->adapt_dwell_lpf_weight;
10138 dwelltime_params.passive_mon_intval =
10139 hdd_ctx->config->adapt_dwell_passive_mon_intval;
10140 dwelltime_params.wifi_act_threshold =
10141 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
10142
Jeff Johnson16528362018-06-14 12:34:16 -070010143 status = sme_set_adaptive_dwelltime_config(hdd_ctx->mac_handle,
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010144 &dwelltime_params);
10145
10146 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
10147 if (!QDF_IS_STATUS_SUCCESS(status)) {
10148 hdd_err("Failed to send Adaptive Dwelltime configuration!");
10149 return -EAGAIN;
10150 }
10151 return 0;
10152}
10153
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010154int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010155{
10156 QDF_STATUS status;
10157 struct wmi_dbs_scan_sel_params dbs_scan_params;
10158 uint32_t i = 0;
10159 uint8_t count = 0, numentries = 0;
10160 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
10161 * CDS_DBS_SCAN_CLIENTS_MAX];
10162
10163 /* check if DBS is enabled or supported */
Bala Venkateshc8236ca2018-03-09 12:38:29 +053010164 if ((hdd_ctx->config->dual_mac_feature_disable ==
10165 DISABLE_DBS_CXN_AND_SCAN) ||
10166 (hdd_ctx->config->dual_mac_feature_disable ==
10167 ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN))
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010168 return -EINVAL;
10169
10170 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
10171 dbs_scan_config, &numentries,
10172 (CDS_DBS_SCAN_PARAM_PER_CLIENT
10173 * CDS_DBS_SCAN_CLIENTS_MAX));
10174
10175 hdd_info("numentries %hu", numentries);
10176 if (!numentries) {
10177 hdd_info("Donot send scan_selection_config");
10178 return 0;
10179 }
10180
10181 /* hdd_set_fw_log_params */
10182 dbs_scan_params.num_clients = 0;
10183 while (count < (numentries - 2)) {
10184 dbs_scan_params.module_id[i] = dbs_scan_config[count];
10185 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
10186 dbs_scan_params.num_non_dbs_scans[i] =
10187 dbs_scan_config[count + 2];
10188 dbs_scan_params.num_clients++;
10189 hdd_debug("module:%d NDS:%d NNDS:%d",
10190 dbs_scan_params.module_id[i],
10191 dbs_scan_params.num_dbs_scans[i],
10192 dbs_scan_params.num_non_dbs_scans[i]);
10193 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
10194 i++;
10195 }
10196
10197 dbs_scan_params.pdev_id = 0;
10198
10199 hdd_debug("clients:%d pdev:%d",
10200 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
10201
Jeff Johnson16528362018-06-14 12:34:16 -070010202 status = sme_set_dbs_scan_selection_config(hdd_ctx->mac_handle,
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010203 &dbs_scan_params);
10204 hdd_debug("Sending DBS Scan Selection Configuration to fw");
10205 if (!QDF_IS_STATUS_SUCCESS(status)) {
10206 hdd_err("Failed to send DBS Scan selection configuration!");
10207 return -EAGAIN;
10208 }
10209 return 0;
10210}
10211
Arun Khandavallid4349a92016-07-25 11:10:43 +053010212#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
10213/**
10214 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
10215 * @hdd_ctx: HDD context
10216 *
10217 * Set auto shutdown callback to get indications from firmware to indicate
10218 * userspace to shutdown WLAN after a configured amount of inactivity.
10219 *
10220 * Return: 0 on success and errno on failure.
10221 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010222static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010223{
10224 QDF_STATUS status;
10225
10226 if (!hdd_ctx->config->WlanAutoShutdown)
10227 return 0;
10228
Jeff Johnson16528362018-06-14 12:34:16 -070010229 status = sme_set_auto_shutdown_cb(hdd_ctx->mac_handle,
Arun Khandavallid4349a92016-07-25 11:10:43 +053010230 wlan_hdd_auto_shutdown_cb);
10231 if (status != QDF_STATUS_SUCCESS)
10232 hdd_err("Auto shutdown feature could not be enabled: %d",
10233 status);
10234
10235 return qdf_status_to_os_return(status);
10236}
10237#else
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 return 0;
10241}
10242#endif
10243
10244/**
10245 * hdd_features_init() - Init features
10246 * @hdd_ctx: HDD context
Arun Khandavallid4349a92016-07-25 11:10:43 +053010247 *
10248 * Initialize features and their feature context after WLAN firmware is up.
10249 *
10250 * Return: 0 on success and errno on failure.
10251 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010252static int hdd_features_init(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +053010253{
10254 tSirTxPowerLimit hddtxlimit;
10255 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +053010256 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010257 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070010258 mac_handle_t mac_handle;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010259
Dustin Brown491d54b2018-03-14 12:39:11 -070010260 hdd_enter();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010261
Arun Khandavallid4349a92016-07-25 11:10:43 +053010262 /* FW capabilities received, Set the Dot11 mode */
Jeff Johnson16528362018-06-14 12:34:16 -070010263 mac_handle = hdd_ctx->mac_handle;
10264 sme_setdef_dot11mode(mac_handle);
10265 sme_set_prefer_80MHz_over_160MHz(mac_handle,
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -070010266 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010267
Arun Khandavallid4349a92016-07-25 11:10:43 +053010268
10269 if (hdd_ctx->config->fIsImpsEnabled)
10270 hdd_set_idle_ps_config(hdd_ctx, true);
10271 else
10272 hdd_set_idle_ps_config(hdd_ctx, false);
10273
Poddar, Siddarth37033032017-10-11 15:47:40 +053010274 /* Send Enable/Disable data stall detection cmd to FW */
10275 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
10276 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
10277
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010278 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Jeff Johnson16528362018-06-14 12:34:16 -070010279 sme_set_cts2self_for_p2p_go(mac_handle);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +053010280
Nachiket Kukade8983cf62017-10-12 18:14:48 +053010281 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
10282 hdd_warn("Error in setting Voltage Corner mode config to FW");
10283
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010284 if (hdd_rx_ol_init(hdd_ctx))
10285 hdd_err("Unable to initialize Rx LRO/GRO in fw");
Arun Khandavallid4349a92016-07-25 11:10:43 +053010286
10287 if (hdd_adaptive_dwelltime_init(hdd_ctx))
10288 hdd_err("Unable to send adaptive dwelltime setting to FW");
10289
Nitesh Shahf9a09ff2017-05-22 15:46:25 +053010290 if (hdd_dbs_scan_selection_init(hdd_ctx))
10291 hdd_err("Unable to send DBS scan selection setting to FW");
10292
Arun Khandavallid4349a92016-07-25 11:10:43 +053010293 ret = hdd_init_thermal_info(hdd_ctx);
10294 if (ret) {
10295 hdd_err("Error while initializing thermal information");
Dustin Browne7e71d32018-05-11 16:00:08 -070010296 return ret;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010297 }
10298
Poddar, Siddarth61fbc932017-12-19 14:27:55 +053010299 /**
10300 * In case of SSR/PDR, if pktlog was enabled manually before
10301 * SSR/PDR, Then enabled it again automatically after Wlan
10302 * device up.
10303 */
10304 if (cds_is_driver_recovering()) {
10305 if (hdd_ctx->is_pktlog_enabled)
10306 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Tiger Yuf3d5d7f2018-03-15 14:48:11 +080010307 }
Poddar, Siddarth66a46592017-02-22 11:44:44 +053010308
Arun Khandavallid4349a92016-07-25 11:10:43 +053010309 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
10310 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
Jeff Johnson16528362018-06-14 12:34:16 -070010311 status = sme_txpower_limit(mac_handle, &hddtxlimit);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010312 if (!QDF_IS_STATUS_SUCCESS(status))
10313 hdd_err("Error setting txlimit in sme: %d", status);
10314
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010315 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010316
Arun Khandavallid4349a92016-07-25 11:10:43 +053010317 ret = hdd_register_cb(hdd_ctx);
10318 if (ret) {
10319 hdd_err("Failed to register HDD callbacks!");
Dustin Browne7e71d32018-05-11 16:00:08 -070010320 return ret;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010321 }
10322
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +053010323 if (hdd_ctx->config->goptimize_chan_avoid_event) {
10324 status = sme_enable_disable_chanavoidind_event(
Jeff Johnson16528362018-06-14 12:34:16 -070010325 mac_handle, 0);
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +053010326 if (!QDF_IS_STATUS_SUCCESS(status)) {
10327 hdd_err("Failed to disable Chan Avoidance Indication");
10328 goto deregister_cb;
10329 }
10330 }
Arun Khandavallid4349a92016-07-25 11:10:43 +053010331
Manjeet Singha9cae432017-02-28 11:58:22 +053010332 if (hdd_ctx->config->enable_5g_band_pref) {
10333 band_pref_params.rssi_boost_threshold_5g =
10334 hdd_ctx->config->rssi_boost_threshold_5g;
10335 band_pref_params.rssi_boost_factor_5g =
10336 hdd_ctx->config->rssi_boost_factor_5g;
10337 band_pref_params.max_rssi_boost_5g =
10338 hdd_ctx->config->max_rssi_boost_5g;
10339 band_pref_params.rssi_penalize_threshold_5g =
10340 hdd_ctx->config->rssi_penalize_threshold_5g;
10341 band_pref_params.rssi_penalize_factor_5g =
10342 hdd_ctx->config->rssi_penalize_factor_5g;
10343 band_pref_params.max_rssi_penalize_5g =
10344 hdd_ctx->config->max_rssi_penalize_5g;
Jeff Johnson16528362018-06-14 12:34:16 -070010345 sme_set_5g_band_pref(mac_handle, &band_pref_params);
Manjeet Singha9cae432017-02-28 11:58:22 +053010346 }
10347
Arun Khandavallid4349a92016-07-25 11:10:43 +053010348 /* register P2P Listen Offload event callback */
10349 if (wma_is_p2p_lo_capable())
Jeff Johnson16528362018-06-14 12:34:16 -070010350 sme_register_p2p_lo_event(mac_handle, hdd_ctx,
10351 wlan_hdd_p2p_lo_event_callback);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010352
10353 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
10354
10355 if (ret)
10356 goto deregister_cb;
10357
Dustin Brown11638b72018-01-25 17:37:25 +053010358 wlan_hdd_init_chan_info(hdd_ctx);
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010359 wlan_hdd_twt_init(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010360
Dustin Browne74003f2018-03-14 12:51:58 -070010361 hdd_exit();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010362 return 0;
10363
10364deregister_cb:
10365 hdd_deregister_cb(hdd_ctx);
Dustin Browne7e71d32018-05-11 16:00:08 -070010366
Arun Khandavallid4349a92016-07-25 11:10:43 +053010367 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010368}
10369
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010370/**
10371 * hdd_features_deinit() - Deinit features
10372 * @hdd_ctx: HDD context
10373 *
10374 * De-Initialize features and their feature context.
10375 *
10376 * Return: none.
10377 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010378static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010379{
Varun Reddy Yeturu3c9f89c2018-04-18 19:10:34 -070010380 wlan_hdd_twt_deinit(hdd_ctx);
Dustin Brown11638b72018-01-25 17:37:25 +053010381 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010382 wlan_hdd_tsf_deinit(hdd_ctx);
10383}
10384
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010385/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010386 * hdd_register_bcn_cb() - register scan beacon callback
10387 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010388 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010389 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010390 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010391static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010392{
10393 QDF_STATUS status;
10394
10395 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
10396 wlan_cfg80211_inform_bss_frame,
10397 SCAN_CB_TYPE_INFORM_BCN);
10398 if (!QDF_IS_STATUS_SUCCESS(status)) {
10399 hdd_err("failed with status code %08d [x%08x]",
10400 status, status);
10401 return status;
10402 }
10403
10404 return QDF_STATUS_SUCCESS;
10405}
Arun Khandavallid4349a92016-07-25 11:10:43 +053010406
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010407/**
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070010408 * hdd_v2_flow_pool_map() - Flow pool create callback when vdev is active
10409 * @vdev_id: vdev_id, corresponds to flow_pool
10410 *
10411 * Return: none.
10412 */
10413static void hdd_v2_flow_pool_map(int vdev_id)
10414{
10415 QDF_STATUS status;
10416
10417 status = cdp_flow_pool_map(cds_get_context(QDF_MODULE_ID_SOC),
10418 cds_get_context(QDF_MODULE_ID_TXRX),
10419 vdev_id);
10420 /*
10421 * For Adrastea flow control v2 is based on FW MAP events,
10422 * so this above callback is not implemented.
10423 * Hence this is not actual failure. Dont return failure
10424 */
10425 if ((status != QDF_STATUS_SUCCESS) &&
10426 (status != QDF_STATUS_E_INVAL)) {
10427 hdd_err("vdev_id: %d, failed to create flow pool status %d",
10428 vdev_id, status);
10429 }
10430}
10431
10432/**
10433 * hdd_v2_flow_pool_unmap() - Flow pool create callback when vdev is not active
10434 * @vdev_id: vdev_id, corresponds to flow_pool
10435 *
10436 * Return: none.
10437 */
10438static void hdd_v2_flow_pool_unmap(int vdev_id)
10439{
10440 cdp_flow_pool_unmap(cds_get_context(QDF_MODULE_ID_SOC),
10441 cds_get_context(QDF_MODULE_ID_TXRX), vdev_id);
10442}
10443
10444/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010445 * hdd_configure_cds() - Configure cds modules
10446 * @hdd_ctx: HDD context
10447 * @adapter: Primary adapter context
10448 *
10449 * Enable Cds modules after WLAN firmware is up.
10450 *
10451 * Return: 0 on success and errno on failure.
10452 */
Dustin Browne7e71d32018-05-11 16:00:08 -070010453int hdd_configure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010454{
10455 int ret;
10456 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010457 int set_value;
Jeff Johnson16528362018-06-14 12:34:16 -070010458 mac_handle_t mac_handle;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010459 uint32_t num_abg_tx_chains = 0;
10460 uint32_t num_11b_tx_chains = 0;
10461 uint32_t num_11ag_tx_chains = 0;
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010462 struct policy_mgr_dp_cbacks dp_cbs = {0};
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010463
Jeff Johnson16528362018-06-14 12:34:16 -070010464 mac_handle = hdd_ctx->mac_handle;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010465 if (hdd_ctx->config->is_force_1x1)
10466 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
10467 1, PDEV_CMD);
10468 /* set chip power save failure detected callback */
Jeff Johnson16528362018-06-14 12:34:16 -070010469 sme_set_chip_pwr_save_fail_cb(mac_handle,
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010470 hdd_chip_pwr_save_fail_detected_cb);
10471
10472 if (hdd_ctx->config->max_mpdus_inampdu) {
10473 set_value = hdd_ctx->config->max_mpdus_inampdu;
10474 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
10475 set_value, PDEV_CMD);
10476 }
10477
10478 if (hdd_ctx->config->enable_rts_sifsbursting) {
10479 set_value = hdd_ctx->config->enable_rts_sifsbursting;
10480 sme_cli_set_command(0,
10481 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
10482 set_value, PDEV_CMD);
10483 }
10484
10485 if (hdd_ctx->config->sap_get_peer_info) {
10486 set_value = hdd_ctx->config->sap_get_peer_info;
10487 sme_cli_set_command(0,
10488 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
10489 set_value, PDEV_CMD);
10490 }
10491
10492 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
10493 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
10494 if (!hdd_ctx->config->enable2x2) {
10495 if (num_11b_tx_chains > 1)
10496 num_11b_tx_chains = 1;
10497 if (num_11ag_tx_chains > 1)
10498 num_11ag_tx_chains = 1;
10499 }
10500 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
10501 num_11b_tx_chains);
10502 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
10503 num_11ag_tx_chains);
10504 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
10505 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +053010506
10507 ret = hdd_pre_enable_configure(hdd_ctx);
10508 if (ret) {
10509 hdd_err("Failed to pre-configure cds");
10510 goto out;
10511 }
10512
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010513 /* Always get latest IPA resources allocated from cds_open and configure
10514 * IPA module before configuring them to FW. Sequence required as crash
10515 * observed otherwise.
10516 */
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010517 if (ucfg_ipa_uc_ol_init(hdd_ctx->hdd_pdev,
10518 cds_get_context(QDF_MODULE_ID_QDF_DEVICE))) {
Manikandan Mohan2e803a02017-02-14 14:57:53 -080010519 hdd_err("Failed to setup pipes");
10520 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010521 }
10522
Arun Khandavallifae92942016-08-01 13:31:08 +053010523 /*
10524 * Start CDS which starts up the SME/MAC/HAL modules and everything
10525 * else
10526 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -070010527 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010528
10529 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010530 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053010531 goto out;
10532 }
10533
10534 status = hdd_post_cds_enable_config(hdd_ctx);
10535 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010536 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010537 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010538 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010539 status = hdd_register_bcn_cb(hdd_ctx);
10540 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +080010541 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010542 goto cds_disable;
10543 }
Arun Khandavallifae92942016-08-01 13:31:08 +053010544
Dustin Browne7e71d32018-05-11 16:00:08 -070010545 ret = hdd_features_init(hdd_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010546 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010547 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010548
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010549 if (hdd_ctx->ol_enable)
10550 dp_cbs.hdd_disable_rx_ol_in_concurrency =
10551 hdd_disable_rx_ol_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -070010552 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
jiadbb47e132018-03-30 16:28:30 +080010553 dp_cbs.hdd_ipa_set_mcc_mode_cb = hdd_ipa_set_mcc_mode;
Manjunathappa Prakasha0cbc922018-05-08 19:48:34 -070010554 dp_cbs.hdd_v2_flow_pool_map = hdd_v2_flow_pool_map;
10555 dp_cbs.hdd_v2_flow_pool_unmap = hdd_v2_flow_pool_unmap;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010556 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
10557 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -070010558 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010559 goto cds_disable;
10560 }
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010561 status = policy_mgr_register_mode_change_cb(hdd_ctx->hdd_psoc,
10562 wlan_hdd_send_mode_change_event);
10563 if (!QDF_IS_STATUS_SUCCESS(status)) {
10564 hdd_debug("Failed to register mode change cb with Policy Manager");
10565 goto cds_disable;
10566 }
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010567
Jeff Johnson8bb61112018-03-31 13:33:54 -070010568 if (hdd_green_ap_enable_egap(hdd_ctx))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +053010569 hdd_debug("enhance green ap is not enabled");
10570
Nachiket Kukadedd302662017-07-13 17:31:44 +053010571 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
10572 hdd_debug("Failed to set wow pulse");
10573
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053010574 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
10575 hdd_ctx->config->gcmp_enabled, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053010576 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
10577 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
10578
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053010579
10580 if (hdd_ctx->config->enable_phy_reg_retention)
10581 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
10582 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
10583
Arun Khandavallifae92942016-08-01 13:31:08 +053010584 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010585
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010586cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010587 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010588
Arun Khandavallifae92942016-08-01 13:31:08 +053010589out:
10590 return -EINVAL;
10591}
10592
10593/**
10594 * hdd_deconfigure_cds() -De-Configure cds
10595 * @hdd_ctx: HDD context
10596 *
10597 * Deconfigure Cds modules before WLAN firmware is down.
10598 *
10599 * Return: 0 on success and errno on failure.
10600 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010601static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010602{
10603 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070010604 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053010605
Dustin Brown491d54b2018-03-14 12:39:11 -070010606 hdd_enter();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010607
10608 /* De-init features */
10609 hdd_features_deinit(hdd_ctx);
10610
Arun Khandavallifae92942016-08-01 13:31:08 +053010611 /* De-register the SME callbacks */
10612 hdd_deregister_cb(hdd_ctx);
10613
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010614 qdf_status = policy_mgr_deregister_mode_change_cb(hdd_ctx->hdd_psoc);
10615 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10616 hdd_debug("Failed to deregister mode change cb with Policy Manager");
10617 }
10618
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010619 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010620 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10621 hdd_err("Failed to Disable the CDS Modules! :%d",
10622 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070010623 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010624 }
10625
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010626 if (ucfg_ipa_uc_ol_deinit(hdd_ctx->hdd_pdev) != QDF_STATUS_SUCCESS) {
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053010627 hdd_err("Failed to disconnect pipes");
10628 ret = -EINVAL;
10629 }
10630
Dustin Browne74003f2018-03-14 12:51:58 -070010631 hdd_exit();
Houston Hoffman6640cf32016-10-10 16:44:29 -070010632 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010633}
10634
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010635#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
10636static void hdd_deregister_policy_manager_callback(
10637 struct wlan_objmgr_psoc *psoc)
10638{
10639 if (QDF_STATUS_SUCCESS !=
10640 policy_mgr_deregister_hdd_cb(psoc)) {
10641 hdd_err("HDD callback deregister with policy manager failed");
10642 }
10643}
10644#else
10645static void hdd_deregister_policy_manager_callback(
10646 struct wlan_objmgr_psoc *psoc)
10647{
10648}
10649#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010650
10651/**
10652 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
10653 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010654 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +053010655 *
10656 * This function maintains the driver state machine it will be invoked from
10657 * exit, shutdown and con_mode change handler. Depending on the driver state
10658 * shall perform the stopping/closing of the modules.
10659 *
10660 * Return: 0 for success; non-zero for failure
10661 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010662int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053010663{
10664 void *hif_ctx;
10665 qdf_device_t qdf_ctx;
10666 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010667 int ret = 0;
Dustin Brown4bc0a622017-12-06 15:56:50 -080010668 bool is_recovery_stop = cds_is_driver_recovering();
Liangwei Donga78cc1d2018-02-01 02:19:30 -050010669 bool is_idle_stop = !cds_is_driver_unloading() && !is_recovery_stop &&
10670 !cds_is_driver_loading();
Dustin Brown70111822017-03-30 15:31:40 -070010671 int active_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010672 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053010673
Dustin Brown491d54b2018-03-14 12:39:11 -070010674 hdd_enter();
Yun Parkfec73dc2017-09-06 10:40:07 -070010675 hdd_alert("stop WLAN module: entering driver status=%d",
10676 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +053010677
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010678 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
10679
Arun Khandavallifae92942016-08-01 13:31:08 +053010680 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
10681 if (!qdf_ctx) {
10682 hdd_err("QDF device context NULL");
10683 return -EINVAL;
10684 }
10685
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010686 mutex_lock(&hdd_ctx->iface_change_lock);
10687 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010688 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053010689
Dustin Brown70111822017-03-30 15:31:40 -070010690 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -070010691 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -070010692 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -070010693 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -070010694
10695 cds_print_external_threads();
10696
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010697 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070010698 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -070010699 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10700 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010701 hdd_prevent_suspend_timeout(
10702 hdd_ctx->config->iface_change_wait_time,
10703 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010704 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010705 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -070010706 return 0;
10707 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070010708 }
10709
Arun Khandavallifae92942016-08-01 13:31:08 +053010710 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
10711
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080010712 /* free user wowl patterns */
10713 hdd_free_user_wowl_ptrns();
10714
Arun Khandavallifae92942016-08-01 13:31:08 +053010715 switch (hdd_ctx->driver_status) {
10716 case DRIVER_MODULES_UNINITIALIZED:
10717 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010718 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010719 case DRIVER_MODULES_CLOSED:
10720 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010721 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010722 case DRIVER_MODULES_ENABLED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010723 hdd_info("Wlan transitioning (OPENED <- ENABLED)");
10724
Komal Seelamf2136bb2016-09-28 18:30:44 +053010725 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053010726 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010727 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053010728 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010729 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010730 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010731 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080010732
Arun Khandavallifae92942016-08-01 13:31:08 +053010733 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010734 hdd_info("Wlan transitioned (now OPENED)");
10735
10736 /* fall through */
Arun Khandavallifae92942016-08-01 13:31:08 +053010737 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010738 hdd_info("Wlan transitioning (CLOSED <- OPENED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010739 break;
10740 default:
10741 hdd_err("Trying to stop wlan in a wrong state: %d",
10742 hdd_ctx->driver_status);
10743 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010744 ret = -EINVAL;
10745 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010746 }
10747
Amar Singhal18081642018-01-26 16:04:13 -080010748 hdd_sysfs_destroy_version_interface();
Dustin Brown550f6d22017-12-14 15:44:01 -080010749 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080010750
Rajeev Kumarbe021242017-02-16 16:12:23 -080010751 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053010752 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10753 hdd_err("Failed to process post CDS disable Modules! :%d",
10754 qdf_status);
10755 ret = -EINVAL;
10756 QDF_ASSERT(0);
10757 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010758
psimhadeea0a12017-12-18 14:50:02 -080010759 hdd_runtime_suspend_context_deinit(hdd_ctx);
10760
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010761 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
10762 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10763 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
10764 ret = -EINVAL;
10765 QDF_ASSERT(0);
10766 }
10767
Jeff Johnsone4b14592017-09-13 14:23:33 -070010768 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010769 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010770 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053010771 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010772 QDF_ASSERT(0);
10773 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -070010774
Amar Singhal410675c2018-01-10 12:14:21 -080010775 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Liangwei Dong50a64a72018-01-11 01:17:00 -050010776 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
10777 if (ret) {
10778 hdd_err("Failed to destroy pdev; errno:%d", ret);
10779 QDF_ASSERT(0);
10780 }
10781
10782 /*
10783 * Reset total mac phy during module stop such that during
10784 * next module start same psoc is used to populate new service
10785 * ready data
10786 */
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010787 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
10788 if (tgt_hdl)
10789 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
10790
Liangwei Dong50a64a72018-01-11 01:17:00 -050010791
Arun Khandavallifae92942016-08-01 13:31:08 +053010792 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
10793 if (!hif_ctx) {
10794 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010795 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010796 }
10797
Arunk Khandavalli4b404332017-09-26 12:46:00 +053010798 if (hdd_ctx->target_hw_name) {
10799 qdf_mem_free(hdd_ctx->target_hw_name);
10800 hdd_ctx->target_hw_name = NULL;
10801 }
10802
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053010803 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010804
10805 ol_cds_free();
10806
Dustin Brown70111822017-03-30 15:31:40 -070010807 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +053010808 ret = pld_power_off(qdf_ctx->dev);
10809 if (ret)
10810 hdd_err("CNSS power down failed put device into Low power mode:%d",
10811 ret);
10812 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010813
Dustin Brown4bc0a622017-12-06 15:56:50 -080010814 /* many adapter resources are not freed by design in SSR case */
10815 if (!is_recovery_stop)
Dustin Browna6246dd2018-05-24 14:35:58 -070010816 hdd_check_for_leaks(hdd_ctx);
Dustin Brown26b3d042017-12-21 11:13:27 -080010817 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010818
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010819 /* Once the firmware sequence is completed reset this flag */
10820 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053010821 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010822 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010823
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010824done:
10825 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010826 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010827 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -070010828 hdd_alert("stop WLAN module: exit driver status=%d",
10829 hdd_ctx->driver_status);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010830
Dustin Browne74003f2018-03-14 12:51:58 -070010831 hdd_exit();
Arun Khandavallifae92942016-08-01 13:31:08 +053010832
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010833 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010834}
10835
Arun Khandavallifae92942016-08-01 13:31:08 +053010836
Wen Gong3f003382018-05-14 14:26:37 +080010837#ifdef WLAN_FEATURE_MEMDUMP_ENABLE
Arun Khandavallifae92942016-08-01 13:31:08 +053010838/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010839 * hdd_state_info_dump() - prints state information of hdd layer
10840 * @buf: buffer pointer
10841 * @size: size of buffer to be filled
10842 *
10843 * This function is used to dump state information of hdd layer
10844 *
10845 * Return: None
10846 */
10847static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
10848{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010849 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070010850 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070010851 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010852 uint16_t len = 0;
10853 char *buf = *buf_ptr;
10854
10855 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10856 if (!hdd_ctx) {
10857 hdd_err("Failed to get hdd context ");
10858 return;
10859 }
10860
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010861 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010862
10863 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070010864 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010865 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080010866 "\n is_scheduler_suspended %d",
10867 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010868
Dustin Brown920397d2017-12-13 16:27:50 -080010869 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010870 if (adapter->dev)
10871 len += scnprintf(buf + len, *size - len,
10872 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080010873 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010874 "\n device_mode: %d", adapter->device_mode);
10875 switch (adapter->device_mode) {
10876 case QDF_STA_MODE:
10877 case QDF_P2P_CLIENT_MODE:
10878 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
10879 len += scnprintf(buf + len, *size - len,
10880 "\n connState: %d",
10881 hdd_sta_ctx->conn_info.connState);
10882 break;
10883
10884 default:
10885 break;
10886 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010887 }
10888
10889 *size -= len;
10890 *buf_ptr += len;
10891}
10892
10893/**
10894 * hdd_register_debug_callback() - registration function for hdd layer
10895 * to print hdd state information
10896 *
10897 * Return: None
10898 */
10899static void hdd_register_debug_callback(void)
10900{
10901 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
10902}
Wen Gong3f003382018-05-14 14:26:37 +080010903#else /* WLAN_FEATURE_MEMDUMP_ENABLE */
Wen Gongaa6d55d2018-04-26 16:33:21 +080010904static void hdd_register_debug_callback(void)
10905{
10906}
Wen Gong3f003382018-05-14 14:26:37 +080010907#endif /* WLAN_FEATURE_MEMDUMP_ENABLE */
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010908
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053010909/*
10910 * wlan_init_bug_report_lock() - Initialize bug report lock
10911 *
10912 * This function is used to create bug report lock
10913 *
10914 * Return: None
10915 */
10916static void wlan_init_bug_report_lock(void)
10917{
Jeff Johnson2b6982c2018-05-29 14:56:11 -070010918 struct cds_context *p_cds_context;
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053010919
10920 p_cds_context = cds_get_global_context();
10921 if (!p_cds_context) {
10922 hdd_err("cds context is NULL");
10923 return;
10924 }
10925
10926 qdf_spinlock_create(&p_cds_context->bug_report_lock);
10927}
10928
Nirav Shahd21a2e32018-04-20 16:34:43 +053010929#ifdef CONFIG_DP_TRACE
Mohit Khannaf8f96822017-05-17 17:11:59 -070010930void hdd_dp_trace_init(struct hdd_config *config)
10931{
10932
10933 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
10934 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
10935 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
10936 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
10937 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
10938 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
10939 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080010940 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070010941
Nirav Shahd21a2e32018-04-20 16:34:43 +053010942 if (!config->enable_dp_trace) {
10943 hdd_err("dp trace is disabled from ini");
10944 return;
10945 }
10946
Mohit Khannaf8f96822017-05-17 17:11:59 -070010947 hdd_string_to_u8_array(config->dp_trace_config, config_params,
10948 &num_entries, sizeof(config_params));
10949
10950 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080010951 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010952 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080010953 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010954 else if (bw_compute_interval > 1000) {
10955 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
10956 thresh_time_limit = 1;
10957 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070010958 hdd_err("busBandwidthComputeInterval is 0, using defaults");
10959
10960 switch (num_entries) {
10961 case 4:
10962 proto_bitmap = config_params[3];
Alok Kumarb5a33a22018-05-07 18:09:14 +053010963 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070010964 case 3:
10965 verbosity = config_params[2];
Alok Kumarb5a33a22018-05-07 18:09:14 +053010966 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070010967 case 2:
10968 thresh = config_params[1];
Alok Kumarb5a33a22018-05-07 18:09:14 +053010969 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070010970 case 1:
10971 live_mode = config_params[0];
Alok Kumarb5a33a22018-05-07 18:09:14 +053010972 /* fall through */
Mohit Khannaf8f96822017-05-17 17:11:59 -070010973 default:
Rajeev Kumar3887f9b2018-01-10 11:24:01 -080010974 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
Mohit Khannaf8f96822017-05-17 17:11:59 -070010975 live_mode, thresh, thresh_time_limit,
10976 verbosity, proto_bitmap);
10977 };
10978
10979 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
10980 verbosity, proto_bitmap);
10981
10982}
Nirav Shahd21a2e32018-04-20 16:34:43 +053010983#endif
10984
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010985/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010986 * hdd_wlan_startup() - HDD init function
10987 * @dev: Pointer to the underlying device
10988 *
10989 * This is the driver startup code executed once a WLAN device has been detected
10990 *
10991 * Return: 0 for success, < 0 for failure
10992 */
Arun Khandavallifae92942016-08-01 13:31:08 +053010993int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010994{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010995 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010996 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010997 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010998 bool rtnl_held;
Jeff Johnson16528362018-06-14 12:34:16 -070010999 mac_handle_t mac_handle;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011000
Dustin Brown491d54b2018-03-14 12:39:11 -070011001 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011002
Arun Khandavallifae92942016-08-01 13:31:08 +053011003 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011004
11005 if (IS_ERR(hdd_ctx))
11006 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011007
Abhishek Singhe9068f12017-03-31 14:14:52 +053011008 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
11009 DEFAULT_PSOC_ID);
11010 if (ret) {
11011 hdd_err("Psoc creation fails!");
11012 QDF_BUG(0);
11013 goto err_hdd_free_context;
11014 }
11015
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053011016 qdf_nbuf_init_replenish_timer();
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053011017#ifdef FEATURE_WLAN_CH_AVOID
11018 mutex_init(&hdd_ctx->avoid_freq_lock);
11019#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053011020
Naveen Rawate02f8f52018-04-05 11:58:04 -070011021 osif_request_manager_init();
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053011022 qdf_atomic_init(&hdd_ctx->con_mode_flag);
Arun Khandavallifae92942016-08-01 13:31:08 +053011023
Dustin Brown021cecd2017-12-11 13:56:43 -080011024 hdd_driver_memdump_init();
11025
Dustin Browne7e71d32018-05-11 16:00:08 -070011026 ret = hdd_wlan_start_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053011027 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011028 hdd_err("Failed to start modules: %d", ret);
Dustin Brown021cecd2017-12-11 13:56:43 -080011029 goto err_memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011030 }
11031
Yingying Tang80e15f32016-09-27 18:23:01 +080011032 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011033
Jeff Johnson16528362018-06-14 12:34:16 -070011034 mac_handle = cds_get_context(QDF_MODULE_ID_SME);
11035 hdd_ctx->mac_handle = mac_handle;
11036 if (!mac_handle) {
11037 hdd_err("Mac Handle is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053011038 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011039 }
11040
Prashanth Bhatta07998752016-04-28 12:35:33 -070011041 ret = hdd_wiphy_init(hdd_ctx);
11042 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011043 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053011044 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011045 }
11046
Nirav Shahd21a2e32018-04-20 16:34:43 +053011047 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053011048
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070011049 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080011050
Paul Zhangfb02f452017-12-22 11:58:43 +080011051 ret = register_netdevice_notifier(&hdd_netdev_notifier);
11052 if (ret) {
11053 hdd_err("register_netdevice_notifier failed: %d", ret);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053011054 goto err_wiphy_unregister;
Paul Zhangfb02f452017-12-22 11:58:43 +080011055 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053011056
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011057 ret = register_reboot_notifier(&system_reboot_notifier);
11058 if (ret) {
11059 hdd_err("Failed to register reboot notifier: %d", ret);
11060 goto err_unregister_netdev;
11061 }
11062
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080011063 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011064
Jeff Johnson957bc272017-02-02 08:54:48 -080011065 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
11066 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011067 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080011068 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011069 }
11070
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080011071 hdd_release_rtnl_lock();
11072 rtnl_held = false;
11073
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080011074 wlan_hdd_update_11n_mode(hdd_ctx->config);
11075
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011076#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053011077 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053011078 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011079 hdd_skip_acs_scan_timer_handler,
11080 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011081 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070011082 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040011083 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011084#endif
11085
Prashanth Bhattaab004382016-10-11 16:08:11 -070011086 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011087
Jeff Johnson9afc5012016-09-23 13:56:27 -070011088 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011089
Nirav Shahbd36b062016-07-18 11:12:59 +053011090 if (hdd_ctx->rps)
11091 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070011092
Paul Zhangfb02f452017-12-22 11:58:43 +080011093 ret = hdd_register_notifiers(hdd_ctx);
11094 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -080011095 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070011096
Paul Zhangfb02f452017-12-22 11:58:43 +080011097 status = wlansap_global_init();
11098 if (QDF_IS_STATUS_ERROR(status)) {
11099 hdd_unregister_notifiers(hdd_ctx);
11100 goto err_close_adapters;
11101 }
11102
Arun Khandavallifae92942016-08-01 13:31:08 +053011103 if (hdd_ctx->config->fIsImpsEnabled)
11104 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070011105 else
11106 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011107
Mukul Sharma07bd8752017-10-10 16:58:14 +053011108 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070011109 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
11110 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053011111 hdd_prevent_suspend_timeout(
11112 hdd_ctx->config->iface_change_wait_time,
11113 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
11114 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053011115
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011116 goto success;
11117
Jeff Johnson957bc272017-02-02 08:54:48 -080011118err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080011119 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011120
Jeff Johnson46bde382017-02-01 15:31:16 -080011121err_release_rtnl_lock:
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011122 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavallid4349a92016-07-25 11:10:43 +053011123 if (rtnl_held)
11124 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011125
Arunk Khandavalli830c9692018-03-22 12:17:40 +053011126err_unregister_netdev:
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053011127 unregister_netdevice_notifier(&hdd_netdev_notifier);
11128
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011129err_wiphy_unregister:
Rachit Kankane30807332018-06-27 18:39:36 +053011130 qdf_dp_trace_deinit();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011131 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011132
Arun Khandavallifae92942016-08-01 13:31:08 +053011133err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070011134 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053011135
Dustin Brown021cecd2017-12-11 13:56:43 -080011136err_memdump_deinit:
11137 hdd_driver_memdump_deinit();
Dustin Brown021cecd2017-12-11 13:56:43 -080011138
Naveen Rawate02f8f52018-04-05 11:58:04 -070011139 osif_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070011140 hdd_exit_netlink_services(hdd_ctx);
11141
Dustin Brown20912462017-06-07 13:48:25 -070011142 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
11143
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080011144err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053011145 if (cds_is_fw_down())
11146 hdd_err("Not setting the complete event as fw is down");
11147 else
11148 hdd_start_complete(ret);
11149
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053011150 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070011151 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070011152 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011153
11154success:
Dustin Browne74003f2018-03-14 12:51:58 -070011155 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011156 return 0;
11157}
11158
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011159/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011160 * hdd_wlan_update_target_info() - update target type info
11161 * @hdd_ctx: HDD context
11162 * @context: hif context
11163 *
11164 * Update target info received from firmware in hdd context
11165 * Return:None
11166 */
11167
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011168void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053011169{
11170 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
11171
11172 if (!tgt_info) {
11173 hdd_err("Target info is Null");
11174 return;
11175 }
11176
11177 hdd_ctx->target_type = tgt_info->target_type;
11178}
11179
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011180void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp, void *context)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011181{
11182 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011183 int status;
11184 struct hdd_adapter *adapter = NULL;
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011185 struct osif_request *request = NULL;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011186
Dustin Brown491d54b2018-03-14 12:39:11 -070011187 hdd_enter();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011188
11189 if (!rsp) {
11190 hdd_err("data is null");
11191 return;
11192 }
11193
11194 status = wlan_hdd_validate_context(hdd_ctx);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011195 if (status != 0)
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011196 return;
11197
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011198 request = osif_request_get(context);
Dundi Raviteja3bcf3a82018-05-22 13:24:18 +053011199 if (!request) {
11200 hdd_err("obselete request");
11201 return;
11202 }
11203
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011204 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
11205 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
11206 hdd_err("Invalid adapter or adapter has invalid magic");
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011207 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011208 return;
11209 }
11210
Dustin Brown5e89ef82018-03-14 11:50:23 -070011211 hdd_info("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
11212 hdd_info("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
11213 hdd_info("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
11214 hdd_info("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
11215 hdd_info("rsp->out_of_order_arp_rsp_drop_cnt :%x",
11216 rsp->out_of_order_arp_rsp_drop_cnt);
11217 hdd_info("rsp->dad_detected :%x", rsp->dad_detected);
11218 hdd_info("rsp->connect_status :%x", rsp->connect_status);
11219 hdd_info("rsp->ba_session_establishment_status :%x",
11220 rsp->ba_session_establishment_status);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011221
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011222 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011223 adapter->dad |= rsp->dad_detected;
11224 adapter->con_status = rsp->connect_status;
11225
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053011226 /* Flag true indicates connectivity check stats present. */
11227 if (rsp->connect_stats_present) {
11228 hdd_info("rsp->tcp_ack_recvd :%x", rsp->tcp_ack_recvd);
11229 hdd_info("rsp->icmpv4_rsp_recvd :%x", rsp->icmpv4_rsp_recvd);
11230 adapter->hdd_stats.hdd_tcp_stats.rx_fw_cnt = rsp->tcp_ack_recvd;
11231 adapter->hdd_stats.hdd_icmpv4_stats.rx_fw_cnt =
11232 rsp->icmpv4_rsp_recvd;
11233 }
11234
Jeff Johnsonf1a99ea2018-06-28 13:27:01 -070011235 osif_request_complete(request);
11236 osif_request_put(request);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011237
Dustin Browne74003f2018-03-14 12:51:58 -070011238 hdd_exit();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053011239}
11240
11241/**
Arun Khandavallifae92942016-08-01 13:31:08 +053011242 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011243 * @hdd_ctx: HDD context
11244 *
11245 * Register the HDD callbacks to CDS/SME.
11246 *
11247 * Return: 0 for success or Error code for failure
11248 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011249int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011250{
11251 QDF_STATUS status;
11252 int ret = 0;
Jeff Johnson16528362018-06-14 12:34:16 -070011253 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011254
Dustin Brown491d54b2018-03-14 12:39:11 -070011255 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011256
Jeff Johnson16528362018-06-14 12:34:16 -070011257 mac_handle = hdd_ctx->mac_handle;
11258 sme_register11d_scan_done_callback(mac_handle, hdd_11d_scan_done);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011259
Jeff Johnson16528362018-06-14 12:34:16 -070011260 sme_register_oem_data_rsp_callback(mac_handle,
11261 hdd_send_oem_data_rsp_msg);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011262
Jeff Johnson16528362018-06-14 12:34:16 -070011263 sme_register_mgmt_frame_ind_callback(mac_handle,
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053011264 hdd_indicate_mgmt_frame);
Jeff Johnson16528362018-06-14 12:34:16 -070011265 sme_set_tsfcb(mac_handle, hdd_get_tsf_cb, hdd_ctx);
11266 sme_nan_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011267 wlan_hdd_cfg80211_nan_callback);
Jeff Johnson16528362018-06-14 12:34:16 -070011268 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011269 wlan_hdd_cfg80211_stats_ext_callback);
11270
Jeff Johnson16528362018-06-14 12:34:16 -070011271 sme_ext_scan_register_callback(mac_handle,
11272 wlan_hdd_cfg80211_extscan_callback);
11273 sme_stats_ext2_register_callback(mac_handle,
lifeng66831662017-05-19 16:01:35 +080011274 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011275
Jeff Johnson16528362018-06-14 12:34:16 -070011276 sme_set_rssi_threshold_breached_cb(mac_handle,
11277 hdd_rssi_threshold_breached);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011278
Jeff Johnson16528362018-06-14 12:34:16 -070011279 sme_set_link_layer_stats_ind_cb(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011280 wlan_hdd_cfg80211_link_layer_stats_callback);
11281
Jeff Johnson16528362018-06-14 12:34:16 -070011282 sme_rso_cmd_status_cb(mac_handle, wlan_hdd_rso_cmd_status_cb);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053011283
Jeff Johnson16528362018-06-14 12:34:16 -070011284 sme_set_link_layer_ext_cb(mac_handle,
Zhang Qianca38fb12016-12-23 11:10:48 +080011285 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
11286
Jeff Johnson16528362018-06-14 12:34:16 -070011287 status = sme_set_lost_link_info_cb(mac_handle,
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053011288 hdd_lost_link_info_cb);
11289 /* print error and not block the startup process */
11290 if (!QDF_IS_STATUS_SUCCESS(status))
11291 hdd_err("set lost link info callback failed");
11292
Poddar, Siddarth34872782017-08-10 14:08:51 +053011293 ret = hdd_register_data_stall_detect_cb();
11294 if (ret) {
11295 hdd_err("Register data stall detect detect callback failed.");
11296 return ret;
11297 }
11298
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011299 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
11300
Jeff Johnson16528362018-06-14 12:34:16 -070011301 sme_register_set_connection_info_cb(mac_handle,
11302 hdd_set_connection_in_progress,
11303 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053011304
Jeff Johnson16528362018-06-14 12:34:16 -070011305 status = sme_congestion_register_callback(mac_handle,
11306 hdd_update_cca_info_cb);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053011307 if (!QDF_IS_STATUS_SUCCESS(status))
11308 hdd_err("set congestion callback failed");
11309
Jeff Johnson16528362018-06-14 12:34:16 -070011310 status = sme_set_bt_activity_info_cb(mac_handle,
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053011311 hdd_bt_activity_cb);
11312 if (!QDF_IS_STATUS_SUCCESS(status))
11313 hdd_err("set bt activity info callback failed");
11314
Jeff Johnson16528362018-06-14 12:34:16 -070011315 status = sme_register_tx_queue_cb(mac_handle,
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080011316 hdd_tx_queue_cb);
11317 if (!QDF_IS_STATUS_SUCCESS(status))
11318 hdd_err("Register tx queue callback failed");
11319
Dustin Browne74003f2018-03-14 12:51:58 -070011320 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011321
11322 return ret;
11323}
11324
11325/**
11326 * hdd_deregister_cb() - De-Register HDD callbacks.
11327 * @hdd_ctx: HDD context
11328 *
11329 * De-Register the HDD callbacks to CDS/SME.
11330 *
11331 * Return: void
11332 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011333void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011334{
11335 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053011336 int ret;
Jeff Johnson16528362018-06-14 12:34:16 -070011337 mac_handle_t mac_handle;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011338
Dustin Brown491d54b2018-03-14 12:39:11 -070011339 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011340
Jeff Johnson16528362018-06-14 12:34:16 -070011341 mac_handle = hdd_ctx->mac_handle;
11342 sme_deregister_tx_queue_cb(mac_handle);
11343 status = sme_deregister_for_dcc_stats_event(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011344 if (!QDF_IS_STATUS_SUCCESS(status))
11345 hdd_err("De-register of dcc stats callback failed: %d",
11346 status);
11347
Jeff Johnson16528362018-06-14 12:34:16 -070011348 sme_reset_link_layer_stats_ind_cb(mac_handle);
11349 sme_reset_rssi_threshold_breached_cb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011350
Jeff Johnson16528362018-06-14 12:34:16 -070011351 sme_stats_ext_register_callback(mac_handle,
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011352 wlan_hdd_cfg80211_stats_ext_callback);
11353
Jeff Johnson16528362018-06-14 12:34:16 -070011354 sme_nan_deregister_callback(mac_handle);
11355 status = sme_reset_tsfcb(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011356 if (!QDF_IS_STATUS_SUCCESS(status))
11357 hdd_err("Failed to de-register tsfcb the callback:%d",
11358 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011359
Poddar, Siddarth34872782017-08-10 14:08:51 +053011360 ret = hdd_deregister_data_stall_detect_cb();
11361 if (ret)
11362 hdd_err("Failed to de-register data stall detect event callback");
11363
Jeff Johnson16528362018-06-14 12:34:16 -070011364 sme_deregister_oem_data_rsp_callback(mac_handle);
11365 sme_deregister11d_scan_done_callback(mac_handle);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011366
Dustin Browne74003f2018-03-14 12:51:58 -070011367 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011368}
11369
11370/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011371 * hdd_softap_sta_deauth() - handle deauth req from HDD
11372 * @adapter: Pointer to the HDD
11373 * @enable: bool value
11374 *
11375 * This to take counter measure to handle deauth req from HDD
11376 *
11377 * Return: None
11378 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011379QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011380 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011381{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011382 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011383
Dustin Brown491d54b2018-03-14 12:39:11 -070011384 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011385
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011386 /* Ignore request to deauth bcmc station */
11387 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011388 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011389
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011390 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011391 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
11392 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011393
Dustin Browne74003f2018-03-14 12:51:58 -070011394 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011395 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011396}
11397
11398/**
11399 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
11400 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011401 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011402 *
11403 * This to take counter measure to handle deauth req from HDD
11404 *
11405 * Return: None
11406 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011407void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011408 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011409{
Dustin Brown491d54b2018-03-14 12:39:11 -070011410 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011411
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011412 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011413 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011414 return;
11415
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011416 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011417 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011418}
11419
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011420/**
11421 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
11422 * @hdd_ctx: HDD Context
11423 *
11424 * API to find if there is any STA or P2P-Client is connected
11425 *
11426 * Return: true if connected; false otherwise
11427 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011428QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011429{
Jeff Johnson16528362018-06-14 12:34:16 -070011430 return sme_is_sta_p2p_client_connected(hdd_ctx->mac_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011431}
11432
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011433void wlan_hdd_disable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011434{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011435 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
11436 struct hdd_adapter *adapter = NULL;
11437 struct csr_roam_profile *roam_profile;
11438 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011439
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011440 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->hdd_psoc)) {
11441 hdd_debug("No active sta session");
11442 return;
11443 }
11444
11445 hdd_for_each_adapter(hdd_ctx, adapter) {
11446 roam_profile = hdd_roam_profile(adapter);
11447 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11448
11449 if (cur_adapter->session_id != adapter->session_id &&
11450 adapter->device_mode == QDF_STA_MODE &&
11451 hdd_conn_is_connected(sta_ctx)) {
11452 hdd_debug("%d Disable roaming", adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -070011453 sme_stop_roaming(hdd_ctx->mac_handle,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011454 adapter->session_id,
11455 ecsr_driver_disabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011456 }
11457 }
11458}
11459
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011460void wlan_hdd_enable_roaming(struct hdd_adapter *cur_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011461{
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011462 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(cur_adapter);
11463 struct hdd_adapter *adapter = NULL;
11464 struct csr_roam_profile *roam_profile;
11465 struct hdd_station_ctx *sta_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011466
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011467 if (!policy_mgr_is_sta_active_connection_exists(hdd_ctx->hdd_psoc)) {
11468 hdd_debug("No active sta session");
11469 return;
11470 }
11471
11472 hdd_for_each_adapter(hdd_ctx, adapter) {
11473 roam_profile = hdd_roam_profile(adapter);
11474 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
11475
11476 if (cur_adapter->session_id != adapter->session_id &&
11477 adapter->device_mode == QDF_STA_MODE &&
11478 hdd_conn_is_connected(sta_ctx)) {
11479 hdd_debug("%d Enable roaming", adapter->session_id);
Jeff Johnson16528362018-06-14 12:34:16 -070011480 sme_start_roaming(hdd_ctx->mac_handle,
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053011481 adapter->session_id,
11482 REASON_DRIVER_ENABLED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011483 }
11484 }
11485}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011486
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011487/**
11488 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
11489 * @skb: sk buffer pointer
11490 *
11491 * Sends the bcast message to SVC multicast group with generic nl socket
11492 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
11493 *
11494 * Return: None
11495 */
11496static void nl_srv_bcast_svc(struct sk_buff *skb)
11497{
11498#ifdef CNSS_GENL
11499 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
11500#else
11501 nl_srv_bcast(skb);
11502#endif
11503}
11504
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011505void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011506{
11507 struct sk_buff *skb;
11508 struct nlmsghdr *nlh;
11509 tAniMsgHdr *ani_hdr;
11510 void *nl_data = NULL;
11511 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011512 struct radio_index_tlv *radio_info;
11513 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011514
11515 if (in_interrupt() || irqs_disabled() || in_atomic())
11516 flags = GFP_ATOMIC;
11517
11518 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
11519
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011520 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011521 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011522
11523 nlh = (struct nlmsghdr *)skb->data;
11524 nlh->nlmsg_pid = 0; /* from kernel */
11525 nlh->nlmsg_flags = 0;
11526 nlh->nlmsg_seq = 0;
11527 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
11528
11529 ani_hdr = NLMSG_DATA(nlh);
11530 ani_hdr->type = type;
11531
11532 switch (type) {
11533 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053011534 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011535 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011536 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011537 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011538 ani_hdr->length = 0;
11539 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011540 break;
11541 case WLAN_SVC_WLAN_STATUS_IND:
11542 case WLAN_SVC_WLAN_VERSION_IND:
11543 case WLAN_SVC_DFS_CAC_START_IND:
11544 case WLAN_SVC_DFS_CAC_END_IND:
11545 case WLAN_SVC_DFS_RADAR_DETECT_IND:
11546 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
11547 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080011548 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053011549 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080011550 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011551 ani_hdr->length = len;
11552 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
11553 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
11554 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011555 break;
11556
11557 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070011558 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011559 type);
11560 kfree_skb(skb);
11561 return;
11562 }
11563
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011564 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080011565 * Add radio index at the end of the svc event in TLV format
11566 * to maintain the backward compatibility with userspace
11567 * applications.
11568 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011569
11570 tlv_len = 0;
11571
11572 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
11573 < WLAN_NL_MAX_PAYLOAD) {
11574 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
11575 sizeof(*ani_hdr) + len);
11576 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
11577 radio_info->length = (unsigned short) sizeof(radio_info->radio);
11578 radio_info->radio = radio;
11579 tlv_len = sizeof(*radio_info);
Dustin Browna2868622018-03-20 11:38:14 -070011580 hdd_debug("Added radio index tlv - radio index %d",
11581 radio_info->radio);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011582 }
11583
11584 nlh->nlmsg_len += tlv_len;
11585 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
11586
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011587 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011588}
11589
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011590#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
11591void wlan_hdd_auto_shutdown_cb(void)
11592{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011593 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011594
11595 if (!hdd_ctx)
11596 return;
11597
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011598 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011599 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
11600 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011601}
11602
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011603void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011604{
Jeff Johnson9d295242017-08-29 14:39:48 -070011605 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011606 bool ap_connected = false, sta_connected = false;
Jeff Johnson16528362018-06-14 12:34:16 -070011607 mac_handle_t mac_handle;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011608
Jeff Johnson16528362018-06-14 12:34:16 -070011609 mac_handle = hdd_ctx->mac_handle;
11610 if (!mac_handle)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011611 return;
11612
11613 if (hdd_ctx->config->WlanAutoShutdown == 0)
11614 return;
11615
11616 if (enable == false) {
Jeff Johnson16528362018-06-14 12:34:16 -070011617 if (sme_set_auto_shutdown_timer(mac_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011618 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011619 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011620 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011621 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011622 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011623 return;
11624 }
11625
11626 /* To enable shutdown timer check conncurrency */
Dustin Brown920397d2017-12-13 16:27:50 -080011627 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->hdd_psoc)) {
11628 hdd_for_each_adapter(hdd_ctx, adapter) {
11629 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011630 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11631 conn_info.connState ==
11632 eConnectionState_Associated) {
11633 sta_connected = true;
11634 break;
11635 }
11636 }
Dustin Brown920397d2017-12-13 16:27:50 -080011637
11638 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011639 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070011640 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011641 ap_connected = true;
11642 break;
11643 }
11644 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011645 }
11646 }
11647
11648 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011649 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011650 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011651 }
Jeff Johnson68755312017-02-10 11:46:55 -080011652
Jeff Johnson16528362018-06-14 12:34:16 -070011653 if (sme_set_auto_shutdown_timer(mac_handle,
Jeff Johnson68755312017-02-10 11:46:55 -080011654 hdd_ctx->config->WlanAutoShutdown)
11655 != QDF_STATUS_SUCCESS)
11656 hdd_err("Failed to start wlan auto shutdown timer");
11657 else
Dustin Brown5e89ef82018-03-14 11:50:23 -070011658 hdd_info("Auto Shutdown timer for %d seconds enabled",
11659 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011660}
11661#endif
11662
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011663struct hdd_adapter *
11664hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
11665 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011666{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011667 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011668 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011669
11670 con_sap_adapter = NULL;
11671
Dustin Brown920397d2017-12-13 16:27:50 -080011672 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011673 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
11674 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011675 adapter != this_sap_adapter) {
11676 if (check_start_bss) {
11677 if (test_bit(SOFTAP_BSS_STARTED,
11678 &adapter->event_flags)) {
11679 con_sap_adapter = adapter;
11680 break;
11681 }
11682 } else {
11683 con_sap_adapter = adapter;
11684 break;
11685 }
11686 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011687 }
11688
11689 return con_sap_adapter;
11690}
11691
11692#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070011693static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011694{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011695 return adapter->device_mode == QDF_STA_MODE ||
11696 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011697}
11698
Jeff Johnson9d295242017-08-29 14:39:48 -070011699static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011700{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011701 return adapter->device_mode == QDF_SAP_MODE ||
11702 adapter->device_mode == QDF_P2P_GO_MODE;
11703}
11704
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011705static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011706{
Dustin Brown920397d2017-12-13 16:27:50 -080011707 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070011708
Dustin Brown920397d2017-12-13 16:27:50 -080011709 hdd_for_each_adapter(hdd_ctx, adapter) {
11710 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070011711 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11712 conn_info.connState == eConnectionState_Associated) {
11713 return true;
11714 }
11715
Dustin Brown920397d2017-12-13 16:27:50 -080011716 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070011717 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070011718 return true;
11719 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011720 }
11721
11722 return false;
11723}
11724
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011725static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011726{
11727 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011728
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011729 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011730 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011731 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011732
Dustin Brown5ec6b552017-03-31 12:11:40 -070011733 return is_running;
11734}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011735
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011736static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011737{
11738 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11739 hdd_ctx->bus_bw_timer_running = true;
11740 qdf_timer_start(&hdd_ctx->bus_bw_timer,
11741 hdd_ctx->config->busBandwidthComputeInterval);
11742 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11743}
11744
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011745void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011746{
Dustin Brown491d54b2018-03-14 12:39:11 -070011747 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011748
11749 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11750 hdd_debug("Bandwidth compute timer already started");
11751 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011752 }
11753
Dustin Brown5ec6b552017-03-31 12:11:40 -070011754 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11755
Dustin Browne74003f2018-03-14 12:51:58 -070011756 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011757}
11758
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011759void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011760{
Dustin Brown491d54b2018-03-14 12:39:11 -070011761 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011762
11763 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11764 hdd_debug("Bandwidth compute timer already started");
11765 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070011766 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011767
11768 if (hdd_any_adapter_is_assoc(hdd_ctx))
11769 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11770
Dustin Browne74003f2018-03-14 12:51:58 -070011771 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011772}
11773
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011774static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011775{
Sravan Kumar Kairam9e99e9a2018-03-12 19:09:45 +053011776 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, 0, 0);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011777
11778 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11779 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
11780 hdd_ctx->bus_bw_timer_running = false;
11781 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11782
11783 hdd_reset_tcp_delack(hdd_ctx);
11784}
11785
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011786void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011787{
Dustin Brown491d54b2018-03-14 12:39:11 -070011788 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011789
11790 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11791 hdd_debug("Bandwidth compute timer already stopped");
11792 return;
11793 }
11794
11795 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11796
Dustin Browne74003f2018-03-14 12:51:58 -070011797 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011798}
11799
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011800void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011801{
Dustin Brown491d54b2018-03-14 12:39:11 -070011802 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011803
11804 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11805 hdd_debug("Bandwidth compute timer already stopped");
11806 return;
11807 }
11808
11809 if (!hdd_any_adapter_is_assoc(hdd_ctx))
11810 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11811
Dustin Browne74003f2018-03-14 12:51:58 -070011812 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011813}
11814#endif
11815
11816/**
11817 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
11818 * and sta's operating channel.
11819 * @sta_adapter: Describe the first argument to foobar.
11820 * @ap_adapter: Describe the second argument to foobar.
11821 * @roam_profile: Roam profile of AP to which STA wants to connect.
11822 * @concurrent_chnl_same: If both SAP and STA channels are same then
11823 * set this flag to true else false.
11824 *
11825 * This function checks the sap's operating channel and sta's operating channel.
11826 * if both are same then it will return false else it will restart the sap in
11827 * sta's channel and return true.
11828 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011829 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011830 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011831QDF_STATUS
11832wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
11833 struct hdd_adapter *ap_adapter,
Jeff Johnson61b5e982018-03-15 11:33:31 -070011834 struct csr_roam_profile *roam_profile,
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011835 tScanResultHandle *scan_cache,
11836 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011837{
Jeff Johnson87251032017-08-29 13:31:11 -070011838 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011839 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011840 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011841 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011842 *concurrent_chnl_same = true;
11843
11844 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11845 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070011846 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011847 scan_cache,
11848 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011849 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011850 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011851 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011852 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011853 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011854 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011855 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011856 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011857 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011858 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011859 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011860 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011861 }
11862 }
11863 } else {
11864 /*
11865 * Lets handle worst case scenario here, Scan cache lookup is
11866 * failed so we have to stop the SAP to avoid any channel
11867 * discrepancy between SAP's channel and STA's channel.
11868 * Return the status as failure so caller function could know
11869 * that scan look up is failed.
11870 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070011871 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011872 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011873 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011874 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011875}
11876
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011877/**
11878 * wlan_hdd_stop_sap() - This function stops bss of SAP.
11879 * @ap_adapter: SAP adapter
11880 *
11881 * This function will process the stopping of sap adapter.
11882 *
11883 * Return: None
11884 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011885void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011886{
Jeff Johnson87251032017-08-29 13:31:11 -070011887 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011888 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011889 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011890 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011891
11892 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011893 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011894 return;
11895 }
11896
11897 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11898 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011899 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011900 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011901
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011902 mutex_lock(&hdd_ctx->sap_lock);
11903 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080011904 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011905 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011906 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011907 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011908 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011909 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053011910 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080011911 qdf_stop_bss_event,
11912 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011913 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011914 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070011915 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011916 return;
11917 }
11918 }
11919 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011920 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
11921 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011922 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070011923 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011924 false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011925 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011926 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011927 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011928 }
11929 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011930}
11931
11932/**
11933 * wlan_hdd_start_sap() - this function starts bss of SAP.
11934 * @ap_adapter: SAP adapter
11935 *
11936 * This function will process the starting of sap adapter.
11937 *
11938 * Return: None
11939 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011940void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011941{
Jeff Johnson87251032017-08-29 13:31:11 -070011942 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011943 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011944 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011945 struct hdd_context *hdd_ctx;
Jeff Johnsone4c11db2018-05-05 23:22:32 -070011946 tsap_config_t *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011947
11948 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011949 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011950 return;
11951 }
11952
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011953 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070011954 hdd_err("SoftAp role has not been enabled");
11955 return;
11956 }
11957
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011958 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
11959 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11960 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070011961 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011962
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011963 mutex_lock(&hdd_ctx->sap_lock);
11964 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
11965 goto end;
11966
11967 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011968 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011969 goto end;
11970 }
11971
Wei Song2f76f642016-11-18 16:32:53 +080011972 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011973 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070011974 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011975 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011976 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011977 goto end;
11978
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011979 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053011980 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080011981 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011982 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011983 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011984 goto end;
11985 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070011986 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011987 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011988 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011989 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011990 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
11991 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011992 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070011993 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011994 true);
11995 }
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053011996 mutex_unlock(&hdd_ctx->sap_lock);
11997
11998 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011999end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053012000 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012001 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070012002 /* SAP context and beacon cleanup will happen during driver unload
12003 * in hdd_stop_adapter
12004 */
12005 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
12006
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012007}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012008
12009/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080012010 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
12011 * mac scan config
12012 * @status: Status of set antenna mode
12013 *
12014 * Callback on setting the dual mac configuration
12015 *
12016 * Return: None
12017 */
12018void wlan_hdd_soc_set_antenna_mode_cb(
12019 enum set_antenna_mode_status status)
12020{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012021 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080012022
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012023 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080012024
12025 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12026 if (0 != wlan_hdd_validate_context(hdd_ctx))
12027 return;
12028
12029 /* Signal the completion of set dual mac config */
12030 complete(&hdd_ctx->set_antenna_mode_cmpl);
12031}
12032
12033/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012034 * hdd_get_fw_version() - Get FW version
12035 * @hdd_ctx: pointer to HDD context.
12036 * @major_spid: FW version - major spid.
12037 * @minor_spid: FW version - minor spid
12038 * @ssid: FW version - ssid
12039 * @crmid: FW version - crmid
12040 *
12041 * This function is called to get the firmware build version stored
12042 * as part of the HDD context
12043 *
12044 * Return: None
12045 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012046void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012047 uint32_t *major_spid, uint32_t *minor_spid,
12048 uint32_t *siid, uint32_t *crmid)
12049{
12050 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
12051 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
12052 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
12053 *crmid = hdd_ctx->target_fw_version & 0x7fff;
12054}
12055
12056#ifdef QCA_CONFIG_SMP
12057/**
12058 * wlan_hdd_get_cpu() - get cpu_index
12059 *
12060 * Return: cpu_index
12061 */
12062int wlan_hdd_get_cpu(void)
12063{
12064 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012065
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080012066 put_cpu();
12067 return cpu_index;
12068}
12069#endif
12070
12071/**
12072 * hdd_get_fwpath() - get framework path
12073 *
12074 * This function is used to get the string written by
12075 * userspace to start the wlan driver
12076 *
12077 * Return: string
12078 */
12079const char *hdd_get_fwpath(void)
12080{
12081 return fwpath.string;
12082}
12083
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070012084static int hdd_qdf_print_init(void)
12085{
12086 int qdf_print_idx;
12087 QDF_STATUS status;
12088
12089 status = qdf_print_setup();
12090 if (status != QDF_STATUS_SUCCESS) {
12091 pr_err("qdf_print_setup failed\n");
12092 return -EINVAL;
12093 }
12094
12095 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
12096
12097 if (qdf_print_idx < 0) {
12098 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
12099 qdf_print_idx);
12100 return -EINVAL;
12101 }
12102
12103 qdf_set_pidx(qdf_print_idx);
12104
12105 return 0;
12106}
12107
12108static void hdd_qdf_print_deinit(void)
12109{
12110 int qdf_print_idx;
12111
12112 qdf_print_idx = qdf_get_pidx();
12113 qdf_print_ctrl_cleanup(qdf_print_idx);
12114}
12115
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012116/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012117 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012118 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012119 * This function initilizes CDS global context with the help of cds_init. This
12120 * has to be the first function called after probe to get a valid global
12121 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012122 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012123 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012124 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012125int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012126{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012127 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012128 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012129
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070012130 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080012131 if (QDF_IS_STATUS_ERROR(status)) {
12132 hdd_err("Failed to allocate CDS context");
12133 ret = -ENOMEM;
12134 goto err_out;
12135 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053012136
12137 wlan_init_bug_report_lock();
12138
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012139#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12140 wlan_logging_sock_init_svc();
12141#endif
12142
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012143 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
12144 (void *)hdd_drv_ops_inactivity_handler, NULL,
12145 QDF_TIMER_TYPE_SW);
12146
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012147 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070012148 hdd_qdf_print_init();
12149
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053012150 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012151
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012152err_out:
12153 return ret;
12154}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012155
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012156/**
12157 * hdd_deinit() - Deinitialize Driver
12158 *
12159 * This function frees CDS global context with the help of cds_deinit. This
12160 * has to be the last function call in remove callback to free the global
12161 * context.
12162 */
12163void hdd_deinit(void)
12164{
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053012165 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012166
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070012167 wlan_destroy_bug_report_lock();
12168 cds_deinit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070012169
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070012170 hdd_qdf_print_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012171#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
12172 wlan_logging_sock_deinit_svc();
12173#endif
12174}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012175
Yue Ma6e7b1a02017-04-03 14:17:46 -070012176#ifdef QCA_WIFI_NAPIER_EMULATION
12177#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
12178#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012179#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070012180#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012181
Sachin Ahujadddd2632017-03-07 19:07:24 +053012182static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
12183 struct file *file)
12184{
12185 return 0;
12186}
12187
12188static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
12189 const char __user *user_buf,
12190 size_t count,
12191 loff_t *f_pos)
12192{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012193 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053012194 static const char wlan_off_str[] = "OFF";
12195 static const char wlan_on_str[] = "ON";
12196 int ret;
12197 unsigned long rc;
12198
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012199 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012200 pr_err("Failed to read buffer\n");
12201 return -EINVAL;
12202 }
12203
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012204 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012205 pr_debug("Wifi turning off from UI\n");
12206 goto exit;
12207 }
12208
Sachin Ahuja16904db2017-12-13 19:56:57 +053012209 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) == 0) {
12210 pr_info("Wifi Turning On from UI\n");
12211 }
12212
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053012213 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053012214 pr_err("Invalid value received from framework");
12215 goto exit;
12216 }
12217
12218 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053012219 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053012220 rc = wait_for_completion_timeout(&wlan_start_comp,
12221 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
12222 if (!rc) {
12223 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
12224 ret = -EINVAL;
Sachin Ahujadddd2632017-03-07 19:07:24 +053012225 return ret;
12226 }
12227
12228 hdd_start_complete(0);
12229 }
12230
12231exit:
12232 return count;
12233}
12234
12235
12236const struct file_operations wlan_hdd_state_fops = {
12237 .owner = THIS_MODULE,
12238 .open = wlan_hdd_state_ctrl_param_open,
12239 .write = wlan_hdd_state_ctrl_param_write,
12240};
12241
12242static int wlan_hdd_state_ctrl_param_create(void)
12243{
12244 unsigned int wlan_hdd_state_major = 0;
12245 int ret;
12246 struct device *dev;
12247
12248 device = MKDEV(wlan_hdd_state_major, 0);
12249
12250 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
12251 if (ret) {
12252 pr_err("Failed to register qcwlanstate");
12253 goto dev_alloc_err;
12254 }
12255 wlan_hdd_state_major = MAJOR(device);
12256
12257 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
12258 if (IS_ERR(class)) {
12259 pr_err("wlan_hdd_state class_create error");
12260 goto class_err;
12261 }
12262
12263 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
12264 if (IS_ERR(dev)) {
12265 pr_err("wlan_hdd_statedevice_create error");
12266 goto err_class_destroy;
12267 }
12268
12269 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
12270 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
12271 if (ret) {
12272 pr_err("Failed to add cdev error");
12273 goto cdev_add_err;
12274 }
12275
12276 pr_info("wlan_hdd_state %s major(%d) initialized",
12277 WLAN_MODULE_NAME, wlan_hdd_state_major);
12278
12279 return 0;
12280
12281cdev_add_err:
12282 device_destroy(class, device);
12283err_class_destroy:
12284 class_destroy(class);
12285class_err:
12286 unregister_chrdev_region(device, dev_num);
12287dev_alloc_err:
12288 return -ENODEV;
12289}
12290
12291static void wlan_hdd_state_ctrl_param_destroy(void)
12292{
12293 cdev_del(&wlan_hdd_state_cdev);
12294 device_destroy(class, device);
12295 class_destroy(class);
12296 unregister_chrdev_region(device, dev_num);
12297
12298 pr_info("Device node unregistered");
12299}
12300
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012301/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053012302 * component_init - API to init cld component's
12303 *
12304 * Return: None
12305 */
12306static void component_init(void)
12307{
12308 pmo_init();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012309 disa_init();
Zhang Qian47e22ce2018-01-04 15:38:38 +080012310 ucfg_ocb_init();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053012311 ipa_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053012312}
12313
12314/**
12315 * component_deinit - API to deinit cld component's
12316 *
12317 * Return: None
12318 */
12319static void component_deinit(void)
12320{
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053012321 ipa_deinit();
Zhang Qian47e22ce2018-01-04 15:38:38 +080012322 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053012323 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012324 disa_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012325}
12326
12327void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
12328{
Zhang Qian47e22ce2018-01-04 15:38:38 +080012329 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012330 disa_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012331}
12332
12333void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
12334{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012335 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080012336 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053012337}
12338
12339/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012340 * __hdd_module_init - Module init helper
12341 *
12342 * Module init helper function used by both module and static driver.
12343 *
12344 * Return: 0 for success, errno on failure
12345 */
12346static int __hdd_module_init(void)
12347{
12348 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012349
Dustin Brown96cd9632017-11-13 12:45:04 -080012350 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070012351 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080012352 g_wlan_driver_version,
Dustin Brownc1034df2018-02-07 14:51:32 -080012353 TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012354
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012355 pld_init();
12356
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012357 ret = hdd_init();
12358 if (ret) {
12359 pr_err("hdd_init failed %x\n", ret);
12360 goto err_hdd_init;
12361 }
12362
Rajeev Kumar97767a02016-11-30 11:20:40 -080012363 dispatcher_init();
12364
Mukul Sharmad75a6672017-06-22 15:40:53 +053012365 /* Ensure to call post objmgr init */
12366 component_init();
12367
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012368 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012369
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012370 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012371
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012372 ret = wlan_hdd_register_driver();
12373 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070012374 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
12375 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012376 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012377 }
12378
Sachin Ahuja16904db2017-12-13 19:56:57 +053012379 ret = wlan_hdd_state_ctrl_param_create();
12380 if (ret) {
12381 pr_err("wlan_hdd_state_create:%x\n", ret);
12382 goto out;
12383 }
12384
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053012385 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012386
12387 return 0;
12388out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012389 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080012390 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080012391 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012392 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080012393
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012394err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012395 pld_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012396 return ret;
12397}
12398
12399/**
12400 * __hdd_module_exit - Module exit helper
12401 *
12402 * Module exit helper function used by both module and static driver.
12403 */
12404static void __hdd_module_exit(void)
12405{
Will Huang36049722018-04-13 11:48:51 +080012406 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053012407
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012408 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
12409 QWLAN_VERSIONSTR);
12410
Arunk Khandavalli830c9692018-03-22 12:17:40 +053012411 if (!hdd_wait_for_recovery_completion())
12412 return;
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053012413
Rajeev Kumar3505ae52018-05-10 18:44:45 -070012414 if (hdd_ctx)
12415 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Will Huang36049722018-04-13 11:48:51 +080012416
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012417 wlan_hdd_unregister_driver();
12418
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012419 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012420
Mukul Sharmad75a6672017-06-22 15:40:53 +053012421 /* Ensure to call prior to objmgr deinit */
12422 component_deinit();
12423
Rajeev Kumar97767a02016-11-30 11:20:40 -080012424 dispatcher_deinit();
Amar Singhal0928b192017-12-01 10:50:54 -080012425
12426 hdd_sysfs_destroy_version_interface();
12427
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012428 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012429 pld_deinit();
12430
Sachin Ahujadddd2632017-03-07 19:07:24 +053012431 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012432}
12433
Arun Khandavallifae92942016-08-01 13:31:08 +053012434#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012435/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012436 * wlan_boot_cb() - Wlan boot callback
12437 * @kobj: object whose directory we're creating the link in.
12438 * @attr: attribute the user is interacting with
12439 * @buff: the buffer containing the user data
12440 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012441 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012442 * This callback is invoked when the fs is ready to start the
12443 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012444 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012445 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012446 */
Arun Khandavallifae92942016-08-01 13:31:08 +053012447static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012448 struct kobj_attribute *attr,
12449 const char *buf,
12450 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012451{
Arun Khandavallifae92942016-08-01 13:31:08 +053012452
Arun Khandavallifae92942016-08-01 13:31:08 +053012453 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012454 pr_err("%s: wlan driver already initialized\n", __func__);
12455 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053012456 }
12457
Arun Khandavallifae92942016-08-01 13:31:08 +053012458 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012459 pr_err("%s: wlan driver initialization failed\n", __func__);
12460 return -EIO;
12461 }
12462
12463 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053012464
12465 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012466}
Arun Khandavallifae92942016-08-01 13:31:08 +053012467
12468/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012469 * hdd_sysfs_cleanup() - cleanup sysfs
12470 *
12471 * Return: None
12472 *
12473 */
12474static void hdd_sysfs_cleanup(void)
12475{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012476 /* remove from group */
12477 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
12478 sysfs_remove_group(wlan_loader->boot_wlan_obj,
12479 wlan_loader->attr_group);
12480
12481 /* unlink the object from parent */
12482 kobject_del(wlan_loader->boot_wlan_obj);
12483
12484 /* free the object */
12485 kobject_put(wlan_loader->boot_wlan_obj);
12486
12487 kfree(wlan_loader->attr_group);
12488 kfree(wlan_loader);
12489
12490 wlan_loader = NULL;
12491}
12492
12493/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012494 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
12495 * ready
12496 *
12497 * This is creates the syfs entry boot_wlan. Which shall be invoked
12498 * when the filesystem is ready.
12499 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012500 * QDF API cannot be used here since this function is called even before
12501 * initializing WLAN driver.
12502 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012503 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053012504 */
12505static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012506{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012507 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012508
12509 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012510 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012511 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012512
12513 wlan_loader->boot_wlan_obj = NULL;
12514 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
12515 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012516 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053012517 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053012518
12519 wlan_loader->loaded_state = 0;
12520 wlan_loader->attr_group->attrs = attrs;
12521
12522 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
12523 kernel_kobj);
12524 if (!wlan_loader->boot_wlan_obj) {
12525 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053012526 goto error_return;
12527 }
12528
12529 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
12530 wlan_loader->attr_group);
12531 if (ret) {
12532 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
12533 goto error_return;
12534 }
12535
12536 return 0;
12537
12538error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012539 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053012540
12541 return ret;
12542}
12543
12544/**
12545 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
12546 *
12547 * Return: 0 on success or errno on failure
12548 */
12549static int wlan_deinit_sysfs(void)
12550{
Arun Khandavallifae92942016-08-01 13:31:08 +053012551 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012552 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053012553 return -EINVAL;
12554 }
12555
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012556 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012557 return 0;
12558}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012559
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012560#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053012561
12562#ifdef MODULE
12563/**
12564 * __hdd_module_init - Module init helper
12565 *
12566 * Module init helper function used by both module and static driver.
12567 *
12568 * Return: 0 for success, errno on failure
12569 */
12570static int hdd_module_init(void)
12571{
Arun Khandavallifae92942016-08-01 13:31:08 +053012572 if (__hdd_module_init()) {
12573 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070012574 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053012575 }
12576
Dustin Brownab482ac2017-06-09 17:00:44 -070012577 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053012578}
12579#else
12580static int __init hdd_module_init(void)
12581{
12582 int ret = -EINVAL;
12583
12584 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012585 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053012586 pr_err("Failed to create sysfs entry for loading wlan");
12587
12588 return ret;
12589}
12590#endif
12591
12592
12593#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012594/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012595 * hdd_module_exit() - Exit function
12596 *
12597 * This is the driver exit point (invoked when module is unloaded using rmmod)
12598 *
12599 * Return: None
12600 */
12601static void __exit hdd_module_exit(void)
12602{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012603 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012604}
Arun Khandavallifae92942016-08-01 13:31:08 +053012605#else
12606static void __exit hdd_module_exit(void)
12607{
12608 __hdd_module_exit();
12609 wlan_deinit_sysfs();
12610}
12611#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012612
Srinivas Girigowda841da292018-02-21 16:33:00 -080012613static int fwpath_changed_handler(const char *kmessage,
12614 const struct kernel_param *kp)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012615{
12616 return param_set_copystring(kmessage, kp);
12617}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012618
Nirav Shah73713f72018-05-17 14:50:41 +053012619#ifdef FEATURE_MONITOR_MODE_SUPPORT
12620static bool is_monitor_mode_supported(void)
12621{
12622 return true;
12623}
12624#else
12625static bool is_monitor_mode_supported(void)
12626{
12627 pr_err("Monitor mode not supported!");
12628 return false;
12629}
12630#endif
12631
12632#ifdef WLAN_FEATURE_EPPING
12633static bool is_epping_mode_supported(void)
12634{
12635 return true;
12636}
12637#else
12638static bool is_epping_mode_supported(void)
12639{
12640 pr_err("Epping mode not supported!");
12641 return false;
12642}
12643#endif
12644
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012645/**
12646 * is_con_mode_valid() check con mode is valid or not
12647 * @mode: global con mode
12648 *
12649 * Return: TRUE on success FALSE on failure
12650 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012651static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012652{
12653 switch (mode) {
12654 case QDF_GLOBAL_MONITOR_MODE:
Nirav Shah73713f72018-05-17 14:50:41 +053012655 return is_monitor_mode_supported();
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012656 case QDF_GLOBAL_EPPING_MODE:
Nirav Shah73713f72018-05-17 14:50:41 +053012657 return is_epping_mode_supported();
12658 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012659 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012660 return true;
12661 default:
12662 return false;
12663 }
12664}
12665
12666/**
12667 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
12668 * @mode: global con mode
12669 *
12670 * Return: adapter mode
12671 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012672static enum QDF_OPMODE hdd_get_adpter_mode(
Jeff Johnson876c1a62017-12-12 10:43:07 -080012673 enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012674{
12675
12676 switch (mode) {
12677 case QDF_GLOBAL_MISSION_MODE:
12678 return QDF_STA_MODE;
12679 case QDF_GLOBAL_MONITOR_MODE:
12680 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012681 case QDF_GLOBAL_EPPING_MODE:
12682 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012683 case QDF_GLOBAL_FTM_MODE:
12684 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012685 case QDF_GLOBAL_QVIT_MODE:
12686 return QDF_QVIT_MODE;
12687 default:
12688 return QDF_MAX_NO_OF_MODE;
12689 }
12690}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012691
Dustin Brown27cd9942017-09-27 16:11:44 -070012692static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012693 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070012694{
12695 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
12696 return;
12697
12698 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070012699 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012700 hdd_info("Release wakelock for monitor mode!");
12701 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
12702 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
Dundi Raviteja0a2a65b2018-04-30 12:34:11 +053012703 /* fallthrough */
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012704 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070012705 case QDF_GLOBAL_FTM_MODE:
12706 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +053012707 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Dustin Browndb2a8be2017-12-20 11:49:56 -080012708 hdd_stop_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -070012709
Dustin Brown27cd9942017-09-27 16:11:44 -070012710 break;
12711 default:
12712 break;
12713 }
12714}
12715
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012716static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012717 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012718{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053012719 int driver_status;
12720
12721 driver_status = hdd_ctx->driver_status;
12722
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012723 switch (curr_mode) {
12724 case QDF_GLOBAL_MISSION_MODE:
12725 case QDF_GLOBAL_MONITOR_MODE:
12726 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012727 hdd_deinit_all_adapters(hdd_ctx, false);
12728 hdd_close_all_adapters(hdd_ctx, false);
12729 break;
12730 case QDF_GLOBAL_EPPING_MODE:
12731 epping_disable();
12732 epping_close();
12733 break;
12734 default:
12735 return;
12736 }
12737}
12738
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012739static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012740 enum QDF_GLOBAL_MODE mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012741{
Jeff Johnson9d295242017-08-29 14:39:48 -070012742 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012743 int ret = 0;
12744 bool rtnl_held;
12745 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
12746 QDF_STATUS status;
12747
12748 if (!qdf_dev) {
12749 hdd_err("qdf device context is Null return!");
12750 return -EINVAL;
12751 }
12752
12753 rtnl_held = hdd_hold_rtnl_lock();
12754 switch (mode) {
12755 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080012756 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
12757 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012758 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012759 break;
12760 case QDF_GLOBAL_FTM_MODE:
12761 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
12762 wlan_hdd_get_intf_addr(hdd_ctx),
12763 NET_NAME_UNKNOWN, rtnl_held);
12764 if (adapter == NULL)
12765 ret = -EINVAL;
12766 break;
12767 case QDF_GLOBAL_MONITOR_MODE:
12768 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
12769 wlan_hdd_get_intf_addr(hdd_ctx),
12770 NET_NAME_UNKNOWN, rtnl_held);
12771 if (adapter == NULL)
12772 ret = -EINVAL;
12773 break;
12774 case QDF_GLOBAL_EPPING_MODE:
12775 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012776 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012777 hdd_err("Failed to open in eeping mode: %d", status);
12778 ret = -EINVAL;
12779 break;
12780 }
12781 ret = epping_enable(qdf_dev->dev);
12782 if (ret) {
12783 hdd_err("Failed to enable in epping mode : %d", ret);
12784 epping_close();
12785 }
12786 break;
12787 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012788 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012789 ret = -ENOTSUPP;
12790 break;
12791 }
12792 hdd_release_rtnl_lock();
12793 rtnl_held = false;
12794 return ret;
12795}
12796
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012797/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012798 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012799 * @kmessage: con mode name on which driver to be bring up
12800 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012801 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012802 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012803 * This function is invoked when user updates con mode using sys entry,
12804 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012805 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012806 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012807 */
Srinivas Girigowda841da292018-02-21 16:33:00 -080012808static int __con_mode_handler(const char *kmessage,
12809 const struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012810 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012811{
12812 int ret;
Jeff Johnson876c1a62017-12-12 10:43:07 -080012813 enum QDF_GLOBAL_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012814 enum QDF_OPMODE adapter_mode;
Dustin Brown20024e32018-01-03 12:34:58 -080012815 int new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012816
Dustin Brownab6029b2017-05-24 13:04:19 -070012817 hdd_info("con_mode handler: %s", kmessage);
12818
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012819 ret = wlan_hdd_validate_context(hdd_ctx);
12820 if (ret)
12821 return ret;
12822
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012823 qdf_atomic_set(&hdd_ctx->con_mode_flag, 1);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012824
Dustin Brown20024e32018-01-03 12:34:58 -080012825 ret = kstrtoint(kmessage, 0, &new_con_mode);
12826 if (ret) {
12827 hdd_err("Failed to parse con_mode '%s'", kmessage);
12828 goto reset_flags;
12829 }
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012830 mutex_lock(&hdd_init_deinit_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +053012831
Dustin Brown20024e32018-01-03 12:34:58 -080012832 if (!is_con_mode_valid(new_con_mode)) {
12833 hdd_err("invalid con_mode %d", new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012834 ret = -EINVAL;
12835 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012836 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012837
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012838 curr_mode = hdd_get_conparam();
Dustin Brown20024e32018-01-03 12:34:58 -080012839 if (curr_mode == new_con_mode) {
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012840 hdd_err("curr mode: %d is same as user triggered mode %d",
Dustin Brown20024e32018-01-03 12:34:58 -080012841 curr_mode, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012842 ret = 0;
12843 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012844 }
12845
Dustin Brown27cd9942017-09-27 16:11:44 -070012846 /* ensure adapters are stopped */
12847 hdd_stop_present_mode(hdd_ctx, curr_mode);
12848
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070012849 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053012850 if (ret) {
12851 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012852 goto reset_flags;
12853 }
12854
Dustin Browndd4e50f2018-05-24 15:43:42 -070012855 /* Cleanup present mode before switching to new mode */
12856 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053012857
Dustin Brown20024e32018-01-03 12:34:58 -080012858 hdd_set_conparam(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012859
12860 /* Register for new con_mode & then kick_start modules again */
Dustin Brown20024e32018-01-03 12:34:58 -080012861 ret = hdd_register_req_mode(hdd_ctx, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012862 if (ret) {
12863 hdd_err("Failed to register for new mode");
12864 goto reset_flags;
12865 }
12866
Dustin Brown20024e32018-01-03 12:34:58 -080012867 adapter_mode = hdd_get_adpter_mode(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012868 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
12869 hdd_err("invalid adapter");
12870 ret = -EINVAL;
12871 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012872 }
12873
Dustin Browne7e71d32018-05-11 16:00:08 -070012874 ret = hdd_wlan_start_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053012875 if (ret) {
12876 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012877 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012878 }
12879
Dustin Brown20024e32018-01-03 12:34:58 -080012880 if (new_con_mode == QDF_GLOBAL_MONITOR_MODE) {
Dustin Browne7e71d32018-05-11 16:00:08 -070012881 struct hdd_adapter *adapter =
12882 hdd_get_adapter(hdd_ctx, adapter_mode);
12883
12884 if (!adapter) {
12885 hdd_err("Failed to get adapter:%d", adapter_mode);
12886 goto reset_flags;
12887 }
12888
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012889 if (hdd_start_adapter(adapter)) {
12890 hdd_err("Failed to start %s adapter", kmessage);
12891 ret = -EINVAL;
12892 goto reset_flags;
12893 }
Arun Khandavallifae92942016-08-01 13:31:08 +053012894
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012895 hdd_info("Acquire wakelock for monitor mode!");
12896 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
12897 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12898 }
12899
Dustin Brown20024e32018-01-03 12:34:58 -080012900 /* con_mode is a global module parameter */
12901 con_mode = new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012902 hdd_info("Mode successfully changed to %s", kmessage);
12903 ret = 0;
12904
12905reset_flags:
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012906 mutex_unlock(&hdd_init_deinit_lock);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012907 qdf_atomic_set(&hdd_ctx->con_mode_flag, 0);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012908 return ret;
12909}
12910
12911
Srinivas Girigowda841da292018-02-21 16:33:00 -080012912static int con_mode_handler(const char *kmessage, const struct kernel_param *kp)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012913{
12914 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012915 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012916
12917 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12918 ret = wlan_hdd_validate_context(hdd_ctx);
12919 if (ret)
12920 return ret;
12921
Ashish Kumar Dhanotiya759b3272018-05-18 17:49:46 +053012922 if (!cds_wait_for_external_threads_completion(__func__)) {
12923 hdd_warn("External threads are still active, can not change mode");
12924 return -EAGAIN;
12925 }
12926
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012927 cds_ssr_protect(__func__);
12928 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
12929 cds_ssr_unprotect(__func__);
12930
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012931 return ret;
12932}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012933
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012934static int con_mode_handler_ftm(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080012935 const struct kernel_param *kp)
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012936{
12937 int ret;
12938
12939 ret = param_set_int(kmessage, kp);
12940
12941 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
12942 pr_err("Only FTM mode supported!");
12943 return -ENOTSUPP;
12944 }
12945
12946 hdd_set_conparam(con_mode_ftm);
12947 con_mode = con_mode_ftm;
12948
12949 return ret;
12950}
12951
Nirav Shah73713f72018-05-17 14:50:41 +053012952#ifdef FEATURE_MONITOR_MODE_SUPPORT
Ravi Joshia307f632017-07-17 23:41:41 -070012953static int con_mode_handler_monitor(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080012954 const struct kernel_param *kp)
Ravi Joshia307f632017-07-17 23:41:41 -070012955{
12956 int ret;
12957
12958 ret = param_set_int(kmessage, kp);
12959
12960 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
12961 pr_err("Only Monitor mode supported!");
12962 return -ENOTSUPP;
12963 }
12964
12965 hdd_set_conparam(con_mode_monitor);
12966 con_mode = con_mode_monitor;
12967
12968 return ret;
12969}
Nirav Shah73713f72018-05-17 14:50:41 +053012970#endif
Ravi Joshia307f632017-07-17 23:41:41 -070012971
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012972/**
12973 * hdd_get_conparam() - driver exit point
12974 *
12975 * This is the driver exit point (invoked when module is unloaded using rmmod)
12976 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080012977 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012978 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012979enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012980{
Jeff Johnson876c1a62017-12-12 10:43:07 -080012981 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012982}
12983
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012984void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012985{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012986 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012987}
12988
Komal Seelamc11bb222016-01-27 18:57:10 +053012989/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012990 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
12991 * @hdd_ctx: HDD context
12992 *
12993 * Cleans up the pre cac interface, if it exists
12994 *
12995 * Return: None
12996 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012997void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012998{
12999 uint8_t session_id;
13000 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070013001 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013002
Jeff Johnson16528362018-06-14 12:34:16 -070013003 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->mac_handle, &session_id);
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013004 if (QDF_IS_STATUS_ERROR(status)) {
13005 hdd_err("failed to get pre cac vdev id");
13006 return;
13007 }
13008
13009 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
13010 if (!precac_adapter) {
Jeff Johnsondd2f1fc2018-05-06 11:22:52 -070013011 hdd_err("invalid pre cac adapter");
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053013012 return;
13013 }
13014
13015 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
13016 wlan_hdd_sap_pre_cac_failure,
13017 (void *)precac_adapter);
13018 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
13019
13020}
13021
13022/**
Komal Seelamec702b02016-02-24 18:42:16 +053013023 * hdd_update_ol_config - API to update ol configuration parameters
13024 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053013025 *
Komal Seelamc11bb222016-01-27 18:57:10 +053013026 * Return: void
13027 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013028static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053013029{
Komal Seelamec702b02016-02-24 18:42:16 +053013030 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053013031 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053013032
Komal Seelamec702b02016-02-24 18:42:16 +053013033 if (!ol_ctx)
13034 return;
13035
13036 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
13037 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
13038 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
13039 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070013040 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053013041
13042 ol_init_ini_config(ol_ctx, &cfg);
13043}
13044
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013045#ifdef FEATURE_RUNTIME_PM
13046/**
13047 * hdd_populate_runtime_cfg() - populate runtime configuration
13048 * @hdd_ctx: hdd context
13049 * @cfg: pointer to the configuration memory being populated
13050 *
13051 * Return: void
13052 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013053static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013054 struct hif_config_info *cfg)
13055{
13056 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
13057 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
13058}
13059#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013060static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013061 struct hif_config_info *cfg)
13062{
13063}
13064#endif
13065
Komal Seelamec702b02016-02-24 18:42:16 +053013066/**
13067 * hdd_update_hif_config - API to update HIF configuration parameters
13068 * @hdd_ctx: HDD Context
13069 *
13070 * Return: void
13071 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013072static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053013073{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053013074 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053013075 struct hif_config_info cfg;
13076
13077 if (!scn)
13078 return;
13079
13080 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070013081 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053013082 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070013083
13084 if (hdd_ctx->config->prevent_link_down)
13085 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053013086}
13087
13088/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013089 * hdd_update_dp_config() - Propagate config parameters to Lithium
13090 * datapath
13091 * @hdd_ctx: HDD Context
13092 *
13093 * Return: 0 for success/errno for failure
13094 */
13095static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
13096{
13097 struct cdp_config_params params;
13098 QDF_STATUS status;
13099
13100 params.tso_enable = hdd_ctx->config->tso_enable;
13101 params.lro_enable = hdd_ctx->config->lro_enable;
13102#ifdef QCA_LL_TX_FLOW_CONTROL_V2
13103 params.tx_flow_stop_queue_threshold =
13104 hdd_ctx->config->TxFlowStopQueueThreshold;
13105 params.tx_flow_start_queue_offset =
13106 hdd_ctx->config->TxFlowStartQueueOffset;
13107#endif
13108 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
13109 params.napi_enable = hdd_ctx->napi_enable;
13110 params.tcp_udp_checksumoffload =
13111 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
13112
13113 status = cdp_update_config_parameters(
13114 cds_get_context(QDF_MODULE_ID_SOC),
13115 &params);
13116 if (status) {
Dustin Browna2868622018-03-20 11:38:14 -070013117 hdd_err("Failed to attach config parameters");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013118 return status;
13119 }
13120
13121 return 0;
13122}
13123
13124/**
Komal Seelamec702b02016-02-24 18:42:16 +053013125 * hdd_update_config() - Initialize driver per module ini parameters
13126 * @hdd_ctx: HDD Context
13127 *
13128 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013129 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053013130 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013131int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053013132{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013133 int ret;
13134
Komal Seelamec702b02016-02-24 18:42:16 +053013135 hdd_update_ol_config(hdd_ctx);
13136 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013137 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
13138 ret = hdd_update_cds_config_ftm(hdd_ctx);
13139 else
13140 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080013141 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053013142
13143 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053013144}
13145
Mukul Sharma9d797a02017-01-05 20:26:03 +053013146#ifdef FEATURE_WLAN_RA_FILTERING
13147/**
13148 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
13149 * @psoc_cfg: pmo psoc Configuration
13150 * @hdd_ctx: Pointer to hdd context
13151 *
13152 * Return: none
13153 */
13154static inline void hdd_ra_populate_pmo_config(
13155 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013156 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013157{
13158 psoc_cfg->ra_ratelimit_interval =
13159 hdd_ctx->config->RArateLimitInterval;
13160 psoc_cfg->ra_ratelimit_enable =
13161 hdd_ctx->config->IsRArateLimitEnabled;
13162}
13163#else
13164static inline void hdd_ra_populate_pmo_config(
13165 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013166 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013167{
13168}
13169#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080013170
Mukul Sharma9d797a02017-01-05 20:26:03 +053013171/**
13172 * hdd_update_pmo_config - API to update pmo configuration parameters
13173 * @hdd_ctx: HDD context
13174 *
13175 * Return: void
13176 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013177static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013178{
Mukul Sharma9d797a02017-01-05 20:26:03 +053013179 struct pmo_psoc_cfg psoc_cfg;
13180 QDF_STATUS status;
13181
13182 /*
13183 * Value of hdd_ctx->wowEnable can be,
13184 * 0 - Disable both magic pattern match and pattern byte match.
13185 * 1 - Enable magic pattern match on all interfaces.
13186 * 2 - Enable pattern byte match on all interfaces.
13187 * 3 - Enable both magic patter and pattern byte match on
13188 * all interfaces.
13189 */
13190 psoc_cfg.magic_ptrn_enable =
13191 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
13192 psoc_cfg.ptrn_match_enable_all_vdev =
13193 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Nachiket Kukadee547a482018-05-22 16:43:30 +053013194 psoc_cfg.apf_enable = hdd_ctx->config->apf_packet_filter_enable;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013195 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Nachiket Kukadef0804072018-02-27 18:20:07 +053013196 psoc_cfg.hw_filter_mode_bitmap = hdd_ctx->config->hw_filter_mode_bitmap;
Dustin Brownb9987af2018-03-01 17:15:11 -080013197 psoc_cfg.ns_offload_enable_dynamic = hdd_ctx->config->fhostNSOffload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013198 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
Dustin Brownb9987af2018-03-01 17:15:11 -080013199 psoc_cfg.packet_filter_enabled = !hdd_ctx->config->disablePacketFilter;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013200 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
13201 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
Dustin Brownb9987af2018-03-01 17:15:11 -080013202 psoc_cfg.active_mode_offload = hdd_ctx->config->active_mode_offload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013203 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080013204 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9223f232017-03-08 18:42:27 +053013205 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
13206 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
13207 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
Dustin Brownb9987af2018-03-01 17:15:11 -080013208 psoc_cfg.power_save_mode = hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053013209 psoc_cfg.auto_power_save_fail_mode =
13210 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053013211
13212 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053013213 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
13214 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013215
Dustin Brownb9987af2018-03-01 17:15:11 -080013216 status = ucfg_pmo_update_psoc_config(hdd_ctx->hdd_psoc, &psoc_cfg);
13217 if (QDF_IS_STATUS_ERROR(status))
13218 hdd_err("failed pmo psoc configuration; status:%d", status);
13219
13220 return qdf_status_to_os_return(status);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013221}
13222
Abhishek Singhb20db962017-03-03 21:28:46 +053013223#ifdef FEATURE_WLAN_SCAN_PNO
13224static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
13225 struct hdd_config *cfg)
13226{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070013227 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
13228
Abhishek Singhb20db962017-03-03 21:28:46 +053013229 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
13230 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
13231 pno_cfg->stationary_thresh = cfg->stationary_thresh;
13232 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
13233 pno_cfg->channel_prediction_full_scan =
13234 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070013235 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
13236 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
13237 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
13238 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053013239}
13240#else
13241static inline void
13242hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070013243 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053013244{
Abhishek Singhb20db962017-03-03 21:28:46 +053013245}
13246#endif
13247
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013248void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
13249 struct hdd_config *cfg)
13250{
13251 uint8_t i = 0;
13252
13253 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
13254 if (!ie_whitelist->white_list)
13255 return;
13256
13257 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
13258 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
13259 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
13260 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
13261 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
13262 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
13263 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
13264 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
13265
13266 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
13267 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
13268 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
13269}
13270
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013271uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
13272{
13273 uint8_t i, score;
13274
13275 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
13276 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
13277 if (score > MAX_INDEX_SCORE)
13278 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
13279 MAX_INDEX_SCORE, i);
13280 }
13281
13282 return per_index_score;
13283}
13284
13285/**
13286 * hdd_update_score_config - API to update candidate scoring related params
13287 * configuration parameters
13288 * @score_config: score config to update
13289 * @cfg: config params
13290 *
13291 * Return: 0 if success else err
13292 */
13293static void hdd_update_score_config(
13294 struct scoring_config *score_config, struct hdd_config *cfg)
13295{
13296 int total_weight;
13297
13298 score_config->weight_cfg.rssi_weightage = cfg->rssi_weightage;
13299 score_config->weight_cfg.ht_caps_weightage = cfg->ht_caps_weightage;
13300 score_config->weight_cfg.vht_caps_weightage =
13301 cfg->vht_caps_weightage;
13302 score_config->weight_cfg.he_caps_weightage =
13303 cfg->he_caps_weightage;
13304 score_config->weight_cfg.chan_width_weightage =
13305 cfg->chan_width_weightage;
13306 score_config->weight_cfg.chan_band_weightage =
13307 cfg->chan_band_weightage;
13308 score_config->weight_cfg.nss_weightage = cfg->nss_weightage;
13309 score_config->weight_cfg.beamforming_cap_weightage =
13310 cfg->beamforming_cap_weightage;
13311 score_config->weight_cfg.pcl_weightage = cfg->pcl_weightage;
13312 score_config->weight_cfg.channel_congestion_weightage =
13313 cfg->channel_congestion_weightage;
13314 score_config->weight_cfg.oce_wan_weightage = cfg->oce_wan_weightage;
13315
13316 total_weight = score_config->weight_cfg.rssi_weightage +
13317 score_config->weight_cfg.ht_caps_weightage +
13318 score_config->weight_cfg.vht_caps_weightage +
13319 score_config->weight_cfg.he_caps_weightage +
13320 score_config->weight_cfg.chan_width_weightage +
13321 score_config->weight_cfg.chan_band_weightage +
13322 score_config->weight_cfg.nss_weightage +
13323 score_config->weight_cfg.beamforming_cap_weightage +
13324 score_config->weight_cfg.pcl_weightage +
13325 score_config->weight_cfg.channel_congestion_weightage +
13326 score_config->weight_cfg.oce_wan_weightage;
13327
13328 if (total_weight > BEST_CANDIDATE_MAX_WEIGHT) {
13329 hdd_err("total weight is greater than %d fallback to default values",
13330 BEST_CANDIDATE_MAX_WEIGHT);
13331
13332 score_config->weight_cfg.rssi_weightage = RSSI_WEIGHTAGE;
13333 score_config->weight_cfg.ht_caps_weightage =
13334 HT_CAPABILITY_WEIGHTAGE;
13335 score_config->weight_cfg.vht_caps_weightage = VHT_CAP_WEIGHTAGE;
13336 score_config->weight_cfg.he_caps_weightage = HE_CAP_WEIGHTAGE;
13337 score_config->weight_cfg.chan_width_weightage =
13338 CHAN_WIDTH_WEIGHTAGE;
13339 score_config->weight_cfg.chan_band_weightage =
13340 CHAN_BAND_WEIGHTAGE;
13341 score_config->weight_cfg.nss_weightage = NSS_WEIGHTAGE;
13342 score_config->weight_cfg.beamforming_cap_weightage =
13343 BEAMFORMING_CAP_WEIGHTAGE;
13344 score_config->weight_cfg.pcl_weightage = PCL_WEIGHT;
13345 score_config->weight_cfg.channel_congestion_weightage =
13346 CHANNEL_CONGESTION_WEIGHTAGE;
13347 score_config->weight_cfg.oce_wan_weightage = OCE_WAN_WEIGHTAGE;
13348 }
13349
13350 score_config->bandwidth_weight_per_index =
13351 hdd_limit_max_per_index_score(
13352 cfg->bandwidth_weight_per_index);
13353 score_config->nss_weight_per_index =
13354 hdd_limit_max_per_index_score(cfg->nss_weight_per_index);
13355 score_config->band_weight_per_index =
13356 hdd_limit_max_per_index_score(cfg->band_weight_per_index);
13357
13358 score_config->rssi_score.best_rssi_threshold =
13359 cfg->best_rssi_threshold;
13360 score_config->rssi_score.good_rssi_threshold =
13361 cfg->good_rssi_threshold;
13362 score_config->rssi_score.bad_rssi_threshold =
13363 cfg->bad_rssi_threshold;
13364 score_config->rssi_score.good_rssi_pcnt = cfg->good_rssi_pcnt;
13365 score_config->rssi_score.bad_rssi_pcnt = cfg->bad_rssi_pcnt;
13366 score_config->rssi_score.good_rssi_bucket_size =
13367 cfg->good_rssi_bucket_size;
13368 score_config->rssi_score.bad_rssi_bucket_size =
13369 cfg->bad_rssi_bucket_size;
13370 score_config->rssi_score.rssi_pref_5g_rssi_thresh =
13371 cfg->rssi_pref_5g_rssi_thresh;
13372
13373 score_config->esp_qbss_scoring.num_slot = cfg->num_esp_qbss_slots;
13374 score_config->esp_qbss_scoring.score_pcnt3_to_0 =
13375 hdd_limit_max_per_index_score(
13376 cfg->esp_qbss_score_slots3_to_0);
13377 score_config->esp_qbss_scoring.score_pcnt7_to_4 =
13378 hdd_limit_max_per_index_score(
13379 cfg->esp_qbss_score_slots7_to_4);
13380 score_config->esp_qbss_scoring.score_pcnt11_to_8 =
13381 hdd_limit_max_per_index_score(
13382 cfg->esp_qbss_score_slots11_to_8);
13383 score_config->esp_qbss_scoring.score_pcnt15_to_12 =
13384 hdd_limit_max_per_index_score(
13385 cfg->esp_qbss_score_slots15_to_12);
13386
13387 score_config->oce_wan_scoring.num_slot = cfg->num_oce_wan_slots;
13388 score_config->oce_wan_scoring.score_pcnt3_to_0 =
13389 hdd_limit_max_per_index_score(
13390 cfg->oce_wan_score_slots3_to_0);
13391 score_config->oce_wan_scoring.score_pcnt7_to_4 =
13392 hdd_limit_max_per_index_score(
13393 cfg->oce_wan_score_slots7_to_4);
13394 score_config->oce_wan_scoring.score_pcnt11_to_8 =
13395 hdd_limit_max_per_index_score(
13396 cfg->oce_wan_score_slots11_to_8);
13397 score_config->oce_wan_scoring.score_pcnt15_to_12 =
13398 hdd_limit_max_per_index_score(
13399 cfg->oce_wan_score_slots15_to_12);
13400
13401
13402 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
13403 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
13404 score_config->nss = cfg->enable2x2 ? 2 : 1;
13405
13406 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
13407 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
13408 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
13409 score_config->he_cap = 1;
13410
13411 if (score_config->he_cap ||
13412 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
13413 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
13414 score_config->vht_cap = 1;
13415
13416 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
13417 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
13418 score_config->ht_cap = 1;
13419
13420 if (score_config->vht_cap && cfg->enableVhtFor24GHzBand)
13421 score_config->vht_24G_cap = 1;
13422
13423 if (cfg->enableTxBF)
13424 score_config->beamformee_cap = 1;
13425
13426}
13427
Abhishek Singh257a9482017-03-06 16:52:39 +053013428/**
bings81fe50a2017-11-27 14:33:26 +080013429 * hdd_update_dfs_config() - API to update dfs configuration parameters.
13430 * @hdd_ctx: HDD context
13431 *
13432 * Return: 0 if success else err
13433 */
13434static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
13435{
13436 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13437 struct hdd_config *cfg = hdd_ctx->config;
13438 struct dfs_user_config dfs_cfg;
13439 QDF_STATUS status;
13440
13441 dfs_cfg.dfs_is_phyerr_filter_offload = !!cfg->fDfsPhyerrFilterOffload;
13442 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
13443 if (QDF_IS_STATUS_ERROR(status)) {
13444 hdd_err("failed dfs psoc configuration");
13445 return -EINVAL;
13446 }
13447
13448 return 0;
13449}
13450
13451/**
Abhishek Singh257a9482017-03-06 16:52:39 +053013452 * hdd_update_scan_config - API to update scan configuration parameters
13453 * @hdd_ctx: HDD context
13454 *
13455 * Return: 0 if success else err
13456 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013457static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053013458{
13459 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13460 struct scan_user_cfg scan_cfg;
13461 struct hdd_config *cfg = hdd_ctx->config;
13462 QDF_STATUS status;
13463
13464 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
13465 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
13466 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
13467 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
13468 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
13469 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
13470 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053013471 /* convert to ms */
13472 scan_cfg.scan_cache_aging_time =
13473 cfg->scanAgingTimeout * 1000;
13474 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
13475 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
13476 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
13477 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053013478 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053013479 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080013480 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
13481 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053013482 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070013483 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singhc87bb042018-01-30 17:10:42 +053013484 scan_cfg.sta_miracast_mcc_rest_time =
13485 cfg->sta_miracast_mcc_rest_time_val;
Abhishek Singh257a9482017-03-06 16:52:39 +053013486
Abhishek Singhb20db962017-03-03 21:28:46 +053013487 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013488 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013489 hdd_update_score_config(&scan_cfg.score_config, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053013490
Abhishek Singh257a9482017-03-06 16:52:39 +053013491 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
13492 if (status != QDF_STATUS_SUCCESS) {
13493 hdd_err("failed pmo psoc configuration");
13494 return -EINVAL;
13495 }
13496
13497 return 0;
13498}
Abhishek Singh257a9482017-03-06 16:52:39 +053013499
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013500int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013501{
13502 int ret;
13503
13504 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053013505 if (ret)
13506 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013507
Abhishek Singh257a9482017-03-06 16:52:39 +053013508 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080013509 if (ret)
13510 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013511
Frank Liud4b2fa02017-03-29 11:46:48 +080013512 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013513 if (ret)
13514 return ret;
13515
13516 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080013517 if (ret)
13518 return ret;
13519
13520 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013521
13522 return ret;
13523}
13524
Agrawal Ashish65634612016-08-18 13:24:32 +053013525/**
13526 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
13527 * @mode : cfg80211 DFS mode
13528 *
13529 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
13530 */
13531enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
13532{
13533 switch (mode) {
13534 case DFS_MODE_ENABLE:
13535 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013536 case DFS_MODE_DISABLE:
13537 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013538 case DFS_MODE_DEPRIORITIZE:
13539 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013540 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013541 hdd_debug("ACS dfs mode is NONE");
13542 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013543 }
13544}
13545
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013546/**
13547 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
13548 * @hddctx: pointer to hdd context
13549 * @set_value: enable/disable
13550 *
13551 * When Host sends vendor command enable, FW will send *ONE* CA ind to
13552 * Host(even though it is duplicate). When Host send vendor command
13553 * disable,FW doesn't perform any action. Whenever any change in
13554 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
13555 *
13556 * return - 0 on success, appropriate error values on failure.
13557 */
Jeff Johnson16528362018-06-14 12:34:16 -070013558int hdd_enable_disable_ca_event(struct hdd_context *hdd_ctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013559{
13560 QDF_STATUS status;
13561
Jeff Johnson16528362018-06-14 12:34:16 -070013562 if (0 != wlan_hdd_validate_context(hdd_ctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013563 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013564
Jeff Johnson16528362018-06-14 12:34:16 -070013565 if (!hdd_ctx->config->goptimize_chan_avoid_event) {
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013566 hdd_warn("goptimize_chan_avoid_event ini param disabled");
13567 return -EINVAL;
13568 }
13569
Jeff Johnson16528362018-06-14 12:34:16 -070013570 status = sme_enable_disable_chanavoidind_event(hdd_ctx->mac_handle,
13571 set_value);
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013572 if (!QDF_IS_STATUS_SUCCESS(status)) {
13573 hdd_err("Failed to send chan avoid command to SME");
13574 return -EINVAL;
13575 }
13576 return 0;
13577}
Agrawal Ashish65634612016-08-18 13:24:32 +053013578
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013579/**
13580 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
13581 * @value: value to set
13582 *
13583 * This function will set the passed value to roaming in progress flag.
13584 *
13585 * Return: None
13586 */
13587void hdd_set_roaming_in_progress(bool value)
13588{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013589 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013590
13591 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13592 if (!hdd_ctx) {
13593 hdd_err("HDD context is NULL");
13594 return;
13595 }
13596
13597 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013598 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013599}
13600
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053013601bool hdd_is_roaming_in_progress(struct hdd_context *hdd_ctx)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013602{
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013603 if (!hdd_ctx) {
13604 hdd_err("HDD context is NULL");
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053013605 return false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013606 }
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013607
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053013608 hdd_debug("roaming_in_progress = %d", hdd_ctx->roaming_in_progress);
13609
13610 return hdd_ctx->roaming_in_progress;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013611}
13612
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013613/**
13614 * hdd_is_connection_in_progress() - check if connection is in
13615 * progress
13616 * @session_id: session id
13617 * @reason: scan reject reason
13618 *
13619 * Go through each adapter and check if Connection is in progress
13620 *
13621 * Return: true if connection is in progress else false
13622 */
13623bool hdd_is_connection_in_progress(uint8_t *session_id,
13624 enum scan_reject_states *reason)
13625{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070013626 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070013627 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013628 uint8_t sta_id = 0;
13629 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013630 struct hdd_context *hdd_ctx;
Jeff Johnson16528362018-06-14 12:34:16 -070013631 mac_handle_t mac_handle;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013632
13633 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13634 if (!hdd_ctx) {
13635 hdd_err("HDD context is NULL");
13636 return false;
13637 }
13638
Jeff Johnson16528362018-06-14 12:34:16 -070013639 mac_handle = hdd_ctx->mac_handle;
13640
Dustin Brown920397d2017-12-13 16:27:50 -080013641 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya929afa42018-06-01 15:04:44 -070013642 hdd_debug("Adapter with device mode %s(%d) exists",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013643 hdd_device_mode_to_string(adapter->device_mode),
13644 adapter->device_mode);
13645 if (((QDF_STA_MODE == adapter->device_mode)
13646 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
13647 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
13648 && (eConnectionState_Connecting ==
13649 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
13650 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013651 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013652 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013653 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013654 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013655 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013656 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013657 }
13658 return true;
13659 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013660 /*
13661 * sme_neighbor_middle_of_roaming is for LFR2
13662 * hdd_is_roaming_in_progress is for LFR3
13663 */
13664 if (((QDF_STA_MODE == adapter->device_mode) &&
13665 sme_neighbor_middle_of_roaming(
Jeff Johnson16528362018-06-14 12:34:16 -070013666 mac_handle,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013667 adapter->session_id)) ||
Padma, Santhosh Kumar86747ec2018-05-29 18:28:29 +053013668 hdd_is_roaming_in_progress(hdd_ctx)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013669 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013670 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013671 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013672 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013673 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013674 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013675 }
13676 return true;
13677 }
13678 if ((QDF_STA_MODE == adapter->device_mode) ||
13679 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
13680 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
13681 hdd_sta_ctx =
13682 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
13683 if ((eConnectionState_Associated ==
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053013684 hdd_sta_ctx->conn_info.connState)
13685 && sme_is_sta_key_exchange_in_progress(
Jeff Johnson16528362018-06-14 12:34:16 -070013686 mac_handle, adapter->session_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013687 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070013688 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013689 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013690 " is in middle of WPS/EAPOL exchange.",
13691 MAC_ADDR_ARRAY(sta_mac));
13692 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013693 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013694 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013695 }
13696 return true;
13697 }
13698 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
13699 (QDF_P2P_GO_MODE == adapter->device_mode)) {
13700 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
13701 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013702 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013703 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013704 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013705 continue;
13706
13707 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013708 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070013709 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013710 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013711 " of SAP/GO is in middle of WPS/EAPOL exchange",
13712 MAC_ADDR_ARRAY(sta_mac));
13713 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013714 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013715 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013716 }
13717 return true;
13718 }
13719 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013720 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013721 return true;
13722 }
13723 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013724 }
Dustin Brown920397d2017-12-13 16:27:50 -080013725
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013726 return false;
13727}
13728
13729/**
13730 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070013731 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013732 *
13733 * Return: None
13734 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013735void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013736{
Jeff Johnson87251032017-08-29 13:31:11 -070013737 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070013738 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013739 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013740 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Jeff Johnsone4c11db2018-05-05 23:22:32 -070013741 tsap_config_t *sap_config;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013742 void *sap_ctx;
13743
13744 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070013745 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070013746 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013747
13748 mutex_lock(&hdd_ctx->sap_lock);
13749 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
13750 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013751 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
13752 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
13753 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
13754 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013755 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013756 qdf_stop_bss_event,
13757 SME_CMD_TIMEOUT_VALUE);
13758
13759 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013760 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013761 goto end;
13762 }
13763 }
13764 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013765 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013766 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070013767 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013768 false);
Jeff Johnson6867ec32017-09-29 20:30:20 -070013769 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013770
13771 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013772 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013773 wlansap_reset_sap_config_add_ie(sap_config,
13774 eUPDATE_IE_ALL);
13775 goto end;
13776 }
13777
13778 qdf_event_reset(&hostapd_state->qdf_event);
13779 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
13780 sap_config,
13781 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013782 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013783 wlansap_reset_sap_config_add_ie(sap_config,
13784 eUPDATE_IE_ALL);
13785 goto end;
13786 }
13787
Jeff Johnson6867ec32017-09-29 20:30:20 -070013788 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013789 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013790 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013791 SME_CMD_TIMEOUT_VALUE);
13792 wlansap_reset_sap_config_add_ie(sap_config,
13793 eUPDATE_IE_ALL);
13794 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013795 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013796 goto end;
13797 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070013798 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013799 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013800 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013801 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
13802 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013803 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070013804 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013805 ap_adapter->device_mode,
13806 true);
13807 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013808 }
13809end:
13810 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013811}
13812
13813/**
13814 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
13815 * with non dfs acs
13816 *
13817 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
13818 *
13819 * Return: None
13820 */
13821void hdd_check_and_restart_sap_with_non_dfs_acs(void)
13822{
Jeff Johnson9d295242017-08-29 14:39:48 -070013823 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013824 struct hdd_context *hdd_ctx;
Jeff Johnson2b6982c2018-05-29 14:56:11 -070013825 struct cds_context *cds_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013826
13827 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13828 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013829 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013830 return;
13831 }
13832
13833 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
13834 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013835 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013836 return;
13837 }
13838
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013839 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
13840 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013841 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013842 return;
13843 }
13844
13845 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070013846 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
13847 &ap_adapter->event_flags) &&
13848 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070013849 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013850
Jeff Johnson6867ec32017-09-29 20:30:20 -070013851 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Jeff Johnsonb9424862017-10-30 08:49:35 -070013852 ap_adapter->session.ap.sap_config.channel =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013853 AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -070013854 ap_adapter->session.ap.sap_config.
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013855 acs_cfg.acs_mode = true;
13856
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013857 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013858 }
13859}
13860
13861/**
13862 * hdd_set_connection_in_progress() - to set the connection in
13863 * progress flag
13864 * @value: value to set
13865 *
13866 * This function will set the passed value to connection in progress flag.
13867 * If value is previously being set to true then no need to set it again.
13868 *
13869 * Return: true if value is being set correctly and false otherwise.
13870 */
13871bool hdd_set_connection_in_progress(bool value)
13872{
13873 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013874 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013875
13876 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13877 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013878 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013879 return false;
13880 }
13881
13882 qdf_spin_lock(&hdd_ctx->connection_status_lock);
13883 /*
13884 * if the value is set to true previously and if someone is
13885 * trying to make it true again then it could be some race
13886 * condition being triggered. Avoid this situation by returning
13887 * false
13888 */
13889 if (hdd_ctx->connection_in_progress && value)
13890 status = false;
13891 else
13892 hdd_ctx->connection_in_progress = value;
13893 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
13894 return status;
13895}
13896
Jeff Johnson9d295242017-08-29 14:39:48 -070013897int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013898{
13899 if (!adapter) {
13900 hdd_err("Invalid adapter");
13901 return -EINVAL;
13902 }
13903 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013904 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013905 WMA_VDEV_MCC_SET_TIME_QUOTA,
13906 set_value, VDEV_CMD);
13907 return 0;
13908
13909}
13910
Jeff Johnson9d295242017-08-29 14:39:48 -070013911int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013912{
13913 if (!adapter) {
13914 hdd_err("Invalid adapter");
13915 return -EINVAL;
13916 }
13917
13918 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013919 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013920 WMA_VDEV_MCC_SET_TIME_LATENCY,
13921 set_value, VDEV_CMD);
13922 return 0;
13923}
13924
Jeff Johnson9d295242017-08-29 14:39:48 -070013925struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013926 *psoc, uint8_t vdev_id)
13927{
Jeff Johnson9d295242017-08-29 14:39:48 -070013928 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013929 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013930
13931 /*
13932 * Currently PSOC is not being used. But this logic will
13933 * change once we have the converged implementation of
13934 * HDD context per PSOC in place. This would break if
13935 * multiple vdev objects reuse the vdev id.
13936 */
13937 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
13938 if (!adapter)
13939 hdd_err("Get adapter by vdev id failed");
13940
13941 return adapter;
13942}
13943
Jeff Johnson9d295242017-08-29 14:39:48 -070013944int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013945 int8_t *rssi, int8_t *snr)
13946{
13947 QDF_STATUS status;
Jeff Johnson16528362018-06-14 12:34:16 -070013948 mac_handle_t mac_handle;
Jeff Johnson025618c2018-03-18 14:41:00 -070013949 struct csr_roam_profile *roam_profile;
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013950
Jeff Johnson025618c2018-03-18 14:41:00 -070013951 roam_profile = hdd_roam_profile(adapter);
Jeff Johnson16528362018-06-14 12:34:16 -070013952 mac_handle = hdd_adapter_get_mac_handle(adapter);
13953 status = sme_get_rssi_snr_by_bssid(mac_handle,
Jeff Johnson025618c2018-03-18 14:41:00 -070013954 roam_profile, bssid, rssi, snr);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013955 if (QDF_STATUS_SUCCESS != status) {
13956 hdd_warn("sme_get_rssi_snr_by_bssid failed");
13957 return -EINVAL;
13958 }
13959
13960 return 0;
13961}
13962
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013963/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013964 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
13965 * @adapter - HDD adapter
13966 * @tos - type of service
13967 * @status - status of the traffic
13968 *
13969 * Return: 0 on success and non zero value on failure
13970 */
13971
13972int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
13973 bool is_tos_active)
13974{
13975 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013976 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013977 uint32_t max_off_chan_time = 0;
13978 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013979 int ret;
13980
13981 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13982 ret = wlan_hdd_validate_context(hdd_ctx);
13983
13984 if (ret < 0) {
13985 hdd_err("failed to set limit off chan params");
13986 return ret;
13987 }
13988
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013989 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
13990
13991 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013992 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013993 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013994 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013995
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013996 if (adapter->active_ac) {
13997 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013998 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013999 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
14000 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
14001 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053014002 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014003 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014004 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
14005 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
14006 PM_LATENCY);
14007 } else {
14008 /*ignore this command if only BE/BK is active */
14009 is_tos_active = false;
14010 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
14011 hdd_ctx->config->conc_system_pref);
14012 }
14013 } else {
14014 /* No active tos */
14015 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
14016 hdd_ctx->config->conc_system_pref);
14017 }
14018
Jeff Johnson16528362018-06-14 12:34:16 -070014019 status = sme_send_limit_off_channel_params(hdd_ctx->mac_handle,
14020 adapter->session_id,
14021 is_tos_active,
14022 max_off_chan_time,
14023 hdd_ctx->config->nRestTimeConc,
14024 true);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014025 if (!QDF_IS_STATUS_SUCCESS(status)) {
14026 hdd_err("failed to set limit off chan params");
14027 ret = -EINVAL;
14028 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014029
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014030 return ret;
14031}
14032
14033/**
14034 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
14035 * @adapter - HDD adapter
14036 *
14037 * Return: 0 on success and non zero value on failure
14038 */
14039int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
14040{
14041 struct hdd_context *hdd_ctx;
14042 int ret;
14043 QDF_STATUS status;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014044
14045 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
14046 ret = wlan_hdd_validate_context(hdd_ctx);
14047 if (ret < 0)
14048 return ret;
14049
14050 /* set the system preferece to default */
14051 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
14052 hdd_ctx->config->conc_system_pref);
14053
14054 /* clear the bitmap */
14055 adapter->active_ac = 0;
14056
14057 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson16528362018-06-14 12:34:16 -070014058 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014059
Jeff Johnson16528362018-06-14 12:34:16 -070014060 status = sme_send_limit_off_channel_params(hdd_ctx->mac_handle,
14061 adapter->session_id,
14062 false, 0, 0, false);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053014063 if (!QDF_IS_STATUS_SUCCESS(status)) {
14064 hdd_err("failed to reset limit off chan params");
14065 ret = -EINVAL;
14066 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053014067
14068 return ret;
14069}
14070
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014071/**
14072 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
14073 * @drv_op: Enum indicating driver op
14074 *
14075 * Return: none
14076 */
14077void hdd_start_driver_ops_timer(int drv_op)
14078{
14079 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
14080 switch (drv_op) {
14081 case eHDD_DRV_OP_PROBE:
14082 memcpy(drv_ops_string, "probe", sizeof("probe"));
14083 break;
14084 case eHDD_DRV_OP_REMOVE:
14085 memcpy(drv_ops_string, "remove", sizeof("remove"));
14086 break;
14087 case eHDD_DRV_OP_SHUTDOWN:
14088 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
14089 break;
14090 case eHDD_DRV_OP_REINIT:
14091 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
14092 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053014093 case eHDD_DRV_OP_IFF_UP:
14094 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
14095 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014096 }
14097
Dustin Brown45ed4bb2017-12-18 12:00:13 -080014098 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014099 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
Dustin Browncfc54fe2018-06-18 16:17:41 -070014100 HDD_OPS_INACTIVITY_TIMEOUT * qdf_timer_get_multiplier());
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014101}
14102
14103/**
14104 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
14105 *
14106 * Return: none
14107 */
14108void hdd_stop_driver_ops_timer(void)
14109{
14110 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
14111}
14112
14113/**
14114 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
14115 * inactivity timer
14116 *
14117 * Return: None
14118 */
14119void hdd_drv_ops_inactivity_handler(void)
14120{
Rajeev Kumar4471f1b2018-06-08 14:18:28 -070014121 hdd_err("WLAN_BUG_RCA %s: %d Sec timer expired while in .%s",
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014122 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
14123
Dustin Brown45ed4bb2017-12-18 12:00:13 -080014124 if (hdd_drv_ops_task) {
14125 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
14126 qdf_print_thread_trace(hdd_drv_ops_task);
14127 } else {
14128 hdd_err("hdd_drv_ops_task is null");
14129 }
14130
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014131 /* Driver shutdown is stuck, no recovery possible at this point */
14132 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
14133 sizeof("shutdown")))
14134 QDF_BUG(0);
14135
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080014136 if (cds_is_fw_down()) {
14137 hdd_err("FW is down");
14138 return;
14139 }
14140
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014141 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053014142 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053014143 else
14144 QDF_BUG(0);
14145}
14146
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053014147void hdd_pld_ipa_uc_shutdown_pipes(void)
14148{
14149 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14150
14151 if (!hdd_ctx)
14152 return;
14153
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +053014154 ucfg_ipa_uc_force_pipe_shutdown(hdd_ctx->hdd_pdev);
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053014155}
14156
Yun Parkff6a16a2017-09-26 16:38:18 -070014157/**
14158 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
14159 * @struct hdd_context *hdd_ctx
14160 * @struct hdd_adapter *padapter
14161 * @bool enble
14162 *
14163 * Return: none
14164 */
14165void hdd_set_rx_mode_rps(bool enable)
14166{
14167 struct cds_config_info *cds_cfg = cds_get_ini_config();
Ryan Hsu0e878fa2018-05-04 15:22:09 -070014168 struct hdd_context *hdd_ctx;
14169 struct hdd_adapter *adapter;
Yun Parkff6a16a2017-09-26 16:38:18 -070014170
Ryan Hsu0e878fa2018-05-04 15:22:09 -070014171 if (!cds_cfg)
14172 return;
14173
14174 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
14175 if (!hdd_ctx)
14176 return;
14177
14178 adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
14179 if (!adapter)
14180 return;
14181
14182 if (!hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
Yun Parkff6a16a2017-09-26 16:38:18 -070014183 if (enable && !cds_cfg->rps_enabled)
14184 hdd_send_rps_ind(adapter);
14185 else if (!enable && cds_cfg->rps_enabled)
14186 hdd_send_rps_disable_ind(adapter);
14187 }
14188}
14189
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +053014190bool hdd_is_cli_iface_up(struct hdd_context *hdd_ctx)
14191{
14192 struct hdd_adapter *adapter = NULL;
14193
14194 hdd_for_each_adapter(hdd_ctx, adapter) {
14195 if ((adapter->device_mode == QDF_STA_MODE ||
14196 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
14197 qdf_atomic_test_bit(DEVICE_IFACE_OPENED,
14198 &adapter->event_flags)){
14199 return true;
14200 }
14201 }
14202
14203 return false;
14204}
14205
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014206/* Register the module init/exit functions */
14207module_init(hdd_module_init);
14208module_exit(hdd_module_exit);
14209
14210MODULE_LICENSE("Dual BSD/GPL");
14211MODULE_AUTHOR("Qualcomm Atheros, Inc.");
14212MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
14213
Srinivas Girigowda841da292018-02-21 16:33:00 -080014214static const struct kernel_param_ops con_mode_ops = {
14215 .set = con_mode_handler,
14216 .get = param_get_int,
14217};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014218
Srinivas Girigowda841da292018-02-21 16:33:00 -080014219static const struct kernel_param_ops con_mode_ftm_ops = {
14220 .set = con_mode_handler_ftm,
14221 .get = param_get_int,
14222};
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053014223
Nirav Shah73713f72018-05-17 14:50:41 +053014224#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080014225static const struct kernel_param_ops con_mode_monitor_ops = {
14226 .set = con_mode_handler_monitor,
14227 .get = param_get_int,
14228};
Nirav Shah73713f72018-05-17 14:50:41 +053014229#endif
Ravi Joshia307f632017-07-17 23:41:41 -070014230
Srinivas Girigowda841da292018-02-21 16:33:00 -080014231static const struct kernel_param_ops fwpath_ops = {
14232 .set = fwpath_changed_handler,
14233 .get = param_get_string,
14234};
14235
14236module_param_cb(con_mode, &con_mode_ops, &con_mode,
14237 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
14238
14239module_param_cb(con_mode_ftm, &con_mode_ftm_ops, &con_mode_ftm,
14240 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
14241
Nirav Shah73713f72018-05-17 14:50:41 +053014242#ifdef FEATURE_MONITOR_MODE_SUPPORT
Srinivas Girigowda841da292018-02-21 16:33:00 -080014243module_param_cb(con_mode_monitor, &con_mode_monitor_ops, &con_mode_monitor,
14244 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Nirav Shah73713f72018-05-17 14:50:41 +053014245#endif
Srinivas Girigowda841da292018-02-21 16:33:00 -080014246
14247module_param_cb(fwpath, &fwpath_ops, &fwpath,
14248 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080014249
14250module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
14251
14252module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
14253
14254module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);