blob: 1cd1f083acaba3047aac98ff29c8ba2283fe74d9 [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 */
27#include <wlan_hdd_includes.h>
28#include <cds_api.h>
29#include <cds_sched.h>
Arun Khandavallifae92942016-08-01 13:31:08 +053030#include <linux/cpu.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080031#include <linux/etherdevice.h>
32#include <linux/firmware.h>
33#include <wlan_hdd_tx_rx.h>
34#include <wni_api.h>
35#include <wlan_hdd_cfg.h>
36#include <wlan_ptt_sock_svc.h>
37#include <dbglog_host.h>
38#include <wlan_logging_sock_svc.h>
39#include <wlan_hdd_wowl.h>
40#include <wlan_hdd_misc.h>
41#include <wlan_hdd_wext.h>
42#include "wlan_hdd_trace.h"
43#include "wlan_hdd_ioctl.h"
44#include "wlan_hdd_ftm.h"
45#include "wlan_hdd_power.h"
46#include "wlan_hdd_stats.h"
Prashanth Bhatta527fd752016-04-28 12:35:23 -070047#include "wlan_hdd_scan.h"
Jeff Johnsonce0032c2017-01-20 07:18:27 -080048#include "wlan_hdd_request_manager.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>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080059
60#include <net/addrconf.h>
61#include <linux/wireless.h>
62#include <net/cfg80211.h>
63#include <linux/inetdevice.h>
64#include <net/addrconf.h>
65#include "wlan_hdd_cfg80211.h"
66#include "wlan_hdd_ext_scan.h"
67#include "wlan_hdd_p2p.h"
68#include <linux/rtnetlink.h>
69#include "sap_api.h"
70#include <linux/semaphore.h>
71#include <linux/ctype.h>
72#include <linux/compat.h>
Arunk Khandavalli830c9692018-03-22 12:17:40 +053073#include <linux/reboot.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080074#ifdef MSM_PLATFORM
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080075#include <soc/qcom/subsystem_restart.h>
76#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080077#include <wlan_hdd_hostapd.h>
78#include <wlan_hdd_softap_tx_rx.h>
Jeff Johnson8bb61112018-03-31 13:33:54 -070079#include <wlan_hdd_green_ap.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080080#include "cfg_api.h"
81#include "qwlan_version.h"
82#include "wma_types.h"
83#include "wlan_hdd_tdls.h"
84#ifdef FEATURE_WLAN_CH_AVOID
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +053085#include "cds_regdomain.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080086#endif /* FEATURE_WLAN_CH_AVOID */
Dustin Brownce46d1d2017-08-15 13:34:24 -070087#include "cdp_txrx_flow_ctrl_v2.h"
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070088#include "pld_common.h"
Tushnim Bhattacharyya15596cf2016-02-12 11:57:02 -080089#include "wlan_hdd_ocb.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080090#include "wlan_hdd_nan.h"
91#include "wlan_hdd_debugfs.h"
92#include "wlan_hdd_driver_ops.h"
93#include "epping_main.h"
Poddar, Siddarth34872782017-08-10 14:08:51 +053094#include "wlan_hdd_data_stall_detection.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080095
96#include <wlan_hdd_ipa.h>
97#include "hif.h"
98#include "wma.h"
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080099#include "wlan_policy_mgr_api.h"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700100#include "wlan_hdd_tsf.h"
Komal Seelamec702b02016-02-24 18:42:16 +0530101#include "bmi.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -0700102#include <wlan_hdd_regulatory.h>
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700103#include "wlan_hdd_lpass.h"
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530104#include "nan_api.h"
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -0700105#include <wlan_hdd_napi.h>
Padma, Santhosh Kumard7cc0792016-06-28 18:54:12 +0530106#include "wlan_hdd_disa.h"
Rajeev Kumar97767a02016-11-30 11:20:40 -0800107#include <dispatcher_init_deinit.h>
Rajeev Kumar699debf2017-01-06 14:17:00 -0800108#include "wlan_hdd_object_manager.h"
yeshwanth sriram guntuka310b3ac2016-11-15 23:25:26 +0530109#include "cds_utils.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800110#include <cdp_txrx_handle.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800111#include <qca_vendor.h>
Mukul Sharma9d797a02017-01-05 20:26:03 +0530112#include "wlan_pmo_ucfg_api.h"
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +0530113#include "sir_api.h"
Naveen Rawat910726a2017-03-06 11:42:51 -0800114#include "os_if_wifi_pos.h"
115#include "wifi_pos_api.h"
116#include "wlan_hdd_oemdata.h"
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -0800117#include "wlan_hdd_he.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700118#include "os_if_nan.h"
119#include "nan_public_structs.h"
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -0700120#include "wlan_reg_ucfg_api.h"
bings81fe50a2017-11-27 14:33:26 +0800121#include "wlan_dfs_ucfg_api.h"
Ravi Joshi4f095952017-06-29 15:39:19 -0700122#include "wlan_hdd_rx_monitor.h"
Mukul Sharmad16c2022017-07-25 18:56:12 +0530123#include "sme_power_save_api.h"
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +0530124#include "enet.h"
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -0700125#include <cdp_txrx_cmn_struct.h>
Amar Singhal0928b192017-12-01 10:50:54 -0800126#include "wlan_hdd_sysfs.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530127#include "wlan_disa_ucfg_api.h"
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +0530128#include "wlan_ipa_ucfg_api.h"
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530129#include <target_if.h>
Alok Kumarb64650c2018-03-23 17:05:11 +0530130#include "wlan_hdd_nud_tracking.h"
Nachiket Kukade98f562a2017-12-15 12:18:07 +0530131
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530132#ifdef CNSS_GENL
133#include <net/cnss_nl.h>
134#endif
Amar Singhal5cccafe2017-02-15 12:42:58 -0800135#include "wlan_reg_ucfg_api.h"
Zhang Qian47e22ce2018-01-04 15:38:38 +0800136#include "wlan_ocb_ucfg_api.h"
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +0530137
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -0800138#include <wlan_hdd_spectralscan.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800139#ifdef MODULE
140#define WLAN_MODULE_NAME module_name(THIS_MODULE)
141#else
142#define WLAN_MODULE_NAME "wlan"
143#endif
144
145#ifdef TIMER_MANAGER
146#define TIMER_MANAGER_STR " +TIMER_MANAGER"
147#else
148#define TIMER_MANAGER_STR ""
149#endif
150
151#ifdef MEMORY_DEBUG
152#define MEMORY_DEBUG_STR " +MEMORY_DEBUG"
153#else
154#define MEMORY_DEBUG_STR ""
155#endif
156
Dustin Brownc1034df2018-02-07 14:51:32 -0800157#ifdef PANIC_ON_BUG
158#define PANIC_ON_BUG_STR " +PANIC_ON_BUG"
159#else
160#define PANIC_ON_BUG_STR ""
161#endif
162
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530163bool g_is_system_reboot_triggered;
Sachin Ahujadddd2632017-03-07 19:07:24 +0530164int wlan_start_ret_val;
165static DECLARE_COMPLETION(wlan_start_comp);
166static unsigned int dev_num = 1;
167static struct cdev wlan_hdd_state_cdev;
168static struct class *class;
169static dev_t device;
Arun Khandavallifae92942016-08-01 13:31:08 +0530170#ifndef MODULE
171static struct gwlan_loader *wlan_loader;
172static ssize_t wlan_boot_cb(struct kobject *kobj,
173 struct kobj_attribute *attr,
174 const char *buf, size_t count);
175struct gwlan_loader {
176 bool loaded_state;
177 struct kobject *boot_wlan_obj;
178 struct attribute_group *attr_group;
179};
180
181static struct kobj_attribute wlan_boot_attribute =
182 __ATTR(boot_wlan, 0220, NULL, wlan_boot_cb);
183
184static struct attribute *attrs[] = {
185 &wlan_boot_attribute.attr,
186 NULL,
187};
188
189#define MODULE_INITIALIZED 1
190#endif
191
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530192#define HDD_OPS_INACTIVITY_TIMEOUT (120000)
193#define MAX_OPS_NAME_STRING_SIZE 20
Rajeev Kumar6d0b2ea2017-12-26 17:55:33 -0800194#define RATE_LIMIT_ERROR_LOG (256)
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530195
196static qdf_timer_t hdd_drv_ops_inactivity_timer;
Dustin Brown45ed4bb2017-12-18 12:00:13 -0800197static struct task_struct *hdd_drv_ops_task;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +0530198static char drv_ops_string[MAX_OPS_NAME_STRING_SIZE];
199
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800200/* the Android framework expects this param even though we don't use it */
201#define BUF_LEN 20
202static char fwpath_buffer[BUF_LEN];
203static struct kparam_string fwpath = {
204 .string = fwpath_buffer,
205 .maxlen = BUF_LEN,
206};
207
208static char *country_code;
209static int enable_11d = -1;
210static int enable_dfs_chan_scan = -1;
211
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800212/*
213 * spinlock for synchronizing asynchronous request/response
214 * (full description of use in wlan_hdd_main.h)
215 */
216DEFINE_SPINLOCK(hdd_context_lock);
Arunk Khandavalli16d84252017-06-21 15:26:29 +0530217DEFINE_MUTEX(hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800218
Rajeev Kumar8e3e2832015-11-06 16:02:54 -0800219#define WLAN_NLINK_CESIUM 30
220
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530221static qdf_wake_lock_t wlan_wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800222
223#define WOW_MAX_FILTER_LISTS 1
224#define WOW_MAX_FILTERS_PER_LIST 4
225#define WOW_MIN_PATTERN_SIZE 6
226#define WOW_MAX_PATTERN_SIZE 64
227
228#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
229static const struct wiphy_wowlan_support wowlan_support_reg_init = {
230 .flags = WIPHY_WOWLAN_ANY |
231 WIPHY_WOWLAN_MAGIC_PKT |
232 WIPHY_WOWLAN_DISCONNECT |
233 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
234 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
235 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
236 WIPHY_WOWLAN_4WAY_HANDSHAKE |
237 WIPHY_WOWLAN_RFKILL_RELEASE,
238 .n_patterns = WOW_MAX_FILTER_LISTS * WOW_MAX_FILTERS_PER_LIST,
239 .pattern_min_len = WOW_MIN_PATTERN_SIZE,
240 .pattern_max_len = WOW_MAX_PATTERN_SIZE,
241};
242#endif
243
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700244static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = {
245 [QDF_MODULE_ID_TLSHIM] = {QDF_TRACE_LEVEL_ALL},
246 [QDF_MODULE_ID_WMI] = {QDF_TRACE_LEVEL_ALL},
247 [QDF_MODULE_ID_HTT] = {QDF_TRACE_LEVEL_ALL},
248 [QDF_MODULE_ID_HDD] = {QDF_TRACE_LEVEL_ALL},
249 [QDF_MODULE_ID_SME] = {QDF_TRACE_LEVEL_ALL},
250 [QDF_MODULE_ID_PE] = {QDF_TRACE_LEVEL_ALL},
251 [QDF_MODULE_ID_WMA] = {QDF_TRACE_LEVEL_ALL},
252 [QDF_MODULE_ID_SYS] = {QDF_TRACE_LEVEL_ALL},
253 [QDF_MODULE_ID_QDF] = {QDF_TRACE_LEVEL_ALL},
254 [QDF_MODULE_ID_SAP] = {QDF_TRACE_LEVEL_ALL},
255 [QDF_MODULE_ID_HDD_SOFTAP] = {QDF_TRACE_LEVEL_ALL},
256 [QDF_MODULE_ID_HDD_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
257 [QDF_MODULE_ID_HDD_SAP_DATA] = {QDF_DATA_PATH_TRACE_LEVEL},
258 [QDF_MODULE_ID_HIF] = {QDF_DATA_PATH_TRACE_LEVEL},
259 [QDF_MODULE_ID_HTC] = {QDF_DATA_PATH_TRACE_LEVEL},
260 [QDF_MODULE_ID_TXRX] = {QDF_DATA_PATH_TRACE_LEVEL},
261 [QDF_MODULE_ID_QDF_DEVICE] = {QDF_TRACE_LEVEL_ALL},
262 [QDF_MODULE_ID_CFG] = {QDF_TRACE_LEVEL_ALL},
263 [QDF_MODULE_ID_BMI] = {QDF_TRACE_LEVEL_ALL},
264 [QDF_MODULE_ID_EPPING] = {QDF_TRACE_LEVEL_ALL},
265 [QDF_MODULE_ID_QVIT] = {QDF_TRACE_LEVEL_ALL},
266 [QDF_MODULE_ID_DP] = {QDF_TRACE_LEVEL_ALL},
267 [QDF_MODULE_ID_SOC] = {QDF_TRACE_LEVEL_ALL},
268 [QDF_MODULE_ID_OS_IF] = {QDF_TRACE_LEVEL_ALL},
269 [QDF_MODULE_ID_TARGET_IF] = {QDF_TRACE_LEVEL_ALL},
270 [QDF_MODULE_ID_SCHEDULER] = {QDF_TRACE_LEVEL_ALL},
271 [QDF_MODULE_ID_MGMT_TXRX] = {QDF_TRACE_LEVEL_ALL},
272 [QDF_MODULE_ID_PMO] = {QDF_TRACE_LEVEL_ALL},
273 [QDF_MODULE_ID_SCAN] = {QDF_TRACE_LEVEL_ALL},
274 [QDF_MODULE_ID_POLICY_MGR] = {QDF_TRACE_LEVEL_ALL},
275 [QDF_MODULE_ID_P2P] = {QDF_TRACE_LEVEL_ALL},
276 [QDF_MODULE_ID_TDLS] = {QDF_TRACE_LEVEL_ALL},
277 [QDF_MODULE_ID_REGULATORY] = {QDF_TRACE_LEVEL_ALL},
278 [QDF_MODULE_ID_SERIALIZATION] = {QDF_TRACE_LEVEL_ALL},
Arif Hussainfde76e72017-09-05 16:58:23 -0700279 [QDF_MODULE_ID_DFS] = {QDF_TRACE_LEVEL_ALL},
Rajeev Kumarca8ef9d2017-10-06 10:43:21 -0700280 [QDF_MODULE_ID_OBJ_MGR] = {QDF_TRACE_LEVEL_ALL},
Deepak Dhamdheref918d422017-07-06 12:56:29 -0700281 [QDF_MODULE_ID_ROAM_DEBUG] = {QDF_TRACE_LEVEL_ALL},
Himanshu Agarwalb229a142017-12-21 10:16:45 +0530282 [QDF_MODULE_ID_GREEN_AP] = {QDF_TRACE_LEVEL_ALL},
Zhang Qian47e22ce2018-01-04 15:38:38 +0800283 [QDF_MODULE_ID_OCB] = {QDF_TRACE_LEVEL_ALL},
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530284 [QDF_MODULE_ID_IPA] = {QDF_TRACE_LEVEL_ALL},
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -0700285};
286
Ganesh Kondabattini35739572017-06-21 16:26:39 +0530287int limit_off_chan_tbl[HDD_MAX_AC][HDD_MAX_OFF_CHAN_ENTRIES] = {
288 { HDD_AC_BK_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BK },
289 { HDD_AC_BE_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BE },
290 { HDD_AC_VI_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VI },
291 { HDD_AC_VO_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VO },
292};
293
Ashish Kumar Dhanotiyacf11bae2017-04-04 03:29:47 +0530294struct notifier_block hdd_netdev_notifier;
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530295struct notifier_block system_reboot_notifier;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800296
297struct sock *cesium_nl_srv_sock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800298#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700299static void wlan_hdd_auto_shutdown_cb(void);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800300#endif
301
Sachin Ahujadddd2632017-03-07 19:07:24 +0530302void hdd_start_complete(int ret)
303{
304 wlan_start_ret_val = ret;
305
306 complete(&wlan_start_comp);
307}
308
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800309/**
Nirav Shahbd36b062016-07-18 11:12:59 +0530310 * hdd_set_rps_cpu_mask - set RPS CPU mask for interfaces
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700311 * @hdd_ctx: pointer to struct hdd_context
Nirav Shahbd36b062016-07-18 11:12:59 +0530312 *
313 * Return: none
314 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700315static void hdd_set_rps_cpu_mask(struct hdd_context *hdd_ctx)
Nirav Shahbd36b062016-07-18 11:12:59 +0530316{
Jeff Johnson9d295242017-08-29 14:39:48 -0700317 struct hdd_adapter *adapter;
Nirav Shahbd36b062016-07-18 11:12:59 +0530318
Dustin Brown920397d2017-12-13 16:27:50 -0800319 hdd_for_each_adapter(hdd_ctx, adapter)
320 hdd_send_rps_ind(adapter);
Nirav Shahbd36b062016-07-18 11:12:59 +0530321}
322
323/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800324 * wlan_hdd_txrx_pause_cb() - pause callback from txrx layer
325 * @vdev_id: vdev_id
326 * @action: action type
327 * @reason: reason type
328 *
329 * Return: none
330 */
331void wlan_hdd_txrx_pause_cb(uint8_t vdev_id,
332 enum netif_action_type action, enum netif_reason_type reason)
333{
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700334 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson9d295242017-08-29 14:39:48 -0700335 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800336
337 if (!hdd_ctx) {
338 hdd_err("hdd ctx is NULL");
339 return;
340 }
341 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
342
343 wlan_hdd_netif_queue_control(adapter, action, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800344}
345
346/*
Dustin Brownab482ac2017-06-09 17:00:44 -0700347 * Store WLAN driver version and timestamp info in global variables such that
348 * crash debugger can extract them from driver debug symbol and crashdump for
349 * post processing
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800350 */
Dustin Brown96cd9632017-11-13 12:45:04 -0800351#ifdef BUILD_TAG
352uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR "; " BUILD_TAG;
353#else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800354uint8_t g_wlan_driver_version[] = QWLAN_VERSIONSTR;
Naveen Rawat93836252017-06-20 16:30:59 -0700355#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800356
357/**
358 * hdd_device_mode_to_string() - return string conversion of device mode
359 * @device_mode: device mode
360 *
361 * This utility function helps log string conversion of device mode.
362 *
363 * Return: string conversion of device mode, if match found;
364 * "Unknown" otherwise.
365 */
366const char *hdd_device_mode_to_string(uint8_t device_mode)
367{
368 switch (device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -0800369 CASE_RETURN_STRING(QDF_STA_MODE);
370 CASE_RETURN_STRING(QDF_SAP_MODE);
371 CASE_RETURN_STRING(QDF_P2P_CLIENT_MODE);
372 CASE_RETURN_STRING(QDF_P2P_GO_MODE);
373 CASE_RETURN_STRING(QDF_FTM_MODE);
374 CASE_RETURN_STRING(QDF_IBSS_MODE);
375 CASE_RETURN_STRING(QDF_P2P_DEVICE_MODE);
376 CASE_RETURN_STRING(QDF_OCB_MODE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700377 CASE_RETURN_STRING(QDF_NDI_MODE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800378 default:
379 return "Unknown";
380 }
381}
382
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530383/**
Liangwei Dong17bf2662018-01-05 02:02:05 -0500384 * hdd_get_valid_chan() - return current chan list from regulatory.
385 * @hdd_ctx: HDD context
386 * @chan_list: buf hold returned chan list
387 * @chan_num: input buf size and output returned chan num
388 *
389 * This function helps get current available chan list from regulatory
390 * module. It excludes the "disabled" and "invalid" channels.
391 *
392 * Return: 0 for success.
393 */
394static int hdd_get_valid_chan(struct hdd_context *hdd_ctx,
395 uint8_t *chan_list,
396 uint32_t *chan_num)
397{
398 int i = 0, j = 0;
399 struct regulatory_channel *cur_chan_list;
400 struct wlan_objmgr_pdev *pdev;
401
402 if (!hdd_ctx || !hdd_ctx->hdd_pdev || !chan_list || !chan_num)
403 return -EINVAL;
404
405 pdev = hdd_ctx->hdd_pdev;
406 cur_chan_list = qdf_mem_malloc(NUM_CHANNELS *
407 sizeof(struct regulatory_channel));
408 if (!cur_chan_list)
409 return -ENOMEM;
410
411 if (wlan_reg_get_current_chan_list(pdev, cur_chan_list) !=
412 QDF_STATUS_SUCCESS) {
413 qdf_mem_free(cur_chan_list);
414 return -EINVAL;
415 }
416
417 for (i = 0; i < NUM_CHANNELS; i++) {
418 uint32_t ch = cur_chan_list[i].chan_num;
419 enum channel_state state = wlan_reg_get_channel_state(pdev,
420 ch);
421
422 if (state != CHANNEL_STATE_DISABLE &&
423 state != CHANNEL_STATE_INVALID &&
424 j < *chan_num) {
425 chan_list[j] = (uint8_t)ch;
426 j++;
427 }
428 }
429 *chan_num = j;
430 qdf_mem_free(cur_chan_list);
431 return 0;
432}
433
434/**
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530435 * hdd_validate_channel_and_bandwidth() - Validate the channel-bandwidth combo
436 * @adapter: HDD adapter
437 * @chan_number: Channel number
438 * @chan_bw: Bandwidth
439 *
440 * Checks if the given bandwidth is valid for the given channel number.
441 *
442 * Return: 0 for success, non-zero for failure
443 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700444int hdd_validate_channel_and_bandwidth(struct hdd_adapter *adapter,
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530445 uint32_t chan_number,
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800446 enum phy_ch_width chan_bw)
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530447{
Liangwei Dong17bf2662018-01-05 02:02:05 -0500448 uint8_t chan[NUM_CHANNELS];
449 uint32_t len = NUM_CHANNELS, i;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530450 bool found = false;
451 tHalHandle hal;
Liangwei Dong17bf2662018-01-05 02:02:05 -0500452 int ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530453
454 hal = WLAN_HDD_GET_HAL_CTX(adapter);
455 if (!hal) {
456 hdd_err("Invalid HAL context");
457 return -EINVAL;
458 }
459
Liangwei Dong17bf2662018-01-05 02:02:05 -0500460 ret = hdd_get_valid_chan(adapter->hdd_ctx, chan,
461 &len);
462 if (ret) {
463 hdd_err("error %d in getting valid channel list", ret);
464 return ret;
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530465 }
466
467 for (i = 0; i < len; i++) {
468 if (chan[i] == chan_number) {
469 found = true;
470 break;
471 }
472 }
473
474 if (found == false) {
475 hdd_err("Channel not in driver's valid channel list");
476 return -EOPNOTSUPP;
477 }
478
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700479 if ((!WLAN_REG_IS_24GHZ_CH(chan_number)) &&
480 (!WLAN_REG_IS_5GHZ_CH(chan_number))) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530481 hdd_err("CH %d is not in 2.4GHz or 5GHz", chan_number);
482 return -EINVAL;
483 }
484
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700485 if (WLAN_REG_IS_24GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530486 if (chan_bw == CH_WIDTH_80MHZ) {
487 hdd_err("BW80 not possible in 2.4GHz band");
488 return -EINVAL;
489 }
490 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 14) &&
491 (chan_bw != CH_WIDTH_MAX)) {
492 hdd_err("Only BW20 possible on channel 14");
493 return -EINVAL;
494 }
495 }
496
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700497 if (WLAN_REG_IS_5GHZ_CH(chan_number)) {
Chandrasekaran, Manishekar794a0982016-01-12 19:42:20 +0530498 if ((chan_bw != CH_WIDTH_20MHZ) && (chan_number == 165) &&
499 (chan_bw != CH_WIDTH_MAX)) {
500 hdd_err("Only BW20 possible on channel 165");
501 return -EINVAL;
502 }
503 }
504
505 return 0;
506}
507
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530508/**
509 * hdd_wait_for_recovery_completion() - Wait for cds recovery completion
510 *
511 * Block the unloading of the driver (or) interface up until the
512 * cds recovery is completed
513 *
514 * Return: true for recovery completion else false
515 */
516static bool hdd_wait_for_recovery_completion(void)
517{
518 int retry = 0;
519
520 /* Wait for recovery to complete */
521 while (cds_is_driver_recovering()) {
522 if (retry == HDD_MOD_EXIT_SSR_MAX_RETRIES/2)
523 hdd_err("Recovery in progress; wait here!!!");
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530524
525 if (g_is_system_reboot_triggered) {
526 hdd_info("System Reboot happening ignore unload!!");
527 return false;
528 }
529
Arunk Khandavallie1b3a382017-09-26 12:01:26 +0530530 msleep(1000);
531 if (retry++ == HDD_MOD_EXIT_SSR_MAX_RETRIES) {
532 hdd_err("SSR never completed, error");
533 /*
534 * Trigger the bug_on in the internal builds, in the
535 * customer builds self-recovery will be enabled
536 * in those cases just return error.
537 */
538 if (cds_is_self_recovery_enabled())
539 return false;
540 QDF_BUG(0);
541 }
542 }
543
544 hdd_info("Recovery completed successfully!");
545 return true;
546}
547
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530548
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800549static int __hdd_netdev_notifier_call(struct notifier_block *nb,
550 unsigned long state, void *data)
551{
552#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
553 struct netdev_notifier_info *dev_notif_info = data;
554 struct net_device *dev = dev_notif_info->dev;
555#else
556 struct net_device *dev = data;
557#endif
Jeff Johnson9d295242017-08-29 14:39:48 -0700558 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700559 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800560
Dustin Brownfdf17c12018-03-14 12:55:34 -0700561 hdd_enter_dev(dev);
Jeff Johnson3c3994a2016-02-11 08:12:30 -0800562
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800563 /* Make sure that this callback corresponds to our device. */
564 if ((strncmp(dev->name, "wlan", 4)) && (strncmp(dev->name, "p2p", 3)))
565 return NOTIFY_DONE;
566
Samuel Ahnc9c48ca2016-09-19 15:46:36 +0530567 if ((adapter->magic != WLAN_HDD_ADAPTER_MAGIC) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800568 (adapter->dev != dev)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700569 hdd_err("device adapter is not matching!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800570 return NOTIFY_DONE;
571 }
572
573 if (!dev->ieee80211_ptr) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700574 hdd_err("ieee80211_ptr is NULL!!!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800575 return NOTIFY_DONE;
576 }
577
578 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
579 if (NULL == hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800580 hdd_err("HDD Context Null Pointer");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530581 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800582 return NOTIFY_DONE;
583 }
Jingxiang Ge9db9d232017-10-14 17:22:15 +0800584
585 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
586 hdd_err("%s: Driver module is closed", __func__);
587 return NOTIFY_DONE;
588 }
589
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530590 if (cds_is_driver_recovering() || cds_is_driver_in_bad_state())
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800591 return NOTIFY_DONE;
592
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800593 hdd_debug("%s New Net Device State = %lu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800594 dev->name, state);
595
596 switch (state) {
597 case NETDEV_REGISTER:
598 break;
599
600 case NETDEV_UNREGISTER:
601 break;
602
603 case NETDEV_UP:
604 sme_ch_avoid_update_req(hdd_ctx->hHal);
605 break;
606
607 case NETDEV_DOWN:
608 break;
609
610 case NETDEV_CHANGE:
Jeff Johnsonc72c5732017-10-28 12:49:37 -0700611 if (adapter->is_link_up_service_needed)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800612 complete(&adapter->linkup_event_var);
613 break;
614
615 case NETDEV_GOING_DOWN:
Sandeep Puligilla5f86d992017-10-29 14:58:53 -0700616 if (ucfg_scan_get_vdev_status(adapter->hdd_vdev) !=
617 SCAN_NOT_IN_PROGRESS) {
Abhishek Singh69ccb512017-04-25 11:58:16 +0530618 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -0700619 adapter->session_id, INVALID_SCAN_ID, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800620 } else {
hqueaa33ee2017-05-04 17:56:35 +0800621 cds_flush_work(&adapter->scan_block_work);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800622 hdd_debug("Scan is not Pending from user");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800623 }
Arunk Khandavallif0c0d762017-12-07 10:18:50 +0530624 /*
625 * After NETDEV_GOING_DOWN, kernel calls hdd_stop.Irrespective
626 * of return status of hdd_stop call, kernel resets the IFF_UP
627 * flag after which driver does not send the cfg80211_scan_done.
628 * Ensure to cleanup the scan queue in NETDEV_GOING_DOWN
629 */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +0530630 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800631 break;
632
633 default:
634 break;
635 }
636
637 return NOTIFY_DONE;
638}
639
640/**
641 * hdd_netdev_notifier_call() - netdev notifier callback function
642 * @nb: pointer to notifier block
643 * @state: state
644 * @ndev: ndev pointer
645 *
646 * Return: 0 on success, error number otherwise.
647 */
648static int hdd_netdev_notifier_call(struct notifier_block *nb,
649 unsigned long state,
650 void *ndev)
651{
652 int ret;
653
654 cds_ssr_protect(__func__);
655 ret = __hdd_netdev_notifier_call(nb, state, ndev);
656 cds_ssr_unprotect(__func__);
657
658 return ret;
659}
660
661struct notifier_block hdd_netdev_notifier = {
662 .notifier_call = hdd_netdev_notifier_call,
663};
664
Arunk Khandavalli830c9692018-03-22 12:17:40 +0530665static int system_reboot_notifier_call(struct notifier_block *nb,
666 unsigned long msg_type, void *_unused)
667{
668 switch (msg_type) {
669 case SYS_DOWN:
670 case SYS_HALT:
671 case SYS_POWER_OFF:
672 g_is_system_reboot_triggered = true;
673 hdd_info("reboot, reason: %ld", msg_type);
674 break;
675 default:
676 break;
677 }
678
679 return NOTIFY_OK;
680}
681
682struct notifier_block system_reboot_notifier = {
683 .notifier_call = system_reboot_notifier_call,
684};
685
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800686/* variable to hold the insmod parameters */
687static int con_mode;
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800688
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530689static int con_mode_ftm;
Ravi Joshia307f632017-07-17 23:41:41 -0700690int con_mode_monitor;
Arunk Khandavalliba3d5582017-07-11 19:48:32 +0530691
Prashanth Bhatta05aaf012015-12-10 17:34:24 -0800692/* Variable to hold connection mode including module parameter con_mode */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800693static int curr_con_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800694
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530695/**
696 * hdd_map_nl_chan_width() - Map NL channel width to internal representation
697 * @ch_width: NL channel width
698 *
699 * Converts the NL channel width to the driver's internal representation
700 *
701 * Return: Converted channel width. In case of non matching NL channel width,
702 * CH_WIDTH_MAX will be returned.
703 */
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800704enum phy_ch_width hdd_map_nl_chan_width(enum nl80211_chan_width ch_width)
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530705{
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800706 uint8_t fw_ch_bw;
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700707
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800708 fw_ch_bw = wma_get_vht_ch_width();
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530709 switch (ch_width) {
710 case NL80211_CHAN_WIDTH_20_NOHT:
711 case NL80211_CHAN_WIDTH_20:
712 return CH_WIDTH_20MHZ;
713 case NL80211_CHAN_WIDTH_40:
714 return CH_WIDTH_40MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530715 case NL80211_CHAN_WIDTH_80:
716 return CH_WIDTH_80MHZ;
717 case NL80211_CHAN_WIDTH_80P80:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800718 if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_80_PLUS_80MHZ)
719 return CH_WIDTH_80P80MHZ;
720 else if (fw_ch_bw == WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
721 return CH_WIDTH_160MHZ;
722 else
723 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530724 case NL80211_CHAN_WIDTH_160:
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -0800725 if (fw_ch_bw >= WNI_CFG_VHT_CHANNEL_WIDTH_160MHZ)
726 return CH_WIDTH_160MHZ;
727 else
728 return CH_WIDTH_80MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530729 case NL80211_CHAN_WIDTH_5:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800730 return CH_WIDTH_5MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530731 case NL80211_CHAN_WIDTH_10:
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800732 return CH_WIDTH_10MHZ;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530733 default:
734 hdd_err("Invalid channel width %d, setting to default",
735 ch_width);
Kiran Kumar Lokere13644672016-02-29 15:40:10 -0800736 return CH_WIDTH_INVALID;
Chandrasekaran, Manishekara74bb022016-01-12 18:37:43 +0530737 }
738}
739
Masti, Narayanraddic4a7ab82015-11-25 15:41:10 +0530740/* wlan_hdd_find_opclass() - Find operating class for a channel
741 * @hal: handler to HAL
742 * @channel: channel id
743 * @bw_offset: bandwidth offset
744 *
745 * Function invokes sme api to find the operating class
746 *
747 * Return: operating class
748 */
749uint8_t wlan_hdd_find_opclass(tHalHandle hal, uint8_t channel,
750 uint8_t bw_offset)
751{
752 uint8_t opclass = 0;
753
754 sme_get_opclass(hal, channel, bw_offset, &opclass);
755 return opclass;
756}
757
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800758/**
Anurag Chouhanf04e84f2016-03-03 10:12:12 +0530759 * hdd_qdf_trace_enable() - configure initial QDF Trace enable
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530760 * @module_id: Module whose trace level is being configured
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800761 * @bitmask: Bitmask of log levels to be enabled
762 *
763 * Called immediately after the cfg.ini is read in order to configure
764 * the desired trace levels.
765 *
766 * Return: None
767 */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530768int hdd_qdf_trace_enable(QDF_MODULE_ID module_id, uint32_t bitmask)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800769{
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530770 QDF_TRACE_LEVEL level;
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530771 int qdf_print_idx = -1;
772 int status = -1;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800773 /*
774 * if the bitmask is the default value, then a bitmask was not
775 * specified in cfg.ini, so leave the logging level alone (it
776 * will remain at the "compiled in" default value)
777 */
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700778 if (CFG_QDF_TRACE_ENABLE_DEFAULT == bitmask)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530779 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800780
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530781 qdf_print_idx = qdf_get_pidx();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800782
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530783 /* a mask was specified. start by disabling all logging */
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530784 status = qdf_print_set_category_verbose(qdf_print_idx, module_id,
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530785 QDF_TRACE_LEVEL_NONE, 0);
786
787 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530788 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800789 /* now cycle through the bitmask until all "set" bits are serviced */
Ashish Kumar Dhanotiya83f286b2017-09-15 19:52:58 +0530790 level = QDF_TRACE_LEVEL_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800791 while (0 != bitmask) {
792 if (bitmask & 1) {
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530793 status = qdf_print_set_category_verbose(qdf_print_idx,
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530794 module_id, level, 1);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +0530795 if (QDF_STATUS_SUCCESS != status)
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530796 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800797 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -0700798
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800799 level++;
800 bitmask >>= 1;
801 }
Ashish Kumar Dhanotiya53c2f692017-02-08 00:25:11 +0530802 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800803}
804
805/**
Chris Guo1751acf2017-07-03 14:09:01 +0800806 * wlan_hdd_validate_context_in_loading() - check the HDD context in loading
807 * @hdd_ctx: HDD context pointer
808 *
809 * Return: 0 if the context is valid. Error code otherwise
810 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700811int wlan_hdd_validate_context_in_loading(struct hdd_context *hdd_ctx)
Chris Guo1751acf2017-07-03 14:09:01 +0800812{
813 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
814 hdd_info("%pS HDD context is Null", (void *)_RET_IP_);
815 return -ENODEV;
816 }
817
818 if (cds_is_driver_recovering()) {
819 hdd_info("%pS Recovery in Progress. State: 0x%x Ignore!!!",
820 (void *)_RET_IP_, cds_get_driver_state());
821 return -EAGAIN;
822 }
823
824 if (hdd_ctx->start_modules_in_progress ||
825 hdd_ctx->stop_modules_in_progress) {
826 hdd_info("%pS Start/Stop Modules in progress. Ignore!!!",
827 (void *)_RET_IP_);
828 return -EAGAIN;
829 }
830
831 return 0;
832}
833
834
835/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800836 * wlan_hdd_validate_context() - check the HDD context
837 * @hdd_ctx: HDD context pointer
838 *
839 * Return: 0 if the context is valid. Error code otherwise
840 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700841int wlan_hdd_validate_context(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800842{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800843 if (NULL == hdd_ctx || NULL == hdd_ctx->config) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530844 hdd_err("%pS HDD context is Null", (void *)_RET_IP_);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800845 return -ENODEV;
846 }
847
Prashanth Bhatta9e143052015-12-04 11:56:47 -0800848 if (cds_is_driver_recovering()) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800849 hdd_debug("%pS Recovery in Progress. State: 0x%x Ignore!!!",
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530850 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800851 return -EAGAIN;
852 }
853
Yue Ma9f275d92017-09-14 16:58:41 -0700854 if (cds_is_load_or_unload_in_progress()) {
855 hdd_debug("%pS Load or unload in progress, state: 0x%x, ignore!",
856 (void *)_RET_IP_, cds_get_driver_state());
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800857 return -EAGAIN;
Yue Ma9f275d92017-09-14 16:58:41 -0700858 }
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530859
860 if (hdd_ctx->start_modules_in_progress ||
861 hdd_ctx->stop_modules_in_progress) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -0800862 hdd_debug("%pS Start/Stop Modules in progress. Ignore!!!",
Arun Khandavallia172c3e2016-08-26 17:33:13 +0530863 (void *)_RET_IP_);
864 return -EAGAIN;
865 }
866
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530867 if (cds_is_driver_in_bad_state()) {
868 hdd_debug("%pS driver in bad State: 0x%x Ignore!!!",
869 (void *)_RET_IP_, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +0530870 return -EAGAIN;
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +0530871 }
872
Arunk Khandavalli2859fa12018-02-14 10:46:26 +0530873 if (cds_is_fw_down()) {
874 hdd_debug("%pS FW is down: 0x%x Ignore!!!",
875 (void *)_RET_IP_, cds_get_driver_state());
Sourav Mohapatra21b3c982018-04-03 17:33:03 +0530876 return -EAGAIN;
Arunk Khandavalli2859fa12018-02-14 10:46:26 +0530877 }
878
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800879 return 0;
880}
881
Jeff Johnson9d295242017-08-29 14:39:48 -0700882int hdd_validate_adapter(struct hdd_adapter *adapter)
Dustin Brownf13b8c32017-05-19 17:23:08 -0700883{
884 if (!adapter) {
885 hdd_err("adapter is null");
886 return -EINVAL;
887 }
888
889 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
890 hdd_err("bad adapter magic: 0x%x (should be 0x%x)",
891 adapter->magic, WLAN_HDD_ADAPTER_MAGIC);
892 return -EINVAL;
893 }
894
895 if (!adapter->dev) {
896 hdd_err("adapter net_device is null");
897 return -EINVAL;
898 }
899
900 if (!(adapter->dev->flags & IFF_UP)) {
901 hdd_info("adapter net_device is not up");
902 return -EAGAIN;
903 }
904
Jeff Johnson1b780e42017-10-31 14:11:45 -0700905 if (wlan_hdd_validate_session_id(adapter->session_id)) {
Dustin Brownf13b8c32017-05-19 17:23:08 -0700906 hdd_info("adapter session is not open");
907 return -EAGAIN;
908 }
909
Jeff Johnson1b780e42017-10-31 14:11:45 -0700910 if (adapter->session_id >= MAX_NUMBER_OF_ADAPTERS) {
911 hdd_err("bad adapter session Id: %u", adapter->session_id);
Dustin Brownf13b8c32017-05-19 17:23:08 -0700912 return -EINVAL;
913 }
914
915 return 0;
916}
917
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800918/**
Arun Khandavallica892f62017-05-26 14:25:50 +0530919 * wlan_hdd_validate_modules_state() - Check modules status
920 * @hdd_ctx: HDD context pointer
921 *
922 * Check's the driver module's state and returns true if the
923 * modules are enabled returns false if modules are closed.
924 *
925 * Return: True if modules are enabled or false.
926 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700927bool wlan_hdd_validate_modules_state(struct hdd_context *hdd_ctx)
Arun Khandavallica892f62017-05-26 14:25:50 +0530928{
929 mutex_lock(&hdd_ctx->iface_change_lock);
930 if (hdd_ctx->driver_status != DRIVER_MODULES_ENABLED) {
931 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown5e89ef82018-03-14 11:50:23 -0700932 hdd_info("Modules not enabled, Present status: %d",
933 hdd_ctx->driver_status);
Arun Khandavallica892f62017-05-26 14:25:50 +0530934 return false;
935 }
936 mutex_unlock(&hdd_ctx->iface_change_lock);
937 return true;
938}
939
940/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800941 * hdd_set_ibss_power_save_params() - update IBSS Power Save params to WMA.
Jeff Johnson9d295242017-08-29 14:39:48 -0700942 * @struct hdd_adapter Hdd adapter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800943 *
944 * This function sets the IBSS power save config parameters to WMA
945 * which will send it to firmware if FW supports IBSS power save
946 * before vdev start.
947 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530948 * Return: QDF_STATUS QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800949 * on failure.
950 */
Jeff Johnson9d295242017-08-29 14:39:48 -0700951QDF_STATUS hdd_set_ibss_power_save_params(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800952{
953 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -0700954 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800955
956 if (hdd_ctx == NULL) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700957 hdd_err("HDD context is null");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530958 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800959 }
960
Jeff Johnson1b780e42017-10-31 14:11:45 -0700961 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800962 WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE,
963 hdd_ctx->config->ibssATIMWinSize,
964 VDEV_CMD);
965 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700966 hdd_err("WMA_VDEV_IBSS_SET_ATIM_WINDOW_SIZE failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530967 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800968 }
969
Jeff Johnson1b780e42017-10-31 14:11:45 -0700970 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800971 WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED,
972 hdd_ctx->config->isIbssPowerSaveAllowed,
973 VDEV_CMD);
974 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700975 hdd_err("WMA_VDEV_IBSS_SET_POWER_SAVE_ALLOWED failed %d",
976 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530977 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800978 }
979
Jeff Johnson1b780e42017-10-31 14:11:45 -0700980 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800981 WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED,
982 hdd_ctx->config->
983 isIbssPowerCollapseAllowed, VDEV_CMD);
984 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700985 hdd_err("WMA_VDEV_IBSS_SET_POWER_COLLAPSE_ALLOWED failed %d",
986 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530987 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800988 }
989
Jeff Johnson1b780e42017-10-31 14:11:45 -0700990 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800991 WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX,
992 hdd_ctx->config->isIbssAwakeOnTxRx,
993 VDEV_CMD);
994 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -0700995 hdd_err("WMA_VDEV_IBSS_SET_AWAKE_ON_TX_RX failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530996 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800997 }
998
Jeff Johnson1b780e42017-10-31 14:11:45 -0700999 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001000 WMA_VDEV_IBSS_SET_INACTIVITY_TIME,
1001 hdd_ctx->config->ibssInactivityCount,
1002 VDEV_CMD);
1003 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001004 hdd_err("WMA_VDEV_IBSS_SET_INACTIVITY_TIME failed %d", ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301005 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001006 }
1007
Jeff Johnson1b780e42017-10-31 14:11:45 -07001008 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001009 WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME,
1010 hdd_ctx->config->ibssTxSpEndInactivityTime,
1011 VDEV_CMD);
1012 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001013 hdd_err("WMA_VDEV_IBSS_SET_TXSP_END_INACTIVITY_TIME failed %d",
1014 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301015 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001016 }
1017
Jeff Johnson1b780e42017-10-31 14:11:45 -07001018 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001019 WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS,
1020 hdd_ctx->config->ibssPsWarmupTime,
1021 VDEV_CMD);
1022 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001023 hdd_err("WMA_VDEV_IBSS_PS_SET_WARMUP_TIME_SECS failed %d",
1024 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301025 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001026 }
1027
Jeff Johnson1b780e42017-10-31 14:11:45 -07001028 ret = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001029 WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW,
1030 hdd_ctx->config->ibssPs1RxChainInAtimEnable,
1031 VDEV_CMD);
1032 if (0 != ret) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001033 hdd_err("WMA_VDEV_IBSS_PS_SET_1RX_CHAIN_IN_ATIM_WINDOW failed %d",
1034 ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301035 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001036 }
1037
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301038 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001039}
1040
Yue Macd359b72017-10-03 15:21:00 -07001041#ifdef FEATURE_RUNTIME_PM
1042/**
1043 * hdd_runtime_suspend_context_init() - API to initialize HDD Runtime Contexts
1044 * @hdd_ctx: HDD context
1045 *
1046 * Return: None
1047 */
1048static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx)
1049{
1050 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1051
Yue Macd359b72017-10-03 15:21:00 -07001052 qdf_runtime_lock_init(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001053 qdf_runtime_lock_init(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001054
1055 wlan_scan_runtime_pm_init(hdd_ctx->hdd_pdev);
1056}
1057
1058/**
1059 * hdd_runtime_suspend_context_deinit() - API to deinit HDD runtime context
1060 * @hdd_ctx: HDD Context
1061 *
1062 * Return: None
1063 */
1064static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx)
1065{
1066 struct hdd_runtime_pm_context *ctx = &hdd_ctx->runtime_context;
1067
Yue Macd359b72017-10-03 15:21:00 -07001068 qdf_runtime_lock_deinit(&ctx->dfs);
Jingxiang Geb49aa302018-01-17 20:54:15 +08001069 qdf_runtime_lock_deinit(&ctx->connect);
Yue Macd359b72017-10-03 15:21:00 -07001070
1071 wlan_scan_runtime_pm_deinit(hdd_ctx->hdd_pdev);
1072}
1073
Yue Macd359b72017-10-03 15:21:00 -07001074#else /* FEATURE_RUNTIME_PM */
1075static void hdd_runtime_suspend_context_init(struct hdd_context *hdd_ctx) {}
1076static void hdd_runtime_suspend_context_deinit(struct hdd_context *hdd_ctx) {}
Yue Macd359b72017-10-03 15:21:00 -07001077#endif /* FEATURE_RUNTIME_PM */
1078
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001079#define INTF_MACADDR_MASK 0x7
1080
1081/**
1082 * hdd_update_macaddr() - update mac address
1083 * @config: hdd configuration
1084 * @hw_macaddr: mac address
1085 *
1086 * Mac address for multiple virtual interface is found as following
1087 * i) The mac address of the first interface is just the actual hw mac address.
1088 * ii) MSM 3 or 4 bits of byte5 of the actual mac address are used to
1089 * define the mac address for the remaining interfaces and locally
1090 * admistered bit is set. INTF_MACADDR_MASK is based on the number of
1091 * supported virtual interfaces, right now this is 0x07 (meaning 8
1092 * interface).
1093 * Byte[3] of second interface will be hw_macaddr[3](bit5..7) + 1,
1094 * for third interface it will be hw_macaddr[3](bit5..7) + 2, etc.
1095 *
1096 * Return: None
1097 */
1098void hdd_update_macaddr(struct hdd_config *config,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301099 struct qdf_mac_addr hw_macaddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001100{
1101 int8_t i;
1102 uint8_t macaddr_b3, tmp_br3;
1103
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301104 qdf_mem_copy(config->intfMacAddr[0].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301105 QDF_MAC_ADDR_SIZE);
1106 for (i = 1; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301107 qdf_mem_copy(config->intfMacAddr[i].bytes, hw_macaddr.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +05301108 QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001109 macaddr_b3 = config->intfMacAddr[i].bytes[3];
1110 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + i) &
1111 INTF_MACADDR_MASK;
1112 macaddr_b3 += tmp_br3;
1113
1114 /* XOR-ing bit-24 of the mac address. This will give enough
1115 * mac address range before collision
1116 */
1117 macaddr_b3 ^= (1 << 7);
1118
1119 /* Set locally administered bit */
1120 config->intfMacAddr[i].bytes[0] |= 0x02;
1121 config->intfMacAddr[i].bytes[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001122 hdd_debug("config->intfMacAddr[%d]: "
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001123 MAC_ADDRESS_STR, i,
1124 MAC_ADDR_ARRAY(config->intfMacAddr[i].bytes));
1125 }
1126}
1127
Kabilan Kannan44a58372017-12-06 18:16:11 -08001128static int hdd_update_tdls_config(struct hdd_context *hdd_ctx)
1129{
1130 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
1131 struct tdls_start_params tdls_cfg;
1132 struct tdls_user_config *config = &tdls_cfg.config;
1133 struct hdd_config *cfg = hdd_ctx->config;
1134 QDF_STATUS status;
1135
1136 config->tdls_tx_states_period = cfg->fTDLSTxStatsPeriod;
1137 config->tdls_tx_pkt_threshold = cfg->fTDLSTxPacketThreshold;
1138 config->tdls_rx_pkt_threshold = cfg->fTDLSRxFrameThreshold;
1139 config->tdls_max_discovery_attempt = cfg->fTDLSMaxDiscoveryAttempt;
1140 config->tdls_idle_timeout = cfg->tdls_idle_timeout;
1141 config->tdls_idle_pkt_threshold = cfg->fTDLSIdlePacketThreshold;
1142 config->tdls_rssi_trigger_threshold = cfg->fTDLSRSSITriggerThreshold;
1143 config->tdls_rssi_teardown_threshold = cfg->fTDLSRSSITeardownThreshold;
1144 config->tdls_rssi_delta = cfg->fTDLSRSSIDelta;
1145 config->tdls_uapsd_mask = cfg->fTDLSUapsdMask;
1146 config->tdls_uapsd_inactivity_time = cfg->fTDLSPuapsdInactivityTimer;
1147 config->tdls_uapsd_pti_window = cfg->fTDLSPuapsdPTIWindow;
1148 config->tdls_uapsd_ptr_timeout = cfg->fTDLSPuapsdPTRTimeout;
1149 config->tdls_pre_off_chan_num = cfg->fTDLSPrefOffChanNum;
1150 config->tdls_pre_off_chan_bw = cfg->fTDLSPrefOffChanBandwidth;
1151 config->tdls_peer_kickout_threshold = cfg->tdls_peer_kickout_threshold;
1152 config->delayed_trig_framint = cfg->DelayedTriggerFrmInt;
1153 config->tdls_feature_flags = ((cfg->fEnableTDLSOffChannel ?
1154 1 << TDLS_FEATURE_OFF_CHANNEL : 0) |
1155 (cfg->fEnableTDLSWmmMode ? 1 << TDLS_FEATURE_WMM : 0) |
1156 (cfg->fEnableTDLSBufferSta ? 1 << TDLS_FEATURE_BUFFER_STA : 0) |
1157 (cfg->fEnableTDLSSleepSta ? 1 << TDLS_FEATURE_SLEEP_STA : 0) |
1158 (cfg->enable_tdls_scan ? 1 << TDLS_FEATURE_SCAN : 0) |
1159 (cfg->fEnableTDLSSupport ? 1 << TDLS_FEATURE_ENABLE : 0) |
1160 (cfg->fEnableTDLSImplicitTrigger ?
1161 1 << TDLS_FEAUTRE_IMPLICIT_TRIGGER : 0) |
1162 (cfg->fTDLSExternalControl ?
1163 1 << TDLS_FEATURE_EXTERNAL_CONTROL : 0));
1164 config->tdls_vdev_nss_2g = CFG_TDLS_NSS(cfg->vdev_type_nss_2g);
1165 config->tdls_vdev_nss_5g = CFG_TDLS_NSS(cfg->vdev_type_nss_5g);
1166
1167 tdls_cfg.tdls_send_mgmt_req = eWNI_SME_TDLS_SEND_MGMT_REQ;
1168 tdls_cfg.tdls_add_sta_req = eWNI_SME_TDLS_ADD_STA_REQ;
1169 tdls_cfg.tdls_del_sta_req = eWNI_SME_TDLS_DEL_STA_REQ;
1170 tdls_cfg.tdls_update_peer_state = WMA_UPDATE_TDLS_PEER_STATE;
1171 tdls_cfg.tdls_del_all_peers = eWNI_SME_DEL_ALL_TDLS_PEERS;
1172 tdls_cfg.tdls_update_dp_vdev_flags = CDP_UPDATE_TDLS_FLAGS;
1173 tdls_cfg.tdls_event_cb = wlan_cfg80211_tdls_event_callback;
1174 tdls_cfg.tdls_evt_cb_data = psoc;
Jeff Johnson1d40f5b2018-03-02 08:35:53 -08001175 tdls_cfg.tdls_peer_context = hdd_ctx;
1176 tdls_cfg.tdls_reg_peer = hdd_tdls_register_peer;
1177 tdls_cfg.tdls_dereg_peer = hdd_tdls_deregister_peer;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001178 tdls_cfg.tdls_wmm_cb = hdd_wmm_is_acm_allowed;
1179 tdls_cfg.tdls_wmm_cb_data = psoc;
1180 tdls_cfg.tdls_rx_cb = wlan_cfg80211_tdls_rx_callback;
1181 tdls_cfg.tdls_rx_cb_data = psoc;
1182 tdls_cfg.tdls_dp_vdev_update = hdd_update_dp_vdev_flags;
1183
1184 status = ucfg_tdls_update_config(psoc, &tdls_cfg);
1185 if (status != QDF_STATUS_SUCCESS) {
1186 hdd_err("failed pmo psoc configuration");
1187 return -EINVAL;
1188 }
1189
1190 hdd_ctx->tdls_umac_comp_active = true;
1191 /* enable napier specific tdls data path */
1192 hdd_ctx->tdls_nap_active = true;
1193
1194 return 0;
1195}
1196
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001197static void hdd_update_tgt_services(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001198 struct wma_tgt_services *cfg)
1199{
1200 struct hdd_config *config = hdd_ctx->config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001201
1202 /* Set up UAPSD */
1203 config->apUapsdEnabled &= cfg->uapsd;
1204
Krishna Kumaar Natarajan4f1d7722017-03-03 21:12:51 -08001205 /* 11AX mode support */
1206 if ((config->dot11Mode == eHDD_DOT11_MODE_11ax ||
1207 config->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY) && !cfg->en_11ax)
1208 config->dot11Mode = eHDD_DOT11_MODE_11ac;
1209
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001210 /* 11AC mode support */
1211 if ((config->dot11Mode == eHDD_DOT11_MODE_11ac ||
1212 config->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY) && !cfg->en_11ac)
1213 config->dot11Mode = eHDD_DOT11_MODE_AUTO;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001214
1215 /* ARP offload: override user setting if invalid */
1216 config->fhostArpOffload &= cfg->arp_offload;
1217
1218#ifdef FEATURE_WLAN_SCAN_PNO
1219 /* PNO offload */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001220 hdd_debug("PNO Capability in f/w = %d", cfg->pno_offload);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001221 if (cfg->pno_offload)
1222 config->PnoOffload = true;
1223#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001224#ifdef FEATURE_WLAN_TDLS
1225 config->fEnableTDLSSupport &= cfg->en_tdls;
Manjeet Singhfdd2ac72016-09-02 18:11:43 +05301226 config->fEnableTDLSOffChannel = config->fEnableTDLSOffChannel &&
1227 cfg->en_tdls_offchan;
1228 config->fEnableTDLSBufferSta = config->fEnableTDLSBufferSta &&
1229 cfg->en_tdls_uapsd_buf_sta;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001230 if (config->fTDLSUapsdMask && cfg->en_tdls_uapsd_sleep_sta)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001231 config->fEnableTDLSSleepSta = true;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07001232 else
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001233 config->fEnableTDLSSleepSta = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001234#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001235#ifdef WLAN_FEATURE_ROAM_OFFLOAD
1236 config->isRoamOffloadEnabled &= cfg->en_roam_offload;
1237#endif
Will Huang496b36c2017-07-11 16:38:50 +08001238 config->sap_get_peer_info &= cfg->get_peer_info_enabled;
Varun Reddy Yeturu62c32652017-10-26 15:32:35 -07001239 config->MAWCEnabled &= cfg->is_fw_mawc_capable;
Kabilan Kannan44a58372017-12-06 18:16:11 -08001240 hdd_update_tdls_config(hdd_ctx);
Krishna Kumaar Natarajan052c6e62015-09-28 15:32:55 -07001241 sme_update_tgt_services(hdd_ctx->hHal, cfg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001242
1243}
1244
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001245/**
1246 * hdd_update_vdev_nss() - sets the vdev nss
1247 * @hdd_ctx: HDD context
1248 *
1249 * Sets the Nss per vdev type based on INI
1250 *
1251 * Return: None
1252 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001253static void hdd_update_vdev_nss(struct hdd_context *hdd_ctx)
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001254{
1255 struct hdd_config *cfg_ini = hdd_ctx->config;
1256 uint8_t max_supp_nss = 1;
1257
Naveen Rawat10b1c152017-01-18 11:16:06 -08001258 if (cfg_ini->enable2x2 && !cds_is_sub_20_mhz_enabled())
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001259 max_supp_nss = 2;
Liangwei Dong22810e82018-03-15 03:42:12 -04001260 hdd_debug("max nss %d vdev_type_nss_2g %x vdev_type_nss_5g %x",
1261 max_supp_nss, cfg_ini->vdev_type_nss_2g,
1262 cfg_ini->vdev_type_nss_5g);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001263
1264 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001265 cfg_ini->vdev_type_nss_2g, BAND_2G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001266
1267 sme_update_vdev_type_nss(hdd_ctx->hHal, max_supp_nss,
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001268 cfg_ini->vdev_type_nss_5g, BAND_5G);
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001269}
1270
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301271/**
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301272 * hdd_update_wiphy_vhtcap() - Updates wiphy vhtcap fields
1273 * @hdd_ctx: HDD context
1274 *
1275 * Updates wiphy vhtcap fields
1276 *
1277 * Return: None
1278 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001279static void hdd_update_wiphy_vhtcap(struct hdd_context *hdd_ctx)
Nachiket Kukade33c34e32017-07-07 18:45:04 +05301280{
1281 struct ieee80211_supported_band *band_5g =
1282 hdd_ctx->wiphy->bands[NL80211_BAND_5GHZ];
1283 uint32_t val;
1284
1285 if (!band_5g) {
1286 hdd_debug("5GHz band disabled, skipping capability population");
1287 return;
1288 }
1289
1290 val = hdd_ctx->config->txBFCsnValue;
1291 band_5g->vht_cap.cap |= (val << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
1292
1293 val = NUM_OF_SOUNDING_DIMENSIONS;
1294 band_5g->vht_cap.cap |=
1295 (val << IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT);
1296
1297 hdd_info("Updated wiphy vhtcap:0x%x, CSNAntSupp:%d, NumSoundDim:%d",
1298 band_5g->vht_cap.cap, hdd_ctx->config->txBFCsnValue, val);
1299}
1300
1301/**
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301302 * hdd_update_hw_dbs_capable() - sets the dbs capability of the device
1303 * @hdd_ctx: HDD context
1304 *
1305 * Sets the DBS capability as per INI and firmware capability
1306 *
1307 * Return: None
1308 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001309static void hdd_update_hw_dbs_capable(struct hdd_context *hdd_ctx)
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301310{
1311 struct hdd_config *cfg_ini = hdd_ctx->config;
1312 uint8_t hw_dbs_capable = 0;
1313
Tushnim Bhattacharyya49ed8ab2017-05-26 18:20:10 -07001314 if (policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc) &&
1315 ((cfg_ini->dual_mac_feature_disable ==
1316 ENABLE_DBS_CXN_AND_SCAN) ||
1317 (cfg_ini->dual_mac_feature_disable ==
1318 ENABLE_DBS_CXN_AND_ENABLE_SCAN_WITH_ASYNC_SCAN_OFF)))
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301319 hw_dbs_capable = 1;
1320
1321 sme_update_hw_dbs_capable(hdd_ctx->hHal, hw_dbs_capable);
1322}
1323
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001324static void hdd_update_tgt_ht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001325 struct wma_tgt_ht_cap *cfg)
1326{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301327 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001328 uint32_t value, val32;
1329 uint16_t val16;
1330 struct hdd_config *pconfig = hdd_ctx->config;
1331 tSirMacHTCapabilityInfo *phtCapInfo;
1332 uint8_t mcs_set[SIZE_OF_SUPPORTED_MCS_SET];
1333 uint8_t enable_tx_stbc;
1334
1335 /* check and update RX STBC */
1336 if (pconfig->enableRxSTBC && !cfg->ht_rx_stbc)
1337 pconfig->enableRxSTBC = cfg->ht_rx_stbc;
1338
1339 /* get the MPDU density */
1340 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY, &value);
1341
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301342 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001343 hdd_err("could not get MPDU DENSITY");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001344 value = 0;
1345 }
1346
1347 /*
1348 * MPDU density:
1349 * override user's setting if value is larger
1350 * than the one supported by target
1351 */
1352 if (value > cfg->mpdu_density) {
1353 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_MPDU_DENSITY,
1354 cfg->mpdu_density);
1355
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301356 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001357 hdd_err("could not set MPDU DENSITY to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001358 }
1359
1360 /* get the HT capability info */
1361 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, &val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301362 if (QDF_STATUS_SUCCESS != status) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001363 hdd_err("could not get HT capability info");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001364 return;
1365 }
1366 val16 = (uint16_t) val32;
1367 phtCapInfo = (tSirMacHTCapabilityInfo *) &val16;
1368
1369 /* Set the LDPC capability */
1370 phtCapInfo->advCodingCap = cfg->ht_rx_ldpc;
1371
1372 if (pconfig->ShortGI20MhzEnable && !cfg->ht_sgi_20)
1373 pconfig->ShortGI20MhzEnable = cfg->ht_sgi_20;
1374
1375 if (pconfig->ShortGI40MhzEnable && !cfg->ht_sgi_40)
1376 pconfig->ShortGI40MhzEnable = cfg->ht_sgi_40;
1377
1378 hdd_ctx->num_rf_chains = cfg->num_rf_chains;
1379 hdd_ctx->ht_tx_stbc_supported = cfg->ht_tx_stbc;
1380
1381 enable_tx_stbc = pconfig->enableTxSTBC;
1382
1383 if (pconfig->enable2x2 && (cfg->num_rf_chains == 2)) {
1384 pconfig->enable2x2 = 1;
1385 } else {
1386 pconfig->enable2x2 = 0;
1387 enable_tx_stbc = 0;
1388
1389 /* 1x1 */
1390 /* Update Rx Highest Long GI data Rate */
1391 if (sme_cfg_set_int(hdd_ctx->hHal,
1392 WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001393 VHT_RX_HIGHEST_SUPPORTED_DATA_RATE_1_1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301394 == QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001395 hdd_err("Could not pass on WNI_CFG_VHT_RX_HIGHEST_SUPPORTED_DATA_RATE to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001396 }
1397
1398 /* Update Tx Highest Long GI data Rate */
1399 if (sme_cfg_set_int
1400 (hdd_ctx->hHal,
1401 WNI_CFG_VHT_TX_HIGHEST_SUPPORTED_DATA_RATE,
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001402 VHT_TX_HIGHEST_SUPPORTED_DATA_RATE_1_1) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301403 QDF_STATUS_E_FAILURE) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001404 hdd_err("VHT_TX_HIGHEST_SUPP_RATE_1_1 to CCM fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001405 }
1406 }
1407 if (!(cfg->ht_tx_stbc && pconfig->enable2x2))
1408 enable_tx_stbc = 0;
1409 phtCapInfo->txSTBC = enable_tx_stbc;
1410
1411 val32 = val16;
1412 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_HT_CAP_INFO, val32);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301413 if (status != QDF_STATUS_SUCCESS)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001414 hdd_err("could not set HT capability to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001415#define WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES 0xff
1416 value = SIZE_OF_SUPPORTED_MCS_SET;
1417 if (sme_cfg_get_str(hdd_ctx->hHal, WNI_CFG_SUPPORTED_MCS_SET, mcs_set,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301418 &value) == QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001419 hdd_debug("Read MCS rate set");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001420
1421 if (pconfig->enable2x2) {
1422 for (value = 0; value < cfg->num_rf_chains; value++)
1423 mcs_set[value] =
1424 WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES;
1425
1426 status =
1427 sme_cfg_set_str(hdd_ctx->hHal,
1428 WNI_CFG_SUPPORTED_MCS_SET,
1429 mcs_set,
1430 SIZE_OF_SUPPORTED_MCS_SET);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301431 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001432 hdd_err("could not set MCS SET to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001433 }
1434 }
1435#undef WLAN_HDD_RX_MCS_ALL_NSTREAM_RATES
1436}
1437
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001438static void hdd_update_tgt_vht_cap(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001439 struct wma_tgt_vht_cap *cfg)
1440{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301441 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001442 uint32_t value = 0;
1443 struct hdd_config *pconfig = hdd_ctx->config;
1444 struct wiphy *wiphy = hdd_ctx->wiphy;
1445 struct ieee80211_supported_band *band_5g =
Srinivas Girigowda11c28e02017-06-27 20:06:21 -07001446 wiphy->bands[HDD_NL80211_BAND_5GHZ];
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001447 uint32_t temp = 0;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001448 uint32_t ch_width = eHT_CHANNEL_WIDTH_80MHZ;
jiad4a7a33c2017-08-08 15:32:24 +08001449 uint32_t hw_rx_ldpc_enabled;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001450 struct wma_caps_per_phy caps_per_phy;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001451
Dustin Brown5e06bd32016-10-04 12:49:10 -07001452 if (!band_5g) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001453 hdd_debug("5GHz band disabled, skipping capability population");
Dustin Brown5e06bd32016-10-04 12:49:10 -07001454 return;
1455 }
1456
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001457 /* Get the current MPDU length */
1458 status =
1459 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MAX_MPDU_LENGTH,
1460 &value);
1461
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301462 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001463 hdd_err("could not get MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001464 value = 0;
1465 }
1466
1467 /*
1468 * VHT max MPDU length:
1469 * override if user configured value is too high
1470 * that the target cannot support
1471 */
1472 if (value > cfg->vht_max_mpdu) {
1473 status = sme_cfg_set_int(hdd_ctx->hHal,
1474 WNI_CFG_VHT_MAX_MPDU_LENGTH,
1475 cfg->vht_max_mpdu);
1476
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001477 if (status == QDF_STATUS_E_FAILURE)
1478 hdd_err("could not set VHT MAX MPDU LENGTH");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001479 }
1480
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001481 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, &temp);
1482 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1483
1484 if (pconfig->enable2x2)
1485 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1486
1487 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_BASIC_MCS_SET, temp) ==
1488 QDF_STATUS_E_FAILURE) {
1489 hdd_err("Could not pass VHT_BASIC_MCS_SET to CCM");
1490 }
1491
1492 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, &temp);
1493 temp = (temp & VHT_MCS_1x1) | pconfig->vhtRxMCS;
1494 if (pconfig->enable2x2)
1495 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtRxMCS2x2 << 2);
1496
1497 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RX_MCS_MAP, temp) ==
1498 QDF_STATUS_E_FAILURE) {
1499 hdd_err("Could not pass WNI_CFG_VHT_RX_MCS_MAP to CCM");
1500 }
1501
1502 sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, &temp);
1503 temp = (temp & VHT_MCS_1x1) | pconfig->vhtTxMCS;
1504 if (pconfig->enable2x2)
1505 temp = (temp & VHT_MCS_2x2) | (pconfig->vhtTxMCS2x2 << 2);
1506
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001507 hdd_debug("vhtRxMCS2x2 - %x temp - %u enable2x2 %d",
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001508 pconfig->vhtRxMCS2x2, temp, pconfig->enable2x2);
1509
1510 if (sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TX_MCS_MAP, temp) ==
1511 QDF_STATUS_E_FAILURE) {
1512 hdd_err("Could not pass WNI_CFG_VHT_TX_MCS_MAP to CCM");
1513 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001514 /* Get the current RX LDPC setting */
Kiran Kumar Lokere666bf852016-05-02 12:23:02 -07001515 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_LDPC_CODING_CAP,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001516 &value);
1517
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301518 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001519 hdd_err("could not get VHT LDPC CODING CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001520 value = 0;
1521 }
1522
jiad4a7a33c2017-08-08 15:32:24 +08001523 /* Set HW RX LDPC capability */
1524 hw_rx_ldpc_enabled = !!cfg->vht_rx_ldpc;
1525 if (hw_rx_ldpc_enabled != value) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001526 status = sme_cfg_set_int(hdd_ctx->hHal,
1527 WNI_CFG_VHT_LDPC_CODING_CAP,
jiad4a7a33c2017-08-08 15:32:24 +08001528 hw_rx_ldpc_enabled);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001529
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001530 if (status == QDF_STATUS_E_FAILURE)
1531 hdd_err("could not set VHT LDPC CODING CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001532 }
1533
1534 /* Get current GI 80 value */
1535 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SHORT_GI_80MHZ,
1536 &value);
1537
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301538 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001539 hdd_err("could not get SHORT GI 80MHZ");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001540 value = 0;
1541 }
1542
1543 /* set the Guard interval 80MHz */
1544 if (value && !cfg->vht_short_gi_80) {
1545 status = sme_cfg_set_int(hdd_ctx->hHal,
1546 WNI_CFG_VHT_SHORT_GI_80MHZ,
1547 cfg->vht_short_gi_80);
1548
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001549 if (status == QDF_STATUS_E_FAILURE)
1550 hdd_err("could not set SHORT GI 80MHZ to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001551 }
1552
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001553 /* Get VHT TX STBC cap */
1554 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC, &value);
1555
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301556 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001557 hdd_err("could not get VHT TX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001558 value = 0;
1559 }
1560
1561 /* VHT TX STBC cap */
1562 if (value && !cfg->vht_tx_stbc) {
1563 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXSTBC,
1564 cfg->vht_tx_stbc);
1565
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001566 if (status == QDF_STATUS_E_FAILURE)
1567 hdd_err("could not set the VHT TX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001568 }
1569
1570 /* Get VHT RX STBC cap */
1571 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC, &value);
1572
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301573 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001574 hdd_err("could not get VHT RX STBC");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001575 value = 0;
1576 }
1577
1578 /* VHT RX STBC cap */
1579 if (value && !cfg->vht_rx_stbc) {
1580 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_RXSTBC,
1581 cfg->vht_rx_stbc);
1582
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001583 if (status == QDF_STATUS_E_FAILURE)
1584 hdd_err("could not set the VHT RX STBC to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001585 }
1586
1587 /* Get VHT SU Beamformer cap */
1588 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1589 &value);
1590
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301591 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001592 hdd_err("could not get VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001593 value = 0;
1594 }
1595
1596 /* set VHT SU Beamformer cap */
1597 if (value && !cfg->vht_su_bformer) {
1598 status = sme_cfg_set_int(hdd_ctx->hHal,
1599 WNI_CFG_VHT_SU_BEAMFORMER_CAP,
1600 cfg->vht_su_bformer);
1601
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001602 if (status == QDF_STATUS_E_FAILURE)
1603 hdd_err("could not set VHT SU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001604 }
1605
1606 /* check and update SU BEAMFORMEE capabality */
1607 if (pconfig->enableTxBF && !cfg->vht_su_bformee)
1608 pconfig->enableTxBF = cfg->vht_su_bformee;
1609
1610 status = sme_cfg_set_int(hdd_ctx->hHal,
1611 WNI_CFG_VHT_SU_BEAMFORMEE_CAP,
1612 pconfig->enableTxBF);
1613
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001614 if (status == QDF_STATUS_E_FAILURE)
1615 hdd_err("could not set VHT SU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001616
1617 /* Get VHT MU Beamformer cap */
1618 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1619 &value);
1620
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301621 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001622 hdd_err("could not get VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001623 value = 0;
1624 }
1625
1626 /* set VHT MU Beamformer cap */
1627 if (value && !cfg->vht_mu_bformer) {
1628 status = sme_cfg_set_int(hdd_ctx->hHal,
1629 WNI_CFG_VHT_MU_BEAMFORMER_CAP,
1630 cfg->vht_mu_bformer);
1631
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001632 if (status == QDF_STATUS_E_FAILURE)
1633 hdd_err("could not set the VHT MU BEAMFORMER CAP to CCM");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001634 }
1635
1636 /* Get VHT MU Beamformee cap */
1637 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1638 &value);
1639
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301640 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001641 hdd_err("could not get VHT MU BEAMFORMEE CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001642 value = 0;
1643 }
1644
1645 /* set VHT MU Beamformee cap */
1646 if (value && !cfg->vht_mu_bformee) {
1647 status = sme_cfg_set_int(hdd_ctx->hHal,
1648 WNI_CFG_VHT_MU_BEAMFORMEE_CAP,
1649 cfg->vht_mu_bformee);
1650
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001651 if (status == QDF_STATUS_E_FAILURE)
1652 hdd_err("could not set VHT MU BEAMFORMER CAP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001653 }
1654
1655 /* Get VHT MAX AMPDU Len exp */
1656 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1657 &value);
1658
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301659 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001660 hdd_err("could not get VHT AMPDU LEN");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001661 value = 0;
1662 }
1663
1664 /*
1665 * VHT max AMPDU len exp:
1666 * override if user configured value is too high
1667 * that the target cannot support.
1668 * Even though Rome publish ampdu_len=7, it can
1669 * only support 4 because of some h/w bug.
1670 */
1671
1672 if (value > cfg->vht_max_ampdu_len_exp) {
1673 status = sme_cfg_set_int(hdd_ctx->hHal,
1674 WNI_CFG_VHT_AMPDU_LEN_EXPONENT,
1675 cfg->vht_max_ampdu_len_exp);
1676
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001677 if (status == QDF_STATUS_E_FAILURE)
1678 hdd_err("could not set the VHT AMPDU LEN EXP");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001679 }
1680
1681 /* Get VHT TXOP PS CAP */
1682 status = sme_cfg_get_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS, &value);
1683
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301684 if (status != QDF_STATUS_SUCCESS) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001685 hdd_err("could not get VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001686 value = 0;
1687 }
1688
1689 /* set VHT TXOP PS cap */
1690 if (value && !cfg->vht_txop_ps) {
1691 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_VHT_TXOP_PS,
1692 cfg->vht_txop_ps);
1693
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001694 if (status == QDF_STATUS_E_FAILURE)
1695 hdd_err("could not set the VHT TXOP PS");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001696 }
1697
1698 if (WMI_VHT_CAP_MAX_MPDU_LEN_11454 == cfg->vht_max_mpdu)
1699 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
1700 else if (WMI_VHT_CAP_MAX_MPDU_LEN_7935 == cfg->vht_max_mpdu)
1701 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
1702 else
1703 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
1704
1705
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001706 if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_80P80MHZ)) {
1707 status = sme_cfg_set_int(hdd_ctx->hHal,
1708 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1709 VHT_CAP_160_AND_80P80_SUPP);
1710 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001711 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001712 band_5g->vht_cap.cap |=
1713 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001714 ch_width = eHT_CHANNEL_WIDTH_80P80MHZ;
1715 } else if (cfg->supp_chan_width & (1 << eHT_CHANNEL_WIDTH_160MHZ)) {
1716 status = sme_cfg_set_int(hdd_ctx->hHal,
1717 WNI_CFG_VHT_SUPPORTED_CHAN_WIDTH_SET,
1718 VHT_CAP_160_SUPP);
1719 if (status == QDF_STATUS_E_FAILURE)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001720 hdd_err("could not set the VHT CAP 160");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001721 band_5g->vht_cap.cap |=
1722 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001723 ch_width = eHT_CHANNEL_WIDTH_160MHZ;
1724 }
1725 pconfig->vhtChannelWidth = QDF_MIN(pconfig->vhtChannelWidth,
1726 ch_width);
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301727 /* Get the current GI 160 value */
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001728 status = sme_cfg_get_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301729 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001730 &value);
1731 if (status != QDF_STATUS_SUCCESS) {
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301732 hdd_err("could not get GI 80 & 160");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001733 value = 0;
1734 }
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301735 /* set the Guard interval 160MHz */
1736 if (value && !cfg->vht_short_gi_160) {
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001737 status = sme_cfg_set_int(hdd_ctx->hHal,
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301738 WNI_CFG_VHT_SHORT_GI_160_AND_80_PLUS_80MHZ,
1739 cfg->vht_short_gi_160);
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001740
1741 if (status == QDF_STATUS_E_FAILURE)
Ashish Kumar Dhanotiya7ebf5692017-04-12 20:04:47 +05301742 hdd_err("failed to set SHORT GI 160MHZ");
Kiran Kumar Lokere4bbbd0d2017-02-07 00:06:43 -08001743 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001744
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001745 if (cfg->vht_rx_ldpc & WMI_VHT_CAP_RX_LDPC) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001746 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
Sandeep Puligilla305d5092018-04-16 14:40:50 -07001747 hdd_debug("VHT RxLDPC capability is set");
1748 } else {
1749 /*
1750 * Get the RX LDPC capability for the NON DBS
1751 * hardware mode for 5G band
1752 */
1753 status = wma_get_caps_for_phyidx_hwmode(&caps_per_phy,
1754 HW_MODE_DBS_NONE, CDS_BAND_5GHZ);
1755 if ((QDF_IS_STATUS_SUCCESS(status)) &&
1756 (caps_per_phy.vht_5g & WMI_VHT_CAP_RX_LDPC)) {
1757 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXLDPC;
1758 hdd_debug("VHT RX LDPC capability is set");
1759 }
1760 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001761
1762 if (cfg->vht_short_gi_80 & WMI_VHT_CAP_SGI_80MHZ)
1763 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
1764 if (cfg->vht_short_gi_160 & WMI_VHT_CAP_SGI_160MHZ)
1765 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
1766
1767 if (cfg->vht_tx_stbc & WMI_VHT_CAP_TX_STBC)
1768 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_TXSTBC;
1769
1770 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_1SS)
1771 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_1;
1772 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_2SS)
1773 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_2;
1774 if (cfg->vht_rx_stbc & WMI_VHT_CAP_RX_STBC_3SS)
1775 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_RXSTBC_3;
1776
1777 band_5g->vht_cap.cap |=
1778 (cfg->vht_max_ampdu_len_exp <<
1779 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1780
1781 if (cfg->vht_su_bformer & WMI_VHT_CAP_SU_BFORMER)
1782 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
1783 if (cfg->vht_su_bformee & WMI_VHT_CAP_SU_BFORMEE)
1784 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1785 if (cfg->vht_mu_bformer & WMI_VHT_CAP_MU_BFORMER)
1786 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE;
1787 if (cfg->vht_mu_bformee & WMI_VHT_CAP_MU_BFORMEE)
1788 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1789
1790 if (cfg->vht_txop_ps & WMI_VHT_CAP_TXOP_PS)
1791 band_5g->vht_cap.cap |= IEEE80211_VHT_CAP_VHT_TXOP_PS;
1792
1793}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001794
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001795/**
1796 * hdd_generate_macaddr_auto() - Auto-generate mac address
1797 * @hdd_ctx: Pointer to the HDD context
1798 *
1799 * Auto-generate mac address using device serial number.
1800 * Keep the first 3 bytes of OUI as before and replace
1801 * the last 3 bytes with the lower 3 bytes of serial number.
1802 *
1803 * Return: 0 for success
1804 * Non zero failure code for errors
1805 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001806static int hdd_generate_macaddr_auto(struct hdd_context *hdd_ctx)
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001807{
1808 unsigned int serialno = 0;
1809 struct qdf_mac_addr mac_addr = {
1810 {0x00, 0x0A, 0xF5, 0x00, 0x00, 0x00}
1811 };
1812
Yuanyuan Liuf97e8222016-09-21 10:31:38 -07001813 serialno = pld_socinfo_get_serial_number(hdd_ctx->parent_dev);
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001814 if (serialno == 0)
1815 return -EINVAL;
1816
1817 serialno &= 0x00ffffff;
1818
1819 mac_addr.bytes[3] = (serialno >> 16) & 0xff;
1820 mac_addr.bytes[4] = (serialno >> 8) & 0xff;
1821 mac_addr.bytes[5] = serialno & 0xff;
1822
1823 hdd_update_macaddr(hdd_ctx->config, mac_addr);
1824 return 0;
1825}
1826
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301827/**
1828 * hdd_update_ra_rate_limit() - Update RA rate limit from target
1829 * configuration to cfg_ini in HDD
1830 * @hdd_ctx: Pointer to hdd_ctx
1831 * @cfg: target configuration
1832 *
1833 * Return: None
1834 */
1835#ifdef FEATURE_WLAN_RA_FILTERING
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001836static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301837 struct wma_tgt_cfg *cfg)
1838{
1839 hdd_ctx->config->IsRArateLimitEnabled = cfg->is_ra_rate_limit_enabled;
1840}
1841#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001842static void hdd_update_ra_rate_limit(struct hdd_context *hdd_ctx,
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301843 struct wma_tgt_cfg *cfg)
1844{
1845}
1846#endif
1847
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001848void hdd_update_tgt_cfg(void *context, void *param)
1849{
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -08001850 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07001851 struct hdd_context *hdd_ctx = (struct hdd_context *) context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001852 struct wma_tgt_cfg *cfg = param;
1853 uint8_t temp_band_cap;
Naveen Rawat64e477e2016-05-20 10:34:56 -07001854 struct cds_config_info *cds_cfg = cds_get_ini_config();
Nitesh Shahe50711f2017-04-26 16:30:45 +05301855 uint8_t antenna_mode;
Arif Hussainee10f902017-12-27 16:30:17 -08001856 QDF_STATUS status;
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301857
Dustin Brownbd68fe12017-11-21 15:28:52 -08001858 ret = hdd_objmgr_create_and_store_pdev(hdd_ctx);
1859 if (ret) {
1860 hdd_err("Failed to create pdev; errno:%d", ret);
1861 QDF_BUG(0);
Sandeep Puligilla1cf6ebe2017-04-04 14:40:27 -07001862 } else {
Dustin Brownbd68fe12017-11-21 15:28:52 -08001863 hdd_debug("New pdev has been created with pdev_id = %u",
Arif Hussainee10f902017-12-27 16:30:17 -08001864 hdd_ctx->hdd_pdev->pdev_objmgr.wlan_pdev_id);
Amar Singhal410675c2018-01-10 12:14:21 -08001865 if (dispatcher_pdev_open(hdd_ctx->hdd_pdev)) {
1866 hdd_err("dispatcher pdev open failed");
1867 QDF_BUG(0);
1868 }
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05301869 }
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07001870
Jeff Johnsone8846ab2018-03-31 11:54:45 -07001871 ret = hdd_green_ap_update_config(hdd_ctx);
Himanshu Agarwalb229a142017-12-21 10:16:45 +05301872
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301873 ucfg_ipa_set_dp_handle(hdd_ctx->hdd_psoc,
1874 cds_get_context(QDF_MODULE_ID_SOC));
1875 ucfg_ipa_set_txrx_handle(hdd_ctx->hdd_psoc,
1876 cds_get_context(QDF_MODULE_ID_TXRX));
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05301877 ucfg_ipa_reg_sap_xmit_cb(hdd_ctx->hdd_pdev,
1878 hdd_softap_hard_start_xmit);
1879 ucfg_ipa_reg_send_to_nw_cb(hdd_ctx->hdd_pdev,
1880 hdd_ipa_send_skb_to_network);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301881
Naveen Rawat64e477e2016-05-20 10:34:56 -07001882 if (cds_cfg) {
1883 if (hdd_ctx->config->enable_sub_20_channel_width !=
1884 WLAN_SUB_20_CH_WIDTH_NONE && !cfg->sub_20_support) {
1885 hdd_err("User requested sub 20 MHz channel width but unsupported by FW.");
1886 cds_cfg->sub_20_channel_width =
1887 WLAN_SUB_20_CH_WIDTH_NONE;
1888 } else {
1889 cds_cfg->sub_20_channel_width =
1890 hdd_ctx->config->enable_sub_20_channel_width;
1891 }
1892 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001893
1894 /* first store the INI band capability */
1895 temp_band_cap = hdd_ctx->config->nBandCapability;
1896
1897 hdd_ctx->config->nBandCapability = cfg->band_cap;
Vignesh Viswanathan731186f2017-09-18 13:47:37 +05301898 hdd_ctx->is_fils_roaming_supported =
1899 cfg->services.is_fils_roaming_supported;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001900
Vignesh Viswanathan694e28e2018-01-18 20:53:57 +05301901 hdd_ctx->config->is_11k_offload_supported =
1902 cfg->services.is_11k_offload_supported;
1903
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08001904 /*
1905 * now overwrite the target band capability with INI
1906 * setting if INI setting is a subset
1907 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001908
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001909 if ((hdd_ctx->config->nBandCapability == BAND_ALL) &&
1910 (temp_band_cap != BAND_ALL))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001911 hdd_ctx->config->nBandCapability = temp_band_cap;
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08001912 else if ((hdd_ctx->config->nBandCapability != BAND_ALL) &&
1913 (temp_band_cap != BAND_ALL) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001914 (hdd_ctx->config->nBandCapability != temp_band_cap)) {
Jeff Johnsonb8969cb2016-08-15 12:38:19 -07001915 hdd_warn("ini BandCapability not supported by the target");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001916 }
1917
Amar Singhal58b45ef2017-08-01 13:43:54 -07001918 hdd_ctx->curr_band = hdd_ctx->config->nBandCapability;
1919
Hanumanth Reddy Pothula2a8a7402017-07-03 14:06:11 +05301920 if (!cds_is_driver_recovering() || cds_is_driver_in_bad_state()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001921 hdd_ctx->reg.reg_domain = cfg->reg_domain;
1922 hdd_ctx->reg.eeprom_rd_ext = cfg->eeprom_rd_ext;
1923 }
1924
1925 /* This can be extended to other configurations like ht, vht cap... */
1926
Anurag Chouhanc5548422016-02-24 18:33:27 +05301927 if (!qdf_is_macaddr_zero(&cfg->hw_macaddr)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001928 hdd_update_macaddr(hdd_ctx->config, cfg->hw_macaddr);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001929 hdd_ctx->update_mac_addr_to_fw = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001930 } else {
Yuanyuan Liu5bdfad72016-07-21 10:33:04 -07001931 static struct qdf_mac_addr default_mac_addr = {
1932 {0x00, 0x0A, 0xF5, 0x89, 0x89, 0xFF}
1933 };
1934 if (qdf_is_macaddr_equal(&hdd_ctx->config->intfMacAddr[0],
1935 &default_mac_addr)) {
1936 if (hdd_generate_macaddr_auto(hdd_ctx) != 0)
1937 hdd_err("Fail to auto-generate MAC, using MAC from ini file "
1938 MAC_ADDRESS_STR,
1939 MAC_ADDR_ARRAY(hdd_ctx->config->
1940 intfMacAddr[0].bytes));
1941 } else {
1942 hdd_err("Invalid MAC passed from target, using MAC from ini file "
1943 MAC_ADDRESS_STR,
1944 MAC_ADDR_ARRAY(hdd_ctx->config->
1945 intfMacAddr[0].bytes));
1946 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07001947 hdd_ctx->update_mac_addr_to_fw = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001948 }
1949
1950 hdd_ctx->target_fw_version = cfg->target_fw_version;
Sandeep Puligilla3d6a8e22016-10-11 18:57:14 -07001951 hdd_ctx->target_fw_vers_ext = cfg->target_fw_vers_ext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001952
1953 hdd_ctx->max_intf_count = cfg->max_intf_count;
1954
Jeff Johnsonc875e242016-09-23 18:12:34 -07001955 hdd_lpass_target_config(hdd_ctx, cfg);
Ryan Hsu3c8f79f2015-12-02 16:45:09 -08001956
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001957 hdd_ctx->ap_arpns_support = cfg->ap_arpns_support;
1958 hdd_update_tgt_services(hdd_ctx, &cfg->services);
1959
1960 hdd_update_tgt_ht_cap(hdd_ctx, &cfg->ht_cap);
1961
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001962 hdd_update_tgt_vht_cap(hdd_ctx, &cfg->vht_cap);
Krishna Kumaar Natarajaned1efd92016-09-24 18:05:47 -07001963 if (cfg->services.en_11ax) {
1964 hdd_info("11AX: 11ax is enabled - update HDD config");
1965 hdd_update_tgt_he_cap(hdd_ctx, cfg);
1966 }
Tushnim Bhattacharyyaf44a9d82016-07-05 10:52:06 -07001967
1968 hdd_update_vdev_nss(hdd_ctx);
1969
Nitesh Shahdb5ea0d2017-03-22 15:17:47 +05301970 hdd_update_hw_dbs_capable(hdd_ctx);
1971
Krishna Kumaar Natarajan1ae49112015-11-24 21:43:22 -08001972 hdd_ctx->config->fine_time_meas_cap &= cfg->fine_time_measurement_cap;
Krunal Sonie3531942016-04-12 17:43:53 -07001973 hdd_ctx->fine_time_meas_cap_target = cfg->fine_time_measurement_cap;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001974 hdd_debug("fine_time_meas_cap: 0x%x",
Arif Hussainee10f902017-12-27 16:30:17 -08001975 hdd_ctx->config->fine_time_meas_cap);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001976
Nitesh Shahe50711f2017-04-26 16:30:45 +05301977 antenna_mode = (hdd_ctx->config->enable2x2 == 0x01) ?
1978 HDD_ANTENNA_MODE_2X2 : HDD_ANTENNA_MODE_1X1;
1979 hdd_update_smps_antenna_mode(hdd_ctx, antenna_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08001980 hdd_debug("Init current antenna mode: %d",
Arif Hussainee10f902017-12-27 16:30:17 -08001981 hdd_ctx->current_antenna_mode);
Archana Ramachandran393f3792015-11-13 17:13:21 -08001982
Rajeev Kumardd3bc602016-08-16 14:21:05 -07001983 hdd_ctx->bpf_enabled = (cfg->bpf_enabled &&
1984 hdd_ctx->config->bpf_packet_filter_enable);
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05301985 hdd_ctx->rcpi_enabled = cfg->rcpi_enabled;
Anurag Chouhan04dbf6d2016-09-08 15:32:52 +05301986 hdd_update_ra_rate_limit(hdd_ctx, cfg);
Arun Khandavalli3dd06de2016-08-17 10:20:29 +05301987
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301988 if ((hdd_ctx->config->txBFCsnValue >
Arif Hussainee10f902017-12-27 16:30:17 -08001989 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF) &&
1990 !cfg->tx_bfee_8ss_enabled)
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301991 hdd_ctx->config->txBFCsnValue =
1992 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED_FW_DEF;
1993
Arif Hussainee10f902017-12-27 16:30:17 -08001994 status = sme_cfg_set_int(hdd_ctx->hHal,
1995 WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED,
1996 hdd_ctx->config->txBFCsnValue);
1997 if (QDF_IS_STATUS_ERROR(status))
Nachiket Kukade8b4bfd82017-05-25 18:34:48 +05301998 hdd_err("fw update WNI_CFG_VHT_CSN_BEAMFORMEE_ANT_SUPPORTED to CFG fails");
1999
2000
2001 hdd_debug("Target BPF %d Host BPF %d 8ss fw support %d txBFCsnValue %d",
Arif Hussainee10f902017-12-27 16:30:17 -08002002 cfg->bpf_enabled, hdd_ctx->config->bpf_packet_filter_enable,
2003 cfg->tx_bfee_8ss_enabled, hdd_ctx->config->txBFCsnValue);
Nachiket Kukade33c34e32017-07-07 18:45:04 +05302004
2005 /*
2006 * Update txBFCsnValue and NumSoundingDim values to vhtcap in wiphy
2007 */
2008 hdd_update_wiphy_vhtcap(hdd_ctx);
Manjeet Singh70d3d932016-12-20 20:41:10 +05302009
Rajeev Kumar Sirasanagandla47873002016-09-09 13:46:09 +05302010 hdd_ctx->wmi_max_len = cfg->wmi_max_len;
2011
Yue Macd359b72017-10-03 15:21:00 -07002012 /*
2013 * This needs to be done after HDD pdev is created and stored since
2014 * it will access the HDD pdev object lock.
2015 */
2016 hdd_runtime_suspend_context_init(hdd_ctx);
2017
Deepak Dhamdhere13230d32016-05-26 00:46:53 -07002018 /* Configure NAN datapath features */
2019 hdd_nan_datapath_target_config(hdd_ctx, cfg);
Arif Hussain759a0232017-03-20 13:17:18 -07002020 hdd_ctx->dfs_cac_offload = cfg->dfs_cac_offload;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08002021 hdd_ctx->lte_coex_ant_share = cfg->services.lte_coex_ant_share;
Arif Hussainee10f902017-12-27 16:30:17 -08002022 status = sme_cfg_set_int(hdd_ctx->hHal, WNI_CFG_OBSS_DETECTION_OFFLOAD,
2023 cfg->obss_detection_offloaded);
2024 if (QDF_IS_STATUS_ERROR(status))
2025 hdd_err("Couldn't pass WNI_CFG_OBSS_DETECTION_OFFLOAD to CFG");
Arif Hussain05fb4872018-01-03 16:02:55 -08002026
2027 status = sme_cfg_set_int(hdd_ctx->hHal,
2028 WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD,
2029 cfg->obss_color_collision_offloaded);
2030 if (QDF_IS_STATUS_ERROR(status))
2031 hdd_err("Failed to set WNI_CFG_OBSS_COLOR_COLLISION_OFFLOAD");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002032}
2033
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002034bool hdd_dfs_indicate_radar(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002035{
Jeff Johnson9d295242017-08-29 14:39:48 -07002036 struct hdd_adapter *adapter;
Jeff Johnson87251032017-08-29 13:31:11 -07002037 struct hdd_ap_ctx *ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002038
Jiachao Wuf610d912018-01-23 17:47:32 +08002039 if (!hdd_ctx) {
2040 hdd_info("Couldn't get hdd_ctx");
2041 return true;
2042 }
2043
2044 if (hdd_ctx->config->disableDFSChSwitch) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07002045 hdd_info("skip tx block hdd_ctx=%pK, disableDFSChSwitch=%d",
Arif Hussaincd151632017-02-11 16:57:19 -08002046 hdd_ctx, hdd_ctx->config->disableDFSChSwitch);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302047 return true;
Arif Hussaincd151632017-02-11 16:57:19 -08002048 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002049
Dustin Brown920397d2017-12-13 16:27:50 -08002050 hdd_for_each_adapter(hdd_ctx, adapter) {
Arif Hussaincd151632017-02-11 16:57:19 -08002051 ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
2052
2053 if ((QDF_SAP_MODE == adapter->device_mode ||
2054 QDF_P2P_GO_MODE == adapter->device_mode) &&
2055 (wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnson01206862017-10-27 20:55:59 -07002056 ap_ctx->operating_channel))) {
Arif Hussaincd151632017-02-11 16:57:19 -08002057 WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx =
2058 true;
2059 hdd_info("tx blocked for session: %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07002060 adapter->session_id);
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302061 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002062 }
Edhar, Mahesh Kumar695468e2015-10-19 12:06:20 +05302063
2064 return true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002065}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002066
2067/**
2068 * hdd_is_valid_mac_address() - validate MAC address
2069 * @pMacAddr: Pointer to the input MAC address
2070 *
2071 * This function validates whether the given MAC address is valid or not
2072 * Expected MAC address is of the format XX:XX:XX:XX:XX:XX
2073 * where X is the hexa decimal digit character and separated by ':'
2074 * This algorithm works even if MAC address is not separated by ':'
2075 *
2076 * This code checks given input string mac contains exactly 12 hexadecimal
2077 * digits and a separator colon : appears in the input string only after
2078 * an even number of hex digits.
2079 *
2080 * Return: 1 for valid and 0 for invalid
2081 */
2082bool hdd_is_valid_mac_address(const uint8_t *pMacAddr)
2083{
2084 int xdigit = 0;
2085 int separator = 0;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07002086
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002087 while (*pMacAddr) {
2088 if (isxdigit(*pMacAddr)) {
2089 xdigit++;
2090 } else if (':' == *pMacAddr) {
2091 if (0 == xdigit || ((xdigit / 2) - 1) != separator)
2092 break;
2093
2094 ++separator;
2095 } else {
2096 /* Invalid MAC found */
2097 return 0;
2098 }
2099 ++pMacAddr;
2100 }
2101 return xdigit == 12 && (separator == 5 || separator == 0);
2102}
2103
2104/**
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302105 * hdd_mon_mode_ether_setup() - Update monitor mode struct net_device.
2106 * @dev: Handle to struct net_device to be updated.
2107 *
2108 * Return: None
2109 */
2110static void hdd_mon_mode_ether_setup(struct net_device *dev)
2111{
2112 dev->header_ops = NULL;
2113 dev->type = ARPHRD_IEEE80211_RADIOTAP;
2114 dev->hard_header_len = ETH_HLEN;
2115 dev->mtu = ETH_DATA_LEN;
2116 dev->addr_len = ETH_ALEN;
2117 dev->tx_queue_len = 1000; /* Ethernet wants good queues */
2118 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2119 dev->priv_flags |= IFF_TX_SKB_SHARING;
2120
2121 memset(dev->broadcast, 0xFF, ETH_ALEN);
2122}
2123
2124/**
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002125 * __hdd__mon_open() - HDD Open function
2126 * @dev: Pointer to net_device structure
2127 *
2128 * This is called in response to ifconfig up
2129 *
2130 * Return: 0 for success; non-zero for failure
2131 */
2132static int __hdd_mon_open(struct net_device *dev)
2133{
2134 int ret;
Ravi Joshia307f632017-07-17 23:41:41 -07002135 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
2136 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002137
Dustin Brownfdf17c12018-03-14 12:55:34 -07002138 hdd_enter_dev(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002139
2140 ret = wlan_hdd_validate_context(hdd_ctx);
2141 if (ret)
2142 return ret;
2143
Arun Khandavallif5c0e0c2016-09-07 20:39:21 +05302144 hdd_mon_mode_ether_setup(dev);
Ravi Joshia307f632017-07-17 23:41:41 -07002145
2146 if (con_mode == QDF_GLOBAL_MONITOR_MODE) {
2147 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2148 if (ret) {
2149 hdd_err("Failed to start WLAN modules return");
2150 return ret;
2151 }
2152 hdd_err("hdd_wlan_start_modules() successful !");
2153
2154 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2155 ret = hdd_start_adapter(adapter);
2156 if (ret) {
2157 hdd_err("Failed to start adapter :%d",
2158 adapter->device_mode);
2159 return ret;
2160 }
2161 hdd_err("hdd_start_adapters() successful !");
2162 }
2163 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2164 }
2165
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002166 ret = hdd_set_mon_rx_cb(dev);
Ravi Joshi4f095952017-06-29 15:39:19 -07002167
2168 if (!ret)
2169 ret = hdd_enable_monitor_mode(dev);
2170
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002171 return ret;
2172}
2173
2174/**
2175 * hdd_mon_open() - Wrapper function for __hdd_mon_open to protect it from SSR
2176 * @dev: Pointer to net_device structure
2177 *
2178 * This is called in response to ifconfig up
2179 *
2180 * Return: 0 for success; non-zero for failure
2181 */
Jeff Johnson590e2012016-10-05 16:16:24 -07002182static int hdd_mon_open(struct net_device *dev)
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002183{
2184 int ret;
2185
2186 cds_ssr_protect(__func__);
2187 ret = __hdd_mon_open(dev);
2188 cds_ssr_unprotect(__func__);
2189
2190 return ret;
2191}
2192
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002193static QDF_STATUS
2194wlan_hdd_update_dbs_scan_and_fw_mode_config(void)
2195{
2196 struct policy_mgr_dual_mac_config cfg = {0};
2197 QDF_STATUS status;
2198 uint32_t channel_select_logic_conc;
2199 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2200
2201 if (!hdd_ctx) {
2202 hdd_err("HDD context is NULL");
2203 return QDF_STATUS_E_FAILURE;
2204 }
2205
2206
2207 if (!policy_mgr_is_hw_dbs_capable(hdd_ctx->hdd_psoc))
2208 return QDF_STATUS_SUCCESS;
2209
2210 cfg.scan_config = 0;
2211 cfg.fw_mode_config = 0;
2212 cfg.set_dual_mac_cb = policy_mgr_soc_set_dual_mac_cfg_cb;
2213
2214 channel_select_logic_conc = hdd_ctx->config->
2215 channel_select_logic_conc;
2216
2217 if (hdd_ctx->config->dual_mac_feature_disable !=
2218 DISABLE_DBS_CXN_AND_SCAN) {
2219 status = policy_mgr_get_updated_scan_and_fw_mode_config(
2220 hdd_ctx->hdd_psoc, &cfg.scan_config,
2221 &cfg.fw_mode_config,
2222 hdd_ctx->config->dual_mac_feature_disable,
2223 channel_select_logic_conc);
2224
2225 if (status != QDF_STATUS_SUCCESS) {
2226 hdd_err("wma_get_updated_scan_and_fw_mode_config failed %d",
2227 status);
2228 return status;
2229 }
2230 }
2231
2232 hdd_debug("send scan_cfg: 0x%x fw_mode_cfg: 0x%x to fw",
2233 cfg.scan_config, cfg.fw_mode_config);
2234
2235 status = sme_soc_set_dual_mac_config(cfg);
2236 if (status != QDF_STATUS_SUCCESS) {
2237 hdd_err("sme_soc_set_dual_mac_config failed %d", status);
2238 return status;
2239 }
2240
2241 return QDF_STATUS_SUCCESS;
2242}
2243
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07002244/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302245 * hdd_start_adapter() - Wrapper function for device specific adapter
2246 * @adapter: pointer to HDD adapter
2247 *
2248 * This function is called to start the device specific adapter for
2249 * the mode passed in the adapter's device_mode.
2250 *
2251 * Return: 0 for success; non-zero for failure
2252 */
Jeff Johnson9d295242017-08-29 14:39:48 -07002253int hdd_start_adapter(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05302254{
2255
2256 int ret;
Jeff Johnsonc1e62782017-11-09 09:50:17 -08002257 enum QDF_OPMODE device_mode = adapter->device_mode;
Arun Khandavallifae92942016-08-01 13:31:08 +05302258
Dustin Brownfdf17c12018-03-14 12:55:34 -07002259 hdd_enter_dev(adapter->dev);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002260 hdd_debug("Start_adapter for mode : %d", adapter->device_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +05302261
2262 switch (device_mode) {
2263 case QDF_P2P_CLIENT_MODE:
2264 case QDF_P2P_DEVICE_MODE:
2265 case QDF_OCB_MODE:
2266 case QDF_STA_MODE:
2267 case QDF_MONITOR_MODE:
2268 ret = hdd_start_station_adapter(adapter);
2269 if (ret)
2270 goto err_start_adapter;
2271 break;
2272 case QDF_P2P_GO_MODE:
2273 case QDF_SAP_MODE:
2274 ret = hdd_start_ap_adapter(adapter);
2275 if (ret)
2276 goto err_start_adapter;
2277 break;
Arun Khandavallib2f6c262016-08-18 19:07:19 +05302278 case QDF_IBSS_MODE:
2279 /*
2280 * For IBSS interface is initialized as part of
2281 * hdd_init_station_mode()
2282 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08002283 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302284 case QDF_FTM_MODE:
Dustin Browndb2a8be2017-12-20 11:49:56 -08002285 /* vdevs are dynamically managed by firmware in FTM */
2286 goto exit_with_success;
Arun Khandavallifae92942016-08-01 13:31:08 +05302287 default:
2288 hdd_err("Invalid session type %d", device_mode);
2289 QDF_ASSERT(0);
2290 goto err_start_adapter;
2291 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08002292
Arun Khandavallifae92942016-08-01 13:31:08 +05302293 if (hdd_set_fw_params(adapter))
2294 hdd_err("Failed to set the FW params for the adapter!");
2295
2296 /*
2297 * Action frame registered in one adapter which will
2298 * applicable to all interfaces
2299 */
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302300 ret = wlan_hdd_cfg80211_register_frames(adapter);
2301 if (ret < 0) {
2302 hdd_err("Failed to register frames - ret %d", ret);
2303 goto err_start_adapter;
2304 }
Zhu Jianmin6a7b7022018-03-10 21:42:21 +08002305 wlan_hdd_update_dbs_scan_and_fw_mode_config();
Ganesh Kondabattini0dc1a6e2017-07-29 12:59:19 +05302306
Dustin Browndb2a8be2017-12-20 11:49:56 -08002307exit_with_success:
Dustin Browne74003f2018-03-14 12:51:58 -07002308 hdd_exit();
Dustin Browndb2a8be2017-12-20 11:49:56 -08002309
Arun Khandavallifae92942016-08-01 13:31:08 +05302310 return 0;
Dustin Browndb2a8be2017-12-20 11:49:56 -08002311
Arun Khandavallifae92942016-08-01 13:31:08 +05302312err_start_adapter:
2313 return -EINVAL;
2314}
2315
2316/**
Komal Seelamf2136bb2016-09-28 18:30:44 +05302317 * hdd_enable_power_management() - API to Enable Power Management
2318 *
2319 * API invokes Bus Interface Layer power management functionality
2320 *
2321 * Return: None
2322 */
2323static void hdd_enable_power_management(void)
2324{
2325 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2326
2327 if (!hif_ctx) {
2328 hdd_err("Bus Interface Context is Invalid");
2329 return;
2330 }
2331
2332 hif_enable_power_management(hif_ctx, cds_is_packet_log_enabled());
2333}
2334
2335/**
2336 * hdd_disable_power_management() - API to disable Power Management
2337 *
2338 * API disable Bus Interface Layer Power management functionality
2339 *
2340 * Return: None
2341 */
2342static void hdd_disable_power_management(void)
2343{
2344 void *hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2345
2346 if (!hif_ctx) {
2347 hdd_err("Bus Interface Context is Invalid");
2348 return;
2349 }
2350
2351 hif_disable_power_management(hif_ctx);
2352}
2353
2354/**
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302355 * hdd_update_hw_sw_info() - API to update the HW/SW information
2356 *
2357 * API to update the HW and SW information in the driver
2358 *
2359 * Return: None
2360 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002361static void hdd_update_hw_sw_info(struct hdd_context *hdd_ctx)
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302362{
2363 void *hif_sc;
Dustin Brown6f17a022017-07-19 13:40:55 -07002364 size_t target_hw_name_len;
2365 const char *target_hw_name;
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302366
2367 hif_sc = cds_get_context(QDF_MODULE_ID_HIF);
2368 if (!hif_sc) {
2369 hdd_err("HIF context is NULL");
2370 return;
2371 }
2372
2373 /*
2374 * target hw version/revision would only be retrieved after firmware
2375 * download
2376 */
Dustin Brown6f17a022017-07-19 13:40:55 -07002377 hif_get_hw_info(hif_sc,
2378 &hdd_ctx->target_hw_version,
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302379 &hdd_ctx->target_hw_revision,
Dustin Brown6f17a022017-07-19 13:40:55 -07002380 &target_hw_name);
2381
2382 if (hdd_ctx->target_hw_name)
2383 qdf_mem_free(hdd_ctx->target_hw_name);
2384
2385 target_hw_name_len = strlen(target_hw_name) + 1;
2386 hdd_ctx->target_hw_name = qdf_mem_malloc(target_hw_name_len);
2387 if (hdd_ctx->target_hw_name)
2388 qdf_mem_copy(hdd_ctx->target_hw_name, target_hw_name,
2389 target_hw_name_len);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302390
2391 /* Get the wlan hw/fw version */
2392 hdd_wlan_get_version(hdd_ctx, NULL, NULL);
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302393}
2394
2395/**
gbian62edd7e2017-03-07 13:12:13 +08002396 * hdd_update_cds_ac_specs_params() - update cds ac_specs params
2397 * @hdd_ctx: Pointer to hdd context
2398 *
2399 * Return: none
2400 */
2401static void
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002402hdd_update_cds_ac_specs_params(struct hdd_context *hdd_ctx)
gbian62edd7e2017-03-07 13:12:13 +08002403{
2404 uint8_t num_entries = 0;
2405 uint8_t tx_sched_wrr_param[TX_SCHED_WRR_PARAMS_NUM];
2406 uint8_t *tx_sched_wrr_ac;
2407 int i;
2408 cds_context_type *cds_ctx;
2409
2410 if (NULL == hdd_ctx)
2411 return;
2412
2413 if (NULL == hdd_ctx->config) {
2414 /* Do nothing if hdd_ctx is invalid */
2415 hdd_err("%s: Warning: hdd_ctx->cfg_ini is NULL", __func__);
2416 return;
2417 }
2418
2419 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
2420
2421 if (!cds_ctx) {
2422 hdd_err("Invalid CDS Context");
2423 return;
2424 }
2425
2426 for (i = 0; i < OL_TX_NUM_WMM_AC; i++) {
2427 switch (i) {
2428 case OL_TX_WMM_AC_BE:
2429 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_be;
2430 break;
2431 case OL_TX_WMM_AC_BK:
2432 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_bk;
2433 break;
2434 case OL_TX_WMM_AC_VI:
2435 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vi;
2436 break;
2437 case OL_TX_WMM_AC_VO:
2438 tx_sched_wrr_ac = hdd_ctx->config->tx_sched_wrr_vo;
2439 break;
2440 default:
2441 tx_sched_wrr_ac = NULL;
2442 break;
2443 }
2444
2445 hdd_string_to_u8_array(tx_sched_wrr_ac,
2446 tx_sched_wrr_param,
2447 &num_entries,
2448 sizeof(tx_sched_wrr_param));
2449
2450 if (num_entries == TX_SCHED_WRR_PARAMS_NUM) {
2451 cds_ctx->ac_specs[i].wrr_skip_weight =
2452 tx_sched_wrr_param[0];
2453 cds_ctx->ac_specs[i].credit_threshold =
2454 tx_sched_wrr_param[1];
2455 cds_ctx->ac_specs[i].send_limit =
2456 tx_sched_wrr_param[2];
2457 cds_ctx->ac_specs[i].credit_reserve =
2458 tx_sched_wrr_param[3];
2459 cds_ctx->ac_specs[i].discard_weight =
2460 tx_sched_wrr_param[4];
2461 }
2462
2463 num_entries = 0;
2464 }
2465}
2466
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302467#ifdef IPA_OFFLOAD
2468/**
2469 * hdd_update_ipa_component_config() - update ipa config
2470 * @hdd_ctx: Pointer to hdd context
2471 *
2472 * Return: none
2473 */
2474static void hdd_update_ipa_component_config(struct hdd_context *hdd_ctx)
2475{
2476 struct hdd_config *cfg = hdd_ctx->config;
2477 struct wlan_ipa_config ipa_cfg;
2478
2479 ipa_cfg.ipa_config = cfg->IpaConfig;
2480 ipa_cfg.desc_size = cfg->IpaDescSize;
2481 ipa_cfg.txbuf_count = cfg->IpaUcTxBufCount;
2482 ipa_cfg.bus_bw_high = cfg->busBandwidthHighThreshold;
2483 ipa_cfg.bus_bw_medium = cfg->busBandwidthMediumThreshold;
2484 ipa_cfg.bus_bw_low = cfg->busBandwidthLowThreshold;
2485 ipa_cfg.ipa_bw_high = cfg->IpaHighBandwidthMbps;
2486 ipa_cfg.ipa_bw_medium = cfg->IpaMediumBandwidthMbps;
2487 ipa_cfg.ipa_bw_low = cfg->IpaLowBandwidthMbps;
2488
2489 ucfg_ipa_update_config(&ipa_cfg);
2490}
2491#else
2492static void hdd_update_ipa_component_config(struct hdd_context *hdd_ctx)
2493{
2494}
2495#endif
2496
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002497#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002498static enum policy_mgr_con_mode wlan_hdd_get_mode_for_non_connected_vdev(
2499 struct wlan_objmgr_psoc *psoc, uint8_t vdev_id)
2500{
Jeff Johnson9d295242017-08-29 14:39:48 -07002501 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002502 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002503
2504 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2505 if (!adapter) {
2506 hdd_err("Adapter is NULL");
2507 return PM_MAX_NUM_OF_MODE;
2508 }
2509
2510 return policy_mgr_convert_device_mode_to_qdf_type(
2511 adapter->device_mode);
2512}
2513
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002514static void hdd_register_policy_manager_callback(
2515 struct wlan_objmgr_psoc *psoc)
2516{
2517 struct policy_mgr_hdd_cbacks hdd_cbacks;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07002518
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002519 hdd_cbacks.sap_restart_chan_switch_cb =
Jeff Johnson23812942017-10-06 11:33:55 -07002520 hdd_sap_restart_chan_switch_cb;
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002521 hdd_cbacks.wlan_hdd_get_channel_for_sap_restart =
2522 wlan_hdd_get_channel_for_sap_restart;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002523 hdd_cbacks.get_mode_for_non_connected_vdev =
2524 wlan_hdd_get_mode_for_non_connected_vdev;
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05302525 hdd_cbacks.hdd_get_device_mode = hdd_get_device_mode;
Tushnim Bhattacharyya9fb2e422017-03-23 09:49:10 -07002526
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002527 if (QDF_STATUS_SUCCESS !=
2528 policy_mgr_register_hdd_cb(psoc, &hdd_cbacks)) {
2529 hdd_err("HDD callback registration with policy manager failed");
2530 }
2531}
2532#else
2533static void hdd_register_policy_manager_callback(
2534 struct wlan_objmgr_psoc *psoc)
2535{
2536}
2537#endif
2538
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002539static void hdd_nan_register_callbacks(struct hdd_context *hdd_ctx)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002540{
2541 struct nan_callbacks cb_obj = {0};
2542
2543 cb_obj.ndi_open = hdd_ndi_open;
2544 cb_obj.ndi_close = hdd_ndi_close;
2545 cb_obj.ndi_start = hdd_ndi_start;
2546 cb_obj.ndi_delete = hdd_ndi_delete;
2547 cb_obj.drv_ndi_create_rsp_handler = hdd_ndi_drv_ndi_create_rsp_handler;
2548 cb_obj.drv_ndi_delete_rsp_handler = hdd_ndi_drv_ndi_delete_rsp_handler;
2549
Naveen Rawat37f62c82017-03-26 22:24:43 -07002550 cb_obj.new_peer_ind = hdd_ndp_new_peer_handler;
2551 cb_obj.get_peer_idx = hdd_ndp_get_peer_idx;
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002552 cb_obj.peer_departed_ind = hdd_ndp_peer_departed_handler;
Naveen Rawat37f62c82017-03-26 22:24:43 -07002553
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002554 os_if_nan_register_hdd_callbacks(hdd_ctx->hdd_psoc, &cb_obj);
2555}
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002556
Dustin Brown26b3d042017-12-21 11:13:27 -08002557#ifdef CONFIG_LEAK_DETECTION
Dustin Brown4c5b9902017-12-19 11:17:19 -08002558/**
2559 * hdd_check_for_leaks() - Perform runtime memory leak checks
2560 *
2561 * This API triggers runtime memory leak detection. This feature enforces the
2562 * policy that any memory allocated at runtime must also be released at runtime.
2563 *
2564 * Allocating memory at runtime and releasing it at unload is effectively a
2565 * memory leak for configurations which never unload (e.g. LONU, statically
2566 * compiled driver). Such memory leaks are NOT false positives, and must be
2567 * fixed.
2568 *
2569 * Return: None
2570 */
Dustin Brown4bc0a622017-12-06 15:56:50 -08002571static void hdd_check_for_leaks(void)
2572{
Dustin Brown4c5b9902017-12-19 11:17:19 -08002573 /* DO NOT REMOVE these checks; for false positives, read above first */
2574
Dustin Brown677e0862017-10-10 16:30:09 -07002575 qdf_mc_timer_check_for_leaks();
Dustin Brown8e711502017-12-07 16:49:11 -08002576 qdf_nbuf_map_check_for_leaks();
Dustin Browne6b9d5a2017-12-14 15:18:49 -08002577 qdf_mem_check_for_leaks();
Dustin Brown4bc0a622017-12-06 15:56:50 -08002578}
2579
Dustin Brown26b3d042017-12-21 11:13:27 -08002580#define hdd_debug_domain_set(domain) qdf_debug_domain_set(domain)
2581#else
2582static inline void hdd_check_for_leaks(void) {}
2583
2584#define hdd_debug_domain_set(domain)
2585#endif /* CONFIG_LEAK_DETECTION */
2586
gbian62edd7e2017-03-07 13:12:13 +08002587/**
Paul Zhange03cf4c2018-01-19 18:33:22 +08002588 * hdd_update_country_code - Update country code
2589 * @hdd_ctx: HDD context
2590 *
2591 * Update country code based on module parameter country_code
2592 *
2593 * Return: 0 on success and errno on failure
2594 */
2595static int hdd_update_country_code(struct hdd_context *hdd_ctx)
2596{
2597 if (!country_code)
2598 return 0;
2599
2600 return hdd_reg_set_country(hdd_ctx, country_code);
2601}
2602
2603/**
Arun Khandavallifae92942016-08-01 13:31:08 +05302604 * hdd_wlan_start_modules() - Single driver state machine for starting modules
2605 * @hdd_ctx: HDD context
2606 * @adapter: HDD adapter
2607 * @reinit: flag to indicate from SSR or normal path
2608 *
2609 * This function maintains the driver state machine it will be invoked from
2610 * startup, reinit and change interface. Depending on the driver state shall
2611 * perform the opening of the modules.
2612 *
2613 * Return: 0 for success; non-zero for failure
2614 */
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002615int hdd_wlan_start_modules(struct hdd_context *hdd_ctx,
2616 struct hdd_adapter *adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302617 bool reinit)
2618{
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002619 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05302620 qdf_device_t qdf_dev;
2621 QDF_STATUS status;
Arun Khandavallifae92942016-08-01 13:31:08 +05302622 bool unint = false;
2623 void *hif_ctx;
Jingxiang Ge95912f82018-04-19 12:01:26 +08002624 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +05302625
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002626 hdd_debug("state:%d reinit:%d", hdd_ctx->driver_status, reinit);
Arun Khandavallifae92942016-08-01 13:31:08 +05302627
2628 qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
2629 if (!qdf_dev) {
2630 hdd_err("QDF Device Context is Invalid return");
2631 return -EINVAL;
2632 }
2633
Dustin Brown6f427922017-09-19 12:19:00 -07002634 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
Arun Khandavallifae92942016-08-01 13:31:08 +05302635
Dustin Brown1fe30a82017-10-03 16:13:36 -07002636 mutex_lock(&hdd_ctx->iface_change_lock);
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302637 if (hdd_ctx->driver_status == DRIVER_MODULES_ENABLED) {
2638 mutex_unlock(&hdd_ctx->iface_change_lock);
2639 hdd_info("Driver modules already Enabled");
Dustin Browne74003f2018-03-14 12:51:58 -07002640 hdd_exit();
Arun Khandavalli5a62a822017-11-14 19:43:00 +05302641 return 0;
2642 }
2643
Dustin Brown1fe30a82017-10-03 16:13:36 -07002644 hdd_ctx->start_modules_in_progress = true;
2645
Arun Khandavallifae92942016-08-01 13:31:08 +05302646 switch (hdd_ctx->driver_status) {
2647 case DRIVER_MODULES_UNINITIALIZED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002648 hdd_info("Wlan transitioning (UNINITIALIZED -> CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302649 unint = true;
2650 /* Fall through dont add break here */
2651 case DRIVER_MODULES_CLOSED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002652 hdd_info("Wlan transitioning (CLOSED -> OPENED)");
2653
Dustin Brown26b3d042017-12-21 11:13:27 -08002654 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002655
Arun Khandavallifae92942016-08-01 13:31:08 +05302656 if (!reinit && !unint) {
2657 ret = pld_power_on(qdf_dev->dev);
2658 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002659 hdd_err("Failed to Powerup the device; errno: %d",
2660 ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302661 goto release_lock;
2662 }
2663 }
Yuanyuan Liuf8fe4bc2017-06-07 16:55:58 -07002664
2665 pld_set_fw_log_mode(hdd_ctx->parent_dev,
2666 hdd_ctx->config->enable_fw_log);
Arun Khandavallifae92942016-08-01 13:31:08 +05302667 ret = hdd_hif_open(qdf_dev->dev, qdf_dev->drv_hdl, qdf_dev->bid,
2668 qdf_dev->bus_type,
2669 (reinit == true) ? HIF_ENABLE_TYPE_REINIT :
2670 HIF_ENABLE_TYPE_PROBE);
2671 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002672 hdd_err("Failed to open hif; errno: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +05302673 goto power_down;
2674 }
2675
2676 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
Arun Khandavalli1318b992016-08-09 11:04:57 +05302677 if (!hif_ctx) {
2678 hdd_err("hif context is null!!");
Dustin Browndca39692017-11-09 15:30:25 -08002679 ret = -EINVAL;
Arun Khandavalli1318b992016-08-09 11:04:57 +05302680 goto power_down;
2681 }
2682
Arun Khandavallifae92942016-08-01 13:31:08 +05302683 status = ol_cds_init(qdf_dev, hif_ctx);
2684 if (status != QDF_STATUS_SUCCESS) {
Dustin Browndca39692017-11-09 15:30:25 -08002685 hdd_err("No Memory to Create BMI Context; status: %d",
2686 status);
2687 ret = qdf_status_to_os_return(status);
Arun Khandavallifae92942016-08-01 13:31:08 +05302688 goto hif_close;
2689 }
2690
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302691 hdd_update_ipa_component_config(hdd_ctx);
2692
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002693 ret = hdd_update_config(hdd_ctx);
2694 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002695 hdd_err("Failed to update configuration; errno: %d",
2696 ret);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002697 goto cds_free;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08002698 }
2699
gbian62edd7e2017-03-07 13:12:13 +08002700 hdd_update_cds_ac_specs_params(hdd_ctx);
2701
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302702 status = cds_open(hdd_ctx->hdd_psoc);
Dustin Brown28b17892017-10-10 13:29:38 -07002703 if (QDF_IS_STATUS_ERROR(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002704 hdd_err("Failed to Open CDS; status: %d", status);
Dustin Brown28b17892017-10-10 13:29:38 -07002705 ret = qdf_status_to_os_return(status);
2706 goto deinit_config;
Arun Khandavallifae92942016-08-01 13:31:08 +05302707 }
2708
Mukul Sharma9d797a02017-01-05 20:26:03 +05302709 /* initalize components configurations after psoc open */
2710 ret = hdd_update_components_config(hdd_ctx);
2711 if (ret) {
Dustin Browndca39692017-11-09 15:30:25 -08002712 hdd_err("Failed to update component configs; errno: %d",
Mukul Sharma9d797a02017-01-05 20:26:03 +05302713 ret);
2714 goto close;
2715 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002716 status = cds_dp_open(hdd_ctx->hdd_psoc);
2717 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002718 hdd_err("Failed to Open cds post open; status: %d",
2719 status);
2720 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002721 goto close;
2722 }
Mukul Sharma9d797a02017-01-05 20:26:03 +05302723
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002724 /*
2725 * NAN compoenet requires certian operations like, open adapter,
2726 * close adapter, etc. to be initiated by HDD, for those
2727 * register HDD callbacks with UMAC's NAN componenet.
2728 */
2729 hdd_nan_register_callbacks(hdd_ctx);
2730
Arun Khandavallifae92942016-08-01 13:31:08 +05302731 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
2732
Jeff Johnson3a280122017-09-13 07:42:00 -07002733 status = cds_pre_enable();
Arun Khandavallifae92942016-08-01 13:31:08 +05302734 if (!QDF_IS_STATUS_SUCCESS(status)) {
Dustin Browndca39692017-11-09 15:30:25 -08002735 hdd_err("Failed to pre-enable CDS; status: %d", status);
2736 ret = qdf_status_to_os_return(status);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002737 goto cds_txrx_free;
Arun Khandavallifae92942016-08-01 13:31:08 +05302738 }
2739
Archana Ramachandranea34c4f2017-03-19 18:56:18 -07002740 hdd_register_policy_manager_callback(
2741 hdd_ctx->hdd_psoc);
2742
Amar Singhal0928b192017-12-01 10:50:54 -08002743 hdd_sysfs_create_version_interface(hdd_ctx->hdd_psoc);
2744
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302745 hdd_update_hw_sw_info(hdd_ctx);
Himanshu Agarwal0b9bbc32017-02-23 16:23:05 +05302746 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002747 hdd_info("Wlan transitioned (now OPENED)");
Arunk Khandavalli67193d52017-02-21 12:03:48 +05302748
Arun Khandavallifae92942016-08-01 13:31:08 +05302749 if (unint) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08002750 hdd_debug("In phase-1 initialization don't enable modules");
Arun Khandavallifae92942016-08-01 13:31:08 +05302751 break;
2752 }
Arun Khandavallicc544b32017-01-30 19:52:16 +05302753
Arun Khandavallifae92942016-08-01 13:31:08 +05302754 /* Fall through dont add break here */
2755 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -08002756 hdd_info("Wlan transitioning (OPENED -> ENABLED)");
2757
Arun Khandavallifae92942016-08-01 13:31:08 +05302758 if (!adapter) {
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002759 hdd_alert("adapter is Null");
Dustin Browndca39692017-11-09 15:30:25 -08002760 ret = -EINVAL;
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002761 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302762 }
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302763 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
2764 hdd_err("in ftm mode, no need to configure cds modules");
Dustin Browndca39692017-11-09 15:30:25 -08002765 ret = -EINVAL;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05302766 break;
2767 }
Dustin Browndca39692017-11-09 15:30:25 -08002768
2769 ret = hdd_configure_cds(hdd_ctx, adapter);
2770 if (ret) {
2771 hdd_err("Failed to Enable cds modules; errno: %d", ret);
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002772 goto post_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +05302773 }
Dustin Browndca39692017-11-09 15:30:25 -08002774
Komal Seelamf2136bb2016-09-28 18:30:44 +05302775 hdd_enable_power_management();
Dustin Brown550f6d22017-12-14 15:44:01 -08002776
Arun Khandavallifae92942016-08-01 13:31:08 +05302777 hdd_ctx->driver_status = DRIVER_MODULES_ENABLED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002778 hdd_info("Wlan transitioned (now ENABLED)");
Arun Khandavallifae92942016-08-01 13:31:08 +05302779 break;
Dustin Brown550f6d22017-12-14 15:44:01 -08002780
Arun Khandavallifae92942016-08-01 13:31:08 +05302781 default:
2782 hdd_err("WLAN start invoked in wrong state! :%d\n",
2783 hdd_ctx->driver_status);
Dustin Browndca39692017-11-09 15:30:25 -08002784 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +05302785 goto release_lock;
2786 }
Dustin Brown550f6d22017-12-14 15:44:01 -08002787
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302788 hdd_ctx->start_modules_in_progress = false;
Paul Zhange03cf4c2018-01-19 18:33:22 +08002789 if (DRIVER_MODULES_ENABLED == hdd_ctx->driver_status) {
2790 ret = hdd_update_country_code(hdd_ctx);
2791 if (ret)
2792 hdd_err("Failed to update command line country code!");
2793 }
Arun Khandavallifae92942016-08-01 13:31:08 +05302794 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown550f6d22017-12-14 15:44:01 -08002795
Dustin Browne74003f2018-03-14 12:51:58 -07002796 hdd_exit();
Dustin Brown550f6d22017-12-14 15:44:01 -08002797
Arun Khandavallifae92942016-08-01 13:31:08 +05302798 return 0;
2799
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002800post_disable:
Rajeev Kumarbe021242017-02-16 16:12:23 -08002801 cds_post_disable();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002802
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002803cds_txrx_free:
Jingxiang Ge95912f82018-04-19 12:01:26 +08002804 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
2805
2806 if (tgt_hdl && target_psoc_get_wmi_ready(tgt_hdl)) {
2807 hdd_runtime_suspend_context_deinit(hdd_ctx);
2808 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
2809 hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
2810 }
2811
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002812 cds_dp_close(hdd_ctx->hdd_psoc);
Dustin Brown550f6d22017-12-14 15:44:01 -08002813
Arun Khandavallifae92942016-08-01 13:31:08 +05302814close:
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002815 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -08002816 hdd_info("Wlan transition aborted (now CLOSED)");
2817
Jeff Johnsone4b14592017-09-13 14:23:33 -07002818 cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +05302819
Dustin Brown28b17892017-10-10 13:29:38 -07002820deinit_config:
2821 cds_deinit_ini_config();
2822
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -07002823cds_free:
Arun Khandavallifae92942016-08-01 13:31:08 +05302824 ol_cds_free();
2825
2826hif_close:
Jeff Johnson60dc2b12017-09-28 14:56:02 -07002827 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
2828 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +05302829power_down:
2830 if (!reinit && !unint)
2831 pld_power_off(qdf_dev->dev);
2832release_lock:
Arun Khandavallia172c3e2016-08-26 17:33:13 +05302833 hdd_ctx->start_modules_in_progress = false;
Arun Khandavallifae92942016-08-01 13:31:08 +05302834 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002835
2836 /* many adapter resources are not freed by design in SSR case */
2837 if (!reinit)
2838 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -08002839 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -08002840
Dustin Browne74003f2018-03-14 12:51:58 -07002841 hdd_exit();
Rajeev Kumara3f672f2017-02-16 13:59:37 -08002842
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -07002843 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +05302844}
2845
Naveen Rawat910726a2017-03-06 11:42:51 -08002846#ifdef WIFI_POS_CONVERGED
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002847static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002848{
2849 int ret = os_if_wifi_pos_register_nl();
2850
2851 if (ret)
2852 hdd_err("os_if_wifi_pos_register_nl failed");
2853
2854 return ret;
2855}
2856
2857static int hdd_deactivate_wifi_pos(void)
2858{
2859 int ret = os_if_wifi_pos_deregister_nl();
2860
2861 if (ret)
2862 hdd_err("os_if_wifi_pos_deregister_nl failed");
2863
2864 return ret;
2865}
2866
2867/**
2868 * hdd_populate_wifi_pos_cfg - populates wifi_pos parameters
2869 * @hdd_ctx: hdd context
2870 *
2871 * Return: status of operation
2872 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002873static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002874{
2875 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
2876 struct hdd_config *cfg = hdd_ctx->config;
2877
2878 wifi_pos_set_oem_target_type(psoc, hdd_ctx->target_type);
2879 wifi_pos_set_oem_fw_version(psoc, hdd_ctx->target_fw_version);
2880 wifi_pos_set_drv_ver_major(psoc, QWLAN_VERSION_MAJOR);
2881 wifi_pos_set_drv_ver_minor(psoc, QWLAN_VERSION_MINOR);
2882 wifi_pos_set_drv_ver_patch(psoc, QWLAN_VERSION_PATCH);
2883 wifi_pos_set_drv_ver_build(psoc, QWLAN_VERSION_BUILD);
2884 wifi_pos_set_dwell_time_min(psoc, cfg->nNeighborScanMinChanTime);
2885 wifi_pos_set_dwell_time_max(psoc, cfg->nNeighborScanMaxChanTime);
2886}
2887#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002888static int hdd_activate_wifi_pos(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002889{
2890 return oem_activate_service(hdd_ctx);
2891}
2892
2893static int hdd_deactivate_wifi_pos(void)
2894{
2895 return 0;
2896}
2897
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002898static void hdd_populate_wifi_pos_cfg(struct hdd_context *hdd_ctx)
Naveen Rawat910726a2017-03-06 11:42:51 -08002899{
2900}
2901#endif
2902
Arun Khandavallifae92942016-08-01 13:31:08 +05302903/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002904 * __hdd_open() - HDD Open function
2905 * @dev: Pointer to net_device structure
2906 *
2907 * This is called in response to ifconfig up
2908 *
2909 * Return: 0 for success; non-zero for failure
2910 */
2911static int __hdd_open(struct net_device *dev)
2912{
Jeff Johnson9d295242017-08-29 14:39:48 -07002913 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07002914 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002915 int ret;
2916
Dustin Brownfdf17c12018-03-14 12:55:34 -07002917 hdd_enter_dev(dev);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302918 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_OPEN_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07002919 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002920
Ashish Kumar Dhanotiya15a7db52017-08-03 10:27:34 +05302921 /* Nothing to be done if device is unloading */
2922 if (cds_is_driver_unloading()) {
2923 hdd_err("Driver is unloading can not open the hdd");
2924 return -EBUSY;
2925 }
2926
Dustin Brown01847752017-10-25 13:56:27 -07002927 if (cds_is_driver_recovering()) {
2928 hdd_err("WLAN is currently recovering; Please try again.");
2929 return -EBUSY;
2930 }
2931
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302932 if (qdf_atomic_read(&hdd_ctx->con_mode_flag)) {
2933 hdd_err("con_mode_handler is in progress; Please try again.");
2934 return -EBUSY;
2935 }
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302936
Sourav Mohapatra421d42b2017-12-29 16:33:23 +05302937 mutex_lock(&hdd_init_deinit_lock);
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302938 hdd_start_driver_ops_timer(eHDD_DRV_OP_IFF_UP);
2939
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302940 /*
2941 * This scenario can be hit in cases where in the wlan driver after
2942 * registering the netdevices and there is a failure in driver
2943 * initialization. So return error gracefully because the netdevices
2944 * will be de-registered as part of the load failure.
2945 */
2946
2947 if (!cds_is_driver_loaded()) {
2948 hdd_err("Failed to start the wlan driver!!");
2949 ret = -EIO;
2950 goto err_hdd_hdd_init_deinit_lock;
2951 }
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302952
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002953
Arun Khandavallifae92942016-08-01 13:31:08 +05302954 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
2955 if (ret) {
2956 hdd_err("Failed to start WLAN modules return");
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302957 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302958 }
2959
2960
2961 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
2962 ret = hdd_start_adapter(adapter);
2963 if (ret) {
2964 hdd_err("Failed to start adapter :%d",
2965 adapter->device_mode);
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302966 goto err_hdd_hdd_init_deinit_lock;
Arun Khandavallifae92942016-08-01 13:31:08 +05302967 }
2968 }
2969
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002970 set_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
2971 if (hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002972 hdd_debug("Enabling Tx Queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002973 /* Enable TX queues only when we are connected */
2974 wlan_hdd_netif_queue_control(adapter,
Arun Khandavallifae92942016-08-01 13:31:08 +05302975 WLAN_START_ALL_NETIF_QUEUE,
2976 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002977 }
2978
Naveen Rawat286def52016-09-23 15:38:02 -07002979 /* Enable carrier and transmit queues for NDI */
2980 if (WLAN_HDD_IS_NDI(adapter)) {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002981 hdd_debug("Enabling Tx Queues");
Naveen Rawat286def52016-09-23 15:38:02 -07002982 wlan_hdd_netif_queue_control(adapter,
2983 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2984 WLAN_CONTROL_PATH);
2985 }
2986
Naveen Rawat910726a2017-03-06 11:42:51 -08002987 hdd_populate_wifi_pos_cfg(hdd_ctx);
2988
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302989err_hdd_hdd_init_deinit_lock:
Hanumanth Reddy Pothula006f3832017-10-12 15:52:43 +05302990 hdd_stop_driver_ops_timer();
Arunk Khandavalli16d84252017-06-21 15:26:29 +05302991 mutex_unlock(&hdd_init_deinit_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002992 return ret;
2993}
2994
Arun Khandavallifae92942016-08-01 13:31:08 +05302995
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002996/**
2997 * hdd_open() - Wrapper function for __hdd_open to protect it from SSR
2998 * @dev: Pointer to net_device structure
2999 *
3000 * This is called in response to ifconfig up
3001 *
3002 * Return: 0 for success; non-zero for failure
3003 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003004static int hdd_open(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003005{
3006 int ret;
3007
3008 cds_ssr_protect(__func__);
3009 ret = __hdd_open(dev);
3010 cds_ssr_unprotect(__func__);
3011
3012 return ret;
3013}
3014
3015/**
3016 * __hdd_stop() - HDD stop function
3017 * @dev: Pointer to net_device structure
3018 *
3019 * This is called in response to ifconfig down
3020 *
3021 * Return: 0 for success; non-zero for failure
3022 */
3023static int __hdd_stop(struct net_device *dev)
3024{
Jeff Johnson9d295242017-08-29 14:39:48 -07003025 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003026 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003027 int ret;
3028
Dustin Brownfdf17c12018-03-14 12:55:34 -07003029 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003030
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303031 MTRACE(qdf_trace(QDF_MODULE_ID_HDD, TRACE_CODE_HDD_STOP_REQUEST,
Jeff Johnson1b780e42017-10-31 14:11:45 -07003032 adapter->session_id, adapter->device_mode));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003033
3034 ret = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303035 if (0 != ret)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003036 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003037
3038 /* Nothing to be done if the interface is not opened */
3039 if (false == test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags)) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003040 hdd_err("NETDEV Interface is not OPENED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003041 return -ENODEV;
3042 }
3043
3044 /* Make sure the interface is marked as closed */
3045 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303046
3047 hdd_debug("Disabling Auto Power save timer");
3048 sme_ps_disable_auto_ps_timer(
3049 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07003050 adapter->session_id);
Mukul Sharmad16c2022017-07-25 18:56:12 +05303051
3052 /*
3053 * Disable TX on the interface, after this hard_start_xmit() will not
3054 * be called on that interface
3055 */
Dustin Brown5e89ef82018-03-14 11:50:23 -07003056 hdd_info("Disabling queues, adapter device mode: %s(%d)",
Kabilan Kannan8dac3502017-10-30 12:40:27 -07003057 hdd_device_mode_to_string(adapter->device_mode),
3058 adapter->device_mode);
3059
Himanshu Agarwal865201d2017-04-12 15:45:31 +05303060 wlan_hdd_netif_queue_control(adapter,
3061 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
3062 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003063
3064 /*
Naveen Rawat286def52016-09-23 15:38:02 -07003065 * NAN data interface is different in some sense. The traffic on NDI is
3066 * bursty in nature and depends on the need to transfer. The service
3067 * layer may down the interface after the usage and up again when
3068 * required. In some sense, the NDI is expected to be available
3069 * (like SAP) iface until NDI delete request is issued by the service
3070 * layer. Skip BSS termination and adapter deletion for NAN Data
3071 * interface (NDI).
3072 */
3073 if (WLAN_HDD_IS_NDI(adapter))
3074 return 0;
3075
3076 /*
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003077 * The interface is marked as down for outside world (aka kernel)
3078 * But the driver is pretty much alive inside. The driver needs to
3079 * tear down the existing connection on the netdev (session)
3080 * cleanup the data pipes and wait until the control plane is stabilized
3081 * for this interface. The call also needs to wait until the above
3082 * mentioned actions are completed before returning to the caller.
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003083 * Notice that hdd_stop_adapter is requested not to close the session
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003084 * That is intentional to be able to scan if it is a STA/P2P interface
3085 */
Dustin Browndb2a8be2017-12-20 11:49:56 -08003086 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003087
3088 /* DeInit the adapter. This ensures datapath cleanup as well */
3089 hdd_deinit_adapter(hdd_ctx, adapter, true);
3090
Arun Khandavallifae92942016-08-01 13:31:08 +05303091
3092 /*
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +05303093 * Upon wifi turn off, DUT has to flush the scan results so if
3094 * this is the last cli iface, flush the scan database.
3095 */
3096 if (!hdd_is_cli_iface_up(hdd_ctx))
3097 sme_scan_flush_result(hdd_ctx->hHal);
3098
3099 /*
Arun Khandavallifae92942016-08-01 13:31:08 +05303100 * Find if any iface is up. If any iface is up then can't put device to
3101 * sleep/power save mode
3102 */
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05303103 if (hdd_check_for_opened_interfaces(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003104 hdd_debug("Closing all modules from the hdd_stop");
Dustin Brown6f427922017-09-19 12:19:00 -07003105 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
3106 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +05303107 hdd_prevent_suspend_timeout(
3108 hdd_ctx->config->iface_change_wait_time,
3109 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Arun Khandavallifae92942016-08-01 13:31:08 +05303110 }
3111
Dustin Browne74003f2018-03-14 12:51:58 -07003112 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003113 return 0;
3114}
3115
3116/**
3117 * hdd_stop() - Wrapper function for __hdd_stop to protect it from SSR
3118 * @dev: pointer to net_device structure
3119 *
3120 * This is called in response to ifconfig down
3121 *
3122 * Return: 0 for success and error number for failure
3123 */
Jeff Johnson590e2012016-10-05 16:16:24 -07003124static int hdd_stop(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003125{
3126 int ret;
3127
3128 cds_ssr_protect(__func__);
3129 ret = __hdd_stop(dev);
3130 cds_ssr_unprotect(__func__);
3131
3132 return ret;
3133}
3134
3135/**
3136 * __hdd_uninit() - HDD uninit function
3137 * @dev: Pointer to net_device structure
3138 *
3139 * This is called during the netdev unregister to uninitialize all data
3140 * associated with the device
3141 *
3142 * Return: None
3143 */
3144static void __hdd_uninit(struct net_device *dev)
3145{
Jeff Johnson9d295242017-08-29 14:39:48 -07003146 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson399c6272017-08-30 10:51:00 -07003147 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003148
Dustin Brownfdf17c12018-03-14 12:55:34 -07003149 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003150
3151 do {
3152 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003153 hdd_err("Invalid magic");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003154 break;
3155 }
3156
Jeff Johnson399c6272017-08-30 10:51:00 -07003157 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3158 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003159 hdd_err("NULL hdd_ctx");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003160 break;
3161 }
3162
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003163 if (dev != adapter->dev)
3164 hdd_err("Invalid device reference");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003165
Jeff Johnson399c6272017-08-30 10:51:00 -07003166 hdd_deinit_adapter(hdd_ctx, adapter, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003167
3168 /* after uninit our adapter structure will no longer be valid */
3169 adapter->dev = NULL;
3170 adapter->magic = 0;
3171 } while (0);
3172
Dustin Browne74003f2018-03-14 12:51:58 -07003173 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003174}
3175
3176/**
3177 * hdd_uninit() - Wrapper function to protect __hdd_uninit from SSR
3178 * @dev: pointer to net_device structure
3179 *
3180 * This is called during the netdev unregister to uninitialize all data
3181 * associated with the device
3182 *
3183 * Return: none
3184 */
3185static void hdd_uninit(struct net_device *dev)
3186{
3187 cds_ssr_protect(__func__);
3188 __hdd_uninit(dev);
3189 cds_ssr_unprotect(__func__);
3190}
3191
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003192static int hdd_open_cesium_nl_sock(void)
3193{
3194#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3195 struct netlink_kernel_cfg cfg = {
3196 .groups = WLAN_NLINK_MCAST_GRP_ID,
3197 .input = NULL
3198 };
3199#endif
3200 int ret = 0;
3201
3202#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
3203 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3204#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
3205 THIS_MODULE,
3206#endif
3207 &cfg);
3208#else
3209 cesium_nl_srv_sock = netlink_kernel_create(&init_net, WLAN_NLINK_CESIUM,
3210 WLAN_NLINK_MCAST_GRP_ID,
3211 NULL, NULL, THIS_MODULE);
3212#endif
3213
3214 if (cesium_nl_srv_sock == NULL) {
Jeff Johnson1346fab2016-08-15 13:09:42 -07003215 hdd_err("NLINK: cesium netlink_kernel_create failed");
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003216 ret = -ECONNREFUSED;
3217 }
3218
3219 return ret;
3220}
3221
3222static void hdd_close_cesium_nl_sock(void)
3223{
3224 if (NULL != cesium_nl_srv_sock) {
3225 netlink_kernel_release(cesium_nl_srv_sock);
3226 cesium_nl_srv_sock = NULL;
3227 }
3228}
3229
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003230/**
3231 * __hdd_set_mac_address() - set the user specified mac address
3232 * @dev: Pointer to the net device.
3233 * @addr: Pointer to the sockaddr.
3234 *
3235 * This function sets the user specified mac address using
3236 * the command ifconfig wlanX hw ether <mac adress>.
3237 *
3238 * Return: 0 for success, non zero for failure
3239 */
3240static int __hdd_set_mac_address(struct net_device *dev, void *addr)
3241{
Jeff Johnson9d295242017-08-29 14:39:48 -07003242 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003243 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003244 struct sockaddr *psta_mac_addr = addr;
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303245 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003246 int ret;
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303247 struct qdf_mac_addr mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003248
Dustin Brownfdf17c12018-03-14 12:55:34 -07003249 hdd_enter_dev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003250
Hanumanth Reddy Pothula5c7a7812018-03-09 12:55:32 +05303251 if (netif_running(dev)) {
3252 hdd_err("On iface up, set mac address change isn't supported");
3253 return -EBUSY;
3254 }
3255
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003256 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3257 ret = wlan_hdd_validate_context(hdd_ctx);
3258 if (0 != ret)
3259 return ret;
3260
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303261 qdf_mem_copy(&mac_addr, psta_mac_addr->sa_data, sizeof(mac_addr));
3262
Ashish Kumar Dhanotiyaf974f332018-04-19 16:03:15 +05303263 if (hdd_get_adapter_by_macaddr(hdd_ctx, mac_addr.bytes)) {
3264 hdd_err("adapter exist with same mac address " MAC_ADDRESS_STR,
3265 MAC_ADDR_ARRAY(mac_addr.bytes));
3266 return -EINVAL;
3267 }
3268
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303269 if (qdf_is_macaddr_zero(&mac_addr)) {
3270 hdd_err("MAC is all zero");
3271 return -EINVAL;
3272 }
3273
3274 if (qdf_is_macaddr_broadcast(&mac_addr)) {
3275 hdd_err("MAC is Broadcast");
3276 return -EINVAL;
3277 }
3278
3279 if (ETHER_IS_MULTICAST(psta_mac_addr->sa_data)) {
3280 hdd_err("MAC is Multicast");
3281 return -EINVAL;
3282 }
Ashish Kumar Dhanotiya8bfef122018-04-18 16:48:27 +05303283 hdd_info("Changing MAC to " MAC_ADDRESS_STR " of the interface %s ",
3284 MAC_ADDR_ARRAY(mac_addr.bytes), dev->name);
Ashish Kumar Dhanotiyaaa0ca602018-02-21 17:42:55 +05303285
Jeff Johnson1e851a12017-10-28 14:36:12 -07003286 memcpy(&adapter->mac_addr, psta_mac_addr->sa_data, ETH_ALEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003287 memcpy(dev->dev_addr, psta_mac_addr->sa_data, ETH_ALEN);
3288
Dustin Browne74003f2018-03-14 12:51:58 -07003289 hdd_exit();
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05303290 return qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003291}
3292
3293/**
3294 * hdd_set_mac_address() - Wrapper function to protect __hdd_set_mac_address()
3295 * function from SSR
3296 * @dev: pointer to net_device structure
3297 * @addr: Pointer to the sockaddr
3298 *
3299 * This function sets the user specified mac address using
3300 * the command ifconfig wlanX hw ether <mac adress>.
3301 *
3302 * Return: 0 for success.
3303 */
3304static int hdd_set_mac_address(struct net_device *dev, void *addr)
3305{
3306 int ret;
3307
3308 cds_ssr_protect(__func__);
3309 ret = __hdd_set_mac_address(dev, addr);
3310 cds_ssr_unprotect(__func__);
3311
3312 return ret;
3313}
3314
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003315uint8_t *wlan_hdd_get_intf_addr(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003316{
3317 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003318
Anurag Chouhan6d760662016-02-20 16:05:43 +05303319 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003320 if (0 == ((hdd_ctx->config->intfAddrMask) & (1 << i)))
3321 break;
3322 }
3323
Anurag Chouhan6d760662016-02-20 16:05:43 +05303324 if (QDF_MAX_CONCURRENCY_PERSONA == i)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003325 return NULL;
3326
3327 hdd_ctx->config->intfAddrMask |= (1 << i);
3328 return &hdd_ctx->config->intfMacAddr[i].bytes[0];
3329}
3330
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07003331void wlan_hdd_release_intf_addr(struct hdd_context *hdd_ctx,
3332 uint8_t *releaseAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003333{
3334 int i;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003335
Anurag Chouhan6d760662016-02-20 16:05:43 +05303336 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003337 if (!memcmp(releaseAddr,
3338 &hdd_ctx->config->intfMacAddr[i].bytes[0],
3339 6)) {
3340 hdd_ctx->config->intfAddrMask &= ~(1 << i);
3341 break;
3342 }
3343 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003344}
3345
3346#ifdef WLAN_FEATURE_PACKET_FILTERING
3347/**
3348 * __hdd_set_multicast_list() - set the multicast address list
3349 * @dev: Pointer to the WLAN device.
3350 * @skb: Pointer to OS packet (sk_buff).
3351 *
3352 * This funciton sets the multicast address list.
3353 *
3354 * Return: None
3355 */
3356static void __hdd_set_multicast_list(struct net_device *dev)
3357{
Jeff Johnson9d295242017-08-29 14:39:48 -07003358 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003359 int i = 0, status;
3360 struct netdev_hw_addr *ha;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003361 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303362 struct pmo_mc_addr_list_params *mc_list_request = NULL;
3363 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
3364 int mc_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003365
Dustin Brownfdf17c12018-03-14 12:55:34 -07003366 hdd_enter_dev(dev);
Anurag Chouhan6d760662016-02-20 16:05:43 +05303367 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303368 goto out;
Mukul Sharma51c44942015-10-30 19:30:19 +05303369
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003370 status = wlan_hdd_validate_context(hdd_ctx);
Hanumantha Reddy Pothula2db50ed2015-11-23 10:48:33 +05303371 if (0 != status)
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303372 goto out;
3373
Dustin Brownc788acb2017-08-01 17:43:51 -07003374 status = hdd_validate_adapter(adapter);
3375 if (status)
3376 goto out;
3377
Arunk Khandavalli6a227882017-12-12 19:31:08 +05303378 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED) {
3379 hdd_err("%s: Driver module is closed", __func__);
3380 return;
3381 }
3382
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303383 mc_list_request = qdf_mem_malloc(sizeof(*mc_list_request));
3384 if (!mc_list_request) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003385 hdd_err("Cannot allocate mc_list_request");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303386 goto out;
3387 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003388
Hanumanth Reddy Pothulaca84ec52017-02-21 12:09:45 +05303389 /* Delete already configured multicast address list */
3390 if (adapter->mc_addr_list.mc_cnt > 0) {
3391 hdd_info("clear previously configured MC address list");
3392 hdd_disable_and_flush_mc_addr_list(adapter,
3393 pmo_mc_list_change_notify);
3394 }
3395
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003396 if (dev->flags & IFF_ALLMULTI) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003397 hdd_debug("allow all multicast frames");
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303398 hdd_disable_and_flush_mc_addr_list(adapter,
3399 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003400 } else {
3401 mc_count = netdev_mc_count(dev);
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303402 if (mc_count > pmo_ucfg_max_mc_addr_supported(psoc)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003403 hdd_debug("Exceeded max MC filter addresses (%d). Allowing all MC frames by disabling MC address filtering",
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303404 pmo_ucfg_max_mc_addr_supported(psoc));
3405 hdd_disable_and_flush_mc_addr_list(adapter,
3406 pmo_mc_list_change_notify);
3407 goto out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003408 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003409 netdev_for_each_mc_addr(ha, dev) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003410 hdd_debug("ha_addr[%d] "MAC_ADDRESS_STR,
Sachin Ahujaa69c72a2016-09-03 15:59:33 +05303411 i, MAC_ADDR_ARRAY(ha->addr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003412 if (i == mc_count)
3413 break;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303414 memset(&(mc_list_request->mc_addr[i].bytes),
3415 0, ETH_ALEN);
3416 memcpy(&(mc_list_request->mc_addr[i].bytes),
3417 ha->addr, ETH_ALEN);
3418 hdd_info("mlist[%d] = %pM", i,
3419 mc_list_request->mc_addr[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003420 i++;
3421 }
3422 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303423
3424 mc_list_request->psoc = psoc;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003425 mc_list_request->vdev_id = adapter->session_id;
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303426 mc_list_request->count = mc_count;
3427 status = hdd_cache_mc_addr_list(mc_list_request);
3428 if (status == 0) {
3429 hdd_enable_mc_addr_filtering(adapter,
3430 pmo_mc_list_change_notify);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003431 } else {
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303432 hdd_err("error while caching mc list");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003433 }
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303434out:
3435 if (mc_list_request)
3436 qdf_mem_free(mc_list_request);
Dustin Browne74003f2018-03-14 12:51:58 -07003437 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003438}
3439
Mukul Sharmaff2ac2e2017-01-16 15:51:29 +05303440
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003441/**
3442 * hdd_set_multicast_list() - SSR wrapper function for __hdd_set_multicast_list
3443 * @dev: pointer to net_device
3444 *
3445 * Return: none
3446 */
3447static void hdd_set_multicast_list(struct net_device *dev)
3448{
3449 cds_ssr_protect(__func__);
3450 __hdd_set_multicast_list(dev);
3451 cds_ssr_unprotect(__func__);
3452}
3453#endif
3454
3455/**
3456 * hdd_select_queue() - used by Linux OS to decide which queue to use first
3457 * @dev: Pointer to the WLAN device.
3458 * @skb: Pointer to OS packet (sk_buff).
3459 *
3460 * This function is registered with the Linux OS for network
3461 * core to decide which queue to use first.
3462 *
3463 * Return: ac, Queue Index/access category corresponding to UP in IP header
3464 */
3465static uint16_t hdd_select_queue(struct net_device *dev, struct sk_buff *skb
3466#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
3467 , void *accel_priv
3468#endif
3469#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
3470 , select_queue_fallback_t fallback
3471#endif
3472)
3473{
3474 return hdd_wmm_select_queue(dev, skb);
3475}
3476
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003477static const struct net_device_ops wlan_drv_ops = {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003478 .ndo_open = hdd_open,
3479 .ndo_stop = hdd_stop,
3480 .ndo_uninit = hdd_uninit,
3481 .ndo_start_xmit = hdd_hard_start_xmit,
3482 .ndo_tx_timeout = hdd_tx_timeout,
3483 .ndo_get_stats = hdd_get_stats,
3484 .ndo_do_ioctl = hdd_ioctl,
3485 .ndo_set_mac_address = hdd_set_mac_address,
3486 .ndo_select_queue = hdd_select_queue,
3487#ifdef WLAN_FEATURE_PACKET_FILTERING
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003488 .ndo_set_rx_mode = hdd_set_multicast_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003489#endif
3490};
3491
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003492/* Monitor mode net_device_ops, doesnot Tx and most of operations. */
Srinivas Girigowdab841da72017-03-25 18:04:39 -07003493static const struct net_device_ops wlan_mon_drv_ops = {
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003494 .ndo_open = hdd_mon_open,
3495 .ndo_stop = hdd_stop,
3496 .ndo_get_stats = hdd_get_stats,
3497};
3498
3499/**
3500 * hdd_set_station_ops() - update net_device ops for monitor mode
Jeff Johnson5505db82017-11-02 21:19:23 -07003501 * @dev: Handle to struct net_device to be updated.
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003502 * Return: None
3503 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003504void hdd_set_station_ops(struct net_device *dev)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003505{
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003506 if (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam())
Jeff Johnson5505db82017-11-02 21:19:23 -07003507 dev->netdev_ops = &wlan_mon_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003508 else
Jeff Johnson5505db82017-11-02 21:19:23 -07003509 dev->netdev_ops = &wlan_drv_ops;
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003510}
3511
3512/**
Ryan Hsu07495ea2016-01-21 15:25:39 -08003513 * hdd_alloc_station_adapter() - allocate the station hdd adapter
3514 * @hdd_ctx: global hdd context
3515 * @macAddr: mac address to assign to the interface
3516 * @name: User-visible name of the interface
3517 *
3518 * hdd adapter pointer would point to the netdev->priv space, this function
3519 * would retrive the pointer, and setup the hdd adapter configuration.
3520 *
3521 * Return: the pointer to hdd adapter, otherwise NULL
3522 */
Jeff Johnson9d295242017-08-29 14:39:48 -07003523static struct hdd_adapter *hdd_alloc_station_adapter(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003524 tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003525 unsigned char name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003526 const char *name)
3527{
Jeff Johnson5505db82017-11-02 21:19:23 -07003528 struct net_device *dev = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07003529 struct hdd_adapter *adapter = NULL;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003530 struct hdd_station_ctx *sta_ctx;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303531 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003532 /*
3533 * cfg80211 initialization and registration....
3534 */
Jeff Johnson5505db82017-11-02 21:19:23 -07003535 dev = alloc_netdev_mq(sizeof(struct hdd_adapter), name,
Ryan Hsu07495ea2016-01-21 15:25:39 -08003536#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) || defined(WITH_BACKPORTS)
3537 name_assign_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003538#endif
Manjunathappa Prakash59f861d2016-04-21 10:33:31 -07003539 (QDF_GLOBAL_MONITOR_MODE == cds_get_conparam() ?
3540 hdd_mon_mode_ether_setup : ether_setup),
3541 NUM_TX_QUEUES);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003542
Jeff Johnson5505db82017-11-02 21:19:23 -07003543 if (dev != NULL) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003544
3545 /* Save the pointer to the net_device in the HDD adapter */
Jeff Johnson5505db82017-11-02 21:19:23 -07003546 adapter = (struct hdd_adapter *) netdev_priv(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003547
Jeff Johnson9d295242017-08-29 14:39:48 -07003548 qdf_mem_zero(adapter, sizeof(struct hdd_adapter));
Jeff Johnsonb9424862017-10-30 08:49:35 -07003549 sta_ctx = &adapter->session.station;
Hanumanth Reddy Pothula18553ae2017-04-28 15:03:10 +05303550 qdf_mem_set(sta_ctx->conn_info.staId,
3551 sizeof(sta_ctx->conn_info.staId),
3552 HDD_WLAN_INVALID_STA_ID);
Jeff Johnson5505db82017-11-02 21:19:23 -07003553 adapter->dev = dev;
Jeff Johnsondba0db62017-08-30 11:12:39 -07003554 adapter->hdd_ctx = hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003555 adapter->magic = WLAN_HDD_ADAPTER_MAGIC;
Jeff Johnson1b780e42017-10-31 14:11:45 -07003556 adapter->session_id = HDD_SESSION_ID_INVALID;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003557
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303558 qdf_status = qdf_event_create(
3559 &adapter->qdf_session_open_event);
3560 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3561 hdd_err("Session open QDF event init failed!");
3562 free_netdev(adapter->dev);
3563 return NULL;
3564 }
3565
3566 qdf_status = qdf_event_create(
3567 &adapter->qdf_session_close_event);
3568 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
3569 hdd_err("Session close QDF event init failed!");
3570 free_netdev(adapter->dev);
3571 return NULL;
3572 }
3573
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003574 init_completion(&adapter->disconnect_comp_var);
Abhishek Singh533c9da2017-05-04 10:23:34 +05303575 init_completion(&adapter->roaming_comp_var);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003576 init_completion(&adapter->linkup_event_var);
3577 init_completion(&adapter->cancel_rem_on_chan_var);
3578 init_completion(&adapter->rem_on_chan_ready_event);
3579 init_completion(&adapter->sta_authorized_event);
3580 init_completion(&adapter->offchannel_tx_event);
3581 init_completion(&adapter->tx_action_cnf_event);
Rajeev Kumar8e3e2832015-11-06 16:02:54 -08003582 init_completion(&adapter->ibss_peer_info_comp);
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +05303583 init_completion(&adapter->lfr_fw_status.disable_lfr_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003584
3585 adapter->offloads_configured = false;
Jeff Johnsonc72c5732017-10-28 12:49:37 -07003586 adapter->is_link_up_service_needed = false;
Alok Kumarb64650c2018-03-23 17:05:11 +05303587 adapter->disconnection_in_progress = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003588 /* Init the net_device structure */
Jeff Johnson5505db82017-11-02 21:19:23 -07003589 strlcpy(dev->name, name, IFNAMSIZ);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003590
Jeff Johnson5505db82017-11-02 21:19:23 -07003591 qdf_mem_copy(dev->dev_addr, (void *)macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003592 sizeof(tSirMacAddr));
Jeff Johnson1e851a12017-10-28 14:36:12 -07003593 qdf_mem_copy(adapter->mac_addr.bytes, macAddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003594 sizeof(tSirMacAddr));
Jeff Johnson5505db82017-11-02 21:19:23 -07003595 dev->watchdog_timeo = HDD_TX_TIMEOUT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003596
3597 if (hdd_ctx->config->enable_ip_tcp_udp_checksum_offload)
Jeff Johnson5505db82017-11-02 21:19:23 -07003598 dev->features |=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003599 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Jeff Johnson5505db82017-11-02 21:19:23 -07003600 dev->features |= NETIF_F_RXCSUM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003601
Jeff Johnson5505db82017-11-02 21:19:23 -07003602 hdd_set_tso_flags(hdd_ctx, dev);
Dhanashri Atre83d373d2015-07-28 16:45:59 -07003603
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003604 hdd_set_station_ops(adapter->dev);
3605
Jeff Johnson5505db82017-11-02 21:19:23 -07003606 hdd_dev_setup_destructor(dev);
3607 dev->ieee80211_ptr = &adapter->wdev;
3608 dev->tx_queue_len = HDD_NETDEV_TX_QUEUE_LEN;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003609 adapter->wdev.wiphy = hdd_ctx->wiphy;
Jeff Johnson5505db82017-11-02 21:19:23 -07003610 adapter->wdev.netdev = dev;
3611 /* set dev's parent to underlying device */
3612 SET_NETDEV_DEV(dev, hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003613 hdd_wmm_init(adapter);
3614 spin_lock_init(&adapter->pause_map_lock);
Nirav Shah617cff92016-04-25 10:24:24 +05303615 adapter->start_time = adapter->last_time = qdf_system_ticks();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003616 }
3617
3618 return adapter;
3619}
3620
Jeff Johnson9d295242017-08-29 14:39:48 -07003621static QDF_STATUS hdd_register_interface(struct hdd_adapter *adapter, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003622{
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003623 struct net_device *dev = adapter->dev;
3624 int ret;
3625
Dustin Brown491d54b2018-03-14 12:39:11 -07003626 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003627
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08003628 if (rtnl_held) {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003629 if (strnchr(dev->name, IFNAMSIZ - 1, '%')) {
3630
3631 ret = dev_alloc_name(dev, dev->name);
3632 if (ret < 0) {
3633 hdd_err(
3634 "unable to get dev name: %s, err = 0x%x",
3635 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303636 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003637 }
3638 }
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003639
3640 ret = register_netdevice(dev);
3641 if (ret) {
3642 hdd_err("register_netdevice(%s) failed, err = 0x%x",
3643 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303644 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003645 }
3646 } else {
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003647 ret = register_netdev(dev);
3648 if (ret) {
3649 hdd_err("register_netdev(%s) failed, err = 0x%x",
3650 dev->name, ret);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303651 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003652 }
3653 }
3654 set_bit(NET_DEVICE_REGISTERED, &adapter->event_flags);
3655
Dustin Browne74003f2018-03-14 12:51:58 -07003656 hdd_exit();
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07003657
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303658 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003659}
3660
Krunal Sonib51eec72017-11-20 21:53:01 -08003661QDF_STATUS hdd_sme_open_session_callback(uint8_t session_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003662{
Krunal Sonib51eec72017-11-20 21:53:01 -08003663 struct hdd_adapter *adapter;
3664 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003665
Krunal Sonib51eec72017-11-20 21:53:01 -08003666 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3667 if (!hdd_ctx) {
3668 hdd_err("Invalid HDD_CTX");
3669 return QDF_STATUS_E_FAILURE;
3670 }
3671
3672 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
3673 if (NULL == adapter) {
3674 hdd_err("NULL adapter");
3675 return QDF_STATUS_E_INVAL;
3676 }
3677 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303678 qdf_event_set(&adapter->qdf_session_open_event);
Krunal Sonib51eec72017-11-20 21:53:01 -08003679 hdd_debug("session %d opened", adapter->session_id);
3680
3681 return QDF_STATUS_SUCCESS;
3682}
3683
3684QDF_STATUS hdd_sme_close_session_callback(uint8_t session_id)
3685{
3686 struct hdd_adapter *adapter;
3687 struct hdd_context *hdd_ctx;
3688
3689 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
3690 if (!hdd_ctx) {
3691 hdd_err("Invalid HDD_CTX");
3692 return QDF_STATUS_E_FAILURE;
3693 }
3694
3695 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003696 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003697 hdd_err("NULL adapter");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303698 return QDF_STATUS_E_INVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003699 }
3700
3701 if (WLAN_HDD_ADAPTER_MAGIC != adapter->magic) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003702 hdd_err("Invalid magic");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303703 return QDF_STATUS_NOT_INITIALIZED;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003704 }
3705
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003706 /*
3707 * For NAN Data interface, the close session results in the final
3708 * indication to the userspace
3709 */
Rakesh Sunki3480f962016-08-29 17:29:53 -07003710 if (adapter->device_mode == QDF_NDI_MODE)
3711 hdd_ndp_session_end_handler(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07003712
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003713 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
3714
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003715 /*
3716 * We can be blocked while waiting for scheduled work to be
3717 * flushed, and the adapter structure can potentially be freed, in
3718 * which case the magic will have been reset. So make sure the
3719 * magic is still good, and hence the adapter structure is still
3720 * valid, before signaling completion
3721 */
3722 if (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303723 qdf_event_set(&adapter->qdf_session_close_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003724
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303725 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003726}
3727
Jeff Johnson9d295242017-08-29 14:39:48 -07003728int hdd_vdev_ready(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003729{
Dustin Brownd28772b2017-03-17 14:16:07 -07003730 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003731
Dustin Brownd28772b2017-03-17 14:16:07 -07003732 status = pmo_vdev_ready(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003733 if (QDF_IS_STATUS_ERROR(status))
3734 return qdf_status_to_os_return(status);
3735
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003736 status = ucfg_reg_11d_vdev_created_update(adapter->hdd_vdev);
Dustin Brown8d8d9fe2017-07-18 16:01:25 -07003737 if (QDF_IS_STATUS_ERROR(status))
3738 return qdf_status_to_os_return(status);
3739
3740 if (wma_capability_enhanced_mcast_filter())
3741 status = pmo_ucfg_enhanced_mc_filter_enable(adapter->hdd_vdev);
3742 else
3743 status = pmo_ucfg_enhanced_mc_filter_disable(adapter->hdd_vdev);
Dustin Brownd28772b2017-03-17 14:16:07 -07003744
3745 return qdf_status_to_os_return(status);
3746}
3747
Jeff Johnson9d295242017-08-29 14:39:48 -07003748int hdd_vdev_destroy(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003749{
3750 QDF_STATUS status;
Jiachao Wu2c42c222018-01-15 18:13:19 +08003751 int errno = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003752 struct hdd_context *hdd_ctx;
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003753 uint8_t vdev_id;
Dustin Brownd28772b2017-03-17 14:16:07 -07003754
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003755 vdev_id = adapter->session_id;
3756 hdd_info("destroying vdev %d", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003757
3758 /* vdev created sanity check */
3759 if (!test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07003760 hdd_err("vdev for Id %d does not exist", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003761 return -EINVAL;
3762 }
Kiran Kumar Lokere3beeb952017-05-02 18:40:24 -07003763 status = ucfg_reg_11d_vdev_delete_update(adapter->hdd_vdev);
Yue Maf9782842017-05-08 12:49:49 -07003764
Dustin Brownd28772b2017-03-17 14:16:07 -07003765 /* close sme session (destroy vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303766 qdf_event_reset(&adapter->qdf_session_close_event);
Dustin Brownd28772b2017-03-17 14:16:07 -07003767 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Krunal Sonib51eec72017-11-20 21:53:01 -08003768 status = sme_close_session(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003769 if (QDF_IS_STATUS_ERROR(status)) {
3770 hdd_err("failed to close sme session: %d", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003771 errno = qdf_status_to_os_return(status);
3772 goto release_vdev;
Dustin Brownd28772b2017-03-17 14:16:07 -07003773 }
3774
3775 /* block on a completion variable until sme session is closed */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303776 status = qdf_wait_for_event_completion(
3777 &adapter->qdf_session_close_event,
3778 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3779 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003780 if (adapter->device_mode == QDF_NDI_MODE)
3781 hdd_ndp_session_end_handler(adapter);
3782 clear_bit(SME_SESSION_OPENED, &adapter->event_flags);
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303783 adapter->session_id = HDD_SESSION_ID_INVALID;
3784 if (QDF_STATUS_E_TIMEOUT != status) {
3785 hdd_err("timed out waiting for close sme session: %u", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003786 errno = -ETIMEDOUT;
3787 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303788 } else if (adapter->qdf_session_close_event.force_set) {
3789 hdd_err("Session close evt focefully set, SSR/PDR has occurred");
Jiachao Wu2c42c222018-01-15 18:13:19 +08003790 errno = -EINVAL;
3791 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303792 } else {
3793 hdd_err("Failed to close sme session (%u)", status);
Jiachao Wu2c42c222018-01-15 18:13:19 +08003794 errno = -EINVAL;
3795 goto release_vdev;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303796 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003797 }
Jiachao Wu2c42c222018-01-15 18:13:19 +08003798
Yue Maf9782842017-05-08 12:49:49 -07003799release_vdev:
Frank Liuc66d4bf2018-01-26 16:18:18 +08003800 /*
3801 * In SSR or driver unloading case, directly exit may cause objects
3802 * leak, if sme_close_session failed. Free objects anyway.
Jiachao Wu2c42c222018-01-15 18:13:19 +08003803 */
Kabilan Kannanb867c312018-02-15 17:43:21 -08003804 if (errno && !cds_is_driver_recovering() && !cds_is_driver_unloading())
Jiachao Wu2c42c222018-01-15 18:13:19 +08003805 return errno;
3806
Sandeep Puligillaef415362017-08-30 16:37:13 -07003807 /* do vdev logical destroy via objmgr */
Dustin Brownb277dd62018-01-26 15:17:33 -08003808 errno = hdd_objmgr_release_and_destroy_vdev(adapter);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003809 if (errno) {
Dustin Brownb277dd62018-01-26 15:17:33 -08003810 hdd_err("failed to destroy objmgr vdev; errno:%d", errno);
Sandeep Puligillaef415362017-08-30 16:37:13 -07003811 return errno;
3812 }
3813
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08003814 hdd_info("vdev %d destroyed successfully", vdev_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003815
3816 return 0;
3817}
3818
Krunal Sonib51eec72017-11-20 21:53:01 -08003819static int hdd_set_sme_session_param(struct hdd_adapter *adapter,
3820 struct sme_session_params *session_param,
3821 csr_roam_completeCallback callback,
3822 void *callback_ctx)
Dustin Brownd28772b2017-03-17 14:16:07 -07003823{
Dustin Brownd28772b2017-03-17 14:16:07 -07003824 uint32_t type;
3825 uint32_t sub_type;
Krunal Sonib51eec72017-11-20 21:53:01 -08003826 QDF_STATUS status;
Dustin Brownd28772b2017-03-17 14:16:07 -07003827
3828 /* determine vdev (sub)type */
3829 status = cds_get_vdev_types(adapter->device_mode, &type, &sub_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303830 if (QDF_STATUS_SUCCESS != status) {
Dustin Brownd28772b2017-03-17 14:16:07 -07003831 hdd_err("failed to get vdev type: %d", status);
3832 return qdf_status_to_os_return(status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003833 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003834 session_param->sme_session_id = adapter->session_id;
3835 session_param->self_mac_addr = (uint8_t *)&adapter->mac_addr;
3836 session_param->type_of_persona = type;
3837 session_param->subtype_of_persona = sub_type;
3838 session_param->session_open_cb = hdd_sme_open_session_callback;
3839 session_param->session_close_cb = hdd_sme_close_session_callback;
3840 session_param->callback = callback;
3841 session_param->callback_ctx = callback_ctx;
3842
3843 return 0;
3844}
3845
3846int hdd_vdev_create(struct hdd_adapter *adapter,
3847 csr_roam_completeCallback callback, void *ctx)
3848{
3849 QDF_STATUS status;
3850 int errno;
3851 struct hdd_context *hdd_ctx;
3852 struct sme_session_params sme_session_params = {0};
Krunal Sonib51eec72017-11-20 21:53:01 -08003853
3854 hdd_info("creating new vdev");
Dustin Brownd28772b2017-03-17 14:16:07 -07003855
3856 /* do vdev create via objmgr */
3857 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Dustin Brown7d043f62017-03-27 12:07:36 -07003858 errno = hdd_objmgr_create_and_store_vdev(hdd_ctx->hdd_pdev, adapter);
Dustin Brownd28772b2017-03-17 14:16:07 -07003859 if (errno) {
3860 hdd_err("failed to create objmgr vdev: %d", errno);
3861 return errno;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003862 }
Dustin Brownd28772b2017-03-17 14:16:07 -07003863
3864 /* Open a SME session (prepare vdev in firmware via legacy API) */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303865 status = qdf_event_reset(&adapter->qdf_session_open_event);
3866 if (QDF_STATUS_SUCCESS != status) {
3867 hdd_err("failed to reinit session open event");
3868 return -EINVAL;
3869 }
Krunal Sonib51eec72017-11-20 21:53:01 -08003870 errno = hdd_set_sme_session_param(adapter, &sme_session_params,
3871 callback, ctx);
3872 if (errno) {
3873 hdd_err("failed to populating SME params");
3874 goto objmgr_vdev_destroy_procedure;
3875 }
3876
3877 status = sme_open_session(hdd_ctx->hHal, &sme_session_params);
Dustin Brownd28772b2017-03-17 14:16:07 -07003878 if (QDF_IS_STATUS_ERROR(status)) {
3879 hdd_err("failed to open sme session: %d", status);
3880 errno = qdf_status_to_os_return(status);
Krunal Soni4a020c72017-10-30 20:58:40 -07003881 goto objmgr_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003882 }
3883
3884 /* block on a completion variable until sme session is opened */
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303885 status = qdf_wait_for_event_completion(&adapter->qdf_session_open_event,
3886 WLAN_WAIT_TIME_SESSIONOPENCLOSE);
3887 if (QDF_STATUS_SUCCESS != status) {
3888 if (adapter->qdf_session_open_event.force_set) {
3889 /*
3890 * SSR/PDR has caused shutdown, which has forcefully
3891 * set the event. Return without the closing session.
3892 */
3893 adapter->session_id = HDD_SESSION_ID_INVALID;
3894 hdd_err("Session open event forcefully set");
3895 return -EINVAL;
Nachiket Kukade08b9f292017-11-17 18:27:37 +05303896 }
Jeff Johnsonc66d3102018-02-28 11:58:26 -08003897
3898 if (QDF_STATUS_E_TIMEOUT == status)
3899 hdd_err("Session failed to open within timeout period");
3900 else
3901 hdd_err("Failed to wait for session open event(status-%d)",
3902 status);
3903 errno = -ETIMEDOUT;
3904 set_bit(SME_SESSION_OPENED, &adapter->event_flags);
3905 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003906 }
3907
3908 /* firmware ready for component communication, raise vdev_ready event */
3909 errno = hdd_vdev_ready(adapter);
3910 if (errno) {
3911 hdd_err("failed to dispatch vdev ready event: %d", errno);
Krunal Soni4a020c72017-10-30 20:58:40 -07003912 goto hdd_vdev_destroy_procedure;
Dustin Brownd28772b2017-03-17 14:16:07 -07003913 }
3914
Naveen Rawat2b430892018-03-13 13:58:18 -07003915 if (adapter->device_mode == QDF_STA_MODE) {
3916 hdd_debug("setting RTT mac randomization param: %d",
3917 hdd_ctx->config->enable_rtt_mac_randomization);
3918 errno = sme_cli_set_command(adapter->session_id,
3919 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_INITIATOR_RANDOM_MAC,
3920 hdd_ctx->config->enable_rtt_mac_randomization,
3921 VDEV_CMD);
3922 if (0 != errno)
3923 hdd_err("RTT mac randomization param set failed %d",
3924 errno);
3925 }
3926
Jeff Johnson1b780e42017-10-31 14:11:45 -07003927 hdd_info("vdev %d created successfully", adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003928
3929 return 0;
3930
3931 /*
3932 * Due to legacy constraints, we need to destroy in the same order as
3933 * create. So, split error handling into 2 cases to accommodate.
3934 */
3935
Krunal Soni4a020c72017-10-30 20:58:40 -07003936objmgr_vdev_destroy_procedure:
Dustin Brown7d043f62017-03-27 12:07:36 -07003937 QDF_BUG(!hdd_objmgr_release_and_destroy_vdev(adapter));
Dustin Brownd28772b2017-03-17 14:16:07 -07003938
3939 return errno;
3940
Krunal Soni4a020c72017-10-30 20:58:40 -07003941hdd_vdev_destroy_procedure:
Dustin Brownd28772b2017-03-17 14:16:07 -07003942 QDF_BUG(!hdd_vdev_destroy(adapter));
3943
3944 return errno;
3945}
3946
Jeff Johnson9d295242017-08-29 14:39:48 -07003947QDF_STATUS hdd_init_station_mode(struct hdd_adapter *adapter)
Dustin Brownd28772b2017-03-17 14:16:07 -07003948{
Jeff Johnsonb9424862017-10-30 08:49:35 -07003949 struct hdd_station_ctx *sta_ctx = &adapter->session.station;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07003950 struct hdd_context *hdd_ctx;
Dustin Brownd28772b2017-03-17 14:16:07 -07003951 QDF_STATUS status;
3952 int ret_val;
3953
Dustin Brownd28772b2017-03-17 14:16:07 -07003954 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
3955 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
3956 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
Jeff Johnson1b780e42017-10-31 14:11:45 -07003957 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->session_id);
Dustin Brownd28772b2017-03-17 14:16:07 -07003958
Jeff Johnson7f2c5912018-03-23 11:42:28 -07003959 hdd_roam_profile_init(adapter);
3960 hdd_register_wext(adapter->dev);
3961
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07003962 hdd_conn_set_connection_state(adapter, eConnectionState_NotConnected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003963
Jeff Johnsond377dce2017-10-04 10:32:42 -07003964 qdf_mem_set(sta_ctx->conn_info.staId,
3965 sizeof(sta_ctx->conn_info.staId), HDD_WLAN_INVALID_STA_ID);
Hanumanth Reddy Pothulab2d729c2017-05-30 11:49:53 +05303966
Deepak Dhamdherea2785822016-11-17 01:17:45 -08003967 /* set fast roaming capability in sme session */
Jeff Johnson1b780e42017-10-31 14:11:45 -07003968 status = sme_config_fast_roaming(hdd_ctx->hHal, adapter->session_id,
Abhishek Singh1f217ec2017-12-22 11:48:27 +05303969 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003970 /* Set the default operation channel */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003971 sta_ctx->conn_info.operationChannel =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003972 hdd_ctx->config->OperatingChannel;
3973
3974 /* Make the default Auth Type as OPEN */
Jeff Johnsond377dce2017-10-04 10:32:42 -07003975 sta_ctx->conn_info.authType = eCSR_AUTH_TYPE_OPEN_SYSTEM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003976
3977 status = hdd_init_tx_rx(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303978 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003979 hdd_err("hdd_init_tx_rx() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003980 status, status);
3981 goto error_init_txrx;
3982 }
3983
3984 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
3985
3986 status = hdd_wmm_adapter_init(adapter);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303987 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08003988 hdd_err("hdd_wmm_adapter_init() failed, status code %08d [x%08x]",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003989 status, status);
3990 goto error_wmm_init;
3991 }
3992
3993 set_bit(WMM_INIT_DONE, &adapter->event_flags);
3994
Jeff Johnson1b780e42017-10-31 14:11:45 -07003995 ret_val = sme_cli_set_command(adapter->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003996 WMI_PDEV_PARAM_BURST_ENABLE,
3997 hdd_ctx->config->enableSifsBurst,
3998 PDEV_CMD);
Dustin Brownd28772b2017-03-17 14:16:07 -07003999 if (ret_val)
4000 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004001
Poddar, Siddarth4b3f7312017-11-02 17:00:20 +05304002 /*
4003 * In case of USB tethering, LRO is disabled. If SSR happened
4004 * during that time, then as part of SSR init, do not enable
4005 * the LRO again. Keep the LRO state same as before SSR.
4006 */
4007 if (!(qdf_atomic_read(&hdd_ctx->vendor_disable_lro_flag)))
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07004008 adapter->dev->features |= NETIF_F_LRO;
Rajeev Kumar Sirasanagandla996e5292016-11-22 21:20:33 +05304009
4010 /* rcpi info initialization */
4011 qdf_mem_zero(&adapter->rcpi, sizeof(adapter->rcpi));
4012
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304013 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004014
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004015error_wmm_init:
4016 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4017 hdd_deinit_tx_rx(adapter);
4018error_init_txrx:
Dustin Brownd28772b2017-03-17 14:16:07 -07004019 hdd_unregister_wext(adapter->dev);
Dustin Brownd28772b2017-03-17 14:16:07 -07004020 QDF_BUG(!hdd_vdev_destroy(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004021
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004022 return status;
4023}
4024
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304025/**
Krunal Soni4a020c72017-10-30 20:58:40 -07004026 * hdd_deinit_station_mode() - De-initialize the station adapter
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304027 * @hdd_ctx: global hdd context
4028 * @adapter: HDD adapter
Jeff Johnson590e2012016-10-05 16:16:24 -07004029 * @rtnl_held: Used to indicate whether or not the caller is holding
4030 * the kernel rtnl_mutex
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304031 *
4032 * This function De-initializes the STA/P2P/OCB adapter.
4033 *
4034 * Return: None.
4035 */
Krunal Soni4a020c72017-10-30 20:58:40 -07004036static void hdd_deinit_station_mode(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004037 struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004038 bool rtnl_held)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304039{
Dustin Brownfdf17c12018-03-14 12:55:34 -07004040 hdd_enter_dev(adapter->dev);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304041
Hanumanth Reddy Pothula7a657402016-09-07 20:59:18 +05304042 if (adapter->dev) {
4043 if (rtnl_held)
4044 adapter->dev->wireless_handlers = NULL;
4045 else {
4046 rtnl_lock();
4047 adapter->dev->wireless_handlers = NULL;
4048 rtnl_unlock();
4049 }
4050 }
4051
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304052 if (test_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags)) {
4053 hdd_deinit_tx_rx(adapter);
4054 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
4055 }
4056
4057 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
4058 hdd_wmm_adapter_close(adapter);
4059 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
4060 }
4061
Krunal Sonib51eec72017-11-20 21:53:01 -08004062
Dustin Browne74003f2018-03-14 12:51:58 -07004063 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304064}
4065
Krunal Sonib51eec72017-11-20 21:53:01 -08004066void hdd_deinit_adapter(struct hdd_context *hdd_ctx,
4067 struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004068 bool rtnl_held)
4069{
Dustin Brown491d54b2018-03-14 12:39:11 -07004070 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05304071
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004072 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004073 case QDF_STA_MODE:
4074 case QDF_P2P_CLIENT_MODE:
4075 case QDF_P2P_DEVICE_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08004076 case QDF_IBSS_MODE:
4077 case QDF_NDI_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004078 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004079 hdd_deinit_station_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004080 break;
4081 }
4082
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004083 case QDF_SAP_MODE:
4084 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004085 {
Krunal Soni4a020c72017-10-30 20:58:40 -07004086 hdd_deinit_ap_mode(hdd_ctx, adapter, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004087 break;
4088 }
4089
4090 default:
4091 break;
4092 }
4093
Dustin Browne74003f2018-03-14 12:51:58 -07004094 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004095}
4096
Jeff Johnson9d295242017-08-29 14:39:48 -07004097static void hdd_cleanup_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Jeff Johnson590e2012016-10-05 16:16:24 -07004098 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004099{
Jeff Johnson5505db82017-11-02 21:19:23 -07004100 struct net_device *dev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004101
4102 if (adapter)
Jeff Johnson5505db82017-11-02 21:19:23 -07004103 dev = adapter->dev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004104 else {
Jeff Johnson5880d792016-08-15 13:32:30 -07004105 hdd_err("adapter is Null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004106 return;
4107 }
4108
Alok Kumarb64650c2018-03-23 17:05:11 +05304109 hdd_nud_deinit_tracking(adapter);
4110 qdf_mutex_destroy(&adapter->disconnection_status_lock);
4111
Rajeev Kumardca5f812016-02-04 17:28:06 -08004112 hdd_debugfs_exit(adapter);
Selvaraj, Sridhar4ea106e2016-08-05 20:34:46 +05304113
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004114 /*
4115 * The adapter is marked as closed. When hdd_wlan_exit() call returns,
4116 * the driver is almost closed and cannot handle either control
4117 * messages or data. However, unregister_netdevice() call above will
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004118 * eventually invoke hdd_stop(ndo_close) driver callback, which attempts
4119 * to close the active connections(basically excites control path) which
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004120 * is not right. Setting this flag helps hdd_stop() to recognize that
4121 * the interface is closed and restricts any operations on that
4122 */
4123 clear_bit(DEVICE_IFACE_OPENED, &adapter->event_flags);
4124
4125 if (test_bit(NET_DEVICE_REGISTERED, &adapter->event_flags)) {
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004126 if (rtnl_held)
Jeff Johnson5505db82017-11-02 21:19:23 -07004127 unregister_netdevice(dev);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004128 else
Jeff Johnson5505db82017-11-02 21:19:23 -07004129 unregister_netdev(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004130 /*
4131 * Note that the adapter is no longer valid at this point
4132 * since the memory has been reclaimed
4133 */
4134 }
4135}
4136
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004137static QDF_STATUS hdd_check_for_existing_macaddr(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07004138 tSirMacAddr macAddr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004139{
Jeff Johnson9d295242017-08-29 14:39:48 -07004140 struct hdd_adapter *adapter;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004141
Dustin Brown920397d2017-12-13 16:27:50 -08004142 hdd_for_each_adapter(hdd_ctx, adapter) {
4143 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
4144 macAddr, sizeof(tSirMacAddr))) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304145 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004146 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004147 }
Dustin Brown920397d2017-12-13 16:27:50 -08004148
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304149 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004150}
Ryan Hsu07495ea2016-01-21 15:25:39 -08004151
Arun Khandavalli2358d522016-05-16 18:05:37 +05304152#ifdef CONFIG_FW_LOGS_BASED_ON_INI
4153/**
4154 * hdd_set_fw_log_params() - Set log parameters to FW
4155 * @hdd_ctx: HDD Context
4156 * @adapter: HDD Adapter
4157 *
4158 * This function set the FW Debug log level based on the INI.
4159 *
4160 * Return: None
4161 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004162static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004163 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304164{
4165 uint8_t count = 0, numentries = 0,
4166 moduleloglevel[FW_MODULE_LOG_LEVEL_STRING_LENGTH];
4167 uint32_t value = 0;
4168 int ret;
4169
Arun Khandavallifae92942016-08-01 13:31:08 +05304170 if (QDF_GLOBAL_FTM_MODE == cds_get_conparam() ||
4171 (!hdd_ctx->config->enable_fw_log)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004172 hdd_debug("enable_fw_log not enabled in INI or in FTM mode return");
Arun Khandavalli2358d522016-05-16 18:05:37 +05304173 return;
4174 }
4175
Arun Khandavallifae92942016-08-01 13:31:08 +05304176 /* Enable FW logs based on INI configuration */
Arun Khandavalli2358d522016-05-16 18:05:37 +05304177 hdd_ctx->fw_log_settings.dl_type =
4178 hdd_ctx->config->enableFwLogType;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004179 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304180 WMI_DBGLOG_TYPE,
4181 hdd_ctx->config->enableFwLogType,
4182 DBG_CMD);
4183 if (ret != 0)
4184 hdd_err("Failed to enable FW log type ret %d",
4185 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304186
4187 hdd_ctx->fw_log_settings.dl_loglevel =
Arun Khandavallifae92942016-08-01 13:31:08 +05304188 hdd_ctx->config->enableFwLogLevel;
Jeff Johnson1b780e42017-10-31 14:11:45 -07004189 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304190 WMI_DBGLOG_LOG_LEVEL,
4191 hdd_ctx->config->enableFwLogLevel,
4192 DBG_CMD);
4193 if (ret != 0)
4194 hdd_err("Failed to enable FW log level ret %d",
4195 ret);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304196
4197 hdd_string_to_u8_array(
4198 hdd_ctx->config->enableFwModuleLogLevel,
4199 moduleloglevel,
4200 &numentries,
4201 FW_MODULE_LOG_LEVEL_STRING_LENGTH);
4202
4203 while (count < numentries) {
4204 /*
4205 * FW module log level input string looks like
4206 * below:
4207 * gFwDebugModuleLoglevel=<FW Module ID>,
4208 * <Log Level>,...
4209 * For example:
4210 * gFwDebugModuleLoglevel=
4211 * 1,0,2,1,3,2,4,3,5,4,6,5,7,6
4212 * Above input string means :
4213 * For FW module ID 1 enable log level 0
4214 * For FW module ID 2 enable log level 1
4215 * For FW module ID 3 enable log level 2
4216 * For FW module ID 4 enable log level 3
4217 * For FW module ID 5 enable log level 4
4218 * For FW module ID 6 enable log level 5
4219 * For FW module ID 7 enable log level 6
4220 */
4221
Nishank Aggarwale239d962017-03-03 12:26:02 +05304222 if ((moduleloglevel[count] > WLAN_MODULE_ID_MAX)
4223 || (moduleloglevel[count + 1] > DBGLOG_LVL_MAX)) {
4224 hdd_err("Module id %d and dbglog level %d input length is more than max",
4225 moduleloglevel[count],
4226 moduleloglevel[count + 1]);
4227 return;
4228 }
4229
4230 value = moduleloglevel[count] << 16;
4231 value |= moduleloglevel[count + 1];
Jeff Johnson1b780e42017-10-31 14:11:45 -07004232 ret = sme_cli_set_command(adapter->session_id,
Arun Khandavallifae92942016-08-01 13:31:08 +05304233 WMI_DBGLOG_MOD_LOG_LEVEL,
4234 value, DBG_CMD);
4235 if (ret != 0)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304236 hdd_err("Failed to enable FW module log level %d ret %d",
4237 value, ret);
4238
4239 count += 2;
4240 }
Arun Khandavallifae92942016-08-01 13:31:08 +05304241
Arun Khandavalli2358d522016-05-16 18:05:37 +05304242}
4243#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004244static void hdd_set_fw_log_params(struct hdd_context *hdd_ctx,
Jeff Johnson9d295242017-08-29 14:39:48 -07004245 struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304246{
4247}
4248
4249#endif
4250
4251/**
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004252 * hdd_configure_chain_mask() - programs chain mask to firmware
4253 * @adapter: HDD adapter
4254 *
4255 * Return: 0 on success or errno on failure
4256 */
4257static int hdd_configure_chain_mask(struct hdd_adapter *adapter)
4258{
4259 int ret_val;
Naveen Rawat98322472018-03-06 10:29:42 -08004260 QDF_STATUS status;
4261 struct wma_caps_per_phy non_dbs_phy_cap;
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004262 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
4263
4264 hdd_debug("enable2x2: %d, lte_coex: %d, ChainMask1x1: tx: %d rx: %d",
4265 hdd_ctx->config->enable2x2, hdd_ctx->lte_coex_ant_share,
4266 hdd_ctx->config->txchainmask1x1,
4267 hdd_ctx->config->rxchainmask1x1);
4268 hdd_debug("disable_DBS: %d, tx_chain_mask_2g: %d, rx_chain_mask_2g: %d",
4269 hdd_ctx->config->dual_mac_feature_disable,
4270 hdd_ctx->config->tx_chain_mask_2g,
4271 hdd_ctx->config->rx_chain_mask_2g);
4272 hdd_debug("tx_chain_mask_5g: %d, rx_chain_mask_5g: %d",
4273 hdd_ctx->config->tx_chain_mask_5g,
4274 hdd_ctx->config->rx_chain_mask_5g);
Liangwei Dong22810e82018-03-15 03:42:12 -04004275 hdd_debug("enable_bt_chain_separation %d",
4276 hdd_ctx->config->enable_bt_chain_separation);
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004277
Naveen Rawat98322472018-03-06 10:29:42 -08004278 status = wma_get_caps_for_phyidx_hwmode(&non_dbs_phy_cap,
4279 HW_MODE_DBS_NONE,
4280 CDS_BAND_ALL);
4281 if (QDF_IS_STATUS_ERROR(status)) {
4282 hdd_err("couldn't get phy caps. skip chain mask programming");
4283 return qdf_status_to_os_return(status);
4284 }
4285
4286 if (non_dbs_phy_cap.tx_chain_mask_2G < 3 ||
4287 non_dbs_phy_cap.rx_chain_mask_2G < 3 ||
4288 non_dbs_phy_cap.tx_chain_mask_5G < 3 ||
4289 non_dbs_phy_cap.rx_chain_mask_5G < 3) {
4290 hdd_info("firmware not capable. skip chain mask programming");
4291 return 0;
4292 }
4293
Liangwei Dong22810e82018-03-15 03:42:12 -04004294 if (hdd_ctx->config->enable2x2 &&
4295 !hdd_ctx->config->enable_bt_chain_separation) {
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004296 hdd_info("2x2 enabled. skip chain mask programming");
4297 return 0;
4298 }
4299
Naveen Rawatb54c72b2018-02-05 10:39:06 -08004300 if (hdd_ctx->config->dual_mac_feature_disable !=
4301 DISABLE_DBS_CXN_AND_SCAN) {
4302 hdd_info("DBS enabled(%d). skip chain mask programming",
4303 hdd_ctx->config->dual_mac_feature_disable);
4304 return 0;
4305 }
4306
Naveen Rawatdacb5032018-02-08 15:23:24 -08004307 if (hdd_ctx->lte_coex_ant_share) {
4308 hdd_info("lte ant sharing enabled. skip chainmask programming");
4309 return 0;
4310 }
4311
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004312 if (hdd_ctx->config->txchainmask1x1) {
4313 ret_val = sme_cli_set_command(adapter->session_id,
4314 WMI_PDEV_PARAM_TX_CHAIN_MASK,
4315 hdd_ctx->config->txchainmask1x1,
4316 PDEV_CMD);
4317 if (ret_val)
4318 goto error;
4319 }
4320
4321 if (hdd_ctx->config->rxchainmask1x1) {
4322 ret_val = sme_cli_set_command(adapter->session_id,
4323 WMI_PDEV_PARAM_RX_CHAIN_MASK,
4324 hdd_ctx->config->rxchainmask1x1,
4325 PDEV_CMD);
4326 if (ret_val)
4327 goto error;
4328 }
4329
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004330 if (hdd_ctx->config->txchainmask1x1 ||
4331 hdd_ctx->config->rxchainmask1x1) {
4332 hdd_info("band agnostic tx/rx chain mask set. skip per band chain mask");
4333 return 0;
4334 }
4335
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004336 if (hdd_ctx->config->tx_chain_mask_2g) {
4337 ret_val = sme_cli_set_command(adapter->session_id,
4338 WMI_PDEV_PARAM_TX_CHAIN_MASK_2G,
4339 hdd_ctx->config->tx_chain_mask_2g, PDEV_CMD);
4340 if (0 != ret_val)
4341 goto error;
4342 }
4343
4344 if (hdd_ctx->config->rx_chain_mask_2g) {
4345 ret_val = sme_cli_set_command(adapter->session_id,
4346 WMI_PDEV_PARAM_RX_CHAIN_MASK_2G,
4347 hdd_ctx->config->rx_chain_mask_2g, PDEV_CMD);
4348 if (0 != ret_val)
4349 goto error;
4350 }
4351
4352 if (hdd_ctx->config->tx_chain_mask_5g) {
4353 ret_val = sme_cli_set_command(adapter->session_id,
4354 WMI_PDEV_PARAM_TX_CHAIN_MASK_5G,
4355 hdd_ctx->config->tx_chain_mask_5g, PDEV_CMD);
4356 if (0 != ret_val)
4357 goto error;
4358 }
4359
4360 if (hdd_ctx->config->rx_chain_mask_5g) {
4361 ret_val = sme_cli_set_command(adapter->session_id,
4362 WMI_PDEV_PARAM_RX_CHAIN_MASK_5G,
4363 hdd_ctx->config->rx_chain_mask_5g, PDEV_CMD);
4364 if (0 != ret_val)
4365 goto error;
4366 }
4367
4368 return 0;
4369
4370error:
4371 hdd_err("WMI PDEV set param failed %d", ret_val);
4372 return -EINVAL;
4373}
4374
4375/**
Arun Khandavalli2358d522016-05-16 18:05:37 +05304376 * hdd_set_fw_params() - Set parameters to firmware
4377 * @adapter: HDD adapter
4378 *
4379 * This function Sets various parameters to fw once the
4380 * adapter is started.
4381 *
4382 * Return: 0 on success or errno on failure
4383 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004384int hdd_set_fw_params(struct hdd_adapter *adapter)
Arun Khandavalli2358d522016-05-16 18:05:37 +05304385{
4386 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004387 struct hdd_context *hdd_ctx;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304388
Dustin Brownfdf17c12018-03-14 12:55:34 -07004389 hdd_enter_dev(adapter->dev);
Arun Khandavalli2358d522016-05-16 18:05:37 +05304390
4391 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
4392 if (!hdd_ctx)
4393 return -EINVAL;
4394
Dustin Brown732ab9c2017-06-15 13:24:09 -07004395 if (cds_get_conparam() == QDF_GLOBAL_FTM_MODE) {
4396 hdd_debug("FTM Mode is active; nothing to do");
4397 return 0;
4398 }
4399
Jeff Johnson1b780e42017-10-31 14:11:45 -07004400 ret = sme_cli_set_command(adapter->session_id,
Ashish Kumar Dhanotiyab8630ab2017-07-21 14:18:14 +05304401 WMI_PDEV_PARAM_DTIM_SYNTH,
4402 hdd_ctx->config->enable_lprx, PDEV_CMD);
4403 if (ret) {
4404 hdd_err("Failed to set LPRx");
4405 goto error;
4406 }
4407
Ashish Kumar Dhanotiya191d1642018-02-08 17:43:09 +05304408
4409 ret = sme_cli_set_command(
4410 adapter->session_id,
4411 WMI_PDEV_PARAM_1CH_DTIM_OPTIMIZED_CHAIN_SELECTION,
4412 hdd_ctx->config->enable_dtim_selection_diversity,
4413 PDEV_CMD);
4414 if (ret) {
4415 hdd_err("Failed to set DTIM_OPTIMIZED_CHAIN_SELECTION");
4416 goto error;
4417 }
4418
Ashish Kumar Dhanotiya48dac7d2018-03-28 14:59:50 +05304419 ret = sme_cli_set_command(
4420 adapter->session_id,
4421 WMI_PDEV_PARAM_TX_SCH_DELAY,
4422 hdd_ctx->config->enable_tx_sch_delay,
4423 PDEV_CMD);
4424 if (ret) {
4425 hdd_err("Failed to set WMI_PDEV_PARAM_TX_SCH_DELAY");
4426 goto error;
4427 }
4428
Ashish Kumar Dhanotiya959b38c2018-04-06 21:07:57 +05304429 ret = sme_cli_set_command(
4430 adapter->session_id,
4431 WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE,
4432 hdd_ctx->config->enable_secondary_rate,
4433 PDEV_CMD);
4434 if (ret) {
4435 hdd_err("Failed to set WMI_PDEV_PARAM_SECONDARY_RETRY_ENABLE");
4436 goto error;
4437 }
4438
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304439 if (adapter->device_mode == QDF_STA_MODE) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07004440 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304441 HDD_STA_SMPS_PARAM_UPPER_BRSSI_THRESH,
4442 hdd_ctx->config->upper_brssi_thresh);
4443
Jeff Johnson1b780e42017-10-31 14:11:45 -07004444 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304445 HDD_STA_SMPS_PARAM_LOWER_BRSSI_THRESH,
4446 hdd_ctx->config->lower_brssi_thresh);
4447
Jeff Johnson1b780e42017-10-31 14:11:45 -07004448 sme_set_smps_cfg(adapter->session_id,
Ashish Kumar Dhanotiyab28338c2017-07-21 20:12:34 +05304449 HDD_STA_SMPS_PARAM_DTIM_1CHRX_ENABLE,
4450 hdd_ctx->config->enable_dtim_1chrx);
4451 }
4452
Dustin Brown732ab9c2017-06-15 13:24:09 -07004453 if (hdd_ctx->config->enable2x2) {
4454 hdd_debug("configuring 2x2 mode fw params");
4455
Jeff Johnson1b780e42017-10-31 14:11:45 -07004456 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004457 WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE,
4458 hdd_ctx->config->enable_cck_tx_fir_override,
4459 PDEV_CMD);
4460 if (ret) {
4461 hdd_err("WMI_PDEV_PARAM_ENABLE_CCK_TXFIR_OVERRIDE set failed %d",
4462 ret);
4463 goto error;
4464 }
Liangwei Dong22810e82018-03-15 03:42:12 -04004465
4466 if (hdd_configure_chain_mask(adapter))
4467 goto error;
Dustin Brown732ab9c2017-06-15 13:24:09 -07004468 } else {
Arun Khandavalli2358d522016-05-16 18:05:37 +05304469#define HDD_DTIM_1CHAIN_RX_ID 0x5
4470#define HDD_SMPS_PARAM_VALUE_S 29
Dustin Brown732ab9c2017-06-15 13:24:09 -07004471 hdd_debug("configuring 1x1 mode fw params");
4472
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004473 /*
4474 * Disable DTIM 1 chain Rx when in 1x1,
4475 * we are passing two value
4476 * as param_id << 29 | param_value.
4477 * Below param_value = 0(disable)
4478 */
Jeff Johnson1b780e42017-10-31 14:11:45 -07004479 ret = sme_cli_set_command(adapter->session_id,
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004480 WMI_STA_SMPS_PARAM_CMDID,
4481 HDD_DTIM_1CHAIN_RX_ID <<
4482 HDD_SMPS_PARAM_VALUE_S,
4483 VDEV_CMD);
4484 if (ret) {
4485 hdd_err("DTIM 1 chain set failed %d", ret);
4486 goto error;
4487 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304488
Arun Khandavalli2358d522016-05-16 18:05:37 +05304489#undef HDD_DTIM_1CHAIN_RX_ID
4490#undef HDD_SMPS_PARAM_VALUE_S
Naveen Rawat269b4ed2017-12-07 06:47:32 -08004491
4492 if (hdd_configure_chain_mask(adapter))
4493 goto error;
Krishna Kumaar Natarajanaa938722016-08-21 23:18:53 -07004494 }
4495
Jeff Johnson1b780e42017-10-31 14:11:45 -07004496 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004497 WMI_PDEV_PARAM_HYST_EN,
4498 hdd_ctx->config->enableMemDeepSleep,
4499 PDEV_CMD);
4500 if (ret) {
4501 hdd_err("WMI_PDEV_PARAM_HYST_EN set failed %d", ret);
4502 goto error;
4503 }
Arun Khandavalli2358d522016-05-16 18:05:37 +05304504
Jeff Johnson1b780e42017-10-31 14:11:45 -07004505 ret = sme_cli_set_command(adapter->session_id,
Dustin Brown732ab9c2017-06-15 13:24:09 -07004506 WMI_VDEV_PARAM_ENABLE_RTSCTS,
4507 hdd_ctx->config->rts_profile,
4508 VDEV_CMD);
4509 if (ret) {
4510 hdd_err("FAILED TO SET RTSCTS Profile ret:%d", ret);
4511 goto error;
Arun Khandavalli2358d522016-05-16 18:05:37 +05304512 }
4513
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004514 hdd_debug("SET AMSDU num %d", hdd_ctx->config->max_amsdu_num);
4515
Jeff Johnson1b780e42017-10-31 14:11:45 -07004516 ret = wma_cli_set_command(adapter->session_id,
Deepak Dhamdhere612392c2016-08-28 02:56:51 -07004517 GEN_VDEV_PARAM_AMSDU,
4518 hdd_ctx->config->max_amsdu_num,
4519 GEN_CMD);
4520 if (ret != 0) {
4521 hdd_err("GEN_VDEV_PARAM_AMSDU set failed %d", ret);
4522 goto error;
4523 }
4524
Arun Khandavalli2358d522016-05-16 18:05:37 +05304525 hdd_set_fw_log_params(hdd_ctx, adapter);
Dustin Browne74003f2018-03-14 12:51:58 -07004526 hdd_exit();
Dustin Brown732ab9c2017-06-15 13:24:09 -07004527
Arun Khandavalli2358d522016-05-16 18:05:37 +05304528 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +05304529
Arun Khandavalli2358d522016-05-16 18:05:37 +05304530error:
4531 return -EINVAL;
4532}
4533
Ryan Hsu07495ea2016-01-21 15:25:39 -08004534/**
4535 * hdd_open_adapter() - open and setup the hdd adatper
4536 * @hdd_ctx: global hdd context
4537 * @session_type: type of the interface to be created
4538 * @iface_name: User-visible name of the interface
4539 * @macAddr: MAC address to assign to the interface
4540 * @name_assign_type: the name of assign type of the netdev
4541 * @rtnl_held: the rtnl lock hold flag
4542 *
4543 * This function open and setup the hdd adpater according to the device
4544 * type request, assign the name, the mac address assigned, and then prepared
4545 * the hdd related parameters, queue, lock and ready to start.
4546 *
4547 * Return: the pointer of hdd adapter, otherwise NULL.
4548 */
Jeff Johnson9d295242017-08-29 14:39:48 -07004549struct hdd_adapter *hdd_open_adapter(struct hdd_context *hdd_ctx, uint8_t session_type,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004550 const char *iface_name, tSirMacAddr macAddr,
Ryan Hsu07495ea2016-01-21 15:25:39 -08004551 unsigned char name_assign_type,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004552 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004553{
Jeff Johnson9d295242017-08-29 14:39:48 -07004554 struct hdd_adapter *adapter = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304555 QDF_STATUS status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004556
4557 if (hdd_ctx->current_intf_count >= hdd_ctx->max_intf_count) {
4558 /*
4559 * Max limit reached on the number of vdevs configured by the
4560 * host. Return error
4561 */
Arun Khandavallifae92942016-08-01 13:31:08 +05304562 hdd_err("Unable to add virtual intf: currentVdevCnt=%d,hostConfiguredVdevCnt=%d",
4563 hdd_ctx->current_intf_count, hdd_ctx->max_intf_count);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004564 return NULL;
4565 }
4566
4567 if (macAddr == NULL) {
4568 /* Not received valid macAddr */
Arun Khandavallifae92942016-08-01 13:31:08 +05304569 hdd_err("Unable to add virtual intf: Not able to get valid mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004570 return NULL;
4571 }
4572 status = hdd_check_for_existing_macaddr(hdd_ctx, macAddr);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304573 if (QDF_STATUS_E_FAILURE == status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304574 hdd_err("Duplicate MAC addr: " MAC_ADDRESS_STR
4575 " already exists",
4576 MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004577 return NULL;
4578 }
4579
4580 switch (session_type) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004581 case QDF_STA_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004582 /* Reset locally administered bit if the device mode is STA */
4583 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(macAddr);
Arunk Khandavalli794fdfc2017-09-13 18:00:40 +05304584 hdd_info("locally administered bit reset in sta mode: "
4585 MAC_ADDRESS_STR, MAC_ADDR_ARRAY(macAddr));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004586 /* fall through */
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004587 case QDF_P2P_CLIENT_MODE:
4588 case QDF_P2P_DEVICE_MODE:
4589 case QDF_OCB_MODE:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07004590 case QDF_NDI_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304591 case QDF_MONITOR_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004592 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4593 name_assign_type,
4594 iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004595
4596 if (NULL == adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05304597 hdd_err("failed to allocate adapter for session %d",
4598 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004599 return NULL;
4600 }
4601
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004602 if (QDF_P2P_CLIENT_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004603 adapter->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004604 else if (QDF_P2P_DEVICE_MODE == session_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004605 adapter->wdev.iftype = NL80211_IFTYPE_P2P_DEVICE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304606 else if (QDF_MONITOR_MODE == session_type)
4607 adapter->wdev.iftype = NL80211_IFTYPE_MONITOR;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004608 else
4609 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4610
4611 adapter->device_mode = session_type;
4612
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004613
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004614 /*
4615 * Workqueue which gets scheduled in IPv4 notification
4616 * callback
4617 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004618 INIT_WORK(&adapter->ipv4_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004619 hdd_ipv4_notifier_work_queue);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004620
4621#ifdef WLAN_NS_OFFLOAD
4622 /*
4623 * Workqueue which gets scheduled in IPv6
4624 * notification callback.
4625 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004626 INIT_WORK(&adapter->ipv6_notifier_work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004627 hdd_ipv6_notifier_work_queue);
4628#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004629 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004630 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004631 goto err_free_netdev;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004632
4633 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004634 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004635 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304636 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4637 WLAN_CONTROL_PATH);
Arun Khandavallifae92942016-08-01 13:31:08 +05304638
Ravi Joshi1a292562017-05-18 16:28:54 -07004639 /* Initialize NAN Data Interface */
4640 if (QDF_NDI_MODE == session_type) {
4641 status = hdd_init_nan_data_mode(adapter);
4642 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004643 goto err_free_netdev;
Ravi Joshi1a292562017-05-18 16:28:54 -07004644 }
4645
Alok Kumarb64650c2018-03-23 17:05:11 +05304646 hdd_nud_init_tracking(adapter);
4647
4648 qdf_mutex_create(&adapter->disconnection_status_lock);
4649
Ravi Joshi1a292562017-05-18 16:28:54 -07004650 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004651
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004652 case QDF_P2P_GO_MODE:
4653 case QDF_SAP_MODE:
Ryan Hsu07495ea2016-01-21 15:25:39 -08004654 adapter = hdd_wlan_create_ap_dev(hdd_ctx, macAddr,
4655 name_assign_type,
4656 (uint8_t *) iface_name);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004657 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004658 hdd_err("failed to allocate adapter for session %d",
Arun Khandavallifae92942016-08-01 13:31:08 +05304659 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004660 return NULL;
4661 }
4662
4663 adapter->wdev.iftype =
4664 (session_type ==
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004665 QDF_SAP_MODE) ? NL80211_IFTYPE_AP :
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004666 NL80211_IFTYPE_P2P_GO;
4667 adapter->device_mode = session_type;
4668
Mahesh Kumar Kalikot Veetilaff94862017-07-28 11:06:19 -07004669 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004670 if (QDF_STATUS_SUCCESS != status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004671 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004672
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004673 hdd_debug("Disabling queues");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004674 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304675 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4676 WLAN_CONTROL_PATH);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304677
4678 /*
4679 * Workqueue which gets scheduled in IPv4 notification
4680 * callback
4681 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004682 INIT_WORK(&adapter->ipv4_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304683 hdd_ipv4_notifier_work_queue);
4684
4685#ifdef WLAN_NS_OFFLOAD
4686 /*
4687 * Workqueue which gets scheduled in IPv6
4688 * notification callback.
4689 */
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004690 INIT_WORK(&adapter->ipv6_notifier_work,
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05304691 hdd_ipv6_notifier_work_queue);
4692#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004693 break;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304694 case QDF_FTM_MODE:
4695 adapter = hdd_alloc_station_adapter(hdd_ctx, macAddr,
4696 name_assign_type,
Lin Bai1c678482017-12-18 18:29:11 +08004697 iface_name);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304698 if (NULL == adapter) {
4699 hdd_err("Failed to allocate adapter for FTM mode");
4700 return NULL;
4701 }
4702 adapter->wdev.iftype = NL80211_IFTYPE_STATION;
4703 adapter->device_mode = session_type;
4704 status = hdd_register_interface(adapter, rtnl_held);
Krunal Sonib51eec72017-11-20 21:53:01 -08004705 if (QDF_STATUS_SUCCESS != status)
Jingxiang Geb49aa302018-01-17 20:54:15 +08004706 goto err_free_netdev;
Krunal Sonib51eec72017-11-20 21:53:01 -08004707
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304708 /* Stop the Interface TX queue. */
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004709 hdd_debug("Disabling queues");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304710 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304711 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4712 WLAN_CONTROL_PATH);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304713 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004714 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004715 hdd_err("Invalid session type %d", session_type);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304716 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004717 return NULL;
4718 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004719
hqueaa33ee2017-05-04 17:56:35 +08004720 INIT_WORK(&adapter->scan_block_work, wlan_hdd_cfg80211_scan_block_cb);
4721
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304722 if (QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004723 /* Add it to the hdd's session list. */
Dustin Brown920397d2017-12-13 16:27:50 -08004724 status = hdd_add_adapter_back(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004725 }
4726
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304727 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004728 if (NULL != adapter) {
4729 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4730 adapter = NULL;
4731 }
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004732
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004733 return NULL;
4734 }
4735
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304736 if (QDF_STATUS_SUCCESS == status) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08004737 policy_mgr_set_concurrency_mode(hdd_ctx->hdd_psoc,
4738 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004739
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004740 /* Adapter successfully added. Increment the vdev count */
4741 hdd_ctx->current_intf_count++;
4742
Jeff Johnson5880d792016-08-15 13:32:30 -07004743 hdd_debug("current_intf_count=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004744 hdd_ctx->current_intf_count);
4745
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08004746 hdd_check_and_restart_sap_with_non_dfs_acs();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004747 }
4748
Rajeev Kumardca5f812016-02-04 17:28:06 -08004749 if (QDF_STATUS_SUCCESS != hdd_debugfs_init(adapter))
Mahesh Kumar Kalikot Veetil80dda9a2017-07-17 11:38:03 -07004750 hdd_err("Interface %s wow debug_fs init failed",
4751 netdev_name(adapter->dev));
4752
4753 hdd_info("%s interface created. iftype: %d", netdev_name(adapter->dev),
4754 session_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004755
4756 return adapter;
4757
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004758err_free_netdev:
Jeff Johnson1e851a12017-10-28 14:36:12 -07004759 wlan_hdd_release_intf_addr(hdd_ctx, adapter->mac_addr.bytes);
Hanumanth Reddy Pothula00a39e72016-11-09 21:32:16 +05304760 free_netdev(adapter->dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004761
4762 return NULL;
4763}
4764
Nirav Shaheb017be2018-02-15 11:20:58 +05304765#ifdef MSM_PLATFORM
4766static inline
4767void hdd_cancel_bus_bw_work(struct hdd_context *hdd_ctx)
4768{
4769 cancel_work_sync(&hdd_ctx->bus_bw_work);
4770}
4771#else
4772static inline
4773void hdd_cancel_bus_bw_work(struct hdd_context *hdd_ctx)
4774{
4775}
4776#endif
4777
Jeff Johnson9d295242017-08-29 14:39:48 -07004778QDF_STATUS hdd_close_adapter(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004779 bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004780{
Dustin Brown920397d2017-12-13 16:27:50 -08004781 /*
4782 * Here we are stopping global bus_bw timer & work per adapter.
4783 *
4784 * The reason is to fix one race condition between
4785 * bus bandwidth work and cleaning up an adapter.
4786 * Under some conditions, it is possible for the bus bandwidth
4787 * work to access a particularly destroyed adapter, leading to
4788 * use-after-free.
4789 */
4790 hdd_debug("wait for bus bw work to flush");
4791 hdd_bus_bw_compute_timer_stop(hdd_ctx);
4792 hdd_bus_bw_cancel_work(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004793
Dustin Brown920397d2017-12-13 16:27:50 -08004794 /* cleanup adapter */
4795 policy_mgr_clear_concurrency_mode(hdd_ctx->hdd_psoc,
4796 adapter->device_mode);
4797 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4798 hdd_remove_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004799
Dustin Brown920397d2017-12-13 16:27:50 -08004800 /* conditionally restart the bw timer */
4801 hdd_bus_bw_compute_timer_try_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004802
Dustin Brown920397d2017-12-13 16:27:50 -08004803 /* Adapter removed. Decrement vdev count */
4804 if (hdd_ctx->current_intf_count != 0)
4805 hdd_ctx->current_intf_count--;
Dustin Brown5ec6b552017-03-31 12:11:40 -07004806
Dustin Brown920397d2017-12-13 16:27:50 -08004807 /* Fw will take care incase of concurrency */
4808 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004809}
4810
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004811/**
4812 * hdd_close_all_adapters - Close all open adapters
4813 * @hdd_ctx: Hdd context
4814 * rtnl_held: True if RTNL lock held
4815 *
4816 * Close all open adapters.
4817 *
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304818 * Return: QDF status code
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08004819 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07004820QDF_STATUS hdd_close_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004821{
Dustin Brown920397d2017-12-13 16:27:50 -08004822 struct hdd_adapter *adapter;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304823 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004824
Dustin Brown491d54b2018-03-14 12:39:11 -07004825 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004826
4827 do {
Dustin Brown920397d2017-12-13 16:27:50 -08004828 status = hdd_remove_front_adapter(hdd_ctx, &adapter);
4829 if (QDF_IS_STATUS_SUCCESS(status)) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304830 wlan_hdd_release_intf_addr(hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08004831 adapter->mac_addr.bytes);
4832 hdd_cleanup_adapter(hdd_ctx, adapter, rtnl_held);
4833
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +05304834 /* Adapter removed. Decrement vdev count */
4835 if (hdd_ctx->current_intf_count != 0)
4836 hdd_ctx->current_intf_count--;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004837 }
Dustin Brown920397d2017-12-13 16:27:50 -08004838 } while (QDF_IS_STATUS_SUCCESS(status));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004839
Dustin Browne74003f2018-03-14 12:51:58 -07004840 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004841
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304842 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004843}
4844
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004845void wlan_hdd_reset_prob_rspies(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004846{
Anurag Chouhan6d760662016-02-20 16:05:43 +05304847 struct qdf_mac_addr *bssid = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004848 tSirUpdateIE updateIE;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004849
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004850 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004851 case QDF_STA_MODE:
4852 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004853 {
Jeff Johnsond377dce2017-10-04 10:32:42 -07004854 struct hdd_station_ctx *sta_ctx =
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004855 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -07004856 bssid = &sta_ctx->conn_info.bssId;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004857 break;
4858 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004859 case QDF_SAP_MODE:
4860 case QDF_P2P_GO_MODE:
4861 case QDF_IBSS_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004862 {
Jeff Johnson1e851a12017-10-28 14:36:12 -07004863 bssid = &adapter->mac_addr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004864 break;
4865 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004866 case QDF_FTM_MODE:
4867 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004868 default:
4869 /*
4870 * wlan_hdd_reset_prob_rspies should not have been called
4871 * for these kind of devices
4872 */
Jeff Johnson5880d792016-08-15 13:32:30 -07004873 hdd_err("Unexpected request for the current device type %d",
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004874 adapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004875 return;
4876 }
4877
Anurag Chouhanc5548422016-02-24 18:33:27 +05304878 qdf_copy_macaddr(&updateIE.bssid, bssid);
Jeff Johnson1b780e42017-10-31 14:11:45 -07004879 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004880 updateIE.ieBufferlength = 0;
4881 updateIE.pAdditionIEBuffer = NULL;
4882 updateIE.append = true;
4883 updateIE.notify = false;
Jeff Johnson9c4f93d2017-10-04 08:56:22 -07004884 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004885 &updateIE,
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304886 eUPDATE_IE_PROBE_RESP) == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07004887 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004888 }
4889}
4890
Dustin Browndb2a8be2017-12-20 11:49:56 -08004891QDF_STATUS hdd_stop_adapter(struct hdd_context *hdd_ctx,
4892 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004893{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05304894 QDF_STATUS qdf_ret_status = QDF_STATUS_SUCCESS;
Jeff Johnson025618c2018-03-18 14:41:00 -07004895 struct csr_roam_profile *roam_profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004896 union iwreq_data wrqu;
4897 tSirUpdateIE updateIE;
4898 unsigned long rc;
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05304899 tsap_Config_t *sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004900
Dustin Brown491d54b2018-03-14 12:39:11 -07004901 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004902
Alok Kumarb64650c2018-03-23 17:05:11 +05304903 hdd_nud_ignore_tracking(adapter, true);
4904 hdd_nud_reset_tracking(adapter);
4905
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07004906 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +05304907 wlan_hdd_netif_queue_control(adapter,
4908 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
4909 WLAN_CONTROL_PATH);
Tushnim Bhattacharyya9bd058f2017-12-27 14:01:31 -08004910 /*
4911 * if this is the last active connection check & stop the
4912 * opportunistic timer first
4913 */
4914 if (((policy_mgr_get_connection_count(hdd_ctx->hdd_psoc) == 1) &&
4915 (policy_mgr_mode_specific_connection_count(hdd_ctx->hdd_psoc,
4916 policy_mgr_convert_device_mode_to_qdf_type(
4917 adapter->device_mode), NULL) == 1)) ||
4918 !policy_mgr_get_connection_count(hdd_ctx->hdd_psoc))
4919 policy_mgr_check_and_stop_opportunistic_timer(
4920 hdd_ctx->hdd_psoc, adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004921 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08004922 case QDF_STA_MODE:
4923 case QDF_P2P_CLIENT_MODE:
4924 case QDF_IBSS_MODE:
4925 case QDF_P2P_DEVICE_MODE:
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004926 case QDF_NDI_MODE:
4927 if ((QDF_NDI_MODE == adapter->device_mode) ||
4928 hdd_conn_is_connected(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004929 WLAN_HDD_GET_STATION_CTX_PTR(adapter)) ||
4930 hdd_is_connecting(
4931 WLAN_HDD_GET_STATION_CTX_PTR(adapter))) {
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004932 INIT_COMPLETION(adapter->disconnect_comp_var);
Jeff Johnson025618c2018-03-18 14:41:00 -07004933 roam_profile = hdd_roam_profile(adapter);
4934 /* For NDI do not use roam_profile */
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004935 if (QDF_NDI_MODE == adapter->device_mode)
4936 qdf_ret_status = sme_roam_disconnect(
4937 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004938 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004939 eCSR_DISCONNECT_REASON_NDI_DELETE);
Jeff Johnson025618c2018-03-18 14:41:00 -07004940 else if (roam_profile->BSSType ==
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004941 eCSR_BSS_TYPE_START_IBSS)
4942 qdf_ret_status = sme_roam_disconnect(
4943 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004944 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004945 eCSR_DISCONNECT_REASON_IBSS_LEAVE);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004946 else if (QDF_STA_MODE == adapter->device_mode) {
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004947 qdf_ret_status =
4948 wlan_hdd_try_disconnect(adapter);
Jingxiang Gecc7e1f42017-11-14 16:21:27 +08004949 hdd_debug("Send disconnected event to userspace");
4950 wlan_hdd_cfg80211_indicate_disconnect(
4951 adapter->dev, true,
4952 WLAN_REASON_UNSPECIFIED);
Jeff Johnson109e79d2018-02-27 15:10:04 -08004953 } else
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004954 qdf_ret_status = sme_roam_disconnect(
4955 hdd_ctx->hHal,
Jeff Johnson1b780e42017-10-31 14:11:45 -07004956 adapter->session_id,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07004957 eCSR_DISCONNECT_REASON_UNSPECIFIED);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004958 /* success implies disconnect command got
4959 * queued up successfully
4960 */
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004961 if (qdf_ret_status == QDF_STATUS_SUCCESS &&
4962 QDF_STA_MODE != adapter->device_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004963 rc = wait_for_completion_timeout(
4964 &adapter->disconnect_comp_var,
4965 msecs_to_jiffies
4966 (WLAN_WAIT_TIME_DISCONNECT));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08004967 if (!rc)
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004968 hdd_warn("disconn_comp_var wait fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004969 }
Varun Reddy Yeturu96dced72017-03-29 18:03:54 -07004970 if (qdf_ret_status != QDF_STATUS_SUCCESS)
4971 hdd_warn("failed to post disconnect");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004972 memset(&wrqu, '\0', sizeof(wrqu));
4973 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
4974 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
4975 wireless_send_event(adapter->dev, SIOCGIWAP, &wrqu,
4976 NULL);
Sachin Ahuja988fd102016-09-15 17:16:25 +05304977 }
Wu Gaoaceec6c2017-08-30 16:08:21 +08004978 wlan_hdd_scan_abort(adapter);
Srinivas Girigowdab841da72017-03-25 18:04:39 -07004979
Abhishek Singh1e94d7a2015-11-30 17:26:54 +05304980 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
Sridhar Selvaraj8c6f5e82017-08-21 14:53:46 +05304981 hdd_clear_fils_connection_info(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004982
4983#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004984 cancel_work_sync(&adapter->ipv4_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004985#endif
4986
4987 hdd_deregister_tx_flow_control(adapter);
4988
4989#ifdef WLAN_NS_OFFLOAD
4990#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07004991 cancel_work_sync(&adapter->ipv6_notifier_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004992#endif
4993#endif
4994
Hanumanth Reddy Pothula05860142017-07-26 18:45:27 +05304995 if (adapter->device_mode == QDF_STA_MODE)
4996 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
4997 adapter->dev);
Dustin Browndb2a8be2017-12-20 11:49:56 -08004998
4999 if (wlan_hdd_try_disconnect(adapter)) {
5000 hdd_err("Error: Can't disconnect adapter");
5001 return QDF_STATUS_E_FAILURE;
Krunal Soni985b8132017-02-10 18:49:08 -08005002 }
Dustin Browndb2a8be2017-12-20 11:49:56 -08005003
Himanshu Agarwalb229a142017-12-21 10:16:45 +05305004 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005005 break;
5006
Rajeev Kumar3b906202018-02-01 10:55:14 -08005007 case QDF_MONITOR_MODE:
5008 wlan_hdd_scan_abort(adapter);
5009 hdd_deregister_tx_flow_control(adapter);
5010 hdd_vdev_destroy(adapter);
5011 break;
5012
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005013 case QDF_SAP_MODE:
wadesongf9b15ed2017-12-14 14:12:32 +08005014 wlan_hdd_scan_abort(adapter);
Govind Singh1dab23b2017-08-12 13:31:00 +05305015 /* Flush IPA exception path packets */
Arunk Khandavalli96c122f2017-10-17 11:49:36 +05305016 sap_config = &adapter->session.ap.sap_config;
5017 if (sap_config)
5018 wlansap_reset_sap_config_add_ie(sap_config,
5019 eUPDATE_IE_ALL);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05305020 ucfg_ipa_flush(hdd_ctx->hdd_pdev);
Rajeev Kumar6e0cbff2017-12-01 18:14:30 -08005021 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
Jeff Johnson46807cd2018-04-29 21:32:22 -07005022 /* fallthrough */
Dustin Browna5cf8e02017-10-19 16:04:19 -07005023
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005024 case QDF_P2P_GO_MODE:
Kiran Kumar Lokere85cb36b2017-09-14 15:19:14 -07005025 if (QDF_SAP_MODE == adapter->device_mode) {
5026 if (test_bit(ACS_PENDING, &adapter->event_flags)) {
5027 cds_flush_delayed_work(
5028 &adapter->acs_pending_work);
5029 clear_bit(ACS_PENDING, &adapter->event_flags);
5030 }
5031 }
Krunal Soni22208392017-09-29 18:10:34 -07005032 cds_flush_work(&adapter->sap_stop_bss_work);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005033
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005034 /* Any softap specific cleanup here... */
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305035 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Dustin Browna5cf8e02017-10-19 16:04:19 -07005036 wlan_hdd_undo_acs(adapter);
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005037 if (adapter->device_mode == QDF_P2P_GO_MODE)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005038 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5039
5040 hdd_deregister_tx_flow_control(adapter);
5041
Kapil Guptac1224bf2017-06-22 21:22:40 +05305042 hdd_destroy_acs_timer(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005043 mutex_lock(&hdd_ctx->sap_lock);
5044 if (test_bit(SOFTAP_BSS_STARTED, &adapter->event_flags)) {
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305045 QDF_STATUS status;
Anurag Chouhance0dc992016-02-16 18:18:03 +05305046 QDF_STATUS qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005047
5048 /* Stop Bss. */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005049 status = wlansap_stop_bss(
5050 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005051
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305052 if (QDF_IS_STATUS_SUCCESS(status)) {
Jeff Johnsonca2530c2017-09-30 18:25:40 -07005053 struct hdd_hostapd_state *hostapd_state =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005054 WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305055 qdf_event_reset(&hostapd_state->
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05305056 qdf_stop_bss_event);
Anurag Chouhance0dc992016-02-16 18:18:03 +05305057 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +05305058 qdf_wait_for_event_completion(
5059 &hostapd_state->qdf_stop_bss_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -08005060 SME_CMD_TIMEOUT_VALUE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005061
Anurag Chouhance0dc992016-02-16 18:18:03 +05305062 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005063 hdd_err("failure waiting for wlansap_stop_bss %d",
5064 qdf_status);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005065 }
5066 } else {
Jeff Johnson5880d792016-08-15 13:32:30 -07005067 hdd_err("failure in wlansap_stop_bss");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005068 }
5069 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005070 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
5071 adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005072 adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005073 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305074 adapter->device_mode,
5075 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005076
Anurag Chouhanc5548422016-02-24 18:33:27 +05305077 qdf_copy_macaddr(&updateIE.bssid,
Jeff Johnson1e851a12017-10-28 14:36:12 -07005078 &adapter->mac_addr);
Jeff Johnson1b780e42017-10-31 14:11:45 -07005079 updateIE.smeSessionId = adapter->session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005080 updateIE.ieBufferlength = 0;
5081 updateIE.pAdditionIEBuffer = NULL;
5082 updateIE.append = false;
5083 updateIE.notify = false;
5084 /* Probe bcn reset */
5085 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
5086 &updateIE, eUPDATE_IE_PROBE_BCN)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305087 == QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005088 hdd_err("Could not pass on PROBE_RSP_BCN data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005089 }
5090 /* Assoc resp reset */
5091 if (sme_update_add_ie(WLAN_HDD_GET_HAL_CTX(adapter),
5092 &updateIE,
5093 eUPDATE_IE_ASSOC_RESP) ==
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305094 QDF_STATUS_E_FAILURE) {
Jeff Johnson5880d792016-08-15 13:32:30 -07005095 hdd_err("Could not pass on ASSOC_RSP data to PE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005096 }
5097 /* Reset WNI_CFG_PROBE_RSP Flags */
5098 wlan_hdd_reset_prob_rspies(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005099 }
Jeff Johnsonb9424862017-10-30 08:49:35 -07005100 qdf_mem_free(adapter->session.ap.beacon);
5101 adapter->session.ap.beacon = NULL;
Ajit Pal Singh747b6802017-05-24 15:42:03 +05305102 /*
5103 * If Do_Not_Break_Stream was enabled clear avoid channel list.
5104 */
5105 if (policy_mgr_is_dnsc_set(adapter->hdd_vdev))
5106 wlan_hdd_send_avoid_freq_for_dnbs(hdd_ctx, 0);
5107
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305108#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005109 cancel_work_sync(&adapter->ipv4_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305110#endif
5111
5112#ifdef WLAN_NS_OFFLOAD
5113#ifdef WLAN_OPEN_SOURCE
Jeff Johnsonb527ebe2017-10-28 13:14:03 -07005114 cancel_work_sync(&adapter->ipv6_notifier_work);
Hanumanth Reddy Pothulaaaa3f882017-10-05 17:45:00 +05305115#endif
5116#endif
Dustin Browndb2a8be2017-12-20 11:49:56 -08005117
5118 hdd_vdev_destroy(adapter);
5119
Krunal Sonib51eec72017-11-20 21:53:01 -08005120 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005121 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005122 case QDF_OCB_MODE:
Krishna Kumaar Natarajane58b4092017-01-25 15:47:35 -08005123 cdp_clear_peer(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08005124 (struct cdp_pdev *)cds_get_context(QDF_MODULE_ID_TXRX),
Leo Changfdb45c32016-10-28 11:09:23 -07005125 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.staId[0]);
Zhang Qian79d0d132018-02-05 13:40:16 +08005126 hdd_deregister_tx_flow_control(adapter);
5127 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005128 break;
5129 default:
5130 break;
5131 }
5132
Dustin Brown04348372017-12-14 16:13:39 -08005133 if (adapter->scan_info.default_scan_ies) {
5134 qdf_mem_free(adapter->scan_info.default_scan_ies);
5135 adapter->scan_info.default_scan_ies = NULL;
5136 }
5137
Dustin Browne74003f2018-03-14 12:51:58 -07005138 hdd_exit();
Dustin Brown04348372017-12-14 16:13:39 -08005139
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305140 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005141}
5142
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305143/**
5144 * hdd_deinit_all_adapters - deinit all adapters
5145 * @hdd_ctx: HDD context
5146 * @rtnl_held: True if RTNL lock held
5147 *
5148 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005149void hdd_deinit_all_adapters(struct hdd_context *hdd_ctx, bool rtnl_held)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305150{
Jeff Johnson9d295242017-08-29 14:39:48 -07005151 struct hdd_adapter *adapter;
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305152
Dustin Brown491d54b2018-03-14 12:39:11 -07005153 hdd_enter();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305154
Dustin Brown920397d2017-12-13 16:27:50 -08005155 hdd_for_each_adapter(hdd_ctx, adapter)
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305156 hdd_deinit_adapter(hdd_ctx, adapter, rtnl_held);
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305157
Dustin Browne74003f2018-03-14 12:51:58 -07005158 hdd_exit();
Hanumanth Reddy Pothula9f4048f2016-09-30 15:06:57 +05305159}
5160
Dustin Browndb2a8be2017-12-20 11:49:56 -08005161QDF_STATUS hdd_stop_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005162{
Jeff Johnson9d295242017-08-29 14:39:48 -07005163 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005164
Dustin Brown491d54b2018-03-14 12:39:11 -07005165 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005166
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305167 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5168
Dustin Brown920397d2017-12-13 16:27:50 -08005169 hdd_for_each_adapter(hdd_ctx, adapter)
Dustin Browndb2a8be2017-12-20 11:49:56 -08005170 hdd_stop_adapter(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005171
Dustin Browne74003f2018-03-14 12:51:58 -07005172 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005173
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305174 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005175}
5176
Paul Zhang84fa9382017-11-10 21:18:21 +08005177static void hdd_reset_scan_operation(struct hdd_context *hdd_ctx,
5178 struct hdd_adapter *adapter)
5179{
5180 switch (adapter->device_mode) {
5181 case QDF_STA_MODE:
5182 case QDF_P2P_CLIENT_MODE:
5183 case QDF_IBSS_MODE:
5184 case QDF_P2P_DEVICE_MODE:
5185 case QDF_NDI_MODE:
5186 wlan_hdd_scan_abort(adapter);
5187 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5188 if (adapter->device_mode == QDF_STA_MODE)
5189 wlan_cfg80211_sched_scan_stop(hdd_ctx->hdd_pdev,
5190 adapter->dev);
5191 break;
5192 case QDF_P2P_GO_MODE:
5193 wlan_hdd_cleanup_remain_on_channel_ctx(adapter);
5194 break;
5195 case QDF_SAP_MODE:
Abhinav Kumarb638b5d2018-03-26 12:25:41 +05305196 qdf_atomic_set(&adapter->session.ap.acs_in_progress, 0);
Paul Zhang84fa9382017-11-10 21:18:21 +08005197 wlan_hdd_undo_acs(adapter);
5198 break;
5199 default:
5200 break;
5201 }
5202}
5203
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005204QDF_STATUS hdd_reset_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005205{
Jeff Johnson9d295242017-08-29 14:39:48 -07005206 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07005207 struct hdd_station_ctx *sta_ctx;
Yue Mad5b4b9f2017-05-26 16:23:40 -07005208 struct qdf_mac_addr peerMacAddr;
Yue Ma42654682018-01-11 16:55:24 -08005209 int sta_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005210
Dustin Brown491d54b2018-03-14 12:39:11 -07005211 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005212
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +05305213 cds_flush_work(&hdd_ctx->sap_pre_cac_work);
5214
Dustin Brown920397d2017-12-13 16:27:50 -08005215 hdd_for_each_adapter(hdd_ctx, adapter) {
Dustin Brown5e89ef82018-03-14 11:50:23 -07005216 hdd_info("[SSR] reset adapter with device mode %s(%d)",
5217 hdd_device_mode_to_string(adapter->device_mode),
5218 adapter->device_mode);
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305219
5220 if ((adapter->device_mode == QDF_STA_MODE) ||
Paul Zhang679025e2018-03-08 22:39:44 +08005221 (adapter->device_mode == QDF_P2P_CLIENT_MODE)) {
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305222 /* Stop tdls timers */
Kabilan Kannan00d20412017-06-04 14:20:32 -07005223 hdd_notify_tdls_reset_adapter(adapter->hdd_vdev);
Paul Zhang679025e2018-03-08 22:39:44 +08005224 adapter->session.station.hdd_reassoc_scenario = false;
5225 }
Ganesh Kondabattini9e4fbbb2017-05-24 16:53:02 +05305226
Arun Khandavallicc544b32017-01-30 19:52:16 +05305227 if (hdd_ctx->config->sap_internal_restart &&
5228 adapter->device_mode == QDF_SAP_MODE) {
5229 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305230 WLAN_STOP_ALL_NETIF_QUEUE,
Arun Khandavallicc544b32017-01-30 19:52:16 +05305231 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005232 if (test_bit(SOFTAP_BSS_STARTED,
Krunal Sonib51eec72017-11-20 21:53:01 -08005233 &adapter->event_flags))
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005234 hdd_sap_indicate_disconnect_for_sta(adapter);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005235 clear_bit(SOFTAP_BSS_STARTED, &adapter->event_flags);
5236 } else {
Arun Khandavallicc544b32017-01-30 19:52:16 +05305237 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +05305238 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005239 WLAN_CONTROL_PATH);
Manikandan Mohan0a44ec82017-02-17 15:06:11 -08005240 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005241
Paul Zhang84fa9382017-11-10 21:18:21 +08005242 hdd_reset_scan_operation(hdd_ctx, adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005243
5244 hdd_deinit_tx_rx(adapter);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08005245 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07005246 adapter->device_mode, adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -07005247 hdd_green_ap_start_state_mc(hdd_ctx, adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +05305248 false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005249 if (test_bit(WMM_INIT_DONE, &adapter->event_flags)) {
5250 hdd_wmm_adapter_close(adapter);
5251 clear_bit(WMM_INIT_DONE, &adapter->event_flags);
5252 }
5253
Vignesh Viswanathan2eb18742017-09-08 11:18:59 +05305254 if (adapter->device_mode == QDF_STA_MODE)
5255 hdd_clear_fils_connection_info(adapter);
5256
Wu Gao3545e642017-07-14 19:24:41 +08005257 if (adapter->device_mode == QDF_SAP_MODE) {
5258 /*
5259 * If adapter is SAP, set session ID to invalid
5260 * since SAP session will be cleanup during SSR.
5261 */
Wu Gao36717432016-11-21 15:09:48 +08005262 wlansap_set_invalid_session(
5263 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5264
Wu Gao3545e642017-07-14 19:24:41 +08005265 wlansap_cleanup_cac_timer(
5266 WLAN_HDD_GET_SAP_CTX_PTR(adapter));
5267 }
5268
Yue Ma42654682018-01-11 16:55:24 -08005269 /* Delete connection peers if any to avoid peer object leaks */
Yue Mad5b4b9f2017-05-26 16:23:40 -07005270 if (adapter->device_mode == QDF_STA_MODE ||
5271 adapter->device_mode == QDF_P2P_CLIENT_MODE) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07005272 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005273 qdf_copy_macaddr(&peerMacAddr,
Jeff Johnsond377dce2017-10-04 10:32:42 -07005274 &sta_ctx->conn_info.bssId);
Yue Mad5b4b9f2017-05-26 16:23:40 -07005275
5276 hdd_objmgr_remove_peer_object(adapter->hdd_vdev,
5277 peerMacAddr.bytes);
Yue Ma42654682018-01-11 16:55:24 -08005278 } else if (adapter->device_mode == QDF_P2P_GO_MODE) {
5279 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT; sta_id++) {
5280 if (adapter->sta_info[sta_id].in_use) {
5281 hdd_debug("[SSR] deregister STA with ID %d",
5282 sta_id);
5283 hdd_softap_deregister_sta(adapter,
5284 sta_id);
5285 adapter->sta_info[sta_id].in_use = 0;
5286 }
5287 }
Yue Mad5b4b9f2017-05-26 16:23:40 -07005288 }
5289
Alok Kumarb64650c2018-03-23 17:05:11 +05305290 hdd_nud_reset_tracking(adapter);
5291 hdd_nud_ignore_tracking(adapter, true);
5292 hdd_set_disconnect_status(adapter, false);
5293
Tiger Yu94a5a5c2018-03-09 21:22:26 +08005294 hdd_softap_deinit_tx_rx(adapter);
5295
Yue Maf9782842017-05-08 12:49:49 -07005296 /* Destroy vdev which will be recreated during reinit. */
5297 hdd_vdev_destroy(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005298 }
5299
Dustin Browne74003f2018-03-14 12:51:58 -07005300 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005301
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305302 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005303}
5304
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005305bool hdd_check_for_opened_interfaces(struct hdd_context *hdd_ctx)
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305306{
Dustin Brown920397d2017-12-13 16:27:50 -08005307 struct hdd_adapter *adapter;
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305308 bool close_modules = true;
5309
Arun Khandavalliba479c42017-07-26 21:29:40 +05305310 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
5311 hdd_info("FTM mode, don't close the module");
5312 return false;
5313 }
5314
Dustin Brown920397d2017-12-13 16:27:50 -08005315 hdd_for_each_adapter(hdd_ctx, adapter) {
5316 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags) ||
5317 test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005318 hdd_debug("Still other ifaces are up cannot close modules");
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305319 close_modules = false;
5320 break;
5321 }
Ashish Kumar Dhanotiya486c13a2017-03-03 12:57:56 +05305322 }
5323
5324 return close_modules;
5325}
5326
yeshwanth sriram guntukaea63f632017-08-30 19:31:56 +05305327bool hdd_is_interface_up(struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +05305328{
5329 if (test_bit(DEVICE_IFACE_OPENED, &adapter->event_flags))
5330 return true;
5331 else
5332 return false;
5333}
5334
Anurag Chouhanc4092922016-09-08 15:56:11 +05305335#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)) \
bingsbdcd4a22017-06-20 09:27:00 +08005336 && !defined(WITH_BACKPORTS) && !defined(IEEE80211_PRIVACY)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305337struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5338 struct ieee80211_channel *channel,
5339 const u8 *bssid, const u8 *ssid,
5340 size_t ssid_len)
5341{
5342 return cfg80211_get_bss(wiphy, channel, bssid,
5343 ssid, ssid_len,
5344 WLAN_CAPABILITY_ESS,
5345 WLAN_CAPABILITY_ESS);
5346}
5347#else
5348struct cfg80211_bss *hdd_cfg80211_get_bss(struct wiphy *wiphy,
5349 struct ieee80211_channel *channel,
5350 const u8 *bssid, const u8 *ssid,
5351 size_t ssid_len)
5352{
5353 return cfg80211_get_bss(wiphy, channel, bssid,
5354 ssid, ssid_len,
5355 IEEE80211_BSS_TYPE_ESS,
5356 IEEE80211_PRIVACY_ANY);
5357}
5358#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305359
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305360#if defined CFG80211_CONNECT_BSS || \
5361 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305362#if defined CFG80211_CONNECT_TIMEOUT_REASON_CODE || \
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305363 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305364/**
5365 * hdd_convert_timeout_reason() - Convert to kernel specific enum
5366 * @timeout_reason: reason for connect timeout
5367 *
5368 * This function is used to convert host timeout
5369 * reason enum to kernel specific enum.
5370 *
5371 * Return: nl timeout enum
5372 */
5373static enum nl80211_timeout_reason hdd_convert_timeout_reason(
5374 tSirResultCodes timeout_reason)
5375{
5376 switch (timeout_reason) {
5377 case eSIR_SME_JOIN_TIMEOUT_RESULT_CODE:
5378 return NL80211_TIMEOUT_SCAN;
5379 case eSIR_SME_AUTH_TIMEOUT_RESULT_CODE:
5380 return NL80211_TIMEOUT_AUTH;
5381 case eSIR_SME_ASSOC_TIMEOUT_RESULT_CODE:
5382 return NL80211_TIMEOUT_ASSOC;
5383 default:
5384 return NL80211_TIMEOUT_UNSPECIFIED;
5385 }
5386}
5387
5388/**
5389 * hdd_cfg80211_connect_timeout() - API to send connection timeout reason
5390 * @dev: network device
5391 * @bssid: bssid to which we want to associate
5392 * @timeout_reason: reason for connect timeout
5393 *
5394 * This API is used to send connection timeout reason to supplicant
5395 *
5396 * Return: void
5397 */
5398static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5399 const u8 *bssid,
5400 tSirResultCodes timeout_reason)
5401{
5402 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005403
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305404 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5405
5406 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL,
5407 nl_timeout_reason);
5408}
5409
5410/**
5411 * __hdd_connect_bss() - API to send connection status to supplicant
5412 * @dev: network device
5413 * @bssid: bssid to which we want to associate
5414 * @req_ie: Request Information Element
5415 * @req_ie_len: len of the req IE
5416 * @resp_ie: Response IE
5417 * @resp_ie_len: len of ht response IE
5418 * @status: status
5419 * @gfp: Kernel Flag
5420 * @timeout_reason: reason for connect timeout
5421 *
5422 * Return: void
5423 */
5424static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5425 struct cfg80211_bss *bss, const u8 *req_ie,
5426 size_t req_ie_len, const u8 *resp_ie,
5427 size_t resp_ie_len, int status, gfp_t gfp,
5428 tSirResultCodes timeout_reason)
5429{
5430 enum nl80211_timeout_reason nl_timeout_reason;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005431
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305432 nl_timeout_reason = hdd_convert_timeout_reason(timeout_reason);
5433
5434 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5435 resp_ie, resp_ie_len, status, gfp,
5436 nl_timeout_reason);
5437}
5438#else
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305439#if defined CFG80211_CONNECT_TIMEOUT || \
5440 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305441static void hdd_cfg80211_connect_timeout(struct net_device *dev,
5442 const u8 *bssid,
5443 tSirResultCodes timeout_reason)
5444{
5445 cfg80211_connect_timeout(dev, bssid, NULL, 0, GFP_KERNEL);
5446}
5447#endif
5448
5449static void __hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5450 struct cfg80211_bss *bss, const u8 *req_ie,
5451 size_t req_ie_len, const u8 *resp_ie,
5452 size_t resp_ie_len, int status, gfp_t gfp,
5453 tSirResultCodes timeout_reason)
5454{
5455 cfg80211_connect_bss(dev, bssid, bss, req_ie, req_ie_len,
5456 resp_ie, resp_ie_len, status, gfp);
5457}
5458#endif
5459
Abhishek Singha84d3952016-09-13 13:45:05 +05305460/**
5461 * hdd_connect_bss() - API to send connection status to supplicant
5462 * @dev: network device
5463 * @bssid: bssid to which we want to associate
5464 * @req_ie: Request Information Element
5465 * @req_ie_len: len of the req IE
5466 * @resp_ie: Response IE
5467 * @resp_ie_len: len of ht response IE
5468 * @status: status
5469 * @gfp: Kernel Flag
5470 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305471 * @timeout_reason: reason for connect timeout
Abhishek Singha84d3952016-09-13 13:45:05 +05305472 *
5473 * The API is a wrapper to send connection status to supplicant
5474 *
5475 * Return: Void
5476 */
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305477#if defined CFG80211_CONNECT_TIMEOUT || \
5478 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
Abhishek Singha84d3952016-09-13 13:45:05 +05305479static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5480 struct cfg80211_bss *bss, const u8 *req_ie,
5481 size_t req_ie_len, const u8 *resp_ie,
5482 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305483 bool connect_timeout,
5484 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305485{
5486 if (connect_timeout)
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305487 hdd_cfg80211_connect_timeout(dev, bssid, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305488 else
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305489 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5490 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305491}
5492#else
5493static void hdd_connect_bss(struct net_device *dev, const u8 *bssid,
5494 struct cfg80211_bss *bss, const u8 *req_ie,
5495 size_t req_ie_len, const u8 *resp_ie,
5496 size_t resp_ie_len, int status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305497 bool connect_timeout,
5498 tSirResultCodes timeout_reason)
Abhishek Singha84d3952016-09-13 13:45:05 +05305499{
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305500 __hdd_connect_bss(dev, bssid, bss, req_ie, req_ie_len, resp_ie,
5501 resp_ie_len, status, gfp, timeout_reason);
Abhishek Singha84d3952016-09-13 13:45:05 +05305502}
5503#endif
Anurag Chouhanc4092922016-09-08 15:56:11 +05305504
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305505#if defined(WLAN_FEATURE_FILS_SK)
5506#if defined(CFG80211_CONNECT_DONE) || \
5507 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
5508#if defined(CFG80211_FILS_SK_OFFLOAD_SUPPORT) || \
5509 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305510/**
5511 * hdd_populate_fils_params() - Populate FILS keys to connect response
5512 * @fils_params: connect response to supplicant
5513 * @fils_kek: FILS kek
5514 * @fils_kek_len: FILS kek length
5515 * @pmk: FILS PMK
5516 * @pmk_len: FILS PMK length
5517 * @pmkid: PMKID
5518 * @fils_seq_num: FILS Seq number
5519 *
5520 * Return: None
5521 */
5522static void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5523 *fils_params, const uint8_t *fils_kek,
5524 size_t fils_kek_len, const uint8_t *pmk,
5525 size_t pmk_len, const uint8_t *pmkid,
5526 uint16_t fils_seq_num)
5527{
5528 /* Increament seq number to be used for next FILS */
5529 fils_params->fils_erp_next_seq_num = fils_seq_num + 1;
5530 fils_params->update_erp_next_seq_num = true;
5531 fils_params->fils_kek = fils_kek;
5532 fils_params->fils_kek_len = fils_kek_len;
5533 fils_params->pmk = pmk;
5534 fils_params->pmk_len = pmk_len;
5535 fils_params->pmkid = pmkid;
5536}
5537#else
5538static inline void hdd_populate_fils_params(struct cfg80211_connect_resp_params
5539 *fils_params, const uint8_t
5540 *fils_kek, size_t fils_kek_len,
5541 const uint8_t *pmk, size_t pmk_len,
5542 const uint8_t *pmkid,
5543 uint16_t fils_seq_num)
5544{ }
5545#endif
5546
Jeff Johnson172237b2017-11-07 15:32:59 -08005547void hdd_update_hlp_info(struct net_device *dev,
5548 struct csr_roam_info *roam_info)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305549{
5550 struct sk_buff *skb;
5551 uint16_t skb_len;
5552 struct llc_snap_hdr_t *llc_hdr;
5553 QDF_STATUS status;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305554 uint8_t *hlp_data;
5555 uint16_t hlp_data_len;
5556 struct fils_join_rsp_params *roam_fils_params
5557 = roam_info->fils_join_rsp;
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305558 struct hdd_adapter *padapter = WLAN_HDD_GET_PRIV_PTR(dev);
5559
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305560 if (!roam_fils_params) {
5561 hdd_err("FILS Roam Param NULL");
5562 return;
5563 }
5564
Srinivas Girigowda3cc8e912017-11-28 18:11:57 -08005565 if (!roam_fils_params->hlp_data_len) {
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305566 hdd_err("FILS HLP Data NULL, len %d",
5567 roam_fils_params->hlp_data_len);
5568 return;
5569 }
5570
5571 hlp_data = roam_fils_params->hlp_data;
5572 hlp_data_len = roam_fils_params->hlp_data_len;
5573
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305574 /* Calculate skb length */
5575 skb_len = (2 * ETH_ALEN) + hlp_data_len;
5576 skb = qdf_nbuf_alloc(NULL, skb_len, 0, 4, false);
5577 if (skb == NULL) {
5578 hdd_err("HLP packet nbuf alloc fails");
5579 return;
5580 }
5581
5582 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->dst_mac.bytes,
5583 QDF_MAC_ADDR_SIZE);
5584 qdf_mem_copy(skb_put(skb, ETH_ALEN), roam_fils_params->src_mac.bytes,
5585 QDF_MAC_ADDR_SIZE);
5586
5587 llc_hdr = (struct llc_snap_hdr_t *) hlp_data;
5588 if (IS_SNAP(llc_hdr)) {
5589 hlp_data += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5590 hlp_data_len += LLC_SNAP_HDR_OFFSET_ETHERTYPE;
5591 }
5592
5593 qdf_mem_copy(skb_put(skb, hlp_data_len), hlp_data, hlp_data_len);
5594
5595 /*
5596 * This HLP packet is formed from HLP info encapsulated
5597 * in assoc response frame which is AEAD encrypted.
5598 * Hence, this checksum validation can be set unnecessary.
5599 * i.e. network layer need not worry about checksum.
5600 */
5601 skb->ip_summed = CHECKSUM_UNNECESSARY;
5602
5603 status = hdd_rx_packet_cbk(padapter, skb);
5604 if (QDF_IS_STATUS_ERROR(status)) {
5605 hdd_err("Sending HLP packet fails");
5606 return;
5607 }
5608 hdd_debug("send HLP packet to netif successfully");
5609}
5610
5611/**
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305612 * hdd_connect_done() - Wrapper API to call cfg80211_connect_done
5613 * @dev: network device
5614 * @bssid: bssid to which we want to associate
5615 * @bss: cfg80211 bss info
5616 * @roam_info: information about connected bss
5617 * @req_ie: Request Information Element
5618 * @req_ie_len: len of the req IE
5619 * @resp_ie: Response IE
5620 * @resp_ie_len: len of ht response IE
5621 * @status: status
5622 * @gfp: allocation flags
5623 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5624 * @timeout_reason: reason for connect timeout
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305625 *
5626 * This API is used as wrapper to send FILS key/sequence number
5627 * params etc. to supplicant in case of FILS connection
5628 *
5629 * Return: None
5630 */
5631static void hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005632 struct cfg80211_bss *bss,
5633 struct csr_roam_info *roam_info,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305634 const u8 *req_ie, size_t req_ie_len,
5635 const u8 *resp_ie, size_t resp_ie_len, u16 status,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005636 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305637 tSirResultCodes timeout_reason)
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305638{
5639 struct cfg80211_connect_resp_params fils_params;
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305640 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
5641 struct fils_join_rsp_params *roam_fils_params =
5642 roam_info->fils_join_rsp;
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005643
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305644 qdf_mem_zero(&fils_params, sizeof(fils_params));
5645
5646 if (!roam_fils_params) {
5647 fils_params.status = WLAN_STATUS_UNSPECIFIED_FAILURE;
5648 } else {
5649 fils_params.status = status;
5650 fils_params.bssid = bssid;
Srinivas Girigowdae975f532018-01-05 14:03:05 -08005651 fils_params.timeout_reason =
5652 hdd_convert_timeout_reason(timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305653 fils_params.req_ie = req_ie;
5654 fils_params.req_ie_len = req_ie_len;
5655 fils_params.resp_ie = resp_ie;
5656 fils_params.resp_ie_len = resp_ie_len;
5657 fils_params.bss = bss;
5658 hdd_populate_fils_params(&fils_params, roam_fils_params->kek,
5659 roam_fils_params->kek_len,
5660 roam_fils_params->fils_pmk,
5661 roam_fils_params->fils_pmk_len,
5662 roam_fils_params->fils_pmkid,
5663 roam_info->fils_seq_num);
Sridhar Selvaraje5260442017-08-19 10:12:03 +05305664 hdd_save_gtk_params(adapter, roam_info, false);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305665 }
5666 hdd_debug("FILS indicate connect status %d seq no %d",
5667 fils_params.status,
5668 fils_params.fils_erp_next_seq_num);
5669
5670 cfg80211_connect_done(dev, &fils_params, gfp);
5671
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305672 if (roam_fils_params && roam_fils_params->hlp_data_len)
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305673 hdd_update_hlp_info(dev, roam_info);
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305674
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305675 /* Clear all the FILS key info */
5676 if (roam_fils_params && roam_fils_params->fils_pmk)
5677 qdf_mem_free(roam_fils_params->fils_pmk);
5678 if (roam_fils_params)
5679 qdf_mem_free(roam_fils_params);
5680 roam_info->fils_join_rsp = NULL;
5681}
5682#else
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005683static inline void
5684hdd_connect_done(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005685 struct cfg80211_bss *bss, struct csr_roam_info *roam_info,
Jeff Johnson4f7f7c62017-10-05 08:53:41 -07005686 const u8 *req_ie, size_t req_ie_len,
5687 const u8 *resp_ie, size_t resp_ie_len, u16 status,
5688 gfp_t gfp, bool connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305689 tSirResultCodes timeout_reason)
Vignesh Viswanathana1bb0922017-09-15 12:58:48 +05305690{ }
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305691#endif
5692#endif
5693
Vignesh Viswanathan3fa1d382017-08-02 19:36:43 +05305694#if defined(WLAN_FEATURE_FILS_SK) && \
5695 (defined(CFG80211_CONNECT_DONE) || \
5696 (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)))
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305697/**
5698 * hdd_fils_update_connect_results() - API to send fils connection status to
5699 * supplicant.
5700 * @dev: network device
5701 * @bssid: bssid to which we want to associate
5702 * @bss: cfg80211 bss info
5703 * @roam_info: information about connected bss
5704 * @req_ie: Request Information Element
5705 * @req_ie_len: len of the req IE
5706 * @resp_ie: Response IE
5707 * @resp_ie_len: len of ht response IE
5708 * @status: status
5709 * @gfp: allocation flags
5710 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
5711 * @timeout_reason: reason for connect timeout
5712 *
5713 * The API is a wrapper to send connection status to supplicant
5714 *
5715 * Return: 0 if success else failure
5716 */
5717static int hdd_fils_update_connect_results(struct net_device *dev,
5718 const u8 *bssid,
5719 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005720 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305721 size_t req_ie_len, const u8 *resp_ie,
5722 size_t resp_ie_len, u16 status, gfp_t gfp,
5723 bool connect_timeout,
5724 tSirResultCodes timeout_reason)
5725{
Dustin Brown491d54b2018-03-14 12:39:11 -07005726 hdd_enter();
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305727 if (!roam_info || !roam_info->is_fils_connection)
5728 return -EINVAL;
5729
5730 hdd_connect_done(dev, bssid, bss, roam_info, req_ie, req_ie_len,
5731 resp_ie, resp_ie_len, status, gfp, connect_timeout,
Vignesh Viswanathanc6d1e1c2017-09-18 12:32:49 +05305732 timeout_reason);
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305733 return 0;
5734}
5735#else
5736static inline int hdd_fils_update_connect_results(struct net_device *dev,
5737 const u8 *bssid,
5738 struct cfg80211_bss *bss,
Jeff Johnson172237b2017-11-07 15:32:59 -08005739 struct csr_roam_info *roam_info, const u8 *req_ie,
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305740 size_t req_ie_len, const u8 *resp_ie,
5741 size_t resp_ie_len, u16 status, gfp_t gfp,
5742 bool connect_timeout,
5743 tSirResultCodes timeout_reason)
5744{
5745 return -EINVAL;
5746}
5747#endif
5748
Anurag Chouhanc4092922016-09-08 15:56:11 +05305749/**
5750 * hdd_connect_result() - API to send connection status to supplicant
5751 * @dev: network device
5752 * @bssid: bssid to which we want to associate
5753 * @roam_info: information about connected bss
5754 * @req_ie: Request Information Element
5755 * @req_ie_len: len of the req IE
5756 * @resp_ie: Response IE
5757 * @resp_ie_len: len of ht response IE
5758 * @status: status
5759 * @gfp: Kernel Flag
Abhishek Singha84d3952016-09-13 13:45:05 +05305760 * @connect_timeout: If timed out waiting for Auth/Assoc/Probe resp
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305761 * @timeout_reason: reason for connect timeout
Anurag Chouhanc4092922016-09-08 15:56:11 +05305762 *
5763 * The API is a wrapper to send connection status to supplicant
5764 * and allow runtime suspend
5765 *
5766 * Return: Void
5767 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305768void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005769 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305770 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305771 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305772 bool connect_timeout,
5773 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305774{
Jeff Johnson9d295242017-08-29 14:39:48 -07005775 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305776 struct cfg80211_bss *bss = NULL;
Jingxiang Ge929c7932018-01-24 14:01:12 +08005777 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305778
5779 if (WLAN_STATUS_SUCCESS == status) {
5780 struct ieee80211_channel *chan;
5781 int freq;
5782 int chan_no = roam_info->pBssDesc->channelId;
5783
5784 if (chan_no <= 14)
5785 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005786 HDD_NL80211_BAND_2GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305787 else
5788 freq = ieee80211_channel_to_frequency(chan_no,
Srinivas Girigowda38f1ded2017-06-12 23:00:38 -07005789 HDD_NL80211_BAND_5GHZ);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305790
5791 chan = ieee80211_get_channel(padapter->wdev.wiphy, freq);
5792 bss = hdd_cfg80211_get_bss(padapter->wdev.wiphy, chan, bssid,
5793 roam_info->u.pConnectedProfile->SSID.ssId,
5794 roam_info->u.pConnectedProfile->SSID.length);
5795 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305796
Sridhar Selvaraj0d5d2c72017-08-17 17:30:01 +05305797 if (hdd_fils_update_connect_results(dev, bssid, bss,
5798 roam_info, req_ie, req_ie_len, resp_ie,
5799 resp_ie_len, status, gfp, connect_timeout,
5800 timeout_reason) != 0) {
5801 hdd_connect_bss(dev, bssid, bss, req_ie,
5802 req_ie_len, resp_ie, resp_ie_len,
5803 status, gfp, connect_timeout, timeout_reason);
5804 }
Komal Seelama89be8d2016-09-29 11:09:26 +05305805
Jingxiang Geb49aa302018-01-17 20:54:15 +08005806 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005807 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305808}
5809#else
5810void hdd_connect_result(struct net_device *dev, const u8 *bssid,
Jeff Johnson172237b2017-11-07 15:32:59 -08005811 struct csr_roam_info *roam_info, const u8 *req_ie,
Anurag Chouhanc4092922016-09-08 15:56:11 +05305812 size_t req_ie_len, const u8 *resp_ie,
Abhishek Singha84d3952016-09-13 13:45:05 +05305813 size_t resp_ie_len, u16 status, gfp_t gfp,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305814 bool connect_timeout,
5815 tSirResultCodes timeout_reason)
Anurag Chouhanc4092922016-09-08 15:56:11 +05305816{
Jeff Johnson9d295242017-08-29 14:39:48 -07005817 struct hdd_adapter *padapter = (struct hdd_adapter *) netdev_priv(dev);
Jingxiang Ge929c7932018-01-24 14:01:12 +08005818 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(padapter);
Komal Seelama89be8d2016-09-29 11:09:26 +05305819
Anurag Chouhanc4092922016-09-08 15:56:11 +05305820 cfg80211_connect_result(dev, bssid, req_ie, req_ie_len,
5821 resp_ie, resp_ie_len, status, gfp);
Prashanth Bhatta87b6dc02017-01-19 15:17:58 -08005822
Jingxiang Geb49aa302018-01-17 20:54:15 +08005823 qdf_runtime_pm_allow_suspend(&hdd_ctx->runtime_context.connect);
Dustin Brownceed67e2017-05-26 11:57:31 -07005824 hdd_allow_suspend(WIFI_POWER_EVENT_WAKELOCK_CONNECT);
Anurag Chouhanc4092922016-09-08 15:56:11 +05305825}
5826#endif
5827
Jeff Johnsond9952752018-04-18 12:15:35 -07005828int wlan_hdd_set_mon_chan(struct hdd_adapter *adapter, uint32_t chan,
5829 uint32_t bandwidth)
5830{
5831 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
5832 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
5833 struct hdd_mon_set_ch_info *ch_info = &sta_ctx->ch_info;
5834 QDF_STATUS status;
5835 tHalHandle hal_hdl = hdd_ctx->hHal;
5836 struct qdf_mac_addr bssid;
5837 struct csr_roam_profile roam_profile;
5838 struct ch_params ch_params;
5839
5840 if (QDF_GLOBAL_MONITOR_MODE != hdd_get_conparam()) {
5841 hdd_err("Not supported, device is not in monitor mode");
5842 return -EINVAL;
5843 }
5844
5845 hdd_debug("Set monitor mode Channel %d", chan);
5846 qdf_mem_zero(&roam_profile, sizeof(roam_profile));
5847 roam_profile.ChannelInfo.ChannelList = &ch_info->channel;
5848 roam_profile.ChannelInfo.numOfChannels = 1;
5849 roam_profile.phyMode = ch_info->phy_mode;
5850 roam_profile.ch_params.ch_width = bandwidth;
5851 hdd_select_cbmode(adapter, chan, &roam_profile.ch_params);
5852
5853 qdf_mem_copy(bssid.bytes, adapter->mac_addr.bytes,
5854 QDF_MAC_ADDR_SIZE);
5855
5856 ch_params.ch_width = bandwidth;
5857 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev, chan, 0, &ch_params);
5858 if (ch_params.ch_width == CH_WIDTH_INVALID) {
5859 hdd_err("Invalid capture channel or bandwidth for a country");
5860 return -EINVAL;
5861 }
5862 if (wlan_hdd_change_hw_mode_for_given_chnl(adapter, chan,
5863 POLICY_MGR_UPDATE_REASON_SET_OPER_CHAN)) {
5864 hdd_err("Failed to change hw mode");
5865 return -EINVAL;
5866 }
5867
5868 status = sme_roam_channel_change_req(hal_hdl, bssid, &ch_params,
5869 &roam_profile);
5870 if (status) {
5871 hdd_err("Status: %d Failed to set sme_roam Channel for monitor mode",
5872 status);
5873 }
5874
5875 adapter->mon_chan = chan;
5876 adapter->mon_bandwidth = bandwidth;
5877 return qdf_status_to_os_return(status);
5878}
Anurag Chouhanc4092922016-09-08 15:56:11 +05305879
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005880QDF_STATUS hdd_start_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005881{
Jeff Johnson9d295242017-08-29 14:39:48 -07005882 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005883#ifndef MSM_PLATFORM
Dustin Brownce5b3d32018-01-17 15:07:38 -08005884 struct qdf_mac_addr bcastMac = QDF_MAC_ADDR_BCAST_INIT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005885#endif
5886 eConnectionState connState;
5887
Dustin Brown491d54b2018-03-14 12:39:11 -07005888 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005889
Dustin Brown920397d2017-12-13 16:27:50 -08005890 hdd_for_each_adapter(hdd_ctx, adapter) {
Arun Khandavallifae92942016-08-01 13:31:08 +05305891 if (!hdd_is_interface_up(adapter))
Dustin Brown920397d2017-12-13 16:27:50 -08005892 continue;
Arun Khandavallifae92942016-08-01 13:31:08 +05305893
Yue Ma42654682018-01-11 16:55:24 -08005894 hdd_debug("[SSR] start adapter with device mode %s(%d)",
5895 hdd_device_mode_to_string(adapter->device_mode),
5896 adapter->device_mode);
5897
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005898 hdd_wmm_init(adapter);
5899
5900 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005901 case QDF_STA_MODE:
5902 case QDF_P2P_CLIENT_MODE:
5903 case QDF_P2P_DEVICE_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005904
5905 connState = (WLAN_HDD_GET_STATION_CTX_PTR(adapter))
5906 ->conn_info.connState;
5907
Krunal Sonib51eec72017-11-20 21:53:01 -08005908 hdd_start_station_adapter(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005909 /* Open the gates for HDD to receive Wext commands */
Jeff Johnsonc72c5732017-10-28 12:49:37 -07005910 adapter->is_link_up_service_needed = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005911
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005912 /* Indicate disconnect event to supplicant
5913 * if associated previously
5914 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005915 if (eConnectionState_Associated == connState ||
Yue Macd961442015-10-20 16:15:31 -07005916 eConnectionState_IbssConnected == connState ||
5917 eConnectionState_NotConnected == connState ||
5918 eConnectionState_IbssDisconnected == connState ||
5919 eConnectionState_Disconnecting == connState) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005920 union iwreq_data wrqu;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005921
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005922 memset(&wrqu, '\0', sizeof(wrqu));
5923 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
5924 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
5925 wireless_send_event(adapter->dev, SIOCGIWAP,
5926 &wrqu, NULL);
Jeff Johnsonb9424862017-10-30 08:49:35 -07005927 adapter->session.station.
Jeff Johnson690fe952017-10-25 11:48:39 -07005928 hdd_reassoc_scenario = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005929
5930 /* indicate disconnected event to nl80211 */
Mahesh A Saptasagarc35e8bf2016-06-17 20:03:46 +05305931 wlan_hdd_cfg80211_indicate_disconnect(
5932 adapter->dev, false,
5933 WLAN_REASON_UNSPECIFIED);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005934 } else if (eConnectionState_Connecting == connState) {
5935 /*
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005936 * Indicate connect failure to supplicant if we
5937 * were in the process of connecting
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005938 */
Anurag Chouhanc4092922016-09-08 15:56:11 +05305939 hdd_connect_result(adapter->dev, NULL, NULL,
yeshwanth sriram guntukaaf7b73f2017-02-22 17:35:32 +05305940 NULL, 0, NULL, 0,
5941 WLAN_STATUS_ASSOC_DENIED_UNSPEC,
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005942 GFP_KERNEL, false, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005943 }
5944
5945 hdd_register_tx_flow_control(adapter,
5946 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08005947 hdd_tx_resume_cb,
5948 hdd_tx_flow_control_is_pause);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005949
Alok Kumarb64650c2018-03-23 17:05:11 +05305950 hdd_nud_ignore_tracking(adapter, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005951 break;
5952
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005953 case QDF_SAP_MODE:
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005954 if (hdd_ctx->config->sap_internal_restart)
Krunal Sonib51eec72017-11-20 21:53:01 -08005955 hdd_start_ap_adapter(adapter);
Arun Khandavallicc544b32017-01-30 19:52:16 +05305956
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005957 break;
5958
Krunal Soni9b04c9b2016-03-10 13:08:05 -08005959 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005960#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005961 hdd_debug("[SSR] send stop ap to supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005962 cfg80211_ap_stopped(adapter->dev, GFP_KERNEL);
5963#else
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08005964 hdd_debug("[SSR] send restart supplicant");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005965 /* event supplicant to restart */
5966 cfg80211_del_sta(adapter->dev,
5967 (const u8 *)&bcastMac.bytes[0],
5968 GFP_KERNEL);
5969#endif
5970 break;
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305971 case QDF_MONITOR_MODE:
Krunal Sonib51eec72017-11-20 21:53:01 -08005972 hdd_start_station_adapter(adapter);
Arunk Khandavalli062fb032017-10-04 12:18:15 +05305973 hdd_set_mon_rx_cb(adapter->dev);
5974 wlan_hdd_set_mon_chan(adapter, adapter->mon_chan,
5975 adapter->mon_bandwidth);
5976 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005977 default:
5978 break;
5979 }
Krunal Soni9c2ee032017-07-18 13:49:54 -07005980 /*
5981 * Action frame registered in one adapter which will
5982 * applicable to all interfaces
5983 */
5984 wlan_hdd_cfg80211_register_frames(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005985 }
5986
Dustin Browne74003f2018-03-14 12:51:58 -07005987 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005988
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305989 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005990}
5991
Jeff Johnsond49c4a12017-08-28 12:08:05 -07005992QDF_STATUS hdd_get_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08005993 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005994{
Anurag Chouhanffb21542016-02-17 14:33:03 +05305995 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08005996 qdf_list_node_t *node;
5997
5998 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07005999
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006000 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006001 status = qdf_list_peek_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006002 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006003
6004 if (QDF_IS_STATUS_ERROR(status))
6005 return status;
6006
6007 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6008
6009 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006010}
6011
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006012QDF_STATUS hdd_get_next_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006013 struct hdd_adapter *current_adapter,
6014 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006015{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306016 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006017 qdf_list_node_t *node;
6018
6019 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006020
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006021 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006022 status = qdf_list_peek_next(&hdd_ctx->hdd_adapters,
Dustin Brown920397d2017-12-13 16:27:50 -08006023 &current_adapter->node,
6024 &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006025 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006026
6027 if (QDF_IS_STATUS_ERROR(status))
6028 return status;
6029
6030 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6031
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006032 return status;
6033}
6034
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006035QDF_STATUS hdd_remove_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006036 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006037{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306038 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006039
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006040 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006041 status = qdf_list_remove_node(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006042 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006043
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006044 return status;
6045}
6046
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006047QDF_STATUS hdd_remove_front_adapter(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006048 struct hdd_adapter **out_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006049{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306050 QDF_STATUS status;
Dustin Brown920397d2017-12-13 16:27:50 -08006051 qdf_list_node_t *node;
6052
6053 *out_adapter = NULL;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006054
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006055 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006056 status = qdf_list_remove_front(&hdd_ctx->hdd_adapters, &node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006057 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006058
6059 if (QDF_IS_STATUS_ERROR(status))
6060 return status;
6061
6062 *out_adapter = qdf_container_of(node, struct hdd_adapter, node);
6063
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006064 return status;
6065}
6066
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006067QDF_STATUS hdd_add_adapter_back(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006068 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006069{
Anurag Chouhanffb21542016-02-17 14:33:03 +05306070 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006071
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006072 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006073 status = qdf_list_insert_back(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006074 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006075
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006076 return status;
6077}
6078
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006079QDF_STATUS hdd_add_adapter_front(struct hdd_context *hdd_ctx,
Dustin Brown920397d2017-12-13 16:27:50 -08006080 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006081{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306082 QDF_STATUS status;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006083
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006084 qdf_spin_lock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006085 status = qdf_list_insert_front(&hdd_ctx->hdd_adapters, &adapter->node);
Rajeev Kumardd4dd082016-02-25 12:24:32 -08006086 qdf_spin_unlock_bh(&hdd_ctx->hdd_adapter_lock);
Dustin Brown920397d2017-12-13 16:27:50 -08006087
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006088 return status;
6089}
6090
Jeff Johnson9d295242017-08-29 14:39:48 -07006091struct hdd_adapter *hdd_get_adapter_by_macaddr(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006092 tSirMacAddr macAddr)
6093{
Jeff Johnson9d295242017-08-29 14:39:48 -07006094 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006095
Dustin Brown920397d2017-12-13 16:27:50 -08006096 hdd_for_each_adapter(hdd_ctx, adapter) {
6097 if (!qdf_mem_cmp(adapter->mac_addr.bytes,
6098 macAddr, sizeof(tSirMacAddr)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006099 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006100 }
6101
6102 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006103}
6104
Jeff Johnson9d295242017-08-29 14:39:48 -07006105struct hdd_adapter *hdd_get_adapter_by_vdev(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006106 uint32_t vdev_id)
6107{
Jeff Johnson9d295242017-08-29 14:39:48 -07006108 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006109
Dustin Brown920397d2017-12-13 16:27:50 -08006110 hdd_for_each_adapter(hdd_ctx, adapter) {
Jeff Johnson1b780e42017-10-31 14:11:45 -07006111 if (adapter->session_id == vdev_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006112 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006113 }
6114
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006115 return NULL;
6116}
6117
Abhishek Singh7996eb72015-12-30 17:24:02 +05306118/**
6119 * hdd_get_adapter_by_sme_session_id() - Return adapter with
6120 * the sessionid
6121 * @hdd_ctx: hdd context.
6122 * @sme_session_id: sme session is for the adapter to get.
6123 *
6124 * This function is used to get the adapter with provided session id
6125 *
6126 * Return: adapter pointer if found
6127 *
6128 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07006129struct hdd_adapter *
6130hdd_get_adapter_by_sme_session_id(struct hdd_context *hdd_ctx,
6131 uint32_t sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306132{
Jeff Johnson9d295242017-08-29 14:39:48 -07006133 struct hdd_adapter *adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306134
Dustin Brown920397d2017-12-13 16:27:50 -08006135 hdd_for_each_adapter(hdd_ctx, adapter) {
6136 if (adapter->session_id == sme_session_id)
Abhishek Singh7996eb72015-12-30 17:24:02 +05306137 return adapter;
Abhishek Singh7996eb72015-12-30 17:24:02 +05306138 }
Dustin Brown920397d2017-12-13 16:27:50 -08006139
Abhishek Singh7996eb72015-12-30 17:24:02 +05306140 return NULL;
6141}
6142
Jeff Johnson9d295242017-08-29 14:39:48 -07006143struct hdd_adapter *hdd_get_adapter_by_iface_name(struct hdd_context *hdd_ctx,
Naveen Rawat4edb6822017-04-12 10:09:17 -07006144 const char *iface_name)
6145{
Jeff Johnson9d295242017-08-29 14:39:48 -07006146 struct hdd_adapter *adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006147
Dustin Brown920397d2017-12-13 16:27:50 -08006148 hdd_for_each_adapter(hdd_ctx, adapter) {
6149 if (!qdf_str_cmp(adapter->dev->name, iface_name))
Naveen Rawat4edb6822017-04-12 10:09:17 -07006150 return adapter;
Naveen Rawat4edb6822017-04-12 10:09:17 -07006151 }
Dustin Brown920397d2017-12-13 16:27:50 -08006152
Naveen Rawat4edb6822017-04-12 10:09:17 -07006153 return NULL;
6154}
6155
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006156/**
6157 * hdd_get_adapter() - to get adapter matching the mode
6158 * @hdd_ctx: hdd context
6159 * @mode: adapter mode
6160 *
6161 * This routine will return the pointer to adapter matching
6162 * with the passed mode.
6163 *
6164 * Return: pointer to adapter or null
6165 */
Jeff Johnson9d295242017-08-29 14:39:48 -07006166struct hdd_adapter *hdd_get_adapter(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006167 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006168{
Jeff Johnson9d295242017-08-29 14:39:48 -07006169 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006170
Dustin Brown920397d2017-12-13 16:27:50 -08006171 hdd_for_each_adapter(hdd_ctx, adapter) {
6172 if (adapter->device_mode == mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006173 return adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006174 }
6175
6176 return NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006177}
6178
Yeshwanth Sriram Guntuka469f9572018-02-12 13:28:22 +05306179enum tQDF_ADAPTER_MODE hdd_get_device_mode(uint32_t session_id)
6180{
6181 struct hdd_context *hdd_ctx;
6182 struct hdd_adapter *adapter;
6183
6184 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
6185 if (!hdd_ctx) {
6186 hdd_err("Invalid HDD context");
6187 return QDF_MAX_NO_OF_MODE;
6188 }
6189
6190 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx, session_id);
6191 if (!adapter) {
6192 hdd_err("Invalid HDD adapter");
6193 return QDF_MAX_NO_OF_MODE;
6194 }
6195
6196 return adapter->device_mode;
6197}
6198
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006199/**
6200 * hdd_get_operating_channel() - return operating channel of the device mode
6201 * @hdd_ctx: Pointer to the HDD context.
6202 * @mode: Device mode for which operating channel is required.
6203 * Suported modes:
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006204 * QDF_STA_MODE,
6205 * QDF_P2P_CLIENT_MODE,
6206 * QDF_SAP_MODE,
6207 * QDF_P2P_GO_MODE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006208 *
6209 * This API returns the operating channel of the requested device mode
6210 *
6211 * Return: channel number. "0" id the requested device is not found OR it is
6212 * not connected.
6213 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006214uint8_t hdd_get_operating_channel(struct hdd_context *hdd_ctx,
Jeff Johnsonc1e62782017-11-09 09:50:17 -08006215 enum QDF_OPMODE mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006216{
Jeff Johnson9d295242017-08-29 14:39:48 -07006217 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006218 uint8_t operatingChannel = 0;
6219
Dustin Brown920397d2017-12-13 16:27:50 -08006220 hdd_for_each_adapter(hdd_ctx, adapter) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006221 if (mode == adapter->device_mode) {
6222 switch (adapter->device_mode) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006223 case QDF_STA_MODE:
6224 case QDF_P2P_CLIENT_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006225 if (hdd_conn_is_connected
6226 (WLAN_HDD_GET_STATION_CTX_PTR
6227 (adapter))) {
6228 operatingChannel =
6229 (WLAN_HDD_GET_STATION_CTX_PTR
6230 (adapter))->conn_info.
6231 operationChannel;
6232 }
6233 break;
Krunal Soni9b04c9b2016-03-10 13:08:05 -08006234 case QDF_SAP_MODE:
6235 case QDF_P2P_GO_MODE:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006236 /* softap connection info */
6237 if (test_bit
6238 (SOFTAP_BSS_STARTED,
6239 &adapter->event_flags))
6240 operatingChannel =
6241 (WLAN_HDD_GET_AP_CTX_PTR
Jeff Johnson01206862017-10-27 20:55:59 -07006242 (adapter))->operating_channel;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006243 break;
6244 default:
6245 break;
6246 }
6247
Srinivas Girigowdab841da72017-03-25 18:04:39 -07006248 /* Found the device of interest. break the loop */
6249 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006250 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006251 }
Dustin Brown920397d2017-12-13 16:27:50 -08006252
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006253 return operatingChannel;
6254}
6255
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006256static inline QDF_STATUS hdd_unregister_wext_all_adapters(struct hdd_context *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006257 hdd_ctx)
6258{
Jeff Johnson9d295242017-08-29 14:39:48 -07006259 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006260
Dustin Brown491d54b2018-03-14 12:39:11 -07006261 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006262
Dustin Brown920397d2017-12-13 16:27:50 -08006263 hdd_for_each_adapter(hdd_ctx, adapter) {
6264 if (adapter->device_mode == QDF_STA_MODE ||
6265 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6266 adapter->device_mode == QDF_IBSS_MODE ||
6267 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6268 adapter->device_mode == QDF_SAP_MODE ||
6269 adapter->device_mode == QDF_P2P_GO_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006270 wlan_hdd_cfg80211_deregister_frames(adapter);
6271 hdd_unregister_wext(adapter->dev);
6272 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006273 }
6274
Dustin Browne74003f2018-03-14 12:51:58 -07006275 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006276
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306277 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006278}
6279
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006280QDF_STATUS hdd_abort_mac_scan_all_adapters(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006281{
Jeff Johnson9d295242017-08-29 14:39:48 -07006282 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006283
Dustin Brown491d54b2018-03-14 12:39:11 -07006284 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006285
Dustin Brown920397d2017-12-13 16:27:50 -08006286 hdd_for_each_adapter(hdd_ctx, adapter) {
6287 if (adapter->device_mode == QDF_STA_MODE ||
6288 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6289 adapter->device_mode == QDF_IBSS_MODE ||
6290 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6291 adapter->device_mode == QDF_SAP_MODE ||
6292 adapter->device_mode == QDF_P2P_GO_MODE) {
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07006293 wlan_abort_scan(hdd_ctx->hdd_pdev, INVAL_PDEV_ID,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006294 adapter->session_id, INVALID_SCAN_ID,
Vignesh Viswanathan19611c82018-01-16 16:20:40 +05306295 true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006296 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006297 }
6298
Dustin Browne74003f2018-03-14 12:51:58 -07006299 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006300
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306301 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006302}
6303
Dustin Brownf27bce82016-11-03 12:52:27 -07006304/**
6305 * hdd_abort_sched_scan_all_adapters() - stops scheduled (PNO) scans for all
6306 * adapters
6307 * @hdd_ctx: The HDD context containing the adapters to operate on
6308 *
6309 * return: QDF_STATUS_SUCCESS
6310 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006311static QDF_STATUS hdd_abort_sched_scan_all_adapters(struct hdd_context *hdd_ctx)
Dustin Brownf27bce82016-11-03 12:52:27 -07006312{
Jeff Johnson9d295242017-08-29 14:39:48 -07006313 struct hdd_adapter *adapter;
Dustin Brownf27bce82016-11-03 12:52:27 -07006314 int err;
6315
Dustin Brown491d54b2018-03-14 12:39:11 -07006316 hdd_enter();
Dustin Brownf27bce82016-11-03 12:52:27 -07006317
Dustin Brown920397d2017-12-13 16:27:50 -08006318 hdd_for_each_adapter(hdd_ctx, adapter) {
6319 if (adapter->device_mode == QDF_STA_MODE ||
6320 adapter->device_mode == QDF_P2P_CLIENT_MODE ||
6321 adapter->device_mode == QDF_IBSS_MODE ||
6322 adapter->device_mode == QDF_P2P_DEVICE_MODE ||
6323 adapter->device_mode == QDF_SAP_MODE ||
6324 adapter->device_mode == QDF_P2P_GO_MODE) {
Dustin Brownf27bce82016-11-03 12:52:27 -07006325 err = wlan_hdd_sched_scan_stop(adapter->dev);
6326 if (err)
6327 hdd_err("Unable to stop scheduled scan");
6328 }
Dustin Brownf27bce82016-11-03 12:52:27 -07006329 }
6330
Dustin Browne74003f2018-03-14 12:51:58 -07006331 hdd_exit();
Dustin Brownf27bce82016-11-03 12:52:27 -07006332
6333 return QDF_STATUS_SUCCESS;
6334}
6335
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006336#ifdef WLAN_NS_OFFLOAD
6337/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006338 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006339 * @hdd_ctx: Pointer to hdd context
6340 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006341 * Unregister for IPv6 address change notifications.
6342 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006343 * Return: None
6344 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006345static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006346{
6347 unregister_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006348}
6349
6350/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006351 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006352 * @hdd_ctx: Pointer to hdd context
6353 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006354 * Register for IPv6 address change notifications.
6355 *
6356 * Return: 0 on success and errno on failure.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006357 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006358static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006359{
6360 int ret;
6361
6362 hdd_ctx->ipv6_notifier.notifier_call = wlan_hdd_ipv6_changed;
6363 ret = register_inet6addr_notifier(&hdd_ctx->ipv6_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006364 if (ret) {
6365 hdd_err("Failed to register IPv6 notifier: %d", ret);
6366 goto out;
6367 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006368
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006369 hdd_debug("Registered IPv6 notifier");
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006370out:
6371 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006372}
6373#else
6374/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006375 * hdd_wlan_unregister_ip6_notifier() - unregister IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006376 * @hdd_ctx: Pointer to hdd context
6377 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006378 * Unregister for IPv6 address change notifications.
6379 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006380 * Return: None
6381 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006382static void hdd_wlan_unregister_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006383{
6384}
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006385
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006386/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006387 * hdd_wlan_register_ip6_notifier() - register IPv6 change notifier
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006388 * @hdd_ctx: Pointer to hdd context
6389 *
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006390 * Register for IPv6 address change notifications.
6391 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006392 * Return: None
6393 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006394static int hdd_wlan_register_ip6_notifier(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006395{
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006396 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006397}
6398#endif
6399
Alok Kumarb64650c2018-03-23 17:05:11 +05306400void hdd_set_disconnect_status(struct hdd_adapter *adapter, bool status)
6401{
6402 qdf_mutex_acquire(&adapter->disconnection_status_lock);
6403 adapter->disconnection_in_progress = status;
6404 qdf_mutex_release(&adapter->disconnection_status_lock);
6405 hdd_debug("setting disconnection status: %d", status);
6406}
6407
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006408/**
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006409 * hdd_register_notifiers - Register netdev notifiers.
6410 * @hdd_ctx: HDD context
6411 *
6412 * Register netdev notifiers like IPv4 and IPv6.
6413 *
6414 * Return: 0 on success and errno on failure
6415 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006416static int hdd_register_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006417{
6418 int ret;
6419
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006420 ret = hdd_wlan_register_ip6_notifier(hdd_ctx);
6421 if (ret)
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306422 goto out;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006423
6424 hdd_ctx->ipv4_notifier.notifier_call = wlan_hdd_ipv4_changed;
6425 ret = register_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
6426 if (ret) {
6427 hdd_err("Failed to register IPv4 notifier: %d", ret);
6428 goto unregister_ip6_notifier;
6429 }
6430
Alok Kumarb64650c2018-03-23 17:05:11 +05306431 ret = hdd_nud_register_netevent_notifier(hdd_ctx);
6432 if (ret) {
6433 hdd_err("Failed to register netevent notifier: %d",
6434 ret);
6435 goto unregister_inetaddr_notifier;
6436 }
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006437 return 0;
6438
Alok Kumarb64650c2018-03-23 17:05:11 +05306439unregister_inetaddr_notifier:
6440 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006441unregister_ip6_notifier:
6442 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006443out:
6444 return ret;
6445
6446}
6447
6448/**
6449 * hdd_unregister_notifiers - Unregister netdev notifiers.
6450 * @hdd_ctx: HDD context
6451 *
6452 * Unregister netdev notifiers like IPv4 and IPv6.
6453 *
6454 * Return: None.
6455 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006456void hdd_unregister_notifiers(struct hdd_context *hdd_ctx)
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006457{
Alok Kumarb64650c2018-03-23 17:05:11 +05306458 hdd_nud_unregister_netevent_notifier(hdd_ctx);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006459 hdd_wlan_unregister_ip6_notifier(hdd_ctx);
6460
6461 unregister_inetaddr_notifier(&hdd_ctx->ipv4_notifier);
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -07006462}
6463
6464/**
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006465 * hdd_exit_netlink_services - Exit netlink services
6466 * @hdd_ctx: HDD context
6467 *
6468 * Exit netlink services like cnss_diag, cesium netlink socket, ptt socket and
6469 * nl service.
6470 *
6471 * Return: None.
6472 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006473static void hdd_exit_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006474{
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006475 hdd_close_cesium_nl_sock();
Naveen Rawat910726a2017-03-06 11:42:51 -08006476 hdd_deactivate_wifi_pos();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006477 ptt_sock_deactivate_svc();
6478
6479 nl_srv_exit();
6480}
6481
6482/**
6483 * hdd_init_netlink_services- Init netlink services
6484 * @hdd_ctx: HDD context
6485 *
6486 * Init netlink services like cnss_diag, cesium netlink socket, ptt socket and
6487 * nl service.
6488 *
6489 * Return: 0 on success and errno on failure.
6490 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006491static int hdd_init_netlink_services(struct hdd_context *hdd_ctx)
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006492{
6493 int ret;
6494
Ryan Hsuceddceb2016-04-28 10:20:14 -07006495 ret = wlan_hdd_nl_init(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006496 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006497 hdd_err("nl_srv_init failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006498 goto out;
6499 }
Ryan Hsuceddceb2016-04-28 10:20:14 -07006500 cds_set_radio_index(hdd_ctx->radio_index);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006501
Naveen Rawat910726a2017-03-06 11:42:51 -08006502 ret = hdd_activate_wifi_pos(hdd_ctx);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006503 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006504 hdd_err("hdd_activate_wifi_pos failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006505 goto err_nl_srv;
6506 }
6507
6508 ret = ptt_sock_activate_svc();
6509 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006510 hdd_err("ptt_sock_activate_svc failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006511 goto err_nl_srv;
6512 }
6513
6514 ret = hdd_open_cesium_nl_sock();
Ryan Hsu5e2e2052016-04-28 10:19:38 -07006515 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006516 hdd_err("hdd_open_cesium_nl_sock failed ret: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006517
6518 ret = cnss_diag_activate_service();
6519 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006520 hdd_err("cnss_diag_activate_service failed: %d", ret);
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006521 goto err_close_cesium;
6522 }
6523
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -08006524 ret = spectral_scan_activate_service();
6525 if (ret) {
6526 hdd_alert("spectral_scan_activate_service failed: %d", ret);
6527 goto err_close_cesium;
6528 }
6529
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006530 return 0;
6531
6532err_close_cesium:
6533 hdd_close_cesium_nl_sock();
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006534 ptt_sock_deactivate_svc();
6535err_nl_srv:
6536 nl_srv_exit();
6537out:
6538 return ret;
6539}
6540
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006541/**
6542 * hdd_rx_wake_lock_destroy() - Destroy RX wakelock
6543 * @hdd_ctx: HDD context.
6544 *
6545 * Destroy RX wakelock.
6546 *
6547 * Return: None.
6548 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006549static void hdd_rx_wake_lock_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006550{
6551 qdf_wake_lock_destroy(&hdd_ctx->rx_wake_lock);
6552}
Prashanth Bhatta6a6a5552016-02-01 13:49:29 -08006553
6554/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006555 * hdd_rx_wake_lock_create() - Create RX wakelock
6556 * @hdd_ctx: HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006557 *
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006558 * Create RX wakelock.
6559 *
6560 * Return: None.
6561 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006562static void hdd_rx_wake_lock_create(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006563{
6564 qdf_wake_lock_create(&hdd_ctx->rx_wake_lock, "qcom_rx_wakelock");
6565}
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006566
6567/**
Houston Hoffman160db392016-10-10 17:37:51 -07006568 * hdd_context_deinit() - Deinitialize HDD context
6569 * @hdd_ctx: HDD context.
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006570 *
Houston Hoffman160db392016-10-10 17:37:51 -07006571 * Deinitialize HDD context along with all the feature specific contexts but
6572 * do not free hdd context itself. Caller of this API is supposed to free
6573 * HDD context.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006574 *
Houston Hoffman160db392016-10-10 17:37:51 -07006575 * return: 0 on success and errno on failure.
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006576 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006577static int hdd_context_deinit(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006578{
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306579 qdf_wake_lock_destroy(&hdd_ctx->monitor_mode_wakelock);
6580
Houston Hoffman160db392016-10-10 17:37:51 -07006581 wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006582
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006583 hdd_sap_context_destroy(hdd_ctx);
6584
6585 hdd_rx_wake_lock_destroy(hdd_ctx);
6586
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006587 hdd_scan_context_destroy(hdd_ctx);
6588
Jeff Johnson19fc8e42017-10-30 19:53:49 -07006589 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006590
Houston Hoffman160db392016-10-10 17:37:51 -07006591 return 0;
6592}
6593
6594/**
6595 * hdd_context_destroy() - Destroy HDD context
6596 * @hdd_ctx: HDD context to be destroyed.
6597 *
6598 * Free config and HDD context as well as destroy all the resources.
6599 *
6600 * Return: None
6601 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006602static void hdd_context_destroy(struct hdd_context *hdd_ctx)
Houston Hoffman160db392016-10-10 17:37:51 -07006603{
Rajeev Kumar493a31b2017-09-29 14:01:24 -07006604 cds_set_context(QDF_MODULE_ID_HDD, NULL);
Arunk Khandavalli3d267b42017-05-02 18:58:59 +05306605
Hanumantha Reddy Pothula00c74f62016-11-24 20:13:32 +05306606 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
6607
Houston Hoffman160db392016-10-10 17:37:51 -07006608 hdd_context_deinit(hdd_ctx);
6609
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306610 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08006611 hdd_ctx->config = NULL;
6612
6613 wiphy_free(hdd_ctx->wiphy);
6614}
6615
6616/**
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +05306617 * wlan_destroy_bug_report_lock() - Destroy bug report lock
6618 *
6619 * This function is used to destroy bug report lock
6620 *
6621 * Return: None
6622 */
6623static void wlan_destroy_bug_report_lock(void)
6624{
6625 p_cds_contextType p_cds_context;
6626
6627 p_cds_context = cds_get_global_context();
6628 if (!p_cds_context) {
6629 hdd_err("cds context is NULL");
6630 return;
6631 }
6632
6633 qdf_spinlock_destroy(&p_cds_context->bug_report_lock);
6634}
6635
6636/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006637 * hdd_wlan_exit() - HDD WLAN exit function
6638 * @hdd_ctx: Pointer to the HDD Context
6639 *
6640 * This is the driver exit point (invoked during rmmod)
6641 *
6642 * Return: None
6643 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006644static void hdd_wlan_exit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006645{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006646 struct wiphy *wiphy = hdd_ctx->wiphy;
Arun Khandavallifae92942016-08-01 13:31:08 +05306647 int driver_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006648
Dustin Brown491d54b2018-03-14 12:39:11 -07006649 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006650
Arun Khandavallifae92942016-08-01 13:31:08 +05306651 hdd_unregister_notifiers(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006652
Prashanth Bhattaab004382016-10-11 16:08:11 -07006653 hdd_bus_bandwidth_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006654
6655#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +05306656 if (QDF_TIMER_STATE_RUNNING ==
6657 qdf_mc_timer_get_current_state(&hdd_ctx->skip_acs_scan_timer)) {
6658 qdf_mc_timer_stop(&hdd_ctx->skip_acs_scan_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006659 }
6660
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306661 if (!QDF_IS_STATUS_SUCCESS
Anurag Chouhan210db072016-02-22 18:42:15 +05306662 (qdf_mc_timer_destroy(&hdd_ctx->skip_acs_scan_timer))) {
Jeff Johnson5880d792016-08-15 13:32:30 -07006663 hdd_err("Cannot deallocate ACS Skip timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006664 }
Liangwei Dongaef84342016-10-21 05:28:00 -04006665 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6666 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6667 hdd_ctx->last_acs_channel_list = NULL;
6668 hdd_ctx->num_of_channels = 0;
6669 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006670#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006671
Arun Khandavallifae92942016-08-01 13:31:08 +05306672 mutex_lock(&hdd_ctx->iface_change_lock);
6673 driver_status = hdd_ctx->driver_status;
6674 mutex_unlock(&hdd_ctx->iface_change_lock);
6675
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006676 /*
6677 * Powersave Offload Case
6678 * Disable Idle Power Save Mode
6679 */
6680 hdd_set_idle_ps_config(hdd_ctx, false);
Sandeep Puligilla8fa28fd2017-11-02 12:19:33 -07006681 /* clear the scan queue in all the scenarios */
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +05306682 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006683
Arun Khandavallifae92942016-08-01 13:31:08 +05306684 if (driver_status != DRIVER_MODULES_CLOSED) {
6685 hdd_unregister_wext_all_adapters(hdd_ctx);
6686 /*
6687 * Cancel any outstanding scan requests. We are about to close
6688 * all of our adapters, but an adapter structure is what SME
6689 * passes back to our callback function. Hence if there
6690 * are any outstanding scan requests then there is a
6691 * race condition between when the adapter is closed and
6692 * when the callback is invoked. We try to resolve that
6693 * race condition here by canceling any outstanding scans
6694 * before we close the adapters.
6695 * Note that the scans may be cancelled in an asynchronous
6696 * manner, so ideally there needs to be some kind of
6697 * synchronization. Rather than introduce a new
6698 * synchronization here, we will utilize the fact that we are
6699 * about to Request Full Power, and since that is synchronized,
6700 * the expectation is that by the time Request Full Power has
6701 * completed, all scans will be cancelled
6702 */
6703 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Dustin Brownf27bce82016-11-03 12:52:27 -07006704 hdd_abort_sched_scan_all_adapters(hdd_ctx);
Dustin Browndb2a8be2017-12-20 11:49:56 -08006705 hdd_stop_all_adapters(hdd_ctx);
bings29c99862017-11-01 13:54:13 +08006706 hdd_deinit_all_adapters(hdd_ctx, false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006707 }
6708
Arunk Khandavalli830c9692018-03-22 12:17:40 +05306709 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavalli08479ba2017-08-07 19:56:23 +05306710 unregister_netdevice_notifier(&hdd_netdev_notifier);
6711
Rajeev Kumar3fef4e82017-03-31 20:25:23 -07006712 hdd_wlan_stop_modules(hdd_ctx, false);
Hanumanth Reddy Pothula709a6362016-10-18 18:19:44 +05306713
Dustin Brown021cecd2017-12-11 13:56:43 -08006714 hdd_driver_memdump_deinit();
6715
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +05306716 qdf_nbuf_deinit_replenish_timer();
6717
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05306718 if (QDF_GLOBAL_MONITOR_MODE == hdd_get_conparam()) {
6719 hdd_info("Release wakelock for monitor mode!");
6720 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
6721 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
6722 }
6723
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05306724 qdf_spinlock_destroy(&hdd_ctx->hdd_adapter_lock);
6725 qdf_spinlock_destroy(&hdd_ctx->sta_update_info_lock);
6726 qdf_spinlock_destroy(&hdd_ctx->connection_status_lock);
6727
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006728 /*
6729 * Close CDS
6730 * This frees pMac(HAL) context. There should not be any call
6731 * that requires pMac access after this.
6732 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006733
Jeff Johnsonce0032c2017-01-20 07:18:27 -08006734 hdd_request_manager_deinit();
Naveen Rawate02f8f52018-04-05 11:58:04 -07006735 osif_request_manager_deinit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006736
Dustin Brownd005ad82018-01-19 10:32:13 -08006737 hdd_close_all_adapters(hdd_ctx, false);
6738
Manishekar Chandrasekaranf7a1dad2016-06-23 06:43:47 +05306739 wlansap_global_deinit();
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306740 /*
6741 * If there is re_init failure wiphy would have already de-registered
6742 * check the wiphy status before un-registering again
6743 */
Ashish Kumar Dhanotiyae16feb72017-03-31 19:39:37 +05306744 if (wiphy && wiphy->registered) {
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05306745 wiphy_unregister(wiphy);
6746 wlan_hdd_cfg80211_deinit(wiphy);
6747 hdd_lpass_notify_stop(hdd_ctx);
6748 }
Yuanyuan Liu3e918e52016-08-17 15:41:35 -07006749
Arun Khandavallifae92942016-08-01 13:31:08 +05306750 hdd_exit_netlink_services(hdd_ctx);
6751 mutex_destroy(&hdd_ctx->iface_change_lock);
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05306752#ifdef FEATURE_WLAN_CH_AVOID
6753 mutex_destroy(&hdd_ctx->avoid_freq_lock);
6754#endif
Abhishek Singhe9068f12017-03-31 14:14:52 +05306755
Abhishek Singhe9068f12017-03-31 14:14:52 +05306756 driver_status = hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
6757 if (driver_status)
6758 hdd_err("Psoc delete failed");
Dustin Brown6f17a022017-07-19 13:40:55 -07006759
Prashanth Bhatta527fd752016-04-28 12:35:23 -07006760 hdd_context_destroy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006761}
6762
6763void __hdd_wlan_exit(void)
6764{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006765 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006766
Dustin Brown491d54b2018-03-14 12:39:11 -07006767 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006768
Anurag Chouhan6d760662016-02-20 16:05:43 +05306769 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006770 if (!hdd_ctx) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006771 hdd_err("Invalid HDD Context");
Dustin Browne74003f2018-03-14 12:51:58 -07006772 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006773 return;
6774 }
6775
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006776 /* Do all the cleanup before deregistering the driver */
6777 hdd_wlan_exit(hdd_ctx);
Mohit Khannaebf8a862016-04-28 17:53:59 -07006778
Dustin Browne74003f2018-03-14 12:51:58 -07006779 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006780}
6781
6782#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Liangwei Dongaef84342016-10-21 05:28:00 -04006783/**
6784 * hdd_skip_acs_scan_timer_handler() - skip ACS scan timer timeout handler
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006785 * @data: pointer to struct hdd_context
Liangwei Dongaef84342016-10-21 05:28:00 -04006786 *
6787 * This function will reset acs_scan_status to eSAP_DO_NEW_ACS_SCAN.
6788 * Then new ACS request will do a fresh scan without reusing the cached
6789 * scan information.
6790 *
6791 * Return: void
6792 */
Tang Yingying523322d2017-01-17 23:28:43 +08006793static void hdd_skip_acs_scan_timer_handler(void *data)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006794{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006795 struct hdd_context *hdd_ctx = (struct hdd_context *) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006796
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006797 hdd_debug("ACS Scan result expired. Reset ACS scan skip");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006798 hdd_ctx->skip_acs_scan_status = eSAP_DO_NEW_ACS_SCAN;
Liangwei Dongaef84342016-10-21 05:28:00 -04006799 qdf_spin_lock(&hdd_ctx->acs_skip_lock);
6800 qdf_mem_free(hdd_ctx->last_acs_channel_list);
6801 hdd_ctx->last_acs_channel_list = NULL;
6802 hdd_ctx->num_of_channels = 0;
6803 qdf_spin_unlock(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006804
6805 if (!hdd_ctx->hHal)
6806 return;
6807 sme_scan_flush_result(hdd_ctx->hHal);
6808}
6809#endif
6810
6811#ifdef QCA_HT_2040_COEX
Jeff Johnsone7672e72017-10-21 15:10:04 -07006812int hdd_wlan_set_ht2040_mode(struct hdd_adapter *adapter, uint16_t sta_id,
6813 struct qdf_mac_addr sta_mac, int channel_type)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006814{
6815 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306816 QDF_STATUS qdf_status;
Jeff Johnsone7672e72017-10-21 15:10:04 -07006817 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006818
6819 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
6820
6821 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306822 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006823 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306824
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006825 if (!hdd_ctx->hHal)
6826 return -EINVAL;
6827
Jeff Johnsone7672e72017-10-21 15:10:04 -07006828 qdf_status = sme_notify_ht2040_mode(hdd_ctx->hHal, sta_id, sta_mac,
Jeff Johnson1b780e42017-10-31 14:11:45 -07006829 adapter->session_id, channel_type);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306830 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006831 hdd_err("Fail to send notification with ht2040 mode");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006832 return -EINVAL;
6833 }
6834
6835 return 0;
6836}
6837#endif
6838
6839/**
6840 * hdd_wlan_notify_modem_power_state() - notify FW with modem power status
6841 * @state: state
6842 *
6843 * This function notifies FW with modem power status
6844 *
6845 * Return: 0 if successful, error number otherwise
6846 */
6847int hdd_wlan_notify_modem_power_state(int state)
6848{
6849 int status;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306850 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006851 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006852
Anurag Chouhan6d760662016-02-20 16:05:43 +05306853 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006854 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306855 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006856 return status;
Abhishek Singh23edd1c2016-05-05 11:56:06 +05306857
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006858 if (!hdd_ctx->hHal)
6859 return -EINVAL;
6860
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306861 qdf_status = sme_notify_modem_power_state(hdd_ctx->hHal, state);
6862 if (QDF_STATUS_SUCCESS != qdf_status) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006863 hdd_err("Fail to send notification with modem power state %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006864 state);
6865 return -EINVAL;
6866 }
6867 return 0;
6868}
6869
6870/**
6871 *
6872 * hdd_post_cds_enable_config() - HDD post cds start config helper
6873 * @adapter - Pointer to the HDD
6874 *
6875 * Return: None
6876 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006877QDF_STATUS hdd_post_cds_enable_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006878{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306879 QDF_STATUS qdf_ret_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006880
6881 /*
6882 * Send ready indication to the HDD. This will kick off the MAC
6883 * into a 'running' state and should kick off an initial scan.
6884 */
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05306885 qdf_ret_status = sme_hdd_ready_ind(hdd_ctx->hHal);
6886 if (!QDF_IS_STATUS_SUCCESS(qdf_ret_status)) {
Jeff Johnson760350b2016-08-15 14:01:52 -07006887 hdd_err("sme_hdd_ready_ind() failed with status code %08d [x%08x]",
6888 qdf_ret_status, qdf_ret_status);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306889 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006890 }
6891
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306892 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006893}
6894
Sourav Mohapatra92ea8d62018-02-05 10:03:10 +05306895struct hdd_adapter *hdd_get_first_valid_adapter(struct hdd_context *hdd_ctx)
6896{
6897 struct hdd_adapter *adapter;
6898
6899 hdd_for_each_adapter(hdd_ctx, adapter) {
6900 if (adapter && adapter->magic == WLAN_HDD_ADAPTER_MAGIC)
6901 return adapter;
6902 }
6903
6904 return NULL;
6905}
6906
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006907/* wake lock APIs for HDD */
6908void hdd_prevent_suspend(uint32_t reason)
6909{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306910 qdf_wake_lock_acquire(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006911}
6912
6913void hdd_allow_suspend(uint32_t reason)
6914{
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306915 qdf_wake_lock_release(&wlan_wake_lock, reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006916}
6917
6918void hdd_prevent_suspend_timeout(uint32_t timeout, uint32_t reason)
6919{
Anurag Chouhan01cfa4e2016-09-04 15:10:49 +05306920 cds_host_diag_log_work(&wlan_wake_lock, timeout, reason);
6921 qdf_wake_lock_timeout_acquire(&wlan_wake_lock, timeout);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006922}
6923
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006924/* Initialize channel list in sme based on the country code */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006925QDF_STATUS hdd_set_sme_chan_list(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006926{
Amar Singhal5cccafe2017-02-15 12:42:58 -08006927
Amar Singhal6f8592b2017-04-26 14:31:58 -07006928 return sme_init_chan_list(hdd_ctx->hHal,
6929 hdd_ctx->reg.alpha2,
6930 hdd_ctx->reg.cc_src);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006931}
6932
6933/**
6934 * hdd_is_5g_supported() - check if hardware supports 5GHz
6935 * @hdd_ctx: Pointer to the hdd context
6936 *
6937 * HDD function to know if hardware supports 5GHz
6938 *
6939 * Return: true if hardware supports 5GHz
6940 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006941bool hdd_is_5g_supported(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006942{
Amar Singhal58b45ef2017-08-01 13:43:54 -07006943 if (!hdd_ctx)
zdingf54169a2016-10-12 17:08:45 +08006944 return true;
6945
Varun Reddy Yeturua48bc412017-11-17 15:33:35 -08006946 if (hdd_ctx->curr_band != BAND_2G)
zdingf54169a2016-10-12 17:08:45 +08006947 return true;
6948 else
6949 return false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006950}
6951
Jeff Johnsond49c4a12017-08-28 12:08:05 -07006952static int hdd_wiphy_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006953{
6954 struct wiphy *wiphy;
Amar Singhale4f28ee2015-10-21 14:36:56 -07006955 int ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006956
6957 wiphy = hdd_ctx->wiphy;
6958
6959 /*
6960 * The channel information in
6961 * wiphy needs to be initialized before wiphy registration
6962 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006963 ret_val = hdd_regulatory_init(hdd_ctx, wiphy);
6964 if (ret_val) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08006965 hdd_err("regulatory init failed");
Amar Singhale4f28ee2015-10-21 14:36:56 -07006966 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006967 }
6968
6969#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
6970 wiphy->wowlan = &wowlan_support_reg_init;
6971#else
6972 wiphy->wowlan.flags = WIPHY_WOWLAN_ANY |
6973 WIPHY_WOWLAN_MAGIC_PKT |
6974 WIPHY_WOWLAN_DISCONNECT |
6975 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
6976 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
6977 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
6978 WIPHY_WOWLAN_4WAY_HANDSHAKE |
6979 WIPHY_WOWLAN_RFKILL_RELEASE;
6980
6981 wiphy->wowlan.n_patterns = (WOW_MAX_FILTER_LISTS *
6982 WOW_MAX_FILTERS_PER_LIST);
6983 wiphy->wowlan.pattern_min_len = WOW_MIN_PATTERN_SIZE;
6984 wiphy->wowlan.pattern_max_len = WOW_MAX_PATTERN_SIZE;
6985#endif
6986
6987 /* registration of wiphy dev with cfg80211 */
Amar Singhale4f28ee2015-10-21 14:36:56 -07006988 ret_val = wlan_hdd_cfg80211_register(wiphy);
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306989 if (0 > ret_val) {
Amar Singhale4f28ee2015-10-21 14:36:56 -07006990 hdd_err("wiphy registration failed");
Ashish Kumar Dhanotiya4da37922017-04-05 14:17:56 +05306991 return ret_val;
6992 }
6993
Amar Singhal2d812012018-02-03 15:06:47 +08006994 pld_increment_driver_load_cnt(hdd_ctx->parent_dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006995
Amar Singhale4f28ee2015-10-21 14:36:56 -07006996 return ret_val;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006997}
6998
Mohit Khannaca4173b2017-09-12 21:52:19 -07006999#ifdef MSM_PLATFORM
7000/**
7001 * hdd_display_periodic_stats() - Function to display periodic stats
7002 * @hdd_ctx - handle to hdd context
7003 * @bool data_in_interval - true, if data detected in bw time interval
7004 *
7005 * The periodicity is determined by hdd_ctx->config->periodic_stats_disp_time.
7006 * Stats show up in wlan driver logs.
7007 *
7008 * Returns: None
7009 */
7010static inline
7011void hdd_display_periodic_stats(struct hdd_context *hdd_ctx,
7012 bool data_in_interval)
7013{
7014 static u32 counter;
7015 static bool data_in_time_period;
7016 ol_txrx_pdev_handle pdev;
7017
7018 if (hdd_ctx->config->periodic_stats_disp_time == 0)
7019 return;
7020
7021 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
7022 if (!pdev) {
7023 hdd_err("pdev is NULL");
7024 return;
7025 }
7026
7027 counter++;
7028 if (data_in_interval)
7029 data_in_time_period = data_in_interval;
7030
7031 if (counter * hdd_ctx->config->busBandwidthComputeInterval >=
7032 hdd_ctx->config->periodic_stats_disp_time * 1000) {
7033 if (data_in_time_period) {
7034 cdp_display_stats(cds_get_context(QDF_MODULE_ID_SOC),
7035 CDP_TXRX_PATH_STATS,
7036 QDF_STATS_VERBOSITY_LEVEL_LOW);
7037 wlan_hdd_display_netif_queue_history
7038 (hdd_ctx, QDF_STATS_VERBOSITY_LEVEL_LOW);
7039 qdf_dp_trace_dump_stats();
7040 }
7041 counter = 0;
7042 data_in_time_period = false;
7043 }
7044}
7045
Ravi Joshie2331e82015-07-01 18:18:54 -07007046/**
Yuanyuan Liu13738502016-04-06 17:41:37 -07007047 * hdd_pld_request_bus_bandwidth() - Function to control bus bandwidth
Ravi Joshie2331e82015-07-01 18:18:54 -07007048 * @hdd_ctx - handle to hdd context
7049 * @tx_packets - transmit packet count
7050 * @rx_packets - receive packet count
7051 *
7052 * The function controls the bus bandwidth and dynamic control of
7053 * tcp delayed ack configuration
7054 *
7055 * Returns: None
7056 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007057
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007058static void hdd_pld_request_bus_bandwidth(struct hdd_context *hdd_ctx,
Jeff Johnson590e2012016-10-05 16:16:24 -07007059 const uint64_t tx_packets,
7060 const uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007061{
Mohit Khannaca4173b2017-09-12 21:52:19 -07007062 u64 total_pkts = tx_packets + rx_packets;
Mohit Khannae71e2262015-11-10 09:37:24 -08007063 uint64_t temp_rx = 0;
7064 uint64_t temp_tx = 0;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007065 enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
Mohit Khannac3da7062017-02-08 21:08:56 -08007066 static enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
Mohit Khannae71e2262015-11-10 09:37:24 -08007067 enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007068 uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007069 uint16_t index = 0;
7070 bool vote_level_change = false;
7071 bool rx_level_change = false;
7072 bool tx_level_change = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007073
Mohit Khannaca4173b2017-09-12 21:52:19 -07007074 if (total_pkts > hdd_ctx->config->busBandwidthHighThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007075 next_vote_level = PLD_BUS_WIDTH_HIGH;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007076 else if (total_pkts > hdd_ctx->config->busBandwidthMediumThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007077 next_vote_level = PLD_BUS_WIDTH_MEDIUM;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007078 else if (total_pkts > hdd_ctx->config->busBandwidthLowThreshold)
Yuanyuan Liu13738502016-04-06 17:41:37 -07007079 next_vote_level = PLD_BUS_WIDTH_LOW;
Yue Mad6478e42015-10-20 18:49:24 -07007080 else
Yuanyuan Liu13738502016-04-06 17:41:37 -07007081 next_vote_level = PLD_BUS_WIDTH_NONE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007082
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007083 if (hdd_ctx->cur_vote_level != next_vote_level) {
Ravi Joshie2331e82015-07-01 18:18:54 -07007084 hdd_debug("trigger level %d, tx_packets: %lld, rx_packets: %lld",
7085 next_vote_level, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007086 hdd_ctx->cur_vote_level = next_vote_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007087 vote_level_change = true;
Yuanyuan Liu13738502016-04-06 17:41:37 -07007088 pld_request_bus_bandwidth(hdd_ctx->parent_dev, next_vote_level);
Nirav Shah3bbfa512016-05-12 16:43:49 +05307089 if (next_vote_level == PLD_BUS_WIDTH_LOW) {
Nirav Shahffc6a092016-06-09 16:09:08 +05307090 if (hdd_ctx->hbw_requested) {
7091 pld_remove_pm_qos(hdd_ctx->parent_dev);
7092 hdd_ctx->hbw_requested = false;
7093 }
Nirav Shah3bbfa512016-05-12 16:43:49 +05307094 if (cds_sched_handle_throughput_req(false))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007095 hdd_warn("low bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007096 } else {
Nirav Shahffc6a092016-06-09 16:09:08 +05307097 if (!hdd_ctx->hbw_requested) {
7098 pld_request_pm_qos(hdd_ctx->parent_dev, 1);
7099 hdd_ctx->hbw_requested = true;
7100 }
7101
Nirav Shah3bbfa512016-05-12 16:43:49 +05307102 if (cds_sched_handle_throughput_req(true))
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007103 hdd_warn("high bandwidth set rx affinity fail");
Jeff Johnson59eb5fd2017-10-05 09:42:39 -07007104 }
Orhan K AKYILDIZ1481aff2016-05-16 12:40:13 -07007105 hdd_napi_apply_throughput_policy(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007106 }
Mohit Khannae71e2262015-11-10 09:37:24 -08007107
Mohit Khannaf8f96822017-05-17 17:11:59 -07007108 qdf_dp_trace_throttle_live_mode(
7109 (next_vote_level > PLD_BUS_WIDTH_NONE) ? true : false);
7110
Mohit Khannae71e2262015-11-10 09:37:24 -08007111 /* fine-tuning parameters for RX Flows */
7112 temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
7113
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007114 hdd_ctx->prev_rx = rx_packets;
Mohit Khannab1dd1e82017-02-04 15:14:38 -08007115
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307116 if (temp_rx < hdd_ctx->config->busBandwidthLowThreshold)
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07007117 hdd_disable_rx_ol_for_low_tput(hdd_ctx, true);
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307118 else
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07007119 hdd_disable_rx_ol_for_low_tput(hdd_ctx, false);
Poddar, Siddarth47c23402017-10-25 12:17:39 +05307120
Ravi Joshifed83572016-10-07 16:20:37 -07007121 if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh) {
7122 if ((hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH) &&
7123 (++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
7124 next_rx_level = WLAN_SVC_TP_HIGH;
7125 }
Ravi Joshib89e7f72016-09-07 13:43:15 -07007126 } else {
Ravi Joshib89e7f72016-09-07 13:43:15 -07007127 hdd_ctx->rx_high_ind_cnt = 0;
Mohit Khannac3da7062017-02-08 21:08:56 -08007128 next_rx_level = WLAN_SVC_TP_LOW;
Ravi Joshib89e7f72016-09-07 13:43:15 -07007129 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007130
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007131 if (hdd_ctx->cur_rx_level != next_rx_level) {
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007132 struct wlan_rx_tp_data rx_tp_data = {0};
7133
Ravi Joshie2331e82015-07-01 18:18:54 -07007134 hdd_debug("TCP DELACK trigger level %d, average_rx: %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007135 next_rx_level, temp_rx);
7136 hdd_ctx->cur_rx_level = next_rx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007137 rx_level_change = true;
Ravi Joshie2331e82015-07-01 18:18:54 -07007138 /* Send throughput indication only if it is enabled.
7139 * Disabling tcp_del_ack will revert the tcp stack behavior
7140 * to default delayed ack. Note that this will disable the
7141 * dynamic delayed ack mechanism across the system
7142 */
7143 if (hdd_ctx->config->enable_tcp_delack)
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007144 rx_tp_data.rx_tp_flags |= TCP_DEL_ACK_IND;
7145
Mohit Khanna6272fb682017-04-13 09:34:36 -07007146 if (hdd_ctx->config->enable_tcp_adv_win_scale)
7147 rx_tp_data.rx_tp_flags |= TCP_ADV_WIN_SCL;
7148
Manjunathappa Prakashc13cb5b2017-10-09 01:47:07 -07007149 rx_tp_data.level = next_rx_level;
7150 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7151 WLAN_SVC_WLAN_TP_IND, &rx_tp_data,
7152 sizeof(rx_tp_data));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007153 }
7154
Mohit Khannae71e2262015-11-10 09:37:24 -08007155 /* fine-tuning parameters for TX Flows */
7156 temp_tx = (tx_packets + hdd_ctx->prev_tx) / 2;
7157 hdd_ctx->prev_tx = tx_packets;
7158 if (temp_tx > hdd_ctx->config->tcp_tx_high_tput_thres)
7159 next_tx_level = WLAN_SVC_TP_HIGH;
7160 else
7161 next_tx_level = WLAN_SVC_TP_LOW;
7162
Prakash Manjunathappae73e3b52018-02-27 18:56:22 -08007163 if ((hdd_ctx->config->enable_tcp_limit_output) &&
7164 (hdd_ctx->cur_tx_level != next_tx_level)) {
Mohit Khannae71e2262015-11-10 09:37:24 -08007165 hdd_debug("change TCP TX trigger level %d, average_tx: %llu",
7166 next_tx_level, temp_tx);
7167 hdd_ctx->cur_tx_level = next_tx_level;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007168 tx_level_change = true;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +05307169 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
7170 WLAN_SVC_WLAN_TP_TX_IND,
Mohit Khannae71e2262015-11-10 09:37:24 -08007171 &next_tx_level,
7172 sizeof(next_tx_level));
7173 }
7174
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007175 index = hdd_ctx->hdd_txrx_hist_idx;
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007176 if (vote_level_change || tx_level_change || rx_level_change) {
7177 hdd_ctx->hdd_txrx_hist[index].next_tx_level = next_tx_level;
7178 hdd_ctx->hdd_txrx_hist[index].next_rx_level = next_rx_level;
7179 hdd_ctx->hdd_txrx_hist[index].next_vote_level = next_vote_level;
7180 hdd_ctx->hdd_txrx_hist[index].interval_rx = rx_packets;
7181 hdd_ctx->hdd_txrx_hist[index].interval_tx = tx_packets;
7182 hdd_ctx->hdd_txrx_hist[index].qtime = qdf_get_log_timestamp();
7183 hdd_ctx->hdd_txrx_hist_idx++;
7184 hdd_ctx->hdd_txrx_hist_idx &= NUM_TX_RX_HISTOGRAM_MASK;
7185 }
Mohit Khannaca4173b2017-09-12 21:52:19 -07007186
7187 hdd_display_periodic_stats(hdd_ctx, (total_pkts > 0) ? true : false);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007188}
7189
7190#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307191static void hdd_bus_bw_work_handler(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007192{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007193 struct hdd_context *hdd_ctx = container_of(work, struct hdd_context,
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307194 bus_bw_work);
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307195 struct hdd_adapter *adapter = NULL, *con_sap_adapter = NULL;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307196 uint64_t tx_packets = 0, rx_packets = 0;
Himanshu Agarwala6cedee2016-06-08 14:50:00 +05307197 uint64_t fwd_tx_packets = 0, fwd_rx_packets = 0;
7198 uint64_t fwd_tx_packets_diff = 0, fwd_rx_packets_diff = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007199 uint64_t total_tx = 0, total_rx = 0;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307200 A_STATUS ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007201 bool connected = false;
7202 uint32_t ipa_tx_packets = 0, ipa_rx_packets = 0;
7203
Prashanth Bhattaab004382016-10-11 16:08:11 -07007204 if (wlan_hdd_validate_context(hdd_ctx))
7205 return;
7206
Jeff Johnson214671b2017-10-30 19:45:23 -07007207 if (hdd_ctx->is_wiphy_suspended)
Jingxiang Gec64e1932017-08-22 14:38:59 +08007208 goto restart_timer;
7209
Dustin Brown920397d2017-12-13 16:27:50 -08007210 hdd_for_each_adapter(hdd_ctx, adapter) {
Manjeet Singh01327cc2016-09-03 12:14:25 +05307211 /*
7212 * Validate magic so we don't end up accessing
7213 * an invalid adapter.
7214 */
7215 if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)
7216 continue;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007217
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007218 if ((adapter->device_mode == QDF_STA_MODE ||
7219 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007220 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->conn_info.connState
7221 != eConnectionState_Associated) {
7222
7223 continue;
7224 }
7225
Krunal Soni9b04c9b2016-03-10 13:08:05 -08007226 if ((adapter->device_mode == QDF_SAP_MODE ||
7227 adapter->device_mode == QDF_P2P_GO_MODE) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -07007228 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active == false) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007229
7230 continue;
7231 }
7232
7233 tx_packets += HDD_BW_GET_DIFF(adapter->stats.tx_packets,
7234 adapter->prev_tx_packets);
7235 rx_packets += HDD_BW_GET_DIFF(adapter->stats.rx_packets,
7236 adapter->prev_rx_packets);
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307237
7238 if (adapter->device_mode == QDF_SAP_MODE ||
7239 adapter->device_mode == QDF_P2P_GO_MODE ||
7240 adapter->device_mode == QDF_IBSS_MODE) {
7241
Dhanashri Atrea8f82f22017-01-23 12:58:24 -08007242 ret = cdp_get_intra_bss_fwd_pkts_count(
7243 cds_get_context(QDF_MODULE_ID_SOC),
Jeff Johnson1b780e42017-10-31 14:11:45 -07007244 adapter->session_id,
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307245 &fwd_tx_packets, &fwd_rx_packets);
7246 if (ret == A_OK) {
7247 fwd_tx_packets_diff += HDD_BW_GET_DIFF(
7248 fwd_tx_packets,
7249 adapter->prev_fwd_tx_packets);
7250 fwd_rx_packets_diff += HDD_BW_GET_DIFF(
7251 fwd_tx_packets,
7252 adapter->prev_fwd_rx_packets);
7253 }
7254 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007255
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307256 if (adapter->device_mode == QDF_SAP_MODE)
7257 con_sap_adapter = adapter;
7258
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007259 total_rx += adapter->stats.rx_packets;
7260 total_tx += adapter->stats.tx_packets;
7261
7262 spin_lock_bh(&hdd_ctx->bus_bw_lock);
7263 adapter->prev_tx_packets = adapter->stats.tx_packets;
7264 adapter->prev_rx_packets = adapter->stats.rx_packets;
Himanshu Agarwal5ac2f7b2016-05-06 20:08:10 +05307265 adapter->prev_fwd_tx_packets = fwd_tx_packets;
7266 adapter->prev_fwd_rx_packets = fwd_rx_packets;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007267 spin_unlock_bh(&hdd_ctx->bus_bw_lock);
7268 connected = true;
7269 }
7270
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007271 if (!connected) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007272 hdd_err("bus bandwidth timer running in disconnected state");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007273 return;
7274 }
7275
Yun Parka29974a2018-04-09 12:05:49 -07007276 /* add intra bss forwarded tx and rx packets */
7277 tx_packets += fwd_tx_packets_diff;
7278 rx_packets += fwd_rx_packets_diff;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007279
Yun Parka29974a2018-04-09 12:05:49 -07007280 if (ucfg_ipa_is_fw_wdi_activated(hdd_ctx->hdd_pdev)) {
7281 ucfg_ipa_uc_stat_query(hdd_ctx->hdd_pdev, &ipa_tx_packets,
7282 &ipa_rx_packets);
7283 tx_packets += (uint64_t)ipa_tx_packets;
7284 rx_packets += (uint64_t)ipa_rx_packets;
7285
Sravan Kumar Kairam86fce772018-04-26 14:15:30 +05307286 if (con_sap_adapter) {
7287 con_sap_adapter->stats.tx_packets += ipa_tx_packets;
7288 con_sap_adapter->stats.rx_packets += ipa_rx_packets;
7289 }
7290
Yun Parka29974a2018-04-09 12:05:49 -07007291 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, tx_packets, rx_packets);
7292 ucfg_ipa_uc_stat_request(hdd_ctx->hdd_pdev, 2);
7293 }
7294
7295 hdd_pld_request_bus_bandwidth(hdd_ctx, tx_packets, rx_packets);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007296
Jingxiang Gec64e1932017-08-22 14:38:59 +08007297restart_timer:
Dustin Brown2ed60362017-01-18 12:25:50 -08007298 /* ensure periodic timer should still be running before restarting it */
Dustin Brownfce08d12017-01-17 16:29:38 -08007299 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown2ed60362017-01-18 12:25:50 -08007300 if (hdd_ctx->bus_bw_timer_running)
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +05307301 qdf_timer_mod(&hdd_ctx->bus_bw_timer,
Dustin Brownfce08d12017-01-17 16:29:38 -08007302 hdd_ctx->config->busBandwidthComputeInterval);
Dustin Brownfce08d12017-01-17 16:29:38 -08007303 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007304}
Prashanth Bhattaab004382016-10-11 16:08:11 -07007305
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307306/**
7307 * __hdd_bus_bw_cbk() - Bus bandwidth data structure callback.
7308 * @arg: Argument of timer function
7309 *
7310 * Schedule a workqueue in this function where all the processing is done.
7311 *
7312 * Return: None.
7313 */
7314static void __hdd_bus_bw_cbk(void *arg)
7315{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007316 struct hdd_context *hdd_ctx = (struct hdd_context *) arg;
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307317
7318 if (wlan_hdd_validate_context(hdd_ctx))
7319 return;
7320
7321 schedule_work(&hdd_ctx->bus_bw_work);
7322}
7323
7324/**
7325 * hdd_bus_bw_cbk() - Wrapper for bus bw callback for SSR protection.
7326 * @arg: Argument of timer function
7327 *
7328 * Return: None.
7329 */
7330static void hdd_bus_bw_cbk(void *arg)
7331{
7332 cds_ssr_protect(__func__);
7333 __hdd_bus_bw_cbk(arg);
7334 cds_ssr_unprotect(__func__);
7335}
7336
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007337int hdd_bus_bandwidth_init(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007338{
7339 spin_lock_init(&hdd_ctx->bus_bw_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307340 INIT_WORK(&hdd_ctx->bus_bw_work,
7341 hdd_bus_bw_work_handler);
Dustin Brownfce08d12017-01-17 16:29:38 -08007342 hdd_ctx->bus_bw_timer_running = false;
7343 qdf_spinlock_create(&hdd_ctx->bus_bw_timer_lock);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307344 qdf_timer_init(NULL,
7345 &hdd_ctx->bus_bw_timer,
7346 hdd_bus_bw_cbk, (void *)hdd_ctx,
7347 QDF_TIMER_TYPE_SW);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007348
7349 return 0;
7350}
7351
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007352void hdd_bus_bandwidth_destroy(struct hdd_context *hdd_ctx)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007353{
Dustin Brownfce08d12017-01-17 16:29:38 -08007354 if (hdd_ctx->bus_bw_timer_running)
Prashanth Bhattaab004382016-10-11 16:08:11 -07007355 hdd_reset_tcp_delack(hdd_ctx);
7356
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007357 hdd_debug("wait for bus bw work to flush");
Nirav Shaheb017be2018-02-15 11:20:58 +05307358 hdd_cancel_bus_bw_work(hdd_ctx);
Poddar, Siddarth2333acb2017-01-09 16:45:39 +05307359 qdf_timer_free(&hdd_ctx->bus_bw_timer);
Dustin Brownfce08d12017-01-17 16:29:38 -08007360 hdd_ctx->bus_bw_timer_running = false;
7361 qdf_spinlock_destroy(&hdd_ctx->bus_bw_timer_lock);
Prashanth Bhattaab004382016-10-11 16:08:11 -07007362}
Lin Baic5c06882017-09-21 13:58:43 +08007363
7364void hdd_bus_bw_cancel_work(struct hdd_context *hdd_ctx)
7365{
7366 if (hdd_ctx)
7367 cancel_work_sync(&hdd_ctx->bus_bw_work);
7368}
jiadcdaf9bd2017-10-26 12:20:21 +08007369
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007370#endif
7371
7372/**
Nirav Shahed34b212016-04-25 10:59:16 +05307373 * wlan_hdd_init_tx_rx_histogram() - init tx/rx histogram stats
7374 * @hdd_ctx: hdd context
7375 *
7376 * Return: 0 for success or error code
7377 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007378static int wlan_hdd_init_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307379{
7380 hdd_ctx->hdd_txrx_hist = qdf_mem_malloc(
7381 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
7382 if (hdd_ctx->hdd_txrx_hist == NULL) {
Jeff Johnson760350b2016-08-15 14:01:52 -07007383 hdd_err("Failed malloc for hdd_txrx_hist");
Nirav Shahed34b212016-04-25 10:59:16 +05307384 return -ENOMEM;
7385 }
7386 return 0;
7387}
7388
7389/**
7390 * wlan_hdd_deinit_tx_rx_histogram() - deinit tx/rx histogram stats
7391 * @hdd_ctx: hdd context
7392 *
7393 * Return: none
7394 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007395void wlan_hdd_deinit_tx_rx_histogram(struct hdd_context *hdd_ctx)
Nirav Shahed34b212016-04-25 10:59:16 +05307396{
Ashish Kumar Dhanotiyaaa2b17c2017-03-29 00:41:32 +05307397 if (!hdd_ctx || hdd_ctx->hdd_txrx_hist == NULL)
7398 return;
7399
7400 qdf_mem_free(hdd_ctx->hdd_txrx_hist);
7401 hdd_ctx->hdd_txrx_hist = NULL;
Nirav Shahed34b212016-04-25 10:59:16 +05307402}
7403
Nirav Shahda008342016-05-17 18:50:40 +05307404static uint8_t *convert_level_to_string(uint32_t level)
7405{
7406 switch (level) {
7407 /* initialize the wlan sub system */
7408 case WLAN_SVC_TP_NONE:
7409 return "NONE";
7410 case WLAN_SVC_TP_LOW:
7411 return "LOW";
7412 case WLAN_SVC_TP_MEDIUM:
7413 return "MED";
7414 case WLAN_SVC_TP_HIGH:
7415 return "HIGH";
7416 default:
7417 return "INVAL";
7418 }
7419}
7420
Nirav Shahed34b212016-04-25 10:59:16 +05307421
7422/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007423 * wlan_hdd_display_tx_rx_histogram() - display tx rx histogram
7424 * @hdd_ctx: hdd context
7425 *
7426 * Return: none
7427 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007428void wlan_hdd_display_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007429{
7430 int i;
7431
7432#ifdef MSM_PLATFORM
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007433 hdd_debug("BW compute Interval: %dms",
Nirav Shahda008342016-05-17 18:50:40 +05307434 hdd_ctx->config->busBandwidthComputeInterval);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007435 hdd_debug("BW High TH: %d BW Med TH: %d BW Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007436 hdd_ctx->config->busBandwidthHighThreshold,
7437 hdd_ctx->config->busBandwidthMediumThreshold,
7438 hdd_ctx->config->busBandwidthLowThreshold);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007439 hdd_debug("Enable TCP DEL ACK: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307440 hdd_ctx->config->enable_tcp_delack);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007441 hdd_debug("TCP DEL High TH: %d TCP DEL Low TH: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007442 hdd_ctx->config->tcpDelackThresholdHigh,
7443 hdd_ctx->config->tcpDelackThresholdLow);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007444 hdd_debug("TCP TX HIGH TP TH: %d (Use to set tcp_output_bytes_limit)",
Nirav Shahda008342016-05-17 18:50:40 +05307445 hdd_ctx->config->tcp_tx_high_tput_thres);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007446#endif
7447
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007448 hdd_debug("Total entries: %d Current index: %d",
Nirav Shahda008342016-05-17 18:50:40 +05307449 NUM_TX_RX_HISTOGRAM, hdd_ctx->hdd_txrx_hist_idx);
7450
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007451 hdd_debug("[index][timestamp]: interval_rx, interval_tx, bus_bw_level, RX TP Level, TX TP Level");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007452
7453 for (i = 0; i < NUM_TX_RX_HISTOGRAM; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007454 /* using hdd_log to avoid printing function name */
Mohit Khannaafff9fb2016-11-16 20:22:03 -08007455 if (hdd_ctx->hdd_txrx_hist[i].qtime > 0)
Dustin Brown632af712018-03-14 15:03:55 -07007456 hdd_debug("[%3d][%15llu]: %6llu, %6llu, %s, %s, %s",
7457 i, hdd_ctx->hdd_txrx_hist[i].qtime,
7458 hdd_ctx->hdd_txrx_hist[i].interval_rx,
7459 hdd_ctx->hdd_txrx_hist[i].interval_tx,
7460 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007461 hdd_ctx->hdd_txrx_hist[i].
7462 next_vote_level),
Dustin Brown632af712018-03-14 15:03:55 -07007463 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007464 hdd_ctx->hdd_txrx_hist[i].
7465 next_rx_level),
Dustin Brown632af712018-03-14 15:03:55 -07007466 convert_level_to_string(
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007467 hdd_ctx->hdd_txrx_hist[i].
7468 next_tx_level));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007469 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007470}
7471
7472/**
7473 * wlan_hdd_clear_tx_rx_histogram() - clear tx rx histogram
7474 * @hdd_ctx: hdd context
7475 *
7476 * Return: none
7477 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007478void wlan_hdd_clear_tx_rx_histogram(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007479{
7480 hdd_ctx->hdd_txrx_hist_idx = 0;
Nirav Shahed34b212016-04-25 10:59:16 +05307481 qdf_mem_zero(hdd_ctx->hdd_txrx_hist,
7482 (sizeof(struct hdd_tx_rx_histogram) * NUM_TX_RX_HISTOGRAM));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007483}
7484
Mohit Khannaca4173b2017-09-12 21:52:19 -07007485/* length of the netif queue log needed per adapter */
7486#define ADAP_NETIFQ_LOG_LEN ((20 * WLAN_REASON_TYPE_MAX) + 50)
7487
7488/**
7489 *
7490 * hdd_display_netif_queue_history_compact() - display compact netifq history
7491 * @hdd_ctx: hdd context
7492 *
7493 * Return: none
7494 */
7495static void
7496hdd_display_netif_queue_history_compact(struct hdd_context *hdd_ctx)
7497{
7498 int adapter_num = 0;
7499 int i;
7500 int bytes_written;
7501 u32 tbytes;
7502 qdf_time_t total, pause, unpause, curr_time, delta;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007503 char temp_str[20 * WLAN_REASON_TYPE_MAX];
jiadbdefb252018-01-03 14:27:06 +08007504 char *comb_log_str;
7505 uint32_t comb_log_str_size;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007506 struct hdd_adapter *adapter = NULL;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007507
jiadbdefb252018-01-03 14:27:06 +08007508 comb_log_str_size = (ADAP_NETIFQ_LOG_LEN * MAX_NUMBER_OF_ADAPTERS) + 1;
7509 comb_log_str = qdf_mem_malloc(comb_log_str_size);
7510 if (!comb_log_str) {
7511 hdd_err("failed to alloc comb_log_str");
7512 return;
7513 }
7514
Mohit Khannaca4173b2017-09-12 21:52:19 -07007515 bytes_written = 0;
Mohit Khannaca4173b2017-09-12 21:52:19 -07007516
Dustin Brown920397d2017-12-13 16:27:50 -08007517 hdd_for_each_adapter(hdd_ctx, adapter) {
Mohit Khannaca4173b2017-09-12 21:52:19 -07007518 curr_time = qdf_system_ticks();
7519 total = curr_time - adapter->start_time;
7520 delta = curr_time - adapter->last_time;
7521
7522 if (adapter->pause_map) {
7523 pause = adapter->total_pause_time + delta;
7524 unpause = adapter->total_unpause_time;
7525 } else {
7526 unpause = adapter->total_unpause_time + delta;
7527 pause = adapter->total_pause_time;
7528 }
7529
7530 tbytes = 0;
7531 qdf_mem_set(temp_str, 0, sizeof(temp_str));
7532 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7533 if (adapter->queue_oper_stats[i].pause_count == 0)
7534 continue;
7535 tbytes +=
7536 snprintf(
7537 &temp_str[tbytes],
7538 (tbytes >= sizeof(temp_str) ?
7539 0 : sizeof(temp_str) - tbytes),
7540 "%d(%d,%d) ",
7541 i,
7542 adapter->queue_oper_stats[i].
7543 pause_count,
7544 adapter->queue_oper_stats[i].
7545 unpause_count);
7546 }
7547 if (tbytes >= sizeof(temp_str))
7548 hdd_warn("log truncated");
7549
7550 bytes_written += snprintf(&comb_log_str[bytes_written],
jiadbdefb252018-01-03 14:27:06 +08007551 bytes_written >= comb_log_str_size ? 0 :
7552 comb_log_str_size - bytes_written,
Mohit Khannaca4173b2017-09-12 21:52:19 -07007553 "[%d %d] (%d) %u/%ums %s|",
7554 adapter->session_id, adapter->device_mode,
7555 adapter->pause_map,
7556 qdf_system_ticks_to_msecs(pause),
7557 qdf_system_ticks_to_msecs(total),
7558 temp_str);
7559
Mohit Khannaca4173b2017-09-12 21:52:19 -07007560 adapter_num++;
7561 }
7562
7563 /* using QDF_TRACE to avoid printing function name */
7564 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_LOW,
7565 "STATS |%s", comb_log_str);
7566
jiadbdefb252018-01-03 14:27:06 +08007567 if (bytes_written >= comb_log_str_size)
Mohit Khannaca4173b2017-09-12 21:52:19 -07007568 hdd_warn("log string truncated");
jiadbdefb252018-01-03 14:27:06 +08007569
7570 qdf_mem_free(comb_log_str);
Mohit Khannaca4173b2017-09-12 21:52:19 -07007571}
7572
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007573/**
Srinivas Girigowdab841da72017-03-25 18:04:39 -07007574 * wlan_hdd_display_netif_queue_history() - display netif queue history
Jeff Johnson58adbcf2017-09-03 08:53:31 -07007575 * @hdd_ctx: hdd context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007576 *
7577 * Return: none
7578 */
Mohit Khannaca4173b2017-09-12 21:52:19 -07007579void
7580wlan_hdd_display_netif_queue_history(struct hdd_context *hdd_ctx,
7581 enum qdf_stats_verbosity_level verb_lvl)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007582{
7583
Jeff Johnson9d295242017-08-29 14:39:48 -07007584 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007585 int i;
Nirav Shahda008342016-05-17 18:50:40 +05307586 qdf_time_t total, pause, unpause, curr_time, delta;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007587
Mohit Khannaca4173b2017-09-12 21:52:19 -07007588 if (verb_lvl == QDF_STATS_VERBOSITY_LEVEL_LOW) {
7589 hdd_display_netif_queue_history_compact(hdd_ctx);
7590 return;
7591 }
7592
Dustin Brown920397d2017-12-13 16:27:50 -08007593 hdd_for_each_adapter(hdd_ctx, adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007594 hdd_debug("Netif queue operation statistics:");
7595 hdd_debug("Session_id %d device mode %d",
Jeff Johnson1b780e42017-10-31 14:11:45 -07007596 adapter->session_id, adapter->device_mode);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007597 hdd_debug("Current pause_map value %x", adapter->pause_map);
Nirav Shah617cff92016-04-25 10:24:24 +05307598 curr_time = qdf_system_ticks();
7599 total = curr_time - adapter->start_time;
Nirav Shahda008342016-05-17 18:50:40 +05307600 delta = curr_time - adapter->last_time;
Nirav Shah617cff92016-04-25 10:24:24 +05307601 if (adapter->pause_map) {
Nirav Shahda008342016-05-17 18:50:40 +05307602 pause = adapter->total_pause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307603 unpause = adapter->total_unpause_time;
7604 } else {
Nirav Shahda008342016-05-17 18:50:40 +05307605 unpause = adapter->total_unpause_time + delta;
Nirav Shah617cff92016-04-25 10:24:24 +05307606 pause = adapter->total_pause_time;
7607 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007608 hdd_debug("Total: %ums Pause: %ums Unpause: %ums",
Nirav Shah617cff92016-04-25 10:24:24 +05307609 qdf_system_ticks_to_msecs(total),
7610 qdf_system_ticks_to_msecs(pause),
7611 qdf_system_ticks_to_msecs(unpause));
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007612 hdd_debug("reason_type: pause_cnt: unpause_cnt: pause_time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007613
Nirav Shahda008342016-05-17 18:50:40 +05307614 for (i = WLAN_CONTROL_PATH; i < WLAN_REASON_TYPE_MAX; i++) {
7615 qdf_time_t pause_delta = 0;
7616
7617 if (adapter->pause_map & (1 << i))
7618 pause_delta = delta;
7619
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007620 /* using hdd_log to avoid printing function name */
Dustin Brown632af712018-03-14 15:03:55 -07007621 hdd_debug("%s: %d: %d: %ums",
7622 hdd_reason_type_to_string(i),
7623 adapter->queue_oper_stats[i].pause_count,
7624 adapter->queue_oper_stats[i].unpause_count,
7625 qdf_system_ticks_to_msecs(
7626 adapter->queue_oper_stats[i].total_pause_time +
7627 pause_delta));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007628 }
7629
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007630 hdd_debug("Netif queue operation history:");
7631 hdd_debug("Total entries: %d current index %d",
Nirav Shahda008342016-05-17 18:50:40 +05307632 WLAN_HDD_MAX_HISTORY_ENTRY, adapter->history_index);
7633
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007634 hdd_debug("index: time: action_type: reason_type: pause_map");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007635
7636 for (i = 0; i < WLAN_HDD_MAX_HISTORY_ENTRY; i++) {
Mohit Khanna3e2115b2016-10-11 13:18:29 -07007637 /* using hdd_log to avoid printing function name */
7638 if (adapter->queue_oper_history[i].time == 0)
7639 continue;
Dustin Brown632af712018-03-14 15:03:55 -07007640 hdd_debug("%d: %u: %s: %s: %x",
7641 i, qdf_system_ticks_to_msecs(
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007642 adapter->queue_oper_history[i].time),
Dustin Brown632af712018-03-14 15:03:55 -07007643 hdd_action_type_to_string(
7644 adapter->queue_oper_history[i].netif_action),
7645 hdd_reason_type_to_string(
7646 adapter->queue_oper_history[i].netif_reason),
7647 adapter->queue_oper_history[i].pause_map);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007648 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007649 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007650}
7651
7652/**
7653 * wlan_hdd_clear_netif_queue_history() - clear netif queue operation history
7654 * @hdd_ctx: hdd context
7655 *
7656 * Return: none
7657 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007658void wlan_hdd_clear_netif_queue_history(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007659{
Jeff Johnson9d295242017-08-29 14:39:48 -07007660 struct hdd_adapter *adapter = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007661
Dustin Brown920397d2017-12-13 16:27:50 -08007662 hdd_for_each_adapter(hdd_ctx, adapter) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307663 qdf_mem_zero(adapter->queue_oper_stats,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007664 sizeof(adapter->queue_oper_stats));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05307665 qdf_mem_zero(adapter->queue_oper_history,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007666 sizeof(adapter->queue_oper_history));
Nirav Shah617cff92016-04-25 10:24:24 +05307667 adapter->history_index = 0;
7668 adapter->start_time = adapter->last_time = qdf_system_ticks();
7669 adapter->total_pause_time = 0;
7670 adapter->total_unpause_time = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007671 }
7672}
7673
7674/**
7675 * hdd_11d_scan_done() - callback for 11d scan completion of flushing results
7676 * @halHandle: Hal handle
7677 * @pContext: Pointer to the context
7678 * @sessionId: Session ID
7679 * @scanId: Scan ID
7680 * @status: Status
7681 *
7682 * This is the callback to be executed when 11d scan is completed to flush out
7683 * the scan results
7684 *
7685 * 11d scan is done during driver load and is a passive scan on all
7686 * channels supported by the device, 11d scans may find some APs on
7687 * frequencies which are forbidden to be used in the regulatory domain
7688 * the device is operating in. If these APs are notified to the supplicant
7689 * it may try to connect to these APs, thus flush out all the scan results
7690 * which are present in SME after 11d scan is done.
7691 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307692 * Return: QDF_STATUS_SUCCESS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007693 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307694static QDF_STATUS hdd_11d_scan_done(tHalHandle halHandle, void *pContext,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007695 uint8_t sessionId, uint32_t scanId,
7696 eCsrScanStatus status)
7697{
Dustin Brown491d54b2018-03-14 12:39:11 -07007698 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007699
7700 sme_scan_flush_result(halHandle);
7701
Dustin Browne74003f2018-03-14 12:51:58 -07007702 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007703
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05307704 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007705}
7706
7707#ifdef WLAN_FEATURE_OFFLOAD_PACKETS
7708/**
7709 * hdd_init_offloaded_packets_ctx() - Initialize offload packets context
7710 * @hdd_ctx: hdd global context
7711 *
7712 * Return: none
7713 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007714static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007715{
7716 uint8_t i;
7717
7718 mutex_init(&hdd_ctx->op_ctx.op_lock);
7719 for (i = 0; i < MAXNUM_PERIODIC_TX_PTRNS; i++) {
7720 hdd_ctx->op_ctx.op_table[i].request_id = MAX_REQUEST_ID;
7721 hdd_ctx->op_ctx.op_table[i].pattern_id = i;
7722 }
7723}
7724#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007725static void hdd_init_offloaded_packets_ctx(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007726{
7727}
7728#endif
7729
Yingying Tang95409972016-10-20 15:16:15 +08007730#ifdef WLAN_FEATURE_WOW_PULSE
7731/**
7732 * wlan_hdd_set_wow_pulse() - call SME to send wmi cmd of wow pulse
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007733 * @phddctx: struct hdd_context structure pointer
Yingying Tang95409972016-10-20 15:16:15 +08007734 * @enable: enable or disable this behaviour
7735 *
7736 * Return: int
7737 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007738static int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007739{
7740 struct hdd_config *pcfg_ini = phddctx->config;
7741 struct wow_pulse_mode wow_pulse_set_info;
7742 QDF_STATUS status;
7743
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007744 hdd_debug("wow pulse enable flag is %d", enable);
Yingying Tang95409972016-10-20 15:16:15 +08007745
7746 if (false == phddctx->config->wow_pulse_support)
7747 return 0;
7748
7749 /* prepare the request to send to SME */
7750 if (enable == true) {
7751 wow_pulse_set_info.wow_pulse_enable = true;
7752 wow_pulse_set_info.wow_pulse_pin =
7753 pcfg_ini->wow_pulse_pin;
7754 wow_pulse_set_info.wow_pulse_interval_low =
7755 pcfg_ini->wow_pulse_interval_low;
7756 wow_pulse_set_info.wow_pulse_interval_high =
7757 pcfg_ini->wow_pulse_interval_high;
7758 } else {
7759 wow_pulse_set_info.wow_pulse_enable = false;
7760 wow_pulse_set_info.wow_pulse_pin = 0;
7761 wow_pulse_set_info.wow_pulse_interval_low = 0;
7762 wow_pulse_set_info.wow_pulse_interval_high = 0;
7763 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007764 hdd_debug("enable %d pin %d low %d high %d",
Yingying Tang95409972016-10-20 15:16:15 +08007765 wow_pulse_set_info.wow_pulse_enable,
7766 wow_pulse_set_info.wow_pulse_pin,
7767 wow_pulse_set_info.wow_pulse_interval_low,
7768 wow_pulse_set_info.wow_pulse_interval_high);
7769
7770 status = sme_set_wow_pulse(&wow_pulse_set_info);
7771 if (QDF_STATUS_E_FAILURE == status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007772 hdd_debug("sme_set_wow_pulse failure!");
Yingying Tang95409972016-10-20 15:16:15 +08007773 return -EIO;
7774 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007775 hdd_debug("sme_set_wow_pulse success!");
Yingying Tang95409972016-10-20 15:16:15 +08007776 return 0;
7777}
7778#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007779static inline int wlan_hdd_set_wow_pulse(struct hdd_context *phddctx, bool enable)
Yingying Tang95409972016-10-20 15:16:15 +08007780{
7781 return 0;
7782}
7783#endif
7784
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007785#ifdef WLAN_FEATURE_FASTPATH
7786/**
7787 * hdd_enable_fastpath() - Enable fastpath if enabled in config INI
7788 * @hdd_cfg: hdd config
7789 * @context: lower layer context
7790 *
7791 * Return: none
7792 */
Arun Khandavallifae92942016-08-01 13:31:08 +05307793void hdd_enable_fastpath(struct hdd_config *hdd_cfg,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007794 void *context)
7795{
7796 if (hdd_cfg->fastpath_enable)
7797 hif_enable_fastpath(context);
7798}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007799#endif
7800
Yuanyuan Liu13738502016-04-06 17:41:37 -07007801#if defined(FEATURE_WLAN_CH_AVOID)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007802/**
7803 * hdd_set_thermal_level_cb() - set thermal level callback function
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007804 * @context: hdd context pointer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007805 * @level: thermal level
7806 *
7807 * Change IPA data path to SW path when the thermal throttle level greater
7808 * than 0, and restore the original data path when throttle level is 0
7809 *
7810 * Return: none
7811 */
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007812static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007813{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007814 struct hdd_context *hdd_ctx = context;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08007815
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007816 /* Change IPA to SW path when throttle level greater than 0 */
7817 if (level > THROTTLE_LEVEL_0)
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05307818 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007819 else
7820 /* restore original concurrency mode */
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05307821 ucfg_ipa_send_mcc_scc_msg(hdd_ctx->hdd_pdev, hdd_ctx->mcc_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007822}
7823
7824/**
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307825 * hdd_get_safe_channel_from_pcl_and_acs_range() - Get safe channel for SAP
7826 * restart
Manishekar Chandrasekarandb9b8672016-06-10 23:31:19 +05307827 * @adapter: AP adapter, which should be checked for NULL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007828 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307829 * Get a safe channel to restart SAP. PCL already takes into account the
7830 * unsafe channels. So, the PCL is validated with the ACS range to provide
7831 * a safe channel for the SAP to restart.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007832 *
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307833 * Return: Channel number to restart SAP in case of success. In case of any
7834 * failure, the channel number returned is zero.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007835 */
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307836static uint8_t hdd_get_safe_channel_from_pcl_and_acs_range(
Jeff Johnson9d295242017-08-29 14:39:48 -07007837 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007838{
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307839 struct sir_pcl_list pcl;
7840 QDF_STATUS status;
7841 uint32_t i, j;
7842 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007843 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307844 bool found = false;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007845 int ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007846
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307847 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7848 if (!hdd_ctx) {
7849 hdd_err("invalid HDD context");
7850 return INVALID_CHANNEL_ID;
7851 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007852
Manishekar Chandrasekaran79746ac2016-06-24 04:45:33 +05307853 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7854 if (!hal_handle) {
7855 hdd_err("invalid HAL handle");
7856 return INVALID_CHANNEL_ID;
7857 }
7858
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007859 status = policy_mgr_get_pcl_for_existing_conn(hdd_ctx->hdd_psoc,
7860 PM_SAP_MODE, pcl.pcl_list, &pcl.pcl_len,
bings37bd58f2017-07-20 16:49:26 +08007861 pcl.weight_list, QDF_ARRAY_SIZE(pcl.weight_list),
7862 false);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307863 if (QDF_IS_STATUS_ERROR(status)) {
7864 hdd_err("Get PCL failed");
7865 return INVALID_CHANNEL_ID;
7866 }
7867
Frank Liudc2cefb2017-06-21 15:38:18 +08007868 /*
7869 * In some scenarios, like hw dbs disabled, sap+sap case, if operating
7870 * channel is unsafe channel, the pcl may be empty, instead of return,
7871 * try to choose a safe channel from acs range.
7872 */
7873 if (!pcl.pcl_len)
7874 hdd_debug("pcl length is zero!");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307875
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007876 hdd_debug("start:%d end:%d",
Jeff Johnsonb9424862017-10-30 08:49:35 -07007877 adapter->session.ap.sap_config.acs_cfg.start_ch,
7878 adapter->session.ap.sap_config.acs_cfg.end_ch);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307879
7880 /* PCL already takes unsafe channel into account */
7881 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007882 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307883 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007884 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307885 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007886 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007887 hdd_debug("found PCL safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307888 return pcl.pcl_list[i];
7889 }
7890 }
7891
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007892 hdd_debug("no safe channel from PCL found in ACS range");
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307893
7894 /* Try for safe channel from all valid channel */
7895 pcl.pcl_len = MAX_NUM_CHAN;
Liangwei Dong17bf2662018-01-05 02:02:05 -05007896 ret = hdd_get_valid_chan(hdd_ctx, pcl.pcl_list,
7897 &pcl.pcl_len);
7898 if (ret) {
7899 hdd_err("error %d in getting valid channel list", ret);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307900 return INVALID_CHANNEL_ID;
7901 }
7902
7903 for (i = 0; i < pcl.pcl_len; i++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007904 hdd_debug("chan[%d]:%d", i, pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307905 found = false;
7906 for (j = 0; j < hdd_ctx->unsafe_channel_count; j++) {
Krunal Soni15f0db12016-10-11 18:53:37 -07007907 if (pcl.pcl_list[i] ==
7908 hdd_ctx->unsafe_channel_list[j]) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007909 hdd_debug("unsafe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307910 found = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007911 break;
7912 }
7913 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307914
7915 if (found)
7916 continue;
7917
7918 if ((pcl.pcl_list[i] >=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007919 adapter->session.ap.sap_config.acs_cfg.start_ch) &&
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307920 (pcl.pcl_list[i] <=
Jeff Johnsonb9424862017-10-30 08:49:35 -07007921 adapter->session.ap.sap_config.acs_cfg.end_ch)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007922 hdd_debug("found safe chan:%d", pcl.pcl_list[i]);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307923 return pcl.pcl_list[i];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007924 }
7925 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307926
7927 return INVALID_CHANNEL_ID;
7928}
Nirav Shaheb017be2018-02-15 11:20:58 +05307929#endif
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307930
7931/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007932 * hdd_switch_sap_channel() - Move SAP to the given channel
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307933 * @adapter: AP adapter
7934 * @channel: Channel
Min Liu2fef5792018-01-19 17:59:42 +08007935 * @forced: Force to switch channel, ignore SCC/MCC check
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307936 *
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08007937 * Moves the SAP interface by invoking the function which
7938 * executes the callback to perform channel switch using (E)CSA.
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307939 *
7940 * Return: None
7941 */
Min Liu2fef5792018-01-19 17:59:42 +08007942void hdd_switch_sap_channel(struct hdd_adapter *adapter, uint8_t channel,
7943 bool forced)
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307944{
Jeff Johnson87251032017-08-29 13:31:11 -07007945 struct hdd_ap_ctx *hdd_ap_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307946 tHalHandle *hal_handle;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07007947 struct hdd_context *hdd_ctx;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307948
7949 if (!adapter) {
7950 hdd_err("invalid adapter");
7951 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007952 }
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307953
7954 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
7955
7956 hal_handle = WLAN_HDD_GET_HAL_CTX(adapter);
7957 if (!hal_handle) {
7958 hdd_err("invalid HAL handle");
7959 return;
7960 }
7961
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007962 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
7963
Jeff Johnson91df29d2017-10-27 19:29:50 -07007964 hdd_ap_ctx->sap_config.channel = channel;
7965 hdd_ap_ctx->sap_config.ch_params.ch_width =
7966 hdd_ap_ctx->sap_config.ch_width_orig;
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307967
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08007968 hdd_debug("chan:%d width:%d",
Jeff Johnson91df29d2017-10-27 19:29:50 -07007969 channel, hdd_ap_ctx->sap_config.ch_width_orig);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307970
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -07007971 wlan_reg_set_channel_params(hdd_ctx->hdd_pdev,
Jeff Johnson91df29d2017-10-27 19:29:50 -07007972 hdd_ap_ctx->sap_config.channel,
7973 hdd_ap_ctx->sap_config.sec_ch,
7974 &hdd_ap_ctx->sap_config.ch_params);
Manishekar Chandrasekaranc67b2bb2016-05-25 18:44:01 +05307975
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -08007976 policy_mgr_change_sap_channel_with_csa(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -07007977 adapter->session_id, channel,
Min Liu2fef5792018-01-19 17:59:42 +08007978 hdd_ap_ctx->sap_config.ch_width_orig, forced);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08007979}
Kapil Gupta8878ad92017-02-13 11:56:04 +05307980
Jeff Johnson9d295242017-08-29 14:39:48 -07007981int hdd_update_acs_timer_reason(struct hdd_adapter *adapter, uint8_t reason)
Kapil Gupta8878ad92017-02-13 11:56:04 +05307982{
7983 struct hdd_external_acs_timer_context *timer_context;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307984 int status;
7985 QDF_STATUS qdf_status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307986
7987 set_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
7988
7989 if (QDF_TIMER_STATE_RUNNING ==
Jeff Johnsonb9424862017-10-30 08:49:35 -07007990 qdf_mc_timer_get_current_state(&adapter->session.
Kapil Gupta8878ad92017-02-13 11:56:04 +05307991 ap.vendor_acs_timer)) {
Jeff Johnsonb9424862017-10-30 08:49:35 -07007992 qdf_mc_timer_stop(&adapter->session.ap.vendor_acs_timer);
Kapil Gupta8878ad92017-02-13 11:56:04 +05307993 }
7994 timer_context = (struct hdd_external_acs_timer_context *)
Jeff Johnsonb9424862017-10-30 08:49:35 -07007995 adapter->session.ap.vendor_acs_timer.user_data;
Kapil Gupta8878ad92017-02-13 11:56:04 +05307996 timer_context->reason = reason;
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307997 qdf_status =
Jeff Johnsonb9424862017-10-30 08:49:35 -07007998 qdf_mc_timer_start(&adapter->session.ap.vendor_acs_timer,
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05307999 WLAN_VENDOR_ACS_WAIT_TIME);
8000 if (qdf_status != QDF_STATUS_SUCCESS) {
8001 hdd_err("failed to start external acs timer");
8002 return -ENOSPC;
8003 }
8004 /* Update config to application */
8005 status = hdd_cfg80211_update_acs_config(adapter, reason);
Dustin Brown5e89ef82018-03-14 11:50:23 -07008006 hdd_info("Updated ACS config to nl with reason %d", reason);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308007
Himanshu Agarwaldfc4dca2017-08-29 19:49:05 +05308008 return status;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308009}
8010
Nirav Shaheb017be2018-02-15 11:20:58 +05308011#if defined(FEATURE_WLAN_CH_AVOID)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308012/**
8013 * hdd_unsafe_channel_restart_sap() - restart sap if sap is on unsafe channel
8014 * @hdd_ctx: hdd context pointer
8015 *
8016 * hdd_unsafe_channel_restart_sap check all unsafe channel list
8017 * and if ACS is enabled, driver will ask userspace to restart the
8018 * sap. User space on LTE coex indication restart driver.
8019 *
8020 * Return - none
8021 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008022void hdd_unsafe_channel_restart_sap(struct hdd_context *hdd_ctxt)
Agrawal Ashish467dde42016-09-08 18:44:22 +05308023{
Dustin Brown920397d2017-12-13 16:27:50 -08008024 struct hdd_adapter *adapter;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308025 uint32_t i;
8026 bool found = false;
8027 uint8_t restart_chan;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008028
Dustin Brown920397d2017-12-13 16:27:50 -08008029 hdd_for_each_adapter(hdd_ctxt, adapter) {
8030 if (!(adapter->device_mode == QDF_SAP_MODE &&
8031 adapter->session.ap.sap_config.acs_cfg.acs_mode)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008032 hdd_debug("skip device mode:%d acs:%d",
Dustin Brown920397d2017-12-13 16:27:50 -08008033 adapter->device_mode,
8034 adapter->session.ap.sap_config.
8035 acs_cfg.acs_mode);
8036 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308037 }
8038
8039 found = false;
8040 for (i = 0; i < hdd_ctxt->unsafe_channel_count; i++) {
Dustin Brown920397d2017-12-13 16:27:50 -08008041 if (adapter->session.ap.operating_channel ==
Agrawal Ashish467dde42016-09-08 18:44:22 +05308042 hdd_ctxt->unsafe_channel_list[i]) {
8043 found = true;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008044 hdd_debug("operating ch:%d is unsafe",
Dustin Brown920397d2017-12-13 16:27:50 -08008045 adapter->session.ap.operating_channel);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308046 break;
8047 }
8048 }
8049
8050 if (!found) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008051 hdd_debug("ch:%d is safe. no need to change channel",
Dustin Brown920397d2017-12-13 16:27:50 -08008052 adapter->session.ap.operating_channel);
8053 continue;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308054 }
8055
Kapil Gupta8878ad92017-02-13 11:56:04 +05308056 if (hdd_ctxt->config->vendor_acs_support &&
8057 hdd_ctxt->config->acs_support_for_dfs_ltecoex) {
Dustin Brown920397d2017-12-13 16:27:50 -08008058 hdd_update_acs_timer_reason(adapter,
Kapil Gupta8878ad92017-02-13 11:56:04 +05308059 QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX);
Dustin Brown920397d2017-12-13 16:27:50 -08008060 continue;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308061 } else
8062 restart_chan =
8063 hdd_get_safe_channel_from_pcl_and_acs_range(
Dustin Brown920397d2017-12-13 16:27:50 -08008064 adapter);
Agrawal Ashish467dde42016-09-08 18:44:22 +05308065 if (!restart_chan) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008066 hdd_err("fail to restart SAP");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308067 } else {
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008068 /*
8069 * SAP restart due to unsafe channel. While
8070 * restarting the SAP, make sure to clear
8071 * acs_channel, channel to reset to
8072 * 0. Otherwise these settings will override
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308073 * the ACS while restart.
Jeff Johnson0d52c7a2017-01-12 08:46:55 -08008074 */
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308075 hdd_ctxt->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Dustin Brown920397d2017-12-13 16:27:50 -08008076 adapter->session.ap.sap_config.channel =
Kondabattini, Ganesh2836c5a2016-09-20 17:10:19 +05308077 AUTO_CHANNEL_SELECT;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008078 hdd_debug("sending coex indication");
Agrawal Ashish467dde42016-09-08 18:44:22 +05308079 wlan_hdd_send_svc_nlink_msg(hdd_ctxt->radio_index,
8080 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Liangwei Dong6663d162017-07-10 03:29:36 -04008081 hdd_debug("driver to start sap: %d",
8082 hdd_ctxt->config->sap_internal_restart);
8083 if (hdd_ctxt->config->sap_internal_restart)
Min Liu2fef5792018-01-19 17:59:42 +08008084 hdd_switch_sap_channel(adapter, restart_chan,
8085 true);
Liangwei Dong6663d162017-07-10 03:29:36 -04008086 else
8087 return;
Agrawal Ashish467dde42016-09-08 18:44:22 +05308088 }
Agrawal Ashish467dde42016-09-08 18:44:22 +05308089 }
8090}
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +05308091
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008092/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008093 * hdd_init_channel_avoidance() - Initialize channel avoidance
8094 * @hdd_ctx: HDD global context
8095 *
8096 * Initialize the channel avoidance logic by retrieving the unsafe
Yuanyuan Liu13738502016-04-06 17:41:37 -07008097 * channel list from the platform driver and plumbing the data
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008098 * down to the lower layers. Then subscribe to subsequent channel
8099 * avoidance events.
8100 *
8101 * Return: None
8102 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008103static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008104{
8105 uint16_t unsafe_channel_count;
8106 int index;
8107
Yuanyuan Liu13738502016-04-06 17:41:37 -07008108 pld_get_wlan_unsafe_channel(hdd_ctx->parent_dev,
8109 hdd_ctx->unsafe_channel_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008110 &(hdd_ctx->unsafe_channel_count),
Amar Singhalb8d4f152016-02-10 10:21:43 -08008111 sizeof(uint16_t) * NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008112
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008113 hdd_debug("num of unsafe channels is %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008114 hdd_ctx->unsafe_channel_count);
8115
Anurag Chouhan6d760662016-02-20 16:05:43 +05308116 unsafe_channel_count = QDF_MIN((uint16_t)hdd_ctx->unsafe_channel_count,
Amar Singhalb8d4f152016-02-10 10:21:43 -08008117 (uint16_t)NUM_CHANNELS);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008118
8119 for (index = 0; index < unsafe_channel_count; index++) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008120 hdd_debug("channel %d is not safe",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008121 hdd_ctx->unsafe_channel_list[index]);
8122
8123 }
8124
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008125}
Dustin Brown676a2322017-08-15 13:16:13 -07008126
Jeff Johnson9d295242017-08-29 14:39:48 -07008127static void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008128 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008129{
8130 uint8_t restart_chan;
8131
8132 restart_chan = hdd_get_safe_channel_from_pcl_and_acs_range(adapter);
8133 if (!restart_chan) {
8134 hdd_alert("fail to restart SAP");
8135 return;
8136 }
8137
8138 /* SAP restart due to unsafe channel. While restarting
8139 * the SAP, make sure to clear acs_channel, channel to
8140 * reset to 0. Otherwise these settings will override
8141 * the ACS while restart.
8142 */
8143 hdd_ctx->acs_policy.acs_channel = AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -07008144 adapter->session.ap.sap_config.channel = AUTO_CHANNEL_SELECT;
Dustin Brown676a2322017-08-15 13:16:13 -07008145
8146 hdd_debug("sending coex indication");
8147
8148 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
8149 WLAN_SVC_LTE_COEX_IND, NULL, 0);
Min Liu2fef5792018-01-19 17:59:42 +08008150 hdd_switch_sap_channel(adapter, restart_chan, true);
Dustin Brown676a2322017-08-15 13:16:13 -07008151}
Liangwei Dong6e1a2092017-08-30 16:29:06 +08008152
8153int hdd_clone_local_unsafe_chan(struct hdd_context *hdd_ctx,
8154 uint16_t **local_unsafe_list, uint16_t *local_unsafe_list_count)
8155{
8156 uint32_t size;
8157 uint16_t *unsafe_list;
8158 uint16_t chan_count;
8159
8160 if (!hdd_ctx || !local_unsafe_list_count || !local_unsafe_list_count)
8161 return -EINVAL;
8162
8163 chan_count = QDF_MIN(hdd_ctx->unsafe_channel_count,
8164 NUM_CHANNELS);
8165 if (chan_count) {
8166 size = chan_count * sizeof(hdd_ctx->unsafe_channel_list[0]);
8167 unsafe_list = qdf_mem_malloc(size);
8168 if (!unsafe_list) {
8169 hdd_err("No memory for unsafe chan list size%d",
8170 size);
8171 return -ENOMEM;
8172 }
8173 qdf_mem_copy(unsafe_list, hdd_ctx->unsafe_channel_list, size);
8174 } else {
8175 unsafe_list = NULL;
8176 }
8177
8178 *local_unsafe_list = unsafe_list;
8179 *local_unsafe_list_count = chan_count;
8180
8181 return 0;
8182}
8183
8184bool hdd_local_unsafe_channel_updated(struct hdd_context *hdd_ctx,
8185 uint16_t *local_unsafe_list, uint16_t local_unsafe_list_count)
8186{
8187 int i, j;
8188
8189 if (local_unsafe_list_count != hdd_ctx->unsafe_channel_count)
8190 return true;
8191 if (local_unsafe_list_count == 0)
8192 return false;
8193 for (i = 0; i < local_unsafe_list_count; i++) {
8194 for (j = 0; j < local_unsafe_list_count; j++)
8195 if (local_unsafe_list[i] ==
8196 hdd_ctx->unsafe_channel_list[j])
8197 break;
8198 if (j >= local_unsafe_list_count)
8199 break;
8200 }
8201 if (i >= local_unsafe_list_count) {
8202 hdd_info("unsafe chan list same");
8203 return false;
8204 }
8205
8206 return true;
8207}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008208#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008209static void hdd_init_channel_avoidance(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008210{
8211}
Dustin Brown676a2322017-08-15 13:16:13 -07008212
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008213static void hdd_set_thermal_level_cb(void *context, u_int8_t level)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008214{
8215}
Dustin Brown676a2322017-08-15 13:16:13 -07008216
Jeff Johnson9d295242017-08-29 14:39:48 -07008217static inline void hdd_lte_coex_restart_sap(struct hdd_adapter *adapter,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008218 struct hdd_context *hdd_ctx)
Dustin Brown676a2322017-08-15 13:16:13 -07008219{
8220 hdd_debug("Channel avoidance is not enabled; Abort SAP restart");
8221}
Yuanyuan Liu13738502016-04-06 17:41:37 -07008222#endif /* defined(FEATURE_WLAN_CH_AVOID) */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008223
8224/**
Rajeev Kumard004abc2016-02-17 12:09:56 -08008225 * hdd_indicate_mgmt_frame() - Wrapper to indicate management frame to
8226 * user space
8227 * @frame_ind: Management frame data to be informed.
8228 *
8229 * This function is used to indicate management frame to
8230 * user space
8231 *
8232 * Return: None
8233 *
8234 */
8235void hdd_indicate_mgmt_frame(tSirSmeMgmtFrameInd *frame_ind)
8236{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008237 struct hdd_context *hdd_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -07008238 struct hdd_adapter *adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008239 int i;
8240
Rajeev Kumard004abc2016-02-17 12:09:56 -08008241 /* Get the HDD context.*/
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008242 hdd_ctx = (struct hdd_context *)cds_get_context(QDF_MODULE_ID_HDD);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008243
8244 if (0 != wlan_hdd_validate_context(hdd_ctx))
8245 return;
8246
8247 if (SME_SESSION_ID_ANY == frame_ind->sessionId) {
8248 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
8249 adapter =
8250 hdd_get_adapter_by_sme_session_id(hdd_ctx, i);
8251 if (adapter)
8252 break;
8253 }
Wu Gaoa0230a62018-01-04 20:56:57 +08008254 } else if (SME_SESSION_ID_BROADCAST == frame_ind->sessionId) {
8255 hdd_for_each_adapter(hdd_ctx, adapter) {
8256 if ((NULL != adapter) &&
8257 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic)) {
8258 __hdd_indicate_mgmt_frame(adapter,
8259 frame_ind->frame_len,
8260 frame_ind->frameBuf,
8261 frame_ind->frameType,
8262 frame_ind->rxChan,
8263 frame_ind->rxRssi);
8264 }
8265 }
8266 adapter = NULL;
Rajeev Kumard004abc2016-02-17 12:09:56 -08008267 } else {
8268 adapter = hdd_get_adapter_by_sme_session_id(hdd_ctx,
8269 frame_ind->sessionId);
8270 }
8271
8272 if ((NULL != adapter) &&
8273 (WLAN_HDD_ADAPTER_MAGIC == adapter->magic))
8274 __hdd_indicate_mgmt_frame(adapter,
8275 frame_ind->frame_len,
8276 frame_ind->frameBuf,
8277 frame_ind->frameType,
8278 frame_ind->rxChan,
8279 frame_ind->rxRssi);
Rajeev Kumard004abc2016-02-17 12:09:56 -08008280}
8281
Kapil Gupta8878ad92017-02-13 11:56:04 +05308282void hdd_acs_response_timeout_handler(void *context)
8283{
8284 struct hdd_external_acs_timer_context *timer_context =
8285 (struct hdd_external_acs_timer_context *)context;
Jeff Johnson9d295242017-08-29 14:39:48 -07008286 struct hdd_adapter *adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008287 struct hdd_context *hdd_ctx;
Kapil Gupta8878ad92017-02-13 11:56:04 +05308288 uint8_t reason;
8289
Dustin Brown491d54b2018-03-14 12:39:11 -07008290 hdd_enter();
Kapil Gupta8878ad92017-02-13 11:56:04 +05308291 if (!timer_context) {
8292 hdd_err("invlaid timer context");
8293 return;
8294 }
8295 adapter = timer_context->adapter;
8296 reason = timer_context->reason;
8297
8298
8299 if ((!adapter) ||
8300 (adapter->magic != WLAN_HDD_ADAPTER_MAGIC)) {
8301 hdd_err("invalid adapter or adapter has invalid magic");
8302 return;
8303 }
8304 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
8305 if (wlan_hdd_validate_context(hdd_ctx))
8306 return;
8307
8308 if (test_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags))
8309 clear_bit(VENDOR_ACS_RESPONSE_PENDING, &adapter->event_flags);
8310 else
8311 return;
8312
8313 hdd_err("ACS timeout happened for %s reason %d",
8314 adapter->dev->name, reason);
8315 switch (reason) {
8316 /* SAP init case */
8317 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_INIT:
8318 wlan_sap_set_vendor_acs(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
8319 false);
8320 wlan_hdd_cfg80211_start_acs(adapter);
8321 break;
8322 /* DFS detected on current channel */
8323 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_DFS:
8324 wlan_sap_update_next_channel(
8325 WLAN_HDD_GET_SAP_CTX_PTR(adapter), 0, 0);
8326 sme_update_new_channel_event(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -07008327 adapter->session_id);
Kapil Gupta8878ad92017-02-13 11:56:04 +05308328 break;
8329 /* LTE coex event on current channel */
8330 case QCA_WLAN_VENDOR_ACS_SELECT_REASON_LTE_COEX:
8331 hdd_lte_coex_restart_sap(adapter, hdd_ctx);
8332 break;
8333 default:
8334 hdd_info("invalid reason for timer invoke");
8335
8336 }
8337}
8338
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008339/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008340 * hdd_override_ini_config - Override INI config
8341 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008342 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008343 * Override INI config based on module parameter.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008344 *
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008345 * Return: None
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008346 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008347static void hdd_override_ini_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008348{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008349
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008350 if (0 == enable_dfs_chan_scan || 1 == enable_dfs_chan_scan) {
8351 hdd_ctx->config->enableDFSChnlScan = enable_dfs_chan_scan;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008352 hdd_debug("Module enable_dfs_chan_scan set to %d",
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008353 enable_dfs_chan_scan);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008354 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008355 if (0 == enable_11d || 1 == enable_11d) {
8356 hdd_ctx->config->Is11dSupportEnabled = enable_11d;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008357 hdd_debug("Module enable_11d set to %d", enable_11d);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008358 }
Leo Chang11545d62016-10-17 14:53:50 -07008359
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +05308360 if (!ucfg_ipa_is_present()) {
Leo Chang11545d62016-10-17 14:53:50 -07008361 hdd_ctx->config->IpaConfig = 0;
Jingxiang Ge7a040dc2018-02-02 11:07:59 +08008362 hdd_debug("IpaConfig override to %d",
8363 hdd_ctx->config->IpaConfig);
8364 }
Yeshwanth Sriram Guntuka2ba6fe92017-10-04 14:40:45 +05308365
8366 if (!hdd_ctx->config->rssi_assoc_reject_enabled ||
8367 !hdd_ctx->config->enable_bcast_probe_rsp) {
8368 hdd_debug("OCE disabled, rssi_assoc_reject_enabled: %d enable_bcast_probe_rsp: %d",
8369 hdd_ctx->config->rssi_assoc_reject_enabled,
8370 hdd_ctx->config->enable_bcast_probe_rsp);
8371 hdd_ctx->config->oce_sta_enabled = 0;
8372 }
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008373}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008374
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008375/**
8376 * hdd_set_trace_level_for_each - Set trace level for each INI config
8377 * @hdd_ctx - HDD context
8378 *
8379 * Set trace level for each module based on INI config.
8380 *
8381 * Return: None
8382 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008383static void hdd_set_trace_level_for_each(struct hdd_context *hdd_ctx)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008384{
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308385 hdd_qdf_trace_enable(QDF_MODULE_ID_WMI,
8386 hdd_ctx->config->qdf_trace_enable_wdi);
8387 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD,
8388 hdd_ctx->config->qdf_trace_enable_hdd);
8389 hdd_qdf_trace_enable(QDF_MODULE_ID_SME,
8390 hdd_ctx->config->qdf_trace_enable_sme);
8391 hdd_qdf_trace_enable(QDF_MODULE_ID_PE,
8392 hdd_ctx->config->qdf_trace_enable_pe);
8393 hdd_qdf_trace_enable(QDF_MODULE_ID_WMA,
8394 hdd_ctx->config->qdf_trace_enable_wma);
8395 hdd_qdf_trace_enable(QDF_MODULE_ID_SYS,
8396 hdd_ctx->config->qdf_trace_enable_sys);
8397 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF,
8398 hdd_ctx->config->qdf_trace_enable_qdf);
8399 hdd_qdf_trace_enable(QDF_MODULE_ID_SAP,
8400 hdd_ctx->config->qdf_trace_enable_sap);
8401 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SOFTAP,
8402 hdd_ctx->config->qdf_trace_enable_hdd_sap);
8403 hdd_qdf_trace_enable(QDF_MODULE_ID_BMI,
8404 hdd_ctx->config->qdf_trace_enable_bmi);
8405 hdd_qdf_trace_enable(QDF_MODULE_ID_CFG,
8406 hdd_ctx->config->qdf_trace_enable_cfg);
8407 hdd_qdf_trace_enable(QDF_MODULE_ID_EPPING,
8408 hdd_ctx->config->qdf_trace_enable_epping);
8409 hdd_qdf_trace_enable(QDF_MODULE_ID_QDF_DEVICE,
8410 hdd_ctx->config->qdf_trace_enable_qdf_devices);
8411 hdd_qdf_trace_enable(QDF_MODULE_ID_TXRX,
Houston Hoffmanfbf05102017-08-28 11:37:01 -07008412 hdd_ctx->config->qdf_trace_enable_txrx);
8413 hdd_qdf_trace_enable(QDF_MODULE_ID_DP,
8414 hdd_ctx->config->qdf_trace_enable_dp);
Anurag Chouhanf04e84f2016-03-03 10:12:12 +05308415 hdd_qdf_trace_enable(QDF_MODULE_ID_HTC,
8416 hdd_ctx->config->qdf_trace_enable_htc);
8417 hdd_qdf_trace_enable(QDF_MODULE_ID_HIF,
8418 hdd_ctx->config->qdf_trace_enable_hif);
8419 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_SAP_DATA,
8420 hdd_ctx->config->qdf_trace_enable_hdd_sap_data);
8421 hdd_qdf_trace_enable(QDF_MODULE_ID_HDD_DATA,
8422 hdd_ctx->config->qdf_trace_enable_hdd_data);
Naveen Rawat7df31862017-03-01 17:09:30 -08008423 hdd_qdf_trace_enable(QDF_MODULE_ID_WIFIPOS,
8424 hdd_ctx->config->qdf_trace_enable_wifi_pos);
Naveen Rawatf2b0dbd2017-03-27 10:00:15 -07008425 hdd_qdf_trace_enable(QDF_MODULE_ID_NAN,
8426 hdd_ctx->config->qdf_trace_enable_nan);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008427 hdd_qdf_trace_enable(QDF_MODULE_ID_REGULATORY,
8428 hdd_ctx->config->qdf_trace_enable_regulatory);
Naveen Rawat3cb779e2018-02-16 16:36:10 -08008429 hdd_qdf_trace_enable(QDF_MODULE_ID_CP_STATS,
8430 hdd_ctx->config->qdf_trace_enable_cp_stats);
Kiran Kumar Lokere798de7e2017-03-30 14:01:12 -07008431
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08008432 hdd_cfg_print(hdd_ctx);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008433}
8434
8435/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008436 * hdd_context_init() - Initialize HDD context
8437 * @hdd_ctx: HDD context.
8438 *
8439 * Initialize HDD context along with all the feature specific contexts.
8440 *
8441 * return: 0 on success and errno on failure.
8442 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008443static int hdd_context_init(struct hdd_context *hdd_ctx)
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008444{
8445 int ret;
8446
8447 hdd_ctx->ioctl_scan_mode = eSIR_ACTIVE_SCAN;
8448 hdd_ctx->max_intf_count = CSR_ROAM_SESSION_MAX;
8449
8450 hdd_init_ll_stats_ctx();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +05308451 hdd_init_nud_stats_ctx(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008452
8453 init_completion(&hdd_ctx->mc_sus_event_var);
8454 init_completion(&hdd_ctx->ready_to_suspend);
8455
8456 qdf_spinlock_create(&hdd_ctx->connection_status_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308457 qdf_spinlock_create(&hdd_ctx->sta_update_info_lock);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008458 qdf_spinlock_create(&hdd_ctx->hdd_adapter_lock);
Manishekar Chandrasekaran7f63d052016-05-07 09:54:00 +05308459
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008460 qdf_list_create(&hdd_ctx->hdd_adapters, MAX_NUMBER_OF_ADAPTERS);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008461
8462 init_completion(&hdd_ctx->set_antenna_mode_cmpl);
8463
8464 ret = hdd_scan_context_init(hdd_ctx);
8465 if (ret)
8466 goto list_destroy;
8467
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008468 hdd_rx_wake_lock_create(hdd_ctx);
8469
8470 ret = hdd_sap_context_init(hdd_ctx);
8471 if (ret)
8472 goto scan_destroy;
8473
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008474 wlan_hdd_cfg80211_extscan_init(hdd_ctx);
8475
8476 hdd_init_offloaded_packets_ctx(hdd_ctx);
8477
8478 ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
8479 hdd_ctx->config);
8480 if (ret)
Wu Gao02bd75b2017-10-13 18:34:02 +08008481 goto sap_destroy;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008482
Arunk Khandavalliebd1e372017-11-06 15:00:24 +05308483 qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
8484 "monitor_mode_wakelock");
8485
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008486 return 0;
8487
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008488sap_destroy:
8489 hdd_sap_context_destroy(hdd_ctx);
8490
8491scan_destroy:
8492 hdd_scan_context_destroy(hdd_ctx);
8493 hdd_rx_wake_lock_destroy(hdd_ctx);
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008494list_destroy:
Jeff Johnson19fc8e42017-10-30 19:53:49 -07008495 qdf_list_destroy(&hdd_ctx->hdd_adapters);
Sandeep Puligillad0004212017-02-26 18:34:56 -08008496
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008497 return ret;
8498}
8499
8500/**
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308501 * ie_whitelist_attrs_init() - initialize ie whitelisting attributes
8502 * @hdd_ctx: pointer to hdd context
8503 *
8504 * Return: status of initialization
8505 * 0 - success
8506 * negative value - failure
8507 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008508static int ie_whitelist_attrs_init(struct hdd_context *hdd_ctx)
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308509{
8510 int ret;
8511
8512 if (!hdd_ctx->config->probe_req_ie_whitelist)
8513 return 0;
8514
8515 if (!hdd_validate_prb_req_ie_bitmap(hdd_ctx)) {
8516 hdd_err("invalid ie bitmap and ouis: disable ie whitelisting");
8517 hdd_ctx->config->probe_req_ie_whitelist = false;
8518 return -EINVAL;
8519 }
8520
8521 /* parse ini string probe req oui */
8522 ret = hdd_parse_probe_req_ouis(hdd_ctx);
8523 if (ret) {
8524 hdd_err("parsing error: disable ie whitelisting");
8525 hdd_ctx->config->probe_req_ie_whitelist = false;
8526 }
8527
8528 return ret;
8529}
8530
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308531/**
8532 * hdd_iface_change_callback() - Function invoked when stop modules expires
8533 * @priv: pointer to hdd context
8534 *
8535 * This function is invoked when the timer waiting for the interface change
8536 * expires, it shall cut-down the power to wlan and stop all the modules.
8537 *
8538 * Return: void
8539 */
8540static void hdd_iface_change_callback(void *priv)
8541{
8542 struct hdd_context *hdd_ctx = (struct hdd_context *) priv;
8543 int ret;
8544 int status = wlan_hdd_validate_context(hdd_ctx);
8545
8546 if (status)
8547 return;
8548
Dustin Brown491d54b2018-03-14 12:39:11 -07008549 hdd_enter();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308550 hdd_debug("Interface change timer expired close the modules!");
8551 ret = hdd_wlan_stop_modules(hdd_ctx, false);
8552 if (ret)
8553 hdd_err("Failed to stop modules");
Dustin Browne74003f2018-03-14 12:51:58 -07008554 hdd_exit();
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308555}
8556
Nirav Shaheb017be2018-02-15 11:20:58 +05308557#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
8558static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8559{
8560 wlan_logging_set_log_to_console(hdd_ctx->config->
8561 wlan_logging_to_console);
8562 wlan_logging_set_active(hdd_ctx->config->wlan_logging_enable);
8563}
8564#else
8565static void hdd_set_wlan_logging(struct hdd_context *hdd_ctx)
8566{ }
8567#endif
8568
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308569/**
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008570 * hdd_context_create() - Allocate and inialize HDD context.
Arun Khandavallifae92942016-08-01 13:31:08 +05308571 * @dev: Device Pointer to the underlying device
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008572 *
8573 * Allocate and initialize HDD context. HDD context is allocated as part of
8574 * wiphy allocation and then context is initialized.
8575 *
8576 * Return: HDD context on success and ERR_PTR on failure
8577 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008578static struct hdd_context *hdd_context_create(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008579{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308580 QDF_STATUS status;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008581 int ret = 0;
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008582 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008583
Dustin Brown491d54b2018-03-14 12:39:11 -07008584 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008585
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008586 hdd_ctx = hdd_cfg80211_wiphy_alloc(sizeof(struct hdd_context));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008587 if (hdd_ctx == NULL) {
8588 ret = -ENOMEM;
8589 goto err_out;
8590 }
8591
Dustin Brown6f427922017-09-19 12:19:00 -07008592 qdf_create_delayed_work(&hdd_ctx->iface_idle_work,
8593 hdd_iface_change_callback,
8594 (void *)hdd_ctx);
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308595
8596 mutex_init(&hdd_ctx->iface_change_lock);
8597
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008598 hdd_ctx->parent_dev = dev;
Sreelakshmi Konamkib53c6292017-03-01 13:13:23 +05308599 hdd_ctx->last_scan_reject_session_id = 0xFF;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008600
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308601 hdd_ctx->config = qdf_mem_malloc(sizeof(struct hdd_config));
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008602 if (hdd_ctx->config == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008603 hdd_err("Failed to alloc memory for HDD config!");
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008604 ret = -ENOMEM;
8605 goto err_free_hdd_context;
8606 }
8607
8608 /* Read and parse the qcom_cfg.ini file */
8609 status = hdd_parse_config_ini(hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05308610 if (QDF_STATUS_SUCCESS != status) {
Arun Khandavallifae92942016-08-01 13:31:08 +05308611 hdd_err("Error (status: %d) parsing INI file: %s", status,
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008612 WLAN_INI_FILE);
8613 ret = -EINVAL;
8614 goto err_free_config;
8615 }
8616
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +05308617 ie_whitelist_attrs_init(hdd_ctx);
8618
Dustin Brown7f939932017-05-18 15:02:17 -07008619 hdd_debug("setting timer multiplier: %u",
8620 hdd_ctx->config->timer_multiplier);
8621 qdf_timer_set_multiplier(hdd_ctx->config->timer_multiplier);
8622
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008623
Sravan Kumar Kairamfece87f2016-07-26 14:58:28 +05308624 if (hdd_ctx->config->fhostNSOffload)
8625 hdd_ctx->ns_offload_enable = true;
8626
Abhishek Singh5ea86532016-04-27 14:10:53 +05308627 cds_set_fatal_event(hdd_ctx->config->enable_fatal_event);
8628
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008629 hdd_override_ini_config(hdd_ctx);
8630
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008631 ret = hdd_context_init(hdd_ctx);
8632
8633 if (ret)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008634 goto err_free_config;
Prashanth Bhatta527fd752016-04-28 12:35:23 -07008635
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008636 /* Uses to enabled logging after SSR */
Komal Seelamc11bb222016-01-27 18:57:10 +05308637 hdd_ctx->fw_log_settings.enable = hdd_ctx->config->enable_fw_log;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008638
Anurag Chouhan6d760662016-02-20 16:05:43 +05308639 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008640 goto skip_multicast_logging;
8641
8642 cds_set_multicast_logging(hdd_ctx->config->multicast_host_fw_msgs);
8643
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008644 ret = wlan_hdd_init_tx_rx_histogram(hdd_ctx);
8645 if (ret)
8646 goto err_deinit_hdd_context;
Nirav Shahed34b212016-04-25 10:59:16 +05308647
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008648 ret = hdd_init_netlink_services(hdd_ctx);
8649 if (ret)
8650 goto err_deinit_txrx_histogram;
8651
Nirav Shaheb017be2018-02-15 11:20:58 +05308652 hdd_set_wlan_logging(hdd_ctx);
Nirav Shahed34b212016-04-25 10:59:16 +05308653
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008654skip_multicast_logging:
8655 hdd_set_trace_level_for_each(hdd_ctx);
8656
Rajeev Kumar493a31b2017-09-29 14:01:24 -07008657 cds_set_context(QDF_MODULE_ID_HDD, hdd_ctx);
8658
Dustin Browne74003f2018-03-14 12:51:58 -07008659 hdd_exit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -07008660
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008661 return hdd_ctx;
8662
Houston Hoffmanb18dc6e2017-08-11 17:43:07 -07008663err_deinit_txrx_histogram:
8664 wlan_hdd_deinit_tx_rx_histogram(hdd_ctx);
8665
Rajeev Kumarfb02a5e2016-09-20 16:16:17 -07008666err_deinit_hdd_context:
8667 hdd_context_deinit(hdd_ctx);
8668
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008669err_free_config:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05308670 qdf_mem_free(hdd_ctx->config);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008671
8672err_free_hdd_context:
Sourav Mohapatrafed6aa92017-11-14 18:05:11 +05308673 mutex_destroy(&hdd_ctx->iface_change_lock);
Rajeev Kumarfa55a692018-01-09 14:12:41 -08008674 wiphy_free(hdd_ctx->wiphy);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -08008675
8676err_out:
8677 return ERR_PTR(ret);
8678}
8679
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008680#ifdef WLAN_OPEN_P2P_INTERFACE
8681/**
8682 * hdd_open_p2p_interface - Open P2P interface
8683 * @hdd_ctx: HDD context
8684 * @rtnl_held: True if RTNL lock held
8685 *
8686 * Open P2P interface during probe. This function called to open the P2P
8687 * interface at probe along with STA interface.
8688 *
8689 * Return: 0 on success and errno on failure
8690 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008691static int hdd_open_p2p_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008692{
Jeff Johnson9d295242017-08-29 14:39:48 -07008693 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008694 uint8_t *p2p_dev_addr;
8695
8696 if (hdd_ctx->config->isP2pDeviceAddrAdministrated &&
8697 !(hdd_ctx->config->intfMacAddr[0].bytes[0] & 0x02)) {
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008698 qdf_mem_copy(hdd_ctx->p2p_device_address.bytes,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008699 hdd_ctx->config->intfMacAddr[0].bytes,
8700 sizeof(tSirMacAddr));
8701
8702 /*
8703 * Generate the P2P Device Address. This consists of
8704 * the device's primary MAC address with the locally
8705 * administered bit set.
8706 */
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008707 hdd_ctx->p2p_device_address.bytes[0] |= 0x02;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008708 } else {
8709 p2p_dev_addr = wlan_hdd_get_intf_addr(hdd_ctx);
8710 if (p2p_dev_addr == NULL) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008711 hdd_err("Failed to allocate mac_address for p2p_device");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008712 return -ENOSPC;
8713 }
8714
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008715 qdf_mem_copy(&hdd_ctx->p2p_device_address.bytes[0],
8716 p2p_dev_addr, QDF_MAC_ADDR_SIZE);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008717 }
8718
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008719 adapter = hdd_open_adapter(hdd_ctx, QDF_P2P_DEVICE_MODE, "p2p%d",
Jeff Johnsonacbdb1c2017-11-02 20:42:02 -07008720 &hdd_ctx->p2p_device_address.bytes[0],
Ryan Hsu07495ea2016-01-21 15:25:39 -08008721 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008722
8723 if (NULL == adapter) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08008724 hdd_err("Failed to do hdd_open_adapter for P2P Device Interface");
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008725 return -ENOSPC;
8726 }
8727
8728 return 0;
8729}
8730#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008731static inline int hdd_open_p2p_interface(struct hdd_context *hdd_ctx,
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008732 bool rtnl_held)
8733{
8734 return 0;
8735}
8736#endif
8737
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008738static int hdd_open_ocb_interface(struct hdd_context *hdd_ctx, bool rtnl_held)
Jeff Johnson957bc272017-02-02 08:54:48 -08008739{
Jeff Johnson9d295242017-08-29 14:39:48 -07008740 struct hdd_adapter *adapter;
Jeff Johnson957bc272017-02-02 08:54:48 -08008741 int ret = 0;
8742
8743 adapter = hdd_open_adapter(hdd_ctx, QDF_OCB_MODE, "wlanocb%d",
8744 wlan_hdd_get_intf_addr(hdd_ctx),
8745 NET_NAME_UNKNOWN, rtnl_held);
8746 if (adapter == NULL) {
8747 hdd_err("Failed to open 802.11p interface");
8748 ret = -ENOSPC;
8749 }
8750
8751 return ret;
8752}
8753
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008754/**
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308755 * hdd_start_station_adapter()- Start the Station Adapter
8756 * @adapter: HDD adapter
8757 *
8758 * This function initializes the adapter for the station mode.
8759 *
8760 * Return: 0 on success or errno on failure.
8761 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008762int hdd_start_station_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308763{
8764 QDF_STATUS status;
Krunal Sonib51eec72017-11-20 21:53:01 -08008765 int ret;
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308766
Dustin Brownfdf17c12018-03-14 12:55:34 -07008767 hdd_enter_dev(adapter->dev);
Krunal Sonib51eec72017-11-20 21:53:01 -08008768 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8769 hdd_err("session is already opened, %d",
8770 adapter->session_id);
8771 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8772 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308773
Krunal Sonib51eec72017-11-20 21:53:01 -08008774 ret = hdd_vdev_create(adapter, hdd_sme_roam_callback, adapter);
8775 if (ret) {
8776 hdd_err("failed to create vdev: %d", ret);
8777 return ret;
8778 }
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308779 status = hdd_init_station_mode(adapter);
8780
8781 if (QDF_STATUS_SUCCESS != status) {
8782 hdd_err("Error Initializing station mode: %d", status);
8783 return qdf_status_to_os_return(status);
8784 }
8785
Arun Khandavallifae92942016-08-01 13:31:08 +05308786 hdd_register_tx_flow_control(adapter,
8787 hdd_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008788 hdd_tx_resume_cb,
8789 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308790
Dustin Browne74003f2018-03-14 12:51:58 -07008791 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308792 return 0;
8793}
8794
8795/**
8796 * hdd_start_ap_adapter()- Start AP Adapter
8797 * @adapter: HDD adapter
8798 *
8799 * This function initializes the adapter for the AP mode.
8800 *
8801 * Return: 0 on success errno on failure.
8802 */
Jeff Johnson9d295242017-08-29 14:39:48 -07008803int hdd_start_ap_adapter(struct hdd_adapter *adapter)
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308804{
8805 QDF_STATUS status;
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008806 bool is_ssr = false;
Krunal Sonib51eec72017-11-20 21:53:01 -08008807 int ret;
Naveen Rawat1af09392018-01-03 17:28:21 -08008808 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308809
Dustin Brown491d54b2018-03-14 12:39:11 -07008810 hdd_enter();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308811
Krunal Sonib51eec72017-11-20 21:53:01 -08008812 if (test_bit(SME_SESSION_OPENED, &adapter->event_flags)) {
8813 hdd_err("session is already opened, %d",
8814 adapter->session_id);
8815 return qdf_status_to_os_return(QDF_STATUS_SUCCESS);
8816 }
8817 /*
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008818 * In SSR case no need to create new sap context.
8819 * Otherwise create sap context first and then create
8820 * vdev as while creating the vdev, driver needs to
8821 * register SAP callback and that callback uses sap context
Krunal Sonib51eec72017-11-20 21:53:01 -08008822 */
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008823 if (adapter->session.ap.sap_context) {
8824 is_ssr = true;
8825 } else if (!hdd_sap_create_ctx(adapter)) {
Krunal Sonib51eec72017-11-20 21:53:01 -08008826 hdd_err("sap creation failed");
8827 return qdf_status_to_os_return(QDF_STATUS_E_FAILURE);
8828 }
8829
8830 ret = hdd_vdev_create(adapter, wlansap_roam_callback,
8831 adapter->session.ap.sap_context);
8832 if (ret) {
8833 hdd_err("failed to create vdev, status:%d", ret);
8834 hdd_sap_destroy_ctx(adapter);
8835 return ret;
8836 }
Naveen Rawat1af09392018-01-03 17:28:21 -08008837
8838 if (adapter->device_mode == QDF_SAP_MODE)
8839 sme_cli_set_command(adapter->session_id,
8840 WMI_VDEV_PARAM_ENABLE_DISABLE_RTT_RESPONDER_ROLE,
8841 (bool)(hdd_ctx->config->fine_time_meas_cap &
8842 WMI_FW_AP_RTT_RESPR),
8843 VDEV_CMD);
8844
Tushnim Bhattacharyya18b0eaa2017-11-27 18:33:50 -08008845 status = hdd_init_ap_mode(adapter, is_ssr);
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308846
8847 if (QDF_STATUS_SUCCESS != status) {
8848 hdd_err("Error Initializing the AP mode: %d", status);
8849 return qdf_status_to_os_return(status);
8850 }
8851
Arun Khandavallifae92942016-08-01 13:31:08 +05308852 hdd_register_tx_flow_control(adapter,
8853 hdd_softap_tx_resume_timer_expired_handler,
bings284f8be2017-08-11 10:41:30 +08008854 hdd_softap_tx_resume_cb,
8855 hdd_tx_flow_control_is_pause);
Arun Khandavallifae92942016-08-01 13:31:08 +05308856
Dustin Browne74003f2018-03-14 12:51:58 -07008857 hdd_exit();
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308858 return 0;
8859}
8860
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308861static int hdd_open_concurrent_interface(struct hdd_context *hdd_ctx,
8862 bool rtnl_held)
8863{
8864 struct hdd_adapter *adapter;
8865
8866 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE,
8867 hdd_ctx->config->enableConcurrentSTA,
8868 wlan_hdd_get_intf_addr(hdd_ctx),
8869 NET_NAME_UNKNOWN, rtnl_held);
8870
8871 if (!adapter)
8872 return -ENOSPC;
8873
8874 return 0;
8875}
8876
Arun Khandavalli7e857c32016-06-26 12:07:16 +05308877/**
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008878 * hdd_open_interfaces - Open all required interfaces
8879 * hdd_ctx: HDD context
8880 * rtnl_held: True if RTNL lock is held
8881 *
8882 * Open all the interfaces like STA, P2P and OCB based on the configuration.
8883 *
Jeff Johnson957bc272017-02-02 08:54:48 -08008884 * Return: 0 if all interfaces were created, otherwise negative errno
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008885 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008886static int hdd_open_interfaces(struct hdd_context *hdd_ctx, bool rtnl_held)
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008887{
Jeff Johnson9d295242017-08-29 14:39:48 -07008888 struct hdd_adapter *adapter;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008889 int ret;
8890
Ravi Joshia307f632017-07-17 23:41:41 -07008891 /* open monitor mode adapter if con_mode is monitor mode */
Lin Bai1c678482017-12-18 18:29:11 +08008892 if (con_mode == QDF_GLOBAL_MONITOR_MODE ||
8893 con_mode == QDF_GLOBAL_FTM_MODE) {
8894 uint8_t session_type = (con_mode == QDF_GLOBAL_MONITOR_MODE) ?
8895 QDF_MONITOR_MODE : QDF_FTM_MODE;
8896
8897 adapter = hdd_open_adapter(hdd_ctx, session_type, "wlan%d",
8898 wlan_hdd_get_intf_addr(hdd_ctx),
8899 NET_NAME_UNKNOWN, rtnl_held);
Ravi Joshia307f632017-07-17 23:41:41 -07008900 if (!adapter) {
8901 hdd_err("open adapter failed");
8902 return -ENOSPC;
8903 }
Lin Bai1c678482017-12-18 18:29:11 +08008904
Ravi Joshia307f632017-07-17 23:41:41 -07008905 return 0;
8906 }
8907
Jeff Johnson957bc272017-02-02 08:54:48 -08008908 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_STANDALONE)
Arun Khandavallifae92942016-08-01 13:31:08 +05308909 /* Create only 802.11p interface */
Jeff Johnson957bc272017-02-02 08:54:48 -08008910 return hdd_open_ocb_interface(hdd_ctx, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008911
Krunal Soni9b04c9b2016-03-10 13:08:05 -08008912 adapter = hdd_open_adapter(hdd_ctx, QDF_STA_MODE, "wlan%d",
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008913 wlan_hdd_get_intf_addr(hdd_ctx),
Ryan Hsu07495ea2016-01-21 15:25:39 -08008914 NET_NAME_UNKNOWN, rtnl_held);
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008915
8916 if (adapter == NULL)
Jeff Johnson957bc272017-02-02 08:54:48 -08008917 return -ENOSPC;
8918
Sourav Mohapatra57006c72017-11-19 16:15:55 +05308919 if (strlen(hdd_ctx->config->enableConcurrentSTA) != 0) {
8920 ret = hdd_open_concurrent_interface(hdd_ctx, rtnl_held);
8921 if (ret)
8922 hdd_err("Cannot create concurrent STA interface");
8923 }
8924
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008925 ret = hdd_open_p2p_interface(hdd_ctx, rtnl_held);
8926 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -08008927 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008928
8929 /* Open 802.11p Interface */
8930 if (hdd_ctx->config->dot11p_mode == WLAN_HDD_11P_CONCURRENT) {
Jeff Johnson957bc272017-02-02 08:54:48 -08008931 ret = hdd_open_ocb_interface(hdd_ctx, rtnl_held);
8932 if (ret)
8933 goto err_close_adapters;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008934 }
8935
Jeff Johnson957bc272017-02-02 08:54:48 -08008936 return 0;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008937
Jeff Johnson957bc272017-02-02 08:54:48 -08008938err_close_adapters:
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008939 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Jeff Johnson957bc272017-02-02 08:54:48 -08008940 return ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08008941}
8942
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08008943
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308944#ifdef QCA_LL_TX_FLOW_CONTROL_V2
8945/**
8946 * hdd_txrx_populate_cds_config() - Populate txrx cds configuration
8947 * @cds_cfg: CDS Configuration
8948 * @hdd_ctx: Pointer to hdd context
8949 *
8950 * Return: none
8951 */
8952static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8953 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008954 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308955{
8956 cds_cfg->tx_flow_stop_queue_th =
8957 hdd_ctx->config->TxFlowStopQueueThreshold;
8958 cds_cfg->tx_flow_start_queue_offset =
8959 hdd_ctx->config->TxFlowStartQueueOffset;
8960}
8961#else
8962static inline void hdd_txrx_populate_cds_config(struct cds_config_info
8963 *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008964 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308965{
8966}
8967#endif
8968
8969#ifdef FEATURE_WLAN_RA_FILTERING
8970/**
8971 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
8972 * @cds_cfg: CDS Configuration
8973 * @hdd_ctx: Pointer to hdd context
8974 *
8975 * Return: none
8976 */
Anand Kumar3b92a912016-12-05 12:01:26 +05308977static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008978 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308979{
8980 cds_cfg->ra_ratelimit_interval =
8981 hdd_ctx->config->RArateLimitInterval;
8982 cds_cfg->is_ra_ratelimit_enabled =
8983 hdd_ctx->config->IsRArateLimitEnabled;
8984}
8985#else
Anand Kumar3b92a912016-12-05 12:01:26 +05308986static inline void hdd_ra_populate_cds_config(struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008987 struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308988{
8989}
8990#endif
8991
8992/**
8993 * hdd_update_cds_config() - API to update cds configuration parameters
8994 * @hdd_ctx: HDD Context
8995 *
8996 * Return: 0 for Success, errno on failure
8997 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07008998static int hdd_update_cds_config(struct hdd_context *hdd_ctx)
Arun Khandavallic811dcc2016-06-26 07:37:21 +05308999{
9000 struct cds_config_info *cds_cfg;
9001
9002 cds_cfg = (struct cds_config_info *)qdf_mem_malloc(sizeof(*cds_cfg));
9003 if (!cds_cfg) {
9004 hdd_err("failed to allocate cds config");
9005 return -ENOMEM;
9006 }
9007
Srinivas Girigowda35b00312017-06-27 21:52:03 -07009008 cds_cfg->driver_type = QDF_DRIVER_TYPE_PRODUCTION;
Kiran Kumar Lokere7006e0a2017-03-07 19:28:36 -08009009 if (!hdd_ctx->config->nMaxPsPoll ||
9010 !hdd_ctx->config->enablePowersaveOffload) {
9011 cds_cfg->powersave_offload_enabled =
9012 hdd_ctx->config->enablePowersaveOffload;
9013 } else {
9014 if ((hdd_ctx->config->enablePowersaveOffload ==
9015 PS_QPOWER_NODEEPSLEEP) ||
9016 (hdd_ctx->config->enablePowersaveOffload ==
9017 PS_LEGACY_NODEEPSLEEP))
9018 cds_cfg->powersave_offload_enabled =
9019 PS_LEGACY_NODEEPSLEEP;
9020 else
9021 cds_cfg->powersave_offload_enabled =
9022 PS_LEGACY_DEEPSLEEP;
9023 hdd_info("Qpower disabled in cds config, %d",
9024 cds_cfg->powersave_offload_enabled);
9025 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309026 cds_cfg->sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
9027 cds_cfg->sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
9028 cds_cfg->sta_maxlimod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
9029 cds_cfg->wow_enable = hdd_ctx->config->wowEnable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309030
9031 /*
9032 * Copy the DFS Phyerr Filtering Offload status.
9033 * This parameter reflects the value of the
9034 * dfs_phyerr_filter_offload flag as set in the ini.
9035 */
9036 cds_cfg->dfs_phyerr_filter_offload =
9037 hdd_ctx->config->fDfsPhyerrFilterOffload;
9038 if (hdd_ctx->config->ssdp)
9039 cds_cfg->ssdp = hdd_ctx->config->ssdp;
9040
SaidiReddy Yenugacc733af2016-11-09 17:45:42 +05309041 cds_cfg->force_target_assert_enabled =
9042 hdd_ctx->config->crash_inject_enabled;
9043
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309044 cds_cfg->enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
9045 cds_cfg->ap_maxoffload_peers = hdd_ctx->config->apMaxOffloadPeers;
9046
9047 cds_cfg->ap_maxoffload_reorderbuffs =
9048 hdd_ctx->config->apMaxOffloadReorderBuffs;
9049
9050 cds_cfg->ap_disable_intrabss_fwd =
9051 hdd_ctx->config->apDisableIntraBssFwd;
9052
9053 cds_cfg->dfs_pri_multiplier =
9054 hdd_ctx->config->dfsRadarPriMultiplier;
9055 cds_cfg->reorder_offload =
9056 hdd_ctx->config->reorderOffloadSupport;
9057
9058 /* IPA micro controller data path offload resource config item */
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05309059 cds_cfg->uc_offload_enabled = ucfg_ipa_uc_is_enabled();
Yun Parkde380782016-08-17 16:26:54 -07009060 if (!is_power_of_2(hdd_ctx->config->IpaUcTxBufCount)) {
9061 /* IpaUcTxBufCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009062 hdd_debug("Round down IpaUcTxBufCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009063 hdd_ctx->config->IpaUcTxBufCount);
9064 hdd_ctx->config->IpaUcTxBufCount =
9065 rounddown_pow_of_two(
9066 hdd_ctx->config->IpaUcTxBufCount);
9067 if (!hdd_ctx->config->IpaUcTxBufCount) {
9068 hdd_err("Failed to round down IpaUcTxBufCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309069 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07009070 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009071 hdd_debug("IpaUcTxBufCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009072 hdd_ctx->config->IpaUcTxBufCount);
9073 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309074 cds_cfg->uc_txbuf_count = hdd_ctx->config->IpaUcTxBufCount;
9075 cds_cfg->uc_txbuf_size = hdd_ctx->config->IpaUcTxBufSize;
Yun Parkde380782016-08-17 16:26:54 -07009076 if (!is_power_of_2(hdd_ctx->config->IpaUcRxIndRingCount)) {
9077 /* IpaUcRxIndRingCount should be power of 2 */
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009078 hdd_debug("Round down IpaUcRxIndRingCount %d to nearest power of 2",
Yun Parkde380782016-08-17 16:26:54 -07009079 hdd_ctx->config->IpaUcRxIndRingCount);
9080 hdd_ctx->config->IpaUcRxIndRingCount =
9081 rounddown_pow_of_two(
9082 hdd_ctx->config->IpaUcRxIndRingCount);
9083 if (!hdd_ctx->config->IpaUcRxIndRingCount) {
9084 hdd_err("Failed to round down IpaUcRxIndRingCount");
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309085 goto exit;
Yun Parkde380782016-08-17 16:26:54 -07009086 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009087 hdd_debug("IpaUcRxIndRingCount rounded down to %d",
Yun Parkde380782016-08-17 16:26:54 -07009088 hdd_ctx->config->IpaUcRxIndRingCount);
9089 }
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309090 cds_cfg->uc_rxind_ringcount =
Yun Parkde380782016-08-17 16:26:54 -07009091 hdd_ctx->config->IpaUcRxIndRingCount;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309092 cds_cfg->uc_tx_partition_base =
9093 hdd_ctx->config->IpaUcTxPartitionBase;
9094 cds_cfg->max_scan = hdd_ctx->config->max_scan_count;
9095
9096 cds_cfg->ip_tcp_udp_checksum_offload =
9097 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
Jeff Johnsone2ba3cd2017-10-30 20:02:09 -07009098 cds_cfg->enable_rxthread = hdd_ctx->enable_rxthread;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309099 cds_cfg->ce_classify_enabled =
9100 hdd_ctx->config->ce_classify_enabled;
Dustin Brownd3fc9ee2016-09-14 13:57:27 -07009101 cds_cfg->bpf_packet_filter_enable =
9102 hdd_ctx->config->bpf_packet_filter_enable;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309103 cds_cfg->tx_chain_mask_cck = hdd_ctx->config->tx_chain_mask_cck;
9104 cds_cfg->self_gen_frm_pwr = hdd_ctx->config->self_gen_frm_pwr;
9105 cds_cfg->max_station = hdd_ctx->config->maxNumberOfPeers;
Naveen Rawat64e477e2016-05-20 10:34:56 -07009106 cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
Manjunathappa Prakashfff753c2016-09-01 19:34:56 -07009107 cds_cfg->flow_steering_enabled = hdd_ctx->config->flow_steering_enable;
Orhan K AKYILDIZ30e8cbc2017-08-11 18:00:28 -07009108 cds_cfg->max_msdus_per_rxinorderind =
9109 hdd_ctx->config->max_msdus_per_rxinorderind;
Naveen Rawat91df30a2016-10-12 21:26:18 -07009110 cds_cfg->self_recovery_enabled = hdd_ctx->config->enableSelfRecovery;
Sandeep Puligillaafa52892016-10-26 19:03:16 -07009111 cds_cfg->fw_timeout_crash = hdd_ctx->config->fw_timeout_crash;
Hanumanth Reddy Pothulae87621b2017-04-12 20:53:35 +05309112 cds_cfg->active_uc_bpf_mode = hdd_ctx->config->active_uc_bpf_mode;
9113 cds_cfg->active_mc_bc_bpf_mode = hdd_ctx->config->active_mc_bc_bpf_mode;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +05309114 cds_cfg->auto_power_save_fail_mode =
9115 hdd_ctx->config->auto_pwr_save_fail_mode;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309116
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309117 cds_cfg->ito_repeat_count = hdd_ctx->config->ito_repeat_count;
Sandeep Puligilla819d94f2017-10-10 18:33:56 -07009118 cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
Zhu Jianmina2f8e8d2018-02-11 16:37:10 +08009119 cds_cfg->delay_before_vdev_stop =
9120 hdd_ctx->config->delay_before_vdev_stop;
Ashish Kumar Dhanotiya9335d812017-06-30 16:57:20 +05309121
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309122 hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
9123 hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
9124 hdd_nan_populate_cds_config(cds_cfg, hdd_ctx);
Jeff Johnson9078bdc2016-09-23 17:18:11 -07009125 hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309126 cds_init_ini_config(cds_cfg);
9127 return 0;
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05309128
9129exit:
9130 qdf_mem_free(cds_cfg);
9131 return -EINVAL;
Arun Khandavallic811dcc2016-06-26 07:37:21 +05309132}
9133
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009134/**
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009135 * hdd_update_user_config() - API to update user configuration
9136 * parameters to obj mgr which are used by multiple components
9137 * @hdd_ctx: HDD Context
9138 *
9139 * Return: 0 for Success, errno on failure
9140 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009141static int hdd_update_user_config(struct hdd_context *hdd_ctx)
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009142{
9143 struct wlan_objmgr_psoc_user_config *user_config;
9144
9145 user_config = qdf_mem_malloc(sizeof(*user_config));
9146 if (user_config == NULL) {
9147 hdd_alert("Failed to alloc memory for user_config!");
9148 return -ENOMEM;
9149 }
9150
9151 user_config->dot11_mode = hdd_ctx->config->dot11Mode;
9152 user_config->dual_mac_feature_disable =
9153 hdd_ctx->config->dual_mac_feature_disable;
9154 user_config->indoor_channel_support =
9155 hdd_ctx->config->indoor_channel_support;
9156 user_config->is_11d_support_enabled =
9157 hdd_ctx->config->Is11dSupportEnabled;
9158 user_config->is_11h_support_enabled =
9159 hdd_ctx->config->Is11hSupportEnabled;
9160 user_config->optimize_chan_avoid_event =
9161 hdd_ctx->config->goptimize_chan_avoid_event;
9162 user_config->skip_dfs_chnl_in_p2p_search =
9163 hdd_ctx->config->skipDfsChnlInP2pSearch;
Naveen Rawat222b2e92017-03-16 09:52:21 -07009164 user_config->band_capability = hdd_ctx->config->nBandCapability;
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -08009165 wlan_objmgr_psoc_set_user_config(hdd_ctx->hdd_psoc, user_config);
9166
9167 qdf_mem_free(user_config);
9168 return 0;
9169}
9170
9171/**
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009172 * hdd_init_thermal_info - Initialize thermal level
9173 * @hdd_ctx: HDD context
9174 *
9175 * Initialize thermal level at SME layer and set the thermal level callback
9176 * which would be called when a configured thermal threshold is hit.
9177 *
9178 * Return: 0 on success and errno on failure
9179 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009180static int hdd_init_thermal_info(struct hdd_context *hdd_ctx)
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009181{
9182 tSmeThermalParams thermal_param;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309183 QDF_STATUS status;
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009184
9185 thermal_param.smeThermalMgmtEnabled =
9186 hdd_ctx->config->thermalMitigationEnable;
9187 thermal_param.smeThrottlePeriod = hdd_ctx->config->throttlePeriod;
9188
Poddar, Siddarth83905022016-04-16 17:56:08 -07009189 thermal_param.sme_throttle_duty_cycle_tbl[0] =
9190 hdd_ctx->config->throttle_dutycycle_level0;
9191 thermal_param.sme_throttle_duty_cycle_tbl[1] =
9192 hdd_ctx->config->throttle_dutycycle_level1;
9193 thermal_param.sme_throttle_duty_cycle_tbl[2] =
9194 hdd_ctx->config->throttle_dutycycle_level2;
9195 thermal_param.sme_throttle_duty_cycle_tbl[3] =
9196 hdd_ctx->config->throttle_dutycycle_level3;
9197
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009198 thermal_param.smeThermalLevels[0].smeMinTempThreshold =
9199 hdd_ctx->config->thermalTempMinLevel0;
9200 thermal_param.smeThermalLevels[0].smeMaxTempThreshold =
9201 hdd_ctx->config->thermalTempMaxLevel0;
9202 thermal_param.smeThermalLevels[1].smeMinTempThreshold =
9203 hdd_ctx->config->thermalTempMinLevel1;
9204 thermal_param.smeThermalLevels[1].smeMaxTempThreshold =
9205 hdd_ctx->config->thermalTempMaxLevel1;
9206 thermal_param.smeThermalLevels[2].smeMinTempThreshold =
9207 hdd_ctx->config->thermalTempMinLevel2;
9208 thermal_param.smeThermalLevels[2].smeMaxTempThreshold =
9209 hdd_ctx->config->thermalTempMaxLevel2;
9210 thermal_param.smeThermalLevels[3].smeMinTempThreshold =
9211 hdd_ctx->config->thermalTempMinLevel3;
9212 thermal_param.smeThermalLevels[3].smeMaxTempThreshold =
9213 hdd_ctx->config->thermalTempMaxLevel3;
9214
9215 status = sme_init_thermal_info(hdd_ctx->hHal, thermal_param);
9216
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05309217 if (!QDF_IS_STATUS_SUCCESS(status))
Anurag Chouhanc5548422016-02-24 18:33:27 +05309218 return qdf_status_to_os_return(status);
Prashanth Bhatta5f7c9b82016-01-09 13:15:21 -08009219
9220 sme_add_set_thermal_level_callback(hdd_ctx->hHal,
9221 hdd_set_thermal_level_cb);
9222
9223 return 0;
9224
9225}
9226
Prashanth Bhatta98f04d22016-01-08 16:46:21 -08009227#if defined(CONFIG_HDD_INIT_WITH_RTNL_LOCK)
9228/**
9229 * hdd_hold_rtnl_lock - Hold RTNL lock
9230 *
9231 * Hold RTNL lock
9232 *
9233 * Return: True if held and false otherwise
9234 */
9235static inline bool hdd_hold_rtnl_lock(void)
9236{
9237 rtnl_lock();
9238 return true;
9239}
9240
9241/**
9242 * hdd_release_rtnl_lock - Release RTNL lock
9243 *
9244 * Release RTNL lock
9245 *
9246 * Return: None
9247 */
9248static inline void hdd_release_rtnl_lock(void)
9249{
9250 rtnl_unlock();
9251}
9252#else
9253static inline bool hdd_hold_rtnl_lock(void) { return false; }
9254static inline void hdd_release_rtnl_lock(void) { }
9255#endif
9256
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009257#if !defined(REMOVE_PKT_LOG)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009258
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309259/* MAX iwpriv command support */
9260#define PKTLOG_SET_BUFF_SIZE 3
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309261#define PKTLOG_CLEAR_BUFF 4
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309262#define MAX_PKTLOG_SIZE 16
9263
9264/**
9265 * hdd_pktlog_set_buff_size() - set pktlog buffer size
9266 * @hdd_ctx: hdd context
9267 * @set_value2: pktlog buffer size value
9268 *
9269 *
9270 * Return: 0 for success or error.
9271 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009272static int hdd_pktlog_set_buff_size(struct hdd_context *hdd_ctx, int set_value2)
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309273{
9274 struct sir_wifi_start_log start_log = { 0 };
9275 QDF_STATUS status;
9276
9277 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9278 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9279 start_log.ini_triggered = cds_is_packet_log_enabled();
9280 start_log.user_triggered = 1;
9281 start_log.size = set_value2;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309282 start_log.is_pktlog_buff_clear = false;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309283
9284 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9285 if (!QDF_IS_STATUS_SUCCESS(status)) {
9286 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009287 hdd_exit();
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309288 return -EINVAL;
9289 }
9290
9291 return 0;
9292}
9293
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009294/**
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309295 * hdd_pktlog_clear_buff() - clear pktlog buffer
9296 * @hdd_ctx: hdd context
9297 *
9298 * Return: 0 for success or error.
9299 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009300static int hdd_pktlog_clear_buff(struct hdd_context *hdd_ctx)
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309301{
9302 struct sir_wifi_start_log start_log;
9303 QDF_STATUS status;
9304
9305 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9306 start_log.verbose_level = WLAN_LOG_LEVEL_OFF;
9307 start_log.ini_triggered = cds_is_packet_log_enabled();
9308 start_log.user_triggered = 1;
9309 start_log.size = 0;
9310 start_log.is_pktlog_buff_clear = true;
9311
9312 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9313 if (!QDF_IS_STATUS_SUCCESS(status)) {
9314 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009315 hdd_exit();
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309316 return -EINVAL;
9317 }
9318
9319 return 0;
9320}
9321
9322
9323/**
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009324 * hdd_process_pktlog_command() - process pktlog command
9325 * @hdd_ctx: hdd context
9326 * @set_value: value set by user
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309327 * @set_value2: pktlog buffer size value
9328 *
9329 * This function process pktlog command.
9330 * set_value2 only matters when set_value is 3 (set buff size)
9331 * otherwise we ignore it.
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009332 *
9333 * Return: 0 for success or error.
9334 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009335int hdd_process_pktlog_command(struct hdd_context *hdd_ctx, uint32_t set_value,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309336 int set_value2)
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009337{
9338 int ret;
9339 bool enable;
9340 uint8_t user_triggered = 0;
9341
9342 ret = wlan_hdd_validate_context(hdd_ctx);
9343 if (0 != ret)
9344 return ret;
9345
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009346 hdd_debug("set pktlog %d, set size %d", set_value, set_value2);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009347
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309348 if (set_value > PKTLOG_CLEAR_BUFF) {
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009349 hdd_err("invalid pktlog value %d", set_value);
9350 return -EINVAL;
9351 }
9352
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309353 if (set_value == PKTLOG_SET_BUFF_SIZE) {
9354 if (set_value2 <= 0) {
9355 hdd_err("invalid pktlog size %d", set_value2);
9356 return -EINVAL;
9357 } else if (set_value2 > MAX_PKTLOG_SIZE) {
9358 hdd_err("Pktlog buff size is too large. max value is 16MB.\n");
9359 return -EINVAL;
9360 }
9361 return hdd_pktlog_set_buff_size(hdd_ctx, set_value2);
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309362 } else if (set_value == PKTLOG_CLEAR_BUFF) {
9363 return hdd_pktlog_clear_buff(hdd_ctx);
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309364 }
9365
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009366 /*
9367 * set_value = 0 then disable packetlog
9368 * set_value = 1 enable packetlog forcefully
9369 * set_vlaue = 2 then disable packetlog if disabled through ini or
9370 * enable packetlog with AUTO type.
9371 */
9372 enable = ((set_value > 0) && cds_is_packet_log_enabled()) ?
9373 true : false;
9374
9375 if (1 == set_value) {
9376 enable = true;
9377 user_triggered = 1;
9378 }
9379
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309380 return hdd_pktlog_enable_disable(hdd_ctx, enable, user_triggered, 0);
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009381}
Jeff Johnson6dff3ee2017-10-06 14:58:57 -07009382
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009383/**
9384 * hdd_pktlog_enable_disable() - Enable/Disable packet logging
9385 * @hdd_ctx: HDD context
9386 * @enable: Flag to enable/disable
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309387 * @user_triggered: triggered through iwpriv
9388 * @size: buffer size to be used for packetlog
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009389 *
9390 * Return: 0 on success; error number otherwise
9391 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009392int hdd_pktlog_enable_disable(struct hdd_context *hdd_ctx, bool enable,
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309393 uint8_t user_triggered, int size)
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009394{
9395 struct sir_wifi_start_log start_log;
9396 QDF_STATUS status;
9397
9398 start_log.ring_id = RING_ID_PER_PACKET_STATS;
9399 start_log.verbose_level =
9400 enable ? WLAN_LOG_LEVEL_ACTIVE : WLAN_LOG_LEVEL_OFF;
Srinivas Girigowdac34f11d2016-02-25 16:02:42 -08009401 start_log.ini_triggered = cds_is_packet_log_enabled();
9402 start_log.user_triggered = user_triggered;
Poddar, Siddarth176c4362016-10-03 12:25:00 +05309403 start_log.size = size;
Poddar, Siddarthab99a272017-04-10 12:53:26 +05309404 start_log.is_pktlog_buff_clear = false;
Poddar, Siddartheefe3482016-09-21 18:12:59 +05309405 /*
9406 * Use "is_iwpriv_command" flag to distinguish iwpriv command from other
9407 * commands. Host uses this flag to decide whether to send pktlog
9408 * disable command to fw without sending pktlog enable command
9409 * previously. For eg, If vendor sends pktlog disable command without
9410 * sending pktlog enable command, then host discards the packet
9411 * but for iwpriv command, host will send it to fw.
9412 */
9413 start_log.is_iwpriv_command = 1;
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009414 status = sme_wifi_start_logger(hdd_ctx->hHal, start_log);
9415 if (!QDF_IS_STATUS_SUCCESS(status)) {
9416 hdd_err("sme_wifi_start_logger failed(err=%d)", status);
Dustin Browne74003f2018-03-14 12:51:58 -07009417 hdd_exit();
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009418 return -EINVAL;
9419 }
9420
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309421 if (enable == true)
9422 hdd_ctx->is_pktlog_enabled = 1;
9423 else
9424 hdd_ctx->is_pktlog_enabled = 0;
9425
Srinivas Girigowdad9e6f7b2016-02-01 19:37:52 -08009426 return 0;
9427}
9428#endif /* REMOVE_PKT_LOG */
9429
Komal Seelam92fff912016-03-24 11:51:41 +05309430/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009431 * hdd_get_platform_wlan_mac_buff() - API to query platform driver
9432 * for MAC address
Komal Seelam92fff912016-03-24 11:51:41 +05309433 * @dev: Device Pointer
9434 * @num: Number of Valid Mac address
9435 *
9436 * Return: Pointer to MAC address buffer
9437 */
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009438static uint8_t *hdd_get_platform_wlan_mac_buff(struct device *dev,
9439 uint32_t *num)
Komal Seelam92fff912016-03-24 11:51:41 +05309440{
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009441 return pld_get_wlan_mac_address(dev, num);
Komal Seelam92fff912016-03-24 11:51:41 +05309442}
Komal Seelam92fff912016-03-24 11:51:41 +05309443
9444/**
9445 * hdd_populate_random_mac_addr() - API to populate random mac addresses
9446 * @hdd_ctx: HDD Context
9447 * @num: Number of random mac addresses needed
9448 *
9449 * Generate random addresses using bit manipulation on the base mac address
9450 *
9451 * Return: None
9452 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009453void hdd_populate_random_mac_addr(struct hdd_context *hdd_ctx, uint32_t num)
Komal Seelam92fff912016-03-24 11:51:41 +05309454{
9455 uint32_t start_idx = QDF_MAX_CONCURRENCY_PERSONA - num;
9456 uint32_t iter;
9457 struct hdd_config *ini = hdd_ctx->config;
9458 uint8_t *buf = NULL;
9459 uint8_t macaddr_b3, tmp_br3;
9460 uint8_t *src = ini->intfMacAddr[0].bytes;
9461
9462 for (iter = start_idx; iter < QDF_MAX_CONCURRENCY_PERSONA; ++iter) {
9463 buf = ini->intfMacAddr[iter].bytes;
9464 qdf_mem_copy(buf, src, QDF_MAC_ADDR_SIZE);
9465 macaddr_b3 = buf[3];
9466 tmp_br3 = ((macaddr_b3 >> 4 & INTF_MACADDR_MASK) + iter) &
9467 INTF_MACADDR_MASK;
9468 macaddr_b3 += tmp_br3;
9469 macaddr_b3 ^= (1 << INTF_MACADDR_MASK);
9470 buf[0] |= 0x02;
9471 buf[3] = macaddr_b3;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009472 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309473 }
9474}
9475
9476/**
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009477 * hdd_platform_wlan_mac() - API to get mac addresses from platform driver
Komal Seelam92fff912016-03-24 11:51:41 +05309478 * @hdd_ctx: HDD Context
9479 *
9480 * API to get mac addresses from platform driver and update the driver
9481 * structures and configure FW with the base mac address.
9482 * Return: int
9483 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009484static int hdd_platform_wlan_mac(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309485{
9486 uint32_t no_of_mac_addr, iter;
9487 uint32_t max_mac_addr = QDF_MAX_CONCURRENCY_PERSONA;
9488 uint32_t mac_addr_size = QDF_MAC_ADDR_SIZE;
9489 uint8_t *addr, *buf;
9490 struct device *dev = hdd_ctx->parent_dev;
9491 struct hdd_config *ini = hdd_ctx->config;
9492 tSirMacAddr mac_addr;
9493 QDF_STATUS status;
9494
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009495 addr = hdd_get_platform_wlan_mac_buff(dev, &no_of_mac_addr);
Komal Seelam92fff912016-03-24 11:51:41 +05309496
9497 if (no_of_mac_addr == 0 || !addr) {
9498 hdd_warn("Platform Driver Doesn't have wlan mac addresses");
9499 return -EINVAL;
9500 }
9501
9502 if (no_of_mac_addr > max_mac_addr)
9503 no_of_mac_addr = max_mac_addr;
9504
9505 qdf_mem_copy(&mac_addr, addr, mac_addr_size);
9506
9507 for (iter = 0; iter < no_of_mac_addr; ++iter, addr += mac_addr_size) {
9508 buf = ini->intfMacAddr[iter].bytes;
9509 qdf_mem_copy(buf, addr, QDF_MAC_ADDR_SIZE);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009510 hdd_debug(MAC_ADDRESS_STR, MAC_ADDR_ARRAY(buf));
Komal Seelam92fff912016-03-24 11:51:41 +05309511 }
9512
9513 status = sme_set_custom_mac_addr(mac_addr);
9514
9515 if (!QDF_IS_STATUS_SUCCESS(status))
9516 return -EAGAIN;
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009517
Komal Seelam92fff912016-03-24 11:51:41 +05309518 if (no_of_mac_addr < max_mac_addr)
9519 hdd_populate_random_mac_addr(hdd_ctx, max_mac_addr -
9520 no_of_mac_addr);
9521 return 0;
9522}
9523
9524/**
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009525 * hdd_update_mac_addr_to_fw() - API to update wlan mac addresses to FW
9526 * @hdd_ctx: HDD Context
9527 *
9528 * Update MAC address to FW. If MAC address passed by FW is invalid, host
9529 * will generate its own MAC and update it to FW.
9530 *
9531 * Return: 0 for success
9532 * Non-zero error code for failure
9533 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009534static int hdd_update_mac_addr_to_fw(struct hdd_context *hdd_ctx)
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009535{
9536 tSirMacAddr customMacAddr;
9537 QDF_STATUS status;
9538
9539 qdf_mem_copy(&customMacAddr,
9540 &hdd_ctx->config->intfMacAddr[0].bytes[0],
9541 sizeof(tSirMacAddr));
9542 status = sme_set_custom_mac_addr(customMacAddr);
9543 if (!QDF_IS_STATUS_SUCCESS(status))
9544 return -EAGAIN;
9545 return 0;
9546}
9547
9548/**
Komal Seelam92fff912016-03-24 11:51:41 +05309549 * hdd_initialize_mac_address() - API to get wlan mac addresses
9550 * @hdd_ctx: HDD Context
9551 *
9552 * Get MAC addresses from platform driver or wlan_mac.bin. If platform driver
9553 * is provisioned with mac addresses, driver uses it, else it will use
9554 * wlan_mac.bin to update HW MAC addresses.
9555 *
9556 * Return: None
9557 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009558static void hdd_initialize_mac_address(struct hdd_context *hdd_ctx)
Komal Seelam92fff912016-03-24 11:51:41 +05309559{
9560 QDF_STATUS status;
9561 int ret;
9562
Yuanyuan Liu7145eb22016-12-01 10:59:29 -08009563 ret = hdd_platform_wlan_mac(hdd_ctx);
Komal Seelam92fff912016-03-24 11:51:41 +05309564 if (ret == 0)
9565 return;
9566
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009567 hdd_info("MAC is not programmed in platform driver ret: %d, use wlan_mac.bin",
9568 ret);
Komal Seelam92fff912016-03-24 11:51:41 +05309569
9570 status = hdd_update_mac_config(hdd_ctx);
9571
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009572 if (QDF_IS_STATUS_SUCCESS(status))
9573 return;
9574
Yuanyuan Liu3d62f6a2017-06-08 11:08:46 -07009575 hdd_info("MAC is not programmed in wlan_mac.bin ret %d, use default MAC",
9576 status);
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009577
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009578 if (hdd_ctx->update_mac_addr_to_fw) {
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009579 ret = hdd_update_mac_addr_to_fw(hdd_ctx);
Yuanyuan Liu1c2caa32016-11-07 17:13:48 -08009580 if (ret != 0) {
9581 hdd_err("MAC address out-of-sync, ret:%d", ret);
9582 QDF_ASSERT(ret);
9583 }
Yuanyuan Liu245a3e42016-09-14 12:15:16 -07009584 }
Komal Seelam92fff912016-03-24 11:51:41 +05309585}
9586
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009587static int hdd_set_smart_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009588{
9589 int vdev_id = 0;
9590 int param_id = WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME;
9591 int value = hdd_ctx->config->smart_chainmask_enabled;
9592 int vpdev = PDEV_CMD;
9593 int ret;
9594
Naveen Rawat247a8682017-06-05 15:00:31 -07009595 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009596 if (ret)
9597 hdd_err("WMI_PDEV_PARAM_SMART_CHAINMASK_SCHEME failed %d", ret);
9598
9599 return ret;
9600}
9601
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009602static int hdd_set_alternative_chainmask_enabled(struct hdd_context *hdd_ctx)
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009603{
9604 int vdev_id = 0;
9605 int param_id = WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME;
9606 int value = hdd_ctx->config->alternative_chainmask_enabled;
9607 int vpdev = PDEV_CMD;
9608 int ret;
9609
Naveen Rawat247a8682017-06-05 15:00:31 -07009610 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009611 if (ret)
9612 hdd_err("WMI_PDEV_PARAM_ALTERNATIVE_CHAINMASK_SCHEME failed %d",
9613 ret);
9614
9615 return ret;
9616}
9617
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009618static int hdd_set_ani_enabled(struct hdd_context *hdd_ctx)
Jeff Johnson12a744b2017-04-04 08:19:37 -07009619{
9620 int vdev_id = 0;
9621 int param_id = WMI_PDEV_PARAM_ANI_ENABLE;
9622 int value = hdd_ctx->config->ani_enabled;
9623 int vpdev = PDEV_CMD;
9624 int ret;
9625
Naveen Rawat247a8682017-06-05 15:00:31 -07009626 ret = sme_cli_set_command(vdev_id, param_id, value, vpdev);
Jeff Johnson12a744b2017-04-04 08:19:37 -07009627 if (ret)
9628 hdd_err("WMI_PDEV_PARAM_ANI_ENABLE failed %d", ret);
9629
9630 return ret;
9631}
9632
Jeff Johnson89c66ff2016-04-22 15:21:37 -07009633/**
Prashanth Bhatta07998752016-04-28 12:35:33 -07009634 * hdd_pre_enable_configure() - Configurations prior to cds_enable
9635 * @hdd_ctx: HDD context
9636 *
9637 * Pre configurations to be done at lower layer before calling cds enable.
9638 *
9639 * Return: 0 on success and errno on failure.
9640 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009641static int hdd_pre_enable_configure(struct hdd_context *hdd_ctx)
Prashanth Bhatta07998752016-04-28 12:35:33 -07009642{
9643 int ret;
9644 QDF_STATUS status;
9645 tSirRetStatus hal_status;
Leo Changfdb45c32016-10-28 11:09:23 -07009646 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009647
Leo Changfdb45c32016-10-28 11:09:23 -07009648 cdp_register_pause_cb(soc, wlan_hdd_txrx_pause_cb);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009649 /*
9650 * Set 802.11p config
9651 * TODO-OCB: This has been temporarily added here to ensure this
9652 * parameter is set in CSR when we init the channel list. This should
9653 * be removed once the 5.9 GHz channels are added to the regulatory
9654 * domain.
9655 */
9656 hdd_set_dot11p_config(hdd_ctx);
9657
9658 /*
9659 * Note that the cds_pre_enable() sequence triggers the cfg download.
9660 * The cfg download must occur before we update the SME config
9661 * since the SME config operation must access the cfg database
9662 */
9663 status = hdd_set_sme_config(hdd_ctx);
9664
9665 if (QDF_STATUS_SUCCESS != status) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009666 hdd_err("Failed hdd_set_sme_config: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009667 ret = qdf_status_to_os_return(status);
9668 goto out;
9669 }
9670
Tushnim Bhattacharyyaba8ee932017-03-23 09:27:40 -07009671 status = hdd_set_policy_mgr_user_cfg(hdd_ctx);
9672 if (QDF_STATUS_SUCCESS != status) {
9673 hdd_alert("Failed hdd_set_policy_mgr_user_cfg: %d", status);
9674 ret = qdf_status_to_os_return(status);
9675 goto out;
9676 }
9677
Naveen Rawat247a8682017-06-05 15:00:31 -07009678 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS,
Prashanth Bhatta07998752016-04-28 12:35:33 -07009679 hdd_ctx->config->tx_chain_mask_1ss,
9680 PDEV_CMD);
9681 if (0 != ret) {
9682 hdd_err("WMI_PDEV_PARAM_TX_CHAIN_MASK_1SS failed %d", ret);
9683 goto out;
9684 }
9685
Jeff Johnsona89e25d2017-02-24 12:25:07 -08009686 ret = hdd_set_smart_chainmask_enabled(hdd_ctx);
9687 if (ret)
9688 goto out;
9689
9690 ret = hdd_set_alternative_chainmask_enabled(hdd_ctx);
9691 if (ret)
9692 goto out;
9693
Jeff Johnson12a744b2017-04-04 08:19:37 -07009694 ret = hdd_set_ani_enabled(hdd_ctx);
9695 if (ret)
9696 goto out;
9697
Naveen Rawat247a8682017-06-05 15:00:31 -07009698 ret = sme_cli_set_command(0, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
Srinivas Girigowda70e169a2017-03-07 23:55:57 -08009699 hdd_ctx->config->arp_ac_category,
9700 PDEV_CMD);
9701 if (0 != ret) {
9702 hdd_err("WMI_PDEV_PARAM_ARP_AC_OVERRIDE ac: %d ret: %d",
9703 hdd_ctx->config->arp_ac_category, ret);
9704 goto out;
9705 }
9706
Prashanth Bhatta07998752016-04-28 12:35:33 -07009707 status = hdd_set_sme_chan_list(hdd_ctx);
9708 if (status != QDF_STATUS_SUCCESS) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009709 hdd_err("Failed to init channel list: %d", status);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009710 ret = qdf_status_to_os_return(status);
9711 goto out;
9712 }
9713
9714 /* Apply the cfg.ini to cfg.dat */
Krunal Sonidf0f8742016-09-26 14:56:31 -07009715 if (!hdd_update_config_cfg(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -08009716 hdd_err("config update failed");
Prashanth Bhatta07998752016-04-28 12:35:33 -07009717 ret = -EINVAL;
9718 goto out;
9719 }
9720
Prashanth Bhatta07998752016-04-28 12:35:33 -07009721 /*
9722 * Set the MAC Address Currently this is used by HAL to add self sta.
9723 * Remove this once self sta is added as part of session open.
9724 */
9725 hal_status = cfg_set_str(hdd_ctx->hHal, WNI_CFG_STA_ID,
9726 hdd_ctx->config->intfMacAddr[0].bytes,
9727 sizeof(hdd_ctx->config->intfMacAddr[0]));
9728
9729 if (!IS_SIR_STATUS_SUCCESS(hal_status)) {
9730 hdd_err("Failed to set MAC Address. HALStatus is %08d [x%08x]",
9731 hal_status, hal_status);
9732 ret = -EINVAL;
9733 goto out;
9734 }
9735
9736 hdd_init_channel_avoidance(hdd_ctx);
9737
Ganesh Kondabattini408fb8d2017-08-08 22:00:20 +05309738 /* update enable sap mandatory chan list */
9739 policy_mgr_enable_disable_sap_mandatory_chan_list(hdd_ctx->hdd_psoc,
9740 hdd_ctx->config->enable_sap_mandatory_chan_list);
Prashanth Bhatta07998752016-04-28 12:35:33 -07009741out:
9742 return ret;
9743}
9744
9745/**
Peng Xu8fdaa492016-06-22 10:20:47 -07009746 * wlan_hdd_p2p_lo_event_callback - P2P listen offload stop event handler
9747 * @context_ptr - hdd context pointer
9748 * @event_ptr - event structure pointer
9749 *
9750 * This is the p2p listen offload stop event handler, it sends vendor
9751 * event back to supplicant to notify the stop reason.
9752 *
9753 * Return: None
9754 */
9755static void wlan_hdd_p2p_lo_event_callback(void *context_ptr,
9756 void *event_ptr)
9757{
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009758 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Peng Xu8fdaa492016-06-22 10:20:47 -07009759 struct sir_p2p_lo_event *evt = event_ptr;
9760 struct sk_buff *vendor_event;
Jeff Johnson9d295242017-08-29 14:39:48 -07009761 struct hdd_adapter *adapter;
Peng Xu8fdaa492016-06-22 10:20:47 -07009762
Dustin Brown491d54b2018-03-14 12:39:11 -07009763 hdd_enter();
Peng Xu8fdaa492016-06-22 10:20:47 -07009764
9765 if (hdd_ctx == NULL) {
9766 hdd_err("Invalid HDD context pointer");
9767 return;
9768 }
9769
Peng Xu5c682812017-08-06 07:39:13 -07009770 adapter = hdd_get_adapter_by_vdev(hdd_ctx, evt->vdev_id);
9771 if (!adapter) {
9772 hdd_err("Cannot find adapter by vdev_id = %d",
9773 evt->vdev_id);
9774 return;
9775 }
9776
Peng Xu8fdaa492016-06-22 10:20:47 -07009777 vendor_event =
9778 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
Peng Xu5c682812017-08-06 07:39:13 -07009779 &(adapter->wdev), sizeof(uint32_t) + NLMSG_HDRLEN,
Peng Xu8fdaa492016-06-22 10:20:47 -07009780 QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
9781 GFP_KERNEL);
9782
9783 if (!vendor_event) {
9784 hdd_err("cfg80211_vendor_event_alloc failed");
9785 return;
9786 }
9787
9788 if (nla_put_u32(vendor_event,
9789 QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
9790 evt->reason_code)) {
9791 hdd_err("nla put failed");
9792 kfree_skb(vendor_event);
9793 return;
9794 }
9795
9796 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Peng Xu5c682812017-08-06 07:39:13 -07009797 hdd_debug("Sent P2P_LISTEN_OFFLOAD_STOP event for vdev_id = %d",
9798 evt->vdev_id);
Peng Xu8fdaa492016-06-22 10:20:47 -07009799}
9800
9801/**
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309802 * hdd_adaptive_dwelltime_init() - initialization for adaptive dwell time config
9803 * @hdd_ctx: HDD context
9804 *
9805 * This function sends the adaptive dwell time config configuration to the
9806 * firmware via WMA
9807 *
9808 * Return: 0 - success, < 0 - failure
9809 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009810static int hdd_adaptive_dwelltime_init(struct hdd_context *hdd_ctx)
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +05309811{
9812 QDF_STATUS status;
9813 struct adaptive_dwelltime_params dwelltime_params;
9814
9815 dwelltime_params.is_enabled =
9816 hdd_ctx->config->adaptive_dwell_mode_enabled;
9817 dwelltime_params.dwelltime_mode =
9818 hdd_ctx->config->global_adapt_dwelltime_mode;
9819 dwelltime_params.lpf_weight =
9820 hdd_ctx->config->adapt_dwell_lpf_weight;
9821 dwelltime_params.passive_mon_intval =
9822 hdd_ctx->config->adapt_dwell_passive_mon_intval;
9823 dwelltime_params.wifi_act_threshold =
9824 hdd_ctx->config->adapt_dwell_wifi_act_threshold;
9825
9826 status = sme_set_adaptive_dwelltime_config(hdd_ctx->hHal,
9827 &dwelltime_params);
9828
9829 hdd_debug("Sending Adaptive Dwelltime Configuration to fw");
9830 if (!QDF_IS_STATUS_SUCCESS(status)) {
9831 hdd_err("Failed to send Adaptive Dwelltime configuration!");
9832 return -EAGAIN;
9833 }
9834 return 0;
9835}
9836
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009837int hdd_dbs_scan_selection_init(struct hdd_context *hdd_ctx)
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309838{
9839 QDF_STATUS status;
9840 struct wmi_dbs_scan_sel_params dbs_scan_params;
9841 uint32_t i = 0;
9842 uint8_t count = 0, numentries = 0;
9843 uint8_t dbs_scan_config[CDS_DBS_SCAN_PARAM_PER_CLIENT
9844 * CDS_DBS_SCAN_CLIENTS_MAX];
9845
9846 /* check if DBS is enabled or supported */
Bala Venkateshc8236ca2018-03-09 12:38:29 +05309847 if ((hdd_ctx->config->dual_mac_feature_disable ==
9848 DISABLE_DBS_CXN_AND_SCAN) ||
9849 (hdd_ctx->config->dual_mac_feature_disable ==
9850 ENABLE_DBS_CXN_AND_DISABLE_DBS_SCAN))
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309851 return -EINVAL;
9852
9853 hdd_string_to_u8_array(hdd_ctx->config->dbs_scan_selection,
9854 dbs_scan_config, &numentries,
9855 (CDS_DBS_SCAN_PARAM_PER_CLIENT
9856 * CDS_DBS_SCAN_CLIENTS_MAX));
9857
9858 hdd_info("numentries %hu", numentries);
9859 if (!numentries) {
9860 hdd_info("Donot send scan_selection_config");
9861 return 0;
9862 }
9863
9864 /* hdd_set_fw_log_params */
9865 dbs_scan_params.num_clients = 0;
9866 while (count < (numentries - 2)) {
9867 dbs_scan_params.module_id[i] = dbs_scan_config[count];
9868 dbs_scan_params.num_dbs_scans[i] = dbs_scan_config[count + 1];
9869 dbs_scan_params.num_non_dbs_scans[i] =
9870 dbs_scan_config[count + 2];
9871 dbs_scan_params.num_clients++;
9872 hdd_debug("module:%d NDS:%d NNDS:%d",
9873 dbs_scan_params.module_id[i],
9874 dbs_scan_params.num_dbs_scans[i],
9875 dbs_scan_params.num_non_dbs_scans[i]);
9876 count += CDS_DBS_SCAN_PARAM_PER_CLIENT;
9877 i++;
9878 }
9879
9880 dbs_scan_params.pdev_id = 0;
9881
9882 hdd_debug("clients:%d pdev:%d",
9883 dbs_scan_params.num_clients, dbs_scan_params.pdev_id);
9884
9885 status = sme_set_dbs_scan_selection_config(hdd_ctx->hHal,
9886 &dbs_scan_params);
9887 hdd_debug("Sending DBS Scan Selection Configuration to fw");
9888 if (!QDF_IS_STATUS_SUCCESS(status)) {
9889 hdd_err("Failed to send DBS Scan selection configuration!");
9890 return -EAGAIN;
9891 }
9892 return 0;
9893}
9894
Arun Khandavallid4349a92016-07-25 11:10:43 +05309895#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
9896/**
9897 * hdd_set_auto_shutdown_cb() - Set auto shutdown callback
9898 * @hdd_ctx: HDD context
9899 *
9900 * Set auto shutdown callback to get indications from firmware to indicate
9901 * userspace to shutdown WLAN after a configured amount of inactivity.
9902 *
9903 * Return: 0 on success and errno on failure.
9904 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009905static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309906{
9907 QDF_STATUS status;
9908
9909 if (!hdd_ctx->config->WlanAutoShutdown)
9910 return 0;
9911
9912 status = sme_set_auto_shutdown_cb(hdd_ctx->hHal,
9913 wlan_hdd_auto_shutdown_cb);
9914 if (status != QDF_STATUS_SUCCESS)
9915 hdd_err("Auto shutdown feature could not be enabled: %d",
9916 status);
9917
9918 return qdf_status_to_os_return(status);
9919}
9920#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -07009921static int hdd_set_auto_shutdown_cb(struct hdd_context *hdd_ctx)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309922{
9923 return 0;
9924}
9925#endif
9926
9927/**
9928 * hdd_features_init() - Init features
9929 * @hdd_ctx: HDD context
9930 * @adapter: Primary adapter context
9931 *
9932 * Initialize features and their feature context after WLAN firmware is up.
9933 *
9934 * Return: 0 on success and errno on failure.
9935 */
Jeff Johnson9d295242017-08-29 14:39:48 -07009936static int hdd_features_init(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallid4349a92016-07-25 11:10:43 +05309937{
9938 tSirTxPowerLimit hddtxlimit;
9939 QDF_STATUS status;
Manjeet Singha9cae432017-02-28 11:58:22 +05309940 struct sme_5g_band_pref_params band_pref_params;
Arun Khandavallid4349a92016-07-25 11:10:43 +05309941 int ret;
9942
Dustin Brown491d54b2018-03-14 12:39:11 -07009943 hdd_enter();
Arun Khandavallid4349a92016-07-25 11:10:43 +05309944
Arun Khandavallid4349a92016-07-25 11:10:43 +05309945 /* FW capabilities received, Set the Dot11 mode */
9946 sme_setdef_dot11mode(hdd_ctx->hHal);
Kiran Kumar Lokere1aa9c9a2016-10-05 18:50:59 -07009947 sme_set_prefer_80MHz_over_160MHz(hdd_ctx->hHal,
9948 hdd_ctx->config->sta_prefer_80MHz_over_160MHz);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309949
Arun Khandavallid4349a92016-07-25 11:10:43 +05309950
9951 if (hdd_ctx->config->fIsImpsEnabled)
9952 hdd_set_idle_ps_config(hdd_ctx, true);
9953 else
9954 hdd_set_idle_ps_config(hdd_ctx, false);
9955
Poddar, Siddarth37033032017-10-11 15:47:40 +05309956 /* Send Enable/Disable data stall detection cmd to FW */
9957 sme_cli_set_command(0, WMI_PDEV_PARAM_DATA_STALL_DETECT_ENABLE,
9958 hdd_ctx->config->enable_data_stall_det, PDEV_CMD);
9959
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309960 if (hdd_ctx->config->enable_go_cts2self_for_sta)
Srinivas Girigowdab841da72017-03-25 18:04:39 -07009961 sme_set_cts2self_for_p2p_go(hdd_ctx->hHal);
Agrawal Ashish642ec9b2017-02-22 14:45:30 +05309962
Nachiket Kukade8983cf62017-10-12 18:14:48 +05309963 if (sme_set_vc_mode_config(hdd_ctx->config->vc_mode_cfg_bitmap))
9964 hdd_warn("Error in setting Voltage Corner mode config to FW");
9965
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -07009966 if (hdd_rx_ol_init(hdd_ctx))
9967 hdd_err("Unable to initialize Rx LRO/GRO in fw");
Arun Khandavallid4349a92016-07-25 11:10:43 +05309968
9969 if (hdd_adaptive_dwelltime_init(hdd_ctx))
9970 hdd_err("Unable to send adaptive dwelltime setting to FW");
9971
Nitesh Shahf9a09ff2017-05-22 15:46:25 +05309972 if (hdd_dbs_scan_selection_init(hdd_ctx))
9973 hdd_err("Unable to send DBS scan selection setting to FW");
9974
Arun Khandavallid4349a92016-07-25 11:10:43 +05309975 ret = hdd_init_thermal_info(hdd_ctx);
9976 if (ret) {
9977 hdd_err("Error while initializing thermal information");
9978 goto deregister_frames;
9979 }
9980
Poddar, Siddarth61fbc932017-12-19 14:27:55 +05309981 /**
9982 * In case of SSR/PDR, if pktlog was enabled manually before
9983 * SSR/PDR, Then enabled it again automatically after Wlan
9984 * device up.
9985 */
9986 if (cds_is_driver_recovering()) {
9987 if (hdd_ctx->is_pktlog_enabled)
9988 hdd_pktlog_enable_disable(hdd_ctx, true, 0, 0);
Tiger Yuf3d5d7f2018-03-15 14:48:11 +08009989 }
Poddar, Siddarth66a46592017-02-22 11:44:44 +05309990
Arun Khandavallid4349a92016-07-25 11:10:43 +05309991 hddtxlimit.txPower2g = hdd_ctx->config->TxPower2g;
9992 hddtxlimit.txPower5g = hdd_ctx->config->TxPower5g;
9993 status = sme_txpower_limit(hdd_ctx->hHal, &hddtxlimit);
9994 if (!QDF_IS_STATUS_SUCCESS(status))
9995 hdd_err("Error setting txlimit in sme: %d", status);
9996
Yu Wangf5d5b5f2017-05-25 22:38:32 +08009997 wlan_hdd_tsf_init(hdd_ctx);
Arun Khandavallid4349a92016-07-25 11:10:43 +05309998
Arun Khandavallid4349a92016-07-25 11:10:43 +05309999 ret = hdd_register_cb(hdd_ctx);
10000 if (ret) {
10001 hdd_err("Failed to register HDD callbacks!");
10002 goto deregister_frames;
10003 }
10004
Selvaraj, Sridhar371f55e2017-02-21 10:36:15 +053010005 if (hdd_ctx->config->goptimize_chan_avoid_event) {
10006 status = sme_enable_disable_chanavoidind_event(
10007 hdd_ctx->hHal, 0);
10008 if (!QDF_IS_STATUS_SUCCESS(status)) {
10009 hdd_err("Failed to disable Chan Avoidance Indication");
10010 goto deregister_cb;
10011 }
10012 }
Arun Khandavallid4349a92016-07-25 11:10:43 +053010013
Manjeet Singha9cae432017-02-28 11:58:22 +053010014 if (hdd_ctx->config->enable_5g_band_pref) {
10015 band_pref_params.rssi_boost_threshold_5g =
10016 hdd_ctx->config->rssi_boost_threshold_5g;
10017 band_pref_params.rssi_boost_factor_5g =
10018 hdd_ctx->config->rssi_boost_factor_5g;
10019 band_pref_params.max_rssi_boost_5g =
10020 hdd_ctx->config->max_rssi_boost_5g;
10021 band_pref_params.rssi_penalize_threshold_5g =
10022 hdd_ctx->config->rssi_penalize_threshold_5g;
10023 band_pref_params.rssi_penalize_factor_5g =
10024 hdd_ctx->config->rssi_penalize_factor_5g;
10025 band_pref_params.max_rssi_penalize_5g =
10026 hdd_ctx->config->max_rssi_penalize_5g;
10027 sme_set_5g_band_pref(hdd_ctx->hHal, &band_pref_params);
10028 }
10029
Arun Khandavallid4349a92016-07-25 11:10:43 +053010030 /* register P2P Listen Offload event callback */
10031 if (wma_is_p2p_lo_capable())
10032 sme_register_p2p_lo_event(hdd_ctx->hHal, hdd_ctx,
10033 wlan_hdd_p2p_lo_event_callback);
10034
10035 ret = hdd_set_auto_shutdown_cb(hdd_ctx);
10036
10037 if (ret)
10038 goto deregister_cb;
10039
Dustin Brown11638b72018-01-25 17:37:25 +053010040 wlan_hdd_init_chan_info(hdd_ctx);
10041
Dustin Browne74003f2018-03-14 12:51:58 -070010042 hdd_exit();
Arun Khandavallid4349a92016-07-25 11:10:43 +053010043 return 0;
10044
10045deregister_cb:
10046 hdd_deregister_cb(hdd_ctx);
10047deregister_frames:
10048 wlan_hdd_cfg80211_deregister_frames(adapter);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010049 return -EINVAL;
Arun Khandavallid4349a92016-07-25 11:10:43 +053010050}
10051
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010052/**
10053 * hdd_features_deinit() - Deinit features
10054 * @hdd_ctx: HDD context
10055 *
10056 * De-Initialize features and their feature context.
10057 *
10058 * Return: none.
10059 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010060static void hdd_features_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010061{
Dustin Brown11638b72018-01-25 17:37:25 +053010062 wlan_hdd_deinit_chan_info(hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010063 wlan_hdd_tsf_deinit(hdd_ctx);
10064}
10065
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010066/**
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010067 * hdd_register_bcn_cb() - register scan beacon callback
10068 * @hdd_ctx - Pointer to the HDD context
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010069 *
Sandeep Puligilla0a11f8d2017-06-23 15:53:29 -070010070 * Return: QDF_STATUS
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010071 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010072static inline QDF_STATUS hdd_register_bcn_cb(struct hdd_context *hdd_ctx)
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010073{
10074 QDF_STATUS status;
10075
10076 status = ucfg_scan_register_bcn_cb(hdd_ctx->hdd_psoc,
10077 wlan_cfg80211_inform_bss_frame,
10078 SCAN_CB_TYPE_INFORM_BCN);
10079 if (!QDF_IS_STATUS_SUCCESS(status)) {
10080 hdd_err("failed with status code %08d [x%08x]",
10081 status, status);
10082 return status;
10083 }
10084
10085 return QDF_STATUS_SUCCESS;
10086}
Arun Khandavallid4349a92016-07-25 11:10:43 +053010087
Gupta, Kapil96c7f2f2016-04-25 19:13:41 +053010088/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010089 * hdd_configure_cds() - Configure cds modules
10090 * @hdd_ctx: HDD context
10091 * @adapter: Primary adapter context
10092 *
10093 * Enable Cds modules after WLAN firmware is up.
10094 *
10095 * Return: 0 on success and errno on failure.
10096 */
Jeff Johnson9d295242017-08-29 14:39:48 -070010097int hdd_configure_cds(struct hdd_context *hdd_ctx, struct hdd_adapter *adapter)
Arun Khandavallifae92942016-08-01 13:31:08 +053010098{
10099 int ret;
10100 QDF_STATUS status;
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010101 int set_value;
10102 uint32_t num_abg_tx_chains = 0;
10103 uint32_t num_11b_tx_chains = 0;
10104 uint32_t num_11ag_tx_chains = 0;
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010105 struct policy_mgr_dp_cbacks dp_cbs = {0};
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010106
10107 if (hdd_ctx->config->sifs_burst_duration) {
10108 set_value = (SIFS_BURST_DUR_MULTIPLIER) *
10109 hdd_ctx->config->sifs_burst_duration;
10110
10111 if ((set_value > 0) && (set_value <= SIFS_BURST_DUR_MAX))
10112 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_BURST_DUR,
10113 set_value, PDEV_CMD);
10114 }
10115
10116 if (hdd_ctx->config->is_force_1x1)
10117 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_SET_IOT_PATTERN,
10118 1, PDEV_CMD);
10119 /* set chip power save failure detected callback */
10120 sme_set_chip_pwr_save_fail_cb(hdd_ctx->hHal,
10121 hdd_chip_pwr_save_fail_detected_cb);
10122
10123 if (hdd_ctx->config->max_mpdus_inampdu) {
10124 set_value = hdd_ctx->config->max_mpdus_inampdu;
10125 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_MAX_MPDUS_IN_AMPDU,
10126 set_value, PDEV_CMD);
10127 }
10128
10129 if (hdd_ctx->config->enable_rts_sifsbursting) {
10130 set_value = hdd_ctx->config->enable_rts_sifsbursting;
10131 sme_cli_set_command(0,
10132 (int)WMI_PDEV_PARAM_ENABLE_RTS_SIFS_BURSTING,
10133 set_value, PDEV_CMD);
10134 }
10135
10136 if (hdd_ctx->config->sap_get_peer_info) {
10137 set_value = hdd_ctx->config->sap_get_peer_info;
10138 sme_cli_set_command(0,
10139 (int)WMI_PDEV_PARAM_PEER_STATS_INFO_ENABLE,
10140 set_value, PDEV_CMD);
10141 }
10142
10143 num_11b_tx_chains = hdd_ctx->config->num_11b_tx_chains;
10144 num_11ag_tx_chains = hdd_ctx->config->num_11ag_tx_chains;
10145 if (!hdd_ctx->config->enable2x2) {
10146 if (num_11b_tx_chains > 1)
10147 num_11b_tx_chains = 1;
10148 if (num_11ag_tx_chains > 1)
10149 num_11ag_tx_chains = 1;
10150 }
10151 WMI_PDEV_PARAM_SET_11B_TX_CHAIN_NUM(num_abg_tx_chains,
10152 num_11b_tx_chains);
10153 WMI_PDEV_PARAM_SET_11AG_TX_CHAIN_NUM(num_abg_tx_chains,
10154 num_11ag_tx_chains);
10155 sme_cli_set_command(0, (int)WMI_PDEV_PARAM_ABG_MODE_TX_CHAIN_NUM,
10156 num_abg_tx_chains, PDEV_CMD);
Arun Khandavallifae92942016-08-01 13:31:08 +053010157
10158 ret = hdd_pre_enable_configure(hdd_ctx);
10159 if (ret) {
10160 hdd_err("Failed to pre-configure cds");
10161 goto out;
10162 }
10163
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010164 /* Always get latest IPA resources allocated from cds_open and configure
10165 * IPA module before configuring them to FW. Sequence required as crash
10166 * observed otherwise.
10167 */
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010168 if (ucfg_ipa_uc_ol_init(hdd_ctx->hdd_pdev,
10169 cds_get_context(QDF_MODULE_ID_QDF_DEVICE))) {
Manikandan Mohan2e803a02017-02-14 14:57:53 -080010170 hdd_err("Failed to setup pipes");
10171 goto out;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -080010172 }
10173
Arun Khandavallifae92942016-08-01 13:31:08 +053010174 /*
10175 * Start CDS which starts up the SME/MAC/HAL modules and everything
10176 * else
10177 */
Jeff Johnson8f9dd5f2017-09-13 14:16:08 -070010178 status = cds_enable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010179
10180 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010181 hdd_err("cds_enable failed");
Arun Khandavallifae92942016-08-01 13:31:08 +053010182 goto out;
10183 }
10184
10185 status = hdd_post_cds_enable_config(hdd_ctx);
10186 if (!QDF_IS_STATUS_SUCCESS(status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010187 hdd_err("hdd_post_cds_enable_config failed");
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010188 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010189 }
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010190 status = hdd_register_bcn_cb(hdd_ctx);
10191 if (!QDF_IS_STATUS_SUCCESS(status)) {
Paul Zhange03cf4c2018-01-19 18:33:22 +080010192 hdd_err("hdd_register_bcn_cb failed");
Abhishek Singh6092fbb2017-01-25 18:10:31 +053010193 goto cds_disable;
10194 }
Arun Khandavallifae92942016-08-01 13:31:08 +053010195
10196 ret = hdd_features_init(hdd_ctx, adapter);
10197 if (ret)
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010198 goto cds_disable;
Arun Khandavallifae92942016-08-01 13:31:08 +053010199
Manjunathappa Prakash7b0ad462018-04-15 00:37:16 -070010200 if (hdd_ctx->ol_enable)
10201 dp_cbs.hdd_disable_rx_ol_in_concurrency =
10202 hdd_disable_rx_ol_in_concurrency;
Yun Parkff6a16a2017-09-26 16:38:18 -070010203 dp_cbs.hdd_set_rx_mode_rps_cb = hdd_set_rx_mode_rps;
jiadbb47e132018-03-30 16:28:30 +080010204 dp_cbs.hdd_ipa_set_mcc_mode_cb = hdd_ipa_set_mcc_mode;
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010205 status = policy_mgr_register_dp_cb(hdd_ctx->hdd_psoc, &dp_cbs);
10206 if (!QDF_IS_STATUS_SUCCESS(status)) {
Yun Parkff6a16a2017-09-26 16:38:18 -070010207 hdd_debug("Failed to register DP cb with Policy Manager");
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010208 goto cds_disable;
10209 }
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010210 status = policy_mgr_register_mode_change_cb(hdd_ctx->hdd_psoc,
10211 wlan_hdd_send_mode_change_event);
10212 if (!QDF_IS_STATUS_SUCCESS(status)) {
10213 hdd_debug("Failed to register mode change cb with Policy Manager");
10214 goto cds_disable;
10215 }
Manjunathappa Prakash7b6cb002017-10-09 00:40:24 -070010216
Jeff Johnson8bb61112018-03-31 13:33:54 -070010217 if (hdd_green_ap_enable_egap(hdd_ctx))
Nachiket Kukadefbd1afc2017-07-12 17:41:54 +053010218 hdd_debug("enhance green ap is not enabled");
10219
Nachiket Kukadedd302662017-07-13 17:31:44 +053010220 if (0 != wlan_hdd_set_wow_pulse(hdd_ctx, true))
10221 hdd_debug("Failed to set wow pulse");
10222
Ashish Kumar Dhanotiyacb14b112018-01-19 19:26:44 +053010223 sme_cli_set_command(0, WMI_PDEV_PARAM_GCMP_SUPPORT_ENABLE,
10224 hdd_ctx->config->gcmp_enabled, PDEV_CMD);
Hanumanth Reddy Pothulaab395952017-09-05 19:12:26 +053010225 sme_cli_set_command(0, WMI_PDEV_AUTO_DETECT_POWER_FAILURE,
10226 hdd_ctx->config->auto_pwr_save_fail_mode, PDEV_CMD);
10227
Ravi Kumar Bokka990edcc2017-01-09 20:02:58 +053010228
10229 if (hdd_ctx->config->enable_phy_reg_retention)
10230 wma_cli_set_command(0, WMI_PDEV_PARAM_FAST_PWR_TRANSITION,
10231 hdd_ctx->config->enable_phy_reg_retention, PDEV_CMD);
10232
Arun Khandavallifae92942016-08-01 13:31:08 +053010233 return 0;
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010234
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010235cds_disable:
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010236 cds_disable(hdd_ctx->hdd_psoc);
Houston Hoffman8d1a6f02016-10-10 17:48:58 -070010237
Arun Khandavallifae92942016-08-01 13:31:08 +053010238out:
10239 return -EINVAL;
10240}
10241
10242/**
10243 * hdd_deconfigure_cds() -De-Configure cds
10244 * @hdd_ctx: HDD context
10245 *
10246 * Deconfigure Cds modules before WLAN firmware is down.
10247 *
10248 * Return: 0 on success and errno on failure.
10249 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010250static int hdd_deconfigure_cds(struct hdd_context *hdd_ctx)
Arun Khandavallifae92942016-08-01 13:31:08 +053010251{
10252 QDF_STATUS qdf_status;
Houston Hoffman6640cf32016-10-10 16:44:29 -070010253 int ret = 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053010254
Dustin Brown491d54b2018-03-14 12:39:11 -070010255 hdd_enter();
Yu Wangf5d5b5f2017-05-25 22:38:32 +080010256
10257 /* De-init features */
10258 hdd_features_deinit(hdd_ctx);
10259
Arun Khandavallifae92942016-08-01 13:31:08 +053010260 /* De-register the SME callbacks */
10261 hdd_deregister_cb(hdd_ctx);
10262
Yeshwanth Sriram Guntuka2d6204f2018-01-23 18:52:14 +053010263 qdf_status = policy_mgr_deregister_mode_change_cb(hdd_ctx->hdd_psoc);
10264 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10265 hdd_debug("Failed to deregister mode change cb with Policy Manager");
10266 }
10267
Jeff Johnsonea5c2aa12017-09-13 14:18:59 -070010268 qdf_status = cds_disable(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010269 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10270 hdd_err("Failed to Disable the CDS Modules! :%d",
10271 qdf_status);
Houston Hoffman6640cf32016-10-10 16:44:29 -070010272 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010273 }
10274
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010275 if (ucfg_ipa_uc_ol_deinit(hdd_ctx->hdd_pdev) != QDF_STATUS_SUCCESS) {
Sravan Kumar Kairam71121712017-04-15 00:34:42 +053010276 hdd_err("Failed to disconnect pipes");
10277 ret = -EINVAL;
10278 }
10279
Dustin Browne74003f2018-03-14 12:51:58 -070010280 hdd_exit();
Houston Hoffman6640cf32016-10-10 16:44:29 -070010281 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010282}
10283
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010284#ifdef FEATURE_WLAN_MCC_TO_SCC_SWITCH
10285static void hdd_deregister_policy_manager_callback(
10286 struct wlan_objmgr_psoc *psoc)
10287{
10288 if (QDF_STATUS_SUCCESS !=
10289 policy_mgr_deregister_hdd_cb(psoc)) {
10290 hdd_err("HDD callback deregister with policy manager failed");
10291 }
10292}
10293#else
10294static void hdd_deregister_policy_manager_callback(
10295 struct wlan_objmgr_psoc *psoc)
10296{
10297}
10298#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010299
10300/**
10301 * hdd_wlan_stop_modules - Single driver state machine for stoping modules
10302 * @hdd_ctx: HDD context
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010303 * @ftm_mode: ftm mode
Arun Khandavallifae92942016-08-01 13:31:08 +053010304 *
10305 * This function maintains the driver state machine it will be invoked from
10306 * exit, shutdown and con_mode change handler. Depending on the driver state
10307 * shall perform the stopping/closing of the modules.
10308 *
10309 * Return: 0 for success; non-zero for failure
10310 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010311int hdd_wlan_stop_modules(struct hdd_context *hdd_ctx, bool ftm_mode)
Arun Khandavallifae92942016-08-01 13:31:08 +053010312{
10313 void *hif_ctx;
10314 qdf_device_t qdf_ctx;
10315 QDF_STATUS qdf_status;
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010316 int ret = 0;
Dustin Brown4bc0a622017-12-06 15:56:50 -080010317 bool is_recovery_stop = cds_is_driver_recovering();
Liangwei Donga78cc1d2018-02-01 02:19:30 -050010318 bool is_idle_stop = !cds_is_driver_unloading() && !is_recovery_stop &&
10319 !cds_is_driver_loading();
Dustin Brown70111822017-03-30 15:31:40 -070010320 int active_threads;
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010321 struct target_psoc_info *tgt_hdl;
Arun Khandavallifae92942016-08-01 13:31:08 +053010322
Dustin Brown491d54b2018-03-14 12:39:11 -070010323 hdd_enter();
Yun Parkfec73dc2017-09-06 10:40:07 -070010324 hdd_alert("stop WLAN module: entering driver status=%d",
10325 hdd_ctx->driver_status);
Arun Khandavallifae92942016-08-01 13:31:08 +053010326
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070010327 hdd_deregister_policy_manager_callback(hdd_ctx->hdd_psoc);
10328
Arun Khandavallifae92942016-08-01 13:31:08 +053010329 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
10330 if (!qdf_ctx) {
10331 hdd_err("QDF device context NULL");
10332 return -EINVAL;
10333 }
10334
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010335 mutex_lock(&hdd_ctx->iface_change_lock);
10336 hdd_ctx->stop_modules_in_progress = true;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010337 cds_set_module_stop_in_progress(true);
Arun Khandavallifae92942016-08-01 13:31:08 +053010338
Dustin Brown70111822017-03-30 15:31:40 -070010339 active_threads = cds_return_external_threads_count();
Jeff Johnson214671b2017-10-30 19:45:23 -070010340 if (active_threads > 0 || hdd_ctx->is_wiphy_suspended) {
Rajeev Kumar86177c22017-03-16 19:44:39 -070010341 hdd_warn("External threads %d wiphy suspend %d",
Jeff Johnson214671b2017-10-30 19:45:23 -070010342 active_threads, hdd_ctx->is_wiphy_suspended);
Dustin Brown70111822017-03-30 15:31:40 -070010343
10344 cds_print_external_threads();
10345
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010346 if (is_idle_stop && !ftm_mode) {
Dustin Brown70111822017-03-30 15:31:40 -070010347 mutex_unlock(&hdd_ctx->iface_change_lock);
Dustin Brown6f427922017-09-19 12:19:00 -070010348 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10349 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010350 hdd_prevent_suspend_timeout(
10351 hdd_ctx->config->iface_change_wait_time,
10352 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010353 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010354 cds_set_module_stop_in_progress(false);
Dustin Brown70111822017-03-30 15:31:40 -070010355 return 0;
10356 }
Rajeev Kumar86177c22017-03-16 19:44:39 -070010357 }
10358
Arun Khandavallifae92942016-08-01 13:31:08 +053010359 hdd_info("Present Driver Status: %d", hdd_ctx->driver_status);
10360
Kabilan Kannan6edafeb2017-11-16 16:34:34 -080010361 /* free user wowl patterns */
10362 hdd_free_user_wowl_ptrns();
10363
Arun Khandavallifae92942016-08-01 13:31:08 +053010364 switch (hdd_ctx->driver_status) {
10365 case DRIVER_MODULES_UNINITIALIZED:
10366 hdd_info("Modules not initialized just return");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010367 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010368 case DRIVER_MODULES_CLOSED:
10369 hdd_info("Modules already closed");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010370 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010371 case DRIVER_MODULES_ENABLED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010372 hdd_info("Wlan transitioning (OPENED <- ENABLED)");
10373
Komal Seelamf2136bb2016-09-28 18:30:44 +053010374 hdd_disable_power_management();
Arun Khandavallifae92942016-08-01 13:31:08 +053010375 if (hdd_deconfigure_cds(hdd_ctx)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010376 hdd_err("Failed to de-configure CDS");
Arun Khandavallifae92942016-08-01 13:31:08 +053010377 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010378 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010379 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010380 hdd_debug("successfully Disabled the CDS modules!");
Dustin Brown550f6d22017-12-14 15:44:01 -080010381
Arun Khandavallifae92942016-08-01 13:31:08 +053010382 hdd_ctx->driver_status = DRIVER_MODULES_OPENED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010383 hdd_info("Wlan transitioned (now OPENED)");
10384
10385 /* fall through */
Arun Khandavallifae92942016-08-01 13:31:08 +053010386 case DRIVER_MODULES_OPENED:
Dustin Brown550f6d22017-12-14 15:44:01 -080010387 hdd_info("Wlan transitioning (CLOSED <- OPENED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010388 break;
10389 default:
10390 hdd_err("Trying to stop wlan in a wrong state: %d",
10391 hdd_ctx->driver_status);
10392 QDF_ASSERT(0);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010393 ret = -EINVAL;
10394 goto done;
Arun Khandavallifae92942016-08-01 13:31:08 +053010395 }
10396
Amar Singhal18081642018-01-26 16:04:13 -080010397 hdd_sysfs_destroy_version_interface();
Dustin Brown550f6d22017-12-14 15:44:01 -080010398 hdd_debug("Closing CDS modules!");
Amar Singhal18081642018-01-26 16:04:13 -080010399
Rajeev Kumarbe021242017-02-16 16:12:23 -080010400 qdf_status = cds_post_disable();
Govind Singhb048e872016-09-27 22:07:43 +053010401 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10402 hdd_err("Failed to process post CDS disable Modules! :%d",
10403 qdf_status);
10404 ret = -EINVAL;
10405 QDF_ASSERT(0);
10406 }
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010407
psimhadeea0a12017-12-18 14:50:02 -080010408 hdd_runtime_suspend_context_deinit(hdd_ctx);
10409
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070010410 qdf_status = cds_dp_close(hdd_ctx->hdd_psoc);
10411 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
10412 hdd_warn("Failed to stop CDS DP: %d", qdf_status);
10413 ret = -EINVAL;
10414 QDF_ASSERT(0);
10415 }
10416
Jeff Johnsone4b14592017-09-13 14:23:33 -070010417 qdf_status = cds_close(hdd_ctx->hdd_psoc);
Arun Khandavallifae92942016-08-01 13:31:08 +053010418 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010419 hdd_warn("Failed to stop CDS: %d", qdf_status);
Govind Singhb048e872016-09-27 22:07:43 +053010420 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010421 QDF_ASSERT(0);
10422 }
Krunal Sonid32c6bc2016-10-18 18:00:21 -070010423
Amar Singhal410675c2018-01-10 12:14:21 -080010424 dispatcher_pdev_close(hdd_ctx->hdd_pdev);
Liangwei Dong50a64a72018-01-11 01:17:00 -050010425 ret = hdd_objmgr_release_and_destroy_pdev(hdd_ctx);
10426 if (ret) {
10427 hdd_err("Failed to destroy pdev; errno:%d", ret);
10428 QDF_ASSERT(0);
10429 }
10430
10431 /*
10432 * Reset total mac phy during module stop such that during
10433 * next module start same psoc is used to populate new service
10434 * ready data
10435 */
Arunk Khandavallia6305a32018-01-25 11:19:18 +053010436 tgt_hdl = wlan_psoc_get_tgt_if_handle(hdd_ctx->hdd_psoc);
10437 if (tgt_hdl)
10438 target_psoc_set_total_mac_phy_cnt(tgt_hdl, 0);
10439
Liangwei Dong50a64a72018-01-11 01:17:00 -050010440
Arun Khandavallifae92942016-08-01 13:31:08 +053010441 hif_ctx = cds_get_context(QDF_MODULE_ID_HIF);
10442 if (!hif_ctx) {
10443 hdd_err("Hif context is Null");
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010444 ret = -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053010445 }
10446
Arunk Khandavalli4b404332017-09-26 12:46:00 +053010447 if (hdd_ctx->target_hw_name) {
10448 qdf_mem_free(hdd_ctx->target_hw_name);
10449 hdd_ctx->target_hw_name = NULL;
10450 }
10451
Sravan Kumar Kairam27296782017-04-21 22:04:18 +053010452 hdd_hif_close(hdd_ctx, hif_ctx);
Arun Khandavallifae92942016-08-01 13:31:08 +053010453
10454 ol_cds_free();
10455
Dustin Brown70111822017-03-30 15:31:40 -070010456 if (is_idle_stop) {
Arun Khandavallifae92942016-08-01 13:31:08 +053010457 ret = pld_power_off(qdf_ctx->dev);
10458 if (ret)
10459 hdd_err("CNSS power down failed put device into Low power mode:%d",
10460 ret);
10461 }
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010462
Dustin Brown4bc0a622017-12-06 15:56:50 -080010463 /* many adapter resources are not freed by design in SSR case */
10464 if (!is_recovery_stop)
10465 hdd_check_for_leaks();
Dustin Brown26b3d042017-12-21 11:13:27 -080010466 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010467
Arunk Khandavalli847969d2017-09-25 15:15:36 +053010468 /* Once the firmware sequence is completed reset this flag */
10469 hdd_ctx->imps_enabled = false;
Arun Khandavallifae92942016-08-01 13:31:08 +053010470 hdd_ctx->driver_status = DRIVER_MODULES_CLOSED;
Dustin Brown550f6d22017-12-14 15:44:01 -080010471 hdd_info("Wlan transitioned (now CLOSED)");
Arun Khandavallifae92942016-08-01 13:31:08 +053010472
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010473done:
10474 hdd_ctx->stop_modules_in_progress = false;
Manjunathappa Prakash71c74a42017-10-19 23:28:43 -070010475 cds_set_module_stop_in_progress(false);
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010476 mutex_unlock(&hdd_ctx->iface_change_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -070010477 hdd_alert("stop WLAN module: exit driver status=%d",
10478 hdd_ctx->driver_status);
Dustin Brown4bc0a622017-12-06 15:56:50 -080010479
Dustin Browne74003f2018-03-14 12:51:58 -070010480 hdd_exit();
Arun Khandavallifae92942016-08-01 13:31:08 +053010481
Arun Khandavallia172c3e2016-08-26 17:33:13 +053010482 return ret;
Arun Khandavallifae92942016-08-01 13:31:08 +053010483}
10484
Arun Khandavallifae92942016-08-01 13:31:08 +053010485
Wen Gongaa6d55d2018-04-26 16:33:21 +080010486#ifdef WLAN_FEATURE_HDD_MEMDUMP_ENABLE
Arun Khandavallifae92942016-08-01 13:31:08 +053010487/**
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010488 * hdd_state_info_dump() - prints state information of hdd layer
10489 * @buf: buffer pointer
10490 * @size: size of buffer to be filled
10491 *
10492 * This function is used to dump state information of hdd layer
10493 *
10494 * Return: None
10495 */
10496static void hdd_state_info_dump(char **buf_ptr, uint16_t *size)
10497{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010498 struct hdd_context *hdd_ctx;
Jeff Johnson40dae4e2017-08-29 14:00:25 -070010499 struct hdd_station_ctx *hdd_sta_ctx;
Jeff Johnson9d295242017-08-29 14:39:48 -070010500 struct hdd_adapter *adapter;
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010501 uint16_t len = 0;
10502 char *buf = *buf_ptr;
10503
10504 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
10505 if (!hdd_ctx) {
10506 hdd_err("Failed to get hdd context ");
10507 return;
10508 }
10509
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010510 hdd_debug("size of buffer: %d", *size);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010511
10512 len += scnprintf(buf + len, *size - len,
Jeff Johnson214671b2017-10-30 19:45:23 -070010513 "\n is_wiphy_suspended %d", hdd_ctx->is_wiphy_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010514 len += scnprintf(buf + len, *size - len,
Rajeev Kumareada0d02016-12-08 17:44:17 -080010515 "\n is_scheduler_suspended %d",
10516 hdd_ctx->is_scheduler_suspended);
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010517
Dustin Brown920397d2017-12-13 16:27:50 -080010518 hdd_for_each_adapter(hdd_ctx, adapter) {
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010519 if (adapter->dev)
10520 len += scnprintf(buf + len, *size - len,
10521 "\n device name: %s", adapter->dev->name);
wadesong42968e92017-06-08 14:11:21 +080010522 len += scnprintf(buf + len, *size - len,
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010523 "\n device_mode: %d", adapter->device_mode);
10524 switch (adapter->device_mode) {
10525 case QDF_STA_MODE:
10526 case QDF_P2P_CLIENT_MODE:
10527 hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
10528 len += scnprintf(buf + len, *size - len,
10529 "\n connState: %d",
10530 hdd_sta_ctx->conn_info.connState);
10531 break;
10532
10533 default:
10534 break;
10535 }
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010536 }
10537
10538 *size -= len;
10539 *buf_ptr += len;
10540}
10541
10542/**
10543 * hdd_register_debug_callback() - registration function for hdd layer
10544 * to print hdd state information
10545 *
10546 * Return: None
10547 */
10548static void hdd_register_debug_callback(void)
10549{
10550 qdf_register_debug_callback(QDF_MODULE_ID_HDD, &hdd_state_info_dump);
10551}
Wen Gongaa6d55d2018-04-26 16:33:21 +080010552#else /* WLAN_FEATURE_HDD_MEMDUMP_ENABLE */
10553static void hdd_register_debug_callback(void)
10554{
10555}
10556#endif /* WLAN_FEATURE_HDD_MEMDUMP_ENABLE */
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010557
SaidiReddy Yenuga699d90e2017-04-14 16:09:24 +053010558/*
10559 * wlan_init_bug_report_lock() - Initialize bug report lock
10560 *
10561 * This function is used to create bug report lock
10562 *
10563 * Return: None
10564 */
10565static void wlan_init_bug_report_lock(void)
10566{
10567 p_cds_contextType p_cds_context;
10568
10569 p_cds_context = cds_get_global_context();
10570 if (!p_cds_context) {
10571 hdd_err("cds context is NULL");
10572 return;
10573 }
10574
10575 qdf_spinlock_create(&p_cds_context->bug_report_lock);
10576}
10577
Mohit Khannaf8f96822017-05-17 17:11:59 -070010578void hdd_dp_trace_init(struct hdd_config *config)
10579{
10580
10581 bool live_mode = DP_TRACE_CONFIG_DEFAULT_LIVE_MODE;
10582 uint8_t thresh = DP_TRACE_CONFIG_DEFAULT_THRESH;
10583 uint16_t thresh_time_limit = DP_TRACE_CONFIG_DEFAULT_THRESH_TIME_LIMIT;
10584 uint8_t verbosity = DP_TRACE_CONFIG_DEFAULT_VERBOSTY;
10585 uint8_t proto_bitmap = DP_TRACE_CONFIG_DEFAULT_BITMAP;
10586 uint8_t config_params[DP_TRACE_CONFIG_NUM_PARAMS];
10587 uint8_t num_entries = 0;
Lin Baiaa7f8d72017-10-18 17:23:45 +080010588 uint32_t bw_compute_interval;
Mohit Khannaf8f96822017-05-17 17:11:59 -070010589
10590 hdd_string_to_u8_array(config->dp_trace_config, config_params,
10591 &num_entries, sizeof(config_params));
10592
10593 /* calculating, num bw timer intervals in a second (1000ms) */
Lin Baiaa7f8d72017-10-18 17:23:45 +080010594 bw_compute_interval = GET_BW_COMPUTE_INTV(config);
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010595 if (bw_compute_interval <= 1000 && bw_compute_interval > 0)
Lin Baiaa7f8d72017-10-18 17:23:45 +080010596 thresh_time_limit = 1000 / bw_compute_interval;
Jiachao Wu1b00ecb2017-07-05 19:13:41 +080010597 else if (bw_compute_interval > 1000) {
10598 hdd_err("busBandwidthComputeInterval > 1000, using 1000");
10599 thresh_time_limit = 1;
10600 } else
Mohit Khannaf8f96822017-05-17 17:11:59 -070010601 hdd_err("busBandwidthComputeInterval is 0, using defaults");
10602
10603 switch (num_entries) {
10604 case 4:
10605 proto_bitmap = config_params[3];
10606 case 3:
10607 verbosity = config_params[2];
10608 case 2:
10609 thresh = config_params[1];
10610 case 1:
10611 live_mode = config_params[0];
10612 default:
Rajeev Kumar3887f9b2018-01-10 11:24:01 -080010613 hdd_debug("live_mode %u thresh %u time_limit %u verbosity %u bitmap 0x%x",
Mohit Khannaf8f96822017-05-17 17:11:59 -070010614 live_mode, thresh, thresh_time_limit,
10615 verbosity, proto_bitmap);
10616 };
10617
10618 qdf_dp_trace_init(live_mode, thresh, thresh_time_limit,
10619 verbosity, proto_bitmap);
10620
10621}
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053010622/**
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010623 * hdd_wlan_startup() - HDD init function
10624 * @dev: Pointer to the underlying device
10625 *
10626 * This is the driver startup code executed once a WLAN device has been detected
10627 *
10628 * Return: 0 for success, < 0 for failure
10629 */
Arun Khandavallifae92942016-08-01 13:31:08 +053010630int hdd_wlan_startup(struct device *dev)
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010631{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010632 QDF_STATUS status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010633 struct hdd_context *hdd_ctx;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010634 int ret;
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010635 bool rtnl_held;
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010636
Dustin Brown491d54b2018-03-14 12:39:11 -070010637 hdd_enter();
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010638
Arun Khandavallifae92942016-08-01 13:31:08 +053010639 hdd_ctx = hdd_context_create(dev);
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010640
10641 if (IS_ERR(hdd_ctx))
10642 return PTR_ERR(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010643
Abhishek Singhe9068f12017-03-31 14:14:52 +053010644 ret = hdd_objmgr_create_and_store_psoc(hdd_ctx,
10645 DEFAULT_PSOC_ID);
10646 if (ret) {
10647 hdd_err("Psoc creation fails!");
10648 QDF_BUG(0);
10649 goto err_hdd_free_context;
10650 }
10651
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010652 qdf_nbuf_init_replenish_timer();
Ajit Pal Singh2c7aecd2017-05-19 15:09:23 +053010653#ifdef FEATURE_WLAN_CH_AVOID
10654 mutex_init(&hdd_ctx->avoid_freq_lock);
10655#endif
Arun Khandavallifae92942016-08-01 13:31:08 +053010656
Naveen Rawate02f8f52018-04-05 11:58:04 -070010657 osif_request_manager_init();
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010658 hdd_request_manager_init();
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053010659 qdf_atomic_init(&hdd_ctx->con_mode_flag);
Arun Khandavallifae92942016-08-01 13:31:08 +053010660
Dustin Brown021cecd2017-12-11 13:56:43 -080010661 hdd_driver_memdump_init();
10662
Jeff Johnson957bc272017-02-02 08:54:48 -080010663 ret = hdd_wlan_start_modules(hdd_ctx, NULL, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010664 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010665 hdd_err("Failed to start modules: %d", ret);
Dustin Brown021cecd2017-12-11 13:56:43 -080010666 goto err_memdump_deinit;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010667 }
10668
Yingying Tang80e15f32016-09-27 18:23:01 +080010669 wlan_hdd_update_wiphy(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010670
Anurag Chouhan6d760662016-02-20 16:05:43 +053010671 hdd_ctx->hHal = cds_get_context(QDF_MODULE_ID_SME);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010672
10673 if (NULL == hdd_ctx->hHal) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010674 hdd_err("HAL context is null");
Arun Khandavallifae92942016-08-01 13:31:08 +053010675 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010676 }
10677
Prashanth Bhatta07998752016-04-28 12:35:33 -070010678 ret = hdd_wiphy_init(hdd_ctx);
10679 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010680 hdd_err("Failed to initialize wiphy: %d", ret);
Arun Khandavallifae92942016-08-01 13:31:08 +053010681 goto err_stop_modules;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010682 }
10683
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010684 if (hdd_ctx->config->enable_dp_trace)
Mohit Khannaf8f96822017-05-17 17:11:59 -070010685 hdd_dp_trace_init(hdd_ctx->config);
Nirav Shahcc1f1ae2016-04-26 11:41:29 +053010686
Yuanyuan Liuc98370e2016-10-13 11:22:13 -070010687 hdd_initialize_mac_address(hdd_ctx);
Prashanth Bhatta75fa9a12016-01-11 18:30:08 -080010688
Paul Zhangfb02f452017-12-22 11:58:43 +080010689 ret = register_netdevice_notifier(&hdd_netdev_notifier);
10690 if (ret) {
10691 hdd_err("register_netdevice_notifier failed: %d", ret);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053010692 goto err_wiphy_unregister;
Paul Zhangfb02f452017-12-22 11:58:43 +080010693 }
Arun Khandavalli08479ba2017-08-07 19:56:23 +053010694
Arunk Khandavalli830c9692018-03-22 12:17:40 +053010695 ret = register_reboot_notifier(&system_reboot_notifier);
10696 if (ret) {
10697 hdd_err("Failed to register reboot notifier: %d", ret);
10698 goto err_unregister_netdev;
10699 }
10700
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010701 rtnl_held = hdd_hold_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010702
Jeff Johnson957bc272017-02-02 08:54:48 -080010703 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
10704 if (ret) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080010705 hdd_err("Failed to open interfaces: %d", ret);
Jeff Johnson46bde382017-02-01 15:31:16 -080010706 goto err_release_rtnl_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010707 }
10708
Prashanth Bhatta98f04d22016-01-08 16:46:21 -080010709 hdd_release_rtnl_lock();
10710 rtnl_held = false;
10711
Yingying Tang3ba3dbc2016-09-27 16:36:58 +080010712 wlan_hdd_update_11n_mode(hdd_ctx->config);
10713
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010714#ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
Anurag Chouhan210db072016-02-22 18:42:15 +053010715 status = qdf_mc_timer_init(&hdd_ctx->skip_acs_scan_timer,
Anurag Chouhan6d760662016-02-20 16:05:43 +053010716 QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010717 hdd_skip_acs_scan_timer_handler,
10718 (void *)hdd_ctx);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053010719 if (!QDF_IS_STATUS_SUCCESS(status))
Jeff Johnson34c88b72016-08-15 14:27:11 -070010720 hdd_err("Failed to init ACS Skip timer");
Liangwei Dongaef84342016-10-21 05:28:00 -040010721 qdf_spinlock_create(&hdd_ctx->acs_skip_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010722#endif
10723
Prashanth Bhattaab004382016-10-11 16:08:11 -070010724 hdd_bus_bandwidth_init(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010725
Jeff Johnson9afc5012016-09-23 13:56:27 -070010726 hdd_lpass_notify_start(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010727
Nirav Shahbd36b062016-07-18 11:12:59 +053010728 if (hdd_ctx->rps)
10729 hdd_set_rps_cpu_mask(hdd_ctx);
Peng Xu8fdaa492016-06-22 10:20:47 -070010730
Paul Zhangfb02f452017-12-22 11:58:43 +080010731 ret = hdd_register_notifiers(hdd_ctx);
10732 if (ret)
Jeff Johnson957bc272017-02-02 08:54:48 -080010733 goto err_close_adapters;
Prashanth Bhatta9b03ab32016-04-28 12:35:13 -070010734
Paul Zhangfb02f452017-12-22 11:58:43 +080010735 status = wlansap_global_init();
10736 if (QDF_IS_STATUS_ERROR(status)) {
10737 hdd_unregister_notifiers(hdd_ctx);
10738 goto err_close_adapters;
10739 }
10740
Arun Khandavallifae92942016-08-01 13:31:08 +053010741 if (hdd_ctx->config->fIsImpsEnabled)
10742 hdd_set_idle_ps_config(hdd_ctx, true);
Kiran Kumar Lokereb0f19c32017-10-13 12:23:26 -070010743 else
10744 hdd_set_idle_ps_config(hdd_ctx, false);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010745
Mukul Sharma07bd8752017-10-10 16:58:14 +053010746 if (QDF_GLOBAL_FTM_MODE != hdd_get_conparam()) {
Dustin Brown6f427922017-09-19 12:19:00 -070010747 qdf_sched_delayed_work(&hdd_ctx->iface_idle_work,
10748 hdd_ctx->config->iface_change_wait_time);
Mukul Sharma07bd8752017-10-10 16:58:14 +053010749 hdd_prevent_suspend_timeout(
10750 hdd_ctx->config->iface_change_wait_time,
10751 WIFI_POWER_EVENT_WAKELOCK_IFACE_CHANGE_TIMER);
10752 }
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053010753
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010754 goto success;
10755
Jeff Johnson957bc272017-02-02 08:54:48 -080010756err_close_adapters:
Jeff Johnson46bde382017-02-01 15:31:16 -080010757 hdd_close_all_adapters(hdd_ctx, rtnl_held);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010758
Jeff Johnson46bde382017-02-01 15:31:16 -080010759err_release_rtnl_lock:
Arunk Khandavalli830c9692018-03-22 12:17:40 +053010760 unregister_reboot_notifier(&system_reboot_notifier);
Arun Khandavallid4349a92016-07-25 11:10:43 +053010761 if (rtnl_held)
10762 hdd_release_rtnl_lock();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010763
Arunk Khandavalli830c9692018-03-22 12:17:40 +053010764err_unregister_netdev:
Poddar, Siddarthaee8ff62017-10-04 12:53:22 +053010765 unregister_netdevice_notifier(&hdd_netdev_notifier);
10766
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010767err_wiphy_unregister:
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010768 wiphy_unregister(hdd_ctx->wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010769
Arun Khandavallifae92942016-08-01 13:31:08 +053010770err_stop_modules:
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070010771 hdd_wlan_stop_modules(hdd_ctx, false);
Arun Khandavallifae92942016-08-01 13:31:08 +053010772
Dustin Brown021cecd2017-12-11 13:56:43 -080010773err_memdump_deinit:
10774 hdd_driver_memdump_deinit();
Dustin Brown021cecd2017-12-11 13:56:43 -080010775
Jeff Johnsonce0032c2017-01-20 07:18:27 -080010776 hdd_request_manager_deinit();
Naveen Rawate02f8f52018-04-05 11:58:04 -070010777 osif_request_manager_deinit();
Ryan Hsucfef0ae2016-04-28 10:20:46 -070010778 hdd_exit_netlink_services(hdd_ctx);
10779
Dustin Brown20912462017-06-07 13:48:25 -070010780 hdd_objmgr_release_and_destroy_psoc(hdd_ctx);
10781
Prashanth Bhattac2a16f62015-12-03 15:06:15 -080010782err_hdd_free_context:
Nachiket Kukade8003d252017-03-30 15:55:58 +053010783 if (cds_is_fw_down())
10784 hdd_err("Not setting the complete event as fw is down");
10785 else
10786 hdd_start_complete(ret);
10787
Sravan Kumar Kairam6b727a42017-08-29 15:39:58 +053010788 qdf_nbuf_deinit_replenish_timer();
Prashanth Bhatta527fd752016-04-28 12:35:23 -070010789 hdd_context_destroy(hdd_ctx);
Srinivas Girigowdabafb8b72017-10-11 17:52:32 -070010790 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010791
10792success:
Dustin Browne74003f2018-03-14 12:51:58 -070010793 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010794 return 0;
10795}
10796
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080010797/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010798 * hdd_wlan_update_target_info() - update target type info
10799 * @hdd_ctx: HDD context
10800 * @context: hif context
10801 *
10802 * Update target info received from firmware in hdd context
10803 * Return:None
10804 */
10805
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010806void hdd_wlan_update_target_info(struct hdd_context *hdd_ctx, void *context)
Arun Khandavallifae92942016-08-01 13:31:08 +053010807{
10808 struct hif_target_info *tgt_info = hif_get_target_info_handle(context);
10809
10810 if (!tgt_info) {
10811 hdd_err("Target info is Null");
10812 return;
10813 }
10814
10815 hdd_ctx->target_type = tgt_info->target_type;
10816}
10817
10818/**
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010819 * hdd_get_nud_stats_cb() - callback api to update the stats
10820 * received from the firmware
10821 * @data: pointer to adapter.
10822 * @rsp: pointer to data received from FW.
10823 *
10824 * This is called when wlan driver received response event for
10825 * get arp stats to firmware.
10826 *
10827 * Return: None
10828 */
10829static void hdd_get_nud_stats_cb(void *data, struct rsp_stats *rsp)
10830{
10831 struct hdd_context *hdd_ctx = (struct hdd_context *)data;
10832 struct hdd_nud_stats_context *context;
10833 int status;
10834 struct hdd_adapter *adapter = NULL;
10835
Dustin Brown491d54b2018-03-14 12:39:11 -070010836 hdd_enter();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010837
10838 if (!rsp) {
10839 hdd_err("data is null");
10840 return;
10841 }
10842
10843 status = wlan_hdd_validate_context(hdd_ctx);
10844 if (0 != status)
10845 return;
10846
10847 adapter = hdd_get_adapter_by_vdev(hdd_ctx, rsp->vdev_id);
10848 if ((NULL == adapter) || (WLAN_HDD_ADAPTER_MAGIC != adapter->magic)) {
10849 hdd_err("Invalid adapter or adapter has invalid magic");
10850 return;
10851 }
10852
Dustin Brown5e89ef82018-03-14 11:50:23 -070010853 hdd_info("rsp->arp_req_enqueue :%x", rsp->arp_req_enqueue);
10854 hdd_info("rsp->arp_req_tx_success :%x", rsp->arp_req_tx_success);
10855 hdd_info("rsp->arp_req_tx_failure :%x", rsp->arp_req_tx_failure);
10856 hdd_info("rsp->arp_rsp_recvd :%x", rsp->arp_rsp_recvd);
10857 hdd_info("rsp->out_of_order_arp_rsp_drop_cnt :%x",
10858 rsp->out_of_order_arp_rsp_drop_cnt);
10859 hdd_info("rsp->dad_detected :%x", rsp->dad_detected);
10860 hdd_info("rsp->connect_status :%x", rsp->connect_status);
10861 hdd_info("rsp->ba_session_establishment_status :%x",
10862 rsp->ba_session_establishment_status);
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010863
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010864 adapter->hdd_stats.hdd_arp_stats.rx_fw_cnt = rsp->arp_rsp_recvd;
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010865 adapter->dad |= rsp->dad_detected;
10866 adapter->con_status = rsp->connect_status;
10867
Poddar, Siddarth31797fa2018-01-22 17:24:15 +053010868 /* Flag true indicates connectivity check stats present. */
10869 if (rsp->connect_stats_present) {
10870 hdd_info("rsp->tcp_ack_recvd :%x", rsp->tcp_ack_recvd);
10871 hdd_info("rsp->icmpv4_rsp_recvd :%x", rsp->icmpv4_rsp_recvd);
10872 adapter->hdd_stats.hdd_tcp_stats.rx_fw_cnt = rsp->tcp_ack_recvd;
10873 adapter->hdd_stats.hdd_icmpv4_stats.rx_fw_cnt =
10874 rsp->icmpv4_rsp_recvd;
10875 }
10876
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010877 spin_lock(&hdd_context_lock);
10878 context = &hdd_ctx->nud_stats_context;
10879 complete(&context->response_event);
10880 spin_unlock(&hdd_context_lock);
10881
Dustin Browne74003f2018-03-14 12:51:58 -070010882 hdd_exit();
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010883}
10884
10885/**
Arun Khandavallifae92942016-08-01 13:31:08 +053010886 * hdd_register_cb - Register HDD callbacks.
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010887 * @hdd_ctx: HDD context
10888 *
10889 * Register the HDD callbacks to CDS/SME.
10890 *
10891 * Return: 0 for success or Error code for failure
10892 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010893int hdd_register_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010894{
10895 QDF_STATUS status;
10896 int ret = 0;
10897
Dustin Brown491d54b2018-03-14 12:39:11 -070010898 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010899
10900 sme_register11d_scan_done_callback(hdd_ctx->hHal, hdd_11d_scan_done);
10901
10902 sme_register_oem_data_rsp_callback(hdd_ctx->hHal,
10903 hdd_send_oem_data_rsp_msg);
10904
Deepthi Gowrid5a58fe2016-09-03 16:01:28 +053010905 sme_register_mgmt_frame_ind_callback(hdd_ctx->hHal,
10906 hdd_indicate_mgmt_frame);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010907 sme_set_tsfcb(hdd_ctx->hHal, hdd_get_tsf_cb, hdd_ctx);
10908 sme_nan_register_callback(hdd_ctx->hHal,
10909 wlan_hdd_cfg80211_nan_callback);
10910 sme_stats_ext_register_callback(hdd_ctx->hHal,
10911 wlan_hdd_cfg80211_stats_ext_callback);
10912
10913 sme_ext_scan_register_callback(hdd_ctx->hHal,
10914 wlan_hdd_cfg80211_extscan_callback);
lifeng66831662017-05-19 16:01:35 +080010915 sme_stats_ext2_register_callback(hdd_ctx->hHal,
10916 wlan_hdd_cfg80211_stats_ext2_callback);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010917
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010918 sme_set_rssi_threshold_breached_cb(hdd_ctx->hHal,
10919 hdd_rssi_threshold_breached);
10920
Anurag Chouhan3920c0f2017-09-11 17:10:56 +053010921 sme_set_nud_debug_stats_cb(hdd_ctx->hHal, hdd_get_nud_stats_cb);
10922
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010923 sme_set_link_layer_stats_ind_cb(hdd_ctx->hHal,
10924 wlan_hdd_cfg80211_link_layer_stats_callback);
10925
Sreelakshmi Konamki88a2a412017-04-14 15:11:55 +053010926 sme_rso_cmd_status_cb(hdd_ctx->hHal, wlan_hdd_rso_cmd_status_cb);
10927
Zhang Qianca38fb12016-12-23 11:10:48 +080010928 sme_set_link_layer_ext_cb(hdd_ctx->hHal,
10929 wlan_hdd_cfg80211_link_layer_stats_ext_callback);
10930
Sreelakshmi Konamki58c72432016-11-09 17:06:44 +053010931 status = sme_set_lost_link_info_cb(hdd_ctx->hHal,
10932 hdd_lost_link_info_cb);
10933 /* print error and not block the startup process */
10934 if (!QDF_IS_STATUS_SUCCESS(status))
10935 hdd_err("set lost link info callback failed");
10936
Poddar, Siddarth34872782017-08-10 14:08:51 +053010937 ret = hdd_register_data_stall_detect_cb();
10938 if (ret) {
10939 hdd_err("Register data stall detect detect callback failed.");
10940 return ret;
10941 }
10942
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010943 wlan_hdd_dcc_register_for_dcc_stats_event(hdd_ctx);
10944
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080010945 sme_register_set_connection_info_cb(hdd_ctx->hHal,
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080010946 hdd_set_connection_in_progress,
10947 hdd_is_connection_in_progress);
Padma, Santhosh Kumar16dacfb2017-03-21 19:05:40 +053010948
10949 status = sme_congestion_register_callback(hdd_ctx->hHal,
10950 hdd_update_cca_info_cb);
10951 if (!QDF_IS_STATUS_SUCCESS(status))
10952 hdd_err("set congestion callback failed");
10953
Vidyullatha Kanchanapallybe0ebb32017-03-23 14:36:21 +053010954 status = sme_set_bt_activity_info_cb(hdd_ctx->hHal,
10955 hdd_bt_activity_cb);
10956 if (!QDF_IS_STATUS_SUCCESS(status))
10957 hdd_err("set bt activity info callback failed");
10958
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080010959 status = sme_register_tx_queue_cb(hdd_ctx->hHal,
10960 hdd_tx_queue_cb);
10961 if (!QDF_IS_STATUS_SUCCESS(status))
10962 hdd_err("Register tx queue callback failed");
10963
Dustin Browne74003f2018-03-14 12:51:58 -070010964 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010965
10966 return ret;
10967}
10968
10969/**
10970 * hdd_deregister_cb() - De-Register HDD callbacks.
10971 * @hdd_ctx: HDD context
10972 *
10973 * De-Register the HDD callbacks to CDS/SME.
10974 *
10975 * Return: void
10976 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070010977void hdd_deregister_cb(struct hdd_context *hdd_ctx)
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010978{
10979 QDF_STATUS status;
Poddar, Siddarth34872782017-08-10 14:08:51 +053010980 int ret;
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010981
Dustin Brown491d54b2018-03-14 12:39:11 -070010982 hdd_enter();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010983
Varun Reddy Yeturu076eaa82018-01-16 12:16:14 -080010984 sme_deregister_tx_queue_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010985 status = sme_deregister_for_dcc_stats_event(hdd_ctx->hHal);
10986 if (!QDF_IS_STATUS_SUCCESS(status))
10987 hdd_err("De-register of dcc stats callback failed: %d",
10988 status);
10989
10990 sme_reset_link_layer_stats_ind_cb(hdd_ctx->hHal);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010991 sme_reset_rssi_threshold_breached_cb(hdd_ctx->hHal);
10992
Arun Khandavalli4b55da72016-07-19 19:55:01 +053010993 sme_stats_ext_register_callback(hdd_ctx->hHal,
10994 wlan_hdd_cfg80211_stats_ext_callback);
10995
10996 sme_nan_deregister_callback(hdd_ctx->hHal);
10997 status = sme_reset_tsfcb(hdd_ctx->hHal);
10998 if (!QDF_IS_STATUS_SUCCESS(status))
10999 hdd_err("Failed to de-register tsfcb the callback:%d",
11000 status);
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011001
Poddar, Siddarth34872782017-08-10 14:08:51 +053011002 ret = hdd_deregister_data_stall_detect_cb();
11003 if (ret)
11004 hdd_err("Failed to de-register data stall detect event callback");
11005
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011006 sme_deregister_oem_data_rsp_callback(hdd_ctx->hHal);
11007 sme_deregister11d_scan_done_callback(hdd_ctx->hHal);
11008
Dustin Browne74003f2018-03-14 12:51:58 -070011009 hdd_exit();
Arun Khandavalli4b55da72016-07-19 19:55:01 +053011010}
11011
11012/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011013 * hdd_softap_sta_deauth() - handle deauth req from HDD
11014 * @adapter: Pointer to the HDD
11015 * @enable: bool value
11016 *
11017 * This to take counter measure to handle deauth req from HDD
11018 *
11019 * Return: None
11020 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011021QDF_STATUS hdd_softap_sta_deauth(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011022 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011023{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011024 QDF_STATUS qdf_status = QDF_STATUS_E_FAULT;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011025
Dustin Brown491d54b2018-03-14 12:39:11 -070011026 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011027
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011028 /* Ignore request to deauth bcmc station */
11029 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011030 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011031
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011032 qdf_status =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011033 wlansap_deauth_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
11034 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011035
Dustin Browne74003f2018-03-14 12:51:58 -070011036 hdd_exit();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011037 return qdf_status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011038}
11039
11040/**
11041 * hdd_softap_sta_disassoc() - take counter measure to handle deauth req from HDD
11042 * @adapter: Pointer to the HDD
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011043 * @p_del_sta_params: pointer to station deletion parameters
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011044 *
11045 * This to take counter measure to handle deauth req from HDD
11046 *
11047 * Return: None
11048 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011049void hdd_softap_sta_disassoc(struct hdd_adapter *adapter,
Jeff Johnsone6bf7192017-11-07 15:16:09 -080011050 struct csr_del_sta_params *pDelStaParams)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011051{
Dustin Brown491d54b2018-03-14 12:39:11 -070011052 hdd_enter();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011053
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011054 /* Ignore request to disassoc bcmc station */
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011055 if (pDelStaParams->peerMacAddr.bytes[0] & 0x1)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011056 return;
11057
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011058 wlansap_disassoc_sta(WLAN_HDD_GET_SAP_CTX_PTR(adapter),
Deepthi Gowrib3bfefd2016-09-13 15:14:34 +053011059 pDelStaParams);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011060}
11061
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011062/**
11063 * hdd_issta_p2p_clientconnected() - check if sta or p2p client is connected
11064 * @hdd_ctx: HDD Context
11065 *
11066 * API to find if there is any STA or P2P-Client is connected
11067 *
11068 * Return: true if connected; false otherwise
11069 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011070QDF_STATUS hdd_issta_p2p_clientconnected(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011071{
11072 return sme_is_sta_p2p_client_connected(hdd_ctx->hHal);
11073}
11074
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011075/**
11076 * wlan_hdd_disable_roaming() - disable roaming on all STAs except the input one
11077 * @adapter: HDD adapter pointer
11078 *
11079 * This function loop through each adapter and disable roaming on each STA
11080 * device mode except the input adapter.
11081 *
11082 * Note: On the input adapter roaming is not enabled yet hence no need to
11083 * disable.
11084 *
11085 * Return: None
11086 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011087void wlan_hdd_disable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011088{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011089 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011090 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011091
11092 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011093 hdd_ctx->config->isRoamOffloadScanEnabled &&
11094 QDF_STA_MODE == adapter->device_mode &&
11095 policy_mgr_is_sta_active_connection_exists(
11096 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011097 hdd_debug("Connect received on STA session Id(%d)",
11098 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011099 /*
11100 * Loop through adapter and disable roaming for each STA device
11101 * mode except the input adapter.
11102 */
Dustin Brown920397d2017-12-13 16:27:50 -080011103 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011104 if (QDF_STA_MODE == adapterIdx->device_mode &&
11105 adapter->session_id != adapterIdx->session_id) {
11106 hdd_debug("Disable Roaming on session Id(%d)",
11107 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011108 sme_stop_roaming(WLAN_HDD_GET_HAL_CTX
11109 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070011110 adapterIdx->session_id, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011111 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011112 }
11113 }
11114}
11115
11116/**
11117 * wlan_hdd_enable_roaming() - enable roaming on all STAs except the input one
11118 * @adapter: HDD adapter pointer
11119 *
11120 * This function loop through each adapter and enable roaming on each STA
11121 * device mode except the input adapter.
11122 * Note: On the input adapter no need to enable roaming because link got
11123 * disconnected on this.
11124 *
11125 * Return: None
11126 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011127void wlan_hdd_enable_roaming(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011128{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011129 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011130 struct hdd_adapter *adapterIdx = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011131
11132 if (hdd_ctx->config->isFastRoamIniFeatureEnabled &&
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011133 hdd_ctx->config->isRoamOffloadScanEnabled &&
11134 QDF_STA_MODE == adapter->device_mode &&
11135 policy_mgr_is_sta_active_connection_exists(
11136 hdd_ctx->hdd_psoc)) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011137 hdd_debug("Disconnect received on STA session Id(%d)",
11138 adapter->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011139 /*
11140 * Loop through adapter and enable roaming for each STA device
11141 * mode except the input adapter.
11142 */
Dustin Brown920397d2017-12-13 16:27:50 -080011143 hdd_for_each_adapter(hdd_ctx, adapterIdx) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070011144 if (QDF_STA_MODE == adapterIdx->device_mode &&
11145 adapter->session_id != adapterIdx->session_id) {
11146 hdd_debug("Enabling Roaming on session Id(%d)",
11147 adapterIdx->session_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011148 sme_start_roaming(WLAN_HDD_GET_HAL_CTX
11149 (adapterIdx),
Jeff Johnson1b780e42017-10-31 14:11:45 -070011150 adapterIdx->session_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011151 REASON_CONNECT);
11152 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011153 }
11154 }
11155}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011156
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011157/**
11158 * nl_srv_bcast_svc() - Wrapper function to send bcast msgs to SVC mcast group
11159 * @skb: sk buffer pointer
11160 *
11161 * Sends the bcast message to SVC multicast group with generic nl socket
11162 * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
11163 *
11164 * Return: None
11165 */
11166static void nl_srv_bcast_svc(struct sk_buff *skb)
11167{
11168#ifdef CNSS_GENL
11169 nl_srv_bcast(skb, CLD80211_MCGRP_SVC_MSGS, WLAN_NL_MSG_SVC);
11170#else
11171 nl_srv_bcast(skb);
11172#endif
11173}
11174
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011175void wlan_hdd_send_svc_nlink_msg(int radio, int type, void *data, int len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011176{
11177 struct sk_buff *skb;
11178 struct nlmsghdr *nlh;
11179 tAniMsgHdr *ani_hdr;
11180 void *nl_data = NULL;
11181 int flags = GFP_KERNEL;
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011182 struct radio_index_tlv *radio_info;
11183 int tlv_len;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011184
11185 if (in_interrupt() || irqs_disabled() || in_atomic())
11186 flags = GFP_ATOMIC;
11187
11188 skb = alloc_skb(NLMSG_SPACE(WLAN_NL_MAX_PAYLOAD), flags);
11189
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011190 if (skb == NULL)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011191 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011192
11193 nlh = (struct nlmsghdr *)skb->data;
11194 nlh->nlmsg_pid = 0; /* from kernel */
11195 nlh->nlmsg_flags = 0;
11196 nlh->nlmsg_seq = 0;
11197 nlh->nlmsg_type = WLAN_NL_MSG_SVC;
11198
11199 ani_hdr = NLMSG_DATA(nlh);
11200 ani_hdr->type = type;
11201
11202 switch (type) {
11203 case WLAN_SVC_FW_CRASHED_IND:
Komal Seelam78ff65a2016-08-18 15:25:24 +053011204 case WLAN_SVC_FW_SHUTDOWN_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011205 case WLAN_SVC_LTE_COEX_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011206 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND:
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011207 case WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011208 ani_hdr->length = 0;
11209 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011210 break;
11211 case WLAN_SVC_WLAN_STATUS_IND:
11212 case WLAN_SVC_WLAN_VERSION_IND:
11213 case WLAN_SVC_DFS_CAC_START_IND:
11214 case WLAN_SVC_DFS_CAC_END_IND:
11215 case WLAN_SVC_DFS_RADAR_DETECT_IND:
11216 case WLAN_SVC_DFS_ALL_CHANNEL_UNAVAIL_IND:
11217 case WLAN_SVC_WLAN_TP_IND:
Mohit Khannae71e2262015-11-10 09:37:24 -080011218 case WLAN_SVC_WLAN_TP_TX_IND:
Nirav Shahbd36b062016-07-18 11:12:59 +053011219 case WLAN_SVC_RPS_ENABLE_IND:
Orhan K AKYILDIZe7445a22017-01-19 21:21:47 -080011220 case WLAN_SVC_CORE_MINFREQ:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011221 ani_hdr->length = len;
11222 nlh->nlmsg_len = NLMSG_LENGTH((sizeof(tAniMsgHdr) + len));
11223 nl_data = (char *)ani_hdr + sizeof(tAniMsgHdr);
11224 memcpy(nl_data, data, len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011225 break;
11226
11227 default:
Jeff Johnson34c88b72016-08-15 14:27:11 -070011228 hdd_err("WLAN SVC: Attempt to send unknown nlink message %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011229 type);
11230 kfree_skb(skb);
11231 return;
11232 }
11233
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011234 /*
Jeff Johnson0d52c7a2017-01-12 08:46:55 -080011235 * Add radio index at the end of the svc event in TLV format
11236 * to maintain the backward compatibility with userspace
11237 * applications.
11238 */
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011239
11240 tlv_len = 0;
11241
11242 if ((sizeof(*ani_hdr) + len + sizeof(struct radio_index_tlv))
11243 < WLAN_NL_MAX_PAYLOAD) {
11244 radio_info = (struct radio_index_tlv *)((char *) ani_hdr +
11245 sizeof(*ani_hdr) + len);
11246 radio_info->type = (unsigned short) WLAN_SVC_WLAN_RADIO_INDEX;
11247 radio_info->length = (unsigned short) sizeof(radio_info->radio);
11248 radio_info->radio = radio;
11249 tlv_len = sizeof(*radio_info);
Dustin Browna2868622018-03-20 11:38:14 -070011250 hdd_debug("Added radio index tlv - radio index %d",
11251 radio_info->radio);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011252 }
11253
11254 nlh->nlmsg_len += tlv_len;
11255 skb_put(skb, NLMSG_SPACE(sizeof(tAniMsgHdr) + len + tlv_len));
11256
Selvaraj, Sridhar046d77d2017-03-07 14:53:13 +053011257 nl_srv_bcast_svc(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011258}
11259
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011260#ifdef FEATURE_WLAN_AUTO_SHUTDOWN
11261void wlan_hdd_auto_shutdown_cb(void)
11262{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011263 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011264
11265 if (!hdd_ctx)
11266 return;
11267
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011268 hdd_debug("Wlan Idle. Sending Shutdown event..");
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011269 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
11270 WLAN_SVC_WLAN_AUTO_SHUTDOWN_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011271}
11272
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011273void wlan_hdd_auto_shutdown_enable(struct hdd_context *hdd_ctx, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011274{
Jeff Johnson9d295242017-08-29 14:39:48 -070011275 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011276 bool ap_connected = false, sta_connected = false;
11277 tHalHandle hal_handle;
11278
11279 hal_handle = hdd_ctx->hHal;
11280 if (hal_handle == NULL)
11281 return;
11282
11283 if (hdd_ctx->config->WlanAutoShutdown == 0)
11284 return;
11285
11286 if (enable == false) {
11287 if (sme_set_auto_shutdown_timer(hal_handle, 0) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011288 QDF_STATUS_SUCCESS) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011289 hdd_err("Failed to stop wlan auto shutdown timer");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011290 }
Kondabattini, Ganesh96ac37b2016-09-02 23:12:15 +053011291 wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index,
Manikandan Mohan5b1980a2016-05-06 12:41:18 -070011292 WLAN_SVC_WLAN_AUTO_SHUTDOWN_CANCEL_IND, NULL, 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011293 return;
11294 }
11295
11296 /* To enable shutdown timer check conncurrency */
Dustin Brown920397d2017-12-13 16:27:50 -080011297 if (policy_mgr_concurrent_open_sessions_running(hdd_ctx->hdd_psoc)) {
11298 hdd_for_each_adapter(hdd_ctx, adapter) {
11299 if (adapter->device_mode == QDF_STA_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011300 if (WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11301 conn_info.connState ==
11302 eConnectionState_Associated) {
11303 sta_connected = true;
11304 break;
11305 }
11306 }
Dustin Brown920397d2017-12-13 16:27:50 -080011307
11308 if (adapter->device_mode == QDF_SAP_MODE) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011309 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->
Jeff Johnson136c51b2017-10-27 20:02:41 -070011310 ap_active == true) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011311 ap_connected = true;
11312 break;
11313 }
11314 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011315 }
11316 }
11317
11318 if (ap_connected == true || sta_connected == true) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011319 hdd_debug("CC Session active. Shutdown timer not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011320 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011321 }
Jeff Johnson68755312017-02-10 11:46:55 -080011322
11323 if (sme_set_auto_shutdown_timer(hal_handle,
11324 hdd_ctx->config->WlanAutoShutdown)
11325 != QDF_STATUS_SUCCESS)
11326 hdd_err("Failed to start wlan auto shutdown timer");
11327 else
Dustin Brown5e89ef82018-03-14 11:50:23 -070011328 hdd_info("Auto Shutdown timer for %d seconds enabled",
11329 hdd_ctx->config->WlanAutoShutdown);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011330}
11331#endif
11332
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011333struct hdd_adapter *
11334hdd_get_con_sap_adapter(struct hdd_adapter *this_sap_adapter,
11335 bool check_start_bss)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011336{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011337 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(this_sap_adapter);
Jeff Johnson9d295242017-08-29 14:39:48 -070011338 struct hdd_adapter *adapter, *con_sap_adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011339
11340 con_sap_adapter = NULL;
11341
Dustin Brown920397d2017-12-13 16:27:50 -080011342 hdd_for_each_adapter(hdd_ctx, adapter) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011343 if (adapter && ((adapter->device_mode == QDF_SAP_MODE) ||
11344 (adapter->device_mode == QDF_P2P_GO_MODE)) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011345 adapter != this_sap_adapter) {
11346 if (check_start_bss) {
11347 if (test_bit(SOFTAP_BSS_STARTED,
11348 &adapter->event_flags)) {
11349 con_sap_adapter = adapter;
11350 break;
11351 }
11352 } else {
11353 con_sap_adapter = adapter;
11354 break;
11355 }
11356 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011357 }
11358
11359 return con_sap_adapter;
11360}
11361
11362#ifdef MSM_PLATFORM
Jeff Johnson9d295242017-08-29 14:39:48 -070011363static inline bool hdd_adapter_is_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011364{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011365 return adapter->device_mode == QDF_STA_MODE ||
11366 adapter->device_mode == QDF_P2P_CLIENT_MODE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011367}
11368
Jeff Johnson9d295242017-08-29 14:39:48 -070011369static inline bool hdd_adapter_is_ap(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011370{
Dustin Brown5ec6b552017-03-31 12:11:40 -070011371 return adapter->device_mode == QDF_SAP_MODE ||
11372 adapter->device_mode == QDF_P2P_GO_MODE;
11373}
11374
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011375static bool hdd_any_adapter_is_assoc(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011376{
Dustin Brown920397d2017-12-13 16:27:50 -080011377 struct hdd_adapter *adapter;
Dustin Brown5ec6b552017-03-31 12:11:40 -070011378
Dustin Brown920397d2017-12-13 16:27:50 -080011379 hdd_for_each_adapter(hdd_ctx, adapter) {
11380 if (hdd_adapter_is_sta(adapter) &&
Dustin Brown5ec6b552017-03-31 12:11:40 -070011381 WLAN_HDD_GET_STATION_CTX_PTR(adapter)->
11382 conn_info.connState == eConnectionState_Associated) {
11383 return true;
11384 }
11385
Dustin Brown920397d2017-12-13 16:27:50 -080011386 if (hdd_adapter_is_ap(adapter) &&
Jeff Johnson136c51b2017-10-27 20:02:41 -070011387 WLAN_HDD_GET_AP_CTX_PTR(adapter)->ap_active) {
Dustin Brown5ec6b552017-03-31 12:11:40 -070011388 return true;
11389 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011390 }
11391
11392 return false;
11393}
11394
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011395static bool hdd_bus_bw_compute_timer_is_running(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011396{
11397 bool is_running;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011398
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011399 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011400 is_running = hdd_ctx->bus_bw_timer_running;
Poddar, Siddarth57f4d3f2017-01-27 12:58:37 +053011401 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011402
Dustin Brown5ec6b552017-03-31 12:11:40 -070011403 return is_running;
11404}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011405
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011406static void __hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011407{
11408 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11409 hdd_ctx->bus_bw_timer_running = true;
11410 qdf_timer_start(&hdd_ctx->bus_bw_timer,
11411 hdd_ctx->config->busBandwidthComputeInterval);
11412 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11413}
11414
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011415void hdd_bus_bw_compute_timer_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011416{
Dustin Brown491d54b2018-03-14 12:39:11 -070011417 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011418
11419 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11420 hdd_debug("Bandwidth compute timer already started");
11421 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011422 }
11423
Dustin Brown5ec6b552017-03-31 12:11:40 -070011424 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11425
Dustin Browne74003f2018-03-14 12:51:58 -070011426 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011427}
11428
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011429void hdd_bus_bw_compute_timer_try_start(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011430{
Dustin Brown491d54b2018-03-14 12:39:11 -070011431 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011432
11433 if (hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11434 hdd_debug("Bandwidth compute timer already started");
11435 return;
Ravi Joshib89e7f72016-09-07 13:43:15 -070011436 }
Dustin Brown5ec6b552017-03-31 12:11:40 -070011437
11438 if (hdd_any_adapter_is_assoc(hdd_ctx))
11439 __hdd_bus_bw_compute_timer_start(hdd_ctx);
11440
Dustin Browne74003f2018-03-14 12:51:58 -070011441 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011442}
11443
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011444static void __hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011445{
Sravan Kumar Kairam9e99e9a2018-03-12 19:09:45 +053011446 ucfg_ipa_set_perf_level(hdd_ctx->hdd_pdev, 0, 0);
Dustin Brown5ec6b552017-03-31 12:11:40 -070011447
11448 qdf_spinlock_acquire(&hdd_ctx->bus_bw_timer_lock);
11449 qdf_timer_stop(&hdd_ctx->bus_bw_timer);
11450 hdd_ctx->bus_bw_timer_running = false;
11451 qdf_spinlock_release(&hdd_ctx->bus_bw_timer_lock);
11452
11453 hdd_reset_tcp_delack(hdd_ctx);
11454}
11455
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011456void hdd_bus_bw_compute_timer_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011457{
Dustin Brown491d54b2018-03-14 12:39:11 -070011458 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011459
11460 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11461 hdd_debug("Bandwidth compute timer already stopped");
11462 return;
11463 }
11464
11465 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11466
Dustin Browne74003f2018-03-14 12:51:58 -070011467 hdd_exit();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011468}
11469
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011470void hdd_bus_bw_compute_timer_try_stop(struct hdd_context *hdd_ctx)
Dustin Brown5ec6b552017-03-31 12:11:40 -070011471{
Dustin Brown491d54b2018-03-14 12:39:11 -070011472 hdd_enter();
Dustin Brown5ec6b552017-03-31 12:11:40 -070011473
11474 if (!hdd_bus_bw_compute_timer_is_running(hdd_ctx)) {
11475 hdd_debug("Bandwidth compute timer already stopped");
11476 return;
11477 }
11478
11479 if (!hdd_any_adapter_is_assoc(hdd_ctx))
11480 __hdd_bus_bw_compute_timer_stop(hdd_ctx);
11481
Dustin Browne74003f2018-03-14 12:51:58 -070011482 hdd_exit();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011483}
11484#endif
11485
11486/**
11487 * wlan_hdd_check_custom_con_channel_rules() - This function checks the sap's
11488 * and sta's operating channel.
11489 * @sta_adapter: Describe the first argument to foobar.
11490 * @ap_adapter: Describe the second argument to foobar.
11491 * @roam_profile: Roam profile of AP to which STA wants to connect.
11492 * @concurrent_chnl_same: If both SAP and STA channels are same then
11493 * set this flag to true else false.
11494 *
11495 * This function checks the sap's operating channel and sta's operating channel.
11496 * if both are same then it will return false else it will restart the sap in
11497 * sta's channel and return true.
11498 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011499 * Return: QDF_STATUS_SUCCESS or QDF_STATUS_E_FAILURE.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011500 */
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011501QDF_STATUS
11502wlan_hdd_check_custom_con_channel_rules(struct hdd_adapter *sta_adapter,
11503 struct hdd_adapter *ap_adapter,
Jeff Johnson61b5e982018-03-15 11:33:31 -070011504 struct csr_roam_profile *roam_profile,
Jeff Johnson6dff3ee2017-10-06 14:58:57 -070011505 tScanResultHandle *scan_cache,
11506 bool *concurrent_chnl_same)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011507{
Jeff Johnson87251032017-08-29 13:31:11 -070011508 struct hdd_ap_ctx *hdd_ap_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011509 uint8_t channel_id;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011510 QDF_STATUS status;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080011511 enum QDF_OPMODE device_mode = ap_adapter->device_mode;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011512 *concurrent_chnl_same = true;
11513
11514 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11515 status =
Archana Ramachandran2eb7a612017-03-23 22:58:42 -070011516 sme_get_ap_channel_from_scan_cache(roam_profile,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011517 scan_cache,
11518 &channel_id);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011519 if (QDF_STATUS_SUCCESS == status) {
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011520 if ((QDF_SAP_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011521 (channel_id < SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011522 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011523 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011524 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011525 }
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011526 } else if ((QDF_P2P_GO_MODE == device_mode) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011527 (channel_id >= SIR_11A_CHANNEL_BEGIN)) {
Jeff Johnson01206862017-10-27 20:55:59 -070011528 if (hdd_ap_ctx->operating_channel != channel_id) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011529 *concurrent_chnl_same = false;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011530 hdd_debug("channels are different");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011531 }
11532 }
11533 } else {
11534 /*
11535 * Lets handle worst case scenario here, Scan cache lookup is
11536 * failed so we have to stop the SAP to avoid any channel
11537 * discrepancy between SAP's channel and STA's channel.
11538 * Return the status as failure so caller function could know
11539 * that scan look up is failed.
11540 */
Jeff Johnson28f8a772016-08-15 15:30:36 -070011541 hdd_err("Finding AP from scan cache failed");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011542 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011543 }
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011544 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011545}
11546
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011547/**
11548 * wlan_hdd_stop_sap() - This function stops bss of SAP.
11549 * @ap_adapter: SAP adapter
11550 *
11551 * This function will process the stopping of sap adapter.
11552 *
11553 * Return: None
11554 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011555void wlan_hdd_stop_sap(struct hdd_adapter *ap_adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011556{
Jeff Johnson87251032017-08-29 13:31:11 -070011557 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011558 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011559 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011560 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011561
11562 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011563 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011564 return;
11565 }
11566
11567 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11568 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011569 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011570 return;
Abhishek Singh23edd1c2016-05-05 11:56:06 +053011571
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011572 mutex_lock(&hdd_ctx->sap_lock);
11573 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
Ryan Hsu8ecb0fa2016-01-18 15:40:55 -080011574 wlan_hdd_del_station(ap_adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011575 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011576 hdd_debug("Now doing SAP STOPBSS");
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053011577 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011578 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(hdd_ap_ctx->
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011579 sap_context)) {
Nachiket Kukade0396b732017-11-14 16:35:16 +053011580 qdf_status = qdf_wait_for_event_completion(&hostapd_state->
Naveen Rawatb56880c2016-12-13 17:56:03 -080011581 qdf_stop_bss_event,
11582 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011583 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011584 mutex_unlock(&hdd_ctx->sap_lock);
Jeff Johnson28f8a772016-08-15 15:30:36 -070011585 hdd_err("SAP Stop Failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011586 return;
11587 }
11588 }
11589 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011590 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
11591 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011592 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070011593 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011594 false);
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011595 hdd_debug("SAP Stop Success");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011596 } else {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011597 hdd_err("Can't stop ap because its not started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011598 }
11599 mutex_unlock(&hdd_ctx->sap_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011600}
11601
11602/**
11603 * wlan_hdd_start_sap() - this function starts bss of SAP.
11604 * @ap_adapter: SAP adapter
11605 *
11606 * This function will process the starting of sap adapter.
11607 *
11608 * Return: None
11609 */
Jeff Johnson9d295242017-08-29 14:39:48 -070011610void wlan_hdd_start_sap(struct hdd_adapter *ap_adapter, bool reinit)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011611{
Jeff Johnson87251032017-08-29 13:31:11 -070011612 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070011613 struct hdd_hostapd_state *hostapd_state;
Anurag Chouhance0dc992016-02-16 18:18:03 +053011614 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011615 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011616 tsap_Config_t *sap_config;
11617
11618 if (NULL == ap_adapter) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011619 hdd_err("ap_adapter is NULL here");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011620 return;
11621 }
11622
Krunal Soni9b04c9b2016-03-10 13:08:05 -080011623 if (QDF_SAP_MODE != ap_adapter->device_mode) {
Peng Xuf5d60c82015-10-02 17:17:03 -070011624 hdd_err("SoftAp role has not been enabled");
11625 return;
11626 }
11627
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011628 hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
11629 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
11630 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
Jeff Johnsonb9424862017-10-30 08:49:35 -070011631 sap_config = &ap_adapter->session.ap.sap_config;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011632
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011633 mutex_lock(&hdd_ctx->sap_lock);
11634 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags))
11635 goto end;
11636
11637 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011638 hdd_err("SAP Not able to set AP IEs");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011639 goto end;
11640 }
11641
Wei Song2f76f642016-11-18 16:32:53 +080011642 qdf_event_reset(&hostapd_state->qdf_event);
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070011643 if (wlansap_start_bss(hdd_ap_ctx->sap_context, hdd_hostapd_sap_event_cb,
Jeff Johnson91df29d2017-10-27 19:29:50 -070011644 &hdd_ap_ctx->sap_config,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011645 ap_adapter->dev)
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053011646 != QDF_STATUS_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011647 goto end;
11648
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011649 hdd_debug("Waiting for SAP to start");
Nachiket Kukade0396b732017-11-14 16:35:16 +053011650 qdf_status = qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Naveen Rawatb56880c2016-12-13 17:56:03 -080011651 SME_CMD_TIMEOUT_VALUE);
Anurag Chouhance0dc992016-02-16 18:18:03 +053011652 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson28f8a772016-08-15 15:30:36 -070011653 hdd_err("SAP Start failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011654 goto end;
11655 }
Jeff Johnson28f8a772016-08-15 15:30:36 -070011656 hdd_info("SAP Start Success");
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011657 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011658 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011659 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080011660 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
11661 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070011662 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070011663 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053011664 true);
11665 }
Sourav Mohapatra9bc67112017-11-08 09:36:11 +053011666 mutex_unlock(&hdd_ctx->sap_lock);
11667
11668 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011669end:
Vignesh Viswanathan85b455e2018-01-17 19:54:33 +053011670 wlansap_reset_sap_config_add_ie(sap_config, eUPDATE_IE_ALL);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011671 mutex_unlock(&hdd_ctx->sap_lock);
Manikandan Mohan3dad1a42017-06-14 10:50:18 -070011672 /* SAP context and beacon cleanup will happen during driver unload
11673 * in hdd_stop_adapter
11674 */
11675 hdd_err("SAP restart after SSR failed! Reload WLAN and try SAP again");
11676
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011677}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011678
11679/**
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011680 * wlan_hdd_soc_set_antenna_mode_cb() - Callback for set dual
11681 * mac scan config
11682 * @status: Status of set antenna mode
11683 *
11684 * Callback on setting the dual mac configuration
11685 *
11686 * Return: None
11687 */
11688void wlan_hdd_soc_set_antenna_mode_cb(
11689 enum set_antenna_mode_status status)
11690{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011691 struct hdd_context *hdd_ctx;
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011692
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080011693 hdd_debug("Status: %d", status);
Archana Ramachandrana20ef812015-11-13 16:12:13 -080011694
11695 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
11696 if (0 != wlan_hdd_validate_context(hdd_ctx))
11697 return;
11698
11699 /* Signal the completion of set dual mac config */
11700 complete(&hdd_ctx->set_antenna_mode_cmpl);
11701}
11702
11703/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011704 * hdd_get_fw_version() - Get FW version
11705 * @hdd_ctx: pointer to HDD context.
11706 * @major_spid: FW version - major spid.
11707 * @minor_spid: FW version - minor spid
11708 * @ssid: FW version - ssid
11709 * @crmid: FW version - crmid
11710 *
11711 * This function is called to get the firmware build version stored
11712 * as part of the HDD context
11713 *
11714 * Return: None
11715 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070011716void hdd_get_fw_version(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011717 uint32_t *major_spid, uint32_t *minor_spid,
11718 uint32_t *siid, uint32_t *crmid)
11719{
11720 *major_spid = (hdd_ctx->target_fw_version & 0xf0000000) >> 28;
11721 *minor_spid = (hdd_ctx->target_fw_version & 0xf000000) >> 24;
11722 *siid = (hdd_ctx->target_fw_version & 0xf00000) >> 20;
11723 *crmid = hdd_ctx->target_fw_version & 0x7fff;
11724}
11725
11726#ifdef QCA_CONFIG_SMP
11727/**
11728 * wlan_hdd_get_cpu() - get cpu_index
11729 *
11730 * Return: cpu_index
11731 */
11732int wlan_hdd_get_cpu(void)
11733{
11734 int cpu_index = get_cpu();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070011735
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080011736 put_cpu();
11737 return cpu_index;
11738}
11739#endif
11740
11741/**
11742 * hdd_get_fwpath() - get framework path
11743 *
11744 * This function is used to get the string written by
11745 * userspace to start the wlan driver
11746 *
11747 * Return: string
11748 */
11749const char *hdd_get_fwpath(void)
11750{
11751 return fwpath.string;
11752}
11753
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011754static int hdd_qdf_print_init(void)
11755{
11756 int qdf_print_idx;
11757 QDF_STATUS status;
11758
11759 status = qdf_print_setup();
11760 if (status != QDF_STATUS_SUCCESS) {
11761 pr_err("qdf_print_setup failed\n");
11762 return -EINVAL;
11763 }
11764
11765 qdf_print_idx = qdf_print_ctrl_register(cinfo, NULL, NULL, "MCL_WLAN");
11766
11767 if (qdf_print_idx < 0) {
11768 pr_err("qdf_print_ctrl_register failed, ret = %d\n",
11769 qdf_print_idx);
11770 return -EINVAL;
11771 }
11772
11773 qdf_set_pidx(qdf_print_idx);
11774
11775 return 0;
11776}
11777
11778static void hdd_qdf_print_deinit(void)
11779{
11780 int qdf_print_idx;
11781
11782 qdf_print_idx = qdf_get_pidx();
11783 qdf_print_ctrl_cleanup(qdf_print_idx);
11784}
11785
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011786/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011787 * hdd_init() - Initialize Driver
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011788 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011789 * This function initilizes CDS global context with the help of cds_init. This
11790 * has to be the first function called after probe to get a valid global
11791 * context.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011792 *
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011793 * Return: 0 for success, errno on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011794 */
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011795int hdd_init(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011796{
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011797 QDF_STATUS status;
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011798 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011799
Jeff Johnson7aaeeea2017-09-26 13:16:24 -070011800 status = cds_init();
wadesongae4ffd12017-10-24 16:45:54 +080011801 if (QDF_IS_STATUS_ERROR(status)) {
11802 hdd_err("Failed to allocate CDS context");
11803 ret = -ENOMEM;
11804 goto err_out;
11805 }
Hanumanth Reddy Pothula788a37e2017-08-17 18:40:11 +053011806
11807 wlan_init_bug_report_lock();
11808
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011809#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11810 wlan_logging_sock_init_svc();
11811#endif
11812
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011813 qdf_timer_init(NULL, &hdd_drv_ops_inactivity_timer,
11814 (void *)hdd_drv_ops_inactivity_handler, NULL,
11815 QDF_TIMER_TYPE_SW);
11816
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011817 hdd_trace_init();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011818 hdd_qdf_print_init();
11819
Padma, Santhosh Kumar9aba02f2016-08-11 16:30:25 +053011820 hdd_register_debug_callback();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011821
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011822err_out:
11823 return ret;
11824}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011825
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011826/**
11827 * hdd_deinit() - Deinitialize Driver
11828 *
11829 * This function frees CDS global context with the help of cds_deinit. This
11830 * has to be the last function call in remove callback to free the global
11831 * context.
11832 */
11833void hdd_deinit(void)
11834{
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053011835 qdf_timer_free(&hdd_drv_ops_inactivity_timer);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011836
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011837 wlan_destroy_bug_report_lock();
11838 cds_deinit();
Mahesh Kumar Kalikot Veetilb85cefd2017-08-14 14:03:32 -070011839
Rajeev Kumar2d0f2192017-10-18 19:48:21 -070011840 hdd_qdf_print_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011841#ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
11842 wlan_logging_sock_deinit_svc();
11843#endif
11844}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011845
Yue Ma6e7b1a02017-04-03 14:17:46 -070011846#ifdef QCA_WIFI_NAPIER_EMULATION
11847#define HDD_WLAN_START_WAIT_TIME ((CDS_WMA_TIMEOUT + 5000) * 100)
11848#else
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011849#define HDD_WLAN_START_WAIT_TIME (CDS_WMA_TIMEOUT + 5000)
Yue Ma6e7b1a02017-04-03 14:17:46 -070011850#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080011851
Sachin Ahujadddd2632017-03-07 19:07:24 +053011852static int wlan_hdd_state_ctrl_param_open(struct inode *inode,
11853 struct file *file)
11854{
11855 return 0;
11856}
11857
11858static ssize_t wlan_hdd_state_ctrl_param_write(struct file *filp,
11859 const char __user *user_buf,
11860 size_t count,
11861 loff_t *f_pos)
11862{
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011863 char buf[3];
Sachin Ahujadddd2632017-03-07 19:07:24 +053011864 static const char wlan_off_str[] = "OFF";
11865 static const char wlan_on_str[] = "ON";
11866 int ret;
11867 unsigned long rc;
11868
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011869 if (copy_from_user(buf, user_buf, 3)) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011870 pr_err("Failed to read buffer\n");
11871 return -EINVAL;
11872 }
11873
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011874 if (strncmp(buf, wlan_off_str, strlen(wlan_off_str)) == 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011875 pr_debug("Wifi turning off from UI\n");
11876 goto exit;
11877 }
11878
Sachin Ahuja16904db2017-12-13 19:56:57 +053011879 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) == 0) {
11880 pr_info("Wifi Turning On from UI\n");
11881 }
11882
SaidiReddy Yenugac356f152017-04-06 17:43:01 +053011883 if (strncmp(buf, wlan_on_str, strlen(wlan_on_str)) != 0) {
Sachin Ahujadddd2632017-03-07 19:07:24 +053011884 pr_err("Invalid value received from framework");
11885 goto exit;
11886 }
11887
11888 if (!cds_is_driver_loaded()) {
Sachin Ahujaee62b542017-04-21 14:14:16 +053011889 init_completion(&wlan_start_comp);
Sachin Ahujadddd2632017-03-07 19:07:24 +053011890 rc = wait_for_completion_timeout(&wlan_start_comp,
11891 msecs_to_jiffies(HDD_WLAN_START_WAIT_TIME));
11892 if (!rc) {
11893 hdd_alert("Timed-out waiting in wlan_hdd_state_ctrl_param_write");
11894 ret = -EINVAL;
Sachin Ahujadddd2632017-03-07 19:07:24 +053011895 return ret;
11896 }
11897
11898 hdd_start_complete(0);
11899 }
11900
11901exit:
11902 return count;
11903}
11904
11905
11906const struct file_operations wlan_hdd_state_fops = {
11907 .owner = THIS_MODULE,
11908 .open = wlan_hdd_state_ctrl_param_open,
11909 .write = wlan_hdd_state_ctrl_param_write,
11910};
11911
11912static int wlan_hdd_state_ctrl_param_create(void)
11913{
11914 unsigned int wlan_hdd_state_major = 0;
11915 int ret;
11916 struct device *dev;
11917
11918 device = MKDEV(wlan_hdd_state_major, 0);
11919
11920 ret = alloc_chrdev_region(&device, 0, dev_num, "qcwlanstate");
11921 if (ret) {
11922 pr_err("Failed to register qcwlanstate");
11923 goto dev_alloc_err;
11924 }
11925 wlan_hdd_state_major = MAJOR(device);
11926
11927 class = class_create(THIS_MODULE, WLAN_MODULE_NAME);
11928 if (IS_ERR(class)) {
11929 pr_err("wlan_hdd_state class_create error");
11930 goto class_err;
11931 }
11932
11933 dev = device_create(class, NULL, device, NULL, WLAN_MODULE_NAME);
11934 if (IS_ERR(dev)) {
11935 pr_err("wlan_hdd_statedevice_create error");
11936 goto err_class_destroy;
11937 }
11938
11939 cdev_init(&wlan_hdd_state_cdev, &wlan_hdd_state_fops);
11940 ret = cdev_add(&wlan_hdd_state_cdev, device, dev_num);
11941 if (ret) {
11942 pr_err("Failed to add cdev error");
11943 goto cdev_add_err;
11944 }
11945
11946 pr_info("wlan_hdd_state %s major(%d) initialized",
11947 WLAN_MODULE_NAME, wlan_hdd_state_major);
11948
11949 return 0;
11950
11951cdev_add_err:
11952 device_destroy(class, device);
11953err_class_destroy:
11954 class_destroy(class);
11955class_err:
11956 unregister_chrdev_region(device, dev_num);
11957dev_alloc_err:
11958 return -ENODEV;
11959}
11960
11961static void wlan_hdd_state_ctrl_param_destroy(void)
11962{
11963 cdev_del(&wlan_hdd_state_cdev);
11964 device_destroy(class, device);
11965 class_destroy(class);
11966 unregister_chrdev_region(device, dev_num);
11967
11968 pr_info("Device node unregistered");
11969}
11970
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080011971/**
Mukul Sharmad75a6672017-06-22 15:40:53 +053011972 * component_init - API to init cld component's
11973 *
11974 * Return: None
11975 */
11976static void component_init(void)
11977{
11978 pmo_init();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011979 disa_init();
Zhang Qian47e22ce2018-01-04 15:38:38 +080011980 ucfg_ocb_init();
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053011981 ipa_init();
Mukul Sharmad75a6672017-06-22 15:40:53 +053011982}
11983
11984/**
11985 * component_deinit - API to deinit cld component's
11986 *
11987 * Return: None
11988 */
11989static void component_deinit(void)
11990{
Sravan Kumar Kairam4af61cf2018-02-22 17:53:44 +053011991 ipa_deinit();
Zhang Qian47e22ce2018-01-04 15:38:38 +080011992 ucfg_ocb_deinit();
Mukul Sharmad75a6672017-06-22 15:40:53 +053011993 pmo_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011994 disa_deinit();
Nachiket Kukade98f562a2017-12-15 12:18:07 +053011995}
11996
11997void hdd_component_psoc_enable(struct wlan_objmgr_psoc *psoc)
11998{
Zhang Qian47e22ce2018-01-04 15:38:38 +080011999 ocb_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012000 disa_psoc_enable(psoc);
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012001}
12002
12003void hdd_component_psoc_disable(struct wlan_objmgr_psoc *psoc)
12004{
Nachiket Kukade98f562a2017-12-15 12:18:07 +053012005 disa_psoc_disable(psoc);
Zhang Qian47e22ce2018-01-04 15:38:38 +080012006 ocb_psoc_disable(psoc);
Mukul Sharmad75a6672017-06-22 15:40:53 +053012007}
12008
12009/**
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012010 * __hdd_module_init - Module init helper
12011 *
12012 * Module init helper function used by both module and static driver.
12013 *
12014 * Return: 0 for success, errno on failure
12015 */
12016static int __hdd_module_init(void)
12017{
12018 int ret = 0;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012019
Dustin Brown96cd9632017-11-13 12:45:04 -080012020 pr_err("%s: Loading driver v%s (%s)\n",
Dustin Brownab482ac2017-06-09 17:00:44 -070012021 WLAN_MODULE_NAME,
Dustin Brown96cd9632017-11-13 12:45:04 -080012022 g_wlan_driver_version,
Dustin Brownc1034df2018-02-07 14:51:32 -080012023 TIMER_MANAGER_STR MEMORY_DEBUG_STR PANIC_ON_BUG_STR);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012024
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012025 pld_init();
12026
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012027 ret = hdd_init();
12028 if (ret) {
12029 pr_err("hdd_init failed %x\n", ret);
12030 goto err_hdd_init;
12031 }
12032
Rajeev Kumar97767a02016-11-30 11:20:40 -080012033 dispatcher_init();
12034
Mukul Sharmad75a6672017-06-22 15:40:53 +053012035 /* Ensure to call post objmgr init */
12036 component_init();
12037
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012038 qdf_wake_lock_create(&wlan_wake_lock, "wlan");
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012039
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012040 hdd_set_conparam((uint32_t) con_mode);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012041
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012042 ret = wlan_hdd_register_driver();
12043 if (ret) {
Mohit Khannafa99aea2016-05-12 21:43:13 -070012044 pr_err("%s: driver load failure, err %d\n", WLAN_MODULE_NAME,
12045 ret);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012046 goto out;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012047 }
12048
Sachin Ahuja16904db2017-12-13 19:56:57 +053012049 ret = wlan_hdd_state_ctrl_param_create();
12050 if (ret) {
12051 pr_err("wlan_hdd_state_create:%x\n", ret);
12052 goto out;
12053 }
12054
Anurag Chouhanf04e84f2016-03-03 10:12:12 +053012055 pr_info("%s: driver loaded\n", WLAN_MODULE_NAME);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012056
12057 return 0;
12058out:
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012059 qdf_wake_lock_destroy(&wlan_wake_lock);
Liangwei Dong9fcc7212017-10-24 13:43:52 +080012060 component_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080012061 dispatcher_deinit();
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012062 hdd_deinit();
Rajeev Kumar97767a02016-11-30 11:20:40 -080012063
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012064err_hdd_init:
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012065 pld_deinit();
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012066 return ret;
12067}
12068
12069/**
12070 * __hdd_module_exit - Module exit helper
12071 *
12072 * Module exit helper function used by both module and static driver.
12073 */
12074static void __hdd_module_exit(void)
12075{
Will Huang36049722018-04-13 11:48:51 +080012076 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Ashish Kumar Dhanotiya7a031ce2017-01-23 13:11:30 +053012077
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012078 pr_info("%s: Unloading driver v%s\n", WLAN_MODULE_NAME,
12079 QWLAN_VERSIONSTR);
12080
Will Huang36049722018-04-13 11:48:51 +080012081 if (!hdd_ctx) {
12082 hdd_err("hdd context is NULL return!!");
12083 return;
12084 }
12085
Arunk Khandavalli830c9692018-03-22 12:17:40 +053012086 if (!hdd_wait_for_recovery_completion())
12087 return;
Arunk Khandavalli07ec8f62016-09-27 21:51:01 +053012088
Will Huang36049722018-04-13 11:48:51 +080012089 qdf_cancel_delayed_work(&hdd_ctx->iface_idle_work);
12090
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012091 wlan_hdd_unregister_driver();
12092
Anurag Chouhana37b5b72016-02-21 14:53:42 +053012093 qdf_wake_lock_destroy(&wlan_wake_lock);
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012094
Mukul Sharmad75a6672017-06-22 15:40:53 +053012095 /* Ensure to call prior to objmgr deinit */
12096 component_deinit();
12097
Rajeev Kumar97767a02016-11-30 11:20:40 -080012098 dispatcher_deinit();
Amar Singhal0928b192017-12-01 10:50:54 -080012099
12100 hdd_sysfs_destroy_version_interface();
12101
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012102 hdd_deinit();
Yuanyuan Liu1d8045c2016-04-06 16:40:49 -070012103 pld_deinit();
12104
Sachin Ahujadddd2632017-03-07 19:07:24 +053012105 wlan_hdd_state_ctrl_param_destroy();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012106}
12107
Arun Khandavallifae92942016-08-01 13:31:08 +053012108#ifndef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012109/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012110 * wlan_boot_cb() - Wlan boot callback
12111 * @kobj: object whose directory we're creating the link in.
12112 * @attr: attribute the user is interacting with
12113 * @buff: the buffer containing the user data
12114 * @count: number of bytes in the buffer
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012115 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012116 * This callback is invoked when the fs is ready to start the
12117 * wlan driver initialization.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012118 *
Arun Khandavallifae92942016-08-01 13:31:08 +053012119 * Return: 'count' on success or a negative error code in case of failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012120 */
Arun Khandavallifae92942016-08-01 13:31:08 +053012121static ssize_t wlan_boot_cb(struct kobject *kobj,
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012122 struct kobj_attribute *attr,
12123 const char *buf,
12124 size_t count)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012125{
Arun Khandavallifae92942016-08-01 13:31:08 +053012126
Arun Khandavallifae92942016-08-01 13:31:08 +053012127 if (wlan_loader->loaded_state) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012128 pr_err("%s: wlan driver already initialized\n", __func__);
12129 return -EALREADY;
Arun Khandavallifae92942016-08-01 13:31:08 +053012130 }
12131
Arun Khandavallifae92942016-08-01 13:31:08 +053012132 if (__hdd_module_init()) {
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012133 pr_err("%s: wlan driver initialization failed\n", __func__);
12134 return -EIO;
12135 }
12136
12137 wlan_loader->loaded_state = MODULE_INITIALIZED;
Arun Khandavallifae92942016-08-01 13:31:08 +053012138
12139 return count;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012140}
Arun Khandavallifae92942016-08-01 13:31:08 +053012141
12142/**
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012143 * hdd_sysfs_cleanup() - cleanup sysfs
12144 *
12145 * Return: None
12146 *
12147 */
12148static void hdd_sysfs_cleanup(void)
12149{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012150 /* remove from group */
12151 if (wlan_loader->boot_wlan_obj && wlan_loader->attr_group)
12152 sysfs_remove_group(wlan_loader->boot_wlan_obj,
12153 wlan_loader->attr_group);
12154
12155 /* unlink the object from parent */
12156 kobject_del(wlan_loader->boot_wlan_obj);
12157
12158 /* free the object */
12159 kobject_put(wlan_loader->boot_wlan_obj);
12160
12161 kfree(wlan_loader->attr_group);
12162 kfree(wlan_loader);
12163
12164 wlan_loader = NULL;
12165}
12166
12167/**
Arun Khandavallifae92942016-08-01 13:31:08 +053012168 * wlan_init_sysfs() - Creates the sysfs to be invoked when the fs is
12169 * ready
12170 *
12171 * This is creates the syfs entry boot_wlan. Which shall be invoked
12172 * when the filesystem is ready.
12173 *
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012174 * QDF API cannot be used here since this function is called even before
12175 * initializing WLAN driver.
12176 *
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012177 * Return: 0 for success, errno on failure
Arun Khandavallifae92942016-08-01 13:31:08 +053012178 */
12179static int wlan_init_sysfs(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012180{
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012181 int ret = -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012182
12183 wlan_loader = kzalloc(sizeof(*wlan_loader), GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012184 if (!wlan_loader)
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012185 return -ENOMEM;
Arun Khandavallifae92942016-08-01 13:31:08 +053012186
12187 wlan_loader->boot_wlan_obj = NULL;
12188 wlan_loader->attr_group = kzalloc(sizeof(*(wlan_loader->attr_group)),
12189 GFP_KERNEL);
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012190 if (!wlan_loader->attr_group)
Arun Khandavallifae92942016-08-01 13:31:08 +053012191 goto error_return;
Arun Khandavallifae92942016-08-01 13:31:08 +053012192
12193 wlan_loader->loaded_state = 0;
12194 wlan_loader->attr_group->attrs = attrs;
12195
12196 wlan_loader->boot_wlan_obj = kobject_create_and_add("boot_wlan",
12197 kernel_kobj);
12198 if (!wlan_loader->boot_wlan_obj) {
12199 pr_err("%s: sysfs create and add failed\n", __func__);
Arun Khandavallifae92942016-08-01 13:31:08 +053012200 goto error_return;
12201 }
12202
12203 ret = sysfs_create_group(wlan_loader->boot_wlan_obj,
12204 wlan_loader->attr_group);
12205 if (ret) {
12206 pr_err("%s: sysfs create group failed %d\n", __func__, ret);
12207 goto error_return;
12208 }
12209
12210 return 0;
12211
12212error_return:
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012213 hdd_sysfs_cleanup();
Arun Khandavallifae92942016-08-01 13:31:08 +053012214
12215 return ret;
12216}
12217
12218/**
12219 * wlan_deinit_sysfs() - Removes the sysfs created to initialize the wlan
12220 *
12221 * Return: 0 on success or errno on failure
12222 */
12223static int wlan_deinit_sysfs(void)
12224{
Arun Khandavallifae92942016-08-01 13:31:08 +053012225 if (!wlan_loader) {
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012226 hdd_err("wlan loader context is Null!");
Arun Khandavallifae92942016-08-01 13:31:08 +053012227 return -EINVAL;
12228 }
12229
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012230 hdd_sysfs_cleanup();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012231 return 0;
12232}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012233
Mahesh Kumar Kalikot Veetil5a3dec62016-11-02 12:46:40 -070012234#endif /* MODULE */
Arun Khandavallifae92942016-08-01 13:31:08 +053012235
12236#ifdef MODULE
12237/**
12238 * __hdd_module_init - Module init helper
12239 *
12240 * Module init helper function used by both module and static driver.
12241 *
12242 * Return: 0 for success, errno on failure
12243 */
12244static int hdd_module_init(void)
12245{
Arun Khandavallifae92942016-08-01 13:31:08 +053012246 if (__hdd_module_init()) {
12247 pr_err("%s: Failed to register handler\n", __func__);
Dustin Brownab482ac2017-06-09 17:00:44 -070012248 return -EINVAL;
Arun Khandavallifae92942016-08-01 13:31:08 +053012249 }
12250
Dustin Brownab482ac2017-06-09 17:00:44 -070012251 return 0;
Arun Khandavallifae92942016-08-01 13:31:08 +053012252}
12253#else
12254static int __init hdd_module_init(void)
12255{
12256 int ret = -EINVAL;
12257
12258 ret = wlan_init_sysfs();
Srinivas Girigowda5e7dafe2016-11-02 14:09:13 -070012259 if (ret)
Arun Khandavallifae92942016-08-01 13:31:08 +053012260 pr_err("Failed to create sysfs entry for loading wlan");
12261
12262 return ret;
12263}
12264#endif
12265
12266
12267#ifdef MODULE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012268/**
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012269 * hdd_module_exit() - Exit function
12270 *
12271 * This is the driver exit point (invoked when module is unloaded using rmmod)
12272 *
12273 * Return: None
12274 */
12275static void __exit hdd_module_exit(void)
12276{
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012277 __hdd_module_exit();
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012278}
Arun Khandavallifae92942016-08-01 13:31:08 +053012279#else
12280static void __exit hdd_module_exit(void)
12281{
12282 __hdd_module_exit();
12283 wlan_deinit_sysfs();
12284}
12285#endif
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012286
Srinivas Girigowda841da292018-02-21 16:33:00 -080012287static int fwpath_changed_handler(const char *kmessage,
12288 const struct kernel_param *kp)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012289{
12290 return param_set_copystring(kmessage, kp);
12291}
Prashanth Bhatta5da711e2015-11-30 14:28:52 -080012292
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012293/**
12294 * is_con_mode_valid() check con mode is valid or not
12295 * @mode: global con mode
12296 *
12297 * Return: TRUE on success FALSE on failure
12298 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012299static bool is_con_mode_valid(enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012300{
12301 switch (mode) {
12302 case QDF_GLOBAL_MONITOR_MODE:
12303 case QDF_GLOBAL_FTM_MODE:
12304 case QDF_GLOBAL_EPPING_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012305 case QDF_GLOBAL_MISSION_MODE:
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012306 return true;
12307 default:
12308 return false;
12309 }
12310}
12311
12312/**
12313 * hdd_get_adpter_mode() - returns adapter mode based on global con mode
12314 * @mode: global con mode
12315 *
12316 * Return: adapter mode
12317 */
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012318static enum QDF_OPMODE hdd_get_adpter_mode(
Jeff Johnson876c1a62017-12-12 10:43:07 -080012319 enum QDF_GLOBAL_MODE mode)
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012320{
12321
12322 switch (mode) {
12323 case QDF_GLOBAL_MISSION_MODE:
12324 return QDF_STA_MODE;
12325 case QDF_GLOBAL_MONITOR_MODE:
12326 return QDF_MONITOR_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012327 case QDF_GLOBAL_EPPING_MODE:
12328 return QDF_EPPING_MODE;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012329 case QDF_GLOBAL_FTM_MODE:
12330 return QDF_FTM_MODE;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012331 case QDF_GLOBAL_QVIT_MODE:
12332 return QDF_QVIT_MODE;
12333 default:
12334 return QDF_MAX_NO_OF_MODE;
12335 }
12336}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012337
Dustin Brown27cd9942017-09-27 16:11:44 -070012338static void hdd_stop_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012339 enum QDF_GLOBAL_MODE curr_mode)
Dustin Brown27cd9942017-09-27 16:11:44 -070012340{
12341 if (hdd_ctx->driver_status == DRIVER_MODULES_CLOSED)
12342 return;
12343
12344 switch (curr_mode) {
Dustin Brown27cd9942017-09-27 16:11:44 -070012345 case QDF_GLOBAL_MONITOR_MODE:
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012346 hdd_info("Release wakelock for monitor mode!");
12347 qdf_wake_lock_release(&hdd_ctx->monitor_mode_wakelock,
12348 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
Dundi Raviteja0a2a65b2018-04-30 12:34:11 +053012349 /* fallthrough */
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012350 case QDF_GLOBAL_MISSION_MODE:
Dustin Brown27cd9942017-09-27 16:11:44 -070012351 case QDF_GLOBAL_FTM_MODE:
12352 hdd_abort_mac_scan_all_adapters(hdd_ctx);
Sourav Mohapatra001cfaf2018-02-28 11:30:46 +053012353 wlan_cfg80211_cleanup_scan_queue(hdd_ctx->hdd_pdev, NULL);
Dustin Browndb2a8be2017-12-20 11:49:56 -080012354 hdd_stop_all_adapters(hdd_ctx);
Dustin Brown27cd9942017-09-27 16:11:44 -070012355
Dustin Brown27cd9942017-09-27 16:11:44 -070012356 break;
12357 default:
12358 break;
12359 }
12360}
12361
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012362static void hdd_cleanup_present_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012363 enum QDF_GLOBAL_MODE curr_mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012364{
Ashish Kumar Dhanotiya00243132017-01-24 16:37:34 +053012365 int driver_status;
12366
12367 driver_status = hdd_ctx->driver_status;
12368
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012369 switch (curr_mode) {
12370 case QDF_GLOBAL_MISSION_MODE:
12371 case QDF_GLOBAL_MONITOR_MODE:
12372 case QDF_GLOBAL_FTM_MODE:
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012373 hdd_deinit_all_adapters(hdd_ctx, false);
12374 hdd_close_all_adapters(hdd_ctx, false);
12375 break;
12376 case QDF_GLOBAL_EPPING_MODE:
12377 epping_disable();
12378 epping_close();
12379 break;
12380 default:
12381 return;
12382 }
12383}
12384
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012385static int hdd_register_req_mode(struct hdd_context *hdd_ctx,
Jeff Johnson876c1a62017-12-12 10:43:07 -080012386 enum QDF_GLOBAL_MODE mode)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012387{
Jeff Johnson9d295242017-08-29 14:39:48 -070012388 struct hdd_adapter *adapter;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012389 int ret = 0;
12390 bool rtnl_held;
12391 qdf_device_t qdf_dev = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
12392 QDF_STATUS status;
12393
12394 if (!qdf_dev) {
12395 hdd_err("qdf device context is Null return!");
12396 return -EINVAL;
12397 }
12398
12399 rtnl_held = hdd_hold_rtnl_lock();
12400 switch (mode) {
12401 case QDF_GLOBAL_MISSION_MODE:
Jeff Johnson957bc272017-02-02 08:54:48 -080012402 ret = hdd_open_interfaces(hdd_ctx, rtnl_held);
12403 if (ret)
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012404 hdd_err("Failed to open interfaces: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012405 break;
12406 case QDF_GLOBAL_FTM_MODE:
12407 adapter = hdd_open_adapter(hdd_ctx, QDF_FTM_MODE, "wlan%d",
12408 wlan_hdd_get_intf_addr(hdd_ctx),
12409 NET_NAME_UNKNOWN, rtnl_held);
12410 if (adapter == NULL)
12411 ret = -EINVAL;
12412 break;
12413 case QDF_GLOBAL_MONITOR_MODE:
12414 adapter = hdd_open_adapter(hdd_ctx, QDF_MONITOR_MODE, "wlan%d",
12415 wlan_hdd_get_intf_addr(hdd_ctx),
12416 NET_NAME_UNKNOWN, rtnl_held);
12417 if (adapter == NULL)
12418 ret = -EINVAL;
12419 break;
12420 case QDF_GLOBAL_EPPING_MODE:
12421 status = epping_open();
Srinivas Girigowdab841da72017-03-25 18:04:39 -070012422 if (status != QDF_STATUS_SUCCESS) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012423 hdd_err("Failed to open in eeping mode: %d", status);
12424 ret = -EINVAL;
12425 break;
12426 }
12427 ret = epping_enable(qdf_dev->dev);
12428 if (ret) {
12429 hdd_err("Failed to enable in epping mode : %d", ret);
12430 epping_close();
12431 }
12432 break;
12433 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080012434 hdd_err("Mode not supported");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012435 ret = -ENOTSUPP;
12436 break;
12437 }
12438 hdd_release_rtnl_lock();
12439 rtnl_held = false;
12440 return ret;
12441}
12442
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012443/**
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012444 * __con_mode_handler() - Handles module param con_mode change
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012445 * @kmessage: con mode name on which driver to be bring up
12446 * @kp: The associated kernel parameter
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012447 * @hdd_ctx: Pointer to the global HDD context
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012448 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012449 * This function is invoked when user updates con mode using sys entry,
12450 * to initialize and bring-up driver in that specific mode.
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012451 *
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012452 * Return - 0 on success and failure code on failure
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012453 */
Srinivas Girigowda841da292018-02-21 16:33:00 -080012454static int __con_mode_handler(const char *kmessage,
12455 const struct kernel_param *kp,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012456 struct hdd_context *hdd_ctx)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012457{
12458 int ret;
Jeff Johnson9d295242017-08-29 14:39:48 -070012459 struct hdd_adapter *adapter;
Jeff Johnson876c1a62017-12-12 10:43:07 -080012460 enum QDF_GLOBAL_MODE curr_mode;
Jeff Johnsonc1e62782017-11-09 09:50:17 -080012461 enum QDF_OPMODE adapter_mode;
Dustin Brown20024e32018-01-03 12:34:58 -080012462 int new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012463
Dustin Brownab6029b2017-05-24 13:04:19 -070012464 hdd_info("con_mode handler: %s", kmessage);
12465
Arunk Khandavalli2dc0c962016-10-20 12:37:26 +053012466 ret = wlan_hdd_validate_context(hdd_ctx);
12467 if (ret)
12468 return ret;
12469
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012470 qdf_atomic_set(&hdd_ctx->con_mode_flag, 1);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012471 cds_set_load_in_progress(true);
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012472
Dustin Brown20024e32018-01-03 12:34:58 -080012473 ret = kstrtoint(kmessage, 0, &new_con_mode);
12474 if (ret) {
12475 hdd_err("Failed to parse con_mode '%s'", kmessage);
12476 goto reset_flags;
12477 }
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012478 mutex_lock(&hdd_init_deinit_lock);
Arun Khandavallifae92942016-08-01 13:31:08 +053012479
Dustin Brown20024e32018-01-03 12:34:58 -080012480 if (!is_con_mode_valid(new_con_mode)) {
12481 hdd_err("invalid con_mode %d", new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012482 ret = -EINVAL;
12483 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012484 }
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012485
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012486 curr_mode = hdd_get_conparam();
Dustin Brown20024e32018-01-03 12:34:58 -080012487 if (curr_mode == new_con_mode) {
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012488 hdd_err("curr mode: %d is same as user triggered mode %d",
Dustin Brown20024e32018-01-03 12:34:58 -080012489 curr_mode, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012490 ret = 0;
12491 goto reset_flags;
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012492 }
12493
Dustin Brown27cd9942017-09-27 16:11:44 -070012494 /* ensure adapters are stopped */
12495 hdd_stop_present_mode(hdd_ctx, curr_mode);
12496
Frank Liu6666f832018-01-04 10:06:05 +080012497 /* Cleanup present mode before switching to new mode */
12498 hdd_cleanup_present_mode(hdd_ctx, curr_mode);
12499
Rajeev Kumar3fef4e82017-03-31 20:25:23 -070012500 ret = hdd_wlan_stop_modules(hdd_ctx, true);
Arun Khandavallifae92942016-08-01 13:31:08 +053012501 if (ret) {
12502 hdd_err("Stop wlan modules failed");
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012503 goto reset_flags;
12504 }
12505
Ashish Kumar Dhanotiyacda57662017-08-14 14:45:25 +053012506
Dustin Brown20024e32018-01-03 12:34:58 -080012507 hdd_set_conparam(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012508
Frank Liu6666f832018-01-04 10:06:05 +080012509 /*
12510 * Set ACTIVE domain before adapters created, otherwise check domain
12511 * match will fail when cleanup adapters.
12512 */
12513 hdd_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012514 /* Register for new con_mode & then kick_start modules again */
Dustin Brown20024e32018-01-03 12:34:58 -080012515 ret = hdd_register_req_mode(hdd_ctx, new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012516 if (ret) {
12517 hdd_err("Failed to register for new mode");
12518 goto reset_flags;
12519 }
12520
Dustin Brown20024e32018-01-03 12:34:58 -080012521 adapter_mode = hdd_get_adpter_mode(new_con_mode);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012522 if (adapter_mode == QDF_MAX_NO_OF_MODE) {
12523 hdd_err("invalid adapter");
12524 ret = -EINVAL;
12525 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012526 }
12527
Hanumanth Reddy Pothula7d51b1d2016-09-21 19:11:20 +053012528 adapter = hdd_get_adapter(hdd_ctx, adapter_mode);
Arun Khandavallifae92942016-08-01 13:31:08 +053012529 if (!adapter) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012530 hdd_err("Failed to get adapter:%d", adapter_mode);
12531 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012532 }
12533
12534 ret = hdd_wlan_start_modules(hdd_ctx, adapter, false);
12535 if (ret) {
12536 hdd_err("Start wlan modules failed: %d", ret);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012537 goto reset_flags;
Arun Khandavallifae92942016-08-01 13:31:08 +053012538 }
12539
Dustin Brown20024e32018-01-03 12:34:58 -080012540 if (new_con_mode == QDF_GLOBAL_MONITOR_MODE) {
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012541 if (hdd_start_adapter(adapter)) {
12542 hdd_err("Failed to start %s adapter", kmessage);
12543 ret = -EINVAL;
12544 goto reset_flags;
12545 }
Arun Khandavallifae92942016-08-01 13:31:08 +053012546
Arunk Khandavalliebd1e372017-11-06 15:00:24 +053012547 hdd_info("Acquire wakelock for monitor mode!");
12548 qdf_wake_lock_acquire(&hdd_ctx->monitor_mode_wakelock,
12549 WIFI_POWER_EVENT_WAKELOCK_MONITOR_MODE);
12550 }
12551
Dustin Brown20024e32018-01-03 12:34:58 -080012552 /* con_mode is a global module parameter */
12553 con_mode = new_con_mode;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012554 hdd_info("Mode successfully changed to %s", kmessage);
12555 ret = 0;
12556
12557reset_flags:
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012558 mutex_unlock(&hdd_init_deinit_lock);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012559 cds_set_load_in_progress(false);
Sourav Mohapatra421d42b2017-12-29 16:33:23 +053012560 qdf_atomic_set(&hdd_ctx->con_mode_flag, 0);
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012561 return ret;
12562}
12563
12564
Srinivas Girigowda841da292018-02-21 16:33:00 -080012565static int con_mode_handler(const char *kmessage, const struct kernel_param *kp)
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012566{
12567 int ret;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012568 struct hdd_context *hdd_ctx;
Arun Khandavalli16fd1ee2016-10-08 17:47:07 +053012569
12570 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
12571 ret = wlan_hdd_validate_context(hdd_ctx);
12572 if (ret)
12573 return ret;
12574
12575 cds_ssr_protect(__func__);
12576 ret = __con_mode_handler(kmessage, kp, hdd_ctx);
12577 cds_ssr_unprotect(__func__);
12578
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012579 return ret;
12580}
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012581
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012582static int con_mode_handler_ftm(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080012583 const struct kernel_param *kp)
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053012584{
12585 int ret;
12586
12587 ret = param_set_int(kmessage, kp);
12588
12589 if (con_mode_ftm != QDF_GLOBAL_FTM_MODE) {
12590 pr_err("Only FTM mode supported!");
12591 return -ENOTSUPP;
12592 }
12593
12594 hdd_set_conparam(con_mode_ftm);
12595 con_mode = con_mode_ftm;
12596
12597 return ret;
12598}
12599
Ravi Joshia307f632017-07-17 23:41:41 -070012600static int con_mode_handler_monitor(const char *kmessage,
Srinivas Girigowda841da292018-02-21 16:33:00 -080012601 const struct kernel_param *kp)
Ravi Joshia307f632017-07-17 23:41:41 -070012602{
12603 int ret;
12604
12605 ret = param_set_int(kmessage, kp);
12606
12607 if (con_mode_monitor != QDF_GLOBAL_MONITOR_MODE) {
12608 pr_err("Only Monitor mode supported!");
12609 return -ENOTSUPP;
12610 }
12611
12612 hdd_set_conparam(con_mode_monitor);
12613 con_mode = con_mode_monitor;
12614
12615 return ret;
12616}
12617
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012618/**
12619 * hdd_get_conparam() - driver exit point
12620 *
12621 * This is the driver exit point (invoked when module is unloaded using rmmod)
12622 *
Jeff Johnson876c1a62017-12-12 10:43:07 -080012623 * Return: enum QDF_GLOBAL_MODE
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012624 */
Jeff Johnson876c1a62017-12-12 10:43:07 -080012625enum QDF_GLOBAL_MODE hdd_get_conparam(void)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012626{
Jeff Johnson876c1a62017-12-12 10:43:07 -080012627 return (enum QDF_GLOBAL_MODE) curr_con_mode;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012628}
12629
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012630void hdd_set_conparam(uint32_t con_param)
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012631{
Prashanth Bhatta05aaf012015-12-10 17:34:24 -080012632 curr_con_mode = con_param;
Prashanth Bhattaedd6ca22015-12-10 17:21:29 -080012633}
12634
Komal Seelamc11bb222016-01-27 18:57:10 +053012635/**
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012636 * hdd_clean_up_pre_cac_interface() - Clean up the pre cac interface
12637 * @hdd_ctx: HDD context
12638 *
12639 * Cleans up the pre cac interface, if it exists
12640 *
12641 * Return: None
12642 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012643void hdd_clean_up_pre_cac_interface(struct hdd_context *hdd_ctx)
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012644{
12645 uint8_t session_id;
12646 QDF_STATUS status;
Jeff Johnson85b5c112017-08-11 15:15:23 -070012647 struct hdd_adapter *precac_adapter;
Manishekar Chandrasekaran9e8c7be2016-08-03 14:57:14 +053012648
12649 status = wlan_sap_get_pre_cac_vdev_id(hdd_ctx->hHal, &session_id);
12650 if (QDF_IS_STATUS_ERROR(status)) {
12651 hdd_err("failed to get pre cac vdev id");
12652 return;
12653 }
12654
12655 precac_adapter = hdd_get_adapter_by_vdev(hdd_ctx, session_id);
12656 if (!precac_adapter) {
12657 hdd_err("invalid pre cac adapater");
12658 return;
12659 }
12660
12661 qdf_create_work(0, &hdd_ctx->sap_pre_cac_work,
12662 wlan_hdd_sap_pre_cac_failure,
12663 (void *)precac_adapter);
12664 qdf_sched_work(0, &hdd_ctx->sap_pre_cac_work);
12665
12666}
12667
12668/**
Komal Seelamec702b02016-02-24 18:42:16 +053012669 * hdd_update_ol_config - API to update ol configuration parameters
12670 * @hdd_ctx: HDD context
Komal Seelamc11bb222016-01-27 18:57:10 +053012671 *
Komal Seelamc11bb222016-01-27 18:57:10 +053012672 * Return: void
12673 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012674static void hdd_update_ol_config(struct hdd_context *hdd_ctx)
Komal Seelamc11bb222016-01-27 18:57:10 +053012675{
Komal Seelamec702b02016-02-24 18:42:16 +053012676 struct ol_config_info cfg;
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012677 struct ol_context *ol_ctx = cds_get_context(QDF_MODULE_ID_BMI);
Komal Seelamc11bb222016-01-27 18:57:10 +053012678
Komal Seelamec702b02016-02-24 18:42:16 +053012679 if (!ol_ctx)
12680 return;
12681
12682 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
12683 cfg.enable_uart_print = hdd_ctx->config->enablefwprint;
12684 cfg.enable_fw_log = hdd_ctx->config->enable_fw_log;
12685 cfg.enable_ramdump_collection = hdd_ctx->config->is_ramdump_enabled;
Jeff Johnsonb8bf9072016-09-23 17:39:27 -070012686 cfg.enable_lpass_support = hdd_lpass_is_supported(hdd_ctx);
Komal Seelamec702b02016-02-24 18:42:16 +053012687
12688 ol_init_ini_config(ol_ctx, &cfg);
12689}
12690
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012691#ifdef FEATURE_RUNTIME_PM
12692/**
12693 * hdd_populate_runtime_cfg() - populate runtime configuration
12694 * @hdd_ctx: hdd context
12695 * @cfg: pointer to the configuration memory being populated
12696 *
12697 * Return: void
12698 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012699static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012700 struct hif_config_info *cfg)
12701{
12702 cfg->enable_runtime_pm = hdd_ctx->config->runtime_pm;
12703 cfg->runtime_pm_delay = hdd_ctx->config->runtime_pm_delay;
12704}
12705#else
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012706static void hdd_populate_runtime_cfg(struct hdd_context *hdd_ctx,
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012707 struct hif_config_info *cfg)
12708{
12709}
12710#endif
12711
Komal Seelamec702b02016-02-24 18:42:16 +053012712/**
12713 * hdd_update_hif_config - API to update HIF configuration parameters
12714 * @hdd_ctx: HDD Context
12715 *
12716 * Return: void
12717 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012718static void hdd_update_hif_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012719{
Anurag Chouhandf2b2682016-02-29 14:15:27 +053012720 struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
Komal Seelamec702b02016-02-24 18:42:16 +053012721 struct hif_config_info cfg;
12722
12723 if (!scn)
12724 return;
12725
12726 cfg.enable_self_recovery = hdd_ctx->config->enableSelfRecovery;
Houston Hoffmanc7c69f02016-03-24 22:45:52 -070012727 hdd_populate_runtime_cfg(hdd_ctx, &cfg);
Komal Seelamec702b02016-02-24 18:42:16 +053012728 hif_init_ini_config(scn, &cfg);
Dustin Brownee3e0592017-09-07 13:50:11 -070012729
12730 if (hdd_ctx->config->prevent_link_down)
12731 hif_vote_link_up(scn);
Komal Seelamec702b02016-02-24 18:42:16 +053012732}
12733
12734/**
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012735 * hdd_update_dp_config() - Propagate config parameters to Lithium
12736 * datapath
12737 * @hdd_ctx: HDD Context
12738 *
12739 * Return: 0 for success/errno for failure
12740 */
12741static int hdd_update_dp_config(struct hdd_context *hdd_ctx)
12742{
12743 struct cdp_config_params params;
12744 QDF_STATUS status;
12745
12746 params.tso_enable = hdd_ctx->config->tso_enable;
12747 params.lro_enable = hdd_ctx->config->lro_enable;
12748#ifdef QCA_LL_TX_FLOW_CONTROL_V2
12749 params.tx_flow_stop_queue_threshold =
12750 hdd_ctx->config->TxFlowStopQueueThreshold;
12751 params.tx_flow_start_queue_offset =
12752 hdd_ctx->config->TxFlowStartQueueOffset;
12753#endif
12754 params.flow_steering_enable = hdd_ctx->config->flow_steering_enable;
12755 params.napi_enable = hdd_ctx->napi_enable;
12756 params.tcp_udp_checksumoffload =
12757 hdd_ctx->config->enable_ip_tcp_udp_checksum_offload;
12758
12759 status = cdp_update_config_parameters(
12760 cds_get_context(QDF_MODULE_ID_SOC),
12761 &params);
12762 if (status) {
Dustin Browna2868622018-03-20 11:38:14 -070012763 hdd_err("Failed to attach config parameters");
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070012764 return status;
12765 }
12766
12767 return 0;
12768}
12769
12770/**
Komal Seelamec702b02016-02-24 18:42:16 +053012771 * hdd_update_config() - Initialize driver per module ini parameters
12772 * @hdd_ctx: HDD Context
12773 *
12774 * API is used to initialize all driver per module configuration parameters
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012775 * Return: 0 for success, errno for failure
Komal Seelamec702b02016-02-24 18:42:16 +053012776 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012777int hdd_update_config(struct hdd_context *hdd_ctx)
Komal Seelamec702b02016-02-24 18:42:16 +053012778{
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012779 int ret;
12780
Komal Seelamec702b02016-02-24 18:42:16 +053012781 hdd_update_ol_config(hdd_ctx);
12782 hdd_update_hif_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012783 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
12784 ret = hdd_update_cds_config_ftm(hdd_ctx);
12785 else
12786 ret = hdd_update_cds_config(hdd_ctx);
Tushnim Bhattacharyya329514d2017-02-07 09:14:25 -080012787 ret = hdd_update_user_config(hdd_ctx);
Arun Khandavallic811dcc2016-06-26 07:37:21 +053012788
12789 return ret;
Komal Seelamc11bb222016-01-27 18:57:10 +053012790}
12791
Mukul Sharma9d797a02017-01-05 20:26:03 +053012792#ifdef FEATURE_WLAN_RA_FILTERING
12793/**
12794 * hdd_ra_populate_cds_config() - Populate RA filtering cds configuration
12795 * @psoc_cfg: pmo psoc Configuration
12796 * @hdd_ctx: Pointer to hdd context
12797 *
12798 * Return: none
12799 */
12800static inline void hdd_ra_populate_pmo_config(
12801 struct pmo_psoc_cfg *psoc_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012802 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012803{
12804 psoc_cfg->ra_ratelimit_interval =
12805 hdd_ctx->config->RArateLimitInterval;
12806 psoc_cfg->ra_ratelimit_enable =
12807 hdd_ctx->config->IsRArateLimitEnabled;
12808}
12809#else
12810static inline void hdd_ra_populate_pmo_config(
12811 struct cds_config_info *cds_cfg,
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012812 struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012813{
12814}
12815#endif
Will Huang3cd2b7c2017-11-17 13:16:56 +080012816
Mukul Sharma9d797a02017-01-05 20:26:03 +053012817/**
12818 * hdd_update_pmo_config - API to update pmo configuration parameters
12819 * @hdd_ctx: HDD context
12820 *
12821 * Return: void
12822 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070012823static int hdd_update_pmo_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053012824{
Mukul Sharma9d797a02017-01-05 20:26:03 +053012825 struct pmo_psoc_cfg psoc_cfg;
12826 QDF_STATUS status;
12827
12828 /*
12829 * Value of hdd_ctx->wowEnable can be,
12830 * 0 - Disable both magic pattern match and pattern byte match.
12831 * 1 - Enable magic pattern match on all interfaces.
12832 * 2 - Enable pattern byte match on all interfaces.
12833 * 3 - Enable both magic patter and pattern byte match on
12834 * all interfaces.
12835 */
12836 psoc_cfg.magic_ptrn_enable =
12837 (hdd_ctx->config->wowEnable & 0x01) ? true : false;
12838 psoc_cfg.ptrn_match_enable_all_vdev =
12839 (hdd_ctx->config->wowEnable & 0x02) ? true : false;
Dustin Brownb9987af2018-03-01 17:15:11 -080012840 psoc_cfg.ptrn_id_per_vdev =
12841 wma_is_service_enabled(wmi_service_unified_wow_capability);
12842 psoc_cfg.apf_enable = hdd_ctx->config->bpf_packet_filter_enable;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012843 psoc_cfg.arp_offload_enable = hdd_ctx->config->fhostArpOffload;
Dustin Brown1224e212017-05-12 14:02:12 -070012844 psoc_cfg.hw_filter_mode = hdd_ctx->config->hw_filter_mode;
Dustin Brownb9987af2018-03-01 17:15:11 -080012845 psoc_cfg.ns_offload_enable_dynamic = hdd_ctx->config->fhostNSOffload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012846 psoc_cfg.ns_offload_enable_static = hdd_ctx->config->fhostNSOffload;
Dustin Brownb9987af2018-03-01 17:15:11 -080012847 psoc_cfg.packet_filter_enabled = !hdd_ctx->config->disablePacketFilter;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012848 psoc_cfg.ssdp = hdd_ctx->config->ssdp;
12849 psoc_cfg.enable_mc_list = hdd_ctx->config->fEnableMCAddrList;
Dustin Brownb9987af2018-03-01 17:15:11 -080012850 psoc_cfg.active_mode_offload = hdd_ctx->config->active_mode_offload;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012851 psoc_cfg.ap_arpns_support = hdd_ctx->ap_arpns_support;
Will Huang3cd2b7c2017-11-17 13:16:56 +080012852 psoc_cfg.d0_wow_supported = wma_d0_wow_is_supported();
Mukul Sharma9223f232017-03-08 18:42:27 +053012853 psoc_cfg.sta_dynamic_dtim = hdd_ctx->config->enableDynamicDTIM;
12854 psoc_cfg.sta_mod_dtim = hdd_ctx->config->enableModulatedDTIM;
12855 psoc_cfg.sta_max_li_mod_dtim = hdd_ctx->config->fMaxLIModulatedDTIM;
Dustin Brownb9987af2018-03-01 17:15:11 -080012856 psoc_cfg.power_save_mode = hdd_ctx->config->enablePowersaveOffload;
Ravi Kumar Bokka05c14e52017-03-27 14:48:23 +053012857 psoc_cfg.auto_power_save_fail_mode =
12858 hdd_ctx->config->auto_pwr_save_fail_mode;
Mukul Sharma9d797a02017-01-05 20:26:03 +053012859
12860 hdd_ra_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9223f232017-03-08 18:42:27 +053012861 hdd_nan_populate_pmo_config(&psoc_cfg, hdd_ctx);
12862 hdd_lpass_populate_pmo_config(&psoc_cfg, hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012863
Dustin Brownb9987af2018-03-01 17:15:11 -080012864 status = ucfg_pmo_update_psoc_config(hdd_ctx->hdd_psoc, &psoc_cfg);
12865 if (QDF_IS_STATUS_ERROR(status))
12866 hdd_err("failed pmo psoc configuration; status:%d", status);
12867
12868 return qdf_status_to_os_return(status);
Mukul Sharma9d797a02017-01-05 20:26:03 +053012869}
12870
Abhishek Singhb20db962017-03-03 21:28:46 +053012871#ifdef FEATURE_WLAN_SCAN_PNO
12872static inline void hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
12873 struct hdd_config *cfg)
12874{
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012875 struct nlo_mawc_params *mawc_cfg = &pno_cfg->mawc_params;
12876
Abhishek Singhb20db962017-03-03 21:28:46 +053012877 pno_cfg->channel_prediction = cfg->pno_channel_prediction;
12878 pno_cfg->top_k_num_of_channels = cfg->top_k_num_of_channels;
12879 pno_cfg->stationary_thresh = cfg->stationary_thresh;
12880 pno_cfg->adaptive_dwell_mode = cfg->adaptive_dwell_mode_enabled;
12881 pno_cfg->channel_prediction_full_scan =
12882 cfg->channel_prediction_full_scan;
Varun Reddy Yeturubba32e92017-09-06 13:31:40 -070012883 mawc_cfg->enable = cfg->MAWCEnabled && cfg->mawc_nlo_enabled;
12884 mawc_cfg->exp_backoff_ratio = cfg->mawc_nlo_exp_backoff_ratio;
12885 mawc_cfg->init_scan_interval = cfg->mawc_nlo_init_scan_interval;
12886 mawc_cfg->max_scan_interval = cfg->mawc_nlo_max_scan_interval;
Abhishek Singhb20db962017-03-03 21:28:46 +053012887}
12888#else
12889static inline void
12890hdd_update_pno_config(struct pno_user_cfg *pno_cfg,
Jeff Johnson33a07922017-10-05 09:08:46 -070012891 struct hdd_config *cfg)
Abhishek Singhb20db962017-03-03 21:28:46 +053012892{
Abhishek Singhb20db962017-03-03 21:28:46 +053012893}
12894#endif
12895
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053012896void hdd_update_ie_whitelist_attr(struct probe_req_whitelist_attr *ie_whitelist,
12897 struct hdd_config *cfg)
12898{
12899 uint8_t i = 0;
12900
12901 ie_whitelist->white_list = cfg->probe_req_ie_whitelist;
12902 if (!ie_whitelist->white_list)
12903 return;
12904
12905 ie_whitelist->ie_bitmap[0] = cfg->probe_req_ie_bitmap_0;
12906 ie_whitelist->ie_bitmap[1] = cfg->probe_req_ie_bitmap_1;
12907 ie_whitelist->ie_bitmap[2] = cfg->probe_req_ie_bitmap_2;
12908 ie_whitelist->ie_bitmap[3] = cfg->probe_req_ie_bitmap_3;
12909 ie_whitelist->ie_bitmap[4] = cfg->probe_req_ie_bitmap_4;
12910 ie_whitelist->ie_bitmap[5] = cfg->probe_req_ie_bitmap_5;
12911 ie_whitelist->ie_bitmap[6] = cfg->probe_req_ie_bitmap_6;
12912 ie_whitelist->ie_bitmap[7] = cfg->probe_req_ie_bitmap_7;
12913
12914 ie_whitelist->num_vendor_oui = cfg->no_of_probe_req_ouis;
12915 for (i = 0; i < ie_whitelist->num_vendor_oui; i++)
12916 ie_whitelist->voui[i] = cfg->probe_req_voui[i];
12917}
12918
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053012919uint32_t hdd_limit_max_per_index_score(uint32_t per_index_score)
12920{
12921 uint8_t i, score;
12922
12923 for (i = 0; i < MAX_INDEX_PER_INI; i++) {
12924 score = WLAN_GET_SCORE_PERCENTAGE(per_index_score, i);
12925 if (score > MAX_INDEX_SCORE)
12926 WLAN_SET_SCORE_PERCENTAGE(per_index_score,
12927 MAX_INDEX_SCORE, i);
12928 }
12929
12930 return per_index_score;
12931}
12932
12933/**
12934 * hdd_update_score_config - API to update candidate scoring related params
12935 * configuration parameters
12936 * @score_config: score config to update
12937 * @cfg: config params
12938 *
12939 * Return: 0 if success else err
12940 */
12941static void hdd_update_score_config(
12942 struct scoring_config *score_config, struct hdd_config *cfg)
12943{
12944 int total_weight;
12945
12946 score_config->weight_cfg.rssi_weightage = cfg->rssi_weightage;
12947 score_config->weight_cfg.ht_caps_weightage = cfg->ht_caps_weightage;
12948 score_config->weight_cfg.vht_caps_weightage =
12949 cfg->vht_caps_weightage;
12950 score_config->weight_cfg.he_caps_weightage =
12951 cfg->he_caps_weightage;
12952 score_config->weight_cfg.chan_width_weightage =
12953 cfg->chan_width_weightage;
12954 score_config->weight_cfg.chan_band_weightage =
12955 cfg->chan_band_weightage;
12956 score_config->weight_cfg.nss_weightage = cfg->nss_weightage;
12957 score_config->weight_cfg.beamforming_cap_weightage =
12958 cfg->beamforming_cap_weightage;
12959 score_config->weight_cfg.pcl_weightage = cfg->pcl_weightage;
12960 score_config->weight_cfg.channel_congestion_weightage =
12961 cfg->channel_congestion_weightage;
12962 score_config->weight_cfg.oce_wan_weightage = cfg->oce_wan_weightage;
12963
12964 total_weight = score_config->weight_cfg.rssi_weightage +
12965 score_config->weight_cfg.ht_caps_weightage +
12966 score_config->weight_cfg.vht_caps_weightage +
12967 score_config->weight_cfg.he_caps_weightage +
12968 score_config->weight_cfg.chan_width_weightage +
12969 score_config->weight_cfg.chan_band_weightage +
12970 score_config->weight_cfg.nss_weightage +
12971 score_config->weight_cfg.beamforming_cap_weightage +
12972 score_config->weight_cfg.pcl_weightage +
12973 score_config->weight_cfg.channel_congestion_weightage +
12974 score_config->weight_cfg.oce_wan_weightage;
12975
12976 if (total_weight > BEST_CANDIDATE_MAX_WEIGHT) {
12977 hdd_err("total weight is greater than %d fallback to default values",
12978 BEST_CANDIDATE_MAX_WEIGHT);
12979
12980 score_config->weight_cfg.rssi_weightage = RSSI_WEIGHTAGE;
12981 score_config->weight_cfg.ht_caps_weightage =
12982 HT_CAPABILITY_WEIGHTAGE;
12983 score_config->weight_cfg.vht_caps_weightage = VHT_CAP_WEIGHTAGE;
12984 score_config->weight_cfg.he_caps_weightage = HE_CAP_WEIGHTAGE;
12985 score_config->weight_cfg.chan_width_weightage =
12986 CHAN_WIDTH_WEIGHTAGE;
12987 score_config->weight_cfg.chan_band_weightage =
12988 CHAN_BAND_WEIGHTAGE;
12989 score_config->weight_cfg.nss_weightage = NSS_WEIGHTAGE;
12990 score_config->weight_cfg.beamforming_cap_weightage =
12991 BEAMFORMING_CAP_WEIGHTAGE;
12992 score_config->weight_cfg.pcl_weightage = PCL_WEIGHT;
12993 score_config->weight_cfg.channel_congestion_weightage =
12994 CHANNEL_CONGESTION_WEIGHTAGE;
12995 score_config->weight_cfg.oce_wan_weightage = OCE_WAN_WEIGHTAGE;
12996 }
12997
12998 score_config->bandwidth_weight_per_index =
12999 hdd_limit_max_per_index_score(
13000 cfg->bandwidth_weight_per_index);
13001 score_config->nss_weight_per_index =
13002 hdd_limit_max_per_index_score(cfg->nss_weight_per_index);
13003 score_config->band_weight_per_index =
13004 hdd_limit_max_per_index_score(cfg->band_weight_per_index);
13005
13006 score_config->rssi_score.best_rssi_threshold =
13007 cfg->best_rssi_threshold;
13008 score_config->rssi_score.good_rssi_threshold =
13009 cfg->good_rssi_threshold;
13010 score_config->rssi_score.bad_rssi_threshold =
13011 cfg->bad_rssi_threshold;
13012 score_config->rssi_score.good_rssi_pcnt = cfg->good_rssi_pcnt;
13013 score_config->rssi_score.bad_rssi_pcnt = cfg->bad_rssi_pcnt;
13014 score_config->rssi_score.good_rssi_bucket_size =
13015 cfg->good_rssi_bucket_size;
13016 score_config->rssi_score.bad_rssi_bucket_size =
13017 cfg->bad_rssi_bucket_size;
13018 score_config->rssi_score.rssi_pref_5g_rssi_thresh =
13019 cfg->rssi_pref_5g_rssi_thresh;
13020
13021 score_config->esp_qbss_scoring.num_slot = cfg->num_esp_qbss_slots;
13022 score_config->esp_qbss_scoring.score_pcnt3_to_0 =
13023 hdd_limit_max_per_index_score(
13024 cfg->esp_qbss_score_slots3_to_0);
13025 score_config->esp_qbss_scoring.score_pcnt7_to_4 =
13026 hdd_limit_max_per_index_score(
13027 cfg->esp_qbss_score_slots7_to_4);
13028 score_config->esp_qbss_scoring.score_pcnt11_to_8 =
13029 hdd_limit_max_per_index_score(
13030 cfg->esp_qbss_score_slots11_to_8);
13031 score_config->esp_qbss_scoring.score_pcnt15_to_12 =
13032 hdd_limit_max_per_index_score(
13033 cfg->esp_qbss_score_slots15_to_12);
13034
13035 score_config->oce_wan_scoring.num_slot = cfg->num_oce_wan_slots;
13036 score_config->oce_wan_scoring.score_pcnt3_to_0 =
13037 hdd_limit_max_per_index_score(
13038 cfg->oce_wan_score_slots3_to_0);
13039 score_config->oce_wan_scoring.score_pcnt7_to_4 =
13040 hdd_limit_max_per_index_score(
13041 cfg->oce_wan_score_slots7_to_4);
13042 score_config->oce_wan_scoring.score_pcnt11_to_8 =
13043 hdd_limit_max_per_index_score(
13044 cfg->oce_wan_score_slots11_to_8);
13045 score_config->oce_wan_scoring.score_pcnt15_to_12 =
13046 hdd_limit_max_per_index_score(
13047 cfg->oce_wan_score_slots15_to_12);
13048
13049
13050 score_config->cb_mode_24G = cfg->nChannelBondingMode24GHz;
13051 score_config->cb_mode_5G = cfg->nChannelBondingMode5GHz;
13052 score_config->nss = cfg->enable2x2 ? 2 : 1;
13053
13054 if (cfg->dot11Mode == eHDD_DOT11_MODE_AUTO ||
13055 cfg->dot11Mode == eHDD_DOT11_MODE_11ax ||
13056 cfg->dot11Mode == eHDD_DOT11_MODE_11ax_ONLY)
13057 score_config->he_cap = 1;
13058
13059 if (score_config->he_cap ||
13060 cfg->dot11Mode == eHDD_DOT11_MODE_11ac ||
13061 cfg->dot11Mode == eHDD_DOT11_MODE_11ac_ONLY)
13062 score_config->vht_cap = 1;
13063
13064 if (score_config->vht_cap || cfg->dot11Mode == eHDD_DOT11_MODE_11n ||
13065 cfg->dot11Mode == eHDD_DOT11_MODE_11n_ONLY)
13066 score_config->ht_cap = 1;
13067
13068 if (score_config->vht_cap && cfg->enableVhtFor24GHzBand)
13069 score_config->vht_24G_cap = 1;
13070
13071 if (cfg->enableTxBF)
13072 score_config->beamformee_cap = 1;
13073
13074}
13075
Abhishek Singh257a9482017-03-06 16:52:39 +053013076/**
bings81fe50a2017-11-27 14:33:26 +080013077 * hdd_update_dfs_config() - API to update dfs configuration parameters.
13078 * @hdd_ctx: HDD context
13079 *
13080 * Return: 0 if success else err
13081 */
13082static int hdd_update_dfs_config(struct hdd_context *hdd_ctx)
13083{
13084 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13085 struct hdd_config *cfg = hdd_ctx->config;
13086 struct dfs_user_config dfs_cfg;
13087 QDF_STATUS status;
13088
13089 dfs_cfg.dfs_is_phyerr_filter_offload = !!cfg->fDfsPhyerrFilterOffload;
13090 status = ucfg_dfs_update_config(psoc, &dfs_cfg);
13091 if (QDF_IS_STATUS_ERROR(status)) {
13092 hdd_err("failed dfs psoc configuration");
13093 return -EINVAL;
13094 }
13095
13096 return 0;
13097}
13098
13099/**
Abhishek Singh257a9482017-03-06 16:52:39 +053013100 * hdd_update_scan_config - API to update scan configuration parameters
13101 * @hdd_ctx: HDD context
13102 *
13103 * Return: 0 if success else err
13104 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013105static int hdd_update_scan_config(struct hdd_context *hdd_ctx)
Abhishek Singh257a9482017-03-06 16:52:39 +053013106{
13107 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
13108 struct scan_user_cfg scan_cfg;
13109 struct hdd_config *cfg = hdd_ctx->config;
13110 QDF_STATUS status;
13111
13112 scan_cfg.active_dwell = cfg->nActiveMaxChnTime;
13113 scan_cfg.passive_dwell = cfg->nPassiveMaxChnTime;
13114 scan_cfg.conc_active_dwell = cfg->nActiveMaxChnTimeConc;
13115 scan_cfg.conc_passive_dwell = cfg->nPassiveMaxChnTimeConc;
13116 scan_cfg.conc_max_rest_time = cfg->nRestTimeConc;
13117 scan_cfg.conc_min_rest_time = cfg->min_rest_time_conc;
13118 scan_cfg.conc_idle_time = cfg->idle_time_conc;
Abhishek Singh158fe252017-03-23 11:09:34 +053013119 /* convert to ms */
13120 scan_cfg.scan_cache_aging_time =
13121 cfg->scanAgingTimeout * 1000;
13122 scan_cfg.prefer_5ghz = cfg->nRoamPrefer5GHz;
13123 scan_cfg.select_5ghz_margin = cfg->nSelect5GHzMargin;
13124 scan_cfg.scan_bucket_threshold = cfg->first_scan_bucket_threshold;
13125 scan_cfg.rssi_cat_gap = cfg->nRssiCatGap;
Abhishek Singh257a9482017-03-06 16:52:39 +053013126 scan_cfg.scan_dwell_time_mode = cfg->scan_adaptive_dwell_mode;
Kapil Guptafa9a8c62017-04-10 15:25:40 +053013127 scan_cfg.is_snr_monitoring_enabled = cfg->fEnableSNRMonitoring;
Jeff Johnson81c00d02017-11-07 12:34:36 -080013128 scan_cfg.usr_cfg_probe_rpt_time = cfg->scan_probe_repeat_time;
13129 scan_cfg.usr_cfg_num_probes = cfg->scan_num_probes;
Abhishek Singhb58164a2017-07-19 18:47:23 +053013130 scan_cfg.is_bssid_hint_priority = cfg->is_bssid_hint_priority;
Kiran Kumar Lokered547fdd2017-09-13 17:20:55 -070013131 scan_cfg.enable_mac_spoofing = cfg->enable_mac_spoofing;
Abhishek Singhc87bb042018-01-30 17:10:42 +053013132 scan_cfg.sta_miracast_mcc_rest_time =
13133 cfg->sta_miracast_mcc_rest_time_val;
Abhishek Singh257a9482017-03-06 16:52:39 +053013134
Abhishek Singhb20db962017-03-03 21:28:46 +053013135 hdd_update_pno_config(&scan_cfg.pno_cfg, cfg);
Rajeev Kumar Sirasanagandlaaec0b082017-06-21 11:59:41 +053013136 hdd_update_ie_whitelist_attr(&scan_cfg.ie_whitelist, cfg);
Abhishek Singhb6cdaf12017-11-10 14:43:39 +053013137 hdd_update_score_config(&scan_cfg.score_config, cfg);
Abhishek Singhb20db962017-03-03 21:28:46 +053013138
Abhishek Singh257a9482017-03-06 16:52:39 +053013139 status = ucfg_scan_update_user_config(psoc, &scan_cfg);
13140 if (status != QDF_STATUS_SUCCESS) {
13141 hdd_err("failed pmo psoc configuration");
13142 return -EINVAL;
13143 }
13144
13145 return 0;
13146}
Abhishek Singh257a9482017-03-06 16:52:39 +053013147
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013148int hdd_update_components_config(struct hdd_context *hdd_ctx)
Mukul Sharma9d797a02017-01-05 20:26:03 +053013149{
13150 int ret;
13151
13152 ret = hdd_update_pmo_config(hdd_ctx);
Abhishek Singh257a9482017-03-06 16:52:39 +053013153 if (ret)
13154 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013155
Abhishek Singh257a9482017-03-06 16:52:39 +053013156 ret = hdd_update_scan_config(hdd_ctx);
Frank Liud4b2fa02017-03-29 11:46:48 +080013157 if (ret)
13158 return ret;
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013159
Frank Liud4b2fa02017-03-29 11:46:48 +080013160 ret = hdd_update_tdls_config(hdd_ctx);
Venkata Sharath Chandra Manchala4aaae0f2017-07-10 11:59:19 -070013161 if (ret)
13162 return ret;
13163
13164 ret = hdd_update_dp_config(hdd_ctx);
bings81fe50a2017-11-27 14:33:26 +080013165 if (ret)
13166 return ret;
13167
13168 ret = hdd_update_dfs_config(hdd_ctx);
Mukul Sharma9d797a02017-01-05 20:26:03 +053013169
13170 return ret;
13171}
13172
Agrawal Ashish65634612016-08-18 13:24:32 +053013173/**
13174 * wlan_hdd_get_dfs_mode() - get ACS DFS mode
13175 * @mode : cfg80211 DFS mode
13176 *
13177 * Return: return SAP ACS DFS mode else return ACS_DFS_MODE_NONE
13178 */
13179enum sap_acs_dfs_mode wlan_hdd_get_dfs_mode(enum dfs_mode mode)
13180{
13181 switch (mode) {
13182 case DFS_MODE_ENABLE:
13183 return ACS_DFS_MODE_ENABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013184 case DFS_MODE_DISABLE:
13185 return ACS_DFS_MODE_DISABLE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013186 case DFS_MODE_DEPRIORITIZE:
13187 return ACS_DFS_MODE_DEPRIORITIZE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013188 default:
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013189 hdd_debug("ACS dfs mode is NONE");
13190 return ACS_DFS_MODE_NONE;
Agrawal Ashish65634612016-08-18 13:24:32 +053013191 }
13192}
13193
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013194/**
13195 * hdd_enable_disable_ca_event() - enable/disable channel avoidance event
13196 * @hddctx: pointer to hdd context
13197 * @set_value: enable/disable
13198 *
13199 * When Host sends vendor command enable, FW will send *ONE* CA ind to
13200 * Host(even though it is duplicate). When Host send vendor command
13201 * disable,FW doesn't perform any action. Whenever any change in
13202 * CA *and* WLAN is in SAP/P2P-GO mode, FW sends CA ind to host.
13203 *
13204 * return - 0 on success, appropriate error values on failure.
13205 */
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013206int hdd_enable_disable_ca_event(struct hdd_context *hddctx, uint8_t set_value)
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013207{
13208 QDF_STATUS status;
13209
Srinivas Girigowdab841da72017-03-25 18:04:39 -070013210 if (0 != wlan_hdd_validate_context(hddctx))
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013211 return -EAGAIN;
Selvaraj, Sridharebda0f22016-08-29 16:05:23 +053013212
13213 if (!hddctx->config->goptimize_chan_avoid_event) {
13214 hdd_warn("goptimize_chan_avoid_event ini param disabled");
13215 return -EINVAL;
13216 }
13217
13218 status = sme_enable_disable_chanavoidind_event(hddctx->hHal, set_value);
13219 if (!QDF_IS_STATUS_SUCCESS(status)) {
13220 hdd_err("Failed to send chan avoid command to SME");
13221 return -EINVAL;
13222 }
13223 return 0;
13224}
Agrawal Ashish65634612016-08-18 13:24:32 +053013225
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013226/**
13227 * hdd_set_roaming_in_progress() - to set the roaming in progress flag
13228 * @value: value to set
13229 *
13230 * This function will set the passed value to roaming in progress flag.
13231 *
13232 * Return: None
13233 */
13234void hdd_set_roaming_in_progress(bool value)
13235{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013236 struct hdd_context *hdd_ctx;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013237
13238 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13239 if (!hdd_ctx) {
13240 hdd_err("HDD context is NULL");
13241 return;
13242 }
13243
13244 hdd_ctx->roaming_in_progress = value;
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013245 hdd_debug("Roaming in Progress set to %d", value);
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013246}
13247
13248/**
13249 * hdd_is_roaming_in_progress() - check if roaming is in progress
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013250 * @adapter - HDD adapter
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013251 *
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013252 * Return: true if roaming is in progress for STA type, else false
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013253 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013254bool hdd_is_roaming_in_progress(struct hdd_adapter *adapter)
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013255{
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013256 struct hdd_context *hdd_ctx;
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013257 bool ret_status = false;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013258
13259 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13260 if (!hdd_ctx) {
13261 hdd_err("HDD context is NULL");
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013262 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013263 }
Srinivas Girigowda3d5250d2017-03-06 17:32:16 -080013264 hdd_debug("dev mode = %d, roaming_in_progress = %d",
13265 adapter->device_mode, hdd_ctx->roaming_in_progress);
Varun Reddy Yeturua5784142017-03-10 12:11:44 -080013266 ret_status = ((adapter->device_mode == QDF_STA_MODE) &&
13267 hdd_ctx->roaming_in_progress);
13268
13269 return ret_status;
Varun Reddy Yeturudce1c562016-11-18 10:00:45 -080013270}
13271
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013272/**
13273 * hdd_is_connection_in_progress() - check if connection is in
13274 * progress
13275 * @session_id: session id
13276 * @reason: scan reject reason
13277 *
13278 * Go through each adapter and check if Connection is in progress
13279 *
13280 * Return: true if connection is in progress else false
13281 */
13282bool hdd_is_connection_in_progress(uint8_t *session_id,
13283 enum scan_reject_states *reason)
13284{
Jeff Johnson40dae4e2017-08-29 14:00:25 -070013285 struct hdd_station_ctx *hdd_sta_ctx = NULL;
Jeff Johnson9d295242017-08-29 14:39:48 -070013286 struct hdd_adapter *adapter = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013287 uint8_t sta_id = 0;
13288 uint8_t *sta_mac = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013289 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013290
13291 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13292 if (!hdd_ctx) {
13293 hdd_err("HDD context is NULL");
13294 return false;
13295 }
13296
Dustin Brown920397d2017-12-13 16:27:50 -080013297 hdd_for_each_adapter(hdd_ctx, adapter) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013298 hdd_info("Adapter with device mode %s(%d) exists",
13299 hdd_device_mode_to_string(adapter->device_mode),
13300 adapter->device_mode);
13301 if (((QDF_STA_MODE == adapter->device_mode)
13302 || (QDF_P2P_CLIENT_MODE == adapter->device_mode)
13303 || (QDF_P2P_DEVICE_MODE == adapter->device_mode))
13304 && (eConnectionState_Connecting ==
13305 (WLAN_HDD_GET_STATION_CTX_PTR(adapter))->
13306 conn_info.connState)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013307 hdd_debug("%pK(%d) Connection is in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013308 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013309 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013310 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013311 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013312 *reason = CONNECTION_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013313 }
13314 return true;
13315 }
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013316 /*
13317 * sme_neighbor_middle_of_roaming is for LFR2
13318 * hdd_is_roaming_in_progress is for LFR3
13319 */
13320 if (((QDF_STA_MODE == adapter->device_mode) &&
13321 sme_neighbor_middle_of_roaming(
13322 WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013323 adapter->session_id)) ||
Archana Ramachandran62886ce2017-03-24 14:46:32 -070013324 hdd_is_roaming_in_progress(adapter)) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013325 hdd_debug("%pK(%d) Reassociation in progress",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013326 WLAN_HDD_GET_STATION_CTX_PTR(adapter),
Jeff Johnson1b780e42017-10-31 14:11:45 -070013327 adapter->session_id);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013328 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013329 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013330 *reason = REASSOC_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013331 }
13332 return true;
13333 }
13334 if ((QDF_STA_MODE == adapter->device_mode) ||
13335 (QDF_P2P_CLIENT_MODE == adapter->device_mode) ||
13336 (QDF_P2P_DEVICE_MODE == adapter->device_mode)) {
13337 hdd_sta_ctx =
13338 WLAN_HDD_GET_STATION_CTX_PTR(adapter);
13339 if ((eConnectionState_Associated ==
Vignesh Viswanathan0a569292018-02-14 15:34:47 +053013340 hdd_sta_ctx->conn_info.connState)
13341 && sme_is_sta_key_exchange_in_progress(
13342 hdd_ctx->hHal, adapter->session_id)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013343 sta_mac = (uint8_t *)
Jeff Johnson1e851a12017-10-28 14:36:12 -070013344 &(adapter->mac_addr.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013345 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013346 " is in middle of WPS/EAPOL exchange.",
13347 MAC_ADDR_ARRAY(sta_mac));
13348 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013349 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013350 *reason = EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013351 }
13352 return true;
13353 }
13354 } else if ((QDF_SAP_MODE == adapter->device_mode) ||
13355 (QDF_P2P_GO_MODE == adapter->device_mode)) {
13356 for (sta_id = 0; sta_id < WLAN_MAX_STA_COUNT;
13357 sta_id++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013358 if (!((adapter->sta_info[sta_id].in_use)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013359 && (OL_TXRX_PEER_STATE_CONN ==
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013360 adapter->sta_info[sta_id].peer_state)))
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013361 continue;
13362
13363 sta_mac = (uint8_t *)
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -070013364 &(adapter->sta_info[sta_id].
Jeff Johnsonf2356512017-10-21 16:04:12 -070013365 sta_mac.bytes[0]);
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013366 hdd_debug("client " MAC_ADDRESS_STR
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013367 " of SAP/GO is in middle of WPS/EAPOL exchange",
13368 MAC_ADDR_ARRAY(sta_mac));
13369 if (session_id && reason) {
Jeff Johnson1b780e42017-10-31 14:11:45 -070013370 *session_id = adapter->session_id;
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013371 *reason = SAP_EAPOL_IN_PROGRESS;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013372 }
13373 return true;
13374 }
13375 if (hdd_ctx->connection_in_progress) {
Vignesh Viswanathan82bd2532017-09-20 11:17:12 +053013376 hdd_debug("AP/GO: connection is in progress");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013377 return true;
13378 }
13379 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013380 }
Dustin Brown920397d2017-12-13 16:27:50 -080013381
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013382 return false;
13383}
13384
13385/**
13386 * hdd_restart_sap() - to restart SAP in driver internally
Jeff Johnson9d295242017-08-29 14:39:48 -070013387 * @ap_adapter: Pointer to SAP struct hdd_adapter structure
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013388 *
13389 * Return: None
13390 */
Jeff Johnson9d295242017-08-29 14:39:48 -070013391void hdd_restart_sap(struct hdd_adapter *ap_adapter)
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013392{
Jeff Johnson87251032017-08-29 13:31:11 -070013393 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -070013394 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013395 QDF_STATUS qdf_status;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013396 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013397 tsap_Config_t *sap_config;
13398 void *sap_ctx;
13399
13400 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(ap_adapter);
Jeff Johnson91df29d2017-10-27 19:29:50 -070013401 sap_config = &hdd_ap_ctx->sap_config;
Jeff Johnson0bbe66f2017-10-27 19:23:49 -070013402 sap_ctx = hdd_ap_ctx->sap_context;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013403
13404 mutex_lock(&hdd_ctx->sap_lock);
13405 if (test_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags)) {
13406 wlan_hdd_del_station(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013407 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(ap_adapter);
13408 qdf_event_reset(&hostapd_state->qdf_stop_bss_event);
13409 if (QDF_STATUS_SUCCESS == wlansap_stop_bss(sap_ctx)) {
13410 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013411 qdf_wait_for_event_completion(&hostapd_state->
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013412 qdf_stop_bss_event,
13413 SME_CMD_TIMEOUT_VALUE);
13414
13415 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013416 hdd_err("SAP Stop Failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013417 goto end;
13418 }
13419 }
13420 clear_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013421 policy_mgr_decr_session_set_pcl(hdd_ctx->hdd_psoc,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013422 ap_adapter->device_mode, ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070013423 hdd_green_ap_start_state_mc(hdd_ctx, ap_adapter->device_mode,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013424 false);
Jeff Johnson6867ec32017-09-29 20:30:20 -070013425 hdd_err("SAP Stop Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013426
13427 if (0 != wlan_hdd_cfg80211_update_apies(ap_adapter)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013428 hdd_err("SAP Not able to set AP IEs");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013429 wlansap_reset_sap_config_add_ie(sap_config,
13430 eUPDATE_IE_ALL);
13431 goto end;
13432 }
13433
13434 qdf_event_reset(&hostapd_state->qdf_event);
13435 if (wlansap_start_bss(sap_ctx, hdd_hostapd_sap_event_cb,
13436 sap_config,
13437 ap_adapter->dev) != QDF_STATUS_SUCCESS) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013438 hdd_err("SAP Start Bss fail");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013439 wlansap_reset_sap_config_add_ie(sap_config,
13440 eUPDATE_IE_ALL);
13441 goto end;
13442 }
13443
Jeff Johnson6867ec32017-09-29 20:30:20 -070013444 hdd_info("Waiting for SAP to start");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013445 qdf_status =
Nachiket Kukade0396b732017-11-14 16:35:16 +053013446 qdf_wait_for_event_completion(&hostapd_state->qdf_event,
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013447 SME_CMD_TIMEOUT_VALUE);
13448 wlansap_reset_sap_config_add_ie(sap_config,
13449 eUPDATE_IE_ALL);
13450 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013451 hdd_err("SAP Start failed");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013452 goto end;
13453 }
Jeff Johnson6867ec32017-09-29 20:30:20 -070013454 hdd_err("SAP Start Success");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013455 set_bit(SOFTAP_BSS_STARTED, &ap_adapter->event_flags);
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013456 if (hostapd_state->bss_state == BSS_START) {
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013457 policy_mgr_incr_active_session(hdd_ctx->hdd_psoc,
13458 ap_adapter->device_mode,
Jeff Johnson1b780e42017-10-31 14:11:45 -070013459 ap_adapter->session_id);
Jeff Johnsone8846ab2018-03-31 11:54:45 -070013460 hdd_green_ap_start_state_mc(hdd_ctx,
Himanshu Agarwal813b2bf2018-01-22 16:32:15 +053013461 ap_adapter->device_mode,
13462 true);
13463 }
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013464 }
13465end:
13466 mutex_unlock(&hdd_ctx->sap_lock);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013467}
13468
13469/**
13470 * hdd_check_and_restart_sap_with_non_dfs_acs() - Restart SAP
13471 * with non dfs acs
13472 *
13473 * Restarts SAP in non-DFS ACS mode when STA-AP mode DFS is not supported
13474 *
13475 * Return: None
13476 */
13477void hdd_check_and_restart_sap_with_non_dfs_acs(void)
13478{
Jeff Johnson9d295242017-08-29 14:39:48 -070013479 struct hdd_adapter *ap_adapter;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013480 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013481 cds_context_type *cds_ctx;
13482
13483 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13484 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013485 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013486 return;
13487 }
13488
13489 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
13490 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013491 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013492 return;
13493 }
13494
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013495 if (policy_mgr_get_concurrency_mode(hdd_ctx->hdd_psoc)
13496 != (QDF_STA_MASK | QDF_SAP_MASK)) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013497 hdd_info("Concurrency mode is not SAP");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013498 return;
13499 }
13500
13501 ap_adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -070013502 if (ap_adapter != NULL && test_bit(SOFTAP_BSS_STARTED,
13503 &ap_adapter->event_flags) &&
13504 wlan_reg_is_dfs_ch(hdd_ctx->hdd_pdev,
Jeff Johnsonb9424862017-10-30 08:49:35 -070013505 ap_adapter->session.ap.operating_channel)) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013506
Jeff Johnson6867ec32017-09-29 20:30:20 -070013507 hdd_warn("STA-AP Mode DFS not supported. Restart SAP with Non DFS ACS");
Jeff Johnsonb9424862017-10-30 08:49:35 -070013508 ap_adapter->session.ap.sap_config.channel =
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013509 AUTO_CHANNEL_SELECT;
Jeff Johnsonb9424862017-10-30 08:49:35 -070013510 ap_adapter->session.ap.sap_config.
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013511 acs_cfg.acs_mode = true;
13512
Tushnim Bhattacharyyade1070d2017-03-09 13:23:55 -080013513 hdd_restart_sap(ap_adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013514 }
13515}
13516
13517/**
13518 * hdd_set_connection_in_progress() - to set the connection in
13519 * progress flag
13520 * @value: value to set
13521 *
13522 * This function will set the passed value to connection in progress flag.
13523 * If value is previously being set to true then no need to set it again.
13524 *
13525 * Return: true if value is being set correctly and false otherwise.
13526 */
13527bool hdd_set_connection_in_progress(bool value)
13528{
13529 bool status = true;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013530 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013531
13532 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13533 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -070013534 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080013535 return false;
13536 }
13537
13538 qdf_spin_lock(&hdd_ctx->connection_status_lock);
13539 /*
13540 * if the value is set to true previously and if someone is
13541 * trying to make it true again then it could be some race
13542 * condition being triggered. Avoid this situation by returning
13543 * false
13544 */
13545 if (hdd_ctx->connection_in_progress && value)
13546 status = false;
13547 else
13548 hdd_ctx->connection_in_progress = value;
13549 qdf_spin_unlock(&hdd_ctx->connection_status_lock);
13550 return status;
13551}
13552
Jeff Johnson9d295242017-08-29 14:39:48 -070013553int wlan_hdd_send_p2p_quota(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013554{
13555 if (!adapter) {
13556 hdd_err("Invalid adapter");
13557 return -EINVAL;
13558 }
13559 hdd_info("Send MCC P2P QUOTA to WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013560 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013561 WMA_VDEV_MCC_SET_TIME_QUOTA,
13562 set_value, VDEV_CMD);
13563 return 0;
13564
13565}
13566
Jeff Johnson9d295242017-08-29 14:39:48 -070013567int wlan_hdd_send_mcc_latency(struct hdd_adapter *adapter, int set_value)
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013568{
13569 if (!adapter) {
13570 hdd_err("Invalid adapter");
13571 return -EINVAL;
13572 }
13573
13574 hdd_info("Send MCC latency WMA: %d", set_value);
Jeff Johnson1b780e42017-10-31 14:11:45 -070013575 sme_cli_set_command(adapter->session_id,
Archana Ramachandranb8c04f92017-03-17 20:05:47 -070013576 WMA_VDEV_MCC_SET_TIME_LATENCY,
13577 set_value, VDEV_CMD);
13578 return 0;
13579}
13580
Jeff Johnson9d295242017-08-29 14:39:48 -070013581struct hdd_adapter *wlan_hdd_get_adapter_from_vdev(struct wlan_objmgr_psoc
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013582 *psoc, uint8_t vdev_id)
13583{
Jeff Johnson9d295242017-08-29 14:39:48 -070013584 struct hdd_adapter *adapter = NULL;
Jeff Johnsond49c4a12017-08-28 12:08:05 -070013585 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Archana Ramachandranea34c4f2017-03-19 18:56:18 -070013586
13587 /*
13588 * Currently PSOC is not being used. But this logic will
13589 * change once we have the converged implementation of
13590 * HDD context per PSOC in place. This would break if
13591 * multiple vdev objects reuse the vdev id.
13592 */
13593 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
13594 if (!adapter)
13595 hdd_err("Get adapter by vdev id failed");
13596
13597 return adapter;
13598}
13599
Jeff Johnson9d295242017-08-29 14:39:48 -070013600int hdd_get_rssi_snr_by_bssid(struct hdd_adapter *adapter, const uint8_t *bssid,
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013601 int8_t *rssi, int8_t *snr)
13602{
13603 QDF_STATUS status;
Jeff Johnson025618c2018-03-18 14:41:00 -070013604 struct csr_roam_profile *roam_profile;
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013605
Jeff Johnson025618c2018-03-18 14:41:00 -070013606 roam_profile = hdd_roam_profile(adapter);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013607 status = sme_get_rssi_snr_by_bssid(WLAN_HDD_GET_HAL_CTX(adapter),
Jeff Johnson025618c2018-03-18 14:41:00 -070013608 roam_profile, bssid, rssi, snr);
Hanumanth Reddy Pothula90051782017-05-04 22:14:43 +053013609 if (QDF_STATUS_SUCCESS != status) {
13610 hdd_warn("sme_get_rssi_snr_by_bssid failed");
13611 return -EINVAL;
13612 }
13613
13614 return 0;
13615}
13616
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013617/**
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013618 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
13619 * @adapter - HDD adapter
13620 * @tos - type of service
13621 * @status - status of the traffic
13622 *
13623 * Return: 0 on success and non zero value on failure
13624 */
13625
13626int hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter, enum tos tos,
13627 bool is_tos_active)
13628{
13629 int ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013630 struct hdd_context *hdd_ctx;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013631 uint32_t max_off_chan_time = 0;
13632 QDF_STATUS status;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013633 int ret;
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013634 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013635
13636 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13637 ret = wlan_hdd_validate_context(hdd_ctx);
13638
13639 if (ret < 0) {
13640 hdd_err("failed to set limit off chan params");
13641 return ret;
13642 }
13643
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013644 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
13645
13646 if (is_tos_active)
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013647 adapter->active_ac |= ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013648 else
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013649 adapter->active_ac &= ~ac_bit;
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013650
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013651 if (adapter->active_ac) {
13652 if (adapter->active_ac & HDD_AC_VO_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013653 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013654 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
13655 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13656 PM_LATENCY);
Ganesh Kondabattini1a2aed82017-09-28 12:21:58 +053013657 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013658 max_off_chan_time =
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013659 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
13660 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13661 PM_LATENCY);
13662 } else {
13663 /*ignore this command if only BE/BK is active */
13664 is_tos_active = false;
13665 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13666 hdd_ctx->config->conc_system_pref);
13667 }
13668 } else {
13669 /* No active tos */
13670 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13671 hdd_ctx->config->conc_system_pref);
13672 }
13673
Jeff Johnson1b780e42017-10-31 14:11:45 -070013674 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013675 is_tos_active, max_off_chan_time,
13676 hdd_ctx->config->nRestTimeConc, true);
13677 if (!QDF_IS_STATUS_SUCCESS(status)) {
13678 hdd_err("failed to set limit off chan params");
13679 ret = -EINVAL;
13680 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013681
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013682 return ret;
13683}
13684
13685/**
13686 * hdd_reset_limit_off_chan() - reset limit off-channel command parameters
13687 * @adapter - HDD adapter
13688 *
13689 * Return: 0 on success and non zero value on failure
13690 */
13691int hdd_reset_limit_off_chan(struct hdd_adapter *adapter)
13692{
13693 struct hdd_context *hdd_ctx;
13694 int ret;
13695 QDF_STATUS status;
13696 tHalHandle hal = WLAN_HDD_GET_HAL_CTX(adapter);
13697
13698 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
13699 ret = wlan_hdd_validate_context(hdd_ctx);
13700 if (ret < 0)
13701 return ret;
13702
13703 /* set the system preferece to default */
13704 policy_mgr_set_cur_conc_system_pref(hdd_ctx->hdd_psoc,
13705 hdd_ctx->config->conc_system_pref);
13706
13707 /* clear the bitmap */
13708 adapter->active_ac = 0;
13709
13710 hdd_debug("reset ac_bitmap for session %hu active_ac %0x",
Jeff Johnson1b780e42017-10-31 14:11:45 -070013711 adapter->session_id, adapter->active_ac);
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013712
Jeff Johnson1b780e42017-10-31 14:11:45 -070013713 status = sme_send_limit_off_channel_params(hal, adapter->session_id,
Ganesh Kondabattini479a8ae2017-10-03 16:49:24 +053013714 false, 0, 0, false);
13715 if (!QDF_IS_STATUS_SUCCESS(status)) {
13716 hdd_err("failed to reset limit off chan params");
13717 ret = -EINVAL;
13718 }
Ganesh Kondabattini35739572017-06-21 16:26:39 +053013719
13720 return ret;
13721}
13722
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013723/**
13724 * hdd_start_driver_ops_timer() - Starts driver ops inactivity timer
13725 * @drv_op: Enum indicating driver op
13726 *
13727 * Return: none
13728 */
13729void hdd_start_driver_ops_timer(int drv_op)
13730{
13731 memset(drv_ops_string, 0, MAX_OPS_NAME_STRING_SIZE);
13732 switch (drv_op) {
13733 case eHDD_DRV_OP_PROBE:
13734 memcpy(drv_ops_string, "probe", sizeof("probe"));
13735 break;
13736 case eHDD_DRV_OP_REMOVE:
13737 memcpy(drv_ops_string, "remove", sizeof("remove"));
13738 break;
13739 case eHDD_DRV_OP_SHUTDOWN:
13740 memcpy(drv_ops_string, "shutdown", sizeof("shutdown"));
13741 break;
13742 case eHDD_DRV_OP_REINIT:
13743 memcpy(drv_ops_string, "reinit", sizeof("reinit"));
13744 break;
Arunk Khandavallie9ef42a2017-10-04 14:49:51 +053013745 case eHDD_DRV_OP_IFF_UP:
13746 memcpy(drv_ops_string, "iff_up", sizeof("iff_up"));
13747 break;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013748 }
13749
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013750 hdd_drv_ops_task = current;
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013751 qdf_timer_start(&hdd_drv_ops_inactivity_timer,
13752 HDD_OPS_INACTIVITY_TIMEOUT);
13753}
13754
13755/**
13756 * hdd_stop_driver_ops_timer() - Stops driver ops inactivity timer
13757 *
13758 * Return: none
13759 */
13760void hdd_stop_driver_ops_timer(void)
13761{
13762 qdf_timer_sync_cancel(&hdd_drv_ops_inactivity_timer);
13763}
13764
13765/**
13766 * hdd_drv_ops_inactivity_handler() - Timeout handler for driver ops
13767 * inactivity timer
13768 *
13769 * Return: None
13770 */
13771void hdd_drv_ops_inactivity_handler(void)
13772{
13773 hdd_err("%s: %d Sec timer expired while in .%s",
13774 __func__, HDD_OPS_INACTIVITY_TIMEOUT/1000, drv_ops_string);
13775
Dustin Brown45ed4bb2017-12-18 12:00:13 -080013776 if (hdd_drv_ops_task) {
13777 printk("Call stack for \"%s\"\n", hdd_drv_ops_task->comm);
13778 qdf_print_thread_trace(hdd_drv_ops_task);
13779 } else {
13780 hdd_err("hdd_drv_ops_task is null");
13781 }
13782
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013783 /* Driver shutdown is stuck, no recovery possible at this point */
13784 if (0 == qdf_mem_cmp(&drv_ops_string[0], "shutdown",
13785 sizeof("shutdown")))
13786 QDF_BUG(0);
13787
Rajeev Kumar1e57b9c2018-01-04 16:17:10 -080013788 if (cds_is_fw_down()) {
13789 hdd_err("FW is down");
13790 return;
13791 }
13792
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013793 if (cds_is_self_recovery_enabled())
Anurag Chouhan4085ff72017-10-05 18:09:56 +053013794 cds_trigger_recovery(QDF_REASON_UNSPECIFIED);
Nachiket Kukadebe8850b2017-09-18 15:37:00 +053013795 else
13796 QDF_BUG(0);
13797}
13798
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013799void hdd_pld_ipa_uc_shutdown_pipes(void)
13800{
13801 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13802
13803 if (!hdd_ctx)
13804 return;
13805
Sravan Kumar Kairam858073b2018-03-13 09:03:32 +053013806 ucfg_ipa_uc_force_pipe_shutdown(hdd_ctx->hdd_pdev);
Sravan Kumar Kairamd80c7662017-10-03 16:11:05 +053013807}
13808
Yun Parkff6a16a2017-09-26 16:38:18 -070013809/**
13810 * hdd_set_rx_mode_rps() - Enable/disable RPS in SAP mode
13811 * @struct hdd_context *hdd_ctx
13812 * @struct hdd_adapter *padapter
13813 * @bool enble
13814 *
13815 * Return: none
13816 */
13817void hdd_set_rx_mode_rps(bool enable)
13818{
13819 struct cds_config_info *cds_cfg = cds_get_ini_config();
13820 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
13821 struct hdd_adapter *adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE);
13822
13823 if (adapter && hdd_ctx &&
13824 !hdd_ctx->rps && cds_cfg->uc_offload_enabled) {
13825 if (enable && !cds_cfg->rps_enabled)
13826 hdd_send_rps_ind(adapter);
13827 else if (!enable && cds_cfg->rps_enabled)
13828 hdd_send_rps_disable_ind(adapter);
13829 }
13830}
13831
Hanumanth Reddy Pothula3862ca92018-01-12 16:44:10 +053013832bool hdd_is_cli_iface_up(struct hdd_context *hdd_ctx)
13833{
13834 struct hdd_adapter *adapter = NULL;
13835
13836 hdd_for_each_adapter(hdd_ctx, adapter) {
13837 if ((adapter->device_mode == QDF_STA_MODE ||
13838 adapter->device_mode == QDF_P2P_CLIENT_MODE) &&
13839 qdf_atomic_test_bit(DEVICE_IFACE_OPENED,
13840 &adapter->event_flags)){
13841 return true;
13842 }
13843 }
13844
13845 return false;
13846}
13847
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013848/* Register the module init/exit functions */
13849module_init(hdd_module_init);
13850module_exit(hdd_module_exit);
13851
13852MODULE_LICENSE("Dual BSD/GPL");
13853MODULE_AUTHOR("Qualcomm Atheros, Inc.");
13854MODULE_DESCRIPTION("WLAN HOST DEVICE DRIVER");
13855
Srinivas Girigowda841da292018-02-21 16:33:00 -080013856static const struct kernel_param_ops con_mode_ops = {
13857 .set = con_mode_handler,
13858 .get = param_get_int,
13859};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013860
Srinivas Girigowda841da292018-02-21 16:33:00 -080013861static const struct kernel_param_ops con_mode_ftm_ops = {
13862 .set = con_mode_handler_ftm,
13863 .get = param_get_int,
13864};
Arunk Khandavalliba3d5582017-07-11 19:48:32 +053013865
Srinivas Girigowda841da292018-02-21 16:33:00 -080013866static const struct kernel_param_ops con_mode_monitor_ops = {
13867 .set = con_mode_handler_monitor,
13868 .get = param_get_int,
13869};
Ravi Joshia307f632017-07-17 23:41:41 -070013870
Srinivas Girigowda841da292018-02-21 16:33:00 -080013871static const struct kernel_param_ops fwpath_ops = {
13872 .set = fwpath_changed_handler,
13873 .get = param_get_string,
13874};
13875
13876module_param_cb(con_mode, &con_mode_ops, &con_mode,
13877 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13878
13879module_param_cb(con_mode_ftm, &con_mode_ftm_ops, &con_mode_ftm,
13880 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13881
13882module_param_cb(con_mode_monitor, &con_mode_monitor_ops, &con_mode_monitor,
13883 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
13884
13885module_param_cb(fwpath, &fwpath_ops, &fwpath,
13886 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080013887
13888module_param(enable_dfs_chan_scan, int, S_IRUSR | S_IRGRP | S_IROTH);
13889
13890module_param(enable_11d, int, S_IRUSR | S_IRGRP | S_IROTH);
13891
13892module_param(country_code, charp, S_IRUSR | S_IRGRP | S_IROTH);